| @@ -59,6 +59,7 @@ private: | |||
| TrackedState<float> m_alpha_value; | |||
| TrackedState<BlendFunc> m_blend_src, m_blend_dst; | |||
| TrackedState<DepthFunc> m_depth_func; | |||
| TrackedState<DepthMask> m_depth_mask; | |||
| TrackedState<CullMode> m_cull_mode; | |||
| TrackedState<PolygonMode> m_polygon_mode; | |||
| }; | |||
| @@ -94,6 +95,9 @@ RenderContext::~RenderContext() | |||
| if (m_data->m_depth_func.HasChanged()) | |||
| g_renderer->SetDepthFunc(m_data->m_depth_func.GetValue()); | |||
| if (m_data->m_depth_mask.HasChanged()) | |||
| g_renderer->SetDepthMask(m_data->m_depth_mask.GetValue()); | |||
| if (m_data->m_cull_mode.HasChanged()) | |||
| g_renderer->SetCullMode(m_data->m_cull_mode.GetValue()); | |||
| @@ -110,6 +114,7 @@ void RenderContext::SetViewport(ibox2 viewport) | |||
| g_renderer->SetViewport(viewport); | |||
| } | |||
| ibox2 RenderContext::GetViewport() | |||
| { | |||
| return g_renderer->GetViewport(); | |||
| @@ -194,6 +199,19 @@ DepthFunc RenderContext::GetDepthFunc() | |||
| return g_renderer->GetDepthFunc(); | |||
| } | |||
| void RenderContext::SetDepthMask(DepthMask mask) | |||
| { | |||
| if (!m_data->m_depth_mask.HasChanged()) | |||
| m_data->m_depth_mask.TrackValue(g_renderer->GetDepthMask()); | |||
| g_renderer->SetDepthMask(mask); | |||
| } | |||
| DepthMask RenderContext::GetDepthMask() | |||
| { | |||
| return g_renderer->GetDepthMask(); | |||
| } | |||
| void RenderContext::SetCullMode(CullMode mode) | |||
| { | |||
| if (!m_data->m_cull_mode.HasChanged()) | |||
| @@ -63,6 +63,7 @@ private: | |||
| float m_alpha_value; | |||
| BlendFunc m_blend_src, m_blend_dst; | |||
| DepthFunc m_depth_func; | |||
| DepthMask m_depth_mask; | |||
| CullMode m_cull_mode; | |||
| PolygonMode m_polygon_mode; | |||
| @@ -156,6 +157,9 @@ Renderer::Renderer(ivec2 size) | |||
| m_data->m_depth_func = DepthFunc::Disabled; | |||
| SetDepthFunc(DepthFunc::LessOrEqual); | |||
| m_data->m_depth_mask = DepthMask::Disabled; | |||
| SetDepthMask(DepthMask::Enabled); | |||
| m_data->m_cull_mode = CullMode::Disabled; | |||
| SetCullMode(CullMode::Clockwise); | |||
| @@ -600,6 +604,35 @@ DepthFunc Renderer::GetDepthFunc() const | |||
| return m_data->m_depth_func; | |||
| } | |||
| /* | |||
| * Depth mask | |||
| */ | |||
| void Renderer::SetDepthMask(DepthMask mask) | |||
| { | |||
| if (m_data->m_depth_mask == mask) | |||
| return; | |||
| #if defined USE_D3D9 || defined _XBOX | |||
| if (mask == DepthMask::Disabled) | |||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZWRITEENABLE, D3DZB_FALSE); | |||
| else | |||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZWRITEENABLE, D3DZB_TRUE); | |||
| #else | |||
| if (mask == DepthMask::Disabled) | |||
| glDepthMask(GL_FALSE); | |||
| else | |||
| glDepthMask(GL_TRUE); | |||
| #endif | |||
| m_data->m_depth_mask = mask; | |||
| } | |||
| DepthMask Renderer::GetDepthMask() const | |||
| { | |||
| return m_data->m_depth_mask; | |||
| } | |||
| /* | |||
| * Face culling | |||
| */ | |||
| @@ -33,6 +33,7 @@ public: | |||
| void SetAlphaFunc(AlphaFunc func, float alpha); | |||
| void SetBlendFunc(BlendFunc src, BlendFunc dst); | |||
| void SetDepthFunc(DepthFunc func); | |||
| void SetDepthMask(DepthMask mask); | |||
| void SetCullMode(CullMode mode); | |||
| void SetPolygonMode(PolygonMode mode); | |||
| @@ -44,6 +45,7 @@ public: | |||
| BlendFunc GetBlendFuncSrc(); | |||
| BlendFunc GetBlendFuncDst(); | |||
| DepthFunc GetDepthFunc(); | |||
| DepthMask GetDepthMask(); | |||
| CullMode GetCullMode(); | |||
| PolygonMode GetPolygonMode(); | |||
| @@ -123,6 +123,21 @@ struct DepthFunc | |||
| inline operator Value() { return m_value; } | |||
| }; | |||
| /* A safe enum to indicate the depth mask. */ | |||
| struct DepthMask | |||
| { | |||
| enum Value | |||
| { | |||
| Disabled, | |||
| Enabled, | |||
| } | |||
| m_value; | |||
| inline DepthMask() : m_value(Disabled) {} | |||
| inline DepthMask(Value v) : m_value(v) {} | |||
| inline operator Value() { return m_value; } | |||
| }; | |||
| /* A safe enum to indicate the alpha test mode. */ | |||
| struct AlphaFunc | |||
| { | |||
| @@ -180,6 +195,9 @@ public: | |||
| void SetDepthFunc(DepthFunc func); | |||
| DepthFunc GetDepthFunc() const; | |||
| void SetDepthMask(DepthMask mask); | |||
| DepthMask GetDepthMask() const; | |||
| void SetCullMode(CullMode mode); | |||
| CullMode GetCullMode() const; | |||