Files
plotter/src/render/buffer.cpp
T

33 lines
1.0 KiB
C++

#include <plot/render/buffer.hpp>
namespace plot::render {
namespace detail {
bool InstanceStore::create(Status* st) noexcept {
// plot::gl::Buffer::create() already reports Unsupported while the entry
// points are unresolved and GLFailure when the driver hands out no name, so
// the wrapper only has to propagate its answer.
if (!buffer_.create(st)) {
return false;
}
capacity_ = 0;
return true;
}
void InstanceStore::upload(const void* data, u32 count, usize instance_bytes) noexcept {
if (buffer_.id() == 0 || count == 0 || instance_bytes == 0) {
return;
}
if (count > capacity_) {
// Only a workload larger than anything staged so far pays for an
// allocation; a frame that repeats the previous one writes into the store
// that is already there.
buffer_.upload(nullptr, static_cast<usize>(count) * instance_bytes, gl::GL_STREAM_DRAW);
capacity_ = count;
}
buffer_.upload_sub(data, static_cast<usize>(count) * instance_bytes, 0);
}
} // namespace detail
} // namespace plot::render