/usr/include/globjects/Program.h is in libglobjects-dev 1.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | #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;
/** \brief 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
\code{.cpp}
Program * program = new Program();
program->attach(
Shader::fromString(gl::GL_VERTEX_SHADER, "...")
, Shader::fromString(gl::GL_FRAGMENT_SHADER, "...")
, ...);
program->use();
// draw calls
program->release();
\endcode
Example code for using a program as compute program
\code{.cpp}
Program * program = new Program();
program->attach(Shader::fromString(gl::GL_COMPUTE_SHADER, "..."));
program->dispatchCompute(128, 1, 1);
program->release();
\endcode
\see http://www.opengl.org/wiki/Program_Object
\see Shader
*/
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;
/** Convenience methods for getInterface()
*/
gl::GLint getInterface(gl::GLenum programInterface, gl::GLenum pname) const;
/** Convenience methods for getResource()
*/
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);
/** Retrieves the existing or creates a new typed uniform, named <name>.
*/
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;
/** 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 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>
|