ShaderProgram Class Reference

Class representing a shader program. More...

Inheritance diagram for ShaderProgram:
BasicProgram

List of all members.

Public Member Functions

 ShaderProgram (string fileName)
 Creates a shader program (from a file)
 ShaderProgram (string vpFileName, string fpFileName)
 Creates a shader program (from a file)
 ShaderProgram (string fileName, ShaderProgramOption option)
 Creates a shader program (from a file, with options)
 ShaderProgram (string vpFileName, string fpFileName, ShaderProgramOption option)
 Creates a shader program (from a file, with options)
 ShaderProgram (byte[] fileImage)
 Creates a shader program (from a file image)
 ShaderProgram (byte[] vpFileImage, byte[] fpFileImage)
 Creates a shader program (from a file image)
 ShaderProgram (byte[] fileImage, ShaderProgramOption option)
 Creates a shader program (from a file image, with options)
 ShaderProgram (byte[] vpFileImage, byte[] fpFileImage, ShaderProgramOption option)
 Creates a shader program (from a file image, with options)
virtual Object ShallowClone ()
 Creates a copy of the shader program.
void Dispose ()
 Frees the unmanaged resources of the shader program.
int FindUniform (string name)
 Enables search by specifying the uniform variable name.
int FindAttribute (string name)
 Enables search by specifying the attribute variable name.
string GetUniformBinding (int index)
 Obtains the uniform variable binding.
void SetUniformBinding (int index, string name)
 Sets the uniform variable binding.
string GetAttributeBinding (int index)
 Obtains the attribute variable binding.
void SetAttributeBinding (int index, string name)
 Sets the attribute variable binding.
ShaderUniformType GetUniformType (int index)
 Obtains the uniform variable type.
ShaderAttributeType GetAttributeType (int index)
 Obtains the attribute variable type.
string GetUniformName (int index)
 Obtains the uniform variable name.
string GetAttributeName (int index)
 Obtains the attribute variable name.
int GetUniformSize (int index)
 Obtains the array size of the uniform variable.
int GetAttributeSize (int index)
 Obtains the array size of the attribute variable.
void SetUniformValue (int index, ref Matrix4 value)
 Sets the uniform variable value.
void SetUniformValue (int index, ref Vector4 value)
 Sets the uniform variable value.
void SetUniformValue (int index, ref Vector3 value)
 Sets the uniform variable value.
void SetUniformValue (int index, ref Vector2 value)
 Sets the uniform variable value.
void SetUniformValue (int index, float value)
 Sets the uniform variable value.
void SetUniformValue (int index, int value)
 Sets the uniform variable value.
void SetUniformValue (int index, float[] value)
 Sets the uniform variable value.
void SetUniformValue (int index, int[] value)
 Sets the uniform variable value.
void SetUniformValue (int index, int offset, ref Matrix4 value)
 Sets the uniform variable value (with offset)
void SetUniformValue (int index, int offset, ref Vector4 value)
 Sets the uniform variable value (with offset)
void SetUniformValue (int index, int offset, ref Vector3 value)
 Sets the uniform variable value (with offset)
void SetUniformValue (int index, int offset, ref Vector2 value)
 Sets the uniform variable value (with offset)
void SetUniformValue (int index, int offset, float value)
 Sets the uniform variable value (with offset)
void SetUniformValue (int index, int offset, int value)
 Sets the uniform variable value (with offset)
void SetUniformValue (int index, int offset, float[] value)
 Sets the uniform variable value (with offset)
void SetUniformValue (int index, int offset, int[] value)
 Sets the uniform variable value (with offset)
void SetUniformValue (int index, Matrix4[] value, int to, int from, int count)
 Sets the uniform variable value (for array data)
void SetUniformValue (int index, Vector4[] value, int to, int from, int count)
 Sets the uniform variable value (for array data)
void SetUniformValue (int index, Vector3[] value, int to, int from, int count)
 Sets the uniform variable value (for array data)
void SetUniformValue (int index, Vector2[] value, int to, int from, int count)
 Sets the uniform variable value (for array data)
void SetUniformValue (int index, float[] value, int to, int from, int count)
 Sets the uniform variable value (for array data)
void SetUniformValue (int index, int[] value, int to, int from, int count)
 Sets the uniform variable value (for array data)
void SetAttributeValue (int index, params float[] value)
 Sets the default value of the attribute variable.
int GetUniformTexture (int index)
 Obtains the uniform variable texture number.
int GetAttributeStream (int index)
 Obtains the vertex stream number of the attribute variable.
void SetAttributeStream (int index, int stream)
 Sets the vertex stream number of the attribute variable.

Protected Member Functions

 ShaderProgram (ShaderProgram program)
 Creates a copy of the shader program.
void SwapShader (ShaderProgram program)
 Changes the shader.
virtual internal void UpdateShader ()
 Updates the shader state.

Properties

int UniformCount [get]
 Number of uniform variables.
int AttributeCount [get]
 Number of attribute variables.

Detailed Description

Class representing a shader program.


Constructor & Destructor Documentation

ShaderProgram ( string  fileName)

Creates a shader program (from a file)

Parameters:
fileNameShader filename

Creates a shader program from a specified file. The usable file format is CGX.

ShaderProgram ( string  vpFileName,
string  fpFileName 
)

Creates a shader program (from a file)

Parameters:
vpFileNameVertex shader filename
fpFileNameFragment shader filename

Creates a shader program from a specified file. The usable file format is CGX.

ShaderProgram ( string  fileName,
ShaderProgramOption  option 
)

Creates a shader program (from a file, with options)

Parameters:
fileNameShader filename
optionShader program creation option

Creates a shader program from a specified file. The usable file format is CGX.

ShaderProgram ( string  vpFileName,
string  fpFileName,
ShaderProgramOption  option 
)

Creates a shader program (from a file, with options)

Parameters:
vpFileNameVertex shader filename
fpFileNameFragment shader filename
optionShader program creation option

Creates a shader program from a specified file. The usable file format is CGX.

ShaderProgram ( byte[]  fileImage)

Creates a shader program (from a file image)

Parameters:
fileImageShader file image

Creates a shader program from a specified file image. The usable file format is CGX.

ShaderProgram ( byte[]  vpFileImage,
byte[]  fpFileImage 
)

Creates a shader program (from a file image)

Parameters:
vpFileImageVertex shader file image
fpFileImageFragment shader file image

Creates a shader program from a specified file image. The usable file format is CGX.

ShaderProgram ( byte[]  fileImage,
ShaderProgramOption  option 
)

Creates a shader program (from a file image, with options)

Parameters:
fileImageShader file image

Creates a shader program from a specified file image. The usable file format is CGX.

ShaderProgram ( byte[]  vpFileImage,
byte[]  fpFileImage,
ShaderProgramOption  option 
)

Creates a shader program (from a file image, with options)

Parameters:
vpFileImageVertex shader file image
fpFileImageFragment shader file image

Creates a shader program from a specified file image. The usable file format is CGX.

ShaderProgram ( ShaderProgram  program) [protected]

Creates a copy of the shader program.

Returns:
Clones a shader program

Creates a copy of the shader program. The 2 shader programs will then share unmanaged resources. When Dispose() is called for all copies, the shared unmanaged resources will be freed.


Member Function Documentation

int FindAttribute ( string  name)

Enables search by specifying the attribute variable name.

Parameters:
nameName of the attribute variable
Returns:
Number of the attribute variable (failure if -1)

Enables search by specifying the attribute variable name. -1 will be returned if the specified variable is not found.

int FindUniform ( string  name)

Enables search by specifying the uniform variable name.

Parameters:
nameName of the uniform variable
Returns:
Number of the uniform variable (failure if -1)

Enables search by specifying the uniform variable name. -1 will be returned if the specified variable is not found.

string GetAttributeBinding ( int  index)

Obtains the attribute variable binding.

Parameters:
indexNumber of the attribute variable (0 to AttributeCount-1)
Returns:
Name of the attribute variable (default when null)
string GetAttributeName ( int  index)

Obtains the attribute variable name.

Parameters:
indexNumber of the attribute variable (0 to AttributeCount-1)
Returns:
Name of the attribute variable
int GetAttributeSize ( int  index)

Obtains the array size of the attribute variable.

Parameters:
indexNumber of the attribute variable (0 to AttributeCount-1)
Returns:
Attribute variable array size
int GetAttributeStream ( int  index)

Obtains the vertex stream number of the attribute variable.

Parameters:
indexNumber of the attribute variable (0 to AttributeCount-1)
Returns:
Vertex stream number (invalid if -1)
ShaderAttributeType GetAttributeType ( int  index)

Obtains the attribute variable type.

Parameters:
indexNumber of the attribute variable (0 to AttributeCount-1)
Returns:
Attribute variable type
string GetUniformBinding ( int  index)

Obtains the uniform variable binding.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
Returns:
Name of the uniform variable (default when null)
string GetUniformName ( int  index)

Obtains the uniform variable name.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
Returns:
Name of the uniform variable
int GetUniformSize ( int  index)

Obtains the array size of the uniform variable.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
Returns:
Obtains the array size of the uniform variable
int GetUniformTexture ( int  index)

Obtains the uniform variable texture number.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
Returns:
Texture number of the uniform variable (disabled if -1)

Obtains the uniform variable texture number. -1 will be returned if the specified variable is not a sampler.

ShaderUniformType GetUniformType ( int  index)

Obtains the uniform variable type.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
Returns:
Uniform variable type
void SetAttributeBinding ( int  index,
string  name 
)

Sets the attribute variable binding.

Parameters:
indexNumber of the attribute variable
nameName of the attribute variable (default when null)

Links the attribute variable to a specific number. The old binding of the specified variable will be freed. Variables that do not have a binding are assigned an unused number.

graphics_attribute_binding.png

It is also possible to specify a number that is equal to or greater than AttributeCount to index. In such cases, an empty variable is inserted and the AttributeCount value increases.

graphics_attribute_binding2.png
void SetAttributeStream ( int  index,
int  stream 
)

Sets the vertex stream number of the attribute variable.

Parameters:
indexNumber of the attribute variable (0 to AttributeCount-1)
streamVertex stream number (invalid if -1)

Sets the vertex stream number of the attribute variable. The initial value is the number of the attribute variable. With this setting, an arbitrary vertex stream can be forwarded to the specified attribute variable. In addition, specific vertex streams can be disabled and a single vertex stream can be forwarded to multiple attribute variables.

graphics_attribute_stream.png
void SetAttributeValue ( int  index,
params float[]  value 
)

Sets the default value of the attribute variable.

Parameters:
indexNumber of the attribute variable (0 to AttributeCount-1)
valueArray data (float)
void SetUniformBinding ( int  index,
string  name 
)

Sets the uniform variable binding.

Parameters:
indexNumber of the uniform variable
nameName of the uniform variable (default when null)

Links the uniform variable to a specific number. The old binding of the specified variable will be freed. Variables that do not have a binding are assigned an unused number.

graphics_uniform_binding.png

It is also possible to specify a number that is equal to or greater than UniformCount to index. In such cases, an empty variable is inserted and the UniformCount value increases.

graphics_uniform_binding2.png
void SetUniformValue ( int  index,
int  offset,
float  value 
)

Sets the uniform variable value (with offset)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
offsetOffset of array variable
valueScalar (float)
void SetUniformValue ( int  index,
int  offset,
ref Vector4  value 
)

Sets the uniform variable value (with offset)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
offsetOffset of array variable
value4D vector (float)
void SetUniformValue ( int  index,
int  offset,
ref Matrix4  value 
)

Sets the uniform variable value (with offset)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
offsetOffset of array variable
value4D matrix (float)
void SetUniformValue ( int  index,
int[]  value 
)

Sets the uniform variable value.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
valueArray data (int)

Sets the uniform variable value. This overload can set a value not only to an int scalar variable, but also to the int vector variable such as int2,int3,int4... However, the array data size must be a multiple of the vector size.

void SetUniformValue ( int  index,
float[]  value 
)

Sets the uniform variable value.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
valueArray data (float)

Sets the uniform variable value. This overload can set a value not only to a float scalar variable, but also to the float vector or matrix variable such as float2,float3,float4... However, the array data size must be a multiple of the vector or matrix size.

void SetUniformValue ( int  index,
int  offset,
int  value 
)

Sets the uniform variable value (with offset)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
offsetOffset of array variable
valueScalar (int)
void SetUniformValue ( int  index,
ref Matrix4  value 
)

Sets the uniform variable value.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
value4D matrix (float)
void SetUniformValue ( int  index,
float[]  value,
int  to,
int  from,
int  count 
)

Sets the uniform variable value (for array data)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
valueArray data (float)
toOffset of the transfer destination
fromOffset of the transfer source
countNumber of data items to be transferred

Sets the uniform variable value. This overload can set a value not only to a float scalar variable, but also to the float vector or matrix variable such as float2,float3,float4... However, note that the offset and count arguments are counted in vector or matrix units.

void SetUniformValue ( int  index,
ref Vector3  value 
)

Sets the uniform variable value.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
value3D vector (float)
void SetUniformValue ( int  index,
Matrix4[]  value,
int  to,
int  from,
int  count 
)

Sets the uniform variable value (for array data)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
value4D matrix array (float)
toOffset of the transfer destination
fromOffset of the transfer source
countNumber of data items to be transferred
void SetUniformValue ( int  index,
ref Vector4  value 
)

Sets the uniform variable value.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
value4D vector (float)
void SetUniformValue ( int  index,
int  offset,
float[]  value 
)

Sets the uniform variable value (with offset)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
offsetOffset of array variable
valueArray data (float)

Sets the uniform variable value. This overload can set a value not only to a float scalar variable, but also to the float vector or matrix variable such as float2,float3,float4... However, the array data size must be a multiple of the vector or matrix size. Note that the offset arguments are counted in vector or matrix units.

void SetUniformValue ( int  index,
Vector3[]  value,
int  to,
int  from,
int  count 
)

Sets the uniform variable value (for array data)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
value3D vector array (float)
toOffset of the transfer destination
fromOffset of the transfer source
countNumber of data items to be transferred
void SetUniformValue ( int  index,
int  offset,
ref Vector3  value 
)

Sets the uniform variable value (with offset)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
offsetOffset of array variable
value3D vector (float)
void SetUniformValue ( int  index,
ref Vector2  value 
)

Sets the uniform variable value.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
value2D vector (float)
void SetUniformValue ( int  index,
float  value 
)

Sets the uniform variable value.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
valueScalar (float)
void SetUniformValue ( int  index,
int  value 
)

Sets the uniform variable value.

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
valueScalar (int)
void SetUniformValue ( int  index,
int  offset,
int[]  value 
)

Sets the uniform variable value (with offset)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
offsetOffset of array variable
valueArray data (int)

Sets the uniform variable value. This overload can set a value not only to an int scalar variable, but also to the int vector variable such as int2,int3,int4... However, the array data size must be a multiple of the vector size. Note that the offset arguments are counted in vector units.

void SetUniformValue ( int  index,
int[]  value,
int  to,
int  from,
int  count 
)

Sets the uniform variable value (for array data)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
valueArray data (int)
toOffset of the transfer destination
fromOffset of the transfer source
countNumber of data items to be transferred

Sets the uniform variable value. This overload can set a value not only to an int scalar variable, but also to the int vector variable such as int2,int3,int4... However, note that the offset and count arguments are counted in vector units.

void SetUniformValue ( int  index,
Vector4[]  value,
int  to,
int  from,
int  count 
)

Sets the uniform variable value (for array data)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
value4D vector array (float)
toOffset of the transfer destination
fromOffset of the transfer source
countNumber of data items to be transferred
void SetUniformValue ( int  index,
Vector2[]  value,
int  to,
int  from,
int  count 
)

Sets the uniform variable value (for array data)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
value2D vector array (float)
toOffset of the transfer destination
fromOffset of the transfer source
countNumber of data items to be transferred
void SetUniformValue ( int  index,
int  offset,
ref Vector2  value 
)

Sets the uniform variable value (with offset)

Parameters:
indexNumber of the uniform variable (0 to UniformCount-1)
offsetOffset of array variable
value2D vector (float)
virtual Object ShallowClone ( ) [virtual]

Creates a copy of the shader program.

Returns:
Copy of the shader program

Creates a copy of the shader program. The 2 shader programs will then share unmanaged resources. When Dispose() is called for all copies, the shared unmanaged resources will be freed.

Reimplemented in BasicProgram.

void SwapShader ( ShaderProgram  program) [protected]

Changes the shader.

Parameters:
programShader Program

Sets the shader of the specified shader program to this shader program. This function is used when switching shaders internally.

virtual internal void UpdateShader ( ) [protected, virtual]

Updates the shader state.

A virtual function that is called from the graphics context before primitive rendering. This function is used when a cached state in a class is applied to the shader.

Reimplemented in BasicProgram.