CUGL
Cornell University Game Library
|
#include <CUShader.h>
Public Member Functions | |
Shader () | |
~Shader () | |
virtual void | dispose () |
std::string | getVertSource () const |
std::string | getFragSource () const |
bool | isReady () const |
bool | isActive () const |
GLuint | getProgram () const |
virtual void | bind () |
virtual void | unbind () |
Protected Member Functions | |
virtual bool | compile () |
Static Protected Member Functions | |
static bool | validateShader (GLuint shader, const char *type) |
static void | logShaderError (GLuint shader) |
static void | logProgramError (GLuint shader) |
Protected Attributes | |
GLuint | _program |
GLuint | _vertShader |
GLuint | _fragShader |
const char * | _vertSource |
const char * | _fragSource |
bool | _active |
This class is the base abstract class for any GLSL shader.
Specific shaders have attached attributes and uniforms. Since it is difficult to write a class that takes all of the possibilities into consideration (and is type-safe), we use subclasses to implement specific shaders. This class just provides support for compilation and binding.
This class is written to be agnostic about whether we are using OpenGL or OpenGLES. Because these shader languages are slightly different, subclasses should take this difference into account.
|
inline |
Creates an uninitialized shader with no source.
You must initialize the shader to add a source and compiled it.
|
inline |
Deletes this shader, disposing all resources.
|
virtual |
Binds this shader, making it active.
Once bound, any OpenGL calls will then be sent to this shader.
Reimplemented in cugl::SpriteShader.
|
protectedvirtual |
Compiles this shader from the given vertex and fragment shader sources.
When compilation is complete, the shader will not be bound. However, any shader that was actively bound during compilation also be unbound as well.
If compilation fails, it will display error messages on the log.
Reimplemented in cugl::SpriteShader.
|
virtual |
Deletes the OpenGL shader and resets all attributes.
You must reinitialize the shader to use it.
Reimplemented in cugl::SpriteShader.
|
inline |
Returns the source string for the fragment shader.
The string is empty if not defined.
|
inline |
Returns the OpenGL program associated with this shader.
This method will return 0 if the program is not initialized.
|
inline |
Returns the source string for the vertex shader.
The string is empty if not defined.
|
inline |
Returns true if this shader is currently active.
The shader is active if its program is currently bound. Any OpenGL calls will then be sent to this shader.
|
inline |
Returns true if this shader has been compiled and is ready for use.
|
staticprotected |
Displays the program linker errors to the log.
If there were no errors, this method will do nothing.
shader | The program to test |
|
staticprotected |
Displays the shader compilation errors to the log.
If there were no errors, this method will do nothing.
shader | The shader to test |
|
virtual |
Unbinds this shader, making it no longer active.
Once unbound, OpenGL calls will no longer be sent to this shader.
Reimplemented in cugl::SpriteShader.
|
staticprotected |
Returns true if the shader was compiled properly.
If compilation fails, it will display error messages on the log.
shader | The shader to test |
type | The shader type (vertex or fragment) |
|
protected |
Whether or not this shader is currently active
|
protected |
The OpenGL fragment shader for this shader
|
protected |
The source string for the fragment shader
|
protected |
The OpenGL program for this shader
|
protected |
The OpenGL vertex shader for this shader
|
protected |
The source string for the vertex shader