From 589c5ced2d3c01cf9fc15f0302973bbb3a4a1903 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 11 Jan 2006 23:15:12 +0000 Subject: [PATCH] added DrawQ_Line/DrawQ_Lines/DrawQ_LineWidth patch from [515], note: buggy, needs cleanup git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5900 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_screen.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ cl_screen.h | 4 +++ gl_draw.c | 11 ++++++++ glquake.h | 4 +++ vid_shared.c | 8 ++++++ 5 files changed, 107 insertions(+) diff --git a/cl_screen.c b/cl_screen.c index d7baa8b2..3e181fbd 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -758,6 +758,86 @@ void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags) r_refdef.drawqueuesize += dq->size; } +void DrawQ_Lines (drawqueuemesh_t *mesh, int flags) +{ + int size; + void *p; + drawqueue_t *dq; + drawqueuemesh_t *m; + size = sizeof(*dq); + size += sizeof(drawqueuemesh_t); + size += sizeof(int[3]) * mesh->num_triangles; + size += sizeof(float[3]) * mesh->num_vertices; + size += sizeof(float[2]) * mesh->num_vertices; + size += sizeof(float[4]) * mesh->num_vertices; + if (r_refdef.drawqueuesize + size > r_refdef.maxdrawqueuesize) + return; + dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize); + dq->size = size; + dq->command = DRAWQUEUE_LINES; + dq->flags = flags; + dq->color = 0; + dq->x = 0; + dq->y = 0; + dq->scalex = 0; + dq->scaley = 0; + p = (void *)(dq + 1); + m = p;p = (unsigned char*)p + sizeof(drawqueuemesh_t); + m->num_triangles = mesh->num_triangles; + m->num_vertices = mesh->num_vertices; + m->texture = mesh->texture; + m->data_element3i = p;memcpy(m->data_element3i , mesh->data_element3i , m->num_triangles * sizeof(int[3]));p = (unsigned char*)p + m->num_triangles * sizeof(int[3]); + m->data_vertex3f = p;memcpy(m->data_vertex3f , mesh->data_vertex3f , m->num_vertices * sizeof(float[3]));p = (unsigned char*)p + m->num_vertices * sizeof(float[3]); + m->data_texcoord2f = p;memcpy(m->data_texcoord2f, mesh->data_texcoord2f, m->num_vertices * sizeof(float[2]));p = (unsigned char*)p + m->num_vertices * sizeof(float[2]); + m->data_color4f = p;memcpy(m->data_color4f , mesh->data_color4f , m->num_vertices * sizeof(float[4]));p = (unsigned char*)p + m->num_vertices * sizeof(float[4]); + r_refdef.drawqueuesize += dq->size; +} + +//LordHavoc: FIXME: this is nasty! +void DrawQ_LineWidth (float width) +{ + drawqueue_t *dq; + static int linewidth = 1; + if(width == linewidth) + return; + linewidth = width; + if(r_refdef.drawqueuesize + (int)sizeof(*dq) > r_refdef.maxdrawqueuesize) + { + Con_DPrint("DrawQueue full !\n"); + return; + } + dq = (void*) (r_refdef.drawqueue + r_refdef.drawqueuesize); + dq->size = sizeof(*dq); + dq->command = DRAWQUEUE_LINEWIDTH; + dq->x = width; + + r_refdef.drawqueuesize += dq->size; +} + +//[515]: this is old, delete +void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, float g, float b, float alpha, int flags) +{ + drawqueue_t *dq; + if(width > 0) + DrawQ_LineWidth(width); + if(r_refdef.drawqueuesize + (int)sizeof(*dq) > r_refdef.maxdrawqueuesize) + { + Con_DPrint("DrawQueue full !\n"); + return; + } + dq = (void*) (r_refdef.drawqueue + r_refdef.drawqueuesize); + dq->size = sizeof(*dq); + dq->command = DRAWQUEUE_LINES; + dq->x = x1; + dq->y = y1; + dq->scalex = x2; + dq->scaley = y2; + dq->flags = flags; + dq->color = ((unsigned int) (r * 255.0f) << 24) | ((unsigned int) (g * 255.0f) << 16) | ((unsigned int) (b * 255.0f) << 8) | ((unsigned int) (alpha * 255.0f)); + + r_refdef.drawqueuesize += dq->size; +} + void DrawQ_SetClipArea(float x, float y, float width, float height) { drawqueue_t * dq; diff --git a/cl_screen.h b/cl_screen.h index a6bcb352..d58d7642 100644 --- a/cl_screen.h +++ b/cl_screen.h @@ -7,6 +7,8 @@ #define DRAWQUEUE_MESH 1 #define DRAWQUEUE_SETCLIP 2 #define DRAWQUEUE_RESETCLIP 3 +#define DRAWQUEUE_LINEWIDTH 4 +#define DRAWQUEUE_LINES 5 typedef struct drawqueue_s { @@ -64,6 +66,8 @@ void DrawQ_Mesh(drawqueuemesh_t *mesh, int flags); void DrawQ_SetClipArea(float x, float y, float width, float height); // reset the clipping area 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); void SHOWLMP_decodehide(void); void SHOWLMP_decodeshow(void); diff --git a/gl_draw.c b/gl_draw.c index cbeefdcf..40146424 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -657,6 +657,17 @@ void R_DrawQueue(void) case DRAWQUEUE_RESETCLIP: GL_ScissorTest(false); break; + case DRAWQUEUE_LINEWIDTH: + qglLineWidth(x); + break; + case DRAWQUEUE_LINES: + mesh = (drawqueuemesh_t *)(dq + 1); + GL_Color(c[0], c[1], c[2], c[3]); + qglBegin(GL_LINE_LOOP); + for (num = 0;num < mesh->num_vertices;num++) + qglVertex2f(mesh->data_vertex3f[num*3+0], mesh->data_vertex3f[num*3+1]); + qglEnd(); + break; } } diff --git a/glquake.h b/glquake.h index 764fe465..f8066af5 100644 --- a/glquake.h +++ b/glquake.h @@ -495,6 +495,10 @@ extern void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint extern void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units); +//[515]: added on 29.07.2005 +extern void (GLAPIENTRY *qglLineWidth)(GLfloat width); +extern void (GLAPIENTRY *qglPointSize)(GLfloat size); + // GL_ARB_shader_objects extern int gl_support_shader_objects; #ifndef GL_PROGRAM_OBJECT_ARB diff --git a/vid_shared.c b/vid_shared.c index b5cee081..b47348ee 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -248,6 +248,10 @@ void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height); void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units); +//[515]: added on 29.07.2005 +void (GLAPIENTRY *qglLineWidth)(GLfloat width); +void (GLAPIENTRY *qglPointSize)(GLfloat size); + void (GLAPIENTRY *qglActiveStencilFaceEXT)(GLenum); void (GLAPIENTRY *qglDeleteObjectARB)(GLhandleARB obj); @@ -420,6 +424,10 @@ static dllfunction_t opengl110funcs[] = {"glVertex3f", (void **) &qglVertex3f}, {"glBegin", (void **) &qglBegin}, {"glEnd", (void **) &qglEnd}, +//[515]: added on 29.07.2005 + {"glLineWidth", (void**) &qglLineWidth}, + {"glPointSize", (void**) &qglPointSize}, +// {"glMatrixMode", (void **) &qglMatrixMode}, {"glOrtho", (void **) &qglOrtho}, {"glFrustum", (void **) &qglFrustum}, -- 2.39.2