base static vertexbuffer on buffer object
This commit is contained in:
26
include/mbgl/geometry/static_vertex_buffer.hpp
Normal file
26
include/mbgl/geometry/static_vertex_buffer.hpp
Normal file
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
14
src/geometry/static_vertex_buffer.cpp
Normal file
14
src/geometry/static_vertex_buffer.cpp
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user