1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox OpenGL
|
---|
4 | *
|
---|
5 | * Simple buffered OpenGL functions
|
---|
6 | *
|
---|
7 | * Contributor: Alexander Eichner
|
---|
8 | */
|
---|
9 |
|
---|
10 | /*
|
---|
11 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
12 | *
|
---|
13 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
14 | * available from http://www.virtualbox.org. This file is free software;
|
---|
15 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
16 | * General Public License as published by the Free Software Foundation,
|
---|
17 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
18 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
19 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
20 | */
|
---|
21 | #define GLX_GLXEXT_PROTOTYPES
|
---|
22 |
|
---|
23 | #include "vboxgl.h"
|
---|
24 | #define LOG_GROUP LOG_GROUP_SHARED_OPENGL
|
---|
25 | #include <VBox/log.h>
|
---|
26 | #include <string.h>
|
---|
27 | #include <stdio.h>
|
---|
28 | #include <GL/gl.h>
|
---|
29 | #include <GL/glx.h>
|
---|
30 | #include <GL/glxext.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | /* X11 server connection for all OpenGL clients.
|
---|
34 | * Neccessary because Mesa and DRI cannot handle more than one
|
---|
35 | * connection per thread (only hardware acceleration, software rendering
|
---|
36 | * runs fine with more than one connection).
|
---|
37 | * Would crash in vboxglDisconnect if on every vboxglConnect
|
---|
38 | * a new Display is created */
|
---|
39 | Display *glXDisplay = NULL;
|
---|
40 |
|
---|
41 | static Bool WaitForNotify( Display *dpy, XEvent *event, XPointer arg ) {
|
---|
42 | return (event->type == MapNotify) && (event->xmap.window == (Window) arg);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /* from http://www.mesa3d.org/brianp/sig97/exten.htm */
|
---|
46 | GLboolean vboxglCheckExtension(Display *dpy, int screenNum, const char *extName )
|
---|
47 | {
|
---|
48 | /*
|
---|
49 | ** Search for extName in the extensions string. Use of strstr()
|
---|
50 | ** is not sufficient because extension names can be prefixes of
|
---|
51 | ** other extension names. Could use strtok() but the constant
|
---|
52 | ** string returned by glGetString can be in read-only memory.
|
---|
53 | */
|
---|
54 | char *p = (char *) glXQueryExtensionsString(dpy, screenNum);
|
---|
55 | char *end;
|
---|
56 | int extNameLen;
|
---|
57 |
|
---|
58 | extNameLen = strlen(extName);
|
---|
59 | end = p + strlen(p);
|
---|
60 |
|
---|
61 | while (p < end) {
|
---|
62 | int n = strcspn(p, " ");
|
---|
63 | if ((extNameLen == n) && (strncmp(extName, p, n) == 0)) {
|
---|
64 | return GL_TRUE;
|
---|
65 | }
|
---|
66 | p += (n + 1);
|
---|
67 | }
|
---|
68 | return GL_FALSE;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Global init of VBox OpenGL
|
---|
73 | *
|
---|
74 | * @returns VBox error code
|
---|
75 | */
|
---|
76 | int vboxglGlobalInit()
|
---|
77 | {
|
---|
78 | Log(("vboxglGlobalInit\n"));
|
---|
79 |
|
---|
80 | /*vboxInitOpenGLExtensions();*/
|
---|
81 | return VINF_SUCCESS;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Global deinit of VBox OpenGL
|
---|
86 | *
|
---|
87 | * @returns VBox error code
|
---|
88 | */
|
---|
89 | int vboxglGlobalUnload()
|
---|
90 | {
|
---|
91 | Log(("vboxglGlobalUnload"));
|
---|
92 |
|
---|
93 | if (glXDisplay)
|
---|
94 | XCloseDisplay(glXDisplay);
|
---|
95 |
|
---|
96 | return VINF_SUCCESS;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Enable OpenGL
|
---|
101 | *
|
---|
102 | * @returns VBox error code
|
---|
103 | * @param pClient Client context
|
---|
104 | */
|
---|
105 | int vboxglEnableOpenGL(PVBOXOGLCTX pClient)
|
---|
106 | {
|
---|
107 | static int attribs[] = {
|
---|
108 | GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
---|
109 | GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
---|
110 | GLX_DOUBLEBUFFER, GL_TRUE, /* Request a double-buffered color buffer with */
|
---|
111 | GLX_RED_SIZE, 1, /* the maximum number of bits per component */
|
---|
112 | GLX_GREEN_SIZE, 1,
|
---|
113 | GLX_BLUE_SIZE, 1,
|
---|
114 | None
|
---|
115 | };
|
---|
116 | int screen_num;
|
---|
117 | XSetWindowAttributes attr;
|
---|
118 | unsigned long mask;
|
---|
119 | int returnedFBConfigs;
|
---|
120 |
|
---|
121 | /* we have to set up a rendering context to be able to use glGetString
|
---|
122 | * a window is created but is not mapped to screen (so it's not visible')
|
---|
123 | * and a GLXContext is bound to it */
|
---|
124 | screen_num = DefaultScreen(pClient->dpy);
|
---|
125 | pClient->enable.fbConfig = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedFBConfigs);
|
---|
126 | Log(("vboxglGetString: returned FBConfigs: %d\n", returnedFBConfigs));
|
---|
127 | pClient->enable.visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, pClient->enable.fbConfig[0]);
|
---|
128 | /* Create Window */
|
---|
129 | attr.background_pixel = 0;
|
---|
130 | attr.border_pixel = 0;
|
---|
131 | attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num), pClient->enable.visinfo->visual, AllocNone);
|
---|
132 | attr.event_mask = StructureNotifyMask | ExposureMask;
|
---|
133 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
---|
134 | pClient->enable.win = XCreateWindow(pClient->dpy, RootWindow(pClient->dpy, screen_num), 0, 0, 100, 100,
|
---|
135 | 0, pClient->enable.visinfo->depth, InputOutput,
|
---|
136 | pClient->enable.visinfo->visual, mask, &attr);
|
---|
137 | /* Create Context */
|
---|
138 | pClient->enable.ctx = pClient->glxCreateNewContext(pClient->dpy, pClient->enable.fbConfig[0], GLX_RGBA_TYPE, NULL, GL_TRUE);
|
---|
139 | glXMakeCurrent(pClient->dpy, pClient->enable.win, pClient->enable.ctx);
|
---|
140 |
|
---|
141 | return VINF_SUCCESS;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Disable OpenGL
|
---|
146 | *
|
---|
147 | * @returns VBox error code
|
---|
148 | * @param pClient Client context
|
---|
149 | */
|
---|
150 | int vboxglDisableOpenGL(PVBOXOGLCTX pClient)
|
---|
151 | {
|
---|
152 | /* Free all data */
|
---|
153 | if (pClient->enable.ctx)
|
---|
154 | {
|
---|
155 | glFlush();
|
---|
156 | glXMakeCurrent(pClient->dpy, None, NULL);
|
---|
157 | XDestroyWindow(pClient->dpy, pClient->enable.win);
|
---|
158 | glXDestroyContext(pClient->dpy, pClient->enable.ctx);
|
---|
159 | XFree(pClient->enable.visinfo);
|
---|
160 | XFree(pClient->enable.fbConfig);
|
---|
161 | }
|
---|
162 |
|
---|
163 | return VINF_SUCCESS;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Client connect init
|
---|
168 | *
|
---|
169 | * @returns VBox error code
|
---|
170 | * @param pClient Client context
|
---|
171 | */
|
---|
172 | int vboxglConnect(PVBOXOGLCTX pClient)
|
---|
173 | {
|
---|
174 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
175 | Log(("vboxglConnect\n"));
|
---|
176 |
|
---|
177 | pClient->PixelFormatToFBConfigMapper = NULL;
|
---|
178 | pClient->xWindow = 0;
|
---|
179 |
|
---|
180 | if (!glXDisplay)
|
---|
181 | glXDisplay = XOpenDisplay(NULL);
|
---|
182 |
|
---|
183 | pClient->dpy = glXDisplay;
|
---|
184 |
|
---|
185 | if (pClient->dpy) {
|
---|
186 | int screenNum, major, minor;
|
---|
187 |
|
---|
188 | screenNum = DefaultScreen(pClient->dpy);
|
---|
189 | glXQueryVersion(pClient->dpy, &major, &minor);
|
---|
190 |
|
---|
191 | if ((major == 1) && (minor >= 3)) {
|
---|
192 | Log(("Server GLX 1.3 supported\n"));
|
---|
193 | pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddressARB(
|
---|
194 | (GLubyte *) "glXChooseFBConfig");
|
---|
195 | pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddressARB(
|
---|
196 | (GLubyte *) "glXGetVisualFromFBConfig");
|
---|
197 | pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddressARB(
|
---|
198 | (GLubyte *) "glXCreateNewContext");
|
---|
199 | } else if (vboxglCheckExtension(pClient->dpy, screenNum, "GLX_SGIX_fbconfig")) {
|
---|
200 | Log(("GLX_SGIX_fbconfig extension supported\n"));
|
---|
201 | pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddressARB(
|
---|
202 | (GLubyte *) "glXChooseFBConfigSGIX");
|
---|
203 | pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddressARB(
|
---|
204 | (GLubyte *) "glXGetVisualFromFBConfigSGIX");
|
---|
205 | pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddressARB(
|
---|
206 | (GLubyte *) "glXCreateContextWithConfigSGIX");
|
---|
207 | } else {
|
---|
208 | Log(("Error no FBConfig supported\n"));
|
---|
209 | rc = VERR_NOT_IMPLEMENTED;
|
---|
210 | }
|
---|
211 | if (pClient->glxChooseFBConfig && pClient->glxGetVisualFromFBConfig && pClient->glxCreateNewContext)
|
---|
212 | rc = VINF_SUCCESS;
|
---|
213 | }
|
---|
214 |
|
---|
215 | return rc;
|
---|
216 | }
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * Client disconnect cleanup
|
---|
220 | *
|
---|
221 | * @returns VBox error code
|
---|
222 | * @param pClient Client context
|
---|
223 | */
|
---|
224 | int vboxglDisconnect(PVBOXOGLCTX pClient)
|
---|
225 | {
|
---|
226 | Log(("vboxglDisconnect\n"));
|
---|
227 |
|
---|
228 | #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
|
---|
229 | if (pClient->xWindow != 0) {
|
---|
230 | XUnmapWindow(pClient->dpy, pClient->xWindow);
|
---|
231 | XDestroyWindow(pClient->dpy, pClient->xWindow);
|
---|
232 | }
|
---|
233 | if (pClient->PixelFormatToFBConfigMapper) {
|
---|
234 | XFree(pClient->PixelFormatToFBConfigMapper);
|
---|
235 | }
|
---|
236 |
|
---|
237 | pClient->dpy = NULL;
|
---|
238 | pClient->xWindow = 0;
|
---|
239 | pClient->actFBConfig = NULL;
|
---|
240 | #endif
|
---|
241 | return VINF_SUCCESS;
|
---|
242 | }
|
---|
243 |
|
---|
244 | /* Driver functions */
|
---|
245 | void vboxglDrvCreateContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
246 | {
|
---|
247 | XSetWindowAttributes attr;
|
---|
248 | XVisualInfo *visinfo = NULL;
|
---|
249 | unsigned long mask;
|
---|
250 | GLXFBConfig fbConfig;
|
---|
251 | GLXContextID glrc;
|
---|
252 | int screen_num;
|
---|
253 | XEvent event;
|
---|
254 | OGL_CMD(DrvCreateContext, 1);
|
---|
255 | OGL_PARAM(HDC, hdc);
|
---|
256 |
|
---|
257 | Log(("DrvCreateContext %x\n", hdc));
|
---|
258 | #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
|
---|
259 |
|
---|
260 | screen_num = DefaultScreen(pClient->dpy);
|
---|
261 | fbConfig = pClient->actFBConfig;
|
---|
262 |
|
---|
263 | visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, fbConfig);
|
---|
264 |
|
---|
265 | if (pClient->xWindow == 0) {
|
---|
266 |
|
---|
267 | /* window attributes */
|
---|
268 | attr.background_pixel = 0;
|
---|
269 | attr.border_pixel = 0;
|
---|
270 | attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num ), visinfo->visual, AllocNone);
|
---|
271 | attr.event_mask = StructureNotifyMask | ExposureMask;
|
---|
272 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
---|
273 | pClient->xWindow = XCreateWindow(pClient->dpy,
|
---|
274 | RootWindow(pClient->dpy, screen_num),
|
---|
275 | 0, 0, pClient->winWidth, pClient->winHeight, 0,
|
---|
276 | visinfo->depth, InputOutput,
|
---|
277 | visinfo->visual, mask, &attr);
|
---|
278 | }
|
---|
279 | XResizeWindow(pClient->dpy, pClient->xWindow, pClient->winWidth, pClient->winHeight);
|
---|
280 | pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
|
---|
281 |
|
---|
282 | XMapWindow(pClient->dpy, pClient->xWindow);
|
---|
283 | XIfEvent(pClient->dpy, &event, WaitForNotify, (XPointer)pClient->xWindow );
|
---|
284 |
|
---|
285 | glrc = 1;
|
---|
286 | Assert(glrc);
|
---|
287 | #else
|
---|
288 | AssertFailed();
|
---|
289 | glrc = 0;
|
---|
290 | #endif
|
---|
291 |
|
---|
292 | pClient->lastretval = (uint64_t)glrc;
|
---|
293 | pClient->fHasLastError = true;
|
---|
294 | pClient->ulLastError = glGetError();
|
---|
295 | }
|
---|
296 |
|
---|
297 | void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
298 | {
|
---|
299 | OGL_CMD(DrvDeleteContext, 1);
|
---|
300 | OGL_PARAM(HGLRC, hglrc);
|
---|
301 | Log(("DrvDeleteContext %x\n", hglrc));
|
---|
302 |
|
---|
303 | glXDestroyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc));
|
---|
304 | pClient->lastretval = 1;
|
---|
305 | pClient->fHasLastError = true;
|
---|
306 | pClient->ulLastError = glGetError();
|
---|
307 | }
|
---|
308 |
|
---|
309 | void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
310 | {
|
---|
311 | OGL_CMD(DrvSetContext, 2);
|
---|
312 | OGL_PARAM(HDC, hdc);
|
---|
313 | OGL_PARAM(HGLRC, hglrc);
|
---|
314 | Log(("DrvSetContext %x %x\n", hdc, hglrc));
|
---|
315 | #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
|
---|
316 |
|
---|
317 | pClient->lastretval = glXMakeCurrent(pClient->dpy, pClient->xWindow,
|
---|
318 | VBOX_OGL_GUEST_TO_HOST_HDC(hglrc));
|
---|
319 | if (!pClient->lastretval)
|
---|
320 | Log(("glXMakeCurrent failed\n"));
|
---|
321 | pClient->fHasLastError = true;
|
---|
322 | pClient->ulLastError = glGetError();
|
---|
323 | #else
|
---|
324 | AssertFailed();
|
---|
325 | #endif
|
---|
326 | }
|
---|
327 |
|
---|
328 | void vboxglDrvCopyContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
329 | {
|
---|
330 | OGL_CMD(DrvDeleteContext, 3);
|
---|
331 | OGL_PARAM(HGLRC, hglrcSrc);
|
---|
332 | OGL_PARAM(HGLRC, hglrcDst);
|
---|
333 | OGL_PARAM(UINT, mask);
|
---|
334 | Log(("DrvCopyContext %x %x %x\n", hglrcSrc, hglrcDst, mask));
|
---|
335 |
|
---|
336 | glXCopyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), mask);
|
---|
337 | pClient->lastretval = 1;
|
---|
338 | pClient->fHasLastError = true;
|
---|
339 | pClient->ulLastError = glGetError();
|
---|
340 | }
|
---|
341 |
|
---|
342 | void vboxglDrvReleaseContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
343 | {
|
---|
344 | OGL_CMD(DrvReleaseContext, 1);
|
---|
345 | OGL_PARAM(HGLRC, hglrc);
|
---|
346 | Log(("DrvReleaseContext %x\n", hglrc));
|
---|
347 | /* clear current selection */
|
---|
348 | pClient->lastretval = glXMakeCurrent(pClient->dpy, None, NULL);
|
---|
349 |
|
---|
350 | if (!pClient->lastretval)
|
---|
351 | Log(("glXMakeCurrent failed\n"));
|
---|
352 | pClient->fHasLastError = true;
|
---|
353 | pClient->ulLastError = glGetError();
|
---|
354 | }
|
---|
355 |
|
---|
356 | void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
357 | {
|
---|
358 | XSetWindowAttributes attr;
|
---|
359 | XVisualInfo *visinfo = NULL;
|
---|
360 | unsigned long mask;
|
---|
361 | GLXFBConfig fbConfig;
|
---|
362 | GLXContextID glrc;
|
---|
363 | int screen_num;
|
---|
364 | XEvent event;
|
---|
365 | OGL_CMD(DrvCreateLayerContext, 2);
|
---|
366 | OGL_PARAM(HDC, hdc);
|
---|
367 | OGL_PARAM(int, iLayerPlane);
|
---|
368 |
|
---|
369 | Log(("DrvCreateLayerContext %x\n", hdc));
|
---|
370 | #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
|
---|
371 |
|
---|
372 | screen_num = DefaultScreen(pClient->dpy);
|
---|
373 | fbConfig = pClient->actFBConfig;
|
---|
374 | visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, fbConfig);
|
---|
375 |
|
---|
376 | if (pClient->xWindow == 0) {
|
---|
377 |
|
---|
378 | /* window attributes */
|
---|
379 | attr.background_pixel = 0;
|
---|
380 | attr.border_pixel = 0;
|
---|
381 | attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num ), visinfo->visual, AllocNone);
|
---|
382 | attr.event_mask = StructureNotifyMask | ExposureMask;
|
---|
383 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
---|
384 | pClient->xWindow = XCreateWindow(pClient->dpy,
|
---|
385 | RootWindow(pClient->dpy, screen_num),
|
---|
386 | 0, 0, pClient->winWidth, pClient->winHeight, 0,
|
---|
387 | visinfo->depth, InputOutput,
|
---|
388 | visinfo->visual, mask, &attr);
|
---|
389 | }
|
---|
390 | XResizeWindow(pClient->dpy, pClient->xWindow, pClient->winWidth, pClient->winHeight);
|
---|
391 | pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
|
---|
392 | XMapWindow(pClient->dpy, pClient->xWindow);
|
---|
393 | XIfEvent(pClient->dpy, &event, WaitForNotify, (XPointer)pClient->xWindow );
|
---|
394 |
|
---|
395 | glrc = 1;
|
---|
396 | Assert(glrc);
|
---|
397 |
|
---|
398 | pClient->lastretval = glrc;
|
---|
399 | pClient->fHasLastError = true;
|
---|
400 | pClient->ulLastError = glGetError();
|
---|
401 | #else
|
---|
402 | AssertFailed();
|
---|
403 | #endif
|
---|
404 | }
|
---|
405 |
|
---|
406 | void vboxglDrvShareLists(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
407 | {
|
---|
408 | OGL_CMD(DrvShareLists, 3);
|
---|
409 | OGL_PARAM(HGLRC, hglrc1);
|
---|
410 | OGL_PARAM(HGLRC, hglrc2);
|
---|
411 | pClient->lastretval = 0; /** @todo */
|
---|
412 | pClient->fHasLastError = true;
|
---|
413 | pClient->ulLastError = glGetError();
|
---|
414 | }
|
---|
415 |
|
---|
416 |
|
---|
417 | void vboxglDrvRealizeLayerPalette(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
418 | {
|
---|
419 | OGL_CMD(DrvRealizeLayerPalette, 3);
|
---|
420 | OGL_PARAM(HDC, hdc);
|
---|
421 | OGL_PARAM(int, iLayerPlane);
|
---|
422 | OGL_PARAM(BOOL, bRealize);
|
---|
423 | pClient->lastretval = 0; /** @todo */
|
---|
424 | pClient->fHasLastError = true;
|
---|
425 | pClient->ulLastError = glGetError();
|
---|
426 | }
|
---|
427 |
|
---|
428 | void vboxglDrvSwapLayerBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
429 | {
|
---|
430 | OGL_CMD(DrvSwapLayerBuffers, 2);
|
---|
431 | OGL_PARAM(HDC, hdc);
|
---|
432 | OGL_PARAM(UINT, fuPlanes);
|
---|
433 | pClient->lastretval = 0; /** @todo */
|
---|
434 | pClient->fHasLastError = true;
|
---|
435 | pClient->ulLastError = glGetError();
|
---|
436 | }
|
---|
437 |
|
---|
438 | void vboxglDrvSetPixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
439 | {
|
---|
440 | int screen_num;
|
---|
441 | OGL_CMD(DrvSetPixelFormat, 4);
|
---|
442 | OGL_PARAM(HDC, hdc);
|
---|
443 | OGL_PARAM(int, iPixelFormat);
|
---|
444 | OGL_PARAM(uint32_t, cx);
|
---|
445 | OGL_PARAM(uint32_t, cy);
|
---|
446 |
|
---|
447 | Log(("vboxDrvSetPixelFormat %d\n", iPixelFormat));
|
---|
448 |
|
---|
449 | /* Get GLXFBConfig based on the given ID */
|
---|
450 | pClient->actFBConfig = pClient->PixelFormatToFBConfigMapper[iPixelFormat-1];
|
---|
451 | screen_num = DefaultScreen(pClient->dpy);
|
---|
452 |
|
---|
453 | pClient->winWidth = cx;
|
---|
454 | pClient->winHeight = cy;
|
---|
455 | pClient->lastretval = true;
|
---|
456 | pClient->fHasLastError = true;
|
---|
457 | pClient->ulLastError = glGetError();
|
---|
458 | }
|
---|
459 |
|
---|
460 | void vboxglDrvSwapBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
461 | {
|
---|
462 | OGL_CMD(DrvSwapBuffers, 1);
|
---|
463 | OGL_PARAM(HDC, hdc);
|
---|
464 |
|
---|
465 | glXSwapBuffers(pClient->dpy, pClient->xWindow);
|
---|
466 | pClient->lastretval = 1;
|
---|
467 | pClient->fHasLastError = true;
|
---|
468 | pClient->ulLastError = glGetError();
|
---|
469 | }
|
---|
470 |
|
---|
471 | void vboxglDrvDescribeLayerPlane(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
472 | {
|
---|
473 | PLAYERPLANEDESCRIPTOR plpd;
|
---|
474 |
|
---|
475 | OGL_CMD(DrvDescribeLayerPlane, 4);
|
---|
476 | OGL_PARAM(HDC, hdc);
|
---|
477 | OGL_PARAM(int, iPixelFormat);
|
---|
478 | OGL_PARAM(int, iLayerPlane);
|
---|
479 | OGL_PARAM(UINT, nBytes);
|
---|
480 | Assert(pClient->cbLastParam == nBytes);
|
---|
481 | plpd = (PLAYERPLANEDESCRIPTOR)pClient->pLastParam;
|
---|
482 |
|
---|
483 | pClient->lastretval = 0; /** @todo */
|
---|
484 | pClient->fHasLastError = true;
|
---|
485 | pClient->ulLastError = glGetError();
|
---|
486 | }
|
---|
487 |
|
---|
488 | void vboxglDrvSetLayerPaletteEntries(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
489 | {
|
---|
490 | OGL_CMD(DrvSetLayerPaletteEntries, 5);
|
---|
491 | OGL_PARAM(HDC, hdc);
|
---|
492 | OGL_PARAM(int, iLayerPlane);
|
---|
493 | OGL_PARAM(int, iStart);
|
---|
494 | OGL_PARAM(int, cEntries);
|
---|
495 | OGL_MEMPARAM(COLORREF, pcr);
|
---|
496 | pClient->lastretval = 0; /** @todo */
|
---|
497 | pClient->fHasLastError = true;
|
---|
498 | pClient->ulLastError = glGetError();
|
---|
499 | }
|
---|
500 |
|
---|
501 | void vboxglDrvGetLayerPaletteEntries(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
502 | {
|
---|
503 | COLORREF *pcr;
|
---|
504 |
|
---|
505 | OGL_CMD(DrvGetLayerPaletteEntries, 4);
|
---|
506 | OGL_PARAM(HDC, hdc);
|
---|
507 | OGL_PARAM(int, iLayerPlane);
|
---|
508 | OGL_PARAM(int, iStart);
|
---|
509 | OGL_PARAM(int, cEntries);
|
---|
510 |
|
---|
511 | Assert(pClient->cbLastParam == sizeof(COLORREF)*cEntries);
|
---|
512 | pcr = (COLORREF *)pClient->pLastParam;
|
---|
513 | pClient->lastretval = 0; /** @todo */
|
---|
514 | pClient->fHasLastError = true;
|
---|
515 | pClient->ulLastError = glGetError();
|
---|
516 | }
|
---|
517 |
|
---|
518 | void vboxglDrvDescribePixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
|
---|
519 | {
|
---|
520 | LPPIXELFORMATDESCRIPTOR ppfd;
|
---|
521 | GLXFBConfig *allFBConfigs, matchingFBConfig;
|
---|
522 | int screenNum, glxReturnValue;
|
---|
523 |
|
---|
524 | OGL_CMD(DrvDescribePixelFormat, 3);
|
---|
525 | OGL_PARAM(HDC, hdc);
|
---|
526 | OGL_PARAM(int, iPixelFormat);
|
---|
527 | OGL_PARAM(UINT, nBytes);
|
---|
528 | Assert(pClient->cbLastParam == nBytes);
|
---|
529 | ppfd = (LPPIXELFORMATDESCRIPTOR)pClient->pLastParam;
|
---|
530 |
|
---|
531 | Log(("iPixelFormat: %d\n", iPixelFormat));
|
---|
532 |
|
---|
533 | if (!pClient->PixelFormatToFBConfigMapper) {
|
---|
534 | /* First get number of all visuals for the return value */
|
---|
535 | screenNum = DefaultScreen(pClient->dpy);
|
---|
536 | allFBConfigs = glXGetFBConfigs(pClient->dpy, screenNum,
|
---|
537 | &pClient->numFBConfigs);
|
---|
538 | pClient->PixelFormatToFBConfigMapper = allFBConfigs;
|
---|
539 | }
|
---|
540 |
|
---|
541 | if (nBytes == sizeof(PIXELFORMATDESCRIPTOR)) {
|
---|
542 | int redSize, greenSize, blueSize, alphaSize, xVisual, xRenderable;
|
---|
543 | /* Get GLXFBConfig which matches iPixelFormat */
|
---|
544 | matchingFBConfig = pClient->PixelFormatToFBConfigMapper[iPixelFormat-1];
|
---|
545 |
|
---|
546 | Log(("Filling values into PIXELFORMATDESCRIPTOR\n"));
|
---|
547 | /* translate all values to theire corresponding Windows ones */
|
---|
548 | ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
---|
549 | ppfd->nVersion = 1;
|
---|
550 | ppfd->iLayerType = PFD_MAIN_PLANE;
|
---|
551 | ppfd->dwFlags = 0;
|
---|
552 |
|
---|
553 | /* Set cColorBits */
|
---|
554 | glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_RED_SIZE, &redSize);
|
---|
555 | glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_GREEN_SIZE, &greenSize);
|
---|
556 | glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_BLUE_SIZE, &blueSize);
|
---|
557 | glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_ALPHA_SIZE, &alphaSize);
|
---|
558 | ppfd->cColorBits = redSize + greenSize + blueSize;
|
---|
559 | ppfd->cRedBits = redSize;
|
---|
560 | ppfd->cBlueBits = blueSize;
|
---|
561 | ppfd->cGreenBits = greenSize;
|
---|
562 | ppfd->cAlphaBits = alphaSize;
|
---|
563 |
|
---|
564 | /* Set dwFlags */
|
---|
565 | if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DRAWABLE_TYPE, &glxReturnValue)) {
|
---|
566 | glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_VISUAL_ID, &xVisual);
|
---|
567 | glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_X_RENDERABLE, &xRenderable);
|
---|
568 | if ((glxReturnValue & GLX_WINDOW_BIT) && xVisual)
|
---|
569 | ppfd->dwFlags |= (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
|
---|
570 | }
|
---|
571 | if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DOUBLEBUFFER, &glxReturnValue)) {
|
---|
572 | if (glxReturnValue)
|
---|
573 | ppfd->dwFlags |= PFD_DOUBLEBUFFER;
|
---|
574 | }
|
---|
575 | /* Set iPixelType */
|
---|
576 | if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_RENDER_TYPE, &glxReturnValue)) {
|
---|
577 | if (glxReturnValue & GLX_RGBA_BIT)
|
---|
578 | ppfd->iPixelType = PFD_TYPE_RGBA;
|
---|
579 | else if ((glxReturnValue & GLX_COLOR_INDEX_BIT) & !(glxReturnValue & GLX_RGBA_BIT))
|
---|
580 | ppfd->iPixelType = PFD_TYPE_COLORINDEX;
|
---|
581 | }
|
---|
582 | /* Set cDepthBits */
|
---|
583 | if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DEPTH_SIZE, &glxReturnValue)) {
|
---|
584 | ppfd->cDepthBits = glxReturnValue;
|
---|
585 | } else {
|
---|
586 | ppfd->cDepthBits = 0;
|
---|
587 | }
|
---|
588 | /* Set cStencilBits */
|
---|
589 | if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_STENCIL_SIZE, &glxReturnValue)) {
|
---|
590 | ppfd->cStencilBits = glxReturnValue;
|
---|
591 | } else {
|
---|
592 | ppfd->cStencilBits = 0;
|
---|
593 | }
|
---|
594 | /** @todo Fill in the rest */
|
---|
595 | }
|
---|
596 |
|
---|
597 | pClient->lastretval = pClient->numFBConfigs;
|
---|
598 | pClient->fHasLastError = true;
|
---|
599 | pClient->ulLastError = glGetError();
|
---|
600 | }
|
---|
601 |
|
---|
602 | RTUINTPTR vboxDrvIsExtensionAvailable(char *pszExtFunctionName)
|
---|
603 | {
|
---|
604 | RTUINTPTR pfnProc = (RTUINTPTR)glXGetProcAddress((const GLubyte *)pszExtFunctionName);
|
---|
605 | Log(("vboxDrvIsExtensionAvailable %s -> %d\n", pszExtFunctionName, !!pfnProc));
|
---|
606 | return pfnProc;
|
---|
607 | }
|
---|
608 |
|
---|