]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
render shownetgraph much faster by drawing an entire batch of lines at a
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 13 Nov 2010 09:03:09 +0000 (09:03 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 13 Nov 2010 09:03:09 +0000 (09:03 +0000)
time

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

cl_screen.c
draw.h
gl_draw.c

index 58ea65227de4f9d2e495598016b885697c00b1d5..f3f75c1c858bc4085a25282594552e664914f524 100644 (file)
@@ -219,12 +219,16 @@ void SCR_CheckDrawCenterString (void)
 void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth, int graphheight, float graphscale, const char *label, float textsize, int packetcounter, netgraphitem_t *netgraph)
 {
        netgraphitem_t *graph;
-       int j, x, y;
+       int j, x, y, numlines;
        int totalbytes = 0;
        char bytesstring[128];
        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;
        DrawQ_Fill(graphx, graphy, graphwidth, graphheight + textsize * 2, 0, 0, 0, 0.5, 0);
        // draw the bar graph itself
        // advance the packet counter because it is the latest packet column being
@@ -260,18 +264,34 @@ void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth, int gra
                g[j][5] = bound(0.0f, g[j][5], 1.0f);
        }
        // render the lines for the graph
+       numlines = 0;
+       v = vertex3f;
+       c = color4f;
        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;
-               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[2], graphx + graphwidth * b[0], graphy + graphheight * b[2], 1.0f, 1.0f, 0.0f, 1.0f, 0);
-               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[1], graphx + graphwidth * b[0], graphy + graphheight * b[1], 1.0f, 0.0f, 0.0f, 1.0f, 0);
-               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[5], graphx + graphwidth * b[0], graphy + graphheight * b[5], 0.0f, 1.0f, 0.0f, 1.0f, 0);
-               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[4], graphx + graphwidth * b[0], graphy + graphheight * b[4], 1.0f, 1.0f, 1.0f, 1.0f, 0);
-               DrawQ_Line(0.0f, graphx + graphwidth * a[0], graphy + graphheight * a[3], graphx + graphwidth * b[0], graphy + graphheight * b[3], 1.0f, 0.5f, 0.0f, 1.0f, 0);
+               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, 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, 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, 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, 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;
+
+               numlines += 5;
        }
+       if (numlines > 0)
+               DrawQ_Lines(0.0f, numlines, vertex3f, color4f, 0);
        x = graphx;
        y = graphy + graphheight;
        dpsnprintf(bytesstring, sizeof(bytesstring), "%i", totalbytes);
diff --git a/draw.h b/draw.h
index cd220ce03a1ebef6a38d8edb522906dcfdecfeb3..317a0f76fde0a8c6748ac0cd8cd2538dd809f4f0 100644 (file)
--- a/draw.h
+++ b/draw.h
@@ -178,6 +178,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 line loop
 void DrawQ_LineLoop(drawqueuemesh_t *mesh, int flags);
 // resets r_refdef.draw2dstage
index 7fec01f1943baacbd0b028d2158cd41c5be61868..55bb59d9f14a9f9a85946d84e93e88023072d3fe 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -1980,6 +1980,47 @@ 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)
+{
+       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)
+               return;
+
+       switch(vid.renderpath)
+       {
+       case RENDERPATH_GL11:
+       case RENDERPATH_GL13:
+       case RENDERPATH_GL20:
+       case RENDERPATH_CGGL:
+               CHECKGLERROR
+
+               R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
+
+               //qglLineWidth(width);CHECKGLERROR
+
+               CHECKGLERROR
+               R_Mesh_PrepareVertices_Generic_Arrays(numlines*2, vertex3f, color4f, NULL);
+               qglDrawArrays(GL_LINES, 0, numlines*2);
+               CHECKGLERROR
+               break;
+       case RENDERPATH_D3D9:
+               //Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       case RENDERPATH_D3D10:
+               Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       case RENDERPATH_D3D11:
+               Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       }
+}
+
 void DrawQ_SetClipArea(float x, float y, float width, float height)
 {
        int ix, iy, iw, ih;