SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
OpenGLShader.hpp
Go to the documentation of this file.
1
#ifndef OPENGLSHADER_HPP_
2
#define OPENGLSHADER_HPP_
3
4
#include <glad/glad.h>
5
6
#include <string>
7
8
#include "
../Common/Shader.hpp
"
9
#ifdef SLEAK_HOT_RELOAD
10
#include <unordered_set>
11
#endif
12
13
namespace
Sleak
{
14
namespace
RenderEngine
{
15
16
/// GLSL shader program compiled from either a combined source file or separate vertex/fragment files.
17
class
ENGINE_API
OpenGLShader
:
public
Shader
{
18
public
:
19
OpenGLShader
();
20
~OpenGLShader
()
override
;
21
OpenGLShader
(
const
OpenGLShader
&) =
delete
;
22
OpenGLShader
&
operator=
(
const
OpenGLShader
&) =
delete
;
23
24
/// Splits a combined shader file into vertex/fragment stages and links them.
25
bool
compile
(
const
std::string& shaderPath)
override
;
26
/// Compiles and links separate vertex and fragment shader files.
27
bool
compile
(
const
std::string& vert,
const
std::string& frag)
override
;
28
void
bind
()
override
;
29
30
GLuint
GetProgram
()
const
{
return
m_program; }
31
32
/// Rebuilds the program from its files, keeping the old one on failure.
33
bool
Reload();
34
/// Returns the stem of the vertex source, e.g. gbuffer for gbuffer_gl.vert.
35
const
std::string&
GetStem
()
const
{
return
m_vertStem; }
36
/// Returns true when the vertex or fragment source has the given stem.
37
bool
UsesStem
(
const
std::string& stem)
const
{
38
return
stem == m_vertStem || stem == m_fragStem;
39
}
40
41
#ifdef SLEAK_HOT_RELOAD
42
/// Returns every live OpenGLShader instance.
43
static
const
std::unordered_set<OpenGLShader*>& GetLiveShaders();
44
#endif
45
46
private
:
47
/// Compiles a single shader stage from source text.
48
bool
CompileShaderSource(
const
std::string& source, GLenum type,
49
const
std::string& path, GLuint& shader);
50
/// Links a new program from the stored paths and swaps it in on success.
51
bool
BuildProgram();
52
std::string ReadFile(
const
std::string& path);
53
54
GLuint m_program = 0;
55
std::string m_vertPath;
56
std::string m_fragPath;
57
std::string m_vertStem;
58
std::string m_fragStem;
59
};
60
61
}
// namespace RenderEngine
62
}
// namespace Sleak
63
64
#endif
// OPENGLSHADER_HPP_
Shader.hpp
Sleak::RenderEngine::OpenGLShader::OpenGLShader
OpenGLShader()
Definition
OpenGLShader.cpp:52
Sleak::RenderEngine::OpenGLShader::GetProgram
GLuint GetProgram() const
Definition
OpenGLShader.hpp:30
Sleak::RenderEngine::OpenGLShader::UsesStem
bool UsesStem(const std::string &stem) const
Returns true when the vertex or fragment source has the given stem.
Definition
OpenGLShader.hpp:37
Sleak::RenderEngine::OpenGLShader::GetStem
const std::string & GetStem() const
Returns the stem of the vertex source, e.g. gbuffer for gbuffer_gl.vert.
Definition
OpenGLShader.hpp:35
Sleak::RenderEngine::OpenGLShader::bind
void bind() override
Binds this program as the active shader for subsequent draws.
Definition
OpenGLShader.cpp:144
Sleak::RenderEngine::OpenGLShader::OpenGLShader
OpenGLShader(const OpenGLShader &)=delete
Sleak::RenderEngine::OpenGLShader::operator=
OpenGLShader & operator=(const OpenGLShader &)=delete
Sleak::RenderEngine::OpenGLShader::compile
bool compile(const std::string &shaderPath) override
Splits a combined shader file into vertex/fragment stages and links them.
Definition
OpenGLShader.cpp:74
Sleak::RenderEngine::Shader
Backend-agnostic compiled shader program.
Definition
Shader.hpp:11
Sleak::RenderEngine
Backend-facing rendering layer shared by the four graphics backends.
Definition
Application.hpp:60
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
include
private
Graphics
OpenGL
OpenGLShader.hpp
Generated on
for SleakEngine by
1.18.0