Class Program

Nested Relationships

Nested Types

Class Documentation

class Program

A resource handling helper for OpenGL Shader “programs”.

The OpenGL “program” resource will be freed upon destruction or when clear() is called.

See also

CRenderizable

Public Types

using Ptr = std::shared_ptr<Program>

Public Functions

Program() = default
~Program()
inline bool empty() const
void clear()

Frees the shader program in OpenGL.

void use()

Activates the program, calling glUseProgram() with this program ID.

void setInt(const char *uniformName, int value) const

Set uniform variables:

void setFloat(const char *uniformName, float value, bool failIfNotExists = true) const
void setFloat3(const char *uniformName, float v1, float v2, float v3) const
void setFloat4(const char *uniformName, float v1, float v2, float v3, float v4) const
bool linkProgram(std::vector<Shader> &shaders, mrpt::optional_ref<std::string> outErrorMessages = std::nullopt)

Links an OpenGL program with all shader code fragments previously inserted into shaders.

Parameters:
  • shaders[inout] The shader code fragments. Will be moved into this Program object, who will become the owner from now on and will eventually free its resources.

  • outErrorMessages[out] If provided, build errors will be saved here. If not, they will dumped to std::cerr

Returns:

false on error.

void declareUniform(const std::string &name)
void declareAttribute(const std::string &name)
inline unsigned int programId() const
inline int uniformId(const char *name) const
inline int attributeId(const char *name) const
inline bool hasUniform(const char *name) const
inline bool hasAttribute(const char *name) const
void dumpProgramDescription(std::ostream &o) const

Prints a textual summary of the program

struct Data

Public Functions

void destroy()

Public Members

std::vector<Shader> shaders
unsigned int program = 0
std::thread::id linkedThread = {}
bool inPostponedDestructionQueue = false
std::unordered_map<std::string, int> uniforms

OpenGL Uniforms/attribs defined by the user as inputs/outputs in shader code.

See also

declareUniform(), declareAttribute();

std::unordered_map<std::string, int> attribs