Browse Source

Remove vid_mode. VID_GetModeString now returns only supported modes from SDL2

pull/2/head
Alibek Omarov 7 years ago
parent
commit
3f2a8f7704
  1. 2
      common/defaults.h
  2. 3
      engine/client/gl_local.h
  3. 2
      engine/client/in_touch.c
  4. 10
      engine/client/vgui/vgui_draw.c
  5. 167
      engine/client/vid_common.c
  6. 11
      engine/client/vid_common.h
  7. 17
      engine/platform/sdl/events.c
  8. 321
      engine/platform/sdl/vid_sdl.c
  9. 5
      vgui_support/vgui_surf.cpp

2
common/defaults.h

@ -147,7 +147,7 @@ Default build-depended cvar and constant values @@ -147,7 +147,7 @@ Default build-depended cvar and constant values
#endif
#ifndef DEFAULT_FULLSCREEN
#define DEFAULT_FULLSCREEN 1
#define DEFAULT_FULLSCREEN 1
#endif
#if TARGET_OS_IPHONE

3
engine/client/gl_local.h

@ -574,7 +574,6 @@ typedef struct @@ -574,7 +574,6 @@ typedef struct
qboolean softwareGammaUpdate;
int prev_width;
int prev_height;
int prev_mode;
} glconfig_t;
typedef struct
@ -667,12 +666,10 @@ extern convar_t *vid_displayfrequency; @@ -667,12 +666,10 @@ extern convar_t *vid_displayfrequency;
extern convar_t *vid_fullscreen;
extern convar_t *vid_brightness;
extern convar_t *vid_gamma;
extern convar_t *vid_mode;
extern convar_t *vid_highdpi;
extern convar_t *window_xpos;
extern convar_t *window_ypos;
extern convar_t *scr_width;
extern convar_t *scr_height;
#endif//GL_LOCAL_H

2
engine/client/in_touch.c

@ -1697,7 +1697,7 @@ int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx @@ -1697,7 +1697,7 @@ int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx
Key_Event( K_MOUSE1, true );
if( type == event_up )
Key_Event( K_MOUSE1, false );
Android_AddMove( dx * scr_width->value, dy * scr_height->value );
Android_AddMove( dx * (float)glState.width, dy * glState.height );
#endif
return 0;
}

10
engine/client/vgui/vgui_draw.c

@ -24,17 +24,17 @@ GNU General Public License for more details. @@ -24,17 +24,17 @@ GNU General Public License for more details.
#include "library.h"
#include "keydefs.h"
#include "gl_local.h"
#ifdef XASH_SDL
#include <SDL_events.h>
static SDL_Cursor* s_pDefaultCursor[20];
#endif
int g_textures[VGUI_MAX_TEXTURES];
int g_textureId = 0;
int g_iBoundTexture;
static enum VGUI_KeyCode s_pVirtualKeyTrans[256];
static enum VGUI_DefaultCursor s_currentCursor;
#ifdef XASH_SDL
#include <SDL_events.h>
static SDL_Cursor* s_pDefaultCursor[20];
#endif
static void *s_pVGuiSupport; // vgui_support library
static HINSTANCE s_pVGuiSupport; // vgui_support library
static convar_t *vgui_utf8 = NULL;
void VGUI_DrawInit( void );

167
engine/client/vid_common.c

@ -41,8 +41,6 @@ convar_t *gl_test; @@ -41,8 +41,6 @@ convar_t *gl_test;
convar_t *gl_msaa;
convar_t *gl_stencilbits;
convar_t *scr_width;
convar_t *scr_height;
convar_t *window_xpos;
convar_t *window_ypos;
convar_t *r_speeds;
@ -68,7 +66,6 @@ convar_t *vid_displayfrequency; @@ -68,7 +66,6 @@ convar_t *vid_displayfrequency;
convar_t *vid_fullscreen;
convar_t *vid_brightness;
convar_t *vid_gamma;
convar_t *vid_mode;
convar_t *vid_highdpi;
byte *r_temppool;
@ -236,39 +233,19 @@ R_SaveVideoMode @@ -236,39 +233,19 @@ R_SaveVideoMode
*/
void R_SaveVideoMode( int w, int h )
{
host.window_center_x = glState.width / 2;
host.window_center_y = glState.height / 2;
glState.width = w;
glState.height = h;
Cvar_FullSet( "width", va( "%i", w ), FCVAR_READ_ONLY | FCVAR_RENDERINFO );
Cvar_FullSet( "height", va( "%i", h ), FCVAR_READ_ONLY | FCVAR_RENDERINFO );
if( vid_mode->value >= 0 && vid_mode->value <= R_MaxVideoModes() )
glState.wideScreen = R_GetVideoMode( vid_mode->value ).wideScreen;
MsgDev( D_NOTE, "Set: [%dx%d]\n", w, h );
}
/*
=================
R_DescribeVIDMode
=================
*/
qboolean R_DescribeVIDMode( int width, int height )
{
int i;
for( i = 0; i < R_MaxVideoModes(); i++ )
{
vidmode_t vidmode = R_GetVideoMode( i );
if( vidmode.width == width && vidmode.height == height )
{
// found specified mode
Cvar_SetValue( "vid_mode", i );
return true;
}
}
Cvar_SetValue( "width", w );
Cvar_SetValue( "height", h );
return false;
// check for 4:3 or 5:4
if( w * 3 != h * 4 && w * 4 != h * 5 )
glState.wideScreen = true;
else glState.wideScreen = false;
}
/*
@ -302,15 +279,15 @@ void VID_CheckChanges( void ) @@ -302,15 +279,15 @@ void VID_CheckChanges( void )
if( host.renderinfo_changed )
{
if( !VID_SetMode( ))
if( VID_SetMode( ))
{
Sys_Error( "Can't re-initialize video subsystem\n" );
SCR_VidInit(); // tell the client.dll what vid_mode has changed
}
else
{
host.renderinfo_changed = false;
SCR_VidInit(); // tell the client.dll what vid_mode has changed
Sys_Error( "Can't re-initialize video subsystem\n" );
}
host.renderinfo_changed = false;
}
}
@ -397,13 +374,43 @@ void R_RenderInfo_f( void ) @@ -397,13 +374,43 @@ void R_RenderInfo_f( void )
}
Con_Printf( "\n" );
Con_Printf( "MODE: %s\n", R_GetVideoMode(vid_mode->value).desc );
Con_Printf( "MODE: %ix%i\n", glState.width, glState.height );
Con_Printf( "\n" );
Con_Printf( "VERTICAL SYNC: %s\n", gl_vsync->value ? "enabled" : "disabled" );
Con_Printf( "Color %d bits, Alpha %d bits, Depth %d bits, Stencil %d bits\n", glConfig.color_bits,
glConfig.alpha_bits, glConfig.depth_bits, glConfig.stencil_bits );
}
static void VID_Mode_f( void )
{
int w, h;
switch( Cmd_Argc() )
{
case 2:
{
vidmode_t vidmode;
vidmode = R_GetVideoMode( Q_atoi( Cmd_Argv( 1 )) );
w = vidmode.width;
h = vidmode.height;
break;
}
case 3:
{
w = Q_atoi( Cmd_Argv( 1 ));
h = Q_atoi( Cmd_Argv( 2 ));
break;
}
default:
Msg( "Usage: vid_mode <modenum>|<width height>\n" );
return;
}
R_ChangeDisplaySettings( w, h, Cvar_VariableInteger( "fullscreen" ) );
}
//=======================================================================
/*
@ -414,8 +421,8 @@ GL_InitCommands @@ -414,8 +421,8 @@ GL_InitCommands
void GL_InitCommands( void )
{
// system screen width and height (don't suppose for change from console at all)
scr_width = Cvar_Get( "width", "640", FCVAR_RENDERINFO, "screen width" );
scr_height = Cvar_Get( "height", "480", FCVAR_RENDERINFO, "screen height" );
Cvar_Get( "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" );
Cvar_Get( "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" );
r_speeds = Cvar_Get( "r_speeds", "0", FCVAR_ARCHIVE, "shows renderer speeds" );
r_fullbright = Cvar_Get( "r_fullbright", "0", FCVAR_CHEAT, "disable lightmaps, get fullbright for entities" );
r_norefresh = Cvar_Get( "r_norefresh", "0", 0, "disable 3D rendering (use with caution)" );
@ -461,14 +468,17 @@ void GL_InitCommands( void ) @@ -461,14 +468,17 @@ void GL_InitCommands( void )
SetBits( gl_vsync->flags, FCVAR_CHANGED );
vid_gamma = Cvar_Get( "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" );
vid_brightness = Cvar_Get( "brightness", "0.0", FCVAR_ARCHIVE, "brighntess factor" );
vid_mode = Cvar_Get( "vid_mode", "-1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "display resolution mode" );
vid_brightness = Cvar_Get( "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" );
vid_fullscreen = Cvar_Get( "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" );
vid_displayfrequency = Cvar_Get ( "vid_displayfrequency", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "fullscreen refresh rate" );
vid_highdpi = Cvar_Get( "vid_highdpi", "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "Enable High-DPI mode" );
vid_highdpi = Cvar_Get( "vid_highdpi", "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" );
Cmd_AddCommand( "r_info", R_RenderInfo_f, "display renderer info" );
// 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_AddCommand( "vid_setmode", VID_Mode_f, "display video mode" );
// give initial OpenGL configuration
host.apply_opengl_config = true;
Cbuf_AddText( "exec opengl.cfg\n" );
@ -490,72 +500,9 @@ void GL_RemoveCommands( void ) @@ -490,72 +500,9 @@ void GL_RemoveCommands( void )
Cmd_RemoveCommand( "r_info");
}
#ifdef WIN32
typedef enum _XASH_DPI_AWARENESS
{
XASH_DPI_UNAWARE = 0,
XASH_SYSTEM_DPI_AWARE = 1,
XASH_PER_MONITOR_DPI_AWARE = 2
} XASH_DPI_AWARENESS;
void WIN_SetDPIAwareness( void )
{
HMODULE hModule;
HRESULT ( __stdcall *pSetProcessDpiAwareness )( XASH_DPI_AWARENESS );
BOOL ( __stdcall *pSetProcessDPIAware )( void );
BOOL bSuccess = FALSE;
if( ( hModule = LoadLibrary( "shcore.dll" ) ) )
{
if( ( pSetProcessDpiAwareness = (void*)GetProcAddress( hModule, "SetProcessDpiAwareness" ) ) )
{
// I hope SDL don't handle WM_DPICHANGED message
HRESULT hResult = pSetProcessDpiAwareness( XASH_SYSTEM_DPI_AWARE );
if( hResult == S_OK )
{
MsgDev( D_NOTE, "SetDPIAwareness: Success\n" );
bSuccess = TRUE;
}
else if( hResult = E_INVALIDARG ) MsgDev( D_NOTE, "SetDPIAwareness: Invalid argument\n" );
else if( hResult == E_ACCESSDENIED ) MsgDev( D_NOTE, "SetDPIAwareness: Access Denied\n" );
}
else MsgDev( D_NOTE, "SetDPIAwareness: Can't get SetProcessDpiAwareness\n" );
FreeLibrary( hModule );
}
else MsgDev( D_NOTE, "SetDPIAwareness: Can't load shcore.dll\n" );
if( !bSuccess )
{
MsgDev( D_NOTE, "SetDPIAwareness: Trying SetProcessDPIAware...\n" );
if( ( hModule = LoadLibrary( "user32.dll" ) ) )
{
if( ( pSetProcessDPIAware = ( void* )GetProcAddress( hModule, "SetProcessDPIAware" ) ) )
{
// I hope SDL don't handle WM_DPICHANGED message
BOOL hResult = pSetProcessDPIAware();
if( hResult )
{
MsgDev( D_NOTE, "SetDPIAwareness: Success\n" );
bSuccess = TRUE;
}
else MsgDev( D_NOTE, "SetDPIAwareness: fail\n" );
}
else MsgDev( D_NOTE, "SetDPIAwareness: Can't get SetProcessDPIAware\n" );
FreeLibrary( hModule );
}
else MsgDev( D_NOTE, "SetDPIAwareness: Can't load user32.dll\n" );
}
}
#endif
static void SetWidthAndHeightFromCommandLine()
{
int width;
int height;
int width, height;
Sys_GetIntFromCmdLine( "-width", &width );
Sys_GetIntFromCmdLine( "-height", &height );
@ -566,9 +513,7 @@ static void SetWidthAndHeightFromCommandLine() @@ -566,9 +513,7 @@ static void SetWidthAndHeightFromCommandLine()
return;
}
Cvar_SetValue( "vid_mode", VID_NOMODE );
Cvar_SetValue( "width", width );
Cvar_SetValue( "height", height );
R_SaveVideoMode( width, height );
}
static void SetFullscreenModeFromCommandLine( )
@ -605,10 +550,6 @@ qboolean R_Init( void ) @@ -605,10 +550,6 @@ qboolean R_Init( void )
GL_SetDefaultState();
#ifdef WIN32
WIN_SetDPIAwareness( );
#endif
// create the window and set up the context
if( !R_Init_OpenGL( ))
{

11
engine/client/vid_common.h

@ -7,7 +7,6 @@ typedef struct vidmode_s @@ -7,7 +7,6 @@ typedef struct vidmode_s
const char *desc;
int width;
int height;
qboolean wideScreen;
} vidmode_t;
typedef enum
@ -18,12 +17,9 @@ typedef enum @@ -18,12 +17,9 @@ typedef enum
rserr_unknown
} rserr_t;
typedef enum
{
VID_NOMODE = -2,
VID_AUTOMODE = -1,
VID_DEFAULTMODE = 3 // 640x480
} vidmode_e;
// minimal recommended resolution
#define VID_MIN_WIDTH 640
#define VID_MIN_HEIGHT 480
//
// vid_common.c
@ -38,7 +34,6 @@ int GL_MaxTextureUnits( void ); @@ -38,7 +34,6 @@ int GL_MaxTextureUnits( void );
qboolean R_Init( void );
void R_Shutdown( void );
const char *VID_GetModeString( int vid_mode );
qboolean R_DescribeVIDMode( int width, int height );
void R_SaveVideoMode( int w, int h );
void VID_StartupGamma( void );
void GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char *cvarname, int r_ext );

17
engine/platform/sdl/events.c

@ -230,10 +230,10 @@ static void SDLash_EventFilter( SDL_Event *event ) @@ -230,10 +230,10 @@ static void SDLash_EventFilter( SDL_Event *event )
#ifdef TOUCHEMU
if( mdown )
IN_TouchEvent( event_motion, 0,
event->motion.x/scr_width->value,
event->motion.y/scr_height->value,
event->motion.xrel/scr_width->value,
event->motion.yrel/scr_height->value );
event->motion.x/(float)glState.width,
event->motion.y/(float)glState.height,
event->motion.xrel/(float)glState.width,
event->motion.yrel/(float)glState.height );
SDL_ShowCursor( true );
#endif
break;
@ -243,8 +243,8 @@ static void SDLash_EventFilter( SDL_Event *event ) @@ -243,8 +243,8 @@ static void SDLash_EventFilter( SDL_Event *event )
#ifdef TOUCHEMU
mdown = event->button.state != SDL_RELEASED;
IN_TouchEvent( event_down, 0,
event->button.x/scr_width->value,
event->button.y/scr_height->value, 0, 0);
event->button.x/(float)glState.width,
event->button.y/(float)glState.height, 0, 0);
#else
SDLash_MouseEvent( event->button );
#endif
@ -261,14 +261,13 @@ static void SDLash_EventFilter( SDL_Event *event ) @@ -261,14 +261,13 @@ static void SDLash_EventFilter( SDL_Event *event )
SDLash_KeyEvent( event->key );
break;
/* Touch events */
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION:
{
touchEventType type;
static int scale = 0;
touchEventType type;
float x, y, dx, dy;
if( event->type == SDL_FINGERDOWN )
@ -456,7 +455,6 @@ static void SDLash_EventFilter( SDL_Event *event ) @@ -456,7 +455,6 @@ static void SDLash_EventFilter( SDL_Event *event )
break;
case SDL_WINDOWEVENT_RESIZED:
if( vid_fullscreen->value ) break;
Cvar_SetValue( "vid_mode", VID_NOMODE ); // no mode
R_ChangeDisplaySettingsFast( event->window.data1,
event->window.data2 );
break;
@ -464,7 +462,6 @@ static void SDLash_EventFilter( SDL_Event *event ) @@ -464,7 +462,6 @@ static void SDLash_EventFilter( SDL_Event *event )
{
int w, h;
if( vid_fullscreen->value ) break;
Cvar_SetValue( "vid_mode", VID_NOMODE ); // no mode
SDL_GL_GetDrawableSize( host.hWnd, &w, &h );
R_ChangeDisplaySettingsFast( w, h );

321
engine/platform/sdl/vid_sdl.c

@ -20,37 +20,8 @@ GNU General Public License for more details. @@ -20,37 +20,8 @@ GNU General Public License for more details.
#include "vid_common.h"
#include <SDL.h>
#define num_vidmodes ARRAYSIZE( vidmode )
vidmode_t vidmode[] =
{
{ "640 x 480", 640, 480, false },
{ "800 x 600", 800, 600, false },
{ "960 x 720", 960, 720, false },
{ "1024 x 768", 1024, 768, false },
{ "1152 x 864", 1152, 864, false },
{ "1280 x 800", 1280, 800, false },
{ "1280 x 960", 1280, 960, false },
{ "1280 x 1024", 1280, 1024, false },
{ "1600 x 1200", 1600, 1200, false },
{ "2048 x 1536", 2048, 1536, false },
{ "800 x 480 (wide)", 800, 480, true },
{ "856 x 480 (wide)", 856, 480, true },
{ "960 x 540 (wide)", 960, 540, true },
{ "1024 x 576 (wide)", 1024, 576, true },
{ "1024 x 600 (wide)", 1024, 600, true },
{ "1280 x 720 (wide)", 1280, 720, true },
{ "1360 x 768 (wide)", 1360, 768, true },
{ "1366 x 768 (wide)", 1366, 768, true },
{ "1440 x 900 (wide)", 1440, 900, true },
{ "1680 x 1050 (wide)", 1680, 1050, true },
{ "1920 x 1080 (wide)", 1920, 1080, true },
{ "1920 x 1200 (wide)", 1920, 1200, true },
{ "2560 x 1440 (wide)", 2560, 1440, true },
{ "2560 x 1600 (wide)", 2560, 1600, true },
{ "1600 x 900 (wide)", 1600, 900, true },
{ "3840 x 2160 (wide)", 3840, 2160, true },
};
static vidmode_t *vidmodes = NULL;
static int num_vidmodes = 0;
static dllfunc_t opengl_110funcs[] =
{
@ -225,6 +196,145 @@ static dllfunc_t texturecompressionfuncs[] = @@ -225,6 +196,145 @@ static dllfunc_t texturecompressionfuncs[] =
static void GL_SetupAttributes( void );
int R_MaxVideoModes( void )
{
return num_vidmodes;
}
vidmode_t R_GetVideoMode( int num )
{
static vidmode_t error = { NULL };
if( !vidmodes || num < 0 || num > R_MaxVideoModes() )
{
error.width = glState.width;
error.height = glState.height;
return error;
}
return vidmodes[num];
}
static void R_InitVideoModes( void )
{
int displayIndex = 0; // TODO: handle multiple displays somehow
int i, modes;
modes = SDL_GetNumDisplayModes( displayIndex );
if( !modes )
return;
vidmodes = Mem_Alloc( host.mempool, modes * sizeof( vidmode_t ) );
for( i = 0; i < modes; i++ )
{
int j;
qboolean skip = false;
SDL_DisplayMode mode;
if( SDL_GetDisplayMode( displayIndex, i, &mode ) )
{
Msg( "SDL_GetDisplayMode: %s\n", SDL_GetError() );
continue;
}
if( mode.w < VID_MIN_WIDTH || mode.h < VID_MIN_HEIGHT )
continue;
for( j = 0; j < num_vidmodes; j++ )
{
if( mode.w == vidmodes[j].width &&
mode.h == vidmodes[j].height )
{
skip = true;
break;
}
}
if( j != num_vidmodes )
continue;
vidmodes[num_vidmodes].width = mode.w;
vidmodes[num_vidmodes].height = mode.h;
vidmodes[num_vidmodes].desc = copystring( va( "%ix%i", mode.w, mode.h ));
num_vidmodes++;
}
}
static void R_FreeVideoModes( void )
{
int i;
for( i = 0; i < num_vidmodes; i++ )
Mem_Free( (char*)vidmodes[i].desc );
Mem_Free( vidmodes );
vidmodes = NULL;
}
#ifdef WIN32
typedef enum _XASH_DPI_AWARENESS
{
XASH_DPI_UNAWARE = 0,
XASH_SYSTEM_DPI_AWARE = 1,
XASH_PER_MONITOR_DPI_AWARE = 2
} XASH_DPI_AWARENESS;
static void WIN_SetDPIAwareness( void )
{
HMODULE hModule;
HRESULT ( __stdcall *pSetProcessDpiAwareness )( XASH_DPI_AWARENESS );
BOOL ( __stdcall *pSetProcessDPIAware )( void );
BOOL bSuccess = FALSE;
if( ( hModule = LoadLibrary( "shcore.dll" ) ) )
{
if( ( pSetProcessDpiAwareness = (void*)GetProcAddress( hModule, "SetProcessDpiAwareness" ) ) )
{
// I hope SDL don't handle WM_DPICHANGED message
HRESULT hResult = pSetProcessDpiAwareness( XASH_SYSTEM_DPI_AWARE );
if( hResult == S_OK )
{
MsgDev( D_NOTE, "SetDPIAwareness: Success\n" );
bSuccess = TRUE;
}
else if( hResult = E_INVALIDARG ) MsgDev( D_NOTE, "SetDPIAwareness: Invalid argument\n" );
else if( hResult == E_ACCESSDENIED ) MsgDev( D_NOTE, "SetDPIAwareness: Access Denied\n" );
}
else MsgDev( D_NOTE, "SetDPIAwareness: Can't get SetProcessDpiAwareness\n" );
FreeLibrary( hModule );
}
else MsgDev( D_NOTE, "SetDPIAwareness: Can't load shcore.dll\n" );
if( !bSuccess )
{
MsgDev( D_NOTE, "SetDPIAwareness: Trying SetProcessDPIAware...\n" );
if( ( hModule = LoadLibrary( "user32.dll" ) ) )
{
if( ( pSetProcessDPIAware = ( void* )GetProcAddress( hModule, "SetProcessDPIAware" ) ) )
{
// I hope SDL don't handle WM_DPICHANGED message
BOOL hResult = pSetProcessDPIAware();
if( hResult )
{
MsgDev( D_NOTE, "SetDPIAwareness: Success\n" );
bSuccess = TRUE;
}
else MsgDev( D_NOTE, "SetDPIAwareness: fail\n" );
}
else MsgDev( D_NOTE, "SetDPIAwareness: Can't get SetProcessDPIAware\n" );
FreeLibrary( hModule );
}
else MsgDev( D_NOTE, "SetDPIAwareness: Can't load user32.dll\n" );
}
}
#endif
/*
========================
DebugCallback
@ -377,7 +487,6 @@ qboolean GL_DeleteContext( void ) @@ -377,7 +487,6 @@ qboolean GL_DeleteContext( void )
return false;
}
static qboolean recreate = false;
qboolean VID_SetScreenResolution( int width, int height )
{
SDL_DisplayMode want, got;
@ -397,21 +506,12 @@ qboolean VID_SetScreenResolution( int width, int height ) @@ -397,21 +506,12 @@ qboolean VID_SetScreenResolution( int width, int height )
MsgDev(D_NOTE, "Got closest display mode: %ix%i@%i\n", got.w, got.h, got.refresh_rate);
#ifdef XASH_SDL_WINDOW_RECREATE
if( recreate )
{
SDL_DestroyWindow( host.hWnd );
host.hWnd = SDL_CreateWindow(wndname, 0, 0, width, height, wndFlags | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_GRABBED );
SDL_GL_MakeCurrent( host.hWnd, glw_state.context );
recreate = false;
}
#endif
if( SDL_SetWindowDisplayMode( host.hWnd, &got) == -1 )
return false;
if( SDL_SetWindowFullscreen( host.hWnd, SDL_WINDOW_FULLSCREEN) == -1 )
return false;
SDL_SetWindowBordered( host.hWnd, SDL_FALSE );
//SDL_SetWindowPosition( host.hWnd, 0, 0 );
SDL_SetWindowGrab( host.hWnd, SDL_TRUE );
@ -428,14 +528,12 @@ void VID_RestoreScreenResolution( void ) @@ -428,14 +528,12 @@ void VID_RestoreScreenResolution( void )
if( !Cvar_VariableInteger("fullscreen") )
{
SDL_SetWindowBordered( host.hWnd, SDL_TRUE );
//SDL_SetWindowPosition( host.hWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED );
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
}
else
{
SDL_MinimizeWindow( host.hWnd );
SDL_SetWindowFullscreen( host.hWnd, 0 );
recreate = true;
}
}
@ -462,8 +560,9 @@ VID_CreateWindow @@ -462,8 +560,9 @@ VID_CreateWindow
qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
{
static string wndname;
Uint32 wndFlags = SDL_WINDOW_OPENGL;
Uint32 wndFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_MOUSE_FOCUS;
rgbdata_t *icon = NULL;
qboolean iconLoaded = false;
char iconpath[MAX_STRING];
if( vid_highdpi->value ) wndFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
@ -471,15 +570,16 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) @@ -471,15 +570,16 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
if( !fullscreen )
{
#ifndef XASH_SDL_DISABLE_RESIZE
wndFlags |= SDL_WINDOW_RESIZABLE;
#endif
host.hWnd = SDL_CreateWindow( wndname, window_xpos->value,
window_ypos->value, width, height, wndFlags | SDL_WINDOW_MOUSE_FOCUS );
host.hWnd = SDL_CreateWindow( wndname,
Cvar_VariableInteger( "_window_xpos" ),
Cvar_VariableInteger( "_window_ypos" ),
width, height, wndFlags );
}
else
{
host.hWnd = SDL_CreateWindow( wndname, 0, 0, width, height, wndFlags | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_GRABBED );
wndFlags |= SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_GRABBED;
host.hWnd = SDL_CreateWindow( wndname, 0, 0, width, height, wndFlags );
}
@ -522,20 +622,19 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) @@ -522,20 +622,19 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
Q_snprintf( localPath, sizeof( localPath ), "%s/%s", GI->gamefolder, GI->iconpath );
ico = (HICON)LoadImage( NULL, localPath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE|LR_DEFAULTSIZE );
if( !ico )
if( ico )
{
MsgDev( D_INFO, "Extract %s from pak if you want to see it.\n", GI->iconpath );
ico = LoadIcon( host.hInst, MAKEINTRESOURCE( 101 ) );
}
iconLoaded = true;
WIN_SetWindowIcon( ico );
}
else
}
#endif // _WIN32 && !XASH_64BIT
if( !iconLoaded )
{
Q_strcpy( iconpath, GI->iconpath );
COM_StripExtension( iconpath );
COM_DefaultExtension( iconpath, ".tga") ;
COM_DefaultExtension( iconpath, ".tga" );
icon = FS_LoadImage( iconpath, NULL, 0 );
@ -549,17 +648,20 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) @@ -549,17 +648,20 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
{
SDL_SetWindowIcon( host.hWnd, surface );
SDL_FreeSurface( surface );
iconLoaded = true;
}
FS_FreeImage( icon );
}
}
#if defined(_WIN32) && !defined(XASH_64BIT) // ICO support only for Win32
else
if( !iconLoaded )
{
WIN_SetWindowIcon( LoadIcon( host.hInst, MAKEINTRESOURCE( 101 ) ) );
iconLoaded = true;
}
#endif
}
SDL_ShowWindow( host.hWnd );
if( !glw_state.initialized )
@ -751,6 +853,13 @@ qboolean R_Init_OpenGL( void ) @@ -751,6 +853,13 @@ qboolean R_Init_OpenGL( void )
return false;
}
R_InitVideoModes();
// must be initialized before creating window
#ifdef _WIN32
WIN_SetDPIAwareness();
#endif
return VID_SetMode();
}
@ -999,26 +1108,6 @@ void GL_InitExtensions( void ) @@ -999,26 +1108,6 @@ void GL_InitExtensions( void )
glw_state.initialized = true;
}
int R_MaxVideoModes( void )
{
return num_vidmodes;
}
vidmode_t R_GetVideoMode( int num )
{
static vidmode_t error = { "NOMODE" };
if( num < 0 || num > num_vidmodes )
{
error.width = scr_width->value;
error.height = scr_height->value;
error.wideScreen = false;
return error;
}
return vidmode[num];
}
/*
==================
R_ChangeDisplaySettingsFast
@ -1028,69 +1117,40 @@ Change window size fastly to custom values, without setting vid mode @@ -1028,69 +1117,40 @@ Change window size fastly to custom values, without setting vid mode
*/
void R_ChangeDisplaySettingsFast( int width, int height )
{
// Cvar_SetValue( "vid_mode", VID_NOMODE );
Cvar_SetValue( "width", width );
Cvar_SetValue( "height", height );
// as we don't recreate window here, update center positions by hand
host.window_center_x = glState.width / 2;
host.window_center_y = glState.height / 2;
if( glState.width != width || glState.height != height )
{
glState.width = width;
glState.height = height;
if( width * 3 != height * 4 && width * 4 != height * 5 )
glState.wideScreen = true;
else glState.wideScreen = false;
R_SaveVideoMode( width, height );
SCR_VidInit();
}
}
rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
{
SDL_DisplayMode displayMode;
qboolean old_fullscreen = glState.fullScreen;
SDL_GetCurrentDisplayMode(0, &displayMode);
#ifdef XASH_NOMODESWITCH
width = displayMode.w;
height = displayMode.h;
fullscreen = false;
#endif
SDL_GetCurrentDisplayMode( 0, &displayMode );
MsgDev(D_INFO, "R_ChangeDisplaySettings: Setting video mode to %dx%d %s\n", width, height, fullscreen ? "fullscreen" : "windowed");
R_SaveVideoMode( width, height );
MsgDev( D_INFO, "R_ChangeDisplaySettings: Setting video mode to %dx%d %s\n", width, height, fullscreen ? "fullscreen" : "windowed" );
// check our desktop attributes
glw_state.desktopBitsPixel = SDL_BITSPERPIXEL(displayMode.format);
glw_state.desktopBitsPixel = SDL_BITSPERPIXEL( displayMode.format );
glw_state.desktopWidth = displayMode.w;
glw_state.desktopHeight = displayMode.h;
glState.fullScreen = fullscreen;
// check for 4:3 or 5:4
if( width * 3 != height * 4 && width * 4 != height * 5 )
glState.wideScreen = true;
else glState.wideScreen = false;
if(!host.hWnd)
if( !host.hWnd )
{
if( !VID_CreateWindow( width, height, fullscreen ) )
return rserr_invalid_mode;
}
#ifndef XASH_NOMODESWITCH
else if( fullscreen )
{
if( !VID_SetScreenResolution( width, height ) )
return rserr_invalid_fullscreen;
}
else if( old_fullscreen )
else
{
VID_RestoreScreenResolution();
if( SDL_SetWindowFullscreen(host.hWnd, 0) )
if( SDL_SetWindowFullscreen( host.hWnd, 0 ) )
return rserr_invalid_fullscreen;
SDL_RestoreWindow( host.hWnd );
#if SDL_VERSION_ATLEAST( 2, 0, 5 )
@ -1101,7 +1161,6 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) @@ -1101,7 +1161,6 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
SDL_GL_GetDrawableSize( host.hWnd, &width, &height );
R_ChangeDisplaySettingsFast( width, height );
}
#endif
return rserr_ok;
}
@ -1119,34 +1178,29 @@ qboolean VID_SetMode( void ) @@ -1119,34 +1178,29 @@ qboolean VID_SetMode( void )
int iScreenWidth, iScreenHeight;
rserr_t err;
if( vid_mode->value == -1 ) // trying to get resolution automatically by default
iScreenWidth = Cvar_VariableInteger( "width" );
iScreenHeight = Cvar_VariableInteger( "height" );
if( iScreenWidth < VID_MIN_WIDTH ||
iScreenHeight < VID_MIN_HEIGHT ) // trying to get resolution automatically by default
{
#if !defined( DEFAULT_MODE_WIDTH ) || !defined( DEFAULT_MODE_HEIGHT )
SDL_DisplayMode mode;
#if !defined DEFAULT_MODE_WIDTH || !defined DEFAULT_MODE_HEIGHT
SDL_GetDesktopDisplayMode( 0, &mode );
#else
mode.w = DEFAULT_MODE_WIDTH;
mode.h = DEFAULT_MODE_HEIGHT;
#endif
iScreenWidth = mode.w;
iScreenHeight = mode.h;
#else
iScreenWidth = DEFAULT_MODE_WIDTH;
iScreenHeight = DEFAULT_MODE_HEIGHT;
#endif
if( !FBitSet( vid_fullscreen->flags, FCVAR_CHANGED ) )
Cvar_SetValue( "fullscreen", DEFAULT_FULLSCREEN );
else
ClearBits( vid_fullscreen->flags, FCVAR_CHANGED );
}
else if( FBitSet( vid_mode->flags, FCVAR_CHANGED ) && vid_mode->value >= 0 && vid_mode->value <= num_vidmodes )
{
iScreenWidth = vidmode[(int)vid_mode->value].width;
iScreenHeight = vidmode[(int)vid_mode->value].height;
}
else
{
iScreenHeight = scr_height->value;
iScreenWidth = scr_width->value;
}
SetBits( gl_vsync->flags, FCVAR_CHANGED );
fullscreen = Cvar_VariableInteger("fullscreen") != 0;
@ -1168,7 +1222,6 @@ qboolean VID_SetMode( void ) @@ -1168,7 +1222,6 @@ qboolean VID_SetMode( void )
}
else if( err == rserr_invalid_mode )
{
Cvar_SetValue( "vid_mode", glConfig.prev_mode );
MsgDev( D_ERROR, "VID_SetMode: invalid mode\n" );
Sys_Warn( "invalid mode" );
}
@ -1195,6 +1248,8 @@ void R_Free_OpenGL( void ) @@ -1195,6 +1248,8 @@ void R_Free_OpenGL( void )
VID_DestroyWindow ();
R_FreeVideoModes();
// now all extensions are disabled
memset( glConfig.extension, 0, sizeof( glConfig.extension ));
glw_state.initialized = false;

5
vgui_support/vgui_surf.cpp

@ -322,11 +322,6 @@ bool CEngineSurface :: setFullscreenMode( int wide, int tall, int bpp ) @@ -322,11 +322,6 @@ bool CEngineSurface :: setFullscreenMode( int wide, int tall, int bpp )
{
// NOTE: Xash3D always working in 32-bit mode
// Skip it now. VGUI cannot change video modes
/*if( R_DescribeVIDMode( wide, tall ))
{
Cvar_SetFloat( "fullscreen", 1.0f );
return true;
}*/
return false;
}

Loading…
Cancel
Save