]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/programdata.h
Split reflection data from Program to a separate struct
[libs/gl.git] / source / render / programdata.h
index a90d868e3bb7e3598200f074791189ee85e0cc15..380f352a66376b6b168805bea5f6c46f4ee0cae5 100644 (file)
@@ -6,8 +6,9 @@
 #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,7 +23,8 @@ public:
 
 class Buffer;
 class BufferBackedUniformBlock;
-class Uniform;
+class PipelineState;
+class Program;
 class UniformBlock;
 struct Color;
 
@@ -111,29 +113,29 @@ private:
 
        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 +148,19 @@ 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;
+       unsigned generation;
        mutable std::vector<SharedBlock> blocks;
        mutable std::vector<ProgramBlock> programs;
        mutable BufferBackedUniformBlock *last_buffer_block;
        mutable Buffer *buffer;
        mutable Mask dirty;
+       std::string debug_name;
 
 public:
        ProgramData(const Program * = 0);
@@ -173,6 +177,7 @@ private:
        void uniform_array(Tag, unsigned, V);
        bool validate_tag(Tag) const;
        void add_uniform(Tag, Uniform *);
+       void mark_dirty(Mask);
 public:
        void uniform(Tag, const Uniform &);
        void uniform(Tag, int);
@@ -183,33 +188,25 @@ public:
        void uniform2(Tag, const float *);
        void uniform(Tag, int, int, int);
        void uniform(Tag, float, float, float);
-       void uniform(Tag, const Vector3 &);
        void uniform3(Tag, const int *);
        void uniform3(Tag, const float *);
        void uniform(Tag, int, int, int, int);
        void uniform(Tag, float, float, float, float);
-       void uniform(Tag, const Vector4 &);
        void uniform(Tag, const Color &);
        void uniform4(Tag, const int *);
        void uniform4(Tag, const float *);
-       void uniform(Tag, const LinAl::Matrix<float, 2, 2> &);
        void uniform_matrix2(Tag, const float *);
-       void uniform(Tag, const LinAl::Matrix<float, 2, 3> &);
        void uniform_matrix3x2(Tag, const float *);
-       void uniform(Tag, const LinAl::Matrix<float, 2, 4> &);
        void uniform_matrix4x2(Tag, const float *);
-       void uniform(Tag, const LinAl::Matrix<float, 3, 2> &);
        void uniform_matrix2x3(Tag, const float *);
-       void uniform(Tag, const LinAl::Matrix<float, 3, 3> &);
        void uniform_matrix3(Tag, const float *);
-       void uniform(Tag, const LinAl::Matrix<float, 3, 4> &);
        void uniform_matrix4x3(Tag, const float *);
-       void uniform(Tag, const LinAl::Matrix<float, 4, 2> &);
        void uniform_matrix2x4(Tag, const float *);
-       void uniform(Tag, const LinAl::Matrix<float, 4, 3> &);
        void uniform_matrix3x4(Tag, const float *);
        void uniform(Tag, const Matrix &);
        void uniform_matrix4(Tag, const float *);
+       void uniform_array(Tag, unsigned, const int *);
+       void uniform_array(Tag, unsigned, const float *);
        void uniform1_array(Tag, unsigned, const int *);
        void uniform1_array(Tag, unsigned, const float *);
        void uniform2_array(Tag, unsigned, const int *);
@@ -227,8 +224,23 @@ public:
        void uniform_matrix2x4_array(Tag, unsigned, const float *);
        void uniform_matrix3x4_array(Tag, unsigned, const float *);
        void uniform_matrix4_array(Tag, unsigned, const float *);
+
+       template<typename T, unsigned N>
+       void uniform(Tag, const LinAl::Vector<T, N> &);
+
+       template<typename T, unsigned R, unsigned C>
+       void uniform(Tag, const LinAl::Matrix<T, R, C> &);
+
+       template<typename T, unsigned N>
+       void uniform_array(Tag, unsigned, const LinAl::Vector<T, N> *);
+
+       template<typename T, unsigned R, unsigned C>
+       void uniform_array(Tag, unsigned, const LinAl::Matrix<T, R, C> *);
+
        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;
@@ -236,15 +248,32 @@ public:
 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;
+       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); }
+
+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)); }
+
+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); }
+
+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)); }
+
 } // namespace GL
 } // namespace Msp