Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
CustomGeometry.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
13#pragma once
14
15#include "../../core/Types.hpp"
16#include "../rhi/Buffer.hpp"
17
18#include <vector>
19
20namespace esengine {
21
22class GfxDevice;
23
31public:
32 CustomGeometry() = default;
33 ~CustomGeometry() = default;
34
39
47 void init(GfxDevice& device, const f32* vertices, u32 vertexCount, const VertexLayout& layout, bool dynamic = false);
48
54 void setIndices(const u16* indices, u32 indexCount);
55
61 void setIndices(const u32* indices, u32 indexCount);
62
69 void updateVertices(const f32* vertices, u32 vertexCount, u32 offset = 0);
70
74 void bind(GfxDevice& device) const;
75
79 VertexLayoutHandle layoutHandle() const { return layout_; }
80
84 const IndexBuffer* indexBuffer() const { return ibo_.get(); }
85
89 u32 getIndexCount() const;
90
94 u32 getVertexCount() const { return vertexCount_; }
95
97 u32 getVertexStride() const { return stride_; }
98
102 bool hasIndices() const;
103
107 bool isDynamic() const { return dynamic_; }
108
112 bool isValid() const { return layout_ != VertexLayoutHandle::Invalid; }
113
114private:
115 GfxDevice* device_ = nullptr;
119 u32 vertexCount_ = 0;
120 u32 stride_ = 0;
121 bool dynamic_ = false;
122};
123
128public:
130 static constexpr GeometryHandle INVALID_HANDLE = 0;
131
132 GeometryManager() = default;
133 ~GeometryManager() = default;
134
140
145 const CustomGeometry* get(GeometryHandle handle) const;
146
150 void release(GeometryHandle handle);
151
155 bool isValid(GeometryHandle handle) const;
156
157private:
158 std::vector<Unique<CustomGeometry>> geometries_;
159 std::vector<GeometryHandle> freeList_;
160 GeometryHandle nextHandle_ = 1;
161};
162
163} // namespace esengine
GPU buffer abstractions for vertex and index data.
Core type definitions and utilities for ESEngine.
Custom geometry for user-defined mesh rendering.
CustomGeometry(CustomGeometry &&)=default
CustomGeometry & operator=(const CustomGeometry &)=delete
bool isDynamic() const
Checks if geometry is dynamic.
u32 getVertexStride() const
Byte stride of one vertex (0 before init) — boundary-validation source.
void setIndices(const u16 *indices, u32 indexCount)
Sets indices for indexed rendering.
const IndexBuffer * indexBuffer() const
Gets the index buffer (null when non-indexed).
bool hasIndices() const
Checks if geometry uses indices.
void updateVertices(const f32 *vertices, u32 vertexCount, u32 offset=0)
Updates vertex data (only for dynamic geometry).
void init(GfxDevice &device, const f32 *vertices, u32 vertexCount, const VertexLayout &layout, bool dynamic=false)
Initializes geometry with vertex data and layout.
u32 getVertexCount() const
Gets the vertex count.
void bind(GfxDevice &device) const
Binds the geometry's buffers for the next draw.
u32 getIndexCount() const
Gets the index count.
bool isValid() const
Checks if geometry is initialized.
VertexLayoutHandle layoutHandle() const
The device vertex layout a pipeline drawing this geometry must reference.
CustomGeometry & operator=(CustomGeometry &&)=default
CustomGeometry(const CustomGeometry &)=delete
static constexpr GeometryHandle INVALID_HANDLE
bool isValid(GeometryHandle handle) const
Checks if handle is valid.
GeometryHandle create()
Creates a new geometry.
CustomGeometry * get(GeometryHandle handle)
Gets a geometry by handle.
void release(GeometryHandle handle)
Releases a geometry.
Abstract graphics device interface.
Definition GfxDevice.hpp:75
GPU buffer for index data.
Definition Buffer.hpp:337
Describes the layout of vertex data in a buffer.
Definition Buffer.hpp:126
std::shared_ptr< T > Shared
Shared ownership smart pointer.
Definition Types.hpp:82
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
std::uint16_t u16
Unsigned 16-bit integer.
Definition Types.hpp:43
float f32
32-bit floating point
Definition Types.hpp:59