FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objShape.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_OBJSHAPE_HPP_INCLUDED
18#define _FGE_C_OBJSHAPE_HPP_INCLUDED
19
20/*
21 * Original from : https://github.com/SFML/SFML
22 * Copyright (C) 2007-2022 Laurent Gomila
23 *
24 * Altered/Modified by Guillaume Guillet
25 */
26
27#include "FastEngine/fge_extern.hpp"
28#include "C_object.hpp"
29#include "FastEngine/accessor/C_texture.hpp"
30
31#define FGE_OBJSHAPE_INSTANCES_SHADER_VERTEX "FGE:OBJ:SHAPE:VERTEX"
32#define FGE_OBJSHAPE_INDEX_FILLCOLOR 0
33#define FGE_OBJSHAPE_INDEX_OUTLINECOLOR 1
34
35namespace fge
36{
37
38class FGE_API ObjShape : public fge::Object
39{
40protected:
41 ObjShape();
42 ObjShape(ObjShape const& r);
43
44public:
46 {
47 alignas(16) glm::uvec4 _color[2];
48 alignas(16) glm::vec2 _offset;
49 };
50
51 ~ObjShape() override = default;
52
53 void setTexture(Texture const& texture, bool resetRect = false);
54 void setTextureRect(fge::RectInt const& rect);
55
56 void setFillColor(Color color, std::size_t instance = 0);
57 void setOutlineColor(Color color, std::size_t instance = 0);
58 void setOffset(fge::Vector2f const& offset, std::size_t instance = 0);
59 void setInstancesCount(std::size_t count);
60 void addInstance(Color fillColor, Color outlineColor, fge::Vector2f const& offset);
61 [[nodiscard]] std::size_t getInstancesCount() const;
62 void clearInstances();
63
64 void setOutlineThickness(float thickness);
65
66 [[nodiscard]] Texture const& getTexture() const;
67
68 [[nodiscard]] RectInt const& getTextureRect() const;
69
70 [[nodiscard]] Color getFillColor(std::size_t instance = 0) const;
71 [[nodiscard]] Color getOutlineColor(std::size_t instance = 0) const;
72 [[nodiscard]] fge::Vector2f const& getOffset(std::size_t instance = 0) const;
73
74 [[nodiscard]] float getOutlineThickness() const;
75
76 [[nodiscard]] virtual std::size_t getPointCount() const = 0;
77 [[nodiscard]] virtual Vector2f getPoint(std::size_t index) const = 0;
78
79 void first(fge::Scene& scene) override;
80
81 FGE_OBJ_DRAW_DECLARE
82
83 [[nodiscard]] fge::RectFloat getLocalBounds() const override;
84 [[nodiscard]] fge::RectFloat getGlobalBounds() const override;
85
86protected:
87 void updateShape();
88
89private:
90 void updateTexCoords();
91 void updateOutline();
92 void resizeBuffer(std::size_t size) const;
93 void updateDescriptors() const;
94
95 inline InstanceData* retrieveInstance(std::size_t index) const;
96
97 fge::Texture g_texture;
98 fge::RectInt g_textureRect;
99
100 float g_outlineThickness;
101
102 fge::vulkan::VertexBuffer g_vertices;
103 fge::vulkan::VertexBuffer g_outlineVertices;
104
105 mutable std::size_t g_instancesCount;
106 mutable fge::vulkan::UniformBuffer g_instances;
107 mutable fge::vulkan::DescriptorSet g_descriptorSet;
108
109 fge::RectFloat g_insideBounds;
110 fge::RectFloat g_bounds;
111};
112
113} // namespace fge
114
115
116#endif // _FGE_C_OBJSHAPE_HPP_INCLUDED
Definition C_color.hpp:35
Definition C_objShape.hpp:39
fge::RectFloat getLocalBounds() const override
Get the local bounds of the object (without any transformations)
void first(fge::Scene &scene) override
Method called when the object is added to a scene for initialization purposes.
fge::RectFloat getGlobalBounds() const override
Get the global bounds of the object.
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450
This class is a wrapper for the texture manager to allow easy manipulation.
Definition C_texture.hpp:36
This class abstract the vulkan descriptor set for easier use.
Definition C_descriptorSet.hpp:41
Definition C_uniformBuffer.hpp:32
Definition C_vertexBuffer.hpp:45
Definition C_objShape.hpp:46