class mrpt::opengl::Shader

A resource handling helper for OpenGL “Shader” compiled code fragment.

The OpenGL shader resource will be freed upon destruction or when clear() is called. Normally, users want shader(s) to be linked into a mrpt::opengl::Program.

See also:

CRenderizable

#include <mrpt/opengl/Shader.h>

class Shader
{
public:
    // construction

    Shader();
    Shader(const Shader&);
    Shader(Shader&& o);

    //
methods

    Shader& operator = (const Shader&);
    Shader& operator = (Shader&& o);
    bool empty() const;
    void clear();

    bool compile(
        unsigned int type,
        const std::string& shaderCode,
        mrpt::optional_ref<std::string> outErrorMessages = std::nullopt
        );

    unsigned int handle() const;
};

Methods

void clear()

Frees the shader program in OpenGL.

bool compile(
    unsigned int type,
    const std::string& shaderCode,
    mrpt::optional_ref<std::string> outErrorMessages = std::nullopt
    )

Build a shader from source code.

Parameters:

type

Any valid argument to glCreateShader()

shaderCode

The shading source code. Tip: users can read it from a file with mrpt::io::file_get_contents().

outErrorMessages

If provided, build errors will be saved here. If not, they will dumped to std::cerr

Returns:

false on error.