]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
implement TEXF_FORCE_RELOAD to reload a pre-existing skinframe
[xonotic/darkplaces.git] / gl_draw.c
index f1a61cff7e2fd744f8ffa3a78870f82b1d47bc0f..86976c858a90ea70221c594a71906397838ce510 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -361,23 +361,31 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                return cachepics; // return the first one
        }
        pic = cachepics + (numcachepics++);
+       memset(pic, 0, sizeof(*pic));
        strlcpy (pic->name, path, sizeof(pic->name));
        // link into list
        pic->chain = cachepichash[hashkey];
        cachepichash[hashkey] = pic;
 
 reload:
+       // TODO why does this crash?
+       if(pic->allow_free_tex && pic->tex)
+               R_PurgeTexture(pic->tex);
+
        // check whether it is an dynamic texture (if so, we can directly use its texture handler)
        pic->flags = cachepicflags;
        pic->tex = CL_GetDynTexture( path );
        // if so, set the width/height, too
        if( pic->tex ) {
+               pic->allow_free_tex = false;
                pic->width = R_TextureWidth(pic->tex);
                pic->height = R_TextureHeight(pic->tex);
                // we're done now (early-out)
                return pic;
        }
 
+       pic->allow_free_tex = true;
+
        pic->hasalpha = true; // assume alpha unless we know it has none
        pic->texflags = texflags;
        pic->autoload = (cachepicflags & CACHEPICFLAG_NOTPERSISTENT);
@@ -413,8 +421,10 @@ reload:
                if (!pic->autoload)
                {
                        pic->tex = R_LoadTexture2D(drawtexturepool, pic->name, image_width, image_height, pixels, vid.sRGB2D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, pic->texflags & (pic->hasalpha ? ~0 : ~TEXF_ALPHA), -1, NULL);
+#ifndef USE_GLES2
                        if (r_texture_dds_save.integer && qglGetCompressedTexImageARB && pic->tex)
                                R_SaveTextureDDSFile(pic->tex, va("dds/%s.dds", pic->name), r_texture_dds_save.integer < 2, pic->hasalpha);
+#endif
                }
        }
        if (!loaded)
@@ -488,6 +498,7 @@ reload:
                pic->tex = draw_generatepic(pic->name, (cachepicflags & CACHEPICFLAG_QUIET) != 0);
                pic->width = R_TextureWidth(pic->tex);
                pic->height = R_TextureHeight(pic->tex);
+               pic->allow_free_tex = (pic->tex != r_texture_notexture);
        }
 
        return pic;
@@ -511,14 +522,18 @@ rtexture_t *Draw_GetPicTexture(cachepic_t *pic)
                if (pic->tex == NULL)
                {
                        pic->tex = loadtextureimage(drawtexturepool, pic->name, false, pic->texflags, true, vid.sRGB2D);
+#ifndef USE_GLES2
                        if (r_texture_dds_save.integer && qglGetCompressedTexImageARB && pic->tex)
                                R_SaveTextureDDSFile(pic->tex, va("dds/%s.dds", pic->name), r_texture_dds_save.integer < 2, pic->hasalpha);
+#endif
                }
                if (pic->tex == NULL && !strncmp(pic->name, "gfx/", 4))
                {
                        pic->tex = loadtextureimage(drawtexturepool, pic->name+4, false, pic->texflags, true, vid.sRGB2D);
+#ifndef USE_GLES2
                        if (r_texture_dds_save.integer && qglGetCompressedTexImageARB && pic->tex)
                                R_SaveTextureDDSFile(pic->tex, va("dds/%s.dds", pic->name), r_texture_dds_save.integer < 2, pic->hasalpha);
+#endif
                }
                if (pic->tex == NULL)
                        pic->tex = draw_generatepic(pic->name, true);
@@ -567,26 +582,24 @@ cachepic_t *Draw_NewPic(const char *picname, int width, int height, int alpha, u
        }
        else
        {
-               if (pic == NULL)
+               if (numcachepics == MAX_CACHED_PICS)
                {
-                       if (numcachepics == MAX_CACHED_PICS)
-                       {
-                               Con_Printf ("Draw_NewPic: numcachepics == MAX_CACHED_PICS\n");
-                               // FIXME: support NULL in callers?
-                               return cachepics; // return the first one
-                       }
-                       pic = cachepics + (numcachepics++);
-                       strlcpy (pic->name, picname, sizeof(pic->name));
-                       // link into list
-                       pic->chain = cachepichash[hashkey];
-                       cachepichash[hashkey] = pic;
+                       Con_Printf ("Draw_NewPic: numcachepics == MAX_CACHED_PICS\n");
+                       // FIXME: support NULL in callers?
+                       return cachepics; // return the first one
                }
+               pic = cachepics + (numcachepics++);
+               memset(pic, 0, sizeof(*pic));
+               strlcpy (pic->name, picname, sizeof(pic->name));
+               // link into list
+               pic->chain = cachepichash[hashkey];
+               cachepichash[hashkey] = pic;
        }
 
        pic->flags = CACHEPICFLAG_NEWPIC; // disable texflags checks in Draw_CachePic
        pic->width = width;
        pic->height = height;
-       if (pic->tex)
+       if (pic->allow_free_tex && pic->tex)
                R_FreeTexture(pic->tex);
        pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels_bgra, TEXTYPE_BGRA, (alpha ? TEXF_ALPHA : 0), -1, NULL);
        return pic;
@@ -1963,6 +1976,7 @@ void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)
        case RENDERPATH_GL11:
        case RENDERPATH_GL13:
        case RENDERPATH_GL20:
+#ifndef USE_GLES2
                CHECKGLERROR
                qglBegin(GL_LINE_LOOP);
                for (num = 0;num < mesh->num_vertices;num++)
@@ -1973,6 +1987,7 @@ void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)
                }
                qglEnd();
                CHECKGLERROR
+#endif
                break;
        case RENDERPATH_D3D9:
                //Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
@@ -2007,6 +2022,7 @@ void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, f
        case RENDERPATH_GL11:
        case RENDERPATH_GL13:
        case RENDERPATH_GL20:
+#ifndef USE_GLES2
                CHECKGLERROR
 
                //qglLineWidth(width);CHECKGLERROR
@@ -2018,6 +2034,7 @@ void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, f
                qglVertex2f(x2, y2);
                qglEnd();
                CHECKGLERROR
+#endif
                break;
        case RENDERPATH_D3D9:
                //Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);