mousetrap v0.2.0
Loading...
Searching...
No Matches
render_task.hpp
1//
2// Copyright 2022 Clemens Cords
3// Created on 7/31/22 by clem (mail@clemens-cords.com)
4//
5
6#pragma once
7
8#include <mousetrap/gl_common.hpp>
9#if MOUSETRAP_ENABLE_OPENGL_COMPONENT
10#include <mousetrap/shape.hpp>
11#include <mousetrap/shader.hpp>
12#include <mousetrap/gl_transform.hpp>
13#include <mousetrap/blend_mode.hpp>
14
15#include <map>
16
17namespace mousetrap
18{
19 #ifndef DOXYGEN
20 namespace detail
21 {
22 struct _RenderTaskInternal
23 {
24 GObject parent;
25
26 detail::ShapeInternal* _shape = nullptr;
27 detail::ShaderInternal* _shader = nullptr;
28 GLTransform _transform;
29 BlendMode _blend_mode;
30
31 static inline Shader* noop_shader = nullptr;
32
33 std::map<std::string, float>* _floats;
34 std::map<std::string, int>* _ints;
35 std::map<std::string, glm::uint>* _uints;
36 std::map<std::string, Vector2f>* _vec2s;
37 std::map<std::string, Vector3f>* _vec3s;
38 std::map<std::string, Vector4f>* _vec4s;
39 std::map<std::string, GLTransform>* _transforms;
40 };
41 using RenderTaskInternal = _RenderTaskInternal;
42 }
43 #endif
44
45 /// @brief bundles a shape in a render task that can be invoked more conveniently during the render cycle
47 {
48 public:
49 /// @brief construct the render task
50 /// @param shape shape to render
51 /// @param shader shader to apply to the shape when rendering, if nullptr, the default shader is used
52 /// @param transform transform to hand to the vertex shader when rendering, if nullptr, the identity transform will be handed isntead
53 /// @param blend_mode blend_mode to set before rendering the shape, normal alpha-blending if unspecified
54 explicit RenderTask(const Shape& shape, const Shader* shader = nullptr, const GLTransform& transform = GLTransform(), BlendMode blend_mode = BlendMode::NORMAL);
55
56 /// @brief create from gobject \for_internal_use_only
57 RenderTask(detail::RenderTaskInternal*);
58
59 /// @brief destructor
61
62 /// @brief register a float that will be handed to a shader uniform of the given name during render
63 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>float</tt>
64 /// @param pointer pointer to value, the user is responsible for keeping it in scope
65 /// @param value
66 void set_uniform_float(const std::string& uniform_name, float value);
67
68 /// @brief register an int that will be handed to a shader uniform of the given name during render
69 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>int</tt>
70 /// @param value
71 void set_uniform_int(const std::string& uniform_name, int value);
72
73 /// @brief register an unsigned integer that will be handed to a shader uniform of the given name during render
74 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>uint</tt>
75 /// @param value
76 void set_uniform_uint(const std::string& uniform_name, glm::uint value);
77
78 /// @brief register a Vector2f that will be handed to a shader uniform of the given name during render
79 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>vec2</tt>
80 /// @param value
81 void set_uniform_vec2(const std::string& uniform_name, Vector2f value);
82
83 /// @brief register a Vector3f that will be handed to a shader uniform of the given name during render
84 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>vec3</tt>
85 /// @param value
86 void set_uniform_vec3(const std::string& uniform_name, Vector3f value);
87
88 /// @brief register a Vector4f that will be handed to a shader uniform of the given name during render
89 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>vec4</tt>
90 /// @param value
91 void set_uniform_vec4(const std::string& uniform_name, Vector4f value);
92
93 /// @brief register a transform that will be handed to a shader uniform of the given name during render
94 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>mat4x4</tt>
95 /// @param value
96 void set_uniform_transform(const std::string& uniform_name, GLTransform value);
97
98 /// @brief register a color as RGBA that will be handed to a shader uniform of the given name during render
99 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>vec4</tt>
100 /// @param value
101 void set_uniform_rgba(const std::string& uniform_name, RGBA value);
102
103 /// @brief register a color as HSVA that will be handed to a shader uniform of the given name during render
104 /// @param uniform_name name of the uniform variable in the glsl shader code, has to be of type <tt>vec4</tt>
105 /// @param value
106 void set_uniform_hsva(const std::string& uniform_name, HSVA value);
107
108 /// @brief access currently registered float
109 /// @param uniform_name
110 /// @return float
111 float get_uniform_float(const std::string& uniform_name) const;
112
113 /// @brief access currently registered int
114 /// @param uniform_name
115 /// @return int32_t
116 int32_t get_uniform_int(const std::string& uniform_name) const;
117
118 /// @brief access currently registered uint
119 /// @param uniform_name
120 /// @return uint32_t
121 uint32_t get_uniform_uint(const std::string& uniform_name) const;
122
123 /// @brief access currently registered vec2
124 /// @param uniform_name
125 /// @return Vector2f
126 Vector2f get_uniform_vec2(const std::string& uniform_name) const;
127
128 /// @brief access currently registered vec3
129 /// @param uniform_name
130 /// @return Vector3f
131 Vector3f get_uniform_vec3(const std::string& uniform_name) const;
132
133 /// @brief access currently registered vec4
134 /// @param uniform_name
135 /// @return Vector4f
136 Vector4f get_uniform_vec4(const std::string& uniform_name) const;
137
138 /// @brief access currently registered transform (mat4x4)
139 /// @param uniform_name
140 /// @return GLTransform
141 GLTransform get_uniform_transform(const std::string& uniform_name) const;
142
143 /// @brief access currently registered color (vec4)
144 /// @param uniform_name
145 /// @return RGBA
146 RGBA get_uniform_rgba(const std::string& uniform_name) const;
147
148 /// @brief access currently registered color (vec4)
149 /// @param uniform_name
150 /// @return HSVA
151 HSVA get_uniform_hsva(const std::string& uniform_name) const;
152
153 /// @brief perform the render step to the currently bound framebuffer
154 void render() const;
155
156 /// @brief expose as GObject \for_internal_use_only
157 operator GObject*() const override;
158
159 private:
160 detail::RenderTaskInternal* _internal;
161 };
162}
163
164#endif // MOUSETRAP_ENABLE_OPENGL_COMPONENT
transform, operates in OpenGL coordinate system
Definition: gl_transform.hpp:18
bundles a shape in a render task that can be invoked more conveniently during the render cycle
Definition: render_task.hpp:47
int32_t get_uniform_int(const std::string &uniform_name) const
access currently registered int
Definition: render_task.cpp:232
GLTransform get_uniform_transform(const std::string &uniform_name) const
access currently registered transform (mat4x4)
Definition: render_task.cpp:332
void set_uniform_float(const std::string &uniform_name, float value)
register a float that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:146
void set_uniform_hsva(const std::string &uniform_name, HSVA value)
register a color as HSVA that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:210
float get_uniform_float(const std::string &uniform_name) const
access currently registered float
Definition: render_task.cpp:218
void set_uniform_vec4(const std::string &uniform_name, Vector4f value)
register a Vector4f that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:186
Vector3f get_uniform_vec3(const std::string &uniform_name) const
access currently registered vec3
Definition: render_task.cpp:274
HSVA get_uniform_hsva(const std::string &uniform_name) const
access currently registered color (vec4)
Definition: render_task.cpp:317
void render() const
perform the render step to the currently bound framebuffer
Definition: render_task.cpp:107
void set_uniform_rgba(const std::string &uniform_name, RGBA value)
register a color as RGBA that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:202
RGBA get_uniform_rgba(const std::string &uniform_name) const
access currently registered color (vec4)
Definition: render_task.cpp:302
void set_uniform_uint(const std::string &uniform_name, glm::uint value)
register an unsigned integer that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:162
Vector4f get_uniform_vec4(const std::string &uniform_name) const
access currently registered vec4
Definition: render_task.cpp:288
void set_uniform_vec3(const std::string &uniform_name, Vector3f value)
register a Vector3f that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:178
void set_uniform_int(const std::string &uniform_name, int value)
register an int that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:154
~RenderTask()
destructor
Definition: render_task.cpp:99
void set_uniform_vec2(const std::string &uniform_name, Vector2f value)
register a Vector2f that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:170
Vector2f get_uniform_vec2(const std::string &uniform_name) const
access currently registered vec2
Definition: render_task.cpp:260
void set_uniform_transform(const std::string &uniform_name, GLTransform value)
register a transform that will be handed to a shader uniform of the given name during render
Definition: render_task.cpp:194
uint32_t get_uniform_uint(const std::string &uniform_name) const
access currently registered uint
Definition: render_task.cpp:246
shader, holds the OpenGL shader program, a vertex and a fragment shader
Definition: shader.hpp:50
opengl shape primitive, variable number of vertices
Definition: shape.hpp:103
object that can emit GLib signals \for_internal_use_only
Definition: signal_emitter.hpp:48
color representation in HSVA
Definition: color.hpp:76
color representation in RGBA
Definition: color.hpp:24