Cogs.Core
Public Member Functions | Public Attributes | List of all members
Cogs::Core::MaterialPropertyBuffer Struct Reference

Material property buffers contain properties for a material, such as color, reflectiveness or other values, packed into a buffer for easy data management in the renderer. More...

#include <MaterialPropertyBuffer.h>

Inheritance diagram for Cogs::Core::MaterialPropertyBuffer:
Cogs::Core::MaterialPropertyBufferInstance

Public Member Functions

COGSCORE_DLL_API MaterialPropertyDescriptor addProperty (size_t propertyAlignment, size_t propertySize, const uint8_t *data)
 Add the value pointed to by data, with the given propertySize, to the buffer.
 
COGSCORE_DLL_API void finalize (Context *context)
 
MaterialPropertyDescriptor addProperty (const bool &data)
 
MaterialPropertyDescriptor addProperty (const float &data)
 
MaterialPropertyDescriptor addProperty (const int &data)
 
MaterialPropertyDescriptor addProperty (const glm::ivec2 &data)
 
MaterialPropertyDescriptor addProperty (const glm::ivec3 &data)
 
MaterialPropertyDescriptor addProperty (const glm::ivec4 &data)
 
MaterialPropertyDescriptor addProperty (const glm::vec2 &data)
 
MaterialPropertyDescriptor addProperty (const glm::vec3 &data)
 
MaterialPropertyDescriptor addProperty (const glm::vec4 &data)
 
MaterialPropertyDescriptor addProperty (const glm::mat4 &data)
 
MaterialPropertyDescriptor addProperty (const uint32_t &data)
 
MaterialPropertyDescriptor addProperty (const glm::uvec2 &data)
 
MaterialPropertyDescriptor addProperty (const glm::uvec3 &data)
 
MaterialPropertyDescriptor addProperty (const glm::uvec4 &data)
 
COGSCORE_DLL_API void setValue (size_t offset, size_t propertySize, const uint8_t *data)
 Set the property value for the property located at offset to that pointed to by data.
 
void setValue (const MaterialPropertyDescriptor &descriptor, const uint8_t *data)
 
template<typename T >
void setValue (size_t offset, const T &value)
 Set the property value for the property located at offset to the value given.
 
template<typename T >
const T & getValue (size_t offset) const
 Get the property value of type T located at offset.
 
template<>
void setValue (size_t offset, const bool &boolValue)
 
template<>
const bool & getValue (size_t offset) const
 

Public Attributes

std::vector< uint8_t > content
 Default content for property buffer instances created from this buffer.
 
ConstantBufferKey index
 Index of the buffer in the set of buffers owned by the same Material.
 
PropertyName name
 Name used to refer to the buffer in shaders.
 
size_t size = 0
 Total size of the buffer in bytes.
 
bool isPerInstance = true
 If the buffer is updated per instance.
 
size_t generation = 1
 Generation counter.
 

Detailed Description

Material property buffers contain properties for a material, such as color, reflectiveness or other values, packed into a buffer for easy data management in the renderer.

When constructing a property buffer manually for use with an Effect, take care ensuring the layout of the buffer matches that of the corresponding constant/uniform layout declared in the shaders used by the effect.

Only simple structures supported by GPU shaders can be stored as properties, such as integers, floats, vec2s and vec4 structures. Using vec3 or other three-component structures is discouraged as these will always be padded in the structure layout anyways.

Material property buffers are never directly used by the Renderer, which will always read buffer contents from MaterialPropertyBufferInstance objects.

Definition at line 41 of file MaterialPropertyBuffer.h.

Member Function Documentation

◆ addProperty() [1/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const bool &  data)
inline

Definition at line 61 of file MaterialPropertyBuffer.h.

◆ addProperty() [2/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const float &  data)
inline

Definition at line 67 of file MaterialPropertyBuffer.h.

◆ addProperty() [3/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::ivec2 &  data)
inline

Definition at line 77 of file MaterialPropertyBuffer.h.

◆ addProperty() [4/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::ivec3 &  data)
inline

Definition at line 82 of file MaterialPropertyBuffer.h.

◆ addProperty() [5/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::ivec4 &  data)
inline

Definition at line 87 of file MaterialPropertyBuffer.h.

◆ addProperty() [6/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::mat4 &  data)
inline

Definition at line 107 of file MaterialPropertyBuffer.h.

◆ addProperty() [7/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::uvec2 &  data)
inline

Definition at line 117 of file MaterialPropertyBuffer.h.

◆ addProperty() [8/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::uvec3 &  data)
inline

Definition at line 122 of file MaterialPropertyBuffer.h.

◆ addProperty() [9/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::uvec4 &  data)
inline

Definition at line 127 of file MaterialPropertyBuffer.h.

◆ addProperty() [10/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::vec2 &  data)
inline

Definition at line 92 of file MaterialPropertyBuffer.h.

◆ addProperty() [11/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::vec3 &  data)
inline

Definition at line 97 of file MaterialPropertyBuffer.h.

◆ addProperty() [12/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const glm::vec4 &  data)
inline

Definition at line 102 of file MaterialPropertyBuffer.h.

◆ addProperty() [13/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const int &  data)
inline

Definition at line 72 of file MaterialPropertyBuffer.h.

◆ addProperty() [14/15]

MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( const uint32_t &  data)
inline

Definition at line 112 of file MaterialPropertyBuffer.h.

◆ addProperty() [15/15]

Cogs::Core::MaterialPropertyDescriptor Cogs::Core::MaterialPropertyBuffer::addProperty ( size_t  propertyAlignment,
size_t  propertySize,
const uint8_t *  data 
)

Add the value pointed to by data, with the given propertySize, to the buffer.

The buffer will expand its storage to at least fit the contents of data, but may be larger due to padding constraints enforced by constant buffers.

Parameters
propertySizeSize of the data type in bytes.
dataData value to set the initialized buffer storage to.
Returns
A tuple containing the offset to the start of the property in bytes, and the storage size allocated for the property.

Definition at line 22 of file MaterialPropertyBuffer.cpp.

◆ finalize()

void Cogs::Core::MaterialPropertyBuffer::finalize ( Context context)

Definition at line 39 of file MaterialPropertyBuffer.cpp.

◆ getValue() [1/2]

template<typename T >
const T & Cogs::Core::MaterialPropertyBuffer::getValue ( size_t  offset) const
inline

Get the property value of type T located at offset.

Parameters
offsetOffset in bytes from the start of the buffer.
Returns
A const reference to the property value.
Template Parameters
Typeof the property value.

Definition at line 172 of file MaterialPropertyBuffer.h.

References content.

◆ getValue() [2/2]

template<>
const bool & Cogs::Core::MaterialPropertyBuffer::getValue ( size_t  offset) const
inline

Definition at line 205 of file MaterialPropertyBuffer.h.

◆ setValue() [1/4]

void Cogs::Core::MaterialPropertyBuffer::setValue ( const MaterialPropertyDescriptor descriptor,
const uint8_t *  data 
)
inline

Definition at line 142 of file MaterialPropertyBuffer.h.

◆ setValue() [2/4]

template<>
void Cogs::Core::MaterialPropertyBuffer::setValue ( size_t  offset,
const bool &  boolValue 
)
inline

Definition at line 198 of file MaterialPropertyBuffer.h.

◆ setValue() [3/4]

template<typename T >
void Cogs::Core::MaterialPropertyBuffer::setValue ( size_t  offset,
const T &  value 
)
inline

Set the property value for the property located at offset to the value given.

Parameters
offsetOffset in bytes from the start of the buffer to the location of the first byte of the property value.
valueProperty value to copy to the buffer.
Template Parameters
TType of the property value.

Definition at line 157 of file MaterialPropertyBuffer.h.

References setValue().

◆ setValue() [4/4]

void Cogs::Core::MaterialPropertyBuffer::setValue ( size_t  offset,
size_t  propertySize,
const uint8_t *  data 
)

Set the property value for the property located at offset to that pointed to by data.

Parameters
offsetOffset in bytes from the start of the buffer to the location of the first byte of the property value.
propertySizeSize of the property in bytes, the number of bytes to copy from data.
dataPointer to a property value to copy from.

Definition at line 11 of file MaterialPropertyBuffer.cpp.

References content, and generation.

Referenced by setValue().

Member Data Documentation

◆ content

std::vector<uint8_t> Cogs::Core::MaterialPropertyBuffer::content

Default content for property buffer instances created from this buffer.

Definition at line 178 of file MaterialPropertyBuffer.h.

Referenced by getValue(), and setValue().

◆ generation

size_t Cogs::Core::MaterialPropertyBuffer::generation = 1

Generation counter.

Definition at line 193 of file MaterialPropertyBuffer.h.

Referenced by setValue().

◆ index

ConstantBufferKey Cogs::Core::MaterialPropertyBuffer::index

Index of the buffer in the set of buffers owned by the same Material.

Definition at line 181 of file MaterialPropertyBuffer.h.

◆ isPerInstance

bool Cogs::Core::MaterialPropertyBuffer::isPerInstance = true

If the buffer is updated per instance.

Definition at line 190 of file MaterialPropertyBuffer.h.

◆ name

PropertyName Cogs::Core::MaterialPropertyBuffer::name

Name used to refer to the buffer in shaders.

Definition at line 184 of file MaterialPropertyBuffer.h.

◆ size

size_t Cogs::Core::MaterialPropertyBuffer::size = 0

Total size of the buffer in bytes.

Definition at line 187 of file MaterialPropertyBuffer.h.


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