]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_glx.c
modified gamma handling, now VID_UpdateGamma is only called from VID_Finish, and...
[xonotic/darkplaces.git] / vid_glx.c
index cc503fda5e474a92d26b2b52e18a40d0c5fac42e..eab081aad9cc7f655986244d7e6b12ce2fe4fb79 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -45,6 +45,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // Tell startup code that we have a client
 int cl_available = true;
 
 // Tell startup code that we have a client
 int cl_available = true;
 
+// note: if we used the XRandR extension we could support refresh rates
+qboolean vid_supportrefreshrate = false;
+
 //GLX prototypes
 XVisualInfo *(GLAPIENTRY *qglXChooseVisual)(Display *dpy, int screen, int *attribList);
 GLXContext (GLAPIENTRY *qglXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct);
 //GLX prototypes
 XVisualInfo *(GLAPIENTRY *qglXChooseVisual)(Display *dpy, int screen, int *attribList);
 GLXContext (GLAPIENTRY *qglXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct);
@@ -94,16 +97,16 @@ static float        mouse_x, mouse_y;
 static int p_mouse_x, p_mouse_y;
 
 #if !defined(__APPLE__) && !defined(SUNOS)
 static int p_mouse_x, p_mouse_y;
 
 #if !defined(__APPLE__) && !defined(SUNOS)
-cvar_t vid_dga = {CVAR_SAVE, "vid_dga", "1"};
-cvar_t vid_dga_mouseaccel = {0, "vid_dga_mouseaccel", "1"};
+// FIXME: vid_dga_mouseaccel is poorly named, it is actually the multiplier for mouse movement, not an acceleration (which would be a power function or something)
+cvar_t vid_dga = {CVAR_SAVE, "vid_dga", "1", "make use of DGA mouse input"};
+cvar_t vid_dga_mouseaccel = {0, "vid_dga_mouseaccel", "1", "speed of mouse when using DGA mouse input"};
 #endif
 
 qboolean vidmode_ext = false;
 
 static int win_x, win_y;
 
 #endif
 
 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;
 static qboolean vid_isfullscreen = false;
 
 static Visual *vidx11_visual;
@@ -519,7 +522,7 @@ void VID_Shutdown(void)
 
                // FIXME: glXDestroyContext here?
                if (vid_isfullscreen)
 
                // 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);
                if (win)
                        XDestroyWindow(vidx11_display, win);
                XCloseDisplay(vidx11_display);
@@ -556,8 +559,9 @@ void InitSig(void)
        signal(SIGTERM, signal_handler);
 }
 
        signal(SIGTERM, signal_handler);
 }
 
-void VID_Finish (void)
+void VID_Finish (qboolean allowmousegrab)
 {
 {
+       int rampsize;
        qboolean vid_usemouse;
 
        vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
        qboolean vid_usemouse;
 
        vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
@@ -570,7 +574,7 @@ void VID_Finish (void)
 
 // handle the mouse state when windowed if that's changed
        vid_usemouse = false;
 
 // 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 && !cls.demoplayback)
                vid_usemouse = true;
        if (!vid_activewindow)
                vid_usemouse = false;
                vid_usemouse = true;
        if (!vid_activewindow)
                vid_usemouse = false;
@@ -584,16 +588,19 @@ void VID_Finish (void)
                        qglFinish();
                qglXSwapBuffers(vidx11_display, win);
        }
                        qglFinish();
                qglXSwapBuffers(vidx11_display, win);
        }
+
+       if(XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &rampsize))
+               VID_UpdateGamma(false, rampsize);
 }
 
 }
 
-int VID_SetGamma(unsigned short *ramps)
+int VID_SetGamma(unsigned short *ramps, int rampsize)
 {
 {
-       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)
 {
 {
-       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)
 }
 
 void VID_Init(void)
@@ -625,7 +632,7 @@ void VID_BuildGLXAttrib(int *attrib, int stencil)
        *attrib++ = None;
 }
 
        *attrib++ = 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)
 {
        int i;
        int attrib[32];
 {
        int i;
        int attrib[32];
@@ -698,6 +705,14 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                // Are we going fullscreen?  If so, let's change video mode
                if (fullscreen)
                {
                // 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;
                        XF86VidModeGetAllModeLines(vidx11_display, vidx11_screen, &num_vidmodes, &vidmodes);
                        best_dist = 9999999;
                        best_fit = -1;
@@ -734,6 +749,8 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                        }
                        else
                                fullscreen = 0;
                        }
                        else
                                fullscreen = 0;
+
+                       free(vidmodes);
                }
        }
 
                }
        }