Remove SDL1 code (WIP) part 2
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7664 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 8358f36af5e80fbbf18f9988436ead20e53f60ac Former-commit-id: 244544eced7c077ad0fe3dc5890177fdc6100f49
This commit is contained in:
parent
9586a48241
commit
595b32628b
4 changed files with 2 additions and 832 deletions
|
@ -39,9 +39,7 @@
|
|||
#include <portability.h>
|
||||
|
||||
#include "tgfclient.h"
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#include "SDL_haptic.h"
|
||||
#endif
|
||||
|
||||
|
||||
static const char *GfJoyBtn[] = {
|
||||
|
@ -139,7 +137,6 @@ static int gfctrlJoyPresent = GFCTRL_JOY_UNTESTED;
|
|||
static SDL_Joystick *Joysticks[GFCTRL_JOY_NUMBER] = {NULL};
|
||||
static tCtrlJoyInfo *joyInfoCopy = NULL;
|
||||
//static tCtrlJoyInfo joyInfo;
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#if SDL_FORCEFEEDBACK
|
||||
static SDL_Haptic *Haptics[GFCTRL_JOY_NUMBER] = {NULL};
|
||||
static SDL_HapticEffect cfx[GFCTRL_JOY_NUMBER];
|
||||
|
@ -147,7 +144,6 @@ static unsigned int cfx_timeout[GFCTRL_JOY_NUMBER];
|
|||
static unsigned int rfx_timeout[GFCTRL_JOY_NUMBER];
|
||||
static int id[GFCTRL_JOY_NUMBER];
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
static jsJoystick *Joysticks[GFCTRL_JOY_NUMBER] = {NULL};
|
||||
#endif
|
||||
|
@ -312,7 +308,6 @@ gfctrlJoyInit(void)
|
|||
}
|
||||
}
|
||||
#else
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#if SDL_FORCEFEEDBACK
|
||||
memset(&cfx, 0, sizeof(cfx));
|
||||
|
||||
|
@ -324,18 +319,13 @@ gfctrlJoyInit(void)
|
|||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0) {
|
||||
#else
|
||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
|
||||
#endif
|
||||
#else
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
|
||||
#endif
|
||||
GfLogError("Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
gfctrlJoyPresent = GFCTRL_JOY_UNTESTED;
|
||||
return;
|
||||
}
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
// Ignore the joystick events, we will poll directly as it is faster
|
||||
SDL_JoystickEventState(SDL_IGNORE);
|
||||
#endif
|
||||
gfctrlJoyPresent = SDL_NumJoysticks();
|
||||
if (gfctrlJoyPresent > GFCTRL_JOY_NUMBER) gfctrlJoyPresent = GFCTRL_JOY_NUMBER;
|
||||
|
||||
|
@ -347,7 +337,7 @@ gfctrlJoyInit(void)
|
|||
// Don't configure the joystick if it doesn't work
|
||||
if (Joysticks[index] == NULL) {
|
||||
GfLogError("Couldn't open joystick %d: %s\n", index, SDL_GetError());
|
||||
#if ((SDL_MAJOR_VERSION >= 2) && (SDL_FORCEFEEDBACK))
|
||||
#if SDL_FORCEFEEDBACK
|
||||
} else {
|
||||
cfx_timeout[index] = 0;
|
||||
rfx_timeout[index] = 0;
|
||||
|
@ -443,7 +433,7 @@ gfctrlJoyShutdown(void)
|
|||
for (int index = 0; index < gfctrlJoyPresent; index++) {
|
||||
SDL_JoystickClose(Joysticks[index]);
|
||||
Joysticks[index] = NULL;
|
||||
#if ((SDL_MAJOR_VERSION >= 2) && (SDL_FORCEFEEDBACK))
|
||||
#if SDL_FORCEFEEDBACK
|
||||
if (Haptics[index]) {
|
||||
SDL_HapticClose(Haptics[index]);
|
||||
Haptics[index] = NULL;
|
||||
|
@ -506,7 +496,6 @@ GfctrlJoyIsAnyPresent(void)
|
|||
|
||||
return gfctrlJoyPresent;
|
||||
}
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#if SDL_JOYSTICK
|
||||
int
|
||||
GfctrlSDL2JoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
||||
|
@ -566,7 +555,6 @@ GfctrlSDL2JoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/** Get the current state of the joysticks
|
||||
@ingroup ctrl
|
||||
@param joyInfo Target joystick structure
|
||||
|
@ -577,10 +565,8 @@ GfctrlSDL2JoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
|||
int
|
||||
GfctrlJoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#ifdef SDL_JOYSTICK
|
||||
return GfctrlSDL2JoyGetCurrentStates(joyInfo);
|
||||
#endif
|
||||
#endif
|
||||
int ind;
|
||||
#ifndef SDL_JOYSTICK
|
||||
|
@ -625,24 +611,11 @@ GfctrlJoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
|||
|
||||
// This polling is missing sometimes, skiping buttons or leaving axes stuck on
|
||||
if (Joysticks[ind]) {
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
// poll each axis
|
||||
// note: for SDL2 use events, set in GfctrlJoySetAxis()
|
||||
j = SDL_JoystickNumAxes(Joysticks[ind]);
|
||||
if (j > GFCTRL_JOY_MAX_AXES) j = GFCTRL_JOY_MAX_AXES;
|
||||
|
||||
for (i=0; i < j;i++)
|
||||
joyInfo->ax[GFCTRL_JOY_MAX_AXES * ind + i] = ((float) SDL_JoystickGetAxis(Joysticks[ind],i)) / 32768;
|
||||
#endif
|
||||
|
||||
// read each button
|
||||
j = SDL_JoystickNumButtons(Joysticks[ind]);
|
||||
if (j > GFCTRL_JOY_MAX_BUTTONS) j = GFCTRL_JOY_MAX_BUTTONS;
|
||||
|
||||
for (i=0; i < j;i++) {
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
GfctrlJoySetButton(ind, i, (int) SDL_JoystickGetButton(Joysticks[ind], i));
|
||||
#else
|
||||
// buttons are read set by events, we just pass them up when requested
|
||||
|
||||
if (joyInfo->oldb[GFCTRL_JOY_MAX_BUTTONS * ind + i] == joyInfo->levelup[GFCTRL_JOY_MAX_BUTTONS * ind + i]) {
|
||||
|
@ -653,7 +626,6 @@ GfctrlJoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
|||
|
||||
// store button for next round
|
||||
joyInfo->oldb[GFCTRL_JOY_MAX_BUTTONS * ind + i] = joyInfo->levelup[GFCTRL_JOY_MAX_BUTTONS * ind + i];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,47 +30,6 @@
|
|||
|
||||
static const char* pszNoUnit = 0;
|
||||
|
||||
|
||||
/** Report if a given OpenGL extension is supported
|
||||
|
||||
Warning: Should not be called before any successfull call to SDL_SetVideoMode()
|
||||
|
||||
Note: Copied from freeGLUT 2.4.0
|
||||
*/
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
static bool gfglIsOpenGLExtensionSupported(const char* extension)
|
||||
{
|
||||
const char *extensions, *start;
|
||||
const int len = strlen(extension);
|
||||
|
||||
// TODO: Make sure there is a current window, and thus a current context available
|
||||
|
||||
if (strchr(extension, ' '))
|
||||
return false;
|
||||
|
||||
start = extensions = (const char *)glGetString(GL_EXTENSIONS);
|
||||
|
||||
if (!extensions)
|
||||
return false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
const char *p = strstr(extensions, extension);
|
||||
if (!p)
|
||||
return 0; // Not found
|
||||
|
||||
// Check that the match isn't a super string
|
||||
if ((p == start || p[-1] == ' ') && (p[len] == ' ' || p[len] == 0))
|
||||
return true;
|
||||
|
||||
// Skip the false match and continue
|
||||
extensions = p + len;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// GfglFeatures singleton --------------------------------------------------------
|
||||
|
||||
// Initialization.
|
||||
|
@ -140,11 +99,7 @@ void GfglFeatures::detectStandardSupport()
|
|||
// driver problems and not a bugfix. According to the specification OpenGL should
|
||||
// choose an uncompressed alternate format if it can't provide the requested
|
||||
// compressed one... but it does not on all cards/drivers.
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
bool bValue = SDL_GL_ExtensionSupported("GL_ARB_texture_compression");
|
||||
#else
|
||||
bool bValue = gfglIsOpenGLExtensionSupported("GL_ARB_texture_compression");
|
||||
#endif
|
||||
if (bValue)
|
||||
{
|
||||
int nFormats;
|
||||
|
@ -155,11 +110,7 @@ void GfglFeatures::detectStandardSupport()
|
|||
_mapSupportedBool[TextureCompression] = bValue;
|
||||
|
||||
// 6) Multi-texturing (automatically select all the texturing units).
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
bValue = SDL_GL_ExtensionSupported("GL_ARB_multitexture");
|
||||
#else
|
||||
bValue = gfglIsOpenGLExtensionSupported("GL_ARB_multitexture");
|
||||
#endif
|
||||
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &nValue);
|
||||
if (nValue < 2)
|
||||
bValue = false;
|
||||
|
@ -170,65 +121,35 @@ void GfglFeatures::detectStandardSupport()
|
|||
_mapSupportedInt[MultiTexturingUnits] = nValue;
|
||||
|
||||
// 7) Rectangle textures.
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
_mapSupportedBool[TextureRectangle] =
|
||||
SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle");
|
||||
#else
|
||||
_mapSupportedBool[TextureRectangle] =
|
||||
gfglIsOpenGLExtensionSupported("GL_ARB_texture_rectangle");
|
||||
#endif
|
||||
|
||||
// 8) Non-power-of-2 textures.
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
_mapSupportedBool[TextureNonPowerOf2] =
|
||||
SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two");
|
||||
#else
|
||||
_mapSupportedBool[TextureNonPowerOf2] =
|
||||
gfglIsOpenGLExtensionSupported("GL_ARB_texture_non_power_of_two");
|
||||
#endif
|
||||
|
||||
// 9) Stereo Vision (need a proper check)
|
||||
_mapSupportedBool[StereoVision] = false;
|
||||
|
||||
// 10) Bump Mapping
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
bValue = SDL_GL_ExtensionSupported("GL_ARB_multitexture")
|
||||
&& SDL_GL_ExtensionSupported("GL_ARB_texture_cube_map")
|
||||
&& SDL_GL_ExtensionSupported("GL_ARB_texture_env_combine")
|
||||
&& SDL_GL_ExtensionSupported("GL_ARB_texture_env_dot3")
|
||||
&& SDL_GL_ExtensionSupported("GL_ARB_imaging");
|
||||
#else
|
||||
bValue =
|
||||
gfglIsOpenGLExtensionSupported("GL_ARB_multitexture")
|
||||
&& gfglIsOpenGLExtensionSupported("GL_ARB_texture_cube_map")
|
||||
&& gfglIsOpenGLExtensionSupported("GL_ARB_texture_env_combine")
|
||||
&& gfglIsOpenGLExtensionSupported("GL_ARB_texture_env_dot3")
|
||||
&& gfglIsOpenGLExtensionSupported("GL_ARB_imaging");
|
||||
#endif
|
||||
|
||||
_mapSupportedBool[BumpMapping] = bValue;
|
||||
|
||||
|
||||
// 10) Anisotropic filtrering
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
bValue = SDL_GL_ExtensionSupported("GL_EXT_texture_filter_anisotropic");
|
||||
#else
|
||||
bValue = gfglIsOpenGLExtensionSupported("GL_EXT_texture_filter_anisotropic");
|
||||
#endif
|
||||
|
||||
_mapSupportedInt[AnisotropicFiltering] = bValue?2:InvalidInt;
|
||||
|
||||
// 11) MultiSampling
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
bValue = SDL_GL_ExtensionSupported("GL_ARB_multisample");
|
||||
#else
|
||||
bValue = gfglIsOpenGLExtensionSupported("GL_ARB_multisample");
|
||||
#endif
|
||||
_mapSupportedBool[MultiSampling] = bValue;
|
||||
_mapSupportedInt[MultiSamplingSamples] = bValue?8:InvalidInt; // Good but reasonable value. (8)
|
||||
|
||||
}
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
// Best supported features detection for the given specs of the frame buffer.
|
||||
bool GfglFeatures::detectBestSupportSDL2(int& nWidth, int& nHeight, int& nDepth,
|
||||
bool& bAlpha, bool& bFullScreen, bool& bBumpMapping, bool& bStereoVision, int &nAniFilt)
|
||||
|
@ -480,204 +401,6 @@ bool GfglFeatures::detectBestSupportSDL2(int& nWidth, int& nHeight, int& nDepth,
|
|||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
// Best supported features detection for the given specs of the frame buffer.
|
||||
bool GfglFeatures::detectBestSupport(int& nWidth, int& nHeight, int& nDepth,
|
||||
bool& bAlpha, bool& bFullScreen, bool& bBumpMapping, bool& bStereoVision, int &nAniFilt)
|
||||
{
|
||||
GfLogInfo("Detecting best supported features for a %dx%dx%d%s frame buffer.\n",
|
||||
nWidth, nHeight, nDepth, bFullScreen ? " full-screen" : "");
|
||||
|
||||
// I) Detection of the max possible values for requested features.
|
||||
// (to do that, we need to try setting up the video modes for real).
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
|
||||
SDL_Surface* pWinSurface = 0;
|
||||
|
||||
int nAlphaChannel = bAlpha ? 1 : 0;
|
||||
int nCurrDepth = nDepth;
|
||||
int nFullScreen = bFullScreen ? 1 : 0;
|
||||
int nStereoVision = bStereoVision ? 1 : 0;
|
||||
|
||||
|
||||
while (!pWinSurface && nFullScreen >= 0)
|
||||
{
|
||||
GfLogTrace("Trying %s mode\n", nFullScreen ? "full-screen" : "windowed");
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
// const int bfVideoMode = SDL_WINDOW_OPENGL | (nFullScreen ? SDL_WINDOW_FULLSCREEN : 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
|
||||
#else
|
||||
const int bfVideoMode = SDL_OPENGL | (nFullScreen ? SDL_FULLSCREEN : 0);
|
||||
#endif
|
||||
|
||||
nAlphaChannel = bAlpha ? 1 : 0;
|
||||
while (!pWinSurface && nAlphaChannel >= 0)
|
||||
{
|
||||
GfLogTrace("Trying with%s alpha channel\n", nAlphaChannel ? "" : "out");
|
||||
nCurrDepth = nDepth;
|
||||
while (!pWinSurface && nCurrDepth >= 16)
|
||||
{
|
||||
GfLogTrace("Trying %d bits RVB+A color depth\n", nCurrDepth);
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, nCurrDepth/4);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, nCurrDepth/4);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, nCurrDepth/4);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, (3*nCurrDepth)/4);
|
||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, nAlphaChannel ? nCurrDepth/4 : 0);
|
||||
|
||||
while (!pWinSurface && nStereoVision >= 0)
|
||||
{
|
||||
GfLogTrace("Trying with%s stereo vision\n", nStereoVision ? "" : "out");
|
||||
if (nStereoVision)
|
||||
SDL_GL_SetAttribute(SDL_GL_STEREO, GL_TRUE);
|
||||
else
|
||||
SDL_GL_SetAttribute(SDL_GL_STEREO, GL_FALSE);
|
||||
|
||||
// Anti-aliasing : detect the max supported number of samples
|
||||
// (assumed to be <= 32).
|
||||
int nMaxMultiSamples = 32; // Hard coded max value for the moment.
|
||||
while (!pWinSurface && nMaxMultiSamples > 1)
|
||||
{
|
||||
// Set the anti-aliasing attributes and setup the video mode.
|
||||
GfLogTrace("Trying %dx anti-aliasing\n", nMaxMultiSamples);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, nMaxMultiSamples);
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
SDL_SetWindowSize(GfuiWindow, nWidth, nHeight);
|
||||
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(GfuiWindow, -1, 0);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_GL_CreateContext(GfuiWindow);
|
||||
|
||||
pWinSurface = SDL_CreateRGBSurface(0, nWidth, nHeight, nCurrDepth,
|
||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
0x00FF0000, 0x0000FF00, 0x000000FF,
|
||||
#else
|
||||
0x000000FF, 0x0000FF00, 0x00FF0000,
|
||||
#endif
|
||||
0x00000000);
|
||||
#else
|
||||
pWinSurface = SDL_SetVideoMode(nWidth, nHeight, nCurrDepth, bfVideoMode);
|
||||
#endif
|
||||
|
||||
// Now check if we have a video mode, and if it actually features
|
||||
// what we specified.
|
||||
int nActualSampleBuffers = 0;
|
||||
int nActualMultiSamples = 0;
|
||||
if (pWinSurface) {
|
||||
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &nActualSampleBuffers);
|
||||
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &nActualMultiSamples);
|
||||
}
|
||||
//GfLogDebug("nMaxMultiSamples=%d : nActualSampleBuffers=%d, nActualMultiSamples=%d\n",
|
||||
// nMaxMultiSamples, nActualSampleBuffers, nActualMultiSamples);
|
||||
|
||||
// If not, try a lower number of samples.
|
||||
if (nActualSampleBuffers == 0 || nActualMultiSamples != nMaxMultiSamples)
|
||||
pWinSurface = 0;
|
||||
if (!pWinSurface)
|
||||
{
|
||||
GfLogTrace("%d+%d bit %dx anti-aliased double-buffer not supported\n",
|
||||
3*nCurrDepth/4, nCurrDepth/4, nMaxMultiSamples);
|
||||
nMaxMultiSamples /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Failed : try without anti-aliasing.
|
||||
if (!pWinSurface)
|
||||
{
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
SDL_SetWindowSize(GfuiWindow, nWidth, nHeight);
|
||||
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(GfuiWindow, -1, 0);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_GL_CreateContext(GfuiWindow);
|
||||
|
||||
pWinSurface = SDL_CreateRGBSurface(0, nWidth, nHeight, nCurrDepth,
|
||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
0x00FF0000, 0x0000FF00, 0x000000FF,
|
||||
#else
|
||||
0x000000FF, 0x0000FF00, 0x00FF0000,
|
||||
#endif
|
||||
0x00000000);
|
||||
#else
|
||||
pWinSurface = SDL_SetVideoMode(nWidth, nHeight, nCurrDepth, bfVideoMode);
|
||||
#endif
|
||||
if (!pWinSurface)
|
||||
GfLogTrace("%d+%d bit double-buffer not supported\n",
|
||||
3*nCurrDepth/4, nCurrDepth/4);
|
||||
}
|
||||
|
||||
// Failed : try without StereoVision
|
||||
if (!pWinSurface)
|
||||
nStereoVision--;
|
||||
}
|
||||
|
||||
// Failed : try with lower color depth.
|
||||
if (!pWinSurface)
|
||||
nCurrDepth -= 8;
|
||||
}
|
||||
|
||||
// Failed : try without alpha channel if not already done
|
||||
// (Note: it this really relevant ?).
|
||||
if (!pWinSurface)
|
||||
nAlphaChannel--;
|
||||
}
|
||||
|
||||
// Failed : try a windowed mode if not already done.
|
||||
if (!pWinSurface)
|
||||
nFullScreen--;
|
||||
}
|
||||
|
||||
// Failed : no more idea :-(
|
||||
if (!pWinSurface)
|
||||
{
|
||||
// Reset support data (will result in emptying the section when storing,
|
||||
// thus forcing new detection when checkSupport will be called again).
|
||||
_mapSupportedBool.clear();
|
||||
_mapSupportedInt.clear();
|
||||
|
||||
GfLogError("No supported 'best' video mode found for a %dx%dx%d%s frame buffer.\n",
|
||||
nWidth, nHeight, nDepth, bFullScreen ? " full-screen" : "");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// II) Read-out what we have from the up-and-running frame buffer
|
||||
// and set "supported" values accordingly.
|
||||
|
||||
// 1) Standard features.
|
||||
detectStandardSupport();
|
||||
|
||||
// 2) Multi-sampling = anti-aliasing
|
||||
int nValue;
|
||||
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &nValue);
|
||||
_mapSupportedBool[MultiSampling] = nValue != 0;
|
||||
//GfLogDebug("SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS) = %d\n", nValue);
|
||||
if (nValue)
|
||||
{
|
||||
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &nValue);
|
||||
//GfLogDebug("SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES) = %d\n", nValue);
|
||||
if (nValue > 1)
|
||||
_mapSupportedInt[MultiSamplingSamples] = nValue;
|
||||
else
|
||||
_mapSupportedBool[MultiSampling] = false;
|
||||
}
|
||||
|
||||
// III) Return the updated frame buffer specs.
|
||||
//nWidth = nWidth; // Unchanged.
|
||||
//nHeight = nHeight; // Unchanged.
|
||||
nDepth = nCurrDepth;
|
||||
bFullScreen = nFullScreen ? true : false;
|
||||
bAlpha = nAlphaChannel ? true : false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth,
|
||||
bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, int &nAniFilt,void* hparmConfig)
|
||||
{
|
||||
|
@ -991,11 +714,7 @@ bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth,
|
|||
bDetBump = bBump;
|
||||
nDetAni = nAniFilt;
|
||||
bSupportFound =
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, nDetAni);
|
||||
#else
|
||||
detectBestSupportSDL2(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, nDetAni);
|
||||
#endif
|
||||
|
||||
// Store support data in any case.
|
||||
storeSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, hparm);
|
||||
|
|
|
@ -129,8 +129,6 @@ class TGFCLIENT_API GfglFeatures
|
|||
GfglFeatures();
|
||||
|
||||
// Update supported OpenGL features according to the given frame buffer specs.
|
||||
bool detectBestSupport(int& nWidth, int& nHeight, int& nDepth,
|
||||
bool& bAlpha, bool& bFullScreen, bool& bBump, bool& bStereo, int& nAniFilt);
|
||||
bool detectBestSupportSDL2(int& nWidth, int& nHeight, int& nDepth,
|
||||
bool& bAlpha, bool& bFullScreen, bool& bBump, bool& bStereo, int& nAniFilt);
|
||||
|
||||
|
|
|
@ -137,7 +137,6 @@ tScreenSize* GfScrGetDefaultSizes(int* pnSizes)
|
|||
*/
|
||||
tScreenSize* GfScrGetSupportedSizes(int nColorDepth, bool bFullScreen, int* pnSizes)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
/* Build list of available screen sizes */
|
||||
int avail;
|
||||
SDL_DisplayMode mode;
|
||||
|
@ -228,86 +227,6 @@ tScreenSize* GfScrGetSupportedSizes(int nColorDepth, bool bFullScreen, int* pnSi
|
|||
else {
|
||||
aSuppSizes = NULL;
|
||||
}
|
||||
#else
|
||||
// Query system video capabilities.
|
||||
const SDL_VideoInfo* sdlVideoInfo = SDL_GetVideoInfo();
|
||||
|
||||
if (!sdlVideoInfo)
|
||||
{
|
||||
GfLogWarning("Could not SDL_GetVideoInfo (%s)\n", SDL_GetError());
|
||||
*pnSizes = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get best supported pixel format.
|
||||
SDL_PixelFormat sdlPixelFormat;
|
||||
memcpy(&sdlPixelFormat, &(sdlVideoInfo->vfmt), sizeof(SDL_PixelFormat));
|
||||
|
||||
//sdlPixelFormat.palette = 0;
|
||||
//sdlPixelFormat.BitsPerPixel = ;
|
||||
//sdlPixelFormat.BytesPerPixel = ;
|
||||
//sdlPixelFormat.Rloss = ;
|
||||
//sdlPixelFormat.Gloss = ;
|
||||
//sdlPixelFormat.Bloss = ;
|
||||
//sdlPixelFormat.Aloss = ;
|
||||
//sdlPixelFormat.Rshift = ;
|
||||
//sdlPixelFormat.Gshift = ;
|
||||
//sdlPixelFormat.Bshift = ;
|
||||
//sdlPixelFormat.Ashift = ;
|
||||
//sdlPixelFormat.Rmask = ;
|
||||
//sdlPixelFormat.Gmask = ;
|
||||
//sdlPixelFormat.Bmask = ;
|
||||
//sdlPixelFormat.Amask = ;
|
||||
//sdlPixelFormat.colorkey = ;
|
||||
//sdlPixelFormat.alpha = ;
|
||||
|
||||
// Update the pixel format to match the requested color depth.
|
||||
sdlPixelFormat.BitsPerPixel = nColorDepth;
|
||||
sdlPixelFormat.BytesPerPixel = nColorDepth / 8;
|
||||
|
||||
// Select the requested display mode.
|
||||
Uint32 sdlDisplayMode = SDL_OPENGL;
|
||||
if (bFullScreen)
|
||||
sdlDisplayMode |= SDL_FULLSCREEN;
|
||||
|
||||
// Get the supported sizes for this pixel format.
|
||||
SDL_Rect **asdlSuppSizes = SDL_ListModes(&sdlPixelFormat, sdlDisplayMode);
|
||||
|
||||
GfLogInfo("Available %u-bit %s video sizes :",
|
||||
sdlPixelFormat.BitsPerPixel, bFullScreen ? "full-screen" : "windowed");
|
||||
|
||||
tScreenSize* aSuppSizes;
|
||||
if (asdlSuppSizes == (SDL_Rect**)0)
|
||||
{
|
||||
GfLogInfo(" None.\n");
|
||||
aSuppSizes = (tScreenSize*)0;
|
||||
*pnSizes = 0;
|
||||
}
|
||||
else if (asdlSuppSizes == (SDL_Rect**)-1)
|
||||
{
|
||||
GfLogInfo(" Any.\n");
|
||||
aSuppSizes = (tScreenSize*)-1;
|
||||
*pnSizes = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Count the supported sizes.
|
||||
*pnSizes = 0;
|
||||
while (asdlSuppSizes[*pnSizes])
|
||||
(*pnSizes)++;
|
||||
|
||||
// Copy them into the output array.
|
||||
aSuppSizes = (tScreenSize*)malloc((*pnSizes)*sizeof(tScreenSize));
|
||||
for (int nSizeInd = 0; nSizeInd < *pnSizes; nSizeInd++)
|
||||
{
|
||||
aSuppSizes[nSizeInd].width = asdlSuppSizes[*pnSizes - 1 - nSizeInd]->w;
|
||||
aSuppSizes[nSizeInd].height = asdlSuppSizes[*pnSizes - 1 - nSizeInd]->h;
|
||||
GfLogInfo(" %dx%d,", aSuppSizes[nSizeInd].width, aSuppSizes[nSizeInd].height);
|
||||
}
|
||||
GfLogInfo("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return aSuppSizes;
|
||||
}
|
||||
|
||||
|
@ -330,79 +249,9 @@ int* GfScrGetDefaultColorDepths(int* pnColorDepths)
|
|||
*/
|
||||
int* GfScrGetSupportedColorDepths(int* pnDepths)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
// Need to completely re-write this function
|
||||
*pnDepths = NDefScreenColorDepths;
|
||||
|
||||
return ADefScreenColorDepths;
|
||||
#else
|
||||
// Determine the maximum supported color depth (default to 32 in any case).
|
||||
const SDL_VideoInfo* sdlVideoInfo = SDL_GetVideoInfo();
|
||||
int nMaxColorDepth = 32;
|
||||
if (sdlVideoInfo)
|
||||
{
|
||||
nMaxColorDepth = sdlVideoInfo->vfmt->BitsPerPixel;
|
||||
if (nMaxColorDepth > 32)
|
||||
nMaxColorDepth = 32;
|
||||
}
|
||||
else
|
||||
GfLogWarning("Could not SDL_GetVideoInfo (%s)\n", SDL_GetError());
|
||||
|
||||
// We support a minimum color depth of 16 bits.
|
||||
const int nMinColorDepth = 16;
|
||||
|
||||
// So we can't have more than ... supported color depths.
|
||||
const int nMaxColorDepths = 1 + (nMaxColorDepth - nMinColorDepth) / 8;
|
||||
|
||||
// Check video backend capabilities for each color depth between min and max,
|
||||
// and store in target array if OK.
|
||||
int nSuppSizes;
|
||||
tScreenSize* aSuppSizes;
|
||||
int* aSuppDepths = (int*)malloc(nMaxColorDepths*sizeof(int));
|
||||
*pnDepths = 0;
|
||||
for (int nDepthInd = 0; nDepthInd < nMaxColorDepths; nDepthInd++)
|
||||
{
|
||||
const int nCheckedColorDepth = nMinColorDepth + 8 * nDepthInd;
|
||||
|
||||
// Windowed mode.
|
||||
aSuppSizes = GfScrGetSupportedSizes(nCheckedColorDepth, false, &nSuppSizes);
|
||||
const bool bWindowedOK = (aSuppSizes != 0);
|
||||
if (aSuppSizes && aSuppSizes != (tScreenSize*)-1)
|
||||
free(aSuppSizes);
|
||||
|
||||
// Full-screen mode
|
||||
aSuppSizes = GfScrGetSupportedSizes(nCheckedColorDepth, true, &nSuppSizes);
|
||||
const bool bFullScreenOK = (aSuppSizes != 0);
|
||||
if (aSuppSizes && aSuppSizes != (tScreenSize*)-1)
|
||||
free(aSuppSizes);
|
||||
|
||||
// Keep this color depth if one of the display modes work
|
||||
// TODO: Shouldn't we use "and" here ?
|
||||
if (bWindowedOK || bFullScreenOK)
|
||||
{
|
||||
aSuppDepths[*pnDepths] = nCheckedColorDepth;
|
||||
(*pnDepths)++;
|
||||
}
|
||||
}
|
||||
|
||||
// Report supported depths.
|
||||
if (*pnDepths == 0)
|
||||
{
|
||||
// Fallback : assume at least 24 bit depth is supported.
|
||||
GfLogWarning("SDL reports no supported color depth : assuming 32 bit is OK");
|
||||
aSuppDepths[*pnDepths] = 32;
|
||||
(*pnDepths)++;
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogInfo("Supported color depths (bits) :");
|
||||
for (int nDepthInd = 0; nDepthInd < *pnDepths; nDepthInd++)
|
||||
GfLogInfo(" %d,", aSuppDepths[nDepthInd]);
|
||||
GfLogInfo("\n");
|
||||
}
|
||||
|
||||
return aSuppDepths;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void gfScrReshapeViewport(int width, int height)
|
||||
|
@ -419,7 +268,6 @@ static void gfScrReshapeViewport(int width, int height)
|
|||
GfScrCenX = width / 2;
|
||||
GfScrCenY = height / 2;
|
||||
}
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
|
||||
SDL_Surface* gfScrCreateWindow(int nWinWidth, int nWinHeight, int nTotalDepth,int bfVideoMode)
|
||||
{
|
||||
|
@ -805,370 +653,9 @@ bool GfScrInitSDL2(int nWinWidth, int nWinHeight, int nFullScreen)
|
|||
GfuiApp().eventLoop().postRedisplay();
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool GfScrInitSDL1(int nWinWidth, int nWinHeight, int nFullScreen)
|
||||
{
|
||||
/*if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||
{
|
||||
GfLogError("\nUnable to initialize SDL: (%s)\n", SDL_GetError());
|
||||
return false;
|
||||
}*/
|
||||
|
||||
// Initialize SDL video subsystem (and exit if not supported).
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
GfLogError("Couldn't initialize SDL audio/video sub-system (%s)\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enable unicode translation for SDL key press events, even if already done before
|
||||
// (SDL_InitSubSystem(SDL_INIT_VIDEO) seems to break it).
|
||||
SDL_EnableUNICODE(/*enable=*/1);
|
||||
|
||||
// Set window/icon captions
|
||||
std::ostringstream ossCaption;
|
||||
ossCaption << GfuiApp().name() << ' ' << GfuiApp().version();
|
||||
|
||||
SDL_WM_SetCaption(ossCaption.str().c_str(), ossCaption.str().c_str());
|
||||
|
||||
// Set window icon (MUST be a 32x32 icon for Windows, and with black pixels as alpha ones,
|
||||
// as BMP doesn't support transparency).
|
||||
std::ostringstream ossIconFilename;
|
||||
ossIconFilename << GfDataDir() << "data/icons/icon.bmp";
|
||||
SDL_Surface* surfIcon = SDL_LoadBMP(ossIconFilename.str().c_str());
|
||||
if (surfIcon)
|
||||
{
|
||||
SDL_SetColorKey(surfIcon, SDL_SRCCOLORKEY, SDL_MapRGB(surfIcon->format, 0, 0, 0));
|
||||
SDL_WM_SetIcon(surfIcon, 0);
|
||||
SDL_FreeSurface(surfIcon);
|
||||
}
|
||||
|
||||
// Query system video capabilities.
|
||||
// Note: Does not work very well as long as you don't force SDL to use
|
||||
// a special hardware driver ... which we don't want at all (the default is the one).
|
||||
//typedef struct{
|
||||
// Uint32 hw_available:1;
|
||||
// Uint32 wm_available:1;
|
||||
// Uint32 blit_hw:1;
|
||||
// Uint32 blit_hw_CC:1;
|
||||
// Uint32 blit_hw_A:1;
|
||||
// Uint32 blit_sw:1;
|
||||
// Uint32 blit_sw_CC:1;
|
||||
// Uint32 blit_sw_A:1;
|
||||
// Uint32 blit_fill;
|
||||
// Uint32 video_mem;
|
||||
// SDL_PixelFormat *vfmt;
|
||||
//} SDL_VideoInfo;
|
||||
|
||||
const SDL_VideoInfo* sdlVideoInfo = SDL_GetVideoInfo();
|
||||
|
||||
if (!sdlVideoInfo)
|
||||
{
|
||||
GfLogError("Could not SDL_GetVideoInfo (%s)\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
char pszDriverName[32];
|
||||
GfLogInfo("SDL video backend info :\n");
|
||||
GfLogInfo(" Driver : %s\n", SDL_VideoDriverName(pszDriverName, 32));
|
||||
GfLogInfo(" Maximum color depth : %d bits\n", sdlVideoInfo->vfmt->BitsPerPixel);
|
||||
// These ones don't report actually real values on some configurations.
|
||||
// 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
|
||||
// 1) Load the config file
|
||||
std::ostringstream ossConfigFilename;
|
||||
ossConfigFilename << GfLocalDir() << GFSCR_CONF_FILE;
|
||||
void* hparmScreen =
|
||||
GfParmReadFile(ossConfigFilename.str().c_str(), 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 still 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'
|
||||
else
|
||||
{
|
||||
GfLogInfo("Testing new screen specs : let's see what's happening ...\n");
|
||||
GfParmSetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
|
||||
GFSCR_VAL_INPROGRESS);
|
||||
}
|
||||
|
||||
// Write the config file to disk (in case the forthcoming test makes the game crash,
|
||||
// or in order the Options / Display menu shows the actual current settings).
|
||||
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) Get/Read the specs.
|
||||
if (nWinWidth < 0)
|
||||
nWinWidth =
|
||||
(int)GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_WIN_X, (char*)NULL, 800);
|
||||
if (nWinHeight < 0)
|
||||
nWinHeight =
|
||||
(int)GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_WIN_Y, (char*)NULL, 600);
|
||||
int nTotalDepth =
|
||||
(int)GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_BPP, (char*)NULL, 32);
|
||||
bool bAlphaChannel =
|
||||
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_ALPHACHANNEL,
|
||||
GFSCR_VAL_YES))
|
||||
== GFSCR_VAL_YES;
|
||||
bool bFullScreen;
|
||||
if (nFullScreen < 0)
|
||||
bFullScreen =
|
||||
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_FSCR, GFSCR_VAL_NO))
|
||||
== GFSCR_VAL_YES;
|
||||
else
|
||||
bFullScreen = nFullScreen ? true : false;
|
||||
|
||||
bool bBumpMap =
|
||||
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_BUMPMAPPING,
|
||||
GFSCR_VAL_NO))
|
||||
== GFSCR_VAL_YES;
|
||||
|
||||
int nAniFilt =
|
||||
(int)GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_ANISOTROPICFILTERING, (char*)NULL, 0);
|
||||
|
||||
|
||||
|
||||
bool bStereo =
|
||||
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_STEREOVISION,
|
||||
GFSCR_VAL_NO))
|
||||
== GFSCR_VAL_YES;
|
||||
bool bTryBestVInitMode =
|
||||
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_VINIT,
|
||||
GFSCR_VAL_VINIT_BEST))
|
||||
== GFSCR_VAL_VINIT_BEST;
|
||||
|
||||
// Prepare video mode.
|
||||
int bfVideoMode = SDL_OPENGL;
|
||||
if (bFullScreen)
|
||||
bfVideoMode |= SDL_FULLSCREEN;
|
||||
|
||||
PScreenSurface = NULL;
|
||||
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.
|
||||
// If specified and possible, setup the best possible settings.
|
||||
if (GfglFeatures::self().checkBestSupport(nWinWidth, nWinHeight, nTotalDepth,
|
||||
bAlphaChannel, bFullScreen, bBumpMap, bStereo,nAniFilt,hparmScreen))
|
||||
{
|
||||
// Load Open GL user settings from the config file.
|
||||
GfglFeatures::self().loadSelection();
|
||||
|
||||
// Setup the video mode parameters.
|
||||
const int nColorDepth =
|
||||
GfglFeatures::self().getSelected(GfglFeatures::ColorDepth);
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, nColorDepth/3);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, nColorDepth/3);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, nColorDepth/3);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, nColorDepth);
|
||||
|
||||
const int nAlphaDepth =
|
||||
GfglFeatures::self().getSelected(GfglFeatures::AlphaDepth);
|
||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, nAlphaDepth);
|
||||
|
||||
const int nDoubleBuffer =
|
||||
GfglFeatures::self().isSelected(GfglFeatures::DoubleBuffer) ? 1 : 0;
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, nDoubleBuffer);
|
||||
|
||||
const int nMultiSampling =
|
||||
GfglFeatures::self().isSelected(GfglFeatures::MultiSampling) ? 1 : 0;
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, nMultiSampling);
|
||||
if (nMultiSampling)
|
||||
{
|
||||
const int nMaxMultiSamples =
|
||||
GfglFeatures::self().getSelected(GfglFeatures::MultiSamplingSamples);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, nMaxMultiSamples);
|
||||
}
|
||||
|
||||
const int nStereoVision =
|
||||
GfglFeatures::self().isSelected(GfglFeatures::StereoVision) ? 1 : 0;
|
||||
SDL_GL_SetAttribute(SDL_GL_STEREO, nStereoVision);
|
||||
|
||||
// Try the video mode with these parameters : should always work
|
||||
// (unless you downgraded you hardware / OS and didn't clear your config file).
|
||||
PScreenSurface = SDL_SetVideoMode(nWinWidth, nWinHeight, nTotalDepth, bfVideoMode);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
||||
// Video initialization with generic compatible settings.
|
||||
if (!PScreenSurface)
|
||||
{
|
||||
GfLogInfo("Trying 'default compatible' mode for video initialization.\n");
|
||||
|
||||
// cancel StereoVision
|
||||
SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
|
||||
|
||||
PScreenSurface = SDL_SetVideoMode(nWinWidth, nWinHeight, nTotalDepth, bfVideoMode);
|
||||
if (!PScreenSurface)
|
||||
GfLogTrace("Can't get a %s%dx%dx%d compatible video mode\n",
|
||||
bFullScreen ? "full-screen " : "", nWinWidth, nWinHeight, nTotalDepth);
|
||||
}
|
||||
|
||||
// Failed : Try and remove the full-screen requirement if present ...
|
||||
if (!PScreenSurface && bFullScreen)
|
||||
{
|
||||
bfVideoMode &= ~SDL_FULLSCREEN;
|
||||
PScreenSurface = SDL_SetVideoMode(nWinWidth, nWinHeight, nTotalDepth, bfVideoMode);
|
||||
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 ...
|
||||
if (!PScreenSurface)
|
||||
{
|
||||
nWinWidth = ADefScreenSizes[0].width;
|
||||
nWinHeight = ADefScreenSizes[0].height;
|
||||
PScreenSurface = SDL_SetVideoMode(nWinWidth, nWinHeight, nTotalDepth, bfVideoMode);
|
||||
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 ...
|
||||
if (!PScreenSurface)
|
||||
{
|
||||
nTotalDepth = ADefScreenColorDepths[0];
|
||||
PScreenSurface = SDL_SetVideoMode(nWinWidth, nWinHeight, nTotalDepth, bfVideoMode);
|
||||
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)
|
||||
{
|
||||
GfLogError("Unable to get any compatible video mode"
|
||||
" (fallback resolution / color depth not supported) : giving up !\n\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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 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;
|
||||
GfScrCenX = nWinWidth / 2;
|
||||
GfScrCenY = nWinHeight / 2;
|
||||
|
||||
// Report about selected SDL video mode.
|
||||
GfLogInfo("Selected SDL video mode :\n");
|
||||
GfLogInfo(" Full screen : %s\n", (bfVideoMode & SDL_FULLSCREEN) ? "Yes" : "No");
|
||||
GfLogInfo(" Size : %dx%d\n", nWinWidth, nWinHeight);
|
||||
GfLogInfo(" Color depth : %d bits\n", nTotalDepth);
|
||||
|
||||
// Report about underlying hardware (needs a running frame buffer).
|
||||
GfglFeatures::self().dumpHardwareInfo();
|
||||
|
||||
#ifdef WIN32
|
||||
// Under Windows, give an initial position to the window if not full-screen mode
|
||||
// (under Linux/Mac OS X, no need, the window manager smartly takes care of this).
|
||||
if (!(bfVideoMode & SDL_FULLSCREEN))
|
||||
{
|
||||
// Try to center the game Window on the desktop, but keep the title bar visible if any.
|
||||
const HWND hDesktop = GetDesktopWindow();
|
||||
RECT rectDesktop;
|
||||
GetWindowRect(hDesktop, &rectDesktop);
|
||||
const int nWMWinXPos =
|
||||
nWinWidth >= rectDesktop.right ? 0 : (rectDesktop.right - nWinWidth) / 2;
|
||||
const int nWMWinYPos =
|
||||
nWinHeight >= rectDesktop.bottom ? 0 : (rectDesktop.bottom - nWinHeight) / 2;
|
||||
GfuiInitWindowPositionAndSize(nWMWinXPos, nWMWinYPos, nWinWidth, nWinHeight);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialize the Open GL viewport.
|
||||
gfScrReshapeViewport(nWinWidth, nWinHeight);
|
||||
|
||||
// Setup the event loop about the new display.
|
||||
GfuiApp().eventLoop().setReshapeCB(gfScrReshapeViewport);
|
||||
GfuiApp().eventLoop().postRedisplay();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
bool GfScrInit(int nWinWidth, int nWinHeight, int nFullScreen)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
return GfScrInitSDL2(nWinWidth,nWinHeight,nFullScreen);
|
||||
#else
|
||||
return GfScrInitSDL1(nWinWidth,nWinHeight,nFullScreen);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Shutdown the screen
|
||||
|
@ -1264,7 +751,6 @@ void GfScrGetSize(int *scrW, int *scrH, int *viewW, int *viewH)
|
|||
|
||||
bool GfScrToggleFullScreen()
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
Uint32 flags = SDL_GetWindowFlags(GfuiWindow);
|
||||
|
||||
if ((flags & SDL_WINDOW_FULLSCREEN) || (flags & SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
||||
|
@ -1282,9 +768,6 @@ bool GfScrToggleFullScreen()
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
return SDL_WM_ToggleFullScreen(PScreenSurface) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Capture screen pixels into an RGB buffer (caller must free the here-allocated buffer).
|
||||
|
@ -1349,9 +832,7 @@ int GfScrCaptureAsPNG(const char *filename)
|
|||
return nStatus;
|
||||
}
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
SDL_Window* GfScrGetMainWindow()
|
||||
{
|
||||
return GfuiWindow;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue