]> git.tdb.fi Git - libs/gl.git/blobdiff - source/uniform.h
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / uniform.h
index ad2d88cc477715021baea7a4f7df4798b43173e7..bc78bab8c1c891ad55086397f2bbcc9250d949a4 100644 (file)
@@ -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<size; ++i)
+               for(unsigned i=0; i<size_; ++i)
                        T::store(info, reinterpret_cast<char *>(buffer)+i*info.array_stride, values+i*elemsize);
        }
 
        virtual UniformArray *clone() const
-       { return new UniformArray(size, values); }
+       { return new UniformArray(size_, values); }
 };
 
 } // namespace GL