gl: Check for image validity in readback
Returning a null QImage is preferable over passing a null bits() to glReadPixels. (matters when QImage's malloc() gives null, thus 'd' is null -> isNull() == true) Fixes: QTBUG-113127 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: Ieca4d91eefdea47da5251dabe77cc31b48eb0e28 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
ab4125685a
commit
11209cfde6
@ -1344,7 +1344,8 @@ static inline QImage qt_gl_read_framebuffer_rgba8(const QSize &size, bool includ
|
||||
bool isOpenGL12orBetter = !context->isOpenGLES() && (context->format().majorVersion() >= 2 || context->format().minorVersion() >= 2);
|
||||
if (isOpenGL12orBetter) {
|
||||
QImage img(size, include_alpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32);
|
||||
funcs->glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, img.bits());
|
||||
if (!img.isNull())
|
||||
funcs->glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, img.bits());
|
||||
return img;
|
||||
}
|
||||
|
||||
@ -1354,7 +1355,8 @@ static inline QImage qt_gl_read_framebuffer_rgba8(const QSize &size, bool includ
|
||||
// BGRA capable impl would return BGRA from there)
|
||||
|
||||
QImage rgbaImage(size, include_alpha ? QImage::Format_RGBA8888_Premultiplied : QImage::Format_RGBX8888);
|
||||
funcs->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaImage.bits());
|
||||
if (!rgbaImage.isNull())
|
||||
funcs->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaImage.bits());
|
||||
return rgbaImage;
|
||||
}
|
||||
|
||||
@ -1362,7 +1364,8 @@ static inline QImage qt_gl_read_framebuffer_rgb10a2(const QSize &size, bool incl
|
||||
{
|
||||
// We assume OpenGL 1.2+ or ES 3.0+ here.
|
||||
QImage img(size, include_alpha ? QImage::Format_A2BGR30_Premultiplied : QImage::Format_BGR30);
|
||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, img.bits());
|
||||
if (!img.isNull())
|
||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, img.bits());
|
||||
return img;
|
||||
}
|
||||
|
||||
@ -1370,7 +1373,8 @@ static inline QImage qt_gl_read_framebuffer_rgba16(const QSize &size, bool inclu
|
||||
{
|
||||
// We assume OpenGL 1.2+ or ES 3.0+ here.
|
||||
QImage img(size, include_alpha ? QImage::Format_RGBA64_Premultiplied : QImage::Format_RGBX64);
|
||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_SHORT, img.bits());
|
||||
if (!img.isNull())
|
||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_SHORT, img.bits());
|
||||
return img;
|
||||
}
|
||||
|
||||
@ -1378,14 +1382,16 @@ static inline QImage qt_gl_read_framebuffer_rgba16f(const QSize &size, bool incl
|
||||
{
|
||||
// We assume OpenGL (ES) 3.0+ here.
|
||||
QImage img(size, include_alpha ? QImage::Format_RGBA16FPx4_Premultiplied : QImage::Format_RGBX16FPx4);
|
||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_HALF_FLOAT, img.bits());
|
||||
if (!img.isNull())
|
||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_HALF_FLOAT, img.bits());
|
||||
return img;
|
||||
}
|
||||
|
||||
static inline QImage qt_gl_read_framebuffer_rgba32f(const QSize &size, bool include_alpha, QOpenGLContext *context)
|
||||
{
|
||||
QImage img(size, include_alpha ? QImage::Format_RGBA32FPx4_Premultiplied : QImage::Format_RGBX32FPx4);
|
||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_FLOAT, img.bits());
|
||||
if (!img.isNull())
|
||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_FLOAT, img.bits());
|
||||
return img;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user