]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_agl.c
Added cl_sound_ric_gunshot which specifies if the related cl_sound_ric and cl_sound_t...
[xonotic/darkplaces.git] / vid_agl.c
index cd62ab0775cafa60fad1c8ec16bdc3b9b350c1b1..4ecbd2ee4b0a1ee74ead33481d4322b01847cb58 100644 (file)
--- a/vid_agl.c
+++ b/vid_agl.c
 #include <dlfcn.h>
 #include <signal.h>
 #include <AGL/agl.h>
+#include <OpenGL/OpenGL.h>
 #include <Carbon/Carbon.h>
 #include "vid_agl_mackeys.h" // this is SDL/src/video/maccommon/SDL_mackeys.h
 #include "quakedef.h"
 
+#ifndef kCGLCEMPEngine
+#define kCGLCEMPEngine 313
+#endif
 
 // Tell startup code that we have a client
 int cl_available = true;
@@ -46,6 +50,9 @@ GLboolean (*qaglSetDrawable) (AGLContext ctx, AGLDrawable draw);
 GLboolean (*qaglSetFullScreen) (AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq, GLint device);
 GLboolean (*qaglSetInteger) (AGLContext ctx, GLenum pname, const GLint *params);
 void (*qaglSwapBuffers) (AGLContext ctx);
+CGLError (*qCGLEnable) (CGLContextObj ctx, CGLContextEnable pname);
+CGLError (*qCGLDisable) (CGLContextObj ctx, CGLContextEnable pname);
+CGLContextObj (*qCGLGetCurrentContext) (void);
 
 static qboolean multithreadedgl;
 static qboolean mouse_avail = true;
@@ -151,32 +158,41 @@ void VID_Finish (qboolean allowmousegrab)
        }
        VID_UpdateGamma(false, GAMMA_TABLE_SIZE);
 
-#ifdef kCGLCEMPEngine
        if (apple_multithreadedgl.integer)
        {
                if (!multithreadedgl)
                {
-                       CGLError err = 0;
-                       CGLContextObj ctx = CGLGetCurrentContext();
-                       err = CGLEnable(ctx, kCGLEMPEngine);
-                       if (err == kCGLNoError)
-                               multithreadedgl = true;
+                       if(qCGLGetCurrentContext && qCGLEnable && qCGLDisable)
+                       {
+                               CGLContextObj ctx = qCGLGetCurrentContext();
+                               CGLError e = qCGLEnable(ctx, kCGLCEMPEngine);
+                               if(e == kCGLNoError)
+                                       multithreadedgl = true;
+                               else
+                               {
+                                       Con_Printf("WARNING: can't enable multithreaded GL, error %d\n", (int) e);
+                                       Cvar_SetValueQuick(&apple_multithreadedgl, 0);
+                               }
+                       }
                        else
+                       {
+                               Con_Printf("WARNING: can't enable multithreaded GL, CGL functions not present\n");
                                Cvar_SetValueQuick(&apple_multithreadedgl, 0);
+                       }
                }
        }
        else
        {
                if (multithreadedgl)
                {
-                       multithreadedgl = false;
-                       CGLDisable(ctx, kCGLEMPEngine);
+                       if(qCGLGetCurrentContext && qCGLEnable && qCGLDisable)
+                       {
+                               CGLContextObj ctx = qCGLGetCurrentContext();
+                               qCGLDisable(ctx, kCGLCEMPEngine);
+                               multithreadedgl = false;
+                       }
                }
        }
-#else
-       if (apple_multithreadedgl.integer)
-               Cvar_SetValueQuick(&apple_multithreadedgl, 0);
-#endif
 }
 
 int VID_SetGamma(unsigned short *ramps, int rampsize)
@@ -238,8 +254,7 @@ void signal_handler(int sig)
 {
        printf("Received signal %d, exiting...\n", sig);
        VID_RestoreSystemGamma();
-       Sys_Quit();
-       exit(0);
+       Sys_Quit(1);
 }
 
 void InitSig(void)
@@ -261,14 +276,18 @@ void VID_Init(void)
        InitSig(); // trap evil signals
        Cvar_RegisterVariable(&apple_multithreadedgl);
 // COMMANDLINEOPTION: Input: -nomouse disables mouse support (see also vid_mouse cvar)
-       if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
+       if (COM_CheckParm ("-nomouse"))
                mouse_avail = false;
 }
 
 static void *prjobj = NULL;
+static void *cglobj = NULL;
 
 static void GL_CloseLibrary(void)
 {
+       if (cglobj)
+               dlclose(cglobj);
+       cglobj = NULL;
        if (prjobj)
                dlclose(prjobj);
        prjobj = NULL;
@@ -281,6 +300,7 @@ static void GL_CloseLibrary(void)
 static int GL_OpenLibrary(void)
 {
        const char *name = "/System/Library/Frameworks/AGL.framework/AGL";
+       const char *name2 = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
 
        Con_Printf("Loading OpenGL driver %s\n", name);
        GL_CloseLibrary();
@@ -290,6 +310,11 @@ static int GL_OpenLibrary(void)
                return false;
        }
        strlcpy(gl_driver, name, sizeof(gl_driver));
+
+       Con_Printf("Loading OpenGL driver %s\n", name2);
+       if (!(cglobj = dlopen(name2, RTLD_LAZY)))
+               Con_Printf("Unable to open symbol list for %s; multithreaded GL disabled\n", name);
+
        return true;
 }
 
@@ -298,6 +323,13 @@ void *GL_GetProcAddress(const char *name)
        return dlsym(prjobj, name);
 }
 
+static void *CGL_GetProcAddress(const char *name)
+{
+       if(!cglobj)
+               return NULL;
+       return dlsym(cglobj, name);
+}
+
 void VID_Shutdown(void)
 {
        if (context == NULL && window == NULL)
@@ -389,7 +421,7 @@ static void VID_ProcessPendingAsyncEvents (void)
 
        // Closed
        if (AsyncEvent_Quitting)
-               Sys_Quit();
+               Sys_Quit(0);
 }
 
 static void VID_BuildAGLAttrib(GLint *attrib, qboolean stencil, qboolean fullscreen, qboolean stereobuffer)
@@ -453,6 +485,12 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
                return false;
        }
 
+       qCGLEnable = (CGLError (*) (CGLContextObj ctx, CGLContextEnable pname)) CGL_GetProcAddress("CGLEnable");
+       qCGLDisable = (CGLError (*) (CGLContextObj ctx, CGLContextEnable pname)) CGL_GetProcAddress("CGLDisable");
+       qCGLGetCurrentContext = (CGLContextObj (*) (void)) CGL_GetProcAddress("CGLGetCurrentContext");
+       if(!qCGLEnable || !qCGLDisable || !qCGLGetCurrentContext)
+               Con_Printf("CGL functions not found; disabling multithreaded OpenGL\n");
+
        // Ignore the events from the previous window
        AsyncEvent_Quitting = false;
        AsyncEvent_Collapsed = false;
@@ -941,7 +979,7 @@ void Sys_SendKeyEvents(void)
                                                VID_AppFocusChanged(false);
                                                break;
                                        case kEventAppQuit:
-                                               Sys_Quit();
+                                               Sys_Quit(0);
                                                break;
                                        case kEventAppActiveWindowChanged:
                                                break;