9#include <spdlog/spdlog.h>
15 int VertexBuffer::_nextId = 0;
21 assert(graphicsDevice !=
nullptr &&
"GraphicsDevice cannot be null");
22 assert(
format !=
nullptr &&
"VertexFormat cannot be null");
23 assert(
numVertices > 0 &&
"Number of vertices must be greater than 0");
29 adjustVramSizeTracking(
_device->_vram, _numBytes);
32 if (!options.
data.empty()) {
33 if (options.
data.size() !=
static_cast<size_t>(_numBytes)) {
34 spdlog::error(
"VertexBuffer: wrong initial data size: expected {}, got {}", _numBytes, options.
data.size());
49 adjustVramSizeTracking(
_device->_vram, _numBytes);
54 const auto it = std::find(
_device->_buffers.begin(),
_device->_buffers.end(),
this);
55 if (it !=
_device->_buffers.end())
61 adjustVramSizeTracking(
_device->_vram, -_numBytes);
64 void VertexBuffer::adjustVramSizeTracking(
DeviceVRAM& vram,
int size) {
65 spdlog::trace(
"${this.id} size: ${size} vram.vb: ${vram.vb} => ${vram.vb + size}");
71 if (data.size() != _numBytes) {
72 spdlog::error(
"VertexBuffer: wrong initial data size: expected " +
73 std::to_string(_numBytes) +
", got " + std::to_string(data.size()));
Abstract GPU interface for resource creation, state management, and draw submission.
bool setData(const std::vector< uint8_t > &data)
std::shared_ptr< VertexFormat > format() const
std::vector< uint8_t > _storage
VertexBuffer(GraphicsDevice *graphicsDevice, std::shared_ptr< VertexFormat > format, int numVertices, const VertexBufferOptions &options=VertexBufferOptions{})
std::vector< uint8_t > data