X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Funiform.h;h=bc78bab8c1c891ad55086397f2bbcc9250d949a4;hp=ad2d88cc477715021baea7a4f7df4798b43173e7;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hpb=6dc3e14d26c747dfcece883771f457e5561c5d09 diff --git a/source/uniform.h b/source/uniform.h index ad2d88cc..bc78bab8 100644 --- a/source/uniform.h +++ b/source/uniform.h @@ -36,6 +36,10 @@ private: public: UniformScalar(Type v): value(v) { } + void set(Type v) { value = v; } + + Type get() const { return value; } + virtual void apply(int index) const { apply(index, 1, &value); } @@ -66,9 +70,13 @@ private: Type value; public: - UniformVector(const T *vp) + UniformVector(const T *vp) { set(vp); } + + void set(const T *vp) { std::copy(vp, vp+vecsize, value); } + BaseType get(unsigned i) const { return value[i]; } + virtual void apply(int index) const { apply(index, 1, value); } @@ -103,7 +111,9 @@ private: Type value; public: - UniformMatrix(const T *vp) + UniformMatrix(const T *vp) { set(vp); } + + void set(const T *vp) { std::copy(vp, vp+rows*cols, value); } virtual void apply(int index) const @@ -143,15 +153,15 @@ private: typedef typename T::BaseType BaseType; enum { elemsize = sizeof(typename T::Type)/sizeof(typename T::BaseType) }; + unsigned size_; BaseType *values; - unsigned size; public: UniformArray(unsigned n, const BaseType *vp): - size(n) + size_(n), + values(new BaseType[elemsize*size_]) { - values = new BaseType[elemsize*size]; - std::copy(vp, vp+elemsize*size, values); + set(vp); } ~UniformArray() @@ -159,17 +169,22 @@ public: delete[] values; } + unsigned size() const { return size_; } + + void set(const BaseType *vp) + { std::copy(vp, vp+elemsize*size_, values); } + virtual void apply(int index) const - { T::apply(index, size, values); } + { T::apply(index, size_, values); } virtual void store(const Program::UniformInfo &info, void *buffer) const { - for(unsigned i=0; i(buffer)+i*info.array_stride, values+i*elemsize); } virtual UniformArray *clone() const - { return new UniformArray(size, values); } + { return new UniformArray(size_, values); } }; } // namespace GL