Euphoria
shader.h
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_set>
4
6#include "render/uniform.h"
8
9namespace eu
10{
11 struct m4;
12 struct v2;
13 struct v3;
14 struct v4;
15}
16
17namespace eu::render
18{
19
20struct UniformBufferSetup;
21
25{
34 const std::string& vertex_source,
35 const std::string& fragment_source,
37 );
38
43
45 ShaderProgram(const ShaderProgram&) = delete;
46
48 void operator=(const ShaderProgram&) = delete;
49
54
59
63 void clear();
64
68 [[nodiscard]] bool is_loaded() const;
69
72 void use() const;
73
78 [[nodiscard]] Uniform get_uniform(const std::string& name) const;
79
86 void set_float(const Uniform& uniform, float value);
87
88
94 void set_bool(const Uniform& uniform, bool value);
95
103 void set_vec2(const Uniform& uniform, float x, float y);
104
111 void set_vec2(const Uniform& uniform, const v2& v);
112
121 void set_vec3(const Uniform& uniform, float x, float y, float z);
122
129 void set_vec3(const Uniform& uniform, const v3& v);
130
140 void set_vec4(const Uniform& uniform, float x, float y, float z, float w);
141
148 void set_vec4(const Uniform& uniform, const v4& v);
149
156
162 void set_mat(const Uniform& uniform, const m4& mat);
163
168
169 unsigned int shader_program;
171};
172
178void setup_textures(ShaderProgram* shader, const std::vector<Uniform*>& uniform_list);
179
186bool is_bound_for_shader(const std::unordered_set<VertexType>& debug_geom_shader_types);
187
193bool is_shader_bound(unsigned int program);
194
198
199}
#define DEBUG_LABEL_ARG_MANY
first debug label argument of many
std::vector< VertexType > VertexTypes
void clear_shader_program()
Clears the current open gl shader program binding.
bool is_bound_for_shader(const std::unordered_set< VertexType > &debug_geom_shader_types)
Verifies if the current shader matches the required vertex types.
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:111
A (inclusive) range between two values.
Definition range.h:19
4x4 matrix
Definition mat4.h:19
A list of CompiledVertexElement (for shader)
RAII representation of a open gl shader program.
Definition shader.h:25
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.
ShaderProgram(DEBUG_LABEL_ARG_MANY const std::string &vertex_source, const std::string &fragment_source, const CompiledShaderVertexAttributes &layout)
Compile and link a shader.
void setup_uniform_block(const UniformBufferSetup &setup)
Configures a uniform block binding for the shader.
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 set_vec2(const Uniform &uniform, float x, float y)
Sets a uniform 2d vector.
VertexTypes debug_vertex_types
The debug information describing the vertex layout that this shader expects.
Definition shader.h:170
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:169
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