]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_agl.c
modified gamma handling, now VID_UpdateGamma is only called from VID_Finish, and...
[xonotic/darkplaces.git] / vid_agl.c
index 604c0a19a3ad717725ced6347eff11ac2984333b..d86441fd47829f96dfd1275c7334129a6d33a024 100644 (file)
--- a/vid_agl.c
+++ b/vid_agl.c
@@ -3,7 +3,7 @@
 
        Mac OS X OpenGL and input module, using Carbon and AGL
 
-       Copyright (C) 2005  Mathieu Olivier
+       Copyright (C) 2005-2006  Mathieu Olivier
 
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
@@ -54,7 +54,7 @@ static qboolean vid_usingvsync = false;
 static int scr_width, scr_height;
 
 static AGLContext context;
-static         WindowRef window;
+static WindowRef window;
 
 
 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
@@ -74,7 +74,7 @@ static void IN_Activate( qboolean grab )
                        CGPoint winCenter;
 
                        SelectWindow(window);
-                       HideCursor();
+                       CGDisplayHideCursor(CGMainDisplayID());
 
                        // Put the mouse cursor at the center of the window
                        GetWindowBounds (window, kWindowContentRgn, &winBounds);
@@ -94,13 +94,14 @@ static void IN_Activate( qboolean grab )
                if (vid_usingmouse)
                {
                        CGAssociateMouseAndMouseCursorPosition(true);
-                       ShowCursor();
+                       CGDisplayShowCursor(CGMainDisplayID());
 
                        vid_usingmouse = false;
                }
        }
 }
 
+#define GAMMA_TABLE_SIZE 256
 void VID_Finish (qboolean allowmousegrab)
 {
        qboolean vid_usemouse;
@@ -108,7 +109,7 @@ void VID_Finish (qboolean allowmousegrab)
 
        // handle the mouse state when windowed if that's changed
        vid_usemouse = false;
-       if (allowmousgrab && vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
+       if (allowmousegrab && vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
                vid_usemouse = true;
        if (!vid_activewindow)
                vid_usemouse = false;
@@ -137,10 +138,10 @@ void VID_Finish (qboolean allowmousegrab)
                        qglFinish();
                qaglSwapBuffers(context);
        }
+       VID_UpdateGamma(false, GAMMA_TABLE_SIZE);
 }
 
-#define GAMMA_TABLE_SIZE 256
-int VID_SetGamma(unsigned short *ramps)
+int VID_SetGamma(unsigned short *ramps, int rampsize)
 {
        CGGammaValue table_red [GAMMA_TABLE_SIZE];
        CGGammaValue table_green [GAMMA_TABLE_SIZE];
@@ -148,14 +149,14 @@ int VID_SetGamma(unsigned short *ramps)
        unsigned int i;
 
        // Convert the unsigned short table into 3 float tables
-       for (i = 0; i < GAMMA_TABLE_SIZE; i++)
+       for (i = 0; i < rampsize; i++)
                table_red[i] = (float)ramps[i] / 65535.0f;
-       for (i = 0; i < GAMMA_TABLE_SIZE; i++)
-               table_green[i] = (float)ramps[i + GAMMA_TABLE_SIZE] / 65535.0f;
-       for (i = 0; i < GAMMA_TABLE_SIZE; i++)
-               table_blue[i] = (float)ramps[i + 2 * GAMMA_TABLE_SIZE] / 65535.0f;
+       for (i = 0; i < rampsize; i++)
+               table_green[i] = (float)ramps[i + rampsize] / 65535.0f;
+       for (i = 0; i < rampsize; i++)
+               table_blue[i] = (float)ramps[i + 2 * rampsize] / 65535.0f;
 
-       if (CGSetDisplayTransferByTable(CGMainDisplayID(), GAMMA_TABLE_SIZE, table_red, table_green, table_blue) != CGDisplayNoErr)
+       if (CGSetDisplayTransferByTable(CGMainDisplayID(), rampsize, table_red, table_green, table_blue) != CGDisplayNoErr)
        {
                Con_Print("VID_SetGamma: ERROR: CGSetDisplayTransferByTable failed!\n");
                return false;
@@ -164,7 +165,7 @@ int VID_SetGamma(unsigned short *ramps)
        return true;
 }
 
-int VID_GetGamma(unsigned short *ramps)
+int VID_GetGamma(unsigned short *ramps, int rampsize)
 {
        CGGammaValue table_red [GAMMA_TABLE_SIZE];
        CGGammaValue table_green [GAMMA_TABLE_SIZE];
@@ -173,24 +174,24 @@ int VID_GetGamma(unsigned short *ramps)
        unsigned int i;
 
        // Get the gamma ramps from the system
-       if (CGGetDisplayTransferByTable(CGMainDisplayID(), GAMMA_TABLE_SIZE, table_red, table_green, table_blue, &actualsize) != CGDisplayNoErr)
+       if (CGGetDisplayTransferByTable(CGMainDisplayID(), rampsize, table_red, table_green, table_blue, &actualsize) != CGDisplayNoErr)
        {
                Con_Print("VID_GetGamma: ERROR: CGGetDisplayTransferByTable failed!\n");
                return false;
        }
-       if (actualsize != GAMMA_TABLE_SIZE)
+       if (actualsize != rampsize)
        {
-               Con_Printf("VID_GetGamma: ERROR: invalid gamma table size (%u != %u)\n", actualsize, GAMMA_TABLE_SIZE);
+               Con_Printf("VID_GetGamma: ERROR: invalid gamma table size (%u != %u)\n", actualsize, rampsize);
                return false;
        }
 
        // Convert the 3 float tables into 1 unsigned short table
-       for (i = 0; i < GAMMA_TABLE_SIZE; i++)
+       for (i = 0; i < rampsize; i++)
                ramps[i] = table_red[i] * 65535.0f;
-       for (i = 0; i < GAMMA_TABLE_SIZE; i++)
-               ramps[i + GAMMA_TABLE_SIZE] = table_green[i] * 65535.0f;
-       for (i = 0; i < GAMMA_TABLE_SIZE; i++)
-               ramps[i + 2 * GAMMA_TABLE_SIZE] = table_blue[i] * 65535.0f;
+       for (i = 0; i < rampsize; i++)
+               ramps[i + rampsize] = table_green[i] * 65535.0f;
+       for (i = 0; i < rampsize; i++)
+               ramps[i + 2 * rampsize] = table_blue[i] * 65535.0f;
 
        return true;
 }
@@ -363,7 +364,6 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
        };
        OSStatus carbonError;
        Rect windowBounds;
-       GDHandle screen;
        AGLPixelFormat pixelFormat;
        GLint attributes [32];
 
@@ -393,9 +393,11 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
        AsyncEvent_Quitting = false;
        AsyncEvent_Collapsed = false;
 
-       // Create the window
-       SetRect(&windowBounds, 0, 0, width, height);
-       OffsetRect(&windowBounds, 100, 100);  // move it a bit towards the center of the screen
+       // Create the window, a bit towards the center of the screen
+       windowBounds.left = 100;
+       windowBounds.top = 100;
+       windowBounds.right = width + 100;
+       windowBounds.bottom = height + 100;
        carbonError = CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &windowBounds, &window);
        if (carbonError != noErr || window == NULL)
        {
@@ -413,17 +415,9 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
        InstallWindowEventHandler (window, NewEventHandlerUPP (MainWindowEventHandler),
                                                           GetEventTypeCount(winEvents), winEvents, window, NULL);
 
-       screen = GetGWorldDevice(GetWindowPort(window));
-       if (screen == NULL)
-       {
-               Con_Printf("Unable to get GDevice for window\n");
-               ReleaseWindow(window);
-               return false;
-       }
-
        // Create and set pixel format
        VID_BuildAGLAttrib(attributes, bpp == 32, fullscreen);
-       pixelFormat = qaglChoosePixelFormat(&screen, 1, attributes);
+       pixelFormat = qaglChoosePixelFormat(NULL, 1, attributes);
        if (pixelFormat == NULL)
        {
                Con_Printf("Unable to create pixel format\n");