X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramdata.cpp;h=4a6c262a37a646bfd128f3cda4143ae5007e2a70;hb=66181b3f47322ffc9b8aebf04a8c222abe1a75a2;hp=68820c59cc9fd0fd829792ebf547190d23c0fe9f;hpb=4af69ec90120a0be828a1ae475a38674087110b5;p=libs%2Fgl.git diff --git a/source/programdata.cpp b/source/programdata.cpp index 68820c59..4a6c262a 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -1,5 +1,7 @@ #include +#include #include +#include #include "buffer.h" #include "color.h" #include "error.h" @@ -92,10 +94,15 @@ void ProgramData::uniform(const string &name, Uniform *uni) else if(name[name.size()-1]==']') throw invalid_argument("ProgramData::uniform"); } - catch(...) + catch(const exception &e) { delete uni; +#ifdef DEBUG + IO::print(IO::cerr, "Error while setting uniform %s: %s: %s\n", name, Debug::demangle(typeid(e).name()), e.what()); + return; +#else throw; +#endif } int i = find_uniform_index(name); @@ -482,21 +489,31 @@ ProgramData::SharedBlock *ProgramData::get_shared_block(const Program::UniformBl if(i==blocks.end()) { bool any_found = false; - for(vector::const_iterator j=info.uniforms.begin(); (!any_found && j!=info.uniforms.end()); ++j) - any_found = (find_uniform_index((*j)->name)>=0); + bool all_found = true; + for(vector::const_iterator j=info.uniforms.begin(); j!=info.uniforms.end(); ++j) + { + if(find_uniform_index((*j)->name)>=0) + any_found = true; + else + all_found = false; + } - // TODO throw if all uniforms for a buffer-backed block are not found if(!any_found) return 0; + else if(!all_found && info.bind_point>=0) + { +#ifdef DEBUG + IO::print(IO::cerr, "Warning: not all uniforms for block %s are present\n", info.name); +#else + throw incomplete_uniform_block(info.name); +#endif + } UniformBlock *block; if(info.bind_point>=0) { if(!buffer) - { buffer = new Buffer(UNIFORM_BUFFER); - buffer->set_usage(STREAM_DRAW); - } block = new UniformBlock(info.data_size); block->use_buffer(buffer, last_block); @@ -539,6 +556,7 @@ void ProgramData::apply() const const Program::UniformBlockMap &prog_blocks = prog->get_uniform_blocks(); + UniformBlock *old_last_block = last_block; if(pu.dirty==ALL_ONES) { /* The set of uniforms has changed since this program was last used. @@ -580,6 +598,22 @@ void ProgramData::apply() const to avoid state thrashing. */ if(buffered_blocks_updated && !ARB_direct_state_access) buffer->bind(); + + if(last_block!=old_last_block) + { + unsigned required_size = last_block->get_required_buffer_size(); + if(last_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->storage(required_size); + } + } } for(vector::iterator i=pu.blocks.begin(); i!=pu.blocks.end(); ++i)