]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/renderer.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / render / renderer.cpp
index f2fb002e73bcbae24ab54f0b7ab16c6b42a6e520..7e010b3f917b0a22a34d5bf1de66a7408e29259e 100644 (file)
@@ -71,7 +71,7 @@ void Renderer::push_state()
 
 void Renderer::pop_state()
 {
-       if(state_stack.size()==1)
+       if(state_stack.size()<=1)
                throw stack_underflow("Renderer::pop_state");
 
        uintptr_t old_pipeline = current_state->pipeline_key;
@@ -181,6 +181,12 @@ void Renderer::set_texture(Tag tag, const Texture *tex, int level, const Sampler
        set_resource(texture_stack, state.texture_count, tag, { tex, samp, level });
 }
 
+void Renderer::set_storage_texture(Tag tag, const Texture *tex)
+{
+       State &state = get_state();
+       set_resource(texture_stack, state.texture_count, tag, { tex, 0, 0 });
+}
+
 template<typename T>
 void Renderer::set_resource(vector<BoundResource<T>> &stack, unsigned &count, Tag tag, const T &res)
 {
@@ -273,38 +279,45 @@ void Renderer::clear(const ClearValue *values)
 void Renderer::draw(const Batch &batch)
 {
        apply_state();
-       batch.refresh(frame_index);
-       PipelineState &ps = get_pipeline_state();
-       ps.set_primitive_type(batch.get_type());
-       commands.use_pipeline(&ps);
+       apply_batch(batch);
        commands.draw(batch);
 }
 
 void Renderer::draw_instanced(const Batch &batch, unsigned count)
 {
        apply_state();
+       apply_batch(batch);
+       commands.draw_instanced(batch, count);
+}
+
+void Renderer::apply_batch(const Batch &batch)
+{
        batch.refresh(frame_index);
        PipelineState &ps = get_pipeline_state();
        ps.set_primitive_type(batch.get_type());
+       if(batch.get_type()==PATCHES)
+               ps.set_patch_size(batch.get_patch_size());
        commands.use_pipeline(&ps);
-       commands.draw_instanced(batch, count);
 }
 
-void Renderer::resolve_multisample(Framebuffer &target)
+void Renderer::dispatch(unsigned count_x, unsigned count_y, unsigned count_z)
+{
+       apply_state();
+       PipelineState &ps = get_pipeline_state();
+       commands.use_pipeline(&ps);
+       commands.dispatch(count_x, count_y, count_z);
+}
+
+void Renderer::resolve_multisample()
 {
        const State &state = get_state();
 
        if(!state.framebuffer)
                throw invalid_operation("Renderer::resolve_multisample");
 
-       unsigned width = state.framebuffer->get_width();
-       unsigned height = state.framebuffer->get_height();
-       if(target.get_width()!=width || target.get_height()!=height)
-               throw incompatible_data("Renderer::resolve_multisample");
-
        apply_framebuffer();
        commands.use_pipeline(&get_pipeline_state());
-       commands.resolve_multisample(target);
+       commands.resolve_multisample();
 }
 
 void Renderer::begin_query(const QueryPool &pool, unsigned index)
@@ -413,7 +426,12 @@ void Renderer::apply_state()
                        if(t.binding<0 || shprog_changed)
                                t.binding = state.shprog->get_uniform_binding(t.tag);
                        if(t.binding>=0)
-                               ps.set_texture(t.binding, t.resource.texture, t.resource.level, t.resource.sampler);
+                       {
+                               if(t.resource.sampler)
+                                       ps.set_texture(t.binding, t.resource.texture, t.resource.level, t.resource.sampler);
+                               else
+                                       ps.set_storage_texture(t.binding, t.resource.texture);
+                       }
                }
 
        static const DepthTest default_depth_test;