X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Fprogramdata.cpp;h=b21c395cf04c27f1084492294dbd2635993af5df;hb=f1244e29afd2a36aafc2373d485457b4cb0411ff;hp=ec273c2277532c9f8a985341663ce9c4ea5836c6;hpb=492325880c47450f50dcdebdcb336b37230ef867;p=libs%2Fgl.git diff --git a/source/render/programdata.cpp b/source/render/programdata.cpp index ec273c22..b21c395c 100644 --- a/source/render/programdata.cpp +++ b/source/render/programdata.cpp @@ -20,6 +20,7 @@ namespace GL { ProgramData::ProgramData(const Program *p): tied_program(p), + generation(0), last_buffer_block(0), buffer(0), dirty(0) @@ -29,6 +30,7 @@ ProgramData::ProgramData(const Program *p): ProgramData::ProgramData(const ProgramData &other): tied_program(other.tied_program), uniforms(other.uniforms), + generation(other.generation), last_buffer_block(0), buffer(0), dirty(0) @@ -107,7 +109,7 @@ void ProgramData::uniform(Tag tag, Uniform *uni) return add_uniform(tag, uni); uniforms[i].replace_value(uni); - dirty |= 1< @@ -125,7 +127,7 @@ void ProgramData::uniform(Tag tag, V value) else uniforms[i].replace_value(new T(value)); - dirty |= 1< @@ -144,7 +146,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 +187,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 +246,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 +268,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 +283,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 +333,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 +437,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,7 +565,14 @@ 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 + } BufferBackedUniformBlock *bb_block = new BufferBackedUniformBlock(info.data_size); block.block = bb_block; @@ -608,8 +588,12 @@ 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 @@ -673,11 +657,6 @@ 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_buffer_block!=old_last_block) { unsigned required_size = last_buffer_block->get_required_buffer_size(); @@ -686,8 +665,13 @@ void ProgramData::apply() const if(buffer->get_size()>0) { delete buffer; - buffer = new Buffer(UNIFORM_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); @@ -700,6 +684,17 @@ void ProgramData::apply() const i->block->apply(i->bind_point); } +void ProgramData::set_debug_name(const string &name) +{ +#ifdef DEBUG + debug_name = name; + if(buffer) + buffer->set_debug_name(name); +#else + (void)name; +#endif +} + ProgramData::TaggedUniform::TaggedUniform(): value(0)