Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Member Functions | Static Public Member Functions | List of all members
jop::ShaderProgram Class Reference

#include <ShaderProgram.hpp>

Inheritance diagram for jop::ShaderProgram:
jop::Resource jop::SafeReferenceable< Resource > jop::SerializeInfo

Public Member Functions

 ShaderProgram (const std::string &name)
 Constructor. More...
 
 ~ShaderProgram ()
 Destructor. More...
 
template<typename... Args>
bool load (const std::string &pp, const Args &...args)
 Load shaders. More...
 
bool attachShader (const Shader &shader)
 Attach shader to the program. More...
 
bool link ()
 Link the shader program. More...
 
void unlink ()
 Unlink the shader program. More...
 
bool bind () const
 Bind this shader program for use. More...
 
void unbind () const
 Unbind this shader program. More...
 
bool validate () const
 Validate program status. More...
 
bool isValid () const
 Check if this program is valid. More...
 
bool setUniform (const std::string &name, const glm::mat4 &matrix)
 Set a mat4 uniform. More...
 
bool setUniform (const std::string &name, const float *matrices, const unsigned int amount)
 Set an array of matrices. More...
 
bool setUniform (const std::string &name, const glm::mat3 &matrix)
 Set a mat3 uniform. More...
 
bool setUniform (const std::string &name, const glm::vec2 &vector)
 Set a two-dimensional float vector uniform. More...
 
bool setUniform (const std::string &name, const glm::vec3 &vector)
 Set a vec3 uniform. More...
 
bool setUniform (const std::string &name, const glm::vec4 &vector)
 Set a vec4 uniform. More...
 
bool setUniform (const std::string &name, const Texture &texture, const unsigned int unit)
 Set a texture uniform. More...
 
bool setUniform (const std::string &name, const float value)
 Set a float uniform. More...
 
bool setUniform (const std::string &name, const int value)
 Set an integer uniform. More...
 
bool setUniform (const std::string &name, const bool value)
 Set a boolean uniform. More...
 
- Public Member Functions inherited from jop::Resource
 Resource (const std::string &name)
 Constructor. More...
 
virtual ~Resource ()=0
 Virtual destructor. More...
 
const std::string & getName () const
 Get the name of this resource. More...
 
void setPersistence (const unsigned short level)
 Set the persistence level. More...
 
unsigned short getPersistence () const
 Get the persistence level. More...
 
- Public Member Functions inherited from jop::SafeReferenceable< Resource >
WeakReference< ResourcegetReference () const
 Get a weak reference to the bound object. More...
 
- Public Member Functions inherited from jop::SerializeInfo
 SerializeInfo ()
 
void setSerializePackage (const uint16 package)
 
uint16 getSerializePackage () const
 
void setShouldSerialize (const bool set)
 
bool shouldSerialize () const
 
void setLightSerializeable (const bool set)
 
bool isLightSerializeable () const
 

Static Public Member Functions

static ShaderProgramgetDefault ()
 Get the default shader program. More...
 
static ShaderProgramgetError ()
 Get the error shader program. More...
 
static unsigned int getMaxAttributes ()
 Get the maximum vertex attributes. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jop::Resource
 Resource (const Resource &other, const std::string &newName)
 Copy constructor. More...
 
- Protected Member Functions inherited from jop::SafeReferenceable< Resource >
 SafeReferenceable (Resource *ref)
 Constructor. More...
 
 SafeReferenceable (SafeReferenceable< Resource > &&other)
 Move constructor. More...
 
SafeReferenceableoperator= (SafeReferenceable< Resource > &&other)
 Move assignment operator. More...
 
 ~SafeReferenceable ()
 Protected destructor. More...
 

Detailed Description

Definition at line 40 of file ShaderProgram.hpp.

Constructor & Destructor Documentation

jop::ShaderProgram::ShaderProgram ( const std::string &  name)

Constructor.

Parameters
nameName of the resource
jop::ShaderProgram::~ShaderProgram ( )

Destructor.

Member Function Documentation

bool jop::ShaderProgram::attachShader ( const Shader shader)

Attach shader to the program.

Parameters
shaderReference to shader object
Returns
True if successful
bool jop::ShaderProgram::bind ( ) const

Bind this shader program for use.

Returns
True if successful
static ShaderProgram& jop::ShaderProgram::getDefault ( )
static

Get the default shader program.

Returns
Reference to the default shader
static ShaderProgram& jop::ShaderProgram::getError ( )
static

Get the error shader program.

This shader will paint any drawn object bright red.

Returns
Reference to the error shader
static unsigned int jop::ShaderProgram::getMaxAttributes ( )
static

Get the maximum vertex attributes.

Returns
The maximum number of vertex attributes supported
bool jop::ShaderProgram::isValid ( ) const

Check if this program is valid.

Returns
True if valid
bool jop::ShaderProgram::link ( )

Link the shader program.

Returns
True if successful
template<typename... Args>
bool jop::ShaderProgram::load ( const std::string &  pp,
const Args &...  args 
)

Load shaders.

Attaches a variable number of shaders to shader program.

Note
Can load some shaders as objects and others as source codes simultaneously.

Invalid shader objects or empty sources will be silently ignored and won't be used in the final link operation.

Parameters
ppPreprocessor string
argsVariable amount of shaders objects or shader sources
Returns
True if successful
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const glm::mat4 &  matrix 
)

Set a mat4 uniform.

Parameters
nameUniform name
matrixA 4x4 matrix
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const float *  matrices,
const unsigned int  amount 
)

Set an array of matrices.

This is for 4x4 matrices (glm::mat4).

Parameters
nameThe uniform name
matricesPointer to the first element of the first matrix
amountAmount of the matrices
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const glm::mat3 &  matrix 
)

Set a mat3 uniform.

Parameters
nameUniform name
matrixA 3x3 matrix
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const glm::vec2 &  vector 
)

Set a two-dimensional float vector uniform.

Parameters
nameName of the uniform
vectorThe vector to set
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const glm::vec3 &  vector 
)

Set a vec3 uniform.

Parameters
nameUniform name
vectorA 3-dimensional vector
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const glm::vec4 &  vector 
)

Set a vec4 uniform.

Parameters
nameUniform name
vectorA 4-dimensional vector
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const Texture texture,
const unsigned int  unit 
)

Set a texture uniform.

Parameters
nameUniform name
textureA texture
unitThe texture unit
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const float  value 
)

Set a float uniform.

Parameters
nameName of the uniform
valueThe float value
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const int  value 
)

Set an integer uniform.

Parameters
nameName of the uniform
valueThe integer to set
Returns
True if set successfully
bool jop::ShaderProgram::setUniform ( const std::string &  name,
const bool  value 
)

Set a boolean uniform.

Parameters
nameName of the uniform
valueThe boolean to set
Returns
True if set successfully
void jop::ShaderProgram::unbind ( ) const

Unbind this shader program.

Returns
True if successful
void jop::ShaderProgram::unlink ( )

Unlink the shader program.

Unbinds shader program and destroys it.

bool jop::ShaderProgram::validate ( ) const

Validate program status.

Returns
True if successfully validated

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