- Timestamp:
- Jul 19, 2007 8:21:00 AM (17 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedOpenGL
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/Makefile.kmk
r3454 r3708 33 33 $(PATH_TOOL_$(VBOX_VCC_TOOL)_ATLMFC_INC) \ 34 34 $(VBOX_PATH_SDK) 35 VBoxSharedOpenGL_CXXFLAGS.linux = -pthread 35 36 36 37 VBoxSharedOpenGL_SOURCES = \ … … 55 56 VBoxSharedOpenGL_LIBS.win = \ 56 57 $(PATH_SDK_WINPSDK_LIB)/opengl32.lib 58 VBoxSharedOpenGL_LIBPATH.linux = \ 59 $(VBOX_LIBPATH_X11) 60 VBoxSharedOpenGL_LIBS.linux = \ 61 GL 57 62 58 63 include $(PATH_KBUILD)/subfooter.kmk -
trunk/src/VBox/HostServices/SharedOpenGL/gldrv.h
r3698 r3708 23 23 24 24 #include <iprt/types.h> 25 #include <iprt/mem.h> 25 26 26 27 #ifdef RT_OS_WINDOWS 27 28 #define VBOX_OGL_DEBUG_WINDOW_OUTPUT 28 #endif 29 29 #elif defined(RT_OS_LINUX) 30 #include <X11/Xlib.h> 31 #include <GL/glx.h> 32 #include <GL/glxext.h> 33 34 typedef GLXContextID (*glXGetContextIDEXTProc) (const GLXContext); 35 typedef GLXContext (*glXImportContextEXTProc) (Display *, GLXContextID); 36 37 #define VBOX_OGL_DEBUG_WINDOW_OUTPUT 38 #endif 39 30 40 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT 41 #if defined(RT_OS_WINDOWS) 31 42 #define VBOX_OGL_GUEST_TO_HOST_HDC(a) pClient->hdc 32 #else 33 #define VBOX_OGL_GUEST_TO_HOST_HDC(a) a 34 #endif 43 #elif defined(RT_OS_LINUX) 44 #define VBOX_OGL_GUEST_TO_HOST_HDC(a) pClient->glxContext 45 #endif 46 #endif 47 35 48 36 49 typedef struct … … 44 57 uint32_t cbLastParam; 45 58 59 struct 60 { 61 #ifdef RT_OS_WINDOWS 62 HWND hwnd; 63 HDC hdc; 64 HGLRC hglrc; 65 #elif defined RT_OS_LINUX 66 Display *dpy; 67 Window win; 68 GLXContext ctx; 69 GLXFBConfig *fbConfig; 70 XVisualInfo *visinfo; 71 #endif 72 } enable; 73 46 74 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT 75 #ifdef RT_OS_WINDOWS 47 76 HWND hwnd; 48 77 HDC hdc; 78 #elif defined RT_OS_LINUX 79 Display *dpy; 80 Window xWindow; 81 GLXFBConfig actFBConfig; 82 int winWidth, winHeight; 83 GLXFBConfig *PixelFormatToFBConfigMapper; 84 int numFBConfigs; 85 GLXContext glxContext; 86 PFNGLXCHOOSEFBCONFIGSGIXPROC glxChooseFBConfig; 87 PFNGLXGETVISUALFROMFBCONFIGSGIXPROC glxGetVisualFromFBConfig; 88 PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC glxCreateNewContext; 89 //glXGetContextIDEXTProc getContextIDPtr; 90 //glXImportContextEXTProc importContextEXTPtr; 91 #endif 49 92 #endif 50 93 } VBOXOGLCTX, *PVBOXOGLCTX; … … 72 115 #define DECLARE_HANDLE(a) typedef HANDLE a 73 116 #define WINAPI 117 118 #define PFD_DOUBLEBUFFER 0x00000001 119 #define PFD_STEREO 0x00000002 120 #define PFD_DRAW_TO_WINDOW 0x00000004 121 #define PFD_SUPPORT_OPENGL 0x00000020 122 123 #define PFD_TYPE_RGBA 0 124 #define PFD_TYPE_COLORINDEX 1 125 126 #define PFD_MAIN_PLANE 0 127 #define PFD_OVERLAY_PLANE 1 128 #define PFD_UNDERLAY_PLANE (-1) 74 129 75 130 typedef struct … … 149 204 void vboxglDrvSwapBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer); 150 205 206 int vboxglEnableOpenGL(VBOXOGLCTX *pClient); 207 int vboxglDisableOpenGL(VBOXOGLCTX *pClient); 151 208 152 209 RTUINTPTR vboxDrvIsExtensionAvailable(char *pszExtFunctionName); -
trunk/src/VBox/HostServices/SharedOpenGL/gllindrv.cpp
r3698 r3708 4 4 * 5 5 * Simple buffered OpenGL functions 6 * 7 * Contributor: Alexander Eichner 6 8 */ 7 9 … … 26 28 #define LOG_GROUP LOG_GROUP_SHARED_OPENGL 27 29 #include <VBox/log.h> 30 #include <string.h> 31 #include <stdio.h> 32 33 /*static int (*X_handler)(Display *, XErrorEvent *) = NULL; 34 static int x_errhandler(Display *d, XErrorEvent *e) 35 { 36 return (X_handler(d, e)); 37 } 38 39 static int (*XIO_handler)(Display *) = NULL; 40 static int xio_errhandler(Display *d) 41 { 42 return (XIO_handler(d)); 43 }*/ 44 45 static Bool WaitForNotify( Display *dpy, XEvent *event, XPointer arg ) { 46 return (event->type == MapNotify) && (event->xmap.window == (Window) arg); 47 } 48 49 /* from http://www.mesa3d.org/brianp/sig97/exten.htm */ 50 GLboolean vboxglCheckExtension(Display *dpy, int screenNum, char *extName ) 51 { 52 /* 53 ** Search for extName in the extensions string. Use of strstr() 54 ** is not sufficient because extension names can be prefixes of 55 ** other extension names. Could use strtok() but the constant 56 ** string returned by glGetString can be in read-only memory. 57 */ 58 char *p = (char *) glXQueryExtensionsString(dpy, screenNum); 59 char *end; 60 int extNameLen; 61 62 extNameLen = strlen(extName); 63 end = p + strlen(p); 64 65 while (p < end) { 66 int n = strcspn(p, " "); 67 if ((extNameLen == n) && (strncmp(extName, p, n) == 0)) { 68 return GL_TRUE; 69 } 70 p += (n + 1); 71 } 72 return GL_FALSE; 73 } 74 75 76 /** 77 * Print parameters for a GLXFBConfig to stdout. 78 * Input: dpy - the X display 79 * screen - the X screen number 80 * fbConfig - the fbconfig handle 81 * horizFormat - if true, print in horizontal format 82 */ 83 void 84 PrintFBConfigInfo(Display *dpy, int screen, GLXFBConfig config) 85 { 86 int bufferSize, level, doubleBuffer, stereo, auxBuffers; 87 int redSize, greenSize, blueSize, alphaSize; 88 int depthSize, stencilSize; 89 int accumRedSize, accumBlueSize, accumGreenSize, accumAlphaSize; 90 int sampleBuffers, samples; 91 int drawableType, renderType, xRenderable, xVisual, id; 92 93 /* do queries using the GLX 1.3 tokens (same as the SGIX tokens) */ 94 glXGetFBConfigAttrib(dpy, config, GLX_BUFFER_SIZE, &bufferSize); 95 glXGetFBConfigAttrib(dpy, config, GLX_LEVEL, &level); 96 glXGetFBConfigAttrib(dpy, config, GLX_DOUBLEBUFFER, &doubleBuffer); 97 glXGetFBConfigAttrib(dpy, config, GLX_STEREO, &stereo); 98 glXGetFBConfigAttrib(dpy, config, GLX_AUX_BUFFERS, &auxBuffers); 99 glXGetFBConfigAttrib(dpy, config, GLX_RED_SIZE, &redSize); 100 glXGetFBConfigAttrib(dpy, config, GLX_GREEN_SIZE, &greenSize); 101 glXGetFBConfigAttrib(dpy, config, GLX_BLUE_SIZE, &blueSize); 102 glXGetFBConfigAttrib(dpy, config, GLX_ALPHA_SIZE, &alphaSize); 103 glXGetFBConfigAttrib(dpy, config, GLX_DEPTH_SIZE, &depthSize); 104 glXGetFBConfigAttrib(dpy, config, GLX_STENCIL_SIZE, &stencilSize); 105 glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_RED_SIZE, &accumRedSize); 106 glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_GREEN_SIZE, &accumGreenSize); 107 glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_BLUE_SIZE, &accumBlueSize); 108 glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_ALPHA_SIZE, &accumAlphaSize); 109 glXGetFBConfigAttrib(dpy, config, GLX_SAMPLE_BUFFERS, &sampleBuffers); 110 glXGetFBConfigAttrib(dpy, config, GLX_SAMPLES, &samples); 111 glXGetFBConfigAttrib(dpy, config, GLX_DRAWABLE_TYPE, &drawableType); 112 glXGetFBConfigAttrib(dpy, config, GLX_RENDER_TYPE, &renderType); 113 glXGetFBConfigAttrib(dpy, config, GLX_X_RENDERABLE, &xRenderable); 114 glXGetFBConfigAttrib(dpy, config, GLX_X_VISUAL_TYPE, &xVisual); 115 if (!xRenderable || !(drawableType & GLX_WINDOW_BIT_SGIX)) 116 xVisual = -1; 117 118 glXGetFBConfigAttrib(dpy, config, GLX_FBCONFIG_ID, &id); 119 120 printf("Id 0x%x\n", id); 121 printf(" Buffer Size: %d\n", bufferSize); 122 printf(" Level: %d\n", level); 123 printf(" Double Buffer: %s\n", doubleBuffer ? "yes" : "no"); 124 printf(" Stereo: %s\n", stereo ? "yes" : "no"); 125 printf(" Aux Buffers: %d\n", auxBuffers); 126 printf(" Red Size: %d\n", redSize); 127 printf(" Green Size: %d\n", greenSize); 128 printf(" Blue Size: %d\n", blueSize); 129 printf(" Alpha Size: %d\n", alphaSize); 130 printf(" Depth Size: %d\n", depthSize); 131 printf(" Stencil Size: %d\n", stencilSize); 132 printf(" Accum Red Size: %d\n", accumRedSize); 133 printf(" Accum Green Size: %d\n", accumGreenSize); 134 printf(" Accum Blue Size: %d\n", accumBlueSize); 135 printf(" Accum Alpha Size: %d\n", accumAlphaSize); 136 printf(" Sample Buffers: %d\n", sampleBuffers); 137 printf(" Samples/Pixel: %d\n", samples); 138 printf(" Drawable Types: "); 139 if (drawableType & GLX_WINDOW_BIT) printf("Window "); 140 if (drawableType & GLX_PIXMAP_BIT) printf("Pixmap "); 141 if (drawableType & GLX_PBUFFER_BIT) printf("PBuffer"); 142 printf("\n"); 143 printf(" Render Types: "); 144 if (renderType & GLX_RGBA_BIT_SGIX) printf("RGBA "); 145 if (renderType & GLX_COLOR_INDEX_BIT_SGIX) printf("CI "); 146 printf("\n"); 147 printf(" X Renderable: %s\n", xRenderable ? "yes" : "no"); 148 149 } 28 150 29 151 /** … … 34 156 int vboxglGlobalInit() 35 157 { 36 vboxInitOpenGLExtensions(); 158 Log(("vboxglGlobalInit\n")); 159 160 /*vboxInitOpenGLExtensions();*/ 161 return VINF_SUCCESS; 162 } 163 164 165 /** 166 * Enable OpenGL 167 * 168 * @returns VBox error code 169 * @param pClient Client context 170 */ 171 int vboxglEnableOpenGL(PVBOXOGLCTX pClient) 172 { 173 Display *dpy; 174 static int attribs[] = { 175 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 176 GLX_RENDER_TYPE, GLX_RGBA_BIT, 177 GLX_DOUBLEBUFFER, True, /* Request a double-buffered color buffer with */ 178 GLX_RED_SIZE, 1, /* the maximum number of bits per component */ 179 GLX_GREEN_SIZE, 1, 180 GLX_BLUE_SIZE, 1, 181 None 182 }; 183 int screen_num; 184 XSetWindowAttributes attr; 185 unsigned long mask; 186 int returnedFBConfigs; 187 188 if (!pClient->glxContext) 189 { 190 /* we have to set up a rendering context to be able to use glGetString 191 * a window is created but is not mapped to screen (so it's not visible') 192 * and a GLXContext is bound to it */ 193 screen_num = DefaultScreen(pClient->dpy); 194 pClient->enable.fbConfig = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedFBConfigs); 195 Log(("vboxglGetString: returned FBConfigs: %d\n", returnedFBConfigs)); 196 pClient->enable.visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, fbConfig[0]); 197 /* Create Window */ 198 attr.background_pixel = 0; 199 attr.border_pixel = 0; 200 attr.colormap = XCreateColormap(pClient->dpy, RootWindow(dpy, screen_num), visinfo->visual, AllocNone); 201 attr.event_mask = StructureNotifyMask | ExposureMask; 202 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; 203 pClient->enable.win = XCreateWindow(pClient->dpy, RootWindow(pClient->dpy, screen_num), 0, 0, 100, 100, 204 0, visinfo->depth, InputOutput, 205 visinfo->visual, mask, &attr); 206 /* Create Context */ 207 pClient->enable.ctx = pClient->glxCreateNewContext(pClient->dpy, fbConfig[0], GLX_RGBA_TYPE, NULL, True); 208 209 glXMakeCurrent(pClient->dpy, pClient->enable.win, pClient->enable.ctx); 210 } 211 else 212 { 213 glXMakeCurrent(pClient->dpy, pClient->xWindow, pClient->glxContext); 214 } 215 216 return VINF_SUCCESS; 217 } 218 219 /** 220 * Disable OpenGL 221 * 222 * @returns VBox error code 223 * @param pClient Client context 224 */ 225 int vboxglDisableOpenGL(PVBOXOGLCTX pClient) 226 { 227 /* Free all data */ 228 glFlush(); 229 if (!pClient->glxContext) 230 { 231 glXMakeCurrent(pClient->dpy, 0, NULL); 232 XDestroyWindow(pClient->dpy, pClient->enable.win); 233 glXDestroyContext(pClient->dpy, pClient->enable.ctx); 234 XFree(pClient->enable.visinfo); 235 XFree(pClient->enable.fbConfig); 236 } 37 237 return VINF_SUCCESS; 38 238 } … … 46 246 int vboxglConnect(PVBOXOGLCTX pClient) 47 247 { 48 return VINF_SUCCESS; 248 int rc = VERR_NOT_IMPLEMENTED; 249 Log(("vboxglConnect\n")); 250 //pClient->getContextIDPtr = NULL; 251 //pClient->importContextEXTPtr = NULL; 252 pClient->PixelFormatToFBConfigMapper = NULL; 253 pClient->xWindow = 0; 254 255 pClient->dpy = XOpenDisplay(NULL); 256 257 if (pClient->dpy) { 258 int screenNum, major, minor; 259 260 screenNum = DefaultScreen(pClient->dpy); 261 glXQueryVersion(pClient->dpy, &major, &minor); 262 263 if ((major == 1) && (minor >= 3)) { 264 Log(("Server GLX 1.3 supported\n")); 265 pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddress( 266 (GLubyte *) "glXChooseFBConfig"); 267 pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddress( 268 (GLubyte *) "glXGetVisualFromFBConfig"); 269 pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddress( 270 (GLubyte *) "glXCreateNewContext"); 271 } else if (vboxglCheckExtension(pClient->dpy, screenNum, "GLX_SGIX_fbconfig")) { 272 Log(("GLX_SGIX_fbconfig extension supported\n")); 273 pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddress( 274 (GLubyte *) "glXChooseFBConfigSGIX"); 275 pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddress( 276 (GLubyte *) "glXGetVisualFromFBConfigSGIX"); 277 pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddress( 278 (GLubyte *) "glXCreateContextWithConfigSGIX"); 279 } else { 280 Log(("Error no FBConfig supported\n")); 281 rc = VERR_NOT_IMPLEMENTED; 282 } 283 if (pClient->glxChooseFBConfig && pClient->glxGetVisualFromFBConfig && pClient->glxCreateNewContext) 284 rc = VINF_SUCCESS; 285 } 286 287 return rc; 49 288 } 50 289 … … 57 296 int vboxglDisconnect(PVBOXOGLCTX pClient) 58 297 { 298 Log(("vboxglDisconnect\n")); 299 300 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT 301 if (pClient->dpy) { 302 if (pClient->xWindow != 0) { 303 XUnmapWindow(pClient->dpy, pClient->xWindow); 304 XDestroyWindow(pClient->dpy, pClient->xWindow); 305 } 306 if (pClient->PixelFormatToFBConfigMapper) { 307 XFree(pClient->PixelFormatToFBConfigMapper); 308 } 309 XCloseDisplay(pClient->dpy); 310 } 311 pClient->dpy = NULL; 312 pClient->xWindow = 0; 313 pClient->actFBConfig = NULL; 314 #endif 59 315 return VINF_SUCCESS; 60 316 } … … 63 319 void vboxglDrvCreateContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) 64 320 { 65 OGL_CMD(DrvCreateContext, 4); 66 OGL_PARAM(HDC, hdc); 67 OGL_PARAM(uint32_t, cx); 68 OGL_PARAM(uint32_t, cy); 69 OGL_PARAM(BYTE, cColorBits); 70 OGL_PARAM(BYTE, iPixelType); 71 OGL_PARAM(BYTE, cDepthBits); 72 73 pClient->lastretval = 0; /** @todo */ 321 XSetWindowAttributes attr; 322 XVisualInfo *visinfo = NULL; 323 unsigned long mask; 324 //GLXContext ctx; 325 GLXFBConfig fbConfig; 326 GLXContextID glrc; 327 int screen_num; 328 XEvent event; 329 OGL_CMD(DrvCreateContext, 1); 330 OGL_PARAM(HDC, hdc); 331 332 Log(("DrvCreateContext %x\n", hdc)); 333 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT 334 335 screen_num = DefaultScreen(pClient->dpy); 336 fbConfig = pClient->actFBConfig; 337 338 #if 0 339 if (!fbConfig) { 340 /* Create a standard fbconfig */ 341 int returnedNumFBConfigs; 342 GLXFBConfig *returnedFBConfigs; 343 static int attribs[] = { 344 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 345 GLX_RENDER_TYPE, GLX_RGBA_BIT, 346 GLX_DOUBLEBUFFER, True, /* Request a double-buffered color buffer with */ 347 GLX_RED_SIZE, 1, /* the maximum number of bits per component */ 348 GLX_GREEN_SIZE, 1, 349 GLX_BLUE_SIZE, 1, 350 None 351 }; 352 353 Log(("Warning: no GLXFBConfig set creating standard one\n")); 354 returnedFBConfigs = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedNumFBConfigs); 355 if (!returnedNumFBConfigs) { 356 pClient->lastretval = 0; 357 pClient->fHasLastError = true; 358 pClient->ulLastError = glGetError(); 359 return; 360 } 361 fbConfig = returnedFBConfigs[0]; 362 } 363 #endif 364 365 visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, fbConfig); 366 367 if (pClient->xWindow == 0) { 368 369 /* window attributes */ 370 attr.background_pixel = 0; 371 attr.border_pixel = 0; 372 attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num ), visinfo->visual, AllocNone); 373 attr.event_mask = StructureNotifyMask | ExposureMask; 374 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; 375 pClient->xWindow = XCreateWindow(pClient->dpy, 376 RootWindow(pClient->dpy, screen_num), 377 0, 0, pClient->winWidth, pClient->winHeight, 0, 378 visinfo->depth, InputOutput, 379 visinfo->visual, mask, &attr); 380 } 381 XResizeWindow(pClient->dpy, pClient->xWindow, pClient->winWidth, pClient->winHeight); 382 pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, True); 383 384 XMapWindow(pClient->dpy, pClient->xWindow); 385 XIfEvent(pClient->dpy, &event, WaitForNotify, (XPointer)pClient->xWindow ); 386 //glrc = pClient->getContextIDPtr(ctx); 387 glrc = 1; 388 Assert(glrc); 389 #else 390 AssertFailed(); 391 glrc = 0; 392 #endif 393 394 pClient->lastretval = (uint64_t)glrc; 395 pClient->fHasLastError = true; 396 pClient->ulLastError = glGetError(); 74 397 } 75 398 76 399 void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) 77 400 { 401 //GLXContext ctx; 78 402 OGL_CMD(DrvDeleteContext, 1); 79 403 OGL_PARAM(HGLRC, hglrc); 80 /** @todo */ 81 pClient->lastretval = 0; /** @todo */ 404 Log(("DrvDeleteContext %x\n", hglrc)); 405 //ctx = pClient->importContextEXTPtr(pClient->dpy, hglrc); 406 glXDestroyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc)); 407 pClient->lastretval = 1; 408 pClient->fHasLastError = true; 409 pClient->ulLastError = glGetError(); 82 410 } 83 411 84 412 void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) 85 413 { 414 //GLXContext ctx; 86 415 OGL_CMD(DrvSetContext, 2); 87 416 OGL_PARAM(HDC, hdc); 88 417 OGL_PARAM(HGLRC, hglrc); 89 90 pClient->lastretval = 0; /** @todo */ 418 Log(("DrvSetContext %x %x\n", hdc, hglrc)); 419 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT 420 //ctx = pClient->importContextEXTPtr(pClient->dpy, hglrc); 421 pClient->lastretval = glXMakeCurrent(pClient->dpy, pClient->xWindow, 422 VBOX_OGL_GUEST_TO_HOST_HDC(hglrc)); 423 if (!pClient->lastretval) 424 Log(("glXMakeCurrent failed\n")); 425 pClient->fHasLastError = true; 426 pClient->ulLastError = glGetError(); 427 #else 428 AssertFailed(); 429 #endif 91 430 } 92 431 93 432 void vboxglDrvCopyContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) 94 433 { 434 //GLXContext ctxSrc, ctxDst; 95 435 OGL_CMD(DrvDeleteContext, 3); 96 436 OGL_PARAM(HGLRC, hglrcSrc); 97 437 OGL_PARAM(HGLRC, hglrcDst); 98 438 OGL_PARAM(UINT, mask); 99 pClient->lastretval = 0; /** @todo */ 439 Log(("DrvCopyContext %x %x %x\n", hglrcSrc, hglrcDst, mask)); 440 //ctxSrc = pClient->importContextEXTPtr(pClient->dpy, hglrcSrc); 441 //ctxDst = pClient->importContextEXTPtr(pClient->dpy, hglrcDst); 442 glXCopyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), mask); 443 pClient->lastretval = 1; 444 pClient->fHasLastError = true; 445 pClient->ulLastError = glGetError(); 100 446 } 101 447 … … 104 450 OGL_CMD(DrvReleaseContext, 1); 105 451 OGL_PARAM(HGLRC, hglrc); 452 Log(("DrvReleaseContext %x\n", hglrc)); 453 /* clear current selection */ 454 pClient->lastretval = glXMakeCurrent(pClient->dpy, 0, NULL); 455 456 if (!pClient->lastretval) 457 Log(("glXMakeCurrent failed\n")); 458 pClient->fHasLastError = true; 459 pClient->ulLastError = glGetError(); 460 } 461 462 void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) 463 { 464 OGL_CMD(DrvCreateLayerContext, 2); 465 OGL_PARAM(HDC, hdc); 466 OGL_PARAM(int, iLayerPlane); 467 468 Log(("DrvCreateLayerContext %x\n", hdc)); 469 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT 106 470 pClient->lastretval = 0; /** @todo */ 107 } 108 109 void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) 110 { 111 OGL_CMD(DrvCreateLayerContext, 5); 112 OGL_PARAM(HDC, hdc); 113 OGL_PARAM(int, iLayerPlane); 114 OGL_PARAM(uint32_t, cx); 115 OGL_PARAM(uint32_t, cy); 116 OGL_PARAM(BYTE, cColorBits); 117 OGL_PARAM(BYTE, iPixelType); 118 OGL_PARAM(BYTE, cDepthBits); 471 pClient->fHasLastError = true; 472 pClient->ulLastError = glGetError(); 473 #else 119 474 AssertFailed(); 120 /** @todo create memory dc with the parameters above */ 121 pClient->lastretval = 0; /** @todo */ 475 #endif 122 476 } 123 477 … … 128 482 OGL_PARAM(HGLRC, hglrc2); 129 483 pClient->lastretval = 0; /** @todo */ 484 pClient->fHasLastError = true; 485 pClient->ulLastError = glGetError(); 130 486 } 131 487 … … 138 494 OGL_PARAM(BOOL, bRealize); 139 495 pClient->lastretval = 0; /** @todo */ 496 pClient->fHasLastError = true; 497 pClient->ulLastError = glGetError(); 140 498 } 141 499 … … 146 504 OGL_PARAM(UINT, fuPlanes); 147 505 pClient->lastretval = 0; /** @todo */ 506 pClient->fHasLastError = true; 507 pClient->ulLastError = glGetError(); 148 508 } 149 509 150 510 void vboxglDrvSetPixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) 151 511 { 152 OGL_CMD(DrvSetPixelFormat, 2); 512 int screen_num; 513 OGL_CMD(DrvSetPixelFormat, 4); 153 514 OGL_PARAM(HDC, hdc); 154 515 OGL_PARAM(int, iPixelFormat); 155 156 pClient->lastretval = 0; /** @todo */ 516 OGL_PARAM(uint32_t, cx); 517 OGL_PARAM(uint32_t, cy); 518 519 Log(("vboxDrvSetPixelFormat %d\n", iPixelFormat)); 520 521 /* Get GLXFBConfig based on the given ID */ 522 pClient->actFBConfig = pClient->PixelFormatToFBConfigMapper[iPixelFormat-1]; 523 screen_num = DefaultScreen(pClient->dpy); 524 PrintFBConfigInfo(pClient->dpy, screen_num, pClient->actFBConfig); 525 Log(("Window width: %d Window height: %d\n", cx, cy)); 526 pClient->winWidth = cx; 527 pClient->winHeight = cy; 528 pClient->lastretval = true; 529 pClient->fHasLastError = true; 530 pClient->ulLastError = glGetError(); 157 531 } 158 532 … … 162 536 OGL_PARAM(HDC, hdc); 163 537 164 pClient->lastretval = 0; /** @todo */ 538 glXSwapBuffers(pClient->dpy, pClient->xWindow); 539 pClient->lastretval = 1; 540 pClient->fHasLastError = true; 541 pClient->ulLastError = glGetError(); 165 542 } 166 543 … … 178 555 179 556 pClient->lastretval = 0; /** @todo */ 557 pClient->fHasLastError = true; 558 pClient->ulLastError = glGetError(); 180 559 } 181 560 … … 189 568 OGL_MEMPARAM(COLORREF, pcr); 190 569 pClient->lastretval = 0; /** @todo */ 570 pClient->fHasLastError = true; 571 pClient->ulLastError = glGetError(); 191 572 } 192 573 … … 204 585 pcr = (COLORREF *)pClient->pLastParam; 205 586 pClient->lastretval = 0; /** @todo */ 587 pClient->fHasLastError = true; 588 pClient->ulLastError = glGetError(); 206 589 } 207 590 … … 209 592 { 210 593 LPPIXELFORMATDESCRIPTOR ppfd; 594 GLXFBConfig *allFBConfigs, matchingFBConfig; 595 int screenNum, glxReturnValue; 211 596 212 597 OGL_CMD(DrvDescribePixelFormat, 3); … … 217 602 ppfd = (LPPIXELFORMATDESCRIPTOR)pClient->pLastParam; 218 603 219 pClient->lastretval = 0; /** @todo */ 604 Log(("iPixelFormat: %d\n", iPixelFormat)); 605 606 if (!pClient->PixelFormatToFBConfigMapper) { 607 /* First get number of all visuals for the return value */ 608 screenNum = DefaultScreen(pClient->dpy); 609 allFBConfigs = glXGetFBConfigs(pClient->dpy, screenNum, 610 &pClient->numFBConfigs); 611 pClient->PixelFormatToFBConfigMapper = allFBConfigs; 612 } 613 614 if (nBytes == sizeof(PIXELFORMATDESCRIPTOR)) { 615 int redSize, greenSize, blueSize, alphaSize, xVisual, xRenderable; 616 /* Get GLXFBConfig which matches iPixelFormat */ 617 matchingFBConfig = pClient->PixelFormatToFBConfigMapper[iPixelFormat-1]; 618 619 Log(("Filling values into PIXELFORMATDESCRIPTOR\n")); 620 /* translate all values to theire corresponding Windows ones */ 621 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR); 622 ppfd->nVersion = 1; 623 ppfd->iLayerType = PFD_MAIN_PLANE; 624 ppfd->dwFlags = 0; 625 626 /* Set cColorBits */ 627 glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_RED_SIZE, &redSize); 628 glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_GREEN_SIZE, &greenSize); 629 glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_BLUE_SIZE, &blueSize); 630 glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_ALPHA_SIZE, &alphaSize); 631 ppfd->cColorBits = redSize + greenSize + blueSize; 632 ppfd->cRedBits = redSize; 633 ppfd->cBlueBits = blueSize; 634 ppfd->cGreenBits = greenSize; 635 ppfd->cAlphaBits = alphaSize; 636 637 /* Set dwFlags */ 638 if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DRAWABLE_TYPE, &glxReturnValue)) { 639 glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_VISUAL_ID, &xVisual); 640 glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_X_RENDERABLE, &xRenderable); 641 if ((glxReturnValue & GLX_WINDOW_BIT) && xVisual) 642 ppfd->dwFlags |= (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL); 643 } 644 if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DOUBLEBUFFER, &glxReturnValue)) { 645 if (glxReturnValue) 646 ppfd->dwFlags |= PFD_DOUBLEBUFFER; 647 } 648 /* Set iPixelType */ 649 if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_RENDER_TYPE, &glxReturnValue)) { 650 if (glxReturnValue & GLX_RGBA_BIT) 651 ppfd->iPixelType = PFD_TYPE_RGBA; 652 else if ((glxReturnValue & GLX_COLOR_INDEX_BIT) & !(glxReturnValue & GLX_RGBA_BIT)) 653 ppfd->iPixelType = PFD_TYPE_COLORINDEX; 654 } 655 /* Set cDepthBits */ 656 if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DEPTH_SIZE, &glxReturnValue)) { 657 ppfd->cDepthBits = glxReturnValue; 658 } else { 659 ppfd->cDepthBits = 0; 660 } 661 /* Set cStencilBits */ 662 if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_STENCIL_SIZE, &glxReturnValue)) { 663 ppfd->cStencilBits = glxReturnValue; 664 } else { 665 ppfd->cStencilBits = 0; 666 } 667 /** @todo Fill in the rest */ 668 } 669 670 pClient->lastretval = pClient->numFBConfigs; 671 pClient->fHasLastError = true; 672 pClient->ulLastError = glGetError(); 220 673 } 221 674 222 675 RTUINTPTR vboxDrvIsExtensionAvailable(char *pszExtFunctionName) 223 676 { 224 return 0; 225 } 226 677 RTUINTPTR pfnProc = (RTUINTPTR)glXGetProcAddress((const GLubyte *)pszExtFunctionName); 678 Log(("vboxDrvIsExtensionAvailable %s -> %d\n", pszExtFunctionName, !!pfnProc)); 679 return pfnProc; 680 } 681 -
trunk/src/VBox/HostServices/SharedOpenGL/glwindrv.cpp
r3698 r3708 105 105 PIXELFORMATDESCRIPTOR pfd; 106 106 int iFormat; 107 /** @todo should NOT use the desktop window -> crashes the Intel OpenGL driver */ 107 108 HDC hdc = GetDC(0); 108 109 … … 131 132 132 133 /** 134 * Enable OpenGL 135 * 136 * @returns VBox error code 137 * @param pClient Client context 138 */ 139 int vboxglEnableOpenGL(PVBOXOGLCTX pClient) 140 { 141 PIXELFORMATDESCRIPTOR pfd; 142 int iFormat; 143 144 /** @todo should NOT use the desktop window -> crashes the Intel OpenGL driver */ 145 pClient->enable.hdc = GetDC(0); 146 147 ZeroMemory(&pfd, sizeof(pfd)); 148 pfd.nSize = sizeof(pfd); 149 pfd.nVersion = 1; 150 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 151 pfd.iPixelType = PFD_TYPE_RGBA; 152 pfd.cColorBits = 24; 153 pfd.cDepthBits = 16; 154 pfd.iLayerType = PFD_MAIN_PLANE; 155 iFormat = ChoosePixelFormat(pClient->enable.hdc, &pfd); 156 SetPixelFormat(pClient->enable.hdc, iFormat, &pfd); 157 158 pClient->enable.hglrc = wglCreateContext(pClient->enable.hdc); 159 wglMakeCurrent(pClient->enable.hdc, pClient->enable.hglrc); 160 return VINF_SUCCESS; 161 } 162 163 164 /** 165 * Disable OpenGL 166 * 167 * @returns VBox error code 168 * @param pClient Client context 169 */ 170 int vboxglDisableOpenGL(PVBOXOGLCTX pClient) 171 { 172 wglMakeCurrent(NULL, NULL); 173 wglDeleteContext(pClient->enable.hglrc); 174 ReleaseDC(0, pClient->enable.hdc); 175 return VINF_SUCCESS; 176 } 177 178 /** 133 179 * Client connect init 134 180 * -
trunk/src/VBox/HostServices/SharedOpenGL/service.cpp
r3468 r3708 287 287 else 288 288 { 289 #ifdef __WIN__ 289 290 /* Execute the function. */ 290 291 if (vboxwglGetProcAddress(pszExtFnName)) … … 292 293 else 293 294 rc = VERR_FILE_NOT_FOUND; 294 295 #else 296 rc = VERR_FILE_NOT_FOUND; 297 #endif 295 298 if (VBOX_SUCCESS(rc)) 296 299 { -
trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.cpp
r3698 r3708 31 31 #include <VBox/log.h> 32 32 33 34 35 33 /** 36 34 * glGetString implementation … … 48 46 int rc = VINF_SUCCESS; 49 47 50 #ifdef RT_OS_WINDOWS 51 PIXELFORMATDESCRIPTOR pfd; 52 int iFormat; 53 HDC hdc = GetDC(0); 54 55 ZeroMemory(&pfd, sizeof(pfd)); 56 pfd.nSize = sizeof(pfd); 57 pfd.nVersion = 1; 58 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 59 pfd.iPixelType = PFD_TYPE_RGBA; 60 pfd.cColorBits = 24; 61 pfd.cDepthBits = 16; 62 pfd.iLayerType = PFD_MAIN_PLANE; 63 iFormat = ChoosePixelFormat(hdc, &pfd); 64 SetPixelFormat(hdc, iFormat, &pfd); 65 66 HGLRC hRC = wglCreateContext(hdc); 67 wglMakeCurrent(hdc, hRC); 68 #endif 48 vboxglEnableOpenGL(pClient); 69 49 70 50 pName = glGetString(name); … … 87 67 end: 88 68 89 #ifdef RT_OS_WINDOWS 90 wglMakeCurrent(NULL, NULL); 91 wglDeleteContext(hRC); 92 ReleaseDC(0, hdc); 93 #endif 69 vboxglDisableOpenGL(pClient); 94 70 return rc; 95 71 } -
trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.h
r3698 r3708 93 93 * @param pszFunctionName OpenGL extension function name 94 94 */ 95 #ifdef RT_OS_WINDOWS 95 96 bool vboxwglGetProcAddress(char *pszFunctionName); 96 97 #endif 97 98 98 99 /* OpenGL wrappers */ … … 352 353 void vboxglGetTexImage (VBOXOGLCTX *pClient, uint8_t *pCmdBuffer); 353 354 355 #ifdef RT_OS_WINDOWS 354 356 void vboxwglSwapIntervalEXT (VBOXOGLCTX *pClient, uint8_t *pCmdBuffer); 355 357 void vboxwglGetSwapIntervalEXT (VBOXOGLCTX *pClient, uint8_t *pCmdBuffer); 358 #endif 356 359 357 360 /* after the above */
Note:
See TracChangeset
for help on using the changeset viewer.