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>
6
7namespace shkyera::utils {
8
10
11template <typename ValueType>
12std::pair<std::string, ValueType> Uniform(const std::string& name, const ValueType& value) {
13 return std::make_pair(name, value);
14}
15
16template <typename... Uniforms>
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();
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
38
39 // Stop using the shader program and unbind framebuffer
40 frameBuffer.unbind();
41}
42
43template <typename ArrayType, typename... Uniforms>
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
71
72 // Stop using the shader program and unbind framebuffer
73 shaderProgram.stopUsing();
74 frameBuffer.unbind();
75}
76
77} // namespace shkyera::utils
Definition SceneFrameBuffer.hpp:11
Definition ShaderProgram.hpp:15
Definition ShaderProgram.hpp:43
Definition Utils.cpp:3
std::pair< std::string, ValueType > Uniform(const std::string &name, const ValueType &value)
Definition Utils.hpp:12
void drawFullscreenQuad()
Definition Utils.cpp:5
void applyShaderToFrameBuffer(SceneFrameBuffer &frameBuffer, ShaderProgram &shaderProgram, std::vector< std::pair< const char *, const Texture * > > textures, Uniforms... uniforms)
Definition Utils.hpp:17
Definition Clock.hpp:9