]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
add DeviceLost and DeviceRestored functions to R_Modules system
[xonotic/darkplaces.git] / gl_draw.c
index faa0c9180fa473a5c06bff3972f696c096a06831..4fdee6f4d80f2bb58ed8c2eaf284c2177158f39e 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -317,13 +317,21 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        fs_offset_t lmpsize;
        unsigned char *lmpdata;
        char lmpname[MAX_QPATH];
+       int texflags;
+
+       texflags = TEXF_ALPHA;
+       if (!(cachepicflags & CACHEPICFLAG_NOCLAMP))
+               texflags |= TEXF_CLAMP;
+       if (!(cachepicflags & CACHEPICFLAG_NOCOMPRESSION) && gl_texturecompression_2d.integer)
+               texflags |= TEXF_COMPRESS;
 
        // check whether the picture has already been cached
        crc = CRC_Block((unsigned char *)path, strlen(path));
        hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
        for (pic = cachepichash[hashkey];pic;pic = pic->chain)
                if (!strcmp (path, pic->name))
-                       return pic;
+                       if(pic->texflags == texflags)
+                               return pic;
 
        if (numcachepics == MAX_CACHED_PICS)
        {
@@ -347,18 +355,13 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                return pic;
        }
 
-       pic->texflags = TEXF_ALPHA;
-       if (!(cachepicflags & CACHEPICFLAG_NOCLAMP))
-               pic->texflags |= TEXF_CLAMP;
-       if (!(cachepicflags & CACHEPICFLAG_NOCOMPRESSION) && gl_texturecompression_2d.integer)
-               pic->texflags |= TEXF_COMPRESS;
-
+       pic->texflags = texflags;
        pic->autoload = (cachepicflags & CACHEPICFLAG_NOTPERSISTENT);
 
        // load a high quality image from disk if possible
-       pixels = loadimagepixelsbgra(path, false, true, r_texture_convertsRGB_2d.integer, NULL);
+       pixels = loadimagepixelsbgra(path, false, true, r_texture_convertsRGB_2d.integer != 0, NULL);
        if (pixels == NULL && !strncmp(path, "gfx/", 4))
-               pixels = loadimagepixelsbgra(path+4, false, true, r_texture_convertsRGB_2d.integer, NULL);
+               pixels = loadimagepixelsbgra(path+4, false, true, r_texture_convertsRGB_2d.integer != 0, NULL);
        if (pixels)
        {
                pic->width = image_width;
@@ -444,9 +447,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);
+               pic->tex = loadtextureimage(drawtexturepool, pic->name, false, pic->texflags, true, r_texture_convertsRGB_2d.integer != 0);
                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);
+                       pic->tex = loadtextureimage(drawtexturepool, pic->name+4, false, pic->texflags, true, r_texture_convertsRGB_2d.integer != 0);
                if (pic->tex == NULL)
                        pic->tex = draw_generatepic(pic->name, true);
        }
@@ -715,7 +718,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 = Mem_Realloc(fonts_mempool, dp_fonts.f, sizeof(dp_font_t) * dp_fonts.maxsize);
+               dp_fonts.f = (dp_font_t *)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];
@@ -935,7 +938,7 @@ void GL_Draw_Init (void)
        // allocate fonts storage
        fonts_mempool = Mem_AllocPool("FONTS", 0, NULL);
        dp_fonts.maxsize = MAX_FONTS;
-       dp_fonts.f = Mem_Alloc(fonts_mempool, sizeof(dp_font_t) * dp_fonts.maxsize);
+       dp_fonts.f = (dp_font_t *)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
@@ -953,7 +956,7 @@ void GL_Draw_Init (void)
                        dpsnprintf(FONT_USER(i)->title, sizeof(FONT_USER(i)->title), "user%d", j++);
 
        Cmd_AddCommand ("loadfont",LoadFont_f, "loadfont function tganame loads a font; example: loadfont console gfx/veramono; loadfont without arguments lists the available functions");
-       R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap);
+       R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap, NULL, NULL);
 }
 
 void _DrawQ_Setup(void)
@@ -980,10 +983,13 @@ void _DrawQ_Setup(void)
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 }
 
+qboolean r_draw2d_force = false;
 static void _DrawQ_ProcessDrawFlag(int flags)
 {
        _DrawQ_Setup();
        CHECKGLERROR
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
        if(flags == DRAWFLAG_ADDITIVE)
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
        else if(flags == DRAWFLAG_MODULATE)
@@ -1001,6 +1007,8 @@ void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, flo
        float floats[36];
 
        _DrawQ_ProcessDrawFlag(flags);
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
 
        R_Mesh_ResetTextureState();
        floats[12] = 0.0f;floats[13] = 0.0f;
@@ -1056,6 +1064,8 @@ void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height,
        float cosar = cos(ar);
 
        _DrawQ_ProcessDrawFlag(flags);
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
 
        R_Mesh_ResetTextureState();
        if (pic)
@@ -1105,6 +1115,8 @@ void DrawQ_Fill(float x, float y, float width, float height, float red, float gr
        float floats[36];
 
        _DrawQ_ProcessDrawFlag(flags);
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
 
        R_Mesh_ResetTextureState();
        R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
@@ -1428,6 +1440,8 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                maxlen = 1<<30;
 
        _DrawQ_ProcessDrawFlag(flags);
+       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_ResetTextureState();
        if (!fontmap)
@@ -1770,6 +1784,8 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
        float floats[36];
 
        _DrawQ_ProcessDrawFlag(flags);
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
 
        R_Mesh_ResetTextureState();
        if (pic)
@@ -1804,6 +1820,8 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
 void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags)
 {
        _DrawQ_ProcessDrawFlag(flags);
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
 
        R_Mesh_ResetTextureState();
        R_SetupShader_Generic(mesh->texture, NULL, GL_MODULATE, 1);
@@ -1817,6 +1835,8 @@ void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)
        int num;
 
        _DrawQ_ProcessDrawFlag(flags);
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
 
        GL_Color(1,1,1,1);
        CHECKGLERROR
@@ -1835,6 +1855,8 @@ void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)
 void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, float g, float b, float alpha, int flags)
 {
        _DrawQ_ProcessDrawFlag(flags);
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
 
        R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);