]> git.tdb.fi Git - libs/gl.git/blobdiff - source/uniform.h
Implement uniform arrays
[libs/gl.git] / source / uniform.h
index 32779ced0a06cc0206a20982ee57ac4d52024335..216d3be6a65c37cf5b2694a004363bf98a306a18 100644 (file)
@@ -34,7 +34,10 @@ private:
 public:
        UniformScalar(Type v): value(v) { }
 
-       virtual void apply(int index) const;
+       virtual void apply(int index) const
+       { apply(index, 1, &value); }
+
+       static void apply(int, unsigned, const T *);
 
        virtual UniformScalar *clone() const
        { return new UniformScalar(value); }
@@ -58,7 +61,10 @@ public:
        UniformVector(const T *vp)
        { std::copy(vp, vp+vecsize, value); }
 
-       virtual void apply(int index) const;
+       virtual void apply(int index) const
+       { apply(index, 1, value); }
+
+       static void apply(int index, unsigned size, const T *value);
 
        virtual UniformVector *clone() const
        { return new UniformVector(value); }
@@ -83,7 +89,10 @@ public:
        UniformMatrix(const T *vp)
        { std::copy(vp, vp+rows*cols, value); }
 
-       virtual void apply(int index) const;
+       virtual void apply(int index) const
+       { apply(index, 1, value); }
+
+       static void apply(int index, unsigned size, const T *value);
 
        virtual UniformMatrix *clone() const
        { return new UniformMatrix(value); }
@@ -91,6 +100,32 @@ public:
 
 typedef UniformMatrix<float, 4, 4> UniformMatrix4x4f;
 
+
+template<typename T>
+class UniformArray: public Uniform
+{
+private:
+       typedef typename T::BaseType BaseType;
+
+       BaseType *values;
+       unsigned size;
+
+public:
+       UniformArray(unsigned n, const BaseType *vp):
+               size(n)
+       {
+               unsigned elemsize = sizeof(typename T::Type)/sizeof(typename T::BaseType);
+               values = new BaseType[elemsize*size];
+               std::copy(vp, vp+elemsize*size, values);
+       }
+
+       virtual void apply(int index) const
+       { T::apply(index, size, values); }
+
+       virtual UniformArray *clone() const
+       { return new UniformArray(size, values); }
+};
+
 } // namespace GL
 } // namespace Msp