]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
2D art can now be drawn using vertex pointers
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 26 May 2003 18:58:16 +0000 (18:58 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 26 May 2003 18:58:16 +0000 (18:58 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3051 d7cf8633-e32d-0410-b094-e92efae38249

cl_screen.c
cl_screen.h
gl_draw.c

index ceffda767f343cc228ec50f75c9828e5e93fbd25..11bf55068dcb2f1dac56a2e8043974f09ecb9a2d 100644 (file)
@@ -496,62 +496,7 @@ void DrawQ_Clear(void)
 static int picelements[6] = {0, 1, 2, 0, 2, 3};
 void DrawQ_Pic(float x, float y, char *picname, float width, float height, float red, float green, float blue, float alpha, int flags)
 {
-#if 1
        DrawQ_SuperPic(x,y,picname,width,height,0,0,red,green,blue,alpha,1,0,red,green,blue,alpha,0,1,red,green,blue,alpha,1,1,red,green,blue,alpha,flags);
-#elif 1
-       float floats[48];
-       cachepic_t *pic;
-       drawqueuemesh_t mesh;
-       if (alpha < (1.0f / 255.0f) || !picname || !picname[0])
-               return;
-       pic = Draw_CachePic(picname);
-       if (width == 0)
-               width = pic->width;
-       if (height == 0)
-               height = pic->height;
-       mesh.texture = pic->tex;
-       mesh.numtriangles = 2;
-       mesh.numvertices = 4;
-       mesh.indices = picelements;
-       mesh.vertex3f = floats;
-       mesh.texcoord2f = floats + 16;
-       mesh.color4f = floats + 32;
-       memset(floats, 0, sizeof(floats));
-       mesh.vertex3f[0] = mesh.vertex3f[12] = x;
-       mesh.vertex3f[1] = mesh.vertex3f[5] = y;
-       mesh.vertex3f[4] = mesh.vertex3f[8] = x + width;
-       mesh.vertex3f[9] = mesh.vertex3f[13] = y + height;
-       mesh.texcoord2f[4] = mesh.texcoord2f[8] = mesh.texcoord2f[9] = mesh.texcoord2f[13] = 1;
-       mesh.color4f[0] = mesh.color4f[4] = mesh.color4f[8] = mesh.color4f[12] = red;
-       mesh.color4f[1] = mesh.color4f[5] = mesh.color4f[9] = mesh.color4f[13] = green;
-       mesh.color4f[2] = mesh.color4f[6] = mesh.color4f[10] = mesh.color4f[14] = blue;
-       mesh.color4f[3] = mesh.color4f[7] = mesh.color4f[11] = mesh.color4f[15] = alpha;
-       DrawQ_Mesh (&mesh, flags);
-#else
-       int size;
-       drawqueue_t *dq;
-       if (alpha < (1.0f / 255.0f) || !picname || !picname[0])
-               return;
-       size = sizeof(*dq) + ((strlen(picname) + 1 + 3) & ~3);
-       if (r_refdef.drawqueuesize + size > r_refdef.maxdrawqueuesize)
-               return;
-       red = bound(0, red, 1);
-       green = bound(0, green, 1);
-       blue = bound(0, blue, 1);
-       alpha = bound(0, alpha, 1);
-       dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
-       dq->size = size;
-       dq->command = DRAWQUEUE_PIC;
-       dq->flags = flags;
-       dq->color = ((unsigned int) (red * 255.0f) << 24) | ((unsigned int) (green * 255.0f) << 16) | ((unsigned int) (blue * 255.0f) << 8) | ((unsigned int) (alpha * 255.0f));
-       dq->x = x;
-       dq->y = y;
-       // if these are not zero, they override the pic's size
-       dq->scalex = width;
-       dq->scaley = height;
-       strcpy((char *)(dq + 1), picname);
-       r_refdef.drawqueuesize += dq->size;
-#endif
 }
 
 void DrawQ_String(float x, float y, const char *string, int maxlen, float scalex, float scaley, float red, float green, float blue, float alpha, int flags)
@@ -595,55 +540,7 @@ void DrawQ_String(float x, float y, const char *string, int maxlen, float scalex
 
 void DrawQ_Fill (float x, float y, float w, float h, float red, float green, float blue, float alpha, int flags)
 {
-#if 1
        DrawQ_SuperPic(x,y,NULL,w,h,0,0,red,green,blue,alpha,1,0,red,green,blue,alpha,0,1,red,green,blue,alpha,1,1,red,green,blue,alpha,flags);
-#elif 1
-       float floats[48];
-       drawqueuemesh_t mesh;
-       if (alpha < (1.0f / 255.0f))
-               return;
-       mesh.texture = NULL;
-       mesh.numtriangles = 2;
-       mesh.numvertices = 4;
-       mesh.indices = picelements;
-       mesh.vertex3f = floats;
-       mesh.texcoord2f = floats + 16;
-       mesh.color4f = floats + 32;
-       memset(floats, 0, sizeof(floats));
-       mesh.vertex3f[0] = mesh.vertex3f[12] = x;
-       mesh.vertex3f[1] = mesh.vertex3f[5] = y;
-       mesh.vertex3f[4] = mesh.vertex3f[8] = x + w;
-       mesh.vertex3f[9] = mesh.vertex3f[13] = y + h;
-       mesh.color4f[0] = mesh.color4f[4] = mesh.color4f[8] = mesh.color4f[12] = red;
-       mesh.color4f[1] = mesh.color4f[5] = mesh.color4f[9] = mesh.color4f[13] = green;
-       mesh.color4f[2] = mesh.color4f[6] = mesh.color4f[10] = mesh.color4f[14] = blue;
-       mesh.color4f[3] = mesh.color4f[7] = mesh.color4f[11] = mesh.color4f[15] = alpha;
-       DrawQ_Mesh (&mesh, flags);
-#else
-       int size;
-       drawqueue_t *dq;
-       if (alpha < (1.0f / 255.0f))
-               return;
-       size = sizeof(*dq) + 4;
-       if (r_refdef.drawqueuesize + size > r_refdef.maxdrawqueuesize)
-               return;
-       red = bound(0, red, 1);
-       green = bound(0, green, 1);
-       blue = bound(0, blue, 1);
-       alpha = bound(0, alpha, 1);
-       dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
-       dq->size = size;
-       dq->command = DRAWQUEUE_PIC;
-       dq->flags = flags;
-       dq->color = ((unsigned int) (red * 255.0f) << 24) | ((unsigned int) (green * 255.0f) << 16) | ((unsigned int) (blue * 255.0f) << 8) | ((unsigned int) (alpha * 255.0f));
-       dq->x = x;
-       dq->y = y;
-       dq->scalex = w;
-       dq->scaley = h;
-       // empty pic name
-       *((char *)(dq + 1)) = 0;
-       r_refdef.drawqueuesize += dq->size;
-#endif
 }
 
 void DrawQ_SuperPic(float x, float y, char *picname, float width, float height, float s1, float t1, float r1, float g1, float b1, float a1, float s2, float t2, float r2, float g2, float b2, float a2, float s3, float t3, float r3, float g3, float b3, float a3, float s4, float t4, float r4, float g4, float b4, float a4, int flags)
index 7f1ddb975e367c2361aa86dc9cd9f984aa9fc283..41d462638b68c7ec2ad2d46a3e776d262b0576bc 100644 (file)
@@ -3,9 +3,8 @@
 #define CL_SCREEN_H
 
 // drawqueue stuff for use by client to feed 2D art to renderer
-#define DRAWQUEUE_PIC 0
-#define DRAWQUEUE_STRING 1
-#define DRAWQUEUE_MESH 2
+#define DRAWQUEUE_STRING 0
+#define DRAWQUEUE_MESH 1
 
 typedef struct drawqueue_s
 {
index 8885586b816310ce1155100066ed0d1788db6328..8830e0600c35a15135401f6acd63e164d84819cc 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -377,7 +377,6 @@ void GL_Draw_Init (void)
        R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap);
 }
 
-float blendtexcoord2f[6] = {0, 0, 0, 0, 0, 0};
 float blendvertex3f[9] = {-5000, -5000, 10, 10000, -5000, 10, -5000, 10000, 10};
 
 int quadelements[768];
@@ -442,7 +441,6 @@ void R_DrawQueue(void)
                else
                        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
                m.depthdisable = true;
-               R_Mesh_MainState(&m);
 
                c[0] = (float) ((color >> 24) & 0xFF) * (1.0f / 255.0f) * r_colorscale;
                c[1] = (float) ((color >> 16) & 0xFF) * (1.0f / 255.0f) * r_colorscale;
@@ -455,46 +453,12 @@ void R_DrawQueue(void)
 
                switch(dq->command)
                {
-               case DRAWQUEUE_PIC:
-                       str = (char *)(dq + 1);
-                       if (strcmp(str, currentpic))
-                       {
-                               currentpic = str;
-                               if (*str)
-                               {
-                                       pic = Draw_CachePic(str);
-                                       m.tex[0] = R_GetTexture(pic->tex);
-                               }
-                               else
-                                       m.tex[0] = 0;
-                               R_Mesh_TextureState(&m);
-                       }
-                       if (*str)
-                       {
-                               if (w == 0)
-                                       w = pic->width;
-                               if (h == 0)
-                                       h = pic->height;
-                       }
-                       GL_Color(c[0], c[1], c[2], c[3]);
-                       R_Mesh_GetSpace(4);
-                       varray_texcoord2f[0][0] = 0;varray_texcoord2f[0][1] = 0;
-                       varray_texcoord2f[0][2] = 1;varray_texcoord2f[0][3] = 0;
-                       varray_texcoord2f[0][4] = 1;varray_texcoord2f[0][5] = 1;
-                       varray_texcoord2f[0][6] = 0;varray_texcoord2f[0][7] = 1;
-                       varray_vertex3f[ 0] = x  ;varray_vertex3f[ 1] = y  ;varray_vertex3f[ 2] = 10;
-                       varray_vertex3f[ 3] = x+w;varray_vertex3f[ 4] = y  ;varray_vertex3f[ 5] = 10;
-                       varray_vertex3f[ 6] = x+w;varray_vertex3f[ 7] = y+h;varray_vertex3f[ 8] = 10;
-                       varray_vertex3f[ 9] = x  ;varray_vertex3f[10] = y+h;varray_vertex3f[11] = 10;
-                       R_Mesh_Draw(4, 2, quadelements);
-                       break;
                case DRAWQUEUE_STRING:
                        str = (char *)(dq + 1);
                        if (strcmp("gfx/conchars", currentpic))
                        {
                                currentpic = "gfx/conchars";
                                m.tex[0] = chartexnum;
-                               R_Mesh_TextureState(&m);
                        }
                        batchcount = 0;
                        at = texttexcoords;
@@ -521,9 +485,25 @@ void R_DrawQueue(void)
                                        batchcount++;
                                        if (batchcount >= 128)
                                        {
-                                               R_Mesh_GetSpace(batchcount * 4);
-                                               R_Mesh_CopyVertex3f(textverts, batchcount * 4);
-                                               R_Mesh_CopyTexCoord2f(0, texttexcoords, batchcount * 4);
+                                               if (gl_mesh_copyarrays.integer)
+                                               {
+                                                       m.pointervertexcount = 0;
+                                                       m.pointer_vertex = NULL;
+                                                       m.pointer_texcoord[0] = NULL;
+                                                       m.pointer_color = NULL;
+                                                       R_Mesh_State(&m);
+                                                       R_Mesh_GetSpace(batchcount * 4);
+                                                       R_Mesh_CopyVertex3f(textverts, batchcount * 4);
+                                                       R_Mesh_CopyTexCoord2f(0, texttexcoords, batchcount * 4);
+                                               }
+                                               else
+                                               {
+                                                       m.pointervertexcount = batchcount * 4;
+                                                       m.pointer_vertex = textverts;
+                                                       m.pointer_texcoord[0] = texttexcoords;
+                                                       m.pointer_color = NULL;
+                                                       R_Mesh_State(&m);
+                                               }
                                                R_Mesh_Draw(batchcount * 4, batchcount * 2, quadelements);
                                                batchcount = 0;
                                                at = texttexcoords;
@@ -534,21 +514,52 @@ void R_DrawQueue(void)
                        }
                        if (batchcount > 0)
                        {
-                               R_Mesh_GetSpace(batchcount * 4);
-                               R_Mesh_CopyVertex3f(textverts, batchcount * 4);
-                               R_Mesh_CopyTexCoord2f(0, texttexcoords, batchcount * 4);
+                               if (gl_mesh_copyarrays.integer)
+                               {
+                                       m.pointervertexcount = 0;
+                                       m.pointer_vertex = NULL;
+                                       m.pointer_texcoord[0] = NULL;
+                                       m.pointer_color = NULL;
+                                       R_Mesh_State(&m);
+                                       R_Mesh_GetSpace(batchcount * 4);
+                                       R_Mesh_CopyVertex3f(textverts, batchcount * 4);
+                                       R_Mesh_CopyTexCoord2f(0, texttexcoords, batchcount * 4);
+                               }
+                               else
+                               {
+                                       m.pointervertexcount = batchcount * 4;
+                                       m.pointer_vertex = textverts;
+                                       m.pointer_texcoord[0] = texttexcoords;
+                                       m.pointer_color = NULL;
+                                       R_Mesh_State(&m);
+                               }
                                R_Mesh_Draw(batchcount * 4, batchcount * 2, quadelements);
                        }
                        break;
                case DRAWQUEUE_MESH:
                        mesh = (void *)(dq + 1);
                        m.tex[0] = R_GetTexture(mesh->texture);
-                       R_Mesh_TextureState(&m);
                        GL_UseColorArray();
-                       R_Mesh_GetSpace(mesh->numvertices);
-                       R_Mesh_CopyVertex3f(mesh->vertex3f, mesh->numvertices);
-                       R_Mesh_CopyTexCoord2f(0, mesh->texcoord2f, mesh->numvertices);
-                       R_Mesh_CopyColor4f(mesh->color4f, mesh->numvertices);
+                       if (gl_mesh_copyarrays.integer)
+                       {
+                               m.pointervertexcount = 0;
+                               m.pointer_vertex = NULL;
+                               m.pointer_texcoord[0] = NULL;
+                               m.pointer_color = NULL;
+                               R_Mesh_State(&m);
+                               R_Mesh_GetSpace(mesh->numvertices);
+                               R_Mesh_CopyVertex3f(mesh->vertex3f, mesh->numvertices);
+                               R_Mesh_CopyTexCoord2f(0, mesh->texcoord2f, mesh->numvertices);
+                               R_Mesh_CopyColor4f(mesh->color4f, mesh->numvertices);
+                       }
+                       else
+                       {
+                               m.pointervertexcount = mesh->numvertices;
+                               m.pointer_vertex = mesh->vertex3f;
+                               m.pointer_texcoord[0] = mesh->texcoord2f;
+                               m.pointer_color = mesh->color4f;
+                               R_Mesh_State(&m);
+                       }
                        R_Mesh_Draw(mesh->numvertices, mesh->numtriangles, mesh->element3i);
                        currentpic = "\0";
                        break;
@@ -573,13 +584,21 @@ void R_DrawQueue(void)
                {
                        m.blendfunc1 = GL_DST_COLOR;
                        m.blendfunc2 = GL_ONE;
-                       R_Mesh_State(&m);
-                       while (c[0] >= 1.01f || c[1] >= 1.01f || c[2] >= 1.01f)
+                       if (gl_mesh_copyarrays.integer)
                        {
-                               GL_Color(bound(0, c[0] - 1, 1), bound(0, c[1] - 1, 1), bound(0, c[2] - 1, 1), 1);
+                               R_Mesh_State(&m);
                                R_Mesh_GetSpace(3);
                                R_Mesh_CopyVertex3f(blendvertex3f, 3);
-                               R_Mesh_CopyTexCoord2f(0, blendtexcoord2f, 3);
+                       }
+                       else
+                       {
+                               m.pointervertexcount = 3;
+                               m.pointer_vertex = blendvertex3f;
+                               R_Mesh_State(&m);
+                       }
+                       while (c[0] >= 1.01f || c[1] >= 1.01f || c[2] >= 1.01f)
+                       {
+                               GL_Color(bound(0, c[0] - 1, 1), bound(0, c[1] - 1, 1), bound(0, c[2] - 1, 1), 1);
                                R_Mesh_Draw(3, 1, polygonelements);
                                VectorScale(c, 0.5, c);
                        }
@@ -596,11 +615,21 @@ void R_DrawQueue(void)
                {
                        m.blendfunc1 = GL_ONE;
                        m.blendfunc2 = GL_ONE;
-                       R_Mesh_State(&m);
+                       if (gl_mesh_copyarrays.integer)
+                       {
+                               m.pointervertexcount = 0;
+                               m.pointer_vertex = NULL;
+                               R_Mesh_State(&m);
+                               R_Mesh_GetSpace(3);
+                               R_Mesh_CopyVertex3f(blendvertex3f, 3);
+                       }
+                       else
+                       {
+                               m.pointervertexcount = 3;
+                               m.pointer_vertex = blendvertex3f;
+                               R_Mesh_State(&m);
+                       }
                        GL_Color(c[0], c[1], c[2], 1);
-                       R_Mesh_GetSpace(3);
-                       R_Mesh_CopyVertex3f(blendvertex3f, 3);
-                       R_Mesh_CopyTexCoord2f(0, blendtexcoord2f, 3);
                        R_Mesh_Draw(3, 1, polygonelements);
                }
        }