MaterialX 1.39.1
|
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 |
static int | UNDEFINED_OPENGL_PROGRAM_LOCATION |
Protected Member Functions | |
const InputMap & | updateUniformsList () |
const InputMap & | updateAttributesList () |
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 (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 InputMap & | getUniformsList () |
Get list of program input uniforms. More... | |
const InputMap & | getAttributesList () |
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... | |
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 & | sourceCode | ||
) |
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. |
sourceCode | 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 |
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.
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.
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 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 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 |