utility 2026.2.0
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
engine.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <functional>
26#include <memory>
27#include <optional>
28#include <string>
29#include <type_traits>
30
33
34#include <utility/graphic/view.hpp>
35#include <utility/graphic/mesh.hpp>
36#include <utility/graphic/model.hpp>
37#include <utility/graphic/scissor.hpp>
38#include <utility/graphic/size.hpp>
40
41#include <utility/math/vector.hpp>
42
43#include <utility/event/event.hpp>
44
45namespace utility
46{
47
59 class Engine:
60 protected utility::logging::Loggable<Engine,
61 utility::logging::DefaultLogger>
62 {
63 public:
68
74 using Handler =
75 std::function<void(std::shared_ptr<utility::event::Event> &)>;
76
77 private:
78 Handler _callback;
79 bool _shouldCaptureViewportInput {
80 true
81 };
82 std::optional<utility::graphic::ScissorRect> _scissor {
83 std::nullopt
84 };
85
86 protected:
92
93 public:
99
107
108 public:
112 Engine(void);
113
117 virtual ~Engine(void) = default;
118
119 public:
123 virtual void clear(void) = 0;
124
128 virtual void present(void) = 0;
129
138 measureText(const utility::graphic::Text &text) const = 0;
139
146 virtual size_t createObject(
147 std::shared_ptr<utility::graphic::Renderable> object) = 0;
148
156 virtual bool
157 updateObject(std::shared_ptr<utility::graphic::Renderable> object,
158 size_t objectID) = 0;
159
167 virtual bool
168 removeObject(std::shared_ptr<utility::graphic::Renderable> object,
169 size_t objectID) = 0;
170
175 virtual utility::graphic::ViewF getView(void) const = 0;
176
187 virtual float getDeltaTime(void) const;
188
199 virtual void setScissor(const utility::graphic::ScissorRect &rect);
200
204 virtual void clearScissor(void);
205
210 std::optional<utility::graphic::ScissorRect> getScissor(void) const;
211
220 void setEventCallback(const Handler &callback);
221
229 virtual void pollEvents(void) = 0;
230
239 virtual void update(void) = 0;
240 };
241
246 template<typename Type>
247 concept InheritFromEngine = std::is_base_of_v<Engine, Type>;
248
249} // namespace utility
Engine interface combining rendering and event handling.
Definition engine.hpp:62
Engine(void)
Default constructor.
virtual void clear(void)=0
Clear the current rendering target with the drawing color.
virtual ~Engine(void)=default
Default destructor.
bool shouldCaptureViewportInput(void) const
Check if viewport input capture is enabled.
virtual utility::graphic::SizeF measureText(const utility::graphic::Text &text) const =0
Measures the pixel dimensions of a given text string when rendered with a specific font.
virtual void update(void)=0
Update the engine state.
void setEventCallback(const Handler &callback)
Set the event callback function.
Handler & getEventCallback(void)
Get the current event callback function.
void setShouldCaptureViewportInput(bool capture)
Set the viewport input capture state.
std::function< void(std::shared_ptr< utility::event::Event > &)> Handler
Type alias for an event handler callback function.
Definition engine.hpp:75
virtual float getDeltaTime(void) const
Get the time elapsed since the previous frame.
std::optional< utility::graphic::ScissorRect > getScissor(void) const
Get the active scissor (clip) rectangle.
virtual void setScissor(const utility::graphic::ScissorRect &rect)
Set the active scissor (clip) rectangle.
virtual void present(void)=0
Present the composed back buffer to the screen.
virtual size_t createObject(std::shared_ptr< utility::graphic::Renderable > object)=0
Create a new render object.
virtual utility::graphic::ViewF getView(void) const =0
Get the full view model.
virtual void clearScissor(void)
Clear the active scissor (clip) rectangle.
virtual bool removeObject(std::shared_ptr< utility::graphic::Renderable > object, size_t objectID)=0
Remove a previously added render object.
virtual bool updateObject(std::shared_ptr< utility::graphic::Renderable > object, size_t objectID)=0
Update a previously added render object.
virtual void pollEvents(void)=0
Poll for events and dispatch them.
Storage for text content and rendering properties.
Definition text.hpp:75
3D perspective view with floating-point components.
Definition view.hpp:55
Mixin base class providing logging capabilities to derived classes.
Definition loggable.hpp:55
3D vector class inheriting from glm::vec3.
Definition vector.hpp:83
Concept to ensure a type inherits from Engine.
Definition engine.hpp:247
Platform-specific default logger alias.
Mixin class to provide logging capabilities to derived classes.
The utility namespace contains classes and functions for the utility project.
Definition cache.hpp:34
Axis-aligned scissor (clip) rectangle.
Definition scissor.hpp:35
Text rendering properties and storage.