X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fpipelinestate.cpp;h=4dc54e2403ffea9288375df8dbfa09eb01f50283;hb=4595453156db0c47926946b0ea1732b1e37e70ce;hp=210a0703868035dc69572fc56cc50eaf67b9ff08;hpb=c89c1fb972fae2cb2f720cb3ec6cf8238ae8d2e1;p=libs%2Fgl.git diff --git a/source/core/pipelinestate.cpp b/source/core/pipelinestate.cpp index 210a0703..4dc54e24 100644 --- a/source/core/pipelinestate.cpp +++ b/source/core/pipelinestate.cpp @@ -2,6 +2,7 @@ #include #include "error.h" #include "pipelinestate.h" +#include "uniformblock.h" using namespace std; @@ -9,7 +10,7 @@ namespace Msp { namespace GL { template -void PipelineState::set(T &target, T value, unsigned flag) +void PipelineState::set(T &target, const T &value, unsigned flag) { if(value!=target) { @@ -23,12 +24,12 @@ void PipelineState::set_framebuffer(const Framebuffer *f) set(framebuffer, f, FRAMEBUFFER); } -void PipelineState::set_viewport(const Rect *v) +void PipelineState::set_viewport(const Rect &v) { set(viewport, v, VIEWPORT); } -void PipelineState::set_scissor(const Rect *s) +void PipelineState::set_scissor(const Rect &s) { set(scissor, s, SCISSOR); } @@ -40,15 +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)); - i->used = block; - if(block!=i->block || binding<0) + 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(i->type!=type || block!=i->block || buffer!=i->buffer || binding<0) { + i->type = type; i->block = block; + i->buffer = buffer; i->changed = true; - changes |= UNIFORMS; + i->used = block; + changes |= RESOURCES; } } @@ -64,17 +70,30 @@ 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)); - i->used = (tex && samp); - if(tex!=i->texture || level!=i->level || samp!=i->sampler) + set_texture_resource(binding, tex, level, samp); +} + +void PipelineState::set_storage_texture(unsigned binding, const Texture *tex) +{ + set_texture_resource(binding, tex, 0, 0); +} + +void PipelineState::set_texture_resource(unsigned binding, const Texture *tex, int level, const Sampler *samp) +{ + auto i = lower_bound_member(resources, static_cast(binding), &BoundResource::binding); + if(i==resources.end() || i->binding!=static_cast(binding)) + i = resources.insert(i, BoundResource(binding)); + + ResourceType type = (tex ? samp ? SAMPLED_TEXTURE : STORAGE_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; - changes |= TEXTURES; + i->used = tex; + changes |= RESOURCES; } } @@ -98,17 +117,17 @@ void PipelineState::set_face_cull(CullMode c) set(face_cull, c, FACE_CULL); } -void PipelineState::set_depth_test(const DepthTest *dt) +void PipelineState::set_depth_test(const DepthTest &dt) { set(depth_test, dt, DEPTH_TEST); } -void PipelineState::set_stencil_test(const StencilTest *st) +void PipelineState::set_stencil_test(const StencilTest &st) { set(stencil_test, st, STENCIL_TEST); } -void PipelineState::set_blend(const Blend *b) +void PipelineState::set_blend(const Blend &b) { set(blend, b, BLEND); }