From 28e02ce5a65a4eb60187acc1bca5e493d7cb78f9 Mon Sep 17 00:00:00 2001 From: divverent Date: Sat, 4 Oct 2014 20:12:56 +0000 Subject: [PATCH] Cache corona occlusion buffer Rather than creating and destroying the occlusion buffer every frame, cache it. This improves performance slightly. From: Alex Goins git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12095 d7cf8633-e32d-0410-b094-e92efae38249 --- client.h | 1 - r_shadow.c | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client.h b/client.h index 0bd75f77..f830c2e7 100644 --- a/client.h +++ b/client.h @@ -317,7 +317,6 @@ typedef struct rtlight_s vec3_t currentcolor; /// used by corona updates, due to occlusion query float corona_visibility; - unsigned int occlusion_buf; unsigned int corona_queryindex_visiblepixels; unsigned int corona_queryindex_allpixels; /// this is R_GetCubemap(rtlight->cubemapname) diff --git a/r_shadow.c b/r_shadow.c index ff8792db..8b0106dd 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -269,6 +269,9 @@ static rtexture_t *r_shadow_fb_colortexture; // lights are reloaded when this changes char r_shadow_mapname[MAX_QPATH]; +// buffer for doing corona fading +unsigned int r_shadow_occlusion_buf = 0; + // used only for light filters (cubemaps) rtexturepool_t *r_shadow_filters_texturepool; @@ -3941,7 +3944,6 @@ static void R_Shadow_PrepareLight(rtlight_t *rtlight) rtlight->cached_numshadowentities = 0; rtlight->cached_numshadowentities_noselfshadow = 0; rtlight->cached_numsurfaces = 0; - rtlight->occlusion_buf = 0; rtlight->cached_lightentities = NULL; rtlight->cached_lightentities_noselfshadow = NULL; rtlight->cached_shadowentities = NULL; @@ -5166,12 +5168,16 @@ static void R_DrawCorona(rtlight_t *rtlight, float cscale, float scale) // See if we can use the GPU-side method to prevent implicit sync if (vid.support.arb_query_buffer_object) { #define BUFFER_OFFSET(i) ((void*)NULL + (i)) - qglGenBuffersARB(1, &rtlight->occlusion_buf); - qglBindBufferARB(GL_QUERY_BUFFER_ARB, rtlight->occlusion_buf); - qglBufferDataARB(GL_QUERY_BUFFER_ARB, 8, NULL, GL_DYNAMIC_COPY); + if (!r_shadow_occlusion_buf) { + qglGenBuffersARB(1, &r_shadow_occlusion_buf); + qglBindBufferARB(GL_QUERY_BUFFER_ARB, r_shadow_occlusion_buf); + qglBufferDataARB(GL_QUERY_BUFFER_ARB, 8, NULL, GL_DYNAMIC_COPY); + } else { + qglBindBufferARB(GL_QUERY_BUFFER_ARB, r_shadow_occlusion_buf); + } qglGetQueryObjectivARB(rtlight->corona_queryindex_visiblepixels, GL_QUERY_RESULT_ARB, BUFFER_OFFSET(0)); qglGetQueryObjectivARB(rtlight->corona_queryindex_allpixels, GL_QUERY_RESULT_ARB, BUFFER_OFFSET(4)); - qglBindBufferBase(GL_UNIFORM_BUFFER, 0, rtlight->occlusion_buf); + qglBindBufferBase(GL_UNIFORM_BUFFER, 0, r_shadow_occlusion_buf); occlude = MATERIALFLAG_OCCLUDE; } else { qglGetQueryObjectivARB(rtlight->corona_queryindex_visiblepixels, GL_QUERY_RESULT_ARB, &visiblepixels); @@ -5224,9 +5230,6 @@ static void R_DrawCorona(rtlight_t *rtlight, float cscale, float scale) if(negated) GL_BlendEquationSubtract(false); } - if (rtlight->occlusion_buf) { - qglDeleteBuffersARB(1, &rtlight->occlusion_buf); - } } void R_Shadow_DrawCoronas(void) -- 2.39.2