summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/gl/element_group.hpp25
-rw-r--r--src/mbgl/gl/vao.cpp5
-rw-r--r--src/mbgl/gl/vao.hpp6
-rw-r--r--src/mbgl/layout/symbol_layout.cpp39
-rw-r--r--src/mbgl/layout/symbol_layout.hpp2
-rw-r--r--src/mbgl/renderer/circle_bucket.cpp30
-rw-r--r--src/mbgl/renderer/circle_bucket.hpp7
-rw-r--r--src/mbgl/renderer/element_group.hpp28
-rw-r--r--src/mbgl/renderer/fill_bucket.cpp60
-rw-r--r--src/mbgl/renderer/fill_bucket.hpp8
-rw-r--r--src/mbgl/renderer/line_bucket.cpp71
-rw-r--r--src/mbgl/renderer/line_bucket.hpp5
-rw-r--r--src/mbgl/renderer/painter_circle.cpp2
-rw-r--r--src/mbgl/renderer/symbol_bucket.cpp32
-rw-r--r--src/mbgl/renderer/symbol_bucket.hpp12
15 files changed, 151 insertions, 181 deletions
diff --git a/src/mbgl/gl/element_group.hpp b/src/mbgl/gl/element_group.hpp
deleted file mode 100644
index f99a03b679..0000000000
--- a/src/mbgl/gl/element_group.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include <mbgl/gl/vao.hpp>
-#include <mbgl/util/noncopyable.hpp>
-
-#include <array>
-
-namespace mbgl {
-namespace gl {
-
-template <uint8_t count>
-struct ElementGroup : public util::noncopyable {
- std::array<VertexArrayObject, count> array;
- uint32_t vertex_length;
- uint32_t elements_length;
-
- ElementGroup(uint32_t vertex_length_ = 0, uint32_t elements_length_ = 0)
- : vertex_length(vertex_length_)
- , elements_length(elements_length_)
- {
- }
-};
-
-} // namespace gl
-} // namespace mbgl
diff --git a/src/mbgl/gl/vao.cpp b/src/mbgl/gl/vao.cpp
index 87c03ac23e..b235b0e63b 100644
--- a/src/mbgl/gl/vao.cpp
+++ b/src/mbgl/gl/vao.cpp
@@ -7,11 +7,6 @@
namespace mbgl {
namespace gl {
-VertexArrayObject::VertexArrayObject() {
-}
-
-VertexArrayObject::~VertexArrayObject() = default;
-
void VertexArrayObject::bindVertexArrayObject(Context& context) {
if (!GenVertexArrays || !BindVertexArray) {
static bool reported = false;
diff --git a/src/mbgl/gl/vao.hpp b/src/mbgl/gl/vao.hpp
index 6a5e7d0e60..826c028d32 100644
--- a/src/mbgl/gl/vao.hpp
+++ b/src/mbgl/gl/vao.hpp
@@ -3,7 +3,6 @@
#include <mbgl/gl/shader.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
-#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
#include <stdexcept>
@@ -11,11 +10,8 @@
namespace mbgl {
namespace gl {
-class VertexArrayObject : public util::noncopyable {
+class VertexArrayObject {
public:
- VertexArrayObject();
- ~VertexArrayObject();
-
template <typename Shader, typename T>
void bind(Shader& shader,
const VertexBuffer<T>& vertexBuffer,
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 1400125dd9..cc8db3ab98 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -391,7 +391,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
if (hasText) {
collisionTile.insertFeature(symbolInstance.textCollisionFeature, glyphScale, layout.textIgnorePlacement);
if (glyphScale < collisionTile.maxScale) {
- addSymbols<SymbolBucket::TextBuffer, SymbolBucket::TextElementGroup>(
+ addSymbols(
bucket->text, symbolInstance.glyphQuads, glyphScale,
layout.textKeepUpright, textPlacement, collisionTile.config.angle);
}
@@ -400,7 +400,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
if (hasIcon) {
collisionTile.insertFeature(symbolInstance.iconCollisionFeature, iconScale, layout.iconIgnorePlacement);
if (iconScale < collisionTile.maxScale) {
- addSymbols<SymbolBucket::IconBuffer, SymbolBucket::IconElementGroup>(
+ addSymbols(
bucket->icon, symbolInstance.iconQuads, iconScale,
layout.iconKeepUpright, iconPlacement, collisionTile.config.angle);
}
@@ -414,7 +414,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
return bucket;
}
-template <typename Buffer, typename GroupType>
+template <typename Buffer>
void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale, const bool keepUpright, const style::SymbolPlacementType placement, const float placementAngle) {
const float placementZoom = ::fmax(std::log(scale) / std::log(2) + zoom, 0);
@@ -449,16 +449,15 @@ void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
const int glyph_vertex_length = 4;
- if (buffer.groups.empty() || (buffer.groups.back()->vertex_length + glyph_vertex_length > 65535)) {
+ if (buffer.groups.empty() || buffer.groups.back().vertexLength + glyph_vertex_length > 65535) {
// Move to a new group because the old one can't hold the geometry.
- buffer.groups.emplace_back(std::make_unique<GroupType>());
+ buffer.groups.emplace_back();
}
// We're generating triangle fans, so we always start with the first
// coordinate in this polygon.
- assert(buffer.groups.back());
- auto &triangleGroup = *buffer.groups.back();
- size_t triangleIndex = triangleGroup.vertex_length;
+ auto& group = buffer.groups.back();
+ size_t index = group.vertexLength;
// Encode angle of glyph
uint8_t glyphAngle = std::round((symbol.glyphAngle / (M_PI * 2)) * 256);
@@ -474,15 +473,15 @@ void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
minZoom, maxZoom, placementZoom, glyphAngle);
// add the two triangles, referencing the four coordinates we just inserted.
- buffer.triangles.emplace_back(static_cast<uint16_t>(triangleIndex + 0),
- static_cast<uint16_t>(triangleIndex + 1),
- static_cast<uint16_t>(triangleIndex + 2));
- buffer.triangles.emplace_back(static_cast<uint16_t>(triangleIndex + 1),
- static_cast<uint16_t>(triangleIndex + 2),
- static_cast<uint16_t>(triangleIndex + 3));
-
- triangleGroup.vertex_length += glyph_vertex_length;
- triangleGroup.elements_length += 2;
+ buffer.triangles.emplace_back(static_cast<uint16_t>(index + 0),
+ static_cast<uint16_t>(index + 1),
+ static_cast<uint16_t>(index + 2));
+ buffer.triangles.emplace_back(static_cast<uint16_t>(index + 1),
+ static_cast<uint16_t>(index + 2),
+ static_cast<uint16_t>(index + 3));
+
+ group.vertexLength += glyph_vertex_length;
+ group.indexLength += 2;
}
}
@@ -518,7 +517,7 @@ void SymbolLayout::addToDebugBuffers(CollisionTile& collisionTile, SymbolBucket&
auto& collisionBox = bucket.collisionBox;
if (collisionBox.groups.empty()) {
// Move to a new group because the old one can't hold the geometry.
- collisionBox.groups.emplace_back(std::make_unique<SymbolBucket::CollisionBoxElementGroup>());
+ collisionBox.groups.emplace_back();
}
collisionBox.vertices.emplace_back(anchor.x, anchor.y, tl.x, tl.y, maxZoom, placementZoom);
@@ -530,8 +529,8 @@ void SymbolLayout::addToDebugBuffers(CollisionTile& collisionTile, SymbolBucket&
collisionBox.vertices.emplace_back(anchor.x, anchor.y, bl.x, bl.y, maxZoom, placementZoom);
collisionBox.vertices.emplace_back(anchor.x, anchor.y, tl.x, tl.y, maxZoom, placementZoom);
- auto &group= *collisionBox.groups.back();
- group.vertex_length += 8;
+ auto& group= collisionBox.groups.back();
+ group.vertexLength += 8;
}
}
}
diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp
index c4e6455794..54acf84aaf 100644
--- a/src/mbgl/layout/symbol_layout.hpp
+++ b/src/mbgl/layout/symbol_layout.hpp
@@ -70,7 +70,7 @@ private:
void addToDebugBuffers(CollisionTile&, SymbolBucket&);
// Adds placed items to the buffer.
- template <typename Buffer, typename GroupType>
+ template <typename Buffer>
void addSymbols(Buffer&, const SymbolQuads&, float scale,
const bool keepUpright, const style::SymbolPlacementType, const float placementAngle);
diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp
index 097410ce3b..f12139d004 100644
--- a/src/mbgl/renderer/circle_bucket.cpp
+++ b/src/mbgl/renderer/circle_bucket.cpp
@@ -31,7 +31,7 @@ void CircleBucket::render(Painter& painter,
}
bool CircleBucket::hasData() const {
- return !triangleGroups.empty();
+ return !groups.empty();
}
bool CircleBucket::needsClipping() const {
@@ -64,13 +64,13 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
vertices.emplace_back(x, y, 1, 1); // 3
vertices.emplace_back(x, y, -1, 1); // 4
- if (!triangleGroups.size() || (triangleGroups.back()->vertex_length + 4 > 65535)) {
+ if (!groups.size() || groups.back().vertexLength + 4 > 65535) {
// Move to a new group because the old one can't hold the geometry.
- triangleGroups.emplace_back(std::make_unique<TriangleGroup>());
+ groups.emplace_back();
}
- TriangleGroup& group = *triangleGroups.back();
- uint16_t index = group.vertex_length;
+ auto& group = groups.back();
+ uint16_t index = group.vertexLength;
// 1, 2, 3
// 1, 4, 3
@@ -81,27 +81,25 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
static_cast<uint16_t>(index + 3),
static_cast<uint16_t>(index + 2));
- group.vertex_length += 4;
- group.elements_length += 2;
+ group.vertexLength += 4;
+ group.indexLength += 2;
}
}
}
-void CircleBucket::drawCircles(CircleShader& shader, gl::Context& context) {
+void CircleBucket::drawCircles(CircleShader& shader, gl::Context& context, PaintMode paintMode) {
GLbyte* vertexIndex = BUFFER_OFFSET(0);
GLbyte* elementsIndex = BUFFER_OFFSET(0);
- for (auto& group : triangleGroups) {
- assert(group);
+ for (auto& group : groups) {
+ if (!group.indexLength) continue;
- if (!group->elements_length) continue;
+ group.getVAO(shader, paintMode).bind(shader, *vertexBuffer, *indexBuffer, vertexIndex, context);
- group->array[0].bind(shader, *vertexBuffer, *indexBuffer, vertexIndex, context);
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT, elementsIndex));
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elementsIndex));
-
- vertexIndex += group->vertex_length * vertexBuffer->vertexSize;
- elementsIndex += group->elements_length * indexBuffer->primitiveSize;
+ vertexIndex += group.vertexLength * vertexBuffer->vertexSize;
+ elementsIndex += group.indexLength * indexBuffer->primitiveSize;
}
}
diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp
index 5f4f357d2f..2f3faccdec 100644
--- a/src/mbgl/renderer/circle_bucket.hpp
+++ b/src/mbgl/renderer/circle_bucket.hpp
@@ -1,11 +1,11 @@
#pragma once
#include <mbgl/renderer/bucket.hpp>
+#include <mbgl/renderer/element_group.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
-#include <mbgl/gl/element_group.hpp>
#include <mbgl/shader/circle_vertex.hpp>
namespace mbgl {
@@ -24,14 +24,13 @@ public:
bool needsClipping() const override;
void addGeometry(const GeometryCollection&);
- void drawCircles(CircleShader&, gl::Context&);
+ void drawCircles(CircleShader&, gl::Context&, PaintMode);
private:
std::vector<CircleVertex> vertices;
std::vector<gl::Triangle> triangles;
- using TriangleGroup = gl::ElementGroup<3>;
- std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
+ std::vector<ElementGroup<CircleShader>> groups;
optional<gl::VertexBuffer<CircleVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
diff --git a/src/mbgl/renderer/element_group.hpp b/src/mbgl/renderer/element_group.hpp
new file mode 100644
index 0000000000..59b5c3068d
--- /dev/null
+++ b/src/mbgl/renderer/element_group.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <mbgl/gl/vao.hpp>
+#include <mbgl/renderer/render_pass.hpp>
+
+namespace mbgl {
+
+template <class... Shaders>
+struct ElementGroup {
+ template <class Shader>
+ struct VAOs {
+ gl::VertexArrayObject normalVAO;
+ gl::VertexArrayObject overdrawVAO;
+ };
+
+ std::tuple<VAOs<Shaders>...> vaos;
+
+ template <class Shader>
+ gl::VertexArrayObject& getVAO(const Shader&, PaintMode paintMode) {
+ auto& vao = std::get<VAOs<Shader>>(vaos);
+ return paintMode == PaintMode::Overdraw ? vao.overdrawVAO : vao.normalVAO;
+ }
+
+ std::size_t vertexLength = 0;
+ std::size_t indexLength = 0;
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp
index 9213c9a777..f570d59743 100644
--- a/src/mbgl/renderer/fill_bucket.cpp
+++ b/src/mbgl/renderer/fill_bucket.cpp
@@ -54,11 +54,11 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
if (nVertices == 0)
continue;
- if (lineGroups.empty() || lineGroups.back()->vertex_length + nVertices > 65535)
- lineGroups.emplace_back(std::make_unique<LineGroup>());
+ if (lineGroups.empty() || lineGroups.back().vertexLength + nVertices > 65535)
+ lineGroups.emplace_back();
- LineGroup& lineGroup = *lineGroups.back();
- uint16_t lineIndex = lineGroup.vertex_length;
+ auto& lineGroup = lineGroups.back();
+ uint16_t lineIndex = lineGroup.vertexLength;
vertices.emplace_back(ring[0].x, ring[0].y);
lines.emplace_back(static_cast<uint16_t>(lineIndex + nVertices - 1),
@@ -70,8 +70,8 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
static_cast<uint16_t>(lineIndex + i));
}
- lineGroup.vertex_length += nVertices;
- lineGroup.elements_length += nVertices;
+ lineGroup.vertexLength += nVertices;
+ lineGroup.indexLength += nVertices;
}
std::vector<uint32_t> indices = mapbox::earcut(polygon);
@@ -79,12 +79,12 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
std::size_t nIndicies = indices.size();
assert(nIndicies % 3 == 0);
- if (triangleGroups.empty() || triangleGroups.back()->vertex_length + totalVertices > 65535) {
- triangleGroups.emplace_back(std::make_unique<TriangleGroup>());
+ if (triangleGroups.empty() || triangleGroups.back().vertexLength + totalVertices > 65535) {
+ triangleGroups.emplace_back();
}
- TriangleGroup& triangleGroup = *triangleGroups.back();
- uint16_t triangleIndex = triangleGroup.vertex_length;
+ auto& triangleGroup = triangleGroups.back();
+ uint16_t triangleIndex = triangleGroup.vertexLength;
for (uint32_t i = 0; i < nIndicies; i += 3) {
triangles.emplace_back(static_cast<uint16_t>(triangleIndex + indices[i]),
@@ -92,8 +92,8 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
static_cast<uint16_t>(triangleIndex + indices[i + 2]));
}
- triangleGroup.vertex_length += totalVertices;
- triangleGroup.elements_length += nIndicies / 3;
+ triangleGroup.vertexLength += totalVertices;
+ triangleGroup.indexLength += nIndicies / 3;
}
}
@@ -127,13 +127,12 @@ void FillBucket::drawElements(PlainShader& shader,
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
for (auto& group : triangleGroups) {
- assert(group);
- group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *vertexBuffer, *triangleIndexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer->vertexSize;
- elements_index += group->elements_length * triangleIndexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * vertexBuffer->vertexSize;
+ elements_index += group.indexLength * triangleIndexBuffer->primitiveSize;
}
}
@@ -143,13 +142,12 @@ void FillBucket::drawElements(PatternShader& shader,
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
for (auto& group : triangleGroups) {
- assert(group);
- group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *vertexBuffer, *triangleIndexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer->vertexSize;
- elements_index += group->elements_length * triangleIndexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * vertexBuffer->vertexSize;
+ elements_index += group.indexLength * triangleIndexBuffer->primitiveSize;
}
}
@@ -159,13 +157,12 @@ void FillBucket::drawVertices(OutlineShader& shader,
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
for (auto& group : lineGroups) {
- assert(group);
- group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *vertexBuffer, *lineIndexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_LINES, group->elements_length * 2, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_LINES, static_cast<GLsizei>(group.indexLength * 2), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer->vertexSize;
- elements_index += group->elements_length * lineIndexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * vertexBuffer->vertexSize;
+ elements_index += group.indexLength * lineIndexBuffer->primitiveSize;
}
}
@@ -175,13 +172,12 @@ void FillBucket::drawVertices(OutlinePatternShader& shader,
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
for (auto& group : lineGroups) {
- assert(group);
- group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *vertexBuffer, *lineIndexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_LINES, group->elements_length * 2, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_LINES, static_cast<GLsizei>(group.indexLength * 2), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer->vertexSize;
- elements_index += group->elements_length * lineIndexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * vertexBuffer->vertexSize;
+ elements_index += group.indexLength * lineIndexBuffer->primitiveSize;
}
}
diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp
index 9392bb5cf3..2ec9fc0e5b 100644
--- a/src/mbgl/renderer/fill_bucket.hpp
+++ b/src/mbgl/renderer/fill_bucket.hpp
@@ -1,8 +1,8 @@
#pragma once
#include <mbgl/renderer/bucket.hpp>
+#include <mbgl/renderer/element_group.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/gl/element_group.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/shader/plain_vertex.hpp>
@@ -39,10 +39,8 @@ private:
std::vector<gl::Line> lines;
std::vector<gl::Triangle> triangles;
- typedef gl::ElementGroup<4> LineGroup;
- typedef gl::ElementGroup<4> TriangleGroup;
- std::vector<std::unique_ptr<LineGroup>> lineGroups;
- std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
+ std::vector<ElementGroup<OutlineShader, OutlinePatternShader>> lineGroups;
+ std::vector<ElementGroup<PlainShader, PatternShader>> triangleGroups;
optional<gl::VertexBuffer<PlainVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Line>> lineIndexBuffer;
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index 23c8b449b3..6ec265d727 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -352,26 +352,22 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
const std::size_t endVertex = vertices.size();
const std::size_t vertexCount = endVertex - startVertex;
- // Store the triangle/line groups.
- {
- if (triangleGroups.empty() || (triangleGroups.back()->vertex_length + vertexCount > 65535)) {
- // Move to a new group because the old one can't hold the geometry.
- triangleGroups.emplace_back(std::make_unique<TriangleGroup>());
- }
+ if (groups.empty() || groups.back().vertexLength + vertexCount > 65535) {
+ // Move to a new group because the old one can't hold the geometry.
+ groups.emplace_back();
+ }
- assert(triangleGroups.back());
- auto& group = *triangleGroups.back();
- uint16_t index = group.vertex_length;
+ auto& group = groups.back();
+ uint16_t index = group.vertexLength;
- for (const auto& triangle : triangleStore) {
- triangles.emplace_back(static_cast<uint16_t>(index + triangle.a),
- static_cast<uint16_t>(index + triangle.b),
- static_cast<uint16_t>(index + triangle.c));
- }
-
- group.vertex_length += vertexCount;
- group.elements_length += triangleStore.size();
+ for (const auto& triangle : triangleStore) {
+ triangles.emplace_back(static_cast<uint16_t>(index + triangle.a),
+ static_cast<uint16_t>(index + triangle.b),
+ static_cast<uint16_t>(index + triangle.c));
}
+
+ group.vertexLength += vertexCount;
+ group.indexLength += triangleStore.size();
}
void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate,
@@ -454,7 +450,7 @@ void LineBucket::render(Painter& painter,
}
bool LineBucket::hasData() const {
- return !triangleGroups.empty();
+ return !groups.empty();
}
bool LineBucket::needsClipping() const {
@@ -466,17 +462,16 @@ void LineBucket::drawLines(LineShader& shader,
PaintMode paintMode) {
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
- for (auto& group : triangleGroups) {
- assert(group);
- if (!group->elements_length) {
+ for (auto& group : groups) {
+ if (!group.indexLength) {
continue;
}
- group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *vertexBuffer, *indexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer->vertexSize;
- elements_index += group->elements_length * indexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * vertexBuffer->vertexSize;
+ elements_index += group.indexLength * indexBuffer->primitiveSize;
}
}
@@ -485,17 +480,16 @@ void LineBucket::drawLineSDF(LineSDFShader& shader,
PaintMode paintMode) {
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
- for (auto& group : triangleGroups) {
- assert(group);
- if (!group->elements_length) {
+ for (auto& group : groups) {
+ if (!group.indexLength) {
continue;
}
- group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *vertexBuffer, *indexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer->vertexSize;
- elements_index += group->elements_length * indexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * vertexBuffer->vertexSize;
+ elements_index += group.indexLength * indexBuffer->primitiveSize;
}
}
@@ -504,17 +498,16 @@ void LineBucket::drawLinePatterns(LinepatternShader& shader,
PaintMode paintMode) {
GLbyte* vertex_index = BUFFER_OFFSET(0);
GLbyte* elements_index = BUFFER_OFFSET(0);
- for (auto& group : triangleGroups) {
- assert(group);
- if (!group->elements_length) {
+ for (auto& group : groups) {
+ if (!group.indexLength) {
continue;
}
- group->array[paintMode == PaintMode::Overdraw ? 5 : 4].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *vertexBuffer, *indexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer->vertexSize;
- elements_index += group->elements_length * indexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * vertexBuffer->vertexSize;
+ elements_index += group.indexLength * indexBuffer->primitiveSize;
}
}
diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp
index 8cb73c1d27..ca07c345da 100644
--- a/src/mbgl/renderer/line_bucket.hpp
+++ b/src/mbgl/renderer/line_bucket.hpp
@@ -1,8 +1,8 @@
#pragma once
#include <mbgl/renderer/bucket.hpp>
+#include <mbgl/renderer/element_group.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/gl/element_group.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/shader/line_vertex.hpp>
@@ -53,8 +53,7 @@ private:
std::vector<LineVertex> vertices;
std::vector<gl::Triangle> triangles;
- using TriangleGroup = gl::ElementGroup<6>;
- std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
+ std::vector<ElementGroup<LineShader, LineSDFShader, LinepatternShader>> groups;
optional<gl::VertexBuffer<LineVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp
index 327011d03e..462ed59ebf 100644
--- a/src/mbgl/renderer/painter_circle.cpp
+++ b/src/mbgl/renderer/painter_circle.cpp
@@ -51,7 +51,7 @@ void Painter::renderCircle(PaintParameters& parameters,
circleShader.u_blur = properties.circleBlur;
circleShader.u_opacity = properties.circleOpacity;
- bucket.drawCircles(circleShader, context);
+ bucket.drawCircles(circleShader, context, paintMode());
}
} // namespace mbgl
diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp
index 0c41031c93..ba064e4cc3 100644
--- a/src/mbgl/renderer/symbol_bucket.cpp
+++ b/src/mbgl/renderer/symbol_bucket.cpp
@@ -72,13 +72,12 @@ void SymbolBucket::drawGlyphs(SDFShader& shader,
GLbyte* vertex_index = BUFFER_OFFSET_0;
GLbyte* elements_index = BUFFER_OFFSET_0;
for (auto& group : text.groups) {
- assert(group);
- group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *text.vertexBuffer, *text.indexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * text.vertexBuffer->vertexSize;
- elements_index += group->elements_length * text.indexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * text.vertexBuffer->vertexSize;
+ elements_index += group.indexLength * text.indexBuffer->primitiveSize;
}
}
@@ -88,13 +87,12 @@ void SymbolBucket::drawIcons(SDFShader& shader,
GLbyte* vertex_index = BUFFER_OFFSET_0;
GLbyte* elements_index = BUFFER_OFFSET_0;
for (auto& group : icon.groups) {
- assert(group);
- group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *icon.vertexBuffer, *icon.indexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * icon.vertexBuffer->vertexSize;
- elements_index += group->elements_length * icon.indexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * icon.vertexBuffer->vertexSize;
+ elements_index += group.indexLength * icon.indexBuffer->primitiveSize;
}
}
@@ -104,13 +102,12 @@ void SymbolBucket::drawIcons(IconShader& shader,
GLbyte* vertex_index = BUFFER_OFFSET_0;
GLbyte* elements_index = BUFFER_OFFSET_0;
for (auto& group : icon.groups) {
- assert(group);
- group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind(
+ group.getVAO(shader, paintMode).bind(
shader, *icon.vertexBuffer, *icon.indexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
+ MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(group.indexLength * 3), GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * icon.vertexBuffer->vertexSize;
- elements_index += group->elements_length * icon.indexBuffer->primitiveSize;
+ vertex_index += group.vertexLength * icon.vertexBuffer->vertexSize;
+ elements_index += group.indexLength * icon.indexBuffer->primitiveSize;
}
}
@@ -118,8 +115,9 @@ void SymbolBucket::drawCollisionBoxes(CollisionBoxShader& shader,
gl::Context& context) {
GLbyte* vertex_index = BUFFER_OFFSET_0;
for (auto& group : collisionBox.groups) {
- group->array[0].bind(shader, *collisionBox.vertexBuffer, vertex_index, context);
- MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, group->vertex_length));
+ group.getVAO(shader, PaintMode::Regular).bind(
+ shader, *collisionBox.vertexBuffer, vertex_index, context);
+ MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(group.vertexLength)));
}
}
diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp
index 36511e964f..6fb61f7b00 100644
--- a/src/mbgl/renderer/symbol_bucket.hpp
+++ b/src/mbgl/renderer/symbol_bucket.hpp
@@ -1,8 +1,8 @@
#pragma once
#include <mbgl/renderer/bucket.hpp>
+#include <mbgl/renderer/element_group.hpp>
#include <mbgl/map/mode.hpp>
-#include <mbgl/gl/element_group.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/shader/texture_rect_vertex.hpp>
@@ -47,14 +47,10 @@ public:
private:
friend class SymbolLayout;
- typedef gl::ElementGroup<2> TextElementGroup;
- typedef gl::ElementGroup<4> IconElementGroup;
- typedef gl::ElementGroup<1> CollisionBoxElementGroup;
-
struct TextBuffer {
std::vector<TextureRectVertex> vertices;
std::vector<gl::Triangle> triangles;
- std::vector<std::unique_ptr<TextElementGroup>> groups;
+ std::vector<ElementGroup<SDFShader>> groups;
optional<gl::VertexBuffer<TextureRectVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
@@ -63,7 +59,7 @@ private:
struct IconBuffer {
std::vector<TextureRectVertex> vertices;
std::vector<gl::Triangle> triangles;
- std::vector<std::unique_ptr<IconElementGroup>> groups;
+ std::vector<ElementGroup<SDFShader, IconShader>> groups;
optional<gl::VertexBuffer<TextureRectVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
@@ -72,7 +68,7 @@ private:
struct CollisionBoxBuffer {
std::vector<CollisionBoxVertex> vertices;
std::vector<gl::Line> lines;
- std::vector<std::unique_ptr<CollisionBoxElementGroup>> groups;
+ std::vector<ElementGroup<CollisionBoxShader>> groups;
optional<gl::VertexBuffer<CollisionBoxVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Line>> indexBuffer;