Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
Utils.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <glad/glad.h>
4
#include <
Rendering/FrameBuffers/SceneFrameBuffer.hpp
>
5
#include <
Rendering/ShaderProgram.hpp
>
6
7
namespace
shkyera::utils
{
8
9
void
drawFullscreenQuad
();
10
11
template
<
typename
ValueType>
12
std::pair<std::string, ValueType>
Uniform
(
const
std::string& name,
const
ValueType
&
value
) {
13
return
std::make_pair(name,
value
);
14
}
15
16
template
<
typename
...
Uniforms
>
17
void
applyShaderToFrameBuffer
(
18
SceneFrameBuffer
&
frameBuffer
,
ShaderProgram
&
shaderProgram
,
19
std::vector<std::pair<const char*, const Texture*>>
textures
,
// List of texture bindings with texture unit indices
20
Uniforms
...
uniforms
)
// Parameter pack for uniform values
21
{
22
// Bind framebuffer and activate shader program
23
frameBuffer
.bind();
24
UseShader
shaderUsage
(
shaderProgram
);
25
26
// Bind textures to their corresponding texture units
27
int
textureIndex
= 0;
28
for
(
const
auto
& [name,
texture
] :
textures
) {
29
texture
->activate(
GL_TEXTURE0
+
textureIndex
);
30
shaderProgram
.setUniform(name,
textureIndex
++);
31
}
32
33
// Set uniforms using the parameter pack
34
(
shaderProgram
.setUniform(
uniforms
.first,
uniforms
.second), ...);
35
36
// Draw fullscreen quad
37
utils::drawFullscreenQuad
();
38
39
// Stop using the shader program and unbind framebuffer
40
frameBuffer
.unbind();
41
}
42
43
template
<
typename
ArrayType
,
typename
...
Uniforms
>
44
void
applyShaderToFrameBuffer
(
45
SceneFrameBuffer
&
frameBuffer
,
ShaderProgram
&
shaderProgram
,
46
std::vector<std::pair<const char*, const Texture*>>
textures
,
// List of texture bindings with texture unit indices
47
std::pair<
const
char
*, std::vector<ArrayType>>
array
,
48
Uniforms
...
uniforms
)
// Parameter pack for uniform values
49
{
50
// Bind framebuffer and activate shader program
51
frameBuffer
.bind();
52
shaderProgram
.use();
53
54
// Bind textures to their corresponding texture units
55
int
textureIndex
= 0;
56
for
(
const
auto
& [name,
texture
] :
textures
) {
57
texture
->activate(
GL_TEXTURE0
+
textureIndex
);
58
shaderProgram
.setUniform(name,
textureIndex
++);
59
}
60
61
int
index = 0;
62
for
(
const
auto
&
val
:
array
.second) {
63
shaderProgram
.setUniform(std::string(
array
.first) +
"["
+ std::to_string(index++) +
"]"
,
val
);
64
}
65
66
// Set uniforms using the parameter pack
67
(
shaderProgram
.setUniform(
uniforms
.first,
uniforms
.second), ...);
68
69
// Draw fullscreen quad
70
utils::drawFullscreenQuad
();
71
72
// Stop using the shader program and unbind framebuffer
73
shaderProgram
.stopUsing();
74
frameBuffer
.unbind();
75
}
76
77
}
// namespace shkyera::utils
SceneFrameBuffer.hpp
ShaderProgram.hpp
shkyera::SceneFrameBuffer
Definition
SceneFrameBuffer.hpp:11
shkyera::ShaderProgram
Definition
ShaderProgram.hpp:15
shkyera::UseShader
Definition
ShaderProgram.hpp:43
shkyera::utils
Definition
Utils.cpp:3
shkyera::utils::Uniform
std::pair< std::string, ValueType > Uniform(const std::string &name, const ValueType &value)
Definition
Utils.hpp:12
shkyera::utils::drawFullscreenQuad
void drawFullscreenQuad()
Definition
Utils.cpp:5
shkyera::utils::applyShaderToFrameBuffer
void applyShaderToFrameBuffer(SceneFrameBuffer &frameBuffer, ShaderProgram &shaderProgram, std::vector< std::pair< const char *, const Texture * > > textures, Uniforms... uniforms)
Definition
Utils.hpp:17
shkyera::Clock
Definition
Clock.hpp:9
src
Rendering
Utils.hpp
Generated by
1.9.8
Franciszek Szewczyk © 2023