Skip to content

Commit

Permalink
If creating window fails, first try to reduce MSAA level, fix #440
Browse files Browse the repository at this point in the history
so if someone configured 16x AA on a system that doesn't support it
(like when using AMDs open source driver), 8x will be tried before
falling back to a 640x480 window with no AA at all.
(and then it'll try 4x and then 2x and then no AA at all, and only then
 reducing color depth will start, and even later it'll fall back to
 a small 640x480 window)
  • Loading branch information
DanielGibson committed Jan 24, 2022
1 parent 815099f commit d09ccb8
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions neo/sys/glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ bool GLimp_Init(glimpParms_t parms) {
int stencilbits = 8;

for (int i = 0; i < 16; i++) {

int multisamples = parms.multiSamples;

// 0 - default
// 1 - minus colorbits
// 2 - minus depthbits
Expand Down Expand Up @@ -226,6 +229,8 @@ bool GLimp_Init(glimpParms_t parms) {

int talphabits = r_waylandcompat.GetBool() ? 0 : channelcolorbits;

try_again:

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, channelcolorbits);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, channelcolorbits);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, channelcolorbits);
Expand All @@ -237,8 +242,8 @@ bool GLimp_Init(glimpParms_t parms) {

SDL_GL_SetAttribute(SDL_GL_STEREO, parms.stereo ? 1 : 0);

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, parms.multiSamples ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, parms.multiSamples);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (multisamples > 1) ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, multisamples);

#if SDL_VERSION_ATLEAST(2, 0, 0)

Expand Down Expand Up @@ -284,9 +289,23 @@ bool GLimp_Init(glimpParms_t parms) {
parms.width, parms.height, flags);

if (!window) {
common->DPrintf("Couldn't set GL mode %d/%d/%d: %s",
channelcolorbits, tdepthbits, tstencilbits, SDL_GetError());
common->Warning("Couldn't set GL mode %d/%d/%d with %dx MSAA: %s",
channelcolorbits, tdepthbits, tstencilbits, parms.multiSamples, SDL_GetError());

// before trying to reduce color channel size or whatever, first try reducing MSAA, if possible
if(multisamples > 1) {
multisamples = (multisamples <= 2) ? 0 : (multisamples/2);

// using goto because enhancing that logic which reduces attributes
// based on i (so it'd first try reducing MSAA) would be too painful
goto try_again;
}

continue;
} else {
// creating the window succeeded, so adjust r_multiSamples to the value that was actually used
parms.multiSamples = multisamples;
r_multiSamples.SetInteger(multisamples);
}

/* Check if we're really in the requested display mode. There is
Expand Down Expand Up @@ -380,7 +399,21 @@ bool GLimp_Init(glimpParms_t parms) {
if (!window) {
common->DPrintf("Couldn't set GL mode %d/%d/%d: %s",
channelcolorbits, tdepthbits, tstencilbits, SDL_GetError());

// before trying to reduce color channel size or whatever, first try reducing MSAA, if possible
if(multisamples > 1) {
multisamples = (multisamples <= 2) ? 0 : (multisamples/2);

// using goto because enhancing that logic which reduces attributes
// based on i (so it'd first try reducing MSAA) would be too painful
goto try_again;
}

continue;
} else {
// creating the window succeeded, so adjust r_multiSamples to the value that was actually used
parms.multiSamples = multisamples;
r_multiSamples.SetInteger(multisamples);
}

glConfig.vidWidth = window->w;
Expand Down

0 comments on commit d09ccb8

Please sign in to comment.