Euphoria
shader.h
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_set>
4
6#include "eu/render/uniform.h"
8
9namespace eu
10{
11 struct m4;
12 struct v2;
13 struct v3;
14 struct v4;
15}
16
17namespace eu::core
18{
19 struct UniformBufferSetup;
20}
21
22namespace eu::render
23{
24
28{
37 const std::string& vertex_source,
38 const std::string& fragment_source,
40 );
41
46
48 ShaderProgram(const ShaderProgram&) = delete;
49
51 void operator=(const ShaderProgram&) = delete;
52
57
62
66 void clear();
67
71 [[nodiscard]] bool is_loaded() const;
72
75 void use() const;
76
81 [[nodiscard]] Uniform get_uniform(const std::string& name) const;
82
89 void set_float(const Uniform& uniform, float value);
90
91
97 void set_bool(const Uniform& uniform, bool value);
98
106 void set_vec2(const Uniform& uniform, float x, float y);
107
114 void set_vec2(const Uniform& uniform, const v2& v);
115
124 void set_vec3(const Uniform& uniform, float x, float y, float z);
125
132 void set_vec3(const Uniform& uniform, const v3& v);
133
143 void set_vec4(const Uniform& uniform, float x, float y, float z, float w);
144
151 void set_vec4(const Uniform& uniform, const v4& v);
152
158 void set_texture(const Uniform& uniform);
159
165 void set_mat(const Uniform& uniform, const m4& mat);
166
171
172 unsigned int shader_program;
174};
175
181void setup_textures(ShaderProgram* shader, const std::vector<Uniform*>& uniform_list);
182
189bool is_bound_for_shader(const std::unordered_set<core::VertexType>& debug_geom_shader_types);
190
196bool is_shader_bound(unsigned int program);
197
201
202}
#define DEBUG_LABEL_ARG_MANY
first debug label argument of many
std::vector< VertexType > VertexTypes
Definition ui.h:4
bool is_bound_for_shader(const std::unordered_set< core::VertexType > &debug_geom_shader_types)
Verifies if the current shader matches the required vertex types.
void clear_shader_program()
Clears the current open gl shader program binding.
void setup_textures(ShaderProgram *shader, const std::vector< Uniform * > &uniform_list)
Sets up textures for a shader program.
bool is_shader_bound(unsigned int program)
Checks if a specific shader program is currently active.
Definition assert.h:118
A (inclusive) range between two values.
Definition range.h:19
A list of CompiledVertexElement (for shader)
4x4 matrix
Definition mat4.h:19
RAII representation of a open gl shader program.
Definition shader.h:28
void set_vec3(const Uniform &uniform, const v3 &v)
Sets a uniform 3d vector.
ShaderProgram(const ShaderProgram &)=delete
Copying is not allowed.
void set_vec4(const Uniform &uniform, const v4 &v)
Sets a uniform 4d vector.
void set_vec3(const Uniform &uniform, float x, float y, float z)
Sets a uniform 3d vector.
void clear()
Turn this object into a zombie by destroying it.
void set_float(const Uniform &uniform, float value)
Sets a uniform float value.
~ShaderProgram()
Destroy the shader if it's loaded.
core::VertexTypes debug_vertex_types
The debug information describing the vertex layout that this shader expects.
Definition shader.h:173
void use() const
Activates the ShaderProgram for rendering.
void set_vec2(const Uniform &uniform, const v2 &v)
Sets a uniform 2d vector.
void set_texture(const Uniform &uniform)
Sets a texture for a uniform.
void setup_uniform_block(const core::UniformBufferSetup &setup)
Configures a uniform block binding for the shader.
ShaderProgram(DEBUG_LABEL_ARG_MANY const std::string &vertex_source, const std::string &fragment_source, const core::CompiledShaderVertexAttributes &layout)
Compile and link a shader.
void set_vec2(const Uniform &uniform, float x, float y)
Sets a uniform 2d vector.
void set_mat(const Uniform &uniform, const m4 &mat)
Sets a uniform 4x4 matrix.
void set_bool(const Uniform &uniform, bool value)
Sets a uniform boolean value.
Uniform get_uniform(const std::string &name) const
Get a uniform by name.
void set_vec4(const Uniform &uniform, float x, float y, float z, float w)
Sets a uniform 4d vector.
ShaderProgram & operator=(ShaderProgram &&rhs) noexcept
Take ownership of another shader.
bool is_loaded() const
Checks if the ShaderProgram is loaded and valid.
unsigned int shader_program
The id of the shader program.
Definition shader.h:172
ShaderProgram(ShaderProgram &&other) noexcept
Take ownership of another shader.
void operator=(const ShaderProgram &)=delete
Copying is not allowed.
Represents a found shader uniform and created via ShaderProgram::GetUniform()
Definition uniform.h:9
a 2d vector
Definition vec2.h:17
a 3d vector
Definition vec3.h:27
A 4d vector.
Definition vec4.h:17