mirror of
https://github.com/ioquake/ioq3.git
synced 2025-06-02 09:51:21 +00:00
Use SDL 2 instead of SDL 1.2
This commit is contained in:
parent
4432a80a3c
commit
f478761e07
13 changed files with 404 additions and 540 deletions
|
@ -43,20 +43,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "../sys/sys_local.h"
|
||||
#include "sdl_icon.h"
|
||||
|
||||
/* Just hack it for now. */
|
||||
#ifdef MACOS_X
|
||||
#include <OpenGL/OpenGL.h>
|
||||
typedef CGLContextObj QGLContext;
|
||||
#define GLimp_GetCurrentContext() CGLGetCurrentContext()
|
||||
#define GLimp_SetCurrentContext(ctx) CGLSetCurrentContext(ctx)
|
||||
#else
|
||||
typedef void *QGLContext;
|
||||
#define GLimp_GetCurrentContext() (NULL)
|
||||
#define GLimp_SetCurrentContext(ctx)
|
||||
#endif
|
||||
|
||||
static QGLContext opengl_context;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RSERR_OK,
|
||||
|
@ -67,8 +53,8 @@ typedef enum
|
|||
RSERR_UNKNOWN
|
||||
} rserr_t;
|
||||
|
||||
static SDL_Surface *screen = NULL;
|
||||
static const SDL_VideoInfo *videoInfo = NULL;
|
||||
SDL_Window *SDL_window = NULL;
|
||||
static SDL_GLContext *SDL_glContext = NULL;
|
||||
|
||||
cvar_t *r_allowSoftwareGL; // Don't abort out if a hardware visual can't be obtained
|
||||
cvar_t *r_allowResize; // make window resizable
|
||||
|
@ -92,7 +78,6 @@ void GLimp_Shutdown( void )
|
|||
ri.IN_Shutdown();
|
||||
|
||||
SDL_QuitSubSystem( SDL_INIT_VIDEO );
|
||||
screen = NULL;
|
||||
|
||||
Com_Memset( &glConfig, 0, sizeof( glConfig ) );
|
||||
Com_Memset( &glState, 0, sizeof( glState ) );
|
||||
|
@ -105,9 +90,9 @@ GLimp_Minimize
|
|||
Minimize the game so that user is back at the desktop
|
||||
===============
|
||||
*/
|
||||
void GLimp_Minimize(void)
|
||||
void GLimp_Minimize( void )
|
||||
{
|
||||
SDL_WM_IconifyWindow();
|
||||
SDL_MinimizeWindow( SDL_window );
|
||||
}
|
||||
|
||||
|
||||
|
@ -128,8 +113,8 @@ GLimp_CompareModes
|
|||
static int GLimp_CompareModes( const void *a, const void *b )
|
||||
{
|
||||
const float ASPECT_EPSILON = 0.001f;
|
||||
SDL_Rect *modeA = *(SDL_Rect **)a;
|
||||
SDL_Rect *modeB = *(SDL_Rect **)b;
|
||||
SDL_Rect *modeA = (SDL_Rect *)&a;
|
||||
SDL_Rect *modeB = (SDL_Rect *)&b;
|
||||
float aspectA = (float)modeA->w / (float)modeA->h;
|
||||
float aspectB = (float)modeB->w / (float)modeB->h;
|
||||
int areaA = modeA->w * modeA->h;
|
||||
|
@ -154,38 +139,52 @@ GLimp_DetectAvailableModes
|
|||
*/
|
||||
static void GLimp_DetectAvailableModes(void)
|
||||
{
|
||||
char buf[ MAX_STRING_CHARS ] = { 0 };
|
||||
SDL_Rect **modes;
|
||||
int numModes;
|
||||
int i;
|
||||
char buf[ MAX_STRING_CHARS ] = { 0 };
|
||||
SDL_Rect modes[ 128 ];
|
||||
int numModes = 0;
|
||||
|
||||
modes = SDL_ListModes( videoInfo->vfmt, SDL_OPENGL | SDL_FULLSCREEN );
|
||||
int display = SDL_GetWindowDisplayIndex( SDL_window );
|
||||
SDL_DisplayMode windowMode;
|
||||
|
||||
if( !modes )
|
||||
if( SDL_GetWindowDisplayMode( SDL_window, &windowMode ) < 0 )
|
||||
{
|
||||
ri.Printf( PRINT_WARNING, "Can't get list of available modes\n" );
|
||||
ri.Printf( PRINT_WARNING, "Couldn't get window display mode, no resolutions detected\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
if( modes == (SDL_Rect **)-1 )
|
||||
for( i = 0; i < SDL_GetNumDisplayModes( display ); i++ )
|
||||
{
|
||||
ri.Printf( PRINT_ALL, "Display supports any resolution\n" );
|
||||
return; // can set any resolution
|
||||
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" );
|
||||
return;
|
||||
}
|
||||
|
||||
if( windowMode.format != mode.format )
|
||||
continue;
|
||||
|
||||
modes[ numModes ].w = mode.w;
|
||||
modes[ numModes ].h = mode.h;
|
||||
numModes++;
|
||||
}
|
||||
|
||||
for( numModes = 0; modes[ numModes ]; numModes++ );
|
||||
|
||||
if( numModes > 1 )
|
||||
qsort( modes, numModes, sizeof( SDL_Rect* ), GLimp_CompareModes );
|
||||
qsort( modes, numModes, sizeof( SDL_Rect ), GLimp_CompareModes );
|
||||
|
||||
for( i = 0; i < numModes; i++ )
|
||||
{
|
||||
const char *newModeString = va( "%ux%u ", modes[ i ]->w, modes[ i ]->h );
|
||||
const char *newModeString = va( "%ux%u ", modes[ i ].w, modes[ i ].h );
|
||||
|
||||
if( strlen( newModeString ) < (int)sizeof( buf ) - strlen( buf ) )
|
||||
Q_strcat( buf, sizeof( buf ), newModeString );
|
||||
else
|
||||
ri.Printf( PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", modes[i]->w, modes[i]->h );
|
||||
ri.Printf( PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", modes[ i ].w, modes[ i ].h );
|
||||
}
|
||||
|
||||
if( *buf )
|
||||
|
@ -203,48 +202,51 @@ GLimp_SetMode
|
|||
*/
|
||||
static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
|
||||
{
|
||||
const char* glstring;
|
||||
int sdlcolorbits;
|
||||
int colorbits, depthbits, stencilbits;
|
||||
int tcolorbits, tdepthbits, tstencilbits;
|
||||
const char *glstring;
|
||||
int perChannelColorBits;
|
||||
int colorBits, depthBits, stencilBits;
|
||||
int samples;
|
||||
int i = 0;
|
||||
SDL_Surface *vidscreen = NULL;
|
||||
Uint32 flags = SDL_OPENGL;
|
||||
SDL_Surface *icon = NULL;
|
||||
Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
|
||||
SDL_DisplayMode desktopMode;
|
||||
int display = 0;
|
||||
int x = 0, y = 0;
|
||||
|
||||
ri.Printf( PRINT_ALL, "Initializing OpenGL display\n");
|
||||
|
||||
if ( r_allowResize->integer )
|
||||
flags |= SDL_RESIZABLE;
|
||||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
|
||||
if( videoInfo == NULL )
|
||||
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
|
||||
);
|
||||
|
||||
// If a window exists, note its display index
|
||||
if( SDL_window != NULL )
|
||||
display = SDL_GetWindowDisplayIndex( SDL_window );
|
||||
|
||||
if( SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
|
||||
{
|
||||
static SDL_VideoInfo sVideoInfo;
|
||||
static SDL_PixelFormat sPixelFormat;
|
||||
displayAspect = (float)desktopMode.w / (float)desktopMode.h;
|
||||
|
||||
videoInfo = SDL_GetVideoInfo( );
|
||||
ri.Printf( PRINT_ALL, "Display aspect: %.3f\n", displayAspect );
|
||||
}
|
||||
else
|
||||
{
|
||||
Com_Memset( &desktopMode, 0, sizeof( SDL_DisplayMode ) );
|
||||
|
||||
// Take a copy of the videoInfo
|
||||
Com_Memcpy( &sPixelFormat, videoInfo->vfmt, sizeof( SDL_PixelFormat ) );
|
||||
sPixelFormat.palette = NULL; // Should already be the case
|
||||
Com_Memcpy( &sVideoInfo, videoInfo, sizeof( SDL_VideoInfo ) );
|
||||
sVideoInfo.vfmt = &sPixelFormat;
|
||||
videoInfo = &sVideoInfo;
|
||||
|
||||
if( videoInfo->current_h > 0 )
|
||||
{
|
||||
// Guess the display aspect ratio through the desktop resolution
|
||||
// by assuming (relatively safely) that it is set at or close to
|
||||
// the display's native aspect ratio
|
||||
displayAspect = (float)videoInfo->current_w / (float)videoInfo->current_h;
|
||||
|
||||
ri.Printf( PRINT_ALL, "Estimated display aspect: %.3f\n", displayAspect );
|
||||
}
|
||||
else
|
||||
{
|
||||
ri.Printf( PRINT_ALL,
|
||||
"Cannot estimate display aspect, assuming 1.333\n" );
|
||||
}
|
||||
ri.Printf( PRINT_ALL,
|
||||
"Cannot determine display aspect, assuming 1.333\n" );
|
||||
}
|
||||
|
||||
ri.Printf (PRINT_ALL, "...setting mode %d:", mode );
|
||||
|
@ -252,10 +254,10 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
|
|||
if (mode == -2)
|
||||
{
|
||||
// use desktop video resolution
|
||||
if( videoInfo->current_h > 0 )
|
||||
if( desktopMode.h > 0 )
|
||||
{
|
||||
glConfig.vidWidth = videoInfo->current_w;
|
||||
glConfig.vidHeight = videoInfo->current_h;
|
||||
glConfig.vidWidth = desktopMode.w;
|
||||
glConfig.vidHeight = desktopMode.h;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -274,35 +276,60 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
|
|||
}
|
||||
ri.Printf( PRINT_ALL, " %d %d\n", glConfig.vidWidth, glConfig.vidHeight);
|
||||
|
||||
if (fullscreen)
|
||||
// Center window
|
||||
if( r_centerWindow->integer && !fullscreen )
|
||||
{
|
||||
flags |= SDL_FULLSCREEN;
|
||||
x = ( desktopMode.w / 2 ) - ( glConfig.vidWidth / 2 );
|
||||
y = ( desktopMode.h / 2 ) - ( glConfig.vidHeight / 2 );
|
||||
}
|
||||
|
||||
// Destroy existing state if it exists
|
||||
if( SDL_glContext != NULL )
|
||||
{
|
||||
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;
|
||||
glConfig.isFullscreen = qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (noborder)
|
||||
flags |= SDL_NOFRAME;
|
||||
if( noborder )
|
||||
flags |= SDL_WINDOW_BORDERLESS;
|
||||
|
||||
glConfig.isFullscreen = qfalse;
|
||||
}
|
||||
|
||||
colorbits = r_colorbits->value;
|
||||
if ((!colorbits) || (colorbits >= 32))
|
||||
colorbits = 24;
|
||||
colorBits = r_colorbits->value;
|
||||
if ((!colorBits) || (colorBits >= 32))
|
||||
colorBits = 24;
|
||||
|
||||
if (!r_depthbits->value)
|
||||
depthbits = 24;
|
||||
depthBits = 24;
|
||||
else
|
||||
depthbits = r_depthbits->value;
|
||||
stencilbits = r_stencilbits->value;
|
||||
depthBits = r_depthbits->value;
|
||||
|
||||
stencilBits = r_stencilbits->value;
|
||||
samples = r_ext_multisample->value;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
int testColorBits, testDepthBits, testStencilBits;
|
||||
|
||||
// 0 - default
|
||||
// 1 - minus colorbits
|
||||
// 2 - minus depthbits
|
||||
// 1 - minus colorBits
|
||||
// 2 - minus depthBits
|
||||
// 3 - minus stencil
|
||||
if ((i % 4) == 0 && i)
|
||||
{
|
||||
|
@ -310,67 +337,68 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
|
|||
switch (i / 4)
|
||||
{
|
||||
case 2 :
|
||||
if (colorbits == 24)
|
||||
colorbits = 16;
|
||||
if (colorBits == 24)
|
||||
colorBits = 16;
|
||||
break;
|
||||
case 1 :
|
||||
if (depthbits == 24)
|
||||
depthbits = 16;
|
||||
else if (depthbits == 16)
|
||||
depthbits = 8;
|
||||
if (depthBits == 24)
|
||||
depthBits = 16;
|
||||
else if (depthBits == 16)
|
||||
depthBits = 8;
|
||||
case 3 :
|
||||
if (stencilbits == 24)
|
||||
stencilbits = 16;
|
||||
else if (stencilbits == 16)
|
||||
stencilbits = 8;
|
||||
if (stencilBits == 24)
|
||||
stencilBits = 16;
|
||||
else if (stencilBits == 16)
|
||||
stencilBits = 8;
|
||||
}
|
||||
}
|
||||
|
||||
tcolorbits = colorbits;
|
||||
tdepthbits = depthbits;
|
||||
tstencilbits = stencilbits;
|
||||
testColorBits = colorBits;
|
||||
testDepthBits = depthBits;
|
||||
testStencilBits = stencilBits;
|
||||
|
||||
if ((i % 4) == 3)
|
||||
{ // reduce colorbits
|
||||
if (tcolorbits == 24)
|
||||
tcolorbits = 16;
|
||||
{ // reduce colorBits
|
||||
if (testColorBits == 24)
|
||||
testColorBits = 16;
|
||||
}
|
||||
|
||||
if ((i % 4) == 2)
|
||||
{ // reduce depthbits
|
||||
if (tdepthbits == 24)
|
||||
tdepthbits = 16;
|
||||
else if (tdepthbits == 16)
|
||||
tdepthbits = 8;
|
||||
{ // reduce depthBits
|
||||
if (testDepthBits == 24)
|
||||
testDepthBits = 16;
|
||||
else if (testDepthBits == 16)
|
||||
testDepthBits = 8;
|
||||
}
|
||||
|
||||
if ((i % 4) == 1)
|
||||
{ // reduce stencilbits
|
||||
if (tstencilbits == 24)
|
||||
tstencilbits = 16;
|
||||
else if (tstencilbits == 16)
|
||||
tstencilbits = 8;
|
||||
{ // reduce stencilBits
|
||||
if (testStencilBits == 24)
|
||||
testStencilBits = 16;
|
||||
else if (testStencilBits == 16)
|
||||
testStencilBits = 8;
|
||||
else
|
||||
tstencilbits = 0;
|
||||
testStencilBits = 0;
|
||||
}
|
||||
|
||||
sdlcolorbits = 4;
|
||||
if (tcolorbits == 24)
|
||||
sdlcolorbits = 8;
|
||||
if (testColorBits == 24)
|
||||
perChannelColorBits = 8;
|
||||
else
|
||||
perChannelColorBits = 4;
|
||||
|
||||
#ifdef __sgi /* Fix for SGIs grabbing too many bits of color */
|
||||
if (sdlcolorbits == 4)
|
||||
sdlcolorbits = 0; /* Use minimum size for 16-bit color */
|
||||
if (perChannelColorBits == 4)
|
||||
perChannelColorBits = 0; /* Use minimum size for 16-bit color */
|
||||
|
||||
/* Need alpha or else SGIs choose 36+ bit RGB mode */
|
||||
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 1);
|
||||
#endif
|
||||
|
||||
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, sdlcolorbits );
|
||||
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, sdlcolorbits );
|
||||
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, sdlcolorbits );
|
||||
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, tdepthbits );
|
||||
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, tstencilbits );
|
||||
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 );
|
||||
|
||||
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, samples ? 1 : 0 );
|
||||
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );
|
||||
|
@ -388,71 +416,70 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
|
|||
|
||||
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
|
||||
|
||||
#if 0 // See http://bugzilla.icculus.org/show_bug.cgi?id=3526
|
||||
// If not allowing software GL, demand accelerated
|
||||
if( !r_allowSoftwareGL->integer )
|
||||
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
|
||||
|
||||
if( ( SDL_window = SDL_CreateWindow( CLIENT_WINDOW_TITLE, x, y,
|
||||
glConfig.vidWidth, glConfig.vidHeight, flags ) ) == 0 )
|
||||
{
|
||||
if( SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 ) < 0 )
|
||||
{
|
||||
ri.Printf( PRINT_ALL, "Unable to guarantee accelerated "
|
||||
"visual with libSDL < 1.2.10\n" );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if( SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, r_swapInterval->integer ) < 0 )
|
||||
ri.Printf( PRINT_ALL, "r_swapInterval requires libSDL >= 1.2.10\n" );
|
||||
|
||||
#ifdef USE_ICON
|
||||
{
|
||||
SDL_Surface *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
|
||||
);
|
||||
|
||||
SDL_WM_SetIcon( icon, NULL );
|
||||
SDL_FreeSurface( icon );
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_WM_SetCaption(CLIENT_WINDOW_TITLE, CLIENT_WINDOW_MIN_TITLE);
|
||||
SDL_ShowCursor(0);
|
||||
|
||||
if (!(vidscreen = SDL_SetVideoMode(glConfig.vidWidth, glConfig.vidHeight, colorbits, flags)))
|
||||
{
|
||||
ri.Printf( PRINT_DEVELOPER, "SDL_SetVideoMode failed: %s\n", SDL_GetError( ) );
|
||||
ri.Printf( PRINT_DEVELOPER, "SDL_CreateWindow failed: %s\n", SDL_GetError( ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
opengl_context = GLimp_GetCurrentContext();
|
||||
if( fullscreen )
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
|
||||
ri.Printf( PRINT_ALL, "Using %d/%d/%d Color bits, %d depth, %d stencil display.\n",
|
||||
sdlcolorbits, sdlcolorbits, sdlcolorbits, tdepthbits, tstencilbits);
|
||||
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;
|
||||
}
|
||||
|
||||
glConfig.colorBits = tcolorbits;
|
||||
glConfig.depthBits = tdepthbits;
|
||||
glConfig.stencilBits = tstencilbits;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetWindowTitle( SDL_window, CLIENT_WINDOW_TITLE );
|
||||
SDL_SetWindowIcon( SDL_window, icon );
|
||||
|
||||
if( ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
|
||||
{
|
||||
ri.Printf( PRINT_DEVELOPER, "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( SDL_GL_MakeCurrent( SDL_window, SDL_glContext ) < 0 )
|
||||
{
|
||||
ri.Printf( PRINT_DEVELOPER, "SDL_GL_MakeCurrent failed: %s\n", SDL_GetError( ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
SDL_GL_SetSwapInterval( r_swapInterval->integer );
|
||||
|
||||
glConfig.colorBits = testColorBits;
|
||||
glConfig.depthBits = testDepthBits;
|
||||
glConfig.stencilBits = testStencilBits;
|
||||
|
||||
ri.Printf( PRINT_ALL, "Using %d color bits, %d depth, %d stencil display.\n",
|
||||
glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits );
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_FreeSurface( icon );
|
||||
|
||||
GLimp_DetectAvailableModes();
|
||||
|
||||
if (!vidscreen)
|
||||
{
|
||||
ri.Printf( PRINT_ALL, "Couldn't get a visual\n" );
|
||||
return RSERR_INVALID_MODE;
|
||||
}
|
||||
|
||||
screen = vidscreen;
|
||||
|
||||
glstring = (char *) qglGetString (GL_RENDERER);
|
||||
ri.Printf( PRINT_ALL, "GL_RENDERER: %s\n", glstring );
|
||||
|
||||
|
@ -470,16 +497,15 @@ static qboolean GLimp_StartDriverAndSetMode(int mode, qboolean fullscreen, qbool
|
|||
|
||||
if (!SDL_WasInit(SDL_INIT_VIDEO))
|
||||
{
|
||||
char driverName[ 64 ];
|
||||
const char *driverName;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) == -1)
|
||||
{
|
||||
ri.Printf( PRINT_ALL, "SDL_Init( SDL_INIT_VIDEO ) FAILED (%s)\n",
|
||||
SDL_GetError());
|
||||
ri.Printf( PRINT_ALL, "SDL_Init( SDL_INIT_VIDEO ) FAILED (%s)\n", SDL_GetError());
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
SDL_VideoDriverName( driverName, sizeof( driverName ) - 1 );
|
||||
driverName = SDL_GetCurrentVideoDriver( );
|
||||
ri.Printf( PRINT_ALL, "SDL using driver \"%s\"\n", driverName );
|
||||
ri.Cvar_Set( "r_sdlDriver", driverName );
|
||||
}
|
||||
|
@ -698,6 +724,8 @@ of OpenGL
|
|||
*/
|
||||
void GLimp_Init( void )
|
||||
{
|
||||
ri.Printf( PRINT_DEVELOPER, "Glimp_Init( )\n" );
|
||||
|
||||
r_allowSoftwareGL = ri.Cvar_Get( "r_allowSoftwareGL", "0", CVAR_LATCH );
|
||||
r_sdlDriver = ri.Cvar_Get( "r_sdlDriver", "", CVAR_ROM );
|
||||
r_allowResize = ri.Cvar_Get( "r_allowResize", "0", CVAR_ARCHIVE );
|
||||
|
@ -711,8 +739,6 @@ void GLimp_Init( void )
|
|||
ri.Cvar_Set( "com_abnormalExit", "0" );
|
||||
}
|
||||
|
||||
ri.Sys_SetEnv( "SDL_VIDEO_CENTERED", r_centerWindow->integer ? "1" : "" );
|
||||
|
||||
ri.Sys_GLimpInit( );
|
||||
|
||||
// Create the window and set up the context
|
||||
|
@ -742,13 +768,15 @@ success:
|
|||
// This values force the UI to disable driver selection
|
||||
glConfig.driverType = GLDRV_ICD;
|
||||
glConfig.hardwareType = GLHW_GENERIC;
|
||||
glConfig.deviceSupportsGamma = SDL_SetGamma( 1.0f, 1.0f, 1.0f ) >= 0;
|
||||
|
||||
// FIXME No SDL_SetGamma in SDL2?
|
||||
/*glConfig.deviceSupportsGamma = SDL_SetGamma( 1.0f, 1.0f, 1.0f ) >= 0;*/
|
||||
|
||||
// Mysteriously, if you use an NVidia graphics card and multiple monitors,
|
||||
// SDL_SetGamma will incorrectly return false... the first time; ask
|
||||
// again and you get the correct answer. This is a suspected driver bug, see
|
||||
// http://bugzilla.icculus.org/show_bug.cgi?id=4316
|
||||
glConfig.deviceSupportsGamma = SDL_SetGamma( 1.0f, 1.0f, 1.0f ) >= 0;
|
||||
/*glConfig.deviceSupportsGamma = SDL_SetGamma( 1.0f, 1.0f, 1.0f ) >= 0;*/
|
||||
|
||||
if ( -1 == r_ignorehwgamma->integer)
|
||||
glConfig.deviceSupportsGamma = 1;
|
||||
|
@ -770,7 +798,7 @@ success:
|
|||
ri.Cvar_Get( "r_availableModes", "", CVAR_ROM );
|
||||
|
||||
// This depends on SDL_INIT_VIDEO, hence having it here
|
||||
ri.IN_Init( );
|
||||
ri.IN_Init( SDL_window );
|
||||
}
|
||||
|
||||
|
||||
|
@ -786,37 +814,32 @@ void GLimp_EndFrame( void )
|
|||
// don't flip if drawing to front buffer
|
||||
if ( Q_stricmp( r_drawBuffer->string, "GL_FRONT" ) != 0 )
|
||||
{
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow( SDL_window );
|
||||
}
|
||||
|
||||
if( r_fullscreen->modified )
|
||||
{
|
||||
qboolean fullscreen;
|
||||
qboolean needToToggle = qtrue;
|
||||
int fullscreen;
|
||||
qboolean needToToggle;
|
||||
qboolean sdlToggled = qfalse;
|
||||
SDL_Surface *s = SDL_GetVideoSurface( );
|
||||
|
||||
if( s )
|
||||
// Find out the current state
|
||||
fullscreen = !!( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_FULLSCREEN );
|
||||
|
||||
if( r_fullscreen->integer && ri.Cvar_VariableIntegerValue( "in_nograb" ) )
|
||||
{
|
||||
// Find out the current state
|
||||
fullscreen = !!( s->flags & SDL_FULLSCREEN );
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Is the state we want different from the current state?
|
||||
needToToggle = !!r_fullscreen->integer != fullscreen;
|
||||
|
||||
if( needToToggle )
|
||||
sdlToggled = SDL_WM_ToggleFullScreen( s );
|
||||
ri.Printf( PRINT_ALL, "Fullscreen not allowed with in_nograb 1\n");
|
||||
ri.Cvar_Set( "r_fullscreen", "0" );
|
||||
r_fullscreen->modified = qfalse;
|
||||
}
|
||||
|
||||
// Is the state we want different from the current state?
|
||||
needToToggle = !!r_fullscreen->integer != fullscreen;
|
||||
|
||||
if( needToToggle )
|
||||
{
|
||||
sdlToggled = SDL_SetWindowFullscreen( SDL_window, r_fullscreen->integer ) >= 0;
|
||||
|
||||
// SDL_WM_ToggleFullScreen didn't work, so do it the slow way
|
||||
if( !sdlToggled )
|
||||
ri.Cmd_ExecuteText(EXEC_APPEND, "vid_restart");
|
||||
|
@ -831,6 +854,7 @@ void GLimp_EndFrame( void )
|
|||
|
||||
|
||||
#ifdef SMP
|
||||
//FIXME: update for SDL2
|
||||
/*
|
||||
===========================================================
|
||||
|
||||
|
@ -956,16 +980,6 @@ qboolean GLimp_SpawnRenderThread( void (*function)( void ) )
|
|||
GLimp_ShutdownRenderThread();
|
||||
return qfalse;
|
||||
}
|
||||
else
|
||||
{
|
||||
// tma 01/09/07: don't think this is necessary anyway?
|
||||
//
|
||||
// !!! FIXME: No detach API available in SDL!
|
||||
//ret = pthread_detach( renderThread );
|
||||
//if ( ret ) {
|
||||
//ri.Printf( PRINT_ALL, "pthread_detach returned %d: %s", ret, strerror( ret ) );
|
||||
//}
|
||||
}
|
||||
|
||||
return qtrue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue