]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
fix MSVC2008 compilation again
[xonotic/darkplaces.git] / gl_draw.c
index 3161e7fa73ad32bb571fc1290f43f8b19f3e1c92..ec9392de31811c6d44a4ff74223bcdb0dc7c3ee2 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -331,10 +331,15 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
        for (pic = cachepichash[hashkey];pic;pic = pic->chain)
                if (!strcmp (path, pic->name))
-                       if(pic->texflags == texflags)
+                       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
@@ -536,7 +542,7 @@ cachepic_t *Draw_NewPic(const char *picname, int width, int height, int alpha, u
        pic->height = height;
        if (pic->tex)
                R_FreeTexture(pic->tex);
-       pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels_bgra, TEXTYPE_BGRA, (alpha ? TEXF_ALPHA : 0) | TEXF_ALLOWUPDATES, -1, NULL);
+       pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels_bgra, TEXTYPE_BGRA, (alpha ? TEXF_ALPHA : 0), -1, NULL);
        return pic;
 }
 
@@ -715,7 +721,7 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale,
 extern cvar_t developer_font;
 dp_font_t *FindFont(const char *title, qboolean allocate_new)
 {
-       int i;
+       int i, oldsize;
 
        // find font
        for(i = 0; i < dp_fonts.maxsize; ++i)
@@ -734,14 +740,18 @@ dp_font_t *FindFont(const char *title, qboolean allocate_new)
                        }
                }
                // if no any 'free' fonts - expand buffer
-               i = dp_fonts.maxsize;
+               oldsize = dp_fonts.maxsize;
                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);
+                       Con_Printf("FindFont: enlarging fonts buffer (%i -> %i)\n", oldsize, dp_fonts.maxsize);
                dp_fonts.f = (dp_font_t *)Mem_Realloc(fonts_mempool, dp_fonts.f, sizeof(dp_font_t) * dp_fonts.maxsize);
+               // relink ft2 structures
+               for(i = 0; i < oldsize; ++i)
+                       if (dp_fonts.f[i].ft2)
+                               dp_fonts.f[i].ft2->settings = &dp_fonts.f[i].settings;
                // 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];
+               strlcpy(dp_fonts.f[oldsize].title, title, sizeof(dp_fonts.f[oldsize].title));
+               return &dp_fonts.f[oldsize];
        }
        return NULL;
 }
@@ -888,10 +898,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++;
                        }
@@ -982,9 +1010,9 @@ void GL_Draw_Init (void)
 static void _DrawQ_Setup(void)
 {
        r_viewport_t viewport;
-       if (r_refdef.draw2dstage)
+       if (r_refdef.draw2dstage == 1)
                return;
-       r_refdef.draw2dstage = true;
+       r_refdef.draw2dstage = 1;
        CHECKGLERROR
        R_Viewport_InitOrtho(&viewport, &identitymatrix, r_refdef.view.x, vid.height - r_refdef.view.y - r_refdef.view.height, r_refdef.view.width, r_refdef.view.height, 0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100, NULL);
        R_SetViewport(&viewport);
@@ -1975,7 +2003,13 @@ void DrawQ_ResetClipArea(void)
 
 void DrawQ_Finish(void)
 {
-       r_refdef.draw2dstage = false;
+       r_refdef.draw2dstage = 0;
+}
+
+void DrawQ_RecalcView(void)
+{
+       if(r_refdef.draw2dstage)
+               r_refdef.draw2dstage = -1; // next draw call will set viewport etc. again
 }
 
 static float blendvertex3f[9] = {-5000, -5000, 10, 10000, -5000, 10, -5000, 10000, 10};