@@ -59,7 +59,8 @@ private: | |||||
TrackedState<float> m_alpha_value; | TrackedState<float> m_alpha_value; | ||||
TrackedState<BlendFunc> m_blend_src, m_blend_dst; | TrackedState<BlendFunc> m_blend_src, m_blend_dst; | ||||
TrackedState<DepthFunc> m_depth_func; | TrackedState<DepthFunc> m_depth_func; | ||||
TrackedState<CullMode> m_face_culling; | |||||
TrackedState<CullMode> m_cull_mode; | |||||
TrackedState<PolygonMode> m_polygon_mode; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -93,8 +94,11 @@ RenderContext::~RenderContext() | |||||
if (m_data->m_depth_func.HasChanged()) | if (m_data->m_depth_func.HasChanged()) | ||||
g_renderer->SetDepthFunc(m_data->m_depth_func.GetValue()); | g_renderer->SetDepthFunc(m_data->m_depth_func.GetValue()); | ||||
if (m_data->m_face_culling.HasChanged()) | |||||
g_renderer->SetFaceCulling(m_data->m_face_culling.GetValue()); | |||||
if (m_data->m_cull_mode.HasChanged()) | |||||
g_renderer->SetCullMode(m_data->m_cull_mode.GetValue()); | |||||
if (m_data->m_polygon_mode.HasChanged()) | |||||
g_renderer->SetPolygonMode(m_data->m_polygon_mode.GetValue()); | |||||
delete m_data; | delete m_data; | ||||
} | } | ||||
@@ -151,12 +155,20 @@ void RenderContext::SetDepthFunc(DepthFunc func) | |||||
g_renderer->SetDepthFunc(func); | g_renderer->SetDepthFunc(func); | ||||
} | } | ||||
void RenderContext::SetFaceCulling(CullMode mode) | |||||
void RenderContext::SetCullMode(CullMode mode) | |||||
{ | |||||
if (!m_data->m_cull_mode.HasChanged()) | |||||
m_data->m_cull_mode.TrackValue(g_renderer->GetCullMode()); | |||||
g_renderer->SetCullMode(mode); | |||||
} | |||||
void RenderContext::SetPolygonMode(PolygonMode mode) | |||||
{ | { | ||||
if (!m_data->m_face_culling.HasChanged()) | |||||
m_data->m_face_culling.TrackValue(g_renderer->GetFaceCulling()); | |||||
if (!m_data->m_polygon_mode.HasChanged()) | |||||
m_data->m_polygon_mode.TrackValue(g_renderer->GetPolygonMode()); | |||||
g_renderer->SetFaceCulling(mode); | |||||
g_renderer->SetPolygonMode(mode); | |||||
} | } | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -63,7 +63,8 @@ private: | |||||
float m_alpha_value; | float m_alpha_value; | ||||
BlendFunc m_blend_src, m_blend_dst; | BlendFunc m_blend_src, m_blend_dst; | ||||
DepthFunc m_depth_func; | DepthFunc m_depth_func; | ||||
CullMode m_face_culling; | |||||
CullMode m_cull_mode; | |||||
PolygonMode m_polygon_mode; | |||||
private: | private: | ||||
#if defined USE_D3D9 | #if defined USE_D3D9 | ||||
@@ -155,8 +156,11 @@ Renderer::Renderer(ivec2 size) | |||||
m_data->m_depth_func = DepthFunc::Disabled; | m_data->m_depth_func = DepthFunc::Disabled; | ||||
SetDepthFunc(DepthFunc::LessOrEqual); | SetDepthFunc(DepthFunc::LessOrEqual); | ||||
m_data->m_face_culling = CullMode::Disabled; | |||||
SetFaceCulling(CullMode::CounterClockwise); | |||||
m_data->m_cull_mode = CullMode::Disabled; | |||||
SetCullMode(CullMode::CounterClockwise); | |||||
m_data->m_polygon_mode = PolygonMode::Point; | |||||
SetPolygonMode(PolygonMode::Fill); | |||||
/* Add some rendering states that we don't export to the user */ | /* Add some rendering states that we don't export to the user */ | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
@@ -600,9 +604,9 @@ DepthFunc Renderer::GetDepthFunc() const | |||||
* Face culling | * Face culling | ||||
*/ | */ | ||||
void Renderer::SetFaceCulling(CullMode mode) | |||||
void Renderer::SetCullMode(CullMode mode) | |||||
{ | { | ||||
if (m_data->m_face_culling == mode) | |||||
if (m_data->m_cull_mode == mode) | |||||
return; | return; | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
@@ -637,12 +641,57 @@ void Renderer::SetFaceCulling(CullMode mode) | |||||
} | } | ||||
#endif | #endif | ||||
m_data->m_face_culling = mode; | |||||
m_data->m_cull_mode = mode; | |||||
} | |||||
CullMode Renderer::GetCullMode() const | |||||
{ | |||||
return m_data->m_cull_mode; | |||||
} | |||||
/* | |||||
* Polygon rendering mode | |||||
*/ | |||||
void Renderer::SetPolygonMode(PolygonMode mode) | |||||
{ | |||||
if (m_data->m_polygon_mode == mode) | |||||
return; | |||||
#if defined USE_D3D9 || defined _XBOX | |||||
switch (mode) | |||||
{ | |||||
case PolygonMode::Point: | |||||
m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT); | |||||
break; | |||||
case PolygonMode::Line: | |||||
m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); | |||||
break; | |||||
case PolygonMode::Fill: | |||||
m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DCULL_SOLID); | |||||
break; | |||||
} | |||||
#else | |||||
switch (mode) | |||||
{ | |||||
case PolygonMode::Point: | |||||
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); | |||||
break; | |||||
case PolygonMode::Line: | |||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | |||||
break; | |||||
case PolygonMode::Fill: | |||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |||||
break; | |||||
} | |||||
#endif | |||||
m_data->m_polygon_mode = mode; | |||||
} | } | ||||
CullMode Renderer::GetFaceCulling() const | |||||
PolygonMode Renderer::GetPolygonMode() const | |||||
{ | { | ||||
return m_data->m_face_culling; | |||||
return m_data->m_polygon_mode; | |||||
} | } | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -1,151 +0,0 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | |||||
// modify it under the terms of the Do What The Fuck You Want To | |||||
// Public License, Version 2, as published by Sam Hocevar. See | |||||
// http://www.wtfpl.net/ for more details. | |||||
// | |||||
// | |||||
// The Renderer class | |||||
// ------------------ | |||||
// | |||||
#if !defined __LOL_RENDERER_H__ | |||||
#define __LOL_RENDERER_H__ | |||||
namespace lol | |||||
{ | |||||
class RendererData; | |||||
/* A safe enum to indicate the blending factors. */ | |||||
struct BlendFunc | |||||
{ | |||||
enum Value | |||||
{ | |||||
Disabled, | |||||
Zero, | |||||
One, | |||||
SrcColor, | |||||
OneMinusSrcColor, | |||||
DstColor, | |||||
OneMinusDstColor, | |||||
SrcAlpha, | |||||
OneMinusSrcAlpha, | |||||
DstAlpha, | |||||
OneMinusDstAlpha, | |||||
ConstantColor, | |||||
OneMinusConstantColor, | |||||
ConstantAlpha, | |||||
OneMinusConstantAlpha, | |||||
} | |||||
m_value; | |||||
inline BlendFunc() : m_value(Zero) {} | |||||
inline BlendFunc(Value v) : m_value(v) {} | |||||
inline operator Value() { return m_value; } | |||||
}; | |||||
/* A safe enum to indicate the face culling mode. */ | |||||
struct CullMode | |||||
{ | |||||
enum Value | |||||
{ | |||||
Disabled, | |||||
Clockwise, | |||||
CounterClockwise, | |||||
} | |||||
m_value; | |||||
inline CullMode() : m_value(Disabled) {} | |||||
inline CullMode(Value v) : m_value(v) {} | |||||
inline operator Value() { return m_value; } | |||||
}; | |||||
/* A safe enum to indicate the depth test mode. */ | |||||
struct DepthFunc | |||||
{ | |||||
enum Value | |||||
{ | |||||
Disabled, | |||||
Never, | |||||
Less, | |||||
Equal, | |||||
LessOrEqual, | |||||
Greater, | |||||
NotEqual, | |||||
GreaterOrEqual, | |||||
Always, | |||||
} | |||||
m_value; | |||||
inline DepthFunc() : m_value(Disabled) {} | |||||
inline DepthFunc(Value v) : m_value(v) {} | |||||
inline operator Value() { return m_value; } | |||||
}; | |||||
/* A safe enum to indicate the alpha test mode. */ | |||||
struct AlphaFunc | |||||
{ | |||||
enum Value | |||||
{ | |||||
Disabled, | |||||
Never, | |||||
Less, | |||||
Equal, | |||||
LessOrEqual, | |||||
Greater, | |||||
NotEqual, | |||||
GreaterOrEqual, | |||||
Always, | |||||
} | |||||
m_value; | |||||
inline AlphaFunc() : m_value(Disabled) {} | |||||
inline AlphaFunc(Value v) : m_value(v) {} | |||||
inline operator Value() { return m_value; } | |||||
}; | |||||
class Renderer | |||||
{ | |||||
private: | |||||
/* Only the Video class can create a renderer for now. */ | |||||
friend class Video; | |||||
Renderer(); | |||||
~Renderer(); | |||||
public: | |||||
void SetClearColor(vec4 color); | |||||
vec4 GetClearColor() const; | |||||
void SetClearDepth(float depth); | |||||
float GetClearDepth() const; | |||||
void SetAlphaFunc(AlphaFunc func, float alpha); | |||||
AlphaFunc GetAlphaFunc() const; | |||||
float GetAlphaValue() const; | |||||
void SetBlendFunc(BlendFunc src, BlendFunc dst); | |||||
BlendFunc GetBlendFuncSrc() const; | |||||
BlendFunc GetBlendFuncDst() const; | |||||
void SetDepthFunc(DepthFunc func); | |||||
DepthFunc GetDepthFunc() const; | |||||
void SetFaceCulling(CullMode mode); | |||||
CullMode GetFaceCulling() const; | |||||
private: | |||||
RendererData *m_data; | |||||
}; | |||||
extern Renderer *g_renderer; | |||||
} /* namespace lol */ | |||||
#endif // __LOL_RENDERER_H__ | |||||
@@ -33,7 +33,8 @@ public: | |||||
void SetAlphaFunc(AlphaFunc func, float alpha); | void SetAlphaFunc(AlphaFunc func, float alpha); | ||||
void SetBlendFunc(BlendFunc src, BlendFunc dst); | void SetBlendFunc(BlendFunc src, BlendFunc dst); | ||||
void SetDepthFunc(DepthFunc func); | void SetDepthFunc(DepthFunc func); | ||||
void SetFaceCulling(CullMode mode); | |||||
void SetCullMode(CullMode mode); | |||||
void SetPolygonMode(PolygonMode mode); | |||||
private: | private: | ||||
RenderContextData *m_data; | RenderContextData *m_data; | ||||
@@ -85,6 +85,22 @@ struct CullMode | |||||
inline operator Value() { return m_value; } | inline operator Value() { return m_value; } | ||||
}; | }; | ||||
/* A safe enum to indicate the polygon mode. */ | |||||
struct PolygonMode | |||||
{ | |||||
enum Value | |||||
{ | |||||
Fill, | |||||
Line, | |||||
Point, | |||||
} | |||||
m_value; | |||||
inline PolygonMode() : m_value(Fill) {} | |||||
inline PolygonMode(Value v) : m_value(v) {} | |||||
inline operator Value() { return m_value; } | |||||
}; | |||||
/* A safe enum to indicate the depth test mode. */ | /* A safe enum to indicate the depth test mode. */ | ||||
struct DepthFunc | struct DepthFunc | ||||
{ | { | ||||
@@ -164,8 +180,11 @@ public: | |||||
void SetDepthFunc(DepthFunc func); | void SetDepthFunc(DepthFunc func); | ||||
DepthFunc GetDepthFunc() const; | DepthFunc GetDepthFunc() const; | ||||
void SetFaceCulling(CullMode mode); | |||||
CullMode GetFaceCulling() const; | |||||
void SetCullMode(CullMode mode); | |||||
CullMode GetCullMode() const; | |||||
void SetPolygonMode(PolygonMode mode); | |||||
PolygonMode GetPolygonMode() const; | |||||
private: | private: | ||||
RendererData *m_data; | RendererData *m_data; | ||||
@@ -75,7 +75,7 @@ void Video::SetDebugRenderMode(DebugRenderMode d) | |||||
// SetFaceCulling(false); | // SetFaceCulling(false); | ||||
// else | // else | ||||
// SetFaceCulling(true); | // SetFaceCulling(true); | ||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |||||
#endif | #endif | ||||
break; | break; | ||||
} | } | ||||
@@ -98,7 +98,7 @@ void Video::SetDebugRenderMode(DebugRenderMode d) | |||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
#elif defined HAVE_GLES_2X | #elif defined HAVE_GLES_2X | ||||
#else | #else | ||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | |||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | |||||
#endif | #endif | ||||
break; | break; | ||||
} | } | ||||