KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::UniformBufferObject Struct Referenceabstract

Abstract class for UBO. A UBO is mostly used for shader variables, for instance projection or view matrices, which can be updated in GPU each frame. More...

#include <Buffer.h>

Inheritance diagram for Karma::UniformBufferObject:

Public Member Functions

 UniformBufferObject (std::vector< ShaderDataType > dataTypes, uint32_t bindingPointIndex)
 An agnostic constructor provided for precomputation of offset and buffer size.
 
virtual ~UniformBufferObject ()=default
 Pure virtual destructor and sub class should have appropriate implementation.
 
template<typename... T>
void UpdateUniforms (T &&... uniforms)
 Set the m_UniformList with latest supplied uniforms.
 
virtual void UploadUniformBuffer (size_t frameIndex=0)=0
 An overridable function to upload the uniform buffer.
 
uint32_t GetBufferSize () const
 
const std::vector< UBODataPointer > & GetUniformList () const
 
const std::vector< ShaderDataType > & GetUniformDataType () const
 
const std::vector< uint32_t > & GetAlignedOffsets () const
 
const std::vector< uint32_t > & GetUniformSize () const
 
uint32_t GetBindingPointIndex () const
 

Static Public Member Functions

static UniformBufferObjectCreate (std::vector< ShaderDataType > dataTypes, uint32_t bindingPointIndex)
 A function for appropriate initialization of UBO based on programmer selected rendered (Vulkan or OpenGL)
 

Protected Member Functions

void CalculateOffsetsAndBufferSize ()
 Calculate offsets and buffer size of the uniform buffer object(s).
 

Protected Attributes

uint32_t m_BufferSize
 Total size of the buffer in bytes.
 
uint32_t m_BindingPoint
 The binding point prescribed in vertex shader for instance https://github.com/ravimohan1991/KarmaEngine/blob/5ff57f5747c19efcea050646bc2d217c99d74015/Resources/Shaders/shader.vert#L14-L18.
 
std::vector< UBODataPointerm_UniformList
 List of uniforms to be uploaded.
 
std::vector< ShaderDataTypem_UniformDataType
 List of data types (ShaderDataType) for the m_UniformList.
 
std::vector< uint32_t > m_UniformAlignedOffsets
 List of individual uniform boundary aligned (with multiple of individual uniform size) offsets.
 
std::vector< uint32_t > m_UniformSizes
 List of individual uniform sizes.
 

Detailed Description

Abstract class for UBO. A UBO is mostly used for shader variables, for instance projection or view matrices, which can be updated in GPU each frame.

See also
VulkanUniformBuffer object
Since
Karma 1.0.0

Constructor & Destructor Documentation

◆ UniformBufferObject()

Karma::UniformBufferObject::UniformBufferObject ( std::vector< ShaderDataType > dataTypes,
uint32_t bindingPointIndex )

An agnostic constructor provided for precomputation of offset and buffer size.

Parameters
dataTypesSee Create for information
bindingPointIndexSee Create for information
Since
Karma 1.0.0

◆ ~UniformBufferObject()

virtual Karma::UniformBufferObject::~UniformBufferObject ( )
virtualdefault

Pure virtual destructor and sub class should have appropriate implementation.

Since
Karma 1.0.0

Member Function Documentation

◆ CalculateOffsetsAndBufferSize()

void Karma::UniformBufferObject::CalculateOffsetsAndBufferSize ( )
protected

Calculate offsets and buffer size of the uniform buffer object(s).

Basically individual uniform's offset (from the beginning) and size are computed and cached in m_UniformAlignedOffsets and m_UniformSizes list. The offsets are boundary aligned to the multiple of individual uniform size.

Since
Karma 1.0.0

◆ Create()

UniformBufferObject * Karma::UniformBufferObject::Create ( std::vector< ShaderDataType > dataTypes,
uint32_t bindingPointIndex )
static

A function for appropriate initialization of UBO based on programmer selected rendered (Vulkan or OpenGL)

Parameters
dataTypesList of data types for uniforms to be uploaded to GPU (like used in shaders), for instance https://github.com/ravimohan1991/KarmaEngine/blob/138c172ccedf31acfab982af51ae130f9a37d3bb/Application/src/KarmaApp.cpp#L39 where Mat4 are for https://github.com/ravimohan1991/KarmaEngine/blob/138c172ccedf31acfab982af51ae130f9a37d3bb/Resources/Shaders/shader.vert#L9-L13
bindingPointIndexthe binding of shader specified index

◆ UpdateUniforms()

template<typename... T>
void Karma::UniformBufferObject::UpdateUniforms ( T &&... uniforms)
inline

Set the m_UniformList with latest supplied uniforms.

See also
Material::OnUpdate
Since
Karma 1.0.0

◆ UploadUniformBuffer()

virtual void Karma::UniformBufferObject::UploadUniformBuffer ( size_t frameIndex = 0)
pure virtual

An overridable function to upload the uniform buffer.

Note
The function is pure virtual with default value provided.
Todo
Need to rewrite implementation of this virtual function because Material::ProcessForSubmission() makes agnostic call and VulkanContext::UploadUBO also makes call to upload uniform which is seperate from Material::ProcessForSubmission.
Since
Karma 1.0.0

Implemented in Karma::OpenGLUniformBuffer, and Karma::VulkanUniformBuffer.

Member Data Documentation

◆ m_BindingPoint

uint32_t Karma::UniformBufferObject::m_BindingPoint
protected

◆ m_BufferSize

uint32_t Karma::UniformBufferObject::m_BufferSize
protected

Total size of the buffer in bytes.

Since
Karma 1.0.0

◆ m_UniformAlignedOffsets

std::vector<uint32_t> Karma::UniformBufferObject::m_UniformAlignedOffsets
protected

List of individual uniform boundary aligned (with multiple of individual uniform size) offsets.

Since
Karma 1.0.0

◆ m_UniformDataType

std::vector<ShaderDataType> Karma::UniformBufferObject::m_UniformDataType
protected

List of data types (ShaderDataType) for the m_UniformList.

Since
Karma 1.0.0

◆ m_UniformList

std::vector<UBODataPointer> Karma::UniformBufferObject::m_UniformList
protected

List of uniforms to be uploaded.

Since
Karma 1.0.0

◆ m_UniformSizes

std::vector<uint32_t> Karma::UniformBufferObject::m_UniformSizes
protected

List of individual uniform sizes.

Since
Karam 1.0.0

The documentation for this struct was generated from the following files: