]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/programdata.h
Eliminate the polymorphic Uniform class hierarchy
[libs/gl.git] / source / render / programdata.h
index 05e1bedc199eb78e7f29f9a4d6b75df9377505e3..474ca4e8d326d3bebbadb567cea32263175ffc5e 100644 (file)
@@ -8,7 +8,6 @@
 #include "matrix.h"
 #include "reflectdata.h"
 #include "tag.h"
-#include "uniform.h"
 #include "vector.h"
 
 namespace Msp {
@@ -104,11 +103,12 @@ private:
        struct TaggedUniform
        {
                Tag tag;
-               Uniform *value;
+               DataType type;
+               unsigned array_size;
+               unsigned data_offset;
+               unsigned data_size;
 
                TaggedUniform();
-
-               void replace_value(Uniform *);
        };
 
        struct SharedBlock
@@ -154,6 +154,7 @@ private:
        // XXX All these mutables are a bit silly, but I'm out of better ideas
        const Program *tied_program;
        std::vector<TaggedUniform> uniforms;
+       std::vector<char> uniform_data;
        unsigned generation;
        mutable std::vector<SharedBlock> blocks;
        mutable std::vector<ProgramBlock> programs;
@@ -170,16 +171,10 @@ public:
        ~ProgramData();
 
 private:
-       void uniform(Tag, Uniform *);
-       template<typename T, typename V>
-       void uniform(Tag, V);
-       template<typename T, typename V>
-       void uniform_array(Tag, unsigned, V);
+       void uniform(Tag, DataType, unsigned, const void *);
        bool validate_tag(Tag) const;
-       void add_uniform(Tag, Uniform *);
        void mark_dirty(Mask);
 public:
-       void uniform(Tag, const Uniform &);
        void uniform(Tag, int);
        void uniform(Tag, float);
        void uniform(Tag, int, int);
@@ -242,8 +237,7 @@ public:
        unsigned get_generation() const { return generation; }
 
        std::vector<Tag> get_uniform_tags() const;
-       const Uniform &get_uniform(Tag) const;
-       const Uniform *find_uniform(Tag) const;
+       void copy_uniform(const ProgramData &, Tag);
 
 private:
        int find_uniform_index(Tag) const;
@@ -260,19 +254,19 @@ public:
 
 template<typename T, unsigned N>
 void ProgramData::uniform(Tag tag, const LinAl::Vector<T, N> &v)
-{ uniform<UniformVector<T, N> >(tag, &v.x); }
+{ uniform(tag, TypeTraits<LinAl::Vector<T, N>>::type, 1, &v.x); }
 
 template<typename T, unsigned R, unsigned C>
 void ProgramData::uniform(Tag tag, const LinAl::Matrix<T, R, C> &v)
-{ uniform<UniformMatrix<T, R, C> >(tag, &v(0, 0)); }
+{ uniform(tag, TypeTraits<LinAl::Matrix<T, R, C>>::type, 1, &v(0, 0)); }
 
 template<typename T, unsigned N>
 void ProgramData::uniform_array(Tag tag, unsigned n, const LinAl::Vector<T, N> *v)
-{ uniform_array<UniformVector<T, N> >(tag, n, &v[0].x); }
+{ uniform(tag, TypeTraits<LinAl::Vector<T, N>>::type, n, &v[0].x); }
 
 template<typename T, unsigned R, unsigned C>
 void ProgramData::uniform_array(Tag tag, unsigned n, const LinAl::Matrix<T, R, C> *v)
-{ uniform_array<UniformMatrix<T, R, C> >(tag, n, &v[0](0, 0)); }
+{ uniform(tag, TypeTraits<LinAl::Matrix<T, R, C>>::type, n, &v[0](0, 0)); }
 
 } // namespace GL
 } // namespace Msp