Ocular Engine
|
D3D11 implementation of a UniformBuffer (ie Shader Constant Buffer) More...
#include <D3D11UniformBuffer.hpp>
Public Member Functions | |
D3D11UniformBuffer (UniformBufferType type, ID3D11Device *device, ID3D11DeviceContext *context) | |
virtual void | bind () override |
virtual void | unbind () override |
![]() | |
UniformBuffer (UniformBufferType type) | |
void | setFixedData (UniformPerFrame const &data) |
void | setFixedData (UniformPerCamera const &data) |
void | setFixedData (UniformPerObject const &data) |
void | setUniform (Uniform const &uniform) |
Uniform const * | getUniform (std::string const &name) const |
Uniform const * | getUniform (uint32_t registerIndex) const |
std::vector< Uniform > const * | getUniforms () const |
uint32_t | getNumUniforms () const |
uint32_t | getUniformsSize () const |
Protected Member Functions | |
void | packUniformData () |
void | packDynamicUniformData () |
void | packFixedUniformData () |
void | buildD3DBuffer () |
void | updateD3DBuffer () |
Protected Attributes | |
ID3D11Device * | m_D3DDevice |
ID3D11DeviceContext * | m_D3DDeviceContext |
ID3D11Buffer * | m_D3DBuffer |
![]() | |
uint32_t | m_Type |
bool | m_IsDirty |
std::vector< Uniform > | m_Uniforms |
User-friendly copy of Uniform data that is easily modifiable. Strictly CPU-only. | |
float * | m_UniformData |
Raw, packed (16-byte) uniform data. Only modify when m_IsDirty is true and not in use by GPU. | |
uint32_t | m_UniformDataSize |
Size of the raw uniform data. | |
D3D11 implementation of a UniformBuffer (ie Shader Constant Buffer)
|
overridevirtual |
Currently binds automatically to both Vertex and Fragment stages.
The issue here is that the CameraManger is requesting to create UniformBuffer objects inside the main OcularEngine initialization method. But at that point, OcularGraphics has not been fully initialized (only created) as the driver requires a window to have been created to use the HWND during D3D11 setup.
Reimplemented from Ocular::Graphics::UniformBuffer.
|
protected |
This method most likely could be placed in the UniformBuffer class. But, there is potentially some very-API specific packing going on here.
For D3D11, everything must be packed along 16-byte registers and this behaviour may or may not be the same for OpenGL (have not yet gotten to writing the GL4 library, and it's been several years since using OpenGL).
If OpenGL ends up having identical requirements, then this method will be migrated to the parent UniformBuffer class.
Here we pack everything along 16-byte sections of the raw data array. This means that padding will need to be added for both single-float uniform values and for Matrix3x3 values.
Examples:
float -> {value, padding, padding , padding} Vector4f -> {value.x, value.y, value.z, value.w} (also Color) Matrix3x3 -> {value[0][0], value[0][1], value[0][2], padding, value[1][0], value[1][1], value[1][2], padding, value[2][0], value[2][1], value[2][2], padding} Matrix4x4 -> {value[0][0], value[0][1], value[0][2], value[0][3], value[1][0], value[1][1], value[1][2], value[1][3], value[2][0], value[2][1], value[2][2], value[2][3], value[3][0], value[3][1], value[3][2], value[3][3]}