diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 4b07f4c346..aface30606 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -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 diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index fac05f4947..cd1e4ec944 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -2740,8 +2740,23 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) } } } else { - result->data.resize(w * h * 4); - f->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, result->data.data()); + 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);