PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
pk::Shader Class Reference

Class for supporting OpenGL GLSL shaders. More...

#include <Shader.hpp>

Collaboration diagram for pk::Shader:
Collaboration graph

Public Member Functions

 Shader ()
 Default constructor - in most cases you should be using the other constructor! Use this in the event you need to load shaders directly from a C-string rather than a file. More...
 
 Shader (const char *vertexLocation, const char *fragmentLocation)
 Preferred constructor for the Shader class. All OpenGL shader programs need at least a vertex and fragment shader to work correctly. More...
 
 ~Shader ()
 
void loadFromString (const char *vertexCode, const char *fragmentCode)
 Load OpenGL shader programs from C-strings. More...
 
void load (const char *vertexLocation, const char *fragmentLocation)
 Load OpenGL shader programs from file locations specified with C-style strings. More...
 
std::string read (const char *fileLocation)
 Read the contents of a shader file and output a std::string to be loaded as an OpenGL GLSL shader. More...
 
GLuint & getProjectionLocation ()
 Get the memory location of the OpenGL Projection matrix in use. More...
 
GLuint & getModelLocation ()
 Get the memory location of the OpenGL Model matrix in use. More...
 
GLuint & getViewLocation ()
 Get the memory location of the OpenGL View matrix in use. More...
 
GLuint & getAmbientIntensityLocation ()
 Get the memory location of the ambient intensity for lighting. More...
 
GLuint & getAmbientColorLocation ()
 Get the memory location of the ambient color for lighting. More...
 
GLuint & getDiffuseIntensityLocation ()
 Get the memory location of the diffuse intensity for lighting. More...
 
GLuint & getDirectionLocation ()
 Get the memory location of the direction of the lighting. More...
 
GLuint & getEyePositionLocation ()
 Get the memory location of the eye position of the lighting. More...
 
GLuint & getSpecularIntensityLocation ()
 Get the memory location of the specular intensity of the lighting. More...
 
GLuint & getShininessLocation ()
 Get the memory location of the shininess of the lighting. More...
 
void use ()
 Call the necessary OpenGL code to use the shader. Needs to be called before drawing occurs in the game loop. More...
 
void clear ()
 Resets all states and data contained in the Shader class. Calls glDeleteProgram(...) because Shader class owns the shader program. More...
 

Private Member Functions

void compile (const char *vertexCode, const char *fragmentCode)
 Internal function that compiles and validates the GLSL shaders being loaded. More...
 
void attach (GLuint theProgram, const char *shaderCode, GLenum shaderType)
 Internal function that performs the necessary actions to attach a shader to the OpenGL program. More...
 

Private Attributes

GLuint m_shaderID
 The OpenGL GLSL shader ID. More...
 
GLuint m_uniformProjection
 An OpenGL Projection matrix memory location. More...
 
GLuint m_uniformModel
 An OpenGL Model matrix memory location. More...
 
GLuint m_uniformView
 An OpenGL View matrix memory location. More...
 
GLuint m_uniformAmbientIntensity
 A memory location for ambient intensity. More...
 
GLuint m_uniformAmbientColor
 A memory location for lighting ambient color. More...
 
GLuint m_uniformDiffuseIntensity
 A memory location for diffuse intensity. More...
 
GLuint m_uniformDirection
 A memory location for direction. More...
 
GLuint m_uniformEyePosition
 A memory location for eye position (camera). More...
 
GLuint m_uniformSpecularIntensity
 A memory location for the specular intensity of the material. More...
 
GLuint m_uniformShininess
 A memory location for the shininess of the material. More...
 

Detailed Description

Class for supporting OpenGL GLSL shaders.

Constructor & Destructor Documentation

◆ Shader() [1/2]

pk::Shader::Shader ( )

Default constructor - in most cases you should be using the other constructor! Use this in the event you need to load shaders directly from a C-string rather than a file.

◆ Shader() [2/2]

pk::Shader::Shader ( const char *  vertexLocation,
const char *  fragmentLocation 
)

Preferred constructor for the Shader class. All OpenGL shader programs need at least a vertex and fragment shader to work correctly.

◆ ~Shader()

pk::Shader::~Shader ( )

Member Function Documentation

◆ attach()

void pk::Shader::attach ( GLuint  theProgram,
const char *  shaderCode,
GLenum  shaderType 
)
private

Internal function that performs the necessary actions to attach a shader to the OpenGL program.

◆ clear()

void pk::Shader::clear ( )

Resets all states and data contained in the Shader class. Calls glDeleteProgram(...) because Shader class owns the shader program.

◆ compile()

void pk::Shader::compile ( const char *  vertexCode,
const char *  fragmentCode 
)
private

Internal function that compiles and validates the GLSL shaders being loaded.

◆ getAmbientColorLocation()

GLuint & pk::Shader::getAmbientColorLocation ( )
inline

Get the memory location of the ambient color for lighting.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the ambient color.

◆ getAmbientIntensityLocation()

GLuint & pk::Shader::getAmbientIntensityLocation ( )
inline

Get the memory location of the ambient intensity for lighting.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the ambient intensity.

◆ getDiffuseIntensityLocation()

GLuint & pk::Shader::getDiffuseIntensityLocation ( )
inline

Get the memory location of the diffuse intensity for lighting.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the diffuse intensity.

◆ getDirectionLocation()

GLuint & pk::Shader::getDirectionLocation ( )
inline

Get the memory location of the direction of the lighting.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the light's direction.

◆ getEyePositionLocation()

GLuint & pk::Shader::getEyePositionLocation ( )
inline

Get the memory location of the eye position of the lighting.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the light's eye position.

◆ getModelLocation()

GLuint & pk::Shader::getModelLocation ( )
inline

Get the memory location of the OpenGL Model matrix in use.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the Model matrix.

◆ getProjectionLocation()

GLuint & pk::Shader::getProjectionLocation ( )
inline

Get the memory location of the OpenGL Projection matrix in use.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the Projection matrix.

◆ getShininessLocation()

GLuint & pk::Shader::getShininessLocation ( )
inline

Get the memory location of the shininess of the lighting.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the light's shininess.

◆ getSpecularIntensityLocation()

GLuint & pk::Shader::getSpecularIntensityLocation ( )
inline

Get the memory location of the specular intensity of the lighting.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the light's specular intensity.

◆ getViewLocation()

GLuint & pk::Shader::getViewLocation ( )
inline

Get the memory location of the OpenGL View matrix in use.

Returns
GLuint - an OpenGL unsigned integer mapped to the address of the View matrix.

◆ load()

void pk::Shader::load ( const char *  vertexLocation,
const char *  fragmentLocation 
)

Load OpenGL shader programs from file locations specified with C-style strings.

Parameters
constchar* vertexLocation - a C-style string containing the vertex shader file location.
constchar* fragmentLocation - a C-style string containing the fragment shader file location.

◆ loadFromString()

void pk::Shader::loadFromString ( const char *  vertexCode,
const char *  fragmentCode 
)

Load OpenGL shader programs from C-strings.

Parameters
constchar* vertexCode - a C-style string containing the vertex shader code.
constchar* fragmentCode - a C-style string containing the fragment shader code.

◆ read()

std::string pk::Shader::read ( const char *  fileLocation)

Read the contents of a shader file and output a std::string to be loaded as an OpenGL GLSL shader.

◆ use()

void pk::Shader::use ( )

Call the necessary OpenGL code to use the shader. Needs to be called before drawing occurs in the game loop.

Member Data Documentation

◆ m_shaderID

GLuint pk::Shader::m_shaderID
private

The OpenGL GLSL shader ID.

◆ m_uniformAmbientColor

GLuint pk::Shader::m_uniformAmbientColor
private

A memory location for lighting ambient color.

◆ m_uniformAmbientIntensity

GLuint pk::Shader::m_uniformAmbientIntensity
private

A memory location for ambient intensity.

◆ m_uniformDiffuseIntensity

GLuint pk::Shader::m_uniformDiffuseIntensity
private

A memory location for diffuse intensity.

◆ m_uniformDirection

GLuint pk::Shader::m_uniformDirection
private

A memory location for direction.

◆ m_uniformEyePosition

GLuint pk::Shader::m_uniformEyePosition
private

A memory location for eye position (camera).

◆ m_uniformModel

GLuint pk::Shader::m_uniformModel
private

An OpenGL Model matrix memory location.

◆ m_uniformProjection

GLuint pk::Shader::m_uniformProjection
private

An OpenGL Projection matrix memory location.

◆ m_uniformShininess

GLuint pk::Shader::m_uniformShininess
private

A memory location for the shininess of the material.

◆ m_uniformSpecularIntensity

GLuint pk::Shader::m_uniformSpecularIntensity
private

A memory location for the specular intensity of the material.

◆ m_uniformView

GLuint pk::Shader::m_uniformView
private

An OpenGL View matrix memory location.


The documentation for this class was generated from the following file: