[core] test OffscreenTexture renderability before using them

This commit is contained in:
Konstantin Käfer
2019-04-03 14:18:54 +02:00
parent 7081d5e154
commit b1a2513b61
4 changed files with 14 additions and 4 deletions

View File

@@ -17,6 +17,8 @@ protected:
public:
virtual ~OffscreenTexture() = default;
virtual bool isRenderable() = 0;
virtual PremultipliedImage readStillImage() = 0;
virtual gfx::Texture& getTexture() = 0;
};

View File

@@ -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();
}

View File

@@ -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;
};

View File

@@ -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;