]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
illuminated surfaces are now sorted by texture, giving a good fps
[xonotic/darkplaces.git] / gl_rsurf.c
index acd7699284904f61c09efe3ed5bb11c8f73f1576..49754e4d83ab95246a496af529becd6119c3cad5 100644 (file)
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 #include "r_shadow.h"
 #include "portals.h"
+#include "csprogs.h"
 
 cvar_t r_ambient = {0, "r_ambient", "0", "brightens map, value is 0-128"};
 cvar_t r_lockpvs = {0, "r_lockpvs", "0", "disables pvs switching, allows you to walk around and inspect what is visible from a given location in the map (anything not visible from your current location will not be drawn)"};
@@ -544,10 +545,10 @@ void R_Q1BSP_DrawSky(entity_render_t *ent)
                R_DrawModelSurfaces(ent, true, true, false, false, false);
 }
 
-extern void R_Water_AddWaterPlane(msurface_t *surface);
+extern void R_Water_AddWaterPlane(msurface_t *surface, int entno);
 void R_Q1BSP_DrawAddWaterPlanes(entity_render_t *ent)
 {
-       int i, j, flagsmask;
+       int i, j, n, flagsmask;
        dp_model_t *model = ent->model;
        msurface_t *surfaces;
        if (model == NULL)
@@ -559,7 +560,7 @@ void R_Q1BSP_DrawAddWaterPlanes(entity_render_t *ent)
                RSurf_ActiveModelEntity(ent, false, false, false);
 
        surfaces = model->data_surfaces;
-       flagsmask = MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION;
+       flagsmask = MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION | MATERIALFLAG_CAMERA;
 
        // add visible surfaces to draw list
        if (ent == r_refdef.scene.worldentity)
@@ -569,16 +570,20 @@ void R_Q1BSP_DrawAddWaterPlanes(entity_render_t *ent)
                        j = model->sortedmodelsurfaces[i];
                        if (r_refdef.viewcache.world_surfacevisible[j])
                                if (surfaces[j].texture->basematerialflags & flagsmask)
-                                       R_Water_AddWaterPlane(surfaces + j);
+                                       R_Water_AddWaterPlane(surfaces + j, 0);
                }
        }
        else
        {
+               if(ent->entitynumber >= MAX_EDICTS) // && CL_VM_TransformView(ent->entitynumber - MAX_EDICTS, NULL, NULL, NULL))
+                       n = ent->entitynumber;
+               else
+                       n = 0;
                for (i = 0;i < model->nummodelsurfaces;i++)
                {
                        j = model->sortedmodelsurfaces[i];
                        if (surfaces[j].texture->basematerialflags & flagsmask)
-                               R_Water_AddWaterPlane(surfaces + j);
+                               R_Water_AddWaterPlane(surfaces + j, n);
                }
        }
        rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
@@ -734,7 +739,7 @@ static void R_Q1BSP_RecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, mnode_t
                        if (SVBSP_AddPolygon(&r_svbsp, portal->numpoints, points[0], false, NULL, NULL, 0) & 2)
                                break;
                }
-               if (portal == NULL)
+               if (leaf->portals && portal == NULL)
                        return; // no portals of this leaf visible
        }
        if (info->svbsp_insertoccluder)
@@ -837,7 +842,7 @@ static void R_Q1BSP_RecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, mnode_t
                                                                if (castshadow)
                                                                        SETPVSBIT(info->outshadowtrispvs, t);
                                                        }
-#if 0
+#if 1
                                                        else if (r_shadow_frontsidecasting.integer)
                                                        {
                                                                // front side casting occludes backfaces,
@@ -946,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;
@@ -1024,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)
@@ -1233,7 +1260,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
                        // now figure out what to do with this particular range of surfaces
                        if (!(rsurface.texture->currentmaterialflags & MATERIALFLAG_WALL))
                                continue;
-                       if (r_waterstate.renderingscene && (rsurface.texture->currentmaterialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION)))
+                       if (r_waterstate.renderingscene && (rsurface.texture->currentmaterialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION | MATERIALFLAG_CAMERA)))
                                continue;
                        if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
                        {
@@ -1304,8 +1331,7 @@ void R_ReplaceWorldTexture (void)
        skinframe_t *skinframe;
        if (!r_refdef.scene.worldmodel)
        {
-               if (gamemode != GAME_BLOODOMNICIDE)
-                       Con_Printf("There is no worldmodel\n");
+               Con_Printf("There is no worldmodel\n");
                return;
        }
        m = r_refdef.scene.worldmodel;
@@ -1318,8 +1344,7 @@ void R_ReplaceWorldTexture (void)
        }
        if(!cl.islocalgame || !cl.worldmodel)
        {
-               if (gamemode != GAME_BLOODOMNICIDE)
-                       Con_Print("This command works only in singleplayer\n");
+               Con_Print("This command works only in singleplayer\n");
                return;
        }
        r = Cmd_Argv(1);
@@ -1335,13 +1360,11 @@ void R_ReplaceWorldTexture (void)
 //                             t->skinframes[0] = skinframe;
                                t->currentskinframe = skinframe;
                                t->currentskinframe = skinframe;
-                               if (gamemode != GAME_BLOODOMNICIDE)
-                                       Con_Printf("%s replaced with %s\n", r, newt);
+                               Con_Printf("%s replaced with %s\n", r, newt);
                        }
                        else
                        {
-                               if (gamemode != GAME_BLOODOMNICIDE)
-                                       Con_Printf("%s was not found\n", newt);
+                               Con_Printf("%s was not found\n", newt);
                                return;
                        }
                }