MRPT  2.0.3
List of all members | Public Types | Public Member Functions | Private Attributes
mrpt::opengl::Program Class Reference

Detailed Description

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

Definition at line 77 of file Shader.h.

#include <mrpt/opengl/Shader.h>

Public Types

using Ptr = std::shared_ptr< Program >
 

Public Member Functions

 Program ()=default
 
 ~Program ()
 
bool empty () const
 
void clear ()
 Frees the shader program in OpenGL. More...
 
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. More...
 
void declareUniform (const std::string &name)
 
void declareAttribute (const std::string &name)
 
unsigned int programId () const
 
int uniformId (const char *name) const
 
int attributeId (const char *name) const
 
bool hasUniform (const char *name) const
 
bool hasAttribute (const char *name) const
 
void dumpProgramDescription (std::ostream &o) const
 Prints a textual summary of the program. More...
 

Private Attributes

std::vector< Shaderm_shaders
 
unsigned int m_program = 0
 
std::unordered_map< std::string, int > m_uniforms
 OpenGL Uniforms/attribs defined by the user as inputs/outputs in shader code. More...
 
std::unordered_map< std::string, int > m_attribs
 

Member Typedef Documentation

◆ Ptr

using mrpt::opengl::Program::Ptr = std::shared_ptr<Program>

Definition at line 83 of file Shader.h.

Constructor & Destructor Documentation

◆ Program()

mrpt::opengl::Program::Program ( )
default

◆ ~Program()

Program::~Program ( )

Definition at line 85 of file Shader.cpp.

References mrpt::containers::clear().

Member Function Documentation

◆ attributeId()

int mrpt::opengl::Program::attributeId ( const char *  name) const
inline

◆ clear()

void Program::clear ( )

Frees the shader program in OpenGL.

Definition at line 87 of file Shader.cpp.

◆ declareAttribute()

void Program::declareAttribute ( const std::string &  name)

Definition at line 172 of file Shader.cpp.

References ASSERT_, mrpt::containers::empty(), THROW_EXCEPTION, and THROW_EXCEPTION_FMT.

◆ declareUniform()

void Program::declareUniform ( const std::string &  name)

Definition at line 152 of file Shader.cpp.

References ASSERT_, mrpt::containers::empty(), THROW_EXCEPTION, and THROW_EXCEPTION_FMT.

◆ dumpProgramDescription()

void Program::dumpProgramDescription ( std::ostream &  o) const

Prints a textual summary of the program.

Definition at line 194 of file Shader.cpp.

References ASSERT_, mrpt::containers::empty(), mrpt::format(), and mrpt::math::size().

◆ empty()

bool mrpt::opengl::Program::empty ( ) const
inline

Definition at line 85 of file Shader.h.

References m_program.

◆ hasAttribute()

bool mrpt::opengl::Program::hasAttribute ( const char *  name) const
inline

Definition at line 120 of file Shader.h.

References m_attribs.

◆ hasUniform()

bool mrpt::opengl::Program::hasUniform ( const char *  name) const
inline

◆ linkProgram()

bool Program::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
[in,out]shadersThe shader code fragments. Will be moved into this Program object, who will become the owner from now on and will eventually free its resources.
[out]outErrorMessagesIf provided, build errors will be saved here. If not, they will dumped to std::cerr
Returns
false on error.

Definition at line 109 of file Shader.cpp.

References ASSERT_, mrpt::containers::clear(), and THROW_EXCEPTION.

◆ programId()

unsigned int mrpt::opengl::Program::programId ( ) const
inline

Definition at line 107 of file Shader.h.

References ASSERT_, and m_program.

Referenced by mrpt::opengl::processRenderQueue().

◆ uniformId()

int mrpt::opengl::Program::uniformId ( const char *  name) const
inline

Member Data Documentation

◆ m_attribs

std::unordered_map<std::string, int> mrpt::opengl::Program::m_attribs
private

Definition at line 136 of file Shader.h.

Referenced by attributeId(), and hasAttribute().

◆ m_program

unsigned int mrpt::opengl::Program::m_program = 0
private

Definition at line 130 of file Shader.h.

Referenced by empty(), and programId().

◆ m_shaders

std::vector<Shader> mrpt::opengl::Program::m_shaders
private

Definition at line 129 of file Shader.h.

◆ m_uniforms

std::unordered_map<std::string, int> mrpt::opengl::Program::m_uniforms
private

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

See also
declareUniform(), declareAttribute();

Definition at line 136 of file Shader.h.

Referenced by hasUniform(), and uniformId().




Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 23:51:15 UTC 2020