1
0
forked from 0ad/0ad

Fix Mesa S3TC-enabling to work in Atlas

This was SVN commit r8433.
This commit is contained in:
Ykkrosh 2010-10-21 23:44:54 +00:00
parent 48121bcef6
commit 3eed24a338
8 changed files with 84 additions and 47 deletions

View File

@ -480,6 +480,7 @@ static void RunGameOrAtlas(int argc, const char* argv[])
// run the game
Init(args, 0);
InitGraphics(args, 0);
MainControllerInit();
while(!quit)
Frame();

View File

@ -737,8 +737,6 @@ static bool Autostart(const CmdLineArgs& args);
void Init(const CmdLineArgs& args, int flags)
{
const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;
MICROLOG(L"Init");
h_mgr_init();
@ -790,9 +788,6 @@ void Init(const CmdLineArgs& args, int flags)
CNetHost::Initialize();
if(setup_vmode)
InitSDL();
new CProfileViewer;
new CProfileManager; // before any script code
@ -804,9 +799,16 @@ void Init(const CmdLineArgs& args, int flags)
// g_ConfigDB, command line args, globals
CONFIG_Init(args);
}
if (setup_vmode)
void InitGraphics(const CmdLineArgs& args, int flags)
{
const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;
if(setup_vmode)
{
InitSDL();
if (!g_VideoMode.InitSDL())
throw PSERROR_System_VmodeFailed(); // abort startup

View File

@ -52,6 +52,7 @@ extern void RenderGui(bool RenderingState);
class CmdLineArgs;
extern void Init(const CmdLineArgs& args, int flags);
extern void InitGraphics(const CmdLineArgs& args, int flags);
extern void Shutdown(int flags);
#endif // INCLUDED_GAMESETUP

View File

@ -116,24 +116,7 @@ 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
EnableS3TC();
// preferred video mode = current desktop settings
// (command line params may override these)
@ -202,6 +185,41 @@ bool CVideoMode::InitSDL()
return true;
}
bool CVideoMode::InitNonSDL()
{
debug_assert(!m_IsInitialised);
ReadConfig();
EnableS3TC();
m_IsInitialised = true;
return true;
}
void CVideoMode::EnableS3TC()
{
// 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
}
bool CVideoMode::ResizeWindow(int w, int h)
{
debug_assert(m_IsInitialised);

View File

@ -28,6 +28,13 @@ public:
*/
bool InitSDL();
/**
* Initialise parts of the video mode, for use in Atlas (which uses
* wxWidgets instead of SDL for GL).
* Currently this just tries to enable S3TC.
*/
bool InitNonSDL();
/**
* Resize the SDL window and associated graphics stuff to the new size.
*/
@ -58,6 +65,7 @@ private:
void ReadConfig();
int GetBestBPP();
bool SetVideoMode(int w, int h, int bpp, bool fullscreen);
void EnableS3TC();
bool m_IsInitialised;

View File

@ -418,6 +418,13 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterfac
// Initialise things that rely on scripts
m_ObjectSettings.Init(AtlasMessage::eRenderView::GAME);
//////////////////////////////////////////////////////////////////////////
// Do some early game initialisation:
// (This must happen before constructing the GL canvas.)
POST_MESSAGE(Init, ());
//////////////////////////////////////////////////////////////////////////
// Menu
@ -516,7 +523,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterfac
POST_MESSAGE(SetCanvas, (static_cast<wxGLCanvas*>(canvas)));
POST_MESSAGE(Init, (true));
POST_MESSAGE(InitGraphics, ());
canvas->InitSize();

View File

@ -37,15 +37,25 @@
namespace AtlasMessage {
static bool g_IsInitialised = false;
const int g_InitFlags = INIT_HAVE_VMODE|INIT_NO_GUI;
MESSAGEHANDLER(Init)
{
UNUSED2(msg);
// Don't do anything if we're called multiple times
if (g_IsInitialised)
return;
g_Quickstart = true;
Init(g_GameLoop->args, g_InitFlags);
// Initialise some graphics state for Atlas.
// (This must be done after Init loads the config DB,
// but before the UI constructs its GL canvases.)
g_VideoMode.InitNonSDL();
}
MESSAGEHANDLER(InitGraphics)
{
UNUSED2(msg);
#if OS_LINUX || OS_MACOSX
// When using GLX (Linux), SDL has to load the GL library to find
@ -65,13 +75,7 @@ MESSAGEHANDLER(Init)
ogl_Init();
g_Quickstart = true;
int flags = INIT_HAVE_VMODE|INIT_NO_GUI;
Init(g_GameLoop->args, flags);
// TODO: we don't use msg->initsimulation any more, it should be deleted
InitGraphics(g_GameLoop->args, g_InitFlags);
#if OS_WIN
// HACK (to stop things looking very ugly when scrolling) - should
@ -79,8 +83,6 @@ MESSAGEHANDLER(Init)
if(ogl_HaveExtension("WGL_EXT_swap_control"))
pwglSwapIntervalEXT(1);
#endif
g_IsInitialised = true;
}
@ -88,10 +90,6 @@ MESSAGEHANDLER(Shutdown)
{
UNUSED2(msg);
// Don't do anything if we're called multiple times
if (! g_IsInitialised)
return;
// Empty the CommandProc, to get rid of its references to entities before
// we kill the EntityManager
GetCommandProc().Destroy();
@ -101,8 +99,6 @@ MESSAGEHANDLER(Shutdown)
int flags = 0;
Shutdown(flags);
g_IsInitialised = false;
}

View File

@ -29,10 +29,14 @@
//////////////////////////////////////////////////////////////////////////
MESSAGE(Init,
((bool, initsimulation)) // whether to initialise simulation/game-specific objects
);
// Initialise some engine code. Must be called before anything else.
MESSAGE(Init, );
// Initialise graphics-related code. Must be called after the first SetCanvas,
// and before much else.
MESSAGE(InitGraphics, );
// Shut down engine/graphics code.
MESSAGE(Shutdown, );
struct eRenderView { enum renderViews { NONE, GAME, ACTOR }; };