From d19ef1d0ccee480cd8f56c1f8518f08348098aa4 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Fri, 24 Dec 2010 18:16:33 +0100 Subject: [PATCH] make the texture compression control sensitive towards support of the feature --- qcsrc/menu/xonotic/slider_picmip.c | 8 +++--- qcsrc/menu/xonotic/util.qc | 41 +++++++++++++++++++++++++++--- qcsrc/menu/xonotic/util.qh | 3 +++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/qcsrc/menu/xonotic/slider_picmip.c b/qcsrc/menu/xonotic/slider_picmip.c index e906242fe4..7ffc626a8b 100644 --- a/qcsrc/menu/xonotic/slider_picmip.c +++ b/qcsrc/menu/xonotic/slider_picmip.c @@ -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! diff --git a/qcsrc/menu/xonotic/util.qc b/qcsrc/menu/xonotic/util.qc index c968c60acc..f6ffa387c9 100644 --- a/qcsrc/menu/xonotic/util.qc +++ b/qcsrc/menu/xonotic/util.qc @@ -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; + } } } diff --git a/qcsrc/menu/xonotic/util.qh b/qcsrc/menu/xonotic/util.qh index ace912dc21..053c507309 100644 --- a/qcsrc/menu/xonotic/util.qh +++ b/qcsrc/menu/xonotic/util.qh @@ -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); -- 2.39.2