MaterialX 1.38.10
Loading...
Searching...
No Matches
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 &sourceCode)
 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...
 
ShaderPtr getShader () const
 Return the shader, if any, used to generate this program.
 
Program building
void build ()
 Build shader program data from the source code set for each shader stage. More...
 
bool hasBuiltData ()
 Return true if built shader program data is present.
 
void clearBuiltData ()
 
Program activation
bool bind ()
 Bind the program. More...
 
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 (CameraPtr camera)
 Bind view information.
 
void bindTimeAndFrame (float time=1.0f, float frame=1.0f)
 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 ()
 
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.
 
using InputMap = std::unordered_map< string, InputPtr >
 Program input shaded pointer map type.
 
const InputMapgetUniformsList ()
 Get list of program input uniforms. More...
 
const InputMapgetAttributesList ()
 Get list of program input attributes. More...
 
void findInputs (const 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 &  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.

◆ 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()

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

◆ findInputs()

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

◆ 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: