222 lines
5.3 KiB
C
222 lines
5.3 KiB
C
/*
|
|
vid_common.c - common vid component
|
|
Copyright (C) 2018 a1batross, Uncle Mike
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
*/
|
|
|
|
#include "common.h"
|
|
#include "client.h"
|
|
#include "mod_local.h"
|
|
#include "input.h"
|
|
#include "vid_common.h"
|
|
#include "platform/platform.h"
|
|
|
|
#define WINDOW_NAME XASH_ENGINE_NAME " Window" // Half-Life
|
|
convar_t *vid_displayfrequency;
|
|
convar_t *vid_fullscreen;
|
|
convar_t *vid_brightness;
|
|
convar_t *vid_gamma;
|
|
convar_t *vid_highdpi;
|
|
|
|
vidstate_t vidState;
|
|
glwstate_t glw_state;
|
|
glcontext_t glContext;
|
|
|
|
convar_t *window_xpos;
|
|
convar_t *window_ypos;
|
|
/*
|
|
=================
|
|
VID_StartupGamma
|
|
=================
|
|
*/
|
|
void VID_StartupGamma( void )
|
|
{
|
|
BuildGammaTable( vid_gamma->value, vid_brightness->value );
|
|
Con_Reportf( "VID_StartupGamma: gamma %g brightness %g\n", vid_gamma->value, vid_brightness->value );
|
|
ClearBits( vid_brightness->flags, FCVAR_CHANGED );
|
|
ClearBits( vid_gamma->flags, FCVAR_CHANGED );
|
|
}
|
|
|
|
/*
|
|
=================
|
|
VID_InitDefaultResolution
|
|
=================
|
|
*/
|
|
void VID_InitDefaultResolution( void )
|
|
{
|
|
// we need to have something valid here
|
|
// until video subsystem initialized
|
|
vidState.width = 640;
|
|
vidState.height = 480;
|
|
}
|
|
|
|
/*
|
|
=================
|
|
R_SaveVideoMode
|
|
=================
|
|
*/
|
|
void R_SaveVideoMode( int w, int h )
|
|
{
|
|
vidState.width = w;
|
|
vidState.height = h;
|
|
|
|
host.window_center_x = w / 2;
|
|
host.window_center_y = h / 2;
|
|
|
|
Cvar_SetValue( "width", w );
|
|
Cvar_SetValue( "height", h );
|
|
|
|
// check for 4:3 or 5:4
|
|
if( w * 3 != h * 4 && w * 4 != h * 5 )
|
|
vidState.wideScreen = true;
|
|
else vidState.wideScreen = false;
|
|
}
|
|
|
|
/*
|
|
=================
|
|
VID_GetModeString
|
|
=================
|
|
*/
|
|
const char *VID_GetModeString( int vid_mode )
|
|
{
|
|
vidmode_t *vidmode;
|
|
if( vid_mode < 0 || vid_mode > R_MaxVideoModes() )
|
|
return NULL;
|
|
|
|
if( !( vidmode = R_GetVideoMode( vid_mode ) ) )
|
|
return NULL;
|
|
|
|
return vidmode->desc;
|
|
}
|
|
|
|
/*
|
|
==================
|
|
VID_CheckChanges
|
|
|
|
check vid modes and fullscreen
|
|
==================
|
|
*/
|
|
void VID_CheckChanges( void )
|
|
{
|
|
if( FBitSet( cl_allow_levelshots->flags, FCVAR_CHANGED ))
|
|
{
|
|
//GL_FreeTexture( cls.loadingBar );
|
|
SCR_RegisterTextures(); // reload 'lambda' image
|
|
ClearBits( cl_allow_levelshots->flags, FCVAR_CHANGED );
|
|
}
|
|
|
|
if( host.renderinfo_changed )
|
|
{
|
|
if( VID_SetMode( ))
|
|
{
|
|
SCR_VidInit(); // tell the client.dll what vid_mode has changed
|
|
}
|
|
else
|
|
{
|
|
Sys_Error( "Can't re-initialize video subsystem\n" );
|
|
}
|
|
host.renderinfo_changed = false;
|
|
}
|
|
}
|
|
|
|
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 )) );
|
|
if( !vidmode )
|
|
{
|
|
Con_Print( S_ERROR "unable to set mode, backend returned null" );
|
|
return;
|
|
}
|
|
|
|
w = vidmode->width;
|
|
h = vidmode->height;
|
|
break;
|
|
}
|
|
case 3:
|
|
{
|
|
w = Q_atoi( Cmd_Argv( 1 ));
|
|
h = Q_atoi( Cmd_Argv( 2 ));
|
|
break;
|
|
}
|
|
default:
|
|
Msg( S_USAGE "vid_mode <modenum>|<width height>\n" );
|
|
return;
|
|
}
|
|
|
|
R_ChangeDisplaySettings( w, h, Cvar_VariableInteger( "fullscreen" ) );
|
|
}
|
|
|
|
static void SetWidthAndHeightFromCommandLine()
|
|
{
|
|
int width, height;
|
|
|
|
Sys_GetIntFromCmdLine( "-width", &width );
|
|
Sys_GetIntFromCmdLine( "-height", &height );
|
|
|
|
if( width < 1 || height < 1 )
|
|
{
|
|
// Not specified or invalid, so don't bother.
|
|
return;
|
|
}
|
|
|
|
R_SaveVideoMode( width, height );
|
|
}
|
|
|
|
static void SetFullscreenModeFromCommandLine( )
|
|
{
|
|
#ifndef __ANDROID__
|
|
if ( Sys_CheckParm("-fullscreen") )
|
|
{
|
|
Cvar_Set( "fullscreen", "1" );
|
|
}
|
|
else if ( Sys_CheckParm( "-windowed" ) )
|
|
{
|
|
Cvar_Set( "fullscreen", "0" );
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void VID_Init()
|
|
{
|
|
// system screen width and height (don't suppose for change from console at all)
|
|
Cvar_Get( "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" );
|
|
Cvar_Get( "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" );
|
|
|
|
window_xpos = Cvar_Get( "_window_xpos", "130", FCVAR_RENDERINFO, "window position by horizontal" );
|
|
window_ypos = Cvar_Get( "_window_ypos", "48", FCVAR_RENDERINFO, "window position by vertical" );
|
|
|
|
vid_gamma = Cvar_Get( "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" );
|
|
vid_brightness = Cvar_Get( "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" );
|
|
vid_displayfrequency = Cvar_Get ( "vid_displayfrequency", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "fullscreen refresh rate" );
|
|
vid_fullscreen = Cvar_Get( "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" );
|
|
vid_highdpi = Cvar_Get( "vid_highdpi", "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" );
|
|
|
|
// 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" );
|
|
|
|
// Set screen resolution and fullscreen mode if passed in on command line.
|
|
// This is done after executing opengl.cfg, as the command line values should take priority.
|
|
SetWidthAndHeightFromCommandLine();
|
|
SetFullscreenModeFromCommandLine();
|
|
|
|
R_Init(); // init renderer
|
|
}
|