]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/programdata.h
Move WindowView::render to the backend
[libs/gl.git] / source / render / programdata.h
index f600f02585c3d13fcd5cdd57ba0004da30c2e04b..9b8a25cb15be498a916bf0ffcf28c868ea56bb02 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 "program.h"
+#include "reflectdata.h"
 #include "tag.h"
-#include "uniform.h"
 #include "vector.h"
 
 namespace Msp {
@@ -22,15 +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.
@@ -102,38 +102,37 @@ 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
        {
-               Program::LayoutHash block_hash;
+               ReflectData::LayoutHash block_hash;
                Mask used;
                Mask dirty;
                UniformBlock *block;
                union
                {
-                       UInt8 type_flag;
-                       UInt8 values[16];
+                       std::uint8_t type_flag;
+                       std::uint8_t values[16];
                        struct
                        {
-                               UInt8 type_flag;
-                               UInt8 *values;
+                               std::uint8_t type_flag;
+                               std::uint8_t *values;
                        } dynamic;
                } indices;
 
-               SharedBlock(Program::LayoutHash);
+               SharedBlock(ReflectData::LayoutHash);
 
-               const UInt8 *get_uniform_indices() const;
+               const std::uint8_t *get_uniform_indices() const;
        };
 
        struct ProgramBlock
        {
-               Program::LayoutHash prog_hash;
+               ReflectData::LayoutHash prog_hash;
                int bind_point;
                int block_index;
                union
@@ -146,17 +145,20 @@ private:
                        } masks;
                };
 
-               ProgramBlock(Program::LayoutHash);
+               ProgramBlock(ReflectData::LayoutHash);
        };
 
        // 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 = 0;
        mutable std::vector<SharedBlock> blocks;
        mutable std::vector<ProgramBlock> programs;
-       mutable BufferBackedUniformBlock *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:
        ProgramData(const Program * = 0);
@@ -166,29 +168,31 @@ 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, unsigned);
        void uniform(Tag, float);
        void uniform(Tag, int, int);
+       void uniform(Tag, unsigned, unsigned);
        void uniform(Tag, float, float);
        void uniform2(Tag, const int *);
+       void uniform2(Tag, const unsigned *);
        void uniform2(Tag, const float *);
        void uniform(Tag, int, int, int);
+       void uniform(Tag, unsigned, unsigned, unsigned);
        void uniform(Tag, float, float, float);
        void uniform3(Tag, const int *);
+       void uniform3(Tag, const unsigned *);
        void uniform3(Tag, const float *);
        void uniform(Tag, int, int, int, int);
+       void uniform(Tag, unsigned, unsigned, unsigned, unsigned);
        void uniform(Tag, float, float, float, float);
        void uniform(Tag, const Color &);
        void uniform4(Tag, const int *);
+       void uniform4(Tag, const unsigned *);
        void uniform4(Tag, const float *);
        void uniform_matrix2(Tag, const float *);
        void uniform_matrix3x2(Tag, const float *);
@@ -201,14 +205,19 @@ public:
        void uniform(Tag, const Matrix &);
        void uniform_matrix4(Tag, const float *);
        void uniform_array(Tag, unsigned, const int *);
+       void uniform_array(Tag, unsigned, const unsigned *);
        void uniform_array(Tag, unsigned, const float *);
        void uniform1_array(Tag, unsigned, const int *);
+       void uniform1_array(Tag, unsigned, const unsigned *);
        void uniform1_array(Tag, unsigned, const float *);
        void uniform2_array(Tag, unsigned, const int *);
+       void uniform2_array(Tag, unsigned, const unsigned *);
        void uniform2_array(Tag, unsigned, const float *);
        void uniform3_array(Tag, unsigned, const int *);
+       void uniform3_array(Tag, unsigned, const unsigned *);
        void uniform3_array(Tag, unsigned, const float *);
        void uniform4_array(Tag, unsigned, const int *);
+       void uniform4_array(Tag, unsigned, const unsigned *);
        void uniform4_array(Tag, unsigned, const float *);
        void uniform_matrix2_array(Tag, unsigned, const float *);
        void uniform_matrix3x2_array(Tag, unsigned, const float *);
@@ -234,37 +243,41 @@ public:
 
        void remove_uniform(Tag);
 
+       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;
        std::vector<ProgramBlock>::iterator get_program(const Program &) const;
-       void update_block_uniform_indices(SharedBlock &, const Program::UniformBlockInfo &) const;
-       void update_block(SharedBlock &, const Program::UniformBlockInfo &) const;
+       void update_block_uniform_indices(SharedBlock &, const ReflectData::UniformBlockInfo &) const;
+       void update_block(SharedBlock &, const ReflectData::UniformBlockInfo &) const;
 
+       std::vector<ProgramBlock>::const_iterator prepare_program(const Program &) const;
 public:
-       /** Applies uniform blocks for the currently bound program, creating them
-       if needed. */
-       void apply() const;
+       /** 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 &);
 };
 
 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