Loading...
Searching...
No Matches
globjects::Program Class Reference

Wraps an OpenGL program. More...

`#include <globjects/include/globjects/Program.h>`

Inheritance diagram for globjects::Program:

## Public Types

enum class | BinaryImplementation { GetProgramBinaryARB , None }
Public Types inherited from globjects::Object
enum class | NameImplementation { DebugKHR , Legacy }

## Public Member Functions

| Program ()
| Program (ProgramBinary *binary)
virtual void | accept (ObjectVisitor &visitor) override
void | use () const
bool | isUsed () const
bool | isLinked () const
void | attach (Shader *shader)
template<class ... Shaders>
void | attach (Shader *shader, Shaders... shaders)
void | detach (Shader *shader)
std::set< Shader * > | shaders () const
void | link () const
void | invalidate () const
void | setBinary (ProgramBinary *binary)
ProgramBinary * | getBinary () const
std::string | infoLog () const
gl::GLint | get (gl::GLenum pname) const
bool | isValid () const
void | validate ()
void | setParameter (gl::GLenum pname, gl::GLint value) const
void | setParameter (gl::GLenum pname, gl::GLboolean value) const
void | getActiveAttrib (gl::GLuint index, gl::GLsizei bufSize, gl::GLsizei *length, gl::GLint *size, gl::GLenum *type, gl::GLchar *name) const
gl::GLint | getAttributeLocation (const std::string &name) const
gl::GLint | getUniformLocation (const std::string &name) const
std::vector< gl::GLint > | getAttributeLocations (const std::vector< std::string > &names) const
std::vector< gl::GLint > | getUniformLocations (const std::vector< std::string > &names) const
void | bindAttributeLocation (gl::GLuint index, const std::string &name) const
void | bindFragDataLocation (gl::GLuint index, const std::string &name) const
gl::GLint | getFragDataLocation (const std::string &name) const
gl::GLint | getFragDataIndex (const std::string &name) const
void | getInterface (gl::GLenum programInterface, gl::GLenum pname, gl::GLint *params) const
gl::GLuint | getResourceIndex (gl::GLenum programInterface, const std::string &name) const
void | getResourceName (gl::GLenum programInterface, gl::GLuint index, gl::GLsizei bufSize, gl::GLsizei *length, char *name) const
void | getResource (gl::GLenum programInterface, gl::GLuint index, gl::GLsizei propCount, const gl::GLenum *props, gl::GLsizei bufSize, gl::GLsizei *length, gl::GLint *params) const
gl::GLint | getResourceLocation (gl::GLenum programInterface, const std::string &name) const
gl::GLint | getResourceLocationIndex (gl::GLenum programInterface, const std::string &name) const
gl::GLint | getInterface (gl::GLenum programInterface, gl::GLenum pname) const
gl::GLint | getResource (gl::GLenum programInterface, gl::GLuint index, gl::GLenum prop, gl::GLsizei *length=nullptr) const
std::vector< gl::GLint > | getResource (gl::GLenum programInterface, gl::GLuint index, const std::vector< gl::GLenum > &props, gl::GLsizei *length=nullptr) const
void | getResource (gl::GLenum programInterface, gl::GLuint index, const std::vector< gl::GLenum > &props, gl::GLsizei bufSize, gl::GLsizei *length, gl::GLint *params) const
gl::GLuint | getUniformBlockIndex (const std::string &name) const
UniformBlock * | uniformBlock (gl::GLuint uniformBlockIndex)
const UniformBlock * | uniformBlock (gl::GLuint uniformBlockIndex) const
UniformBlock * | uniformBlock (const std::string &name)
const UniformBlock * | uniformBlock (const std::string &name) const
void | getActiveUniforms (gl::GLsizei uniformCount, const gl::GLuint *uniformIndices, gl::GLenum pname, gl::GLint *params) const
std::vector< gl::GLint > | getActiveUniforms (const std::vector< gl::GLuint > &uniformIndices, gl::GLenum pname) const
std::vector< gl::GLint > | getActiveUniforms (const std::vector< gl::GLint > &uniformIndices, gl::GLenum pname) const
gl::GLint | getActiveUniform (gl::GLuint uniformIndex, gl::GLenum pname) const
std::string | getActiveUniformName (gl::GLuint uniformIndex) const
template<typename T >
void | setUniform (const std::string &name, const T &value)
template<typename T >
void | setUniform (gl::GLint location, const T &value)
template<typename T >
Uniform< T > * | getUniform (const std::string &name)
template<typename T >
const Uniform< T > * | getUniform (const std::string &name) const
template<typename T >
Uniform< T > * | getUniform (gl::GLint location)
template<typename T >
const Uniform< T > * | getUniform (gl::GLint location) const
void | addUniform (AbstractUniform *uniform)
void | setShaderStorageBlockBinding (gl::GLuint storageBlockIndex, gl::GLuint storageBlockBinding) const
void | dispatchCompute (gl::GLuint numGroupsX, gl::GLuint numGroupsY, gl::GLuint numGroupsZ)
void | dispatchCompute (const glm::uvec3 &numGroups)
void | dispatchComputeGroupSize (gl::GLuint numGroupsX, gl::GLuint numGroupsY, gl::GLuint numGroupsZ, gl::GLuint groupSizeX, gl::GLuint groupSizeY, gl::GLuint groupSizeZ)
void | dispatchComputeGroupSize (const glm::uvec3 &numGroups, const glm::uvec3 &groupSizes)
virtual gl::GLenum | objectType () const override
Public Member Functions inherited from globjects::Object
gl::GLuint | id () const
std::string | name () const
void | setName (const std::string &name)
bool | hasName () const
bool | isDefault () const
void | detach ()
Public Member Functions inherited from globjects::Referenced
| Referenced ()
void | ref () const
void | unref () const
int | refCounter () const
Public Member Functions inherited from globjects::HeapOnly
| HeapOnly ()
void | destroy () const
Public Member Functions inherited from globjects::Changeable
void | changed () const
void | registerListener (ChangeListener *listener)
void | deregisterListener (ChangeListener *listener)

## Static Public Member Functions

static void | hintBinaryImplementation (BinaryImplementation impl)
static void | release ()
Static Public Member Functions inherited from globjects::Object
static void | hintNameImplementation (NameImplementation impl)

## Protected Member Functions

virtual | ~Program ()
bool | checkLinkStatus () const
void | checkDirty () const
bool | compileAttachedShaders () const
void | updateUniforms () const
void | updateUniformBlockBindings () const
virtual void | notifyChanged (const Changeable *sender) override
template<typename T >
void | setUniformByIdentity (const LocationIdentity &identity, const T &value)
template<typename T >
Uniform< T > * | getUniformByIdentity (const LocationIdentity &identity)
template<typename T >
const Uniform< T > * | getUniformByIdentity (const LocationIdentity &identity) const
UniformBlock * | getUniformBlockByIdentity (const LocationIdentity &identity)
const UniformBlock * | getUniformBlockByIdentity (const LocationIdentity &identity) const
Protected Member Functions inherited from globjects::Object
| Object (IDResource *resource)
virtual | ~Object ()
Protected Member Functions inherited from globjects::Referenced
virtual | ~Referenced ()
Protected Member Functions inherited from globjects::HeapOnly
virtual | ~HeapOnly ()
Protected Member Functions inherited from globjects::ChangeListener
virtual | ~ChangeListener ()
Protected Member Functions inherited from globjects::Changeable
void | changed () const
void | registerListener (ChangeListener *listener)
void | deregisterListener (ChangeListener *listener)

## Static Protected Member Functions

static gl::GLuint | createProgram ()

## Protected Attributes

std::set< ref_ptr< Shader > > | m_shaders
ref_ptr< ProgramBinary > | m_binary
std::unordered_map< LocationIdentity, ref_ptr< AbstractUniform > > | m_uniforms
std::unordered_map< LocationIdentity, UniformBlock > | m_uniformBlocks
bool | m_linked
bool | m_dirty
Protected Attributes inherited from globjects::Object
IDResource * | m_resource
void * | m_objectLabelState

## Friends

class | UniformBlock
class | ProgramBinaryImplementation_GetProgramBinaryARB
class | ProgramBinaryImplementation_None

## Detailed Description

Wraps an OpenGL program.

Therefor it suclasses Object. Programs get attached a set of shaders with attach(). It inherits ChangeListener to react to changes to attached shaders. To use a program for rendering, call use(). During use() the program ensure that all attached shaders are compiled and linked. After that, the program is registered in OpenGL to be used during the upcoming rendering pileline calls.

Shaders can be detached using detach() and queried with shaders().

To use a program as a compute program, dispatchCompute() can be used to start the kernel.

Example code for setting up a program and use it for rendering

Program * program = new Program();
program->attach(
Shader::fromString(gl::GL_VERTEX_SHADER, "...")
, Shader::fromString(gl::GL_FRAGMENT_SHADER, "...")
, ...);
program->use();
// draw calls
program->release();
globjects::Program
Wraps an OpenGL program.
Definition Program.h:79
globjects::Program::release
static void release()
globjects::Program::use
void use() const
globjects::Program::Program
Program()
globjects::Program::attach
void attach(Shader *shader)
globjects::Shader::fromString
static Shader * fromString(const gl::GLenum type, const std::string &sourceString, const IncludePaths &includePaths=IncludePaths())

Example code for using a program as compute program

Program * program = new Program();
program->attach(Shader::fromString(gl::GL_COMPUTE_SHADER, "..."));
program->dispatchCompute(128, 1, 1);
program->release();
globjects::Program::dispatchCompute
void dispatchCompute(gl::GLuint numGroupsX, gl::GLuint numGroupsY, gl::GLuint numGroupsZ)

See also
  http://www.opengl.org/wiki/Program_Object
  Shader

## Member Enumeration Documentation

## BinaryImplementation

enum class globjects::Program::BinaryImplementation

strong

Enumerator
GetProgramBinaryARB |
None |

## Constructor & Destructor Documentation

## Program() [1/2]

globjects::Program::Program | ( |  | ) |

## Program() [2/2]

globjects::Program::Program | ( | ProgramBinary * | binary | ) |

## ~Program()

virtual globjects::Program::~Program | ( |  | ) |

protected virtual

## Member Function Documentation

## hintBinaryImplementation()

static void globjects::Program::hintBinaryImplementation | ( | BinaryImplementation | impl | ) |

static

## accept()

virtual void globjects::Program::accept | ( | ObjectVisitor & | visitor | ) |

override virtual

Implements globjects::Object.

## use()

void globjects::Program::use | ( |  | ) | const

## release()

static void globjects::Program::release | ( |  | ) |

static

## isUsed()

bool globjects::Program::isUsed | ( |  | ) | const

## isLinked()

bool globjects::Program::isLinked | ( |  | ) | const

## attach() [1/2]

void globjects::Program::attach | ( | Shader * | shader | ) |

## attach() [2/2]

template<class ... Shaders>

void globjects::Program::attach | ( | Shader * | shader,
|  | Shaders... | shaders
| ) |  |

## detach()

void globjects::Program::detach | ( | Shader * | shader | ) |

## shaders()

std::set< Shader * > globjects::Program::shaders | ( |  | ) | const

## link()

void globjects::Program::link | ( |  | ) | const

## invalidate()

void globjects::Program::invalidate | ( |  | ) | const

## setBinary()

void globjects::Program::setBinary | ( | ProgramBinary * | binary | ) |

## getBinary()

ProgramBinary * globjects::Program::getBinary | ( |  | ) | const

## infoLog()

std::string globjects::Program::infoLog | ( |  | ) | const

## get()

gl::GLint globjects::Program::get | ( | gl::GLenum | pname | ) | const

## isValid()

bool globjects::Program::isValid | ( |  | ) | const

## validate()

void globjects::Program::validate | ( |  | ) |

## setParameter() [1/2]

void globjects::Program::setParameter | ( | gl::GLenum | pname,
|  | gl::GLint | value
| ) |  | const

## setParameter() [2/2]

void globjects::Program::setParameter | ( | gl::GLenum | pname,
|  | gl::GLboolean | value
| ) |  | const

## getActiveAttrib()

void globjects::Program::getActiveAttrib | ( | gl::GLuint | index,
|  | gl::GLsizei | bufSize,
|  | gl::GLsizei * | length,
|  | gl::GLint * | size,
|  | gl::GLenum * | type,
|  | gl::GLchar * | name
| ) |  | const

## getAttributeLocation()

gl::GLint globjects::Program::getAttributeLocation | ( | const std::string & | name | ) | const

## getUniformLocation()

gl::GLint globjects::Program::getUniformLocation | ( | const std::string & | name | ) | const

## getAttributeLocations()

std::vector< gl::GLint > globjects::Program::getAttributeLocations | ( | const std::vector< std::string > & | names | ) | const

## getUniformLocations()

std::vector< gl::GLint > globjects::Program::getUniformLocations | ( | const std::vector< std::string > & | names | ) | const

## bindAttributeLocation()

void globjects::Program::bindAttributeLocation | ( | gl::GLuint | index,
|  | const std::string & | name
| ) |  | const

## bindFragDataLocation()

void globjects::Program::bindFragDataLocation | ( | gl::GLuint | index,
|  | const std::string & | name
| ) |  | const

## getFragDataLocation()

gl::GLint globjects::Program::getFragDataLocation | ( | const std::string & | name | ) | const

## getFragDataIndex()

gl::GLint globjects::Program::getFragDataIndex | ( | const std::string & | name | ) | const

## getInterface() [1/2]

void globjects::Program::getInterface | ( | gl::GLenum | programInterface,
|  | gl::GLenum | pname,
|  | gl::GLint * | params
| ) |  | const

## getResourceIndex()

gl::GLuint globjects::Program::getResourceIndex | ( | gl::GLenum | programInterface,
|  | const std::string & | name
| ) |  | const

## getResourceName()

void globjects::Program::getResourceName | ( | gl::GLenum | programInterface,
|  | gl::GLuint | index,
|  | gl::GLsizei | bufSize,
|  | gl::GLsizei * | length,
|  | char * | name
| ) |  | const

## getResource() [1/4]

void globjects::Program::getResource | ( | gl::GLenum | programInterface,
|  | gl::GLuint | index,
|  | gl::GLsizei | propCount,
|  | const gl::GLenum * | props,
|  | gl::GLsizei | bufSize,
|  | gl::GLsizei * | length,
|  | gl::GLint * | params
| ) |  | const

## getResourceLocation()

gl::GLint globjects::Program::getResourceLocation | ( | gl::GLenum | programInterface,
|  | const std::string & | name
| ) |  | const

## getResourceLocationIndex()

gl::GLint globjects::Program::getResourceLocationIndex | ( | gl::GLenum | programInterface,
|  | const std::string & | name
| ) |  | const

## getInterface() [2/2]

gl::GLint globjects::Program::getInterface | ( | gl::GLenum | programInterface,
|  | gl::GLenum | pname
| ) |  | const

Convenience methods for getInterface()

## getResource() [2/4]

gl::GLint globjects::Program::getResource | ( | gl::GLenum | programInterface,
|  | gl::GLuint | index,
|  | gl::GLenum | prop,
|  | gl::GLsizei * | length = `nullptr`
| ) |  | const

Convenience methods for getResource()

## getResource() [3/4]

std::vector< gl::GLint > globjects::Program::getResource | ( | gl::GLenum | programInterface,
|  | gl::GLuint | index,
|  | const std::vector< gl::GLenum > & | props,
|  | gl::GLsizei * | length = `nullptr`
| ) |  | const

## getResource() [4/4]

void globjects::Program::getResource | ( | gl::GLenum | programInterface,
|  | gl::GLuint | index,
|  | const std::vector< gl::GLenum > & | props,
|  | gl::GLsizei | bufSize,
|  | gl::GLsizei * | length,
|  | gl::GLint * | params
| ) |  | const

## getUniformBlockIndex()

gl::GLuint globjects::Program::getUniformBlockIndex | ( | const std::string & | name | ) | const

## uniformBlock() [1/4]

UniformBlock * globjects::Program::uniformBlock | ( | gl::GLuint | uniformBlockIndex | ) |

## uniformBlock() [2/4]

const UniformBlock * globjects::Program::uniformBlock | ( | gl::GLuint | uniformBlockIndex | ) | const

## uniformBlock() [3/4]

UniformBlock * globjects::Program::uniformBlock | ( | const std::string & | name | ) |

## uniformBlock() [4/4]

const UniformBlock * globjects::Program::uniformBlock | ( | const std::string & | name | ) | const

## getActiveUniforms() [1/3]

void globjects::Program::getActiveUniforms | ( | gl::GLsizei | uniformCount,
|  | const gl::GLuint * | uniformIndices,
|  | gl::GLenum | pname,
|  | gl::GLint * | params
| ) |  | const

## getActiveUniforms() [2/3]

std::vector< gl::GLint > globjects::Program::getActiveUniforms | ( | const std::vector< gl::GLuint > & | uniformIndices,
|  | gl::GLenum | pname
| ) |  | const

## getActiveUniforms() [3/3]

std::vector< gl::GLint > globjects::Program::getActiveUniforms | ( | const std::vector< gl::GLint > & | uniformIndices,
|  | gl::GLenum | pname
| ) |  | const

## getActiveUniform()

gl::GLint globjects::Program::getActiveUniform | ( | gl::GLuint | uniformIndex,
|  | gl::GLenum | pname
| ) |  | const

## getActiveUniformName()

std::string globjects::Program::getActiveUniformName | ( | gl::GLuint | uniformIndex | ) | const

## setUniform() [1/2]

template<typename T >

void globjects::Program::setUniform | ( | const std::string & | name,
|  | const T & | value
| ) |  |

## setUniform() [2/2]

template<typename T >

void globjects::Program::setUniform | ( | gl::GLint | location,
|  | const T & | value
| ) |  |

## getUniform() [1/4]

template<typename T >

Uniform< T > * globjects::Program::getUniform | ( | const std::string & | name | ) |

Retrieves the existing or creates a new typed uniform, named <name>.

## getUniform() [2/4]

template<typename T >

const Uniform< T > * globjects::Program::getUniform | ( | const std::string & | name | ) | const

## getUniform() [3/4]

template<typename T >

Uniform< T > * globjects::Program::getUniform | ( | gl::GLint | location | ) |

## getUniform() [4/4]

template<typename T >

const Uniform< T > * globjects::Program::getUniform | ( | gl::GLint | location | ) | const

## addUniform()

void globjects::Program::addUniform | ( | AbstractUniform * | uniform | ) |

Adds the uniform to the internal list of named uniforms. If an equally named uniform already exists, this program derigisters itself and the uniform gets replaced (and by this the old one gets dereferenced). If the current program is linked, the uniforms value will be passed to the program object.

## setShaderStorageBlockBinding()

void globjects::Program::setShaderStorageBlockBinding | ( | gl::GLuint | storageBlockIndex,
|  | gl::GLuint | storageBlockBinding
| ) |  | const

## dispatchCompute() [1/2]

void globjects::Program::dispatchCompute | ( | gl::GLuint | numGroupsX,
|  | gl::GLuint | numGroupsY,
|  | gl::GLuint | numGroupsZ
| ) |  |

## dispatchCompute() [2/2]

void globjects::Program::dispatchCompute | ( | const glm::uvec3 & | numGroups | ) |

## dispatchComputeGroupSize() [1/2]

void globjects::Program::dispatchComputeGroupSize | ( | gl::GLuint | numGroupsX,
|  | gl::GLuint | numGroupsY,
|  | gl::GLuint | numGroupsZ,
|  | gl::GLuint | groupSizeX,
|  | gl::GLuint | groupSizeY,
|  | gl::GLuint | groupSizeZ
| ) |  |

## dispatchComputeGroupSize() [2/2]

void globjects::Program::dispatchComputeGroupSize | ( | const glm::uvec3 & | numGroups,
|  | const glm::uvec3 & | groupSizes
| ) |  |

## objectType()

virtual gl::GLenum globjects::Program::objectType | ( |  | ) | const

override virtual

Implements globjects::Object.

## checkLinkStatus()

bool globjects::Program::checkLinkStatus | ( |  | ) | const

protected

## checkDirty()

void globjects::Program::checkDirty | ( |  | ) | const

protected

## compileAttachedShaders()

bool globjects::Program::compileAttachedShaders | ( |  | ) | const

protected

## updateUniforms()

void globjects::Program::updateUniforms | ( |  | ) | const

protected

## updateUniformBlockBindings()

void globjects::Program::updateUniformBlockBindings | ( |  | ) | const

protected

## notifyChanged()

virtual void globjects::Program::notifyChanged | ( | const Changeable * | sender | ) |

override protected virtual

Reimplemented from globjects::ChangeListener.

## createProgram()

static gl::GLuint globjects::Program::createProgram | ( |  | ) |

static protected

## setUniformByIdentity()

template<typename T >

void globjects::Program::setUniformByIdentity | ( | const LocationIdentity & | identity,
|  | const T & | value
| ) |  |

protected

## getUniformByIdentity() [1/2]

template<typename T >

Uniform< T > * globjects::Program::getUniformByIdentity | ( | const LocationIdentity & | identity | ) |

protected

## getUniformByIdentity() [2/2]

template<typename T >

const Uniform< T > * globjects::Program::getUniformByIdentity | ( | const LocationIdentity & | identity | ) | const

protected

## getUniformBlockByIdentity() [1/2]

UniformBlock * globjects::Program::getUniformBlockByIdentity | ( | const LocationIdentity & | identity | ) |

protected

## getUniformBlockByIdentity() [2/2]

const UniformBlock * globjects::Program::getUniformBlockByIdentity | ( | const LocationIdentity & | identity | ) | const

protected

## Friends And Related Symbol Documentation

## UniformBlock

friend class UniformBlock

friend

## ProgramBinaryImplementation_GetProgramBinaryARB

friend class ProgramBinaryImplementation_GetProgramBinaryARB

friend

## ProgramBinaryImplementation_None

friend class ProgramBinaryImplementation_None

friend

## Member Data Documentation

## m_shaders

std::set<ref_ptr<Shader> > globjects::Program::m_shaders

protected

## m_binary

ref_ptr<ProgramBinary> globjects::Program::m_binary

protected

## m_uniforms

std::unordered_map<LocationIdentity, ref_ptr<AbstractUniform> > globjects::Program::m_uniforms

protected

## m_uniformBlocks

std::unordered_map<LocationIdentity, UniformBlock> globjects::Program::m_uniformBlocks

protected

## m_linked

bool globjects::Program::m_linked

mutable protected

## m_dirty

bool globjects::Program::m_dirty

mutable protected

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

- Program.h