]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_agl.c
implemented vid_refreshrate cvar to specify display refresh rate in windows
[xonotic/darkplaces.git] / vid_agl.c
index 6e3f566392f0b9c709a113d1fe2290d010ee9a44..83de5e8df36c0ee8ef0a1c5e59d4b484f84e822f 100644 (file)
--- a/vid_agl.c
+++ b/vid_agl.c
@@ -31,6 +31,8 @@
 // Tell startup code that we have a client
 int cl_available = true;
 
+qboolean vid_supportrefreshrate = false;
+
 // AGL prototypes
 AGLPixelFormat (*qaglChoosePixelFormat) (const AGLDevice *gdevs, GLint ndev, const GLint *attribList);
 AGLContext (*qaglCreateContext) (AGLPixelFormat pix, AGLContext share);
@@ -198,16 +200,16 @@ void VID_Shutdown(void)
 {
        if (context == NULL || window == NULL)
                return;
-       
+
        IN_Activate(false);
        VID_RestoreSystemGamma();
-       
+
        if (context != NULL)
        {
                qaglDestroyContext(context);
                context = NULL;
        }
-       
+
        if (window != NULL)
        {
                DisposeWindow(window);
@@ -227,7 +229,7 @@ static qboolean AsyncEvent_Collapsed = false;
 static OSStatus MainWindowEventHandler (EventHandlerCallRef nextHandler, EventRef event, void *userData)
 {
        OSStatus err = noErr;
-       
+
        switch (GetEventKind (event))
        {
                case kEventWindowClosed:
@@ -271,7 +273,7 @@ static void VID_ProcessPendingAsyncEvents (void)
                vid_activewindow = false;
                VID_RestoreSystemGamma();
        }
-       
+
        // Closed
        if (AsyncEvent_Quitting)
        {
@@ -299,7 +301,7 @@ static void VID_BuildAGLAttrib(GLint *attrib, int stencil, qboolean fullscreen)
        *attrib++ = AGL_NONE;
 }
 
-int VID_InitMode(int fullscreen, int width, int height, int bpp)
+int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate)
 {
     const EventTypeSpec winEvents[] =
        {
@@ -319,14 +321,14 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                return false;
        }
 
-       if ((qaglChoosePixelFormat = GL_GetProcAddress("aglChoosePixelFormat")) == NULL
-        || (qaglCreateContext = GL_GetProcAddress("aglCreateContext")) == NULL
-        || (qaglDestroyContext = GL_GetProcAddress("aglDestroyContext")) == NULL
-        || (qaglDestroyPixelFormat = GL_GetProcAddress("aglDestroyPixelFormat")) == NULL
-        || (qaglSetCurrentContext = GL_GetProcAddress("aglSetCurrentContext")) == NULL
-        || (qaglSetDrawable = GL_GetProcAddress("aglSetDrawable")) == NULL
-        || (qaglSetFullScreen = GL_GetProcAddress("aglSetFullScreen")) == NULL
-        || (qaglSwapBuffers = GL_GetProcAddress("aglSwapBuffers")) == NULL
+       if ((qaglChoosePixelFormat = (AGLPixelFormat (*) (const AGLDevice *gdevs, GLint ndev, const GLint *attribList))GL_GetProcAddress("aglChoosePixelFormat")) == NULL
+        || (qaglCreateContext = (AGLContext (*) (AGLPixelFormat pix, AGLContext share))GL_GetProcAddress("aglCreateContext")) == NULL
+        || (qaglDestroyContext = (GLboolean (*) (AGLContext ctx))GL_GetProcAddress("aglDestroyContext")) == NULL
+        || (qaglDestroyPixelFormat = (void (*) (AGLPixelFormat pix))GL_GetProcAddress("aglDestroyPixelFormat")) == NULL
+        || (qaglSetCurrentContext = (GLboolean (*) (AGLContext ctx))GL_GetProcAddress("aglSetCurrentContext")) == NULL
+        || (qaglSetDrawable = (GLboolean (*) (AGLContext ctx, AGLDrawable draw))GL_GetProcAddress("aglSetDrawable")) == NULL
+        || (qaglSetFullScreen = (GLboolean (*) (AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq, GLint device))GL_GetProcAddress("aglSetFullScreen")) == NULL
+        || (qaglSwapBuffers = (void (*) (AGLContext ctx))GL_GetProcAddress("aglSwapBuffers")) == NULL
        )
        {
                Con_Printf("AGL functions not found\n");
@@ -347,7 +349,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                Con_Printf("Unable to create window (error %d)\n", carbonError);
                return false;
        }
-       
+
        // Set the window title
        CFStringRef windowTitle = CFSTR("DarkPlaces AGL");
        SetWindowTitleWithCFString(window, windowTitle);
@@ -356,7 +358,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
        // Install the callback function for the window events we can't get
        // through ReceiveNextEvent (i.e. close, collapse, and expand)
        InstallWindowEventHandler (window, NewEventHandlerUPP (MainWindowEventHandler),
-                                                          GetEventTypeCount(winEvents), winEvents, window, NULL); 
+                                                          GetEventTypeCount(winEvents), winEvents, window, NULL);
 
        screen = GetGWorldDevice(GetWindowPort(window));
        if (screen == NULL)
@@ -378,31 +380,33 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
 
        // Set context and show the window
        context = qaglCreateContext(pixelFormat, NULL);
-       qaglDestroyPixelFormat(pixelFormat);
        if (context == NULL)
-               Sys_Error ("aglCreateContext failed\n");
-       if (!qaglSetDrawable(context, GetWindowPort(window)))
-               Sys_Error ("aglSetDrawable failed\n");
-       if (!qaglSetCurrentContext(context))
-               Sys_Error ("aglSetCurrentContext failed\n");
-       
-       scr_width = width;
-       scr_height = height;
-
-       if ((qglGetString = GL_GetProcAddress("glGetString")) == NULL)
-               Sys_Error("glGetString not found in %s", gl_driver);
-
+               Sys_Error ("aglCreateContext failed");
        if (fullscreen)
        {
                if (!qaglSetFullScreen (context, width, height, 0, 0))
-                       Sys_Error("aglSetFullScreen failed\n");
+                       Sys_Error("aglSetFullScreen failed");
                vid_isfullscreen = true;
        }
+       else
+       {
+               if (!qaglSetDrawable(context, GetWindowPort(window)))
+                       Sys_Error ("aglSetDrawable failed");
+       }
+       if (!qaglSetCurrentContext(context))
+               Sys_Error ("aglSetCurrentContext failed");
+       qaglDestroyPixelFormat(pixelFormat);
 
-       gl_renderer = qglGetString(GL_RENDERER);
-       gl_vendor = qglGetString(GL_VENDOR);
-       gl_version = qglGetString(GL_VERSION);
-       gl_extensions = qglGetString(GL_EXTENSIONS);
+       scr_width = width;
+       scr_height = height;
+
+       if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
+               Sys_Error("glGetString not found in %s", gl_driver);
+
+       gl_renderer = (const char *)qglGetString(GL_RENDERER);
+       gl_vendor = (const char *)qglGetString(GL_VENDOR);
+       gl_version = (const char *)qglGetString(GL_VERSION);
+       gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
        gl_platform = "AGL";
        gl_videosyncavailable = false;
 
@@ -454,7 +458,7 @@ static void Handle_KeyMod(UInt32 keymod)
        prev_keymod = keymod;
 }
 
-static void Handle_Key(qbyte charcode, qboolean keypressed)
+static void Handle_Key(unsigned char charcode, qboolean keypressed)
 {
        unsigned int keycode = 0;
        char ascii = '\0';
@@ -512,7 +516,7 @@ static void Handle_Key(qbyte charcode, qboolean keypressed)
                                keycode = charcode + ('a' - 'A');  // lowercase it
                                ascii = charcode;
                        }
-                       else if (32 <= charcode && charcode <= 126)
+                       else if (32 <= charcode)
                        {
                                keycode = charcode;
                                ascii = charcode;
@@ -529,8 +533,8 @@ void Sys_SendKeyEvents(void)
 {
        EventRef theEvent;
        EventTargetRef theTarget;
-       
-       // Start by processing the asynchronous events we received since the previous frame 
+
+       // Start by processing the asynchronous events we received since the previous frame
        VID_ProcessPendingAsyncEvents();
 
        theTarget = GetEventDispatcherTarget();
@@ -573,7 +577,7 @@ void Sys_SendKeyEvents(void)
                                        case kEventMouseMoved:
                                        {
                                                HIPoint deltaPos;
-                                               
+
                                                GetEventParameter(theEvent, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(deltaPos), NULL, &deltaPos);
                                                //Con_Printf(">> kEventMouseMoved (%f, %f) <<\n", deltaPos.x, deltaPos.y);
 
@@ -627,7 +631,7 @@ void Sys_SendKeyEvents(void)
                                                Handle_Key(keycode, false);
                                                //Con_Printf(">> kEventRawKeyUp (%d) <<\n", keycode);
                                                break;
-                                       
+
                                        case kEventRawKeyModifiersChanged:
                                        {
                                                UInt32 keymod = 0;