diff --git a/doc/tutorial/08_fbo.cpp b/doc/tutorial/08_fbo.cpp index 61cecd0a..cccf9a6d 100644 --- a/doc/tutorial/08_fbo.cpp +++ b/doc/tutorial/08_fbo.cpp @@ -78,9 +78,9 @@ public: m_fbo->Bind(); { - RenderContext rc(scene.get_renderer()); - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + render_context rc(scene.get_renderer()); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); } @@ -92,8 +92,8 @@ public: } /* FIXME: we should just disable depth test in the shader */ - RenderContext rc(scene.get_renderer()); - rc.SetDepthFunc(DepthFunc::Disabled); + render_context rc(scene.get_renderer()); + rc.depth_func(DepthFunc::Disabled); /* FIXME: this no longer works because we don’t restore the * actually bound framebuffer. */ diff --git a/doc/tutorial/12_voronoi.cpp b/doc/tutorial/12_voronoi.cpp index b45c8012..9fa13916 100644 --- a/doc/tutorial/12_voronoi.cpp +++ b/doc/tutorial/12_voronoi.cpp @@ -146,9 +146,9 @@ public: m_fbos.last().m1->Bind(); { - RenderContext rc(scene.get_renderer()); - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + render_context rc(scene.get_renderer()); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); } m_fbos.last().m1->Unbind(); @@ -157,9 +157,9 @@ public: temp_buffer = std::make_shared(Video::GetSize()); temp_buffer->Bind(); { - RenderContext rc(scene.get_renderer()); - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + render_context rc(scene.get_renderer()); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); } temp_buffer->Unbind(); @@ -221,9 +221,9 @@ public: temp_buffer->Bind(); { - RenderContext rc(scene.get_renderer()); - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + render_context rc(scene.get_renderer()); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); } temp_buffer->Unbind(); @@ -251,9 +251,9 @@ public: m_fbos[f].m1->Bind(); { - RenderContext rc(scene.get_renderer()); - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + render_context rc(scene.get_renderer()); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); } m_fbos[f].m1->Unbind(); @@ -304,9 +304,9 @@ public: //m_timer = 1.0f; m_fbos[m_cur_fbo].m1->Bind(); { - RenderContext rc(scene.get_renderer()); - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + render_context rc(scene.get_renderer()); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); } m_fbos[m_cur_fbo].m1->Unbind(); diff --git a/src/gpu/rendercontext.cpp b/src/gpu/rendercontext.cpp index 040b097b..b4d8618d 100644 --- a/src/gpu/rendercontext.cpp +++ b/src/gpu/rendercontext.cpp @@ -47,7 +47,7 @@ private: class RenderContextData { - friend class RenderContext; + friend class render_context; private: tracked_var m_viewport; @@ -66,16 +66,16 @@ private: }; /* - * Public RenderContext class + * Public render_context class */ -RenderContext::RenderContext(std::shared_ptr renderer) +render_context::render_context(std::shared_ptr renderer) : m_renderer(renderer), m_data(std::make_unique()) { } -RenderContext::~RenderContext() +render_context::~render_context() { if (m_data->m_viewport.is_dirty()) m_renderer->SetViewport(m_data->m_viewport.get()); @@ -110,7 +110,7 @@ RenderContext::~RenderContext() m_renderer->SetScissorMode(m_data->m_scissor_mode.get()); } -void RenderContext::SetViewport(ibox2 viewport) +void render_context::viewport(ibox2 viewport) { if (!m_data->m_viewport.is_dirty()) m_data->m_viewport.set(m_renderer->GetViewport()); @@ -118,12 +118,12 @@ void RenderContext::SetViewport(ibox2 viewport) m_renderer->SetViewport(viewport); } -ibox2 RenderContext::GetViewport() +ibox2 render_context::viewport() { return m_renderer->GetViewport(); } -void RenderContext::SetClearColor(vec4 color) +void render_context::clear_color(vec4 color) { if (!m_data->m_clear_color.is_dirty()) m_data->m_clear_color.set(m_renderer->GetClearColor()); @@ -131,12 +131,12 @@ void RenderContext::SetClearColor(vec4 color) m_renderer->SetClearColor(color); } -vec4 RenderContext::GetClearColor() +vec4 render_context::clear_color() { return m_renderer->GetClearColor(); } -void RenderContext::SetClearDepth(float depth) +void render_context::clear_depth(float depth) { if (!m_data->m_clear_depth.is_dirty()) m_data->m_clear_depth.set(m_renderer->GetClearDepth()); @@ -144,12 +144,12 @@ void RenderContext::SetClearDepth(float depth) m_renderer->SetClearDepth(depth); } -float RenderContext::GetClearDepth() +float render_context::clear_depth() { return m_renderer->GetClearDepth(); } -void RenderContext::SetAlphaFunc(AlphaFunc func, float alpha) +void render_context::alpha_func(AlphaFunc func, float alpha) { if (!m_data->m_alpha_func.is_dirty()) m_data->m_alpha_func.set(m_renderer->GetAlphaFunc()); @@ -159,17 +159,17 @@ void RenderContext::SetAlphaFunc(AlphaFunc func, float alpha) m_renderer->SetAlphaFunc(func, alpha); } -AlphaFunc RenderContext::GetAlphaFunc() +AlphaFunc render_context::alpha_func() { return m_renderer->GetAlphaFunc(); } -float RenderContext::GetAlphaValue() +float render_context::alpha_value() { return m_renderer->GetAlphaValue(); } -void RenderContext::SetBlendEquation(BlendEquation rgb, BlendEquation alpha) +void render_context::blend_equation(BlendEquation rgb, BlendEquation alpha) { if (!m_data->m_blend_rgb.is_dirty()) m_data->m_blend_rgb.set(m_renderer->GetBlendEquationRgb()); @@ -179,17 +179,17 @@ void RenderContext::SetBlendEquation(BlendEquation rgb, BlendEquation alpha) m_renderer->SetBlendEquation(rgb, alpha); } -BlendEquation RenderContext::GetBlendEquationRgb() +BlendEquation render_context::blend_equation_rgb() { return m_renderer->GetBlendEquationRgb(); } -BlendEquation RenderContext::GetBlendEquationAlpha() +BlendEquation render_context::blend_equation_alpha() { return m_renderer->GetBlendEquationAlpha(); } -void RenderContext::SetBlendFunc(BlendFunc src, BlendFunc dst) +void render_context::blend_func(BlendFunc src, BlendFunc dst) { if (!m_data->m_blend_src.is_dirty()) m_data->m_blend_src.set(m_renderer->GetBlendFuncSrc()); @@ -199,17 +199,17 @@ void RenderContext::SetBlendFunc(BlendFunc src, BlendFunc dst) m_renderer->SetBlendFunc(src, dst); } -BlendFunc RenderContext::GetBlendFuncSrc() +BlendFunc render_context::blend_func_src() { return m_renderer->GetBlendFuncSrc(); } -BlendFunc RenderContext::GetBlendFuncDst() +BlendFunc render_context::blend_func_dst() { return m_renderer->GetBlendFuncDst(); } -void RenderContext::SetDepthFunc(DepthFunc func) +void render_context::depth_func(DepthFunc func) { if (!m_data->m_depth_func.is_dirty()) m_data->m_depth_func.set(m_renderer->GetDepthFunc()); @@ -217,12 +217,12 @@ void RenderContext::SetDepthFunc(DepthFunc func) m_renderer->SetDepthFunc(func); } -DepthFunc RenderContext::GetDepthFunc() +DepthFunc render_context::depth_func() { return m_renderer->GetDepthFunc(); } -void RenderContext::SetDepthMask(DepthMask mask) +void render_context::depth_mask(DepthMask mask) { if (!m_data->m_depth_mask.is_dirty()) m_data->m_depth_mask.set(m_renderer->GetDepthMask()); @@ -230,12 +230,12 @@ void RenderContext::SetDepthMask(DepthMask mask) m_renderer->SetDepthMask(mask); } -DepthMask RenderContext::GetDepthMask() +DepthMask render_context::depth_mask() { return m_renderer->GetDepthMask(); } -void RenderContext::SetCullMode(CullMode mode) +void render_context::cull_mode(CullMode mode) { if (!m_data->m_cull_mode.is_dirty()) m_data->m_cull_mode.set(m_renderer->GetCullMode()); @@ -243,12 +243,12 @@ void RenderContext::SetCullMode(CullMode mode) m_renderer->SetCullMode(mode); } -CullMode RenderContext::GetCullMode() +CullMode render_context::cull_mode() { return m_renderer->GetCullMode(); } -void RenderContext::SetPolygonMode(PolygonMode mode) +void render_context::polygon_mode(PolygonMode mode) { if (!m_data->m_polygon_mode.is_dirty()) m_data->m_polygon_mode.set(m_renderer->GetPolygonMode()); @@ -256,12 +256,12 @@ void RenderContext::SetPolygonMode(PolygonMode mode) m_renderer->SetPolygonMode(mode); } -PolygonMode RenderContext::GetPolygonMode() +PolygonMode render_context::polygon_mode() { return m_renderer->GetPolygonMode(); } -void RenderContext::SetScissorMode(ScissorMode mode) +void render_context::scissor_mode(ScissorMode mode) { if (!m_data->m_scissor_mode.is_dirty()) m_data->m_scissor_mode.set(m_renderer->GetScissorMode()); @@ -269,7 +269,7 @@ void RenderContext::SetScissorMode(ScissorMode mode) m_renderer->SetScissorMode(mode); } -void RenderContext::SetScissorRect(vec4 rect) +void render_context::scissor_rect(vec4 rect) { if (!m_data->m_scissor_rect.is_dirty()) m_data->m_scissor_rect.set(m_renderer->GetScissorRect()); @@ -277,12 +277,12 @@ void RenderContext::SetScissorRect(vec4 rect) m_renderer->SetScissorRect(rect); } -ScissorMode RenderContext::GetScissorMode() +ScissorMode render_context::scissor_mode() { return m_renderer->GetScissorMode(); } -vec4 RenderContext::GetScissorRect() +vec4 render_context::scissor_rect() { return m_renderer->GetScissorRect(); } diff --git a/src/lol/gpu/rendercontext.h b/src/lol/gpu/rendercontext.h index 132f11c2..4fe308c3 100644 --- a/src/lol/gpu/rendercontext.h +++ b/src/lol/gpu/rendercontext.h @@ -26,40 +26,40 @@ namespace lol class RenderContextData; -class RenderContext +class render_context { public: - RenderContext(std::shared_ptr renderer); - ~RenderContext(); + render_context(std::shared_ptr renderer); + ~render_context(); - void SetViewport(ibox2 viewport); - void SetClearColor(vec4 color); - void SetClearDepth(float depth); - void SetAlphaFunc(AlphaFunc func, float alpha); - void SetBlendEquation(BlendEquation rgb, BlendEquation alpha); - void SetBlendFunc(BlendFunc src, BlendFunc dst); - void SetDepthFunc(DepthFunc func); - void SetDepthMask(DepthMask mask); - void SetCullMode(CullMode mode); - void SetPolygonMode(PolygonMode mode); - void SetScissorMode(ScissorMode mode); - void SetScissorRect(vec4 rect); + void viewport(ibox2 viewport); + void clear_color(vec4 color); + void clear_depth(float depth); + void alpha_func(AlphaFunc func, float alpha); + void blend_equation(BlendEquation rgb, BlendEquation alpha); + void blend_func(BlendFunc src, BlendFunc dst); + void depth_func(DepthFunc func); + void depth_mask(DepthMask mask); + void cull_mode(CullMode mode); + void polygon_mode(PolygonMode mode); + void scissor_mode(ScissorMode mode); + void scissor_rect(vec4 rect); - ibox2 GetViewport(); - vec4 GetClearColor(); - float GetClearDepth(); - AlphaFunc GetAlphaFunc(); - float GetAlphaValue(); - BlendEquation GetBlendEquationRgb(); - BlendEquation GetBlendEquationAlpha(); - BlendFunc GetBlendFuncSrc(); - BlendFunc GetBlendFuncDst(); - DepthFunc GetDepthFunc(); - DepthMask GetDepthMask(); - CullMode GetCullMode(); - PolygonMode GetPolygonMode(); - ScissorMode GetScissorMode(); - vec4 GetScissorRect(); + ibox2 viewport(); + vec4 clear_color(); + float clear_depth(); + AlphaFunc alpha_func(); + float alpha_value(); + BlendEquation blend_equation_rgb(); + BlendEquation blend_equation_alpha(); + BlendFunc blend_func_src(); + BlendFunc blend_func_dst(); + DepthFunc depth_func(); + DepthMask depth_mask(); + CullMode cull_mode(); + PolygonMode polygon_mode(); + ScissorMode scissor_mode(); + vec4 scissor_rect(); private: std::shared_ptr m_renderer; diff --git a/src/lolimgui.cpp b/src/lolimgui.cpp index 2f5ab5ce..a69610b1 100644 --- a/src/lolimgui.cpp +++ b/src/lolimgui.cpp @@ -361,10 +361,10 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) if (!m_shader) return; - RenderContext rc(Scene::GetScene(0).get_renderer()); - rc.SetCullMode(CullMode::Disabled); - rc.SetDepthFunc(DepthFunc::Disabled); - rc.SetScissorMode(ScissorMode::Enabled); + render_context rc(Scene::GetScene(0).get_renderer()); + rc.cull_mode(CullMode::Disabled); + rc.depth_func(DepthFunc::Disabled); + rc.scissor_mode(ScissorMode::Enabled); m_shader->Bind(); @@ -407,7 +407,7 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) m_shader->SetUniform(m_texture, texture->GetTextureUniform(), 0); } - rc.SetScissorRect(command.ClipRect); + rc.scissor_rect(command.ClipRect); #ifdef SHOW_IMGUI_DEBUG //----------------------------------------------------------------- diff --git a/src/scene.cpp b/src/scene.cpp index 9fcb0489..79cb1bc7 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -143,7 +143,7 @@ private: SceneDisplay* m_display = nullptr; /** Render buffers: where to render to. */ - Framebuffer *m_renderbuffer[4]; + std::shared_ptr m_renderbuffer[4]; struct postprocess { @@ -210,10 +210,8 @@ Scene::Scene(ivec2 size) data(std::make_unique()), m_renderer(std::make_shared(size)) { - data->m_renderbuffer[0] = new Framebuffer(m_size); - data->m_renderbuffer[1] = new Framebuffer(m_size); - data->m_renderbuffer[2] = new Framebuffer(m_size); - data->m_renderbuffer[3] = new Framebuffer(m_size); + for (int i = 0; i < 4; ++i) + data->m_renderbuffer[i] = std::make_shared(m_size); data->m_pp.m_shader[0] = Shader::Create(LOLFX_RESOURCE_NAME(gpu_blit)); data->m_pp.m_shader[1] = Shader::Create(LOLFX_RESOURCE_NAME(gpu_postprocess)); data->m_pp.m_coord[0] = data->m_pp.m_shader[0]->GetAttribLocation(VertexUsage::Position, 0); @@ -579,14 +577,8 @@ void Scene::pre_render(float) if (m_size != m_wanted_size) { m_size = m_wanted_size; - delete data->m_renderbuffer[0]; - delete data->m_renderbuffer[1]; - delete data->m_renderbuffer[2]; - delete data->m_renderbuffer[3]; - data->m_renderbuffer[0] = new Framebuffer(m_size); - data->m_renderbuffer[1] = new Framebuffer(m_size); - data->m_renderbuffer[2] = new Framebuffer(m_size); - data->m_renderbuffer[3] = new Framebuffer(m_size); + for (int i = 0; i < 4; ++i) + data->m_renderbuffer[i] = std::make_shared(m_size); mat4 proj = mat4::ortho(0.f, (float)m_size.x, 0.f, (float)m_size.y, -1000.f, 1000.f); data->m_default_cam->SetProjection(proj); @@ -599,11 +591,11 @@ void Scene::pre_render(float) } { - RenderContext rc(m_renderer); + render_context rc(m_renderer); if (do_pp) { - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); } m_renderer->Clear(ClearMask::Color | ClearMask::Depth); @@ -633,9 +625,9 @@ void Scene::post_render(float) data->m_renderbuffer[3]->Bind(); - RenderContext rc(m_renderer); - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + render_context rc(m_renderer); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); m_renderer->Clear(ClearMask::Color | ClearMask::Depth); /* Execute post process */ @@ -657,9 +649,9 @@ void Scene::post_render(float) data->m_pp.m_shader[0]->Bind(); - RenderContext rc(m_renderer); - rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f)); - rc.SetClearDepth(1.f); + render_context rc(m_renderer); + rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); + rc.clear_depth(1.f); m_renderer->Clear(ClearMask::Color | ClearMask::Depth); /* Blit final image to screen */ @@ -687,9 +679,9 @@ void Scene::render_primitives() ASSERT(!!data, "Trying to access a non-ready scene"); /* FIXME: Temp fix for mesh having no render context*/ - RenderContext rc(m_renderer); - rc.SetCullMode(CullMode::Clockwise); - rc.SetDepthFunc(DepthFunc::LessOrEqual); + render_context rc(m_renderer); + rc.cull_mode(CullMode::Clockwise); + rc.depth_func(DepthFunc::LessOrEqual); /* new scenegraph */ for (uintptr_t key : keys(data->m_prim_renderers)) @@ -708,7 +700,7 @@ void Scene::render_tiles() // XXX: rename to Blit() { ASSERT(!!data, "Trying to access a non-ready scene"); - RenderContext rc(m_renderer); + render_context rc(m_renderer); /* Early test if nothing needs to be rendered */ if (!data->m_tile_api.m_tiles.count() && !data->m_tile_api.m_palettes.count()) @@ -716,12 +708,12 @@ void Scene::render_tiles() // XXX: rename to Blit() /* FIXME: we disable culling for now because we don’t have a reliable * way to know which side is facing the camera. */ - rc.SetCullMode(CullMode::Disabled); + rc.cull_mode(CullMode::Disabled); - rc.SetDepthFunc(DepthFunc::LessOrEqual); - rc.SetBlendFunc(BlendFunc::SrcAlpha, BlendFunc::OneMinusSrcAlpha); - rc.SetBlendEquation(BlendEquation::Add, BlendEquation::Max); - rc.SetAlphaFunc(AlphaFunc::GreaterOrEqual, 0.01f); + rc.depth_func(DepthFunc::LessOrEqual); + rc.blend_func(BlendFunc::SrcAlpha, BlendFunc::OneMinusSrcAlpha); + rc.blend_equation(BlendEquation::Add, BlendEquation::Max); + rc.alpha_func(AlphaFunc::GreaterOrEqual, 0.01f); #if (defined LOL_USE_GLEW || defined HAVE_GL_2X) && !defined HAVE_GLES_2X glEnable(GL_TEXTURE_2D); @@ -832,15 +824,15 @@ void Scene::render_lines(float seconds) { ASSERT(!!data, "Trying to access a non-ready scene"); - RenderContext rc(m_renderer); + render_context rc(m_renderer); if (!data->m_line_api.m_lines.count()) return; - rc.SetDepthFunc(DepthFunc::LessOrEqual); - rc.SetBlendFunc(BlendFunc::SrcAlpha, BlendFunc::OneMinusSrcAlpha); - rc.SetBlendEquation(BlendEquation::Add, BlendEquation::Max); - rc.SetAlphaFunc(AlphaFunc::GreaterOrEqual, 0.01f); + rc.depth_func(DepthFunc::LessOrEqual); + rc.blend_func(BlendFunc::SrcAlpha, BlendFunc::OneMinusSrcAlpha); + rc.blend_equation(BlendEquation::Add, BlendEquation::Max); + rc.alpha_func(AlphaFunc::GreaterOrEqual, 0.01f); int linecount = (int)data->m_line_api.m_lines.count();