| @@ -130,6 +130,39 @@ Renderer::~Renderer() | |||||
| delete m_data; | 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 | * Viewport dimensions | ||||
| */ | */ | ||||
| @@ -21,6 +21,26 @@ namespace lol | |||||
| class RendererData; | 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. */ | /* A safe enum to indicate the blending factors. */ | ||||
| struct BlendFunc | struct BlendFunc | ||||
| { | { | ||||
| @@ -118,6 +138,9 @@ private: | |||||
| Renderer(ivec2 size); | Renderer(ivec2 size); | ||||
| ~Renderer(); | ~Renderer(); | ||||
| public: | |||||
| void Clear(ClearMask mask); | |||||
| public: | public: | ||||
| void SetViewport(ibox2 viewport); | void SetViewport(ibox2 viewport); | ||||
| ibox2 GetViewport() const; | ibox2 GetViewport() const; | ||||
| @@ -387,7 +387,7 @@ void TickerData::DrawThreadTick() | |||||
| { | { | ||||
| case Entity::DRAWGROUP_BEGIN: | case Entity::DRAWGROUP_BEGIN: | ||||
| Scene::GetDefault()->Reset(); | Scene::GetDefault()->Reset(); | ||||
| Video::Clear(ClearMask::All); | |||||
| g_renderer->Clear(ClearMask::All); | |||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| @@ -185,36 +185,6 @@ DebugRenderMode Video::GetDebugRenderMode() | |||||
| return VideoData::render_mode; | 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() | void Video::Destroy() | ||||
| { | { | ||||
| delete g_renderer; | delete g_renderer; | ||||
| @@ -22,25 +22,6 @@ | |||||
| namespace lol | 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 | struct DebugRenderMode | ||||
| { | { | ||||
| enum Value | enum Value | ||||
| @@ -68,11 +49,11 @@ public: | |||||
| static void Setup(ivec2 size); | static void Setup(ivec2 size); | ||||
| static void Destroy(); | static void Destroy(); | ||||
| static ivec2 GetSize(); | |||||
| static void SetDebugRenderMode(DebugRenderMode d); | static void SetDebugRenderMode(DebugRenderMode d); | ||||
| static DebugRenderMode GetDebugRenderMode(); | static DebugRenderMode GetDebugRenderMode(); | ||||
| static void Clear(ClearMask m); | |||||
| static void Capture(uint32_t *buffer); | static void Capture(uint32_t *buffer); | ||||
| static ivec2 GetSize(); | |||||
| }; | }; | ||||
| } /* namespace lol */ | } /* namespace lol */ | ||||
| @@ -472,7 +472,7 @@ public: | |||||
| #else | #else | ||||
| m_meshes[i].m1.Render(m_mat); | m_meshes[i].m1.Render(m_mat); | ||||
| #endif | #endif | ||||
| Video::Clear(ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Depth); | |||||
| } | } | ||||
| } | } | ||||
| Scene::GetDefault()->GetCamera()->SetProjection(default_proj); | Scene::GetDefault()->GetCamera()->SetProjection(default_proj); | ||||
| @@ -78,7 +78,7 @@ public: | |||||
| RenderContext rc; | RenderContext rc; | ||||
| rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | ||||
| rc.SetClearDepth(1.f); | rc.SetClearDepth(1.f); | ||||
| Video::Clear(ClearMask::Color | ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||||
| } | } | ||||
| m_fbo->Unbind(); | m_fbo->Unbind(); | ||||
| @@ -126,7 +126,7 @@ public: | |||||
| RenderContext rc; | RenderContext rc; | ||||
| rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | ||||
| rc.SetClearDepth(1.f); | rc.SetClearDepth(1.f); | ||||
| Video::Clear(ClearMask::Color | ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||||
| } | } | ||||
| m_fbos.Last().m1->Unbind(); | m_fbos.Last().m1->Unbind(); | ||||
| } | } | ||||
| @@ -137,7 +137,7 @@ public: | |||||
| RenderContext rc; | RenderContext rc; | ||||
| rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | ||||
| rc.SetClearDepth(1.f); | rc.SetClearDepth(1.f); | ||||
| Video::Clear(ClearMask::Color | ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||||
| } | } | ||||
| temp_buffer->Unbind(); | temp_buffer->Unbind(); | ||||
| @@ -198,7 +198,7 @@ public: | |||||
| RenderContext rc; | RenderContext rc; | ||||
| rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | ||||
| rc.SetClearDepth(1.f); | rc.SetClearDepth(1.f); | ||||
| Video::Clear(ClearMask::Color | ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||||
| } | } | ||||
| temp_buffer->Unbind(); | temp_buffer->Unbind(); | ||||
| @@ -228,7 +228,7 @@ public: | |||||
| RenderContext rc; | RenderContext rc; | ||||
| rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | ||||
| rc.SetClearDepth(1.f); | rc.SetClearDepth(1.f); | ||||
| Video::Clear(ClearMask::Color | ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||||
| } | } | ||||
| m_fbos[f].m1->Unbind(); | m_fbos[f].m1->Unbind(); | ||||
| @@ -251,7 +251,7 @@ public: | |||||
| dst_buf->Bind(); | dst_buf->Bind(); | ||||
| /* FIXME: we should just disable depth test in the shader */ | /* FIXME: we should just disable depth test in the shader */ | ||||
| Video::Clear(ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Depth); | |||||
| m_fbos[f].m2->Bind(); | m_fbos[f].m2->Bind(); | ||||
| int i = 0; | int i = 0; | ||||
| @@ -270,7 +270,7 @@ public: | |||||
| } | } | ||||
| } | } | ||||
| Video::Clear(ClearMask::Color | ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||||
| //FRAME BUFFER DRAW | //FRAME BUFFER DRAW | ||||
| m_timer -= seconds; | m_timer -= seconds; | ||||
| @@ -282,7 +282,7 @@ public: | |||||
| RenderContext rc; | RenderContext rc; | ||||
| rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); | ||||
| rc.SetClearDepth(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(); | m_fbos[m_cur_fbo].m1->Unbind(); | ||||
| @@ -313,7 +313,7 @@ public: | |||||
| dst_buf->Bind(); | dst_buf->Bind(); | ||||
| /* FIXME: we should just disable depth test in the shader */ | /* FIXME: we should just disable depth test in the shader */ | ||||
| Video::Clear(ClearMask::Depth); | |||||
| g_renderer->Clear(ClearMask::Depth); | |||||
| shader->Bind(); | shader->Bind(); | ||||
| //08_FBO ?? | //08_FBO ?? | ||||