Changeset View
Changeset View
Standalone View
Standalone View
source/ps/VideoMode.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
static int DEFAULT_FULLSCREEN_W = 1024; | static int DEFAULT_FULLSCREEN_W = 1024; | ||||
static int DEFAULT_FULLSCREEN_H = 768; | static int DEFAULT_FULLSCREEN_H = 768; | ||||
CVideoMode g_VideoMode; | CVideoMode g_VideoMode; | ||||
CVideoMode::CVideoMode() : | CVideoMode::CVideoMode() : | ||||
m_IsFullscreen(false), m_IsInitialised(false), m_Window(NULL), | m_IsFullscreen(false), m_IsInitialised(false), m_Window(NULL), | ||||
m_PreferredW(0), m_PreferredH(0), m_PreferredBPP(0), m_PreferredFreq(0), | 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_ConfigForceS3TCEnable(true), | m_ConfigW(0), m_ConfigH(0), m_ConfigBPP(0), m_ConfigFullscreen(false), | ||||
m_WindowedW(DEFAULT_WINDOW_W), m_WindowedH(DEFAULT_WINDOW_H), m_WindowedX(0), m_WindowedY(0) | m_WindowedW(DEFAULT_WINDOW_W), m_WindowedH(DEFAULT_WINDOW_H), m_WindowedX(0), m_WindowedY(0) | ||||
{ | { | ||||
// (m_ConfigFullscreen defaults to false, so users don't get stuck if | // (m_ConfigFullscreen defaults to false, so users don't get stuck if | ||||
// e.g. half the filesystem is missing and the config files aren't loaded) | // e.g. half the filesystem is missing and the config files aren't loaded) | ||||
} | } | ||||
void CVideoMode::ReadConfig() | void CVideoMode::ReadConfig() | ||||
{ | { | ||||
bool windowed = !m_ConfigFullscreen; | bool windowed = !m_ConfigFullscreen; | ||||
CFG_GET_VAL("windowed", windowed); | CFG_GET_VAL("windowed", windowed); | ||||
m_ConfigFullscreen = !windowed; | m_ConfigFullscreen = !windowed; | ||||
CFG_GET_VAL("xres", m_ConfigW); | CFG_GET_VAL("xres", m_ConfigW); | ||||
CFG_GET_VAL("yres", m_ConfigH); | CFG_GET_VAL("yres", m_ConfigH); | ||||
CFG_GET_VAL("bpp", m_ConfigBPP); | CFG_GET_VAL("bpp", m_ConfigBPP); | ||||
CFG_GET_VAL("display", m_ConfigDisplay); | CFG_GET_VAL("display", m_ConfigDisplay); | ||||
CFG_GET_VAL("force_s3tc_enable", m_ConfigForceS3TCEnable); | |||||
} | } | ||||
bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen) | bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen) | ||||
{ | { | ||||
Uint32 flags = 0; | Uint32 flags = 0; | ||||
if (fullscreen) | if (fullscreen) | ||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool CVideoMode::InitSDL() | bool CVideoMode::InitSDL() | ||||
{ | { | ||||
ENSURE(!m_IsInitialised); | ENSURE(!m_IsInitialised); | ||||
ReadConfig(); | ReadConfig(); | ||||
EnableS3TC(); | |||||
// preferred video mode = current desktop settings | // preferred video mode = current desktop settings | ||||
// (command line params may override these) | // (command line params may override these) | ||||
gfx::GetVideoMode(&m_PreferredW, &m_PreferredH, &m_PreferredBPP, &m_PreferredFreq); | gfx::GetVideoMode(&m_PreferredW, &m_PreferredH, &m_PreferredBPP, &m_PreferredFreq); | ||||
int w = m_ConfigW; | int w = m_ConfigW; | ||||
int h = m_ConfigH; | int h = m_ConfigH; | ||||
if (m_ConfigFullscreen) | if (m_ConfigFullscreen) | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool CVideoMode::InitNonSDL() | bool CVideoMode::InitNonSDL() | ||||
{ | { | ||||
ENSURE(!m_IsInitialised); | ENSURE(!m_IsInitialised); | ||||
ReadConfig(); | ReadConfig(); | ||||
EnableS3TC(); | |||||
m_IsInitialised = true; | m_IsInitialised = true; | ||||
return true; | return true; | ||||
} | } | ||||
void CVideoMode::Shutdown() | void CVideoMode::Shutdown() | ||||
{ | { | ||||
ENSURE(m_IsInitialised); | ENSURE(m_IsInitialised); | ||||
m_IsFullscreen = false; | m_IsFullscreen = false; | ||||
m_IsInitialised = false; | m_IsInitialised = false; | ||||
if (m_Window) | if (m_Window) | ||||
{ | { | ||||
SDL_DestroyWindow(m_Window); | SDL_DestroyWindow(m_Window); | ||||
m_Window = NULL; | m_Window = NULL; | ||||
} | } | ||||
} | } | ||||
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) | bool CVideoMode::ResizeWindow(int w, int h) | ||||
{ | { | ||||
ENSURE(m_IsInitialised); | ENSURE(m_IsInitialised); | ||||
// Ignore if not windowed | // Ignore if not windowed | ||||
if (m_IsFullscreen) | if (m_IsFullscreen) | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator