]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/pipelinestate.cpp
Unify handling of shader resources in PipelineState
[libs/gl.git] / source / core / pipelinestate.cpp
index 8d59a31624eddc823e23cd7260ed444c4efc9129..5ad51502010a1b1c2a2c37e7dd21b2a680dbdf2f 100644 (file)
@@ -41,17 +41,20 @@ void PipelineState::set_shader_program(const Program *p)
 
 void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
 {
-       auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
-       if(i==uniform_blocks.end() || i->binding!=binding)
-               i = uniform_blocks.insert(i, BoundUniformBlock(binding));
+       auto i = lower_bound_member(resources, binding, &BoundResource::binding);
+       if(i==resources.end() || i->binding!=binding)
+               i = resources.insert(i, BoundResource(binding));
+
+       ResourceType type = (block ? UNIFORM_BLOCK : NO_RESOURCE);
        const Buffer *buffer = (block ? block->get_buffer() : 0);
-       if(block!=i->block || buffer!=i->buffer || binding<0)
+       if(i->type!=type || block!=i->block || buffer!=i->buffer || binding<0)
        {
+               i->type = type;
                i->block = block;
                i->buffer = buffer;
                i->changed = true;
                i->used = block;
-               changes |= UNIFORMS;
+               changes |= RESOURCES;
        }
 }
 
@@ -67,17 +70,20 @@ void PipelineState::set_texture(unsigned binding, const Texture *tex, int level,
        if(level>=0 && !can_bind_tex_level(level))
                throw invalid_operation("PipelineState::set_texture");
 
-       auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
-       if(i==textures.end() || i->binding!=binding)
-               i = textures.insert(i, BoundTexture(binding));
-       if(tex!=i->texture || level!=i->level || samp!=i->sampler)
+       auto i = lower_bound_member(resources, static_cast<int>(binding), &BoundResource::binding);
+       if(i==resources.end() || i->binding!=static_cast<int>(binding))
+               i = resources.insert(i, BoundResource(binding));
+
+       ResourceType type = (tex ? TEXTURE : NO_RESOURCE);
+       if(i->type!=type || tex!=i->texture || level!=i->mip_level || samp!=i->sampler)
        {
+               i->type = type;
                i->texture = tex;
                i->sampler = samp;
-               i->level = level;
+               i->mip_level = level;
                i->changed = true;
                i->used = (tex && samp);
-               changes |= TEXTURES;
+               changes |= RESOURCES;
        }
 }