From: Mikko Rasa Date: Wed, 22 Aug 2012 13:17:34 +0000 (+0300) Subject: Remove the specialized setters from UniformBlock X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8c24084524198e23d65058454001ffb0bf20e94f;p=libs%2Fgl.git Remove the specialized setters from UniformBlock They were not very useful and were also getting in the way of uniform buffer support. UniformBlock also no longer clones the uniforms for itself, reducing overhead. --- diff --git a/source/programdata.cpp b/source/programdata.cpp index 0a2ec605..5bfbd68f 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -170,7 +170,7 @@ const UniformBlock &ProgramData::get_block(const Program &prog) const { int loc = prog.get_uniform_location(j->first); if(loc>=0) - block.uniform(loc, *j->second); + block.attach(loc, *j->second); } i->second.dirty = false; } diff --git a/source/uniformblock.cpp b/source/uniformblock.cpp index fe044750..2ff00fa2 100644 --- a/source/uniformblock.cpp +++ b/source/uniformblock.cpp @@ -10,97 +10,9 @@ using namespace std; namespace Msp { namespace GL { -UniformBlock::~UniformBlock() +void UniformBlock::attach(int index, const Uniform &uni) { - for(map::iterator i=uniforms.begin(); i!=uniforms.end(); ++i) - delete i->second; -} - -void UniformBlock::uniform(int index, Uniform *uni) -{ - map::iterator i = uniforms.find(index); - if(i!=uniforms.end()) - { - delete i->second; - i->second = uni; - } - else - uniforms[index] = uni; -} - -void UniformBlock::uniform(int index, const Uniform &uni) -{ - uniform(index, uni.clone()); -} - -void UniformBlock::uniform(int index, int v) -{ - uniform(index, new Uniform1i(v)); -} - -void UniformBlock::uniform(int index, float v) -{ - uniform(index, new Uniform1f(v)); -} - -void UniformBlock::uniform(int index, float v0, float v1) -{ - float va[2] = { v0, v1 }; - uniform2(index, va); -} - -void UniformBlock::uniform2(int index, const float *v) -{ - uniform(index, new Uniform2f(v)); -} - -void UniformBlock::uniform(int index, float v0, float v1, float v2) -{ - float va[3] = { v0, v1, v2 }; - uniform3(index, va); -} - -void UniformBlock::uniform(int index, const Vector3 &v) -{ - uniform(index, v.x, v.y, v.z); -} - -void UniformBlock::uniform3(int index, const float *v) -{ - uniform(index, new Uniform3f(v)); -} - -void UniformBlock::uniform(int index, float v0, float v1, float v2, float v3) -{ - float va[4] = { v0, v1, v2, v3 }; - uniform4(index, va); -} - -void UniformBlock::uniform(int index, const Vector4 &v) -{ - uniform(index, v.x, v.y, v.z, v.w); -} - -void UniformBlock::uniform(int index, const Color &c) -{ - uniform(index, c.r, c.g, c.b, c.a); -} - -void UniformBlock::uniform4(int index, const float *v) -{ - uniform(index, new Uniform4f(v)); -} - -void UniformBlock::uniform_matrix4(int index, const float *v) -{ - uniform(index, new UniformMatrix4x4f(v)); -} - -void UniformBlock::uniform_matrix4(int index, const Matrix &m) -{ - float v[16]; - copy(m.data(), m.data()+16, v); - uniform_matrix4(index, v); + uniforms[index] = &uni; } void UniformBlock::apply(int index) const @@ -108,7 +20,7 @@ void UniformBlock::apply(int index) const if(index>=0) throw logic_error("GL_ARB_uniform_buffer_object support not implemented yet"); - for(map::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i) + for(map::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i) i->second->apply(i->first); } diff --git a/source/uniformblock.h b/source/uniformblock.h index 815f49b1..3a1cdb95 100644 --- a/source/uniformblock.h +++ b/source/uniformblock.h @@ -15,31 +15,14 @@ class Vector4; class UniformBlock { private: - std::map uniforms; + std::map uniforms; UniformBlock(const UniformBlock &); UniformBlock &operator=(const UniformBlock &); public: UniformBlock() { } - ~UniformBlock(); -private: - void uniform(int, Uniform *); -public: - void uniform(int, const Uniform &); - void uniform(int, int); - void uniform(int, float); - void uniform(int, float, float); - void uniform2(int, const float *); - void uniform(int, float, float, float); - void uniform(int, const Vector3 &); - void uniform3(int, const float *); - void uniform(int, float, float, float, float); - void uniform(int, const Vector4 &); - void uniform(int, const Color &); - void uniform4(int, const float *); - void uniform_matrix4(int, const float *); - void uniform_matrix4(int, const Matrix &); + void attach(int, const Uniform &); void apply(int) const; };