]> git.tdb.fi Git - libs/gl.git/commitdiff
Move a few bits of Renderer into a backend class
authorMikko Rasa <tdb@tdb.fi>
Fri, 12 Nov 2021 19:36:05 +0000 (21:36 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 12 Nov 2021 19:36:05 +0000 (21:36 +0200)
This allows the upcoming Vulkan backend to take care of submitting
command buffers.

source/backends/opengl/renderer_backend.cpp [new file with mode: 0644]
source/backends/opengl/renderer_backend.h [new file with mode: 0644]
source/render/renderer.cpp
source/render/renderer.h

diff --git a/source/backends/opengl/renderer_backend.cpp b/source/backends/opengl/renderer_backend.cpp
new file mode 100644 (file)
index 0000000..e49f6ce
--- /dev/null
@@ -0,0 +1,13 @@
+#include "renderer.h"
+#include "renderer_backend.h"
+
+namespace Msp {
+namespace GL {
+
+void OpenGLRenderer::end()
+{
+       static_cast<Renderer *>(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 (file)
index 0000000..f6f7334
--- /dev/null
@@ -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
index 999ff1a22e32bc3bfa6e72d84a88936f6187661d..6c8f1b67b29c0deb30161db2acfb19f6cffb2b79 100644 (file)
@@ -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()
index 575dbe67ee8af1e9adf758c3be0c7ca0caea3045..a0b4e75fdf2ece24b7e082787258b63238080762 100644 (file)
@@ -5,8 +5,8 @@
 #include <vector>
 #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<BoundProgramData> shdata_stack;
        std::vector<BoundTexture> texture_stack;
-       PipelineState pipeline_state;
        Commands commands;
 
 public: