rhi: gl: Attempt reading back floating point formats

...in the hope that they may work. If not, that's it, but at least we
tried.

Task-number: QTBUG-76970
Change-Id: I134c5cc4cfb5ad1e6f9edbfcf506df20022e127a
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
Laszlo Agocs 2021-02-02 12:41:45 +01:00
parent eadbf2dd0b
commit d136299bb8
2 changed files with 27 additions and 9 deletions

View File

@ -618,13 +618,16 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
dFdy(), and fwidth() are supported in shaders.
\value ReadBackAnyTextureFormat Indicates that reading back texture
contents can be expected to work for any QRhiTexture::Format. When reported
as false, which will typically happen with OpenGL, only the formats
QRhiTexture::RGBA8 and QRhiTexture::BGRA8 are guaranteed to be supported
for readbacks. In addition, with OpenGL, but not OpenGL ES, reading back
the 1 byte per component formats QRhiTexture::R8 and
QRhiTexture::RED_OR_ALPHA8 are supported as well. Backends other than
OpenGL can be expected to return true for this feature.
contents can be expected to work for any QRhiTexture::Format. Backends
other than OpenGL can be expected to return true for this feature. When
reported as false, which will typically happen with OpenGL, only the
formats QRhiTexture::RGBA8 and QRhiTexture::BGRA8 are guaranteed to be
supported for readbacks. In addition, with OpenGL, but not OpenGL ES,
reading back the 1 byte per component formats QRhiTexture::R8 and
QRhiTexture::RED_OR_ALPHA8 are supported as well. Reading back floating
point formats QRhiTexture::RGBA16F and RGBA32F may work too with OpenGL, as
long as the implementation provides support for these, but QRhi can give no
guarantees, as indicated by this flag.
\value PipelineCacheDataLoadSave Indicates that the pipelineCacheData() and
setPipelineCacheData() functions are functional. When not supported, the

View File

@ -2740,8 +2740,23 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
}
}
} else {
switch (result->format) {
// For floating point formats try it because this can be
// relevant for some use cases; if it works, then fine, if
// not, there's nothing we can do.
case QRhiTexture::RGBA16F:
result->data.resize(w * h * 8);
f->glReadPixels(0, 0, w, h, GL_RGBA, GL_HALF_FLOAT, result->data.data());
break;
case QRhiTexture::RGBA32F:
result->data.resize(w * h * 16);
f->glReadPixels(0, 0, w, h, GL_RGBA, GL_FLOAT, result->data.data());
break;
default:
result->data.resize(w * h * 4);
f->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, result->data.data());
break;
}
}
} else {
result->data.resize(w * h * 4);