diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-04-03 14:18:54 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-04-05 11:49:17 +0200 |
commit | b1a2513b61761d09b3ae08904c03d28caedd09fe (patch) | |
tree | 132c95888496aeb8493deeedd4897bd7639d292f | |
parent | 7081d5e154e208322b95f8efab74ec6e014a263d (diff) | |
download | qtlocation-mapboxgl-b1a2513b61761d09b3ae08904c03d28caedd09fe.tar.gz |
[core] test OffscreenTexture renderability before using them
-rw-r--r-- | src/mbgl/gfx/offscreen_texture.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/offscreen_texture.cpp | 9 | ||||
-rw-r--r-- | src/mbgl/gl/offscreen_texture.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_heatmap_layer.cpp | 5 |
4 files changed, 14 insertions, 4 deletions
diff --git a/src/mbgl/gfx/offscreen_texture.hpp b/src/mbgl/gfx/offscreen_texture.hpp index 1eaf4557c6..5690ff7625 100644 --- a/src/mbgl/gfx/offscreen_texture.hpp +++ b/src/mbgl/gfx/offscreen_texture.hpp @@ -17,6 +17,8 @@ protected: public: virtual ~OffscreenTexture() = default; + virtual bool isRenderable() = 0; + virtual PremultipliedImage readStillImage() = 0; virtual gfx::Texture& getTexture() = 0; }; diff --git a/src/mbgl/gl/offscreen_texture.cpp b/src/mbgl/gl/offscreen_texture.cpp index 96d8b7e4c4..0b06fedf46 100644 --- a/src/mbgl/gl/offscreen_texture.cpp +++ b/src/mbgl/gl/offscreen_texture.cpp @@ -75,6 +75,15 @@ OffscreenTexture::OffscreenTexture( size, std::make_unique<OffscreenTextureResource>(context, size_, renderbuffer, type)) { } +bool OffscreenTexture::isRenderable() { + try { + getResource<OffscreenTextureResource>().bind(); + return true; + } catch (const std::runtime_error& ex) { + return false; + } +} + PremultipliedImage OffscreenTexture::readStillImage() { return getResource<OffscreenTextureResource>().readStillImage(); } diff --git a/src/mbgl/gl/offscreen_texture.hpp b/src/mbgl/gl/offscreen_texture.hpp index 5b211df505..07da4f57e2 100644 --- a/src/mbgl/gl/offscreen_texture.hpp +++ b/src/mbgl/gl/offscreen_texture.hpp @@ -18,6 +18,8 @@ public: gfx::Renderbuffer<gfx::RenderbufferPixelType::Depth>&, gfx::TextureChannelDataType type = gfx::TextureChannelDataType::UnsignedByte); + bool isRenderable() override; + PremultipliedImage readStillImage() override; gfx::Texture& getTexture() override; }; diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 15345ffe9e..f8a159f3da 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -62,10 +62,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) { if (parameters.context.supportsHalfFloatTextures) { renderTexture = parameters.context.createOffscreenTexture(size, gfx::TextureChannelDataType::HalfFloat); - // TODO: try binding in the offscreen texture constructor - try { - renderTexture->getResource<gl::RenderableResource>().bind(); - } catch (const std::runtime_error& ex) { + if (!renderTexture->isRenderable()) { // can't render to a half-float texture; falling back to unsigned byte one renderTexture.reset(); parameters.context.supportsHalfFloatTextures = false; |