]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
colors for DrawQ_Mesh are now float rather than byte, and vertices are padded to...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 17 Sep 2002 21:25:51 +0000 (21:25 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 17 Sep 2002 21:25:51 +0000 (21:25 +0000)
R_DrawQueue conversion to R_Mesh is getting closer to done

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

cl_screen.c
cl_screen.h
cl_video.c
gl_draw.c

index 8dc3839135acdd300dd4bb4896e7e4fc8d1b4dab..9d5ca6289982a2c06715a2eb172683483d8c16eb 100644 (file)
@@ -581,7 +581,7 @@ void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags)
        size = sizeof(*dq);
        size += sizeof(drawqueuemesh_t);
        size += sizeof(int) * mesh->numindices;
-       size += sizeof(float[3]) * mesh->numvertices;
+       size += sizeof(float[4]) * mesh->numvertices;
        size += sizeof(float[2]) * mesh->numvertices;
        size += sizeof(float[4]) * mesh->numvertices;
        if (r_refdef.drawqueuesize + size > r_refdef.maxdrawqueuesize)
@@ -601,7 +601,7 @@ void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags)
        m->numvertices = mesh->numvertices;
        m->texture = mesh->texture;
        m->indices   = p;memcpy(m->indices  , mesh->indices  , m->numindices  * sizeof(int     ));(qbyte *)p += m->numindices  * sizeof(int     );
-       m->vertices  = p;memcpy(m->vertices , mesh->vertices , m->numvertices * sizeof(float[3]));(qbyte *)p += m->numvertices * sizeof(float[3]);
+       m->vertices  = p;memcpy(m->vertices , mesh->vertices , m->numvertices * sizeof(float[4]));(qbyte *)p += m->numvertices * sizeof(float[4]);
        m->texcoords = p;memcpy(m->texcoords, mesh->texcoords, m->numvertices * sizeof(float[2]));(qbyte *)p += m->numvertices * sizeof(float[2]);
        m->colors    = p;memcpy(m->colors   , mesh->colors   , m->numvertices * sizeof(float[4]));(qbyte *)p += m->numvertices * sizeof(float[4]);
        r_refdef.drawqueuesize += dq->size;
index da063b8d8e24694604049e34eaf421de39a4ca58..f54d99a9a4546d5445998c649f4d6e62b6d11157 100644 (file)
@@ -17,6 +17,9 @@ typedef struct drawqueue_s
 drawqueue_t;
 
 // a triangle mesh... embedded in the drawqueue
+// each vertex is 4 floats (3 are used)
+// each texcoord pair is 2 floats
+// each color is 4 floats
 typedef struct drawqueuemesh_s
 {
        rtexture_t *texture;
@@ -25,7 +28,7 @@ typedef struct drawqueuemesh_s
        int *indices;
        float *vertices;
        float *texcoords;
-       qbyte *colors;
+       float *colors;
 }
 drawqueuemesh_t;
 
index 1afbb87fb8c468e96bb3c272afc00d5716703859..58f367f4a60fcc2bb5a0c2403d062c8be5c7e9c1 100644 (file)
@@ -91,9 +91,9 @@ void CL_DrawVideo(void)
        {
                drawqueuemesh_t mesh;
                int indices[6];
-               float vertices[12];
+               float vertices[16];
                float texcoords[8];
-               qbyte colorsb[16];
+               float colorsf[16];
                float s1, t1, s2, t2, x1, y1, x2, y2;
                indices[0] = 0;
                indices[1] = 1;
@@ -105,50 +105,23 @@ void CL_DrawVideo(void)
                y1 = 0;
                x2 = vid.conwidth;
                y2 = vid.conheight;
-               vertices[0] = y1;
-               vertices[1] = y1;
-               vertices[2] = 0;
-               vertices[3] = x2;
-               vertices[4] = y1;
-               vertices[5] = 0;
-               vertices[6] = x2;
-               vertices[7] = y2;
-               vertices[8] = 0;
-               vertices[9] = x1;
-               vertices[10] = y2;
-               vertices[11] = 0;
                R_FragmentLocation(cl_videotexture, NULL, NULL, &s1, &t1, &s2, &t2);
-               texcoords[0] = s1;
-               texcoords[1] = t1;
-               texcoords[2] = s2;
-               texcoords[3] = t1;
-               texcoords[4] = s2;
-               texcoords[5] = t2;
-               texcoords[6] = s1;
-               texcoords[7] = t2;
-               colorsb[0] = 255 >> v_overbrightbits.integer;
-               colorsb[1] = 255 >> v_overbrightbits.integer;
-               colorsb[2] = 255 >> v_overbrightbits.integer;
-               colorsb[3] = 255;
-               colorsb[4] = 255 >> v_overbrightbits.integer;
-               colorsb[5] = 255 >> v_overbrightbits.integer;
-               colorsb[6] = 255 >> v_overbrightbits.integer;
-               colorsb[7] = 255;
-               colorsb[8] = 255 >> v_overbrightbits.integer;
-               colorsb[9] = 255 >> v_overbrightbits.integer;
-               colorsb[10] = 255 >> v_overbrightbits.integer;
-               colorsb[11] = 255;
-               colorsb[12] = 255 >> v_overbrightbits.integer;
-               colorsb[13] = 255 >> v_overbrightbits.integer;
-               colorsb[14] = 255 >> v_overbrightbits.integer;
-               colorsb[15] = 255;
+               texcoords[0] = s1;texcoords[1] = t1;
+               texcoords[2] = s2;texcoords[3] = t1;
+               texcoords[4] = s2;texcoords[5] = t2;
+               texcoords[6] = s1;texcoords[7] = t2;
+               R_FillColors(colorsf, 4, r_colorscale, r_colorscale, r_colorscale, 1);
+               vertices[ 0] = x1;vertices[ 1] = y1;vertices[ 2] = 0;vertices[ 3] = 0;
+               vertices[ 4] = x2;vertices[ 5] = y1;vertices[ 6] = 0;vertices[ 7] = 0;
+               vertices[ 8] = x2;vertices[ 9] = y2;vertices[10] = 0;vertices[11] = 0;
+               vertices[12] = x1;vertices[13] = y2;vertices[14] = 0;vertices[15] = 0;
                mesh.texture = cl_videotexture;
                mesh.numindices = 6;
                mesh.numvertices = 4;
                mesh.indices = indices;
                mesh.vertices = vertices;
                mesh.texcoords = texcoords;
-               mesh.colors = colorsb;
+               mesh.colors = colorsf;
                DrawQ_Mesh(&mesh, 0);
                //DrawQ_Pic(0, 0, "engine_videoframe", vid.conwidth, vid.conheight, 1, 1, 1, 1, 0);
        }
index 132674f920379a8857f9c03de3cde675f6eb904d..73b3f40f5db31edca85c15b4f62c7bc698b4a193 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -369,7 +369,7 @@ void R_DrawQueue(void)
        cachepic_t *pic;
        drawqueue_t *dq;
        char *str, *currentpic;
-       int batch, batchcount, additive;
+       int batchcount;
        unsigned int color;
        drawqueuemesh_t *mesh;
 
@@ -384,13 +384,10 @@ void R_DrawQueue(void)
 
        chartexnum = R_GetTexture(char_texture);
 
-       additive = false;
-       qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        currentpic = "";
        pic = NULL;
-       qglBindTexture(GL_TEXTURE_2D, 0);
+       texnum = 0;
        color = 0;
-       qglColor4ub(0,0,0,0);
 
        overbright = v_overbrightbits.integer;
        batch = false;
@@ -407,6 +404,7 @@ void R_DrawQueue(void)
                        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
                m.depthdisable = true;
                R_Mesh_MainState(&m);
+
                cr = (float) ((color >> 24) & 0xFF) * (1.0f / 255.0f) * r_colorscale;
                cg = (float) ((color >> 16) & 0xFF) * (1.0f / 255.0f) * r_colorscale;
                cb = (float) ((color >>  8) & 0xFF) * (1.0f / 255.0f) * r_colorscale;
@@ -415,67 +413,42 @@ void R_DrawQueue(void)
                y = dq->y;
                w = dq->scalex;
                h = dq->scaley;
+               
                switch(dq->command)
                {
                case DRAWQUEUE_PIC:
                        str = (char *)(dq + 1);
-                       if (*str)
+                       if (strcmp(str, currentpic))
                        {
-                               if (strcmp(str, currentpic))
+                               if (batch)
                                {
-                                       if (batch)
-                                       {
-                                               batch = false;
-                                               qglEnd();
-                                       }
-                                       currentpic = str;
-                                       pic = Draw_CachePic(str);
-                                       qglBindTexture(GL_TEXTURE_2D, R_GetTexture(pic->tex));
+                                       batch = false;
+                                       qglEnd();
                                }
+                               currentpic = str;
+                               pic = Draw_CachePic(str);
+                               qglBindTexture(GL_TEXTURE_2D, R_GetTexture(pic->tex));
+                       }
+                       if (*str)
+                       {
                                if (w == 0)
                                        w = pic->width;
                                if (h == 0)
                                        h = pic->height;
-                               if (!batch)
-                               {
-                                       batch = true;
-                                       qglBegin(GL_TRIANGLES);
-                                       batchcount = 0;
-                               }
-                               qglTexCoord2f (0, 0);qglVertex2f (x  , y  );
-                               qglTexCoord2f (1, 0);qglVertex2f (x+w, y  );
-                               qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
-                               qglTexCoord2f (0, 0);qglVertex2f (x  , y  );
-                               qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
-                               qglTexCoord2f (0, 1);qglVertex2f (x  , y+h);
-                               batchcount++;
-                       }
-                       else
-                       {
-                               if (currentpic[0])
-                               {
-                                       if (batch)
-                                       {
-                                               batch = false;
-                                               qglEnd();
-                                       }
-                                       currentpic = "";
-                                       qglBindTexture(GL_TEXTURE_2D, 0);
-                               }
-                               if (!batch)
-                               {
-                                       batch = true;
-                                       qglBegin(GL_TRIANGLES);
-                                       batchcount = 0;
-                               }
-                               qglTexCoord2f (0, 0);qglVertex2f (x  , y  );
-                               qglTexCoord2f (1, 0);qglVertex2f (x+w, y  );
-                               qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
-                               qglTexCoord2f (0, 0);qglVertex2f (x  , y  );
-                               qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
-                               qglTexCoord2f (0, 1);qglVertex2f (x  , y+h);
-                               batchcount++;
                        }
+                       varray_color[0] = varray_color[4] = varray_color[ 8] = varray_color[12] = cr;
+                       varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = cg;
+                       varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = cb;
+                       varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = ca;
+                       varray_texcoord[0] = 0;varray_texcoord[1] = 0;
+                       varray_texcoord[2] = 1;varray_texcoord[3] = 0;
+                       varray_texcoord[4] = 1;varray_texcoord[5] = 1;
+                       varray_texcoord[6] = 0;varray_texcoord[7] = 1;
+                       varray_vertex[ 0] = x  ;varray_vertex[ 1] = y  ;varray_vertex[ 2] = 0;
+                       varray_vertex[ 4] = x+w;varray_vertex[ 5] = y  ;varray_vertex[ 6] = 0;
+                       varray_vertex[ 8] = x+w;varray_vertex[ 9] = y+h;varray_vertex[10] = 0;
+                       varray_vertex[12] = x  ;varray_vertex[13] = y+h;varray_vertex[14] = 0;
+                       R_Mesh_Draw(4, 2, polygonelements);
                        break;
                case DRAWQUEUE_STRING:
                        str = (char *)(dq + 1);
@@ -489,12 +462,10 @@ void R_DrawQueue(void)
                                currentpic = "conchars";
                                qglBindTexture(GL_TEXTURE_2D, chartexnum);
                        }
-                       if (!batch)
-                       {
-                               batch = true;
-                               qglBegin(GL_TRIANGLES);
-                               batchcount = 0;
-                       }
+                       batchcount = 0;
+                       ac = varray_color;
+                       at = varray_texcoord;
+                       av = varray_vertex;
                        while ((num = *str++) && x < vid.conwidth)
                        {
                                if (num != ' ')
@@ -503,71 +474,74 @@ void R_DrawQueue(void)
                                        t = (num >> 4)*0.0625f + (0.5f / 256.0f);
                                        u = 0.0625f - (1.0f / 256.0f);
                                        v = 0.0625f - (1.0f / 256.0f);
-                                       qglTexCoord2f (s  , t  );qglVertex2f (x  , y  );
-                                       qglTexCoord2f (s+u, t  );qglVertex2f (x+w, y  );
-                                       qglTexCoord2f (s+u, t+v);qglVertex2f (x+w, y+h);
-                                       qglTexCoord2f (s  , t  );qglVertex2f (x  , y  );
-                                       qglTexCoord2f (s+u, t+v);qglVertex2f (x+w, y+h);
-                                       qglTexCoord2f (s  , t+v);qglVertex2f (x  , y+h);
+                                       ac[0] = ac[4] = ac[ 8] = ac[12] = cr;
+                                       ac[1] = ac[5] = ac[ 9] = ac[13] = cg;
+                                       ac[2] = ac[6] = ac[10] = ac[14] = cb;
+                                       ac[3] = ac[7] = ac[11] = ac[15] = ca;
+                                       at[0] = s  ;at[1] = t  ;
+                                       at[2] = s+u;at[3] = t  ;
+                                       at[4] = s+u;at[5] = t+v;
+                                       at[6] = s  ;at[7] = t+v;
+                                       av[0] = x  ;av[1] = y  ;av[2] = 0;
+                                       av[4] = x+w;av[1] = y  ;av[2] = 0;
+                                       av[8] = x+w;av[1] = y+h;av[2] = 0;
+                                       av[0] = x  ;av[1] = y+h;av[2] = 0;
+                                       ac += 16;
+                                       at += 8;
+                                       av += 16;
                                        batchcount++;
+                                       if (batchcount >= 128)
+                                       {
+                                               R_Mesh_Draw(batchcount * 4, batchcount * 2, polygonelements);
+                                               batchcount = 0;
+                                               ac = varray_color;
+                                               at = varray_texcoord;
+                                               av = varray_vertex;
+                                       }
                                }
                                x += w;
                        }
+                       R_Mesh_Draw(batchcount * 4, batchcount * 2, polygonelements);
                        break;
                case DRAWQUEUE_MESH:
-                       if (batch)
-                       {
-                               batch = false;
-                               qglEnd();
-                       }
-                       
                        mesh = (void *)(dq + 1);
-                       qglBindTexture(GL_TEXTURE_2D, R_GetTexture(mesh->texture));
-                       qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), mesh->vertices);CHECKGLERROR
-                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), mesh->texcoords);CHECKGLERROR
-                       qglColorPointer(4, GL_UNSIGNED_BYTE, sizeof(qbyte[4]), mesh->colors);CHECKGLERROR
-                       qglEnableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
-                       qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
-                       qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR
-                       GL_DrawRangeElements(0, mesh->numvertices, mesh->numindices, mesh->indices);
-                       qglDisableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
-                       qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
-                       qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR
-
-                       // restore color, since it got trashed by using color array
-                       qglColor4ub((qbyte)(((color >> 24) & 0xFF) >> overbright), (qbyte)(((color >> 16) & 0xFF) >> overbright), (qbyte)(((color >> 8) & 0xFF) >> overbright), (qbyte)(color & 0xFF));
-                       CHECKGLERROR
+                       m.tex[0] = R_GetTexture(mesh->texture);
+                       R_Mesh_ResizeCheck(mesh->numvertices);
+                       memcpy(varray_vertex, mesh->vertices, sizeof(float[4]) * mesh->numvertices);
+                       memcpy(varray_texcoord, mesh->texcoords, sizeof(float[2]) * mesh->numvertices);
+                       memcpy(varray_color, mesh->colors, sizeof(float[4]) * mesh->numvertices);
+                       R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->indices);
                        currentpic = "\0";
                        break;
                }
        }
-       if (batch)
-               qglEnd();
-       CHECKGLERROR
 
        if (!v_hwgamma.integer)
        {
-               qglDisable(GL_TEXTURE_2D);
-               CHECKGLERROR
                t = v_contrast.value * (float) (1 << v_overbrightbits.integer);
                if (t >= 1.01f)
                {
-                       qglBlendFunc (GL_DST_COLOR, GL_ONE);
-                       CHECKGLERROR
-                       qglBegin (GL_TRIANGLES);
+                       m.blendfunc1 = GL_DST_COLOR;
+                       m.blendfunc2 = GL_ONE;
+                       m.depthdisable = true;
+                       R_Mesh_State(&m);
                        while (t >= 1.01f)
                        {
-                               num = (int) ((t - 1.0f) * 255.0f);
-                               if (num > 255)
-                                       num = 255;
-                               qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
-                               qglVertex2f (-5000, -5000);
-                               qglVertex2f (10000, -5000);
-                               qglVertex2f (-5000, 10000);
+                               cr = t - 1.0f;
+                               if (cr > 1.0f)
+                                       cr = 1.0f;
+                               varray_color[0] = varray_color[4] = varray_color[ 8] = varray_color[12] = cr;
+                               varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = cr;
+                               varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = cr;
+                               varray_texcoord[0] = 0;varray_texcoord[1] = 0;
+                               varray_texcoord[2] = 0;varray_texcoord[3] = 0;
+                               varray_texcoord[4] = 0;varray_texcoord[5] = 0;
+                               varray_vertex[0] = -5000;varray_vertex[1] = -5000;varray_vertex[2] = 0;
+                               varray_vertex[4] = 10000;varray_vertex[1] = -5000;varray_vertex[2] = 0;
+                               varray_vertex[8] = -5000;varray_vertex[1] = 10000;varray_vertex[2] = 0;
+                               R_Mesh_Draw(3, 1, polygonelements);
                                t *= 0.5;
                        }
-                       qglEnd ();
-                       CHECKGLERROR
                }
                else if (t <= 0.99f)
                {
@@ -803,9 +777,9 @@ void R_DrawQueue(void)
                        
                        mesh = (void *)(dq + 1);
                        qglBindTexture(GL_TEXTURE_2D, R_GetTexture(mesh->texture));
-                       qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), mesh->vertices);CHECKGLERROR
+                       qglVertexPointer(3, GL_FLOAT, sizeof(float[4]), mesh->vertices);CHECKGLERROR
                        qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), mesh->texcoords);CHECKGLERROR
-                       qglColorPointer(4, GL_UNSIGNED_BYTE, sizeof(qbyte[4]), mesh->colors);CHECKGLERROR
+                       qglColorPointer(4, GL_FLOAT, sizeof(float[4]), mesh->colors);CHECKGLERROR
                        qglEnableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
                        qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
                        qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR