utility 2026.1.9
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 <string>
28#include <type_traits>
29
32
33#include <utility/graphic/view.hpp>
34#include <utility/graphic/mesh.hpp>
35#include <utility/graphic/model.hpp>
36#include <utility/graphic/size.hpp>
38
39#include <utility/math/vector.hpp>
40
41#include <utility/event/event.hpp>
42
43namespace utility
44{
45
57 class Engine:
58 protected utility::logging::Loggable<Engine,
59 utility::logging::DefaultLogger>
60 {
61 public:
66
72 using Handler =
73 std::function<void(std::shared_ptr<utility::event::Event> &)>;
74
75 private:
76 Handler _callback;
77 bool _shouldCaptureViewportInput {
78 true
79 };
80
81 protected:
87
88 public:
94
102
103 public:
107 Engine(void);
108
112 virtual ~Engine(void) = default;
113
114 public:
118 virtual void clear(void) = 0;
119
123 virtual void present(void) = 0;
124
133 virtual size_t addMesh(const utility::graphic::Mesh &mesh,
134 const std::string &materialName) = 0;
135
142 virtual bool removeObject(size_t objectID) = 0;
143
152 measureText(const utility::graphic::Text &text) const = 0;
153
159 virtual size_t addText(utility::graphic::Text text) = 0;
160
166 virtual size_t
167 addModel(std::shared_ptr<utility::graphic::Model> model) = 0;
168
173 virtual utility::graphic::ViewF getView(void) const = 0;
174
179 virtual void addScene(size_t sceneIndex) = 0;
180
189 void setEventCallback(const Handler &callback);
190
198 virtual void pollEvents(void) = 0;
199
208 virtual void update(void) = 0;
209 };
210
215 template<typename Type>
216 concept InheritFromEngine = std::is_base_of_v<Engine, Type>;
217
218} // namespace utility
Engine interface combining rendering and event handling.
Definition engine.hpp:60
Engine(void)
Default constructor.
virtual void clear(void)=0
Clear the current rendering target with the drawing color.
virtual size_t addText(utility::graphic::Text text)=0
Add a text element to the engine at a specified pose.
virtual size_t addMesh(const utility::graphic::Mesh &mesh, const std::string &materialName)=0
Add a mesh to the engine.
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:73
virtual size_t addModel(std::shared_ptr< utility::graphic::Model > model)=0
Add a model to the engine for rendering.
virtual void addScene(size_t sceneIndex)=0
Add a scene to the engine.
virtual void present(void)=0
Present the composed back buffer to the screen.
virtual bool removeObject(size_t objectID)=0
Remove a previously added render object.
virtual utility::graphic::ViewF getView(void) const =0
Get the full view model.
virtual void pollEvents(void)=0
Poll for events and dispatch them.
The Mesh class represents a 3D mesh used for rendering in a graphics application.
Definition mesh.hpp:25
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:216
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
Text rendering properties and storage.