summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-27 13:01:31 -0700
committerKonstantin Käfer <mail@kkaefer.com>2016-11-01 18:41:52 +0100
commite4e9b3a2f062fe712e7e346718c039fe2778c638 (patch)
treefb6774dc6841b26c7033e7e2eb6cc2964643be95
parented155460d3ec3777bfd95ce3d40c809e583b07de (diff)
downloadqtlocation-mapboxgl-e4e9b3a2f062fe712e7e346718c039fe2778c638.tar.gz
[core] convert FrameHistory to use managed texture handling
-rw-r--r--src/mbgl/renderer/frame_history.cpp71
-rw-r--r--src/mbgl/renderer/frame_history.hpp12
2 files changed, 21 insertions, 62 deletions
diff --git a/src/mbgl/renderer/frame_history.cpp b/src/mbgl/renderer/frame_history.cpp
index daf24c8c37..d77c89a1bd 100644
--- a/src/mbgl/renderer/frame_history.cpp
+++ b/src/mbgl/renderer/frame_history.cpp
@@ -3,11 +3,13 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/gl.hpp>
+#include <cassert>
+
namespace mbgl {
FrameHistory::FrameHistory() {
changeOpacities.fill(0);
- opacities.fill(0);
+ std::fill(opacities.data.get(), opacities.data.get() + opacities.bytes(), 0);
}
void FrameHistory::record(const TimePoint& now, float zoom, const Duration& duration) {
@@ -18,7 +20,7 @@ void FrameHistory::record(const TimePoint& now, float zoom, const Duration& dura
changeTimes.fill(now);
for (int16_t z = 0; z <= zoomIndex; z++) {
- opacities[z] = 255u;
+ opacities.data[z] = 255u;
}
firstFrame = false;
}
@@ -26,12 +28,12 @@ void FrameHistory::record(const TimePoint& now, float zoom, const Duration& dura
if (zoomIndex < previousZoomIndex) {
for (int16_t z = zoomIndex + 1; z <= previousZoomIndex; z++) {
changeTimes[z] = now;
- changeOpacities[z] = opacities[z];
+ changeOpacities[z] = opacities.data[z];
}
} else {
for (int16_t z = zoomIndex; z > previousZoomIndex; z--) {
changeTimes[z] = now;
- changeOpacities[z] = opacities[z];
+ changeOpacities[z] = opacities.data[z];
}
}
@@ -39,13 +41,13 @@ void FrameHistory::record(const TimePoint& now, float zoom, const Duration& dura
std::chrono::duration<float> timeDiff = now - changeTimes[z];
int32_t opacityChange = (duration == Milliseconds(0) ? 1 : (timeDiff / duration)) * 255;
if (z <= zoomIndex) {
- opacities[z] = util::min(255, changeOpacities[z] + opacityChange);
+ opacities.data[z] = util::min(255, changeOpacities[z] + opacityChange);
} else {
- opacities[z] = util::max(0, changeOpacities[z] - opacityChange);
+ opacities.data[z] = util::max(0, changeOpacities[z] - opacityChange);
}
}
- changed = true;
+ dirty = true;
if (zoomIndex != previousZoomIndex) {
previousZoomIndex = zoomIndex;
@@ -60,58 +62,17 @@ bool FrameHistory::needsAnimation(const Duration& duration) const {
}
void FrameHistory::upload(gl::Context& context, uint32_t unit) {
-
- if (changed) {
- const bool first = !texture;
- bind(context, unit);
-
- if (first) {
- MBGL_CHECK_ERROR(glTexImage2D(
- GL_TEXTURE_2D, // GLenum target
- 0, // GLint level
- GL_ALPHA, // GLint internalformat
- width, // GLsizei width
- height, // GLsizei height
- 0, // GLint border
- GL_ALPHA, // GLenum format
- GL_UNSIGNED_BYTE, // GLenum type
- opacities.data()
- ));
- } else {
- MBGL_CHECK_ERROR(glTexSubImage2D(
- GL_TEXTURE_2D, // GLenum target
- 0, // GLint level
- 0, // GLint xoffset
- 0, // GLint yoffset
- width, // GLsizei width
- height, // GLsizei height
- GL_ALPHA, // GLenum format
- GL_UNSIGNED_BYTE, // GLenum type
- opacities.data()
- ));
- }
-
- changed = false;
-
+ if (!texture) {
+ texture = context.createTexture(opacities, unit);
+ } else if (dirty) {
+ context.updateTexture(*texture, opacities, unit);
}
+ dirty = false;
}
void FrameHistory::bind(gl::Context& context, uint32_t unit) {
- if (!texture) {
- texture = context.createTexture();
- context.activeTexture = unit;
- context.texture[unit] = *texture;
-#if not MBGL_USE_GLES2
- 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(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
- MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
- } else if (context.texture[unit] != *texture) {
- context.activeTexture = unit;
- context.texture[unit] = *texture;
- }
+ upload(context, unit);
+ context.bindTexture(*texture, unit);
}
} // namespace mbgl
diff --git a/src/mbgl/renderer/frame_history.hpp b/src/mbgl/renderer/frame_history.hpp
index 063930af26..d8fd06d27b 100644
--- a/src/mbgl/renderer/frame_history.hpp
+++ b/src/mbgl/renderer/frame_history.hpp
@@ -3,8 +3,9 @@
#include <array>
#include <mbgl/platform/platform.hpp>
-#include <mbgl/gl/object.hpp>
+#include <mbgl/gl/texture.hpp>
#include <mbgl/util/chrono.hpp>
+#include <mbgl/util/image.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {
@@ -23,20 +24,17 @@ public:
void upload(gl::Context&, uint32_t);
private:
- const int width = 256;
- const int height = 1;
-
std::array<TimePoint, 256> changeTimes;
std::array<uint8_t, 256> changeOpacities;
- std::array<uint8_t, 256> opacities;
+ const AlphaImage opacities{ { 256, 1 } };
int16_t previousZoomIndex = 0;
TimePoint previousTime = TimePoint::min();
TimePoint time = TimePoint::min();
bool firstFrame = true;
- bool changed = true;
+ bool dirty = true;
- mbgl::optional<gl::UniqueTexture> texture;
+ mbgl::optional<gl::Texture> texture;
};
} // namespace mbgl