summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-29 15:32:48 +0200
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-29 10:17:47 -0700
commitcc78b74098e02311cc646fe5b82c13641ff705fa (patch)
treeaf0219d5611f0984bf3b244a336fbc6074a44cb4 /src/mbgl/geometry
parent15aece8a30dcc1f1f97e28180edda46d05641a2d (diff)
downloadqtlocation-mapboxgl-cc78b74098e02311cc646fe5b82c13641ff705fa.tar.gz
[core] remove dependence on gl.h types
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r--src/mbgl/geometry/buffer.hpp27
-rw-r--r--src/mbgl/geometry/collision_box_buffer.hpp2
-rw-r--r--src/mbgl/geometry/elements_buffer.hpp12
-rw-r--r--src/mbgl/geometry/line_atlas.cpp8
-rw-r--r--src/mbgl/geometry/line_atlas.hpp13
-rw-r--r--src/mbgl/geometry/line_buffer.cpp5
-rw-r--r--src/mbgl/geometry/line_buffer.hpp2
-rw-r--r--src/mbgl/geometry/static_vertex_buffer.hpp4
-rw-r--r--src/mbgl/geometry/text_buffer.hpp2
-rw-r--r--src/mbgl/geometry/vao.cpp5
-rw-r--r--src/mbgl/geometry/vao.hpp11
11 files changed, 43 insertions, 48 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp
index 2faa9a9d84..5e1591f098 100644
--- a/src/mbgl/geometry/buffer.hpp
+++ b/src/mbgl/geometry/buffer.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/noncopyable.hpp>
@@ -13,15 +12,13 @@
namespace mbgl {
-template <
- GLsizei item_size,
- GLenum target = GL_ARRAY_BUFFER,
- GLsizei defaultLength = 8192,
- bool retainAfterUpload = false
->
+template <size_t item_size,
+ gl::BufferType target = gl::BufferType::Vertex,
+ size_t defaultLength = 8192,
+ bool retainAfterUpload = false>
class Buffer : private util::noncopyable {
- static_assert(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER,
- "target must be one of GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER");
+ static_assert(target == gl::BufferType::Vertex || target == gl::BufferType::Element,
+ "target must be one of gl::BufferType::Vertex or gl::BufferType::Element");
public:
~Buffer() {
@@ -30,8 +27,8 @@ public:
// Returns the number of elements in this buffer. This is not the number of
// bytes, but rather the number of coordinates with associated information.
- GLsizei index() const {
- return static_cast<GLsizei>(pos / itemSize);
+ size_t index() const {
+ return static_cast<size_t>(pos / itemSize);
}
bool empty() const {
@@ -45,7 +42,7 @@ public:
buffer = context.createBuffer();
}
- if (target == GL_ARRAY_BUFFER) {
+ if (target == gl::BufferType::Vertex) {
context.vertexBuffer = *buffer;
} else {
context.elementBuffer = *buffer;
@@ -56,7 +53,7 @@ public:
Log::Debug(Event::OpenGL, "Buffer doesn't contain elements");
pos = 0;
}
- MBGL_CHECK_ERROR(glBufferData(target, pos, array, GL_STATIC_DRAW));
+ context.uploadBuffer(target, pos, array);
if (!retainAfterUpload) {
cleanup();
}
@@ -103,10 +100,10 @@ public:
private:
// CPU buffer
- GLvoid *array = nullptr;
+ void* array = nullptr;
// Byte position where we are writing.
- GLsizeiptr pos = 0;
+ size_t pos = 0;
// Number of bytes that are valid in this buffer.
size_t length = 0;
diff --git a/src/mbgl/geometry/collision_box_buffer.hpp b/src/mbgl/geometry/collision_box_buffer.hpp
index b2756dd97a..3e4cdb99d2 100644
--- a/src/mbgl/geometry/collision_box_buffer.hpp
+++ b/src/mbgl/geometry/collision_box_buffer.hpp
@@ -7,7 +7,7 @@ namespace mbgl {
class CollisionBoxVertexBuffer : public Buffer <
12,
- GL_ARRAY_BUFFER,
+ gl::BufferType::Vertex,
32768
> {
public:
diff --git a/src/mbgl/geometry/elements_buffer.hpp b/src/mbgl/geometry/elements_buffer.hpp
index 5fdff0c678..d955d4a8af 100644
--- a/src/mbgl/geometry/elements_buffer.hpp
+++ b/src/mbgl/geometry/elements_buffer.hpp
@@ -9,13 +9,13 @@
namespace mbgl {
-template <GLsizei count>
+template <size_t count>
struct ElementGroup : public util::noncopyable {
std::array<VertexArrayObject, count> array;
- GLsizei vertex_length;
- GLsizei elements_length;
+ size_t vertex_length;
+ size_t elements_length;
- ElementGroup(GLsizei vertex_length_ = 0, GLsizei elements_length_ = 0)
+ ElementGroup(size_t vertex_length_ = 0, size_t elements_length_ = 0)
: vertex_length(vertex_length_)
, elements_length(elements_length_)
{
@@ -24,7 +24,7 @@ struct ElementGroup : public util::noncopyable {
class TriangleElementsBuffer : public Buffer<
6, // bytes per triangle (3 * unsigned short == 6 bytes)
- GL_ELEMENT_ARRAY_BUFFER
+ gl::BufferType::Element
> {
public:
typedef uint16_t element_type;
@@ -35,7 +35,7 @@ public:
class LineElementsBuffer : public Buffer<
4, // bytes per triangle (2 * unsigned short == 6 bytes)
- GL_ELEMENT_ARRAY_BUFFER
+ gl::BufferType::Element
> {
public:
typedef uint16_t element_type;
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index 2131c43966..50e82cc015 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -11,10 +11,10 @@
namespace mbgl {
-LineAtlas::LineAtlas(GLsizei w, GLsizei h)
+LineAtlas::LineAtlas(uint16_t w, uint16_t h)
: width(w),
height(h),
- data(std::make_unique<GLbyte[]>(w * h)),
+ data(std::make_unique<char[]>(w * h)),
dirty(true) {
}
@@ -120,13 +120,13 @@ LinePatternPos LineAtlas::addDash(const std::vector<float>& dasharray, LinePatte
return position;
}
-void LineAtlas::upload(gl::Context& context, uint32_t unit) {
+void LineAtlas::upload(gl::Context& context, gl::TextureUnit unit) {
if (dirty) {
bind(context, unit);
}
}
-void LineAtlas::bind(gl::Context& context, uint32_t unit) {
+void LineAtlas::bind(gl::Context& context, gl::TextureUnit unit) {
bool first = false;
if (!texture) {
texture = context.createTexture();
diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp
index cb957901f3..e974b4ff02 100644
--- a/src/mbgl/geometry/line_atlas.hpp
+++ b/src/mbgl/geometry/line_atlas.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/util/optional.hpp>
@@ -27,24 +26,24 @@ enum class LinePatternCap : bool {
class LineAtlas {
public:
- LineAtlas(GLsizei width, GLsizei height);
+ LineAtlas(uint16_t width, uint16_t height);
~LineAtlas();
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
- void bind(gl::Context&, uint32_t unit);
+ void bind(gl::Context&, gl::TextureUnit unit);
// Uploads the texture to the GPU to be available when we need it. This is a lazy operation;
// the texture is only bound when the data is out of date (=dirty).
- void upload(gl::Context&, uint32_t unit);
+ void upload(gl::Context&, gl::TextureUnit unit);
LinePatternPos getDashPosition(const std::vector<float>&, LinePatternCap);
LinePatternPos addDash(const std::vector<float>& dasharray, LinePatternCap);
- const GLsizei width;
- const GLsizei height;
+ const uint16_t width;
+ const uint16_t height;
private:
- const std::unique_ptr<GLbyte[]> data;
+ const std::unique_ptr<char[]> data;
bool dirty;
mbgl::optional<gl::UniqueTexture> texture;
int nextRow = 0;
diff --git a/src/mbgl/geometry/line_buffer.cpp b/src/mbgl/geometry/line_buffer.cpp
index 7d2e2eb9a2..523b767e25 100644
--- a/src/mbgl/geometry/line_buffer.cpp
+++ b/src/mbgl/geometry/line_buffer.cpp
@@ -1,12 +1,11 @@
#include <mbgl/geometry/line_buffer.hpp>
-#include <mbgl/gl/gl.hpp>
#include <cmath>
namespace mbgl {
-GLsizei LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar) {
- GLsizei idx = index();
+size_t LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar) {
+ size_t idx = index();
void *data = addElement();
int16_t *coords = static_cast<int16_t *>(data);
diff --git a/src/mbgl/geometry/line_buffer.hpp b/src/mbgl/geometry/line_buffer.hpp
index 5511b009ac..756e6cfebc 100644
--- a/src/mbgl/geometry/line_buffer.hpp
+++ b/src/mbgl/geometry/line_buffer.hpp
@@ -30,7 +30,7 @@ public:
* @param {number} ty texture normal
* @param {number} dir direction of the line cap (-1/0/1)
*/
- GLsizei add(vertex_type x, vertex_type y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar = 0);
+ size_t add(vertex_type x, vertex_type y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar = 0);
};
diff --git a/src/mbgl/geometry/static_vertex_buffer.hpp b/src/mbgl/geometry/static_vertex_buffer.hpp
index 2e738afc98..edf3b966fd 100644
--- a/src/mbgl/geometry/static_vertex_buffer.hpp
+++ b/src/mbgl/geometry/static_vertex_buffer.hpp
@@ -9,7 +9,7 @@ namespace mbgl {
class StaticVertexBuffer : public Buffer<
4, // bytes per vertex (2 * signed short == 4 bytes)
- GL_ARRAY_BUFFER,
+ gl::BufferType::Vertex,
32 // default length
> {
public:
@@ -19,7 +19,7 @@ public:
class StaticRasterVertexBuffer : public Buffer<
8, // bytes per vertex (4 * signed short == 8 bytes)
- GL_ARRAY_BUFFER,
+ gl::BufferType::Vertex,
32 // default length
> {
public:
diff --git a/src/mbgl/geometry/text_buffer.hpp b/src/mbgl/geometry/text_buffer.hpp
index c6b632c67e..6f5a89bc69 100644
--- a/src/mbgl/geometry/text_buffer.hpp
+++ b/src/mbgl/geometry/text_buffer.hpp
@@ -7,7 +7,7 @@ namespace mbgl {
class TextVertexBuffer : public Buffer <
16,
- GL_ARRAY_BUFFER,
+ gl::BufferType::Vertex,
32768
> {
public:
diff --git a/src/mbgl/geometry/vao.cpp b/src/mbgl/geometry/vao.cpp
index d7bddcac7a..214ed7a88d 100644
--- a/src/mbgl/geometry/vao.cpp
+++ b/src/mbgl/geometry/vao.cpp
@@ -1,6 +1,7 @@
#include <mbgl/geometry/vao.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/string.hpp>
+#include <mbgl/gl/gl.hpp>
namespace mbgl {
@@ -31,7 +32,7 @@ void VertexArrayObject::bindVertexArrayObject(gl::Context& context) {
void VertexArrayObject::verifyBinding(Shader& shader,
gl::BufferID vertexBuffer,
gl::BufferID elementsBuffer,
- GLbyte* offset) {
+ int8_t* offset) {
if (bound_shader != shader.getID()) {
throw std::runtime_error(std::string("trying to rebind VAO to another shader from " +
util::toString(bound_shader) + "(" + bound_shader_name + ") to " +
@@ -48,7 +49,7 @@ void VertexArrayObject::verifyBinding(Shader& shader,
void VertexArrayObject::storeBinding(Shader& shader,
gl::BufferID vertexBuffer,
gl::BufferID elementsBuffer,
- GLbyte* offset) {
+ int8_t* offset) {
bound_shader = shader.getID();
bound_shader_name = shader.name;
bound_offset = offset;
diff --git a/src/mbgl/geometry/vao.hpp b/src/mbgl/geometry/vao.hpp
index 42527a7ad6..65abab1e4e 100644
--- a/src/mbgl/geometry/vao.hpp
+++ b/src/mbgl/geometry/vao.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/shader/shader.hpp>
-#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
@@ -18,7 +17,7 @@ public:
template <typename VertexBuffer>
void bind(Shader& shader,
VertexBuffer& vertexBuffer,
- GLbyte* offset,
+ int8_t* offset,
gl::Context& context) {
bindVertexArrayObject(context);
if (bound_shader == 0) {
@@ -36,7 +35,7 @@ public:
void bind(Shader& shader,
VertexBuffer& vertexBuffer,
ElementsBuffer& elementsBuffer,
- GLbyte* offset,
+ int8_t* offset,
gl::Context& context) {
bindVertexArrayObject(context);
if (bound_shader == 0) {
@@ -60,11 +59,11 @@ private:
void storeBinding(Shader& shader,
gl::BufferID vertexBuffer,
gl::BufferID elementsBuffer,
- GLbyte* offset);
+ int8_t* offset);
void verifyBinding(Shader& shader,
gl::BufferID vertexBuffer,
gl::BufferID elementsBuffer,
- GLbyte* offset);
+ int8_t* offset);
mbgl::optional<gl::UniqueVertexArray> vertexArray;
@@ -74,7 +73,7 @@ private:
const char* bound_shader_name = "";
gl::BufferID bound_vertex_buffer = 0;
gl::BufferID bound_elements_buffer = 0;
- GLbyte *bound_offset = nullptr;
+ int8_t *bound_offset = nullptr;
};
} // namespace mbgl