Update existing UBOs instead of replacing (#1198)

This commit is contained in:
mwilsnd
2023-06-02 14:51:07 -05:00
committed by Bart Louwers
parent 5dab47a5a2
commit 0f321fb11e
7 changed files with 70 additions and 16 deletions

View File

@@ -1,7 +1,9 @@
#include <mbgl/gl/uniform_buffer_gl.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/util/logging.hpp>
#include <cassert>
namespace mbgl {
namespace gl {
@@ -12,7 +14,7 @@ UniformBufferGL::UniformBufferGL(const void* data, std::size_t size_)
: UniformBuffer(size_) {
MBGL_CHECK_ERROR(glGenBuffers(1, &id));
MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, id));
MBGL_CHECK_ERROR(glBufferData(GL_UNIFORM_BUFFER, size, data, GL_STATIC_DRAW));
MBGL_CHECK_ERROR(glBufferData(GL_UNIFORM_BUFFER, size, data, GL_DYNAMIC_DRAW));
MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, 0));
}
@@ -23,5 +25,19 @@ UniformBufferGL::~UniformBufferGL() {
}
}
void UniformBufferGL::update(const void* data, std::size_t size_) {
assert(size == size_);
if (size != size_) {
Log::Error(
Event::General,
"Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_));
return;
}
MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, id));
MBGL_CHECK_ERROR(glBufferSubData(GL_UNIFORM_BUFFER, 0, size_, data));
MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, 0));
}
} // namespace gl
} // namespace mbgl