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

#include <GlslProgram.h>


struct  Input

Public Member Functions

virtual ~GlslProgram ()
 Destructor. More...
Shader code setup
void setStages (ShaderPtr shader)
void addStage (const string &stage, const string &sourcCode)
const stringgetStageSourceCode (const string &stage) const
void clearStages ()
 Clear out any existing stages. More...
ShaderPtr getShader () const
 Return the shader, if any, used to generate this program. More...
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...
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


Protected Member Functions

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

Static Protected Member Functions

static int mapTypeToOpenGLType (const TypeDesc *type)

Program validation and introspection

using InputPtr = std::shared_ptr< Input >
 Program input structure shared pointer type. More...
using InputMap = std::unordered_map< std::string, InputPtr >
 Program input shaded pointer map type. More...
unsigned int build ()
const InputMapgetUniformsList ()
const InputMapgetAttributesList ()
void findInputs (const std::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<std::string, InputPtr>

Program input shaded pointer map type.

Definition at line 119 of file GlslProgram.h.

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

Program input structure shared pointer type.

Definition at line 117 of file GlslProgram.h.

Constructor & Destructor Documentation

virtual GlslProgram::~GlslProgram ( )


GlslProgram::GlslProgram ( )

Member Function Documentation

void GlslProgram::addStage ( const string stage,
const string sourcCode 

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

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

Bind the program.

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.

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 
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 
void GlslProgram::bindViewInformation ( CameraPtr  camera)

Bind view information.

unsigned int GlslProgram::build ( )

Create the shader program from stages specified An exception is thrown if the program cannot be created. The exception will contain a list of program creation errors.

Program identifier.
void GlslProgram::clearInputLists ( )
void GlslProgram::clearStages ( )

Clear out any existing stages.

static GlslProgramPtr GlslProgram::create ( )

Create a GLSL program instance.

Definition at line 35 of file GlslProgram.h.

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

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

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.
MaterialX::ValuePtr GlslProgram::findUniformValue ( const std::string uniformName,
const InputMap uniformList 
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.

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

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

Definition at line 64 of file GlslProgram.h.

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

Get source code string for a given stage.

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.

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

Return true if the program has active attributes.

bool GlslProgram::hasUniform ( const string name)

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

static int GlslProgram::mapTypeToOpenGLType ( const TypeDesc type)
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.

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 ( )
const InputMap& GlslProgram::updateUniformsList ( )

Member Data Documentation


Definition at line 205 of file GlslProgram.h.

unsigned int GlslProgram::UNDEFINED_OPENGL_RESOURCE_ID

Definition at line 204 of file GlslProgram.h.

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