void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height) { IntRect bounds; bounds.left = 0; bounds.top = 0; bounds.width = width; bounds.height = height; // we must be sure the GPU finished reading from the buffer before we fill it with new data. glFinish(); // Switch to render buffers dimensioned for the savepic mBuffers = mSaveBuffers; hw_ClearFakeFlat(); gl_RenderState.SetVertexBuffer(screen->mVertexData); screen->mVertexData->Reset(); screen->mLights->Clear(); screen->mViewpoints->Clear(); // This shouldn't overwrite the global viewpoint even for a short time. FRenderViewpoint savevp; sector_t *viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); glDisable(GL_STENCIL_TEST); gl_RenderState.SetNoSoftLightLevel(); CopyToBackbuffer(&bounds, false); // strictly speaking not needed as the glReadPixels should block until the scene is rendered, but this is to safeguard against shitty drivers glFinish(); int numpixels = width * height; uint8_t * scr = (uint8_t *)M_Malloc(numpixels * 3); glReadPixels(0,0,width, height,GL_RGB,GL_UNSIGNED_BYTE,scr); DoWriteSavePic(file, SS_RGB, scr, width, height, viewsector, true); M_Free(scr); // Switch back the screen render buffers screen->SetViewportRects(nullptr); mBuffers = mScreenBuffers; }
void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height) { GL_IRECT bounds; bounds.left=0; bounds.top=0; bounds.width=width; bounds.height=height; glFlush(); SetFixedColormap(player); gl_RenderState.SetVertexBuffer(mVBO); GLRenderer->mVBO->Reset(); if (!gl.legacyMode) GLRenderer->mLights->Clear(); // Check if there's some lights. If not some code can be skipped. TThinkerIterator<ADynamicLight> it(STAT_DLIGHT); GLRenderer->mLightCount = ((it.Next()) != NULL); sector_t *viewsector = RenderViewpoint(players[consoleplayer].camera, &bounds, FieldOfView.Degrees, 1.6f, 1.6f, true, false); glDisable(GL_STENCIL_TEST); gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetSoftLightLevel(-1); screen->Begin2D(false); if (!FGLRenderBuffers::IsEnabled()) { DrawBlend(viewsector); } CopyToBackbuffer(&bounds, false); glFlush(); byte * scr = (byte *)M_Malloc(width * height * 3); glReadPixels(0,0,width, height,GL_RGB,GL_UNSIGNED_BYTE,scr); M_CreatePNG (file, scr + ((height-1) * width * 3), NULL, SS_RGB, width, height, -width*3); M_Free(scr); }