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 <laszlo.agocs@qt.io>
This commit is contained in:
Jonas Karlsson 2024-02-19 18:09:05 +01:00
parent 4c1e23c9d3
commit aedbc7ba7a

View File

@ -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());