Program.h
Go to the documentation of this file.
#pragma once
#include <set>
#include <unordered_map>
#include <vector>
#include <glm/fwd.hpp>
#include <globjects/base/ChangeListener.h>
#include <globjects/base/Changeable.h>
#include <globjects/base/ref_ptr.h>
#include <globjects/globjects_api.h>
#include <globjects/Object.h>
#include <globjects/LocationIdentity.h>
#include <globjects/UniformBlock.h>
namespace globjects
{
class AbstractUniform;
class ProgramBinary;
class Shader;
template <typename T>
class Uniform;
class GLOBJECTS_API Program : public Object, protected ChangeListener, public Changeable
{
friend class UniformBlock;
friend class ProgramBinaryImplementation_GetProgramBinaryARB;
friend class ProgramBinaryImplementation_None;
public:
enum class BinaryImplementation
{
GetProgramBinaryARB
, None
};
static void hintBinaryImplementation(BinaryImplementation impl);
public:
Program();
Program(ProgramBinary * binary);
virtual void accept(ObjectVisitor & visitor) override;
void use() const;
static void release();
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;
protected:
virtual ~Program();
bool checkLinkStatus() const;
void checkDirty() const;
bool compileAttachedShaders() const;
void updateUniforms() const;
void updateUniformBlockBindings() const;
// ChangeListener Interface
virtual void notifyChanged(const Changeable * sender) override;
protected:
static gl::GLuint createProgram();
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:
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;
mutable bool m_linked;
mutable bool m_dirty;
};
} // namespace globjects
#include <globjects/Program.inl>
globjects::Uniform
Wraps access to typed global GLSL variables.
Definition: AbstractUniform.h:25
ChangeListener.h
globjects::ref_ptr
The ref_ptr class provides the interface for a reference pointer.
Definition: LogMessageBuilder.h:20
globjects
Contains all the classes that wrap OpenGL functionality.
globjects::Object
Superclass of all wrapped OpenGL objects.
Definition: Object.h:26
globjects::UniformBlock
Definition: UniformBlock.h:16
globjects::Program
Wraps an OpenGL program.
Definition: Program.h:78
ref_ptr.h
globjects::Program::m_linked
bool m_linked
Definition: Program.h:237
globjects::Program::BinaryImplementation
BinaryImplementation
Definition: Program.h:85
Changeable.h
globjects::Program::m_shaders
std::set< ref_ptr< Shader > > m_shaders
Definition: Program.h:231
globjects::Changeable
Superclass of all objects that want others to signal that they have changed.
Definition: Changeable.h:22
globjects::ObjectVisitor
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition: ObjectVisitor.h:29
Object.h
globjects::AbstractUniform
Abstract base class for templated Uniforms.
Definition: AbstractUniform.h:34
globjects::Program::m_uniformBlocks
std::unordered_map< LocationIdentity, UniformBlock > m_uniformBlocks
Definition: Program.h:235
globjects::ProgramBinary
The ProgramBinary class is used for directly setting binary sources for a Program.
Definition: ProgramBinary.h:27
globjects::Program::m_dirty
bool m_dirty
Definition: Program.h:238
globjects::ChangeListener
Allows listening to any Changeable.
Definition: ChangeListener.h:22
globjects::Program::m_uniforms
std::unordered_map< LocationIdentity, ref_ptr< AbstractUniform > > m_uniforms
Definition: Program.h:234
globjects::Shader
Encapsulates OpenGL shaders.
Definition: Shader.h:40
globjects::LocationIdentity
Definition: LocationIdentity.h:16
UniformBlock.h
globjects::Program::m_binary
ref_ptr< ProgramBinary > m_binary
Definition: Program.h:232
LocationIdentity.h