#include <uniform.h>
Public Types | |
enum | baseType_e { BASE_TYPE_BAD = 0, BASE_TYPE_BOOL, BASE_TYPE_INT, BASE_TYPE_FLOAT, BASE_TYPE_SAMPLER } |
Uniform base type. More... | |
Public Member Functions | |
CUniform (const QString &name=QString(), int type=0, int location=-1) | |
Constructs a named uniform variable object. | |
CUniform (const CUniform &u, int location) | |
Constructs a copy of a giver CUniform object. | |
virtual | ~CUniform (void) |
Destructor. | |
const QString & | getName (void) const |
Returns the name of the uniform variable. | |
int | getType (void) const |
Returns the OpenGL type of the uniform variable. | |
QString | getTypeName (void) const |
Returns the name string of the OpenGL type of this uniform. | |
int | getLocation (void) const |
Returns the location of this uniform. | |
int | getComponentCount (void) const |
Returns the number of vector components in the uniform. | |
baseType_e | getBaseType (void) const |
Extracts the scalar types for vectors and matrices out of the OpenGL type of this uniform. | |
bool | isMatrix (void) const |
Returns TRUE, if hte uniform is of a matrix type. | |
int | getColumnCount (void) const |
Returns the number of matrix columns. | |
CUniform | getColumnVector (int column) const |
Get an indexed matrix column. | |
void | setColumnVector (int column, const CUniform &u) |
Set an indexed matrix column. | |
bool | getValueAsBool (int component) const |
Returns a boolean value. | |
int | getValueAsInt (int component) const |
Returns an integer value. | |
double | getValueAsFloat (int component) const |
Returns a floating point value. | |
void | setValueAsBool (int component, bool value) |
Sets a component to a boolean value. | |
void | setValueAsInt (int component, int value) |
Sets a component to an integer value. | |
void | setValueAsFloat (int component, double value) |
Sets a component to a floating point value. | |
void | applyToGL (void) |
Passes the currently stored uniform data to OpenGL. | |
Static Public Member Functions | |
static QString | getTypeNameString (int type) |
Converts OpenGL's symbolic type constants from integer to string representation. | |
Classes | |
union | dataUnit_u |
The actual data container. |
This class is capable of storing uniform variable data of different types and formats used in GLSL program. It stores the data itself and the metadata, like variable name, type and location. It also provides methods that return meta information about those meta informations ( example: getBaseType() ).
This class supports bool, int and float variables with up to 4x4 elements. The methods for accessing the data of these types are exclusive to its type. For example, results are undefined if the uniform type is int and the method setValueAsFloat is called. These types are also called base types, because they are the scalars used in vectors an matrix uniforms.
A CUniform object can be accessed like a matrix and like a vector. the getValue and setValue methods treat it like a 4 component vector, even if only one component is available! Accessing the other components is possible, but they are not passed to OpenGL via applyToGL. Matrices are also treated like vectors by accessing only the first column of the matrix. To access the other columns you need to extract/insert the individual column with the getColumnVector() and setColumnVector() methods.
enum CUniform::baseType_e |
Uniform base type.
Since uniforms can be vectors and matrices, this defines the type if the scalars stored in those vectors and matrices.
CUniform::CUniform | ( | const QString & | name = QString() , |
|
int | type = 0 , |
|||
int | location = -1 | |||
) |
Constructs a named uniform variable object.
If the uniform type is a matrix, the object is initialized to the identity matrix of the dimension specified in that type. Otherwise all data elements are initialized to zero.
name | Name of the unifrom variable. | |
type | Type of the variable. Possible types are those defined in the OpenGL 2.0 specification. | |
location | Location of the uniform variable. |
CUniform::CUniform | ( | const CUniform & | u, | |
int | location | |||
) |
Constructs a copy of a giver CUniform object.
An location must be specified, which overrides the location stored in the source object.
u | Source uniform variable. | |
location | New location of the uniform variable. |
CUniform::~CUniform | ( | void | ) | [virtual] |
Destructor.
const QString& CUniform::getName | ( | void | ) | const [inline] |
Returns the name of the uniform variable.
int CUniform::getType | ( | void | ) | const [inline] |
Returns the OpenGL type of the uniform variable.
QString CUniform::getTypeName | ( | void | ) | const [inline] |
Returns the name string of the OpenGL type of this uniform.
int CUniform::getLocation | ( | void | ) | const [inline] |
Returns the location of this uniform.
int CUniform::getComponentCount | ( | void | ) | const |
Returns the number of vector components in the uniform.
It treats the uniform as a vector. For matrices, this returns the number of components of each column vector.
CUniform::baseType_e CUniform::getBaseType | ( | void | ) | const |
Extracts the scalar types for vectors and matrices out of the OpenGL type of this uniform.
bool CUniform::isMatrix | ( | void | ) | const |
Returns TRUE, if hte uniform is of a matrix type.
int CUniform::getColumnCount | ( | void | ) | const |
Returns the number of matrix columns.
If this uniform is a matrix, this call return the number of matrix columns. Otherwise it returns 1.
CUniform CUniform::getColumnVector | ( | int | column | ) | const |
Get an indexed matrix column.
This can be used to extract a column out of a matrix uniform. If the column index is out of range for the stored type, or the type is not a matrix, then behavior is undefined.
column | Column index. |
void CUniform::setColumnVector | ( | int | column, | |
const CUniform & | u | |||
) |
Set an indexed matrix column.
This can be used to replace a column of a matrix uniform. If the column index is out of range for the stored type, or the type is not a matrix, or the new base type is not equal to the current base type, then behavior is undefined.
column | Column index. | |
u | A CUniform that represents the source column vector. |
bool CUniform::getValueAsBool | ( | int | component | ) | const |
Returns a boolean value.
Treats the uniform like a vector. The component index must be in range [0,3]. If the index is out of range, the behavior is undefined.
component | Component index. |
int CUniform::getValueAsInt | ( | int | component | ) | const |
Returns an integer value.
Treats the uniform like a vector. The component index must be in range [0,3]. If the index is out of range, the behavior is undefined.
component | Component index. |
double CUniform::getValueAsFloat | ( | int | component | ) | const |
Returns a floating point value.
Treats the uniform like a vector. The component index must be in range [0,3]. If the index is out of range, the behavior is undefined.
component | Component index. |
void CUniform::setValueAsBool | ( | int | component, | |
bool | value | |||
) |
Sets a component to a boolean value.
Treats the uniform like a vector. The component index must be in range [0,3]. If the index is out of range, the behavior is undefined.
component | Component index. | |
value | Value to be stored. |
void CUniform::setValueAsInt | ( | int | component, | |
int | value | |||
) |
Sets a component to an integer value.
Treats the uniform like a vector. The component index must be in range [0,3]. If the index is out of range, the behavior is undefined.
component | Component index. | |
value | Value to be stored. |
void CUniform::setValueAsFloat | ( | int | component, | |
double | value | |||
) |
Sets a component to a floating point value.
Treats the uniform like a vector. The component index must be in range [0,3]. If the index is out of range, the behavior is undefined.
component | Component index. | |
value | Value to be stored. |
void CUniform::applyToGL | ( | void | ) |
Passes the currently stored uniform data to OpenGL.
It uses the glUniform* command based on the stored type. If the location of this uniform is -1, this call has no effect.
QString CUniform::getTypeNameString | ( | int | type | ) | [static] |
Converts OpenGL's symbolic type constants from integer to string representation.
This can be used to translate a queried type identifier into format the user can read. If the type is unknown, a string containing the integer representation will be returned.
type | The type symbol to translate. |