MaterialX 1.38.2
|
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 InputMap & | updateUniformsList () |
const InputMap & | updateAttributesList () |
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 InputMap & | getUniformsList () |
Get list of program input uniforms. More... | |
const InputMap & | getAttributesList () |
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... | |
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.
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.
stage | Name of the shader stage. |
sourcCode | Source code of the shader stage. |
bool bind | ( | ) |
Bind the program.
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.
inputs | Attribute inputs to bind to |
mesh | Mesh containing streams to bind |
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.
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.
variable | Variable to search for |
variableList | List of program inputs to search |
foundList | Returned list of found program inputs. Empty if none found. |
exactMatch | Search for exact variable name match. |
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.
const string & getStageSourceCode | ( | const string & | stage | ) | const |
Get source code string for a given stage.
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.
void setStages | ( | ShaderPtr | shader | ) |
Set up code stages to validate based on an input hardware shader.
shader | Hardware shader to use |