From aedbc7ba7a00d473764323969560bc30fba35523 Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Mon, 19 Feb 2024 18:09:05 +0100 Subject: [PATCH] rhi: gl: Add R16F/R32F handling in pixel readback When reading pixels back from a QRhiTexture if the format is R16F/R32F then we will read pixels to a buffer with just a red component comprised of (half) floats instead of the default case (RGBA). This is useful when reading back a shadow map. Change-Id: Iff2881992f0341252d5c565b5dd64bed078319bc Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhigles2.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 2f0659909f1..d42e72301b9 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -3386,6 +3386,14 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) result->data.resize(w * h * 8); f->glReadPixels(0, 0, w, h, GL_RGBA, GL_HALF_FLOAT, result->data.data()); break; + case QRhiTexture::R16F: + result->data.resize(w * h * 2); + f->glReadPixels(0, 0, w, h, GL_RED, GL_HALF_FLOAT, result->data.data()); + break; + case QRhiTexture::R32F: + result->data.resize(w * h * 4); + f->glReadPixels(0, 0, w, h, GL_RED, GL_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());