]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
renamed q3mface_t to q3msurface_t
[xonotic/darkplaces.git] / gl_rsurf.c
index 3b3622d33c4a19c558c85eb1d7fe62e8359469e5..01fa9408ecb8b710a6e9160a1c645862f868d0e7 100644 (file)
@@ -54,7 +54,7 @@ int r_q3bsp_nummarkleafs;
 q3mleaf_t *r_q3bsp_maxleaflist[65536];
 int r_q3bsp_maxmarksurfaces;
 int r_q3bsp_nummarksurfaces;
-q3mface_t *r_q3bsp_maxsurfacelist[65536];
+q3msurface_t *r_q3bsp_maxsurfacelist[65536];
 */
 
 static int dlightdivtable[32768];
@@ -1296,7 +1296,7 @@ static void R_DrawSurfaceChain(const entity_render_t *ent, const texture_t *text
                                }
                        }
                }
-               else if (ent->effects & EF_FULLBRIGHT)
+               else if (ent->effects & EF_FULLBRIGHT || r_fullbright.integer)
                {
                        RSurfShader_OpaqueWall_Pass_BaseTexture(ent, texture, surfchain);
                        if (r_detailtextures.integer)
@@ -1391,32 +1391,20 @@ void R_UpdateTextureInfo(entity_render_t *ent)
        }
 }
 
-void R_PrepareSurfaces(entity_render_t *ent)
+void R_UpdateLightmapInfo(entity_render_t *ent)
 {
-       int i, numsurfaces, *surfacevisframes;
-       model_t *model;
-       msurface_t *surf, *surfaces, **surfchain;
-       vec3_t modelorg;
-
-       if (!ent->model)
+       int i;
+       msurface_t *surface, **surfacechain;
+       model_t *model = ent->model;
+       if (!model)
                return;
-
-       model = ent->model;
-       Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
-       numsurfaces = model->brushq1.nummodelsurfaces;
-       surfaces = model->brushq1.surfaces + model->brushq1.firstmodelsurface;
-       surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
-
-       R_UpdateTextureInfo(ent);
-
        if (r_dynamic.integer && !r_shadow_realtime_dlight.integer)
                R_MarkLights(ent);
-
        if (model->brushq1.light_ambient != r_ambient.value)
        {
                model->brushq1.light_ambient = r_ambient.value;
-               for (i = 0;i < model->brushq1.nummodelsurfaces;i++)
-                       model->brushq1.surfaces[i + model->brushq1.firstmodelsurface].cached_dlight = true;
+               for (i = 0;i < model->nummodelsurfaces;i++)
+                       model->brushq1.surfaces[i + model->firstmodelsurface].cached_dlight = true;
        }
        else
        {
@@ -1425,12 +1413,28 @@ void R_PrepareSurfaces(entity_render_t *ent)
                        if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
                        {
                                model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
-                               for (surfchain = model->brushq1.light_styleupdatechains[i];*surfchain;surfchain++)
-                                       (**surfchain).cached_dlight = true;
+                               for (surfacechain = model->brushq1.light_styleupdatechains[i];(surface = *surfacechain);surfacechain++)
+                                       surface->cached_dlight = true;
                        }
                }
        }
+}
 
+void R_PrepareSurfaces(entity_render_t *ent)
+{
+       int i, numsurfaces, *surfacevisframes;
+       model_t *model;
+       msurface_t *surf, *surfaces;
+       vec3_t modelorg;
+
+       if (!ent->model)
+               return;
+
+       model = ent->model;
+       Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
+       numsurfaces = model->nummodelsurfaces;
+       surfaces = model->brushq1.surfaces + model->firstmodelsurface;
+       surfacevisframes = model->brushq1.surfacevisframes + model->firstmodelsurface;
        for (i = 0, surf = surfaces;i < numsurfaces;i++, surf++)
        {
                if (surfacevisframes[i] == r_framecount)
@@ -1549,10 +1553,10 @@ void R_PrepareBrushModel(entity_render_t *ent)
 #if WORLDNODECULLBACKFACES
        Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
 #endif
-       numsurfaces = model->brushq1.nummodelsurfaces;
-       surf = model->brushq1.surfaces + model->brushq1.firstmodelsurface;
-       surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
-       surfacepvsframes = model->brushq1.surfacepvsframes + model->brushq1.firstmodelsurface;
+       numsurfaces = model->nummodelsurfaces;
+       surf = model->brushq1.surfaces + model->firstmodelsurface;
+       surfacevisframes = model->brushq1.surfacevisframes + model->firstmodelsurface;
+       surfacepvsframes = model->brushq1.surfacepvsframes + model->firstmodelsurface;
        for (i = 0;i < numsurfaces;i++, surf++)
        {
 #if WORLDNODECULLBACKFACES
@@ -1569,7 +1573,8 @@ void R_PrepareBrushModel(entity_render_t *ent)
 #endif
                surf->dlightframe = -1;
        }
-       R_PrepareSurfaces(ent);
+       R_UpdateTextureInfo(ent);
+       R_UpdateLightmapInfo(ent);
 }
 
 void R_SurfaceWorldNode (entity_render_t *ent)
@@ -1584,8 +1589,8 @@ void R_SurfaceWorldNode (entity_render_t *ent)
        model = ent->model;
        if (model == NULL)
                return;
-       surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
-       surfacepvsframes = model->brushq1.surfacepvsframes + model->brushq1.firstmodelsurface;
+       surfacevisframes = model->brushq1.surfacevisframes + model->firstmodelsurface;
+       surfacepvsframes = model->brushq1.surfacepvsframes + model->firstmodelsurface;
        Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
 
        for (leaf = model->brushq1.pvsleafchain;leaf;leaf = leaf->pvschain)
@@ -1743,27 +1748,9 @@ void R_WorldVisibility(entity_render_t *ent)
                R_SurfaceWorldNode (ent);
        else
                R_PortalWorldNode (ent, viewleaf);
-}
 
-void R_DrawWorld(entity_render_t *ent)
-{
-       if (ent->model == NULL)
-               return;
-       if (!ent->model->brushq1.num_leafs)
-       {
-               if (ent->model->DrawSky)
-                       ent->model->DrawSky(ent);
-               if (ent->model->Draw)
-                       ent->model->Draw(ent);
-       }
-       else
-       {
-               R_PrepareSurfaces(ent);
-               R_DrawSurfaces(ent, SURF_DRAWSKY);
-               R_DrawSurfaces(ent, SURF_DRAWTURB | SURF_LIGHTMAP);
-               if (r_drawportals.integer)
-                       R_DrawPortals(ent);
-       }
+       if (r_drawportals.integer)
+               R_DrawPortals(ent);
 }
 
 void R_Model_Brush_DrawSky(entity_render_t *ent)
@@ -1772,6 +1759,7 @@ void R_Model_Brush_DrawSky(entity_render_t *ent)
                return;
        if (ent != &cl_entities[0].render)
                R_PrepareBrushModel(ent);
+       R_PrepareSurfaces(ent);
        R_DrawSurfaces(ent, SURF_DRAWSKY);
 }
 
@@ -1782,6 +1770,9 @@ void R_Model_Brush_Draw(entity_render_t *ent)
        c_bmodels++;
        if (ent != &cl_entities[0].render)
                R_PrepareBrushModel(ent);
+       R_PrepareSurfaces(ent);
+       R_UpdateTextureInfo(ent);
+       R_UpdateLightmapInfo(ent);
        R_DrawSurfaces(ent, SURF_DRAWTURB | SURF_LIGHTMAP);
 }
 
@@ -1804,7 +1795,7 @@ void R_Model_Brush_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin
        *outnumclusterspointer = 0;
        *outnumsurfacespointer = 0;
        memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
-       memset(outsurfacepvs, 0, (model->numsurfaces + 7) >> 3);
+       memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
        if (model == NULL)
        {
                VectorCopy(lightmins, outmins);
@@ -1839,7 +1830,7 @@ void R_Model_Brush_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin
                                if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
                                {
                                        surface = model->brushq1.surfaces + surfaceindex;
-                                       if (BoxesOverlap(lightmins, lightmaxs, surface->poly_mins, surface->poly_maxs))
+                                       if (BoxesOverlap(lightmins, lightmaxs, surface->poly_mins, surface->poly_maxs) && (surface->flags & SURF_LIGHTMAP) && !surface->texinfo->texture->skin.fog)
                                        {
                                                for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
                                                {
@@ -1901,7 +1892,7 @@ void R_Model_Brush_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightor
                                        shadowmarklist[numshadowmark++] = t;
                        }
                }
-               R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius, numshadowmark, shadowmarklist);
+               R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
        }
 }
 
@@ -1922,6 +1913,7 @@ void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
                lightmaxs[2] = relativelightorigin[2] + lightradius;
                R_Mesh_Matrix(&ent->matrix);
                Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
+               R_UpdateTextureInfo(ent);
                for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
                {
                        surface = model->brushq1.surfaces + surfacelist[surfacelistindex];
@@ -1956,7 +1948,7 @@ void R_DrawCollisionBrush(colbrushf_t *brush)
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawCollisionFace(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawCollisionFace(entity_render_t *ent, q3msurface_t *face)
 {
        int i;
        rmeshstate_t m;
@@ -1965,14 +1957,14 @@ void R_Q3BSP_DrawCollisionFace(entity_render_t *ent, q3mface_t *face)
        memset(&m, 0, sizeof(m));
        m.pointer_vertex = face->data_collisionvertex3f;
        R_Mesh_State(&m);
-       i = ((int)face) / sizeof(q3mface_t);
+       i = ((int)face) / sizeof(q3msurface_t);
        GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
        GL_LockArrays(0, face->num_collisionvertices);
        R_Mesh_Draw(face->num_collisionvertices, face->num_collisiontriangles, face->data_collisionelement3i);
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawSkyFace(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawSkyFace(entity_render_t *ent, q3msurface_t *face)
 {
        rmeshstate_t m;
        if (!face->num_triangles)
@@ -2014,7 +2006,7 @@ void R_Q3BSP_DrawSkyFace(entity_render_t *ent, q3mface_t *face)
        GL_ColorMask(1,1,1,1);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_OpaqueGlow(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_OpaqueGlow(entity_render_t *ent, q3msurface_t *face)
 {
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
@@ -2036,7 +2028,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_OpaqueGlow(entity_render_t *ent, q3mface_t
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_TextureLightmapCombine(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_TextureLightmapCombine(entity_render_t *ent, q3msurface_t *face)
 {
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
@@ -2056,7 +2048,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_TextureLightmapCombine(entity_render_t *en
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_Texture(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_Texture(entity_render_t *ent, q3msurface_t *face)
 {
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
@@ -2073,7 +2065,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_Texture(entity_render_t *ent, q3mface_t *f
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_Lightmap(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_Lightmap(entity_render_t *ent, q3msurface_t *face)
 {
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
@@ -2090,7 +2082,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_Lightmap(entity_render_t *ent, q3mface_t *
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_LightmapOnly(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_LightmapOnly(entity_render_t *ent, q3msurface_t *face)
 {
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
@@ -2110,7 +2102,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_LightmapOnly(entity_render_t *ent, q3mface
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_Glow(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_Glow(entity_render_t *ent, q3msurface_t *face)
 {
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
@@ -2132,7 +2124,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_Glow(entity_render_t *ent, q3mface_t *face
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_TextureVertex(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_TextureVertex(entity_render_t *ent, q3msurface_t *face)
 {
        int i;
        float mul;
@@ -2171,7 +2163,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_TextureVertex(entity_render_t *ent, q3mfac
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_VertexOnly(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_VertexOnly(entity_render_t *ent, q3msurface_t *face)
 {
        int i;
        float mul;
@@ -2203,7 +2195,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_VertexOnly(entity_render_t *ent, q3mface_t
        GL_LockArrays(0, 0);
 }
 
-void R_Q3BSP_DrawFace_OpaqueWall_Pass_AddTextureAmbient(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace_OpaqueWall_Pass_AddTextureAmbient(entity_render_t *ent, q3msurface_t *face)
 {
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
@@ -2223,7 +2215,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_AddTextureAmbient(entity_render_t *ent, q3
 void R_Q3BSP_DrawFace_TransparentCallback(const void *voident, int facenumber)
 {
        const entity_render_t *ent = voident;
-       q3mface_t *face = ent->model->brushq3.data_faces + facenumber;
+       q3msurface_t *face = ent->model->brushq3.data_faces + facenumber;
        rmeshstate_t m;
        R_Mesh_Matrix(&ent->matrix);
        memset(&m, 0, sizeof(m));
@@ -2284,15 +2276,12 @@ void R_Q3BSP_DrawFace_TransparentCallback(const void *voident, int facenumber)
        qglEnable(GL_CULL_FACE);
 }
 
-void R_Q3BSP_DrawFace(entity_render_t *ent, q3mface_t *face)
+void R_Q3BSP_DrawFace(entity_render_t *ent, q3msurface_t *face)
 {
        if (!face->num_triangles)
                return;
-       if (face->texture->surfaceparms)
-       {
-               if (face->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW))
-                       return;
-       }
+       if (face->texture->surfaceflags && (face->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)))
+               return;
        c_faces++;
        if ((face->texture->surfaceparms & Q3SURFACEPARM_TRANS) || ent->alpha < 1 || (ent->effects & EF_ADDITIVE))
        {
@@ -2392,7 +2381,7 @@ static int r_q3bsp_framecount = -1;
 void R_Q3BSP_DrawSky(entity_render_t *ent)
 {
        int i;
-       q3mface_t *face;
+       q3msurface_t *face;
        vec3_t modelorg;
        model_t *model;
        R_Mesh_Matrix(&ent->matrix);
@@ -2422,7 +2411,7 @@ void R_Q3BSP_DrawSky(entity_render_t *ent)
 void R_Q3BSP_Draw(entity_render_t *ent)
 {
        int i;
-       q3mface_t *face;
+       q3msurface_t *face;
        vec3_t modelorg;
        model_t *model;
        qbyte *pvs;
@@ -2471,7 +2460,7 @@ void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
        int t, leafindex, marksurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
        const int *e;
        const float *v[3];
-       q3mface_t *surface;
+       q3msurface_t *surface;
        q3mleaf_t *leaf;
        const qbyte *pvs;
        lightmins[0] = relativelightorigin[0] - lightradius;
@@ -2483,7 +2472,7 @@ void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
        *outnumclusterspointer = 0;
        *outnumsurfacespointer = 0;
        memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
-       memset(outsurfacepvs, 0, (model->numsurfaces + 7) >> 3);
+       memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
        if (model == NULL)
        {
                VectorCopy(lightmins, outmins);
@@ -2518,7 +2507,7 @@ void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
                                surfaceindex = surface - model->brushq3.data_faces;
                                if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
                                {
-                                       if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs))
+                                       if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS) && !(surface->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)))
                                        {
                                                for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->num_triangles;triangleindex++, t++, e += 3)
                                                {
@@ -2554,7 +2543,7 @@ void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
 {
        model_t *model = ent->model;
        vec3_t lightmins, lightmaxs;
-       q3mface_t *surface;
+       q3msurface_t *surface;
        int surfacelistindex, j, t;
        const int *e;
        const float *v[3];
@@ -2584,7 +2573,7 @@ void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
                                }
                        }
                }
-               R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius, numshadowmark, shadowmarklist);
+               R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
        }
 }
 
@@ -2592,7 +2581,7 @@ void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t
 {
        model_t *model = ent->model;
        vec3_t lightmins, lightmaxs, modelorg;
-       q3mface_t *surface;
+       q3msurface_t *surface;
        int surfacelistindex;
        if (r_drawcollisionbrushes.integer < 2)
        {