summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r--src/mbgl/geometry/glyph_atlas.cpp16
-rw-r--r--src/mbgl/geometry/glyph_atlas.hpp8
-rw-r--r--src/mbgl/geometry/line_atlas.cpp24
-rw-r--r--src/mbgl/geometry/line_atlas.hpp12
4 files changed, 37 insertions, 23 deletions
diff --git a/src/mbgl/geometry/glyph_atlas.cpp b/src/mbgl/geometry/glyph_atlas.cpp
index c45a93d24e..cfc5962eb3 100644
--- a/src/mbgl/geometry/glyph_atlas.cpp
+++ b/src/mbgl/geometry/glyph_atlas.cpp
@@ -2,6 +2,7 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
+#include <mbgl/gl/gl_config.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
@@ -141,13 +142,14 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) {
}
}
-void GlyphAtlas::upload(gl::ObjectStore& store) {
+void GlyphAtlas::upload(gl::ObjectStore& store, gl::Config& config, uint32_t unit) {
if (dirty) {
const bool first = !texture;
- bind(store);
+ bind(store, config, unit);
std::lock_guard<std::mutex> lock(mtx);
+ config.activeTexture = unit;
if (first) {
MBGL_CHECK_ERROR(glTexImage2D(
GL_TEXTURE_2D, // GLenum target
@@ -182,10 +184,11 @@ void GlyphAtlas::upload(gl::ObjectStore& store) {
}
}
-void GlyphAtlas::bind(gl::ObjectStore& store) {
+void GlyphAtlas::bind(gl::ObjectStore& store, gl::Config& config, uint32_t unit) {
if (!texture) {
texture = store.createTexture();
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
+ config.activeTexture = unit;
+ config.texture[unit] = *texture;
#ifndef GL_ES_VERSION_2_0
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
#endif
@@ -193,8 +196,9 @@ void GlyphAtlas::bind(gl::ObjectStore& store) {
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
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));
- } else {
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
+ } else if (config.texture[unit] != *texture) {
+ config.activeTexture = unit;
+ config.texture[unit] = *texture;
}
}
diff --git a/src/mbgl/geometry/glyph_atlas.hpp b/src/mbgl/geometry/glyph_atlas.hpp
index b1fc9d5747..5252963f51 100644
--- a/src/mbgl/geometry/glyph_atlas.hpp
+++ b/src/mbgl/geometry/glyph_atlas.hpp
@@ -15,6 +15,10 @@
namespace mbgl {
+namespace gl {
+class Config;
+} // namespace gl
+
class GlyphAtlas : public util::noncopyable {
public:
GlyphAtlas(uint16_t width, uint16_t height);
@@ -28,11 +32,11 @@ public:
void removeGlyphs(uintptr_t tileUID);
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
- void bind(gl::ObjectStore&);
+ void bind(gl::ObjectStore&, gl::Config&, uint32_t 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::ObjectStore&);
+ void upload(gl::ObjectStore&, gl::Config&, uint32_t unit);
const GLsizei width;
const GLsizei height;
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index d7ae5b4a60..f08ea1e5fc 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -1,6 +1,7 @@
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
+#include <mbgl/gl/gl_config.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
@@ -20,7 +21,7 @@ LineAtlas::LineAtlas(GLsizei w, GLsizei h)
LineAtlas::~LineAtlas() = default;
-LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, bool round, gl::ObjectStore& store) {
+LinePatternPos LineAtlas::getDashPosition(const std::vector<float>& dasharray, bool round) {
size_t key = round ? std::numeric_limits<size_t>::min() : std::numeric_limits<size_t>::max();
for (const float part : dasharray) {
boost::hash_combine<float>(key, part);
@@ -29,7 +30,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, b
// Note: We're not handling hash collisions here.
const auto it = positions.find(key);
if (it == positions.end()) {
- auto inserted = positions.emplace(key, addDash(dasharray, round, store));
+ auto inserted = positions.emplace(key, addDash(dasharray, round));
assert(inserted.second);
return inserted.first->second;
} else {
@@ -37,8 +38,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, b
}
}
-LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool round, gl::ObjectStore& store) {
-
+LinePatternPos LineAtlas::addDash(const std::vector<float>& dasharray, bool round) {
int n = round ? 7 : 0;
int dashheight = 2 * n + 1;
const uint8_t offset = 128;
@@ -115,32 +115,34 @@ LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool roun
nextRow += dashheight;
dirty = true;
- bind(store);
return position;
}
-void LineAtlas::upload(gl::ObjectStore& store) {
+void LineAtlas::upload(gl::ObjectStore& store, gl::Config& config, uint32_t unit) {
if (dirty) {
- bind(store);
+ bind(store, config, unit);
}
}
-void LineAtlas::bind(gl::ObjectStore& store) {
+void LineAtlas::bind(gl::ObjectStore& store, gl::Config& config, uint32_t unit) {
bool first = false;
if (!texture) {
texture = store.createTexture();
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
+ config.activeTexture = unit;
+ config.texture[unit] = *texture;
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
first = true;
- } else {
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
+ } else if (config.texture[unit] != *texture) {
+ config.activeTexture = unit;
+ config.texture[unit] = *texture;
}
if (dirty) {
+ config.activeTexture = unit;
if (first) {
MBGL_CHECK_ERROR(glTexImage2D(
GL_TEXTURE_2D, // GLenum target
diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp
index 0ca5e95a23..1e6c0ac84e 100644
--- a/src/mbgl/geometry/line_atlas.hpp
+++ b/src/mbgl/geometry/line_atlas.hpp
@@ -9,6 +9,10 @@
namespace mbgl {
+namespace gl {
+class Config;
+} // namespace gl
+
typedef struct {
float width;
float height;
@@ -21,14 +25,14 @@ public:
~LineAtlas();
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
- void bind(gl::ObjectStore&);
+ void bind(gl::ObjectStore&, gl::Config&, uint32_t 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::ObjectStore&);
+ void upload(gl::ObjectStore&, gl::Config&, uint32_t unit);
- LinePatternPos getDashPosition(const std::vector<float>&, bool, gl::ObjectStore&);
- LinePatternPos addDash(const std::vector<float> &dasharray, bool round, gl::ObjectStore&);
+ LinePatternPos getDashPosition(const std::vector<float>&, bool);
+ LinePatternPos addDash(const std::vector<float>& dasharray, bool round);
const GLsizei width;
const GLsizei height;