MaterialX 1.38.2
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
GlslProgram Class Reference

A class representing an executable GLSL program. More...

#include <GlslProgram.h>

Classes

struct  Input
 Structure to hold information about program inputs. More...
 

Public Member Functions

virtual ~GlslProgram ()
 Destructor.
 
Shader code setup
void setStages (ShaderPtr shader)
 Set up code stages to validate based on an input hardware shader. More...
 
void addStage (const string &stage, const string &sourcCode)
 Set the code stages based on a list of stage strings. More...
 
const string & getStageSourceCode (const string &stage) const
 Get source code string for a given stage. More...
 
void clearStages ()
 Clear out any existing stages.
 
Program activation
bool bind ()
 Bind the program. More...
 
void bindInputs (ViewHandlerPtr viewHandler, GeometryHandlerPtr geometryHandler, ImageHandlerPtr imageHandler, LightHandlerPtr lightHandler)
 Bind inputs.
 
void unbindInputs (ImageHandlerPtr imageHandler)
 Unbind inputs.
 
bool hasActiveAttributes () const
 Return true if the program has active attributes.
 
bool hasUniform (const string &name)
 Return true if a uniform with the given name is present.
 
void bindUniform (const string &name, ConstValuePtr value, bool errorIfMissing=true)
 Bind a value to the uniform with the given name.
 
void bindAttribute (const GlslProgram::InputMap &inputs, MeshPtr mesh)
 Bind attribute buffers to attribute inputs. More...
 
void bindPartition (MeshPartitionPtr partition)
 Bind input geometry partition (indexing)
 
void bindMesh (MeshPtr mesh)
 Bind input geometry streams.
 
void unbindGeometry ()
 Unbind any bound geometry.
 
void bindTextures (ImageHandlerPtr imageHandler)
 Bind any input textures.
 
void bindLighting (LightHandlerPtr lightHandler, ImageHandlerPtr imageHandler)
 Bind lighting.
 
void bindViewInformation (ViewHandlerPtr viewHandler)
 Bind view information.
 
void bindTimeAndFrame ()
 Bind time and frame.
 
void unbind () const
 Unbind the program. Equivalent to binding no program.
 
Utilities
void printUniforms (std::ostream &outputStream)
 Print all uniforms to the given stream.
 
void printAttributes (std::ostream &outputStream)
 Print all attributes to the given stream.
 

Static Public Member Functions

static GlslProgramPtr create ()
 Create a GLSL program instance.
 

Static Public Attributes

static unsigned int UNDEFINED_OPENGL_RESOURCE_ID = 0
 
static int UNDEFINED_OPENGL_PROGRAM_LOCATION = -1
 

Protected Member Functions

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.
 
using InputMap = std::unordered_map< std::string, InputPtr >
 Program input shaded pointer map type.
 
unsigned int build ()
 Create the shader program from stages specified An exception is thrown if the program cannot be created. More...
 
const InputMapgetUniformsList ()
 Get list of program input uniforms. More...
 
const InputMapgetAttributesList ()
 Get list of program input attributes. More...
 
void 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. More...
 

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.

Member Function Documentation

◆ addStage()

void 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.

Parameters
stageName of the shader stage.
sourcCodeSource code of the shader stage.

◆ bind()

bool bind ( )

Bind the program.

Returns
False if failed

◆ bindAttribute()

void 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

◆ build()

unsigned int 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.

Returns
Program identifier.

◆ findInputs()

void 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.

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.

◆ getAttributesList()

const GlslProgram::InputMap & 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.

◆ getStageSourceCode()

const string & getStageSourceCode ( const string &  stage) const

Get source code string for a given stage.

Returns
Shader stage string. String is empty if not found.

◆ getUniformsList()

const GlslProgram::InputMap & 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.

◆ setStages()

void setStages ( ShaderPtr  shader)

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

Parameters
shaderHardware shader to use

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