God rays tweaks. Also made it so that FBO's are now used everywhere and not just for the level rendering.

This commit is contained in:
Andrei Drexler 2011-03-15 18:28:58 +00:00
parent 2fff41d467
commit 7b882ae08f
4 changed files with 119 additions and 92 deletions

View File

@ -500,15 +500,6 @@ void RB_BeginDrawingView (void) {
// 2D images again
backEnd.projection2D = qfalse;
if (backEnd.refdef.width == glConfig.vidWidth && backEnd.refdef.height == glConfig.vidHeight && 0 == (backEnd.refdef.rdflags & RDF_NOWORLDMODEL))
{
R_FBO_Bind(tr.fbo.full[0]);
}
else
{
R_FBO_Bind(NULL);
}
//
// set the modelview matrix for the viewer
//
@ -826,24 +817,22 @@ RENDER BACK END THREAD FUNCTIONS
/*
================
RB_SetGL2D_Level
RB_SetGL2D_Ex
================
*/
void RB_SetGL2D_Level(int level)
void RB_SetGL2D_Ex(int x, int y, int width, int height)
{
matrix_t matrix;
int width = glConfig.vidWidth >> level;
int height = glConfig.vidHeight >> level;
backEnd.projection2D = qtrue;
// set 2D virtual screen size
qglViewport( 0, 0, width, height );
qglScissor( 0, 0, width, height );
qglViewport( x, y, width, height );
qglScissor( x, y, width, height );
Matrix16Ortho(0, width, height, 0, 0, 1, matrix);
Matrix16Ortho(x, x+width, y+height, y, 0, 1, matrix);
GL_SetProjectionMatrix(matrix);
Matrix16Identity(matrix);
GL_SetModelviewMatrix(matrix);
@ -860,6 +849,21 @@ void RB_SetGL2D_Level(int level)
backEnd.refdef.floatTime = backEnd.refdef.time * 0.001f;
}
/*
================
RB_SetGL2D_Level
================
*/
void RB_SetGL2D_Level(int level)
{
int x = 0;
int y = 0;
int width = glConfig.vidWidth >> level;
int height = glConfig.vidHeight >> level;
RB_SetGL2D_Ex(x, y, width, height);
}
/*
================
RB_SetGL2D
@ -1338,6 +1342,8 @@ const void *RB_SwapBuffers( const void *data ) {
RB_ShowImages();
}
RB_FBO_Blit();
cmd = (const swapBuffersCommand_t *)data;
// we measure overdraw by reading back the stencil buffer and

View File

@ -265,18 +265,21 @@ void R_FBO_AddColorBuffer(fbo_t* fbo, fboColorBuffer_t* color)
}
}
/*
===============
R_FBO_Bind
===============
*/
/*
===============
R_FBO_Bind
===============
*/
fbo_t* R_FBO_Bind(fbo_t* fbo)
{
fbo_t* old = glState.currentFBO;
GLuint id = 0;
if (!glRefConfig.framebufferObject)
return old;
{
glState.currentFBO = NULL;
return NULL;
}
if (old == fbo)
return old;
@ -303,11 +306,11 @@ fbo_t* R_FBO_Bind(fbo_t* fbo)
return old;
}
/*
===============
R_FBO_BindColorBuffer
===============
*/
/*
===============
R_FBO_BindColorBuffer
===============
*/
void R_FBO_BindColorBuffer(fbo_t* fbo, int index)
{
@ -322,28 +325,28 @@ void R_FBO_BindColorBuffer(fbo_t* fbo, int index)
int id;
int width = color->buf->width;
int height = color->buf->height;
qglBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, color->fboResolve[0]);
qglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, color->fboResolve[1]);
qglBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
if (glState.currentFBO)
id = glState.currentFBO->id;
else
id = 0;
qglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, id);
qglBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, id);
}
qglBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, color->fboResolve[0]);
qglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, color->fboResolve[1]);
qglBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
if (glState.currentFBO)
id = glState.currentFBO->id;
else
id = 0;
qglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, id);
qglBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, id);
}
}
GL_Bind(color->tex);
}
/*
===============
R_FBO_CreateEx
===============
*/
/*
===============
R_FBO_CreateEx
===============
*/
fbo_t* R_FBO_CreateEx(const char* name, int numColorBuffers, fboColorBuffer_t** colorBuffers, fboZBuffer_t* depth, fboStencilBuffer_t* stencil)
{
@ -389,11 +392,11 @@ fbo_t* R_FBO_CreateSimple(const char* name, fboColorBuffer_t* color, fboZBuffer_
return R_FBO_CreateEx(name, color != NULL, &color, depth, stencil);
}
/*
===============
R_FBO_CreateDefaultBuffers
===============
*/
/*
===============
R_FBO_CreateDefaultBuffers
===============
*/
static void R_FBO_CreateDefaultBuffers(void)
{
@ -426,11 +429,11 @@ static void R_FBO_CreateDefaultBuffers(void)
ri.Printf(PRINT_DEVELOPER, "...created %d FBOs\n", tr.fbo.numFBOs);
}
/*
===============
R_InitFBOs
===============
*/
/*
===============
R_InitFBOs
===============
*/
void R_InitFBOs(void)
{
@ -456,16 +459,16 @@ void R_InitFBOs(void)
ri.Printf(PRINT_ALL, "MSAA enabled with %d samples (max %d)\n", tr.fbo.samples, maxSamples);
R_FBO_CreateDefaultBuffers();
ri.Printf(PRINT_DEVELOPER, "...created %d FBOs\n", tr.fbo.numFBOs);
R_FBO_Bind(tr.fbo.full[0]);
}
/*
===============
R_ShutDownFBOs
===============
*/
/*
===============
R_ShutDownFBOs
===============
*/
void R_ShutDownFBOs(void)
{

View File

@ -2757,8 +2757,11 @@ void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, byte *color, flo
void RB_ShowImages( void );
void RB_SetGL2D(void);
void RB_SetGL2D_Ex(int x, int y, int width, int height);
void RB_SetGL2D_Level(int level);
void RB_SetGL2D(void);
void RB_FBO_Blit();
void RB_PostProcess( void );

View File

@ -209,7 +209,7 @@ static void RB_GodRays(void)
R_FBO_BindColorBuffer(tr.fbo.full[1], 0);
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
mul = 0.5f;
mul = 0.75f;
RB_Color4f(mul, mul, mul, 1.f);
RB_DrawQuad(x, y, w2, h2, 0.f, 0.f, 1.f, 1.f);
@ -217,7 +217,7 @@ static void RB_GodRays(void)
R_FBO_Bind(tr.fbo.quarter[1]);
R_FBO_BindColorBuffer(tr.fbo.quarter[0], 0);
mul = 0.5f;
mul = 0.25f;
RB_Color4f(mul, mul, mul, 1.f);
RB_DrawScaledQuad(x, y, w2, h2, pos[0], pos[1], 1.f);
@ -231,6 +231,9 @@ static void RB_GodRays(void)
R_FBO_Bind(tr.fbo.quarter[0]);
R_FBO_BindColorBuffer(tr.fbo.quarter[1], 0);
mul = 1.f/6.f;
RB_Color4f(mul, mul, mul, 1.f/5.f);
RB_DrawScaledQuad(x, y, w2, h2, pos[0], pos[1], 1.f);
RB_RadialBlur(5, 5.f, x, y, w2, h2, pos[0], pos[1], 1.f);
RB_Color4f(1.f, 1.f, 1.f, 1.f);
@ -245,31 +248,8 @@ static void RB_GodRays(void)
RB_DrawQuad(x, y, w, h, 0.f, 0.f, 1.f, 1.f);
}
static void RB_BlitFBO(void)
void RB_FBO_Set2D(void)
{
R_FBO_Bind(NULL);
RB_Color4f(1.f, 1.f, 1.f, 1.f);
R_FBO_BindColorBuffer(tr.fbo.full[0], 0);
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
RB_DrawQuad(0.f, 0.f, glConfig.vidWidth, glConfig.vidHeight, 0.f, 0.f, 1.f, 1.f);
}
/*
================
RB_PostProcess
================
*/
void RB_PostProcess(void)
{
if (!glState.currentFBO)
return;
RB_DrawQuad = NULL;
RB_Color4f = NULL;
@ -315,7 +295,42 @@ void RB_PostProcess(void)
GL_SelectTexture(0);
RB_Color4f(1.f, 1.f, 1.f, 1.f);
RB_GodRays();
RB_BlitFBO();
}
/*
================
RB_FBO_Blit
================
*/
void RB_FBO_Blit(void)
{
fbo_t* fbo = R_FBO_Bind(NULL);
if (!fbo)
return;
RB_FBO_Set2D();
R_FBO_BindColorBuffer(fbo, 0);
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
RB_DrawQuad(0.f, 0.f, glConfig.vidWidth, glConfig.vidHeight, 0.f, 0.f, 1.f, 1.f);
R_FBO_Bind(fbo);
}
/*
================
RB_PostProcess
================
*/
void RB_PostProcess(void)
{
if (!glState.currentFBO)
return;
RB_FBO_Set2D();
RB_GodRays();
}