1 #ifndef MSP_GL_PROGRAMDATA_H_
2 #define MSP_GL_PROGRAMDATA_H_
5 #include <msp/datafile/objectloader.h>
20 Stores uniform variables for shader programs. The uniforms are stored in a
21 program-independent way, and UniformBlocks are created to match the uniform
22 layouts of different programs. If multiple programs have the same layout, the
23 same block is used for them.
25 The class is optimized for an access pattern where the set of uniforms and
26 programs stays constants, with only the values changing.
31 class Loader: public DataFile::ObjectLoader<ProgramData>
34 Loader(ProgramData &);
36 void uniform1i(const std::string &, int);
37 void uniform1f(const std::string &, float);
38 void uniform2f(const std::string &, float, float);
39 void uniform3f(const std::string &, float, float, float);
40 void uniform4f(const std::string &, float, float, float, float);
55 std::map<unsigned, const Uniform *const *> uniforms;
60 typedef std::map<std::string, Uniform *> UniformMap;
61 typedef std::map<unsigned, Block> BlockMap;
63 // XXX All these mutables are a bit silly, but I'm out of better ideas
65 mutable BlockMap blocks;
66 mutable UniformBlock *last_block;
67 mutable Buffer *buffer;
68 mutable Changes changes;
72 ProgramData(const ProgramData &);
73 ProgramData &operator=(const ProgramData &);
77 void uniform(const std::string &, Uniform *);
79 void uniform(const std::string &, int);
80 void uniform(const std::string &, float);
81 void uniform(const std::string &, float, float);
82 void uniform2(const std::string &, const float *);
83 void uniform(const std::string &, float, float, float);
84 void uniform(const std::string &, const Vector3 &);
85 void uniform3(const std::string &, const float *);
86 void uniform(const std::string &, float, float, float, float);
87 void uniform(const std::string &, const Vector4 &);
88 void uniform(const std::string &, const Color &);
89 void uniform4(const std::string &, const float *);
90 void uniform_matrix2(const std::string &, const float *);
91 void uniform_matrix3(const std::string &, const float *);
92 void uniform(const std::string &, const Matrix &);
93 void uniform_matrix4(const std::string &, const float *);
94 void uniform1_array(const std::string &, unsigned, const float *);
95 void uniform2_array(const std::string &, unsigned, const float *);
96 void uniform3_array(const std::string &, unsigned, const float *);
97 void uniform4_array(const std::string &, unsigned, const float *);
98 void uniform_matrix4_array(const std::string &, unsigned, const float *);
101 void find_uniforms_for_block(Block &, const Program::UniformBlockInfo &) const;
102 UniformBlock *create_block(const Program::UniformBlockInfo &) const;
103 const UniformBlock *get_block(const Program &, const Program::UniformBlockInfo *) const;
106 /** Returns a UniformBlock matching the program's layout. If name is empty,
107 uniforms for the default uniform block (outside any uniform block
108 declarations) are returned. */
109 const UniformBlock *get_block(const Program &prog, const std::string &name) const;
111 /// Creates blocks for the currently bound program and applies them.