From: Mikko Rasa Date: Fri, 12 Nov 2021 19:36:05 +0000 (+0200) Subject: Move a few bits of Renderer into a backend class X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b95aa29809038b39e6729f4e53af0dfb545bfcdc;p=libs%2Fgl.git Move a few bits of Renderer into a backend class This allows the upcoming Vulkan backend to take care of submitting command buffers. --- diff --git a/source/backends/opengl/renderer_backend.cpp b/source/backends/opengl/renderer_backend.cpp new file mode 100644 index 00000000..e49f6ce6 --- /dev/null +++ b/source/backends/opengl/renderer_backend.cpp @@ -0,0 +1,13 @@ +#include "renderer.h" +#include "renderer_backend.h" + +namespace Msp { +namespace GL { + +void OpenGLRenderer::end() +{ + static_cast(this)->commands.use_pipeline(0); +} + +} // namespace GL +} // namespace Msp diff --git a/source/backends/opengl/renderer_backend.h b/source/backends/opengl/renderer_backend.h new file mode 100644 index 00000000..f6f7334b --- /dev/null +++ b/source/backends/opengl/renderer_backend.h @@ -0,0 +1,23 @@ +#ifndef MSP_GL_RENDERER_BACKEND_H_ +#define MSP_GL_RENDERER_BACKEND_H_ + +#include "pipelinestate.h" + +namespace Msp { +namespace GL { + +class OpenGLRenderer +{ +protected: + PipelineState pipeline_state; + + void begin() { } + void end(); +}; + +using RendererBackend = OpenGLRenderer; + +} // namespace GL +} // namespace Msp + +#endif diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 999ff1a2..6c8f1b67 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -38,6 +38,9 @@ void Renderer::begin() state_stack.push_back(State()); current_state = &state_stack.back(); + + RendererBackend::begin(); + add_shader_data(standard_shdata); } @@ -46,12 +49,12 @@ void Renderer::end() if(!current_state || state_stack.size()>1) throw invalid_operation("Renderer::end"); + RendererBackend::end(); + current_state = 0; state_stack.clear(); texture_stack.clear(); shdata_stack.clear(); - - commands.use_pipeline(0); } void Renderer::push_state() diff --git a/source/render/renderer.h b/source/render/renderer.h index 575dbe67..a0b4e75f 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -5,8 +5,8 @@ #include #include "commands.h" #include "matrix.h" -#include "pipelinestate.h" #include "programdata.h" +#include "renderer_backend.h" #include "tag.h" namespace Msp { @@ -39,8 +39,10 @@ Renderables can save the state by pushing it on the stack before beginning their work, and pop it afterwards to restore it without disturbing state set by outer scopes. */ -class Renderer +class Renderer: public RendererBackend { + friend RendererBackend; + public: /** RAII helper class for pushing state on the stack. @@ -104,7 +106,6 @@ private: ProgramData standard_shdata; std::vector shdata_stack; std::vector texture_stack; - PipelineState pipeline_state; Commands commands; public: