globjects  2.0.0.690708773bba
Strict OpenGL objects wrapper.

Wraps an OpenGL program. More...

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

Inheritance diagram for globjects::Program:
globjects::Object globjects::ChangeListener globjects::Changeable globjects::Instantiator< Program >

Public Types

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

Public Member Functions

 Program ()
 
 Program (std::unique_ptr< ProgramBinary > &&binary)
 
virtual ~Program ()
 
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)
 
const std::set< Shader * > & shaders () const
 
void link () const
 
void invalidate () const
 
void setBinary (std::unique_ptr< ProgramBinary > &&binary)
 
ProgramBinarybinary () 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
 
UniformBlockuniformBlock (gl::GLuint uniformBlockIndex)
 
const UniformBlockuniformBlock (gl::GLuint uniformBlockIndex) const
 
UniformBlockuniformBlock (const std::string &name)
 
const UniformBlockuniformBlock (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 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::Changeable
 Changeable ()
 
virtual ~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 std::unique_ptr< ProgramBinaryobtainBinary (Program *program)
 
- Static Public Member Functions inherited from globjects::Object
static void hintNameImplementation (NameImplementation impl)
 
- Static Public Member Functions inherited from globjects::Instantiator< Program >
static std::unique_ptr< Programcreate (Args &&...args)
 
static std::unique_ptr< ProgramfromId (gl::GLuint id, Args &&...args)
 

Protected Member Functions

bool checkLinkStatus () const
 
void checkDirty () const
 
bool compileAttachedShaders () const
 
void updateUniforms () const
 
void updateUniformBlockBindings () const
 
void addUniform (std::unique_ptr< AbstractUniform > &&uniform)
 
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
 
UniformBlockgetUniformBlockByIdentity (const LocationIdentity &identity)
 
const UniformBlockgetUniformBlockByIdentity (const LocationIdentity &identity) const
 
- Protected Member Functions inherited from globjects::Object
 Object (std::unique_ptr< IDResource > &&resource)
 
virtual ~Object ()
 
- Protected Member Functions inherited from globjects::ChangeListener
void addSubject (Changeable *subject)
 
virtual void removeSubject (Changeable *subject)
 
virtual ~ChangeListener ()
 
- Protected Member Functions inherited from globjects::Changeable
 Changeable ()
 
virtual ~Changeable ()
 
void changed () const
 
void registerListener (ChangeListener *listener)
 
void deregisterListener (ChangeListener *listener)
 

Static Protected Member Functions

static gl::GLuint createProgram ()
 
- Static Protected Member Functions inherited from globjects::Instantiator< Program >
static std::unique_ptr< Programcreate (Args &&...args)
 
static std::unique_ptr< ProgramfromId (gl::GLuint id, Args &&...args)
 

Protected Attributes

std::set< Shader * > m_shaders
 
std::unique_ptr< ProgramBinarym_binary
 
std::unordered_map< LocationIdentity, std::unique_ptr< AbstractUniform > > m_uniforms
 
std::unordered_map< LocationIdentity, UniformBlockm_uniformBlocks
 
bool m_linked
 
bool m_dirty
 
- Protected Attributes inherited from globjects::Object
std::unique_ptr< IDResourcem_resource
 
void * m_objectLabelState
 
- Protected Attributes inherited from globjects::ChangeListener
std::set< Changeable * > m_subjects
 
- Protected Attributes inherited from globjects::Changeable
std::set< ChangeListener * > m_listeners
 

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

[TODO]: Adjust examples

Program * program = new Program();
program->attach(
Shader::fromString(gl::GL_VERTEX_SHADER, "...")
, Shader::fromString(gl::GL_FRAGMENT_SHADER, "...")
, ...);
program->use();
// draw calls
program->release();

Example code for using a program as compute program [TODO]: Adjust examples

Program * program = new Program();
program->attach(Shader::fromString(gl::GL_COMPUTE_SHADER, "..."));
program->dispatchCompute(128, 1, 1);
program->release();
See also
http://www.opengl.org/wiki/Program_Object
Shader

Member Enumeration Documentation

Enumerator
GetProgramBinaryARB 
None 

Constructor & Destructor Documentation

globjects::Program::Program ( )
globjects::Program::Program ( std::unique_ptr< ProgramBinary > &&  binary)
virtual globjects::Program::~Program ( )
virtual

Member Function Documentation

static void globjects::Program::hintBinaryImplementation ( BinaryImplementation  impl)
static
virtual void globjects::Program::accept ( ObjectVisitor visitor)
overridevirtual

Implements globjects::Object.

void globjects::Program::use ( ) const
static void globjects::Program::release ( )
static
bool globjects::Program::isUsed ( ) const
bool globjects::Program::isLinked ( ) const
void globjects::Program::attach ( Shader shader)
template<class... Shaders>
void globjects::Program::attach ( Shader shader,
Shaders...  shaders 
)
void globjects::Program::detach ( Shader shader)
const std::set<Shader*>& globjects::Program::shaders ( ) const
void globjects::Program::link ( ) const
void globjects::Program::invalidate ( ) const
void globjects::Program::setBinary ( std::unique_ptr< ProgramBinary > &&  binary)
ProgramBinary* globjects::Program::binary ( ) const
static std::unique_ptr<ProgramBinary> globjects::Program::obtainBinary ( Program program)
static
std::string globjects::Program::infoLog ( ) const
gl::GLint globjects::Program::get ( gl::GLenum  pname) const
bool globjects::Program::isValid ( ) const
void globjects::Program::validate ( )
void globjects::Program::setParameter ( gl::GLenum  pname,
gl::GLint  value 
) const
void globjects::Program::setParameter ( gl::GLenum  pname,
gl::GLboolean  value 
) const
void globjects::Program::getActiveAttrib ( gl::GLuint  index,
gl::GLsizei  bufSize,
gl::GLsizei *  length,
gl::GLint *  size,
gl::GLenum *  type,
gl::GLchar *  name 
) const
gl::GLint globjects::Program::getAttributeLocation ( const std::string &  name) const
gl::GLint globjects::Program::getUniformLocation ( const std::string &  name) const
std::vector<gl::GLint> globjects::Program::getAttributeLocations ( const std::vector< std::string > &  names) const
std::vector<gl::GLint> globjects::Program::getUniformLocations ( const std::vector< std::string > &  names) const
void globjects::Program::bindAttributeLocation ( gl::GLuint  index,
const std::string &  name 
) const
void globjects::Program::bindFragDataLocation ( gl::GLuint  index,
const std::string &  name 
) const
gl::GLint globjects::Program::getFragDataLocation ( const std::string &  name) const
gl::GLint globjects::Program::getFragDataIndex ( const std::string &  name) const
void globjects::Program::getInterface ( gl::GLenum  programInterface,
gl::GLenum  pname,
gl::GLint *  params 
) const
gl::GLuint globjects::Program::getResourceIndex ( gl::GLenum  programInterface,
const std::string &  name 
) const
void globjects::Program::getResourceName ( gl::GLenum  programInterface,
gl::GLuint  index,
gl::GLsizei  bufSize,
gl::GLsizei *  length,
char *  name 
) const
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
gl::GLint globjects::Program::getResourceLocation ( gl::GLenum  programInterface,
const std::string &  name 
) const
gl::GLint globjects::Program::getResourceLocationIndex ( gl::GLenum  programInterface,
const std::string &  name 
) const
gl::GLint globjects::Program::getInterface ( gl::GLenum  programInterface,
gl::GLenum  pname 
) const

Convenience methods for getInterface()

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

Convenience methods for getResource()

std::vector<gl::GLint> globjects::Program::getResource ( gl::GLenum  programInterface,
gl::GLuint  index,
const std::vector< gl::GLenum > &  props,
gl::GLsizei *  length = nullptr 
) const
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
gl::GLuint globjects::Program::getUniformBlockIndex ( const std::string &  name) const
UniformBlock* globjects::Program::uniformBlock ( gl::GLuint  uniformBlockIndex)
const UniformBlock* globjects::Program::uniformBlock ( gl::GLuint  uniformBlockIndex) const
UniformBlock* globjects::Program::uniformBlock ( const std::string &  name)
const UniformBlock* globjects::Program::uniformBlock ( const std::string &  name) const
void globjects::Program::getActiveUniforms ( gl::GLsizei  uniformCount,
const gl::GLuint *  uniformIndices,
gl::GLenum  pname,
gl::GLint *  params 
) const
std::vector<gl::GLint> globjects::Program::getActiveUniforms ( const std::vector< gl::GLuint > &  uniformIndices,
gl::GLenum  pname 
) const
std::vector<gl::GLint> globjects::Program::getActiveUniforms ( const std::vector< gl::GLint > &  uniformIndices,
gl::GLenum  pname 
) const
gl::GLint globjects::Program::getActiveUniform ( gl::GLuint  uniformIndex,
gl::GLenum  pname 
) const
std::string globjects::Program::getActiveUniformName ( gl::GLuint  uniformIndex) const
template<typename T >
void globjects::Program::setUniform ( const std::string &  name,
const T &  value 
)
template<typename T >
void globjects::Program::setUniform ( gl::GLint  location,
const T &  value 
)
template<typename T >
Uniform<T>* globjects::Program::getUniform ( const std::string &  name)

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

template<typename T >
const Uniform<T>* globjects::Program::getUniform ( const std::string &  name) const
template<typename T >
Uniform<T>* globjects::Program::getUniform ( gl::GLint  location)
template<typename T >
const Uniform<T>* globjects::Program::getUniform ( gl::GLint  location) const
void globjects::Program::setShaderStorageBlockBinding ( gl::GLuint  storageBlockIndex,
gl::GLuint  storageBlockBinding 
) const
void globjects::Program::dispatchCompute ( gl::GLuint  numGroupsX,
gl::GLuint  numGroupsY,
gl::GLuint  numGroupsZ 
)
void globjects::Program::dispatchCompute ( const glm::uvec3 &  numGroups)
void globjects::Program::dispatchComputeGroupSize ( gl::GLuint  numGroupsX,
gl::GLuint  numGroupsY,
gl::GLuint  numGroupsZ,
gl::GLuint  groupSizeX,
gl::GLuint  groupSizeY,
gl::GLuint  groupSizeZ 
)
void globjects::Program::dispatchComputeGroupSize ( const glm::uvec3 &  numGroups,
const glm::uvec3 &  groupSizes 
)
virtual gl::GLenum globjects::Program::objectType ( ) const
overridevirtual

Implements globjects::Object.

bool globjects::Program::checkLinkStatus ( ) const
protected
void globjects::Program::checkDirty ( ) const
protected
bool globjects::Program::compileAttachedShaders ( ) const
protected
void globjects::Program::updateUniforms ( ) const
protected
void globjects::Program::updateUniformBlockBindings ( ) const
protected
void globjects::Program::addUniform ( std::unique_ptr< AbstractUniform > &&  uniform)
protected
virtual void globjects::Program::notifyChanged ( const Changeable sender)
overrideprotectedvirtual

Reimplemented from globjects::ChangeListener.

static gl::GLuint globjects::Program::createProgram ( )
staticprotected
template<typename T >
void globjects::Program::setUniformByIdentity ( const LocationIdentity identity,
const T &  value 
)
protected
template<typename T >
Uniform<T>* globjects::Program::getUniformByIdentity ( const LocationIdentity identity)
protected
template<typename T >
const Uniform<T>* globjects::Program::getUniformByIdentity ( const LocationIdentity identity) const
protected
UniformBlock* globjects::Program::getUniformBlockByIdentity ( const LocationIdentity identity)
protected
const UniformBlock* globjects::Program::getUniformBlockByIdentity ( const LocationIdentity identity) const
protected

Friends And Related Function Documentation

friend class UniformBlock
friend
friend class ProgramBinaryImplementation_GetProgramBinaryARB
friend
friend class ProgramBinaryImplementation_None
friend

Member Data Documentation

std::set<Shader *> globjects::Program::m_shaders
protected
std::unique_ptr<ProgramBinary> globjects::Program::m_binary
protected
std::unordered_map<LocationIdentity, std::unique_ptr<AbstractUniform> > globjects::Program::m_uniforms
protected
std::unordered_map<LocationIdentity, UniformBlock> globjects::Program::m_uniformBlocks
protected
bool globjects::Program::m_linked
mutableprotected
bool globjects::Program::m_dirty
mutableprotected

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