Extra2D/include/renderer/mesh.h

114 lines
2.8 KiB
C
Raw Normal View History

#pragma once
#include <renderer/rhi/rhi.h>
#include <types/math/color.h>
#include <types/math/rect.h>
#include <types/math/vec2.h>
#include <types/ptr/intrusive_ptr.h>
#include <types/ptr/ref_counted.h>
namespace extra2d {
/**
* @brief
*/
struct Vertex {
Vec2 position; // 位置
Vec2 texCoord; // 纹理坐标
Color color; // 颜色
Vertex() = default;
Vertex(const Vec2& pos, const Vec2& uv, const Color& col)
: position(pos), texCoord(uv), color(col) {}
};
/**
* @brief
*
* RHI
*
*/
class Mesh : public RefCounted {
public:
/**
* @brief
*/
Mesh();
/**
* @brief
*/
~Mesh() override;
/**
* @brief
* @param vertices
* @param count
*/
void setVertices(const Vertex* vertices, uint32_t count);
/**
* @brief
* @param indices
* @param count
*/
void setIndices(const uint16_t* indices, uint32_t count);
/**
* @brief
* @param vertices
* @param count
* @param offset
*/
void updateVertices(const Vertex* vertices, uint32_t count, uint32_t offset);
/**
* @brief
* @return
*/
uint32_t getVertexCount() const { return vertexCount_; }
/**
* @brief
* @return
*/
uint32_t getIndexCount() const { return indexCount_; }
/**
* @brief
* @return
*/
BufferHandle getVertexBuffer() const { return vertexBuffer_; }
/**
* @brief
* @return
*/
BufferHandle getIndexBuffer() const { return indexBuffer_; }
/**
* @brief
* @return
*/
bool hasIndices() const { return indexCount_ > 0; }
/**
* @brief
* @param size
* @param uv
* @return
*/
static Ptr<Mesh> createQuad(const Vec2& size,
const Rect& uv = Rect(0, 0, 1, 1));
private:
BufferHandle vertexBuffer_; // 顶点缓冲区句柄
BufferHandle indexBuffer_; // 索引缓冲区句柄
uint32_t vertexCount_ = 0; // 顶点数量
uint32_t indexCount_ = 0; // 索引数量
uint32_t vertexCapacity_ = 0; // 顶点缓冲区容量
uint32_t indexCapacity_ = 0; // 索引缓冲区容量
};
} // namespace extra2d