UBO consolidation (#3089)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Alex Cristici
2025-01-08 17:41:29 +02:00
committed by GitHub
parent cf9f41cf61
commit f582327191
262 changed files with 6968 additions and 6928 deletions

View File

@@ -102,28 +102,55 @@ BufferID UniformBufferGL::getID() const {
}
}
void UniformBufferGL::update(const void* data_, std::size_t size_) {
assert(isManagedAllocation ? managedBuffer.getContents().size() == size_ : size == size_);
void UniformBufferGL::update(const void* data, std::size_t dataSize) {
assert(isManagedAllocation ? dataSize <= managedBuffer.getContents().size() : dataSize <= size);
if (size != size_ || (isManagedAllocation && managedBuffer.getContents().size() != size_)) {
Log::Error(
Event::General,
"Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_));
if (dataSize > size || (isManagedAllocation && dataSize > managedBuffer.getContents().size())) {
Log::Error(Event::General,
"Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " +
std::to_string(dataSize));
return;
}
if (std::memcmp(data_, managedBuffer.getContents().data(), managedBuffer.getContents().size()) == 0) {
if (std::memcmp(data, managedBuffer.getContents().data(), dataSize) == 0) {
return;
}
if (isManagedAllocation) {
managedBuffer.allocate(data_, size);
managedBuffer.allocate(data, dataSize);
} else {
MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, localID));
MBGL_CHECK_ERROR(glBufferSubData(GL_UNIFORM_BUFFER, 0, size_, data_));
MBGL_CHECK_ERROR(glBufferSubData(GL_UNIFORM_BUFFER, 0, dataSize, data));
MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, 0));
}
}
void UniformBufferArrayGL::bind() const {
MLN_TRACE_FUNC();
for (size_t id = 0; id < allocatedSize(); id++) {
const auto& uniformBuffer = get(id);
if (!uniformBuffer) continue;
GLint binding = static_cast<GLint>(id);
const auto& uniformBufferGL = static_cast<const UniformBufferGL&>(*uniformBuffer);
MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER,
binding,
uniformBufferGL.getID(),
uniformBufferGL.getManagedBuffer().getBindingOffset(),
uniformBufferGL.getSize()));
}
}
void UniformBufferArrayGL::unbind() const {
MLN_TRACE_FUNC();
for (size_t id = 0; id < allocatedSize(); id++) {
const auto& uniformBuffer = get(id);
if (!uniformBuffer) continue;
GLint binding = static_cast<GLint>(id);
MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0));
}
}
} // namespace gl
} // namespace mbgl