diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-03-15 02:15:41 +0000 |
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-03-15 02:15:41 +0000 |
| commit | 200b96d780598fe5ec59f2fc7e2e3eb6ac69d0de (patch) | |
| tree | e078fdf6027a9914ad96c66e8f3849958dbad862 /lib/glAllocator.cpp | |
| parent | Add missing algorithm include (diff) | |
| download | ilt-200b96d780598fe5ec59f2fc7e2e3eb6ac69d0de.tar.bz2 ilt-200b96d780598fe5ec59f2fc7e2e3eb6ac69d0de.tar.xz ilt-200b96d780598fe5ec59f2fc7e2e3eb6ac69d0de.zip | |
Remove the map of buffers, now a fat pointer containing the buffer's
name. This is accessible via the container's begin/end iterator. Move
the bulk of the logic out of the template, it's mostly void * from the
mapping anyway. Add allocate_at_least support.
Diffstat (limited to 'lib/glAllocator.cpp')
| -rw-r--r-- | lib/glAllocator.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/glAllocator.cpp b/lib/glAllocator.cpp new file mode 100644 index 0000000..633f7ab --- /dev/null +++ b/lib/glAllocator.cpp @@ -0,0 +1,28 @@ +#include "glAllocator.h" + +namespace Detail { + std::pair<void *, GLuint> + allocateBuffer(size_t count, size_t objSize) + { + constexpr static GLbitfield MAPPING_FLAGS + = GL_MAP_WRITE_BIT | GL_MAP_READ_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT; + constexpr static GLbitfield STORAGE_FLAGS = GL_DYNAMIC_STORAGE_BIT | MAPPING_FLAGS; + GLuint name = 0; + glCreateBuffers(1, &name); + const auto size = static_cast<GLsizeiptr>(count * objSize); + glNamedBufferStorage(name, size, nullptr, STORAGE_FLAGS); + const auto data = (glMapNamedBufferRange(name, 0, size, MAPPING_FLAGS)); + if (!data) { + glDeleteBuffers(1, &name); + throw std::bad_alloc(); + } + return {data, name}; + } + + void + deallocateBuffer(GLuint name) + { + glUnmapNamedBuffer(name); + glDeleteBuffers(1, &name); + } +} |
