Add fixes from upstream ioq3

This commit is contained in:
smallmodel 2024-09-19 19:24:04 +02:00
parent 3e70a9fab8
commit 205709271b
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
5 changed files with 175 additions and 110 deletions

View file

@ -52,7 +52,7 @@ cvar_t *r_allowSoftwareGL; // Don't abort out if a hardware visual can't be obta
cvar_t *r_allowResize; // make window resizable
cvar_t *r_centerWindow;
cvar_t *r_sdlDriver;
cvar_t *r_useOpenGLES;
cvar_t *r_preferOpenGLES;
int qglMajorVersion, qglMinorVersion;
int qglesMajorVersion, qglesMinorVersion;
@ -315,7 +315,8 @@ static qboolean GLimp_GetProcAddresses( qboolean fixedFunction ) {
} else {
Com_Error( ERR_FATAL, "Unsupported OpenGL Version (%s), OpenGL 1.1 is required", version );
}
// Add compression-related GL functions for the renderer
// Added in OPM
// Add compression-related GL functions for the renderer
if ( QGL_VERSION_ATLEAST( 1, 3 ) ) {
QGL_1_3_PROCS;
}
@ -398,6 +399,12 @@ GLimp_SetMode
*/
static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qboolean fixedFunction)
{
struct GLimp_ContextType {
int profileMask;
int majorVersion;
int minorVersion;
} contexts[4];
int numContexts, type;
const char *glstring;
int perChannelColorBits;
int colorBits, depthBits, stencilBits;
@ -436,10 +443,11 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool
if( display < 0 )
{
ri.Printf( PRINT_DEVELOPER, "SDL_GetWindowDisplayIndex() failed: %s\n", SDL_GetError() );
display = 0;
}
}
if( display >= 0 && SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
if( SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
{
displayAspect = (float)desktopMode.w / (float)desktopMode.h;
@ -528,6 +536,63 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool
stencilBits = r_stencilbits->value;
samples = r_ext_multisample->value;
numContexts = 0;
if ( !fixedFunction ) {
int profileMask;
qboolean preferOpenGLES;
SDL_GL_ResetAttributes();
SDL_GL_GetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, &profileMask );
preferOpenGLES = ( r_preferOpenGLES->integer == 1 ||
( r_preferOpenGLES->integer == -1 && profileMask == SDL_GL_CONTEXT_PROFILE_ES ) );
if ( preferOpenGLES ) {
#ifdef __EMSCRIPTEN__
// WebGL 2.0 isn't fully backward compatible so you have to ask for it specifically
contexts[numContexts].profileMask = SDL_GL_CONTEXT_PROFILE_ES;
contexts[numContexts].majorVersion = 3;
contexts[numContexts].minorVersion = 0;
numContexts++;
#endif
contexts[numContexts].profileMask = SDL_GL_CONTEXT_PROFILE_ES;
contexts[numContexts].majorVersion = 2;
contexts[numContexts].minorVersion = 0;
numContexts++;
}
contexts[numContexts].profileMask = SDL_GL_CONTEXT_PROFILE_CORE;
contexts[numContexts].majorVersion = 3;
contexts[numContexts].minorVersion = 2;
numContexts++;
contexts[numContexts].profileMask = 0;
contexts[numContexts].majorVersion = 2;
contexts[numContexts].minorVersion = 0;
numContexts++;
if ( !preferOpenGLES ) {
#ifdef __EMSCRIPTEN__
contexts[numContexts].profileMask = SDL_GL_CONTEXT_PROFILE_ES;
contexts[numContexts].majorVersion = 3;
contexts[numContexts].minorVersion = 0;
numContexts++;
#endif
contexts[numContexts].profileMask = SDL_GL_CONTEXT_PROFILE_ES;
contexts[numContexts].majorVersion = 2;
contexts[numContexts].minorVersion = 0;
numContexts++;
}
} else {
contexts[numContexts].profileMask = 0;
contexts[numContexts].majorVersion = 1;
contexts[numContexts].minorVersion = 1;
numContexts++;
}
for (i = 0; i < 16; i++)
{
int testColorBits, testDepthBits, testStencilBits;
@ -660,116 +725,68 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool
SDL_SetWindowIcon( SDL_window, icon );
if (!fixedFunction)
{
int profileMask;
for ( type = 0; type < numContexts; type++ ) {
char contextName[32];
SDL_GL_GetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, &profileMask );
if ( r_useOpenGLES->integer == 1 || ( r_useOpenGLES->integer == -1 && profileMask == SDL_GL_CONTEXT_PROFILE_ES ) )
{
ri.Printf( PRINT_ALL, "Trying to get an OpenGL ES 2.0 context\n" );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 0 );
SDL_glContext = SDL_GL_CreateContext( SDL_window );
if ( !SDL_glContext )
{
ri.Printf( PRINT_ALL, "SDL_GL_CreateContext failed: %s\n", SDL_GetError() );
}
else
{
ri.Printf( PRINT_ALL, "SDL_GL_CreateContext succeeded.\n" );
if ( !GLimp_GetProcAddresses( fixedFunction ) )
{
ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() failed for OpenGL ES 2.0 context\n" );
GLimp_ClearProcAddresses();
SDL_GL_DeleteContext( SDL_glContext );
SDL_glContext = NULL;
}
}
switch ( contexts[type].profileMask ) {
default:
case 0:
Com_sprintf( contextName, sizeof( contextName ), "OpenGL %d.%d",
contexts[type].majorVersion, contexts[type].minorVersion );
break;
case SDL_GL_CONTEXT_PROFILE_CORE:
Com_sprintf( contextName, sizeof( contextName ), "OpenGL %d.%d Core",
contexts[type].majorVersion, contexts[type].minorVersion );
break;
case SDL_GL_CONTEXT_PROFILE_ES:
Com_sprintf( contextName, sizeof( contextName ), "OpenGL ES %d.%d",
contexts[type].majorVersion, contexts[type].minorVersion );
break;
}
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, contexts[type].profileMask );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, contexts[type].majorVersion );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, contexts[type].minorVersion );
SDL_glContext = SDL_GL_CreateContext( SDL_window );
if ( !SDL_glContext )
{
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 );
SDL_glContext = SDL_GL_CreateContext( SDL_window );
if ( !SDL_glContext )
{
ri.Printf( PRINT_ALL, "SDL_GL_CreateContext failed: %s\n", SDL_GetError() );
}
else
{
const char *renderer;
ri.Printf( PRINT_ALL, "SDL_GL_CreateContext succeeded.\n" );
if ( GLimp_GetProcAddresses( fixedFunction ) )
{
renderer = (const char *)qglGetString( GL_RENDERER );
}
else
{
ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() failed for OpenGL 3.2 core context\n" );
renderer = NULL;
}
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();
SDL_GL_DeleteContext( SDL_glContext );
SDL_glContext = NULL;
}
}
}
if ( !SDL_glContext )
{
ri.Printf( PRINT_ALL, "Trying to get an OpenGL 2.0 context\n" );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, 0 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 0 );
}
}
else
{
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, 0 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
SDL_glContext = NULL;
}
if ( !SDL_glContext )
{
if( ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
{
ri.Printf( PRINT_DEVELOPER, "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
SDL_DestroyWindow( SDL_window );
SDL_window = NULL;
ri.Printf( PRINT_ALL, "SDL_GL_CreateContext() for %s context failed: %s\n", contextName, SDL_GetError() );
continue;
}
if ( !GLimp_GetProcAddresses( fixedFunction ) )
{
ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() failed\n" );
ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() for %s context failed\n", contextName );
GLimp_ClearProcAddresses();
SDL_GL_DeleteContext( SDL_glContext );
SDL_glContext = NULL;
SDL_DestroyWindow( SDL_window );
SDL_window = NULL;
continue;
}
if ( contexts[type].profileMask == SDL_GL_CONTEXT_PROFILE_CORE ) {
const char *renderer;
renderer = (const char *)qglGetString( GL_RENDERER );
if ( !renderer || strstr( renderer, "Software Renderer" ) || strstr( renderer, "Software Rasterizer" ) )
{
ri.Printf( PRINT_ALL, "GL_RENDERER is %s, rejecting %s context\n", renderer, contextName );
GLimp_ClearProcAddresses();
SDL_GL_DeleteContext( SDL_glContext );
SDL_glContext = NULL;
continue;
}
}
break;
}
if ( !SDL_glContext ) {
SDL_DestroyWindow( SDL_window );
SDL_window = NULL;
continue;
}
qglClearColor( 0, 0, 0, 1 );
@ -1059,7 +1076,7 @@ void GLimp_Init( qboolean fixedFunction )
r_sdlDriver = ri.Cvar_Get( "r_sdlDriver", "", CVAR_ROM );
r_allowResize = ri.Cvar_Get( "r_allowResize", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_centerWindow = ri.Cvar_Get( "r_centerWindow", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_useOpenGLES = ri.Cvar_Get( "r_useOpenGLES", "-1", CVAR_ARCHIVE | CVAR_LATCH );
r_preferOpenGLES = ri.Cvar_Get( "r_preferOpenGLES", "-1", CVAR_ARCHIVE | CVAR_LATCH );
if( ri.Cvar_VariableIntegerValue( "com_abnormalExit" ) )
{

View file

@ -59,6 +59,8 @@ static int in_eventTime = 0;
static SDL_Window *SDL_window = NULL;
#define CTRL(a) ((a)-'a'+1)
/*
===============
IN_PrintKey
@ -213,6 +215,8 @@ static keyNum_t IN_TranslateSDLToQ3Key( SDL_Keysym *keysym, qboolean down )
}
else if (keysym->scancode == SDL_SCANCODE_GRAVE)
{
// Added in OPM
// so the console can be toggled properly
key = '`';
}
else
@ -1016,7 +1020,7 @@ static void IN_ProcessEvents( void )
if( key == K_BACKSPACE )
Com_QueueEvent( in_eventTime, SE_CHAR, CTRL('h'), 0, 0, NULL );
else if (key == K_ENTER || key == K_TAB || key == K_ESCAPE) // mostly used by UINotepad
else if (key == K_ENTER || key == K_TAB || key == K_ESCAPE) // Added in OPM: mostly used by UINotepad
Com_QueueEvent( in_eventTime, SE_CHAR, key, 0, 0, NULL);
else if( keys[K_CTRL].down && key >= 'a' && key <= 'z' )
Com_QueueEvent( in_eventTime, SE_CHAR, CTRL(key), 0, 0, NULL );

View file

@ -31,6 +31,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <ctype.h>
#include <errno.h>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
#ifndef DEDICATED
#ifdef USE_LOCAL_HEADERS
# include "SDL.h"
@ -834,16 +838,13 @@ int main( int argc, char **argv )
}
containsSpaces = strchr(argv[i], ' ') != NULL;
//
// Seriously ioquake3, why? Why??
//
//if (containsSpaces)
// Q_strcat( commandLine, sizeof( commandLine ), "\"" );
if (containsSpaces)
Q_strcat( commandLine, sizeof( commandLine ), "\"" );
Q_strcat( commandLine, sizeof( commandLine ), argv[ i ] );
//if (containsSpaces)
// Q_strcat( commandLine, sizeof( commandLine ), "\"" );
if (containsSpaces)
Q_strcat( commandLine, sizeof( commandLine ), "\"" );
Q_strcat( commandLine, sizeof( commandLine ), " " );
}
@ -859,7 +860,7 @@ int main( int argc, char **argv )
CON_Init( );
Com_Init( commandLine );
Sys_InitEx();
Sys_InitEx(); // Added in OPM
NET_Init( );
signal( SIGILL, Sys_SigHandler );
@ -868,10 +869,14 @@ int main( int argc, char **argv )
signal( SIGTERM, Sys_SigHandler );
signal( SIGINT, Sys_SigHandler );
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop( Com_Frame, 0, 1 );
#else
while( 1 )
{
Com_Frame( );
}
#endif
return 0;
}

View file

@ -67,10 +67,11 @@ char *Sys_DefaultHomePath(void)
if( !*homePath && com_homepath != NULL )
{
#ifdef __APPLE__
if( ( p = getenv( "HOME" ) ) != NULL )
{
Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP);
#ifdef __APPLE__
Q_strcat(homePath, sizeof(homePath),
"Library/Application Support/");
@ -78,13 +79,44 @@ char *Sys_DefaultHomePath(void)
Q_strcat(homePath, sizeof(homePath), com_homepath->string);
else
Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_MACOSX);
}
#else
if( ( p = getenv( "FLATPAK_ID" ) ) != NULL && *p != '\0' )
{
if( ( p = getenv( "XDG_DATA_HOME" ) ) != NULL && *p != '\0' )
{
Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP);
}
else if( ( p = getenv( "HOME" ) ) != NULL && *p != '\0' )
{
Com_sprintf(homePath, sizeof(homePath), "%s%c.local%cshare%c", p, PATH_SEP, PATH_SEP, PATH_SEP);
}
if( *homePath )
{
char *dir;
if(com_homepath->string[0])
dir = com_homepath->string;
else
dir = HOMEPATH_NAME_UNIX;
if(dir[0] == '.' && dir[1] != '\0')
dir++;
Q_strcat(homePath, sizeof(homePath), dir);
}
}
else if( ( p = getenv( "HOME" ) ) != NULL )
{
Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP);
if(com_homepath->string[0])
Q_strcat(homePath, sizeof(homePath), com_homepath->string);
else
Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_UNIX);
#endif
}
#endif
}
return homePath;

View file

@ -20,6 +20,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#ifdef _WIN32_WINNT_WINXP
// Use EnumProcesses() with Windows XP compatibility
# define PSAPI_VERSION 1
#endif
#include "../qcommon/q_shared.h"
#include "../qcommon/qcommon.h"
#include "sys_local.h"
@ -724,6 +729,8 @@ Display an error message
*/
void Sys_ErrorDialog( const char *error )
{
Sys_Print( va( "%s\n", error ) );
if( Sys_Dialog( DT_YES_NO, va( "%s. Copy console log to clipboard?", error ),
"Error" ) == DR_YES )
{