diff --git a/src/gpu/rendercontext.cpp b/src/gpu/rendercontext.cpp index 5f024bad..7976ca5c 100644 --- a/src/gpu/rendercontext.cpp +++ b/src/gpu/rendercontext.cpp @@ -59,6 +59,7 @@ private: TrackedState m_alpha_value; TrackedState m_blend_src, m_blend_dst; TrackedState m_depth_func; + TrackedState m_depth_mask; TrackedState m_cull_mode; TrackedState 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()) diff --git a/src/gpu/renderer.cpp b/src/gpu/renderer.cpp index 085f002d..a1cc7ec1 100644 --- a/src/gpu/renderer.cpp +++ b/src/gpu/renderer.cpp @@ -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 */ diff --git a/src/lol/gpu/rendercontext.h b/src/lol/gpu/rendercontext.h index 7ed9e169..78cb4a66 100644 --- a/src/lol/gpu/rendercontext.h +++ b/src/lol/gpu/rendercontext.h @@ -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(); diff --git a/src/lol/gpu/renderer.h b/src/lol/gpu/renderer.h index 7c428802..72b57661 100644 --- a/src/lol/gpu/renderer.h +++ b/src/lol/gpu/renderer.h @@ -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;