engine: platform: sdl2: add command vid_info to dump current SDL window state

This commit is contained in:
Alibek Omarov
2026-01-21 01:58:38 +05:00
parent 214b133e5d
commit 56e5a95cb6
3 changed files with 54 additions and 9 deletions
+1
View File
@@ -224,6 +224,7 @@ void VID_Init( void )
// a1ba: planned to be named vid_mode for compability
// but supported mode list is filled by backends, so numbers are not portable any more
Cmd_AddRestrictedCommand( "vid_setmode", VID_Mode_f, "display video mode" );
Cmd_AddCommand( "vid_info", VID_Info_f, "show vid component info" );
V_Init(); // init gamma
R_Init(); // init renderer
+1
View File
@@ -339,6 +339,7 @@ void SW_UnlockBuffer( void );
qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b );
void Platform_Minimize_f( void );
ref_window_type_t R_GetWindowHandle( void **handle, ref_window_type_t type );
void VID_Info_f( void );
//
// in_evdev.c
+52 -9
View File
@@ -389,20 +389,24 @@ static qboolean GL_DeleteContext( void )
return false;
}
static void VID_GetWindowSizeInPixels( SDL_Window *window, SDL_Renderer *renderer, int *w, int *h )
{
#if SDL_VERSION_ATLEAST( 2, 26, 0 )
SDL_GetWindowSizeInPixels( window, w, h );
#else
if( glw_state.software )
SDL_GetRendererOutputSize( renderer, w, h );
else
SDL_GL_GetDrawableSize( window, w, h );
#endif
}
void VID_SaveWindowSize( int width, int height )
{
qboolean maximized = FBitSet( SDL_GetWindowFlags( host.hWnd ), SDL_WINDOW_MAXIMIZED );
int render_w = width, render_h = height;
#if SDL_VERSION_ATLEAST( 2, 26, 0 )
SDL_GetWindowSizeInPixels( host.hWnd, &render_w, &render_h );
#else
if( glw_state.software )
SDL_GetRendererOutputSize( sw.renderer, &render_w, &render_h );
else
SDL_GL_GetDrawableSize( host.hWnd, &render_w, &render_h );
#endif
VID_GetWindowSizeInPixels( host.hWnd, sw.renderer, &render_w, &render_h );
VID_SetDisplayTransform( &render_w, &render_h );
R_SaveVideoMode( width, height, render_w, render_h, maximized );
}
@@ -875,6 +879,8 @@ static qboolean VID_CreateWindow( const int input_width, const int input_height,
Cvar_DirectSetValue( &window_ypos, rect.y );
}
VID_Info_f();
return true;
}
@@ -1253,3 +1259,40 @@ void R_Free_Video( void )
ref.dllFuncs.GL_ClearExtensions();
}
void VID_Info_f( void )
{
Uint32 flags = SDL_GetWindowFlags( host.hWnd );
int width, height;
int render_width, render_height;
int x, y;
int display_index;
SDL_DisplayMode dm;
SDL_GetWindowSize( host.hWnd, &width, &height );
VID_GetWindowSizeInPixels( host.hWnd, sw.renderer, &render_width, &render_height );
SDL_GetWindowPosition( host.hWnd, &x, &y );
Con_Printf( "Video: " S_GREEN "SDL" S_DEFAULT "\n" );
Con_Printf( "Video driver: " S_GREEN "%s" S_DEFAULT "\n", SDL_GetCurrentVideoDriver( ));
Con_Printf( "Window size: " S_GREEN "%dx%d" S_DEFAULT " (" S_YELLOW"real %dx%d" S_DEFAULT")\n", width, height, render_width, render_height );
Con_Printf( "Window position: " S_GREEN "%dx%d" S_DEFAULT "\n", x, y );
Con_Printf( "Window mode: %s" S_DEFAULT "\n",
FBitSet( flags, SDL_WINDOW_FULLSCREEN_DESKTOP ) ? S_GREEN "fullscreen desktop" :
FBitSet( flags, SDL_WINDOW_FULLSCREEN ) ? S_YELLOW "fullscreen" :
S_CYAN "windowed" );
Con_Printf( "Window bordered: %s" S_DEFAULT "\n", FBitSet( flags, SDL_WINDOW_BORDERLESS ) ? S_RED "false" : S_GREEN "true" );
Con_Printf( "Window resizable: %s" S_DEFAULT "\n", FBitSet( flags, SDL_WINDOW_RESIZABLE ) ? S_GREEN "true" : S_RED "false" );
Con_Printf( "Window maximized: %s" S_DEFAULT "\n", FBitSet( flags, SDL_WINDOW_MAXIMIZED ) ? S_GREEN "true" : S_RED "false" );
display_index = SDL_GetWindowDisplayIndex( host.hWnd );
if( display_index >= 0 )
Con_Printf( "Window display index: " S_GREEN "%d" S_DEFAULT "\n", display_index );
else
Con_Printf( "Window display index: " S_RED "fail: " S_DEFAULT "%s\n", SDL_GetError( ));
if( SDL_GetWindowDisplayMode( host.hWnd, &dm ) >= 0 )
Con_Printf( "Window display mode: " S_GREEN "%dx%d@%d" S_DEFAULT "\n", dm.w, dm.h, dm.refresh_rate );
else
Con_Printf( "Window display mode: " S_RED "fail: " S_DEFAULT "%s\n", SDL_GetError( ));
}