summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-04-22 17:52:10 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-05-04 17:33:04 +0200
commitc891df0b5f3e946840324dbe238f29c1fba16ea3 (patch)
tree232e4ac8a0a4f2a6bd9b95ee36bf62aa6eb96432 /src
parent5beb635028b6634f57ae874a416a291999f31e97 (diff)
downloadqtlocation-mapboxgl-c891df0b5f3e946840324dbe238f29c1fba16ea3.tar.gz
add upload API to gl objects
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/geometry/buffer.hpp22
-rw-r--r--src/mbgl/map/tile_parser.cpp6
-rw-r--r--src/mbgl/renderer/raster_bucket.cpp7
-rw-r--r--src/mbgl/renderer/raster_bucket.hpp2
-rw-r--r--src/mbgl/util/raster.cpp30
-rw-r--r--src/mbgl/util/raster.hpp4
6 files changed, 26 insertions, 45 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp
index 4198425ecf..01af5df18e 100644
--- a/src/mbgl/geometry/buffer.hpp
+++ b/src/mbgl/geometry/buffer.hpp
@@ -2,6 +2,7 @@
#define MBGL_GEOMETRY_BUFFER
#include <mbgl/platform/gl.hpp>
+#include <mbgl/platform/log.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/map/environment.hpp>
@@ -38,17 +39,16 @@ public:
}
// Transfers this buffer to the GPU and binds the buffer to the GL context.
- void bind(bool force = false) {
- if (buffer == 0) {
+ void bind() {
+ if (buffer) {
+ MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
+ } else {
MBGL_CHECK_ERROR(glGenBuffers(1, &buffer));
- force = true;
- }
- MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
- if (force) {
+ MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
if (array == nullptr) {
- throw std::runtime_error("Buffer was already deleted or doesn't contain elements");
+ Log::Debug(Event::OpenGL, "Buffer doesn't contain elements");
+ pos = 0;
}
-
MBGL_CHECK_ERROR(glBufferData(bufferType, pos, array, GL_STATIC_DRAW));
if (!retainAfterUpload) {
cleanup();
@@ -67,6 +67,12 @@ public:
return buffer;
}
+ inline void upload() {
+ if (!buffer) {
+ bind();
+ }
+ }
+
protected:
// increase the buffer size by at least /required/ bytes.
inline void *addElement() {
diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp
index 35c504ab29..1438bcddaa 100644
--- a/src/mbgl/map/tile_parser.cpp
+++ b/src/mbgl/map/tile_parser.cpp
@@ -157,7 +157,7 @@ std::unique_ptr<Bucket> TileParser::createFillBucket(const GeometryTileLayer& la
tile.triangleElementsBuffer,
tile.lineElementsBuffer);
addBucketGeometries(bucket, layer, bucket_desc.filter);
- return std::move(bucket);
+ return bucket->hasData() ? std::move(bucket) : nullptr;
}
std::unique_ptr<Bucket> TileParser::createLineBucket(const GeometryTileLayer& layer,
@@ -174,7 +174,7 @@ std::unique_ptr<Bucket> TileParser::createLineBucket(const GeometryTileLayer& la
applyLayoutProperty(PropertyKey::LineRoundLimit, bucket_desc.layout, layout.round_limit, z);
addBucketGeometries(bucket, layer, bucket_desc.filter);
- return std::move(bucket);
+ return bucket->hasData() ? std::move(bucket) : nullptr;
}
std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer& layer,
@@ -224,6 +224,6 @@ std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer&
bucket->addFeatures(
layer, bucket_desc.filter, reinterpret_cast<uintptr_t>(&tile), spriteAtlas, *sprite, glyphAtlas, glyphStore);
- return std::move(bucket);
+ return bucket->hasData() ? std::move(bucket) : nullptr;
}
}
diff --git a/src/mbgl/renderer/raster_bucket.cpp b/src/mbgl/renderer/raster_bucket.cpp
index cf1036dbf2..bcaf6e7daf 100644
--- a/src/mbgl/renderer/raster_bucket.cpp
+++ b/src/mbgl/renderer/raster_bucket.cpp
@@ -29,13 +29,6 @@ void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index()));
}
-void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture_) {
- raster.bind(texture_);
- shader.u_image = 0;
- array.bind(shader, vertices, BUFFER_OFFSET(0));
- MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index()));
-}
-
bool RasterBucket::hasData() const {
return raster.isLoaded();
}
diff --git a/src/mbgl/renderer/raster_bucket.hpp b/src/mbgl/renderer/raster_bucket.hpp
index ed2d46bb26..d216404caf 100644
--- a/src/mbgl/renderer/raster_bucket.hpp
+++ b/src/mbgl/renderer/raster_bucket.hpp
@@ -26,8 +26,6 @@ public:
void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array);
- void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture);
-
Raster raster;
};
diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp
index d0e305c33a..f2171a6165 100644
--- a/src/mbgl/util/raster.cpp
+++ b/src/mbgl/util/raster.cpp
@@ -46,16 +46,7 @@ void Raster::bind(bool linear) {
}
if (img && !textured) {
- texture = texturePool.getTextureID();
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
-#ifndef GL_ES_VERSION_2_0
- MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
-#endif
- MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
- MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
- MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->getData()));
- img.reset();
- textured = true;
+ upload();
} else if (textured) {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
}
@@ -68,24 +59,17 @@ void Raster::bind(bool linear) {
}
}
-// overload ::bind for prerendered raster textures
-void Raster::bind(const GLuint custom_texture) {
+void Raster::upload() {
if (img && !textured) {
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, custom_texture));
+ texture = texturePool.getTextureID();
+ MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
+#ifndef GL_ES_VERSION_2_0
+ MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
+#endif
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->getData()));
img.reset();
textured = true;
- } else if (textured) {
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, custom_texture));
}
-
- GLuint new_filter = GL_LINEAR;
- 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));
- filter = new_filter;
- }
-
}
diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp
index f19ff7178a..1789ae87f7 100644
--- a/src/mbgl/util/raster.hpp
+++ b/src/mbgl/util/raster.hpp
@@ -25,8 +25,8 @@ public:
// bind current texture
void bind(bool linear = false);
- // bind prerendered texture
- void bind(const GLuint texture);
+ // uploads the texture if it hasn't been uploaded yet.
+ void upload();
// loaded status
bool isLoaded() const;