summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-09-10 17:59:58 +0300
committerKonstantin Käfer <mail@kkaefer.com>2015-09-15 13:22:04 +0200
commitc33a6bddc66efd18159b111796cce65ad78950f2 (patch)
treea2b2fcfba977724b8d7bda2632f92d71886e60a1
parent05d01194b7864673b412fbd80487973859d2dd9f (diff)
downloadqtlocation-mapboxgl-c33a6bddc66efd18159b111796cce65ad78950f2.tar.gz
[core] GL types for buckets, textures, buffers
-rw-r--r--src/mbgl/geometry/buffer.hpp10
-rw-r--r--src/mbgl/geometry/elements_buffer.hpp14
-rw-r--r--src/mbgl/geometry/glyph_atlas.hpp3
-rw-r--r--src/mbgl/geometry/line_atlas.cpp4
-rw-r--r--src/mbgl/geometry/line_atlas.hpp12
-rw-r--r--src/mbgl/geometry/sprite_atlas.hpp4
-rw-r--r--src/mbgl/renderer/fill_bucket.cpp4
-rw-r--r--src/mbgl/renderer/line_bucket.cpp20
-rw-r--r--src/mbgl/renderer/line_bucket.hpp10
-rw-r--r--src/mbgl/renderer/painter.cpp4
-rw-r--r--src/mbgl/renderer/painter.hpp8
-rw-r--r--src/mbgl/renderer/symbol_bucket.cpp2
-rw-r--r--src/mbgl/util/raster.cpp2
-rw-r--r--src/mbgl/util/raster.hpp8
-rw-r--r--src/mbgl/util/texture_pool.cpp4
15 files changed, 56 insertions, 53 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp
index c696b5b862..620315d490 100644
--- a/src/mbgl/geometry/buffer.hpp
+++ b/src/mbgl/geometry/buffer.hpp
@@ -14,9 +14,9 @@
namespace mbgl {
template <
- size_t item_size,
- int bufferType = GL_ARRAY_BUFFER,
- size_t defaultLength = 8192,
+ GLsizei item_size,
+ GLenum bufferType = GL_ARRAY_BUFFER,
+ GLsizei defaultLength = 8192,
bool retainAfterUpload = false
>
class Buffer : private util::noncopyable {
@@ -31,8 +31,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.
- inline size_t index() const {
- return pos / itemSize;
+ inline GLsizei index() const {
+ return static_cast<GLsizei>(pos / itemSize);
}
inline bool empty() const {
diff --git a/src/mbgl/geometry/elements_buffer.hpp b/src/mbgl/geometry/elements_buffer.hpp
index 24753ebafe..5e642f06db 100644
--- a/src/mbgl/geometry/elements_buffer.hpp
+++ b/src/mbgl/geometry/elements_buffer.hpp
@@ -10,16 +10,16 @@
namespace mbgl {
-template <int count>
+template <GLsizei count>
struct ElementGroup : public util::noncopyable {
std::array<VertexArrayObject, count> array;
- uint32_t vertex_length;
- uint32_t elements_length;
+ GLsizei vertex_length;
+ GLsizei elements_length;
- ElementGroup() : vertex_length(0), elements_length(0) {}
- ElementGroup(uint32_t vertex_length_, uint32_t elements_length_)
- : vertex_length(vertex_length_),
- elements_length(elements_length_) {
+ ElementGroup(GLsizei vertex_length_ = 0, GLsizei elements_length_ = 0)
+ : vertex_length(vertex_length_)
+ , elements_length(elements_length_)
+ {
}
};
diff --git a/src/mbgl/geometry/glyph_atlas.hpp b/src/mbgl/geometry/glyph_atlas.hpp
index 8bc21da09f..f499859d7e 100644
--- a/src/mbgl/geometry/glyph_atlas.hpp
+++ b/src/mbgl/geometry/glyph_atlas.hpp
@@ -4,6 +4,7 @@
#include <mbgl/geometry/binpack.hpp>
#include <mbgl/text/glyph_store.hpp>
#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/platform/gl.hpp>
#include <string>
#include <set>
@@ -51,7 +52,7 @@ private:
std::map<std::string, std::map<uint32_t, GlyphValue>> index;
const std::unique_ptr<uint8_t[]> data;
std::atomic<bool> dirty;
- uint32_t texture = 0;
+ GLuint texture = 0;
};
};
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index aeac3067e9..bbda2dce6f 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -12,10 +12,10 @@
using namespace mbgl;
-LineAtlas::LineAtlas(uint16_t w, uint16_t h)
+LineAtlas::LineAtlas(GLsizei w, GLsizei h)
: width(w),
height(h),
- data(std::make_unique<uint8_t[]>(w * h)),
+ data(std::make_unique<GLbyte[]>(w * h)),
dirty(true) {
}
diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp
index 3c3b90f752..a8663cb820 100644
--- a/src/mbgl/geometry/line_atlas.hpp
+++ b/src/mbgl/geometry/line_atlas.hpp
@@ -1,6 +1,8 @@
#ifndef MBGL_GEOMETRY_LINE_ATLAS
#define MBGL_GEOMETRY_LINE_ATLAS
+#include <mbgl/platform/gl.hpp>
+
#include <vector>
#include <map>
#include <memory>
@@ -15,7 +17,7 @@ typedef struct {
class LineAtlas {
public:
- LineAtlas(uint16_t width, uint16_t height);
+ LineAtlas(GLsizei width, GLsizei height);
~LineAtlas();
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
@@ -28,13 +30,13 @@ public:
LinePatternPos getDashPosition(const std::vector<float>&, bool);
LinePatternPos addDash(const std::vector<float> &dasharray, bool round);
- const int width;
- const int height;
+ const GLsizei width;
+ const GLsizei height;
private:
- const std::unique_ptr<uint8_t[]> data;
+ const std::unique_ptr<GLbyte[]> data;
bool dirty;
- uint32_t texture = 0;
+ GLuint texture = 0;
int nextRow = 0;
std::map<size_t, LinePatternPos> positions;
};
diff --git a/src/mbgl/geometry/sprite_atlas.hpp b/src/mbgl/geometry/sprite_atlas.hpp
index bfe4f843da..4a8c3fefaf 100644
--- a/src/mbgl/geometry/sprite_atlas.hpp
+++ b/src/mbgl/geometry/sprite_atlas.hpp
@@ -2,7 +2,7 @@
#define MBGL_GEOMETRY_SPRITE_ATLAS
#include <mbgl/geometry/binpack.hpp>
-
+#include <mbgl/platform/gl.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
@@ -93,7 +93,7 @@ private:
const std::unique_ptr<uint32_t[]> data;
std::atomic<bool> dirty;
bool fullUploadRequired = true;
- uint32_t texture = 0;
+ GLuint texture = 0;
uint32_t filter = 0;
static const int buffer = 1;
};
diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp
index 1828ae0a2d..7fb25d9a80 100644
--- a/src/mbgl/renderer/fill_bucket.cpp
+++ b/src/mbgl/renderer/fill_bucket.cpp
@@ -107,7 +107,7 @@ void FillBucket::tessellate() {
assert(lineGroups.back());
LineGroup& lineGroup = *lineGroups.back();
- uint32_t lineIndex = lineGroup.vertex_length;
+ GLsizei lineIndex = lineGroup.vertex_length;
for (const auto& polygon : polygons) {
const size_t group_count = polygon.size();
@@ -156,7 +156,7 @@ void FillBucket::tessellate() {
// coordinate in this polygon.
assert(triangleGroups.back());
TriangleGroup& triangleGroup = *triangleGroups.back();
- uint32_t triangleIndex = triangleGroup.vertex_length;
+ GLsizei triangleIndex = triangleGroup.vertex_length;
for (int i = 0; i < triangle_count; ++i) {
const TESSindex *element_group = &elements[i * vertices_per_group];
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index f0d52fa51c..9769cac332 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -75,7 +75,7 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
nextNormal = util::perp(util::unit(vec2<double>(firstVertex - currentVertex)));
}
- const int32_t startVertex = (int32_t)vertexBuffer.index();
+ const GLint startVertex = vertexBuffer.index();
std::vector<TriangleElement> triangleStore;
for (size_t i = 0; i < len; ++i) {
@@ -333,16 +333,15 @@ void LineBucket::addCurrentVertex(const Coordinate& currentVertex,
float endLeft,
float endRight,
bool round,
- int32_t startVertex,
+ GLint startVertex,
std::vector<TriangleElement>& triangleStore) {
int8_t tx = round ? 1 : 0;
vec2<double> extrude = normal * flip;
if (endLeft)
extrude = extrude - (util::perp(normal) * endLeft);
- e3 = (int32_t)vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 0,
- distance) -
- startVertex;
+ e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 0, distance)
+ - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}
@@ -352,9 +351,8 @@ void LineBucket::addCurrentVertex(const Coordinate& currentVertex,
extrude = normal * (-flip);
if (endRight)
extrude = extrude - (util::perp(normal) * endRight);
- e3 = (int32_t)vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 1,
- distance) -
- startVertex;
+ e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 1, distance)
+ - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}
@@ -367,13 +365,13 @@ void LineBucket::addPieSliceVertex(const Coordinate& currentVertex,
double distance,
const vec2<double>& extrude,
bool lineTurnsLeft,
- int32_t startVertex,
+ GLint startVertex,
std::vector<TriangleElement>& triangleStore) {
int8_t ty = lineTurnsLeft;
auto flippedExtrude = extrude * (flip * (lineTurnsLeft ? -1 : 1));
- e3 = (int32_t)vertexBuffer.add(currentVertex.x, currentVertex.y, flippedExtrude.x, flippedExtrude.y, 0, ty,
- distance) - startVertex;
+ e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, flippedExtrude.x, flippedExtrude.y, 0, ty, distance)
+ - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}
diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp
index cd5fce3cb9..ea12a1d844 100644
--- a/src/mbgl/renderer/line_bucket.hpp
+++ b/src/mbgl/renderer/line_bucket.hpp
@@ -46,9 +46,9 @@ private:
};
void addCurrentVertex(const Coordinate& currentVertex, float flip, double distance,
const vec2<double>& normal, float endLeft, float endRight, bool round,
- int32_t startVertex, std::vector<LineBucket::TriangleElement>& triangleStore);
+ GLint startVertex, std::vector<LineBucket::TriangleElement>& triangleStore);
void addPieSliceVertex(const Coordinate& currentVertex, float flip, double distance,
- const vec2<double>& extrude, bool lineTurnsLeft, int32_t startVertex,
+ const vec2<double>& extrude, bool lineTurnsLeft, GLint startVertex,
std::vector<TriangleElement>& triangleStore);
public:
@@ -61,9 +61,9 @@ private:
const size_t vertex_start;
const size_t triangle_elements_start;
- int32_t e1;
- int32_t e2;
- int32_t e3;
+ GLint e1;
+ GLint e2;
+ GLint e3;
std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
};
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index e757d682a6..a1b5566f2b 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -117,14 +117,14 @@ void Painter::setDebug(bool enabled) {
debug = enabled;
}
-void Painter::useProgram(uint32_t program) {
+void Painter::useProgram(GLuint program) {
if (gl_program != program) {
MBGL_CHECK_ERROR(glUseProgram(program));
gl_program = program;
}
}
-void Painter::lineWidth(float line_width) {
+void Painter::lineWidth(GLfloat line_width) {
if (gl_lineWidth != line_width) {
MBGL_CHECK_ERROR(glLineWidth(line_width));
gl_lineWidth = line_width;
diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp
index 9c0f5db8ca..ce42b59d1f 100644
--- a/src/mbgl/renderer/painter.hpp
+++ b/src/mbgl/renderer/painter.hpp
@@ -161,8 +161,8 @@ private:
void setDepthSublayer(int n);
public:
- void useProgram(uint32_t program);
- void lineWidth(float lineWidth);
+ void useProgram(GLuint program);
+ void lineWidth(GLfloat lineWidth);
public:
mat4 projMatrix;
@@ -194,8 +194,8 @@ private:
gl::Config config;
- uint32_t gl_program = 0;
- float gl_lineWidth = 0;
+ GLuint gl_program = 0;
+ GLfloat gl_lineWidth = 0;
std::array<uint16_t, 2> gl_viewport = {{ 0, 0 }};
RenderPass pass = RenderPass::Opaque;
Color background = {{ 0, 0, 0, 0 }};
diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp
index 11b3bf3d0f..9b1deef912 100644
--- a/src/mbgl/renderer/symbol_bucket.cpp
+++ b/src/mbgl/renderer/symbol_bucket.cpp
@@ -488,7 +488,7 @@ void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
// coordinate in this polygon.
assert(buffer.groups.back());
auto &triangleGroup = *buffer.groups.back();
- uint32_t triangleIndex = triangleGroup.vertex_length;
+ GLsizei triangleIndex = triangleGroup.vertex_length;
// coordinates (2 triangles)
buffer.vertices.add(anchorPoint.x, anchorPoint.y, tl.x, tl.y, tex.x, tex.y, minZoom,
diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp
index 9b82540894..1c277040cd 100644
--- a/src/mbgl/util/raster.cpp
+++ b/src/mbgl/util/raster.cpp
@@ -50,7 +50,7 @@ void Raster::bind(bool linear) {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
}
- GLuint new_filter = linear ? GL_LINEAR : GL_NEAREST;
+ GLint new_filter = linear ? GL_LINEAR : GL_NEAREST;
if (new_filter != this->filter) {
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, new_filter));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, new_filter));
diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp
index 39ab26ffc6..adf3b2cbf7 100644
--- a/src/mbgl/util/raster.hpp
+++ b/src/mbgl/util/raster.hpp
@@ -1,6 +1,7 @@
#ifndef MBGL_UTIL_RASTER
#define MBGL_UTIL_RASTER
+#include <mbgl/platform/gl.hpp>
#include <mbgl/util/texture_pool.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/ptr.hpp>
@@ -32,13 +33,14 @@ public:
public:
// loaded image dimensions
- uint32_t width = 0, height = 0;
+ GLsizei width = 0;
+ GLsizei height = 0;
// has been uploaded to texture
bool textured = false;
// the uploaded texture
- uint32_t texture = 0;
+ GLuint texture = 0;
// texture opacity
double opacity = 0;
@@ -53,7 +55,7 @@ private:
TexturePool& texturePool;
// min/mag filter
- uint32_t filter = 0;
+ GLint filter = 0;
// the raw pixels
std::unique_ptr<util::Image> img;
diff --git a/src/mbgl/util/texture_pool.cpp b/src/mbgl/util/texture_pool.cpp
index 84d24ac77c..d4afb1f868 100644
--- a/src/mbgl/util/texture_pool.cpp
+++ b/src/mbgl/util/texture_pool.cpp
@@ -5,7 +5,7 @@
#include <vector>
-const int TextureMax = 64;
+const GLsizei TextureMax = 64;
using namespace mbgl;
@@ -13,7 +13,7 @@ GLuint TexturePool::getTextureID() {
if (texture_ids.empty()) {
GLuint new_texture_ids[TextureMax];
MBGL_CHECK_ERROR(glGenTextures(TextureMax, new_texture_ids));
- for (uint32_t id = 0; id < TextureMax; id++) {
+ for (GLuint id = 0; id < TextureMax; id++) {
texture_ids.insert(new_texture_ids[id]);
}
}