StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
ShaderProgram.hpp
1#pragma once
2#ifdef StevEngine_RENDERER_GL
3#include "Shader.hpp"
4#include "utilities/Vector3.hpp"
5#include "utilities/Vector2.hpp"
6#include "utilities/Color.hpp"
7#include "utilities/Matrix4.hpp"
8#include "utilities/Stream.hpp"
9#include "visuals/Texture.hpp"
10
11#include <map>
12#include <cstdint>
13#include <glad/gl.h>
14
15namespace StevEngine::Renderer {
23 public:
29 ShaderProgram(ShaderType shaderType, bool useDefaultShaders = true);
30
39 ShaderProgram(const std::vector<Shader>& shaders, bool useDefaultShaders = true);
40
46
49
55 uint32_t AddShader(Shader shader);
56
61 void RemoveShader(uint32_t location);
62
64 void RelinkProgram();
65
67 void DeleteProgram();
68
69 // Uniform setters
75 void SetShaderUniform(const char* name, Utilities::Matrix4 value) const;
76
82 void SetShaderUniform(const char* name, Utilities::Color value) const;
83
89 void SetShaderUniform(const char* name, Utilities::Vector3 value) const;
90
96 void SetShaderUniform(const char* name, Utilities::Vector2 value) const;
97
103 void SetShaderUniform(const char* name, bool value) const;
104
110 void SetShaderUniform(const char* name, int32_t value) const;
111
117 void SetShaderUniform(const char* name, uint32_t value) const;
118
124 void SetShaderUniform(const char* name, float value) const;
125
131 void SetShaderUniform(const char* name, double value) const;
132
137 uint32_t GetLocation() const { return location; }
138
143 bool IsModified() const { return modified; }
144
149 ShaderType GetType() const { return shaderType; };
150
156 Utilities::Stream Export(Utilities::StreamType type) const;
157
158 protected:
159 uint32_t location;
160 ShaderType shaderType;
161 bool modified;
162 std::map<uint32_t, Shader> shaders;
163 };
164
166 public:
173 ComputeShader(const char* source);
174
180 ComputeShader(const std::vector<Shader>& shaders) : ShaderProgram(shaders) {};
181
187
195 void Run(const Visuals::ComputeTexture& output) const { return Run(output, output.width, output.height, 1); }
203 void Run(const Visuals::ComputeTexture& output, uint32_t groupsX, uint32_t groupsY, uint32_t groupsZ = 1) const;
210 void Run(uint32_t groupsX, uint32_t groupsY, uint32_t groupsZ = 1) const;
211
212 };
213}
214#endif
ComputeShader(const std::vector< Shader > &shaders)
Create compute shader program.
Definition ShaderProgram.hpp:180
ComputeShader(Utilities::Stream &stream)
Create from serialized data.
Definition ShaderProgram.hpp:186
void Run(const Visuals::ComputeTexture &output) const
Run the compute shader.
Definition ShaderProgram.hpp:195
ComputeShader(const char *source)
Create compute shader program , with a single shader from source.
Definition ShaderProgram.cpp:124
ShaderProgram()
Create empty program.
Definition ShaderProgram.hpp:48
uint32_t AddShader(Shader shader)
Add shader stage to program.
Definition ShaderProgram.cpp:45
uint32_t location
OpenGL program ID.
Definition ShaderProgram.hpp:159
uint32_t GetLocation() const
Get OpenGL program ID.
Definition ShaderProgram.hpp:137
Utilities::Stream Export(Utilities::StreamType type) const
Serialize shader program to a stream.
Definition ShaderProgram.cpp:79
bool modified
Whether program needs relinking.
Definition ShaderProgram.hpp:161
ShaderType GetType() const
Get program shader type.
Definition ShaderProgram.hpp:149
ShaderProgram(ShaderType shaderType, bool useDefaultShaders=true)
Create shader program.
Definition ShaderProgram.cpp:19
ShaderType shaderType
Type of shaders in program.
Definition ShaderProgram.hpp:160
void RelinkProgram()
Relink program after shader changes.
Definition ShaderProgram.cpp:59
void SetShaderUniform(const char *name, Utilities::Matrix4 value) const
Set matrix uniform.
Definition ShaderProgram.cpp:95
void RemoveShader(uint32_t location)
Remove shader from program.
Definition ShaderProgram.cpp:52
bool IsModified() const
Check if program needs relinking.
Definition ShaderProgram.hpp:143
std::map< uint32_t, Shader > shaders
Shaders by OpenGL ID.
Definition ShaderProgram.hpp:162
void DeleteProgram()
Deletes program and all shaders from OpenGL.
Definition ShaderProgram.cpp:72
Single shader stage (vertex or fragment)
Definition Shader.hpp:23
4x4 matrix for 3D transformations
Definition Matrix4.hpp:12
Stream for serialization of data.
Definition Stream.hpp:20
2D vector class
Definition Vector2.hpp:13
3D vector class
Definition Vector3.hpp:19
Definition Texture.hpp:82
const uint32_t height
Height of the texture.
Definition Texture.hpp:118
const uint32_t width
Width of the texture.
Definition Texture.hpp:117
Core rendering system.
Definition Object.cpp:19
RGBA color representation.
Definition Color.hpp:12