summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Agafonkin <agafonkin@gmail.com>2018-02-09 14:45:08 +0200
committerVladimir Agafonkin <agafonkin@gmail.com>2018-02-09 14:45:08 +0200
commitd2fb1d9ca1a375fa2d1ccf199173ffc3fc181ea8 (patch)
tree614e450b5e82e4f919c58003e0ce2360520cf6ec
parent6aaf46aab14c0e34242b5b06cb72da475c373d18 (diff)
downloadqtlocation-mapboxgl-d2fb1d9ca1a375fa2d1ccf199173ffc3fc181ea8.tar.gz
use PremultipliedImage for heatmap color ramp
-rw-r--r--src/mbgl/gl/context.hpp7
-rw-r--r--src/mbgl/renderer/layers/render_heatmap_layer.cpp20
-rw-r--r--src/mbgl/renderer/layers/render_heatmap_layer.hpp2
3 files changed, 13 insertions, 16 deletions
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 9116aa7d93..5c6d0bc793 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -144,13 +144,12 @@ public:
obj.size = image.size;
}
- // Creates a texture from raw data
+ // Creates an empty texture with the specified dimensions.
Texture createTexture(const Size size,
TextureFormat format = TextureFormat::RGBA,
TextureUnit unit = 0,
- TextureType type = TextureType::UnsignedByte,
- const void* data = nullptr) {
- return { size, createTexture(size, data, format, unit, type) };
+ TextureType type = TextureType::UnsignedByte) {
+ return { size, createTexture(size, nullptr, format, unit, type) };
}
void bindTexture(Texture&,
diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
index 4717c224c8..a451843340 100644
--- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp
+++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
@@ -18,7 +18,7 @@ using namespace style;
RenderHeatmapLayer::RenderHeatmapLayer(Immutable<style::HeatmapLayer::Impl> _impl)
: RenderLayer(style::LayerType::Heatmap, _impl),
- unevaluated(impl().paint.untransitioned()) {
+ unevaluated(impl().paint.untransitioned()), colorRamp({256, 1}) {
}
const style::HeatmapLayer::Impl& RenderHeatmapLayer::impl() const {
@@ -76,9 +76,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
}
if (!colorRampTexture) {
- const auto colorRampSize = Size{256, 1};
- colorRampTexture = parameters.context.createTexture(colorRampSize, gl::TextureFormat::RGBA, 1,
- gl::TextureType::UnsignedByte, colorRamp.data());
+ colorRampTexture = parameters.context.createTexture(colorRamp, 1, gl::TextureType::UnsignedByte);
}
parameters.context.clear(Color{ 0.0f, 0.0f, 0.0f, 1.0f }, {}, {});
@@ -147,14 +145,14 @@ void RenderHeatmapLayer::updateColorRamp() {
colorValue = HeatmapLayer::getDefaultHeatmapColor();
}
- const auto size = colorRamp.size();
+ const auto length = colorRamp.bytes();
- for (uint32_t i = 0; i < size; i += 4) {
- const auto color = colorValue.evaluate(static_cast<double>(i) / size);
- colorRamp[i + 0] = std::floor(color.r * 255);
- colorRamp[i + 1] = std::floor(color.g * 255);
- colorRamp[i + 2] = std::floor(color.b * 255);
- colorRamp[i + 3] = std::floor(color.a * 255);
+ for (uint32_t i = 0; i < length; i += 4) {
+ const auto color = colorValue.evaluate(static_cast<double>(i) / length);
+ colorRamp.data[i + 0] = std::floor(color.r * 255);
+ colorRamp.data[i + 1] = std::floor(color.g * 255);
+ colorRamp.data[i + 2] = std::floor(color.b * 255);
+ colorRamp.data[i + 3] = std::floor(color.a * 255);
}
if (colorRampTexture) {
diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.hpp b/src/mbgl/renderer/layers/render_heatmap_layer.hpp
index 413a799195..3f0b1f91b4 100644
--- a/src/mbgl/renderer/layers/render_heatmap_layer.hpp
+++ b/src/mbgl/renderer/layers/render_heatmap_layer.hpp
@@ -35,7 +35,7 @@ public:
const style::HeatmapLayer::Impl& impl() const;
- std::array<uint8_t, 1024> colorRamp;
+ PremultipliedImage colorRamp;
optional<OffscreenTexture> renderTexture;
optional<gl::Texture> colorRampTexture;
};