]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/opengl/pipelinestate_backend.cpp
Unify handling of shader resources in PipelineState
[libs/gl.git] / source / backends / opengl / pipelinestate_backend.cpp
index 3117a271c405308b8b0a628a9f722e4dd8fcd02f..3b8c6a5ae736c3f33543f9febb1c4b5a17696142 100644 (file)
@@ -105,55 +105,50 @@ void OpenGLPipelineState::apply() const
                }
        }
 
-       if(changes&PipelineState::UNIFORMS)
+       if(changes&PipelineState::RESOURCES)
        {
-               for(const PipelineState::BoundUniformBlock &u: self.uniform_blocks)
-                       if(u.changed || changes==~0U)
+               for(const PipelineState::BoundResource &r: self.resources)
+               {
+                       if(!r.changed && changes!=~0U)
+                               continue;
+
+                       if(r.used)
                        {
-                               if(u.used)
+                               if(r.type==PipelineState::UNIFORM_BLOCK)
                                {
-                                       if(u.binding>=0)
+                                       if(r.binding>=0)
                                        {
-                                               glBindBufferRange(GL_UNIFORM_BUFFER, u.binding, u.buffer->id, u.block->get_offset(), u.block->get_data_size());
-                                               dev_state.bound_uniform_blocks[u.binding] = 1;
+                                               glBindBufferRange(GL_UNIFORM_BUFFER, r.binding, r.buffer->id, r.block->get_offset(), r.block->get_data_size());
+                                               dev_state.bound_uniform_blocks[r.binding] = 1;
                                        }
-                                       else if(u.binding==ReflectData::DEFAULT_BLOCK && self.shprog)
+                                       else if(r.binding==ReflectData::DEFAULT_BLOCK && self.shprog)
                                        {
-                                               const char *data = static_cast<const char *>(u.block->get_data_pointer());
+                                               const char *data = static_cast<const char *>(r.block->get_data_pointer());
                                                for(const Program::UniformCall &call: self.shprog->uniform_calls)
                                                        call.func(call.location, call.size, data+call.location*16);
                                        }
                                }
-
-                               u.changed = false;
-                       }
-       }
-
-       if(changes&PipelineState::TEXTURES)
-       {
-               for(const PipelineState::BoundTexture &t: self.textures)
-                       if(t.changed || changes==~0U)
-                       {
-                               if(t.used)
+                               else if(r.type==PipelineState::TEXTURE)
                                {
                                        if(ARB_direct_state_access)
-                                               glBindTextureUnit(t.binding, t.texture->id);
+                                               glBindTextureUnit(r.binding, r.texture->id);
                                        else
                                        {
-                                               glActiveTexture(GL_TEXTURE0+t.binding);
-                                               if(dev_state.bound_tex_targets[t.binding] && static_cast<int>(t.texture->target)!=dev_state.bound_tex_targets[t.binding])
-                                                       glBindTexture(dev_state.bound_tex_targets[t.binding], 0);
-                                               glBindTexture(t.texture->target, t.texture->id);
+                                               glActiveTexture(GL_TEXTURE0+r.binding);
+                                               if(dev_state.bound_tex_targets[r.binding] && static_cast<int>(r.texture->target)!=dev_state.bound_tex_targets[r.binding])
+                                                       glBindTexture(dev_state.bound_tex_targets[r.binding], 0);
+                                               glBindTexture(r.texture->target, r.texture->id);
                                        }
 
-                                       dev_state.bound_tex_targets[t.binding] = t.texture->target;
+                                       dev_state.bound_tex_targets[r.binding] = r.texture->target;
 
-                                       glBindSampler(t.binding, t.sampler->id);
-                                       t.sampler->refresh();
+                                       glBindSampler(r.binding, r.sampler->id);
+                                       r.sampler->refresh();
                                }
-
-                               t.changed = false;
                        }
+
+                       r.changed = false;
+               }
        }
 
        if(changes&PipelineState::VERTEX_SETUP)