guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
arc_render.cpp
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#include "guillaume/systems/arc_render.hpp"
24
25#include <memory>
26#include <vector>
27
28#include "guillaume/mesh_renderable.hpp"
30
31namespace guillaume::systems
32{
33 ArcRender::ArcRender(utility::Engine &engine)
34 : ecs::SystemFiller<components::Transform, components::Bound,
35 components::Color, components::Arc>(
36 ecs::Phase::Render)
37 , _engine(engine)
38 {
39 }
40
42 {
44 }
45
47 {
48 removeUnused(_engine);
49 }
50
51 void ArcRender::update(const ecs::Entity::Identifier &entityIdentifier)
52 {
53 if (!requireComponent<components::Bound>(entityIdentifier)
54 || !requireComponent<components::Transform>(entityIdentifier)
55 || !requireComponent<components::Color>(entityIdentifier)
56 || !requireComponent<components::Arc>(entityIdentifier)) {
57 return;
58 }
59
60 const auto &pose =
61 getComponent<components::Transform>(entityIdentifier).getPose();
62 const auto &bound = getComponent<components::Bound>(entityIdentifier);
63 const auto &color =
64 getComponent<components::Color>(entityIdentifier).getColor();
65 const auto &arc = getComponent<components::Arc>(entityIdentifier);
66
67 const utility::graphic::PositionF center(
68 pose.getPosition().x + bound.getWidth() / 2.0f,
69 pose.getPosition().y - bound.getHeight() / 2.0f,
70 pose.getPosition().z);
71
72 utility::graphic::Mesh mesh(std::vector<utility::graphic::VertexF> {},
73 std::vector<uint32_t> {});
74
76 mesh, center, pose.getOrientation(), bound.getWidth() / 2.0f,
77 bound.getHeight() / 2.0f, arc.getThickness(), arc.getStartAngle(),
78 arc.getSweepAngle(), arc.getSegments(), false, color);
79
80 // A transparent shape adds no geometry: submit nothing, so the
81 // object is removed at the end of the frame.
82 if (mesh.getVertices().empty()) {
83 return;
84 }
85
86 auto renderable = std::make_shared<MeshRenderable>(
87 std::vector<utility::graphic::Mesh> { mesh }, "mesh_material");
88
89 RenderHandle *handle = find(entityIdentifier);
90 if (handle == nullptr) {
91 insert(entityIdentifier,
92 RenderHandle { _engine.createObject(renderable), renderable,
93 true });
94 } else {
95 if (!_engine.updateObject(renderable, handle->objectId)) {
96 handle->objectId = _engine.createObject(renderable);
97 }
98 handle->renderable = renderable;
99 handle->used = true;
100 }
101 }
102
103} // namespace guillaume::systems
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
void cleanup(void) override
Remove the engine objects of the entities that were not drawn this frame. Called once per frame after...
ArcRender(utility::Engine &engine)
Create the system in the Render phase.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Rebuild the mesh of one arc and upload it, creating the engine object on the first frame.
void prepare(void) override
Mark every engine object as not drawn yet. Called once per frame before the entities are visited.
void insert(const ecs::Entity::Identifier &identifier, RenderHandle handle)
Store the handle of an entity, replacing the one it had.
void markAllUnused(void)
Clear the used flag of every handle. Call it from the system's prepare(), before any entity is drawn.
void removeUnused(utility::Engine &engine)
Remove from the engine, then from the map, every handle whose used flag is still false....
RenderHandle * find(const ecs::Entity::Identifier &identifier)
Look up the handle of an entity.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Definition component.hpp:28
Rules. Every class here runs each frame on the entities that have the components it declares.
Mesh builders shared by the shape render systems.
void buildRingMesh(utility::graphic::Mesh &mesh, const utility::graphic::PositionF &center, const utility::graphic::OrientationF &orientation, float outerHalfWidth, float outerHalfHeight, float thickness, float startAngle, float sweepAngle, int segments, bool closed, const utility::graphic::Color32Bit &color)
Build a ring, or a part of one, as a strip of triangles.
What a render system remembers about the engine object it created for one entity.