Don't create images/framebuffers that won't be used, and add checks before use.

This commit is contained in:
SmileTheory 2014-01-12 20:52:36 -08:00
parent d4fc617cec
commit eea652f5c5
6 changed files with 69 additions and 48 deletions

View file

@ -461,7 +461,7 @@ void RB_BeginDrawingView (void) {
FBO_Bind(backEnd.viewParms.targetFbo);
// FIXME: hack for cubemap testing
if (backEnd.viewParms.targetFbo == tr.renderCubeFbo)
if (tr.renderCubeFbo && backEnd.viewParms.targetFbo == tr.renderCubeFbo)
{
//qglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + backEnd.viewParms.targetFboLayer, backEnd.viewParms.targetFbo->colorImage[0]->texnum, 0);
qglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + backEnd.viewParms.targetFboLayer, tr.cubemaps[backEnd.viewParms.targetFboCubemapIndex]->texnum, 0);
@ -501,7 +501,7 @@ void RB_BeginDrawingView (void) {
}
// clear to black for cube maps
if (backEnd.viewParms.targetFbo == tr.renderCubeFbo)
if (tr.renderCubeFbo && backEnd.viewParms.targetFbo == tr.renderCubeFbo)
{
clearBits |= GL_COLOR_BUFFER_BIT;
qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
@ -1081,7 +1081,7 @@ const void *RB_DrawSurfs( const void *data ) {
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, tr.hdrDepthFbo, NULL, NULL, NULL, 0);
}
if (backEnd.viewParms.flags & VPF_USESUNLIGHT)
if (r_sunlightMode->integer && backEnd.viewParms.flags & VPF_USESUNLIGHT)
{
vec4_t quadVerts[4];
vec2_t texCoords[4];
@ -1296,7 +1296,7 @@ const void *RB_DrawSurfs( const void *data ) {
RB_RenderFlares();
}
if (glRefConfig.framebufferObject && backEnd.viewParms.targetFbo == tr.renderCubeFbo)
if (glRefConfig.framebufferObject && tr.renderCubeFbo && backEnd.viewParms.targetFbo == tr.renderCubeFbo)
{
FBO_Bind(NULL);
GL_SelectTexture(TB_CUBEMAP);
@ -1558,13 +1558,19 @@ const void *RB_CapShadowMap(const void *data)
GL_SelectTexture(0);
if (cmd->cubeSide != -1)
{
GL_Bind(tr.shadowCubemaps[cmd->map]);
qglCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + cmd->cubeSide, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0);
if (tr.shadowCubemaps[cmd->map])
{
GL_Bind(tr.shadowCubemaps[cmd->map]);
qglCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + cmd->cubeSide, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0);
}
}
else
{
GL_Bind(tr.pshadowMaps[cmd->map]);
qglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0);
if (tr.pshadowMaps[cmd->map])
{
GL_Bind(tr.pshadowMaps[cmd->map]);
qglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0);
}
}
}
@ -1666,7 +1672,7 @@ const void *RB_PostProcess(const void *data)
else
RB_GaussianBlur(backEnd.refdef.blurFactor);
if (0)
if (0 && r_sunlightMode->integer)
{
ivec4_t dstBox;
VectorSet4(dstBox, 0, 0, 128, 128);

View file

@ -465,34 +465,48 @@ void FBO_Init(void)
}
// FIXME: Don't use separate color/depth buffers for a shadow buffer
for( i = 0; i < MAX_DRAWN_PSHADOWS; i++)
if (MAX_DRAWN_PSHADOWS && tr.pshadowMaps[0])
{
tr.pshadowFbos[i] = FBO_Create(va("_shadowmap%d", i), tr.pshadowMaps[i]->width, tr.pshadowMaps[i]->height);
FBO_Bind(tr.pshadowFbos[i]);
for( i = 0; i < MAX_DRAWN_PSHADOWS; i++)
{
tr.pshadowFbos[i] = FBO_Create(va("_shadowmap%d", i), tr.pshadowMaps[i]->width, tr.pshadowMaps[i]->height);
FBO_Bind(tr.pshadowFbos[i]);
//FBO_CreateBuffer(tr.pshadowFbos[i], GL_RGBA8, 0, 0);
FBO_AttachTextureImage(tr.pshadowMaps[i], 0);
//FBO_CreateBuffer(tr.pshadowFbos[i], GL_RGBA8, 0, 0);
FBO_AttachTextureImage(tr.pshadowMaps[i], 0);
FBO_CreateBuffer(tr.pshadowFbos[i], GL_DEPTH_COMPONENT24_ARB, 0, 0);
//R_AttachFBOTextureDepth(tr.textureDepthImage->texnum);
FBO_CreateBuffer(tr.pshadowFbos[i], GL_DEPTH_COMPONENT24_ARB, 0, 0);
//R_AttachFBOTextureDepth(tr.textureDepthImage->texnum);
R_CheckFBO(tr.pshadowFbos[i]);
R_CheckFBO(tr.pshadowFbos[i]);
}
}
for ( i = 0; i < 3; i++)
if (tr.sunShadowDepthImage[0])
{
tr.sunShadowFbo[i] = FBO_Create("_sunshadowmap", tr.sunShadowDepthImage[i]->width, tr.sunShadowDepthImage[i]->height);
FBO_Bind(tr.sunShadowFbo[i]);
for ( i = 0; i < 3; i++)
{
tr.sunShadowFbo[i] = FBO_Create("_sunshadowmap", tr.sunShadowDepthImage[i]->width, tr.sunShadowDepthImage[i]->height);
FBO_Bind(tr.sunShadowFbo[i]);
//FBO_CreateBuffer(tr.sunShadowFbo[i], GL_RGBA8, 0, 0);
//FBO_AttachTextureImage(tr.sunShadowImage, 0);
qglDrawBuffer(GL_NONE);
qglReadBuffer(GL_NONE);
//FBO_CreateBuffer(tr.sunShadowFbo[i], GL_RGBA8, 0, 0);
//FBO_AttachTextureImage(tr.sunShadowImage, 0);
qglDrawBuffer(GL_NONE);
qglReadBuffer(GL_NONE);
//FBO_CreateBuffer(tr.sunShadowFbo, GL_DEPTH_COMPONENT24_ARB, 0, 0);
R_AttachFBOTextureDepth(tr.sunShadowDepthImage[i]->texnum);
//FBO_CreateBuffer(tr.sunShadowFbo, GL_DEPTH_COMPONENT24_ARB, 0, 0);
R_AttachFBOTextureDepth(tr.sunShadowDepthImage[i]->texnum);
R_CheckFBO(tr.sunShadowFbo[i]);
R_CheckFBO(tr.sunShadowFbo[i]);
}
tr.screenShadowFbo = FBO_Create("_screenshadow", tr.screenShadowImage->width, tr.screenShadowImage->height);
FBO_Bind(tr.screenShadowFbo);
FBO_AttachTextureImage(tr.screenShadowImage, 0);
R_CheckFBO(tr.screenShadowFbo);
}
for (i = 0; i < 2; i++)
@ -537,15 +551,6 @@ void FBO_Init(void)
R_CheckFBO(tr.quarterFbo[i]);
}
{
tr.screenShadowFbo = FBO_Create("_screenshadow", tr.screenShadowImage->width, tr.screenShadowImage->height);
FBO_Bind(tr.screenShadowFbo);
FBO_AttachTextureImage(tr.screenShadowImage, 0);
R_CheckFBO(tr.screenShadowFbo);
}
if (r_ssao->integer)
{
tr.hdrDepthFbo = FBO_Create("_hdrDepth", tr.hdrDepthImage->width, tr.hdrDepthImage->height);
@ -563,6 +568,7 @@ void FBO_Init(void)
R_CheckFBO(tr.screenSsaoFbo);
}
if (tr.renderCubeImage)
{
tr.renderCubeFbo = FBO_Create("_renderCubeFbo", tr.renderCubeImage->width, tr.renderCubeImage->height);
FBO_Bind(tr.renderCubeFbo);

View file

@ -2972,25 +2972,34 @@ void R_CreateBuiltinImages( void ) {
tr.quarterImage[x] = R_CreateImage(va("*quarter%d", x), NULL, width / 2, height / 2, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
}
tr.screenShadowImage = R_CreateImage("*screenShadow", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
if (r_ssao->integer)
{
tr.screenSsaoImage = R_CreateImage("*screenSsao", NULL, width / 2, height / 2, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
tr.hdrDepthImage = R_CreateImage("*hdrDepth", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_INTENSITY32F_ARB);
}
for( x = 0; x < MAX_DRAWN_PSHADOWS; x++)
if (r_shadows->integer == 4)
{
tr.pshadowMaps[x] = R_CreateImage(va("*shadowmap%i", x), NULL, PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
for( x = 0; x < MAX_DRAWN_PSHADOWS; x++)
{
tr.pshadowMaps[x] = R_CreateImage(va("*shadowmap%i", x), NULL, PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
}
}
for ( x = 0; x < 3; x++)
if (r_sunlightMode->integer)
{
tr.sunShadowDepthImage[x] = R_CreateImage(va("*sunshadowdepth%i", x), NULL, r_shadowMapSize->integer, r_shadowMapSize->integer, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24_ARB);
for ( x = 0; x < 3; x++)
{
tr.sunShadowDepthImage[x] = R_CreateImage(va("*sunshadowdepth%i", x), NULL, r_shadowMapSize->integer, r_shadowMapSize->integer, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24_ARB);
}
tr.screenShadowImage = R_CreateImage("*screenShadow", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
}
tr.renderCubeImage = R_CreateImage("*renderCube", NULL, CUBE_MAP_SIZE, CUBE_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE | IMGFLAG_MIPMAP | IMGFLAG_CUBEMAP, rgbFormat);
if (r_cubeMapping->integer)
{
tr.renderCubeImage = R_CreateImage("*renderCube", NULL, CUBE_MAP_SIZE, CUBE_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE | IMGFLAG_MIPMAP | IMGFLAG_CUBEMAP, rgbFormat);
}
}
}

View file

@ -2851,7 +2851,7 @@ void R_RenderCubemapSide( int cubemapIndex, int cubemapSide, qboolean subscene )
// FIXME: sun shadows aren't rendered correctly in cubemaps
// fix involves changing r_FBufScale to fit smaller cubemap image size, or rendering cubemap to framebuffer first
if(0) //(glRefConfig.framebufferObject && (r_forceSun->integer || tr.sunShadows))
if(0) //(glRefConfig.framebufferObject && r_sunlightMode->integer && (r_forceSun->integer || tr.sunShadows))
{
R_RenderSunShadowMaps(&refdef, 0);
R_RenderSunShadowMaps(&refdef, 1);

View file

@ -496,7 +496,7 @@ void RE_RenderScene( const refdef_t *fd ) {
}
// playing with even more shadows
if(glRefConfig.framebufferObject && !( fd->rdflags & RDF_NOWORLDMODEL ) && (r_forceSun->integer || tr.sunShadows))
if(glRefConfig.framebufferObject && r_sunlightMode->integer && !( fd->rdflags & RDF_NOWORLDMODEL ) && (r_forceSun->integer || tr.sunShadows))
{
R_RenderSunShadowMaps(fd, 0);
R_RenderSunShadowMaps(fd, 1);

View file

@ -1241,7 +1241,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
int i;
vec4_t enableTextures;
if ((backEnd.viewParms.flags & VPF_USESUNLIGHT) && (pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK))
if (r_sunlightMode->integer && (backEnd.viewParms.flags & VPF_USESUNLIGHT) && (pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK))
{
GL_BindToTMU(tr.screenShadowImage, TB_SHADOWMAP);
GLSL_SetUniformVec3(sp, UNIFORM_PRIMARYLIGHTAMBIENT, backEnd.refdef.sunAmbCol);
@ -1552,8 +1552,8 @@ void RB_StageIteratorGeneric( void )
//
// pshadows!
//
if (glRefConfig.framebufferObject && tess.pshadowBits && tess.shader->sort <= SS_OPAQUE
&& !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY) ) ) {
if (glRefConfig.framebufferObject && r_shadows->integer == 4 && tess.pshadowBits
&& tess.shader->sort <= SS_OPAQUE && !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY) ) ) {
ProjectPshadowVBOGLSL();
}