[core] test OffscreenTexture renderability before using them
This commit is contained in:
@@ -17,6 +17,8 @@ protected:
|
||||
public:
|
||||
virtual ~OffscreenTexture() = default;
|
||||
|
||||
virtual bool isRenderable() = 0;
|
||||
|
||||
virtual PremultipliedImage readStillImage() = 0;
|
||||
virtual gfx::Texture& getTexture() = 0;
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user