Commit 422dd09c authored by Manuel Moos's avatar Manuel Moos
Browse files

Merge: Proper high DPI/Retina support

Closes #95

See merge request !123
parents 0ba8c6ff a13d1756
Pipeline #269831483 passed with stages
in 78 minutes and 27 seconds
......@@ -21,6 +21,7 @@ EXTRA_DIST=icons/16x16/armagetronad.png\
armagetronad-armagetronad-handler.desktop.in\
armagetronad-link.xml.in\
armagetronad.protocol.in\
os-x/background.png \
os-x/armagetronad.icns os-x/Info.plist.in\
os-x/armagetronad.icns os-x/background.png\
os-x/armagetronad.icns os-x/armagetronad.icns\
......
......@@ -20,6 +20,9 @@
<key>NSHumanReadableCopyright</key>
<string>© The Armagetron Advanced Developer Team, 2003, 2013</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>CFBundleShortVersionString</key>
<string>@version@</string>
......
......@@ -68,7 +68,12 @@ SDL_GLContext sr_glcontext=NULL;
SDL_Surface *sr_screen=NULL; // our window
#endif
#ifndef DEDICATED
#if ! SDL_VERSION_ATLEAST(2,0,1)
// this flag was introduced in 2.0.1, we can live without
#define SDL_WINDOW_ALLOW_HIGHDPI 0
#endif
#ifndef DEDICATED
#ifndef SDL_OPENGL
#error "need SDL 1.1"
#endif
......@@ -83,7 +88,13 @@ static int width[ArmageTron_Custom+2] = {0, 320, 320, 400, 512, 640, 800, 1024
static int height[ArmageTron_Custom+2] = {0, 200, 240, 300, 384, 480, 600, 768 , 800, 854, 1024, 1200, 1050, 1572,600,200};
static REAL aspect[ArmageTron_Custom+2]= {1, 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1, 1, 1 , 1, 1, 1,1, 1};
int sr_screenWidth,sr_screenHeight;
// screen/window dimensions in pixels
int sr_screenWidth{960},sr_screenHeight{540};
// screen/window dimensions in whatever the system uses for screen coordinates (points/pixels)
int sr_screenWidthInPoints{960},sr_screenHeightInPoints{540};
static tSettingItem<int> at_ch("CUSTOM_SCREEN_HEIGHT" , height[ArmageTron_Custom]);
static tSettingItem<int> at_cw("CUSTOM_SCREEN_WIDTH" , width [ArmageTron_Custom]);
......@@ -91,7 +102,7 @@ static tSettingItem<REAL> at_ca("CUSTOM_SCREEN_ASPECT" , aspect[ArmageTron_Custo
#define MAXEMERGENCY 7
rScreenSettings lastSuccess(ArmageTron_640_480, false);
rScreenSettings lastSuccess(ArmageTron_Desktop, true);
rScreenSettings lastSuccessLowZBuffer(ArmageTron_640_480, false);
rScreenSettings lastSuccessLowColor(ArmageTron_640_480, false);
......@@ -595,8 +606,8 @@ static bool lowlevel_sr_InitDisplay(){
currentScreensetting.aspect = aspect[res.res];
res.UpdateSize();
sr_screenWidth = res.width;
sr_screenHeight= res.height;
sr_screenWidthInPoints = res.width;
sr_screenHeightInPoints= res.height;
// desktop color depth
static int desktopCD_R = 8;
......@@ -672,8 +683,8 @@ static bool lowlevel_sr_InitDisplay(){
int defaultHeight = sr_desktopHeight;
if(!currentScreensetting.fullscreen)
{
defaultWidth = sr_screenWidth;
defaultHeight = sr_screenHeight;
defaultWidth = sr_screenWidthInPoints;
defaultHeight = sr_screenHeightInPoints;
}
int defaultX = screenBounds.x + (screenBounds.w-defaultWidth)/2;
......@@ -737,16 +748,16 @@ static bool lowlevel_sr_InitDisplay(){
sr_SetGLAttributes( singleCD_R, singleCD_G, singleCD_B, zDepth );
int attrib=SDL_WINDOW_OPENGL;
int attrib=SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI;
SDL_SetRelativeMouseMode(SDL_FALSE);
#ifdef FORCE_WINDOW
#ifdef WIN32
// sr_screenWidth = 400;
// sr_screenHeight = 300;
// sr_screenWidthInPoints = 400;
// sr_screenHeightInPoints = 300;
#else
// sr_screenWidth = minWidth;
// sr_screenHeight = minHeight;
// sr_screenWidthInPoints = minWidth;
// sr_screenHeightInPoints = minHeight;
#endif
#endif
// int CD = fullCD;
......@@ -804,27 +815,29 @@ static bool lowlevel_sr_InitDisplay(){
// SDL2 can resize window or toggle fullscreen without recreating a new window and therefore keeping existing GL context.
if (currentScreensetting.fullscreen)
{
bool fullscreenSuccess = false;
bool fullscreenSuccess = true;
// do we need a custom display mode? if a display mode
// is set, yes, but also if a non-default custom refresh rate
// is set.
if ( sr_screenWidth + sr_screenHeight > 0 || (currentScreensetting.refreshRate != desktopMode.refresh_rate && currentScreensetting.refreshRate > 0))
if ( sr_screenWidthInPoints + sr_screenHeightInPoints > 0 || (currentScreensetting.refreshRate != desktopMode.refresh_rate && currentScreensetting.refreshRate > 0))
{
fullscreenSuccess = false;
// find best display mode
SDL_DisplayMode desiredMode, mode, lastMode;
desiredMode.format = 0;
desiredMode.w = sr_screenWidth;
desiredMode.h = sr_screenHeight;
if ( sr_screenWidth + sr_screenHeight <= 0)
desiredMode.w = sr_screenWidthInPoints;
desiredMode.h = sr_screenHeightInPoints;
if ( sr_screenWidthInPoints + sr_screenHeightInPoints <= 0)
{
desiredMode.w = desktopMode.w;
desiredMode.h = desktopMode.h;
}
else
{
desiredMode.w = sr_screenWidth;
desiredMode.h = sr_screenHeight;
desiredMode.w = sr_screenWidthInPoints;
desiredMode.h = sr_screenHeightInPoints;
}
desiredMode.refresh_rate = currentScreensetting.refreshRate;
desiredMode.driverdata = NULL;
......@@ -843,14 +856,14 @@ static bool lowlevel_sr_InitDisplay(){
}
// set the display mode
sr_screenWidth = closest->w;
sr_screenHeight = closest->h;
sr_screenWidthInPoints = closest->w;
sr_screenHeightInPoints = closest->h;
if(0 == SDL_SetWindowDisplayMode(sr_screen, closest))
{
SDL_Delay(100);
SDL_PumpEvents();
SDL_SetWindowSize(sr_screen, sr_screenWidth, sr_screenHeight);
SDL_SetWindowSize(sr_screen, sr_screenWidthInPoints, sr_screenHeightInPoints);
SDL_Delay(100);
SDL_PumpEvents();
fullscreenSuccess = (0 == SDL_SetWindowFullscreen(sr_screen, SDL_WINDOW_FULLSCREEN));
......@@ -865,17 +878,22 @@ static bool lowlevel_sr_InitDisplay(){
std::cerr << lastError << '\n';
}
}
else
{
// simply set fullscreen mode
fullscreenSuccess = (0 == SDL_SetWindowFullscreen(sr_screen, SDL_WINDOW_FULLSCREEN_DESKTOP));
}
// if desktop resolution was selected or custom mode setting failed, pick desktop mode
// if desktop resolution was selected or custom mode setting failed, pick desktop mode with explicit resolution
if(!fullscreenSuccess)
{
sr_screenWidth = sr_desktopWidth;
sr_screenHeight = sr_desktopHeight;
sr_screenWidthInPoints = sr_desktopWidth;
sr_screenHeightInPoints = sr_desktopHeight;
SDL_SetWindowFullscreen(sr_screen, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_SetWindowFullscreen(sr_screen, 0);
SDL_Delay(100);
SDL_PumpEvents();
SDL_SetWindowSize(sr_screen, sr_screenWidth, sr_screenHeight);
SDL_SetWindowSize(sr_screen, sr_screenWidthInPoints, sr_screenHeightInPoints);
SDL_Delay(100);
SDL_PumpEvents();
fullscreenSuccess = (0 == SDL_SetWindowFullscreen(sr_screen, SDL_WINDOW_FULLSCREEN_DESKTOP));
......@@ -894,8 +912,8 @@ static bool lowlevel_sr_InitDisplay(){
currentScreensetting.fullscreen = false;
sr_screenWidth = currentScreensetting.windowSize.width;
sr_screenHeight = currentScreensetting.windowSize.height;
sr_screenWidthInPoints = currentScreensetting.windowSize.width;
sr_screenHeightInPoints = currentScreensetting.windowSize.height;
}
}
if (!currentScreensetting.fullscreen)
......@@ -903,7 +921,7 @@ static bool lowlevel_sr_InitDisplay(){
// Set windowed mode and size accordingly
if (!SDL_SetWindowFullscreen(sr_screen, 0))
{
SDL_SetWindowSize(sr_screen, sr_screenWidth, sr_screenHeight);
SDL_SetWindowSize(sr_screen, sr_screenWidthInPoints, sr_screenHeightInPoints);
SDL_SetWindowPosition(sr_screen, defaultX, defaultY);
SDL_SetRelativeMouseMode(SDL_FALSE);
}
......@@ -1102,8 +1120,8 @@ static bool lowlevel_sr_InitDisplay(){
currentScreensetting.aspect = aspect[res.res];
res.UpdateSize();
sr_screenWidth = res.width;
sr_screenHeight= res.height;
sr_screenWidthInPoints = res.width;
sr_screenHeightInPoints= res.height;
// desktop color depth
static int desktopCD_R = 5;
......@@ -1192,7 +1210,7 @@ static bool lowlevel_sr_InitDisplay(){
/*
#ifdef POWERPAK_DEB
PD_SetGFXMode(sr_screenWidth, sr_screenHeight, 32, PD_DEFAULT);
PD_SetGFXMode(sr_screenWidthInPoints, sr_screenHeightInPoints, 32, PD_DEFAULT);
sr_screen=DoubleBuffer;
#else
*/
......@@ -1212,29 +1230,29 @@ static bool lowlevel_sr_InitDisplay(){
#ifdef FORCE_WINDOW
#ifdef WIN32
// sr_screenWidth = 400;
// sr_screenHeight = 300;
// sr_screenWidthInPoints = 400;
// sr_screenHeightInPoints = 300;
#else
// sr_screenWidth = minWidth;
// sr_screenHeight = 480;
// sr_screenWidthInPoints = minWidth;
// sr_screenHeightInPoints = 480;
#endif
#endif
int CD = fullCD;
// only check for errors if requested and if we're not about to set the
// desktop resolution, where SDL_VideoModeOK apparently doesn't work.
if (currentScreensetting.checkErrors && sr_screenWidth + sr_screenHeight > 0)
if (currentScreensetting.checkErrors && sr_screenWidthInPoints + sr_screenHeightInPoints > 0)
{
// check if the video mode should be OK:
CD = SDL_VideoModeOK
(sr_screenWidth, sr_screenHeight, fullCD,
(sr_screenWidthInPoints, sr_screenHeightInPoints, fullCD,
attrib);
// if not quite right
if (CD < 15){
// check if the other fs/windowed mode is better
int CD_fsinv = SDL_VideoModeOK
(sr_screenWidth, sr_screenHeight, fullCD,
(sr_screenWidthInPoints, sr_screenHeightInPoints, fullCD,
attrib^SDL_FULLSCREEN);
if (CD_fsinv >= 15){
......@@ -1254,10 +1272,10 @@ static bool lowlevel_sr_InitDisplay(){
}
// if desktop resolution was selected, pick it
if ( sr_screenWidth + sr_screenHeight == 0 )
if ( sr_screenWidthInPoints + sr_screenHeightInPoints == 0 )
{
sr_screenWidth = sr_desktopWidth;
sr_screenHeight = sr_desktopHeight;
sr_screenWidthInPoints = sr_desktopWidth;
sr_screenHeightInPoints = sr_desktopHeight;
}
else
{
......@@ -1267,8 +1285,8 @@ static bool lowlevel_sr_InitDisplay(){
// only reinit the screen if the desktop res detection hasn't left us
// with a perfectly good one.
if ( !sr_screen && (sr_screen=SDL_SetVideoMode (sr_screenWidth, sr_screenHeight, CD, attrib)) == NULL) {
if((sr_screen=SDL_SetVideoMode (sr_screenWidth, sr_screenHeight, CD, attrib^SDL_FULLSCREEN))==NULL ) {
if ( !sr_screen && (sr_screen=SDL_SetVideoMode (sr_screenWidthInPoints, sr_screenHeightInPoints, CD, attrib)) == NULL) {
if((sr_screen=SDL_SetVideoMode (sr_screenWidthInPoints, sr_screenHeightInPoints, CD, attrib^SDL_FULLSCREEN))==NULL ) {
lastError.Clear();
lastError << "Couldn't set video mode: ";
lastError << SDL_GetError();
......@@ -1501,23 +1519,30 @@ bool sr_InitDisplay(){
#endif
#endif
sr_LockSDL();
if (lowlevel_sr_InitDisplay())
auto Success = [&]()
{
sr_GetDrawableSize();
sr_UnlockSDL();
failed_attempts = 0;
st_SaveConfig();
return true;
};
sr_screenWidth = sr_screenWidthInPoints;
sr_screenHeight = sr_screenHeightInPoints;
sr_LockSDL();
if (lowlevel_sr_InitDisplay())
{
return Success();
}
st_SaveConfig();
if (lowlevel_sr_InitDisplay())
{
sr_UnlockSDL();
failed_attempts = 0;
st_SaveConfig();
return true;
return Success();
}
sr_UnlockSDL();
......@@ -1566,6 +1591,22 @@ void sr_ExitDisplay(){
#endif
}
void sr_GetDrawableSize()
{
#ifndef DEDICATED
#if SDL_VERSION_ATLEAST(2,0,1)
if(sr_screen)
{
SDL_GL_GetDrawableSize(sr_screen, &sr_screenWidth, &sr_screenHeight);
return;
}
#endif
sr_screenWidth = sr_screenWidthInPoints;
sr_screenHeight = sr_screenHeightInPoints;
#endif
}
bool sr_alphaBlend=true;
bool sr_glOut=true;
bool sr_smoothShading=true;
......
......@@ -103,6 +103,7 @@ struct SDL_Surface;
extern SDL_Surface *sr_screen;
#endif
// screen/window dimensions in pixels
extern int sr_screenWidth,sr_screenHeight;
extern bool sr_alphaBlend;
......@@ -198,6 +199,7 @@ public:
bool sr_InitDisplay();
void sr_ExitDisplay();
void sr_ReinitDisplay();
void sr_GetDrawableSize();
void sr_LoadDefaultConfig();
......
......@@ -679,8 +679,7 @@ public:
}
#endif
sr_GetDrawableSize();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment