SleakEngine 0.1.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
MeshComponent.hpp
Go to the documentation of this file.
1#ifndef _MESHCOMPONENT_H_
2#define _MESHCOMPONENT_H_
3
4#include <ECS/Component.hpp>
6#include <Math/AABB.hpp>
8#include <Memory/RefPtr.hpp>
9
10namespace Sleak {
11 class MeshData;
12 namespace RenderEngine {
13 class TransformBuffer;
14 class BufferBase;
15 } // namespace RenderEngine
16
17 /// Untyped payload blob, currently unused by any buffer path.
18 struct VoidData {
19 uint16_t size;
20 void* data;
21 };
22
23 /// Holds the GPU vertex/index/constant buffers for a renderable mesh and
24 /// submits a draw call each Update, subject to frustum culling.
25 /// @ingroup scene
26 class ENGINE_API MeshComponent : public Component {
27 public:
28 MeshComponent(GameObject* object) : Component(object) {}
29 /// Uploads data's vertex/index arrays to new GPU buffers.
31
32 /// Validates that vertex and index buffers were created successfully.
33 virtual bool Initialize() override;
34
35 /// Culls, then submits sibling transform and material state and the
36 /// draw.
37 virtual void Update(float deltaTime) override;
38
39 void SetVertexBuffer(RefPtr<RenderEngine::BufferBase>& buffer);
40
41 void SetIndexBuffer(RefPtr<RenderEngine::BufferBase>& buffer);
42
43 /// Creates a new constant buffer from bufferData and appends it to the draw's buffer list.
44 void AddConstantBuffer(RenderEngine::TransformBuffer& bufferData);
45
46 void AddConstantBuffer(RefPtr<RenderEngine::BufferBase>& buffer);
47
48 // World-space bounds used for CPU frustum culling of this mesh.
49 void SetCullBoundsWorld(const Math::AABB& bounds);
50 // Local-space bounds, transformed by the owner each Update.
51 void SetCullBoundsLocal(const Math::AABB& bounds);
52
53 private:
55 RefPtr<RenderEngine::BufferBase> IndexBuffer{};
56 List<RefPtr<RenderEngine::BufferBase>> ConstantBuffers{};
57
58 uint32_t VertexCount;
59 uint32_t IndexCount;
60
61 Math::AABB m_cullBounds{};
62 bool m_hasCullBounds = false;
63 Math::AABB m_localBounds{};
64 bool m_hasLocalBounds = false;
65
66 };
67}
68
69#endif
friend class GameObject
Definition Component.hpp:88
Component(GameObject *object)
Definition Component.hpp:61
MeshComponent(GameObject *object)
Backend-agnostic GPU buffer: vertex, index, constant, or resource view target.
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10
Per-draw world-view-projection and world matrices.
Untyped payload blob, currently unused by any buffer path.