Propane::Shader::Program Class Reference

An entire shader that may have any number of vertex/fragment shaders attached. More...

#include <PropaneShader.h>

List of all members.

Public Member Functions

void loadVertexShader (const std::string &filename)
 Load a vertex shader from a source file and attach it to this program.
void loadFragmentShader (const std::string &filename)
 Load a fragment shader from a source file and attach it to this program.
bool compile ()
 Compile the shader (must be done after loading all necessary attached programs). Returns false on compile failure.
void turnOn ()
 Turn on the shader.
void turnOff ()
 Turn off the shader.
bool isReady ()
 Returns true if the shader is ready to use.
bool isSupported ()
 Returns true if the shader can be used on this computer.
GLint getUniformLocation (const std::string &uniformName)
 Get the handle for a uniform in the shader program.
void passToUniform (GLint uniformHandle, float value)
 Pass a floating-point number to a uniform value in the program.
void passVectorToUniform (GLint uniformHandle, const Propane::Math::Vector3 &theVector)
 Pass a floating-point Propane::Math::Vector3 to the program as a uniform vec3.
std::string getInfoLog ()
 Return the info log from program compilation (if any).
 Program ()
 Basic constructor that tests for hardware compatibility.
virtual ~Program ()
 Basic destructor that turns off the shader and deletes all attached programs.


Detailed Description

An entire shader that may have any number of vertex/fragment shaders attached.
Examples:

ShaderUse.cpp.


Constructor & Destructor Documentation

Propane::Shader::Program::Program  ) 
 

Basic constructor that tests for hardware compatibility.

Basic constructor for the program. Checks for hardware support, sets initial values. Emits warnings to stderr if not hardware supported. Checks pointers and process addresses for Linux and Windows NT, and enables the program object.

Will assert if a GL error is thrown beforehand.

Propane::Shader::Program::~Program  )  [virtual]
 

Basic destructor that turns off the shader and deletes all attached programs.

Basic deconstructor for the program. Turns off the shader, frees all attached shaders, then the program object itself.


Member Function Documentation

bool Propane::Shader::Program::compile  ) 
 

Compile the shader (must be done after loading all necessary attached programs). Returns false on compile failure.

Compile a program, once you have added whatever shaders you want to it. Emits a warning to stderr if the shader did not validate.

Returns:
True if the link succeeded, false otherwise.
Examples:
ShaderUse.cpp.

std::string Propane::Shader::Program::getInfoLog  ) 
 

Return the info log from program compilation (if any).

Returns the info log for the main program. Uses getShaderInfoLog internally.

Returns:
The info log for the main program object only.
Examples:
ShaderUse.cpp.

GLint Propane::Shader::Program::getUniformLocation const std::string &  name  ) 
 

Get the handle for a uniform in the shader program.

Returns a handle to a shader program's named uniform value

Parameters:
name The name of the uniform value you're looking for (e.g. "timer")
Returns:
The handle to the uniform, or -1 if the shader is not ready/supported or the uniform was not found
Examples:
ShaderUse.cpp.

bool Propane::Shader::Program::isReady  ) 
 

Returns true if the shader is ready to use.

Checks if the program is ready. A program is only "ready" if the compile step has completed.

If programs are not ready, most of the calls that use them will abort.

Returns:
True if the program is ready, false otherwise.

bool Propane::Shader::Program::isSupported  ) 
 

Returns true if the shader can be used on this computer.

Checks if the program is supported by the current hardware. This value is set by the program constructor.

Almost all functions in this class will fail if the shader functions are not supported, for safety reasons. It is in your best interest to check this method before trying to load or use shaders, and select an alternate path if shader functionality is not available on this card.

Returns:
True if shaders are supported by the hardware, false otherwise.

void Propane::Shader::Program::loadFragmentShader const std::string &  filename  ) 
 

Load a fragment shader from a source file and attach it to this program.

Loads a fragment shader from disk and attaches it to the program. If the shader is not supported, the function exits silently. If the file is not found, it returns an error to stderr. If the compile fails, it returns an error to stderr.

Parameters:
filename The file name of the shader file to load (e.g. "data/shaders/shader.frag")
Examples:
ShaderUse.cpp.

void Propane::Shader::Program::loadVertexShader const std::string &  filename  ) 
 

Load a vertex shader from a source file and attach it to this program.

Loads a vertex shader from disk and attaches it to the program. If the shader is not supported, the function exits silently. If the file is not found, it returns an error to stderr. If the compile fails, it returns an error to stderr.

Parameters:
filename The file name of the shader file to load (e.g. "data/shaders/shader.vert")
Examples:
ShaderUse.cpp.

void Propane::Shader::Program::passToUniform GLint  uniformHandle,
float  value
 

Pass a floating-point number to a uniform value in the program.

Set the value of a given uniform from its handle.

Fails silently if the shader is not ready, or not supported.

Parameters:
uniformHandle The handle provided to you by getUniformLocation.
value The floating-point value to set the handle to.
Examples:
ShaderUse.cpp.

void Propane::Shader::Program::passVectorToUniform GLint  uniformHandle,
const Propane::Math::Vector3 &  theVector
 

Pass a floating-point Propane::Math::Vector3 to the program as a uniform vec3.

Pass a Propane::Math::Vector3 to the program through a given handle.

The handle must represent uniform vec3; check the OpenGL documentation for what happens when you have a uniform type mismatch.

Fails silently if the shader is not ready, or not supported.

Parameters:
uniformHandle The handle provided to you by getUniformLocation.
theVector The floating-point 3-vector that you are going to hand over.

void Propane::Shader::Program::turnOff  ) 
 

Turn off the shader.

Stop using the shader.

Fails silently if isSupported() is false.

Uses glUseProgramObjectARB.

Examples:
ShaderUse.cpp.

void Propane::Shader::Program::turnOn  ) 
 

Turn on the shader.

Start using the shader.

Fails silently if isSupported() is false.

Uses glUseProgramObjectARB.

Examples:
ShaderUse.cpp.


The documentation for this class was generated from the following files:
Generated on Sun Jan 14 16:49:12 2007 for Propane Injector by  doxygen 1.4.6