]> git.tdb.fi Git - libs/gl.git/blob - source/core/uniformblock.h
Split reflection data from Program to a separate struct
[libs/gl.git] / source / core / uniformblock.h
1 #ifndef MSP_GL_UNIFORMBLOCK_H_
2 #define MSP_GL_UNIFORMBLOCK_H_
3
4 #include <map>
5 #include <vector>
6 #include <msp/core/noncopyable.h>
7 #include "bufferable.h"
8 #include "reflectdata.h"
9 #include "vector.h"
10
11 namespace Msp {
12 namespace GL {
13
14 class BufferRange;
15 class Matrix;
16 class Uniform;
17 struct Color;
18
19 /**
20 Stores uniforms with a specific layout.  Both named and default uniform blocks
21 are supported.
22 */
23 class UniformBlock: public NonCopyable
24 {
25 protected:
26         UniformBlock() { }
27 public:
28         virtual ~UniformBlock() { }
29
30         virtual void attach(const ReflectData::UniformInfo &, const Uniform &) = 0;
31 };
32
33 /** Stores uniforms for the default uniform block.  Uniforms are associated
34 with locations, as returned by Program::get_uniform_location. */
35 class DefaultUniformBlock: public UniformBlock
36 {
37 private:
38         std::vector<const Uniform *> uniforms;
39
40 public:
41         DefaultUniformBlock();
42
43         virtual void attach(const ReflectData::UniformInfo &, const Uniform &);
44         void attach(int, const Uniform &);
45         void apply() const;
46 };
47
48 /** Stores uniforms for a buffer-backed uniform block.  Uniform values are
49 stored in a memory block which can be uploaded into a buffer and bound for use
50 by a Program. */
51 class BufferBackedUniformBlock: public UniformBlock, public Bufferable
52 {
53 private:
54         unsigned size;
55         std::vector<char> data;
56
57 public:
58         BufferBackedUniformBlock(unsigned);
59
60         virtual unsigned get_data_size() const { return size; }
61 private:
62         virtual const void *get_data_pointer() const { return &data[0]; }
63         virtual unsigned get_alignment() const;
64
65 public:
66         void attach(const ReflectData::UniformInfo &, const Uniform &);
67 };
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif