From 56e5a95cb66266341f8d5a79390d570897752727 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 21 Jan 2026 00:38:17 +0500 Subject: [PATCH] engine: platform: sdl2: add command vid_info to dump current SDL window state --- engine/client/vid_common.c | 1 + engine/platform/platform.h | 1 + engine/platform/sdl2/vid_sdl2.c | 61 ++++++++++++++++++++++++++++----- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index 7f06b0c3..5d5e3fc2 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -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 diff --git a/engine/platform/platform.h b/engine/platform/platform.h index 7eb0bca8..1f7cac4f 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -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 diff --git a/engine/platform/sdl2/vid_sdl2.c b/engine/platform/sdl2/vid_sdl2.c index cad2525e..d7a400b9 100644 --- a/engine/platform/sdl2/vid_sdl2.c +++ b/engine/platform/sdl2/vid_sdl2.c @@ -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( )); +}