1532 // OpenGL gives ABGR (i.e. RGBA backwards); Qt wants ARGB |
1532 // OpenGL gives ABGR (i.e. RGBA backwards); Qt wants ARGB |
1533 for (int y = 0; y < h; y++) { |
1533 for (int y = 0; y < h; y++) { |
1534 uint *q = (uint*)img.scanLine(y); |
1534 uint *q = (uint*)img.scanLine(y); |
1535 for (int x=0; x < w; ++x) { |
1535 for (int x=0; x < w; ++x) { |
1536 const uint pixel = *q; |
1536 const uint pixel = *q; |
1537 *q = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | (pixel & 0xff00ff00); |
1537 if (alpha_format && include_alpha) { |
|
1538 *q = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) |
|
1539 | (pixel & 0xff00ff00); |
|
1540 } else { |
|
1541 *q = 0xff000000 | ((pixel << 16) & 0xff0000) |
|
1542 | ((pixel >> 16) & 0xff) | (pixel & 0x00ff00); |
|
1543 } |
|
1544 |
1538 q++; |
1545 q++; |
1539 } |
1546 } |
1540 } |
1547 } |
1541 |
1548 |
1542 } |
1549 } |
1543 img = img.mirrored(); |
1550 img = img.mirrored(); |
1544 } |
1551 } |
1545 |
1552 |
1546 QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha) |
1553 QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha) |
1547 { |
1554 { |
1548 QImage img(size, alpha_format ? QImage::Format_ARGB32 : QImage::Format_RGB32); |
1555 QImage img(size, (alpha_format && include_alpha) ? QImage::Format_ARGB32 |
|
1556 : QImage::Format_RGB32); |
1549 int w = size.width(); |
1557 int w = size.width(); |
1550 int h = size.height(); |
1558 int h = size.height(); |
1551 glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); |
1559 glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); |
1552 convertFromGLImage(img, w, h, alpha_format, include_alpha); |
1560 convertFromGLImage(img, w, h, alpha_format, include_alpha); |
1553 return img; |
1561 return img; |