Ocular Engine
UniformBuffer.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_GRAPHICS_UNIFORM_BUFFER_H__
19 #define __H__OCULAR_GRAPHICS_UNIFORM_BUFFER_H__
20 
21 #include "Uniform.hpp"
22 #include <vector>
23 
24 //------------------------------------------------------------------------------------------
25 
30 namespace Ocular
31 {
36  namespace Graphics
37  {
38  struct UniformPerFrame;
39  struct UniformPerCamera;
40  struct UniformPerObject;
41 
42  enum class UniformBufferType : uint32_t
43  {
44  PerFrame = 0,
45  PerCamera,
46  PerObject,
47  PerMaterial
48  };
49 
74  {
75  public:
76 
77  UniformBuffer(UniformBufferType type);
78  virtual ~UniformBuffer();
79 
80  virtual void bind();
81  virtual void unbind();
82 
86  void setFixedData(UniformPerFrame const& data);
87 
91  void setFixedData(UniformPerCamera const& data);
92 
96  void setFixedData(UniformPerObject const& data);
97 
101  void setUniform(Uniform const& uniform);
102 
106  Uniform const* getUniform(std::string const& name) const;
107 
111  Uniform const* getUniform(uint32_t registerIndex) const;
112 
116  std::vector<Uniform> const* getUniforms() const;
117 
121  uint32_t getNumUniforms() const;
122 
126  uint32_t getUniformsSize() const;
127 
128  protected:
129 
130  uint32_t m_Type;
131  bool m_IsDirty;
132 
133  std::vector<Uniform> m_Uniforms;
134 
135  float* m_UniformData;
136  uint32_t m_UniformDataSize;
137 
138  private:
139  };
140  }
144 }
149 //------------------------------------------------------------------------------------------
150 
151 #endif
uint32_t getNumUniforms() const
Definition: UniformBuffer.cpp:180
Definition: Uniform.hpp:43
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
float * m_UniformData
Raw, packed (16-byte) uniform data. Only modify when m_IsDirty is true and not in use by GPU...
Definition: UniformBuffer.hpp:135
std::vector< Uniform > m_Uniforms
User-friendly copy of Uniform data that is easily modifiable. Strictly CPU-only.
Definition: UniformBuffer.hpp:133
The fixed struct for all Uniform data for Cameras/Views.
Definition: UniformPerCamera.hpp:41
uint32_t getUniformsSize() const
Definition: UniformBuffer.cpp:185
void setUniform(Uniform const &uniform)
Definition: UniformBuffer.cpp:133
The fixed struct for all Uniform data for Objects.
Definition: UniformPerObject.hpp:41
uint32_t m_UniformDataSize
Size of the raw uniform data.
Definition: UniformBuffer.hpp:136
Generic buffer for storing and binding of shader uniforms.
Definition: UniformBuffer.hpp:73
The fixed struct for all global per-frame Uniform data.
Definition: UniformsPerFrame.hpp:41
Uniform const * getUniform(std::string const &name) const
Definition: UniformBuffer.cpp:147