CPP-TOOLBOX
Loading...
Searching...
No Matches
ShaderCache Class Reference

facilitates simple and robust interaction with shaders More...

#include <shader_cache.hpp>

Public Member Functions

 ShaderCache (std::vector< ShaderType > requested_shaders)
 
 ~ShaderCache ()
 
ShaderProgramInfo get_shader_program (ShaderType type) const
 
void use_shader_program (ShaderType type)
 
void stop_using_shader_program ()
 
void register_shader_program (ShaderType type)
 
void configure_vertex_attributes_for_drawables_vao (GLuint vertex_attribute_object, GLuint vertex_buffer_object, ShaderType type, ShaderVertexAttributeVariable shader_vertex_attribute_variable)
 configures a VAO so that it knows how to transmit data from a VBO into the shader program
 
void log_shader_program_info ()
 
GLVertexAttributeConfiguration get_gl_vertex_attribute_configuration_for_vertex_attribute_variable (ShaderVertexAttributeVariable shader_vertex_attribute_variable)
 
std::vector< ShaderVertexAttributeVariable > get_used_vertex_attribute_variables_for_shader (ShaderType type)
 
std::string get_vertex_attribute_variable_name (ShaderVertexAttributeVariable shader_vertex_attribute_variable)
 
std::string get_uniform_name (ShaderUniformVariable uniform)
 
GLint get_uniform_location (ShaderType type, ShaderUniformVariable uniform)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, bool value)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, int value)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, float value)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, const glm::vec2 &vec)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, float x, float y)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, const glm::vec3 &vec)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, float x, float y, float z)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, const glm::vec4 &vec)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, const std::vector< glm::vec4 > &values)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, float x, float y, float z, float w)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, const glm::mat2 &mat)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, const glm::mat3 &mat)
 
void set_uniform (ShaderType type, ShaderUniformVariable uniform, const glm::mat4 &mat)
 
void print_out_active_uniforms_in_shader (ShaderType type)
 

Public Attributes

ShaderStandard shader_standard
 
Logger logger = Logger("shader_cache")
 

Detailed Description

facilitates simple and robust interaction with shaders

a shader cache is a tool which helps manage shaders in a sane way, firstly the user defines what types of shaders by passing in the requested shaders from the shader catalog, then that shader can be selected easily, it also adheres to the cpp_toolbox standard for naming variables in shader files, this makes it easy to read shader files as when you see a variable you will know exactly what it standard for. With these features it makes it hard to mess up when using shaders

Constructor & Destructor Documentation

◆ ShaderCache()

ShaderCache::ShaderCache ( std::vector< ShaderType > requested_shaders)
Precondition
there is an active opengl context, otherwise undefined behavior
Parameters
requested_shadersout of the passed in which ones to actually create on instantiation

◆ ~ShaderCache()

ShaderCache::~ShaderCache ( )

Member Function Documentation

◆ configure_vertex_attributes_for_drawables_vao()

void ShaderCache::configure_vertex_attributes_for_drawables_vao ( GLuint vertex_attribute_object,
GLuint vertex_buffer_object,
ShaderType type,
ShaderVertexAttributeVariable shader_vertex_attribute_variable )

configures a VAO so that it knows how to transmit data from a VBO into the shader program

Todo
make sure that the vertex attribute variable is actually used in the selected shader type
Note
this assumes that each vertex attribute data array has its own unique vector for storing (usually a std::vector<glm::vec3>>) [or whatever type of vector]

a good way to think about this is that a shader program has a bunch of incoming conveyor belts, and we need to tell the shader program how big the boxes that are coming in are for each different conveyor belt, then this function is like a conveyor belt configuration, so that we say "BIG_BOXES" and then this function automates setting up the conveyor belt so that the shader program can properly consume those boxes,

With this analogy VAOs are like employees in charge of physical objects, they have different types of objects, say toys, and books which are represented by VBOs they for each type of object, they need to configure how the conveyor belt will operate for each object type (ie, the books can be packed closer than the toys).

This function is then like a "training session" for the employee so that they learn how to configure the conveyor belts, for their own custom objects this is done so that no matter what objects need to be packaged up, the corresponding employee will know how to properly do this.

Parameters
vertex_attribute_objectthe vao that we need to configure the vertex attributes for
vertex_buffer_objectthe buffer contiaining the vertex attribute data
typethe shader we want to do this for

◆ get_gl_vertex_attribute_configuration_for_vertex_attribute_variable()

GLVertexAttributeConfiguration ShaderCache::get_gl_vertex_attribute_configuration_for_vertex_attribute_variable ( ShaderVertexAttributeVariable shader_vertex_attribute_variable)

◆ get_shader_program()

ShaderProgramInfo ShaderCache::get_shader_program ( ShaderType type) const
Precondition
the requested shader program has been created
Parameters
typethe type of shader to get
Returns
the id of the shader program

◆ get_uniform_location()

GLint ShaderCache::get_uniform_location ( ShaderType type,
ShaderUniformVariable uniform )

◆ get_uniform_name()

std::string ShaderCache::get_uniform_name ( ShaderUniformVariable uniform)

◆ get_used_vertex_attribute_variables_for_shader()

std::vector< ShaderVertexAttributeVariable > ShaderCache::get_used_vertex_attribute_variables_for_shader ( ShaderType type)

◆ get_vertex_attribute_variable_name()

std::string ShaderCache::get_vertex_attribute_variable_name ( ShaderVertexAttributeVariable shader_vertex_attribute_variable)

◆ log_shader_program_info()

void ShaderCache::log_shader_program_info ( )

◆ print_out_active_uniforms_in_shader()

void ShaderCache::print_out_active_uniforms_in_shader ( ShaderType type)

◆ register_shader_program()

void ShaderCache::register_shader_program ( ShaderType type)

◆ set_uniform() [1/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
bool value )

◆ set_uniform() [2/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
const glm::mat2 & mat )

◆ set_uniform() [3/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
const glm::mat3 & mat )

◆ set_uniform() [4/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
const glm::mat4 & mat )

◆ set_uniform() [5/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
const glm::vec2 & vec )

◆ set_uniform() [6/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
const glm::vec3 & vec )

◆ set_uniform() [7/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
const glm::vec4 & vec )

◆ set_uniform() [8/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
const std::vector< glm::vec4 > & values )

◆ set_uniform() [9/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
float value )

◆ set_uniform() [10/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
float x,
float y )

◆ set_uniform() [11/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
float x,
float y,
float z )

◆ set_uniform() [12/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
float x,
float y,
float z,
float w )

◆ set_uniform() [13/13]

void ShaderCache::set_uniform ( ShaderType type,
ShaderUniformVariable uniform,
int value )

◆ stop_using_shader_program()

void ShaderCache::stop_using_shader_program ( )

◆ use_shader_program()

void ShaderCache::use_shader_program ( ShaderType type)

Member Data Documentation

◆ logger

Logger ShaderCache::logger = Logger("shader_cache")

◆ shader_standard

ShaderStandard ShaderCache::shader_standard

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