49 ES_LOG_ERROR(
"CustomGeometry::init: unusable vertex layout (stride {}, {} attributes); skipping setup",
53 vertexCount_ = vertexCount *
sizeof(
f32) / stride_;
57 vertexCount *
sizeof(
f32)));
58 vbo_->setDataRaw(vertices, vertexCount *
sizeof(
f32));
61 vertexCount *
sizeof(
f32)));
63 vbo_->setLayout(layout);
67 for (
const auto& attr : layout) {
71 out.
type = toGfxDataType(attr.type);
81 if (!
isValid() || !device_)
return;
86 if (!
isValid() || !device_)
return;
91 if (!dynamic_ || !vbo_) {
96 vbo_->setSubDataRaw(vertices, vertexCount *
sizeof(
f32), offset *
sizeof(
f32));
98 u32 endOffset = offset + vertexCount;
99 u32 newVertexCount = endOffset *
sizeof(
f32) / stride_;
100 if (newVertexCount > vertexCount_) {
101 vertexCount_ = newVertexCount;
113 return ibo_->getCount();
119 return ibo_ !=
nullptr && ibo_->getCount() > 0;
129 if (!freeList_.empty()) {
130 handle = freeList_.back();
131 freeList_.pop_back();
134 handle = nextHandle_++;
145 return geometries_[handle - 1].get();
152 return geometries_[handle - 1].get();
159 geometries_[handle - 1].reset();
160 freeList_.push_back(handle);
167 return geometries_[handle - 1] !=
nullptr;
Custom geometry for user-defined mesh rendering.
Abstract graphics device interface.
Logging utilities for ESEngine.
#define ES_LOG_WARN(...)
Logs a warning message.
#define ES_LOG_ERROR(...)
Logs an error message.
Custom geometry for user-defined mesh rendering.
void setIndices(const u16 *indices, u32 indexCount)
Sets indices for indexed rendering.
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.
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.
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.
static constexpr GfxContent retained()
Abstract graphics device interface.
virtual void setVertexBuffer(u32 slot, BufferHandle buffer, u32 offsetBytes)=0
Binds a vertex buffer to a layout slot for subsequent draws.
virtual void setIndexBuffer(BufferHandle buffer)=0
Binds the index buffer for subsequent indexed draws.
VertexLayoutHandle createVertexLayout(const VertexLayoutDesc &desc)
Registers an immutable vertex layout; pipelines reference it by handle.
static Unique< IndexBuffer > create(GfxDevice &device, GfxContent content, std::span< const u32 > indices)
Creates an index buffer from a span of 32-bit indices.
static Unique< VertexBuffer > createRaw(GfxDevice &device, GfxContent content, const void *data, u32 sizeBytes)
Creates a buffer from raw data pointer for internal use.
static Unique< VertexBuffer > create(GfxDevice &device, GfxContent content, std::span< const T > data)
Creates a static buffer from a span.
Describes the layout of vertex data in a buffer.
u32 getStride() const
Gets the stride (total size) of one vertex.
const std::vector< VertexAttribute > & getAttributes() const
Gets all vertex attributes.
constexpr Unique< T > makeUnique(Args &&... args)
Creates a Unique pointer with the given arguments.
ShaderDataType
Vertex attribute data types.
@ UByte4N
4 unsigned bytes, normalized to [0,1] vec4
@ Int
Single 32-bit integer.
std::shared_ptr< T > Shared
Shared ownership smart pointer.
static constexpr u32 MAX_VERTEX_ATTRIBUTES
std::uint32_t u32
Unsigned 32-bit integer.
u32 shaderDataTypeComponentCount(ShaderDataType type)
Gets the component count of a shader data type.
std::uint8_t u8
Unsigned 8-bit integer.
std::uint16_t u16
Unsigned 16-bit integer.
float f32
32-bit floating point
u32 offset
Byte offset within one element of its buffer slot.
Describes how vertex-buffer bytes map to shader attributes.
GfxVertexAttribute attributes[MAX_VERTEX_ATTRIBUTES]
u32 strides[MAX_VERTEX_BUFFER_SLOTS]