summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/geometry/buffer.hpp115
-rw-r--r--src/mbgl/geometry/circle_buffer.cpp15
-rw-r--r--src/mbgl/geometry/circle_buffer.hpp24
-rw-r--r--src/mbgl/geometry/collision_box_buffer.cpp27
-rw-r--r--src/mbgl/geometry/collision_box_buffer.hpp20
-rw-r--r--src/mbgl/geometry/debug_font_buffer.cpp44
-rw-r--r--src/mbgl/geometry/debug_font_buffer.hpp14
-rw-r--r--src/mbgl/geometry/elements_buffer.cpp18
-rw-r--r--src/mbgl/geometry/elements_buffer.hpp46
-rw-r--r--src/mbgl/geometry/fill_buffer.cpp15
-rw-r--r--src/mbgl/geometry/fill_buffer.hpp18
-rw-r--r--src/mbgl/geometry/icon_buffer.cpp35
-rw-r--r--src/mbgl/geometry/icon_buffer.hpp17
-rw-r--r--src/mbgl/geometry/line_buffer.cpp37
-rw-r--r--src/mbgl/geometry/line_buffer.hpp37
-rw-r--r--src/mbgl/geometry/static_vertex_buffer.cpp24
-rw-r--r--src/mbgl/geometry/static_vertex_buffer.hpp30
-rw-r--r--src/mbgl/geometry/text_buffer.cpp36
-rw-r--r--src/mbgl/geometry/text_buffer.hpp20
-rw-r--r--src/mbgl/gl/context.cpp20
-rw-r--r--src/mbgl/gl/context.hpp21
-rw-r--r--src/mbgl/gl/element_group.hpp25
-rw-r--r--src/mbgl/gl/index_buffer.hpp41
-rw-r--r--src/mbgl/gl/vao.cpp (renamed from src/mbgl/geometry/vao.cpp)2
-rw-r--r--src/mbgl/gl/vao.hpp (renamed from src/mbgl/geometry/vao.hpp)29
-rw-r--r--src/mbgl/gl/vertex_buffer.hpp17
-rw-r--r--src/mbgl/layout/symbol_layout.cpp32
-rw-r--r--src/mbgl/map/map.cpp1
-rw-r--r--src/mbgl/renderer/circle_bucket.cpp38
-rw-r--r--src/mbgl/renderer/circle_bucket.hpp19
-rw-r--r--src/mbgl/renderer/debug_bucket.cpp89
-rw-r--r--src/mbgl/renderer/debug_bucket.hpp13
-rw-r--r--src/mbgl/renderer/fill_bucket.cpp50
-rw-r--r--src/mbgl/renderer/fill_bucket.hpp23
-rw-r--r--src/mbgl/renderer/line_bucket.cpp53
-rw-r--r--src/mbgl/renderer/line_bucket.hpp30
-rw-r--r--src/mbgl/renderer/painter.cpp26
-rw-r--r--src/mbgl/renderer/painter.hpp37
-rw-r--r--src/mbgl/renderer/painter_background.cpp6
-rw-r--r--src/mbgl/renderer/painter_clipping.cpp4
-rw-r--r--src/mbgl/renderer/painter_debug.cpp6
-rw-r--r--src/mbgl/renderer/painter_raster.cpp2
-rw-r--r--src/mbgl/renderer/raster_bucket.cpp4
-rw-r--r--src/mbgl/renderer/raster_bucket.hpp7
-rw-r--r--src/mbgl/renderer/symbol_bucket.cpp33
-rw-r--r--src/mbgl/renderer/symbol_bucket.hpp35
-rw-r--r--src/mbgl/shader/circle_shader.cpp8
-rw-r--r--src/mbgl/shader/circle_shader.hpp9
-rw-r--r--src/mbgl/shader/circle_vertex.cpp13
-rw-r--r--src/mbgl/shader/circle_vertex.hpp26
-rw-r--r--src/mbgl/shader/collision_box_shader.cpp16
-rw-r--r--src/mbgl/shader/collision_box_shader.hpp9
-rw-r--r--src/mbgl/shader/collision_box_vertex.cpp15
-rw-r--r--src/mbgl/shader/collision_box_vertex.hpp28
-rw-r--r--src/mbgl/shader/icon_shader.cpp19
-rw-r--r--src/mbgl/shader/icon_shader.hpp9
-rw-r--r--src/mbgl/shader/line_shader.cpp11
-rw-r--r--src/mbgl/shader/line_shader.hpp9
-rw-r--r--src/mbgl/shader/line_vertex.cpp14
-rw-r--r--src/mbgl/shader/line_vertex.hpp58
-rw-r--r--src/mbgl/shader/linepattern_shader.cpp11
-rw-r--r--src/mbgl/shader/linepattern_shader.hpp9
-rw-r--r--src/mbgl/shader/linesdf_shader.cpp11
-rw-r--r--src/mbgl/shader/linesdf_shader.hpp9
-rw-r--r--src/mbgl/shader/outline_shader.cpp8
-rw-r--r--src/mbgl/shader/outline_shader.hpp9
-rw-r--r--src/mbgl/shader/outlinepattern_shader.cpp8
-rw-r--r--src/mbgl/shader/outlinepattern_shader.hpp9
-rw-r--r--src/mbgl/shader/pattern_shader.cpp8
-rw-r--r--src/mbgl/shader/pattern_shader.hpp9
-rw-r--r--src/mbgl/shader/plain_shader.cpp8
-rw-r--r--src/mbgl/shader/plain_shader.hpp9
-rw-r--r--src/mbgl/shader/plain_vertex.cpp13
-rw-r--r--src/mbgl/shader/plain_vertex.hpp17
-rw-r--r--src/mbgl/shader/raster_shader.cpp13
-rw-r--r--src/mbgl/shader/raster_shader.hpp9
-rw-r--r--src/mbgl/shader/raster_vertex.cpp14
-rw-r--r--src/mbgl/shader/raster_vertex.hpp25
-rw-r--r--src/mbgl/shader/sdf_shader.cpp19
-rw-r--r--src/mbgl/shader/sdf_shader.hpp11
-rw-r--r--src/mbgl/shader/shader.hpp3
-rw-r--r--src/mbgl/shader/texture_rect_vertex.cpp16
-rw-r--r--src/mbgl/shader/texture_rect_vertex.hpp39
-rw-r--r--src/mbgl/tile/tile.cpp1
84 files changed, 854 insertions, 933 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp
deleted file mode 100644
index 2d010e39ac..0000000000
--- a/src/mbgl/geometry/buffer.hpp
+++ /dev/null
@@ -1,115 +0,0 @@
-#pragma once
-
-#include <mbgl/gl/context.hpp>
-#include <mbgl/platform/log.hpp>
-#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/util/optional.hpp>
-
-#include <memory>
-#include <cstdlib>
-#include <cassert>
-#include <stdexcept>
-
-namespace mbgl {
-
-template <uint32_t item_size,
- gl::BufferType target = gl::BufferType::Vertex,
- uint32_t defaultLength = 8192,
- bool retainAfterUpload = false>
-class Buffer : private util::noncopyable {
- static_assert(target == gl::BufferType::Vertex || target == gl::BufferType::Element,
- "target must be one of gl::BufferType::Vertex or gl::BufferType::Element");
-
-public:
- ~Buffer() {
- cleanup();
- }
-
- // Returns the number of elements in this buffer. This is not the number of
- // bytes, but rather the number of coordinates with associated information.
- uint32_t index() const {
- return pos / itemSize;
- }
-
- bool empty() const {
- return pos == 0;
- }
-
- // Transfers this buffer to the GPU and binds the buffer to the GL context.
- void bind(gl::Context& context) {
- const bool initialized { buffer };
- if (!initialized) {
- buffer = context.createBuffer();
- }
-
- if (target == gl::BufferType::Vertex) {
- context.vertexBuffer = *buffer;
- } else {
- context.elementBuffer = *buffer;
- }
-
- if (!initialized) {
- if (array == nullptr) {
- Log::Debug(Event::OpenGL, "Buffer doesn't contain elements");
- pos = 0;
- }
- context.uploadBuffer(target, pos, array);
- if (!retainAfterUpload) {
- cleanup();
- }
- }
- }
-
- void cleanup() {
- if (array) {
- free(array);
- array = nullptr;
- }
- }
-
- gl::BufferID getID() const {
- return buffer ? *buffer : 0;
- }
-
- // Uploads the buffer to the GPU to be available when we need it.
- void upload(gl::Context& context) {
- if (!buffer) {
- bind(context);
- }
- }
-
-protected:
- // increase the buffer size by at least /required/ bytes.
- void *addElement() {
- if (buffer) {
- throw std::runtime_error("Can't add elements after buffer was bound to GPU");
- }
- if (length < pos + itemSize) {
- while (length < pos + itemSize) length += defaultLength;
- array = realloc(array, length);
- if (array == nullptr) {
- throw std::runtime_error("Buffer reallocation failed");
- }
- }
- pos += itemSize;
- return reinterpret_cast<char *>(array) + (pos - itemSize);
- }
-
-public:
- static constexpr const uint32_t itemSize = item_size;
-
-private:
- // CPU buffer
- void* array = nullptr;
-
- // Byte position where we are writing.
- uint32_t pos = 0;
-
- // Number of bytes that are valid in this buffer.
- uint32_t length = 0;
-
- // GL buffer object handle.
- mbgl::optional<gl::UniqueBuffer> buffer;
-};
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/circle_buffer.cpp b/src/mbgl/geometry/circle_buffer.cpp
deleted file mode 100644
index cc31fb83bf..0000000000
--- a/src/mbgl/geometry/circle_buffer.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <mbgl/geometry/circle_buffer.hpp>
-
-#include <mbgl/gl/gl.hpp>
-
-#include <climits>
-
-namespace mbgl {
-
-void CircleVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey) {
- vertex_type *vertices = static_cast<vertex_type *>(addElement());
- vertices[0] = (x * 2) + ((ex + 1) / 2);
- vertices[1] = (y * 2) + ((ey + 1) / 2);
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/circle_buffer.hpp b/src/mbgl/geometry/circle_buffer.hpp
deleted file mode 100644
index 2b188c4003..0000000000
--- a/src/mbgl/geometry/circle_buffer.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-
-namespace mbgl {
-
-class CircleVertexBuffer : public Buffer<
- 4 // 2 bytes per short * 4 of them.
-> {
-public:
- typedef int16_t vertex_type;
-
- /*
- * Add a vertex to this buffer
- *
- * @param {number} x vertex position
- * @param {number} y vertex position
- * @param {number} ex extrude normal
- * @param {number} ey extrude normal
- */
- void add(vertex_type x, vertex_type y, float ex, float ey);
-};
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/collision_box_buffer.cpp b/src/mbgl/geometry/collision_box_buffer.cpp
deleted file mode 100644
index ae58cf7bca..0000000000
--- a/src/mbgl/geometry/collision_box_buffer.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <mbgl/geometry/collision_box_buffer.hpp>
-#include <mbgl/gl/gl.hpp>
-#include <mbgl/util/math.hpp>
-
-#include <cmath>
-
-namespace mbgl {
-
-uint32_t CollisionBoxVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, float maxzoom, float placementZoom) {
- const uint32_t idx = index();
- void *data = addElement();
-
- int16_t *shorts = static_cast<int16_t *>(data);
- shorts[0] /* pos */ = x;
- shorts[1] /* pos */ = y;
- shorts[2] /* offset */ = ::round(ox); // use 1/64 pixels for placement
- shorts[3] /* offset */ = ::round(oy);
-
- uint8_t *ubytes = static_cast<uint8_t *>(data);
- // a_data
- ubytes[8] = maxzoom * 10;
- ubytes[9] = placementZoom * 10;
-
- return idx;
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/collision_box_buffer.hpp b/src/mbgl/geometry/collision_box_buffer.hpp
deleted file mode 100644
index 5360ac3f4c..0000000000
--- a/src/mbgl/geometry/collision_box_buffer.hpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-#include <array>
-
-namespace mbgl {
-
-class CollisionBoxVertexBuffer : public Buffer <
- 12,
- gl::BufferType::Vertex,
- 32768
-> {
-public:
- typedef int16_t vertex_type;
-
- uint32_t add(int16_t x, int16_t y, float ex, float ey, float maxzoom, float placementZoom);
-};
-
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/debug_font_buffer.cpp b/src/mbgl/geometry/debug_font_buffer.cpp
deleted file mode 100644
index f64ce8816b..0000000000
--- a/src/mbgl/geometry/debug_font_buffer.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#include <mbgl/geometry/debug_font_buffer.hpp>
-#include <mbgl/geometry/debug_font_data.hpp>
-
-#include <mbgl/gl/gl.hpp>
-#include <cmath>
-#include <cstring>
-
-namespace mbgl {
-
-void DebugFontBuffer::addText(const char *text, double left, double baseline, double scale) {
- uint16_t *coords = nullptr;
-
- const size_t len = strlen(text);
- for (size_t i = 0; i < len; ++i) {
- if (text[i] < 32 || (unsigned char)(text[i]) >= 127) {
- continue;
- }
-
- const glyph& glyph = simplex[text[i] - 32];
-
- int16_t prev_x = -1, prev_y = -1, prev = false;
- for (int32_t j = 0; j < glyph.length; j += 2) {
- if (glyph.data[j] == -1 && glyph.data[j + 1] == -1) {
- prev = false;
- } else {
- int16_t x = ::round(left + glyph.data[j] * scale);
- int16_t y = ::round(baseline - glyph.data[j + 1] * scale);
- if (prev) {
- coords = static_cast<uint16_t *>(addElement());
- coords[0] = prev_x;
- coords[1] = prev_y;
-
- coords = static_cast<uint16_t *>(addElement());
- coords[0] = x;
- coords[1] = y;
- }
- prev_x = x; prev_y = y; prev = true;
- }
- }
- left += glyph.width * scale;
- }
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/debug_font_buffer.hpp b/src/mbgl/geometry/debug_font_buffer.hpp
deleted file mode 100644
index f2debe97a4..0000000000
--- a/src/mbgl/geometry/debug_font_buffer.hpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-
-namespace mbgl {
-
-class DebugFontBuffer : public Buffer<
- 4 // 2 bytes per coordinate, 2 coordinates
-> {
-public:
- void addText(const char *text, double left, double baseline, double scale = 1);
-};
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/elements_buffer.cpp b/src/mbgl/geometry/elements_buffer.cpp
deleted file mode 100644
index b7d8cb2015..0000000000
--- a/src/mbgl/geometry/elements_buffer.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <mbgl/geometry/elements_buffer.hpp>
-
-namespace mbgl {
-
-void TriangleElementsBuffer::add(element_type a, element_type b, element_type c) {
- element_type *elements = static_cast<element_type *>(addElement());
- elements[0] = a;
- elements[1] = b;
- elements[2] = c;
-}
-
-void LineElementsBuffer::add(element_type a, element_type b) {
- element_type *elements = static_cast<element_type *>(addElement());
- elements[0] = a;
- elements[1] = b;
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/elements_buffer.hpp b/src/mbgl/geometry/elements_buffer.hpp
deleted file mode 100644
index f995229c9d..0000000000
--- a/src/mbgl/geometry/elements_buffer.hpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-#include <mbgl/geometry/vao.hpp>
-
-#include <mbgl/util/noncopyable.hpp>
-
-#include <array>
-
-namespace mbgl {
-
-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_)
- {
- }
-};
-
-class TriangleElementsBuffer : public Buffer<
- 6, // bytes per triangle (3 * unsigned short == 6 bytes)
- gl::BufferType::Element
-> {
-public:
- typedef uint16_t element_type;
-
- void add(element_type a, element_type b, element_type c);
-};
-
-
-class LineElementsBuffer : public Buffer<
- 4, // bytes per triangle (2 * unsigned short == 6 bytes)
- gl::BufferType::Element
-> {
-public:
- typedef uint16_t element_type;
-
- void add(element_type a, element_type b);
-};
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/fill_buffer.cpp b/src/mbgl/geometry/fill_buffer.cpp
deleted file mode 100644
index 6cb07ea66a..0000000000
--- a/src/mbgl/geometry/fill_buffer.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <mbgl/geometry/fill_buffer.hpp>
-
-#include <mbgl/gl/gl.hpp>
-
-#include <climits>
-
-namespace mbgl {
-
-void FillVertexBuffer::add(vertex_type x, vertex_type y) {
- vertex_type *vertices = static_cast<vertex_type *>(addElement());
- vertices[0] = x;
- vertices[1] = y;
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/fill_buffer.hpp b/src/mbgl/geometry/fill_buffer.hpp
deleted file mode 100644
index a180d9c5a2..0000000000
--- a/src/mbgl/geometry/fill_buffer.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-#include <vector>
-#include <cstdint>
-
-namespace mbgl {
-
-class FillVertexBuffer : public Buffer<
- 4 // bytes per coordinates (2 * unsigned short == 4 bytes)
-> {
-public:
- typedef int16_t vertex_type;
-
- void add(vertex_type x, vertex_type y);
-};
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/icon_buffer.cpp b/src/mbgl/geometry/icon_buffer.cpp
deleted file mode 100644
index 745003a548..0000000000
--- a/src/mbgl/geometry/icon_buffer.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include <mbgl/geometry/icon_buffer.hpp>
-#include <mbgl/gl/gl.hpp>
-#include <mbgl/util/math.hpp>
-
-#include <cmath>
-
-namespace mbgl {
-
-uint32_t IconVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, int16_t tx, int16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle) {
- const uint32_t idx = index();
- void *data = addElement();
-
- int16_t *shorts = static_cast<int16_t *>(data);
- shorts[0] /* pos */ = x;
- shorts[1] /* pos */ = y;
- shorts[2] /* offset */ = ::round(ox * 64); // use 1/64 pixels for placement
- shorts[3] /* offset */ = ::round(oy * 64);
-
- uint16_t *ushorts = static_cast<uint16_t *>(data);
- // a_texture_pos
- ushorts[4] /* tex */ = tx / 4;
- ushorts[5] /* tex */ = ty / 4;
-
- uint8_t *ubytes = static_cast<uint8_t *>(data);
- // a_data
- ubytes[12] /* labelminzoom */ = labelminzoom * 10;
- ubytes[13] /* labelangle */ = labelangle;
-
- ubytes[14] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160.
- ubytes[15] /* maxzoom */ = ::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
-
- return idx;
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/icon_buffer.hpp b/src/mbgl/geometry/icon_buffer.hpp
deleted file mode 100644
index 81e17df495..0000000000
--- a/src/mbgl/geometry/icon_buffer.hpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-
-#include <array>
-
-namespace mbgl {
-
- class IconVertexBuffer : public Buffer<
- 16
- > {
- public:
- uint32_t add(int16_t x, int16_t y, float ox, float oy, int16_t tx, int16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle);
-
- };
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/line_buffer.cpp b/src/mbgl/geometry/line_buffer.cpp
deleted file mode 100644
index 0eabf8e1e9..0000000000
--- a/src/mbgl/geometry/line_buffer.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <mbgl/geometry/line_buffer.hpp>
-
-#include <cmath>
-
-namespace mbgl {
-
-uint32_t LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar) {
- uint32_t idx = index();
- void *data = addElement();
-
- int16_t *coords = static_cast<int16_t *>(data);
- coords[0] = (x * 2) | tx;
- coords[1] = (y * 2) | ty;
-
- uint8_t *ubytes = static_cast<uint8_t *>(data);
- // add 128 to store an byte in an unsigned byte
- ubytes[4] = ::round(extrudeScale * ex) + 128;
- ubytes[5] = ::round(extrudeScale * ey) + 128;
-
- // Encode the -1/0/1 direction value into the first two bits of .z of a_data.
- // Combine it with the lower 6 bits of `linesofar` (shifted by 2 bites to make
- // room for the direction value). The upper 8 bits of `linesofar` are placed in
- // the `w` component. `linesofar` is scaled down by `LINE_DISTANCE_SCALE` so that
- // we can store longer distances while sacrificing precision.
-
- // Encode the -1/0/1 direction value into .zw coordinates of a_data, which is normally covered
- // by linesofar, so we need to merge them.
- // The z component's first bit, as well as the sign bit is reserved for the direction,
- // so we need to shift the linesofar.
-
- ubytes[6] = ((dir == 0 ? 0 : (dir < 0 ? -1 : 1 )) + 1) | ((linesofar & 0x3F) << 2);
- ubytes[7] = linesofar >> 6;
-
- return idx;
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/line_buffer.hpp b/src/mbgl/geometry/line_buffer.hpp
deleted file mode 100644
index bfa9a55021..0000000000
--- a/src/mbgl/geometry/line_buffer.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-
-namespace mbgl {
-
-class LineVertexBuffer : public Buffer<
- 8 // 2 coordinates per vertex + 1 linesofar + 1 extrude coord pair == 4 (== 8 bytes)
-> {
-public:
- typedef int16_t vertex_type;
-
- /*
- * Scale the extrusion vector so that the normal length is this value.
- * Contains the "texture" normals (-1..1). This is distinct from the extrude
- * normals for line joins, because the x-value remains 0 for the texture
- * normal array, while the extrude normal actually moves the vertex to create
- * the acute/bevelled line join.
- */
- static const int8_t extrudeScale = 63;
-
- /*
- * Add a vertex to this buffer
- *
- * @param {number} x vertex position
- * @param {number} y vertex position
- * @param {number} ex extrude normal
- * @param {number} ey extrude normal
- * @param {number} tx texture normal
- * @param {number} ty texture normal
- * @param {number} dir direction of the line cap (-1/0/1)
- */
- uint32_t add(vertex_type x, vertex_type y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar = 0);
-};
-
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/static_vertex_buffer.cpp b/src/mbgl/geometry/static_vertex_buffer.cpp
deleted file mode 100644
index c66b194748..0000000000
--- a/src/mbgl/geometry/static_vertex_buffer.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <mbgl/geometry/static_vertex_buffer.hpp>
-#include <mbgl/gl/gl.hpp>
-
-namespace mbgl {
-
-StaticVertexBuffer::StaticVertexBuffer(std::initializer_list<std::array<VertexType, 2>> init) {
- for (const auto& vertex : init) {
- VertexType* vertices = static_cast<VertexType*>(addElement());
- vertices[0] = std::get<0>(vertex);
- vertices[1] = std::get<1>(vertex);
- }
-}
-
-StaticRasterVertexBuffer::StaticRasterVertexBuffer(std::initializer_list<std::array<VertexType, 4>> init) {
- for (const auto& vertex : init) {
- VertexType* vertices = static_cast<VertexType*>(addElement());
- vertices[0] = std::get<0>(vertex);
- vertices[1] = std::get<1>(vertex);
- vertices[2] = std::get<2>(vertex);
- vertices[3] = std::get<3>(vertex);
- }
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/static_vertex_buffer.hpp b/src/mbgl/geometry/static_vertex_buffer.hpp
deleted file mode 100644
index edf3b966fd..0000000000
--- a/src/mbgl/geometry/static_vertex_buffer.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-
-#include <array>
-#include <cstdint>
-
-namespace mbgl {
-
-class StaticVertexBuffer : public Buffer<
- 4, // bytes per vertex (2 * signed short == 4 bytes)
- gl::BufferType::Vertex,
- 32 // default length
-> {
-public:
- using VertexType = int16_t;
- StaticVertexBuffer(std::initializer_list<std::array<VertexType, 2>>);
-};
-
-class StaticRasterVertexBuffer : public Buffer<
- 8, // bytes per vertex (4 * signed short == 8 bytes)
- gl::BufferType::Vertex,
- 32 // default length
-> {
-public:
- using VertexType = int16_t;
- StaticRasterVertexBuffer(std::initializer_list<std::array<VertexType, 4>>);
-};
-
-} // namespace mbgl
diff --git a/src/mbgl/geometry/text_buffer.cpp b/src/mbgl/geometry/text_buffer.cpp
deleted file mode 100644
index 8fed7a71d1..0000000000
--- a/src/mbgl/geometry/text_buffer.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <mbgl/geometry/text_buffer.hpp>
-#include <mbgl/gl/gl.hpp>
-#include <mbgl/util/math.hpp>
-
-#include <cmath>
-
-namespace mbgl {
-
-uint32_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle) {
- const uint32_t idx = index();
- void *data = addElement();
-
- int16_t *shorts = static_cast<int16_t *>(data);
- shorts[0] /* pos */ = x;
- shorts[1] /* pos */ = y;
- shorts[2] /* offset */ = ::round(ox * 64); // use 1/64 pixels for placement
- shorts[3] /* offset */ = ::round(oy * 64);
-
- uint16_t *ushorts = static_cast<uint16_t *>(data);
- // a_texture_pos
- ushorts[4] /* tex */ = tx / 4;
- ushorts[5] /* tex */ = ty / 4;
-
- uint8_t *ubytes = static_cast<uint8_t *>(data);
- // a_data
- ubytes[12] /* labelminzoom */ = labelminzoom * 10;
- ubytes[13] /* labelangle */ = labelangle;
-
- ubytes[14] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160.
- ubytes[15] /* maxzoom */ = ::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
-
- return idx;
-}
-
-} // namespace mbgl
-
diff --git a/src/mbgl/geometry/text_buffer.hpp b/src/mbgl/geometry/text_buffer.hpp
deleted file mode 100644
index 4b46a38770..0000000000
--- a/src/mbgl/geometry/text_buffer.hpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include <mbgl/geometry/buffer.hpp>
-#include <array>
-
-namespace mbgl {
-
-class TextVertexBuffer : public Buffer <
- 16,
- gl::BufferType::Vertex,
- 32768
-> {
-public:
- typedef int16_t vertex_type;
-
- uint32_t add(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle);
-};
-
-
-} // namespace mbgl
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index ded7936feb..5837aa3399 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -91,10 +91,22 @@ UniqueShader Context::createFragmentShader() {
return UniqueShader{ MBGL_CHECK_ERROR(glCreateShader(GL_FRAGMENT_SHADER)), { this } };
}
-UniqueBuffer Context::createBuffer() {
+UniqueBuffer Context::createVertexBuffer(const void* data, std::size_t size) {
BufferID id = 0;
MBGL_CHECK_ERROR(glGenBuffers(1, &id));
- return UniqueBuffer{ std::move(id), { this } };
+ UniqueBuffer result { std::move(id), { this } };
+ vertexBuffer = result;
+ MBGL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW));
+ return result;
+}
+
+UniqueBuffer Context::createIndexBuffer(const void* data, std::size_t size) {
+ BufferID id = 0;
+ MBGL_CHECK_ERROR(glGenBuffers(1, &id));
+ UniqueBuffer result { std::move(id), { this } };
+ elementBuffer = result;
+ MBGL_CHECK_ERROR(glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, GL_STATIC_DRAW));
+ return result;
}
UniqueTexture Context::createTexture() {
@@ -120,10 +132,6 @@ UniqueFramebuffer Context::createFramebuffer() {
return UniqueFramebuffer{ std::move(id), { this } };
}
-void Context::uploadBuffer(BufferType type, size_t size, void* data) {
- MBGL_CHECK_ERROR(glBufferData(static_cast<GLenum>(type), size, data, GL_STATIC_DRAW));
-}
-
UniqueTexture
Context::createTexture(uint16_t width, uint16_t height, const void* data, TextureUnit unit) {
auto obj = createTexture();
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 0ec846033a..e26b35e7c0 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -4,6 +4,8 @@
#include <mbgl/gl/state.hpp>
#include <mbgl/gl/value.hpp>
#include <mbgl/gl/texture.hpp>
+#include <mbgl/gl/vertex_buffer.hpp>
+#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <memory>
@@ -22,12 +24,24 @@ public:
UniqueProgram createProgram();
UniqueShader createVertexShader();
UniqueShader createFragmentShader();
- UniqueBuffer createBuffer();
UniqueTexture createTexture();
UniqueVertexArray createVertexArray();
UniqueFramebuffer createFramebuffer();
- void uploadBuffer(BufferType, size_t, void*);
+ template <class V>
+ VertexBuffer<V> createVertexBuffer(std::vector<V>&& v) {
+ return VertexBuffer<V> {
+ v.size(),
+ createVertexBuffer(v.data(), v.size() * sizeof(V))
+ };
+ }
+
+ template <class P>
+ IndexBuffer<P> createIndexBuffer(std::vector<P>&& v) {
+ return IndexBuffer<P> {
+ createIndexBuffer(v.data(), v.size() * sizeof(P))
+ };
+ }
// Create a texture from an image with data.
template <typename Image>
@@ -98,9 +112,10 @@ public:
State<value::BindVertexArray> vertexArrayObject;
private:
+ UniqueBuffer createVertexBuffer(const void* data, std::size_t size);
+ UniqueBuffer createIndexBuffer(const void* data, std::size_t size);
UniqueTexture createTexture(uint16_t width, uint16_t height, const void* data, TextureUnit);
-private:
friend detail::ProgramDeleter;
friend detail::ShaderDeleter;
friend detail::BufferDeleter;
diff --git a/src/mbgl/gl/element_group.hpp b/src/mbgl/gl/element_group.hpp
new file mode 100644
index 0000000000..f99a03b679
--- /dev/null
+++ b/src/mbgl/gl/element_group.hpp
@@ -0,0 +1,25 @@
+#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/index_buffer.hpp b/src/mbgl/gl/index_buffer.hpp
new file mode 100644
index 0000000000..f38d7fd4f5
--- /dev/null
+++ b/src/mbgl/gl/index_buffer.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <mbgl/gl/object.hpp>
+
+namespace mbgl {
+namespace gl {
+
+class Line {
+public:
+ Line(uint16_t a_, uint16_t b_)
+ : a(a_), b(b_) {}
+
+ uint16_t a;
+ uint16_t b;
+
+ static constexpr std::size_t IndexCount = 2;
+};
+
+class Triangle {
+public:
+ Triangle(uint16_t a_, uint16_t b_, uint16_t c_)
+ : a(a_), b(b_), c(c_) {}
+
+ uint16_t a;
+ uint16_t b;
+ uint16_t c;
+
+ static constexpr std::size_t IndexCount = 3;
+};
+
+template <class Primitive>
+class IndexBuffer {
+public:
+ static_assert(std::is_same<Primitive, Line>::value || std::is_same<Primitive, Triangle>::value,
+ "primitive must be Line or Triangle");
+ static constexpr std::size_t primitiveSize = sizeof(Primitive);
+ UniqueBuffer buffer;
+};
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/geometry/vao.cpp b/src/mbgl/gl/vao.cpp
index 2c5e1677ff..527dd214fb 100644
--- a/src/mbgl/geometry/vao.cpp
+++ b/src/mbgl/gl/vao.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/geometry/vao.hpp>
+#include <mbgl/gl/vao.hpp>
#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/string.hpp>
diff --git a/src/mbgl/geometry/vao.hpp b/src/mbgl/gl/vao.hpp
index 65abab1e4e..c2e3470367 100644
--- a/src/mbgl/geometry/vao.hpp
+++ b/src/mbgl/gl/vao.hpp
@@ -2,6 +2,7 @@
#include <mbgl/shader/shader.hpp>
#include <mbgl/gl/context.hpp>
+#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
@@ -14,39 +15,39 @@ public:
VertexArrayObject();
~VertexArrayObject();
- template <typename VertexBuffer>
+ template <typename Shader, typename T>
void bind(Shader& shader,
- VertexBuffer& vertexBuffer,
+ const gl::VertexBuffer<T>& vertexBuffer,
int8_t* offset,
gl::Context& context) {
bindVertexArrayObject(context);
if (bound_shader == 0) {
- vertexBuffer.bind(context);
- shader.bind(offset);
+ context.vertexBuffer = vertexBuffer.buffer;
+ shader.bind(vertexBuffer, offset);
if (vertexArray) {
- storeBinding(shader, vertexBuffer.getID(), 0, offset);
+ storeBinding(shader, vertexBuffer.buffer, 0, offset);
}
} else {
- verifyBinding(shader, vertexBuffer.getID(), 0, offset);
+ verifyBinding(shader, vertexBuffer.buffer, 0, offset);
}
}
- template <typename VertexBuffer, typename ElementsBuffer>
+ template <typename Shader, typename T, typename P>
void bind(Shader& shader,
- VertexBuffer& vertexBuffer,
- ElementsBuffer& elementsBuffer,
+ const gl::VertexBuffer<T>& vertexBuffer,
+ const gl::IndexBuffer<P>& indexBuffer,
int8_t* offset,
gl::Context& context) {
bindVertexArrayObject(context);
if (bound_shader == 0) {
- vertexBuffer.bind(context);
- elementsBuffer.bind(context);
- shader.bind(offset);
+ context.vertexBuffer = vertexBuffer.buffer;
+ context.elementBuffer = indexBuffer.buffer;
+ shader.bind(vertexBuffer, offset);
if (vertexArray) {
- storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
+ storeBinding(shader, vertexBuffer.buffer, indexBuffer.buffer, offset);
}
} else {
- verifyBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
+ verifyBinding(shader, vertexBuffer.buffer, indexBuffer.buffer, offset);
}
}
diff --git a/src/mbgl/gl/vertex_buffer.hpp b/src/mbgl/gl/vertex_buffer.hpp
new file mode 100644
index 0000000000..c77a9a4213
--- /dev/null
+++ b/src/mbgl/gl/vertex_buffer.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <mbgl/gl/object.hpp>
+
+namespace mbgl {
+namespace gl {
+
+template <class Vertex>
+class VertexBuffer {
+public:
+ static constexpr std::size_t vertexSize = sizeof(Vertex);
+ std::size_t vertexCount;
+ UniqueBuffer buffer;
+};
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index fdd66095fe..1400125dd9 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -464,18 +464,22 @@ void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
uint8_t glyphAngle = std::round((symbol.glyphAngle / (M_PI * 2)) * 256);
// coordinates (2 triangles)
- buffer.vertices.add(anchorPoint.x, anchorPoint.y, tl.x, tl.y, tex.x, tex.y, minZoom,
+ buffer.vertices.emplace_back(anchorPoint.x, anchorPoint.y, tl.x, tl.y, tex.x, tex.y, minZoom,
maxZoom, placementZoom, glyphAngle);
- buffer.vertices.add(anchorPoint.x, anchorPoint.y, tr.x, tr.y, tex.x + tex.w, tex.y,
+ buffer.vertices.emplace_back(anchorPoint.x, anchorPoint.y, tr.x, tr.y, tex.x + tex.w, tex.y,
minZoom, maxZoom, placementZoom, glyphAngle);
- buffer.vertices.add(anchorPoint.x, anchorPoint.y, bl.x, bl.y, tex.x, tex.y + tex.h,
+ buffer.vertices.emplace_back(anchorPoint.x, anchorPoint.y, bl.x, bl.y, tex.x, tex.y + tex.h,
minZoom, maxZoom, placementZoom, glyphAngle);
- buffer.vertices.add(anchorPoint.x, anchorPoint.y, br.x, br.y, tex.x + tex.w, tex.y + tex.h,
+ buffer.vertices.emplace_back(anchorPoint.x, anchorPoint.y, br.x, br.y, tex.x + tex.w, tex.y + tex.h,
minZoom, maxZoom, placementZoom, glyphAngle);
// add the two triangles, referencing the four coordinates we just inserted.
- buffer.triangles.add(triangleIndex + 0, triangleIndex + 1, triangleIndex + 2);
- buffer.triangles.add(triangleIndex + 1, triangleIndex + 2, triangleIndex + 3);
+ 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;
@@ -517,14 +521,14 @@ void SymbolLayout::addToDebugBuffers(CollisionTile& collisionTile, SymbolBucket&
collisionBox.groups.emplace_back(std::make_unique<SymbolBucket::CollisionBoxElementGroup>());
}
- collisionBox.vertices.add(anchor.x, anchor.y, tl.x, tl.y, maxZoom, placementZoom);
- collisionBox.vertices.add(anchor.x, anchor.y, tr.x, tr.y, maxZoom, placementZoom);
- collisionBox.vertices.add(anchor.x, anchor.y, tr.x, tr.y, maxZoom, placementZoom);
- collisionBox.vertices.add(anchor.x, anchor.y, br.x, br.y, maxZoom, placementZoom);
- collisionBox.vertices.add(anchor.x, anchor.y, br.x, br.y, maxZoom, placementZoom);
- collisionBox.vertices.add(anchor.x, anchor.y, bl.x, bl.y, maxZoom, placementZoom);
- collisionBox.vertices.add(anchor.x, anchor.y, bl.x, bl.y, maxZoom, placementZoom);
- collisionBox.vertices.add(anchor.x, anchor.y, tl.x, tl.y, maxZoom, placementZoom);
+ collisionBox.vertices.emplace_back(anchor.x, anchor.y, tl.x, tl.y, maxZoom, placementZoom);
+ collisionBox.vertices.emplace_back(anchor.x, anchor.y, tr.x, tr.y, maxZoom, placementZoom);
+ collisionBox.vertices.emplace_back(anchor.x, anchor.y, tr.x, tr.y, maxZoom, placementZoom);
+ collisionBox.vertices.emplace_back(anchor.x, anchor.y, br.x, br.y, maxZoom, placementZoom);
+ collisionBox.vertices.emplace_back(anchor.x, anchor.y, br.x, br.y, maxZoom, placementZoom);
+ collisionBox.vertices.emplace_back(anchor.x, anchor.y, bl.x, bl.y, maxZoom, placementZoom);
+ 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;
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index e04f7f3900..d5894504e0 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -22,6 +22,7 @@
#include <mbgl/util/mapbox.hpp>
#include <mbgl/util/tile_coordinate.hpp>
#include <mbgl/actor/thread_pool.hpp>
+#include <mbgl/platform/log.hpp>
namespace mbgl {
diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp
index 7b10fafc93..097410ce3b 100644
--- a/src/mbgl/renderer/circle_bucket.cpp
+++ b/src/mbgl/renderer/circle_bucket.cpp
@@ -18,8 +18,8 @@ CircleBucket::~CircleBucket() {
}
void CircleBucket::upload(gl::Context& context) {
- vertexBuffer_.upload(context);
- elementsBuffer_.upload(context);
+ vertexBuffer = context.createVertexBuffer(std::move(vertices));
+ indexBuffer = context.createIndexBuffer(std::move(triangles));
uploaded = true;
}
@@ -31,7 +31,7 @@ void CircleBucket::render(Painter& painter,
}
bool CircleBucket::hasData() const {
- return !triangleGroups_.empty();
+ return !triangleGroups.empty();
}
bool CircleBucket::needsClipping() const {
@@ -59,23 +59,27 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
// │ 1 2 │
// └─────────┘
//
- vertexBuffer_.add(x, y, -1, -1); // 1
- vertexBuffer_.add(x, y, 1, -1); // 2
- vertexBuffer_.add(x, y, 1, 1); // 3
- vertexBuffer_.add(x, y, -1, 1); // 4
+ vertices.emplace_back(x, y, -1, -1); // 1
+ vertices.emplace_back(x, y, 1, -1); // 2
+ 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 (!triangleGroups.size() || (triangleGroups.back()->vertex_length + 4 > 65535)) {
// Move to a new group because the old one can't hold the geometry.
- triangleGroups_.emplace_back(std::make_unique<TriangleGroup>());
+ triangleGroups.emplace_back(std::make_unique<TriangleGroup>());
}
- TriangleGroup& group = *triangleGroups_.back();
- auto index = group.vertex_length;
+ TriangleGroup& group = *triangleGroups.back();
+ uint16_t index = group.vertex_length;
// 1, 2, 3
// 1, 4, 3
- elementsBuffer_.add(index, index + 1, index + 2);
- elementsBuffer_.add(index, index + 3, index + 2);
+ triangles.emplace_back(index,
+ static_cast<uint16_t>(index + 1),
+ static_cast<uint16_t>(index + 2));
+ triangles.emplace_back(index,
+ static_cast<uint16_t>(index + 3),
+ static_cast<uint16_t>(index + 2));
group.vertex_length += 4;
group.elements_length += 2;
@@ -87,17 +91,17 @@ void CircleBucket::drawCircles(CircleShader& shader, gl::Context& context) {
GLbyte* vertexIndex = BUFFER_OFFSET(0);
GLbyte* elementsIndex = BUFFER_OFFSET(0);
- for (auto& group : triangleGroups_) {
+ for (auto& group : triangleGroups) {
assert(group);
if (!group->elements_length) continue;
- group->array[0].bind(shader, vertexBuffer_, elementsBuffer_, vertexIndex, context);
+ group->array[0].bind(shader, *vertexBuffer, *indexBuffer, vertexIndex, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elementsIndex));
- vertexIndex += group->vertex_length * vertexBuffer_.itemSize;
- elementsIndex += group->elements_length * elementsBuffer_.itemSize;
+ vertexIndex += group->vertex_length * vertexBuffer->vertexSize;
+ elementsIndex += group->elements_length * indexBuffer->primitiveSize;
}
}
diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp
index 9e9357d77f..5f4f357d2f 100644
--- a/src/mbgl/renderer/circle_bucket.hpp
+++ b/src/mbgl/renderer/circle_bucket.hpp
@@ -3,17 +3,16 @@
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/geometry/elements_buffer.hpp>
-#include <mbgl/geometry/circle_buffer.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 {
-class CircleVertexBuffer;
class CircleShader;
class CircleBucket : public Bucket {
- using TriangleGroup = ElementGroup<3>;
-
public:
CircleBucket(const MapMode);
~CircleBucket() override;
@@ -28,10 +27,14 @@ public:
void drawCircles(CircleShader&, gl::Context&);
private:
- CircleVertexBuffer vertexBuffer_;
- TriangleElementsBuffer elementsBuffer_;
+ std::vector<CircleVertex> vertices;
+ std::vector<gl::Triangle> triangles;
+
+ using TriangleGroup = gl::ElementGroup<3>;
+ std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
- std::vector<std::unique_ptr<TriangleGroup>> triangleGroups_;
+ optional<gl::VertexBuffer<CircleVertex>> vertexBuffer;
+ optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
const MapMode mode;
};
diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp
index 249924abb7..e37ccbff2f 100644
--- a/src/mbgl/renderer/debug_bucket.cpp
+++ b/src/mbgl/renderer/debug_bucket.cpp
@@ -1,54 +1,101 @@
#include <mbgl/renderer/debug_bucket.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/shader/plain_shader.hpp>
+#include <mbgl/shader/plain_vertex.hpp>
+#include <mbgl/geometry/debug_font_data.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/gl/gl.hpp>
-#include <cassert>
+#include <cmath>
#include <string>
+#include <vector>
namespace mbgl {
-DebugBucket::DebugBucket(const OverscaledTileID& id,
- const bool renderable_,
- const bool complete_,
- optional<Timestamp> modified_,
- optional<Timestamp> expires_,
- MapDebugOptions debugMode_)
- : renderable(renderable_),
- complete(complete_),
- modified(std::move(modified_)),
- expires(std::move(expires_)),
- debugMode(debugMode_) {
+std::vector<PlainVertex> buildTextVertexes(const OverscaledTileID& id,
+ const bool renderable,
+ const bool complete,
+ optional<Timestamp> modified,
+ optional<Timestamp> expires,
+ MapDebugOptions debugMode) {
+ std::vector<PlainVertex> textPoints;
+
+ auto addText = [&] (const std::string& text, double left, double baseline, double scale) {
+ for (uint8_t c : text) {
+ if (c < 32 || c >= 127)
+ continue;
+
+ optional<Point<int16_t>> prev;
+
+ const glyph& glyph = simplex[c - 32];
+ for (int32_t j = 0; j < glyph.length; j += 2) {
+ if (glyph.data[j] == -1 && glyph.data[j + 1] == -1) {
+ prev = {};
+ } else {
+ Point<int16_t> p {
+ int16_t(::round(left + glyph.data[j] * scale)),
+ int16_t(::round(baseline - glyph.data[j + 1] * scale))
+ };
+
+ if (prev) {
+ textPoints.emplace_back(prev->x, prev->y);
+ textPoints.emplace_back(p.x, p.y);
+ }
+
+ prev = p;
+ }
+ }
+
+ left += glyph.width * scale;
+ }
+ };
+
double baseline = 200;
if (debugMode & MapDebugOptions::ParseStatus) {
const std::string text = util::toString(id) + " - " +
(complete ? "complete" : renderable ? "renderable" : "pending");
- fontBuffer.addText(text.c_str(), 50, baseline, 5);
+ addText(text, 50, baseline, 5);
baseline += 200;
}
if (debugMode & MapDebugOptions::Timestamps && modified && expires) {
const std::string modifiedText = "modified: " + util::iso8601(*modified);
- fontBuffer.addText(modifiedText.c_str(), 50, baseline, 5);
+ addText(modifiedText, 50, baseline, 5);
const std::string expiresText = "expires: " + util::iso8601(*expires);
- fontBuffer.addText(expiresText.c_str(), 50, baseline + 200, 5);
+ addText(expiresText, 50, baseline + 200, 5);
}
+
+ return textPoints;
+}
+
+DebugBucket::DebugBucket(const OverscaledTileID& id,
+ const bool renderable_,
+ const bool complete_,
+ optional<Timestamp> modified_,
+ optional<Timestamp> expires_,
+ MapDebugOptions debugMode_,
+ gl::Context& context)
+ : renderable(renderable_),
+ complete(complete_),
+ modified(std::move(modified_)),
+ expires(std::move(expires_)),
+ debugMode(debugMode_),
+ textVertexes(context.createVertexBuffer(buildTextVertexes(id, renderable_, complete_, modified_, expires_, debugMode_))) {
}
void DebugBucket::drawLines(PlainShader& shader, gl::Context& context) {
- if (!fontBuffer.empty()) {
- array.bind(shader, fontBuffer, BUFFER_OFFSET_0, context);
- MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, (GLsizei)(fontBuffer.index())));
+ if (textVertexes.vertexCount != 0) {
+ array.bind(shader, textVertexes, BUFFER_OFFSET_0, context);
+ MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(textVertexes.vertexCount)));
}
}
void DebugBucket::drawPoints(PlainShader& shader, gl::Context& context) {
- if (!fontBuffer.empty()) {
- array.bind(shader, fontBuffer, BUFFER_OFFSET_0, context);
- MBGL_CHECK_ERROR(glDrawArrays(GL_POINTS, 0, (GLsizei)(fontBuffer.index())));
+ if (textVertexes.vertexCount != 0) {
+ array.bind(shader, textVertexes, BUFFER_OFFSET_0, context);
+ MBGL_CHECK_ERROR(glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(textVertexes.vertexCount)));
}
}
diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp
index 51315967da..59c1e315ea 100644
--- a/src/mbgl/renderer/debug_bucket.hpp
+++ b/src/mbgl/renderer/debug_bucket.hpp
@@ -1,9 +1,13 @@
#pragma once
#include <mbgl/map/mode.hpp>
-#include <mbgl/geometry/debug_font_buffer.hpp>
-#include <mbgl/geometry/vao.hpp>
#include <mbgl/util/chrono.hpp>
+#include <mbgl/util/geometry.hpp>
+#include <mbgl/util/optional.hpp>
+#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/gl/vertex_buffer.hpp>
+#include <mbgl/gl/vao.hpp>
+#include <mbgl/shader/plain_vertex.hpp>
namespace mbgl {
@@ -21,7 +25,8 @@ public:
bool complete,
optional<Timestamp> modified,
optional<Timestamp> expires,
- MapDebugOptions);
+ MapDebugOptions,
+ gl::Context&);
void drawLines(PlainShader&, gl::Context&);
void drawPoints(PlainShader&, gl::Context&);
@@ -33,7 +38,7 @@ public:
const MapDebugOptions debugMode;
private:
- DebugFontBuffer fontBuffer;
+ gl::VertexBuffer<PlainVertex> textVertexes;
VertexArrayObject array;
};
diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp
index d07fe5c725..9213c9a777 100644
--- a/src/mbgl/renderer/fill_bucket.cpp
+++ b/src/mbgl/renderer/fill_bucket.cpp
@@ -58,14 +58,16 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
lineGroups.emplace_back(std::make_unique<LineGroup>());
LineGroup& lineGroup = *lineGroups.back();
- GLsizei lineIndex = lineGroup.vertex_length;
+ uint16_t lineIndex = lineGroup.vertex_length;
- vertexBuffer.add(ring[0].x, ring[0].y);
- lineElementsBuffer.add(lineIndex + nVertices - 1, lineIndex);
+ vertices.emplace_back(ring[0].x, ring[0].y);
+ lines.emplace_back(static_cast<uint16_t>(lineIndex + nVertices - 1),
+ static_cast<uint16_t>(lineIndex));
for (uint32_t i = 1; i < nVertices; i++) {
- vertexBuffer.add(ring[i].x, ring[i].y);
- lineElementsBuffer.add(lineIndex + i - 1, lineIndex + i);
+ vertices.emplace_back(ring[i].x, ring[i].y);
+ lines.emplace_back(static_cast<uint16_t>(lineIndex + i - 1),
+ static_cast<uint16_t>(lineIndex + i));
}
lineGroup.vertex_length += nVertices;
@@ -82,12 +84,12 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
}
TriangleGroup& triangleGroup = *triangleGroups.back();
- GLsizei triangleIndex = triangleGroup.vertex_length;
+ uint16_t triangleIndex = triangleGroup.vertex_length;
for (uint32_t i = 0; i < nIndicies; i += 3) {
- triangleElementsBuffer.add(triangleIndex + indices[i],
- triangleIndex + indices[i + 1],
- triangleIndex + indices[i + 2]);
+ triangles.emplace_back(static_cast<uint16_t>(triangleIndex + indices[i]),
+ static_cast<uint16_t>(triangleIndex + indices[i + 1]),
+ static_cast<uint16_t>(triangleIndex + indices[i + 2]));
}
triangleGroup.vertex_length += totalVertices;
@@ -96,9 +98,9 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
}
void FillBucket::upload(gl::Context& context) {
- vertexBuffer.upload(context);
- triangleElementsBuffer.upload(context);
- lineElementsBuffer.upload(context);
+ vertexBuffer = context.createVertexBuffer(std::move(vertices));
+ lineIndexBuffer = context.createIndexBuffer(std::move(lines));
+ triangleIndexBuffer = context.createIndexBuffer(std::move(triangles));
// From now on, we're going to render during the opaque and translucent pass.
uploaded = true;
@@ -127,11 +129,11 @@ void FillBucket::drawElements(PlainShader& shader,
for (auto& group : triangleGroups) {
assert(group);
group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
- shader, vertexBuffer, triangleElementsBuffer, vertex_index, context);
+ shader, *vertexBuffer, *triangleIndexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer.itemSize;
- elements_index += group->elements_length * triangleElementsBuffer.itemSize;
+ vertex_index += group->vertex_length * vertexBuffer->vertexSize;
+ elements_index += group->elements_length * triangleIndexBuffer->primitiveSize;
}
}
@@ -143,11 +145,11 @@ void FillBucket::drawElements(PatternShader& shader,
for (auto& group : triangleGroups) {
assert(group);
group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind(
- shader, vertexBuffer, triangleElementsBuffer, vertex_index, context);
+ shader, *vertexBuffer, *triangleIndexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer.itemSize;
- elements_index += group->elements_length * triangleElementsBuffer.itemSize;
+ vertex_index += group->vertex_length * vertexBuffer->vertexSize;
+ elements_index += group->elements_length * triangleIndexBuffer->primitiveSize;
}
}
@@ -159,11 +161,11 @@ void FillBucket::drawVertices(OutlineShader& shader,
for (auto& group : lineGroups) {
assert(group);
group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
- shader, vertexBuffer, lineElementsBuffer, vertex_index, context);
+ shader, *vertexBuffer, *lineIndexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_LINES, group->elements_length * 2, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer.itemSize;
- elements_index += group->elements_length * lineElementsBuffer.itemSize;
+ vertex_index += group->vertex_length * vertexBuffer->vertexSize;
+ elements_index += group->elements_length * lineIndexBuffer->primitiveSize;
}
}
@@ -175,11 +177,11 @@ void FillBucket::drawVertices(OutlinePatternShader& shader,
for (auto& group : lineGroups) {
assert(group);
group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind(
- shader, vertexBuffer, lineElementsBuffer, vertex_index, context);
+ shader, *vertexBuffer, *lineIndexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_LINES, group->elements_length * 2, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer.itemSize;
- elements_index += group->elements_length * lineElementsBuffer.itemSize;
+ vertex_index += group->vertex_length * vertexBuffer->vertexSize;
+ elements_index += group->elements_length * lineIndexBuffer->primitiveSize;
}
}
diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp
index 2e6d390bfe..9392bb5cf3 100644
--- a/src/mbgl/renderer/fill_bucket.hpp
+++ b/src/mbgl/renderer/fill_bucket.hpp
@@ -2,8 +2,10 @@
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/geometry/elements_buffer.hpp>
-#include <mbgl/geometry/fill_buffer.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>
#include <vector>
#include <memory>
@@ -33,15 +35,18 @@ public:
void drawVertices(OutlinePatternShader&, gl::Context&, PaintMode);
private:
- FillVertexBuffer vertexBuffer;
- TriangleElementsBuffer triangleElementsBuffer;
- LineElementsBuffer lineElementsBuffer;
+ std::vector<PlainVertex> vertices;
+ std::vector<gl::Line> lines;
+ std::vector<gl::Triangle> triangles;
- typedef ElementGroup<4> TriangleGroup;
- typedef ElementGroup<4> LineGroup;
-
- std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
+ typedef gl::ElementGroup<4> LineGroup;
+ typedef gl::ElementGroup<4> TriangleGroup;
std::vector<std::unique_ptr<LineGroup>> lineGroups;
+ std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
+
+ optional<gl::VertexBuffer<PlainVertex>> vertexBuffer;
+ optional<gl::IndexBuffer<gl::Line>> lineIndexBuffer;
+ optional<gl::IndexBuffer<gl::Triangle>> triangleIndexBuffer;
};
} // namespace mbgl
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index f892a01ea1..23c8b449b3 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -1,6 +1,5 @@
#include <mbgl/renderer/line_bucket.hpp>
#include <mbgl/style/layers/line_layer.hpp>
-#include <mbgl/geometry/elements_buffer.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/shader/line_shader.hpp>
#include <mbgl/shader/linesdf_shader.hpp>
@@ -101,7 +100,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
nextNormal = util::perp(util::unit(convertPoint<double>(firstCoordinate - *currentCoordinate)));
}
- const int32_t startVertex = vertexBuffer.index();
+ const std::size_t startVertex = vertices.size();
std::vector<TriangleElement> triangleStore;
for (GLsizei i = 0; i < len; ++i) {
@@ -350,8 +349,8 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
startOfLine = false;
}
- const GLsizei endVertex = vertexBuffer.index();
- const GLsizei vertexCount = endVertex - startVertex;
+ const std::size_t endVertex = vertices.size();
+ const std::size_t vertexCount = endVertex - startVertex;
// Store the triangle/line groups.
{
@@ -362,10 +361,12 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
assert(triangleGroups.back());
auto& group = *triangleGroups.back();
+ uint16_t index = group.vertex_length;
+
for (const auto& triangle : triangleStore) {
- triangleElementsBuffer.add(group.vertex_length + triangle.a,
- group.vertex_length + triangle.b,
- group.vertex_length + triangle.c);
+ 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;
@@ -379,15 +380,15 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate,
double endLeft,
double endRight,
bool round,
- int32_t startVertex,
+ std::size_t startVertex,
std::vector<TriangleElement>& triangleStore) {
int8_t tx = round ? 1 : 0;
Point<double> extrude = normal;
if (endLeft)
extrude = extrude - (util::perp(normal) * endLeft);
- e3 = vertexBuffer.add(currentCoordinate.x, currentCoordinate.y, extrude.x, extrude.y, tx, 0, endLeft, distance * LINE_DISTANCE_SCALE)
- - startVertex;
+ vertices.emplace_back(currentCoordinate.x, currentCoordinate.y, extrude.x, extrude.y, tx, 0, endLeft, distance * LINE_DISTANCE_SCALE);
+ e3 = vertices.size() - 1 - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}
@@ -397,8 +398,8 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate,
extrude = normal * -1.0;
if (endRight)
extrude = extrude - (util::perp(normal) * endRight);
- e3 = vertexBuffer.add(currentCoordinate.x, currentCoordinate.y, extrude.x, extrude.y, tx, 1, -endRight, distance * LINE_DISTANCE_SCALE)
- - startVertex;
+ vertices.emplace_back(currentCoordinate.x, currentCoordinate.y, extrude.x, extrude.y, tx, 1, -endRight, distance * LINE_DISTANCE_SCALE);
+ e3 = vertices.size() - 1 - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}
@@ -419,13 +420,13 @@ void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex,
double distance,
const Point<double>& extrude,
bool lineTurnsLeft,
- int32_t startVertex,
+ std::size_t startVertex,
std::vector<TriangleElement>& triangleStore) {
int8_t ty = lineTurnsLeft;
Point<double> flippedExtrude = extrude * (lineTurnsLeft ? -1.0 : 1.0);
- e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, flippedExtrude.x, flippedExtrude.y, 0, ty, 0, distance * LINE_DISTANCE_SCALE)
- - startVertex;
+ vertices.emplace_back(currentVertex.x, currentVertex.y, flippedExtrude.x, flippedExtrude.y, 0, ty, 0, distance * LINE_DISTANCE_SCALE);
+ e3 = vertices.size() - 1 - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}
@@ -438,8 +439,8 @@ void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex,
}
void LineBucket::upload(gl::Context& context) {
- vertexBuffer.upload(context);
- triangleElementsBuffer.upload(context);
+ vertexBuffer = context.createVertexBuffer(std::move(vertices));
+ indexBuffer = context.createIndexBuffer(std::move(triangles));
// From now on, we're only going to render during the translucent pass.
uploaded = true;
@@ -471,11 +472,11 @@ void LineBucket::drawLines(LineShader& shader,
continue;
}
group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
- shader, vertexBuffer, triangleElementsBuffer, vertex_index, context);
+ shader, *vertexBuffer, *indexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer.itemSize;
- elements_index += group->elements_length * triangleElementsBuffer.itemSize;
+ vertex_index += group->vertex_length * vertexBuffer->vertexSize;
+ elements_index += group->elements_length * indexBuffer->primitiveSize;
}
}
@@ -490,11 +491,11 @@ void LineBucket::drawLineSDF(LineSDFShader& shader,
continue;
}
group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind(
- shader, vertexBuffer, triangleElementsBuffer, vertex_index, context);
+ shader, *vertexBuffer, *indexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer.itemSize;
- elements_index += group->elements_length * triangleElementsBuffer.itemSize;
+ vertex_index += group->vertex_length * vertexBuffer->vertexSize;
+ elements_index += group->elements_length * indexBuffer->primitiveSize;
}
}
@@ -509,11 +510,11 @@ void LineBucket::drawLinePatterns(LinepatternShader& shader,
continue;
}
group->array[paintMode == PaintMode::Overdraw ? 5 : 4].bind(
- shader, vertexBuffer, triangleElementsBuffer, vertex_index, context);
+ shader, *vertexBuffer, *indexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * vertexBuffer.itemSize;
- elements_index += group->elements_length * triangleElementsBuffer.itemSize;
+ vertex_index += group->vertex_length * vertexBuffer->vertexSize;
+ elements_index += group->elements_length * indexBuffer->primitiveSize;
}
}
diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp
index 5ddaca8ae8..8cb73c1d27 100644
--- a/src/mbgl/renderer/line_bucket.hpp
+++ b/src/mbgl/renderer/line_bucket.hpp
@@ -2,23 +2,21 @@
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/geometry/vao.hpp>
-#include <mbgl/geometry/elements_buffer.hpp>
-#include <mbgl/geometry/line_buffer.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>
#include <mbgl/style/layers/line_layer_properties.hpp>
#include <vector>
namespace mbgl {
-class LineVertexBuffer;
-class TriangleElementsBuffer;
class LineShader;
class LineSDFShader;
class LinepatternShader;
class LineBucket : public Bucket {
- using TriangleGroup = ElementGroup<6>;
public:
LineBucket(uint32_t overscaling);
@@ -43,24 +41,28 @@ private:
};
void addCurrentVertex(const GeometryCoordinate& currentVertex, double& distance,
const Point<double>& normal, double endLeft, double endRight, bool round,
- int32_t startVertex, std::vector<LineBucket::TriangleElement>& triangleStore);
+ std::size_t startVertex, std::vector<LineBucket::TriangleElement>& triangleStore);
void addPieSliceVertex(const GeometryCoordinate& currentVertex, double distance,
- const Point<double>& extrude, bool lineTurnsLeft, int32_t startVertex,
+ const Point<double>& extrude, bool lineTurnsLeft, std::size_t startVertex,
std::vector<TriangleElement>& triangleStore);
public:
style::LineLayoutProperties layout;
private:
- LineVertexBuffer vertexBuffer;
- TriangleElementsBuffer triangleElementsBuffer;
-
- int32_t e1;
- int32_t e2;
- int32_t e3;
+ std::vector<LineVertex> vertices;
+ std::vector<gl::Triangle> triangles;
+ using TriangleGroup = gl::ElementGroup<6>;
std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
+ optional<gl::VertexBuffer<LineVertex>> vertexBuffer;
+ optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
+
+ std::ptrdiff_t e1;
+ std::ptrdiff_t e2;
+ std::ptrdiff_t e3;
+
const uint32_t overscaling;
};
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index 4c624a0d7a..825ac053f1 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -39,7 +39,28 @@ namespace mbgl {
using namespace style;
Painter::Painter(const TransformState& state_)
- : state(state_) {
+ : state(state_),
+ tileTriangleVertexes(context.createVertexBuffer(std::vector<PlainVertex> {{
+ { 0, 0 },
+ { util::EXTENT, 0 },
+ { 0, util::EXTENT },
+ { util::EXTENT, 0 },
+ { 0, util::EXTENT },
+ { util::EXTENT, util::EXTENT }
+ }})),
+ tileLineStripVertexes(context.createVertexBuffer(std::vector<PlainVertex> {{
+ { 0, 0 },
+ { util::EXTENT, 0 },
+ { util::EXTENT, util::EXTENT },
+ { 0, util::EXTENT },
+ { 0, 0 }
+ }})),
+ rasterVertexes(context.createVertexBuffer(std::vector<RasterVertex> {{
+ { 0, 0, 0, 0 },
+ { util::EXTENT, 0, 32767, 0 },
+ { 0, util::EXTENT, 0, 32767 },
+ { util::EXTENT, util::EXTENT, 32767, 32767 }
+ }})) {
#ifndef NDEBUG
gl::debugging::enable();
#endif
@@ -109,9 +130,6 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
{
MBGL_DEBUG_GROUP("upload");
- tileStencilBuffer.upload(context);
- rasterBoundsBuffer.upload(context);
- tileBorderBuffer.upload(context);
spriteAtlas->upload(context, 0);
lineAtlas->upload(context, 0);
glyphAtlas->upload(context, 0);
diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp
index 2159881ffd..55f5c654b9 100644
--- a/src/mbgl/renderer/painter.hpp
+++ b/src/mbgl/renderer/painter.hpp
@@ -8,10 +8,10 @@
#include <mbgl/renderer/render_item.hpp>
#include <mbgl/renderer/bucket.hpp>
-#include <mbgl/geometry/vao.hpp>
-#include <mbgl/geometry/static_vertex_buffer.hpp>
-
+#include <mbgl/gl/vao.hpp>
#include <mbgl/gl/context.hpp>
+#include <mbgl/shader/plain_vertex.hpp>
+#include <mbgl/shader/raster_vertex.hpp>
#include <mbgl/style/style.hpp>
@@ -188,34 +188,9 @@ private:
std::unique_ptr<Shaders> overdrawShaders;
#endif
- // Set up the stencil quad we're using to generate the stencil mask.
- StaticVertexBuffer tileStencilBuffer {
- // top left triangle
- {{ 0, 0 }},
- {{ util::EXTENT, 0 }},
- {{ 0, util::EXTENT }},
-
- // bottom right triangle
- {{ util::EXTENT, 0 }},
- {{ 0, util::EXTENT }},
- {{ util::EXTENT, util::EXTENT }},
- };
-
- StaticRasterVertexBuffer rasterBoundsBuffer {
- {{ 0, 0, 0, 0 }},
- {{ util::EXTENT, 0, 32767, 0 }},
- {{ 0, util::EXTENT, 0, 32767 }},
- {{ util::EXTENT, util::EXTENT, 32767, 32767 }},
- };
-
- // Set up the tile boundary lines we're using to draw the tile outlines.
- StaticVertexBuffer tileBorderBuffer {
- {{ 0, 0 }},
- {{ util::EXTENT, 0 }},
- {{ util::EXTENT, util::EXTENT }},
- {{ 0, util::EXTENT }},
- {{ 0, 0 }},
- };
+ gl::VertexBuffer<PlainVertex> tileTriangleVertexes;
+ gl::VertexBuffer<PlainVertex> tileLineStripVertexes;
+ gl::VertexBuffer<RasterVertex> rasterVertexes;
VertexArrayObject tileBorderArray;
};
diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp
index af92f17c97..2dab1ccacb 100644
--- a/src/mbgl/renderer/painter_background.cpp
+++ b/src/mbgl/renderer/painter_background.cpp
@@ -46,14 +46,14 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye
patternShader.u_opacity = properties.backgroundOpacity;
spriteAtlas->bind(true, context, 0);
- arrayBackgroundPattern.bind(patternShader, tileStencilBuffer, BUFFER_OFFSET(0), context);
+ arrayBackgroundPattern.bind(patternShader, tileTriangleVertexes, BUFFER_OFFSET(0), context);
} else {
context.program = plainShader.getID();
plainShader.u_color = properties.backgroundColor;
plainShader.u_opacity = properties.backgroundOpacity;
- arrayBackground.bind(plainShader, tileStencilBuffer, BUFFER_OFFSET(0), context);
+ arrayBackground.bind(plainShader, tileTriangleVertexes, BUFFER_OFFSET(0), context);
}
context.stencilTest = false;
@@ -84,7 +84,7 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye
plainShader.u_matrix = vertexMatrix;
}
- MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)tileStencilBuffer.index()));
+ MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, static_cast<GLsizei>(tileTriangleVertexes.vertexCount)));
}
}
diff --git a/src/mbgl/renderer/painter_clipping.cpp b/src/mbgl/renderer/painter_clipping.cpp
index 03402a2695..e60e861e22 100644
--- a/src/mbgl/renderer/painter_clipping.cpp
+++ b/src/mbgl/renderer/painter_clipping.cpp
@@ -29,7 +29,7 @@ void Painter::drawClippingMasks(PaintParameters& parameters, const std::map<Unwr
context.colorMask = { false, false, false, false };
context.stencilMask = mask;
- arrayCoveringPlain.bind(plainShader, tileStencilBuffer, BUFFER_OFFSET_0, context);
+ arrayCoveringPlain.bind(plainShader, tileTriangleVertexes, BUFFER_OFFSET_0, context);
for (const auto& stencil : stencils) {
const auto& id = stencil.first;
@@ -42,7 +42,7 @@ void Painter::drawClippingMasks(PaintParameters& parameters, const std::map<Unwr
const GLint ref = (GLint)(clip.reference.to_ulong());
context.stencilFunc = { gl::StencilTestFunction::Always, ref, mask };
- MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index()));
+ MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(tileTriangleVertexes.vertexCount)));
}
}
diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp
index f19b77462a..a3fc6bff20 100644
--- a/src/mbgl/renderer/painter_debug.cpp
+++ b/src/mbgl/renderer/painter_debug.cpp
@@ -35,7 +35,7 @@ void Painter::renderDebugText(Tile& tile, const mat4 &matrix) {
tile.debugBucket->debugMode != frame.debugOptions) {
tile.debugBucket = std::make_unique<DebugBucket>(
tile.id, tile.isRenderable(), tile.isComplete(), tile.modified,
- tile.expires, frame.debugOptions);
+ tile.expires, frame.debugOptions, context);
}
auto& plainShader = shaders->plain;
@@ -80,10 +80,10 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
plainShader.u_opacity = 1.0f;
// draw tile outline
- tileBorderArray.bind(plainShader, tileBorderBuffer, BUFFER_OFFSET_0, context);
+ tileBorderArray.bind(plainShader, tileLineStripVertexes, BUFFER_OFFSET_0, context);
plainShader.u_color = { 1.0f, 0.0f, 0.0f, 1.0f };
context.lineWidth = 4.0f * frame.pixelRatio;
- MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index()));
+ MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, static_cast<GLsizei>(tileLineStripVertexes.vertexCount)));
}
#ifndef NDEBUG
diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp
index 8a05456927..243f704952 100644
--- a/src/mbgl/renderer/painter_raster.cpp
+++ b/src/mbgl/renderer/painter_raster.cpp
@@ -47,7 +47,7 @@ void Painter::renderRaster(PaintParameters& parameters,
context.depthMask = false;
setDepthSublayer(0);
- bucket.drawRaster(rasterShader, rasterBoundsBuffer, rasterVAO, context);
+ bucket.drawRaster(rasterShader, rasterVertexes, rasterVAO, context);
}
}
diff --git a/src/mbgl/renderer/raster_bucket.cpp b/src/mbgl/renderer/raster_bucket.cpp
index 3edbe3e042..c8f3987134 100644
--- a/src/mbgl/renderer/raster_bucket.cpp
+++ b/src/mbgl/renderer/raster_bucket.cpp
@@ -26,14 +26,14 @@ void RasterBucket::render(Painter& painter,
}
void RasterBucket::drawRaster(RasterShader& shader,
- StaticRasterVertexBuffer& vertices,
+ gl::VertexBuffer<RasterVertex>& vertices,
VertexArrayObject& array,
gl::Context& context) {
assert(texture);
context.bindTexture(*texture, 0, gl::TextureFilter::Linear);
context.bindTexture(*texture, 1, gl::TextureFilter::Linear);
array.bind(shader, vertices, BUFFER_OFFSET_0, context);
- MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)vertices.index()));
+ MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, static_cast<GLsizei>(vertices.vertexCount)));
}
bool RasterBucket::hasData() const {
diff --git a/src/mbgl/renderer/raster_bucket.hpp b/src/mbgl/renderer/raster_bucket.hpp
index db8138b875..1a23e62133 100644
--- a/src/mbgl/renderer/raster_bucket.hpp
+++ b/src/mbgl/renderer/raster_bucket.hpp
@@ -7,9 +7,14 @@
namespace mbgl {
class RasterShader;
+class RasterVertex;
class StaticRasterVertexBuffer;
class VertexArrayObject;
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
class RasterBucket : public Bucket {
public:
RasterBucket(PremultipliedImage&&);
@@ -19,7 +24,7 @@ public:
bool hasData() const override;
bool needsClipping() const override;
- void drawRaster(RasterShader&, StaticRasterVertexBuffer&, VertexArrayObject&, gl::Context&);
+ void drawRaster(RasterShader&, gl::VertexBuffer<RasterVertex>&, VertexArrayObject&, gl::Context&);
private:
PremultipliedImage image;
diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp
index 3ef0686e4d..0c41031c93 100644
--- a/src/mbgl/renderer/symbol_bucket.cpp
+++ b/src/mbgl/renderer/symbol_bucket.cpp
@@ -22,12 +22,17 @@ SymbolBucket::SymbolBucket(const MapMode mode_,
void SymbolBucket::upload(gl::Context& context) {
if (hasTextData()) {
- text.vertices.upload(context);
- text.triangles.upload(context);
+ text.vertexBuffer = context.createVertexBuffer(std::move(text.vertices));
+ text.indexBuffer = context.createIndexBuffer(std::move(text.triangles));
}
+
if (hasIconData()) {
- icon.vertices.upload(context);
- icon.triangles.upload(context);
+ icon.vertexBuffer = context.createVertexBuffer(std::move(icon.vertices));
+ icon.indexBuffer = context.createIndexBuffer(std::move(icon.triangles));
+ }
+
+ if (hasCollisionBoxData()) {
+ collisionBox.vertexBuffer = context.createVertexBuffer(std::move(collisionBox.vertices));
}
uploaded = true;
@@ -69,11 +74,11 @@ void SymbolBucket::drawGlyphs(SDFShader& shader,
for (auto& group : text.groups) {
assert(group);
group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
- shader, text.vertices, text.triangles, vertex_index, context);
+ shader, *text.vertexBuffer, *text.indexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * text.vertices.itemSize;
- elements_index += group->elements_length * text.triangles.itemSize;
+ vertex_index += group->vertex_length * text.vertexBuffer->vertexSize;
+ elements_index += group->elements_length * text.indexBuffer->primitiveSize;
}
}
@@ -85,11 +90,11 @@ void SymbolBucket::drawIcons(SDFShader& shader,
for (auto& group : icon.groups) {
assert(group);
group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind(
- shader, icon.vertices, icon.triangles, vertex_index, context);
+ shader, *icon.vertexBuffer, *icon.indexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * icon.vertices.itemSize;
- elements_index += group->elements_length * icon.triangles.itemSize;
+ vertex_index += group->vertex_length * icon.vertexBuffer->vertexSize;
+ elements_index += group->elements_length * icon.indexBuffer->primitiveSize;
}
}
@@ -101,11 +106,11 @@ void SymbolBucket::drawIcons(IconShader& shader,
for (auto& group : icon.groups) {
assert(group);
group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind(
- shader, icon.vertices, icon.triangles, vertex_index, context);
+ shader, *icon.vertexBuffer, *icon.indexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT,
elements_index));
- vertex_index += group->vertex_length * icon.vertices.itemSize;
- elements_index += group->elements_length * icon.triangles.itemSize;
+ vertex_index += group->vertex_length * icon.vertexBuffer->vertexSize;
+ elements_index += group->elements_length * icon.indexBuffer->primitiveSize;
}
}
@@ -113,7 +118,7 @@ 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.vertices, vertex_index, context);
+ group->array[0].bind(shader, *collisionBox.vertexBuffer, vertex_index, context);
MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, group->vertex_length));
}
}
diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp
index 87c8250d55..36511e964f 100644
--- a/src/mbgl/renderer/symbol_bucket.hpp
+++ b/src/mbgl/renderer/symbol_bucket.hpp
@@ -2,10 +2,11 @@
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/map/mode.hpp>
-#include <mbgl/geometry/elements_buffer.hpp>
-#include <mbgl/geometry/text_buffer.hpp>
-#include <mbgl/geometry/icon_buffer.hpp>
-#include <mbgl/geometry/collision_box_buffer.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>
+#include <mbgl/shader/collision_box_vertex.hpp>
#include <mbgl/text/glyph_range.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
@@ -46,25 +47,35 @@ public:
private:
friend class SymbolLayout;
- typedef ElementGroup<2> TextElementGroup;
- typedef ElementGroup<4> IconElementGroup;
- typedef ElementGroup<1> CollisionBoxElementGroup;
+ typedef gl::ElementGroup<2> TextElementGroup;
+ typedef gl::ElementGroup<4> IconElementGroup;
+ typedef gl::ElementGroup<1> CollisionBoxElementGroup;
struct TextBuffer {
- TextVertexBuffer vertices;
- TriangleElementsBuffer triangles;
+ std::vector<TextureRectVertex> vertices;
+ std::vector<gl::Triangle> triangles;
std::vector<std::unique_ptr<TextElementGroup>> groups;
+
+ optional<gl::VertexBuffer<TextureRectVertex>> vertexBuffer;
+ optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
} text;
struct IconBuffer {
- IconVertexBuffer vertices;
- TriangleElementsBuffer triangles;
+ std::vector<TextureRectVertex> vertices;
+ std::vector<gl::Triangle> triangles;
std::vector<std::unique_ptr<IconElementGroup>> groups;
+
+ optional<gl::VertexBuffer<TextureRectVertex>> vertexBuffer;
+ optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
} icon;
struct CollisionBoxBuffer {
- CollisionBoxVertexBuffer vertices;
+ std::vector<CollisionBoxVertex> vertices;
+ std::vector<gl::Line> lines;
std::vector<std::unique_ptr<CollisionBoxElementGroup>> groups;
+
+ optional<gl::VertexBuffer<CollisionBoxVertex>> vertexBuffer;
+ optional<gl::IndexBuffer<gl::Line>> indexBuffer;
} collisionBox;
};
diff --git a/src/mbgl/shader/circle_shader.cpp b/src/mbgl/shader/circle_shader.cpp
index b3430d4450..5ad6a73a1a 100644
--- a/src/mbgl/shader/circle_shader.cpp
+++ b/src/mbgl/shader/circle_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/circle_shader.hpp>
#include <mbgl/shader/circle.vertex.hpp>
#include <mbgl/shader/circle.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/circle_vertex.hpp>
namespace mbgl {
@@ -12,9 +12,9 @@ CircleShader::CircleShader(gl::Context& context, Defines defines)
context, defines) {
}
-void CircleShader::bind(int8_t* offset) {
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 4, offset));
+void CircleShader::bind(const gl::VertexBuffer<CircleVertex>&,
+ const int8_t* offset) {
+ CircleVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/circle_shader.hpp b/src/mbgl/shader/circle_shader.hpp
index b87d856775..8ea13c7e00 100644
--- a/src/mbgl/shader/circle_shader.hpp
+++ b/src/mbgl/shader/circle_shader.hpp
@@ -6,11 +6,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class CircleVertex;
+
class CircleShader : public Shader {
public:
CircleShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<CircleVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<std::array<float, 2>> u_extrude_scale = {"u_extrude_scale", *this};
diff --git a/src/mbgl/shader/circle_vertex.cpp b/src/mbgl/shader/circle_vertex.cpp
new file mode 100644
index 0000000000..3f14fc5747
--- /dev/null
+++ b/src/mbgl/shader/circle_vertex.cpp
@@ -0,0 +1,13 @@
+#include <mbgl/shader/circle_vertex.hpp>
+#include <mbgl/shader/shader.hpp>
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+
+void CircleVertex::bind(const int8_t* offset) {
+ static_assert(sizeof(CircleVertex) == 4, "expected CircleVertex size");
+
+ MBGL_BIND_VERTEX_ATTRIBUTE(CircleVertex, a_pos, offset);
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/circle_vertex.hpp b/src/mbgl/shader/circle_vertex.hpp
new file mode 100644
index 0000000000..8b4e37431b
--- /dev/null
+++ b/src/mbgl/shader/circle_vertex.hpp
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <cstdint>
+
+namespace mbgl {
+
+class CircleVertex {
+public:
+ /*
+ * @param {number} x vertex position
+ * @param {number} y vertex position
+ * @param {number} ex extrude normal
+ * @param {number} ey extrude normal
+ */
+ CircleVertex(int16_t x, int16_t y, float ex, float ey)
+ : a_pos {
+ static_cast<int16_t>((x * 2) + ((ex + 1) / 2)),
+ static_cast<int16_t>((y * 2) + ((ey + 1) / 2))
+ } {}
+
+ const int16_t a_pos[2];
+
+ static void bind(const int8_t* offset);
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/collision_box_shader.cpp b/src/mbgl/shader/collision_box_shader.cpp
index c0a24f0f6f..8fed895c86 100644
--- a/src/mbgl/shader/collision_box_shader.cpp
+++ b/src/mbgl/shader/collision_box_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/collision_box_shader.hpp>
#include <mbgl/shader/collisionbox.vertex.hpp>
#include <mbgl/shader/collisionbox.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/collision_box_vertex.hpp>
namespace mbgl {
@@ -12,17 +12,9 @@ CollisionBoxShader::CollisionBoxShader(gl::Context& context)
context) {
}
-void CollisionBoxShader::bind(GLbyte *offset) {
- const GLint stride = 12;
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_SHORT, false, stride, offset + 4));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 2, GL_UNSIGNED_BYTE, false, stride, offset + 8));
+void CollisionBoxShader::bind(const gl::VertexBuffer<CollisionBoxVertex>&,
+ const int8_t* offset) {
+ CollisionBoxVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/collision_box_shader.hpp b/src/mbgl/shader/collision_box_shader.hpp
index 65c3ca0146..fe99ef274e 100644
--- a/src/mbgl/shader/collision_box_shader.hpp
+++ b/src/mbgl/shader/collision_box_shader.hpp
@@ -5,11 +5,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class CollisionBoxVertex;
+
class CollisionBoxShader : public Shader {
public:
CollisionBoxShader(gl::Context&);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<CollisionBoxVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<float> u_scale = {"u_scale", *this};
diff --git a/src/mbgl/shader/collision_box_vertex.cpp b/src/mbgl/shader/collision_box_vertex.cpp
new file mode 100644
index 0000000000..d12433ee7d
--- /dev/null
+++ b/src/mbgl/shader/collision_box_vertex.cpp
@@ -0,0 +1,15 @@
+#include <mbgl/shader/collision_box_vertex.hpp>
+#include <mbgl/shader/shader.hpp>
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+
+void CollisionBoxVertex::bind(const int8_t* offset) {
+ static_assert(sizeof(CollisionBoxVertex) == 10, "expected CollisionBoxVertex size");
+
+ MBGL_BIND_VERTEX_ATTRIBUTE(CollisionBoxVertex, a_pos, offset);
+ MBGL_BIND_VERTEX_ATTRIBUTE(CollisionBoxVertex, a_extrude, offset);
+ MBGL_BIND_VERTEX_ATTRIBUTE(CollisionBoxVertex, a_data, offset);
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/collision_box_vertex.hpp b/src/mbgl/shader/collision_box_vertex.hpp
new file mode 100644
index 0000000000..f591a64ca1
--- /dev/null
+++ b/src/mbgl/shader/collision_box_vertex.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <cstdint>
+#include <cmath>
+
+namespace mbgl {
+
+class CollisionBoxVertex {
+public:
+ CollisionBoxVertex(int16_t x, int16_t y, float ox, float oy, float maxzoom, float placementZoom)
+ : a_pos { x, y },
+ a_extrude {
+ static_cast<int16_t>(::round(ox)),
+ static_cast<int16_t>(::round(oy))
+ },
+ a_data {
+ static_cast<uint8_t>(maxzoom * 10),
+ static_cast<uint8_t>(placementZoom * 10)
+ } {}
+
+ const int16_t a_pos[2];
+ const int16_t a_extrude[2];
+ const uint8_t a_data[2];
+
+ static void bind(const int8_t* offset);
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/icon_shader.cpp b/src/mbgl/shader/icon_shader.cpp
index d002e49a49..520c987768 100644
--- a/src/mbgl/shader/icon_shader.cpp
+++ b/src/mbgl/shader/icon_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/icon_shader.hpp>
#include <mbgl/shader/icon.vertex.hpp>
#include <mbgl/shader/icon.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/texture_rect_vertex.hpp>
namespace mbgl {
@@ -12,20 +12,9 @@ IconShader::IconShader(gl::Context& context, Defines defines)
context, defines) {
}
-void IconShader::bind(int8_t* offset) {
- const GLsizei stride = 16;
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_texture_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_texture_pos, 2, GL_UNSIGNED_SHORT, false, stride, offset + 8));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12));
+void IconShader::bind(const gl::VertexBuffer<TextureRectVertex>&,
+ const int8_t* offset) {
+ TextureRectVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/icon_shader.hpp b/src/mbgl/shader/icon_shader.hpp
index c4f24c91f7..b7d724e05d 100644
--- a/src/mbgl/shader/icon_shader.hpp
+++ b/src/mbgl/shader/icon_shader.hpp
@@ -5,11 +5,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class TextureRectVertex;
+
class IconShader : public Shader {
public:
IconShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<TextureRectVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<std::array<float, 2>> u_extrude_scale = {"u_extrude_scale", *this};
diff --git a/src/mbgl/shader/line_shader.cpp b/src/mbgl/shader/line_shader.cpp
index 684390815c..866c814384 100644
--- a/src/mbgl/shader/line_shader.cpp
+++ b/src/mbgl/shader/line_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/line_shader.hpp>
#include <mbgl/shader/line.vertex.hpp>
#include <mbgl/shader/line.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/line_vertex.hpp>
namespace mbgl {
@@ -12,12 +12,9 @@ LineShader::LineShader(gl::Context& context, Defines defines)
context, defines) {
}
-void LineShader::bind(int8_t* offset) {
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4));
+void LineShader::bind(const gl::VertexBuffer<LineVertex>&,
+ const int8_t* offset) {
+ LineVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/line_shader.hpp b/src/mbgl/shader/line_shader.hpp
index a6be32ebc3..4c1f395dfc 100644
--- a/src/mbgl/shader/line_shader.hpp
+++ b/src/mbgl/shader/line_shader.hpp
@@ -6,11 +6,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class LineVertex;
+
class LineShader : public Shader {
public:
LineShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<LineVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<Color> u_color = {"u_color", *this};
diff --git a/src/mbgl/shader/line_vertex.cpp b/src/mbgl/shader/line_vertex.cpp
new file mode 100644
index 0000000000..a7a51d9fd7
--- /dev/null
+++ b/src/mbgl/shader/line_vertex.cpp
@@ -0,0 +1,14 @@
+#include <mbgl/shader/line_vertex.hpp>
+#include <mbgl/shader/shader.hpp>
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+
+void LineVertex::bind(const int8_t* offset) {
+ static_assert(sizeof(LineVertex) == 8, "expected LineVertex size");
+
+ MBGL_BIND_VERTEX_ATTRIBUTE(LineVertex, a_pos, offset);
+ MBGL_BIND_VERTEX_ATTRIBUTE(LineVertex, a_data, offset);
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/line_vertex.hpp b/src/mbgl/shader/line_vertex.hpp
new file mode 100644
index 0000000000..8a85397539
--- /dev/null
+++ b/src/mbgl/shader/line_vertex.hpp
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <cstdint>
+#include <cmath>
+
+namespace mbgl {
+
+class LineVertex {
+public:
+ /*
+ * @param {number} x vertex position
+ * @param {number} y vertex position
+ * @param {number} ex extrude normal
+ * @param {number} ey extrude normal
+ * @param {number} tx texture normal
+ * @param {number} ty texture normal
+ * @param {number} dir direction of the line cap (-1/0/1)
+ */
+ LineVertex(int16_t x, int16_t y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar = 0)
+ : a_pos {
+ static_cast<int16_t>((x * 2) | tx),
+ static_cast<int16_t>((y * 2) | ty)
+ },
+ a_data {
+ // add 128 to store an byte in an unsigned byte
+ static_cast<uint8_t>(::round(extrudeScale * ex) + 128),
+ static_cast<uint8_t>(::round(extrudeScale * ey) + 128),
+
+ // Encode the -1/0/1 direction value into the first two bits of .z of a_data.
+ // Combine it with the lower 6 bits of `linesofar` (shifted by 2 bites to make
+ // room for the direction value). The upper 8 bits of `linesofar` are placed in
+ // the `w` component. `linesofar` is scaled down by `LINE_DISTANCE_SCALE` so that
+ // we can store longer distances while sacrificing precision.
+
+ // Encode the -1/0/1 direction value into .zw coordinates of a_data, which is normally covered
+ // by linesofar, so we need to merge them.
+ // The z component's first bit, as well as the sign bit is reserved for the direction,
+ // so we need to shift the linesofar.
+ static_cast<uint8_t>(((dir == 0 ? 0 : (dir < 0 ? -1 : 1 )) + 1) | ((linesofar & 0x3F) << 2)),
+ static_cast<uint8_t>(linesofar >> 6)
+ } {}
+
+ const int16_t a_pos[2];
+ const uint8_t a_data[4];
+
+ /*
+ * Scale the extrusion vector so that the normal length is this value.
+ * Contains the "texture" normals (-1..1). This is distinct from the extrude
+ * normals for line joins, because the x-value remains 0 for the texture
+ * normal array, while the extrude normal actually moves the vertex to create
+ * the acute/bevelled line join.
+ */
+ static const int8_t extrudeScale = 63;
+
+ static void bind(const int8_t* offset);
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/linepattern_shader.cpp b/src/mbgl/shader/linepattern_shader.cpp
index 8f755d4140..86f58d9d99 100644
--- a/src/mbgl/shader/linepattern_shader.cpp
+++ b/src/mbgl/shader/linepattern_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/linepattern_shader.hpp>
#include <mbgl/shader/linepattern.vertex.hpp>
#include <mbgl/shader/linepattern.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/line_vertex.hpp>
namespace mbgl {
@@ -12,12 +12,9 @@ LinepatternShader::LinepatternShader(gl::Context& context, Defines defines)
context, defines) {
}
-void LinepatternShader::bind(int8_t* offset) {
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4));
+void LinepatternShader::bind(const gl::VertexBuffer<LineVertex>&,
+ const int8_t* offset) {
+ LineVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/linepattern_shader.hpp b/src/mbgl/shader/linepattern_shader.hpp
index 89f64d3e1f..c6a30b6c47 100644
--- a/src/mbgl/shader/linepattern_shader.hpp
+++ b/src/mbgl/shader/linepattern_shader.hpp
@@ -5,11 +5,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class LineVertex;
+
class LinepatternShader : public Shader {
public:
LinepatternShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<LineVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<float> u_linewidth = {"u_linewidth", *this};
diff --git a/src/mbgl/shader/linesdf_shader.cpp b/src/mbgl/shader/linesdf_shader.cpp
index 788239459f..5245bc71f4 100644
--- a/src/mbgl/shader/linesdf_shader.cpp
+++ b/src/mbgl/shader/linesdf_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/linesdf_shader.hpp>
#include <mbgl/shader/linesdfpattern.vertex.hpp>
#include <mbgl/shader/linesdfpattern.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/line_vertex.hpp>
namespace mbgl {
@@ -12,12 +12,9 @@ LineSDFShader::LineSDFShader(gl::Context& context, Defines defines)
context, defines) {
}
-void LineSDFShader::bind(int8_t* offset) {
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4));
+void LineSDFShader::bind(const gl::VertexBuffer<LineVertex>&,
+ const int8_t* offset) {
+ LineVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/linesdf_shader.hpp b/src/mbgl/shader/linesdf_shader.hpp
index 4c1fd89635..def4a2a983 100644
--- a/src/mbgl/shader/linesdf_shader.hpp
+++ b/src/mbgl/shader/linesdf_shader.hpp
@@ -6,11 +6,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class LineVertex;
+
class LineSDFShader : public Shader {
public:
LineSDFShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<LineVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<Color> u_color = {"u_color", *this};
diff --git a/src/mbgl/shader/outline_shader.cpp b/src/mbgl/shader/outline_shader.cpp
index 94e981f4a6..3f7642b2c9 100644
--- a/src/mbgl/shader/outline_shader.cpp
+++ b/src/mbgl/shader/outline_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/outline_shader.hpp>
#include <mbgl/shader/outline.vertex.hpp>
#include <mbgl/shader/outline.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/plain_vertex.hpp>
namespace mbgl {
@@ -12,9 +12,9 @@ OutlineShader::OutlineShader(gl::Context& context, Defines defines)
context, defines) {
}
-void OutlineShader::bind(int8_t* offset) {
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
+void OutlineShader::bind(const gl::VertexBuffer<PlainVertex>&,
+ const int8_t* offset) {
+ PlainVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/outline_shader.hpp b/src/mbgl/shader/outline_shader.hpp
index ccd8dc4303..09fa9431c9 100644
--- a/src/mbgl/shader/outline_shader.hpp
+++ b/src/mbgl/shader/outline_shader.hpp
@@ -6,11 +6,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class PlainVertex;
+
class OutlineShader : public Shader {
public:
OutlineShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<PlainVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<Color> u_outline_color = {"u_outline_color", *this};
diff --git a/src/mbgl/shader/outlinepattern_shader.cpp b/src/mbgl/shader/outlinepattern_shader.cpp
index b33c2b2c1f..afe375f377 100644
--- a/src/mbgl/shader/outlinepattern_shader.cpp
+++ b/src/mbgl/shader/outlinepattern_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/outlinepattern_shader.hpp>
#include <mbgl/shader/outlinepattern.vertex.hpp>
#include <mbgl/shader/outlinepattern.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/plain_vertex.hpp>
namespace mbgl {
@@ -12,9 +12,9 @@ OutlinePatternShader::OutlinePatternShader(gl::Context& context, Defines defines
context, defines) {
}
-void OutlinePatternShader::bind(GLbyte *offset) {
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
+void OutlinePatternShader::bind(const gl::VertexBuffer<PlainVertex>&,
+ const int8_t* offset) {
+ PlainVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/outlinepattern_shader.hpp b/src/mbgl/shader/outlinepattern_shader.hpp
index 795d390f19..b6b1cda422 100644
--- a/src/mbgl/shader/outlinepattern_shader.hpp
+++ b/src/mbgl/shader/outlinepattern_shader.hpp
@@ -5,11 +5,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class PlainVertex;
+
class OutlinePatternShader : public Shader {
public:
OutlinePatternShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<PlainVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<std::array<float, 2>> u_pattern_tl_a = {"u_pattern_tl_a", *this};
diff --git a/src/mbgl/shader/pattern_shader.cpp b/src/mbgl/shader/pattern_shader.cpp
index dba12155f9..632775c181 100644
--- a/src/mbgl/shader/pattern_shader.cpp
+++ b/src/mbgl/shader/pattern_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/pattern_shader.hpp>
#include <mbgl/shader/pattern.vertex.hpp>
#include <mbgl/shader/pattern.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/plain_vertex.hpp>
namespace mbgl {
@@ -12,9 +12,9 @@ PatternShader::PatternShader(gl::Context& context, Defines defines)
context, defines) {
}
-void PatternShader::bind(GLbyte *offset) {
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
+void PatternShader::bind(const gl::VertexBuffer<PlainVertex>&,
+ const int8_t* offset) {
+ PlainVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/pattern_shader.hpp b/src/mbgl/shader/pattern_shader.hpp
index 6ba141a2cb..2b8590814c 100644
--- a/src/mbgl/shader/pattern_shader.hpp
+++ b/src/mbgl/shader/pattern_shader.hpp
@@ -5,11 +5,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class PlainVertex;
+
class PatternShader : public Shader {
public:
PatternShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<PlainVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<std::array<float, 2>> u_pattern_tl_a = {"u_pattern_tl_a", *this};
diff --git a/src/mbgl/shader/plain_shader.cpp b/src/mbgl/shader/plain_shader.cpp
index 8ea008c4ec..a6dce02a32 100644
--- a/src/mbgl/shader/plain_shader.cpp
+++ b/src/mbgl/shader/plain_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/plain_shader.hpp>
#include <mbgl/shader/fill.vertex.hpp>
#include <mbgl/shader/fill.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/plain_vertex.hpp>
namespace mbgl {
@@ -12,9 +12,9 @@ PlainShader::PlainShader(gl::Context& context, Defines defines)
context, defines) {
}
-void PlainShader::bind(int8_t* offset) {
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
+void PlainShader::bind(const gl::VertexBuffer<PlainVertex>&,
+ const int8_t* offset) {
+ PlainVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/plain_shader.hpp b/src/mbgl/shader/plain_shader.hpp
index 2611a5a549..7dbb212e1b 100644
--- a/src/mbgl/shader/plain_shader.hpp
+++ b/src/mbgl/shader/plain_shader.hpp
@@ -6,11 +6,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class PlainVertex;
+
class PlainShader : public Shader {
public:
PlainShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<PlainVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<Color> u_color = {"u_color", *this};
diff --git a/src/mbgl/shader/plain_vertex.cpp b/src/mbgl/shader/plain_vertex.cpp
new file mode 100644
index 0000000000..679ef05c39
--- /dev/null
+++ b/src/mbgl/shader/plain_vertex.cpp
@@ -0,0 +1,13 @@
+#include <mbgl/shader/plain_vertex.hpp>
+#include <mbgl/shader/shader.hpp>
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+
+void PlainVertex::bind(const int8_t* offset) {
+ static_assert(sizeof(PlainVertex) == 4, "expected PlainVertex size");
+
+ MBGL_BIND_VERTEX_ATTRIBUTE(PlainVertex, a_pos, offset);
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/plain_vertex.hpp b/src/mbgl/shader/plain_vertex.hpp
new file mode 100644
index 0000000000..46abbf737c
--- /dev/null
+++ b/src/mbgl/shader/plain_vertex.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <cstdint>
+
+namespace mbgl {
+
+class PlainVertex {
+public:
+ PlainVertex(int16_t x, int16_t y)
+ : a_pos { x, y } {}
+
+ const int16_t a_pos[2];
+
+ static void bind(const int8_t* offset);
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/raster_shader.cpp b/src/mbgl/shader/raster_shader.cpp
index 8133b396c6..f3909bb2ac 100644
--- a/src/mbgl/shader/raster_shader.cpp
+++ b/src/mbgl/shader/raster_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/raster_shader.hpp>
#include <mbgl/shader/raster.vertex.hpp>
#include <mbgl/shader/raster.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/raster_vertex.hpp>
namespace mbgl {
@@ -12,14 +12,9 @@ RasterShader::RasterShader(gl::Context& context, Defines defines)
context, defines) {
}
-void RasterShader::bind(int8_t* offset) {
- const GLint stride = 8;
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_texture_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_texture_pos, 2, GL_SHORT, false, stride, offset + 4));
+void RasterShader::bind(const gl::VertexBuffer<RasterVertex>&,
+ const int8_t* offset) {
+ RasterVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/raster_shader.hpp b/src/mbgl/shader/raster_shader.hpp
index e583b2337d..ca474ede15 100644
--- a/src/mbgl/shader/raster_shader.hpp
+++ b/src/mbgl/shader/raster_shader.hpp
@@ -5,11 +5,18 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class RasterVertex;
+
class RasterShader : public Shader {
public:
RasterShader(gl::Context&, Defines defines = None);
- void bind(int8_t* offset) final;
+ void bind(const gl::VertexBuffer<RasterVertex>&,
+ const int8_t* offset);
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<int32_t> u_image0 = {"u_image0", *this};
diff --git a/src/mbgl/shader/raster_vertex.cpp b/src/mbgl/shader/raster_vertex.cpp
new file mode 100644
index 0000000000..c77cacef88
--- /dev/null
+++ b/src/mbgl/shader/raster_vertex.cpp
@@ -0,0 +1,14 @@
+#include <mbgl/shader/raster_vertex.hpp>
+#include <mbgl/shader/shader.hpp>
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+
+void RasterVertex::bind(const int8_t* offset) {
+ static_assert(sizeof(RasterVertex) == 8, "expected RasterVertex size");
+
+ MBGL_BIND_VERTEX_ATTRIBUTE(RasterVertex, a_pos, offset);
+ MBGL_BIND_VERTEX_ATTRIBUTE(RasterVertex, a_texture_pos, offset);
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/raster_vertex.hpp b/src/mbgl/shader/raster_vertex.hpp
new file mode 100644
index 0000000000..b983010d3d
--- /dev/null
+++ b/src/mbgl/shader/raster_vertex.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <cstdint>
+
+namespace mbgl {
+
+class RasterVertex {
+public:
+ RasterVertex(int16_t x, int16_t y, int16_t tx, int16_t ty)
+ : a_pos {
+ x,
+ y
+ },
+ a_texture_pos {
+ tx,
+ ty
+ } {}
+
+ const int16_t a_pos[2];
+ const int16_t a_texture_pos[2];
+
+ static void bind(const int8_t* offset);
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/sdf_shader.cpp b/src/mbgl/shader/sdf_shader.cpp
index 3b4aa69535..804e96706f 100644
--- a/src/mbgl/shader/sdf_shader.cpp
+++ b/src/mbgl/shader/sdf_shader.cpp
@@ -1,7 +1,7 @@
#include <mbgl/shader/sdf_shader.hpp>
#include <mbgl/shader/sdf.vertex.hpp>
#include <mbgl/shader/sdf.fragment.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/shader/texture_rect_vertex.hpp>
namespace mbgl {
@@ -12,20 +12,9 @@ SDFShader::SDFShader(gl::Context& context, Defines defines)
context, defines) {
}
-void SDFShader::bind(int8_t* offset) {
- const int stride = 16;
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_texture_pos));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_texture_pos, 2, GL_UNSIGNED_SHORT, false, stride, offset + 8));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12));
+void SDFShader::bind(const gl::VertexBuffer<TextureRectVertex>&,
+ const int8_t* offset) {
+ TextureRectVertex::bind(offset);
}
} // namespace mbgl
diff --git a/src/mbgl/shader/sdf_shader.hpp b/src/mbgl/shader/sdf_shader.hpp
index f7fde3e539..2e7f6d6795 100644
--- a/src/mbgl/shader/sdf_shader.hpp
+++ b/src/mbgl/shader/sdf_shader.hpp
@@ -6,10 +6,19 @@
namespace mbgl {
+namespace gl {
+template <class> class VertexBuffer;
+} // namespace gl
+
+class TextureRectVertex;
+
class SDFShader : public Shader {
public:
SDFShader(gl::Context&, Defines defines = None);
+ void bind(const gl::VertexBuffer<TextureRectVertex>&,
+ const int8_t* offset);
+
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<std::array<float, 2>> u_extrude_scale = {"u_extrude_scale", *this};
Uniform<Color> u_color = {"u_color", *this};
@@ -25,8 +34,6 @@ public:
Uniform<int32_t> u_pitch_with_map = {"u_pitch_with_map", *this};
Uniform<int32_t> u_texture = {"u_texture", *this};
Uniform<int32_t> u_fadetexture = {"u_fadetexture", *this};
-
- void bind(int8_t* offset) final;
};
} // namespace mbgl
diff --git a/src/mbgl/shader/shader.hpp b/src/mbgl/shader/shader.hpp
index 91dd8ed518..977edebd7e 100644
--- a/src/mbgl/shader/shader.hpp
+++ b/src/mbgl/shader/shader.hpp
@@ -22,8 +22,6 @@ public:
gl::UniformLocation getUniformLocation(const char* uniform) const;
- virtual void bind(int8_t *offset) = 0;
-
enum Defines : bool {
None = false,
Overdraw = true,
@@ -36,6 +34,7 @@ protected:
gl::Context&,
Defines defines = Defines::None);
+public:
static constexpr gl::AttributeLocation a_pos = 0;
static constexpr gl::AttributeLocation a_extrude = 1;
static constexpr gl::AttributeLocation a_offset = 2;
diff --git a/src/mbgl/shader/texture_rect_vertex.cpp b/src/mbgl/shader/texture_rect_vertex.cpp
new file mode 100644
index 0000000000..4693ada9e7
--- /dev/null
+++ b/src/mbgl/shader/texture_rect_vertex.cpp
@@ -0,0 +1,16 @@
+#include <mbgl/shader/texture_rect_vertex.hpp>
+#include <mbgl/shader/shader.hpp>
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+
+void TextureRectVertex::bind(const int8_t* offset) {
+ static_assert(sizeof(TextureRectVertex) == 16, "expected TextureRectVertex size");
+
+ MBGL_BIND_VERTEX_ATTRIBUTE(TextureRectVertex, a_pos, offset);
+ MBGL_BIND_VERTEX_ATTRIBUTE(TextureRectVertex, a_offset, offset);
+ MBGL_BIND_VERTEX_ATTRIBUTE(TextureRectVertex, a_texture_pos, offset);
+ MBGL_BIND_VERTEX_ATTRIBUTE(TextureRectVertex, a_data, offset);
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/shader/texture_rect_vertex.hpp b/src/mbgl/shader/texture_rect_vertex.hpp
new file mode 100644
index 0000000000..e2e2526f16
--- /dev/null
+++ b/src/mbgl/shader/texture_rect_vertex.hpp
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <cstdint>
+#include <cmath>
+
+namespace mbgl {
+
+// A vertex that holds a position, offset and texture coordinate. Used for symbol layer icons and glyphs.
+class TextureRectVertex {
+public:
+ TextureRectVertex(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle)
+ : a_pos {
+ x,
+ y
+ },
+ a_offset {
+ static_cast<int16_t>(::round(ox * 64)), // use 1/64 pixels for placement
+ static_cast<int16_t>(::round(oy * 64))
+ },
+ a_texture_pos {
+ static_cast<uint16_t>(tx / 4),
+ static_cast<uint16_t>(ty / 4)
+ },
+ a_data {
+ static_cast<uint8_t>(labelminzoom * 10), // 1/10 zoom levels: z16 == 160
+ static_cast<uint8_t>(labelangle),
+ static_cast<uint8_t>(minzoom * 10),
+ static_cast<uint8_t>(::fmin(maxzoom, 25) * 10)
+ } {}
+
+ const int16_t a_pos[2];
+ const int16_t a_offset[2];
+ const uint16_t a_texture_pos[2];
+ const uint8_t a_data[4];
+
+ static void bind(const int8_t* offset);
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp
index ec0540b1ad..1375263107 100644
--- a/src/mbgl/tile/tile.cpp
+++ b/src/mbgl/tile/tile.cpp
@@ -2,6 +2,7 @@
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/renderer/debug_bucket.hpp>
#include <mbgl/util/string.hpp>
+#include <mbgl/platform/log.hpp>
namespace mbgl {