Need a 3D graph? Try the 3DSurface Viewer! Draw 3D graphs with free calculus software from Bright Ideas Software.
GLE32 Ver. 4 Manual
  Skip Navigation Links
Math ToolsExpand Math Tools
DevelopersExpand Developers
About BISExpand About BIS
  Skip Navigation LinksHome --> Developers --> GLE32 Version 4 --> GLE32 Manual --> OpenGL Shader Class Search:
Skip Navigation Links

OpenGL® and OpenGL|ES are trademarks of Silicon Graphics, Inc.





OpenGL Shader Class

This class wraps the GLSL shading language capability promoted to the OpenGL core w/ Version 2.0. It is intended as a shader development tool, not necessarily a high-performance implementation you'd want to use in production code. An example is the Uniformnv set of methods. These take a friendly string name for the uniform variable, call glGetUniformLocationARB, followed by the appropriate glUniformxxARB call. It would make more sense from a performance standpoint for the application to query the location of the uniform variables once during the program's active session and store then re-use the result, as opposed to the repeatedly calling glGetUniformLocationARB. Still, when using this as a shader development tool, the convenience of using string names for the variables is hard to argue with.

This class performs the shader extension API initialization internally when one of the CreateShaderFromxxx or InitializeFromxxx methods are called, making it directly dependent on the GL Extensions module. It also incorporates an adaptation of the 3D Perlin noise function from the OpenGL Shading Language Manual by Randi Rost. This requires the use of the multitexturing extension API, which is also internally initialized by the shader class. The public interface is documented below.


CgleShader

Variables

  

Description

BOOL m_bShowDiagnosticMessages  Set TRUE to turn on error reporting. This returns useful status information as the shaders are compiled, the progam is linked and used. Default is FALSE.
BOOL m_bUseNoiseTexture  Set TRUE to turn on the 3D noise function. The noise function is initialized when one of the CreateShaderFromxxx or InitializeFromxxx functions is called. Default is FALSE.
UINT m_iNoiseTexUnit  The texture unit to assign to the noise texture. Default is GL_TEXTURE0.
 

Methods

  

Description

CgleShader ()   
~CgleShader ()   
 
void Enable ()  Wraps glUseProgramObjectARB and (if m_bShowDiagnosticMessages is TRUE) outputs error information if the attempt fails. If m_bUseNoiseTexture is TRUE, it also enables the noise texture object.
void Disable ()  Passes 0 to glUseProgramObjectARB.
 
BOOL InitializeFromFiles (char* fragment_filename, char* vertex_filename, BOOL link_program)  Opens the specified files, reads the contents and attempts to create shader objects, then optionally creates the program object, attaches the shaders and links the program. NULL may be passed as in place of one of the file names, but at least one must contain a valid file name. The program and shader handles created in the process are stored in private variables and may be read with the GetnnnnHandle methods.
BOOL InitializeFromStrings (char* fragment_program, char* vertex_program, BOOL link_program)  As above, except the shaders are passed directly as strings. This is intended for use with shaders embedded as string resources.
 
BOOL CreateShaderFromFile (char* filename, GLenum type, UINT& handle)  Creates and compiles a shader object from the contents of filename. Type must be either GL_VERTEX_SHADER_ARB or GL_FRAGMENT_SHADER_ARB. This function is intended to support the use of multiple shaders in a program; to that end, the handle created is NOT linked to a program or assigned to a private variable, and will NOT be returned by a call to one of the GetnnnnHandle methods.
BOOL CreateShaderFromString (char* program, GGLenum type, UINT& handle)  As above except the shader is passed directly as a string.
 
void AttachShaderObject (UINT handle)  Attaches a shader to a CgleShader's program object. (Call CreateProgramObject first.)
void DetachShaderObject (UINT handle)  Detached the shader from a CgleShader's proogram object.
void DeleteObject (UINT objectHandle)  Delete a shader or program object.
void CreateProgramObject ()  Create a program object and assign it's handle to a private variable; this handle can be accessed via the GetProgramHandle method.
BOOL LinkProgram ()  Links the CgleShader's program object to any currently attached shader objects.
 
BOOL ApiIsInitialized ()  Returns TRUE if the necessary extensions have been successfully initialized. As noted above, the extensions are automatically initialized the first time one of the CreateShaderFromxxx or InitializeFromxxx methods is called.
UINT GetProgramHandle ()  Returns the handle of the CgleShader's program object.
UINT GetFragmentShaderHandle/  Returns the handle of the fragment shader created via one of the InitializeFromnnnn methods.
UINT GetVertexShaderHandle ()  Returns the handle of the vertex shader created via one of the InitializeFromnnnn methods.
 
UINT GetNoiseTextureIndex ()  Returns the texture object handle assigned to the noise texture.
 
void Uniform1f (const char* variableName, float value1)
void Uniform2f (const char* variableName, float value1, float value2)
void Uniform3f (const char* variableName, float value1, float value2, float value3)
void Uniform4f (const char* variableName, float value1, float value2, float value3, float value4)
 
void Uniform1i (const char* variableName, int value1)
void Uniform2i (const char* variableName, int value1, int value2)
void Uniform3i (const char* variableName, int value1, int value2, int value3)
void Uniform4i (const char* variableName, int value1, int value2, int value3, int value4)
 
void Uniform1fv (const char* variableName, int count, float* values)
void Uniform2fv (const char* variableName, int count, float* values)
void Uniform3fv (const char* variableName, int count, float* values)
void Uniform4fv (const char* variableName, int count, float* values)
 
void Uniform1iv (const char* variableName, int count, int* values)
void Uniform2iv (const char* variableName, int count, int* values)
void Uniform3iv (const char* variableName, int count, int* values)
void Uniform4iv (const char* variableName, int count, int* values)
 
void UniformMatrix2fv (const char* variableName, int count, BOOL transpose, float* values)
void UniformMatrix3fv (const char* variableName, int count, BOOL transpose, float* values)
void UniformMatrix4fv (const char* variableName, int count, BOOL transpose, float* values)
 
int GetUniformVariableLocation (const char* variableName)
void GetUniformiv (const char* variableName, int* values)
void GetUniformfv (const char* variableName, float* values)
 

Back To Top



Copyright© 2001-2008 by Bright Ideas Software®. All rights reserved.