From a1a7264aeccc3e35f0abaab71fed06adc0efd348 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Fri, 15 Oct 2010 00:06:48 +0000 Subject: [PATCH] Set force_s3tc_enable automatically for greater chance of compressed texture support on Linux (see #575). This was SVN commit r8356. --- binaries/data/config/default.cfg | 4 ++++ source/ps/GameSetup/GameSetup.cpp | 4 ++-- source/ps/VideoMode.cpp | 22 +++++++++++++++++++++- source/ps/VideoMode.h | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index dea94d44ac..ccd897f181 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -36,6 +36,10 @@ noautomipmap = true novbo = false noframebufferobject = false +; Linux only: Set the driconf force_s3tc_enable option at startup, +; for compressed texture support +force_s3tc_enable = true + ; Specify the render path. This can be one of: ; default Automatically select one of the below, depending on system capabilities ; fixed Only use OpenGL fixed function pipeline diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 2d031721e3..0ccf136f9a 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -496,8 +496,8 @@ static void InitPs(bool setup_gui, const CStrW& gui_page) g_GUI->DisplayMessageBox(600, 270, L"Warning", L"Your graphics drivers do not support S3TC compressed textures. This may reduce performance.\n\n" #if !(OS_WIN || OS_MACOSX) - L"To fix this, run the program \"driconf\" and enable the force_s3tc_enable option (\"Enable S3TC texture compression\"). " - L"(If this causes rendering errors, you may have to disable the option again.)" + L"To fix this, you may have to install the \"libtxc_dxtn\" library. " + L"See http://dri.freedesktop.org/wiki/S3TC for more information." #else L"Please try updating your graphics drivers to ensure you have full hardware acceleration." #endif diff --git a/source/ps/VideoMode.cpp b/source/ps/VideoMode.cpp index 970a04b042..ed26be2424 100644 --- a/source/ps/VideoMode.cpp +++ b/source/ps/VideoMode.cpp @@ -43,7 +43,7 @@ CVideoMode g_VideoMode; CVideoMode::CVideoMode() : m_IsInitialised(false), m_PreferredW(0), m_PreferredH(0), m_PreferredBPP(0), m_PreferredFreq(0), - m_ConfigW(0), m_ConfigH(0), m_ConfigBPP(0), m_ConfigFullscreen(false), + m_ConfigW(0), m_ConfigH(0), m_ConfigBPP(0), m_ConfigFullscreen(false), m_ConfigForceS3TCEnable(true), m_WindowedW(DEFAULT_WINDOW_W), m_WindowedH(DEFAULT_WINDOW_H) { // (m_ConfigFullscreen defaults to false, so users don't get stuck if @@ -59,6 +59,7 @@ void CVideoMode::ReadConfig() CFG_GET_USER_VAL("xres", Int, m_ConfigW); CFG_GET_USER_VAL("yres", Int, m_ConfigH); CFG_GET_USER_VAL("bpp", Int, m_ConfigBPP); + CFG_GET_USER_VAL("force_s3tc_enable", Bool, m_ConfigForceS3TCEnable); } bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen) @@ -115,6 +116,25 @@ bool CVideoMode::InitSDL() ReadConfig(); + // On Linux we have to try hard to get S3TC compressed texture support. + // If the extension is already provided by default, that's fine. + // Otherwise we should enable the 'force_s3tc_enable' environment variable + // and (re)initialise the video system, so that Mesa provides the extension + // (if the driver at least supports decompression). + // (This overrides the force_s3tc_enable specified via driconf files.) + // Otherwise we should complain to the user, and stop using compressed textures. + // + // Setting the environment variable causes Mesa to print an ugly message to stderr + // ("ATTENTION: default value of option force_s3tc_enable overridden by environment."), + // so it'd be nicer to skip that if S3TC will be supported by default, + // but reinitialising video is a pain (and it might do weird things when fullscreen) + // so we just unconditionally set it (unless our config file explicitly disables it). + +#if !(OS_WIN || OS_MACOSX) // (assume Mesa is used for all non-Windows non-Mac platforms) + if (m_ConfigForceS3TCEnable) + setenv("force_s3tc_enable", "true", 0); +#endif + // preferred video mode = current desktop settings // (command line params may override these) gfx_get_video_mode(&m_PreferredW, &m_PreferredH, &m_PreferredBPP, &m_PreferredFreq); diff --git a/source/ps/VideoMode.h b/source/ps/VideoMode.h index 90056e475e..68462edabb 100644 --- a/source/ps/VideoMode.h +++ b/source/ps/VideoMode.h @@ -72,6 +72,7 @@ private: int m_ConfigH; int m_ConfigBPP; bool m_ConfigFullscreen; + bool m_ConfigForceS3TCEnable; // If we're fullscreen, size of window when we were last windowed (or the default window size // if we started fullscreen), to support switching back to the old window size