CShader Class Reference

Implementation of IShader. More...

Inheritance diagram for CShader:

IShader IUniformState

List of all members.

Public Member Functions

 CShader (void)
 Constructs a shader object.
virtual ~CShader (void)
 Destructor.
bool init (void)
 Initialized the object.
void shutdown (void)
 Destroys all OpenGL objects and goes back to uninitialized state.
bool bindState (VertexAttribLocations &attribs)
 Setups OpenGL to use that program.
void setShaderSource (int shaderType, const QString &source)
 Assigns GLSL source code to a shader.
void setGeometryInputType (int type)
 Sets the geometry shaders input primitive type.
void setGeometryOutputType (int type)
 Sets the geometry shaders output primitive type.
bool compileAndLink (void)
 Compiles shaders and links the program.
void deactivateProgram (void)
 Destroys the current program and makes it unuseable.
QString getBuildLog (void)
 Returns a string with compile and link results.
bool isShaderTypeAvailable (int type)
 Check wether a given shader type is avilable for this program.
int getActiveUniforms (void)
 Returns the number of uniforms stored in this object.
CUniform getUniform (int index)
 Returns an indexed uniform.
void setUniform (int index, const CUniform &u)
 Sets the uniform at a given index.


Detailed Description

Implementation of IShader.

This class doensn't add new functionality. It is only used to hide the class definition from the interface definition.


Constructor & Destructor Documentation

CShader::CShader ( void   ) 

Constructs a shader object.


Member Function Documentation

bool CShader::init ( void   )  [virtual]

Initialized the object.

After this call the object is ready to compile and link GLSL code.

Precondition:
Requeires a valid OpenGL context in use.

Implements IShader.

bool CShader::bindState ( VertexAttribLocations attribs  )  [virtual]

Setups OpenGL to use that program.

If the program was not suceessfully linked, then this call makes OpenGL use the fixed-function pipeline.

Parameters:
attribs Locations of used custom vertex attributes will be returned in this argument. If a vertex attribute is not available, that attribute will be set to -1.
Returns:
True, if the program is in use, False otherwise.

Implements IShader.

void CShader::setShaderSource ( int  shaderType,
const QString &  source 
) [virtual]

Assigns GLSL source code to a shader.

Old source code is replaced with the new code. the program is not changed until compileAndLink() is called. An empty string indicates that the specified shader type should not be attached to the program.

Parameters:
shaderType The shader type to replace.
source The source code.

Implements IShader.

void CShader::setGeometryInputType ( int  type  )  [virtual]

Sets the geometry shaders input primitive type.

If the program does not support geometry shaders, this call has no effect. If the primitive type is invalid, this call has no effect. This call does not change the porgam. You will have to relink the program for the changes to take effect.

Parameters:
type OpenGL primitive type. Valid types are those specified in the GL_EXT_geometry_shader4 extension.

Implements IShader.

void CShader::setGeometryOutputType ( int  type  )  [virtual]

Sets the geometry shaders output primitive type.

If the program does not support geometry shaders, this call has no effect. If the primitive type is invalid, this call has no effect. This call does not change the porgam. You will have to relink the program for the changes to take effect.

Parameters:
type OpenGL primitive type. Valid types are those specified in the GL_EXT_geometry_shader4 extension.

Implements IShader.

bool CShader::compileAndLink ( void   )  [virtual]

Compiles shaders and links the program.

Is also setups uniform lists and build log. If no sources are specified for all shaders, this call will return true although no program is generated.

Returns:
True if the program was successfully linked. False otherwise.

Implements IShader.

void CShader::deactivateProgram ( void   )  [virtual]

Destroys the current program and makes it unuseable.

Future calls to bindState() will fail until a call to compileAndLink() successfully created a program.

Implements IShader.

QString CShader::getBuildLog ( void   )  [virtual]

Returns a string with compile and link results.

This log also includes information about active uniforms and vertex attributes. The log is already formatted, so it can be displayed to the user.

Returns:
The build log string.

Implements IShader.

bool CShader::isShaderTypeAvailable ( int  type  )  [virtual]

Check wether a given shader type is avilable for this program.

Returns false for invalid input.

Parameters:
type Shader type identifier, defined in shaderType_e
Returns:
Wether the shader type is supported by the program.

Implements IShader.

int CShader::getActiveUniforms ( void   )  [virtual]

Returns the number of uniforms stored in this object.

The returned value is always >= 0.

Returns:
The highest possible uniform index + 1.

Implements IUniformState.

CUniform CShader::getUniform ( int  index  )  [virtual]

Returns an indexed uniform.

If the index is out of range, a CUniform object with undefined content will be returned.

Parameters:
index Zero based index to a uniform. The maximum possible index is n-1 where n is the value returned by getActiveUniforms().
Returns:
Uniform at the given index.

Implements IUniformState.

void CShader::setUniform ( int  index,
const CUniform u 
) [virtual]

Sets the uniform at a given index.

If the index is out of range, this call has no effect. If the new uniform has a different name or a different type or a different location like the uniform currently stored, this call has no effect.

Parameters:
index Zero based index to a uniform. The maximum possible index is n-1 where n is the value returned by getActiveUniforms().
u The value the indexed uniform is set to.

Implements IUniformState.


The documentation for this class was generated from the following file:
Generated on Sun Mar 2 17:12:32 2008 for Shader Maker by  doxygen 1.5.4