]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
added cvar r_fixtrans_auto to automatically call fixtrans on all textures that are...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 12 Nov 2007 08:21:33 +0000 (08:21 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 12 Nov 2007 08:21:33 +0000 (08:21 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7685 d7cf8633-e32d-0410-b094-e92efae38249

cl_particles.c
gl_draw.c
gl_rmain.c
host_cmd.c
image.c
image.h
model_brush.c
r_lightning.c
r_shadow.c
r_sky.c

index 52509ad2a6242776400f76739066f86a0d7ea9b0..0762614b9a3c68a6ba34e0c744707277817c4e1a 100644 (file)
@@ -1954,7 +1954,7 @@ static void R_InitParticleTexture (void)
        // we invert it again during the blendfunc to make it work...
 
 #ifndef DUMPPARTICLEFONT
-       particlefonttexture = loadtextureimage(particletexturepool, "particles/particlefont.tga", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE);
+       particlefonttexture = loadtextureimage(particletexturepool, "particles/particlefont.tga", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE, true);
        if (!particlefonttexture)
 #endif
        {
@@ -2097,7 +2097,7 @@ static void R_InitParticleTexture (void)
        }
 
 #ifndef DUMPPARTICLEFONT
-       particletexture[tex_beam].texture = loadtextureimage(particletexturepool, "particles/nexbeam.tga", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE);
+       particletexture[tex_beam].texture = loadtextureimage(particletexturepool, "particles/nexbeam.tga", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE, true);
        if (!particletexture[tex_beam].texture)
 #endif
        {
index 2f01464dbeeb48f7bcca3f0d76cabafad61a7db6..b600d6df5df49df6b6a0dfb1573c7f0013c87a85 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -342,11 +342,11 @@ cachepic_t        *Draw_CachePic (const char *path, qboolean persistent)
                flags |= TEXF_CLAMP;
 
        // load a high quality image from disk if possible
-       pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, flags | (gl_texturecompression_2d.integer ? TEXF_COMPRESS : 0));
+       pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, flags | (gl_texturecompression_2d.integer ? TEXF_COMPRESS : 0), true);
        if (pic->tex == NULL && !strncmp(path, "gfx/", 4))
        {
                // compatibility with older versions which did not require gfx/ prefix
-               pic->tex = loadtextureimage(drawtexturepool, path + 4, 0, 0, false, flags | (gl_texturecompression_2d.integer ? TEXF_COMPRESS : 0));
+               pic->tex = loadtextureimage(drawtexturepool, path + 4, 0, 0, false, flags | (gl_texturecompression_2d.integer ? TEXF_COMPRESS : 0), true);
        }
        // if a high quality image was loaded, set the pic's size to match it, just
        // in case there's no low quality version to get the size from
index cbc74a3cb70a95caf6dd6fd55d84897ac803c921..86d9833a8eff4cbddf335ad748541684e2c11e25 100644 (file)
@@ -1524,7 +1524,7 @@ skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qboole
        if (skinframe && skinframe->base)
                return skinframe;
 
-       basepixels = loadimagepixels(name, complain, 0, 0);
+       basepixels = loadimagepixels(name, complain, 0, 0, true);
        if (basepixels == NULL)
                return NULL;
 
@@ -1569,13 +1569,13 @@ skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qboole
        // _norm is the name used by tenebrae and has been adopted as standard
        if (loadnormalmap)
        {
-               if ((pixels = loadimagepixels(va("%s_norm", skinframe->basename), false, 0, 0)) != NULL)
+               if ((pixels = loadimagepixels(va("%s_norm", skinframe->basename), false, 0, 0, false)) != NULL)
                {
                        skinframe->nmap = R_LoadTexture2D (r_main_texturepool, va("%s_nmap", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_normal.integer ? ~0 : ~TEXF_COMPRESS), NULL);
                        Mem_Free(pixels);
                        pixels = NULL;
                }
-               else if (r_shadow_bumpscale_bumpmap.value > 0 && (bumppixels = loadimagepixels(va("%s_bump", skinframe->basename), false, 0, 0)) != NULL)
+               else if (r_shadow_bumpscale_bumpmap.value > 0 && (bumppixels = loadimagepixels(va("%s_bump", skinframe->basename), false, 0, 0, false)) != NULL)
                {
                        pixels = (unsigned char *)Mem_Alloc(tempmempool, image_width * image_height * 4);
                        Image_HeightmapToNormalmap(bumppixels, pixels, image_width, image_height, false, r_shadow_bumpscale_bumpmap.value);
@@ -1594,10 +1594,10 @@ skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qboole
        // _luma is supported for tenebrae compatibility
        // (I think it's a very stupid name, but oh well)
        // _glow is the preferred name
-       if (loadglow          && ((pixels = loadimagepixels(va("%s_glow", skinframe->basename), false, 0, 0)) != NULL || (pixels = loadimagepixels(va("%s_luma", skinframe->basename), false, 0, 0)) != NULL)) {skinframe->glow = R_LoadTexture2D (r_main_texturepool, va("%s_glow", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_glow.integer ? ~0 : ~TEXF_COMPRESS), NULL);Mem_Free(pixels);pixels = NULL;}
-       if (loadgloss         && (pixels = loadimagepixels(va("%s_gloss", skinframe->basename), false, 0, 0)) != NULL) {skinframe->gloss = R_LoadTexture2D (r_main_texturepool, va("%s_gloss", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_gloss.integer ? ~0 : ~TEXF_COMPRESS), NULL);Mem_Free(pixels);pixels = NULL;}
-       if (loadpantsandshirt && (pixels = loadimagepixels(va("%s_pants", skinframe->basename), false, 0, 0)) != NULL) {skinframe->pants = R_LoadTexture2D (r_main_texturepool, va("%s_pants", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_color.integer ? ~0 : ~TEXF_COMPRESS), NULL);Mem_Free(pixels);pixels = NULL;}
-       if (loadpantsandshirt && (pixels = loadimagepixels(va("%s_shirt", skinframe->basename), false, 0, 0)) != NULL) {skinframe->shirt = R_LoadTexture2D (r_main_texturepool, va("%s_shirt", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_color.integer ? ~0 : ~TEXF_COMPRESS), NULL);Mem_Free(pixels);pixels = NULL;}
+       if (loadglow          && ((pixels = loadimagepixels(va("%s_glow", skinframe->basename), false, 0, 0, false)) != NULL || (pixels = loadimagepixels(va("%s_luma", skinframe->basename), false, 0, 0, false)) != NULL)) {skinframe->glow = R_LoadTexture2D (r_main_texturepool, va("%s_glow", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_glow.integer ? ~0 : ~TEXF_COMPRESS), NULL);Mem_Free(pixels);pixels = NULL;}
+       if (loadgloss         && (pixels = loadimagepixels(va("%s_gloss", skinframe->basename), false, 0, 0, false)) != NULL) {skinframe->gloss = R_LoadTexture2D (r_main_texturepool, va("%s_gloss", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_gloss.integer ? ~0 : ~TEXF_COMPRESS), NULL);Mem_Free(pixels);pixels = NULL;}
+       if (loadpantsandshirt && (pixels = loadimagepixels(va("%s_pants", skinframe->basename), false, 0, 0, false)) != NULL) {skinframe->pants = R_LoadTexture2D (r_main_texturepool, va("%s_pants", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_color.integer ? ~0 : ~TEXF_COMPRESS), NULL);Mem_Free(pixels);pixels = NULL;}
+       if (loadpantsandshirt && (pixels = loadimagepixels(va("%s_shirt", skinframe->basename), false, 0, 0, false)) != NULL) {skinframe->shirt = R_LoadTexture2D (r_main_texturepool, va("%s_shirt", skinframe->basename), image_width, image_height, pixels, TEXTYPE_RGBA, skinframe->textureflags & (gl_texturecompression_color.integer ? ~0 : ~TEXF_COMPRESS), NULL);Mem_Free(pixels);pixels = NULL;}
 
        if (basepixels)
                Mem_Free(basepixels);
index 578a2b8745d1d3d2e04296d0b6211bc327958445..706d24d07d8d9a27a2d86e72827b6dd3e32c2505 100644 (file)
@@ -30,6 +30,7 @@ cvar_t rcon_address = {0, "rcon_address", "", "server address to send rcon comma
 cvar_t team = {CVAR_USERINFO | CVAR_SAVE, "team", "none", "QW team (4 character limit, example: blue)"};
 cvar_t skin = {CVAR_USERINFO | CVAR_SAVE, "skin", "", "QW player skin name (example: base)"};
 cvar_t noaim = {CVAR_USERINFO | CVAR_SAVE, "noaim", "1", "QW option to disable vertical autoaim"};
+cvar_t r_fixtrans_auto = {0, "r_fixtrans_auto", "0", "automatically fixtrans textures (when set to 2, it also saves the fixed versions to a fixtrans directory)"};
 qboolean allowcheats = false;
 
 extern qboolean host_shuttingdown;
@@ -2498,6 +2499,7 @@ void Host_InitCommands (void)
        Cmd_AddCommand ("pingplreport", Host_PingPLReport_f, "command sent by server containing client ping and packet loss values for scoreboard, triggered by pings command from client (not used by QW servers)");
 
        Cmd_AddCommand ("fixtrans", Image_FixTransparentPixels_f, "change alpha-zero pixels in an image file to sensible values, and write out a new TGA (warning: SLOW)");
+       Cvar_RegisterVariable (&r_fixtrans_auto);
 
        Cvar_RegisterVariable (&team);
        Cvar_RegisterVariable (&skin);
diff --git a/image.c b/image.c
index 7539acdd95583256cafc53075adec5ea9401e0ea..dd2d159194fff656553ae800f4d0d5e3d1aa9058 100644 (file)
--- a/image.c
+++ b/image.c
@@ -836,7 +836,8 @@ imageformat_t imageformats_other[] =
        {NULL, NULL}
 };
 
-unsigned char *loadimagepixels (const char *filename, qboolean complain, int matchwidth, int matchheight)
+int fixtransparentpixels(unsigned char *data, int w, int h);
+unsigned char *loadimagepixels (const char *filename, qboolean complain, int matchwidth, int matchheight, qboolean allowFixtrans)
 {
        fs_offset_t filesize;
        imageformat_t *firstformat, *format;
@@ -884,6 +885,22 @@ unsigned char *loadimagepixels (const char *filename, qboolean complain, int mat
                                        Con_Printf("loaded image %s (%dx%d)\n", name, image_width, image_height);
                                if (developer_memorydebug.integer)
                                        Mem_CheckSentinelsGlobal();
+                               if(allowFixtrans && r_fixtrans_auto.integer)
+                               {
+                                       int n = fixtransparentpixels(data, image_width, image_height);
+                                       if(n)
+                                       {
+                                               Con_Printf("- had to fix %s (%d pixels changed)\n", name, n);
+                                               if(r_fixtrans_auto.integer >= 2)
+                                               {
+                                                       char outfilename[MAX_QPATH], buf[MAX_QPATH];
+                                                       Image_StripImageExtension(name, buf, sizeof(buf));
+                                                       dpsnprintf(outfilename, sizeof(outfilename), "fixtrans/%s.tga", buf);
+                                                       Image_WriteTGARGBA(outfilename, image_width, image_height, data);
+                                                       Con_Printf("- %s written.\n", outfilename);
+                                               }
+                                       }
+                               }
                                return data;
                        }
                        else
@@ -907,11 +924,11 @@ unsigned char *loadimagepixels (const char *filename, qboolean complain, int mat
        return NULL;
 }
 
-rtexture_t *loadtextureimage (rtexturepool_t *pool, const char *filename, int matchwidth, int matchheight, qboolean complain, int flags)
+rtexture_t *loadtextureimage (rtexturepool_t *pool, const char *filename, int matchwidth, int matchheight, qboolean complain, int flags, qboolean allowFixtrans)
 {
        unsigned char *data;
        rtexture_t *rt;
-       if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
+       if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight, allowFixtrans)))
                return 0;
        rt = R_LoadTexture2D(pool, filename, image_width, image_height, data, TEXTYPE_RGBA, flags, NULL);
        Mem_Free(data);
@@ -1059,7 +1076,7 @@ void Image_FixTransparentPixels_f(void)
                Con_Printf("Processing %s... ", filename);
                Image_StripImageExtension(filename, buf, sizeof(buf));
                dpsnprintf(outfilename, sizeof(outfilename), "fixtrans/%s.tga", buf);
-               if(!(data = loadimagepixels(filename, true, 0, 0)))
+               if(!(data = loadimagepixels(filename, true, 0, 0, false)))
                        return;
                if((n = fixtransparentpixels(data, image_width, image_height)))
                {
diff --git a/image.h b/image.h
index 3a0052e88d9f6fcfb568327b44182a9f4bbb1d9a..47f5f4cfdb9a5ae471bab82be317dd9640f63344 100644 (file)
--- a/image.h
+++ b/image.h
@@ -23,10 +23,10 @@ void Image_StripImageExtension (const char *in, char *out, size_t size_out);
 unsigned char *LoadTGA (const unsigned char *f, int filesize, int matchwidth, int matchheight);
 
 // loads a texture, as pixel data
-unsigned char *loadimagepixels (const char *filename, qboolean complain, int matchwidth, int matchheight);
+unsigned char *loadimagepixels (const char *filename, qboolean complain, int matchwidth, int matchheight, qboolean allowFixtrans);
 
 // loads a texture, as a texture
-rtexture_t *loadtextureimage (rtexturepool_t *pool, const char *filename, int matchwidth, int matchheight, qboolean complain, int flags);
+rtexture_t *loadtextureimage (rtexturepool_t *pool, const char *filename, int matchwidth, int matchheight, qboolean complain, int flags, qboolean allowFixtrans);
 
 // writes a RGB TGA that is already upside down (which TGA wants)
 qboolean Image_WriteTGARGB_preflipped (const char *filename, int width, int height, const unsigned char *data, unsigned char *buffer);
@@ -47,6 +47,7 @@ void Image_HeightmapToNormalmap(const unsigned char *inpixels, unsigned char *ou
 
 // console command to fix the colors of transparent pixels (to prevent weird borders)
 void Image_FixTransparentPixels_f(void);
+extern cvar_t r_fixtrans_auto;
 
 #endif
 
index 0b1293ae336bbf217c8455037efe7ad833169e90..ebcd7bf1cc40995351e277e4e6dfa9465ae8ad87 100644 (file)
@@ -1510,7 +1510,7 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                        {
                                if (loadmodel->isworldmodel)
                                {
-                                       data = loadimagepixels(tx->name, false, 0, 0);
+                                       data = loadimagepixels(tx->name, false, 0, 0, false);
                                        if (data)
                                        {
                                                R_Q1BSP_LoadSplitSky(data, image_width, image_height, 4);
index c8ff41f4eb8107dab90ba66459505ef257d23106..4438ba77c1aecb97c99476b372c451834cf531c2 100644 (file)
@@ -25,7 +25,7 @@ void r_lightningbeams_start(void)
 
 void r_lightningbeams_setupqmbtexture(void)
 {
-       r_lightningbeamqmbtexture = loadtextureimage(r_lightningbeamtexturepool, "textures/particles/lightning.pcx", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE);
+       r_lightningbeamqmbtexture = loadtextureimage(r_lightningbeamtexturepool, "textures/particles/lightning.pcx", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE, false);
        if (r_lightningbeamqmbtexture == NULL)
                Cvar_SetValueQuick(&r_lightningbeam_qmbtexture, false);
 }
index 01f23c28f5edc58460f4c7a0ab868d8f4efb0cc5..4230cbf55685b650f9ebb66c5b950a4ec10df752 100644 (file)
@@ -3215,7 +3215,7 @@ rtexture_t *R_Shadow_LoadCubemap(const char *basename)
                        // generate an image name based on the base and and suffix
                        dpsnprintf(name, sizeof(name), "%s%s", basename, suffix[j][i].suffix);
                        // load it
-                       if ((image_rgba = loadimagepixels(name, false, cubemapsize, cubemapsize)))
+                       if ((image_rgba = loadimagepixels(name, false, cubemapsize, cubemapsize, false)))
                        {
                                // an image loaded, make sure width and height are equal
                                if (image_width == image_height)
diff --git a/r_sky.c b/r_sky.c
index 340be966300574433b8c0acab172fca5dca95256..a33b5346c24a27bc6ff523dbcc48927e1d3c32fb 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -102,13 +102,13 @@ int R_LoadSkyBox(void)
                success = 0;
                for (i=0; i<6; i++)
                {
-                       if (dpsnprintf(name, sizeof(name), "%s_%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0)))
+                       if (dpsnprintf(name, sizeof(name), "%s_%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0, false)))
                        {
-                               if (dpsnprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0)))
+                               if (dpsnprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0, false)))
                                {
-                                       if (dpsnprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0)))
+                                       if (dpsnprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0, false)))
                                        {
-                                               if (dpsnprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0)))
+                                               if (dpsnprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0, false)))
                                                        continue;
                                        }
                                }