This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As specified in: https://github.com/mapbox/mapbox-gl-style-spec/blob/v8-circle/reference/v8.json Part of #1740.
- Loading branch information
1 parent
d1100f3
commit 9853463
Showing
29 changed files
with
497 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <mbgl/geometry/circle_buffer.hpp> | ||
|
||
#include <mbgl/platform/gl.hpp> | ||
|
||
#include <climits> | ||
|
||
using 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef MBGL_GEOMETRY_CIRCLE_BUFFER | ||
#define MBGL_GEOMETRY_CIRCLE_BUFFER | ||
|
||
#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); | ||
}; | ||
|
||
} | ||
|
||
#endif // MBGL_GEOMETRY_CIRCLE_BUFFER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <mbgl/renderer/circle_bucket.hpp> | ||
#include <mbgl/renderer/painter.hpp> | ||
|
||
#include <mbgl/shader/circle_shader.hpp> | ||
|
||
using namespace mbgl; | ||
|
||
CircleBucket::CircleBucket(CircleVertexBuffer& vertexBuffer, | ||
TriangleElementsBuffer& elementsBuffer) | ||
: vertexBuffer_(vertexBuffer) | ||
, elementsBuffer_(elementsBuffer) | ||
, vertexStart_(vertexBuffer_.index()) | ||
, elementsStart_(elementsBuffer_.index()) { | ||
} | ||
|
||
CircleBucket::~CircleBucket() { | ||
// Do not remove. header file only contains forward definitions to unique pointers. | ||
} | ||
|
||
void CircleBucket::upload() { | ||
vertexBuffer_.upload(); | ||
elementsBuffer_.upload(); | ||
uploaded = true; | ||
} | ||
|
||
void CircleBucket::render(Painter& painter, | ||
const StyleLayer& layer_desc, | ||
const TileID& id, | ||
const mat4& matrix) { | ||
painter.renderCircle(*this, layer_desc, id, matrix); | ||
} | ||
|
||
bool CircleBucket::hasData() const { | ||
return !triangleGroups_.empty(); | ||
} | ||
|
||
void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) { | ||
for (auto& circle : geometryCollection) { | ||
for(auto & geometry : circle) { | ||
auto x = geometry.x; | ||
auto y = geometry.y; | ||
|
||
// this geometry will be of the Point type, and we'll derive | ||
// two triangles from it. | ||
// | ||
// ┌─────────┐ | ||
// │ 4 3 │ | ||
// │ │ | ||
// │ 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 | ||
|
||
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>()); | ||
} | ||
|
||
TriangleGroup& group = *triangleGroups_.back(); | ||
auto index = group.vertex_length; | ||
|
||
// 1, 2, 3 | ||
// 1, 4, 3 | ||
elementsBuffer_.add(index, index + 1, index + 2); | ||
elementsBuffer_.add(index, index + 3, index + 2); | ||
|
||
group.vertex_length += 4; | ||
group.elements_length += 2; | ||
} | ||
} | ||
} | ||
|
||
void CircleBucket::drawCircles(CircleShader& shader) { | ||
char* vertexIndex = BUFFER_OFFSET(vertexStart_ * vertexBuffer_.itemSize); | ||
char* elementsIndex = BUFFER_OFFSET(elementsStart_ * elementsBuffer_.itemSize); | ||
|
||
for (auto& group : triangleGroups_) { | ||
assert(group); | ||
|
||
if (!group->elements_length) continue; | ||
|
||
group->array[0].bind(shader, vertexBuffer_, elementsBuffer_, vertexIndex); | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef MBGL_RENDERER_CIRCLE_BUCKET | ||
#define MBGL_RENDERER_CIRCLE_BUCKET | ||
|
||
#include <mbgl/renderer/bucket.hpp> | ||
|
||
#include <mbgl/map/geometry_tile.hpp> | ||
|
||
#include <mbgl/geometry/elements_buffer.hpp> | ||
#include <mbgl/geometry/circle_buffer.hpp> | ||
|
||
#include <mbgl/style/style_bucket.hpp> | ||
#include <mbgl/style/style_layout.hpp> | ||
|
||
namespace mbgl { | ||
|
||
class CircleVertexBuffer; | ||
class CircleShader; | ||
|
||
class CircleBucket : public Bucket { | ||
using TriangleGroup = ElementGroup<3>; | ||
|
||
public: | ||
CircleBucket(CircleVertexBuffer &vertexBuffer, TriangleElementsBuffer &elementsBuffer); | ||
~CircleBucket() override; | ||
|
||
void upload() override; | ||
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override; | ||
|
||
bool hasData() const; | ||
void addGeometry(const GeometryCollection&); | ||
|
||
void drawCircles(CircleShader& shader); | ||
|
||
private: | ||
CircleVertexBuffer& vertexBuffer_; | ||
TriangleElementsBuffer& elementsBuffer_; | ||
|
||
const size_t vertexStart_; | ||
const size_t elementsStart_; | ||
|
||
std::vector<std::unique_ptr<TriangleGroup>> triangleGroups_; | ||
}; | ||
|
||
} // namespace mbgl | ||
|
||
#endif // MBGL_RENDERER_CIRCLE_BUCKET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.