iridescence
Loading...
Searching...
No Matches
glk::GLSLShader Class Reference

GLSLShader is a wrapper for OpenGL shader programs. More...

#include <glsl_shader.hpp>

Public Member Functions

 GLSLShader ()
 ~GLSLShader ()
bool attach_source (const std::string &filename, GLuint shader_type)
bool attach_source (const std::vector< std::string > &filenames, GLuint shader_type)
bool attach_source (const std::string &filename, const std::unordered_set< std::string > &include_filenames, const std::string &defines, GLuint shader_type)
bool attach_source (const std::vector< std::string > &filenames, const std::unordered_set< std::string > &include_filenames, const std::string &defines, GLuint shader_type)
bool attach_source (const std::string &filename, const std::unordered_set< std::string > &include_filenames, const std::string &defines, const std::vector< std::pair< std::string, std::string > > &replaces, GLuint shader_type)
bool attach_source (const std::vector< std::string > &filenames, const std::unordered_set< std::string > &include_filenames, const std::string &defines, const std::vector< std::pair< std::string, std::string > > &replaces, GLuint shader_type)
 Attach shader source code from multiple files, with optional include files, defines, and replacements.
bool attach_source_code (const std::string &source_code, GLuint shader_type)
 Attach shader source code from a string.
bool add_feedback_varying (const std::string &name)
bool link_program ()
 Link attached shaders into a shader program.
bool init (const std::string &shader_path)
bool init (const std::string &vertex_shader_path, const std::string &fragment_shader_path)
bool init (const std::vector< std::string > &vertex_shader_paths, const std::vector< std::string > &fragment_shader_paths)
GLuint id () const
 Returns shader ID.
void use () const
 Use the shader in the OpenGL context.
void unuse () const
 Unuse the shader.
GLint attrib (std::uint64_t name, const char *debug_msg=nullptr)
GLint attrib (const std::string &name)
GLint uniform (std::uint64_t name, const char *debug_msg=nullptr)
GLint uniform (const std::string &name)
GLint subroutine (GLenum shader_type, std::uint64_t name, const char *debug_msg=nullptr)
GLint subroutine (GLenum shader_type, const std::string &name)
GLint subroutine_uniform (GLenum shader_type, std::uint64_t name, const char *debug_msg=nullptr)
GLint subroutine_uniform (GLenum shader_type, const std::string &name)
int get_uniformi (std::uint64_t name)
int get_uniformi (const std::string &name)
float get_uniformf (std::uint64_t name)
float get_uniformf (const std::string &name)
Eigen::Vector4f get_uniform4f (std::uint64_t name)
Eigen::Vector4f get_uniform4f (const std::string &name)
Eigen::Matrix4f get_uniform_matrix4f (std::uint64_t name)
Eigen::Matrix4f get_uniform_matrix4f (const std::string &name)
void copy_cached_uniforms (GLSLShader &other) const
template<typename T>
T get_uniform_cache (std::uint64_t name) const
template<typename T>
std::optional< T > get_uniform_cache_safe (std::uint64_t name) const
void set_uniform (std::uint64_t name, int value, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, int value)
void set_uniform (std::uint64_t name, float value, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, float value)
void set_uniform (std::uint64_t name, const Eigen::Vector2f &vector, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const Eigen::Vector2f &vector)
void set_uniform (std::uint64_t name, const Eigen::Vector3f &vector, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const Eigen::Vector3f &vector)
void set_uniform (std::uint64_t name, const Eigen::Vector4f &vector, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const Eigen::Vector4f &vector)
void set_uniform (std::uint64_t name, const Eigen::Vector2i &vector, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const Eigen::Vector2i &vector)
void set_uniform (std::uint64_t name, const Eigen::Vector3i &vector, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const Eigen::Vector3i &vector)
void set_uniform (std::uint64_t name, const Eigen::Vector4i &vector, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const Eigen::Vector4i &vector)
void set_uniform (std::uint64_t name, const Eigen::Matrix4f &matrix, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const Eigen::Matrix4f &matrix)
void set_uniform (std::uint64_t name, const std::vector< int > &vectors, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const std::vector< int > &vectors)
void set_uniform (std::uint64_t name, const std::vector< float > &vectors, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const std::vector< float > &vectors)
void set_uniform (std::uint64_t name, const std::vector< Eigen::Vector2f > &vectors, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const std::vector< Eigen::Vector2f > &vectors)
void set_uniform (std::uint64_t name, const std::vector< Eigen::Vector3f > &vectors, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const std::vector< Eigen::Vector3f > &vectors)
void set_uniform (std::uint64_t name, const std::vector< Eigen::Vector4f > &vectors, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const std::vector< Eigen::Vector4f > &vectors)
void set_uniform (std::uint64_t name, const Eigen::Matrix4d &matrix_, const char *debug_msg=nullptr)
void set_uniform (const std::string &name, const Eigen::Matrix4d &matrix_)
void set_subroutine (GLenum shader_type, const std::string &loc, const std::string &func)

Detailed Description

GLSLShader is a wrapper for OpenGL shader programs.

Building a shader program — Option 1: From source files — auto shader = std::make_shared<glk::GLSLShader>(); shader->attach_source("vertex_shader.glsl", GL_VERTEX_SHADER); shader->attach_source("fragment_shader.glsl", GL_FRAGMENT_SHADER); shader->link_program(); — Option 2: From source files — std::string vs_source = "..."; // Vertex shader source code std::string fs_source = "..."; // Fragment shader source code shader->attach_source(vs_source, GL_VERTEX_SHADER); shader->attach_source(fs_source, GL_FRAGMENT_SHADER); shader->link_program();

Getting attribute and uniform locations

shader->use(); GLint position_loc = shader->attrib("position"); GLint color_loc = shader->attrib("color"); GLint model_matrix_loc = shader->uniform("model_matrix");

shader->unuse();

Copying (cached) uniform variables from another shader

src_shader->copy_cached_uniforms(dst_shader);

Constructor & Destructor Documentation

◆ GLSLShader()

glk::GLSLShader::GLSLShader ( )

◆ ~GLSLShader()

glk::GLSLShader::~GLSLShader ( )

Member Function Documentation

◆ add_feedback_varying()

bool glk::GLSLShader::add_feedback_varying ( const std::string & name)

◆ attach_source() [1/6]

bool glk::GLSLShader::attach_source ( const std::string & filename,
const std::unordered_set< std::string > & include_filenames,
const std::string & defines,
const std::vector< std::pair< std::string, std::string > > & replaces,
GLuint shader_type )

◆ attach_source() [2/6]

bool glk::GLSLShader::attach_source ( const std::string & filename,
const std::unordered_set< std::string > & include_filenames,
const std::string & defines,
GLuint shader_type )

◆ attach_source() [3/6]

bool glk::GLSLShader::attach_source ( const std::string & filename,
GLuint shader_type )

◆ attach_source() [4/6]

bool glk::GLSLShader::attach_source ( const std::vector< std::string > & filenames,
const std::unordered_set< std::string > & include_filenames,
const std::string & defines,
const std::vector< std::pair< std::string, std::string > > & replaces,
GLuint shader_type )

Attach shader source code from multiple files, with optional include files, defines, and replacements.

Parameters
filenamesFilenames of the shader source files to attach.
include_filenamesFilenames of the include files to be inserted into the shader source code.
definesPreprocessor definitions to be added to the shader source code.
replacesPairs of strings representing text replacements to be made in the shader source code.
shader_typeType of shader (e.g., GL_VERTEX_SHADER, GL_FRAGMENT_SHADER).
Returns
True if all shader source files were successfully attached, false otherwise.

◆ attach_source() [5/6]

bool glk::GLSLShader::attach_source ( const std::vector< std::string > & filenames,
const std::unordered_set< std::string > & include_filenames,
const std::string & defines,
GLuint shader_type )

◆ attach_source() [6/6]

bool glk::GLSLShader::attach_source ( const std::vector< std::string > & filenames,
GLuint shader_type )

◆ attach_source_code()

bool glk::GLSLShader::attach_source_code ( const std::string & source_code,
GLuint shader_type )

Attach shader source code from a string.

Parameters
source_codeSource code text
shader_typeType of shader
Returns
True if the shader source code was successfully attached, false otherwise.

◆ attrib() [1/2]

GLint glk::GLSLShader::attrib ( const std::string & name)

◆ attrib() [2/2]

GLint glk::GLSLShader::attrib ( std::uint64_t name,
const char * debug_msg = nullptr )

◆ copy_cached_uniforms()

void glk::GLSLShader::copy_cached_uniforms ( GLSLShader & other) const

◆ get_uniform4f() [1/2]

Eigen::Vector4f glk::GLSLShader::get_uniform4f ( const std::string & name)

◆ get_uniform4f() [2/2]

Eigen::Vector4f glk::GLSLShader::get_uniform4f ( std::uint64_t name)

◆ get_uniform_cache()

template<typename T>
T glk::GLSLShader::get_uniform_cache ( std::uint64_t name) const
inline

◆ get_uniform_cache_safe()

template<typename T>
std::optional< T > glk::GLSLShader::get_uniform_cache_safe ( std::uint64_t name) const
inline

◆ get_uniform_matrix4f() [1/2]

Eigen::Matrix4f glk::GLSLShader::get_uniform_matrix4f ( const std::string & name)

◆ get_uniform_matrix4f() [2/2]

Eigen::Matrix4f glk::GLSLShader::get_uniform_matrix4f ( std::uint64_t name)

◆ get_uniformf() [1/2]

float glk::GLSLShader::get_uniformf ( const std::string & name)

◆ get_uniformf() [2/2]

float glk::GLSLShader::get_uniformf ( std::uint64_t name)

◆ get_uniformi() [1/2]

int glk::GLSLShader::get_uniformi ( const std::string & name)

◆ get_uniformi() [2/2]

int glk::GLSLShader::get_uniformi ( std::uint64_t name)

◆ id()

GLuint glk::GLSLShader::id ( ) const

Returns shader ID.

◆ init() [1/3]

bool glk::GLSLShader::init ( const std::string & shader_path)

◆ init() [2/3]

bool glk::GLSLShader::init ( const std::string & vertex_shader_path,
const std::string & fragment_shader_path )

◆ init() [3/3]

bool glk::GLSLShader::init ( const std::vector< std::string > & vertex_shader_paths,
const std::vector< std::string > & fragment_shader_paths )

◆ link_program()

bool glk::GLSLShader::link_program ( )

Link attached shaders into a shader program.

Returns
true if linking is successful, false otherwise.

◆ set_subroutine()

void glk::GLSLShader::set_subroutine ( GLenum shader_type,
const std::string & loc,
const std::string & func )

◆ set_uniform() [1/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const Eigen::Matrix4d & matrix_ )

◆ set_uniform() [2/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const Eigen::Matrix4f & matrix )

◆ set_uniform() [3/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const Eigen::Vector2f & vector )

◆ set_uniform() [4/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const Eigen::Vector2i & vector )

◆ set_uniform() [5/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const Eigen::Vector3f & vector )

◆ set_uniform() [6/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const Eigen::Vector3i & vector )

◆ set_uniform() [7/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const Eigen::Vector4f & vector )

◆ set_uniform() [8/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const Eigen::Vector4i & vector )

◆ set_uniform() [9/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const std::vector< Eigen::Vector2f > & vectors )

◆ set_uniform() [10/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const std::vector< Eigen::Vector3f > & vectors )

◆ set_uniform() [11/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const std::vector< Eigen::Vector4f > & vectors )

◆ set_uniform() [12/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const std::vector< float > & vectors )

◆ set_uniform() [13/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
const std::vector< int > & vectors )

◆ set_uniform() [14/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
float value )

◆ set_uniform() [15/30]

void glk::GLSLShader::set_uniform ( const std::string & name,
int value )

◆ set_uniform() [16/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const Eigen::Matrix4d & matrix_,
const char * debug_msg = nullptr )

◆ set_uniform() [17/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const Eigen::Matrix4f & matrix,
const char * debug_msg = nullptr )

◆ set_uniform() [18/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const Eigen::Vector2f & vector,
const char * debug_msg = nullptr )

◆ set_uniform() [19/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const Eigen::Vector2i & vector,
const char * debug_msg = nullptr )

◆ set_uniform() [20/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const Eigen::Vector3f & vector,
const char * debug_msg = nullptr )

◆ set_uniform() [21/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const Eigen::Vector3i & vector,
const char * debug_msg = nullptr )

◆ set_uniform() [22/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const Eigen::Vector4f & vector,
const char * debug_msg = nullptr )

◆ set_uniform() [23/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const Eigen::Vector4i & vector,
const char * debug_msg = nullptr )

◆ set_uniform() [24/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const std::vector< Eigen::Vector2f > & vectors,
const char * debug_msg = nullptr )

◆ set_uniform() [25/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const std::vector< Eigen::Vector3f > & vectors,
const char * debug_msg = nullptr )

◆ set_uniform() [26/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const std::vector< Eigen::Vector4f > & vectors,
const char * debug_msg = nullptr )

◆ set_uniform() [27/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const std::vector< float > & vectors,
const char * debug_msg = nullptr )

◆ set_uniform() [28/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
const std::vector< int > & vectors,
const char * debug_msg = nullptr )

◆ set_uniform() [29/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
float value,
const char * debug_msg = nullptr )

◆ set_uniform() [30/30]

void glk::GLSLShader::set_uniform ( std::uint64_t name,
int value,
const char * debug_msg = nullptr )

◆ subroutine() [1/2]

GLint glk::GLSLShader::subroutine ( GLenum shader_type,
const std::string & name )

◆ subroutine() [2/2]

GLint glk::GLSLShader::subroutine ( GLenum shader_type,
std::uint64_t name,
const char * debug_msg = nullptr )

◆ subroutine_uniform() [1/2]

GLint glk::GLSLShader::subroutine_uniform ( GLenum shader_type,
const std::string & name )

◆ subroutine_uniform() [2/2]

GLint glk::GLSLShader::subroutine_uniform ( GLenum shader_type,
std::uint64_t name,
const char * debug_msg = nullptr )

◆ uniform() [1/2]

GLint glk::GLSLShader::uniform ( const std::string & name)

◆ uniform() [2/2]

GLint glk::GLSLShader::uniform ( std::uint64_t name,
const char * debug_msg = nullptr )

◆ unuse()

void glk::GLSLShader::unuse ( ) const

Unuse the shader.

◆ use()

void glk::GLSLShader::use ( ) const

Use the shader in the OpenGL context.


The documentation for this class was generated from the following file: