Nvidia crashes because the stack size of the service thread is too
small.
The patch fixes this and cleans up the linux implementation.

Alexander

Am Donnerstag, den 19.07.2007, 16:35 +0200 schrieb Alexander Eichner:
> This really fixes SharedOpenGL with Mesa/DRI.
> Nvidia doesn't work (my setup was broken and it used software rendering
> thatswhy i thought it worked)
> 
> Alexander
> 
> Am Mittwoch, den 18.07.2007, 17:21 +0200 schrieb Alexander Eichner:
> > This is the new version of the patch.
> > It removes the need for a global display variable and replaces the
> > PixelFormat to XVisualInfo conversion code with one which uses
> > GLXFBConfig. All demos are now working with nvidia drivers.
> > 
> > Alexander Eichner
> > 
> > Am Mittwoch, den 11.07.2007, 12:59 +0200 schrieb Alexander Eichner:
> > > there were some things left in the Makefile.kmk from a previous attempt
> > > to get Display variable via global qApp object.
> > > Prevents VirtualBox from building on other Distros like Fedira 7.
> > > Removed it. Updated patch attached.
> > > 
> > > Alexander
> > > 
> > > Am Mittwoch, den 11.07.2007, 11:51 +0200 schrieb Alexander Eichner:
> > > > the attached patch adds basic Shared OpenGL support for Windows guests
> > > > on Linux hosts.
> > > > It currently works with the mesa software renderer.
> > > > tests with the accelerated but proprietary nvidia driver resulted in a
> > > > segmentation fault.
> > > > Another problem is that it needs a global Display variable which is
> > > > defined in the VirtualBox frontend.
> > > > The patched is released under the MIT license
> > > > 
> > > > Regards,
> > > > Alexander Eichner
> > > > _______________________________________________
> > > > vbox-dev mailing list
> > > > [email protected]
> > > > http://vbox.innotek.de/mailman/listinfo/vbox-dev
> > > _______________________________________________
> > > vbox-dev mailing list
> > > [email protected]
> > > http://vbox.innotek.de/mailman/listinfo/vbox-dev
> > _______________________________________________
> > vbox-dev mailing list
> > [email protected]
> > http://vbox.innotek.de/mailman/listinfo/vbox-dev
> _______________________________________________
> vbox-dev mailing list
> [email protected]
> http://vbox.innotek.de/mailman/listinfo/vbox-dev
Index: src/VBox/HostServices/SharedOpenGL/service.cpp
===================================================================
--- src/VBox/HostServices/SharedOpenGL/service.cpp	(Revision 3787)
+++ src/VBox/HostServices/SharedOpenGL/service.cpp	(Arbeitskopie)
@@ -37,7 +37,8 @@
     int rc = VINF_SUCCESS;
 
     Log(("svcUnload\n"));
-
+
+    vboxglGlobalUnload();
     return rc;
 }
 
Index: src/VBox/HostServices/SharedOpenGL/gllindrv.cpp
===================================================================
--- src/VBox/HostServices/SharedOpenGL/gllindrv.cpp	(Revision 3787)
+++ src/VBox/HostServices/SharedOpenGL/gllindrv.cpp	(Arbeitskopie)
@@ -23,25 +23,18 @@
  * license agreement apply instead of the previous paragraph.
  *
  */
+#define GLX_GLXEXT_PROTOTYPES
 
 #include "vboxgl.h"
 #define LOG_GROUP LOG_GROUP_SHARED_OPENGL
 #include <VBox/log.h>
 #include <string.h>
 #include <stdio.h>
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <GL/glxext.h>
 
-/*static int (*X_handler)(Display *, XErrorEvent *) = NULL;
-static int x_errhandler(Display *d, XErrorEvent *e)
-{
-    return (X_handler(d, e));
-}
 
-static int (*XIO_handler)(Display *) = NULL;
-static int xio_errhandler(Display *d)
-{
-    return (XIO_handler(d));
-}*/
-
 /* X11 server connection for all OpenGL clients.
  * Neccessary because Mesa and DRI cannot handle more than one
  * connection per thread (only hardware acceleration, software rendering
@@ -80,84 +73,8 @@
     return GL_FALSE;
 }
 
-
 /**
- * Print parameters for a GLXFBConfig to stdout.
- * Input:  dpy - the X display
- *         screen - the X screen number
- *         fbConfig - the fbconfig handle
- *         horizFormat - if true, print in horizontal format
- */
-void
-PrintFBConfigInfo(Display *dpy, int screen, GLXFBConfig config)
-{
-   int bufferSize, level, doubleBuffer, stereo, auxBuffers;
-   int redSize, greenSize, blueSize, alphaSize;
-   int depthSize, stencilSize;
-   int accumRedSize, accumBlueSize, accumGreenSize, accumAlphaSize;
-//   int sampleBuffers, samples;
-   int drawableType, renderType, xRenderable, xVisual, id;
-
-   /* do queries using the GLX 1.3 tokens (same as the SGIX tokens) */
-   glXGetFBConfigAttrib(dpy, config, GLX_BUFFER_SIZE, &bufferSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_LEVEL, &level);
-   glXGetFBConfigAttrib(dpy, config, GLX_DOUBLEBUFFER, &doubleBuffer);
-   glXGetFBConfigAttrib(dpy, config, GLX_STEREO, &stereo);
-   glXGetFBConfigAttrib(dpy, config, GLX_AUX_BUFFERS, &auxBuffers);
-   glXGetFBConfigAttrib(dpy, config, GLX_RED_SIZE, &redSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_GREEN_SIZE, &greenSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_BLUE_SIZE, &blueSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_ALPHA_SIZE, &alphaSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_DEPTH_SIZE, &depthSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_STENCIL_SIZE, &stencilSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_RED_SIZE, &accumRedSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_GREEN_SIZE, &accumGreenSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_BLUE_SIZE, &accumBlueSize);
-   glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_ALPHA_SIZE, &accumAlphaSize);
-//   glXGetFBConfigAttrib(dpy, config, GLX_SAMPLE_BUFFERS, &sampleBuffers);
-//   glXGetFBConfigAttrib(dpy, config, GLX_SAMPLES, &samples);
-   glXGetFBConfigAttrib(dpy, config, GLX_DRAWABLE_TYPE, &drawableType);
-   glXGetFBConfigAttrib(dpy, config, GLX_RENDER_TYPE, &renderType);
-   glXGetFBConfigAttrib(dpy, config, GLX_X_RENDERABLE, &xRenderable);
-   glXGetFBConfigAttrib(dpy, config, GLX_X_VISUAL_TYPE, &xVisual);
-   if (!xRenderable || !(drawableType & GLX_WINDOW_BIT_SGIX))
-      xVisual = -1;
-
-   glXGetFBConfigAttrib(dpy, config, GLX_FBCONFIG_ID, &id);
-
-      printf("Id 0x%x\n", id);
-      printf("  Buffer Size: %d\n", bufferSize);
-      printf("  Level: %d\n", level);
-      printf("  Double Buffer: %s\n", doubleBuffer ? "yes" : "no");
-      printf("  Stereo: %s\n", stereo ? "yes" : "no");
-      printf("  Aux Buffers: %d\n", auxBuffers);
-      printf("  Red Size: %d\n", redSize);
-      printf("  Green Size: %d\n", greenSize);
-      printf("  Blue Size: %d\n", blueSize);
-      printf("  Alpha Size: %d\n", alphaSize);
-      printf("  Depth Size: %d\n", depthSize);
-      printf("  Stencil Size: %d\n", stencilSize);
-      printf("  Accum Red Size: %d\n", accumRedSize);
-      printf("  Accum Green Size: %d\n", accumGreenSize);
-      printf("  Accum Blue Size: %d\n", accumBlueSize);
-      printf("  Accum Alpha Size: %d\n", accumAlphaSize);
-//      printf("  Sample Buffers: %d\n", sampleBuffers);
-//      printf("  Samples/Pixel: %d\n", samples);
-      printf("  Drawable Types: ");
-      if (drawableType & GLX_WINDOW_BIT)  printf("Window ");
-      if (drawableType & GLX_PIXMAP_BIT)  printf("Pixmap ");
-      if (drawableType & GLX_PBUFFER_BIT)  printf("PBuffer");
-      printf("\n");
-      printf("  Render Types: ");
-      if (renderType & GLX_RGBA_BIT_SGIX)  printf("RGBA ");
-      if (renderType & GLX_COLOR_INDEX_BIT_SGIX)  printf("CI ");
-      printf("\n");
-      printf("  X Renderable: %s\n", xRenderable ? "yes" : "no");
-
-}
-
-/**
- * Global init of VBox OpenGL for windows
+ * Global init of VBox OpenGL
  *
  * @returns VBox error code
  */
@@ -165,13 +82,25 @@
 {
     Log(("vboxglGlobalInit\n"));
 
-    glXDisplay = XOpenDisplay(NULL);
-
     /*vboxInitOpenGLExtensions();*/
     return VINF_SUCCESS;
 }
+
+/**
+ * Global deinit of VBox OpenGL
+ *
+ * @returns VBox error code
+ */
+int vboxglGlobalUnload()
+{
+    Log(("vboxglGlobalUnload"));
+
+    if (glXDisplay)
+        XCloseDisplay(glXDisplay);
+
+    return VINF_SUCCESS;
+}
 
-
 /**
  * Enable OpenGL
  *
@@ -179,12 +108,12 @@
  * @param   pClient         Client context
  */
 int vboxglEnableOpenGL(PVBOXOGLCTX pClient)
-{
+{
     static int attribs[] = {
         GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
         GLX_RENDER_TYPE,   GLX_RGBA_BIT,
-        GLX_DOUBLEBUFFER,  True,  /* Request a double-buffered color buffer with */
-        GLX_RED_SIZE,      1,     /* the maximum number of bits per component    */
+        GLX_DOUBLEBUFFER,  GL_TRUE,  /* Request a double-buffered color buffer with */
+        GLX_RED_SIZE,      1,        /* the maximum number of bits per component    */
         GLX_GREEN_SIZE,    1, 
         GLX_BLUE_SIZE,     1,
         None
@@ -194,34 +123,26 @@
     unsigned long mask;
     int returnedFBConfigs;
 
-    if (!pClient->glxContext) 
-    {
-        /* we have to set up a rendering context to be able to use glGetString
-         * a window is created but is not mapped to screen (so it's not visible') 
-         * and a GLXContext is bound to it */
-        screen_num = DefaultScreen(pClient->dpy);
-        pClient->enable.fbConfig = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedFBConfigs);
-        Log(("vboxglGetString: returned FBConfigs: %d\n", returnedFBConfigs));
-        pClient->enable.visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, pClient->enable.fbConfig[0]);
-        /* Create Window */
-        attr.background_pixel = 0;
-        attr.border_pixel = 0;
-        attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num), pClient->enable.visinfo->visual, AllocNone);
-        attr.event_mask = StructureNotifyMask | ExposureMask;
-        mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
-        pClient->enable.win = XCreateWindow(pClient->dpy, RootWindow(pClient->dpy, screen_num), 0, 0, 100, 100,
-		           0, pClient->enable.visinfo->depth, InputOutput,
-		           pClient->enable.visinfo->visual, mask, &attr);
-        /* Create Context */
-        pClient->enable.ctx = pClient->glxCreateNewContext(pClient->dpy, pClient->enable.fbConfig[0], GLX_RGBA_TYPE, NULL, True);
+    /* we have to set up a rendering context to be able to use glGetString
+     * a window is created but is not mapped to screen (so it's not visible') 
+     * and a GLXContext is bound to it */
+    screen_num = DefaultScreen(pClient->dpy);
+    pClient->enable.fbConfig = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedFBConfigs);
+    Log(("vboxglGetString: returned FBConfigs: %d\n", returnedFBConfigs));
+    pClient->enable.visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, pClient->enable.fbConfig[0]);
+    /* Create Window */
+    attr.background_pixel = 0;
+    attr.border_pixel = 0;
+    attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num), pClient->enable.visinfo->visual, AllocNone);
+    attr.event_mask = StructureNotifyMask | ExposureMask;
+    mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+    pClient->enable.win = XCreateWindow(pClient->dpy, RootWindow(pClient->dpy, screen_num), 0, 0, 100, 100,
+                                        0, pClient->enable.visinfo->depth, InputOutput,
+                                        pClient->enable.visinfo->visual, mask, &attr);
+    /* Create Context */
+    pClient->enable.ctx = pClient->glxCreateNewContext(pClient->dpy, pClient->enable.fbConfig[0], GLX_RGBA_TYPE, NULL, GL_TRUE);
+    glXMakeCurrent(pClient->dpy, pClient->enable.win, pClient->enable.ctx);
 
-        glXMakeCurrent(pClient->dpy, pClient->enable.win, pClient->enable.ctx);
-    } 
-    else 
-    {
-        glXMakeCurrent(pClient->dpy, pClient->xWindow, pClient->glxContext);
-    }
-
     return VINF_SUCCESS;
 }
 
@@ -232,17 +153,18 @@
  * @param   pClient         Client context
  */
 int vboxglDisableOpenGL(PVBOXOGLCTX pClient)
-{
+{
     /* Free all data */
-    glFlush();
-    if (!pClient->glxContext) 
-    {
-        glXMakeCurrent(pClient->dpy, 0, NULL);
+    if (pClient->enable.ctx) 
+    {
+        glFlush();
+        glXMakeCurrent(pClient->dpy, None, NULL);
         XDestroyWindow(pClient->dpy, pClient->enable.win);
         glXDestroyContext(pClient->dpy, pClient->enable.ctx);
         XFree(pClient->enable.visinfo);
         XFree(pClient->enable.fbConfig);
-    }
+    }
+
     return VINF_SUCCESS;
 }
 
@@ -256,10 +178,12 @@
 {
     int rc = VERR_NOT_IMPLEMENTED;
     Log(("vboxglConnect\n"));
-    //pClient->getContextIDPtr = NULL;
-    //pClient->importContextEXTPtr = NULL;
+
     pClient->PixelFormatToFBConfigMapper = NULL;
     pClient->xWindow = 0;
+
+    if (!glXDisplay)
+        glXDisplay = XOpenDisplay(NULL);
 
     pClient->dpy = glXDisplay;
 
@@ -268,27 +192,27 @@
 
         screenNum = DefaultScreen(pClient->dpy);
         glXQueryVersion(pClient->dpy, &major, &minor);
-
+
         if ((major == 1) && (minor >= 3)) {
             Log(("Server GLX 1.3 supported\n"));
-            pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddress( 
+            pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddressARB( 
                                           (GLubyte *) "glXChooseFBConfig");
-            pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddress( 
+            pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddressARB( 
                                                  (GLubyte *) "glXGetVisualFromFBConfig");
-            pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddress(
+            pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddressARB(
                                             (GLubyte *) "glXCreateNewContext");
-        } else if (vboxglCheckExtension(pClient->dpy, screenNum, "GLX_SGIX_fbconfig")) {
+        } else if (vboxglCheckExtension(pClient->dpy, screenNum, "GLX_SGIX_fbconfig")) {
             Log(("GLX_SGIX_fbconfig extension supported\n"));
-            pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddress( 
+            pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddressARB( 
                                           (GLubyte *) "glXChooseFBConfigSGIX");
-            pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddress( 
+            pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddressARB( 
                                                  (GLubyte *) "glXGetVisualFromFBConfigSGIX");
-            pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddress(
+            pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddressARB(
                                             (GLubyte *) "glXCreateContextWithConfigSGIX");
         } else {
                 Log(("Error no FBConfig supported\n"));
                 rc = VERR_NOT_IMPLEMENTED;
-        }
+        }
         if (pClient->glxChooseFBConfig && pClient->glxGetVisualFromFBConfig && pClient->glxCreateNewContext)
             rc = VINF_SUCCESS;
     }
@@ -328,7 +252,6 @@
     XSetWindowAttributes attr;
     XVisualInfo *visinfo = NULL;
     unsigned long mask;
-    //GLXContext ctx;
     GLXFBConfig fbConfig;
     GLXContextID glrc;
     int screen_num;
@@ -342,33 +265,6 @@
     screen_num = DefaultScreen(pClient->dpy);
     fbConfig = pClient->actFBConfig;
 
-#if 0
-    if (!fbConfig) {
-        /* Create a standard fbconfig */
-        int returnedNumFBConfigs;
-        GLXFBConfig *returnedFBConfigs;
-        static int attribs[] = {
-            GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
-            GLX_RENDER_TYPE,   GLX_RGBA_BIT,
-            GLX_DOUBLEBUFFER,  True,  /* Request a double-buffered color buffer with */
-            GLX_RED_SIZE,      1,     /* the maximum number of bits per component    */
-            GLX_GREEN_SIZE,    1, 
-            GLX_BLUE_SIZE,     1,
-            None
-        };
-
-        Log(("Warning: no GLXFBConfig set creating standard one\n"));
-        returnedFBConfigs = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedNumFBConfigs);
-        if (!returnedNumFBConfigs) {
-            pClient->lastretval = 0;
-            pClient->fHasLastError = true;
-            pClient->ulLastError   = glGetError();
-            return;
-        }
-        fbConfig = returnedFBConfigs[0];
-    }
-#endif
-
     visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, fbConfig);
 
     if (pClient->xWindow == 0) {
@@ -386,11 +282,11 @@
 	                                visinfo->visual, mask, &attr);
     }
     XResizeWindow(pClient->dpy, pClient->xWindow, pClient->winWidth, pClient->winHeight);
-    pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, True);
+    pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
 
     XMapWindow(pClient->dpy, pClient->xWindow);
     XIfEvent(pClient->dpy, &event, WaitForNotify, (XPointer)pClient->xWindow );
-    //glrc = pClient->getContextIDPtr(ctx);
+
     glrc = 1;
     Assert(glrc);
 #else
@@ -405,11 +301,10 @@
 
 void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    //GLXContext ctx;
     OGL_CMD(DrvDeleteContext, 1);
     OGL_PARAM(HGLRC, hglrc);
     Log(("DrvDeleteContext %x\n", hglrc));
-    //ctx = pClient->importContextEXTPtr(pClient->dpy, hglrc);
+
     glXDestroyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc));
     pClient->lastretval = 1;
     pClient->fHasLastError = true;
@@ -418,14 +313,13 @@
 
 void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    //GLXContext ctx;
     OGL_CMD(DrvSetContext, 2);
     OGL_PARAM(HDC, hdc);
     OGL_PARAM(HGLRC, hglrc);
     Log(("DrvSetContext %x %x\n", hdc, hglrc));
 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
-    //ctx = pClient->importContextEXTPtr(pClient->dpy, hglrc);
-    pClient->lastretval = glXMakeCurrent(pClient->dpy, pClient->xWindow, 
+
+    pClient->lastretval = glXMakeCurrent(pClient->dpy, pClient->xWindow,
                                          VBOX_OGL_GUEST_TO_HOST_HDC(hglrc));
     if (!pClient->lastretval)
         Log(("glXMakeCurrent failed\n"));
@@ -438,14 +332,12 @@
 
 void vboxglDrvCopyContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    //GLXContext ctxSrc, ctxDst;
     OGL_CMD(DrvDeleteContext, 3);
     OGL_PARAM(HGLRC, hglrcSrc);
     OGL_PARAM(HGLRC, hglrcDst);
     OGL_PARAM(UINT,  mask);
     Log(("DrvCopyContext %x %x %x\n", hglrcSrc, hglrcDst, mask));
-    //ctxSrc = pClient->importContextEXTPtr(pClient->dpy, hglrcSrc);
-    //ctxDst = pClient->importContextEXTPtr(pClient->dpy, hglrcDst);
+
     glXCopyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), mask);
     pClient->lastretval = 1;
     pClient->fHasLastError = true;
@@ -458,7 +350,7 @@
     OGL_PARAM(HGLRC, hglrc);
     Log(("DrvReleaseContext %x\n", hglrc));
     /* clear current selection */
-    pClient->lastretval = glXMakeCurrent(pClient->dpy, 0, NULL);
+    pClient->lastretval = glXMakeCurrent(pClient->dpy, None, NULL);
 
     if (!pClient->lastretval)
         Log(("glXMakeCurrent failed\n"));
@@ -467,14 +359,48 @@
 }
 
 void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
-{
+{
+    XSetWindowAttributes attr;
+    XVisualInfo *visinfo = NULL;
+    unsigned long mask;
+    GLXFBConfig fbConfig;
+    GLXContextID glrc;
+    int screen_num;
+    XEvent event;
     OGL_CMD(DrvCreateLayerContext, 2);
     OGL_PARAM(HDC, hdc);
     OGL_PARAM(int, iLayerPlane);
 
     Log(("DrvCreateLayerContext %x\n", hdc));
-#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
-    pClient->lastretval = 0; /** @todo */
+#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
+
+    screen_num = DefaultScreen(pClient->dpy);
+    fbConfig = pClient->actFBConfig;
+    visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, fbConfig);
+
+    if (pClient->xWindow == 0) {
+
+	/* window attributes */
+	attr.background_pixel = 0;
+	attr.border_pixel = 0;
+	attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num ), visinfo->visual, AllocNone);
+	attr.event_mask = StructureNotifyMask | ExposureMask;
+	mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+	pClient->xWindow = XCreateWindow(pClient->dpy, 
+	                                RootWindow(pClient->dpy, screen_num), 
+	                                0, 0, pClient->winWidth, pClient->winHeight, 0,
+	                                visinfo->depth, InputOutput,
+	                                visinfo->visual, mask, &attr);
+    }
+    XResizeWindow(pClient->dpy, pClient->xWindow, pClient->winWidth, pClient->winHeight);
+    pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
+    XMapWindow(pClient->dpy, pClient->xWindow);
+    XIfEvent(pClient->dpy, &event, WaitForNotify, (XPointer)pClient->xWindow );
+
+    glrc = 1;
+    Assert(glrc);
+
+    pClient->lastretval = glrc;
     pClient->fHasLastError = true;
     pClient->ulLastError   = glGetError();
 #else
@@ -528,8 +454,7 @@
     /* Get GLXFBConfig based on the given ID */
     pClient->actFBConfig = pClient->PixelFormatToFBConfigMapper[iPixelFormat-1];
     screen_num = DefaultScreen(pClient->dpy);
-    PrintFBConfigInfo(pClient->dpy, screen_num, pClient->actFBConfig);
-    Log(("Window width: %d Window height: %d\n", cx, cy));
+
     pClient->winWidth = cx;
     pClient->winHeight = cy;
     pClient->lastretval = true;
Index: src/VBox/HostServices/SharedOpenGL/vboxgl.cpp
===================================================================
--- src/VBox/HostServices/SharedOpenGL/vboxgl.cpp	(Revision 3787)
+++ src/VBox/HostServices/SharedOpenGL/vboxgl.cpp	(Arbeitskopie)
@@ -40,7 +40,7 @@
  * @param   pcbString   String length (in/out)
  */
 int vboxglGetString(VBOXOGLCTX *pClient, GLenum name, char *pString, uint32_t *pcbString)
-{
+{
     const GLubyte *pName;
     uint32_t cbLen;
     int      rc = VINF_SUCCESS;
@@ -66,7 +66,8 @@
 
 end:
 
-    vboxglDisableOpenGL(pClient);
+    vboxglDisableOpenGL(pClient);
+
     return rc;
 }
 
Index: src/VBox/HostServices/SharedOpenGL/gldrv.h
===================================================================
--- src/VBox/HostServices/SharedOpenGL/gldrv.h	(Revision 3787)
+++ src/VBox/HostServices/SharedOpenGL/gldrv.h	(Arbeitskopie)
@@ -26,14 +26,14 @@
 
 #ifdef RT_OS_WINDOWS
 #define VBOX_OGL_DEBUG_WINDOW_OUTPUT
-#elif defined(RT_OS_LINUX)
-#include <X11/Xlib.h>
+#elif defined(RT_OS_LINUX)
+
+#define GLX_GLXEXT_PROTOTYPES
+#include <X11/Xlib.h>
+#include <GL/gl.h>
 #include <GL/glx.h>
 #include <GL/glxext.h>
  
-typedef GLXContextID (*glXGetContextIDEXTProc) (const GLXContext);
-typedef GLXContext (*glXImportContextEXTProc) (Display *, GLXContextID);
- 
 #define VBOX_OGL_DEBUG_WINDOW_OUTPUT
 #endif
   
@@ -86,8 +86,6 @@
     PFNGLXCHOOSEFBCONFIGSGIXPROC glxChooseFBConfig;
     PFNGLXGETVISUALFROMFBCONFIGSGIXPROC glxGetVisualFromFBConfig;
     PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC glxCreateNewContext;
-    //glXGetContextIDEXTProc getContextIDPtr;
-    //glXImportContextEXTProc importContextEXTPtr;
 #endif
 #endif
 } VBOXOGLCTX, *PVBOXOGLCTX;
Index: src/VBox/HostServices/SharedOpenGL/vboxgl.h
===================================================================
--- src/VBox/HostServices/SharedOpenGL/vboxgl.h	(Revision 3787)
+++ src/VBox/HostServices/SharedOpenGL/vboxgl.h	(Arbeitskopie)
@@ -32,11 +32,18 @@
 typedef void (* PFN_VBOXGLWRAPPER)(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer);
 
 /**
- * Global init of VBox OpenGL for windows
+ * Global init of VBox OpenGL
  *
  * @returns VBox error code
  */
 int vboxglGlobalInit();
+
+/**
+ * Global deinit of VBox OpenGL
+ *
+ * @returns VBox error code
+ */
+int vboxglGlobalUnload();
 
 /**
  * Client connect init
Index: src/VBox/HostServices/SharedOpenGL/glwindrv.cpp
===================================================================
--- src/VBox/HostServices/SharedOpenGL/glwindrv.cpp	(Revision 3787)
+++ src/VBox/HostServices/SharedOpenGL/glwindrv.cpp	(Arbeitskopie)
@@ -129,6 +129,18 @@
 
     return VINF_SUCCESS;
 }
+
+/**
+ * Global deinit of VBox OpenGL
+ *
+ * @returns VBox error code
+ */
+int vboxglGlobalUnload()
+{
+    Log(("vboxglGlobalUnload"));
+
+    return VINF_SUCCESS;
+}
 
 /**
  * Enable OpenGL
Index: src/VBox/Frontends/VirtualBox/src/main.cpp
===================================================================
--- src/VBox/Frontends/VirtualBox/src/main.cpp	(Revision 3787)
+++ src/VBox/Frontends/VirtualBox/src/main.cpp	(Arbeitskopie)
@@ -53,8 +53,10 @@
 # define REG_PC REG_EIP
 #endif
 
+#ifdef Q_WS_X11
+#include <X11/Xlib.h>
+#endif
 
-
 /**
  * the signal handler that prints out a backtrace of the call stack.
  * the code is taken from http://www.linuxjournal.com/article/6391.
@@ -131,6 +133,10 @@
     sigaction (SIGUSR1, &sa, NULL);
 #endif
 
+#ifdef Q_WS_X11
+    XInitThreads();
+#endif
+
     qInstallMsgHandler (QtMessageOutput);
 
     QIApplication a (argc, argv);
Index: src/VBox/Main/hgcm/HGCMThread.cpp
===================================================================
--- src/VBox/Main/hgcm/HGCMThread.cpp	(Revision 3787)
+++ src/VBox/Main/hgcm/HGCMThread.cpp	(Arbeitskopie)
@@ -291,7 +291,7 @@
                 m_fu32ThreadFlags = HGCMMSG_TF_INITIALIZING;
 
                 RTTHREAD thread;
-                rc = RTThreadCreate (&thread, hgcmWorkerThreadFunc, this, 64 * _1K,
+                rc = RTThreadCreate (&thread, hgcmWorkerThreadFunc, this, 0,
                                      RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE,
                                      pszThreadName);
 
_______________________________________________
vbox-dev mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-dev

Reply via email to