CPP-TOOLBOX
Loading...
Searching...
No Matches
shader_cache.hpp
Go to the documentation of this file.
1#ifndef SHADER_CACHE_HPP
2#define SHADER_CACHE_HPP
3
4#include <glm/glm.hpp>
5#include <stdexcept>
6#include <string>
7#include <unordered_map>
8
10
24 public:
25 ShaderCache(std::vector<ShaderType> requested_shaders);
27 ShaderStandard shader_standard;
28
29 Logger logger = Logger("shader_cache");
30
31 ShaderProgramInfo get_shader_program(ShaderType type) const;
32 void use_shader_program(ShaderType type);
34 void register_shader_program(ShaderType type);
35
36 void configure_vertex_attributes_for_drawables_vao(GLuint vertex_attribute_object, GLuint vertex_buffer_object,
37 ShaderType type,
38 ShaderVertexAttributeVariable shader_vertex_attribute_variable);
39
41
43 ShaderVertexAttributeVariable shader_vertex_attribute_variable);
44 std::vector<ShaderVertexAttributeVariable> get_used_vertex_attribute_variables_for_shader(ShaderType type);
45 std::string get_vertex_attribute_variable_name(ShaderVertexAttributeVariable shader_vertex_attribute_variable);
46 std::string get_uniform_name(ShaderUniformVariable uniform);
47 GLint get_uniform_location(ShaderType type, ShaderUniformVariable uniform);
48
49 void set_uniform(ShaderType type, ShaderUniformVariable uniform, bool value);
50 void set_uniform(ShaderType type, ShaderUniformVariable uniform, int value);
51 void set_uniform(ShaderType type, ShaderUniformVariable uniform, float value);
52 void set_uniform(ShaderType type, ShaderUniformVariable uniform, const glm::vec2 &vec);
53 void set_uniform(ShaderType type, ShaderUniformVariable uniform, float x, float y);
54 void set_uniform(ShaderType type, ShaderUniformVariable uniform, const glm::vec3 &vec);
55 void set_uniform(ShaderType type, ShaderUniformVariable uniform, float x, float y, float z);
56 void set_uniform(ShaderType type, ShaderUniformVariable uniform, const glm::vec4 &vec);
57 void set_uniform(ShaderType type, ShaderUniformVariable uniform, const std::vector<glm::vec4> &values);
58 void set_uniform(ShaderType type, ShaderUniformVariable uniform, float x, float y, float z, float w);
59 void set_uniform(ShaderType type, ShaderUniformVariable uniform, const glm::mat2 &mat);
60 void set_uniform(ShaderType type, ShaderUniformVariable uniform, const glm::mat3 &mat);
61 void set_uniform(ShaderType type, ShaderUniformVariable uniform, const glm::mat4 &mat);
62 void print_out_active_uniforms_in_shader(ShaderType type);
63
64 private:
65 GLuint attach_shader(GLuint program, const std::string &path, GLenum shader_type);
66 void link_program(GLuint program);
67
68 std::unordered_map<ShaderType, ShaderProgramInfo> created_shaders;
69};
70
71std::string shader_type_to_string(ShaderType type);
72
73#endif // SHADER_CACHE_HPP
Definition logger.hpp:22
~ShaderCache()
Definition shader_cache.cpp:24
ShaderCache(std::vector< ShaderType > requested_shaders)
Definition shader_cache.cpp:14
GLint get_uniform_location(ShaderType type, ShaderUniformVariable uniform)
Definition shader_cache.cpp:212
void print_out_active_uniforms_in_shader(ShaderType type)
Definition shader_cache.cpp:51
std::string get_uniform_name(ShaderUniformVariable uniform)
Definition shader_cache.cpp:163
GLVertexAttributeConfiguration get_gl_vertex_attribute_configuration_for_vertex_attribute_variable(ShaderVertexAttributeVariable shader_vertex_attribute_variable)
Definition shader_cache.cpp:173
void stop_using_shader_program()
Definition shader_cache.cpp:64
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
Definition shader_cache.cpp:124
ShaderStandard shader_standard
Definition shader_cache.hpp:27
void set_uniform(ShaderType type, ShaderUniformVariable uniform, bool value)
Definition shader_cache.cpp:221
ShaderProgramInfo get_shader_program(ShaderType type) const
Definition shader_cache.cpp:35
void register_shader_program(ShaderType type)
Definition shader_cache.cpp:66
Logger logger
Definition shader_cache.hpp:29
std::string get_vertex_attribute_variable_name(ShaderVertexAttributeVariable shader_vertex_attribute_variable)
Definition shader_cache.cpp:199
void log_shader_program_info()
Definition shader_cache.cpp:384
std::vector< ShaderVertexAttributeVariable > get_used_vertex_attribute_variables_for_shader(ShaderType type)
Definition shader_cache.cpp:187
void use_shader_program(ShaderType type)
Definition shader_cache.cpp:46
@ y
Definition input_state.hpp:51
@ x
Definition input_state.hpp:50
@ w
Definition input_state.hpp:49
@ z
Definition input_state.hpp:52
std::string shader_type_to_string(ShaderType type)