changed r_refdef.stats struct to be an array indexed by r_stat_* enums
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 23 Feb 2013 07:37:10 +0000 (07:37 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 23 Feb 2013 07:37:10 +0000 (07:37 +0000)
added r_speeds_graph and associated cvars, this will visually graph any
chosen renderer statistics (8 allowed at one time)
added a lot of additional statistics for the batcher

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11899 d7cf8633-e32d-0410-b094-e92efae38249

cl_particles.c
cl_screen.c
client.h
collision.c
draw.h
gl_backend.c
gl_draw.c
gl_rmain.c
gl_rsurf.c
host.c
r_shadow.c

index 56ac5b5..853c25e 100644 (file)
@@ -2437,7 +2437,7 @@ static void R_DrawDecal_TransparentCallback(const entity_render_t *ent, const rt
 
        RSurf_ActiveWorldEntity();
 
-       r_refdef.stats.drawndecals += numsurfaces;
+       r_refdef.stats[r_stat_drawndecals] += numsurfaces;
 //     R_Mesh_ResetTextureState();
        GL_DepthMask(false);
        GL_DepthRange(0, 1);
@@ -2574,7 +2574,7 @@ killdecal:
                Mem_Free(olddecals);
        }
 
-       r_refdef.stats.totaldecals = cl.num_decals;
+       r_refdef.stats[r_stat_totaldecals] = cl.num_decals;
 }
 
 static void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
@@ -2598,7 +2598,7 @@ static void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const
 
        Vector4Set(colormultiplier, r_refdef.view.colorscale * (1.0 / 256.0f), r_refdef.view.colorscale * (1.0 / 256.0f), r_refdef.view.colorscale * (1.0 / 256.0f), cl_particles_alpha.value * (1.0 / 256.0f));
 
-       r_refdef.stats.particles += numsurfaces;
+       r_refdef.stats[r_stat_particles] += numsurfaces;
 //     R_Mesh_ResetTextureState();
        GL_DepthMask(false);
        GL_DepthRange(0, 1);
@@ -2855,7 +2855,7 @@ void R_DrawParticles (void)
        int drawparticles = r_drawparticles.integer;
        float minparticledist_start;
        particle_t *p;
-       float gravity, frametime, f, dist, oldorg[3];
+       float gravity, frametime, f, dist, oldorg[3], decaldir[3];
        float drawdist2;
        int hitent;
        trace_t trace;
index 1f5f7db..cfa8f8f 100644 (file)
@@ -84,6 +84,26 @@ cvar_t cl_demo_mousegrab = {0, "cl_demo_mousegrab", "0", "Allows reading the mou
 cvar_t timedemo_screenshotframelist = {0, "timedemo_screenshotframelist", "", "when performing a timedemo, take screenshots of each frame in this space-separated list - example: 1 201 401"};
 cvar_t vid_touchscreen_outlinealpha = {0, "vid_touchscreen_outlinealpha", "0.25", "opacity of touchscreen area outlines"};
 cvar_t vid_touchscreen_overlayalpha = {0, "vid_touchscreen_overlayalpha", "0.25", "opacity of touchscreen area icons"};
+cvar_t r_speeds_graph = {CVAR_SAVE, "r_speeds_graph", "0", "display a graph of renderer statistics "};
+cvar_t r_speeds_graph_filter[8] =
+{
+       {CVAR_SAVE, "r_speeds_graph_filter_r", "timedelta", "Red - display the specified renderer statistic"},
+       {CVAR_SAVE, "r_speeds_graph_filter_g", "batch_batches", "Green - display the specified renderer statistic"},
+       {CVAR_SAVE, "r_speeds_graph_filter_b", "batch_triangles", "Blue - display the specified renderer statistic"},
+       {CVAR_SAVE, "r_speeds_graph_filter_y", "fast_triangles", "Yellow - display the specified renderer statistic"},
+       {CVAR_SAVE, "r_speeds_graph_filter_c", "copytriangles_triangles", "Cyan - display the specified renderer statistic"},
+       {CVAR_SAVE, "r_speeds_graph_filter_m", "dynamic_triangles", "Magenta - display the specified renderer statistic"},
+       {CVAR_SAVE, "r_speeds_graph_filter_w", "animcache_shade_vertices", "White - display the specified renderer statistic"},
+       {CVAR_SAVE, "r_speeds_graph_filter_o", "animcache_shape_vertices", "Orange - display the specified renderer statistic"},
+};
+cvar_t r_speeds_graph_length = {CVAR_SAVE, "r_speeds_graph_length", "1024", "number of frames in statistics graph, can be from 4 to 8192"};
+cvar_t r_speeds_graph_seconds = {CVAR_SAVE, "r_speeds_graph_seconds", "2", "number of seconds in graph, can be from 0.1 to 120"};
+cvar_t r_speeds_graph_x = {CVAR_SAVE, "r_speeds_graph_x", "0", "position of graph"};
+cvar_t r_speeds_graph_y = {CVAR_SAVE, "r_speeds_graph_y", "0", "position of graph"};
+cvar_t r_speeds_graph_width = {CVAR_SAVE, "r_speeds_graph_width", "256", "size of graph"};
+cvar_t r_speeds_graph_height = {CVAR_SAVE, "r_speeds_graph_height", "128", "size of graph"};
+
+
 
 extern cvar_t v_glslgamma;
 extern cvar_t sbar_info_pos;
@@ -233,10 +253,8 @@ static void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth,
        float g[NETGRAPH_PACKETS][6];
        float *a;
        float *b;
-       float vertex3f[(NETGRAPH_PACKETS+2)*5*2*3];
-       float color4f[(NETGRAPH_PACKETS+2)*5*2*4];
-       float *v;
-       float *c;
+       r_vertexgeneric_t vertex[(NETGRAPH_PACKETS+2)*5*2];
+       r_vertexgeneric_t *v;
        DrawQ_Fill(graphx, graphy, graphwidth, graphheight + textsize * 2, 0, 0, 0, 0.5, 0);
        // draw the bar graph itself
        memset(g, 0, sizeof(g));
@@ -270,33 +288,35 @@ static void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth,
        }
        // render the lines for the graph
        numlines = 0;
-       v = vertex3f;
-       c = color4f;
+       v = vertex;
        for (j = 0;j < NETGRAPH_PACKETS;j++)
        {
                a = g[j];
                b = g[(j+1)%NETGRAPH_PACKETS];
                if (a[0] < 0.0f || b[0] > 1.0f || b[0] < a[0])
                        continue;
-               VectorSet(v, graphx + graphwidth * a[0], graphy + graphheight * a[2], 0.0f);v += 3;Vector4Set(c, 1.0f, 1.0f, 0.0f, 1.0f);c += 4;
-               VectorSet(v, graphx + graphwidth * b[0], graphy + graphheight * b[2], 0.0f);v += 3;Vector4Set(c, 1.0f, 1.0f, 0.0f, 1.0f);c += 4;
+               VectorSet(v->vertex3f, graphx + graphwidth * a[0], graphy + graphheight * a[2], 0.0f);Vector4Set(v->color4f, 1.0f, 1.0f, 0.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
+               VectorSet(v->vertex3f, graphx + graphwidth * b[0], graphy + graphheight * b[2], 0.0f);Vector4Set(v->color4f, 1.0f, 1.0f, 0.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
 
-               VectorSet(v, graphx + graphwidth * a[0], graphy + graphheight * a[1], 0.0f);v += 3;Vector4Set(c, 1.0f, 0.0f, 0.0f, 1.0f);c += 4;
-               VectorSet(v, graphx + graphwidth * b[0], graphy + graphheight * b[1], 0.0f);v += 3;Vector4Set(c, 1.0f, 0.0f, 0.0f, 1.0f);c += 4;
+               VectorSet(v->vertex3f, graphx + graphwidth * a[0], graphy + graphheight * a[1], 0.0f);Vector4Set(v->color4f, 1.0f, 0.0f, 0.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
+               VectorSet(v->vertex3f, graphx + graphwidth * b[0], graphy + graphheight * b[1], 0.0f);Vector4Set(v->color4f, 1.0f, 0.0f, 0.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
 
-               VectorSet(v, graphx + graphwidth * a[0], graphy + graphheight * a[5], 0.0f);v += 3;Vector4Set(c, 0.0f, 1.0f, 0.0f, 1.0f);c += 4;
-               VectorSet(v, graphx + graphwidth * b[0], graphy + graphheight * b[5], 0.0f);v += 3;Vector4Set(c, 0.0f, 1.0f, 0.0f, 1.0f);c += 4;
+               VectorSet(v->vertex3f, graphx + graphwidth * a[0], graphy + graphheight * a[5], 0.0f);Vector4Set(v->color4f, 0.0f, 1.0f, 0.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
+               VectorSet(v->vertex3f, graphx + graphwidth * b[0], graphy + graphheight * b[5], 0.0f);Vector4Set(v->color4f, 0.0f, 1.0f, 0.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
 
-               VectorSet(v, graphx + graphwidth * a[0], graphy + graphheight * a[4], 0.0f);v += 3;Vector4Set(c, 1.0f, 1.0f, 1.0f, 1.0f);c += 4;
-               VectorSet(v, graphx + graphwidth * b[0], graphy + graphheight * b[4], 0.0f);v += 3;Vector4Set(c, 1.0f, 1.0f, 1.0f, 1.0f);c += 4;
+               VectorSet(v->vertex3f, graphx + graphwidth * a[0], graphy + graphheight * a[4], 0.0f);Vector4Set(v->color4f, 1.0f, 1.0f, 1.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
+               VectorSet(v->vertex3f, graphx + graphwidth * b[0], graphy + graphheight * b[4], 0.0f);Vector4Set(v->color4f, 1.0f, 1.0f, 1.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
 
-               VectorSet(v, graphx + graphwidth * a[0], graphy + graphheight * a[3], 0.0f);v += 3;Vector4Set(c, 1.0f, 0.5f, 0.0f, 1.0f);c += 4;
-               VectorSet(v, graphx + graphwidth * b[0], graphy + graphheight * b[3], 0.0f);v += 3;Vector4Set(c, 1.0f, 0.5f, 0.0f, 1.0f);c += 4;
+               VectorSet(v->vertex3f, graphx + graphwidth * a[0], graphy + graphheight * a[3], 0.0f);Vector4Set(v->color4f, 1.0f, 0.5f, 0.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
+               VectorSet(v->vertex3f, graphx + graphwidth * b[0], graphy + graphheight * b[3], 0.0f);Vector4Set(v->color4f, 1.0f, 0.5f, 0.0f, 1.0f);Vector2Set(v->texcoord2f, 0.0f, 0.0f);v++;
 
                numlines += 5;
        }
        if (numlines > 0)
-               DrawQ_Lines(0.0f, numlines, vertex3f, color4f, 0);
+       {
+               R_Mesh_PrepareVertices_Generic(numlines*2, vertex, NULL);
+               DrawQ_Lines(0.0f, numlines, 0, false);
+       }
        x = graphx;
        y = graphy + graphheight;
        dpsnprintf(bytesstring, sizeof(bytesstring), "%i", totalbytes);
@@ -721,6 +741,145 @@ void SCR_BeginLoadingPlaque (qboolean startup)
 
 //=============================================================================
 
+const char *r_stat_name[r_stat_count] =
+{
+       "timedelta",
+       "quality",
+       "renders",
+       "entities",
+       "entities_surfaces",
+       "entities_triangles",
+       "world_leafs",
+       "world_portals",
+       "world_surfaces",
+       "world_triangles",
+       "lightmapupdates",
+       "lightmapupdatepixels",
+       "particles",
+       "drawndecals",
+       "totaldecals",
+       "draws",
+       "draws_vertices",
+       "draws_elements",
+       "lights",
+       "lights_clears",
+       "lights_scissored",
+       "lights_lighttriangles",
+       "lights_shadowtriangles",
+       "lights_dynamicshadowtriangles",
+       "bouncegrid_lights",
+       "bouncegrid_particles",
+       "bouncegrid_traces",
+       "bouncegrid_hits",
+       "bouncegrid_splats",
+       "bouncegrid_bounces",
+       "photoncache_animated",
+       "photoncache_cached",
+       "photoncache_traced",
+       "bloom",
+       "bloom_copypixels",
+       "bloom_drawpixels",
+       "indexbufferuploadcount",
+       "indexbufferuploadsize",
+       "vertexbufferuploadcount",
+       "vertexbufferuploadsize",
+       "framedatacurrent",
+       "framedatasize",
+       "animcache_vertexmesh_count",
+       "animcache_vertexmesh_vertices",
+       "animcache_vertexmesh_maxvertices",
+       "animcache_skeletal_count",
+       "animcache_skeletal_bones",
+       "animcache_skeletal_maxbones",
+       "animcache_shade_count",
+       "animcache_shade_vertices",
+       "animcache_shade_maxvertices",
+       "animcache_shape_count",
+       "animcache_shape_vertices",
+       "animcache_shape_maxvertices",
+       "batch_batches",
+       "batch_withgaps",
+       "batch_surfaces",
+       "batch_vertices",
+       "batch_triangles",
+       "fast_batches",
+       "fast_surfaces",
+       "fast_vertices",
+       "fast_triangles",
+       "copytriangles_batches",
+       "copytriangles_surfaces",
+       "copytriangles_vertices",
+       "copytriangles_triangles",
+       "dynamic_batches",
+       "dynamic_surfaces",
+       "dynamic_vertices",
+       "dynamic_triangles",
+       "dynamicskeletal_batches",
+       "dynamicskeletal_surfaces",
+       "dynamicskeletal_vertices",
+       "dynamicskeletal_triangles",
+       "dynamic_batches_because_cvar",
+       "dynamic_surfaces_because_cvar",
+       "dynamic_vertices_because_cvar",
+       "dynamic_triangles_because_cvar",
+       "dynamic_batches_because_lightmapvertex",
+       "dynamic_surfaces_because_lightmapvertex",
+       "dynamic_vertices_because_lightmapvertex",
+       "dynamic_triangles_because_lightmapvertex",
+       "dynamic_batches_because_deformvertexes_autosprite",
+       "dynamic_surfaces_because_deformvertexes_autosprite",
+       "dynamic_vertices_because_deformvertexes_autosprite",
+       "dynamic_triangles_because_deformvertexes_autosprite",
+       "dynamic_batches_because_deformvertexes_autosprite2",
+       "dynamic_surfaces_because_deformvertexes_autosprite2",
+       "dynamic_vertices_because_deformvertexes_autosprite2",
+       "dynamic_triangles_because_deformvertexes_autosprite2",
+       "dynamic_batches_because_deformvertexes_normal",
+       "dynamic_surfaces_because_deformvertexes_normal",
+       "dynamic_vertices_because_deformvertexes_normal",
+       "dynamic_triangles_because_deformvertexes_normal",
+       "dynamic_batches_because_deformvertexes_wave",
+       "dynamic_surfaces_because_deformvertexes_wave",
+       "dynamic_vertices_because_deformvertexes_wave",
+       "dynamic_triangles_because_deformvertexes_wave",
+       "dynamic_batches_because_deformvertexes_bulge",
+       "dynamic_surfaces_because_deformvertexes_bulge",
+       "dynamic_vertices_because_deformvertexes_bulge",
+       "dynamic_triangles_because_deformvertexes_bulge",
+       "dynamic_batches_because_deformvertexes_move",
+       "dynamic_surfaces_because_deformvertexes_move",
+       "dynamic_vertices_because_deformvertexes_move",
+       "dynamic_triangles_because_deformvertexes_move",
+       "dynamic_batches_because_tcgen_lightmap",
+       "dynamic_surfaces_because_tcgen_lightmap",
+       "dynamic_vertices_because_tcgen_lightmap",
+       "dynamic_triangles_because_tcgen_lightmap",
+       "dynamic_batches_because_tcgen_vector",
+       "dynamic_surfaces_because_tcgen_vector",
+       "dynamic_vertices_because_tcgen_vector",
+       "dynamic_triangles_because_tcgen_vector",
+       "dynamic_batches_because_tcgen_environment",
+       "dynamic_surfaces_because_tcgen_environment",
+       "dynamic_vertices_because_tcgen_environment",
+       "dynamic_triangles_because_tcgen_environment",
+       "dynamic_batches_because_tcmod_turbulent",
+       "dynamic_surfaces_because_tcmod_turbulent",
+       "dynamic_vertices_because_tcmod_turbulent",
+       "dynamic_triangles_because_tcmod_turbulent",
+       "dynamic_batches_because_interleavedarrays",
+       "dynamic_surfaces_because_interleavedarrays",
+       "dynamic_vertices_because_interleavedarrays",
+       "dynamic_triangles_because_interleavedarrays",
+       "dynamic_batches_because_nogaps",
+       "dynamic_surfaces_because_nogaps",
+       "dynamic_vertices_because_nogaps",
+       "dynamic_triangles_because_nogaps",
+       "dynamic_batches_because_derived",
+       "dynamic_surfaces_because_derived",
+       "dynamic_vertices_because_derived",
+       "dynamic_triangles_because_derived",
+};
+
 char r_speeds_timestring[4096];
 int speedstringcount, r_timereport_active;
 double r_timereport_temp = 0, r_timereport_current = 0, r_timereport_start = 0;
@@ -782,6 +941,10 @@ static int R_CountLeafTriangles(const dp_model_t *model, const mleaf_t *leaf)
        return triangles;
 }
 
+#define R_SPEEDS_GRAPH_COLORS 8
+#define R_SPEEDS_GRAPH_TEXTLENGTH 64
+static float r_speeds_graph_colors[R_SPEEDS_GRAPH_COLORS][4] = {{1, 0, 0, 1}, {0, 1, 0, 1}, {0, 0, 1, 1}, {1, 1, 0, 1}, {0, 1, 1, 1}, {1, 0, 1, 1}, {1, 1, 1, 1}, {1, 0.5f, 0, 1}};
+
 extern cvar_t r_viewscale;
 extern float viewscalefpsadjusted;
 static void R_TimeReport_EndFrame(void)
@@ -790,6 +953,11 @@ static void R_TimeReport_EndFrame(void)
        cl_locnode_t *loc;
        char string[1024+4096];
        mleaf_t *viewleaf;
+       static double oldtime = 0;
+
+       r_refdef.stats[r_stat_timedelta] = (int)((realtime - oldtime) * 1000000.0);
+       oldtime = realtime;
+       r_refdef.stats[r_stat_quality] = (int)(100 * r_refdef.view.quality);
 
        string[0] = 0;
        if (r_speeds.integer)
@@ -799,42 +967,48 @@ static void R_TimeReport_EndFrame(void)
                loc = CL_Locs_FindNearest(cl.movement_origin);
                viewleaf = (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.PointInLeaf) ? r_refdef.scene.worldmodel->brush.PointInLeaf(r_refdef.scene.worldmodel, r_refdef.view.origin) : NULL;
                dpsnprintf(string, sizeof(string),
-"%6.0fus rendertime %3.0f%% viewscale %s%s %.3f cl.time%2.4f brightness\n"
+"%6ius time delta %s%s %.3f cl.time%2.4f brightness\n"
 "%3i renders org:'%+8.2f %+8.2f %+8.2f' dir:'%+2.3f %+2.3f %+2.3f'\n"
 "%5i viewleaf%5i cluster%3i area%4i brushes%4i surfaces(%7i triangles)\n"
 "%7i surfaces%7i triangles %5i entities (%7i surfaces%7i triangles)\n"
 "%5i leafs%5i portals%6i/%6i particles%6i/%6i decals %3i%% quality\n"
-"%7i lightmap updates (%7i pixels)%8iKB/%8iKB framedata\n"
+"%7i lightmap updates (%7i pixels)%8i/%8i framedata\n"
 "%4i lights%4i clears%4i scissored%7i light%7i shadow%7i dynamic\n"
 "bouncegrid:%4i lights%6i particles%6i traces%6i hits%6i splats%6i bounces\n"
-"collision cache efficiency:%6i cached%6i traced%6ianimated\n"
+"photon cache efficiency:%6i cached%6i traced%6ianimated\n"
 "%6i draws%8i vertices%8i triangles bloompixels%8i copied%8i drawn\n"
 "updated%5i indexbuffers%8i bytes%5i vertexbuffers%8i bytes\n"
+"animcache%5ib gpuskeletal%7i vertices (%7i with normals)\n"
+"fastbatch%5i count%5i surfaces%7i vertices %7i triangles\n"
+"copytris%5i count%5i surfaces%7i vertices %7i triangles\n"
+"dynamic%5i count%5i surfaces%7i vertices%7i triangles\n"
 "%s"
-, r_refdef.lastdrawscreentime * 1000000.0, r_viewscale.value * sqrt(viewscalefpsadjusted) * 100.0f, loc ? "Location: " : "", loc ? loc->name : "", cl.time, r_refdef.view.colorscale
-, r_refdef.stats.renders, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], r_refdef.view.forward[0], r_refdef.view.forward[1], r_refdef.view.forward[2]
+, r_refdef.stats[r_stat_timedelta], loc ? "Location: " : "", loc ? loc->name : "", cl.time, r_refdef.view.colorscale
+, r_refdef.stats[r_stat_renders], r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], r_refdef.view.forward[0], r_refdef.view.forward[1], r_refdef.view.forward[2]
 , viewleaf ? (int)(viewleaf - r_refdef.scene.worldmodel->brush.data_leafs) : -1, viewleaf ? viewleaf->clusterindex : -1, viewleaf ? viewleaf->areaindex : -1, viewleaf ? viewleaf->numleafbrushes : 0, viewleaf ? viewleaf->numleafsurfaces : 0, viewleaf ? R_CountLeafTriangles(r_refdef.scene.worldmodel, viewleaf) : 0
-, r_refdef.stats.world_surfaces, r_refdef.stats.world_triangles, r_refdef.stats.entities, r_refdef.stats.entities_surfaces, r_refdef.stats.entities_triangles
-, r_refdef.stats.world_leafs, r_refdef.stats.world_portals, r_refdef.stats.particles, cl.num_particles, r_refdef.stats.drawndecals, r_refdef.stats.totaldecals, (int)(100 * r_refdef.view.quality)
-, r_refdef.stats.lightmapupdates, r_refdef.stats.lightmapupdatepixels, (r_refdef.stats.framedatacurrent+512) / 1024, (r_refdef.stats.framedatasize+512)/1024
-, r_refdef.stats.lights, r_refdef.stats.lights_clears, r_refdef.stats.lights_scissored, r_refdef.stats.lights_lighttriangles, r_refdef.stats.lights_shadowtriangles, r_refdef.stats.lights_dynamicshadowtriangles
-, r_refdef.stats.bouncegrid_lights, r_refdef.stats.bouncegrid_particles, r_refdef.stats.bouncegrid_traces, r_refdef.stats.bouncegrid_hits, r_refdef.stats.bouncegrid_splats, r_refdef.stats.bouncegrid_bounces
-, r_refdef.stats.collisioncache_cached, r_refdef.stats.collisioncache_traced, r_refdef.stats.collisioncache_animated
-, r_refdef.stats.draws, r_refdef.stats.draws_vertices, r_refdef.stats.draws_elements / 3, r_refdef.stats.bloom_copypixels, r_refdef.stats.bloom_drawpixels
-, r_refdef.stats.indexbufferuploadcount, r_refdef.stats.indexbufferuploadsize, r_refdef.stats.vertexbufferuploadcount, r_refdef.stats.vertexbufferuploadsize
+, r_refdef.stats[r_stat_world_surfaces], r_refdef.stats[r_stat_world_triangles], r_refdef.stats[r_stat_entities], r_refdef.stats[r_stat_entities_surfaces], r_refdef.stats[r_stat_entities_triangles]
+, r_refdef.stats[r_stat_world_leafs], r_refdef.stats[r_stat_world_portals], r_refdef.stats[r_stat_particles], cl.num_particles, r_refdef.stats[r_stat_drawndecals], r_refdef.stats[r_stat_totaldecals], r_refdef.stats[r_stat_quality]
+, r_refdef.stats[r_stat_lightmapupdates], r_refdef.stats[r_stat_lightmapupdatepixels], r_refdef.stats[r_stat_framedatacurrent], r_refdef.stats[r_stat_framedatasize]
+, r_refdef.stats[r_stat_lights], r_refdef.stats[r_stat_lights_clears], r_refdef.stats[r_stat_lights_scissored], r_refdef.stats[r_stat_lights_lighttriangles], r_refdef.stats[r_stat_lights_shadowtriangles], r_refdef.stats[r_stat_lights_dynamicshadowtriangles]
+, r_refdef.stats[r_stat_bouncegrid_lights], r_refdef.stats[r_stat_bouncegrid_particles], r_refdef.stats[r_stat_bouncegrid_traces], r_refdef.stats[r_stat_bouncegrid_hits], r_refdef.stats[r_stat_bouncegrid_splats], r_refdef.stats[r_stat_bouncegrid_bounces]
+, r_refdef.stats[r_stat_photoncache_cached], r_refdef.stats[r_stat_photoncache_traced], r_refdef.stats[r_stat_photoncache_animated]
+, r_refdef.stats[r_stat_draws], r_refdef.stats[r_stat_draws_vertices], r_refdef.stats[r_stat_draws_elements] / 3, r_refdef.stats[r_stat_bloom_copypixels], r_refdef.stats[r_stat_bloom_drawpixels]
+, r_refdef.stats[r_stat_indexbufferuploadcount], r_refdef.stats[r_stat_indexbufferuploadsize], r_refdef.stats[r_stat_vertexbufferuploadcount], r_refdef.stats[r_stat_vertexbufferuploadsize]
+, r_refdef.stats[r_stat_animcache_skeletal_bones], r_refdef.stats[r_stat_animcache_shape_vertices], r_refdef.stats[r_stat_animcache_shade_vertices]
+, r_refdef.stats[r_stat_batch_fast_batches], r_refdef.stats[r_stat_batch_fast_surfaces], r_refdef.stats[r_stat_batch_fast_vertices], r_refdef.stats[r_stat_batch_fast_triangles]
+, r_refdef.stats[r_stat_batch_copytriangles_batches], r_refdef.stats[r_stat_batch_copytriangles_surfaces], r_refdef.stats[r_stat_batch_copytriangles_vertices], r_refdef.stats[r_stat_batch_copytriangles_triangles]
+, r_refdef.stats[r_stat_batch_dynamic_batches], r_refdef.stats[r_stat_batch_dynamic_surfaces], r_refdef.stats[r_stat_batch_dynamic_vertices], r_refdef.stats[r_stat_batch_dynamic_triangles]
 , r_speeds_timestring);
+       }
 
-               memset(&r_refdef.stats, 0, sizeof(r_refdef.stats));
-
-               speedstringcount = 0;
-               r_speeds_timestring[0] = 0;
-               r_timereport_active = false;
+       speedstringcount = 0;
+       r_speeds_timestring[0] = 0;
+       r_timereport_active = false;
 
-               if (r_speeds.integer >= 2)
-               {
-                       r_timereport_active = true;
-                       r_timereport_start = r_timereport_current = Sys_DirtyTime();
-               }
+       if (r_speeds.integer >= 2)
+       {
+               r_timereport_active = true;
+               r_timereport_start = r_timereport_current = Sys_DirtyTime();
        }
 
        if (string[0])
@@ -862,6 +1036,218 @@ static void R_TimeReport_EndFrame(void)
                }
                r_draw2d_force = false;
        }
+
+       if (r_speeds_graph_length.integer != bound(4, r_speeds_graph_length.integer, 8192))
+               Cvar_SetValueQuick(&r_speeds_graph_length, bound(4, r_speeds_graph_length.integer, 8192));
+       if (fabs(r_speeds_graph_seconds.value - bound(0.1f, r_speeds_graph_seconds.value, 120.0f)) > 0.01f)
+               Cvar_SetValueQuick(&r_speeds_graph_seconds, bound(0.1f, r_speeds_graph_seconds.value, 120.0f));
+       if (r_speeds_graph.integer)
+       {
+               // if we currently have no graph data, reset the graph data entirely
+               if (!cls.r_speeds_graph_data)
+                       for (i = 0;i < r_stat_count;i++)
+                               cls.r_speeds_graph_datamin[i] = cls.r_speeds_graph_datamax[i] = r_refdef.stats[i];
+               if (cls.r_speeds_graph_length != r_speeds_graph_length.integer)
+               {
+                       int i, stat, index, d, graph_length, *graph_data;
+                       cls.r_speeds_graph_length = r_speeds_graph_length.integer;
+                       cls.r_speeds_graph_current = 0;
+                       if (cls.r_speeds_graph_data)
+                               Mem_Free(cls.r_speeds_graph_data);
+                       cls.r_speeds_graph_data = Mem_Alloc(cls.permanentmempool, cls.r_speeds_graph_length * sizeof(r_refdef.stats));
+                       // initialize the graph to have the current values throughout history
+                       graph_data = cls.r_speeds_graph_data;
+                       graph_length = cls.r_speeds_graph_length;
+                       index = 0;
+                       for (stat = 0;stat < r_stat_count;stat++)
+                       {
+                               d = r_refdef.stats[stat];
+                               if (stat == r_stat_timedelta)
+                                       d = 0;
+                               for (i = 0;i < graph_length;i++)
+                                       graph_data[index++] = d;
+                       }
+               }
+       }
+       else
+       {
+               if (cls.r_speeds_graph_length)
+               {
+                       cls.r_speeds_graph_length = 0;
+                       Mem_Free(cls.r_speeds_graph_data);
+                       cls.r_speeds_graph_data = NULL;
+                       cls.r_speeds_graph_current = 0;
+               }
+       }
+
+       if (cls.r_speeds_graph_length)
+       {
+               char legend[128];
+               r_vertexgeneric_t *v;
+               int numlines;
+               const int *data;
+               float x, y, width, height, scalex, scaley;
+               int color, stat, stats, index, range_min, range_max;
+               int graph_current, graph_length, *graph_data;
+               int statindex[R_SPEEDS_GRAPH_COLORS];
+               int frameslastsecond;
+               int sum;
+
+               // add current stats to the graph_data
+               cls.r_speeds_graph_current++;
+               if (cls.r_speeds_graph_current >= cls.r_speeds_graph_length)
+                       cls.r_speeds_graph_current = 0;
+               // poke each new stat into the current offset of its graph
+               graph_data = cls.r_speeds_graph_data;
+               graph_current = cls.r_speeds_graph_current;
+               graph_length = cls.r_speeds_graph_length;
+               for (stat = 0;stat < r_stat_count;stat++)
+                       graph_data[stat * graph_length + graph_current] = r_refdef.stats[stat];
+
+               // update the graph ranges
+               for (stat = 0;stat < r_stat_count;stat++)
+               {
+                       if (cls.r_speeds_graph_datamin[stat] > r_refdef.stats[stat])
+                               cls.r_speeds_graph_datamin[stat] = r_refdef.stats[stat];
+                       if (cls.r_speeds_graph_datamax[stat] < r_refdef.stats[stat])
+                               cls.r_speeds_graph_datamax[stat] = r_refdef.stats[stat];
+               }
+
+               // force 2D drawing to occur even if r_render is 0
+               r_draw2d_force = true;
+
+               // position the graph
+               width = r_speeds_graph_width.value;
+               height = r_speeds_graph_height.value;
+               x = bound(0, r_speeds_graph_x.value, vid_conwidth.value - width);
+               y = bound(0, r_speeds_graph_y.value, vid_conheight.value - height);
+
+               // count how many frames were in the last second
+               data = graph_data + r_stat_timedelta * graph_length;
+               index = graph_current;
+               sum = 0;
+               for (i = 0;i < graph_length;i++)
+               {
+                       sum += data[index];
+                       if (sum >= 1000000)
+                               break;
+                       index--;
+                       if (index < 0)
+                               index = graph_length - 1;
+               }
+               frameslastsecond = i;
+
+               // fill background with a pattern of gray and black at one second intervals
+               scalex = (float)width / (float)r_speeds_graph_seconds.value;
+               for (i = 0;i < r_speeds_graph_seconds.integer + 1;i++)
+               {
+                       float x1 = x + width - (i + 1) * scalex;
+                       float x2 = x + width - i * scalex;
+                       if (x1 < x)
+                               x1 = x;
+                       if (i & 1)
+                               DrawQ_Fill(x1, y, x2 - x1, height, 0.0f, 0.0f, 0.0f, 0.5f, 0);
+                       else
+                               DrawQ_Fill(x1, y, x2 - x1, height, 0.2f, 0.2f, 0.2f, 0.5f, 0);
+               }
+
+               // count how many stats match our pattern
+               stats = 0;
+               color = 0;
+               for (color = 0;color < R_SPEEDS_GRAPH_COLORS;color++)
+               {
+                       // look at all stat names and find ones matching the filter
+                       statindex[color] = -1;
+                       if (!r_speeds_graph_filter[color].string)
+                               continue;
+                       for (stat = 0;stat < r_stat_count;stat++)
+                               if (!strcmp(r_stat_name[stat], r_speeds_graph_filter[color].string))
+                                       break;
+                       if (stat >= r_stat_count)
+                               continue;
+                       // record that this color is this stat for the line drawing loop
+                       statindex[color] = stat;
+                       // draw the legend text in the background of the graph
+                       dpsnprintf(legend, sizeof(legend), "%10i :%s", graph_data[stat * graph_length + graph_current], r_stat_name[stat]);
+                       DrawQ_String(x, y + stats * 8, legend, 0, 8, 8, r_speeds_graph_colors[color][0], r_speeds_graph_colors[color][1], r_speeds_graph_colors[color][2], r_speeds_graph_colors[color][3] * 1.00f, 0, NULL, true, FONT_DEFAULT);
+                       // count how many stats we need to graph in vertex buffer
+                       stats++;
+               }
+               dpsnprintf(legend, sizeof(legend), "%10i  frames last second", frameslastsecond);
+               DrawQ_String(x, y + stats * 8, legend, 0, 8, 8, 0.5f, 0.5f, 0.5f, 0.5f, 0, NULL, true, FONT_DEFAULT);
+
+               if (stats)
+               {
+                       // legend text is drawn after the graphs
+                       // render the graph lines, we'll go back and render the legend text later
+                       scalex = (float)width / (1000000.0 * r_speeds_graph_seconds.value);
+                       // get space in a vertex buffer to draw this
+                       numlines = stats * (graph_length - 1);
+                       v = R_Mesh_PrepareVertices_Generic_Lock(numlines * 2);
+                       stats = 0;
+                       for (color = 0;color < R_SPEEDS_GRAPH_COLORS;color++)
+                       {
+                               // look at all stat names and find ones matching the filter
+                               stat = statindex[color];
+                               if (stat < 0)
+                                       continue;
+                               // prefer to graph stats with 0 base, but if they are
+                               // negative we have no choice
+                               range_min = min(cls.r_speeds_graph_datamin[stat], 0);
+                               range_max = cls.r_speeds_graph_datamax[stat];
+                               // some stats we specifically override the graph scale on
+                               if (stat == r_stat_timedelta)
+                                       range_max = 100000;
+                               if (range_max == range_min)
+                                       range_max++;
+                               scaley = height / (range_max - range_min);
+                               // generate lines (2 vertices each)
+                               // to deal with incomplete data we walk right to left
+                               data = graph_data + stat * graph_length;
+                               index = graph_current;
+                               sum = 0;
+                               for (i = 0;i < graph_length - 1;)
+                               {
+                                       v->vertex3f[0] = x + width - sum * scalex;
+                                       if (v->vertex3f[0] < x)
+                                               v->vertex3f[0] = x;
+                                       v->vertex3f[1] = y + height - (data[index] - range_min) * scaley;
+                                       v->vertex3f[2] = 0;
+                                       v->color4f[0] = r_speeds_graph_colors[color][0];
+                                       v->color4f[1] = r_speeds_graph_colors[color][1];
+                                       v->color4f[2] = r_speeds_graph_colors[color][2];
+                                       v->color4f[3] = r_speeds_graph_colors[color][3];
+                                       v->texcoord2f[0] = 0;
+                                       v->texcoord2f[1] = 0;
+                                       v++;
+                                       sum += graph_data[r_stat_timedelta * graph_length + index];
+                                       index--;
+                                       if (index < 0)
+                                               index = graph_length - 1;
+                                       i++;
+                                       v->vertex3f[0] = x + width - sum * scalex;
+                                       if (v->vertex3f[0] < x)
+                                               v->vertex3f[0] = x;
+                                       v->vertex3f[1] = y + height - (data[index] - range_min) * scaley;
+                                       v->vertex3f[2] = 0;
+                                       v->color4f[0] = r_speeds_graph_colors[color][0];
+                                       v->color4f[1] = r_speeds_graph_colors[color][1];
+                                       v->color4f[2] = r_speeds_graph_colors[color][2];
+                                       v->color4f[3] = r_speeds_graph_colors[color][3];
+                                       v->texcoord2f[0] = 0;
+                                       v->texcoord2f[1] = 0;
+                                       v++;
+                               }
+                       }
+                       R_Mesh_PrepareVertices_Generic_Unlock();
+                       DrawQ_Lines(0.0f, numlines, 0, false);
+               }
+
+               // return to not drawing anything if r_render is 0
+               r_draw2d_force = false;
+       }
+
+       memset(&r_refdef.stats, 0, sizeof(r_refdef.stats));
 }
 
 /*
@@ -897,6 +1283,7 @@ void CL_Screen_Shutdown(void)
 
 void CL_Screen_Init(void)
 {
+       int i;
        Cvar_RegisterVariable (&scr_fov);
        Cvar_RegisterVariable (&scr_viewsize);
        Cvar_RegisterVariable (&scr_conalpha);
@@ -967,6 +1354,15 @@ void CL_Screen_Init(void)
        Cvar_RegisterVariable(&timedemo_screenshotframelist);
        Cvar_RegisterVariable(&vid_touchscreen_outlinealpha);
        Cvar_RegisterVariable(&vid_touchscreen_overlayalpha);
+       Cvar_RegisterVariable(&r_speeds_graph);
+       for (i = 0;i < (int)(sizeof(r_speeds_graph_filter)/sizeof(r_speeds_graph_filter[0]));i++)
+               Cvar_RegisterVariable(&r_speeds_graph_filter[i]);
+       Cvar_RegisterVariable(&r_speeds_graph_length);
+       Cvar_RegisterVariable(&r_speeds_graph_seconds);
+       Cvar_RegisterVariable(&r_speeds_graph_x);
+       Cvar_RegisterVariable(&r_speeds_graph_y);
+       Cvar_RegisterVariable(&r_speeds_graph_width);
+       Cvar_RegisterVariable(&r_speeds_graph_height);
 
        // if we want no console, turn it off here too
        if (COM_CheckParm ("-noconsole"))
index afd75a2..5918b4e 100644 (file)
--- a/client.h
+++ b/client.h
@@ -25,6 +25,148 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "matrixlib.h"
 #include "snd_main.h"
 
+// NOTE: r_stat_name[] must match this indexing
+typedef enum r_stat_e
+{
+       r_stat_timedelta,
+       r_stat_quality,
+       r_stat_renders,
+       r_stat_entities,
+       r_stat_entities_surfaces,
+       r_stat_entities_triangles,
+       r_stat_world_leafs,
+       r_stat_world_portals,
+       r_stat_world_surfaces,
+       r_stat_world_triangles,
+       r_stat_lightmapupdates,
+       r_stat_lightmapupdatepixels,
+       r_stat_particles,
+       r_stat_drawndecals,
+       r_stat_totaldecals,
+       r_stat_draws,
+       r_stat_draws_vertices,
+       r_stat_draws_elements,
+       r_stat_lights,
+       r_stat_lights_clears,
+       r_stat_lights_scissored,
+       r_stat_lights_lighttriangles,
+       r_stat_lights_shadowtriangles,
+       r_stat_lights_dynamicshadowtriangles,
+       r_stat_bouncegrid_lights,
+       r_stat_bouncegrid_particles,
+       r_stat_bouncegrid_traces,
+       r_stat_bouncegrid_hits,
+       r_stat_bouncegrid_splats,
+       r_stat_bouncegrid_bounces,
+       r_stat_photoncache_animated,
+       r_stat_photoncache_cached,
+       r_stat_photoncache_traced,
+       r_stat_bloom,
+       r_stat_bloom_copypixels,
+       r_stat_bloom_drawpixels,
+       r_stat_indexbufferuploadcount,
+       r_stat_indexbufferuploadsize,
+       r_stat_vertexbufferuploadcount,
+       r_stat_vertexbufferuploadsize,
+       r_stat_framedatacurrent,
+       r_stat_framedatasize,
+       r_stat_animcache_vertexmesh_count,
+       r_stat_animcache_vertexmesh_vertices,
+       r_stat_animcache_vertexmesh_maxvertices,
+       r_stat_animcache_skeletal_count,
+       r_stat_animcache_skeletal_bones,
+       r_stat_animcache_skeletal_maxbones,
+       r_stat_animcache_shade_count,
+       r_stat_animcache_shade_vertices,
+       r_stat_animcache_shade_maxvertices,
+       r_stat_animcache_shape_count,
+       r_stat_animcache_shape_vertices,
+       r_stat_animcache_shape_maxvertices,
+       r_stat_batch_batches,
+       r_stat_batch_withgaps,
+       r_stat_batch_surfaces,
+       r_stat_batch_vertices,
+       r_stat_batch_triangles,
+       r_stat_batch_fast_batches,
+       r_stat_batch_fast_surfaces,
+       r_stat_batch_fast_vertices,
+       r_stat_batch_fast_triangles,
+       r_stat_batch_copytriangles_batches,
+       r_stat_batch_copytriangles_surfaces,
+       r_stat_batch_copytriangles_vertices,
+       r_stat_batch_copytriangles_triangles,
+       r_stat_batch_dynamic_batches,
+       r_stat_batch_dynamic_surfaces,
+       r_stat_batch_dynamic_vertices,
+       r_stat_batch_dynamic_triangles,
+       r_stat_batch_dynamicskeletal_batches,
+       r_stat_batch_dynamicskeletal_surfaces,
+       r_stat_batch_dynamicskeletal_vertices,
+       r_stat_batch_dynamicskeletal_triangles,
+       r_stat_batch_dynamic_batches_because_cvar,
+       r_stat_batch_dynamic_surfaces_because_cvar,
+       r_stat_batch_dynamic_vertices_because_cvar,
+       r_stat_batch_dynamic_triangles_because_cvar,
+       r_stat_batch_dynamic_batches_because_lightmapvertex,
+       r_stat_batch_dynamic_surfaces_because_lightmapvertex,
+       r_stat_batch_dynamic_vertices_because_lightmapvertex,
+       r_stat_batch_dynamic_triangles_because_lightmapvertex,
+       r_stat_batch_dynamic_batches_because_deformvertexes_autosprite,
+       r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite,
+       r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite,
+       r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite,
+       r_stat_batch_dynamic_batches_because_deformvertexes_autosprite2,
+       r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite2,
+       r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite2,
+       r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite2,
+       r_stat_batch_dynamic_batches_because_deformvertexes_normal,
+       r_stat_batch_dynamic_surfaces_because_deformvertexes_normal,
+       r_stat_batch_dynamic_vertices_because_deformvertexes_normal,
+       r_stat_batch_dynamic_triangles_because_deformvertexes_normal,
+       r_stat_batch_dynamic_batches_because_deformvertexes_wave,
+       r_stat_batch_dynamic_surfaces_because_deformvertexes_wave,
+       r_stat_batch_dynamic_vertices_because_deformvertexes_wave,
+       r_stat_batch_dynamic_triangles_because_deformvertexes_wave,
+       r_stat_batch_dynamic_batches_because_deformvertexes_bulge,
+       r_stat_batch_dynamic_surfaces_because_deformvertexes_bulge,
+       r_stat_batch_dynamic_vertices_because_deformvertexes_bulge,
+       r_stat_batch_dynamic_triangles_because_deformvertexes_bulge,
+       r_stat_batch_dynamic_batches_because_deformvertexes_move,
+       r_stat_batch_dynamic_surfaces_because_deformvertexes_move,
+       r_stat_batch_dynamic_vertices_because_deformvertexes_move,
+       r_stat_batch_dynamic_triangles_because_deformvertexes_move,
+       r_stat_batch_dynamic_batches_because_tcgen_lightmap,
+       r_stat_batch_dynamic_surfaces_because_tcgen_lightmap,
+       r_stat_batch_dynamic_vertices_because_tcgen_lightmap,
+       r_stat_batch_dynamic_triangles_because_tcgen_lightmap,
+       r_stat_batch_dynamic_batches_because_tcgen_vector,
+       r_stat_batch_dynamic_surfaces_because_tcgen_vector,
+       r_stat_batch_dynamic_vertices_because_tcgen_vector,
+       r_stat_batch_dynamic_triangles_because_tcgen_vector,
+       r_stat_batch_dynamic_batches_because_tcgen_environment,
+       r_stat_batch_dynamic_surfaces_because_tcgen_environment,
+       r_stat_batch_dynamic_vertices_because_tcgen_environment,
+       r_stat_batch_dynamic_triangles_because_tcgen_environment,
+       r_stat_batch_dynamic_batches_because_tcmod_turbulent,
+       r_stat_batch_dynamic_surfaces_because_tcmod_turbulent,
+       r_stat_batch_dynamic_vertices_because_tcmod_turbulent,
+       r_stat_batch_dynamic_triangles_because_tcmod_turbulent,
+       r_stat_batch_dynamic_batches_because_interleavedarrays,
+       r_stat_batch_dynamic_surfaces_because_interleavedarrays,
+       r_stat_batch_dynamic_vertices_because_interleavedarrays,
+       r_stat_batch_dynamic_triangles_because_interleavedarrays,
+       r_stat_batch_dynamic_batches_because_nogaps,
+       r_stat_batch_dynamic_surfaces_because_nogaps,
+       r_stat_batch_dynamic_vertices_because_nogaps,
+       r_stat_batch_dynamic_triangles_because_nogaps,
+       r_stat_batch_dynamic_batches_because_derived,
+       r_stat_batch_dynamic_surfaces_because_derived,
+       r_stat_batch_dynamic_vertices_because_derived,
+       r_stat_batch_dynamic_triangles_because_derived,
+       r_stat_count // size of array
+}
+r_stat_t;
+
 // flags for rtlight rendering
 #define LIGHTFLAG_NORMALMODE 1
 #define LIGHTFLAG_REALTIMEMODE 2
@@ -725,6 +867,14 @@ typedef struct client_static_s
        // don't write-then-read csprogs.dat (useful for demo playback)
        unsigned char *caughtcsprogsdata;
        fs_offset_t caughtcsprogsdatasize;
+
+       int r_speeds_graph_length;
+       int r_speeds_graph_current;
+       int *r_speeds_graph_data;
+
+       // graph scales
+       int r_speeds_graph_datamin[r_stat_count];
+       int r_speeds_graph_datamax[r_stat_count];
 }
 client_static_t;
 
@@ -1548,51 +1698,6 @@ extern qboolean sb_showscores;
 float RSurf_FogVertex(const vec3_t p);
 float RSurf_FogPoint(const vec3_t p);
 
-typedef struct r_refdef_stats_s
-{
-       int renders;
-       int entities;
-       int entities_surfaces;
-       int entities_triangles;
-       int world_leafs;
-       int world_portals;
-       int world_surfaces;
-       int world_triangles;
-       int lightmapupdates;
-       int lightmapupdatepixels;
-       int particles;
-       int drawndecals;
-       int totaldecals;
-       int draws;
-       int draws_vertices;
-       int draws_elements;
-       int lights;
-       int lights_clears;
-       int lights_scissored;
-       int lights_lighttriangles;
-       int lights_shadowtriangles;
-       int lights_dynamicshadowtriangles;
-       int bouncegrid_lights;
-       int bouncegrid_particles;
-       int bouncegrid_traces;
-       int bouncegrid_hits;
-       int bouncegrid_splats;
-       int bouncegrid_bounces;
-       int collisioncache_animated;
-       int collisioncache_cached;
-       int collisioncache_traced;
-       int bloom;
-       int bloom_copypixels;
-       int bloom_drawpixels;
-       int indexbufferuploadcount;
-       int indexbufferuploadsize;
-       int vertexbufferuploadcount;
-       int vertexbufferuploadsize;
-       int framedatacurrent;
-       int framedatasize;
-}
-r_refdef_stats_t;
-
 typedef enum r_viewport_type_e
 {
        R_VIEWPORTTYPE_ORTHO,
@@ -1830,7 +1935,7 @@ typedef struct r_refdef_s
 
        // rendering stats for r_speeds display
        // (these are incremented in many places)
-       r_refdef_stats_t stats;
+       int stats[r_stat_count];
 }
 r_refdef_t;
 
index 264eddb..ef237e9 100644 (file)
@@ -1683,7 +1683,7 @@ static collision_cachedtrace_t *Collision_Cache_Lookup(dp_model_t *model, const
        collision_cachedtrace_parameters_t params;
        // all non-cached traces use the same index
        if (!collision_cache.integer)
-               r_refdef.stats.collisioncache_traced++;
+               r_refdef.stats[r_stat_photoncache_traced]++;
        else
        {
                // cached trace lookup
@@ -1728,12 +1728,12 @@ static collision_cachedtrace_t *Collision_Cache_Lookup(dp_model_t *model, const
                        )
                                continue;
                        // found a matching trace in the cache
-                       r_refdef.stats.collisioncache_cached++;
+                       r_refdef.stats[r_stat_photoncache_cached]++;
                        cached->valid = true;
                        collision_cachedtrace_arrayused[index] = collision_cachedtrace_sequence;
                        return cached;
                }
-               r_refdef.stats.collisioncache_traced++;
+               r_refdef.stats[r_stat_photoncache_traced]++;
                // find an unused cache entry
                for (index = collision_cachedtrace_firstfree, range = collision_cachedtrace_max;index < range;index++)
                        if (collision_cachedtrace_arrayused[index] == 0)
diff --git a/draw.h b/draw.h
index 1daa5eb..316a696 100644 (file)
--- a/draw.h
+++ b/draw.h
@@ -188,8 +188,8 @@ void DrawQ_SetClipArea(float x, float y, float width, float height);
 void DrawQ_ResetClipArea(void);
 // draw a line
 void DrawQ_Line(float width, float x1, float y1, float x2, float y2, float r, float g, float b, float alpha, int flags);
-// draw a lot of lines
-void DrawQ_Lines (float width, int numlines, const float *vertex3f, const float *color4f, int flags);
+// draw a lot of lines (call R_Mesh_PrepareVertices_Generic first)
+void DrawQ_Lines(float width, int numlines, int flags, qboolean hasalpha);
 // draw a line loop
 void DrawQ_LineLoop(drawqueuemesh_t *mesh, int flags);
 // resets r_refdef.draw2dstage
index 8415c14..f68d27b 100644 (file)
@@ -2805,9 +2805,9 @@ void R_Mesh_Draw(int firstvertex, int numvertices, int firsttriangle, int numtri
        bufferoffset3i = element3i_bufferoffset;
        bufferobject3s = element3s_indexbuffer ? element3s_indexbuffer->bufferobject : 0;
        bufferoffset3s = element3s_bufferoffset;
-       r_refdef.stats.draws++;
-       r_refdef.stats.draws_vertices += numvertices;
-       r_refdef.stats.draws_elements += numelements;
+       r_refdef.stats[r_stat_draws]++;
+       r_refdef.stats[r_stat_draws_vertices] += numvertices;
+       r_refdef.stats[r_stat_draws_elements] += numelements;
        if (gl_paranoid.integer)
        {
                unsigned int i;
@@ -3300,13 +3300,13 @@ void R_Mesh_UpdateMeshBuffer(r_meshbuffer_t *buffer, const void *data, size_t si
                return;
        if (buffer->isindexbuffer)
        {
-               r_refdef.stats.indexbufferuploadcount++;
-               r_refdef.stats.indexbufferuploadsize += size;
+               r_refdef.stats[r_stat_indexbufferuploadcount]++;
+               r_refdef.stats[r_stat_indexbufferuploadsize] += size;
        }
        else
        {
-               r_refdef.stats.vertexbufferuploadcount++;
-               r_refdef.stats.vertexbufferuploadsize += size;
+               r_refdef.stats[r_stat_vertexbufferuploadcount]++;
+               r_refdef.stats[r_stat_vertexbufferuploadsize] += size;
        }
        switch(vid.renderpath)
        {
index 6569a92..88431d9 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -2062,14 +2062,8 @@ void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, f
        }
 }
 
-void DrawQ_Lines (float width, int numlines, const float *vertex3f, const float *color4f, int flags)
+void DrawQ_Lines (float width, int numlines, int flags, qboolean hasalpha)
 {
-       int i;
-       qboolean hasalpha = false;
-       for (i = 0;i < numlines*2;i++)
-               if (color4f[i*4+3] < 1.0f)
-                       hasalpha = true;
-
        _DrawQ_SetupAndProcessDrawFlag(flags, NULL, hasalpha ? 0.5f : 1.0f);
 
        if(!r_draw2d.integer && !r_draw2d_force)
@@ -2087,7 +2081,6 @@ void DrawQ_Lines (float width, int numlines, const float *vertex3f, const float
                //qglLineWidth(width);CHECKGLERROR
 
                CHECKGLERROR
-               R_Mesh_PrepareVertices_Generic_Arrays(numlines*2, vertex3f, color4f, NULL);
                qglDrawArrays(GL_LINES, 0, numlines*2);
                CHECKGLERROR
                break;
index 834b7ce..3b44bee 100644 (file)
@@ -4543,8 +4543,8 @@ void *R_FrameData_Alloc(size_t size)
        r_framedata_mem->current += size;
 
        // count the usage for stats
-       r_refdef.stats.framedatacurrent = max(r_refdef.stats.framedatacurrent, (int)r_framedata_mem->current);
-       r_refdef.stats.framedatasize = max(r_refdef.stats.framedatasize, (int)r_framedata_mem->size);
+       r_refdef.stats[r_stat_framedatacurrent] = max(r_refdef.stats[r_stat_framedatacurrent], (int)r_framedata_mem->current);
+       r_refdef.stats[r_stat_framedatasize] = max(r_refdef.stats[r_stat_framedatasize], (int)r_framedata_mem->size);
 
        return (void *)data;
 }
@@ -4616,6 +4616,9 @@ static void R_AnimCache_UpdateEntityMeshBuffers(entity_render_t *ent, int numver
        // TODO: upload vertex3f buffer?
        if (ent->animcache_vertexmesh)
        {
+               r_refdef.stats[r_stat_animcache_vertexmesh_count] += 1;
+               r_refdef.stats[r_stat_animcache_vertexmesh_vertices] += numvertices;
+               r_refdef.stats[r_stat_animcache_vertexmesh_maxvertices] = max(r_refdef.stats[r_stat_animcache_vertexmesh_maxvertices], numvertices);
                memcpy(ent->animcache_vertexmesh, ent->model->surfmesh.vertexmesh, sizeof(r_vertexmesh_t)*numvertices);
                for (i = 0;i < numvertices;i++)
                        memcpy(ent->animcache_vertexmesh[i].vertex3f, ent->animcache_vertex3f + 3*i, sizeof(float[3]));
@@ -4647,6 +4650,9 @@ qboolean R_AnimCache_GetEntity(entity_render_t *ent, qboolean wantnormals, qbool
                float *boneposerelative;
                float m[12];
                static float bonepose[256][12];
+               r_refdef.stats[r_stat_animcache_skeletal_count] += 1;
+               r_refdef.stats[r_stat_animcache_skeletal_bones] += model->num_bones;
+               r_refdef.stats[r_stat_animcache_skeletal_maxbones] = max(r_refdef.stats[r_stat_animcache_skeletal_maxbones], model->num_bones);
                ent->animcache_skeletaltransform3x4 = (float *)R_FrameData_Alloc(sizeof(float[3][4]) * model->num_bones);
                boneposerelative = ent->animcache_skeletaltransform3x4;
                if (skeleton && !skeleton->relativetransforms)
@@ -4758,6 +4764,9 @@ qboolean R_AnimCache_GetEntity(entity_render_t *ent, qboolean wantnormals, qbool
                                }
                                model->AnimateVertices(model, ent->frameblend, ent->skeleton, NULL, wantnormals ? ent->animcache_normal3f : NULL, wanttangents ? ent->animcache_svector3f : NULL, wanttangents ? ent->animcache_tvector3f : NULL);
                                R_AnimCache_UpdateEntityMeshBuffers(ent, model->surfmesh.num_vertices);
+                               r_refdef.stats[r_stat_animcache_shade_count] += 1;
+                               r_refdef.stats[r_stat_animcache_shade_vertices] += numvertices;
+                               r_refdef.stats[r_stat_animcache_shade_maxvertices] = max(r_refdef.stats[r_stat_animcache_shade_maxvertices], numvertices);
                        }
                }
        }
@@ -4796,6 +4805,15 @@ qboolean R_AnimCache_GetEntity(entity_render_t *ent, qboolean wantnormals, qbool
                }
                model->AnimateVertices(model, ent->frameblend, ent->skeleton, ent->animcache_vertex3f, ent->animcache_normal3f, ent->animcache_svector3f, ent->animcache_tvector3f);
                R_AnimCache_UpdateEntityMeshBuffers(ent, model->surfmesh.num_vertices);
+               if (wantnormals || wanttangents)
+               {
+                       r_refdef.stats[r_stat_animcache_shade_count] += 1;
+                       r_refdef.stats[r_stat_animcache_shade_vertices] += numvertices;
+                       r_refdef.stats[r_stat_animcache_shade_maxvertices] = max(r_refdef.stats[r_stat_animcache_shade_maxvertices], numvertices);
+               }
+               r_refdef.stats[r_stat_animcache_shape_count] += 1;
+               r_refdef.stats[r_stat_animcache_shape_vertices] += numvertices;
+               r_refdef.stats[r_stat_animcache_shape_maxvertices] = max(r_refdef.stats[r_stat_animcache_shape_maxvertices], numvertices);
        }
        return true;
 }
@@ -5082,7 +5100,7 @@ static void R_DrawModels(void)
                if (!r_refdef.viewcache.entityvisible[i])
                        continue;
                ent = r_refdef.scene.entities[i];
-               r_refdef.stats.entities++;
+               r_refdef.stats[r_stat_entities]++;
                /*
                if (ent->model && !strncmp(ent->model->name, "models/proto_", 13))
                {
@@ -6343,14 +6361,14 @@ static void R_Bloom_MakeTexture(void)
        rtexture_t *intex;
        float colorscale = r_bloom_colorscale.value;
 
-       r_refdef.stats.bloom++;
+       r_refdef.stats[r_stat_bloom]++;
     
 #if 0
     // this copy is unnecessary since it happens in R_BlendView already
        if (!r_fb.fbo)
        {
                R_Mesh_CopyToTexture(r_fb.colortexture, 0, 0, r_refdef.view.viewport.x, r_refdef.view.viewport.y, r_refdef.view.viewport.width, r_refdef.view.viewport.height);
-               r_refdef.stats.bloom_copypixels += r_refdef.view.viewport.width * r_refdef.view.viewport.height;
+               r_refdef.stats[r_stat_bloom_copypixels] += r_refdef.view.viewport.width * r_refdef.view.viewport.height;
        }
 #endif
 
@@ -6382,14 +6400,14 @@ static void R_Bloom_MakeTexture(void)
        // TODO: do boxfilter scale-down in shader?
        R_SetupShader_Generic(r_fb.colortexture, NULL, GL_MODULATE, 1, false, true, true);
        R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
-       r_refdef.stats.bloom_drawpixels += r_fb.bloomwidth * r_fb.bloomheight;
+       r_refdef.stats[r_stat_bloom_drawpixels] += r_fb.bloomwidth * r_fb.bloomheight;
 
        // we now have a properly scaled bloom image
        if (!r_fb.bloomfbo[r_fb.bloomindex])
        {
                // copy it into the bloom texture
                R_Mesh_CopyToTexture(r_fb.bloomtexture[r_fb.bloomindex], 0, 0, r_fb.bloomviewport.x, r_fb.bloomviewport.y, r_fb.bloomviewport.width, r_fb.bloomviewport.height);
-               r_refdef.stats.bloom_copypixels += r_fb.bloomviewport.width * r_fb.bloomviewport.height;
+               r_refdef.stats[r_stat_bloom_copypixels] += r_fb.bloomviewport.width * r_fb.bloomviewport.height;
        }
 
        // multiply bloom image by itself as many times as desired
@@ -6415,13 +6433,13 @@ static void R_Bloom_MakeTexture(void)
                R_Mesh_PrepareVertices_Generic_Arrays(4, r_screenvertex3f, NULL, r_fb.bloomtexcoord2f);
                R_SetupShader_Generic(intex, NULL, GL_MODULATE, 1, false, true, false);
                R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
-               r_refdef.stats.bloom_drawpixels += r_fb.bloomwidth * r_fb.bloomheight;
+               r_refdef.stats[r_stat_bloom_drawpixels] += r_fb.bloomwidth * r_fb.bloomheight;
 
                if (!r_fb.bloomfbo[r_fb.bloomindex])
                {
                        // copy the darkened image to a texture
                        R_Mesh_CopyToTexture(r_fb.bloomtexture[r_fb.bloomindex], 0, 0, r_fb.bloomviewport.x, r_fb.bloomviewport.y, r_fb.bloomviewport.width, r_fb.bloomviewport.height);
-                       r_refdef.stats.bloom_copypixels += r_fb.bloomviewport.width * r_fb.bloomviewport.height;
+                       r_refdef.stats[r_stat_bloom_copypixels] += r_fb.bloomviewport.width * r_fb.bloomviewport.height;
                }
        }
 
@@ -6467,7 +6485,7 @@ static void R_Bloom_MakeTexture(void)
                        GL_Color(r, r, r, 1);
                        R_Mesh_PrepareVertices_Generic_Arrays(4, r_screenvertex3f, NULL, r_fb.offsettexcoord2f);
                        R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
-                       r_refdef.stats.bloom_drawpixels += r_fb.bloomwidth * r_fb.bloomheight;
+                       r_refdef.stats[r_stat_bloom_drawpixels] += r_fb.bloomwidth * r_fb.bloomheight;
                        GL_BlendFunc(GL_ONE, GL_ONE);
                }
 
@@ -6475,7 +6493,7 @@ static void R_Bloom_MakeTexture(void)
                {
                        // copy the vertically or horizontally blurred bloom view to a texture
                        R_Mesh_CopyToTexture(r_fb.bloomtexture[r_fb.bloomindex], 0, 0, r_fb.bloomviewport.x, r_fb.bloomviewport.y, r_fb.bloomviewport.width, r_fb.bloomviewport.height);
-                       r_refdef.stats.bloom_copypixels += r_fb.bloomviewport.width * r_fb.bloomviewport.height;
+                       r_refdef.stats[r_stat_bloom_copypixels] += r_fb.bloomviewport.width * r_fb.bloomviewport.height;
                }
        }
 }
@@ -6507,7 +6525,7 @@ static void R_BlendView(int fbo, rtexture_t *depthtexture, rtexture_t *colortext
                        if (!r_fb.fbo)
                        {
                                R_Mesh_CopyToTexture(r_fb.colortexture, 0, 0, r_refdef.view.viewport.x, r_refdef.view.viewport.y, r_refdef.view.viewport.width, r_refdef.view.viewport.height);
-                               r_refdef.stats.bloom_copypixels += r_refdef.view.viewport.width * r_refdef.view.viewport.height;
+                               r_refdef.stats[r_stat_bloom_copypixels] += r_refdef.view.viewport.width * r_refdef.view.viewport.height;
                        }
 
                        if(!R_Stereo_Active() && (r_motionblur.value > 0 || r_damageblur.value > 0) && r_fb.ghosttexture)
@@ -6573,7 +6591,7 @@ static void R_BlendView(int fbo, rtexture_t *depthtexture, rtexture_t *colortext
                                        }
                                        R_SetupShader_Generic(r_fb.ghosttexture, NULL, GL_MODULATE, 1, false, true, true);
                                        R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
-                                       r_refdef.stats.bloom_drawpixels += r_refdef.view.viewport.width * r_refdef.view.viewport.height;
+                                       r_refdef.stats[r_stat_bloom_drawpixels] += r_refdef.view.viewport.width * r_refdef.view.viewport.height;
                                }
 
                                // updates old view angles for next pass
@@ -6581,7 +6599,7 @@ static void R_BlendView(int fbo, rtexture_t *depthtexture, rtexture_t *colortext
 
                                // copy view into the ghost texture
                                R_Mesh_CopyToTexture(r_fb.ghosttexture, 0, 0, r_refdef.view.viewport.x, r_refdef.view.viewport.y, r_refdef.view.viewport.width, r_refdef.view.viewport.height);
-                               r_refdef.stats.bloom_copypixels += r_refdef.view.viewport.width * r_refdef.view.viewport.height;
+                               r_refdef.stats[r_stat_bloom_copypixels] += r_refdef.view.viewport.width * r_refdef.view.viewport.height;
                                r_fb.ghosttexture_valid = true;
                        }
                }
@@ -6689,7 +6707,7 @@ static void R_BlendView(int fbo, rtexture_t *depthtexture, rtexture_t *colortext
                        break;
                }
                R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
-               r_refdef.stats.bloom_drawpixels += r_refdef.view.width * r_refdef.view.height;
+               r_refdef.stats[r_stat_bloom_drawpixels] += r_refdef.view.width * r_refdef.view.height;
                break;
        case RENDERPATH_GL11:
        case RENDERPATH_GL13:
@@ -7124,7 +7142,7 @@ void R_RenderScene(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture)
        if (r_timereport_active)
                R_TimeReport("beginscene");
 
-       r_refdef.stats.renders++;
+       r_refdef.stats[r_stat_renders]++;
 
        R_UpdateFog();
 
@@ -8713,6 +8731,7 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
        int surfacefirstvertex;
        int surfaceendvertex;
        int surfacenumvertices;
+       int batchnumsurfaces = texturenumsurfaces;
        int batchnumvertices;
        int batchnumtriangles;
        int needsupdate;
@@ -8754,6 +8773,13 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
                batchnumtriangles += surfacenumtriangles;
        }
 
+       r_refdef.stats[r_stat_batch_batches]++;
+       if (gaps)
+               r_refdef.stats[r_stat_batch_withgaps]++;
+       r_refdef.stats[r_stat_batch_surfaces] += batchnumsurfaces;
+       r_refdef.stats[r_stat_batch_vertices] += batchnumvertices;
+       r_refdef.stats[r_stat_batch_triangles] += batchnumtriangles;
+
        // we now know the vertex range used, and if there are any gaps in it
        rsurface.batchfirstvertex = firstvertex;
        rsurface.batchnumvertices = endvertex - firstvertex;
@@ -8769,11 +8795,27 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
 
        // a cvar to force the dynamic vertex path to be taken, for debugging
        if (r_batch_debugdynamicvertexpath.integer)
+       {
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_cvar] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_cvar] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_cvar] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_cvar] += batchnumtriangles;
+               }
                dynamicvertex = true;
+       }
 
        // if there is a chance of animated vertex colors, it's a dynamic batch
        if ((batchneed & (BATCHNEED_VERTEXMESH_VERTEXCOLOR | BATCHNEED_ARRAY_VERTEXCOLOR)) && texturesurfacelist[0]->lightmapinfo)
        {
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_lightmapvertex] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_lightmapvertex] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_lightmapvertex] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_lightmapvertex] += batchnumtriangles;
+               }
                dynamicvertex = true;
                needsupdate |= BATCHNEED_VERTEXMESH_VERTEXCOLOR;
        }
@@ -8795,16 +8837,37 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
                case Q3DEFORM_NONE:
                        break;
                case Q3DEFORM_AUTOSPRITE:
+                       if (!dynamicvertex)
+                       {
+                               r_refdef.stats[r_stat_batch_dynamic_batches_because_deformvertexes_autosprite] += 1;
+                               r_refdef.stats[r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite] += batchnumsurfaces;
+                               r_refdef.stats[r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite] += batchnumvertices;
+                               r_refdef.stats[r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite] += batchnumtriangles;
+                       }
                        dynamicvertex = true;
                        batchneed |= BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_ARRAY_VECTOR | BATCHNEED_ARRAY_TEXCOORD;
                        needsupdate |= BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR;
                        break;
                case Q3DEFORM_AUTOSPRITE2:
+                       if (!dynamicvertex)
+                       {
+                               r_refdef.stats[r_stat_batch_dynamic_batches_because_deformvertexes_autosprite2] += 1;
+                               r_refdef.stats[r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite2] += batchnumsurfaces;
+                               r_refdef.stats[r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite2] += batchnumvertices;
+                               r_refdef.stats[r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite2] += batchnumtriangles;
+                       }
                        dynamicvertex = true;
                        batchneed |= BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_TEXCOORD;
                        needsupdate |= BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR;
                        break;
                case Q3DEFORM_NORMAL:
+                       if (!dynamicvertex)
+                       {
+                               r_refdef.stats[r_stat_batch_dynamic_batches_because_deformvertexes_normal] += 1;
+                               r_refdef.stats[r_stat_batch_dynamic_surfaces_because_deformvertexes_normal] += batchnumsurfaces;
+                               r_refdef.stats[r_stat_batch_dynamic_vertices_because_deformvertexes_normal] += batchnumvertices;
+                               r_refdef.stats[r_stat_batch_dynamic_triangles_because_deformvertexes_normal] += batchnumtriangles;
+                       }
                        dynamicvertex = true;
                        batchneed |= BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_ARRAY_TEXCOORD;
                        needsupdate |= BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR;
@@ -8812,11 +8875,25 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
                case Q3DEFORM_WAVE:
                        if(!R_TestQ3WaveFunc(deform->wavefunc, deform->waveparms))
                                break; // if wavefunc is a nop, ignore this transform
+                       if (!dynamicvertex)
+                       {
+                               r_refdef.stats[r_stat_batch_dynamic_batches_because_deformvertexes_wave] += 1;
+                               r_refdef.stats[r_stat_batch_dynamic_surfaces_because_deformvertexes_wave] += batchnumsurfaces;
+                               r_refdef.stats[r_stat_batch_dynamic_vertices_because_deformvertexes_wave] += batchnumvertices;
+                               r_refdef.stats[r_stat_batch_dynamic_triangles_because_deformvertexes_wave] += batchnumtriangles;
+                       }
                        dynamicvertex = true;
                        batchneed |= BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_ARRAY_TEXCOORD;
                        needsupdate |= BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR;
                        break;
                case Q3DEFORM_BULGE:
+                       if (!dynamicvertex)
+                       {
+                               r_refdef.stats[r_stat_batch_dynamic_batches_because_deformvertexes_bulge] += 1;
+                               r_refdef.stats[r_stat_batch_dynamic_surfaces_because_deformvertexes_bulge] += batchnumsurfaces;
+                               r_refdef.stats[r_stat_batch_dynamic_vertices_because_deformvertexes_bulge] += batchnumvertices;
+                               r_refdef.stats[r_stat_batch_dynamic_triangles_because_deformvertexes_bulge] += batchnumtriangles;
+                       }
                        dynamicvertex = true;
                        batchneed |= BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_ARRAY_TEXCOORD;
                        needsupdate |= BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR;
@@ -8824,6 +8901,13 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
                case Q3DEFORM_MOVE:
                        if(!R_TestQ3WaveFunc(deform->wavefunc, deform->waveparms))
                                break; // if wavefunc is a nop, ignore this transform
+                       if (!dynamicvertex)
+                       {
+                               r_refdef.stats[r_stat_batch_dynamic_batches_because_deformvertexes_move] += 1;
+                               r_refdef.stats[r_stat_batch_dynamic_surfaces_because_deformvertexes_move] += batchnumsurfaces;
+                               r_refdef.stats[r_stat_batch_dynamic_vertices_because_deformvertexes_move] += batchnumvertices;
+                               r_refdef.stats[r_stat_batch_dynamic_triangles_because_deformvertexes_move] += batchnumtriangles;
+                       }
                        dynamicvertex = true;
                        batchneed |= BATCHNEED_ARRAY_VERTEX;
                        needsupdate |= BATCHNEED_VERTEXMESH_VERTEX;
@@ -8836,16 +8920,37 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
        case Q3TCGEN_TEXTURE:
                break;
        case Q3TCGEN_LIGHTMAP:
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_tcgen_lightmap] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_tcgen_lightmap] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_tcgen_lightmap] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_tcgen_lightmap] += batchnumtriangles;
+               }
                dynamicvertex = true;
                batchneed |= BATCHNEED_ARRAY_LIGHTMAP;
                needsupdate |= BATCHNEED_VERTEXMESH_LIGHTMAP;
                break;
        case Q3TCGEN_VECTOR:
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_tcgen_vector] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_tcgen_vector] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_tcgen_vector] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_tcgen_vector] += batchnumtriangles;
+               }
                dynamicvertex = true;
                batchneed |= BATCHNEED_ARRAY_VERTEX;
                needsupdate |= BATCHNEED_VERTEXMESH_TEXCOORD;
                break;
        case Q3TCGEN_ENVIRONMENT:
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_tcgen_environment] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_tcgen_environment] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_tcgen_environment] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_tcgen_environment] += batchnumtriangles;
+               }
                dynamicvertex = true;
                batchneed |= BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL;
                needsupdate |= BATCHNEED_VERTEXMESH_TEXCOORD;
@@ -8853,6 +8958,13 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
        }
        if (rsurface.texture->tcmods[0].tcmod == Q3TCMOD_TURBULENT)
        {
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_tcmod_turbulent] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_tcmod_turbulent] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_tcmod_turbulent] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_tcmod_turbulent] += batchnumtriangles;
+               }
                dynamicvertex = true;
                batchneed |= BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_TEXCOORD;
                needsupdate |= BATCHNEED_VERTEXMESH_TEXCOORD;
@@ -8860,6 +8972,13 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
 
        if (!rsurface.modelvertexmesh && (batchneed & (BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR | BATCHNEED_VERTEXMESH_VERTEXCOLOR | BATCHNEED_VERTEXMESH_TEXCOORD | BATCHNEED_VERTEXMESH_LIGHTMAP)))
        {
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_interleavedarrays] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_interleavedarrays] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_interleavedarrays] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_interleavedarrays] += batchnumtriangles;
+               }
                dynamicvertex = true;
                needsupdate |= (batchneed & (BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR | BATCHNEED_VERTEXMESH_VERTEXCOLOR | BATCHNEED_VERTEXMESH_TEXCOORD | BATCHNEED_VERTEXMESH_LIGHTMAP));
        }
@@ -8873,7 +8992,16 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
        // firstvertex = 0 and endvertex = numvertices (no gaps, no firstvertex),
        // we ensure this by treating the vertex batch as dynamic...
        if ((batchneed & BATCHNEED_NOGAPS) && (gaps || firstvertex > 0))
+       {
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_nogaps] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_nogaps] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_nogaps] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_nogaps] += batchnumtriangles;
+               }
                dynamicvertex = true;
+       }
 
        if (dynamicvertex)
        {
@@ -8889,11 +9017,29 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
 
        // if needsupdate, we have to do a dynamic vertex batch for sure
        if (needsupdate & batchneed)
+       {
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_derived] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_derived] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_derived] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_derived] += batchnumtriangles;
+               }
                dynamicvertex = true;
+       }
 
        // see if we need to build vertexmesh from arrays
        if (!rsurface.modelvertexmesh && (batchneed & (BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR | BATCHNEED_VERTEXMESH_VERTEXCOLOR | BATCHNEED_VERTEXMESH_TEXCOORD | BATCHNEED_VERTEXMESH_LIGHTMAP)))
+       {
+               if (!dynamicvertex)
+               {
+                       r_refdef.stats[r_stat_batch_dynamic_batches_because_interleavedarrays] += 1;
+                       r_refdef.stats[r_stat_batch_dynamic_surfaces_because_interleavedarrays] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_dynamic_vertices_because_interleavedarrays] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_dynamic_triangles_because_interleavedarrays] += batchnumtriangles;
+               }
                dynamicvertex = true;
+       }
 
        // if we're going to have to apply the skeletal transform manually, we need to batch the skeletal data
        if (dynamicvertex && rsurface.entityskeletaltransform3x4)
@@ -8964,6 +9110,10 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
                // otherwise use the original static buffer with an appropriate offset
                if (gaps)
                {
+                       r_refdef.stats[r_stat_batch_copytriangles_batches] += 1;
+                       r_refdef.stats[r_stat_batch_copytriangles_surfaces] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_copytriangles_vertices] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_copytriangles_triangles] += batchnumtriangles;
                        if ((batchneed & BATCHNEED_ALLOWMULTIDRAW) && r_batch_multidraw.integer && batchnumtriangles >= r_batch_multidraw_mintriangles.integer)
                        {
                                rsurface.batchmultidraw = true;
@@ -8995,6 +9145,13 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
                                        rsurface.batchelement3s[i] = rsurface.batchelement3i[i];
                        }
                }
+               else
+               {
+                       r_refdef.stats[r_stat_batch_fast_batches] += 1;
+                       r_refdef.stats[r_stat_batch_fast_surfaces] += batchnumsurfaces;
+                       r_refdef.stats[r_stat_batch_fast_vertices] += batchnumvertices;
+                       r_refdef.stats[r_stat_batch_fast_triangles] += batchnumtriangles;
+               }
                return;
        }
 
@@ -9002,6 +9159,10 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
        // we only directly handle separate array data in this case and then
        // generate interleaved data if needed...
        rsurface.batchgeneratedvertex = true;
+       r_refdef.stats[r_stat_batch_dynamic_batches] += 1;
+       r_refdef.stats[r_stat_batch_dynamic_surfaces] += batchnumsurfaces;
+       r_refdef.stats[r_stat_batch_dynamic_vertices] += batchnumvertices;
+       r_refdef.stats[r_stat_batch_dynamic_triangles] += batchnumtriangles;
 
        // now copy the vertex data into a combined array and make an index array
        // (this is what Quake3 does all the time)
@@ -9179,6 +9340,10 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const
                float w[4];
                float m[3][4], n[3][4];
                float tp[3], ts[3], tt[3], tn[3];
+               r_refdef.stats[r_stat_batch_dynamicskeletal_batches] += 1;
+               r_refdef.stats[r_stat_batch_dynamicskeletal_surfaces] += batchnumsurfaces;
+               r_refdef.stats[r_stat_batch_dynamicskeletal_vertices] += batchnumvertices;
+               r_refdef.stats[r_stat_batch_dynamicskeletal_triangles] += batchnumtriangles;
                si = rsurface.batchskeletalindex4ub;
                sw = rsurface.batchskeletalweight4ub;
                vp = rsurface.batchvertex3f;
@@ -11714,7 +11879,7 @@ static void R_DrawModelDecals_Entity(entity_render_t *ent)
 
        if (numtris > 0)
        {
-               r_refdef.stats.drawndecals += numtris;
+               r_refdef.stats[r_stat_drawndecals] += numtris;
 
                // now render the decals all at once
                // (this assumes they all use one particle font texture!)
@@ -11752,7 +11917,7 @@ static void R_DrawModelDecals(void)
        for (i = 0;i < r_refdef.scene.numentities;i++)
                numdecals += r_refdef.scene.entities[i]->decalsystem.numdecals;
 
-       r_refdef.stats.totaldecals += numdecals;
+       r_refdef.stats[r_stat_totaldecals] += numdecals;
 
        if (r_showsurfaces.integer)
                return;
@@ -12072,9 +12237,9 @@ void R_DrawWorldSurfaces(qboolean skysurfaces, qboolean writedepth, qboolean dep
        // add to stats if desired
        if (r_speeds.integer && !skysurfaces && !depthonly)
        {
-               r_refdef.stats.world_surfaces += numsurfacelist;
+               r_refdef.stats[r_stat_world_surfaces] += numsurfacelist;
                for (j = 0;j < numsurfacelist;j++)
-                       r_refdef.stats.world_triangles += r_surfacelist[j]->num_triangles;
+                       r_refdef.stats[r_stat_world_triangles] += r_surfacelist[j]->num_triangles;
        }
 
        rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
@@ -12208,9 +12373,9 @@ void R_DrawModelSurfaces(entity_render_t *ent, qboolean skysurfaces, qboolean wr
        // add to stats if desired
        if (r_speeds.integer && !skysurfaces && !depthonly)
        {
-               r_refdef.stats.entities_surfaces += numsurfacelist;
+               r_refdef.stats[r_stat_entities_surfaces] += numsurfacelist;
                for (j = 0;j < numsurfacelist;j++)
-                       r_refdef.stats.entities_triangles += r_surfacelist[j]->num_triangles;
+                       r_refdef.stats[r_stat_entities_triangles] += r_surfacelist[j]->num_triangles;
        }
 
        rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
index d99aea9..98c3649 100644 (file)
@@ -53,8 +53,8 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
        size = smax*tmax;
        size3 = size*3;
 
-       r_refdef.stats.lightmapupdatepixels += size;
-       r_refdef.stats.lightmapupdates++;
+       r_refdef.stats[r_stat_lightmapupdatepixels] += size;
+       r_refdef.stats[r_stat_lightmapupdates]++;
 
        if (cl.buildlightmapmemorysize < size*sizeof(int[3]))
        {
@@ -446,7 +446,7 @@ void R_View_WorldVisibility(qboolean forcenovis)
                        // if leaf is in current pvs and on the screen, mark its surfaces
                        if (CHECKPVSBIT(r_refdef.viewcache.world_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
                        {
-                               r_refdef.stats.world_leafs++;
+                               r_refdef.stats[r_stat_world_leafs]++;
                                r_refdef.viewcache.world_leafvisible[j] = true;
                                if (leaf->numleafsurfaces)
                                        for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
@@ -486,7 +486,7 @@ void R_View_WorldVisibility(qboolean forcenovis)
                                // if leaf is in current pvs and on the screen, mark its surfaces
                                if (!R_CullBox(leaf->mins, leaf->maxs))
                                {
-                                       r_refdef.stats.world_leafs++;
+                                       r_refdef.stats[r_stat_world_leafs]++;
                                        r_refdef.viewcache.world_leafvisible[j] = true;
                                        if (leaf->numleafsurfaces)
                                                for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
@@ -509,7 +509,7 @@ void R_View_WorldVisibility(qboolean forcenovis)
                                // if leaf is in current pvs and on the screen, mark its surfaces
                                if (CHECKPVSBIT(r_refdef.viewcache.world_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
                                {
-                                       r_refdef.stats.world_leafs++;
+                                       r_refdef.stats[r_stat_world_leafs]++;
                                        r_refdef.viewcache.world_leafvisible[j] = true;
                                        if (leaf->numleafsurfaces)
                                                for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
@@ -540,7 +540,7 @@ void R_View_WorldVisibility(qboolean forcenovis)
                                        continue;
                                if (leaf->clusterindex < 0)
                                        continue;
-                               r_refdef.stats.world_leafs++;
+                               r_refdef.stats[r_stat_world_leafs]++;
                                r_refdef.viewcache.world_leafvisible[leaf - model->brush.data_leafs] = true;
                                // mark any surfaces bounding this leaf
                                if (leaf->numleafsurfaces)
@@ -555,7 +555,7 @@ void R_View_WorldVisibility(qboolean forcenovis)
                                // (the first two checks won't cause as many cache misses as the leaf checks)
                                for (p = leaf->portals;p;p = p->next)
                                {
-                                       r_refdef.stats.world_portals++;
+                                       r_refdef.stats[r_stat_world_portals]++;
                                        if (DotProduct(r_refdef.view.origin, p->plane.normal) < (p->plane.dist + 1)
                                         && !r_refdef.viewcache.world_leafvisible[p->past - model->brush.data_leafs]
                                         && CHECKPVSBIT(r_refdef.viewcache.world_pvsbits, p->past->clusterindex)
@@ -1403,8 +1403,8 @@ void R_Q1BSP_DrawShadowMap(int side, entity_render_t *ent, const vec3_t relative
                        continue;
                if (!BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs))
                        continue;
-               r_refdef.stats.lights_dynamicshadowtriangles += surface->num_triangles;
-               r_refdef.stats.lights_shadowtriangles += surface->num_triangles;
+               r_refdef.stats[r_stat_lights_dynamicshadowtriangles] += surface->num_triangles;
+               r_refdef.stats[r_stat_lights_shadowtriangles] += surface->num_triangles;
                batchsurfacelist[0] = surface;
                batchnumsurfaces = 1;
                while(++modelsurfacelistindex < modelnumsurfaces && batchnumsurfaces < RSURF_MAX_BATCHSURFACES)
@@ -1416,8 +1416,8 @@ void R_Q1BSP_DrawShadowMap(int side, entity_render_t *ent, const vec3_t relative
                                break;
                        if (!BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs))
                                continue;
-                       r_refdef.stats.lights_dynamicshadowtriangles += surface->num_triangles;
-                       r_refdef.stats.lights_shadowtriangles += surface->num_triangles;
+                       r_refdef.stats[r_stat_lights_dynamicshadowtriangles] += surface->num_triangles;
+                       r_refdef.stats[r_stat_lights_shadowtriangles] += surface->num_triangles;
                        batchsurfacelist[batchnumsurfaces++] = surface;
                }
                --modelsurfacelistindex;
diff --git a/host.c b/host.c
index a8c8bf2..f4be51c 100644 (file)
--- a/host.c
+++ b/host.c
@@ -925,7 +925,7 @@ void Host_Main(void)
                {
                        R_TimeReport("---");
                        Collision_Cache_NewFrame();
-                       R_TimeReport("collisioncache");
+                       R_TimeReport("photoncache");
                        // decide the simulation time
                        if (cls.capturevideo.active)
                        {
index f0c23bf..1884285 100644 (file)
@@ -1396,8 +1396,8 @@ void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f,
                        tris = R_Shadow_ConstructShadowVolume_ZPass(numverts, numtris, elements, neighbors, invertex3f, &outverts, shadowelements, shadowvertex3f, projectorigin, projectdirection, projectdistance, nummarktris, marktris);
                else
                        tris = R_Shadow_ConstructShadowVolume_ZFail(numverts, numtris, elements, neighbors, invertex3f, &outverts, shadowelements, shadowvertex3f, projectorigin, projectdirection, projectdistance, nummarktris, marktris);
-               r_refdef.stats.lights_dynamicshadowtriangles += tris;
-               r_refdef.stats.lights_shadowtriangles += tris;
+               r_refdef.stats[r_stat_lights_dynamicshadowtriangles] += tris;
+               r_refdef.stats[r_stat_lights_shadowtriangles] += tris;
                if (r_shadow_rendermode == R_SHADOW_RENDERMODE_ZPASS_STENCIL)
                {
                        // increment stencil if frontface is infront of depthbuffer
@@ -2063,7 +2063,7 @@ void R_Shadow_RenderMode_Reset(void)
 void R_Shadow_ClearStencil(void)
 {
        GL_Clear(GL_STENCIL_BUFFER_BIT, NULL, 1.0f, 128);
-       r_refdef.stats.lights_clears++;
+       r_refdef.stats[r_stat_lights_clears]++;
 }
 
 void R_Shadow_RenderMode_StencilShadowVolumes(qboolean zpass)
@@ -2694,8 +2694,8 @@ void R_Shadow_UpdateBounceGridTexture(void)
                radius = rtlight->radius * settings.lightradiusscale;
                s = settings.particleintensity / shootparticles;
                VectorScale(rtlight->photoncolor, s, baseshotcolor);
-               r_refdef.stats.bouncegrid_lights++;
-               r_refdef.stats.bouncegrid_particles += shootparticles;
+               r_refdef.stats[r_stat_bouncegrid_lights]++;
+               r_refdef.stats[r_stat_bouncegrid_particles] += shootparticles;
                for (shotparticles = 0;shotparticles < shootparticles;shotparticles++)
                {
                        if (settings.stablerandom > 0)
@@ -2709,7 +2709,7 @@ void R_Shadow_UpdateBounceGridTexture(void)
                        VectorMA(clipstart, radius, clipend, clipend);
                        for (bouncecount = 0;;bouncecount++)
                        {
-                               r_refdef.stats.bouncegrid_traces++;
+                               r_refdef.stats[r_stat_bouncegrid_traces]++;
                                //r_refdef.scene.worldmodel->TraceLineAgainstSurfaces(r_refdef.scene.worldmodel, NULL, NULL, &cliptrace, clipstart, clipend, hitsupercontentsmask);
                                //r_refdef.scene.worldmodel->TraceLine(r_refdef.scene.worldmodel, NULL, NULL, &cliptrace2, clipstart, clipend, hitsupercontentsmask);
                                if (settings.staticmode)
@@ -2775,7 +2775,7 @@ void R_Shadow_UpdateBounceGridTexture(void)
                                        VectorMA(clipstart, 0.5f, stepdelta, steppos);
                                        for (step = 0;step < numsteps;step++)
                                        {
-                                               r_refdef.stats.bouncegrid_splats++;
+                                               r_refdef.stats[r_stat_bouncegrid_splats]++;
                                                // figure out which texture pixel this is in
                                                texlerp[1][0] = ((steppos[0] - mins[0]) * ispacing[0]) - 0.5f;
                                                texlerp[1][1] = ((steppos[1] - mins[1]) * ispacing[1]) - 0.5f;
@@ -2829,7 +2829,7 @@ void R_Shadow_UpdateBounceGridTexture(void)
                                }
                                if (cliptrace.fraction >= 1.0f)
                                        break;
-                               r_refdef.stats.bouncegrid_hits++;
+                               r_refdef.stats[r_stat_bouncegrid_hits]++;
                                if (bouncecount >= maxbounce)
                                        break;
                                // scale down shot color by bounce intensity and texture color (or 50% if no texture reported)
@@ -2845,7 +2845,7 @@ void R_Shadow_UpdateBounceGridTexture(void)
                                VectorMultiply(shotcolor, surfcolor, shotcolor);
                                if (VectorLength2(baseshotcolor) == 0.0f)
                                        break;
-                               r_refdef.stats.bouncegrid_bounces++;
+                               r_refdef.stats[r_stat_bouncegrid_bounces]++;
                                if (settings.bounceanglediffuse)
                                {
                                        // random direction, primarily along plane normal
@@ -2991,7 +2991,7 @@ qboolean R_Shadow_ScissorForBBox(const float *mins, const float *maxs)
        || r_shadow_lightscissor[1] != r_refdef.view.viewport.y
        || r_shadow_lightscissor[2] != r_refdef.view.viewport.width
        || r_shadow_lightscissor[3] != r_refdef.view.viewport.height)
-               r_refdef.stats.lights_scissored++;
+               r_refdef.stats[r_stat_lights_scissored]++;
        return false;
 }
 
@@ -3764,7 +3764,7 @@ static void R_Shadow_DrawWorldShadow_ShadowMap(int numsurfaces, int *surfacelist
                {
                        if (!mesh->sidetotals[r_shadow_shadowmapside])
                                continue;
-                       r_refdef.stats.lights_shadowtriangles += mesh->sidetotals[r_shadow_shadowmapside];
+                       r_refdef.stats[r_stat_lights_shadowtriangles] += mesh->sidetotals[r_shadow_shadowmapside];
                        if (mesh->vertex3fbuffer)
                                R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vertex3fbuffer);
                        else
@@ -3804,7 +3804,7 @@ static void R_Shadow_DrawWorldShadow_ShadowVolume(int numsurfaces, int *surfacel
                mesh = zpass ? rsurface.rtlight->static_meshchain_shadow_zpass : rsurface.rtlight->static_meshchain_shadow_zfail;
                for (;mesh;mesh = mesh->next)
                {
-                       r_refdef.stats.lights_shadowtriangles += mesh->numtriangles;
+                       r_refdef.stats[r_stat_lights_shadowtriangles] += mesh->numtriangles;
                        if (mesh->vertex3fbuffer)
                                R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vertex3fbuffer);
                        else
@@ -4129,7 +4129,7 @@ static void R_Shadow_PrepareLight(rtlight_t *rtlight)
                return;
 
        // count this light in the r_speeds
-       r_refdef.stats.lights++;
+       r_refdef.stats[r_stat_lights]++;
 
        // flag it as worth drawing later
        rtlight->draw = true;