CUGL 1.3
Cornell University Game Library
|
#include <CUSpriteShader.h>
Public Member Functions | |
SpriteShader () | |
~SpriteShader () | |
void | dispose () override |
bool | init () |
bool | init (std::string vsource, std::string fsource) |
bool | init (const char *vsource, const char *fsource) |
GLint | getPositionAttr () const |
GLint | getColorAttr () const |
GLint | getTexCoodAttr () const |
GLint | getPerspectiveUni () const |
GLint | getTextureUni () const |
void | setPerspective (const Mat4 &matrix) |
const Mat4 & | getPerspective () |
void | setTexture (const std::shared_ptr< Texture > &texture) |
std::shared_ptr< Texture > | getTexture () |
const std::shared_ptr< Texture > & | getTexture () const |
void | attach (GLuint vArray, GLuint vBuffer) |
void | bind () override |
void | unbind () override |
Public Member Functions inherited from cugl::Shader | |
Shader () | |
~Shader () | |
std::string | getVertSource () const |
std::string | getFragSource () const |
bool | isReady () const |
bool | isActive () const |
GLuint | getProgram () const |
Static Public Member Functions | |
static std::shared_ptr< SpriteShader > | alloc () |
static std::shared_ptr< SpriteShader > | alloc (std::string vsource, std::string fsource) |
static std::shared_ptr< SpriteShader > | alloc (const char *vsource, const char *fsource) |
Protected Member Functions | |
bool | compile () override |
bool | validateVariable (GLint variable, const char *name) |
Additional Inherited Members | |
Static Protected Member Functions inherited from cugl::Shader | |
static bool | validateShader (GLuint shader, const char *type) |
static void | logShaderError (GLuint shader) |
static void | logProgramError (GLuint shader) |
Protected Attributes inherited from cugl::Shader | |
GLuint | _program |
GLuint | _vertShader |
GLuint | _fragShader |
const char * | _vertSource |
const char * | _fragSource |
bool | _active |
This class is a GLSL shader to use with a sprite batch.
This class provides you the option to use your own shader sources. However, any shader used with this class must have the following properties.
First, it must provide three attributes corresponding to the Vertex2 class. These attributes must be names as follows.
aPosition: The position attribute aColor: The color attribute aTexCoord: The texture coordinate attribute
In addition, it must include the following two uniforms.
uPerspective: The perspective matrix (combined modelview projection) uTexture: The shading texture
Any other attributes or uniforms will be ignored.
|
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.
|
inlinestatic |
Returns a new shader with the default vertex and fragment source.
The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will not be bound. However, any shader that was actively bound during compilation also be unbound as well.
|
inlinestatic |
Returns a new shader with the given vertex and fragment source.
The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will not be bound. However, any shader that was actively bound during compilation also be unbound as well.
vsource | The source string for the vertex shader. |
fsource | The source string for the fragment shader. |
|
inlinestatic |
Returns a new shader with the given vertex and fragment source.
The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will not be bound. However, any shader that was actively bound during compilation also be unbound as well.
vsource | The source string for the vertex shader. |
fsource | The source string for the fragment shader. |
void cugl::SpriteShader::attach | ( | GLuint | vArray, |
GLuint | vBuffer | ||
) |
Attaches the given memory buffer to this shader.
Because of limitations in OpenGL ES, we cannot draw anything without both a vertex buffer object and an vertex array object.
vArray | The vertex array object |
vBuffer | The vertex buffer object |
|
overridevirtual |
Binds this shader, making it active.
Once bound, any OpenGL calls will then be sent to this shader.
Reimplemented from cugl::Shader.
|
overrideprotectedvirtual |
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 from cugl::Shader.
|
overridevirtual |
Deletes the OpenGL shader and resets all attributes.
You must reinitialize the shader to use it.
Reimplemented from cugl::Shader.
|
inline |
Returns the GLSL location for the color attribute
This method will return -1 if the program is not initialized.
|
inline |
Returns the current perspective matrix in use.
|
inline |
Returns the GLSL location for the perspective matrix uniform
This method will return -1 if the program is not initialized.
|
inline |
Returns the GLSL location for the position attribute
This method will return -1 if the program is not initialized.
|
inline |
Returns the GLSL location for the texture coordinate attribute
This method will return -1 if the program is not initialized.
|
inline |
Returns the current texture in use.
|
inline |
Returns the current texture in use.
|
inline |
Returns the GLSL location for the texture uniform
This method will return -1 if the program is not initialized.
bool cugl::SpriteShader::init | ( | ) |
Initializes this shader with the default vertex and fragment source.
The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will not be bound. However, any shader that was actively bound during compilation also be unbound as well.
bool cugl::SpriteShader::init | ( | const char * | vsource, |
const char * | fsource | ||
) |
Initializes this shader with the given vertex and fragment source.
The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will not be bound. However, any shader that was actively bound during compilation also be unbound as well.
vsource | The source string for the vertex shader. |
fsource | The source string for the fragment shader. |
|
inline |
Initializes this shader with the given vertex and fragment source.
The shader will compile the vertex and fragment sources and link them together. When compilation is complete, the shader will not be bound. However, any shader that was actively bound during compilation also be unbound as well.
vsource | The source string for the vertex shader. |
fsource | The source string for the fragment shader. |
void cugl::SpriteShader::setPerspective | ( | const Mat4 & | matrix | ) |
Sets the perspective matrix to use in the shader.
matrix | The perspective matrix |
void cugl::SpriteShader::setTexture | ( | const std::shared_ptr< Texture > & | texture | ) |
Sets the texture in use in the shader
texture | The shader texture |
|
overridevirtual |
Unbinds this shader, making it no longer active.
Once unbound, OpenGL calls will no longer be sent to this shader.
Reimplemented from cugl::Shader.
|
protected |
Returns true if the GLSL variable was found in this shader.
If variable is not found, it will display error messages on the log.
variable | The variable (reference) to test |
name | The variable (name) to test |