X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Fprogramdata.cpp;h=79b559019d116b196502267222e5c37e6985642d;hb=f8bf444f26ce0bb392b96317ef3665be0af110aa;hp=7323df905db7093fcbb5db5572b9b7f7faedb5ca;hpb=ba1427f10d574ff8c4dafc4b8673452b19308ca2;p=libs%2Fgl.git diff --git a/source/render/programdata.cpp b/source/render/programdata.cpp index 7323df90..79b55901 100644 --- a/source/render/programdata.cpp +++ b/source/render/programdata.cpp @@ -7,6 +7,7 @@ #include "color.h" #include "error.h" #include "matrix.h" +#include "pipelinestate.h" #include "program.h" #include "programdata.h" #include "uniform.h" @@ -20,7 +21,8 @@ namespace GL { ProgramData::ProgramData(const Program *p): tied_program(p), - last_block(0), + generation(0), + last_buffer_block(0), buffer(0), dirty(0) { } @@ -29,7 +31,8 @@ ProgramData::ProgramData(const Program *p): ProgramData::ProgramData(const ProgramData &other): tied_program(other.tied_program), uniforms(other.uniforms), - last_block(0), + generation(other.generation), + last_buffer_block(0), buffer(0), dirty(0) { @@ -39,7 +42,7 @@ ProgramData::ProgramData(const ProgramData &other): ProgramData::ProgramData(const ProgramData &other, const Program *p): tied_program(p), - last_block(0), + last_buffer_block(0), buffer(0), dirty(0) { @@ -66,7 +69,7 @@ ProgramData &ProgramData::operator=(const ProgramData &other) delete i->block; programs.clear(); - last_block = 0; + last_buffer_block = 0; buffer = 0; dirty = 0; @@ -107,7 +110,7 @@ void ProgramData::uniform(Tag tag, Uniform *uni) return add_uniform(tag, uni); uniforms[i].replace_value(uni); - dirty |= 1< @@ -125,7 +128,7 @@ void ProgramData::uniform(Tag tag, V value) else uniforms[i].replace_value(new T(value)); - dirty |= 1< @@ -144,7 +147,7 @@ void ProgramData::uniform_array(Tag tag, unsigned n, V value) else uniforms[i].replace_value(new UniformArray(n, value)); - dirty |= 1<get_uniform_info(tag); + { + const Program::UniformInfo &info = tied_program->get_uniform_info(tag); + if(is_image(info.type)) + throw invalid_operation("ProgramData::uniform"); + } return true; } #ifdef DEBUG @@ -181,7 +188,14 @@ void ProgramData::add_uniform(Tag tag, Uniform *uni) nu.value = uni; uniforms.insert(j, nu); - dirty = ALL_ONES; + mark_dirty(ALL_ONES); +} + +void ProgramData::mark_dirty(Mask bits) +{ + if(!dirty) + ++generation; + dirty |= bits; } void ProgramData::uniform(Tag tag, const Uniform &u) @@ -233,11 +247,6 @@ void ProgramData::uniform(Tag tag, float v0, float v1, float v2) uniform3(tag, va); } -void ProgramData::uniform(Tag tag, const Vector3 &v) -{ - uniform(tag, v.x, v.y, v.z); -} - void ProgramData::uniform3(Tag tag, const int *v) { uniform(tag, v); @@ -260,11 +269,6 @@ void ProgramData::uniform(Tag tag, float v0, float v1, float v2, float v3) uniform4(tag, va); } -void ProgramData::uniform(Tag tag, const Vector4 &v) -{ - uniform(tag, v.x, v.y, v.z, v.w); -} - void ProgramData::uniform(Tag tag, const Color &c) { uniform(tag, c.r, c.g, c.b, c.a); @@ -280,81 +284,41 @@ void ProgramData::uniform4(Tag tag, const float *v) uniform(tag, v); } -void ProgramData::uniform(Tag tag, const LinAl::Matrix &m) -{ - uniform_matrix2(tag, &m(0, 0)); -} - void ProgramData::uniform_matrix2(Tag tag, const float *v) { uniform(tag, v); } -void ProgramData::uniform(Tag tag, const LinAl::Matrix &m) -{ - uniform_matrix3x2(tag, &m(0, 0)); -} - void ProgramData::uniform_matrix3x2(Tag tag, const float *v) { uniform(tag, v); } -void ProgramData::uniform(Tag tag, const LinAl::Matrix &m) -{ - uniform_matrix4x2(tag, &m(0, 0)); -} - void ProgramData::uniform_matrix4x2(Tag tag, const float *v) { uniform(tag, v); } -void ProgramData::uniform(Tag tag, const LinAl::Matrix &m) -{ - uniform_matrix2x3(tag, &m(0, 0)); -} - void ProgramData::uniform_matrix2x3(Tag tag, const float *v) { uniform(tag, v); } -void ProgramData::uniform(Tag tag, const LinAl::Matrix &m) -{ - uniform_matrix3(tag, &m(0, 0)); -} - void ProgramData::uniform_matrix3(Tag tag, const float *v) { uniform(tag, v); } -void ProgramData::uniform(Tag tag, const LinAl::Matrix &m) -{ - uniform_matrix4x3(tag, &m(0, 0)); -} - void ProgramData::uniform_matrix4x3(Tag tag, const float *v) { uniform(tag, v); } -void ProgramData::uniform(Tag tag, const LinAl::Matrix &m) -{ - uniform_matrix2x4(tag, &m(0, 0)); -} - void ProgramData::uniform_matrix2x4(Tag tag, const float *v) { uniform(tag, v); } -void ProgramData::uniform(Tag tag, const LinAl::Matrix &m) -{ - uniform_matrix3x4(tag, &m(0, 0)); -} - void ProgramData::uniform_matrix3x4(Tag tag, const float *v) { uniform(tag, v); @@ -370,6 +334,16 @@ void ProgramData::uniform_matrix4(Tag tag, const float *v) uniform(tag, v); } +void ProgramData::uniform_array(Tag tag, unsigned n, const int *v) +{ + uniform_array(tag, n, v); +} + +void ProgramData::uniform_array(Tag tag, unsigned n, const float *v) +{ + uniform_array(tag, n, v); +} + void ProgramData::uniform1_array(Tag tag, unsigned n, const int *v) { uniform_array(tag, n, v); @@ -464,7 +438,7 @@ void ProgramData::remove_uniform(Tag tag) delete i->value; uniforms.erase(i); - dirty = ALL_ONES; + mark_dirty(ALL_ONES); } vector ProgramData::get_uniform_tags() const @@ -592,14 +566,22 @@ void ProgramData::update_block_uniform_indices(SharedBlock &block, const Program if(info.bind_point>=0) { if(!buffer) - buffer = new Buffer(UNIFORM_BUFFER); + { + buffer = new Buffer(); + +#ifdef DEBUG + if(!debug_name.empty()) + buffer->set_debug_name(debug_name); +#endif + } - block.block = new UniformBlock(info.data_size); - block.block->use_buffer(buffer, last_block); - last_block = block.block; + BufferBackedUniformBlock *bb_block = new BufferBackedUniformBlock(info.data_size); + block.block = bb_block; + bb_block->use_buffer(buffer, last_buffer_block); + last_buffer_block = bb_block; } else - block.block = new UniformBlock; + block.block = new DefaultUniformBlock; } } @@ -607,19 +589,18 @@ void ProgramData::update_block(SharedBlock &block, const Program::UniformBlockIn { const UInt8 *indices = block.get_uniform_indices(); for(unsigned i=0; itype)) + ; // Temporarily ignore deprecated use of sampler uniforms in ProgramData + else if(indices[i]!=0xFF) block.block->attach(*info.uniforms[i], *uniforms[indices[i]].value); + } } -void ProgramData::apply() const +vector::const_iterator ProgramData::prepare_program(const Program &prog) const { - const Program *prog = Program::current(); - if(!prog) - throw invalid_operation("ProgramData::apply"); - - UniformBlock *old_last_block = last_block; - vector::iterator prog_begin = get_program(*prog); - Program::LayoutHash prog_hash = prog->get_uniform_layout_hash(); + BufferBackedUniformBlock *old_last_block = last_buffer_block; + vector::iterator prog_begin = get_program(prog); Mask force_dirty = (dirty==ALL_ONES ? ALL_ONES : 0U); Mask affected = (dirty&prog_begin->masks.used) | force_dirty; @@ -638,7 +619,7 @@ void ProgramData::apply() const dirty = 0; } - const vector &block_infos = prog->get_uniform_blocks(); + const vector &block_infos = prog.get_uniform_blocks(); if(prog_begin->masks.dirty==ALL_ONES) { @@ -672,21 +653,21 @@ void ProgramData::apply() const prog_begin->masks.dirty = 0; - /* If any blocks stored in the buffer were updated, bind the buffer here - to avoid state thrashing. */ - if(buffered_blocks_updated && !ARB_direct_state_access) - buffer->bind(); - - if(last_block!=old_last_block) + if(last_buffer_block!=old_last_block) { - unsigned required_size = last_block->get_required_buffer_size(); - if(last_block->get_required_buffer_size()>buffer->get_size()) + unsigned required_size = last_buffer_block->get_required_buffer_size(); + if(last_buffer_block->get_required_buffer_size()>buffer->get_size()) { if(buffer->get_size()>0) { delete buffer; - buffer = new Buffer(UNIFORM_BUFFER); - last_block->change_buffer(buffer); + buffer = new Buffer(); + last_buffer_block->change_buffer(buffer); + +#ifdef DEBUG + if(!debug_name.empty()) + buffer->set_debug_name(debug_name); +#endif } buffer->storage(required_size); @@ -694,9 +675,36 @@ void ProgramData::apply() const } } - for(vector::iterator i=prog_begin+1; (i!=programs.end() && i->prog_hash==prog_hash); ++i) + return prog_begin; +} + +void ProgramData::apply(const Program &prog, PipelineState &state) const +{ + vector::const_iterator prog_begin = prepare_program(prog); + Program::LayoutHash prog_hash = prog_begin->prog_hash; + for(vector::const_iterator i=prog_begin+1; (i!=programs.end() && i->prog_hash==prog_hash); ++i) if(i->block) - i->block->apply(i->bind_point); + { + if(i->bind_point<0) + state.set_uniforms(static_cast(i->block)); + else + { + const BufferBackedUniformBlock *block = static_cast(i->block); + block->refresh(); + state.set_uniform_block(i->bind_point, block); + } + } +} + +void ProgramData::set_debug_name(const string &name) +{ +#ifdef DEBUG + debug_name = name; + if(buffer) + buffer->set_debug_name(name); +#else + (void)name; +#endif }