]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
r_showtris/r_shownormals/r_showcollisionbrushes are no longer obscured
[xonotic/darkplaces.git] / gl_rsurf.c
index 6f77b47fe094faac5cb1781d06d3aee1efc656c8..5cd7f27a3ebafa89394167a4eb3cc14e5a0bba9c 100644 (file)
@@ -352,6 +352,7 @@ static void R_DrawPortal_Callback(const entity_render_t *ent, const rtlight_t *r
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthRange(0, 1);
+       GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);
        GL_DepthTest(true);
        GL_CullFace(GL_NONE);
        R_Mesh_Matrix(&identitymatrix);
@@ -403,7 +404,7 @@ void R_DrawPortals(void)
        }
 }
 
-void R_View_WorldVisibility(void)
+void R_View_WorldVisibility(qboolean forcenovis)
 {
        int i, j, *mark;
        mleaf_t *leaf;
@@ -413,11 +414,34 @@ void R_View_WorldVisibility(void)
        if (!model)
                return;
 
+       if (r_view.usecustompvs)
+       {
+               // clear the visible surface and leaf flags arrays
+               memset(r_viewcache.world_surfacevisible, 0, model->num_surfaces);
+               memset(r_viewcache.world_leafvisible, 0, model->brush.num_leafs);
+               r_viewcache.world_novis = false;
+
+               // simply cull each marked leaf to the frustum (view pyramid)
+               for (j = 0, leaf = model->brush.data_leafs;j < model->brush.num_leafs;j++, leaf++)
+               {
+                       // if leaf is in current pvs and on the screen, mark its surfaces
+                       if (CHECKPVSBIT(r_viewcache.world_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
+                       {
+                               r_refdef.stats.world_leafs++;
+                               r_viewcache.world_leafvisible[j] = true;
+                               if (leaf->numleafsurfaces)
+                                       for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
+                                               r_viewcache.world_surfacevisible[*mark] = true;
+                       }
+               }
+               return;
+       }
+
        // if possible find the leaf the view origin is in
        viewleaf = model->brush.PointInLeaf ? model->brush.PointInLeaf(model, r_view.origin) : NULL;
        // if possible fetch the visible cluster bits
        if (!r_lockpvs.integer && model->brush.FatPVS)
-               model->brush.FatPVS(model, r_view.origin, 2, r_viewcache.world_pvsbits, sizeof(r_viewcache.world_pvsbits));
+               model->brush.FatPVS(model, r_view.origin, 2, r_viewcache.world_pvsbits, sizeof(r_viewcache.world_pvsbits), false);
 
        if (!r_lockvisibility.integer)
        {
@@ -429,7 +453,7 @@ void R_View_WorldVisibility(void)
 
                // if floating around in the void (no pvs data available, and no
                // portals available), simply use all on-screen leafs.
-               if (!viewleaf || viewleaf->clusterindex < 0)
+               if (!viewleaf || viewleaf->clusterindex < 0 || forcenovis)
                {
                        // no visibility method: (used when floating around in the void)
                        // simply cull each leaf to the frustum (view pyramid)
@@ -523,9 +547,20 @@ void R_Q1BSP_DrawSky(entity_render_t *ent)
        if (ent->model == NULL)
                return;
        if (ent == r_refdef.worldentity)
-               R_DrawWorldSurfaces(true, true, false);
+               R_DrawWorldSurfaces(true, true, false, false, false);
+       else
+               R_DrawModelSurfaces(ent, true, true, false, false, false);
+}
+
+void R_Q1BSP_DrawAddWaterPlanes(entity_render_t *ent)
+{
+       model_t *model = ent->model;
+       if (model == NULL)
+               return;
+       if (ent == r_refdef.worldentity)
+               R_DrawWorldSurfaces(false, false, false, true, false);
        else
-               R_DrawModelSurfaces(ent, true, true, false);
+               R_DrawModelSurfaces(ent, false, false, false, true, false);
 }
 
 void R_Q1BSP_Draw(entity_render_t *ent)
@@ -534,9 +569,9 @@ void R_Q1BSP_Draw(entity_render_t *ent)
        if (model == NULL)
                return;
        if (ent == r_refdef.worldentity)
-               R_DrawWorldSurfaces(false, true, false);
+               R_DrawWorldSurfaces(false, true, false, false, false);
        else
-               R_DrawModelSurfaces(ent, false, true, false);
+               R_DrawModelSurfaces(ent, false, true, false, false, false);
 }
 
 void R_Q1BSP_DrawDepth(entity_render_t *ent)
@@ -545,9 +580,19 @@ void R_Q1BSP_DrawDepth(entity_render_t *ent)
        if (model == NULL)
                return;
        if (ent == r_refdef.worldentity)
-               R_DrawWorldSurfaces(false, false, true);
+               R_DrawWorldSurfaces(false, false, true, false, false);
        else
-               R_DrawModelSurfaces(ent, false, false, true);
+               R_DrawModelSurfaces(ent, false, false, true, false, false);
+}
+
+void R_Q1BSP_DrawDebug(entity_render_t *ent)
+{
+       if (ent->model == NULL)
+               return;
+       if (ent == r_refdef.worldentity)
+               R_DrawWorldSurfaces(false, false, false, false, true);
+       else
+               R_DrawModelSurfaces(ent, false, false, false, false, true);
 }
 
 typedef struct r_q1bsp_getlightinfo_s
@@ -929,6 +974,8 @@ void R_Q1BSP_CompileShadowVolume(entity_render_t *ent, vec3_t relativelightorigi
        r_shadow_compilingrtlight->static_meshchain_shadow = Mod_ShadowMesh_Finish(r_main_mempool, r_shadow_compilingrtlight->static_meshchain_shadow, false, false, true);
 }
 
+extern cvar_t r_polygonoffset_submodel_factor;
+extern cvar_t r_polygonoffset_submodel_offset;
 void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativelightdirection, float lightradius, int modelnumsurfaces, const int *modelsurfacelist, const vec3_t lightmins, const vec3_t lightmaxs)
 {
        model_t *model = ent->model;
@@ -939,6 +986,8 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
        if (!BoxesOverlap(model->normalmins, model->normalmaxs, lightmins, lightmaxs))
                return;
        R_UpdateAllTextureInfo(ent);
+       if (ent->model->brush.submodel)
+               GL_PolygonOffset(r_refdef.shadowpolygonfactor + r_polygonoffset_submodel_factor.value, r_refdef.shadowpolygonoffset + r_polygonoffset_submodel_offset.value);
        if (model->brush.shadowmesh)
        {
                R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
@@ -967,6 +1016,8 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
                }
                R_Shadow_VolumeFromList(model->surfmesh.num_vertices, model->surfmesh.num_triangles, rsurface.vertex3f, model->surfmesh.data_element3i, model->surfmesh.data_neighbor3i, relativelightorigin, relativelightdirection, projectdistance, numshadowmark, shadowmarklist);
        }
+       if (ent->model->brush.submodel)
+               GL_PolygonOffset(r_refdef.shadowpolygonfactor, r_refdef.shadowpolygonoffset);
 }
 
 #define BATCHSIZE 1024
@@ -1137,6 +1188,11 @@ void R_ReplaceWorldTexture (void)
        int                     i;
        const char      *r, *newt;
        skinframe_t *skinframe;
+       if (!r_refdef.worldmodel)
+       {
+               Con_Printf("There is no worldmodel\n");
+               return;
+       }
        m = r_refdef.worldmodel;
 
        if(Cmd_Argc() < 2)
@@ -1179,6 +1235,11 @@ void R_ListWorldTextures (void)
        model_t         *m;
        texture_t       *t;
        int                     i;
+       if (!r_refdef.worldmodel)
+       {
+               Con_Printf("There is no worldmodel\n");
+               return;
+       }
        m = r_refdef.worldmodel;
 
        Con_Print("Worldmodel textures :\n");