HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RE_UniformBlock Class Reference

#include <RE_UniformBlock.h>

+ Inheritance diagram for RE_UniformBlock:

Public Member Functions

 RE_UniformBlock (const char *name=NULL)
 
 ~RE_UniformBlock ()
 
int64 getMemoryUsage (bool inclusive) const
 
const char * getName () const
 Name of the uniform block (uniform <name> { } ) More...
 
void setInstanceName (const char *name)
 
const char * getInstanceName () const
 Optional instance name of the uniform block (uniform block { } <name>) More...
 
int getArrayLength () const
 Array length of variably sized arrays (for GL4 SSBOs). More...
 
RE_UniformBlockduplicate (bool block_data_too=true) const
 
RE_UniformBlockarrayDuplicate (int array_size) const
 
bool isCompatible (const RE_UniformBlock *block) const
 returns true if 'block' shares the same size and structure as this block More...
 
int getSizeB () const
 Size of the underlying GL buffer. More...
 
bool hasUniform (const char *name) const
 Returns true if this block has a member variable called 'name'. More...
 
int getNumUniforms () const
 Number of member variables in the uniform block. More...
 
const char * getUniformName (int index) const
 Returns the name of the member variable at 'index'. More...
 
int getUniformShaderIndex (int index) const
 Which UBO or SSBO index this uniform block was created for. More...
 
bool bindInt (const char *name, int v, int array_index=0)
 
bool bindFloat (const char *name, fpreal32 v, int array_index=0)
 Bind a single float value. More...
 
bool bindDouble (const char *name, fpreal64 v, int array_index=0)
 Bind a single double value. GPU must support native FP64 values. More...
 
bool bindUint64 (const char *name, uint64 v, int array_index=0)
 
bool bindInts (const char *name, const int *valarray, int array_size, int array_index=0)
 Set values for a fixed-length integer array. More...
 
bool bindFloats (const char *name, const fpreal32 *valarray, int array_size, int array_index=0)
 Set values for a fixed-length float array. More...
 
bool bindDoubles (const char *name, const fpreal64 *valarray, int array_size, int array_index=0)
 Set values for a fixed-length double array. More...
 
bool bindUint64s (const char *name, const uint64 *valarray, int array_size, int array_index=0)
 Set values for a uint64 handle array. More...
 
bool bindIntVector3 (const char *name, const int *valarray, int array_size, int array_index=0)
 bind a series of ivec3s, using std140 packing (padded to ivec4) More...
 
bool bindVector3 (const char *name, const fpreal32 *valarray, int array_size, int array_index=0)
 bind a series of vec3s, using std140 packing (padded to ivec4) More...
 
bool bindDVector3 (const char *name, const fpreal64 *valarray, int array_size, int array_index=0)
 bind a series of dvec3s, using std140 packing (padded to ivec4) More...
 
bool bindVector (const char *name, const UT_Vector2F &v, int array_index=0)
 Bind a single vec2 uniform value. More...
 
bool bindVector (const char *name, const UT_Vector3F &v, int array_index=0)
 Bind a single vec3 uniform value. More...
 
bool bindVector (const char *name, const UT_Vector4F &v, int array_index=0)
 Bind a single vec4 uniform value. More...
 
bool bindVector (const char *name, const UT_Vector2D &v, int array_index=0)
 Bind a single dvec2 uniform value. More...
 
bool bindVector (const char *name, const UT_Vector3D &v, int array_index=0)
 Set a single dvec3 uniform value. More...
 
bool bindVector (const char *name, const UT_Vector4D &v, int array_index=0)
 Set a single dvec4 uniform value. More...
 
bool bindMatrix (const char *name, const UT_Matrix2F &m, int array_index=0)
 Set a single 2x2 matrix value. More...
 
bool bindMatrix (const char *name, const UT_Matrix3F &m, int array_index=0)
 Set a single 3x3 matrix value. More...
 
bool bindMatrix (const char *name, const UT_Matrix4F &m, int array_index=0)
 Set a single 4x4 matrix value. More...
 
bool bindMatrix (const char *name, const UT_Matrix2D &m, int array_index=0)
 Set a single 2x2 matrix value (dmat2). More...
 
bool bindMatrix (const char *name, const UT_Matrix3D &m, int array_index=0)
 Set a single 3x3 matrix value (dmat3). More...
 
bool bindMatrix (const char *name, const UT_Matrix4D &m, int array_index=0)
 Set a single 4x4 matrix value (dmat4). More...
 
void uploadBuffer (RE_Render *r)
 
void downloadBuffer (RE_Render *r)
 
int getID () const
 
void print (std::ostream *os=NULL)
 Debug printout of the block, including currently bound values. More...
 
void setName (const char *name)
 
void setSize (int bytes)
 Size of the underlying GL buffer, in bytes. Generally set by the shader. More...
 
void addUniform (const char *name, RE_UniformType type, int array_size, int offset, int location, int top_array_size, int top_array_stride)
 
void clearUniforms ()
 
void setBufferSizes (int fixed_size_bytes, int variable_size_bytes)
 
bool updateBlock (RE_UniformBlock *b, const RE_Shader *sh) const
 
bool isDirty () const
 Whether this block requires uploading to the GPU. More...
 
void setInitializedFor (const RE_Shader *sh)
 Which shader this block is currently laid out for. More...
 
bool isInitializedFor (const RE_Shader *sh) const
 Which shader this block is currently laid out for. More...
 
const RE_ShadergetInitializedShader () const
 Which shader this block is currently laid out for. More...
 
void setOriginProgramID (int pid)
 Program ID of the program this block was created from. More...
 
- Public Member Functions inherited from UT_IntrusiveRefCounter< RE_UniformBlock >
SYS_FORCE_INLINE UT_IntrusiveRefCounter ()
 Default constructor: Sets counter to 0. More...
 
SYS_FORCE_INLINE UT_IntrusiveRefCounter (const UT_IntrusiveRefCounter &)
 Copy constructor: Sets counter to 0. More...
 
UT_IntrusiveRefCounteroperator= (const UT_IntrusiveRefCounter &)
 Assignment operator: Does not modify counter. More...
 
SYS_FORCE_INLINE uint32 use_count () const
 Return current counter. More...
 

Static Public Member Functions

static void dirtyAllUniformBlocks ()
 

Additional Inherited Members

- Protected Member Functions inherited from UT_IntrusiveRefCounter< RE_UniformBlock >
SYS_FORCE_INLINE ~UT_IntrusiveRefCounter ()
 Destructor: Only derived classes can destruct this. More...
 

Detailed Description

A uniform block is a structure of uniforms used by a GLSL shader. This class can represent either a Uniform Buffer Object (UBO) or a Shader Storage Buffer Objects (SSBO, GL4.3).

Definition at line 28 of file RE_UniformBlock.h.

Constructor & Destructor Documentation

RE_UniformBlock::RE_UniformBlock ( const char *  name = NULL)
explicit
RE_UniformBlock::~RE_UniformBlock ( )

Member Function Documentation

void RE_UniformBlock::addUniform ( const char *  name,
RE_UniformType  type,
int  array_size,
int  offset,
int  location,
int  top_array_size,
int  top_array_stride 
)

Called during shader intitialization to layout the structure of this block.

RE_UniformBlock* RE_UniformBlock::arrayDuplicate ( int  array_size) const

Create a new shader storage block, specifying an array size for array member data with an unspecified array size. If there are no arrays with unspecified bounds, array_size is ignored. Data is left uninitialized.

bool RE_UniformBlock::bindDouble ( const char *  name,
fpreal64  v,
int  array_index = 0 
)

Bind a single double value. GPU must support native FP64 values.

bool RE_UniformBlock::bindDoubles ( const char *  name,
const fpreal64 valarray,
int  array_size,
int  array_index = 0 
)

Set values for a fixed-length double array.

bool RE_UniformBlock::bindDVector3 ( const char *  name,
const fpreal64 valarray,
int  array_size,
int  array_index = 0 
)

bind a series of dvec3s, using std140 packing (padded to ivec4)

bool RE_UniformBlock::bindFloat ( const char *  name,
fpreal32  v,
int  array_index = 0 
)

Bind a single float value.

bool RE_UniformBlock::bindFloats ( const char *  name,
const fpreal32 valarray,
int  array_size,
int  array_index = 0 
)

Set values for a fixed-length float array.

bool RE_UniformBlock::bindInt ( const char *  name,
int  v,
int  array_index = 0 
)

Copy the data for uniform 'name' into the buffer. If name does not exist in the buffer, or its type/array size doesn't match, bind...() will return false. If its value is not different from the current value in the block, it will not cause an upload. Shader Storage Blocks can have open-ended arrays, and variables within those arrays can specify their array index with 'array_index'.

bool RE_UniformBlock::bindInts ( const char *  name,
const int valarray,
int  array_size,
int  array_index = 0 
)

Set values for a fixed-length integer array.

bool RE_UniformBlock::bindIntVector3 ( const char *  name,
const int valarray,
int  array_size,
int  array_index = 0 
)

bind a series of ivec3s, using std140 packing (padded to ivec4)

vec3 is a little different, as it is padded to vec4 in uniform blocks. SSBOs with std420 packing should use bindVector().

bool RE_UniformBlock::bindMatrix ( const char *  name,
const UT_Matrix2F m,
int  array_index = 0 
)

Set a single 2x2 matrix value.

bool RE_UniformBlock::bindMatrix ( const char *  name,
const UT_Matrix3F m,
int  array_index = 0 
)

Set a single 3x3 matrix value.

bool RE_UniformBlock::bindMatrix ( const char *  name,
const UT_Matrix4F m,
int  array_index = 0 
)

Set a single 4x4 matrix value.

bool RE_UniformBlock::bindMatrix ( const char *  name,
const UT_Matrix2D m,
int  array_index = 0 
)

Set a single 2x2 matrix value (dmat2).

bool RE_UniformBlock::bindMatrix ( const char *  name,
const UT_Matrix3D m,
int  array_index = 0 
)

Set a single 3x3 matrix value (dmat3).

bool RE_UniformBlock::bindMatrix ( const char *  name,
const UT_Matrix4D m,
int  array_index = 0 
)

Set a single 4x4 matrix value (dmat4).

bool RE_UniformBlock::bindUint64 ( const char *  name,
uint64  v,
int  array_index = 0 
)

Bind a single handle value to a sampler. GPU must support bindless textures.

bool RE_UniformBlock::bindUint64s ( const char *  name,
const uint64 valarray,
int  array_size,
int  array_index = 0 
)

Set values for a uint64 handle array.

bool RE_UniformBlock::bindVector ( const char *  name,
const UT_Vector2F v,
int  array_index = 0 
)

Bind a single vec2 uniform value.

bool RE_UniformBlock::bindVector ( const char *  name,
const UT_Vector3F v,
int  array_index = 0 
)

Bind a single vec3 uniform value.

bool RE_UniformBlock::bindVector ( const char *  name,
const UT_Vector4F v,
int  array_index = 0 
)

Bind a single vec4 uniform value.

bool RE_UniformBlock::bindVector ( const char *  name,
const UT_Vector2D v,
int  array_index = 0 
)

Bind a single dvec2 uniform value.

bool RE_UniformBlock::bindVector ( const char *  name,
const UT_Vector3D v,
int  array_index = 0 
)

Set a single dvec3 uniform value.

bool RE_UniformBlock::bindVector ( const char *  name,
const UT_Vector4D v,
int  array_index = 0 
)

Set a single dvec4 uniform value.

bool RE_UniformBlock::bindVector3 ( const char *  name,
const fpreal32 valarray,
int  array_size,
int  array_index = 0 
)

bind a series of vec3s, using std140 packing (padded to ivec4)

void RE_UniformBlock::clearUniforms ( )
static void RE_UniformBlock::dirtyAllUniformBlocks ( )
inlinestatic

Definition at line 191 of file RE_UniformBlock.h.

void RE_UniformBlock::downloadBuffer ( RE_Render r)

Fetches the contents of the GL buffer into the main mem block contained by this class.

RE_UniformBlock* RE_UniformBlock::duplicate ( bool  block_data_too = true) const

Creates a new uniform block with its own buffer based on the structure of this uniform block. If data_too is true, the data inside the uniform block is also copied.

int RE_UniformBlock::getArrayLength ( ) const
inline

Array length of variably sized arrays (for GL4 SSBOs).

Definition at line 50 of file RE_UniformBlock.h.

int RE_UniformBlock::getID ( ) const
inline

The raw GL id of the buffer. Will not exist unless uploadBuffer() was previously called. Returns -1 if there is no buffer object.

Definition at line 186 of file RE_UniformBlock.h.

const RE_Shader* RE_UniformBlock::getInitializedShader ( ) const
inline

Which shader this block is currently laid out for.

Definition at line 230 of file RE_UniformBlock.h.

const char * RE_UniformBlock::getInstanceName ( ) const
inline

Optional instance name of the uniform block (uniform block { } <name>)

Definition at line 275 of file RE_UniformBlock.h.

int64 RE_UniformBlock::getMemoryUsage ( bool  inclusive) const

Returns the amount of main memory (NOT graphics memory!) owned by this RE_UniformBlock.

const char * RE_UniformBlock::getName ( void  ) const
inline

Name of the uniform block (uniform <name> { } )

Definition at line 269 of file RE_UniformBlock.h.

int RE_UniformBlock::getNumUniforms ( ) const

Number of member variables in the uniform block.

int RE_UniformBlock::getSizeB ( ) const

Size of the underlying GL buffer.

const char* RE_UniformBlock::getUniformName ( int  index) const

Returns the name of the member variable at 'index'.

int RE_UniformBlock::getUniformShaderIndex ( int  index) const

Which UBO or SSBO index this uniform block was created for.

bool RE_UniformBlock::hasUniform ( const char *  name) const

Returns true if this block has a member variable called 'name'.

bool RE_UniformBlock::isCompatible ( const RE_UniformBlock block) const

returns true if 'block' shares the same size and structure as this block

bool RE_UniformBlock::isDirty ( void  ) const
inline

Whether this block requires uploading to the GPU.

Definition at line 223 of file RE_UniformBlock.h.

bool RE_UniformBlock::isInitializedFor ( const RE_Shader sh) const
inline

Which shader this block is currently laid out for.

Definition at line 287 of file RE_UniformBlock.h.

void RE_UniformBlock::print ( std::ostream *  os = NULL)

Debug printout of the block, including currently bound values.

void RE_UniformBlock::setBufferSizes ( int  fixed_size_bytes,
int  variable_size_bytes 
)
void RE_UniformBlock::setInitializedFor ( const RE_Shader sh)
inline

Which shader this block is currently laid out for.

Definition at line 281 of file RE_UniformBlock.h.

void RE_UniformBlock::setInstanceName ( const char *  name)

Optional instance name of the uniform block (uniform block { } <name>) This will need to be specified to bind a UBO to a specific instance when instanced UBOs are used by the shader.

void RE_UniformBlock::setName ( const char *  name)

Name of the uniform block (uniform <name> { } ), generally set by the shader.

void RE_UniformBlock::setOriginProgramID ( int  pid)
inline

Program ID of the program this block was created from.

Definition at line 232 of file RE_UniformBlock.h.

void RE_UniformBlock::setSize ( int  bytes)

Size of the underlying GL buffer, in bytes. Generally set by the shader.

bool RE_UniformBlock::updateBlock ( RE_UniformBlock b,
const RE_Shader sh 
) const

Update the passed uniform block with the uniforms found in this block. This is generally done by the shader before a draw call.

void RE_UniformBlock::uploadBuffer ( RE_Render r)

commits any changes to the buffer object, creating the buffer object if required.


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