From: havoc Date: Sun, 28 Jan 2007 02:50:32 +0000 (+0000) Subject: added Debug_Polygon functions for testing, these are currently abusing the CSQC polyg... X-Git-Tag: xonotic-v0.1.0preview~3652 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8113139cb204c7e10f35bb748bc223a6200af2fa;p=xonotic%2Fdarkplaces.git added Debug_Polygon functions for testing, these are currently abusing the CSQC polygon queue and have many stupid limitations which should be cleaned up at some point, but it is now possible to call these to draw things for debugging purposes git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6758 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/client.h b/client.h index dcc8723f..cb69ceac 100644 --- 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; diff --git a/prvm_cmds.c b/prvm_cmds.c index f7c5e716..8d3d415a 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -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); +} + +