namespace Msp {
namespace GL {
-UniformBlock::~UniformBlock()
+void UniformBlock::attach(int index, const Uniform &uni)
{
- for(map<int, Uniform *>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
- delete i->second;
-}
-
-void UniformBlock::uniform(int index, Uniform *uni)
-{
- map<int, Uniform *>::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
if(index>=0)
throw logic_error("GL_ARB_uniform_buffer_object support not implemented yet");
- for(map<int, Uniform *>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
+ for(map<int, const Uniform *>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
i->second->apply(i->first);
}
class UniformBlock
{
private:
- std::map<int, Uniform *> uniforms;
+ std::map<int, const Uniform *> 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;
};