HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GlslProgram Class Reference

#include <GlslProgram.h>

Classes

struct  Input
 

Public Member Functions

virtual ~GlslProgram ()
 Destructor. More...
 
Shader code setup
void setStages (ShaderPtr shader)
 
void addStage (const string &stage, const string &sourceCode)
 
const stringgetStageSourceCode (const string &stage) const
 
ShaderPtr getShader () const
 Return the shader, if any, used to generate this program. More...
 
Program building
void build ()
 
bool hasBuiltData ()
 Return true if built shader program data is present. More...
 
void clearBuiltData ()
 
Program activation
bool bind ()
 
bool hasActiveAttributes () const
 Return true if the program has active attributes. More...
 
bool hasUniform (const string &name)
 Return true if a uniform with the given name is present. More...
 
void bindUniform (const string &name, ConstValuePtr value, bool errorIfMissing=true)
 Bind a value to the uniform with the given name. More...
 
void bindAttribute (const GlslProgram::InputMap &inputs, MeshPtr mesh)
 
void bindPartition (MeshPartitionPtr partition)
 Bind input geometry partition (indexing) More...
 
void bindMesh (MeshPtr mesh)
 Bind input geometry streams. More...
 
void unbindGeometry ()
 Unbind any bound geometry. More...
 
void bindTextures (ImageHandlerPtr imageHandler)
 Bind any input textures. More...
 
void bindLighting (LightHandlerPtr lightHandler, ImageHandlerPtr imageHandler)
 Bind lighting. More...
 
void bindViewInformation (CameraPtr camera)
 Bind view information. More...
 
void bindTimeAndFrame (float time=1.0f, float frame=1.0f)
 Bind time and frame. More...
 
void unbind () const
 Unbind the program. Equivalent to binding no program. More...
 
Utilities
void printUniforms (std::ostream &outputStream)
 Print all uniforms to the given stream. More...
 
void printAttributes (std::ostream &outputStream)
 Print all attributes to the given stream. More...
 

Static Public Member Functions

static GlslProgramPtr create ()
 Create a GLSL program instance. More...
 

Static Public Attributes

static unsigned int UNDEFINED_OPENGL_RESOURCE_ID
 
static int UNDEFINED_OPENGL_PROGRAM_LOCATION
 

Protected Member Functions

 GlslProgram ()
 
const InputMapupdateUniformsList ()
 
const InputMapupdateAttributesList ()
 
ValuePtr findUniformValue (const string &uniformName, const InputMap &uniformList)
 
ImagePtr bindTexture (unsigned int uniformType, int uniformLocation, const FilePath &filePath, ImageHandlerPtr imageHandler, const ImageSamplingProperties &imageProperties)
 
void bindUniformLocation (int location, ConstValuePtr value)
 

Static Protected Member Functions

static int mapTypeToOpenGLType (const TypeDesc *type)
 

Program introspection

using InputPtr = std::shared_ptr< Input >
 Program input structure shared pointer type. More...
 
using InputMap = std::unordered_map< string, InputPtr >
 Program input shaded pointer map type. More...
 
const InputMapgetUniformsList ()
 
const InputMapgetAttributesList ()
 
void findInputs (const string &variable, const InputMap &variableList, InputMap &foundList, bool exactMatch)
 

Detailed Description

A class representing an executable GLSL program.

There are two main interfaces which can be used. One which takes in a HwShader and one which allows for explicit setting of shader stage code.

Definition at line 31 of file GlslProgram.h.

Member Typedef Documentation

using GlslProgram::InputMap = std::unordered_map<string, InputPtr>

Program input shaded pointer map type.

Definition at line 127 of file GlslProgram.h.

using GlslProgram::InputPtr = std::shared_ptr<Input>

Program input structure shared pointer type.

Definition at line 125 of file GlslProgram.h.

Constructor & Destructor Documentation

virtual GlslProgram::~GlslProgram ( )
virtual

Destructor.

GlslProgram::GlslProgram ( )
protected

Member Function Documentation

void GlslProgram::addStage ( const string stage,
const string sourceCode 
)

Set the code stages based on a list of stage strings. Refer to the ordering of stages as defined by a HwShader.

Parameters
stageName of the shader stage.
sourceCodeSource code of the shader stage.
bool GlslProgram::bind ( )

Bind the program.

Returns
False if failed
void GlslProgram::bindAttribute ( const GlslProgram::InputMap inputs,
MeshPtr  mesh 
)

Bind attribute buffers to attribute inputs. A hardware buffer of the given attribute type is created and bound to the program locations for the input attribute.

Parameters
inputsAttribute inputs to bind to
meshMesh containing streams to bind
void GlslProgram::bindLighting ( LightHandlerPtr  lightHandler,
ImageHandlerPtr  imageHandler 
)

Bind lighting.

void GlslProgram::bindMesh ( MeshPtr  mesh)

Bind input geometry streams.

void GlslProgram::bindPartition ( MeshPartitionPtr  partition)

Bind input geometry partition (indexing)

ImagePtr GlslProgram::bindTexture ( unsigned int  uniformType,
int  uniformLocation,
const FilePath filePath,
ImageHandlerPtr  imageHandler,
const ImageSamplingProperties imageProperties 
)
protected
void GlslProgram::bindTextures ( ImageHandlerPtr  imageHandler)

Bind any input textures.

void GlslProgram::bindTimeAndFrame ( float  time = 1.0f,
float  frame = 1.0f 
)

Bind time and frame.

void GlslProgram::bindUniform ( const string name,
ConstValuePtr  value,
bool  errorIfMissing = true 
)

Bind a value to the uniform with the given name.

void GlslProgram::bindUniformLocation ( int  location,
ConstValuePtr  value 
)
protected
void GlslProgram::bindViewInformation ( CameraPtr  camera)

Bind view information.

void GlslProgram::build ( )

Build shader program data from the source code set for each shader stage.

An exception is thrown if the program cannot be built. The exception will contain a list of compilation errors.

void GlslProgram::clearBuiltData ( )

Build shader program data from the source code set for each shader stage.

An exception is thrown if the program cannot be built. The exception will contain a list of compilation errors.

static GlslProgramPtr GlslProgram::create ( )
inlinestatic

Create a GLSL program instance.

Definition at line 35 of file GlslProgram.h.

void GlslProgram::findInputs ( const string variable,
const InputMap variableList,
InputMap foundList,
bool  exactMatch 
)

Find the locations in the program which starts with a given variable name

Parameters
variableVariable to search for
variableListList of program inputs to search
foundListReturned list of found program inputs. Empty if none found.
exactMatchSearch for exact variable name match.
ValuePtr GlslProgram::findUniformValue ( const string uniformName,
const InputMap uniformList 
)
protected
const InputMap& GlslProgram::getAttributesList ( )

Get list of program input attributes. The program must have been created successfully first. An exception is thrown if the parsing of the program for attribute cannot be performed.

Returns
Program attributes list.
ShaderPtr GlslProgram::getShader ( ) const
inline

Return the shader, if any, used to generate this program.

Definition at line 61 of file GlslProgram.h.

const string& GlslProgram::getStageSourceCode ( const string stage) const

Get source code string for a given stage.

Returns
Shader stage string. String is empty if not found.
const InputMap& GlslProgram::getUniformsList ( )

Get list of program input uniforms. The program must have been created successfully first. An exception is thrown if the parsing of the program for uniforms cannot be performed.

Returns
Program uniforms list.
bool GlslProgram::hasActiveAttributes ( ) const

Return true if the program has active attributes.

bool GlslProgram::hasBuiltData ( )

Return true if built shader program data is present.

bool GlslProgram::hasUniform ( const string name)

Return true if a uniform with the given name is present.

static int GlslProgram::mapTypeToOpenGLType ( const TypeDesc type)
staticprotected
void GlslProgram::printAttributes ( std::ostream &  outputStream)

Print all attributes to the given stream.

void GlslProgram::printUniforms ( std::ostream &  outputStream)

Print all uniforms to the given stream.

void GlslProgram::setStages ( ShaderPtr  shader)

Set up code stages to validate based on an input hardware shader.

Parameters
shaderHardware shader to use
void GlslProgram::unbind ( ) const

Unbind the program. Equivalent to binding no program.

void GlslProgram::unbindGeometry ( )

Unbind any bound geometry.

const InputMap& GlslProgram::updateAttributesList ( )
protected
const InputMap& GlslProgram::updateUniformsList ( )
protected

Member Data Documentation

int GlslProgram::UNDEFINED_OPENGL_PROGRAM_LOCATION
static

Definition at line 213 of file GlslProgram.h.

unsigned int GlslProgram::UNDEFINED_OPENGL_RESOURCE_ID
static

Definition at line 212 of file GlslProgram.h.


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