X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramdata.cpp;h=0beb9e7f6cb85d1f095def0cbe93063c64dd0a62;hb=259254bc46e3aec6f719e1aea5e4936569c15b6e;hp=b8a272c0fc0bde8a3699a81e347115327c41938f;hpb=3cdcc7f689b3868dd275774b9bd9adb5c436f244;p=libs%2Fgl.git diff --git a/source/programdata.cpp b/source/programdata.cpp index b8a272c0..0beb9e7f 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -1,7 +1,6 @@ #include "buffer.h" #include "color.h" #include "error.h" -#include "extension.h" #include "matrix.h" #include "program.h" #include "programdata.h" @@ -18,9 +17,7 @@ ProgramData::ProgramData(): last_block(0), buffer(0), changes(NO_CHANGES) -{ - static RequireExtension _ext("GL_ARB_shader_objects"); -} +{ } // Blocks are intentionally left uncopied ProgramData::ProgramData(const ProgramData &other): @@ -33,12 +30,31 @@ ProgramData::ProgramData(const ProgramData &other): i->second = i->second->clone(); } +ProgramData &ProgramData::operator=(const ProgramData &other) +{ + for(UniformMap::iterator i=uniforms.begin(); i!=uniforms.end(); ++i) + delete i->second; + uniforms.clear(); + + for(UniformMap::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i) + uniforms.insert(uniforms.end(), UniformMap::value_type(i->first, i->second->clone())); + + for(BlockMap::iterator i=blocks.begin(); i!=blocks.end(); ++i) + delete i->second.block; + blocks.clear(); + + changes = NO_CHANGES; + + return *this; +} + ProgramData::~ProgramData() { for(UniformMap::iterator i=uniforms.begin(); i!=uniforms.end(); ++i) delete i->second; for(BlockMap::iterator i=blocks.begin(); i!=blocks.end(); ++i) delete i->second.block; + delete buffer; } void ProgramData::uniform(const string &name, Uniform *uni) @@ -46,6 +62,9 @@ void ProgramData::uniform(const string &name, Uniform *uni) UniformMap::iterator i = uniforms.find(name); if(i!=uniforms.end()) { + /* UniformBlock does not copy the uniforms, so existing blocks will be + left with stale pointers. This is not a problem as long as no one stores + pointers to the blocks and expects them to stay valid. */ delete i->second; i->second = uni; changes = VALUES_CHANGED; @@ -115,16 +134,24 @@ void ProgramData::uniform4(const string &name, const float *v) uniform(name, new Uniform4f(v)); } -void ProgramData::uniform_matrix4(const string &name, const float *v) +void ProgramData::uniform_matrix2(const string &name, const float *v) { - uniform(name, new UniformMatrix4x4f(v)); + uniform(name, new UniformMatrix2x2f(v)); } -void ProgramData::uniform_matrix4(const string &name, const Matrix &m) +void ProgramData::uniform_matrix3(const string &name, const float *v) { - float v[16]; - copy(m.data(), m.data()+16, v); - uniform_matrix4(name, v); + uniform(name, new UniformMatrix3x3f(v)); +} + +void ProgramData::uniform(const string &name, const Matrix &m) +{ + uniform_matrix4(name, m.data()); +} + +void ProgramData::uniform_matrix4(const string &name, const float *v) +{ + uniform(name, new UniformMatrix4x4f(v)); } void ProgramData::uniform1_array(const string &name, unsigned n, const float *v) @@ -168,7 +195,10 @@ UniformBlock *ProgramData::create_block(const Program::UniformBlockInfo &info) c { UniformBlock *block = new UniformBlock(info.data_size); if(!buffer) + { buffer = new Buffer(UNIFORM_BUFFER); + buffer->set_usage(STREAM_DRAW); + } block->use_buffer(buffer, last_block); last_block = block; return block; @@ -184,9 +214,9 @@ const UniformBlock *ProgramData::get_block(const Program &prog, const Program::U changes = NO_CHANGES; } - unsigned layout_hash = (info ? info->layout_hash : prog.get_uniform_layout_hash()); + Program::LayoutHash layout_hash = (info ? info->layout_hash : prog.get_uniform_layout_hash()); - map::iterator i = blocks.find(layout_hash); + map::iterator i = blocks.find(layout_hash); if(i==blocks.end()) { i = blocks.insert(BlockMap::value_type(layout_hash, Block())).first;