]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Cache corona occlusion buffer
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 4 Oct 2014 20:12:56 +0000 (20:12 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 4 Oct 2014 20:12:56 +0000 (20:12 +0000)
Rather than creating and destroying the occlusion buffer every frame, cache it.
This improves performance slightly.

From: Alex Goins <agoins@nvidia.com>

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12095 d7cf8633-e32d-0410-b094-e92efae38249

client.h
r_shadow.c

index 0bd75f77d3929c613b4b04e27e271203e72b34a5..f830c2e74c05976953403879fbc1bb6ca584a9bd 100644 (file)
--- 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)
index ff8792db3f8df1a5ed9047bef59715919eaf5a86..8b0106dd78c69e73a29274d0dd16178d446a7815 100644 (file)
@@ -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)