]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/renderer.cpp
Initial implementation of Vulkan backend
[libs/gl.git] / source / render / renderer.cpp
index d53d71459304540512362bbc6846c637d6244a1f..5262d09a90ee2862e6c0db07dcd02e71044241fd 100644 (file)
@@ -27,18 +27,19 @@ Renderer::Renderer()
        texture_stack.reserve(32);
 }
 
-Renderer::~Renderer()
-{
-}
-
 void Renderer::begin()
 {
        if(current_state)
                throw invalid_operation("Renderer::begin");
 
-       state_stack.push_back(State());
+       ++frame_index;
+       state_stack.emplace_back();
        current_state = &state_stack.back();
+
+       RendererBackend::begin();
+
        add_shader_data(standard_shdata);
+       commands.begin_frame(frame_index);
 }
 
 void Renderer::end()
@@ -46,12 +47,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()
@@ -95,12 +96,6 @@ void Renderer::set_matrix(const Matrix &matrix)
        changed |= MATRIX;
 }
 
-void Renderer::transform(const Matrix &matrix)
-{
-       get_state().model_matrix *= matrix;
-       changed |= MATRIX;
-}
-
 void Renderer::set_framebuffer(const Framebuffer *f)
 {
        get_state().framebuffer = f;
@@ -170,7 +165,7 @@ void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
                        break;
                }
 
-       texture_stack.push_back(BoundTexture());
+       texture_stack.emplace_back();
        BoundTexture &bound_tex = texture_stack.back();
        bound_tex.tag = tag;
        bound_tex.texture = tex;
@@ -247,6 +242,7 @@ void Renderer::draw(const Batch &batch)
 {
        apply_state();
        batch.refresh();
+       pipeline_state.set_primitive_type(batch.get_type());
        commands.use_pipeline(&pipeline_state);
        commands.draw(batch);
 }
@@ -255,6 +251,7 @@ void Renderer::draw_instanced(const Batch &batch, unsigned count)
 {
        apply_state();
        batch.refresh();
+       pipeline_state.set_primitive_type(batch.get_type());
        commands.use_pipeline(&pipeline_state);
        commands.draw_instanced(batch, count);
 }