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

void bind (const void *data) const
 Sets the uniform data for the current shader program.
 
bgfx::UniformHandle handle () const
 Returns the underlying 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)
 Creates a new shader uniform.
 
 Uniform (const Uniform &oth)=delete
 
 Uniform (Uniform &&oth)
 Move constructor.
 
 ~Uniform ()
 Destructor. Destroys the underlying bgfx::UniformHandle.
 

Static Public Member Functions

static uint floatToUintBits (float f)
 Utility function to reinterpret the bits of a float as an unsigned integer.
 
static float uintBitsToFloat (uint bits)
 Utility function to reinterpret the bits of an unsigned integer as a float.
 

Private Attributes

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 
)
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.

◆ Uniform() [2/2]

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

Move constructor.

Parameters
[in]othThe Uniform to move from.

Member Function Documentation

◆ bind()

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.

◆ floatToUintBits()

static uint vcl::Uniform::floatToUintBits ( float  f)
inlinestatic

Utility function to reinterpret the bits of a float as an unsigned integer.

Parameters
[in]fThe float to convert.
Returns
The unsigned integer with the same bit representation.

◆ handle()

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

Returns the underlying bgfx::UniformHandle.

Returns
The handle to the uniform.

◆ 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.

◆ uintBitsToFloat()

static float vcl::Uniform::uintBitsToFloat ( uint  bits)
inlinestatic

Utility function to reinterpret the bits of an unsigned integer as a float.

Parameters
[in]bitsThe unsigned integer to convert.
Returns
The float value with the same bit representation.

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: