Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::Uniform Class Reference

The Uniform class wraps a bgfx::UniformHandle and provides a simple interface to set the uniform data. More...

#include <vclib/bgfx/uniform.h>

Public Member Functions

uint16_t arraySize () const
 Returns the array size of the uniform (number of elements for array uniforms, 1 for non-array uniforms).
 
void bind (const void *data) const
 Sets the uniform data for the current shader program.
 
void bind (const void *data, uint16_t numElements) const
 Sets the uniform data for the current shader program, specifying the number of elements for array uniforms.
 
bgfx::UniformHandle handle () const
 Returns the underlying bgfx::UniformHandle.
 
bool isValid () const
 Checks if the Uniform is valid (i.e., if it has a valid bgfx::UniformHandle).
 
const std::string & name () const
 Returns the name of the uniform.
 
Uniformoperator= (const Uniform &oth)=delete
 
Uniformoperator= (Uniform &&oth)
 Move assignment operator.
 
void swap (Uniform &oth)
 Swaps the content of this Uniform with another.
 
bgfx::UniformType::Enum type () const
 Returns the type of the uniform.
 
 Uniform ()=default
 Default constructor. Creates an invalid Uniform.
 
 Uniform (const std::string &name, bgfx::UniformType::Enum type, uint16_t size=1)
 Creates a new shader uniform.
 
 Uniform (const Uniform &oth)=delete
 
 Uniform (Uniform &&oth)
 Move constructor.
 
 ~Uniform ()
 Destructor. Destroys the underlying bgfx::UniformHandle.
 

Private Attributes

uint16_t mArraySize = 1
 
bgfx::UniformHandle mUniformHandle = BGFX_INVALID_HANDLE
 
std::string mUniformName
 
bgfx::UniformType::Enum mUniformType = bgfx::UniformType::Count
 

Friends

void swap (Uniform &a, Uniform &b)
 Swaps two Uniform objects.
 

Detailed Description

The Uniform class wraps a bgfx::UniformHandle and provides a simple interface to set the uniform data.

It manages the lifetime of the bgfx::UniformHandle: each instance of this class creates a new bgfx::UniformHandle and destroys it when the instance goes out of scope. This simplifies resource management for shader uniforms.

Constructor & Destructor Documentation

◆ Uniform() [1/2]

vcl::Uniform::Uniform ( const std::string &  name,
bgfx::UniformType::Enum  type,
uint16_t  size = 1 
)
inline

Creates a new shader uniform.

Parameters
[in]nameThe name of the uniform. It must match the name used in the shader.
[in]typeThe data type of the uniform.
[in]sizeThe number of elements for array uniforms (default is 1 for non-array uniforms).

◆ Uniform() [2/2]

vcl::Uniform::Uniform ( Uniform &&  oth)
inline

Move constructor.

Parameters
[in]othThe Uniform to move from.

Member Function Documentation

◆ arraySize()

uint16_t vcl::Uniform::arraySize ( ) const
inline

Returns the array size of the uniform (number of elements for array uniforms, 1 for non-array uniforms).

Returns
The uniform's array size.

◆ bind() [1/2]

void vcl::Uniform::bind ( const void data) const
inline

Sets the uniform data for the current shader program.

This function should be called after a shader program has been set with bgfx::submit(). The data pointer must point to a memory block that matches the uniform's type and size.

Parameters
[in]dataA pointer to the uniform data.

◆ bind() [2/2]

void vcl::Uniform::bind ( const void data,
uint16_t  numElements 
) const
inline

Sets the uniform data for the current shader program, specifying the number of elements for array uniforms.

This function should be called after a shader program has been set with bgfx::submit(). The data pointer must point to a memory block that matches the uniform's type and size. The numElements parameter specifies how many elements of the array uniform to set (for non-array uniforms, this should be 1).

Parameters
[in]dataA pointer to the uniform data.
[in]numElementsThe number of elements to set for array uniforms.

◆ handle()

bgfx::UniformHandle vcl::Uniform::handle ( ) const
inline

Returns the underlying bgfx::UniformHandle.

Returns
The handle to the uniform.

◆ isValid()

bool vcl::Uniform::isValid ( ) const
inline

Checks if the Uniform is valid (i.e., if it has a valid bgfx::UniformHandle).

Returns
true if the Uniform is valid, false otherwise.

◆ name()

const std::string & vcl::Uniform::name ( ) const
inline

Returns the name of the uniform.

Returns
The uniform's name.

◆ operator=()

Uniform & vcl::Uniform::operator= ( Uniform &&  oth)
inline

Move assignment operator.

Parameters
[in]othThe Uniform to move from.
Returns
A reference to this Uniform.

◆ swap()

void vcl::Uniform::swap ( Uniform oth)
inline

Swaps the content of this Uniform with another.

Parameters
[in]othThe other Uniform to swap with.

◆ type()

bgfx::UniformType::Enum vcl::Uniform::type ( ) const
inline

Returns the type of the uniform.

Returns
The uniform's type.

Friends And Related Symbol Documentation

◆ swap

void swap ( Uniform a,
Uniform b 
)
friend

Swaps two Uniform objects.

Parameters
[in]aThe first Uniform.
[in]bThe second Uniform.

The documentation for this class was generated from the following file: