]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
added Debug_Polygon functions for testing, these are currently abusing the CSQC polyg...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 28 Jan 2007 02:50:32 +0000 (02:50 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 28 Jan 2007 02:50:32 +0000 (02:50 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6758 d7cf8633-e32d-0410-b094-e92efae38249

client.h
prvm_cmds.c

index dcc8723f0fd3b616b58c80dce4e1390601b36d78..cb69ceac4844036c28f112b8a35a19ac8d176afe 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1187,6 +1187,10 @@ void CL_MoveParticles(void);
 void R_MoveExplosions(void);
 void R_NewExplosion(const vec3_t org);
 
+void Debug_PolygonBegin(const char *picname, int flags, qboolean draw2d, float linewidth);
+void Debug_PolygonVertex(float x, float y, float z, float s, float t, float r, float g, float b, float a);
+void Debug_PolygonEnd(void);
+
 #include "cl_screen.h"
 
 extern qboolean sb_showscores;
index f7c5e7165507385e40741fa80a543c0641bfb262..8d3d415ab1dc239bee5655b5c733a6618c5a59a6 100644 (file)
@@ -3180,14 +3180,114 @@ void VM_R_PolygonEnd (void)
 
 void VM_AddPolygonsToMeshQueue (void)
 {
-       unsigned int i;
+       int i;
        if(!vm_drawpolygons_num)
                return;
-       for(i = 0;i < vm_drawpolygons_num;i++)
-               VM_DrawPolygonCallback(NULL, NULL, i, NULL);
+       R_Mesh_Matrix(&identitymatrix);
+       GL_CullFace(GL_NONE);
+       for(i = 0;i < (int)vm_drawpolygons_num;i++)
+               VM_DrawPolygonCallback(NULL, NULL, 1, &i);
        vm_drawpolygons_num = 0;
 }
 
+void Debug_PolygonBegin(const char *picname, int flags, qboolean draw2d, float linewidth)
+{
+       vm_polygon_t    *p;
+
+       if(!vm_polygons_initialized)
+               VM_InitPolygons();
+       if(vm_polygonbegin)
+       {
+               Con_Printf("Debug_PolygonBegin: called twice without Debug_PolygonEnd after first\n");
+               return;
+       }
+       // limit polygons to a vaguely sane amount, beyond this each one just
+       // replaces the last one
+       vm_drawpolygons_num = min(vm_drawpolygons_num, (1<<20)-1);
+       if(vm_drawpolygons_num >= vm_polygons_num)
+       {
+               p = (vm_polygon_t *)Mem_Alloc(vm_polygons_pool, 2 * vm_polygons_num * sizeof(vm_polygon_t));
+               memset(p, 0, 2 * vm_polygons_num * sizeof(vm_polygon_t));
+               memcpy(p, vm_polygons, vm_polygons_num * sizeof(vm_polygon_t));
+               Mem_Free(vm_polygons);
+               vm_polygons = p;
+               vm_polygons_num *= 2;
+       }
+       p = &vm_polygons[vm_drawpolygons_num];
+       if(picname && picname[0])
+               p->tex = Draw_CachePic(picname, true)->tex;
+       else
+               p->tex = r_texture_white;
+       p->flags = flags;
+       vm_current_vertices = 0;
+       vm_polygonbegin = true;
+       if(draw2d)
+               p->flags |= VM_POLYGON_FL2D;
+       if(linewidth)
+       {
+               p->data[13] = linewidth;        //[515]: linewidth
+               p->flags |= VM_POLYGON_FLLINES;
+       }
+}
+
+void Debug_PolygonVertex(float x, float y, float z, float s, float t, float r, float g, float b, float a)
+{
+       vm_polygon_t    *p;
+
+       if(!vm_polygonbegin)
+       {
+               Con_Printf("Debug_PolygonVertex: Debug_PolygonBegin wasn't called\n");
+               return;
+       }
+
+       p = &vm_polygons[vm_drawpolygons_num];
+       if(vm_current_vertices > 4)
+       {
+               Con_Printf("Debug_PolygonVertex: may have 4 vertices max\n");
+               return;
+       }
+
+       p->data[vm_current_vertices*3]          = x;
+       p->data[1+vm_current_vertices*3]        = y;
+       p->data[2+vm_current_vertices*3]        = z;
+
+       p->data[12+vm_current_vertices*2]       = s;
+       if(!(p->flags & VM_POLYGON_FLLINES))
+               p->data[13+vm_current_vertices*2]       = t;
+
+       p->data[20+vm_current_vertices*4]       = r;
+       p->data[21+vm_current_vertices*4]       = g;
+       p->data[22+vm_current_vertices*4]       = b;
+       p->data[23+vm_current_vertices*4]       = a;
+
+       vm_current_vertices++;
+       if(vm_current_vertices == 4)
+               p->flags |= VM_POLYGON_FL4V;
+       else
+               if(vm_current_vertices == 3)
+                       p->flags |= VM_POLYGON_FL3V;
+}
+
+void Debug_PolygonEnd(void)
+{
+       if(!vm_polygonbegin)
+       {
+               Con_Printf("Debug_PolygonEnd: Debug_PolygonBegin wasn't called\n");
+               return;
+       }
+       vm_polygonbegin = false;
+       if(vm_current_vertices > 2 || (vm_current_vertices >= 2 && vm_polygons[vm_drawpolygons_num].flags & VM_POLYGON_FLLINES))
+       {
+               if(vm_polygons[vm_drawpolygons_num].flags & VM_POLYGON_FL2D)    //[515]: don't use qcpolygons memory if 2D
+                       VM_AddPolygonTo2DScene(&vm_polygons[vm_drawpolygons_num]);
+               else
+                       vm_drawpolygons_num++;
+       }
+       else
+               Con_Printf("Debug_PolygonEnd: %i vertices isn't a good choice\n", vm_current_vertices);
+}
+
+