]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/programdata.h
Update and improve documentation
[libs/gl.git] / source / render / programdata.h
index 05e1bedc199eb78e7f29f9a4d6b75df9377505e3..9d08219ef84368943f6cb4535466bc61a1c742af 100644 (file)
@@ -1,14 +1,12 @@
 #ifndef MSP_GL_PROGRAMDATA_H_
 #define MSP_GL_PROGRAMDATA_H_
 
-#include <map>
 #include <stdexcept>
 #include <msp/datafile/objectloader.h>
 #include "datatype.h"
 #include "matrix.h"
 #include "reflectdata.h"
 #include "tag.h"
-#include "uniform.h"
 #include "vector.h"
 
 namespace Msp {
@@ -22,17 +20,17 @@ public:
 };
 
 class Buffer;
-class BufferBackedUniformBlock;
 class PipelineState;
 class Program;
 class UniformBlock;
 struct Color;
 
 /**
-Stores uniform variables for shader programs.  The uniforms are stored in a
-program-independent way, and UniformBlocks are created to match the uniform
-layouts of different programs.  If multiple programs have the same layout, the
-same block is used for them.
+Stores uniform values for shader programs.
+
+The uniforms are stored in a program-independent way, and UniformBlocks are
+created to match the uniform layouts of different programs.  If multiple
+programs have the same layout, the same block is used for them.
 
 The class is optimized for an access pattern where the set of uniforms and
 programs stays constants, with only the values changing.
@@ -104,11 +102,10 @@ private:
        struct TaggedUniform
        {
                Tag tag;
-               Uniform *value;
-
-               TaggedUniform();
-
-               void replace_value(Uniform *);
+               DataType type = VOID;
+               unsigned array_size = 0;
+               unsigned data_offset = 0;
+               unsigned data_size = 0;
        };
 
        struct SharedBlock
@@ -154,12 +151,13 @@ private:
        // XXX All these mutables are a bit silly, but I'm out of better ideas
        const Program *tied_program;
        std::vector<TaggedUniform> uniforms;
-       unsigned generation;
+       std::vector<char> uniform_data;
+       unsigned generation = 0;
        mutable std::vector<SharedBlock> blocks;
        mutable std::vector<ProgramBlock> programs;
-       mutable UniformBlock *last_buffer_block;
-       mutable Buffer *buffer;
-       mutable Mask dirty;
+       mutable UniformBlock *last_buffer_block = 0;
+       mutable Buffer *buffer = 0;
+       mutable Mask dirty = 0;
        std::string debug_name;
 
 public:
@@ -170,16 +168,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 +234,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;
@@ -253,6 +244,8 @@ private:
 
        std::vector<ProgramBlock>::const_iterator prepare_program(const Program &) const;
 public:
+       /** Creates or updates UniformBlocks for a specific program if necessary,
+       then sets them to the PipelineState. */
        void apply(const Program &, PipelineState &) const;
 
        void set_debug_name(const std::string &);
@@ -260,19 +253,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