Re #320 Back to the 'compatible' video init mode by default + SD now auto-reverts to the last valid video mode when a new one is set but fails

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3563 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: ac9da95aa0bfb5f53d8a4cd4448cc75781ab438d
Former-commit-id: a7e91a835c31eef348d73c0eed75335d4ec92e0c
This commit is contained in:
pouillot 2011-05-14 15:48:21 +00:00
parent f7a7800687
commit 89c2510901
10 changed files with 237 additions and 136 deletions

View file

@ -445,41 +445,10 @@ void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth,
if (_mapSupportedBool.empty() && _mapSupportedInt.empty())
{
// Frame buffer specs.
GfParmRemove(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_X);
GfParmRemove(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_Y);
GfParmRemove(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP);
GfParmRemove(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL);
GfParmRemove(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_FSCR);
GfParmRemoveSection(hparm, GFSCR_SECT_GLDETSPECS);
// Supported values.
// 1) Double-buffer.
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_DOUBLEBUFFER);
// 2) Color buffer depth.
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_COLORDEPTH);
// 3) Alpha-channel depth.
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ALPHADEPTH);
// 4) Max texture size.
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MAXTEXTURESIZE);
// 5) Texture compression.
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_TEXTURECOMPRESSION);
// 6) Multi-texturing.
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURING);
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS);
// 7) Rectangle textures).
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_RECTANGLETEXTURES);
// 8) Non-power-of-2 textures.
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_NONPOTTEXTURES);
// 9) Multi-sampling.
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLING);
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES);
GfParmRemoveSection(hparm, GFSCR_SECT_GLDETFEATURES);
}
// If there's support for anything, store it.
@ -601,17 +570,23 @@ bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth,
{
// Write new user settings about the frame buffer specs
// (the detection process might have down-casted them ...).
GfParmSetNum(hparm, GFSCR_SECT_PROP, GFSCR_ATT_WIN_X, pszNoUnit,
// Note: Sure the specs are in the 'in-test' state here,
// otherwise they would not have changed.
GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_X, pszNoUnit,
(tdble)nDetWidth);
GfParmSetNum(hparm, GFSCR_SECT_PROP, GFSCR_ATT_WIN_Y, pszNoUnit,
GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_Y, pszNoUnit,
(tdble)nDetHeight);
GfParmSetNum(hparm, GFSCR_SECT_PROP, GFSCR_ATT_BPP, pszNoUnit,
GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_BPP, pszNoUnit,
(tdble)nDetDepth);
GfParmSetStr(hparm, GFSCR_SECT_PROP, GFSCR_ATT_ALPHACHANNEL,
GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_ALPHACHANNEL,
bDetAlpha ? GFSCR_VAL_YES : GFSCR_VAL_NO);
GfParmSetStr(hparm, GFSCR_SECT_PROP, GFSCR_ATT_FSCR,
GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_FSCR,
bDetFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO);
// But make sure they are not validated yet at restart (only next time if OK).
GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
GFSCR_VAL_TODO);
// Write new params to config file.
GfParmWriteFile(NULL, hparm, "Screen");
@ -749,7 +724,7 @@ void GfglFeatures::loadSelection(void* hparmConfig)
if (!hparmConfig)
closeConfigFile(hparm);
// Display what we have selected.
// Display what we have really selected (after checking / fixing to supported values).
dumpSelection();
}
@ -787,7 +762,26 @@ void GfglFeatures::storeSelection(void* hparmConfig) const
// Force 'best possible' mode for video initialization when anti-aliasing selected
if (isSelected(MultiSampling))
GfParmSetStr(hparm, GFSCR_SECT_PROP, GFSCR_ATT_VINIT, GFSCR_VAL_VINIT_BEST);
{
// Use the 'in-test' specs if present, and reset the test state
// (force a new validation).
if (GfParmExistsSection(hparm, GFSCR_SECT_INTESTPROPS))
{
GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
GFSCR_VAL_INPROGRESS);
GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VINIT,
GFSCR_VAL_VINIT_BEST);
}
// Otherwise, use the 'validated' specs ... no new validation needed
// (if we can en/disable multi-sampling, it means that we already checked
// that it was possible, and how much).
else
{
GfParmSetStr(hparm, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_VINIT,
GFSCR_VAL_VINIT_BEST);
}
}
// Write new params to config file.
GfParmWriteFile(NULL, hparm, "Screen");
@ -835,13 +829,6 @@ bool GfglFeatures::isSelected(EFeatureBool eFeature) const
return itFeature == _mapSelectedBool.end() ? false : itFeature->second;
}
// void GfglFeatures::setSupported(EFeatureBool eFeature, bool bSupported)
// {
// _mapSupportedBool[eFeature] = bSupported;
// if (!bSupported && isSelected(eFeature))
// _mapSelectedBool[eFeature] = false; // Deselect if selected and not supported.
// }
bool GfglFeatures::isSupported(EFeatureBool eFeature) const
{
const std::map<EFeatureBool, bool>::const_iterator itFeature =
@ -867,13 +854,6 @@ int GfglFeatures::getSelected(EFeatureInt eFeature) const
return itFeature == _mapSelectedInt.end() ? InvalidInt : itFeature->second;
}
// void GfglFeatures::setSupported(EFeatureInt eFeature, int nSupportedValue)
// {
// _mapSupportedInt[eFeature] = nSupportedValue;
// if (getSelected(eFeature) > nSupportedValue) // Selected can't be greater than supported.
// _mapSelectedInt[eFeature] = nSupportedValue;
// }
int GfglFeatures::getSupported(EFeatureInt eFeature) const
{
const std::map<EFeatureInt, int>::const_iterator itFeature =

View file

@ -103,7 +103,6 @@ class TGFCLIENT_API GfglFeatures
void select(EFeatureBool eFeature, bool bSelected);
bool isSelected(EFeatureBool eFeature) const;
bool isSupported(EFeatureBool eFeature) const;
//void setSupported(EFeatureBool eFeature, bool bSupported);
// Integer-valued features (use InvalidInt for the "not supported" / "not selected" cases).
static int InvalidInt;
@ -117,7 +116,6 @@ class TGFCLIENT_API GfglFeatures
void select(EFeatureInt eFeature, int nSelectedValue);
int getSelected(EFeatureInt eFeature) const;
int getSupported(EFeatureInt eFeature) const;
//void setSupported(EFeatureInt eFeature, int nSupportedValue);
// Get the pointer to the named OpenGL extension function.
static void* getProcAddress(const char* pszName);

View file

@ -387,26 +387,56 @@ bool GfScrInit(void)
// GfLogInfo(" Hardware acceleration : %s\n", sdlVideoInfo->hw_available ? "Yes" : "No");
// GfLogInfo(" Total video memory : %u Kb\n", sdlVideoInfo->video_mem);
// Get selected frame buffer specs from config file.
// Get selected frame buffer specs from config file
// 1) Load the config file
char pszConfigFilename[256];
sprintf(pszConfigFilename, "%s%s", GfLocalDir(), GFSCR_CONF_FILE);
void* hparmScreen = GfParmReadFile(pszConfigFilename, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
// 2) Check / update test state of any 'in-test' specs.
if (GfParmExistsSection(hparmScreen, GFSCR_SECT_INTESTPROPS))
{
// Remove the 'in-test' specs if the test failed (we are stil in the 'in progress'
// test state because the game crashed during the test).
if (std::string(GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
GFSCR_VAL_INPROGRESS)) == GFSCR_VAL_INPROGRESS)
{
GfLogInfo("Reverting to last validated screen specs, as last test failed.\n");
GfParmRemoveSection(hparmScreen, GFSCR_SECT_INTESTPROPS);
}
// If the test has not yet been done, mark it as in-progress
// and write the config file to disk, in case the test makes the game crash.
else
{
GfLogInfo("Testing new screen specs : let's see what's happening ...\n");
GfParmSetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
GFSCR_VAL_INPROGRESS);
GfParmWriteFile(NULL, hparmScreen, "Screen");
}
}
// 3) Select the 'in-test' specs if present, otherwise the 'validated' ones.
const char* pszScrPropSec =
GfParmExistsSection(hparmScreen, GFSCR_SECT_INTESTPROPS)
? GFSCR_SECT_INTESTPROPS : GFSCR_SECT_VALIDPROPS;
// 4) Read the specs.
int nWinWidth =
(int)GfParmGetNum(hparmScreen, GFSCR_SECT_PROP, GFSCR_ATT_WIN_X, (char*)NULL, 800);
(int)GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_WIN_X, (char*)NULL, 800);
int nWinHeight =
(int)GfParmGetNum(hparmScreen, GFSCR_SECT_PROP, GFSCR_ATT_WIN_Y, (char*)NULL, 600);
(int)GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_WIN_Y, (char*)NULL, 600);
int nTotalDepth =
(int)GfParmGetNum(hparmScreen, GFSCR_SECT_PROP, GFSCR_ATT_BPP, (char*)NULL, 32);
(int)GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_BPP, (char*)NULL, 32);
bool bAlphaChannel =
std::string(GfParmGetStr(hparmScreen, GFSCR_SECT_PROP, GFSCR_ATT_ALPHACHANNEL,
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_ALPHACHANNEL,
GFSCR_VAL_YES))
== GFSCR_VAL_YES;
bool bFullScreen =
std::string(GfParmGetStr(hparmScreen, GFSCR_SECT_PROP, GFSCR_ATT_FSCR, GFSCR_VAL_NO))
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_FSCR, GFSCR_VAL_NO))
== GFSCR_VAL_YES;
bool bBestVideoInitMode =
std::string(GfParmGetStr(hparmScreen, GFSCR_SECT_PROP, GFSCR_ATT_VINIT,
bool bTryBestVInitMode =
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_VINIT,
GFSCR_VAL_VINIT_BEST))
== GFSCR_VAL_VINIT_BEST;
@ -417,18 +447,15 @@ bool GfScrInit(void)
// If specified, try best possible settings.
PScreenSurface = 0;
if (bBestVideoInitMode)
if (bTryBestVInitMode)
{
GfLogInfo("Trying 'best possible mode' for video initialization.\n");
// Detect best supported features for the specified frame buffer specs.
// Warning: Restarts the game if the frame buffer specs changed since last call.
bBestVideoInitMode =
GfglFeatures::self().checkBestSupport(nWinWidth, nWinHeight, nTotalDepth,
bAlphaChannel, bFullScreen, hparmScreen);
// If successfull detection, setup the user-selected mode.
if (bBestVideoInitMode)
// If specified and possible, setup the best possible settings.
if (GfglFeatures::self().checkBestSupport(nWinWidth, nWinHeight, nTotalDepth,
bAlphaChannel, bFullScreen, hparmScreen))
{
// Load Open GL user settings from the config file.
GfglFeatures::self().loadSelection();
@ -460,35 +487,44 @@ bool GfScrInit(void)
}
// Try the video mode with these parameters : should always work
// (unless you upgraded you hardware / OS and didn't clear your config file).
// (unless you downgraded you hardware / OS and didn't clear your config file).
PScreenSurface = SDL_SetVideoMode(nWinWidth, nWinHeight, nTotalDepth, bfVideoMode);
if (!PScreenSurface)
}
// If best mode not supported, or test actually failed,
// revert to a supported mode (restart the game).
if (!PScreenSurface)
{
GfLogWarning("Failed to setup best supported video mode "
"whereas previously detected !\n");
GfLogWarning("Tip: You should remove your %s%s file and restart,\n",
GfLocalDir(), GFSCR_CONF_FILE);
GfLogWarning(" if something changed in your OS"
" or video hardware/driver configuration.\n");
// If testing new screen specs, remember that the test failed
// in order to revert to the previous validated specs on restart.
if (std::string(pszScrPropSec) == GFSCR_SECT_INTESTPROPS)
{
// Should not happen, as we tested it in checkBestSupport ...
GfLogWarning("Failed to setup best supported video mode "
"whereas previously detected !\n");
GfLogWarning("Falling back to a more compatible default mode ...\n");
GfLogInfo("Tip: You should remove your %s%s file and restart,\n",
GfLocalDir(), GFSCR_CONF_FILE);
GfLogInfo(" if something changed in your OS"
" or video hardware/driver configuration.\n");
// Forcing compatible video init. mode.
GfParmSetStr(hparmScreen, GFSCR_SECT_PROP, GFSCR_ATT_VINIT,
GFSCR_VAL_VINIT_COMPATIBLE);
GfParmWriteFile(NULL, hparmScreen, "Screen");
GfParmReleaseHandle(hparmScreen);
// And restart the game.
GfuiApp().restart(); // Never returns.
GfParmSetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_TESTSTATE,
GFSCR_VAL_FAILED);
}
// Force compatible video init. mode if not testing a new video mode.
else
{
GfLogWarning("Falling back to a more compatible default mode ...\n");
GfParmSetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_VINIT,
GFSCR_VAL_VINIT_COMPATIBLE);
}
GfParmWriteFile(NULL, hparmScreen, "Screen");
GfParmReleaseHandle(hparmScreen);
// And restart the game.
GfuiApp().restart(); // Never returns.
}
}
// No more need for the config file.
GfParmReleaseHandle(hparmScreen);
// Video initialization with generic compatible settings.
if (!PScreenSurface)
{
@ -507,6 +543,10 @@ bool GfScrInit(void)
if (!PScreenSurface)
GfLogTrace("Can't get a non-full-screen %dx%dx%d compatible video mode\n",
nWinWidth, nWinHeight, nTotalDepth);
// Update screen specs.
GfParmSetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_FSCR, GFSCR_VAL_NO);
GfParmWriteFile(NULL, hparmScreen, "Screen");
}
// Failed : Try with a lower fallback size : should be supported everywhere ...
@ -518,6 +558,11 @@ bool GfScrInit(void)
if (!PScreenSurface)
GfLogTrace("Can't get a %dx%dx%d compatible video mode\n",
nWinWidth, nWinHeight, nTotalDepth);
// Update screen specs.
GfParmSetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_WIN_X, 0, (tdble)nWinWidth);
GfParmSetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_WIN_Y, 0, (tdble)nWinHeight);
GfParmWriteFile(NULL, hparmScreen, "Screen");
}
// Failed : Try with a lower fallback color depth : should be supported everywhere ...
@ -528,8 +573,15 @@ bool GfScrInit(void)
if (!PScreenSurface)
GfLogTrace("Can't get a %dx%dx%d compatible video mode\n",
nWinWidth, nWinHeight, nTotalDepth);
// Update screen specs.
GfParmSetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_BPP, 0, (tdble)nTotalDepth);
GfParmWriteFile(NULL, hparmScreen, "Screen");
}
// Close the config file.
GfParmReleaseHandle(hparmScreen);
// Failed : No way ... no more ideas !
if (!PScreenSurface)
{
@ -541,16 +593,14 @@ bool GfScrInit(void)
// If we get here, that's because we succeeded in getting a valid video mode :-)
// If 'compatible mode' selected, detect only standard Open GL features
// and load settings from the config file.
if (!bBestVideoInitMode)
// and load OpenGL settings from the config file.
if (!bTryBestVInitMode)
{
GfglFeatures::self().detectStandardSupport();
GfglFeatures::self().dumpSupport();
GfglFeatures::self().loadSelection();
}
// Save view geometry and screen center.
GfViewWidth = nWinWidth;
GfViewHeight = nWinHeight;
@ -600,8 +650,71 @@ bool GfScrInit(void)
void GfScrShutdown(void)
{
GfLogTrace("Shutting down screen.\n");
// Shutdown SDL video sub-system.
SDL_QuitSubSystem(SDL_INIT_VIDEO);
// If there's an 'in-test' screen properties section in the config file,
// * if the test state is 'to do', do nothing (will be taken care of in next GfScrInit),
// * if the test state is 'in progress', validate the new screen properties,
// * if the test state is 'failed', revert to the validated screen properties.
char pszConfigFilename[256];
sprintf(pszConfigFilename, "%s%s", GfLocalDir(), GFSCR_CONF_FILE);
void* hparmScreen = GfParmReadFile(pszConfigFilename, GFPARM_RMODE_STD);
if (GfParmExistsSection(hparmScreen, GFSCR_SECT_INTESTPROPS))
{
if (std::string(GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
GFSCR_VAL_INPROGRESS)) == GFSCR_VAL_INPROGRESS)
{
GfLogInfo("Validating new screen specs (test was successful).\n");
// Copy the 'in test' props to the 'validated' ones.
GfParmSetNum(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_WIN_X, 0,
GfParmGetNum(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_X, 0, 800));
GfParmSetNum(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_WIN_Y, 0,
GfParmGetNum(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_Y, 0, 600));
GfParmSetNum(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_BPP, 0,
GfParmGetNum(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_BPP, 0, 32));
// GfParmSetNum(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_MAXREFRESH, 0,
// GfParmGetNum(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_MAXREFRESH, 0, 0));
GfParmSetStr(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_VDETECT,
GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VDETECT, GFSCR_VAL_VDETECT_AUTO));
const char* pszVInitMode =
GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VINIT,
GFSCR_VAL_VINIT_COMPATIBLE);
GfParmSetStr(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_VINIT, pszVInitMode);
GfParmSetStr(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_FSCR,
GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_FSCR, GFSCR_VAL_NO));
// Store OpenGL settings if best video init mode selected
// (because loadSelection can changed them).
if (std::string(pszVInitMode) == GFSCR_VAL_VINIT_BEST)
GfglFeatures::self().storeSelection(hparmScreen);
}
else if (std::string(GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
GFSCR_VAL_INPROGRESS)) == GFSCR_VAL_FAILED)
{
GfLogInfo("Canceling new screen specs, back to old ones (test failed).\n");
}
if (std::string(GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
GFSCR_VAL_INPROGRESS)) != GFSCR_VAL_TODO)
{
// Remove the 'in-test' section.
GfParmRemoveSection(hparmScreen, GFSCR_SECT_INTESTPROPS);
// Write the screen config file to disk.
GfParmWriteFile(NULL, hparmScreen, "Screen");
}
else
{
GfLogInfo("New screen specs will be tested when restarting.\n");
}
}
// Release screen config params file.
GfParmReleaseHandle(hparmScreen);
}

View file

@ -28,7 +28,8 @@
#define GFSCR_CONF_FILE "config/screen.xml"
#define GFSCR_SECT_PROP "Screen Properties"
#define GFSCR_SECT_VALIDPROPS "Validated Screen Properties"
#define GFSCR_SECT_INTESTPROPS "In-Test Screen Properties"
#define GFSCR_ATT_BPP "bpp"
#define GFSCR_ATT_WIN_X "window width"
@ -40,6 +41,11 @@
#define GFSCR_ATT_GAMMA "gamma"
#define GFSCR_ATT_ALPHACHANNEL "alpha channel"
#define GFSCR_ATT_TESTSTATE "test state"
#define GFSCR_VAL_TODO "to do"
#define GFSCR_VAL_INPROGRESS "in progress"
#define GFSCR_VAL_FAILED "failed"
#define GFSCR_ATT_VDETECT "video mode detect"
#define GFSCR_VAL_VDETECT_AUTO "auto"
#define GFSCR_VAL_VDETECT_MANUAL "manual"

View file

@ -582,7 +582,7 @@ GfTexWriteImageToPNG(unsigned char *img, const char *filename, int width, int he
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
#if (ReadGammaFromSettingsFile)
handle = GfParmReadFile(GFSCR_CONF_FILE, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
screen_gamma = (float)GfParmGetNum(handle, GFSCR_SECT_PROP, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
screen_gamma = (float)GfParmGetNum(handle, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
GfParmReleaseHandle(handle);
#else
screen_gamma = 2.0;
@ -632,7 +632,7 @@ GfTexReadTexture(const char *filename, int* pWidth, int* pHeight,
sprintf(buf, "%s%s", GfLocalDir(), GFSCR_CONF_FILE);
void *handle = GfParmReadFile(buf, GFPARM_RMODE_STD);
const float screen_gamma =
(float)GfParmGetNum(handle, GFSCR_SECT_PROP, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
(float)GfParmGetNum(handle, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
GfParmReleaseHandle(handle);
// Load the image buffer from the file (JPEG 888 / PNG 8888)

View file

@ -16,9 +16,9 @@
<!DOCTYPE params SYSTEM "../tgf/params.dtd">
<params name="Screen" version="1.3">
<params name="Screen" version="1.4">
<section name="Screen Properties">
<section name="Validated Screen Properties">
<attnum name="window width" val="800"/>
<attnum name="window height" val="600"/>
<attnum name="bpp" val="32"/>
@ -26,7 +26,7 @@
<attstr name="alpha channel" in="yes,no" val="yes"/>
<attnum name="gamma" val="2"/>
<attstr name="video mode detect" in="auto,manual" val="auto"/>
<attstr name="video mode init" in="compatible,best" val="best"/>
<attstr name="video mode init" in="compatible,best" val="compatible"/>
</section>
<section name="Menu Font">

View file

@ -120,9 +120,6 @@ void DisplayMenu::onAccept(void *pDisplayMenu)
// Restart the game.
GfuiApp().restart();
// TODO: A nice system to get back to previous display settings if the chosen ones
// keep the game from really restarting (ex: unsupported full screen size) ?
}
void DisplayMenu::onCancel(void *pDisplayMenu)
@ -164,40 +161,46 @@ void DisplayMenu::updateControls()
void DisplayMenu::loadSettings()
{
// Load screen config params file.
// Open screen config params file.
std::ostringstream ossConfFile;
ossConfFile << GfLocalDir() << GFSCR_CONF_FILE;
void* hScrConfParams =
GfParmReadFile(ossConfFile.str().c_str(), GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
// Select the screen properties to edit : the 'in-test' ones if present,
// otherwise the 'validated' ones.
const char* pszScrPropSec =
GfParmExistsSection(hScrConfParams, GFSCR_SECT_INTESTPROPS)
? GFSCR_SECT_INTESTPROPS : GFSCR_SECT_VALIDPROPS;
// Video detection mode : Auto or Manual.
const char *pszVideoDetectMode =
GfParmGetStr(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_VDETECT, GFSCR_VAL_VDETECT_AUTO);
GfParmGetStr(hScrConfParams, pszScrPropSec, GFSCR_ATT_VDETECT, GFSCR_VAL_VDETECT_AUTO);
_eVideoDetectMode =
strcmp(pszVideoDetectMode, GFSCR_VAL_VDETECT_AUTO) ? eManual : eAuto;
// Color depth (bits per pixel, alpha included).
_nColorDepth = (int)GfParmGetNum(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_BPP, NULL, 32);
_nColorDepth = (int)GfParmGetNum(hScrConfParams, pszScrPropSec, GFSCR_ATT_BPP, NULL, 32);
// Display mode : Full-screen or Windowed.
const char *pszFullScreen =
GfParmGetStr(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_FSCR, GFSCR_VAL_NO);
GfParmGetStr(hScrConfParams, pszScrPropSec, GFSCR_ATT_FSCR, GFSCR_VAL_NO);
_eDisplayMode = strcmp(pszFullScreen, GFSCR_VAL_YES) ? eWindowed : eFullScreen;
// Screen / window size.
_nScreenWidth = (int)GfParmGetNum(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_WIN_X, NULL, 800);
_nScreenHeight = (int)GfParmGetNum(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_WIN_Y, NULL, 600);
_nScreenWidth = (int)GfParmGetNum(hScrConfParams, pszScrPropSec, GFSCR_ATT_WIN_X, NULL, 800);
_nScreenHeight = (int)GfParmGetNum(hScrConfParams, pszScrPropSec, GFSCR_ATT_WIN_Y, NULL, 600);
// Video initialization mode : Compatible or Best.
const char *pszVideoInitMode =
GfParmGetStr(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_VINIT, GFSCR_VAL_VINIT_COMPATIBLE);
GfParmGetStr(hScrConfParams, pszScrPropSec, GFSCR_ATT_VINIT, GFSCR_VAL_VINIT_COMPATIBLE);
_eVideoInitMode =
strcmp(pszVideoInitMode, GFSCR_VAL_VINIT_COMPATIBLE) ? eBestPossible : eCompatible;
#ifndef NoMaxRefreshRate
// Max. refresh rate (Hz).
_nMaxRefreshRate =
(int)GfParmGetNum(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_MAXREFRESH, NULL, 0);
(int)GfParmGetNum(hScrConfParams, pszScrPropSec, GFSCR_ATT_MAXREFRESH, NULL, 0);
#endif
// Release screen config params file.
@ -207,34 +210,38 @@ void DisplayMenu::loadSettings()
// Save graphical settings to XML file.
void DisplayMenu::storeSettings() const
{
// Load screen config params file.
// Open screen config params file.
std::ostringstream ossConfFile;
ossConfFile << GfLocalDir() << GFSCR_CONF_FILE;
void* hScrConfParams =
GfParmReadFile(ossConfFile.str().c_str(), GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
// Write new settings.
GfParmSetNum(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_WIN_X, (char*)NULL, _nScreenWidth);
GfParmSetNum(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_WIN_Y, (char*)NULL, _nScreenHeight);
GfParmSetNum(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_BPP, (char*)NULL, _nColorDepth);
// Write new screen properties to the 'in-test' section, with 'to do' test state
// (will become 'validated' after a succesfull restart, once we are sure they are OK :
// see guiscreen::GfScrShutdown).
GfParmSetStr(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE, GFSCR_VAL_TODO);
GfParmSetNum(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_X, (char*)NULL, _nScreenWidth);
GfParmSetNum(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_Y, (char*)NULL, _nScreenHeight);
GfParmSetNum(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_BPP, (char*)NULL, _nColorDepth);
#ifndef NoMaxRefreshRate
GfParmSetNum(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_MAXREFRESH, (char*)NULL, _nMaxRefreshRate);
GfParmSetNum(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_MAXREFRESH, (char*)NULL, _nMaxRefreshRate);
#endif
const char* pszVDetectMode =
(_eVideoDetectMode == eAuto) ? GFSCR_VAL_VDETECT_AUTO : GFSCR_VAL_VDETECT_MANUAL;
GfParmSetStr(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_VDETECT, pszVDetectMode);
GfParmSetStr(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VDETECT, pszVDetectMode);
const char* pszVInitMode =
(_eVideoInitMode == eCompatible) ? GFSCR_VAL_VINIT_COMPATIBLE : GFSCR_VAL_VINIT_BEST;
GfParmSetStr(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_VINIT, pszVInitMode);
GfParmSetStr(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VINIT, pszVInitMode);
const char* pszDisplMode =
(_eDisplayMode == eFullScreen) ? GFSCR_VAL_YES : GFSCR_VAL_NO;
GfParmSetStr(hScrConfParams, GFSCR_SECT_PROP, GFSCR_ATT_FSCR, pszDisplMode);
GfParmSetStr(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_FSCR, pszDisplMode);
// Deselect anti-aliasing from the Open GL settings if 'compatible' mode
// selected for the video initialization (anti-aliasing not supported in this mode).
// Deselect anti-aliasing from the Open GL settings if 'compatible' mode selected
// for the video initialization (anti-aliasing not supported in this mode).
if (_eVideoInitMode == eCompatible)
GfParmSetStr(hScrConfParams, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLING,
GFSCR_ATT_MULTISAMPLING_DISABLED);

View file

@ -100,7 +100,7 @@ static void onAccept(void *)
GfglFeatures::self().select(GfglFeatures::MultiSamplingSamples,
(int)pow(2.0, (double)NCurMultiSampleIndex));
// Store settings from the GL features layer to the graph.xml file.
// Store settings from the GL features layer to the screen.xml file.
GfglFeatures::self().storeSelection();
// Return to previous screen.
@ -116,9 +116,6 @@ static void onAccept(void *)
// Restart the game.
GfuiApp().restart();
// TODO: A nice system to get back to previous display settings if the chosen ones
// keep the game from really restarting (ex: unsupported full screen size) ?
}
}

View file

@ -272,7 +272,7 @@ bool SplashScreen(void)
//sprintf(buf, "%s%s", GfLocalDir(), GFSCR_CONF_FILE);
//void* handle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
//float screen_gamma =
// (float)GfParmGetNum(handle, GFSCR_SECT_PROP, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
// (float)GfParmGetNum(handle, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
// Load splash texture from file.
s_texture = GfTexReadTexture("data/img/splash.jpg",

View file

@ -260,7 +260,7 @@ rmScreenActivate(void * /* dummy */)
void* hparmScrConf = GfParmReadFile(ossConfFile.str().c_str(), GFPARM_RMODE_STD);
FPSLimLastTime = 0.0;
FPSLimMaxRate =
GfParmGetNum(hparmScrConf, GFSCR_SECT_PROP, GFSCR_ATT_MAXREFRESH, NULL, 0.0);
GfParmGetNum(hparmScrConf, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_MAXREFRESH, NULL, 0.0);
if (FPSLimMaxRate)
GfLogInfo("FPS limiter is on (%.1f Hz).\n", FPSLimMaxRate);
else