diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2021-02-02 12:41:45 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2021-02-03 16:07:53 +0100 |
commit | 7a0f2cafaf65826c696eb736ddb5c1067d09ead2 (patch) | |
tree | 785f5b83aaa001a5d4c5e3542ccf85a1cbd3f0e5 /src | |
parent | 936d499ed4a27e6836e9525114830c57fbfd37f3 (diff) |
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>
(cherry picked from commit d136299bb83f5343a62f9e02693f6737981edf62)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 17 | ||||
-rw-r--r-- | src/gui/rhi/qrhigles2.cpp | 19 |
2 files changed, 27 insertions, 9 deletions
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); |