Defold Learn logo


Component render constants

Api for setting and updating component render constants

Namespace: dmGameSystem
Include: #include <dmsdk/gamesys/render_constants.h>
TYPES
CompGetConstantCallback Used in GetMaterialConstant to resolve a render co...
CompSetConstantCallback Used in SetMaterialConstant to set a render consta...
HashState32 Found in hash.h
HComponentRenderConstants Render constants handle
FUNCTIONS
int AreRenderConstantsUpdated (dmGameSystem::HComponentRenderConstants constants) check if the constants have changed
int ClearRenderConstant (dmGameSystem::HComponentRenderConstants constants, dmhash_t name_hash) Removes a render constant from the container
dmGameSystem::HComponentRenderConstants CreateRenderConstants () Create a new HComponentRenderConstants container
void DestroyRenderConstants (dmGameSystem::HComponentRenderConstants constants) Destroys a render constants container
void EnableRenderObjectConstants (dmRender::RenderObject* ro, dmGameSystem::HComponentRenderConstants constants) set the constants of a render object
dmGameObject::PropertyResult GetMaterialConstant (dmRender::HMaterial material, dmhash_t name_hash, int32_t value_index, dmGameObject::PropertyDesc& out_desc, bool use_value_ptr, CompGetConstantCallback callback, void* callback_user_data) Helper function to get material constants of compo...
bool GetRenderConstant (dmGameSystem::HComponentRenderConstants constants, dmhash_t name_hash, dmRender::Constant** out_constant) Destroys a render constants container
dmRender::HConstant GetRenderConstant (dmGameSystem::HComponentRenderConstants constants, uint32_t index) Get a render constant by index
uint32_t GetRenderConstantCount (dmGameSystem::HComponentRenderConstants constants) Get the number of render constants
void HashRenderConstants (dmGameSystem::HComponentRenderConstants constants, HashState32* state) Hashes the constants
dmGameObject::PropertyResult SetMaterialConstant (dmRender::HMaterial material, dmhash_t name_hash, uint32_t value_index, dmGameObject::PropertyVar var, CompGetConstantCallback callback, void* callback_user_data) Helper function to set material constants of compo...
void SetRenderConstant (dmGameSystem::HComponentRenderConstants constants, dmRender::HMaterial material, dmhash_t name_hash, uint32_t value_index, uint32_t* element_index, const dmGameObject::PropertyVar& var) Set a render constant by name. The constant must e...
void SetRenderConstant (dmGameSystem::HComponentRenderConstants constants, dmhash_t name_hash, dmVMath::Vector4* values, uint32_t num_values) Set a render constant by name. The constant must e...

Functions

AreRenderConstantsUpdated

int AreRenderConstantsUpdated(dmGameSystem::HComponentRenderConstants constants)

check if the constants have changed

PARAMETERS

dmGameSystem::HComponentRenderConstants constants the constants

RETURNS

int non zero if the constants were changed

ClearRenderConstant

int ClearRenderConstant(dmGameSystem::HComponentRenderConstants constants, dmhash_t name_hash)

Removes a render constant from the container

PARAMETERS

dmGameSystem::HComponentRenderConstants constants the constants
dmhash_t name_hash the hashed name of the constant

RETURNS

int non zero if the constant was removed

CreateRenderConstants

dmGameSystem::HComponentRenderConstants CreateRenderConstants()

Create a new HComponentRenderConstants container

PARAMETERS

RETURNS

dmGameSystem::HComponentRenderConstants

DestroyRenderConstants

void DestroyRenderConstants(dmGameSystem::HComponentRenderConstants constants)

Destroys a render constants container

PARAMETERS

dmGameSystem::HComponentRenderConstants constants (must not be 0)

EnableRenderObjectConstants

void EnableRenderObjectConstants(dmRender::RenderObject* ro, dmGameSystem::HComponentRenderConstants constants)

set the constants of a render object

PARAMETERS

dmRender::RenderObject* ro the render object
dmGameSystem::HComponentRenderConstants constants the constants

GetMaterialConstant

dmGameObject::PropertyResult GetMaterialConstant(dmRender::HMaterial material, dmhash_t name_hash, int32_t value_index, dmGameObject::PropertyDesc& out_desc, bool use_value_ptr, CompGetConstantCallback callback, void* callback_user_data)

Helper function to get material constants of components that use them: sprite, label, tile maps, spine and models Sprite and Label should not use value ptr. Deleting a gameobject (that included sprite(s) or label(s)) will rearrange the object pool for components (due to EraseSwap in the Free for the object pool). This result in the original animation value pointer will still point to the original memory location in the component object pool.

PARAMETERS

dmRender::HMaterial material the material
dmhash_t name_hash the name of the property
int32_t value_index the index of the constant value to get, if it is an array
dmGameObject::PropertyDesc& out_desc the property descriptor
bool use_value_ptr should the property pointer be used (m_ValuePtr)
CompGetConstantCallback callback callback to resolve property
void* callback_user_data callback user data

RETURNS

dmGameObject::PropertyResult the result

GetRenderConstant

bool GetRenderConstant(dmGameSystem::HComponentRenderConstants constants, dmhash_t name_hash, dmRender::Constant** out_constant)

Destroys a render constants container

PARAMETERS

dmGameSystem::HComponentRenderConstants constants the constants
dmhash_t name_hash the hashed name of the property
dmRender::Constant** out_constant the pointer where to store the constant

RETURNS

bool returns true if the constant exists

GetRenderConstant

dmRender::HConstant GetRenderConstant(dmGameSystem::HComponentRenderConstants constants, uint32_t index)

Get a render constant by index

PARAMETERS

dmGameSystem::HComponentRenderConstants constants the constants
uint32_t index the index

RETURNS

dmRender::HConstant the pointer where to store the constant

GetRenderConstantCount

uint32_t GetRenderConstantCount(dmGameSystem::HComponentRenderConstants constants)

Get the number of render constants

PARAMETERS

dmGameSystem::HComponentRenderConstants constants the constants

RETURNS

uint32_t returns the number of set constants

HashRenderConstants

void HashRenderConstants(dmGameSystem::HComponentRenderConstants constants, HashState32* state)

Hashes the constants

PARAMETERS

dmGameSystem::HComponentRenderConstants constants the constants
HashState32* state the hash state to update

SetMaterialConstant

dmGameObject::PropertyResult SetMaterialConstant(dmRender::HMaterial material, dmhash_t name_hash, uint32_t value_index, dmGameObject::PropertyVar var, CompGetConstantCallback callback, void* callback_user_data)

Helper function to set material constants of components that use them: sprite, label, tile maps, spine and models

PARAMETERS

dmRender::HMaterial material the material
dmhash_t name_hash the name of the property
uint32_t value_index index of the constant value to set, if the material constant is an array
dmGameObject::PropertyVar var the property
CompGetConstantCallback callback the callback used to set the property
void* callback_user_data callback user data

RETURNS

dmGameObject::PropertyResult the result

SetRenderConstant

void SetRenderConstant(dmGameSystem::HComponentRenderConstants constants, dmRender::HMaterial material, dmhash_t name_hash, uint32_t value_index, uint32_t* element_index, const dmGameObject::PropertyVar& var)

Set a render constant by name. The constant must exist in the material

PARAMETERS

dmGameSystem::HComponentRenderConstants constants the render constants buffer
dmRender::HMaterial material the material to get default values from if constant didn't already exist in the render constants buffer
dmhash_t name_hash the hashed name of the constant
uint32_t value_index index of the constant value to set, if the constant is an array
uint32_t* element_index pointer to the index of the element (in range [0,3]). May be 0
const dmGameObject::PropertyVar& var the constant value

SetRenderConstant

void SetRenderConstant(dmGameSystem::HComponentRenderConstants constants, dmhash_t name_hash, dmVMath::Vector4* values, uint32_t num_values)

Set a render constant by name. The constant must exist in the material

PARAMETERS

dmGameSystem::HComponentRenderConstants constants the constants
dmhash_t name_hash the hashed name of the constant
dmVMath::Vector4* values the values
uint32_t num_values number of values in the array

Types

CompGetConstantCallback

void CompGetConstantCallback()

Used in GetMaterialConstant to resolve a render constant's value

PARAMETERS



CompSetConstantCallback

void CompSetConstantCallback()

Used in SetMaterialConstant to set a render constant's value

PARAMETERS



HashState32

void HashState32()

Found in hash.h

PARAMETERS



HComponentRenderConstants

void HComponentRenderConstants()

Render constants handle

PARAMETERS