Skip to content

Commit

Permalink
Add display index, size, and aspect to glConfig_t
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed Sep 24, 2024
1 parent 3616cbd commit 44aeb50
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

glstate_t glState;

float displayAspect = 0.0f;

static void GfxInfo_f();

cvar_t *r_glMajorVersion;
Expand Down
2 changes: 0 additions & 2 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2795,8 +2795,6 @@ enum class realtimeLightingRenderer_t { LEGACY, TILED };

extern glstate_t glState; // outside of TR since it shouldn't be cleared during ref re-init

extern float displayAspect; // FIXME

//
// cvars
//
Expand Down
5 changes: 4 additions & 1 deletion src/engine/renderer/tr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ struct glconfig_t

textureCompression_t textureCompression;

int vidWidth, vidHeight;
int displayIndex;
float displayAspect;
int displayWidth, displayHeight; // the entire monitor (the one indicated by displayIndex)
int vidWidth, vidHeight; // what the game is using

bool8_t smpActive; // dual processor
};
Expand Down
15 changes: 9 additions & 6 deletions src/engine/sys/sdl_glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ static int GLimp_CompareModes( const void *a, const void *b )
float aspectB = ( float ) modeB->w / ( float ) modeB->h;
int areaA = modeA->w * modeA->h;
int areaB = modeB->w * modeB->h;
float aspectDiffA = fabsf( aspectA - displayAspect );
float aspectDiffB = fabsf( aspectB - displayAspect );
float aspectDiffA = fabsf( aspectA - glConfig.displayAspect );
float aspectDiffB = fabsf( aspectB - glConfig.displayAspect );
float aspectDiffsDiff = aspectDiffA - aspectDiffB;

if ( aspectDiffsDiff > ASPECT_EPSILON )
Expand Down Expand Up @@ -960,16 +960,18 @@ static rserr_t GLimp_SetModeAndResolution( const int mode )

if ( SDL_GetDesktopDisplayMode( r_displayIndex->integer, &desktopMode ) == 0 )
{
displayAspect = ( float ) desktopMode.w / ( float ) desktopMode.h;
glConfig.displayAspect = ( float ) desktopMode.w / ( float ) desktopMode.h;
logger.Notice( "Display aspect: %.3f", glConfig.displayAspect );
}
else
{
memset( &desktopMode, 0, sizeof( SDL_DisplayMode ) );
displayAspect = 1.333f;
logger.Warn("Cannot determine display aspect, assuming %.3f: %s", displayAspect, SDL_GetError() );
glConfig.displayAspect = 1.333f;
logger.Warn("Cannot determine display aspect, assuming %.3f: %s", glConfig.displayAspect, SDL_GetError() );
}

logger.Notice("Display aspect: %.3f", displayAspect );
glConfig.displayWidth = desktopMode.w;
glConfig.displayHeight = desktopMode.h;

if ( mode == -2 )
{
Expand Down Expand Up @@ -1616,6 +1618,7 @@ static bool GLimp_StartDriverAndSetMode( int mode, bool fullscreen, bool bordere
#endif

AssertCvarRange( r_displayIndex, 0, numDisplays - 1, true );
glConfig.displayIndex = r_displayIndex->integer;

rserr_t err = GLimp_SetMode(mode, fullscreen, bordered);

Expand Down

0 comments on commit 44aeb50

Please sign in to comment.