]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
model_shared: Avoid using R_FrameData_Alloc when building sorted surfaces list
authorCloudwalk <cloudwalk009@gmail.com>
Wed, 21 Jul 2021 18:49:35 +0000 (14:49 -0400)
committerCloudwalk <cloudwalk009@gmail.com>
Wed, 21 Jul 2021 22:19:59 +0000 (18:19 -0400)
Works around an issue where the r_framedatasize cvar would grow to a
ridiculous size over time. To be investigated further...

gl_rmain.c
model_shared.c
model_shared.h

index e5516ded985c28c7e3a5ed5728e96ffda776f921..d164550d78b37c7f6c266d90ddeb29254df53a48 100644 (file)
@@ -247,6 +247,7 @@ cvar_t r_glsl_saturation_redcompensate = {CF_CLIENT | CF_ARCHIVE, "r_glsl_satura
 
 cvar_t r_glsl_vertextextureblend_usebothalphas = {CF_CLIENT | CF_ARCHIVE, "r_glsl_vertextextureblend_usebothalphas", "0", "use both alpha layers on vertex blended surfaces, each alpha layer sets amount of 'blend leak' on another layer, requires mod_q3shader_force_terrain_alphaflag on."};
 
+// FIXME: This cvar would grow to a ridiculous size after several launches and clean exits when used during surface sorting.
 cvar_t r_framedatasize = {CF_CLIENT | CF_ARCHIVE, "r_framedatasize", "0.5", "size of renderer data cache used during one frame (for skeletal animation caching, light processing, etc)"};
 cvar_t r_buffermegs[R_BUFFERDATA_COUNT] =
 {
index e7d3228d13f8ed5e1fc377ccaf412ffaa1bea85c..8e707337afe4fe8c9b8d4273ddae4247272112c5 100644 (file)
@@ -2936,7 +2936,7 @@ void Mod_MakeSortedSurfaces(model_t *mod)
        if(cls.state == ca_dedicated)
                return;
 
-       info = (Mod_MakeSortedSurfaces_qsortsurface_t*)R_FrameData_Alloc(mod->num_surfaces * sizeof(*info));
+       info = (Mod_MakeSortedSurfaces_qsortsurface_t*)Mem_Alloc(loadmodel->mempool, mod->num_surfaces * sizeof(*info));
        if (!mod->modelsurfaces_sorted)
                mod->modelsurfaces_sorted = (int *) Mem_Alloc(loadmodel->mempool, mod->num_surfaces * sizeof(*mod->modelsurfaces_sorted));
        // the goal is to sort by submodel (can't change which submodel a surface belongs to), and then by effects and textures
@@ -2952,6 +2952,7 @@ void Mod_MakeSortedSurfaces(model_t *mod)
                        qsort(info + mod->brush.submodels[k]->submodelsurfaces_start, (size_t)mod->brush.submodels[k]->submodelsurfaces_end - mod->brush.submodels[k]->submodelsurfaces_start, sizeof(*info), Mod_MakeSortedSurfaces_qsortfunc);
        for (j = 0; j < mod->num_surfaces; j++)
                mod->modelsurfaces_sorted[j] = info[j].surfaceindex;
+       Mem_Free(info);
 }
 
 void Mod_BuildVBOs(void)
@@ -4645,25 +4646,24 @@ static void Mod_Mesh_MakeSortedSurfaces(model_t *mod)
 {
        int i, j;
        texture_t *tex;
-       unsigned char* included = (unsigned char *)R_FrameData_Alloc(mod->num_surfaces * sizeof(unsigned char));
 
        // build the sorted surfaces list properly to reduce material setup
        // this is easy because we're just sorting on texture and don't care about the order of textures
        mod->submodelsurfaces_start = 0;
        mod->submodelsurfaces_end = 0;
        for (i = 0; i < mod->num_surfaces; i++)
-               included[i] = 0;
+               mod->data_surfaces[i].included = false;
        for (i = 0; i < mod->num_surfaces; i++)
        {
-               if (included[i])
+               if (mod->data_surfaces[i].included)
                        continue;
                tex = mod->data_surfaces[i].texture;
                // j = i is intentional
                for (j = i; j < mod->num_surfaces; j++)
                {
-                       if (!included[j] && mod->data_surfaces[j].texture == tex)
+                       if (!mod->data_surfaces[j].included && mod->data_surfaces[j].texture == tex)
                        {
-                               included[j] = 1;
+                               mod->data_surfaces[j].included = 1;
                                mod->modelsurfaces_sorted[mod->submodelsurfaces_end++] = j;
                        }
                }
index 072d61f9397ca512cedabec3c321204eaaf355f6..cf5e02dc1ec4450210fceb52f9767a01ca738caf 100644 (file)
@@ -404,6 +404,9 @@ typedef struct msurface_s
        int num_firstcollisiontriangle; // q3bsp only
        int num_collisiontriangles; // number of triangles (if surface has collisions enabled)
        int num_collisionvertices; // number of vertices referenced by collision triangles (if surface has collisions enabled)
+
+       // used by Mod_Mesh_Finalize when building sortedmodelsurfaces
+       qbool included;
 }
 msurface_t;