SleakEngine 1.0.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 against cull bounds if set, then submits an indexed draw call.
36 virtual void Update(float deltaTime) override;
37
38 void SetVertexBuffer(RefPtr<RenderEngine::BufferBase>& buffer);
39
40 void SetIndexBuffer(RefPtr<RenderEngine::BufferBase>& buffer);
41
42 /// Creates a new constant buffer from bufferData and appends it to the draw's buffer list.
43 void AddConstantBuffer(RenderEngine::TransformBuffer& bufferData);
44
45 void AddConstantBuffer(RefPtr<RenderEngine::BufferBase>& buffer);
46
47 // World-space bounds used for CPU frustum culling of this mesh.
48 void SetCullBoundsWorld(const Math::AABB& bounds);
49 // Local-space bounds, transformed by the owner each Update.
50 void SetCullBoundsLocal(const Math::AABB& bounds);
51
52 private:
54 RefPtr<RenderEngine::BufferBase> IndexBuffer{};
55 List<RefPtr<RenderEngine::BufferBase>> ConstantBuffers{};
56
57 uint32_t VertexCount;
58 uint32_t IndexCount;
59
60 Math::AABB m_cullBounds{};
61 bool m_hasCullBounds = false;
62 Math::AABB m_localBounds{};
63 bool m_hasLocalBounds = false;
64
65 };
66}
67
68#endif
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.