2011-02-18 14:31:32 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
|
|
|
|
|
|
This file is part of Quake III Arena source code.
|
|
|
|
|
|
|
|
Quake III Arena source code 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 2 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
Quake III Arena source code 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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Quake III Arena source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_LOCAL_HEADERS
|
|
|
|
# include "SDL.h"
|
|
|
|
#else
|
|
|
|
# include <SDL.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
#include "../renderercommon/tr_common.h"
|
2011-02-18 14:31:32 +00:00
|
|
|
#include "../sys/sys_local.h"
|
|
|
|
#include "sdl_icon.h"
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
RSERR_OK,
|
|
|
|
|
|
|
|
RSERR_INVALID_FULLSCREEN,
|
|
|
|
RSERR_INVALID_MODE,
|
|
|
|
|
|
|
|
RSERR_UNKNOWN
|
|
|
|
} rserr_t;
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_Window *SDL_window = NULL;
|
|
|
|
static SDL_GLContext SDL_glContext = NULL;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
cvar_t *r_allowSoftwareGL; // Don't abort out if a hardware visual can't be obtained
|
|
|
|
cvar_t *r_allowResize; // make window resizable
|
|
|
|
cvar_t *r_centerWindow;
|
|
|
|
cvar_t *r_sdlDriver;
|
|
|
|
|
2017-11-04 11:30:30 +00:00
|
|
|
int qglMajorVersion, qglMinorVersion;
|
|
|
|
int qglesMajorVersion, qglesMinorVersion;
|
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
void (APIENTRYP qglActiveTextureARB) (GLenum texture);
|
|
|
|
void (APIENTRYP qglClientActiveTextureARB) (GLenum texture);
|
|
|
|
void (APIENTRYP qglMultiTexCoord2fARB) (GLenum target, GLfloat s, GLfloat t);
|
|
|
|
|
|
|
|
void (APIENTRYP qglLockArraysEXT) (GLint first, GLsizei count);
|
|
|
|
void (APIENTRYP qglUnlockArraysEXT) (void);
|
|
|
|
|
2017-11-04 11:30:30 +00:00
|
|
|
#define GLE(ret, name, ...) name##proc * qgl##name;
|
|
|
|
QGL_1_1_PROCS;
|
2018-07-30 11:35:12 +00:00
|
|
|
QGL_1_1_FIXED_FUNCTION_PROCS;
|
2017-11-04 11:30:30 +00:00
|
|
|
QGL_DESKTOP_1_1_PROCS;
|
2018-07-30 11:35:12 +00:00
|
|
|
QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS;
|
2017-11-04 11:30:30 +00:00
|
|
|
QGL_ES_1_1_PROCS;
|
2018-07-30 11:35:12 +00:00
|
|
|
QGL_ES_1_1_FIXED_FUNCTION_PROCS;
|
|
|
|
QGL_1_3_PROCS;
|
|
|
|
QGL_1_5_PROCS;
|
|
|
|
QGL_2_0_PROCS;
|
2017-11-04 11:30:30 +00:00
|
|
|
QGL_3_0_PROCS;
|
2018-07-30 11:35:12 +00:00
|
|
|
QGL_ARB_occlusion_query_PROCS;
|
|
|
|
QGL_ARB_framebuffer_object_PROCS;
|
|
|
|
QGL_ARB_vertex_array_object_PROCS;
|
|
|
|
QGL_EXT_direct_state_access_PROCS;
|
2017-11-04 11:30:30 +00:00
|
|
|
#undef GLE
|
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_Shutdown
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void GLimp_Shutdown( void )
|
|
|
|
{
|
2011-08-10 21:14:44 +00:00
|
|
|
ri.IN_Shutdown();
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
SDL_QuitSubSystem( SDL_INIT_VIDEO );
|
|
|
|
}
|
|
|
|
|
2011-07-26 08:52:24 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_Minimize
|
|
|
|
|
|
|
|
Minimize the game so that user is back at the desktop
|
|
|
|
===============
|
|
|
|
*/
|
2017-07-10 01:33:41 +00:00
|
|
|
void GLimp_Minimize( void )
|
2011-07-26 08:52:24 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_MinimizeWindow( SDL_window );
|
2011-07-26 08:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_LogComment
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void GLimp_LogComment( char *comment )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_CompareModes
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static int GLimp_CompareModes( const void *a, const void *b )
|
|
|
|
{
|
|
|
|
const float ASPECT_EPSILON = 0.001f;
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_Rect *modeA = (SDL_Rect *)a;
|
|
|
|
SDL_Rect *modeB = (SDL_Rect *)b;
|
2011-02-18 14:31:32 +00:00
|
|
|
float aspectA = (float)modeA->w / (float)modeA->h;
|
|
|
|
float aspectB = (float)modeB->w / (float)modeB->h;
|
|
|
|
int areaA = modeA->w * modeA->h;
|
|
|
|
int areaB = modeB->w * modeB->h;
|
|
|
|
float aspectDiffA = fabs( aspectA - displayAspect );
|
|
|
|
float aspectDiffB = fabs( aspectB - displayAspect );
|
|
|
|
float aspectDiffsDiff = aspectDiffA - aspectDiffB;
|
|
|
|
|
|
|
|
if( aspectDiffsDiff > ASPECT_EPSILON )
|
|
|
|
return 1;
|
|
|
|
else if( aspectDiffsDiff < -ASPECT_EPSILON )
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return areaA - areaB;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_DetectAvailableModes
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static void GLimp_DetectAvailableModes(void)
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
int i, j;
|
2011-02-18 14:31:32 +00:00
|
|
|
char buf[ MAX_STRING_CHARS ] = { 0 };
|
2017-07-10 01:33:41 +00:00
|
|
|
int numSDLModes;
|
|
|
|
SDL_Rect *modes;
|
|
|
|
int numModes = 0;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_DisplayMode windowMode;
|
|
|
|
int display = SDL_GetWindowDisplayIndex( SDL_window );
|
|
|
|
if( display < 0 )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_WARNING, "Couldn't get window display index, no resolutions detected: %s\n", SDL_GetError() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
numSDLModes = SDL_GetNumDisplayModes( display );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if( SDL_GetWindowDisplayMode( SDL_window, &windowMode ) < 0 || numSDLModes <= 0 )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Printf( PRINT_WARNING, "Couldn't get window display mode, no resolutions detected: %s\n", SDL_GetError() );
|
2011-02-18 14:31:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
modes = SDL_calloc( (size_t)numSDLModes, sizeof( SDL_Rect ) );
|
|
|
|
if ( !modes )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Error( ERR_FATAL, "Out of memory" );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
for( i = 0; i < numSDLModes; i++ )
|
|
|
|
{
|
|
|
|
SDL_DisplayMode mode;
|
|
|
|
|
|
|
|
if( SDL_GetDisplayMode( display, i, &mode ) < 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !mode.w || !mode.h )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "Display supports any resolution\n" );
|
|
|
|
SDL_free( modes );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( windowMode.format != mode.format )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// SDL can give the same resolution with different refresh rates.
|
|
|
|
// Only list resolution once.
|
|
|
|
for( j = 0; j < numModes; j++ )
|
|
|
|
{
|
|
|
|
if( mode.w == modes[ j ].w && mode.h == modes[ j ].h )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( j != numModes )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
modes[ numModes ].w = mode.w;
|
|
|
|
modes[ numModes ].h = mode.h;
|
|
|
|
numModes++;
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
if( numModes > 1 )
|
2017-07-10 01:33:41 +00:00
|
|
|
qsort( modes, numModes, sizeof( SDL_Rect ), GLimp_CompareModes );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
for( i = 0; i < numModes; i++ )
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
const char *newModeString = va( "%ux%u ", modes[ i ].w, modes[ i ].h );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
if( strlen( newModeString ) < (int)sizeof( buf ) - strlen( buf ) )
|
|
|
|
Q_strcat( buf, sizeof( buf ), newModeString );
|
|
|
|
else
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Printf( PRINT_WARNING, "Skipping mode %ux%u, buffer too small\n", modes[ i ].w, modes[ i ].h );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( *buf )
|
|
|
|
{
|
|
|
|
buf[ strlen( buf ) - 1 ] = 0;
|
|
|
|
ri.Printf( PRINT_ALL, "Available modes: '%s'\n", buf );
|
|
|
|
ri.Cvar_Set( "r_availableModes", buf );
|
|
|
|
}
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_free( modes );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 11:30:30 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_GetProcAddresses
|
|
|
|
|
|
|
|
Get addresses for OpenGL functions.
|
|
|
|
===============
|
|
|
|
*/
|
2018-07-30 11:35:12 +00:00
|
|
|
static qboolean GLimp_GetProcAddresses( qboolean fixedFunction ) {
|
2017-11-04 11:30:30 +00:00
|
|
|
qboolean success = qtrue;
|
|
|
|
const char *version;
|
|
|
|
|
|
|
|
#ifdef __SDL_NOGETPROCADDR__
|
|
|
|
#define GLE( ret, name, ... ) qgl##name = gl#name;
|
|
|
|
#else
|
|
|
|
#define GLE( ret, name, ... ) qgl##name = (name##proc *) SDL_GL_GetProcAddress("gl" #name); \
|
|
|
|
if ( qgl##name == NULL ) { \
|
|
|
|
ri.Printf( PRINT_ALL, "ERROR: Missing OpenGL function %s\n", "gl" #name ); \
|
|
|
|
success = qfalse; \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// OpenGL 1.0 and OpenGL ES 1.0
|
|
|
|
GLE(const GLubyte *, GetString, GLenum name)
|
|
|
|
|
|
|
|
if ( !qglGetString ) {
|
|
|
|
Com_Error( ERR_FATAL, "glGetString is NULL" );
|
|
|
|
}
|
|
|
|
|
|
|
|
version = (const char *)qglGetString( GL_VERSION );
|
|
|
|
|
|
|
|
if ( !version ) {
|
|
|
|
Com_Error( ERR_FATAL, "GL_VERSION is NULL\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Q_stricmpn( "OpenGL ES", version, 9 ) == 0 ) {
|
|
|
|
char profile[6]; // ES, ES-CM, or ES-CL
|
|
|
|
sscanf( version, "OpenGL %5s %d.%d", profile, &qglesMajorVersion, &qglesMinorVersion );
|
|
|
|
// common lite profile (no floating point) is not supported
|
|
|
|
if ( Q_stricmp( profile, "ES-CL" ) == 0 ) {
|
|
|
|
qglesMajorVersion = 0;
|
|
|
|
qglesMinorVersion = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sscanf( version, "%d.%d", &qglMajorVersion, &qglMinorVersion );
|
|
|
|
}
|
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
if ( fixedFunction ) {
|
|
|
|
if ( QGL_VERSION_ATLEAST( 1, 2 ) ) {
|
|
|
|
QGL_1_1_PROCS;
|
|
|
|
QGL_1_1_FIXED_FUNCTION_PROCS;
|
|
|
|
QGL_DESKTOP_1_1_PROCS;
|
|
|
|
QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS;
|
|
|
|
} else if ( qglesMajorVersion == 1 && qglesMinorVersion >= 1 ) {
|
|
|
|
// OpenGL ES 1.1 (2.0 is not backward compatible)
|
|
|
|
QGL_1_1_PROCS;
|
|
|
|
QGL_1_1_FIXED_FUNCTION_PROCS;
|
|
|
|
QGL_ES_1_1_PROCS;
|
|
|
|
QGL_ES_1_1_FIXED_FUNCTION_PROCS;
|
|
|
|
// error so this doesn't segfault due to NULL desktop GL functions being used
|
|
|
|
Com_Error( ERR_FATAL, "Unsupported OpenGL Version: %s\n", version );
|
|
|
|
} else {
|
|
|
|
Com_Error( ERR_FATAL, "Unsupported OpenGL Version (%s), OpenGL 1.2 is required\n", version );
|
|
|
|
}
|
2017-11-04 11:30:30 +00:00
|
|
|
} else {
|
2018-07-30 11:35:12 +00:00
|
|
|
if ( QGL_VERSION_ATLEAST( 2, 0 ) ) {
|
|
|
|
QGL_1_1_PROCS;
|
|
|
|
QGL_DESKTOP_1_1_PROCS;
|
|
|
|
QGL_1_3_PROCS;
|
|
|
|
QGL_1_5_PROCS;
|
|
|
|
QGL_2_0_PROCS;
|
|
|
|
} else if ( QGLES_VERSION_ATLEAST( 2, 0 ) ) {
|
|
|
|
QGL_1_1_PROCS;
|
|
|
|
QGL_ES_1_1_PROCS;
|
|
|
|
QGL_1_3_PROCS;
|
|
|
|
QGL_1_5_PROCS;
|
|
|
|
QGL_2_0_PROCS;
|
|
|
|
// error so this doesn't segfault due to NULL desktop GL functions being used
|
|
|
|
Com_Error( ERR_FATAL, "Unsupported OpenGL Version: %s\n", version );
|
|
|
|
} else {
|
|
|
|
Com_Error( ERR_FATAL, "Unsupported OpenGL Version (%s), OpenGL 2.0 is required\n", version );
|
|
|
|
}
|
2017-11-04 11:30:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( QGL_VERSION_ATLEAST( 3, 0 ) || QGLES_VERSION_ATLEAST( 3, 0 ) ) {
|
|
|
|
QGL_3_0_PROCS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef GLE
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_ClearProcAddresses
|
|
|
|
|
|
|
|
Clear addresses for OpenGL functions.
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static void GLimp_ClearProcAddresses( void ) {
|
|
|
|
#define GLE( ret, name, ... ) qgl##name = NULL;
|
|
|
|
|
|
|
|
qglMajorVersion = 0;
|
|
|
|
qglMinorVersion = 0;
|
|
|
|
qglesMajorVersion = 0;
|
|
|
|
qglesMinorVersion = 0;
|
|
|
|
|
|
|
|
QGL_1_1_PROCS;
|
2018-07-30 11:35:12 +00:00
|
|
|
QGL_1_1_FIXED_FUNCTION_PROCS;
|
2017-11-04 11:30:30 +00:00
|
|
|
QGL_DESKTOP_1_1_PROCS;
|
2018-07-30 11:35:12 +00:00
|
|
|
QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS;
|
2017-11-04 11:30:30 +00:00
|
|
|
QGL_ES_1_1_PROCS;
|
2018-07-30 11:35:12 +00:00
|
|
|
QGL_ES_1_1_FIXED_FUNCTION_PROCS;
|
|
|
|
QGL_1_3_PROCS;
|
|
|
|
QGL_1_5_PROCS;
|
|
|
|
QGL_2_0_PROCS;
|
2017-11-04 11:30:30 +00:00
|
|
|
QGL_3_0_PROCS;
|
2018-07-30 11:35:12 +00:00
|
|
|
QGL_ARB_occlusion_query_PROCS;
|
|
|
|
QGL_ARB_framebuffer_object_PROCS;
|
|
|
|
QGL_ARB_vertex_array_object_PROCS;
|
|
|
|
QGL_EXT_direct_state_access_PROCS;
|
|
|
|
|
|
|
|
qglActiveTextureARB = NULL;
|
|
|
|
qglClientActiveTextureARB = NULL;
|
|
|
|
qglMultiTexCoord2fARB = NULL;
|
|
|
|
|
|
|
|
qglLockArraysEXT = NULL;
|
|
|
|
qglUnlockArraysEXT = NULL;
|
2017-11-04 11:30:30 +00:00
|
|
|
|
|
|
|
#undef GLE
|
|
|
|
}
|
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_SetMode
|
|
|
|
===============
|
|
|
|
*/
|
2018-07-30 11:35:12 +00:00
|
|
|
static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qboolean fixedFunction)
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
const char *glstring;
|
|
|
|
int perChannelColorBits;
|
|
|
|
int colorBits, depthBits, stencilBits;
|
2011-02-18 14:31:32 +00:00
|
|
|
int samples;
|
|
|
|
int i = 0;
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_Surface *icon = NULL;
|
|
|
|
Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
|
|
|
|
SDL_DisplayMode desktopMode;
|
|
|
|
int display = 0;
|
|
|
|
int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
ri.Printf( PRINT_ALL, "Initializing OpenGL display\n");
|
|
|
|
|
|
|
|
if ( r_allowResize->integer )
|
2017-07-10 01:33:41 +00:00
|
|
|
flags |= SDL_WINDOW_RESIZABLE;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
#ifdef USE_ICON
|
|
|
|
icon = SDL_CreateRGBSurfaceFrom(
|
|
|
|
(void *)CLIENT_WINDOW_ICON.pixel_data,
|
|
|
|
CLIENT_WINDOW_ICON.width,
|
|
|
|
CLIENT_WINDOW_ICON.height,
|
|
|
|
CLIENT_WINDOW_ICON.bytes_per_pixel * 8,
|
|
|
|
CLIENT_WINDOW_ICON.bytes_per_pixel * CLIENT_WINDOW_ICON.width,
|
|
|
|
#ifdef Q3_LITTLE_ENDIAN
|
|
|
|
0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
|
|
|
|
#else
|
|
|
|
0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
#endif
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
// If a window exists, note its display index
|
|
|
|
if( SDL_window != NULL )
|
|
|
|
{
|
|
|
|
display = SDL_GetWindowDisplayIndex( SDL_window );
|
|
|
|
if( display < 0 )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_DEVELOPER, "SDL_GetWindowDisplayIndex() failed: %s\n", SDL_GetError() );
|
|
|
|
}
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if( display >= 0 && SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
|
|
|
|
{
|
|
|
|
displayAspect = (float)desktopMode.w / (float)desktopMode.h;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Printf( PRINT_ALL, "Display aspect: %.3f\n", displayAspect );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Com_Memset( &desktopMode, 0, sizeof( SDL_DisplayMode ) );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Printf( PRINT_ALL,
|
|
|
|
"Cannot determine display aspect, assuming 1.333\n" );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ri.Printf (PRINT_ALL, "...setting mode %d:", mode );
|
|
|
|
|
2012-09-15 03:03:44 +00:00
|
|
|
if (mode == -2)
|
|
|
|
{
|
|
|
|
// use desktop video resolution
|
2017-07-10 01:33:41 +00:00
|
|
|
if( desktopMode.h > 0 )
|
2012-09-15 03:03:44 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
glConfig.vidWidth = desktopMode.w;
|
|
|
|
glConfig.vidHeight = desktopMode.h;
|
2012-09-15 03:03:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glConfig.vidWidth = 640;
|
|
|
|
glConfig.vidHeight = 480;
|
|
|
|
ri.Printf( PRINT_ALL,
|
|
|
|
"Cannot determine display resolution, assuming 640x480\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
glConfig.windowAspect = (float)glConfig.vidWidth / (float)glConfig.vidHeight;
|
|
|
|
}
|
|
|
|
else if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect, mode ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, " invalid mode\n" );
|
|
|
|
return RSERR_INVALID_MODE;
|
|
|
|
}
|
|
|
|
ri.Printf( PRINT_ALL, " %d %d\n", glConfig.vidWidth, glConfig.vidHeight);
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
// Center window
|
|
|
|
if( r_centerWindow->integer && !fullscreen )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
x = ( desktopMode.w / 2 ) - ( glConfig.vidWidth / 2 );
|
|
|
|
y = ( desktopMode.h / 2 ) - ( glConfig.vidHeight / 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy existing state if it exists
|
|
|
|
if( SDL_glContext != NULL )
|
|
|
|
{
|
2017-11-04 11:30:30 +00:00
|
|
|
GLimp_ClearProcAddresses();
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_GL_DeleteContext( SDL_glContext );
|
|
|
|
SDL_glContext = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( SDL_window != NULL )
|
|
|
|
{
|
|
|
|
SDL_GetWindowPosition( SDL_window, &x, &y );
|
|
|
|
ri.Printf( PRINT_DEVELOPER, "Existing window at %dx%d before being destroyed\n", x, y );
|
|
|
|
SDL_DestroyWindow( SDL_window );
|
|
|
|
SDL_window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fullscreen )
|
|
|
|
{
|
|
|
|
flags |= SDL_WINDOW_FULLSCREEN;
|
2011-02-18 14:31:32 +00:00
|
|
|
glConfig.isFullscreen = qtrue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
if( noborder )
|
|
|
|
flags |= SDL_WINDOW_BORDERLESS;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
glConfig.isFullscreen = qfalse;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
colorBits = r_colorbits->value;
|
|
|
|
if ((!colorBits) || (colorBits >= 32))
|
|
|
|
colorBits = 24;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
if (!r_depthbits->value)
|
2017-07-10 01:33:41 +00:00
|
|
|
depthBits = 24;
|
2011-02-18 14:31:32 +00:00
|
|
|
else
|
2017-07-10 01:33:41 +00:00
|
|
|
depthBits = r_depthbits->value;
|
|
|
|
|
|
|
|
stencilBits = r_stencilbits->value;
|
2011-02-18 14:31:32 +00:00
|
|
|
samples = r_ext_multisample->value;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
int testColorBits, testDepthBits, testStencilBits;
|
2018-07-30 11:35:12 +00:00
|
|
|
int realColorBits[3];
|
2017-07-10 01:33:41 +00:00
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
// 0 - default
|
2017-07-10 01:33:41 +00:00
|
|
|
// 1 - minus colorBits
|
|
|
|
// 2 - minus depthBits
|
2011-02-18 14:31:32 +00:00
|
|
|
// 3 - minus stencil
|
|
|
|
if ((i % 4) == 0 && i)
|
|
|
|
{
|
|
|
|
// one pass, reduce
|
|
|
|
switch (i / 4)
|
|
|
|
{
|
|
|
|
case 2 :
|
2017-07-10 01:33:41 +00:00
|
|
|
if (colorBits == 24)
|
|
|
|
colorBits = 16;
|
2011-02-18 14:31:32 +00:00
|
|
|
break;
|
|
|
|
case 1 :
|
2017-07-10 01:33:41 +00:00
|
|
|
if (depthBits == 24)
|
|
|
|
depthBits = 16;
|
|
|
|
else if (depthBits == 16)
|
|
|
|
depthBits = 8;
|
2011-02-18 14:31:32 +00:00
|
|
|
case 3 :
|
2017-07-10 01:33:41 +00:00
|
|
|
if (stencilBits == 24)
|
|
|
|
stencilBits = 16;
|
|
|
|
else if (stencilBits == 16)
|
|
|
|
stencilBits = 8;
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
testColorBits = colorBits;
|
|
|
|
testDepthBits = depthBits;
|
|
|
|
testStencilBits = stencilBits;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
if ((i % 4) == 3)
|
2017-07-10 01:33:41 +00:00
|
|
|
{ // reduce colorBits
|
|
|
|
if (testColorBits == 24)
|
|
|
|
testColorBits = 16;
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((i % 4) == 2)
|
2017-07-10 01:33:41 +00:00
|
|
|
{ // reduce depthBits
|
|
|
|
if (testDepthBits == 24)
|
|
|
|
testDepthBits = 16;
|
|
|
|
else if (testDepthBits == 16)
|
|
|
|
testDepthBits = 8;
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((i % 4) == 1)
|
2017-07-10 01:33:41 +00:00
|
|
|
{ // reduce stencilBits
|
|
|
|
if (testStencilBits == 24)
|
|
|
|
testStencilBits = 16;
|
|
|
|
else if (testStencilBits == 16)
|
|
|
|
testStencilBits = 8;
|
2011-02-18 14:31:32 +00:00
|
|
|
else
|
2017-07-10 01:33:41 +00:00
|
|
|
testStencilBits = 0;
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if (testColorBits == 24)
|
|
|
|
perChannelColorBits = 8;
|
|
|
|
else
|
|
|
|
perChannelColorBits = 4;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
#ifdef __sgi /* Fix for SGIs grabbing too many bits of color */
|
2017-07-10 01:33:41 +00:00
|
|
|
if (perChannelColorBits == 4)
|
|
|
|
perChannelColorBits = 0; /* Use minimum size for 16-bit color */
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
/* Need alpha or else SGIs choose 36+ bit RGB mode */
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 1);
|
|
|
|
#endif
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, perChannelColorBits );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, perChannelColorBits );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, perChannelColorBits );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, testDepthBits );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, testStencilBits );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, samples ? 1 : 0 );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );
|
|
|
|
|
|
|
|
if(r_stereoEnabled->integer)
|
|
|
|
{
|
|
|
|
glConfig.stereoEnabled = qtrue;
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glConfig.stereoEnabled = qfalse;
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
#if 0 // if multisampling is enabled on X11, this causes create window to fail.
|
2011-02-18 14:31:32 +00:00
|
|
|
// If not allowing software GL, demand accelerated
|
|
|
|
if( !r_allowSoftwareGL->integer )
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
|
2011-02-18 14:31:32 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if( ( SDL_window = SDL_CreateWindow( CLIENT_WINDOW_TITLE, x, y,
|
|
|
|
glConfig.vidWidth, glConfig.vidHeight, flags ) ) == NULL )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_DEVELOPER, "SDL_CreateWindow failed: %s\n", SDL_GetError( ) );
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if( fullscreen )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_DisplayMode mode;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
switch( testColorBits )
|
|
|
|
{
|
|
|
|
case 16: mode.format = SDL_PIXELFORMAT_RGB565; break;
|
|
|
|
case 24: mode.format = SDL_PIXELFORMAT_RGB24; break;
|
|
|
|
default: ri.Printf( PRINT_DEVELOPER, "testColorBits is %d, can't fullscreen\n", testColorBits ); continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode.w = glConfig.vidWidth;
|
|
|
|
mode.h = glConfig.vidHeight;
|
|
|
|
mode.refresh_rate = glConfig.displayFrequency = ri.Cvar_VariableIntegerValue( "r_displayRefresh" );
|
|
|
|
mode.driverdata = NULL;
|
|
|
|
|
|
|
|
if( SDL_SetWindowDisplayMode( SDL_window, &mode ) < 0 )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowDisplayMode failed: %s\n", SDL_GetError( ) );
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_SetWindowIcon( SDL_window, icon );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
if (!fixedFunction)
|
2017-08-07 05:23:43 +00:00
|
|
|
{
|
|
|
|
int profileMask, majorVersion, minorVersion;
|
|
|
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
|
|
|
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &majorVersion);
|
|
|
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minorVersion);
|
|
|
|
|
|
|
|
ri.Printf(PRINT_ALL, "Trying to get an OpenGL 3.2 core context\n");
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
|
|
|
if ((SDL_glContext = SDL_GL_CreateContext(SDL_window)) == NULL)
|
|
|
|
{
|
|
|
|
ri.Printf(PRINT_ALL, "SDL_GL_CreateContext failed: %s\n", SDL_GetError());
|
|
|
|
ri.Printf(PRINT_ALL, "Reverting to default context\n");
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profileMask);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *renderer;
|
|
|
|
|
|
|
|
ri.Printf(PRINT_ALL, "SDL_GL_CreateContext succeeded.\n");
|
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
if ( GLimp_GetProcAddresses( fixedFunction ) )
|
2017-08-07 05:23:43 +00:00
|
|
|
{
|
2017-11-04 11:30:30 +00:00
|
|
|
renderer = (const char *)qglGetString(GL_RENDERER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() failed for OpenGL 3.2 core context\n" );
|
|
|
|
renderer = NULL;
|
|
|
|
}
|
2017-08-07 05:23:43 +00:00
|
|
|
|
2017-11-04 11:30:30 +00:00
|
|
|
if (!renderer || (strstr(renderer, "Software Renderer") || strstr(renderer, "Software Rasterizer")))
|
|
|
|
{
|
|
|
|
if ( renderer )
|
|
|
|
ri.Printf(PRINT_ALL, "GL_RENDERER is %s, rejecting context\n", renderer);
|
|
|
|
|
|
|
|
GLimp_ClearProcAddresses();
|
2017-08-07 05:23:43 +00:00
|
|
|
SDL_GL_DeleteContext(SDL_glContext);
|
|
|
|
SDL_glContext = NULL;
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profileMask);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SDL_glContext = NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-04 11:30:30 +00:00
|
|
|
if ( !SDL_glContext )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2017-11-04 11:30:30 +00:00
|
|
|
if( ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_DEVELOPER, "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
|
2018-07-30 11:35:12 +00:00
|
|
|
SDL_DestroyWindow( SDL_window );
|
|
|
|
SDL_window = NULL;
|
2017-11-04 11:30:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
if ( !GLimp_GetProcAddresses( fixedFunction ) )
|
2017-11-04 11:30:30 +00:00
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() failed\n" );
|
|
|
|
GLimp_ClearProcAddresses();
|
|
|
|
SDL_GL_DeleteContext( SDL_glContext );
|
|
|
|
SDL_glContext = NULL;
|
|
|
|
SDL_DestroyWindow( SDL_window );
|
|
|
|
SDL_window = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
qglClearColor( 0, 0, 0, 1 );
|
|
|
|
qglClear( GL_COLOR_BUFFER_BIT );
|
|
|
|
SDL_GL_SwapWindow( SDL_window );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if( SDL_GL_SetSwapInterval( r_swapInterval->integer ) == -1 )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_DEVELOPER, "SDL_GL_SetSwapInterval failed: %s\n", SDL_GetError( ) );
|
|
|
|
}
|
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &realColorBits[0] );
|
|
|
|
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &realColorBits[1] );
|
|
|
|
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &realColorBits[2] );
|
|
|
|
SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &glConfig.depthBits );
|
|
|
|
SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &glConfig.stencilBits );
|
|
|
|
|
|
|
|
glConfig.colorBits = realColorBits[0] + realColorBits[1] + realColorBits[2];
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Printf( PRINT_ALL, "Using %d color bits, %d depth, %d stencil display.\n",
|
|
|
|
glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits );
|
2011-02-18 14:31:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_FreeSurface( icon );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if( !SDL_window )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "Couldn't get a visual\n" );
|
|
|
|
return RSERR_INVALID_MODE;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
GLimp_DetectAvailableModes();
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
glstring = (char *) qglGetString (GL_RENDERER);
|
|
|
|
ri.Printf( PRINT_ALL, "GL_RENDERER: %s\n", glstring );
|
|
|
|
|
|
|
|
return RSERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_StartDriverAndSetMode
|
|
|
|
===============
|
|
|
|
*/
|
2017-08-07 05:23:43 +00:00
|
|
|
static qboolean GLimp_StartDriverAndSetMode(int mode, qboolean fullscreen, qboolean noborder, qboolean gl3Core)
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
rserr_t err;
|
|
|
|
|
|
|
|
if (!SDL_WasInit(SDL_INIT_VIDEO))
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
const char *driverName;
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) != 0)
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Printf( PRINT_ALL, "SDL_Init( SDL_INIT_VIDEO ) FAILED (%s)\n", SDL_GetError());
|
2011-02-18 14:31:32 +00:00
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
driverName = SDL_GetCurrentVideoDriver( );
|
2011-02-18 14:31:32 +00:00
|
|
|
ri.Printf( PRINT_ALL, "SDL using driver \"%s\"\n", driverName );
|
2011-08-10 21:14:44 +00:00
|
|
|
ri.Cvar_Set( "r_sdlDriver", driverName );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2011-08-10 21:14:44 +00:00
|
|
|
if (fullscreen && ri.Cvar_VariableIntegerValue( "in_nograb" ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "Fullscreen not allowed with in_nograb 1\n");
|
|
|
|
ri.Cvar_Set( "r_fullscreen", "0" );
|
|
|
|
r_fullscreen->modified = qfalse;
|
|
|
|
fullscreen = qfalse;
|
|
|
|
}
|
|
|
|
|
2017-08-07 05:23:43 +00:00
|
|
|
err = GLimp_SetMode(mode, fullscreen, noborder, gl3Core);
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
switch ( err )
|
|
|
|
{
|
|
|
|
case RSERR_INVALID_FULLSCREEN:
|
|
|
|
ri.Printf( PRINT_ALL, "...WARNING: fullscreen unavailable in this mode\n" );
|
|
|
|
return qfalse;
|
|
|
|
case RSERR_INVALID_MODE:
|
|
|
|
ri.Printf( PRINT_ALL, "...WARNING: could not set the given mode (%d)\n", mode );
|
|
|
|
return qfalse;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_InitExtensions
|
|
|
|
===============
|
|
|
|
*/
|
2018-07-30 11:35:12 +00:00
|
|
|
static void GLimp_InitExtensions( qboolean fixedFunction )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
if ( !r_allowExtensions->integer )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "* IGNORING OPENGL EXTENSIONS *\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ri.Printf( PRINT_ALL, "Initializing OpenGL extensions\n" );
|
|
|
|
|
|
|
|
glConfig.textureCompression = TC_NONE;
|
|
|
|
|
|
|
|
// GL_EXT_texture_compression_s3tc
|
2017-07-10 01:33:41 +00:00
|
|
|
if ( SDL_GL_ExtensionSupported( "GL_ARB_texture_compression" ) &&
|
|
|
|
SDL_GL_ExtensionSupported( "GL_EXT_texture_compression_s3tc" ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
if ( r_ext_compressed_textures->value )
|
|
|
|
{
|
|
|
|
glConfig.textureCompression = TC_S3TC_ARB;
|
|
|
|
ri.Printf( PRINT_ALL, "...using GL_EXT_texture_compression_s3tc\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...ignoring GL_EXT_texture_compression_s3tc\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...GL_EXT_texture_compression_s3tc not found\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// GL_S3_s3tc ... legacy extension before GL_EXT_texture_compression_s3tc.
|
|
|
|
if (glConfig.textureCompression == TC_NONE)
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
if ( SDL_GL_ExtensionSupported( "GL_S3_s3tc" ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
if ( r_ext_compressed_textures->value )
|
|
|
|
{
|
|
|
|
glConfig.textureCompression = TC_S3TC;
|
|
|
|
ri.Printf( PRINT_ALL, "...using GL_S3_s3tc\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...ignoring GL_S3_s3tc\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...GL_S3_s3tc not found\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
// OpenGL 1 fixed function pipeline
|
|
|
|
if ( fixedFunction )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
// GL_EXT_texture_env_add
|
|
|
|
glConfig.textureEnvAddAvailable = qfalse;
|
|
|
|
if ( SDL_GL_ExtensionSupported( "GL_EXT_texture_env_add" ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
if ( r_ext_texture_env_add->integer )
|
|
|
|
{
|
|
|
|
glConfig.textureEnvAddAvailable = qtrue;
|
|
|
|
ri.Printf( PRINT_ALL, "...using GL_EXT_texture_env_add\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glConfig.textureEnvAddAvailable = qfalse;
|
|
|
|
ri.Printf( PRINT_ALL, "...ignoring GL_EXT_texture_env_add\n" );
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
ri.Printf( PRINT_ALL, "...GL_EXT_texture_env_add not found\n" );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
// GL_ARB_multitexture
|
|
|
|
qglMultiTexCoord2fARB = NULL;
|
|
|
|
qglActiveTextureARB = NULL;
|
|
|
|
qglClientActiveTextureARB = NULL;
|
|
|
|
if ( SDL_GL_ExtensionSupported( "GL_ARB_multitexture" ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
if ( r_ext_multitexture->value )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
qglMultiTexCoord2fARB = SDL_GL_GetProcAddress( "glMultiTexCoord2fARB" );
|
|
|
|
qglActiveTextureARB = SDL_GL_GetProcAddress( "glActiveTextureARB" );
|
|
|
|
qglClientActiveTextureARB = SDL_GL_GetProcAddress( "glClientActiveTextureARB" );
|
|
|
|
|
|
|
|
if ( qglActiveTextureARB )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
GLint glint = 0;
|
|
|
|
qglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &glint );
|
|
|
|
glConfig.numTextureUnits = (int) glint;
|
|
|
|
if ( glConfig.numTextureUnits > 1 )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...using GL_ARB_multitexture\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qglMultiTexCoord2fARB = NULL;
|
|
|
|
qglActiveTextureARB = NULL;
|
|
|
|
qglClientActiveTextureARB = NULL;
|
|
|
|
ri.Printf( PRINT_ALL, "...not using GL_ARB_multitexture, < 2 texture units\n" );
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 11:35:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...ignoring GL_ARB_multitexture\n" );
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
ri.Printf( PRINT_ALL, "...GL_ARB_multitexture not found\n" );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
// GL_EXT_compiled_vertex_array
|
|
|
|
if ( SDL_GL_ExtensionSupported( "GL_EXT_compiled_vertex_array" ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
if ( r_ext_compiled_vertex_array->value )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
ri.Printf( PRINT_ALL, "...using GL_EXT_compiled_vertex_array\n" );
|
|
|
|
qglLockArraysEXT = ( void ( APIENTRY * )( GLint, GLint ) ) SDL_GL_GetProcAddress( "glLockArraysEXT" );
|
|
|
|
qglUnlockArraysEXT = ( void ( APIENTRY * )( void ) ) SDL_GL_GetProcAddress( "glUnlockArraysEXT" );
|
|
|
|
if (!qglLockArraysEXT || !qglUnlockArraysEXT)
|
|
|
|
{
|
|
|
|
ri.Error (ERR_FATAL, "bad getprocaddress");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...ignoring GL_EXT_compiled_vertex_array\n" );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-30 11:35:12 +00:00
|
|
|
ri.Printf( PRINT_ALL, "...GL_EXT_compiled_vertex_array not found\n" );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
textureFilterAnisotropic = qfalse;
|
2017-07-10 01:33:41 +00:00
|
|
|
if ( SDL_GL_ExtensionSupported( "GL_EXT_texture_filter_anisotropic" ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
if ( r_ext_texture_filter_anisotropic->integer ) {
|
|
|
|
qglGetIntegerv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint *)&maxAnisotropy );
|
|
|
|
if ( maxAnisotropy <= 0 ) {
|
|
|
|
ri.Printf( PRINT_ALL, "...GL_EXT_texture_filter_anisotropic not properly supported!\n" );
|
|
|
|
maxAnisotropy = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...using GL_EXT_texture_filter_anisotropic (max: %i)\n", maxAnisotropy );
|
|
|
|
textureFilterAnisotropic = qtrue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...ignoring GL_EXT_texture_filter_anisotropic\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "...GL_EXT_texture_filter_anisotropic not found\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define R_MODE_FALLBACK 3 // 640 * 480
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_Init
|
|
|
|
|
|
|
|
This routine is responsible for initializing the OS specific portions
|
|
|
|
of OpenGL
|
|
|
|
===============
|
|
|
|
*/
|
2018-07-30 11:35:12 +00:00
|
|
|
void GLimp_Init( qboolean fixedFunction )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Printf( PRINT_DEVELOPER, "Glimp_Init( )\n" );
|
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
r_allowSoftwareGL = ri.Cvar_Get( "r_allowSoftwareGL", "0", CVAR_LATCH );
|
|
|
|
r_sdlDriver = ri.Cvar_Get( "r_sdlDriver", "", CVAR_ROM );
|
2017-07-10 01:33:41 +00:00
|
|
|
r_allowResize = ri.Cvar_Get( "r_allowResize", "0", CVAR_ARCHIVE | CVAR_LATCH );
|
|
|
|
r_centerWindow = ri.Cvar_Get( "r_centerWindow", "0", CVAR_ARCHIVE | CVAR_LATCH );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2011-08-10 21:14:44 +00:00
|
|
|
if( ri.Cvar_VariableIntegerValue( "com_abnormalExit" ) )
|
2011-02-18 14:31:32 +00:00
|
|
|
{
|
|
|
|
ri.Cvar_Set( "r_mode", va( "%d", R_MODE_FALLBACK ) );
|
|
|
|
ri.Cvar_Set( "r_fullscreen", "0" );
|
|
|
|
ri.Cvar_Set( "r_centerWindow", "0" );
|
|
|
|
ri.Cvar_Set( "com_abnormalExit", "0" );
|
|
|
|
}
|
|
|
|
|
2011-08-10 21:14:44 +00:00
|
|
|
ri.Sys_GLimpInit( );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
// Create the window and set up the context
|
2018-07-30 11:35:12 +00:00
|
|
|
if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, r_noborder->integer, fixedFunction))
|
2011-02-18 14:31:32 +00:00
|
|
|
goto success;
|
|
|
|
|
|
|
|
// Try again, this time in a platform specific "safe mode"
|
2011-08-10 21:14:44 +00:00
|
|
|
ri.Sys_GLimpSafeInit( );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, qfalse, fixedFunction))
|
2011-02-18 14:31:32 +00:00
|
|
|
goto success;
|
|
|
|
|
|
|
|
// Finally, try the default screen resolution
|
|
|
|
if( r_mode->integer != R_MODE_FALLBACK )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "Setting r_mode %d failed, falling back on r_mode %d\n",
|
|
|
|
r_mode->integer, R_MODE_FALLBACK );
|
|
|
|
|
2018-07-30 11:35:12 +00:00
|
|
|
if(GLimp_StartDriverAndSetMode(R_MODE_FALLBACK, qfalse, qfalse, fixedFunction))
|
2011-02-18 14:31:32 +00:00
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing worked, give up
|
2011-07-26 08:52:24 +00:00
|
|
|
ri.Error( ERR_FATAL, "GLimp_Init() - could not load OpenGL subsystem" );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
success:
|
2017-07-10 01:33:41 +00:00
|
|
|
// These values force the UI to disable driver selection
|
2011-02-18 14:31:32 +00:00
|
|
|
glConfig.driverType = GLDRV_ICD;
|
|
|
|
glConfig.hardwareType = GLHW_GENERIC;
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
// Only using SDL_SetWindowBrightness to determine if hardware gamma is supported
|
|
|
|
glConfig.deviceSupportsGamma = !r_ignorehwgamma->integer &&
|
|
|
|
SDL_SetWindowBrightness( SDL_window, 1.0f ) >= 0;
|
2012-09-15 03:03:44 +00:00
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
// get our config strings
|
|
|
|
Q_strncpyz( glConfig.vendor_string, (char *) qglGetString (GL_VENDOR), sizeof( glConfig.vendor_string ) );
|
|
|
|
Q_strncpyz( glConfig.renderer_string, (char *) qglGetString (GL_RENDERER), sizeof( glConfig.renderer_string ) );
|
|
|
|
if (*glConfig.renderer_string && glConfig.renderer_string[strlen(glConfig.renderer_string) - 1] == '\n')
|
|
|
|
glConfig.renderer_string[strlen(glConfig.renderer_string) - 1] = 0;
|
|
|
|
Q_strncpyz( glConfig.version_string, (char *) qglGetString (GL_VERSION), sizeof( glConfig.version_string ) );
|
2017-11-04 11:30:30 +00:00
|
|
|
|
|
|
|
// manually create extension list if using OpenGL 3
|
|
|
|
if ( qglGetStringi )
|
|
|
|
{
|
|
|
|
int i, numExtensions, extensionLength, listLength;
|
|
|
|
const char *extension;
|
|
|
|
|
|
|
|
qglGetIntegerv( GL_NUM_EXTENSIONS, &numExtensions );
|
|
|
|
listLength = 0;
|
|
|
|
|
|
|
|
for ( i = 0; i < numExtensions; i++ )
|
|
|
|
{
|
|
|
|
extension = (char *) qglGetStringi( GL_EXTENSIONS, i );
|
|
|
|
extensionLength = strlen( extension );
|
|
|
|
|
|
|
|
if ( ( listLength + extensionLength + 1 ) >= sizeof( glConfig.extensions_string ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ( i > 0 ) {
|
|
|
|
Q_strcat( glConfig.extensions_string, sizeof( glConfig.extensions_string ), " " );
|
|
|
|
listLength++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_strcat( glConfig.extensions_string, sizeof( glConfig.extensions_string ), extension );
|
|
|
|
listLength += extensionLength;
|
|
|
|
}
|
|
|
|
}
|
2017-08-07 05:23:43 +00:00
|
|
|
else
|
2017-11-04 11:30:30 +00:00
|
|
|
{
|
|
|
|
Q_strncpyz( glConfig.extensions_string, (char *) qglGetString (GL_EXTENSIONS), sizeof( glConfig.extensions_string ) );
|
|
|
|
}
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
// initialize extensions
|
2018-07-30 11:35:12 +00:00
|
|
|
GLimp_InitExtensions( fixedFunction );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
|
|
|
ri.Cvar_Get( "r_availableModes", "", CVAR_ROM );
|
|
|
|
|
|
|
|
// This depends on SDL_INIT_VIDEO, hence having it here
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.IN_Init( SDL_window );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GLimp_EndFrame
|
|
|
|
|
|
|
|
Responsible for doing a swapbuffers
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void GLimp_EndFrame( void )
|
|
|
|
{
|
|
|
|
// don't flip if drawing to front buffer
|
|
|
|
if ( Q_stricmp( r_drawBuffer->string, "GL_FRONT" ) != 0 )
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
SDL_GL_SwapWindow( SDL_window );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( r_fullscreen->modified )
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
int fullscreen;
|
|
|
|
qboolean needToToggle;
|
2011-02-18 14:31:32 +00:00
|
|
|
qboolean sdlToggled = qfalse;
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
// Find out the current state
|
|
|
|
fullscreen = !!( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_FULLSCREEN );
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
if( r_fullscreen->integer && ri.Cvar_VariableIntegerValue( "in_nograb" ) )
|
|
|
|
{
|
|
|
|
ri.Printf( PRINT_ALL, "Fullscreen not allowed with in_nograb 1\n");
|
|
|
|
ri.Cvar_Set( "r_fullscreen", "0" );
|
|
|
|
r_fullscreen->modified = qfalse;
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 01:33:41 +00:00
|
|
|
// Is the state we want different from the current state?
|
|
|
|
needToToggle = !!r_fullscreen->integer != fullscreen;
|
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
if( needToToggle )
|
|
|
|
{
|
2017-07-10 01:33:41 +00:00
|
|
|
sdlToggled = SDL_SetWindowFullscreen( SDL_window, r_fullscreen->integer ) >= 0;
|
|
|
|
|
2011-02-18 14:31:32 +00:00
|
|
|
// SDL_WM_ToggleFullScreen didn't work, so do it the slow way
|
|
|
|
if( !sdlToggled )
|
2017-07-10 01:33:41 +00:00
|
|
|
ri.Cmd_ExecuteText(EXEC_APPEND, "vid_restart\n");
|
2011-02-18 14:31:32 +00:00
|
|
|
|
2011-08-10 21:14:44 +00:00
|
|
|
ri.IN_Restart( );
|
2011-02-18 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r_fullscreen->modified = qfalse;
|
|
|
|
}
|
|
|
|
}
|