]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/renderer.cpp
InstanceArray doesn't need to refresh the vertex arrays
[libs/gl.git] / source / render / renderer.cpp
index 45ad120045397de5848e4cecfe1968f39e83433b..946f0100bbbf0a5467877e451343d643a0f13670 100644 (file)
@@ -32,12 +32,14 @@ void Renderer::begin()
        if(current_state)
                throw invalid_operation("Renderer::begin");
 
+       ++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()
@@ -137,6 +139,11 @@ void Renderer::add_shader_data(const ProgramData &d)
 }
 
 void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
+{
+       set_texture(tag, tex, -1, samp);
+}
+
+void Renderer::set_texture(Tag tag, const Texture *tex, int level, const Sampler *samp)
 {
        State &state = get_state();
 
@@ -168,6 +175,7 @@ void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
        bound_tex.tag = tag;
        bound_tex.texture = tex;
        bound_tex.sampler = samp;
+       bound_tex.level = level;
        state.texture_count = texture_stack.size();
 }
 
@@ -240,6 +248,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);
 }
@@ -248,6 +257,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);
 }
@@ -340,7 +350,7 @@ void Renderer::apply_state()
                        if(t.binding<0 || shprog_changed)
                                t.binding = state.shprog->get_uniform_binding(t.tag);
                        if(t.binding>=0)
-                               pipeline_state.set_texture(t.binding, t.texture, t.sampler);
+                               pipeline_state.set_texture(t.binding, t.texture, t.level, t.sampler);
                }
 
        pipeline_state.set_depth_test(state.depth_test);