X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=vid_glx.c;h=22075cb485455d05e6afecb8828fa19554b0e033;hp=de6c7c443df1a83568b12b1b952bc1e0e5788cbe;hb=fabdca42b48cc4acf214c06adda9814e5cce8577;hpb=195a5f4e8031dcc37d16fc81e7dc9da044721b33 diff --git a/vid_glx.c b/vid_glx.c index de6c7c44..22075cb4 100644 --- a/vid_glx.c +++ b/vid_glx.c @@ -40,6 +40,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" +int cl_available = true; + //GLX prototypes XVisualInfo *(GLAPIENTRY *qglXChooseVisual)(Display *dpy, int screen, int *attribList); GLXContext (GLAPIENTRY *qglXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct); @@ -81,8 +83,6 @@ Atom wm_delete_window_atom; #define X_MASK (KEY_MASK | MOUSE_MASK | VisibilityChangeMask | StructureNotifyMask ) -viddef_t vid; // global video state - static qboolean mouse_avail = true; static qboolean mouse_active = false, usingmouse = false; static float mouse_x, mouse_y; @@ -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) @@ -634,49 +637,61 @@ int VID_SetGamma(float prescale, float gamma, float scale, float base) #endif } -void VID_Init(int fullscreen, int width, int height) +void VID_Init(void) { - int i; -// LordHavoc: FIXME: finish this code, we need to allocate colors before we can store them -#if 0 - int gammaattrib[] = + Cvar_RegisterVariable (&vid_dga); + Cvar_RegisterVariable (&vid_dga_mouseaccel); + InitSig(); // trap evil signals + if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe")) + mouse_avail = false; +} + +void VID_BuildGLXAttrib(int *attrib, int stencil, int gamma) +{ + *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 is enabled, ask for alpha too + 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; + *attrib++ = GLX_ALPHA_SIZE;*attrib++ = 1; + } + 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")) - Sys_Error("Unable to load GL driver\n"); - - Cvar_RegisterVariable (&vid_dga); - Cvar_RegisterVariable (&vid_dga_mouseaccel); + 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 \"%s\"\n", drivername); + return false; + } if (!(vidx11_display = XOpenDisplay(NULL))) { - fprintf(stderr, "Error couldn't open the X display\n"); - exit(1); + Con_Printf("Couldn't open the X display\n"); + return false; } scrnum = DefaultScreen(vidx11_display); @@ -697,21 +712,28 @@ void VID_Init(int fullscreen, int width, int height) || (qglXMakeCurrent = GL_GetProcAddress("glXMakeCurrent")) == NULL || (qglXSwapBuffers = GL_GetProcAddress("glXSwapBuffers")) == NULL || (qglXQueryExtensionsString = GL_GetProcAddress("glXQueryExtensionsString")) == NULL) - Sys_Error("glX functions not found in %s\n", gl_driver); + { + Con_Printf("glX functions not found in %s\n", gl_driver); + return false; + } visinfo = NULL; // 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) { - Sys_Error("couldn't get an RGB, Double-buffered, Depth visual\n"); - exit(1); + Con_Printf("Couldn't get an RGB, Double-buffered, Depth visual\n"); + return false; } } @@ -800,11 +822,16 @@ void VID_Init(int fullscreen, int width, int height) 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"); - qglXMakeCurrent(vidx11_display, win, ctx); + if (!qglXMakeCurrent(vidx11_display, win, ctx)) + Sys_Error ("glXMakeCurrent failed\n"); + + XSync(vidx11_display, False); scr_width = width; scr_height = height; @@ -822,13 +849,10 @@ void VID_Init(int fullscreen, int width, int height) GL_CheckExtension("GLX_ARB_get_proc_address", getprocaddressfuncs, "-nogetprocaddress", false); gl_videosyncavailable = GL_CheckExtension("GLX_SGI_video_sync", videosyncfuncs, "-novideosync", false); - InitSig(); // trap evil signals - + usingmouse = false; vid_hidden = false; - GL_Init(); - - Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height); + return true; } void Sys_SendKeyEvents(void) @@ -836,16 +860,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