globjects  1.1.0.2f0c753c8647
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::Referenced globjects::HeapOnly

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 (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)
 
ProgramBinarygetBinary () 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 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
 
UniformBlockgetUniformBlockByIdentity (const LocationIdentity &identity)
 
const UniformBlockgetUniformBlockByIdentity (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< ProgramBinarym_binary
 
std::unordered_map< LocationIdentity, ref_ptr< AbstractUniform > > m_uniforms
 
std::unordered_map< LocationIdentity, UniformBlockm_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();

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();
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 ( ProgramBinary binary)
virtual globjects::Program::~Program ( )
protectedvirtual

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)
std::set<Shader*> globjects::Program::shaders ( ) const
void globjects::Program::link ( ) const
void globjects::Program::invalidate ( ) const
void globjects::Program::setBinary ( ProgramBinary binary)
ProgramBinary* globjects::Program::getBinary ( ) const
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::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.

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
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<ref_ptr<Shader> > globjects::Program::m_shaders
protected
ref_ptr<ProgramBinary> globjects::Program::m_binary
protected
std::unordered_map<LocationIdentity, ref_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: