]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_glx.c
added vid_stereobuffer cvar based on patch from syschuck on the alientrap forums
[xonotic/darkplaces.git] / vid_glx.c
index bb4ea0710ab57115ca228fe618a02ced6607efea..de1ac666dc29f00015a58f0553f11f7d28e0f4e8 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -17,12 +17,6 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
-//#include <termios.h>
-//#include <sys/ioctl.h>
-//#include <sys/stat.h>
-//#include <sys/vt.h>
-//#include <stdarg.h>
-//#include <stdio.h>
 #include <signal.h>
 
 #include <dlfcn.h>
@@ -93,6 +87,8 @@ static qboolean mouse_avail = true;
 static qboolean vid_usingmouse = false;
 static qboolean vid_usingvsync = false;
 static qboolean vid_usevsync = false;
+static qboolean vid_x11_hardwaregammasupported = false;
+static int vid_x11_gammarampsize = 0;
 static float   mouse_x, mouse_y;
 static int p_mouse_x, p_mouse_y;
 
@@ -106,8 +102,7 @@ qboolean vidmode_ext = false;
 
 static int win_x, win_y;
 
-static XF86VidModeModeInfo **vidmodes;
-static int num_vidmodes;
+static XF86VidModeModeInfo init_vidmode;
 static qboolean vid_isfullscreen = false;
 
 static Visual *vidx11_visual;
@@ -198,6 +193,7 @@ static int XLateKey(XKeyEvent *ev, char *ascii)
 
                case XK_Alt_L:
                case XK_Meta_L:
+               case XK_ISO_Level3_Shift:
                case XK_Alt_R:
                case XK_Meta_R: key = K_ALT;                    break;
 
@@ -438,13 +434,11 @@ static void HandleEvents(void)
                case MapNotify:
                        // window restored
                        vid_hidden = false;
-                       vid_activewindow = false;
                        VID_RestoreSystemGamma();
                        break;
                case UnmapNotify:
                        // window iconified/rolledup/whatever
                        vid_hidden = true;
-                       vid_activewindow = false;
                        VID_RestoreSystemGamma();
                        break;
                case FocusIn:
@@ -497,7 +491,7 @@ static int GL_OpenLibrary(const char *name)
                Con_Printf("Unable to open symbol list for %s\n", name);
                return false;
        }
-       strcpy(gl_driver, name);
+       strlcpy(gl_driver, name, sizeof(gl_driver));
        return true;
 }
 
@@ -523,7 +517,7 @@ void VID_Shutdown(void)
 
                // FIXME: glXDestroyContext here?
                if (vid_isfullscreen)
-                       XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[0]);
+                       XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, &init_vidmode);
                if (win)
                        XDestroyWindow(vidx11_display, win);
                XCloseDisplay(vidx11_display);
@@ -560,7 +554,7 @@ void InitSig(void)
        signal(SIGTERM, signal_handler);
 }
 
-void VID_Finish (void)
+void VID_Finish (qboolean allowmousegrab)
 {
        qboolean vid_usemouse;
 
@@ -572,9 +566,9 @@ void VID_Finish (void)
                        Con_Print("glXSwapIntervalSGI didn't accept the vid_vsync change, it will take effect on next vid_restart (GLX_SGI_swap_control does not allow turning off vsync)\n");
        }
 
-// handle the mouse state when windowed if that's changed
+       // handle the mouse state when windowed if that's changed
        vid_usemouse = false;
-       if (vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
+       if (allowmousegrab && vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback))
                vid_usemouse = true;
        if (!vid_activewindow)
                vid_usemouse = false;
@@ -584,32 +578,26 @@ void VID_Finish (void)
 
        if (r_render.integer)
        {
+               CHECKGLERROR
                if (r_speeds.integer || gl_finish.integer)
-                       qglFinish();
-               qglXSwapBuffers(vidx11_display, win);
+               {
+                       qglFinish();CHECKGLERROR
+               }
+               qglXSwapBuffers(vidx11_display, win);CHECKGLERROR
        }
+
+       if (vid_x11_hardwaregammasupported)
+               VID_UpdateGamma(false, vid_x11_gammarampsize);
 }
 
-int VID_SetGamma(unsigned short *ramps)
+int VID_SetGamma(unsigned short *ramps, int rampsize)
 {
-       int rampsize;
-       // FIXME: it would be good to generate ramps of the size reported by X,
-       // for instance Quadro cards seem to use 1024 color ramps not 256
-       if(!XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &rampsize))
-               return 0;
-       if(rampsize != 256)
-               return 0;
-       return XF86VidModeSetGammaRamp(vidx11_display, vidx11_screen, 256, ramps, ramps + 256, ramps + 512);
+       return XF86VidModeSetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
 }
 
-int VID_GetGamma(unsigned short *ramps)
+int VID_GetGamma(unsigned short *ramps, int rampsize)
 {
-       int rampsize;
-       if(!XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &rampsize))
-               return 0;
-       if(rampsize != 256)
-               return 0;
-       return XF86VidModeGetGammaRamp(vidx11_display, vidx11_screen, 256, ramps, ramps + 256, ramps + 512);
+       return XF86VidModeGetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
 }
 
 void VID_Init(void)
@@ -624,7 +612,7 @@ void VID_Init(void)
                mouse_avail = false;
 }
 
-void VID_BuildGLXAttrib(int *attrib, int stencil)
+void VID_BuildGLXAttrib(int *attrib, qboolean stencil, qboolean stereobuffer)
 {
        *attrib++ = GLX_RGBA;
        *attrib++ = GLX_RED_SIZE;*attrib++ = 1;
@@ -638,10 +626,12 @@ void VID_BuildGLXAttrib(int *attrib, int stencil)
                *attrib++ = GLX_STENCIL_SIZE;*attrib++ = 8;
                *attrib++ = GLX_ALPHA_SIZE;*attrib++ = 1;
        }
+       if (stereobuffer)
+               *attrib++ = GLX_STEREO;
        *attrib++ = None;
 }
 
-int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate)
+int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer)
 {
        int i;
        int attrib[32];
@@ -699,7 +689,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
                return false;
        }
 
-       VID_BuildGLXAttrib(attrib, bpp == 32);
+       VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer);
        visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
        if (!visinfo)
        {
@@ -714,6 +704,14 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
                // Are we going fullscreen?  If so, let's change video mode
                if (fullscreen)
                {
+                       XF86VidModeModeLine *current_vidmode;
+                       XF86VidModeModeInfo **vidmodes;
+                       int num_vidmodes;
+
+                       // This nice hack comes from the SDL source code
+                       current_vidmode = (XF86VidModeModeLine*)((char*)&init_vidmode + sizeof(init_vidmode.dotclock));
+                       XF86VidModeGetModeLine(vidx11_display, vidx11_screen, (int*)&init_vidmode.dotclock, current_vidmode);
+
                        XF86VidModeGetAllModeLines(vidx11_display, vidx11_screen, &num_vidmodes, &vidmodes);
                        best_dist = 9999999;
                        best_fit = -1;
@@ -750,6 +748,8 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
                        }
                        else
                                fullscreen = 0;
+
+                       free(vidmodes);
                }
        }
 
@@ -836,12 +836,27 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
        vid_usingvsync = false;
        vid_hidden = false;
        vid_activewindow = true;
+       vid_x11_hardwaregammasupported = XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &vid_x11_gammarampsize) != 0;
        GL_Init();
        return true;
 }
 
 void Sys_SendKeyEvents(void)
 {
+       static qboolean sound_active = true;
+
+       // enable/disable sound on focus gain/loss
+       if (!vid_activewindow && sound_active)
+       {
+               S_BlockSound ();
+               sound_active = false;
+       }
+       else if (vid_activewindow && !sound_active)
+       {
+               S_UnblockSound ();
+               sound_active = true;
+       }
+
        HandleEvents();
 }