Support Forum       G3D Web Page     
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Protected Member Functions | Friends | List of all members
G3D::Shader::ShaderProgram Class Reference

A wrapper around an actual openGL shader program object. More...

Inherits G3D::ReferenceCountedObject.

Classes

class  AttributeDeclaration
 Vertex Attribute (stream) variable declaration discovered in the program. More...
 
class  UniformDeclaration
 Uniform variable declaration discovered in the program. More...
 

Public Types

typedef Table< String, AttributeDeclarationAttributeDeclarationTable
 
typedef Table< String, UniformDeclarationUniformDeclarationTable
 

Public Member Functions

 ShaderProgram ()
 
void addActiveAttributesFromProgram ()
 Called from the constructor. More...
 
void addActiveUniformsFromProgram ()
 Called from the constructor. More...
 
void addUniformsFromCode (const String &code, const Args &args)
 Finds any uniform variables in the code string, and adds them to the uniform table. More...
 
void addUniformsFromSource (const Array< PreprocessedShaderSource > &preprocessedSource, const Args &args)
 Finds any uniform variables in the code for all shader stages that are not already in the uniform list that OpenGL returned and adds them to the uniform declaration table. More...
 
void addVertexAttributesFromSource (const Array< PreprocessedShaderSource > &preprocessedSource, const Args &args)
 Finds any vertex attribute variables in the code for the vertex shader that are not already in the attribute list that OpenGL returned and adds them to the attribute declaration table. More...
 
void compile (const Array< PreprocessedShaderSource > &preprocessedSource, const String &preambleAndMacroArgs, const Args &args, const Table< int, String > &indexToNameTable, Array< String > &code)
 Compile using the current macro args, preamble, and source code. More...
 
bool containsNonDummyUniform (const String &name)
 True if and only if the uniform declaration table contains a non-dummy entry name. More...
 
GLuint glShaderProgramObject ()
 The underlying OpenGL Program Object.
More...
 
void init (const Array< PreprocessedShaderSource > &preprocessedSource, const String &preambleAndMacroArgs, const Args &args, const Table< int, String > &indexToNameTable)
 Compile and link the shader, and set up the formal parameter lists. More...
 
bool isOk ()
 False if and only if there was an error in compilation or linking. More...
 
void link ()
 Link the program object. More...
 
void printUniformDeclarations () const
 Used for error reporting. More...
 

Static Public Member Functions

static shared_ptr< ShaderProgramcreate (const Array< PreprocessedShaderSource > &preprocessedSource, const String &preambleAndMacroArgs, const Args &args, const Table< int, String > &indexToNameTable)
 Compile and link the shader, returning a reference to it. More...
 

Public Attributes

AttributeDeclarationTable attributeDeclarationTable
 
GLuint glProgramObject
 The underlying OpenGL Program Object. More...
 
GLuint glShaderObject [STAGE_COUNT]
 The underlying OpenGL Shader Objects for all possible shader stages. More...
 
String messages
 Warning and error messages generated during compilation and/or linking. More...
 
bool ok
 False if compilation and/or linking failed. More...
 
UniformDeclarationTable uniformDeclarationTable
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Friends

class Shader
 

Detailed Description

A wrapper around an actual openGL shader program object.

Contains the shader objects and declarations of variables found by querying the program object

Member Typedef Documentation

◆ AttributeDeclarationTable

◆ UniformDeclarationTable

Constructor & Destructor Documentation

◆ ShaderProgram()

G3D::Shader::ShaderProgram::ShaderProgram ( )
inline

Member Function Documentation

◆ addActiveAttributesFromProgram()

void G3D::Shader::ShaderProgram::addActiveAttributesFromProgram ( )

Called from the constructor.

◆ addActiveUniformsFromProgram()

void G3D::Shader::ShaderProgram::addActiveUniformsFromProgram ( )

Called from the constructor.

◆ addUniformsFromCode()

void G3D::Shader::ShaderProgram::addUniformsFromCode ( const String code,
const Args args 
)

Finds any uniform variables in the code string, and adds them to the uniform table.

Parameters
argsused to evaluate pragmas in array bounds
See also
addUniformsFromSource

◆ addUniformsFromSource()

void G3D::Shader::ShaderProgram::addUniformsFromSource ( const Array< PreprocessedShaderSource > &  preprocessedSource,
const Args args 
)

Finds any uniform variables in the code for all shader stages that are not already in the uniform list that OpenGL returned and adds them to the uniform declaration table.

This causes ShaderProgram to surpress warnings about setting variables that have been compiled away–those warnings are annoying when temporarily commenting out code.

Parameters
argsused to evaluate pragmas in array bounds

◆ addVertexAttributesFromSource()

void G3D::Shader::ShaderProgram::addVertexAttributesFromSource ( const Array< PreprocessedShaderSource > &  preprocessedSource,
const Args args 
)

Finds any vertex attribute variables in the code for the vertex shader that are not already in the attribute list that OpenGL returned and adds them to the attribute declaration table.

This causes ShaderProgram to surpress warnings about setting variables that have been compiled away–those warnings are annoying when temporarily commenting out code.

◆ compile()

void G3D::Shader::ShaderProgram::compile ( const Array< PreprocessedShaderSource > &  preprocessedSource,
const String preambleAndMacroArgs,
const Args args,
const Table< int, String > &  indexToNameTable,
Array< String > &  code 
)

Compile using the current macro args, preamble, and source code.

Parameters
codeCode after the G3D preprocessor, preamble and macroArgs, for use in reporting link errors.

◆ containsNonDummyUniform()

bool G3D::Shader::ShaderProgram::containsNonDummyUniform ( const String name)

True if and only if the uniform declaration table contains a non-dummy entry name.

◆ create()

static shared_ptr<ShaderProgram> G3D::Shader::ShaderProgram::create ( const Array< PreprocessedShaderSource > &  preprocessedSource,
const String preambleAndMacroArgs,
const Args args,
const Table< int, String > &  indexToNameTable 
)
static

Compile and link the shader, returning a reference to it.

Parameters
indexToNameTableis for converting file indices to filenames, for useful error/warning messages

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ glShaderProgramObject()

GLuint G3D::Shader::ShaderProgram::glShaderProgramObject ( )
inline

The underlying OpenGL Program Object.

◆ init()

void G3D::Shader::ShaderProgram::init ( const Array< PreprocessedShaderSource > &  preprocessedSource,
const String preambleAndMacroArgs,
const Args args,
const Table< int, String > &  indexToNameTable 
)

Compile and link the shader, and set up the formal parameter lists.

◆ isOk()

bool G3D::Shader::ShaderProgram::isOk ( )
inline

False if and only if there was an error in compilation or linking.

◆ link()

void G3D::Shader::ShaderProgram::link ( )

Link the program object.

◆ printUniformDeclarations()

void G3D::Shader::ShaderProgram::printUniformDeclarations ( ) const

Used for error reporting.

Friends And Related Function Documentation

◆ Shader

friend class Shader
friend

Member Data Documentation

◆ attributeDeclarationTable

AttributeDeclarationTable G3D::Shader::ShaderProgram::attributeDeclarationTable

◆ glProgramObject

GLuint G3D::Shader::ShaderProgram::glProgramObject

The underlying OpenGL Program Object.

Referenced by glShaderProgramObject().

◆ glShaderObject

GLuint G3D::Shader::ShaderProgram::glShaderObject[STAGE_COUNT]

The underlying OpenGL Shader Objects for all possible shader stages.

◆ messages

String G3D::Shader::ShaderProgram::messages

Warning and error messages generated during compilation and/or linking.

◆ ok

bool G3D::Shader::ShaderProgram::ok

False if compilation and/or linking failed.

Referenced by isOk().

◆ uniformDeclarationTable

UniformDeclarationTable G3D::Shader::ShaderProgram::uniformDeclarationTable

documentation generated on Wed Nov 24 2021 08:02:00 using doxygen 1.8.15