]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_glx.c
added -gl_driver commandline option, and cleaned up some glX init stuff a bit
[xonotic/darkplaces.git] / vid_glx.c
index 706cb5fda9f8d34269efefaa1fdb30b6fd7f1d8c..542690a6f8b6548b2b05f3bfef9e4eb7cafad47b 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -474,10 +474,13 @@ void VID_Shutdown(void)
        if (!ctx || !vidx11_display)
                return;
 
+       vid_hidden = true;
+       usingmouse = false;
        if (vidx11_display)
        {
                uninstall_grabs();
 
+               // FIXME: glXDestroyContext here?
                if (vidmode_active)
                        XF86VidModeSwitchToMode(vidx11_display, scrnum, vidmodes[0]);
                if (win)
@@ -639,44 +642,47 @@ void VID_Init(void)
        Cvar_RegisterVariable (&vid_dga);
        Cvar_RegisterVariable (&vid_dga_mouseaccel);
        InitSig(); // trap evil signals
+       if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
+               mouse_avail = false;
 }
 
-int VID_InitMode(int fullscreen, int width, int height, int bpp)
+void VID_BuildGLXAttrib(int *attrib, int stencil, int gamma)
 {
-       int i;
-// LordHavoc: FIXME: finish this code, we need to allocate colors before we can store them
-#if 0
-       int gammaattrib[] =
+       *attrib++ = GLX_RGBA;
+       *attrib++ = GLX_RED_SIZE;*attrib++ = 1;
+       *attrib++ = GLX_GREEN_SIZE;*attrib++ = 1;
+       *attrib++ = GLX_BLUE_SIZE;*attrib++ = 1;
+       *attrib++ = GLX_DOUBLEBUFFER;
+       *attrib++ = GLX_DEPTH_SIZE;*attrib++ = 1;
+       if (stencil)
        {
-               GLX_RGBA,
-               GLX_RED_SIZE, 1,
-               GLX_GREEN_SIZE, 1,
-               GLX_BLUE_SIZE, 1,
-               GLX_DOUBLEBUFFER,
-               GLX_DEPTH_SIZE, 1,
-               GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR,
-               None
-       };
-#endif
-       int nogammaattrib[] =
+               *attrib++ = GLX_STENCIL_SIZE;*attrib++ = 8;
+       }
+       if (gamma)
        {
-               GLX_RGBA,
-               GLX_RED_SIZE, 1,
-               GLX_GREEN_SIZE, 1,
-               GLX_BLUE_SIZE, 1,
-               GLX_DOUBLEBUFFER,
-               GLX_DEPTH_SIZE, 1,
-               None
+               *attrib++ = GLX_X_VISUAL_TYPE;*attrib++ = GLX_DIRECT_COLOR;
        };
+       *attrib++ = None;
+}
+
+int VID_InitMode(int fullscreen, int width, int height, int bpp, int stencil)
+{
+       int i;
+       int attrib[32];
        XSetWindowAttributes attr;
        unsigned long mask;
        Window root;
        XVisualInfo *visinfo;
        int MajorVersion, MinorVersion;
+       const char *drivername;
 
-       if (!GL_OpenLibrary("libGL.so.1"))
+       drivername = "libGL.so.1";
+       i = COM_CheckParm("-gl_driver");
+       if (i && i < com_argc - 1)
+               drivername = com_argv[i + 1];
+       if (!GL_OpenLibrary(drivername))
        {
-               Con_Printf("Unable to load GL driver\n");
+               Con_Printf("Unable to load GL driver \"%s\"\n", drivername);
                return false;
        }
 
@@ -713,11 +719,15 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
 // LordHavoc: FIXME: finish this code, we need to allocate colors before we can store them
 #if 0
        if (!COM_CheckParm("-nogamma"))
-               visinfo = qglXChooseVisual(vidx11_display, scrnum, gammaattrib);
+       {
+               VID_BuildGLXAttrib(attrib, stencil, true);
+               visinfo = qglXChooseVisual(vidx11_display, scrnum, attrib);
+       }
 #endif
        if (!visinfo)
        {
-               visinfo = qglXChooseVisual(vidx11_display, scrnum, nogammaattrib);
+               VID_BuildGLXAttrib(attrib, stencil, false);
+               visinfo = qglXChooseVisual(vidx11_display, scrnum, attrib);
                if (!visinfo)
                {
                        Con_Printf("Couldn't get an RGB, Double-buffered, Depth visual\n");
@@ -810,11 +820,16 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                XF86VidModeSetViewPort(vidx11_display, scrnum, 0, 0);
        }
 
-       XFlush(vidx11_display);
+       //XSync(vidx11_display, False);
 
        ctx = qglXCreateContext(vidx11_display, visinfo, NULL, True);
+       if (!ctx)
+               Sys_Error ("glXCreateContext failed\n");
+
+       if (!qglXMakeCurrent(vidx11_display, win, ctx))
+               Sys_Error ("glXMakeCurrent failed\n");
 
-       qglXMakeCurrent(vidx11_display, win, ctx);
+       XSync(vidx11_display, False);
 
        scr_width = width;
        scr_height = height;
@@ -832,6 +847,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
        GL_CheckExtension("GLX_ARB_get_proc_address", getprocaddressfuncs, "-nogetprocaddress", false);
        gl_videosyncavailable = GL_CheckExtension("GLX_SGI_video_sync", videosyncfuncs, "-novideosync", false);
 
+       usingmouse = false;
        vid_hidden = false;
        GL_Init();
        return true;
@@ -842,16 +858,6 @@ void Sys_SendKeyEvents(void)
        HandleEvents();
 }
 
-void IN_Init(void)
-{
-       if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
-               mouse_avail = false;
-}
-
-void IN_Shutdown(void)
-{
-}
-
 /*
 ===========
 IN_Commands