1 #ifndef MSP_GL_PROGRAMDATA_H_
2 #define MSP_GL_PROGRAMDATA_H_
5 #include <msp/datafile/objectloader.h>
19 Stores uniform variables for shader programs. The uniforms are stored in a
20 program-independent way, and UniformBlocks are created to match the uniform
21 layouts of different programs. If multiple programs have the same layout, the
22 same block is used for them.
24 The class is optimized for an access pattern where the set of uniforms and
25 programs stays constants, with only the values changing.
30 class Loader: public DataFile::ObjectLoader<ProgramData>
33 Loader(ProgramData &);
35 void uniform1i(const std::string &, int);
36 void uniform1f(const std::string &, float);
37 void uniform2f(const std::string &, float, float);
38 void uniform3f(const std::string &, float, float, float);
39 void uniform4f(const std::string &, float, float, float, float);
43 typedef unsigned Mask;
47 MASK_BITS = sizeof(Mask)*8,
48 ALL_ONES = static_cast<Mask>(-1)
58 SharedBlock(unsigned, UniformBlock *);
68 ProgramBlock(int, SharedBlock *);
71 struct ProgramUniforms
73 std::vector<ProgramBlock> blocks;
80 typedef std::map<std::string, unsigned> SlotMap;
81 typedef std::map<Program::LayoutHash, SharedBlock> BlockMap;
82 typedef std::map<Program::LayoutHash, ProgramUniforms> ProgramMap;
84 // XXX All these mutables are a bit silly, but I'm out of better ideas
85 SlotMap uniform_slots;
86 std::vector<Uniform *> uniforms;
87 mutable BlockMap blocks;
88 mutable ProgramMap programs;
89 mutable UniformBlock *last_block;
90 mutable Buffer *buffer;
91 mutable unsigned dirty;
95 ProgramData(const ProgramData &);
96 ProgramData &operator=(const ProgramData &);
100 void uniform(const std::string &, Uniform *);
102 void uniform(const std::string &, int);
103 void uniform(const std::string &, float);
104 void uniform(const std::string &, float, float);
105 void uniform2(const std::string &, const float *);
106 void uniform(const std::string &, float, float, float);
107 void uniform(const std::string &, const Vector3 &);
108 void uniform3(const std::string &, const float *);
109 void uniform(const std::string &, float, float, float, float);
110 void uniform(const std::string &, const Vector4 &);
111 void uniform(const std::string &, const Color &);
112 void uniform4(const std::string &, const float *);
113 void uniform(const std::string &, const LinAl::Matrix<float, 2, 2> &);
114 void uniform_matrix2(const std::string &, const float *);
115 void uniform(const std::string &, const LinAl::Matrix<float, 3, 3> &);
116 void uniform_matrix3(const std::string &, const float *);
117 void uniform(const std::string &, const Matrix &);
118 void uniform_matrix4(const std::string &, const float *);
119 void uniform1_array(const std::string &, unsigned, const int *);
120 void uniform1_array(const std::string &, unsigned, const float *);
121 void uniform2_array(const std::string &, unsigned, const float *);
122 void uniform3_array(const std::string &, unsigned, const float *);
123 void uniform4_array(const std::string &, unsigned, const float *);
124 void uniform_matrix4_array(const std::string &, unsigned, const float *);
127 unsigned compute_slot_mask(const Program::UniformBlockInfo &) const;
128 void update_block(UniformBlock &, const Program::UniformBlockInfo &) const;
129 SharedBlock *get_shared_block(const Program::UniformBlockInfo &) const;
132 /** Applies uniform blocks for the currently bound program, creating them