/* ============= RB_SwapBuffers ============= */ const void *RB_SwapBuffers( const void *data ) { const swapBuffersCommand_t *cmd; // finish any 2D drawing if needed if ( tess.numIndexes ) { RB_EndSurface(); } // texture swapping test if ( r_showImages->integer ) { RB_ShowImages(); } cmd = (const swapBuffersCommand_t *)data; // we measure overdraw by reading back the stencil buffer and // counting up the number of increments that have happened if ( r_measureOverdraw->integer ) { int i; long sum = 0; unsigned char *stencilReadback; stencilReadback = ri.Hunk_AllocateTempMemory( glConfig.vidWidth * glConfig.vidHeight ); qglReadPixels( 0, 0, glConfig.vidWidth, glConfig.vidHeight, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencilReadback ); for ( i = 0; i < glConfig.vidWidth * glConfig.vidHeight; i++ ) { sum += stencilReadback[i]; } backEnd.pc.c_overDraw += sum; ri.Hunk_FreeTempMemory( stencilReadback ); } #ifdef FRAMEBUFFER_AND_GLSL_SUPPORT // Check to render Framebuffer if still not done if (!backEnd.projection2D) { R_FrameBuffer_EndFrame(); } #endif if ( !glState.finishCalled ) { qglFinish(); } GLimp_LogComment( "***************** RB_SwapBuffers *****************\n\n\n" ); GLimp_EndFrame(); backEnd.projection2D = qfalse; return (const void *)(cmd + 1); }
/* ============= RE_StretchRaw FIXME: not exactly backend Stretches a raw 32 bit power of 2 bitmap image over the given screen rectangle. Used for cinematics. ============= */ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty) { int i, j; int start, end; if ( !tr.registered ) { return; } R_SyncRenderThread(); #ifdef FRAMEBUFFER_AND_GLSL_SUPPORT // Needed here to support cinematics R_FrameBuffer_EndFrame(); #endif // we definately want to sync every frame for the cinematics qglFinish(); start = end = 0; if ( r_speeds->integer ) { start = ri.Milliseconds(); } // make sure rows and cols are powers of 2 for ( i = 0 ; ( 1 << i ) < cols ; i++ ) { } for ( j = 0 ; ( 1 << j ) < rows ; j++ ) { } if ( ( 1 << i ) != cols || ( 1 << j ) != rows) { ri.Error (ERR_DROP, "Draw_StretchRaw: size not a power of 2: %i by %i", cols, rows); } GL_Bind( tr.scratchImage[client] ); // if the scratchImage isn't in the format we want, specify it as a new texture if ( cols != tr.scratchImage[client]->width || rows != tr.scratchImage[client]->height ) { tr.scratchImage[client]->width = tr.scratchImage[client]->uploadWidth = cols; tr.scratchImage[client]->height = tr.scratchImage[client]->uploadHeight = rows; qglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, cols, rows, 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); } else { if (dirty) { // otherwise, just subimage upload it so that drivers can tell we are going to be changing // it and don't try and do a texture compression qglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, cols, rows, GL_RGBA, GL_UNSIGNED_BYTE, data ); } } if ( r_speeds->integer ) { end = ri.Milliseconds(); ri.Printf( PRINT_ALL, "qglTexSubImage2D %i, %i: %i msec\n", cols, rows, end - start ); } RB_SetGL2D(); qglColor3f( tr.identityLight, tr.identityLight, tr.identityLight ); qglBegin (GL_QUADS); qglTexCoord2f ( 0.5f / cols, 0.5f / rows ); qglVertex2f (x, y); qglTexCoord2f ( ( cols - 0.5f ) / cols , 0.5f / rows ); qglVertex2f (x+w, y); qglTexCoord2f ( ( cols - 0.5f ) / cols, ( rows - 0.5f ) / rows ); qglVertex2f (x+w, y+h); qglTexCoord2f ( 0.5f / cols, ( rows - 0.5f ) / rows ); qglVertex2f (x, y+h); qglEnd (); }
/* ==================== RB_ExecuteRenderCommands This function will be called synchronously if running without smp extensions, or asynchronously by another thread. ==================== */ void RB_ExecuteRenderCommands( const void *data ) { int t1, t2; t1 = ri.Milliseconds (); if ( !r_smp->integer || data == backEndData[0]->commands.cmds ) { backEnd.smpFrame = 0; } else { backEnd.smpFrame = 1; } while ( 1 ) { data = PADP(data, sizeof(void *)); switch ( *(const int *)data ) { case RC_SET_COLOR: data = RB_SetColor( data ); break; case RC_STRETCH_PIC: #ifdef FRAMEBUFFER_AND_GLSL_SUPPORT R_FrameBuffer_EndFrame(); #endif data = RB_StretchPic( data ); break; case RC_DRAW_SURFS: data = RB_DrawSurfs( data ); break; case RC_DRAW_BUFFER: #ifdef FRAMEBUFFER_AND_GLSL_SUPPORT data = useFrameBuffer ? RB_DrawFrameBuffer( data ) : RB_DrawBuffer( data ); #else data = RB_DrawBuffer( data ); #endif break; case RC_SWAP_BUFFERS: data = RB_SwapBuffers( data ); break; //these two use a hack to let them copy the framebuffer effects too case RC_SCREENSHOT: #ifdef FRAMEBUFFER_AND_GLSL_SUPPORT R_FrameBufferUnBind(); #endif data = RB_TakeScreenshotCmd( data ); #ifdef FRAMEBUFFER_AND_GLSL_SUPPORT R_FrameBufferBind(); #endif break; case RC_VIDEOFRAME: #ifdef FRAMEBUFFER_AND_GLSL_SUPPORT R_FrameBufferUnBind(); #endif data = RB_TakeVideoFrameCmd( data ); #ifdef FRAMEBUFFER_AND_GLSL_SUPPORT R_FrameBufferBind(); #endif break; case RC_COLORMASK: data = RB_ColorMask(data); break; case RC_CLEARDEPTH: data = RB_ClearDepth(data); break; case RC_END_OF_LIST: default: // stop rendering on this thread t2 = ri.Milliseconds (); backEnd.pc.msec = t2 - t1; return; } } }
/* ============= RB_SwapBuffers ============= */ static int RB_SwapBuffers( const void *data ) { // finish any 2D drawing if needed if ( tess.numIndexes ) { RB_EndSurface(); } // texture swapping test if ( r_showImages->integer ) { RB_ShowImages(); } backEnd.projection2D = qfalse; tr.capturingDofOrStereo = qfalse; tr.latestDofOrStereoFrame = qfalse; /* Take and merge DOF frames */ if ( r_stereoSeparation->value <= 0.0f && !tr.finishStereo) { if ( R_MME_MultiPassNext() ) { return 1; } } else if ( r_stereoSeparation->value > 0.0f) { if ( R_MME_MultiPassNextStereo() ) { return 1; } } // we measure overdraw by reading back the stencil buffer and // counting up the number of increments that have happened if ( r_measureOverdraw->integer ) { int i; long sum = 0; unsigned char *stencilReadback; stencilReadback = ri.Hunk_AllocateTempMemory( glConfig.vidWidth * glConfig.vidHeight ); qglReadPixels( 0, 0, glConfig.vidWidth, glConfig.vidHeight, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencilReadback ); for ( i = 0; i < glConfig.vidWidth * glConfig.vidHeight; i++ ) { sum += stencilReadback[i]; } backEnd.pc.c_overDraw += sum; ri.Hunk_FreeTempMemory( stencilReadback ); } if ( !glState.finishCalled ) { qglFinish(); } /* Allow MME to take a screenshot */ if ( r_stereoSeparation->value < 0.0f && tr.finishStereo) { tr.capturingDofOrStereo = qtrue; tr.latestDofOrStereoFrame = qtrue; Cvar_SetValue("r_stereoSeparation", -r_stereoSeparation->value); return 1; } else if ( r_stereoSeparation->value <= 0.0f) { if ( R_MME_TakeShot( ) && r_stereoSeparation->value != 0.0f) { tr.capturingDofOrStereo = qtrue; tr.latestDofOrStereoFrame = qfalse; Cvar_SetValue("r_stereoSeparation", -r_stereoSeparation->value); tr.finishStereo = qtrue; return 1; } } else if ( r_stereoSeparation->value > 0.0f) { if ( tr.finishStereo) { R_MME_TakeShotStereo( ); R_MME_DoNotTake( ); Cvar_SetValue("r_stereoSeparation", -r_stereoSeparation->value); tr.finishStereo = qfalse; } } R_FrameBuffer_EndFrame(); GLimp_LogComment( "***************** RB_SwapBuffers *****************\n\n\n" ); GLimp_EndFrame(); return 0; }