X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Funiform.h;fp=source%2Funiform.h;h=216d3be6a65c37cf5b2694a004363bf98a306a18;hp=32779ced0a06cc0206a20982ee57ac4d52024335;hb=0070eec93efbf27bcc70720141d8730b059eb964;hpb=f9c15dc04462b2f1eea1d6bdd71e3ba967b1bd8c diff --git a/source/uniform.h b/source/uniform.h index 32779ced..216d3be6 100644 --- a/source/uniform.h +++ b/source/uniform.h @@ -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 UniformMatrix4x4f; + +template +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