]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
I guess those glLoadIdentity calls were more important than expected
[xonotic/darkplaces.git] / gl_rsurf.c
index db6c318849ea20e965b866e9dda9e5291935ce77..0c0c77a65e79f7827c80ae3d0f2d2e10984d840e 100644 (file)
@@ -36,7 +36,7 @@ cvar_t r_drawportals = {0, "r_drawportals", "0"};
 cvar_t r_testvis = {0, "r_testvis", "0"};
 cvar_t r_floatbuildlightmap = {0, "r_floatbuildlightmap", "0"};
 cvar_t r_detailtextures = {CVAR_SAVE, "r_detailtextures", "1"};
-cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "0"};
+cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "1"};
 
 static int dlightdivtable[32768];
 
@@ -231,7 +231,7 @@ R_BuildLightMap
 Combine and scale multiple lightmaps into the 8.8 format in blocklights
 ===============
 */
-static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf, int dlightchanged)
+static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
 {
        if (!r_floatbuildlightmap.integer)
        {
@@ -241,12 +241,6 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf, int d
 
                // update cached lighting info
                surf->cached_dlight = 0;
-               surf->cached_lightmapscalebit = r_lightmapscalebit;
-               surf->cached_ambient = r_ambient.value;
-               surf->cached_light[0] = d_lightstylevalue[surf->styles[0]];
-               surf->cached_light[1] = d_lightstylevalue[surf->styles[1]];
-               surf->cached_light[2] = d_lightstylevalue[surf->styles[2]];
-               surf->cached_light[3] = d_lightstylevalue[surf->styles[3]];
 
                smax = (surf->extents[0]>>4)+1;
                tmax = (surf->extents[1]>>4)+1;
@@ -278,8 +272,6 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf, int d
                                surf->cached_dlight = R_IntAddDynamicLights(&ent->inversematrix, surf);
                                if (surf->cached_dlight)
                                        c_light_polys++;
-                               else if (dlightchanged)
-                                       return; // don't upload if only updating dlights and none mattered
                        }
 
        // add all the lightmaps
@@ -335,12 +327,6 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf, int d
 
                // update cached lighting info
                surf->cached_dlight = 0;
-               surf->cached_lightmapscalebit = r_lightmapscalebit;
-               surf->cached_ambient = r_ambient.value;
-               surf->cached_light[0] = d_lightstylevalue[surf->styles[0]];
-               surf->cached_light[1] = d_lightstylevalue[surf->styles[1]];
-               surf->cached_light[2] = d_lightstylevalue[surf->styles[2]];
-               surf->cached_light[3] = d_lightstylevalue[surf->styles[3]];
 
                smax = (surf->extents[0]>>4)+1;
                tmax = (surf->extents[1]>>4)+1;
@@ -369,8 +355,6 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf, int d
                        surf->cached_dlight = R_FloatAddDynamicLights(&ent->inversematrix, surf);
                        if (surf->cached_dlight)
                                c_light_polys++;
-                       else if (dlightchanged)
-                               return; // don't upload if only updating dlights and none mattered
                }
 
                // add all the lightmaps
@@ -802,9 +786,10 @@ static void RSurfShader_Sky(const entity_render_t *ent, const texture_t *texture
 
 static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
 {
+       int i;
        const entity_render_t *ent = calldata1;
        const msurface_t *surf = ent->model->surfaces + calldata2;
-       float f, colorscale;
+       float f, colorscale, scroll[2], *v;
        const surfmesh_t *mesh;
        rmeshstate_t m;
        float alpha;
@@ -846,6 +831,13 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
                R_Mesh_ResizeCheck(mesh->numverts);
                memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4]));
                memcpy(varray_texcoord[0], mesh->str, mesh->numverts * sizeof(float[4]));
+               scroll[0] = sin(cl.time) * 0.125f;
+               scroll[1] = sin(cl.time * 0.8f) * 0.125f;
+               for (i = 0, v = varray_texcoord[0];i < mesh->numverts;i++, v += 4)
+               {
+                       v[0] += scroll[0];
+                       v[1] += scroll[1];
+               }
                f = surf->flags & SURF_DRAWFULLBRIGHT ? 1.0f : ((surf->flags & SURF_LIGHTMAP) ? 0 : 0.5f);
                R_FillColors(varray_color, mesh->numverts, f, f, f, alpha);
                if (!(surf->flags & SURF_DRAWFULLBRIGHT || ent->effects & EF_FULLBRIGHT))
@@ -885,7 +877,7 @@ static void RSurfShader_Water(const entity_render_t *ent, const texture_t *textu
        vec3_t center;
        if (texture->rendertype != SURFRENDER_OPAQUE)
        {
-               for (chain = surfchain;(surf = *chain) != NULL;*chain++)
+               for (chain = surfchain;(surf = *chain) != NULL;chain++)
                {
                        if (surf->visframe == r_framecount)
                        {
@@ -895,7 +887,7 @@ static void RSurfShader_Water(const entity_render_t *ent, const texture_t *textu
                }
        }
        else
-               for (chain = surfchain;(surf = *chain) != NULL;*chain++)
+               for (chain = surfchain;(surf = *chain) != NULL;chain++)
                        if (surf->visframe == r_framecount)
                                RSurfShader_Water_Callback(ent, surf - ent->model->surfaces);
 }
@@ -1430,7 +1422,7 @@ void R_PrepareSurfaces(entity_render_t *ent)
 {
        int i, numsurfaces, *surfacevisframes;
        model_t *model;
-       msurface_t *surf, *surfaces;
+       msurface_t *surf, *surfaces, **surfchain;
        vec3_t modelorg;
 
        if (!ent->model)
@@ -1447,6 +1439,26 @@ void R_PrepareSurfaces(entity_render_t *ent)
        if (r_dynamic.integer && r_shadow_lightingmode < 1)
                R_MarkLights(ent);
 
+       if (model->light_ambient != r_ambient.value || model->light_scalebit != r_lightmapscalebit)
+       {
+               model->light_ambient = r_ambient.value;
+               model->light_scalebit = r_lightmapscalebit;
+               for (i = 0;i < model->nummodelsurfaces;i++)
+                       model->surfaces[i + model->firstmodelsurface].cached_dlight = true;
+       }
+       else
+       {
+               for (i = 0;i < model->light_styles;i++)
+               {
+                       if (model->light_stylevalue[i] != d_lightstylevalue[model->light_style[i]])
+                       {
+                               model->light_stylevalue[i] = d_lightstylevalue[model->light_style[i]];
+                               for (surfchain = model->light_styleupdatechains[i];*surfchain;surfchain++)
+                                       (**surfchain).cached_dlight = true;
+                       }
+               }
+       }
+
        for (i = 0, surf = surfaces;i < numsurfaces;i++, surf++)
        {
                if (surfacevisframes[i] == r_framecount)
@@ -1468,23 +1480,8 @@ void R_PrepareSurfaces(entity_render_t *ent)
                        {
                                c_faces++;
                                surf->visframe = r_framecount;
-                               if (!r_vertexsurfaces.integer && surf->lightmaptexture != NULL)
-                               {
-                                       if (surf->cached_dlight
-                                        || surf->cached_ambient != r_ambient.value
-                                        || surf->cached_lightmapscalebit != r_lightmapscalebit)
-                                               R_BuildLightMap(ent, surf, false); // base lighting changed
-                                       else if (r_dynamic.integer)
-                                       {
-                                               if  (surf->styles[0] != 255 && (d_lightstylevalue[surf->styles[0]] != surf->cached_light[0]
-                                                || (surf->styles[1] != 255 && (d_lightstylevalue[surf->styles[1]] != surf->cached_light[1]
-                                                || (surf->styles[2] != 255 && (d_lightstylevalue[surf->styles[2]] != surf->cached_light[2]
-                                                || (surf->styles[3] != 255 && (d_lightstylevalue[surf->styles[3]] != surf->cached_light[3]))))))))
-                                                       R_BuildLightMap(ent, surf, false); // base lighting changed
-                                               else if (surf->dlightframe == r_framecount && r_dlightmap.integer)
-                                                       R_BuildLightMap(ent, surf, true); // only dlights
-                                       }
-                               }
+                               if (surf->cached_dlight && surf->lightmaptexture != NULL && !r_vertexsurfaces.integer)
+                                       R_BuildLightMap(ent, surf);
                        }
                }
        }