diff options
-rw-r--r-- | include/mbgl/geometry/static_vertex_buffer.hpp | 26 | ||||
-rw-r--r-- | include/mbgl/geometry/vertex_buffer.hpp | 40 | ||||
-rw-r--r-- | include/mbgl/renderer/painter.hpp | 28 | ||||
-rw-r--r-- | include/mbgl/renderer/raster_bucket.hpp | 6 | ||||
-rw-r--r-- | src/geometry/static_vertex_buffer.cpp | 14 | ||||
-rw-r--r-- | src/geometry/vertex_buffer.cpp | 32 | ||||
-rw-r--r-- | src/renderer/raster_bucket.cpp | 4 |
7 files changed, 59 insertions, 91 deletions
diff --git a/include/mbgl/geometry/static_vertex_buffer.hpp b/include/mbgl/geometry/static_vertex_buffer.hpp new file mode 100644 index 0000000000..ce932269f0 --- /dev/null +++ b/include/mbgl/geometry/static_vertex_buffer.hpp @@ -0,0 +1,26 @@ +#ifndef MBGL_GEOMETRY_STATIC_VERTEX_BUFFER +#define MBGL_GEOMETRY_STATIC_VERTEX_BUFFER + +#include <mbgl/geometry/buffer.hpp> + +#include <vector> +#include <cstddef> +#include <cstdint> +#include <cmath> + +namespace mbgl { + +class StaticVertexBuffer : public Buffer< + 4, // bytes per vertex (2 * signed short == 4 bytes) + GL_ARRAY_BUFFER, + 32 // default length +> { +public: + typedef int16_t vertex_type; + + StaticVertexBuffer(std::initializer_list<std::pair<int16_t, int16_t>> init); +}; + +} + +#endif diff --git a/include/mbgl/geometry/vertex_buffer.hpp b/include/mbgl/geometry/vertex_buffer.hpp deleted file mode 100644 index 05cda94245..0000000000 --- a/include/mbgl/geometry/vertex_buffer.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MBGL_GEOMETRY_VERTEX_BUFFER -#define MBGL_GEOMETRY_VERTEX_BUFFER - -#include <vector> -#include <cstddef> -#include <cstdint> -#include <cmath> - -namespace mbgl { - -class VertexBuffer { -public: - typedef int16_t vertex_type; - VertexBuffer(std::initializer_list<vertex_type> init); - ~VertexBuffer(); - - /* - * Returns the number of elements in this buffer. This is not the number of - * bytes, but rather the number of coordinates with associated information. - */ - size_t index() const; - - /* - * Transfers this buffer to the GPU and binds the buffer to the GL context. - */ - void bind(); - - /* - * Returns the OpenGL ID of the buffer object. - */ - uint32_t getID() const; - -private: - const std::vector<vertex_type> array; - uint32_t buffer = 0; -}; - -} - -#endif diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index 4cf99f102d..1ef5fee836 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -3,7 +3,7 @@ #include <mbgl/map/tile_data.hpp> #include <mbgl/geometry/vao.hpp> -#include <mbgl/geometry/vertex_buffer.hpp> +#include <mbgl/geometry/static_vertex_buffer.hpp> #include <mbgl/util/mat4.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/renderer/frame_history.hpp> @@ -176,16 +176,16 @@ public: std::unique_ptr<GaussianShader> gaussianShader; // Set up the stencil quad we're using to generate the stencil mask. - VertexBuffer tileStencilBuffer = { + StaticVertexBuffer tileStencilBuffer = { // top left triangle - 0, 0, - 4096, 0, - 0, 4096, + { 0, 0 }, + { 4096, 0 }, + { 0, 4096 }, // bottom right triangle - 4096, 0, - 0, 4096, - 4096, 4096 + { 4096, 0 }, + { 0, 4096 }, + { 4096, 4096 }, }; VertexArrayObject coveringPlainArray; @@ -197,12 +197,12 @@ public: VertexArrayObject matteArray; // Set up the tile boundary lines we're using to draw the tile outlines. - VertexBuffer tileBorderBuffer = { - 0, 0, - 4096, 0, - 4096, 4096, - 0, 4096, - 0, 0 + StaticVertexBuffer tileBorderBuffer = { + { 0, 0 }, + { 4096, 0 }, + { 4096, 4096 }, + { 0, 4096 }, + { 0, 0 }, }; VertexArrayObject tileBorderArray; diff --git a/include/mbgl/renderer/raster_bucket.hpp b/include/mbgl/renderer/raster_bucket.hpp index a68475565b..66cceac8e7 100644 --- a/include/mbgl/renderer/raster_bucket.hpp +++ b/include/mbgl/renderer/raster_bucket.hpp @@ -11,7 +11,7 @@ namespace mbgl { class RasterShader; -class VertexBuffer; +class StaticVertexBuffer; class VertexArrayObject; class RasterBucket : public Bucket { @@ -26,9 +26,9 @@ public: const StyleBucketRaster &properties; PrerenderedTexture texture; - void drawRaster(RasterShader& shader, VertexBuffer &vertices, VertexArrayObject &array); + void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array); - void drawRaster(RasterShader& shader, VertexBuffer &vertices, VertexArrayObject &array, GLuint texture); + void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture); Raster raster; diff --git a/src/geometry/static_vertex_buffer.cpp b/src/geometry/static_vertex_buffer.cpp new file mode 100644 index 0000000000..c86211c50f --- /dev/null +++ b/src/geometry/static_vertex_buffer.cpp @@ -0,0 +1,14 @@ +#include <mbgl/geometry/static_vertex_buffer.hpp> +#include <mbgl/platform/gl.hpp> + +namespace mbgl { + +StaticVertexBuffer::StaticVertexBuffer(std::initializer_list<std::pair<int16_t, int16_t>> init) { + for (const std::pair<int16_t, int16_t> &vertex : init) { + vertex_type *vertices = static_cast<vertex_type *>(addElement()); + vertices[0] = vertex.first; + vertices[1] = vertex.second; + } +} + +} diff --git a/src/geometry/vertex_buffer.cpp b/src/geometry/vertex_buffer.cpp deleted file mode 100644 index 888cc57a99..0000000000 --- a/src/geometry/vertex_buffer.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include <mbgl/geometry/vertex_buffer.hpp> -#include <mbgl/platform/gl.hpp> - -using namespace mbgl; - - -VertexBuffer::VertexBuffer(std::initializer_list<int16_t> init) : array(init) {} - -VertexBuffer::~VertexBuffer() { - if (buffer != 0) { - glDeleteBuffers(1, &buffer); - } -} - -size_t VertexBuffer::index() const { - // We store 2 coordinates per vertex + 1 linesofar + 1 extrude coord pair == 4 (== 8 bytes) - return array.size() / 2; -} - -void VertexBuffer::bind() { - if (buffer == 0) { - glGenBuffers(1, &buffer); - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(vertex_type), array.data(), GL_STATIC_DRAW); - } else { - glBindBuffer(GL_ARRAY_BUFFER, buffer); - } -} - -uint32_t VertexBuffer::getID() const { - return buffer; -}
\ No newline at end of file diff --git a/src/renderer/raster_bucket.cpp b/src/renderer/raster_bucket.cpp index ddfff119e0..10dadc03fc 100644 --- a/src/renderer/raster_bucket.cpp +++ b/src/renderer/raster_bucket.cpp @@ -17,14 +17,14 @@ bool RasterBucket::setImage(const std::string &data) { return raster.load(data); } -void RasterBucket::drawRaster(RasterShader& shader, VertexBuffer &vertices, VertexArrayObject &array) { +void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array) { raster.bind(true); shader.setImage(0); array.bind(shader, vertices, BUFFER_OFFSET(0)); glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index()); } -void RasterBucket::drawRaster(RasterShader& shader, VertexBuffer &vertices, VertexArrayObject &array, GLuint texture) { +void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture) { raster.bind(texture); shader.setImage(0); array.bind(shader, vertices, BUFFER_OFFSET(0)); |