[core] Per-segment-per-layer vertex arrays

Reduces rebinding, matches gl-js, and works around the buggy VAO implementation on PowerVR SGX544 GPUs.
This commit is contained in:
John Firebaugh
2017-07-06 08:06:12 -07:00
parent d7bdc7a60d
commit de91e68090
13 changed files with 59 additions and 26 deletions

View File

@@ -58,7 +58,8 @@ public:
const SegmentVector<Attributes>& segments,
const PaintPropertyBinders& paintPropertyBinders,
const typename PaintProperties::Evaluated& currentProperties,
float currentZoom) {
float currentZoom,
const std::string& layerID) {
typename AllUniforms::Values allUniformValues = uniformValues
.concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties));
@@ -66,8 +67,10 @@ public:
.concat(paintPropertyBinders.attributeBindings(currentProperties));
for (auto& segment : segments) {
if (!segment.vertexArray) {
segment.vertexArray = context.createVertexArray();
optional<gl::VertexArray>& vertexArray = segment.vertexArrays[layerID];
if (!vertexArray) {
vertexArray = context.createVertexArray();
}
program.draw(
@@ -77,7 +80,7 @@ public:
std::move(stencilMode),
std::move(colorMode),
allUniformValues,
*segment.vertexArray,
*vertexArray,
Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset),
indexBuffer,
segment.indexOffset,

View File

@@ -28,7 +28,14 @@ public:
std::size_t vertexLength;
std::size_t indexLength;
mutable optional<gl::VertexArray> vertexArray;
// One VertexArray per layer ID. This minimizes rebinding in cases where
// several layers share buckets but have different sets of active attributes.
// This can happen:
// * when two layers have the same layout properties, but differing
// data-driven paint properties
// * when two fill layers have the same layout properties, but one
// uses fill-color and the other uses fill-pattern
mutable std::map<std::string, optional<gl::VertexArray>> vertexArrays;
};
template <class Attributes>

View File

@@ -360,7 +360,8 @@ public:
const SegmentVector<Attributes>& segments,
const PaintPropertyBinders& paintPropertyBinders,
const typename PaintProperties::Evaluated& currentProperties,
float currentZoom) {
float currentZoom,
const std::string& layerID) {
typename AllUniforms::Values allUniformValues = uniformValues
.concat(symbolSizeBinder.uniformValues(currentZoom))
.concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties));
@@ -370,8 +371,10 @@ public:
.concat(paintPropertyBinders.attributeBindings(currentProperties));
for (auto& segment : segments) {
if (!segment.vertexArray) {
segment.vertexArray = context.createVertexArray();
optional<gl::VertexArray>& vertexArray = segment.vertexArrays[layerID];
if (!vertexArray) {
vertexArray = context.createVertexArray();
}
program.draw(
@@ -381,7 +384,7 @@ public:
std::move(stencilMode),
std::move(colorMode),
allUniformValues,
*segment.vertexArray,
*vertexArray,
Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset),
indexBuffer,
segment.indexOffset,