| 499 | //=========================================================================== |
| 500 | |
| 501 | TArray<uint8_t> OpenGLFrameBuffer::GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma) |
| 502 | { |
| 503 | const auto &viewport = mOutputLetterbox; |
| 504 | |
| 505 | // Grab what is in the back buffer. |
| 506 | // We cannot rely on SCREENWIDTH/HEIGHT here because the output may have been scaled. |
| 507 | TArray<uint8_t> pixels; |
| 508 | pixels.Resize(viewport.width * viewport.height * 3); |
| 509 | glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 510 | glReadPixels(viewport.left, viewport.top, viewport.width, viewport.height, GL_RGB, GL_UNSIGNED_BYTE, &pixels[0]); |
| 511 | glPixelStorei(GL_PACK_ALIGNMENT, 4); |
| 512 | |
| 513 | // Copy to screenshot buffer: |
| 514 | int w = SCREENWIDTH; |
| 515 | int h = SCREENHEIGHT; |
| 516 | |
| 517 | TArray<uint8_t> ScreenshotBuffer(w * h * 3, true); |
| 518 | |
| 519 | float rcpWidth = 1.0f / w; |
| 520 | float rcpHeight = 1.0f / h; |
| 521 | for (int y = 0; y < h; y++) |
| 522 | { |
| 523 | for (int x = 0; x < w; x++) |
| 524 | { |
| 525 | float u = (x + 0.5f) * rcpWidth; |
| 526 | float v = (y + 0.5f) * rcpHeight; |
| 527 | int sx = u * viewport.width; |
| 528 | int sy = v * viewport.height; |
| 529 | int sindex = (sx + sy * viewport.width) * 3; |
| 530 | int dindex = (x + (h - y - 1) * w) * 3; |
| 531 | ScreenshotBuffer[dindex] = pixels[sindex]; |
| 532 | ScreenshotBuffer[dindex + 1] = pixels[sindex + 1]; |
| 533 | ScreenshotBuffer[dindex + 2] = pixels[sindex + 2]; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | pitch = w * 3; |
| 538 | color_type = SS_RGB; |
| 539 | |
| 540 | // Screenshot should not use gamma correction if it was already applied to rendered image |
| 541 | gamma = 1; |
| 542 | if (vid_hdr_active && vid_fullscreen) |
| 543 | gamma *= 2.2f; |
| 544 | return ScreenshotBuffer; |
| 545 | } |
| 546 | |
| 547 | //=========================================================================== |
| 548 | // |
no test coverage detected