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