diff --git a/src/gpu/renderer.cpp b/src/gpu/renderer.cpp index 434610e4..95c2f008 100644 --- a/src/gpu/renderer.cpp +++ b/src/gpu/renderer.cpp @@ -130,6 +130,39 @@ Renderer::~Renderer() delete m_data; } +/* + * Buffer clearing + */ + +void Renderer::Clear(ClearMask mask) +{ +#if defined USE_D3D9 || defined _XBOX + int m = 0; + if (mask & ClearMask::Color) + m |= D3DCLEAR_TARGET; + if (mask & ClearMask::Depth) + m |= D3DCLEAR_ZBUFFER; + if (mask & ClearMask::Stencil) + m |= D3DCLEAR_STENCIL; + + vec3 tmp = 255.999f * GetClearColor().rgb; + D3DCOLOR clear_color = D3DCOLOR_XRGB((int)tmp.r, (int)tmp.g, (int)tmp.b); + + if (FAILED(VideoData::d3d_dev->Clear(0, nullptr, m, clear_color, + g_renderer->GetClearDepth(), 0))) + Abort(); +#else + GLbitfield m = 0; + if (mask & ClearMask::Color) + m |= GL_COLOR_BUFFER_BIT; + if (mask & ClearMask::Depth) + m |= GL_DEPTH_BUFFER_BIT; + if (mask & ClearMask::Stencil) + m |= GL_STENCIL_BUFFER_BIT; + glClear(m); +#endif +} + /* * Viewport dimensions */ diff --git a/src/lol/gpu/renderer.h b/src/lol/gpu/renderer.h index 68e69128..5bb2f125 100644 --- a/src/lol/gpu/renderer.h +++ b/src/lol/gpu/renderer.h @@ -21,6 +21,26 @@ namespace lol class RendererData; +/* A list of bitmasks to clear a render buffer. */ +struct ClearMask +{ + enum Value + { + /* Note: D3D9 doesn't appear to support the accumulation buffer, + * and it is a deprecated OpenGL feature. No reason to support it. */ + Color = 1 << 0, + Depth = 1 << 1, + Stencil = 1 << 2, + + All = 0xffffffff + } + m_value; + + inline ClearMask(Value v) : m_value(v) {} + inline ClearMask(uint64_t i) : m_value((Value)i) {} + inline operator Value() { return m_value; } +}; + /* A safe enum to indicate the blending factors. */ struct BlendFunc { @@ -118,6 +138,9 @@ private: Renderer(ivec2 size); ~Renderer(); +public: + void Clear(ClearMask mask); + public: void SetViewport(ibox2 viewport); ibox2 GetViewport() const; diff --git a/src/ticker.cpp b/src/ticker.cpp index 86410be6..8cb23d9b 100644 --- a/src/ticker.cpp +++ b/src/ticker.cpp @@ -387,7 +387,7 @@ void TickerData::DrawThreadTick() { case Entity::DRAWGROUP_BEGIN: Scene::GetDefault()->Reset(); - Video::Clear(ClearMask::All); + g_renderer->Clear(ClearMask::All); break; default: break; diff --git a/src/video.cpp b/src/video.cpp index e2bd8881..3340f353 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -185,36 +185,6 @@ DebugRenderMode Video::GetDebugRenderMode() return VideoData::render_mode; } -void Video::Clear(ClearMask m) -{ -#if defined USE_D3D9 || defined _XBOX - int mask = 0; - if (m & ClearMask::Color) - mask |= D3DCLEAR_TARGET; - if (m & ClearMask::Depth) - mask |= D3DCLEAR_ZBUFFER; - if (m & ClearMask::Stencil) - mask |= D3DCLEAR_STENCIL; - - vec4 tmp = 255.999f * g_renderer->GetClearColor(); - D3DCOLOR clear_color = D3DCOLOR_XRGB((int)tmp.r, (int)tmp.g, (int)tmp.b); - - if (FAILED(VideoData::d3d_dev->Clear(0, nullptr, mask, - clear_color, - g_renderer->GetClearDepth(), 0))) - Abort(); -#else - GLbitfield mask = 0; - if (m & ClearMask::Color) - mask |= GL_COLOR_BUFFER_BIT; - if (m & ClearMask::Depth) - mask |= GL_DEPTH_BUFFER_BIT; - if (m & ClearMask::Stencil) - mask |= GL_STENCIL_BUFFER_BIT; - glClear(mask); -#endif -} - void Video::Destroy() { delete g_renderer; diff --git a/src/video.h b/src/video.h index 846e6a48..e32fc03e 100644 --- a/src/video.h +++ b/src/video.h @@ -22,25 +22,6 @@ namespace lol { -struct ClearMask -{ - enum Value - { - /* Note: D3D9 doesn't appear to support the accumulation buffer, - * and it is a deprecated OpenGL feature. No reason to support it. */ - Color = 1 << 0, - Depth = 1 << 1, - Stencil = 1 << 2, - - All = 0xffffffff - } - m_value; - - inline ClearMask(Value v) : m_value(v) {} - inline ClearMask(uint64_t i) : m_value((Value)i) {} - inline operator Value() { return m_value; } -}; - struct DebugRenderMode { enum Value @@ -68,11 +49,11 @@ public: static void Setup(ivec2 size); static void Destroy(); + static ivec2 GetSize(); + static void SetDebugRenderMode(DebugRenderMode d); static DebugRenderMode GetDebugRenderMode(); - static void Clear(ClearMask m); static void Capture(uint32_t *buffer); - static ivec2 GetSize(); }; } /* namespace lol */ diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index 8390d68f..bc9b65a4 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -472,7 +472,7 @@ public: #else m_meshes[i].m1.Render(m_mat); #endif - Video::Clear(ClearMask::Depth); + g_renderer->Clear(ClearMask::Depth); } } Scene::GetDefault()->GetCamera()->SetProjection(default_proj); diff --git a/tutorial/08_fbo.cpp b/tutorial/08_fbo.cpp index 43201bc2..291021c7 100644 --- a/tutorial/08_fbo.cpp +++ b/tutorial/08_fbo.cpp @@ -78,7 +78,7 @@ public: RenderContext rc; rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); rc.SetClearDepth(1.f); - Video::Clear(ClearMask::Color | ClearMask::Depth); + g_renderer->Clear(ClearMask::Color | ClearMask::Depth); } m_fbo->Unbind(); diff --git a/tutorial/12_voronoi.cpp b/tutorial/12_voronoi.cpp index f4db8326..08548943 100644 --- a/tutorial/12_voronoi.cpp +++ b/tutorial/12_voronoi.cpp @@ -126,7 +126,7 @@ public: RenderContext rc; rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); rc.SetClearDepth(1.f); - Video::Clear(ClearMask::Color | ClearMask::Depth); + g_renderer->Clear(ClearMask::Color | ClearMask::Depth); } m_fbos.Last().m1->Unbind(); } @@ -137,7 +137,7 @@ public: RenderContext rc; rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); rc.SetClearDepth(1.f); - Video::Clear(ClearMask::Color | ClearMask::Depth); + g_renderer->Clear(ClearMask::Color | ClearMask::Depth); } temp_buffer->Unbind(); @@ -198,7 +198,7 @@ public: RenderContext rc; rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); rc.SetClearDepth(1.f); - Video::Clear(ClearMask::Color | ClearMask::Depth); + g_renderer->Clear(ClearMask::Color | ClearMask::Depth); } temp_buffer->Unbind(); @@ -228,7 +228,7 @@ public: RenderContext rc; rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); rc.SetClearDepth(1.f); - Video::Clear(ClearMask::Color | ClearMask::Depth); + g_renderer->Clear(ClearMask::Color | ClearMask::Depth); } m_fbos[f].m1->Unbind(); @@ -251,7 +251,7 @@ public: dst_buf->Bind(); /* FIXME: we should just disable depth test in the shader */ - Video::Clear(ClearMask::Depth); + g_renderer->Clear(ClearMask::Depth); m_fbos[f].m2->Bind(); int i = 0; @@ -270,7 +270,7 @@ public: } } - Video::Clear(ClearMask::Color | ClearMask::Depth); + g_renderer->Clear(ClearMask::Color | ClearMask::Depth); //FRAME BUFFER DRAW m_timer -= seconds; @@ -282,7 +282,7 @@ public: RenderContext rc; rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); rc.SetClearDepth(1.f); - Video::Clear(ClearMask::Color | ClearMask::Depth); + g_renderer->Clear(ClearMask::Color | ClearMask::Depth); } m_fbos[m_cur_fbo].m1->Unbind(); @@ -313,7 +313,7 @@ public: dst_buf->Bind(); /* FIXME: we should just disable depth test in the shader */ - Video::Clear(ClearMask::Depth); + g_renderer->Clear(ClearMask::Depth); shader->Bind(); //08_FBO ??