]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
make the texture compression control sensitive towards support of the feature
authorRudolf Polzer <divverent@alientrap.org>
Fri, 24 Dec 2010 17:16:33 +0000 (18:16 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Fri, 24 Dec 2010 17:16:33 +0000 (18:16 +0100)
qcsrc/menu/xonotic/slider_picmip.c
qcsrc/menu/xonotic/util.qc
qcsrc/menu/xonotic/util.qh

index e906242fe44fc90c3cdcc80bad6afa213e8c9317..7ffc626a8b5ea544d5c16922e95bb1001f8db231 100644 (file)
@@ -3,6 +3,7 @@ CLASS(XonoticPicmipSlider) EXTENDS(XonoticTextSlider)
        METHOD(XonoticPicmipSlider, configureXonoticPicmipSlider, void(entity))
        METHOD(XonoticPicmipSlider, draw, void(entity))
        METHOD(XonoticPicmipSlider, autofix, void(entity))
+       ATTRIB(XonoticPicmipSlider, have_s3tc, float, 0)
 ENDCLASS(XonoticPicmipSlider)
 entity makeXonoticPicmipSlider(); // note: you still need to call addValue and configureXonoticTextSliderValues!
 #endif
@@ -19,14 +20,15 @@ void XonoticPicmipSlider_configureXonoticPicmipSlider(entity me)
 {
        me.configureXonoticTextSlider(me, "gl_picmip");
        me.autofix(me);
+       me.have_s3tc = GL_Have_TextureCompression();
 }
-float texmemsize()
+float texmemsize(float s3tc)
 {
        return
        (
                  2500 * pow(0.5, max(0, cvar("gl_picmip") + cvar("gl_picmip_other")))
                + 1500 * pow(0.5, max(0, cvar("gl_picmip") + cvar("gl_picmip_world")))
-       ) * ((cvar("r_texture_dds_load") || cvar("gl_texturecompression")) ? 0.4 : 1.0); // TC: normalmaps 50%, other 25%, few incompressible, guessing 40% as conservative average
+       ) * (s3tc && ((cvar("r_texture_dds_load") || cvar("gl_texturecompression")) ? 0.4 : 1.0)); // TC: normalmaps 50%, other 25%, few incompressible, guessing 40% as conservative average
 }
 void XonoticPicmipSlider_autofix(entity me)
 {
@@ -35,7 +37,7 @@ void XonoticPicmipSlider_autofix(entity me)
        max_soft = cvar("sys_memsize_physical");
        if(max_hard > 0)
        {
-               while(me.value > 0 && texmemsize() > max_hard)
+               while(me.value > 0 && texmemsize(me.have_s3tc) > max_hard)
                        me.setValue(me, me.value - 1);
        }
        // TODO also check the soft limit!
index c968c60acc10154223c31c57bbb00d2d34137914..f6ffa387c996624bb06acef3ea585a580423b803 100644 (file)
@@ -1,3 +1,13 @@
+float GL_CheckExtension(string ext)
+{
+       return (strstrofs(strcat(" ", cvar_string("gl_info_extensions"), " "), strcat(" ", ext, " "), 0) >= 0);
+}
+
+float GL_Have_TextureCompression()
+{
+       return (GL_CheckExtension("GL_EXT_texture_compression_s3tc") && GL_CheckExtension("GL_ARB_texture_compression"));
+}
+
 float tooltipdb;
 void loadTooltips()
 {
@@ -459,29 +469,52 @@ float updateCompression()
 {
        float fh;
        float have_dds, have_jpg, have_tga;
+       float can_dds;
        if((have_dds = ((fh = fopen("dds/particles/particlefont.dds", FILE_READ)) >= 0)))
                fclose(fh);
        if((have_jpg = ((fh = fopen("particles/particlefont.jpg", FILE_READ)) >= 0)))
                fclose(fh);
        if((have_tga = ((fh = fopen("particles/particlefont.tga", FILE_READ)) >= 0)))
                fclose(fh);
+       can_dds = GL_Have_TextureCompression();
        if(have_dds && (have_jpg || have_tga))
        {
                // both? Let's only use good quality precompressed files
-               cvar_set("gl_texturecompression", "0");
-               return 1;
+               // but ONLY if we actually support it!
+               if(can_dds)
+               {
+                       cvar_set("gl_texturecompression", "0");
+                       return 1;
+               }
+               else
+               {
+                       cvar_set("gl_texturecompression", "0");
+                       cvar_set("r_texture_dds_load", "0");
+                       return 0;
+               }
        }
        else if(have_dds)
        {
                // DDS only? We probably always want texture compression
                cvar_set("gl_texturecompression", "1");
                cvar_set("r_texture_dds_load", "1");
+               if(!can_dds)
+                       print("^1ERROR: Texture compression is required but not supported.\n^1Expect visual problems.\n");
                return 0;
        }
        else
        {
                // TGA only? Allow runtime compression
-               cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
-               return 2;
+               if(can_dds)
+               {
+                       cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
+                       return 2;
+               }
+               else
+               {
+                       cvar_set("gl_texturecompression", "0");
+                       cvar_set("r_texture_dds_load", "0");
+                       return 0;
+               }
        }
 }
index ace912dc21394bbcde6a5a6e9398eb443eecbd7a..053c5073095f6c64a65f08166dbafd8ad2df46eb 100644 (file)
@@ -1,3 +1,6 @@
+float GL_CheckExtension(string ext);
+float GL_Have_TextureCompression();
+
 void forAllDescendants(entity root, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
 void saveAllCvars(entity root);
 void loadAllCvars(entity root);