]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
fix two types to hopefulyl compile on MSVC
[xonotic/darkplaces.git] / gl_draw.c
index 92aa3b1e3442996d1ff286b9492c1f74d2644cfa..6b5c76222ba1ec9d8d902d0569c82804d64ff059 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -334,7 +334,12 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                        if(!((pic->texflags ^ texflags) & ~(TEXF_COMPRESS))) // ignore TEXF_COMPRESS when comparing, because fallback pics remove the flag
                        {
                                if(!(cachepicflags & CACHEPICFLAG_NOTPERSISTENT))
-                                       pic->autoload = false; // persist it
+                               {
+                                       if(pic->tex)
+                                               pic->autoload = false; // persist it
+                                       else
+                                               goto reload; // load it below, and then persist
+                               }
                                return pic;
                        }
 
@@ -350,6 +355,7 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        pic->chain = cachepichash[hashkey];
        cachepichash[hashkey] = pic;
 
+reload:
        // check whether it is an dynamic texture (if so, we can directly use its texture handler)
        pic->tex = CL_GetDynTexture( path );
        // if so, set the width/height, too
@@ -365,9 +371,9 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        pic->autoload = (cachepicflags & CACHEPICFLAG_NOTPERSISTENT);
 
        // load a high quality image from disk if possible
-       pixels = loadimagepixelsbgra(path, false, true, r_texture_convertsRGB_2d.integer != 0, NULL);
+       pixels = loadimagepixelsbgra(path, false, true, r_texture_convertsRGB_2d.integer, NULL);
        if (pixels == NULL && !strncmp(path, "gfx/", 4))
-               pixels = loadimagepixelsbgra(path+4, false, true, r_texture_convertsRGB_2d.integer != 0, NULL);
+               pixels = loadimagepixelsbgra(path+4, false, true, r_texture_convertsRGB_2d.integer, NULL);
        if (pixels)
        {
                pic->hasalpha = false;
@@ -466,9 +472,9 @@ rtexture_t *Draw_GetPicTexture(cachepic_t *pic)
 {
        if (pic->autoload && !pic->tex)
        {
-               pic->tex = loadtextureimage(drawtexturepool, pic->name, false, pic->texflags, true, r_texture_convertsRGB_2d.integer != 0);
+               pic->tex = loadtextureimage(drawtexturepool, pic->name, false, pic->texflags, true, r_texture_convertsRGB_2d.integer);
                if (pic->tex == NULL && !strncmp(pic->name, "gfx/", 4))
-                       pic->tex = loadtextureimage(drawtexturepool, pic->name+4, false, pic->texflags, true, r_texture_convertsRGB_2d.integer != 0);
+                       pic->tex = loadtextureimage(drawtexturepool, pic->name+4, false, pic->texflags, true, r_texture_convertsRGB_2d.integer);
                if (pic->tex == NULL)
                        pic->tex = draw_generatepic(pic->name, true);
        }
@@ -738,7 +744,7 @@ dp_font_t *FindFont(const char *title, qboolean allocate_new)
                dp_fonts.maxsize = dp_fonts.maxsize + FONTS_EXPAND;
                if (developer_font.integer)
                        Con_Printf("FindFont: enlarging fonts buffer (%i -> %i)\n", i, dp_fonts.maxsize);
-               dp_fonts.f = (dp_font_t *)Mem_Realloc(fonts_mempool, dp_fonts.f, sizeof(dp_font_t) * dp_fonts.maxsize);
+               dp_fonts.f = Mem_Realloc(fonts_mempool, dp_fonts.f, sizeof(dp_font_t) * dp_fonts.maxsize);
                // register a font in first expanded slot
                strlcpy(dp_fonts.f[i].title, title, sizeof(dp_fonts.f[i].title));
                return &dp_fonts.f[i];
@@ -888,10 +894,28 @@ static void LoadFont_f(void)
                                        voffset = atof(Cmd_Argv(i));
                                continue;
                        }
+
+                       if (sizes == -1)
+                               continue; // no slot for other sizes
+
                        // parse one of sizes
                        sz = atof(Cmd_Argv(i));
                        if (sz > 0.001f && sz < 1000.0f) // do not use crap sizes
                        {
+                               // search for duplicated sizes
+                               int j;
+                               for (j=0; j<sizes; j++)
+                                       if (f->req_sizes[j] == sz)
+                                               break;
+                               if (j != sizes)
+                                       continue; // sz already in req_sizes, don't add it again
+
+                               if (sizes == MAX_FONT_SIZES)
+                               {
+                                       Con_Printf("Warning: specified more than %i different font sizes, exceding ones are ignored\n", MAX_FONT_SIZES);
+                                       sizes = -1;
+                                       continue;
+                               }
                                f->req_sizes[sizes] = sz;
                                sizes++;
                        }
@@ -958,7 +982,7 @@ void GL_Draw_Init (void)
        // allocate fonts storage
        fonts_mempool = Mem_AllocPool("FONTS", 0, NULL);
        dp_fonts.maxsize = MAX_FONTS;
-       dp_fonts.f = (dp_font_t *)Mem_Alloc(fonts_mempool, sizeof(dp_font_t) * dp_fonts.maxsize);
+       dp_fonts.f = Mem_Alloc(fonts_mempool, sizeof(dp_font_t) * dp_fonts.maxsize);
        memset(dp_fonts.f, 0, sizeof(dp_font_t) * dp_fonts.maxsize);
 
        // assign starting font names
@@ -1046,21 +1070,16 @@ void DrawQ_ProcessDrawFlag(int flags, qboolean alpha)
 
 void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, float red, float green, float blue, float alpha, int flags)
 {
-       float floats[36];
+       float floats[20];
 
        _DrawQ_SetupAndProcessDrawFlag(flags, pic, alpha);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
+       GL_Color(red, green, blue, alpha);
 
+       R_Mesh_VertexPointer(floats, 0, 0);
+       R_Mesh_ColorPointer(NULL, 0, 0);
        R_Mesh_ResetTextureState();
-       floats[12] = 0.0f;floats[13] = 0.0f;
-       floats[14] = 1.0f;floats[15] = 0.0f;
-       floats[16] = 1.0f;floats[17] = 1.0f;
-       floats[18] = 0.0f;floats[19] = 1.0f;
-       floats[20] = floats[24] = floats[28] = floats[32] = red;
-       floats[21] = floats[25] = floats[29] = floats[33] = green;
-       floats[22] = floats[26] = floats[30] = floats[34] = blue;
-       floats[23] = floats[27] = floats[31] = floats[35] = alpha;
        if (pic)
        {
                if (width == 0)
@@ -1068,8 +1087,14 @@ void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, flo
                if (height == 0)
                        height = pic->height;
                R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1);
-
-#if 0
+               R_Mesh_TexCoordPointer(0, 2, floats + 12, 0, 0);
+
+#if 1
+               floats[12] = 0.0f;floats[13] = 0.0f;
+               floats[14] = 1.0f;floats[15] = 0.0f;
+               floats[16] = 1.0f;floats[17] = 1.0f;
+               floats[18] = 0.0f;floats[19] = 1.0f;
+#else
       // AK07: lets be texel correct on the corners
       {
          float horz_offset = 0.5f / pic->width;
@@ -1091,13 +1116,12 @@ void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, flo
        floats[3] = floats[6] = x + width;
        floats[7] = floats[10] = y + height;
 
-       R_Mesh_PrepareVertices_Generic_Arrays(4, floats, floats + 20, floats + 12);
-       R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+       R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, polygonelement3s, 0, 0);
 }
 
 void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height, float org_x, float org_y, float angle, float red, float green, float blue, float alpha, int flags)
 {
-       float floats[36];
+       float floats[20];
        float af = DEG2RAD(-angle); // forward
        float ar = DEG2RAD(-angle + 90); // right
        float sinaf = sin(af);
@@ -1108,7 +1132,10 @@ void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height,
        _DrawQ_SetupAndProcessDrawFlag(flags, pic, alpha);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
+       GL_Color(red, green, blue, alpha);
 
+       R_Mesh_VertexPointer(floats, 0, 0);
+       R_Mesh_ColorPointer(NULL, 0, 0);
        R_Mesh_ResetTextureState();
        if (pic)
        {
@@ -1117,6 +1144,12 @@ void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height,
                if (height == 0)
                        height = pic->height;
                R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1);
+               R_Mesh_TexCoordPointer(0, 2, floats + 12, 0, 0);
+
+               floats[12] = 0.0f;floats[13] = 0.0f;
+               floats[14] = 1.0f;floats[15] = 0.0f;
+               floats[16] = 1.0f;floats[17] = 1.0f;
+               floats[18] = 0.0f;floats[19] = 1.0f;
        }
        else
                R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
@@ -1139,27 +1172,20 @@ void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height,
        floats[9]  = x - cosaf*org_x + cosar*(height-org_y);
        floats[10] = y - sinaf*org_x + sinar*(height-org_y);
 
-       floats[12] = 0.0f;floats[13] = 0.0f;
-       floats[14] = 1.0f;floats[15] = 0.0f;
-       floats[16] = 1.0f;floats[17] = 1.0f;
-       floats[18] = 0.0f;floats[19] = 1.0f;
-       floats[20] = floats[24] = floats[28] = floats[32] = red;
-       floats[21] = floats[25] = floats[29] = floats[33] = green;
-       floats[22] = floats[26] = floats[30] = floats[34] = blue;
-       floats[23] = floats[27] = floats[31] = floats[35] = alpha;
-
-       R_Mesh_PrepareVertices_Generic_Arrays(4, floats, floats + 20, floats + 12);
-       R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+       R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, polygonelement3s, 0, 0);
 }
 
 void DrawQ_Fill(float x, float y, float width, float height, float red, float green, float blue, float alpha, int flags)
 {
-       float floats[36];
+       float floats[12];
 
        _DrawQ_SetupAndProcessDrawFlag(flags, NULL, alpha);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
+       GL_Color(red, green, blue, alpha);
 
+       R_Mesh_VertexPointer(floats, 0, 0);
+       R_Mesh_ColorPointer(NULL, 0, 0);
        R_Mesh_ResetTextureState();
        R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
 
@@ -1168,17 +1194,8 @@ void DrawQ_Fill(float x, float y, float width, float height, float red, float gr
        floats[1] = floats[4] = y;
        floats[3] = floats[6] = x + width;
        floats[7] = floats[10] = y + height;
-       floats[12] = 0.0f;floats[13] = 0.0f;
-       floats[14] = 1.0f;floats[15] = 0.0f;
-       floats[16] = 1.0f;floats[17] = 1.0f;
-       floats[18] = 0.0f;floats[19] = 1.0f;
-       floats[20] = floats[24] = floats[28] = floats[32] = red;
-       floats[21] = floats[25] = floats[29] = floats[33] = green;
-       floats[22] = floats[26] = floats[30] = floats[34] = blue;
-       floats[23] = floats[27] = floats[31] = floats[35] = alpha;
-
-       R_Mesh_PrepareVertices_Generic_Arrays(4, floats, floats + 20, floats + 12);
-       R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+
+       R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, polygonelement3s, 0, 0);
 }
 
 /// color tag printing
@@ -1485,9 +1502,12 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
        if(!r_draw2d.integer && !r_draw2d_force)
                return startx + DrawQ_TextWidth_UntilWidth_TrackColors_Scale(text, &maxlen, w, h, sw, sh, NULL, ignorecolorcodes, fnt, 1000000000);
 
+       R_Mesh_ColorPointer(color4f, 0, 0);
        R_Mesh_ResetTextureState();
        if (!fontmap)
                R_Mesh_TexBind(0, fnt->tex);
+       R_Mesh_TexCoordPointer(0, 2, texcoord2f, 0, 0);
+       R_Mesh_VertexPointer(vertex3f, 0, 0);
        R_SetupShader_Generic(fnt->tex, NULL, GL_MODULATE, 1);
 
        ac = color4f;
@@ -1617,8 +1637,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                                if (batchcount)
                                                {
                                                        // switching from freetype to non-freetype rendering
-                                                       R_Mesh_PrepareVertices_Generic_Arrays(batchcount * 4, vertex3f, color4f, texcoord2f);
-                                                       R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, NULL, 0, quadelement3s, NULL, 0);
+                                                       R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0);
                                                        batchcount = 0;
                                                        ac = color4f;
                                                        at = texcoord2f;
@@ -1655,8 +1674,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                batchcount++;
                                if (batchcount >= QUADELEMENTS_MAXQUADS)
                                {
-                                       R_Mesh_PrepareVertices_Generic_Arrays(batchcount * 4, vertex3f, color4f, texcoord2f);
-                                       R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, NULL, 0, quadelement3s, NULL, 0);
+                                       R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0);
                                        batchcount = 0;
                                        ac = color4f;
                                        at = texcoord2f;
@@ -1670,8 +1688,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                        if (batchcount)
                                        {
                                                // we need a different character map, render what we currently have:
-                                               R_Mesh_PrepareVertices_Generic_Arrays(batchcount * 4, vertex3f, color4f, texcoord2f);
-                                               R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, NULL, 0, quadelement3s, NULL, 0);
+                                               R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0);
                                                batchcount = 0;
                                                ac = color4f;
                                                at = texcoord2f;
@@ -1730,8 +1747,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                batchcount++;
                                if (batchcount >= QUADELEMENTS_MAXQUADS)
                                {
-                                       R_Mesh_PrepareVertices_Generic_Arrays(batchcount * 4, vertex3f, color4f, texcoord2f);
-                                       R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, NULL, 0, quadelement3s, NULL, 0);
+                                       R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0);
                                        batchcount = 0;
                                        ac = color4f;
                                        at = texcoord2f;
@@ -1749,10 +1765,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                }
        }
        if (batchcount > 0)
-       {
-               R_Mesh_PrepareVertices_Generic_Arrays(batchcount * 4, vertex3f, color4f, texcoord2f);
-               R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, NULL, 0, quadelement3s, NULL, 0);
-       }
+               R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0);
 
        if (outcolor)
                *outcolor = colorindex;
@@ -1829,6 +1842,8 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
+       R_Mesh_VertexPointer(floats, 0, 0);
+       R_Mesh_ColorPointer(floats + 20, 0, 0);
        R_Mesh_ResetTextureState();
        if (pic)
        {
@@ -1837,6 +1852,11 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
                if (height == 0)
                        height = pic->height;
                R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1);
+               R_Mesh_TexCoordPointer(0, 2, floats + 12, 0, 0);
+               floats[12] = s1;floats[13] = t1;
+               floats[14] = s2;floats[15] = t2;
+               floats[16] = s4;floats[17] = t4;
+               floats[18] = s3;floats[19] = t3;
        }
        else
                R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
@@ -1846,17 +1866,12 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
        floats[1] = floats[4] = y;
        floats[3] = floats[6] = x + width;
        floats[7] = floats[10] = y + height;
-       floats[12] = s1;floats[13] = t1;
-       floats[14] = s2;floats[15] = t2;
-       floats[16] = s4;floats[17] = t4;
-       floats[18] = s3;floats[19] = t3;
        floats[20] = r1;floats[21] = g1;floats[22] = b1;floats[23] = a1;
        floats[24] = r2;floats[25] = g2;floats[26] = b2;floats[27] = a2;
        floats[28] = r4;floats[29] = g4;floats[30] = b4;floats[31] = a4;
        floats[32] = r3;floats[33] = g3;floats[34] = b3;floats[35] = a3;
 
-       R_Mesh_PrepareVertices_Generic_Arrays(4, floats, floats + 20, floats + 12);
-       R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+       R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, polygonelement3s, 0, 0);
 }
 
 void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags, qboolean hasalpha)
@@ -1867,11 +1882,13 @@ void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags, qboolean hasalpha)
                return;
        DrawQ_ProcessDrawFlag(flags, hasalpha);
 
+       R_Mesh_VertexPointer(mesh->data_vertex3f, 0, 0);
+       R_Mesh_ColorPointer(mesh->data_color4f, 0, 0);
        R_Mesh_ResetTextureState();
+       R_Mesh_TexCoordPointer(0, 2, mesh->data_texcoord2f, 0, 0);
        R_SetupShader_Generic(mesh->texture, NULL, GL_MODULATE, 1);
 
-       R_Mesh_PrepareVertices_Generic_Arrays(mesh->num_vertices, mesh->data_vertex3f, mesh->data_color4f, mesh->data_texcoord2f);
-       R_Mesh_Draw(0, mesh->num_vertices, 0, mesh->num_triangles, mesh->data_element3i, NULL, 0, mesh->data_element3s, NULL, 0);
+       R_Mesh_Draw(0, mesh->num_vertices, 0, mesh->num_triangles, mesh->data_element3i, mesh->data_element3s, 0, 0);
 }
 
 void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)
@@ -1967,6 +1984,8 @@ void R_DrawGamma(void)
                break;
        }
        // all the blends ignore depth
+       R_Mesh_VertexPointer(blendvertex3f, 0, 0);
+       R_Mesh_ColorPointer(NULL, 0, 0);
        R_Mesh_ResetTextureState();
        R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
        GL_DepthMask(true);
@@ -1986,9 +2005,8 @@ void R_DrawGamma(void)
                GL_BlendFunc(GL_DST_COLOR, GL_ONE);
                while (c[0] >= 1.01f || c[1] >= 1.01f || c[2] >= 1.01f)
                {
-                       GL_Color(c[0] - 1, c[1] - 1, c[2] - 1, 1);
-                       R_Mesh_PrepareVertices_Generic_Arrays(3, blendvertex3f, NULL, NULL);
-                       R_Mesh_Draw(0, 3, 0, 1, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+                       GL_Color(bound(0, c[0] - 1, 1), bound(0, c[1] - 1, 1), bound(0, c[2] - 1, 1), 1);
+                       R_Mesh_Draw(0, 3, 0, 1, polygonelement3i, polygonelement3s, 0, 0);
                        VectorScale(c, 0.5, c);
                }
        }
@@ -2003,9 +2021,8 @@ void R_DrawGamma(void)
        if (c[0] >= 0.01f || c[1] >= 0.01f || c[2] >= 0.01f)
        {
                GL_BlendFunc(GL_ONE, GL_ONE);
-               GL_Color(c[0] - 1, c[1] - 1, c[2] - 1, 1);
-               R_Mesh_PrepareVertices_Generic_Arrays(3, blendvertex3f, NULL, NULL);
-               R_Mesh_Draw(0, 3, 0, 1, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+               GL_Color(c[0], c[1], c[2], 1);
+               R_Mesh_Draw(0, 3, 0, 1, polygonelement3i, polygonelement3s, 0, 0);
        }
 }