From: havoc Date: Sun, 14 Nov 2010 13:24:27 +0000 (+0000) Subject: illuminated surfaces are now sorted by texture, giving a good fps X-Git-Tag: xonotic-v0.1.0preview~69 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3f813368afcd9ff97aee42698c159edbfaf95efe;p=xonotic%2Fdarkplaces.git illuminated surfaces are now sorted by texture, giving a good fps increase, especially in realtime world lighting, this can be turned off with the r_shadow_sortsurfaces cvar if desired git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10599 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=14b5649a2b45037ad244a2d2c2dcae6049fc6ce6 --- diff --git a/gl_rsurf.c b/gl_rsurf.c index 8027d960..49754e4d 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -951,6 +951,23 @@ static void R_Q1BSP_CallRecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, qboo } } +static msurface_t *r_q1bsp_getlightinfo_surfaces; + +int R_Q1BSP_GetLightInfo_comparefunc(const void *ap, const void *bp) +{ + int a = *(int*)ap; + int b = *(int*)bp; + const msurface_t *as = r_q1bsp_getlightinfo_surfaces + a; + const msurface_t *bs = r_q1bsp_getlightinfo_surfaces + b; + if (as->texture < bs->texture) + return -1; + if (as->texture > bs->texture) + return 1; + return a - b; +} + +extern cvar_t r_shadow_sortsurfaces; + void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outleaflist, unsigned char *outleafpvs, int *outnumleafspointer, int *outsurfacelist, unsigned char *outsurfacepvs, int *outnumsurfacespointer, unsigned char *outshadowtrispvs, unsigned char *outlighttrispvs, unsigned char *visitingleafpvs, int numfrustumplanes, const mplane_t *frustumplanes) { r_q1bsp_getlightinfo_t info; @@ -1029,6 +1046,11 @@ void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa *outnumleafspointer = info.outnumleafs; *outnumsurfacespointer = info.outnumsurfaces; + + // now sort surfaces by texture for faster rendering + r_q1bsp_getlightinfo_surfaces = info.model->data_surfaces; + if (r_shadow_sortsurfaces.integer) + qsort(info.outsurfacelist, info.outnumsurfaces, sizeof(*info.outsurfacelist), R_Q1BSP_GetLightInfo_comparefunc); } void R_Q1BSP_CompileShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativelightdirection, float lightradius, int numsurfaces, const int *surfacelist) diff --git a/r_shadow.c b/r_shadow.c index 654cfa91..1d22d930 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -317,6 +317,7 @@ cvar_t r_shadow_shadowmapping_nearclip = {CVAR_SAVE, "r_shadow_shadowmapping_nea cvar_t r_shadow_shadowmapping_bias = {CVAR_SAVE, "r_shadow_shadowmapping_bias", "0.03", "shadowmap bias parameter (this is multiplied by nearclip * 1024 / lodsize)"}; cvar_t r_shadow_shadowmapping_polygonfactor = {CVAR_SAVE, "r_shadow_shadowmapping_polygonfactor", "2", "slope-dependent shadowmapping bias"}; cvar_t r_shadow_shadowmapping_polygonoffset = {CVAR_SAVE, "r_shadow_shadowmapping_polygonoffset", "0", "constant shadowmapping bias"}; +cvar_t r_shadow_sortsurfaces = {0, "r_shadow_sortsurfaces", "1", "improve performance by sorting illuminated surfaces by texture"}; cvar_t r_shadow_polygonfactor = {0, "r_shadow_polygonfactor", "0", "how much to enlarge shadow volume polygons when rendering (should be 0!)"}; cvar_t r_shadow_polygonoffset = {0, "r_shadow_polygonoffset", "1", "how much to push shadow volumes into the distance when rendering, to reduce chances of zfighting artifacts (should not be less than 0)"}; cvar_t r_shadow_texture3d = {0, "r_shadow_texture3d", "1", "use 3D voxel textures for spherical attenuation rather than cylindrical (does not affect OpenGL 2.0 render path)"}; @@ -718,6 +719,7 @@ void R_Shadow_Init(void) Cvar_RegisterVariable(&r_shadow_shadowmapping_bias); Cvar_RegisterVariable(&r_shadow_shadowmapping_polygonfactor); Cvar_RegisterVariable(&r_shadow_shadowmapping_polygonoffset); + Cvar_RegisterVariable(&r_shadow_sortsurfaces); Cvar_RegisterVariable(&r_shadow_polygonfactor); Cvar_RegisterVariable(&r_shadow_polygonoffset); Cvar_RegisterVariable(&r_shadow_texture3d); @@ -3941,7 +3943,7 @@ void R_Shadow_DrawPrepass(void) { lightindex = r_shadow_debuglight.integer; light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex); - if (light && (light->flags & flag)) + if (light && (light->flags & flag) && light->rtlight.draw) R_Shadow_DrawLight(&light->rtlight); } else @@ -3950,13 +3952,14 @@ void R_Shadow_DrawPrepass(void) for (lightindex = 0;lightindex < range;lightindex++) { light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex); - if (light && (light->flags & flag)) + if (light && (light->flags & flag) && light->rtlight.draw) R_Shadow_DrawLight(&light->rtlight); } } if (r_refdef.scene.rtdlight) for (lnum = 0;lnum < r_refdef.scene.numlights;lnum++) - R_Shadow_DrawLight(r_refdef.scene.lights[lnum]); + if (r_refdef.scene.lights[lnum]->draw) + R_Shadow_DrawLight(r_refdef.scene.lights[lnum]); qglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);CHECKGLERROR if (r_refdef.fogenabled)