First cut at Drawable fundamentals (#983)

Co-authored-by: mwilsnd <mwilsnd@gmail.com>
Co-authored-by: Alex Cristici <alex.cristici@gmail.com>
This commit is contained in:
Tim Sylvester
2023-04-17 09:58:57 -07:00
committed by Bart Louwers
parent 42afe4189c
commit 14b53e54ec
60 changed files with 1904 additions and 87 deletions

View File

@@ -3,10 +3,13 @@
#include <mbgl/gl/enum.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/command_encoder.hpp>
#include <mbgl/gl/vertex_attribute_gl.hpp>
#include <mbgl/gl/vertex_buffer_resource.hpp>
#include <mbgl/gl/index_buffer_resource.hpp>
#include <mbgl/gl/texture_resource.hpp>
#include <algorithm>
namespace mbgl {
namespace gl {
@@ -119,6 +122,54 @@ void UploadPass::updateTextureResourceSub(gfx::TextureResource& resource,
data));
}
std::pair<gfx::AttributeBindingArray, std::unique_ptr<gfx::VertexBufferResource>>
UploadPass::buildAttributeBindings(const gfx::VertexAttributeArray& defaults,
const gfx::VertexAttributeArray& overrides,
const gfx::BufferUsageType usage) {
AttributeBindingArray bindings;
bindings.reserve(defaults.size());
std::vector<std::uint8_t> allData;
constexpr auto ExpectedSize = 32;
allData.reserve(defaults.size() * ExpectedSize);
defaults.resolve(overrides, [&](const std::string& /*name*/,
const gfx::VertexAttribute& defaultAttr,
const gfx::VertexAttribute* overrideAttr) {
const auto& effectiveAttr = *(overrideAttr ? overrideAttr : &defaultAttr);
const auto& effectiveGL = static_cast<const gl::VertexAttributeGL&>(effectiveAttr);
const auto& defaultGL = static_cast<const gl::VertexAttributeGL&>(defaultAttr);
// Pad to 16 bytes
allData.insert(allData.end(), 16 - allData.size() % 16, 0);
const auto offset = static_cast<uint8_t>(allData.size());
bindings.emplace_back(gfx::AttributeBinding{
gfx::AttributeDescriptor{ defaultAttr.getDataType(), offset },
static_cast<uint8_t>(effectiveGL.getStride()),
nullptr, // buffer pointer established later
static_cast<uint32_t>(defaultGL.getIndex())
});
const auto& rawData = effectiveGL.getRaw();
allData.insert(allData.begin(), rawData.begin(), rawData.end());
});
auto vertBuf = createVertexBufferResource(&allData[0], allData.size(), usage);
// Assign to each element
std::for_each(bindings.begin(), bindings.end(), [&](auto& b){ b->vertexBufferResource = vertBuf.get(); });
gfx::AttributeBindingArray& a = bindings;
std::unique_ptr<gfx::VertexBufferResource>& b = vertBuf;
return std::make_pair(std::move(a), std::move(b));
//return std::make_pair(bindings, vertBuf);
}
void UploadPass::pushDebugGroup(const char* name) {
commandEncoder.pushDebugGroup(name);
}