VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/icd_drv.c@ 40267

Last change on this file since 40267 was 40267, checked in by vboxsync, 13 years ago

crOpenGL: fixe VSG Open Inventor interop issues

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.8 KB
Line 
1/* $Id: icd_drv.c 40267 2012-02-28 07:09:18Z vboxsync $ */
2
3/** @file
4 * VBox OpenGL windows ICD driver functions
5 */
6
7/*
8 * Copyright (C) 2006-2008 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "cr_error.h"
20#include "icd_drv.h"
21#include "cr_gl.h"
22#include "stub.h"
23#include "cr_mem.h"
24
25#include <windows.h>
26
27//TODO: consider
28/* We can modify chronium dispatch table functions order to match the one required by ICD,
29 * but it'd render us incompatible with other chromium SPUs and require more changes.
30 * In current state, we can use unmodified binary chromium SPUs. Question is do we need it?
31*/
32
33#define GL_FUNC(func) cr_gl##func
34
35static ICDTABLE icdTable = { 336, {
36#define ICD_ENTRY(func) (PROC)GL_FUNC(func),
37#include "VBoxICDList.h"
38#undef ICD_ENTRY
39} };
40
41static GLuint desiredVisual = CR_RGB_BIT;
42
43/**
44 * Compute a mask of CR_*_BIT flags which reflects the attributes of
45 * the pixel format of the given hdc.
46 */
47static GLuint ComputeVisBits( HDC hdc )
48{
49 PIXELFORMATDESCRIPTOR pfd;
50 int iPixelFormat;
51 GLuint b = 0;
52
53 iPixelFormat = GetPixelFormat( hdc );
54
55 DescribePixelFormat( hdc, iPixelFormat, sizeof(pfd), &pfd );
56
57 if (pfd.cDepthBits > 0)
58 b |= CR_DEPTH_BIT;
59 if (pfd.cAccumBits > 0)
60 b |= CR_ACCUM_BIT;
61 if (pfd.cColorBits > 8)
62 b |= CR_RGB_BIT;
63 if (pfd.cStencilBits > 0)
64 b |= CR_STENCIL_BIT;
65 if (pfd.cAlphaBits > 0)
66 b |= CR_ALPHA_BIT;
67 if (pfd.dwFlags & PFD_DOUBLEBUFFER)
68 b |= CR_DOUBLE_BIT;
69 if (pfd.dwFlags & PFD_STEREO)
70 b |= CR_STEREO_BIT;
71
72 return b;
73}
74
75void APIENTRY DrvReleaseContext(HGLRC hglrc)
76{
77 CR_DDI_PROLOGUE();
78 /*crDebug( "DrvReleaseContext(0x%x) called", hglrc );*/
79 stubMakeCurrent( NULL, NULL );
80}
81
82BOOL APIENTRY DrvValidateVersion(DWORD version)
83{
84 CR_DDI_PROLOGUE();
85 if (stubInit()) {
86 crDebug("DrvValidateVersion %x -> TRUE\n", version);
87 return TRUE;
88 }
89
90 crDebug("DrvValidateVersion %x -> FALSE, going to use system default opengl32.dll\n", version);
91 return FALSE;
92}
93
94//we're not going to change icdTable at runtime, so callback is unused
95PICDTABLE APIENTRY DrvSetContext(HDC hdc, HGLRC hglrc, void *callback)
96{
97 ContextInfo *context;
98 WindowInfo *window;
99 BOOL ret;
100
101 CR_DDI_PROLOGUE();
102
103 /*crDebug( "DrvSetContext called(0x%x, 0x%x)", hdc, hglrc );*/
104 (void) (callback);
105
106 crHashtableLock(stub.windowTable);
107 crHashtableLock(stub.contextTable);
108
109 context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
110 window = stubGetWindowInfo(hdc);
111
112 ret = stubMakeCurrent(window, context);
113
114 crHashtableUnlock(stub.contextTable);
115 crHashtableUnlock(stub.windowTable);
116
117 return ret ? &icdTable:NULL;
118}
119
120BOOL APIENTRY DrvSetPixelFormat(HDC hdc, int iPixelFormat)
121{
122 CR_DDI_PROLOGUE();
123 crDebug( "DrvSetPixelFormat(0x%x, %i) called.", hdc, iPixelFormat );
124
125 if ( (iPixelFormat<1) || (iPixelFormat>2) ) {
126 crError( "wglSetPixelFormat: iPixelFormat=%d?", iPixelFormat );
127 }
128
129 return 1;
130}
131
132HGLRC APIENTRY DrvCreateContext(HDC hdc)
133{
134 char dpyName[MAX_DPY_NAME];
135 ContextInfo *context;
136
137 CR_DDI_PROLOGUE();
138
139 crDebug( "DrvCreateContext(0x%x) called.", hdc);
140
141 stubInit();
142
143 CRASSERT(stub.contextTable);
144
145 sprintf(dpyName, "%d", hdc);
146 if (stub.haveNativeOpenGL)
147 desiredVisual |= ComputeVisBits( hdc );
148
149 context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0);
150 if (!context)
151 return 0;
152
153 return (HGLRC) context->id;
154}
155
156HGLRC APIENTRY DrvCreateLayerContext(HDC hdc, int iLayerPlane)
157{
158 CR_DDI_PROLOGUE();
159 crDebug( "DrvCreateLayerContext(0x%x, %i) called.", hdc, iLayerPlane);
160 //We don't support more than 1 layers.
161 if (iLayerPlane == 0) {
162 return DrvCreateContext(hdc);
163 } else {
164 crError( "DrvCreateLayerContext (%x,%x): unsupported", hdc, iLayerPlane);
165 return NULL;
166 }
167
168}
169
170BOOL APIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
171 int iLayerPlane, UINT nBytes,
172 LPLAYERPLANEDESCRIPTOR plpd)
173{
174 CR_DDI_PROLOGUE();
175 crWarning( "DrvDescribeLayerPlane: unimplemented" );
176 CRASSERT(false);
177 return 0;
178}
179
180int APIENTRY DrvGetLayerPaletteEntries(HDC hdc, int iLayerPlane,
181 int iStart, int cEntries,
182 COLORREF *pcr)
183{
184 CR_DDI_PROLOGUE();
185 crWarning( "DrvGetLayerPaletteEntries: unsupported" );
186 CRASSERT(false);
187 return 0;
188}
189
190int APIENTRY DrvDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR pfd)
191{
192 CR_DDI_PROLOGUE();
193 if ( !pfd ) {
194 return 2;
195 }
196
197 if ( nBytes != sizeof(*pfd) ) {
198 crWarning( "DrvDescribePixelFormat: nBytes=%u?", nBytes );
199 return 2;
200 }
201
202 if (iPixelFormat==1)
203 {
204 crMemZero(pfd, sizeof(*pfd));
205
206 pfd->nSize = sizeof(*pfd);
207 pfd->nVersion = 1;
208 pfd->dwFlags = (PFD_DRAW_TO_WINDOW |
209 PFD_SUPPORT_OPENGL |
210 PFD_DOUBLEBUFFER);
211
212 pfd->dwFlags |= 0x8000; /* <- Needed for VSG Open Inventor to be happy */
213
214 pfd->iPixelType = PFD_TYPE_RGBA;
215 pfd->cColorBits = 32;
216 pfd->cRedBits = 8;
217 pfd->cRedShift = 24;
218 pfd->cGreenBits = 8;
219 pfd->cGreenShift = 16;
220 pfd->cBlueBits = 8;
221 pfd->cBlueShift = 8;
222 pfd->cAlphaBits = 8;
223 pfd->cAlphaShift = 0;
224 pfd->cAccumBits = 0;
225 pfd->cAccumRedBits = 0;
226 pfd->cAccumGreenBits = 0;
227 pfd->cAccumBlueBits = 0;
228 pfd->cAccumAlphaBits = 0;
229 pfd->cDepthBits = 32;
230 pfd->cStencilBits = 8;
231 pfd->cAuxBuffers = 0;
232 pfd->iLayerType = PFD_MAIN_PLANE;
233 pfd->bReserved = 0;
234 pfd->dwLayerMask = 0;
235 pfd->dwVisibleMask = 0;
236 pfd->dwDamageMask = 0;
237 }
238 else
239 {
240 crMemZero(pfd, sizeof(*pfd));
241 pfd->nVersion = 1;
242 pfd->dwFlags = (PFD_DRAW_TO_WINDOW|
243 PFD_SUPPORT_OPENGL);
244
245 pfd->iPixelType = PFD_TYPE_RGBA;
246 pfd->cColorBits = 32;
247 pfd->cRedBits = 8;
248 pfd->cRedShift = 16;
249 pfd->cGreenBits = 8;
250 pfd->cGreenShift = 8;
251 pfd->cBlueBits = 8;
252 pfd->cBlueShift = 0;
253 pfd->cAlphaBits = 0;
254 pfd->cAlphaShift = 0;
255 pfd->cAccumBits = 64;
256 pfd->cAccumRedBits = 16;
257 pfd->cAccumGreenBits = 16;
258 pfd->cAccumBlueBits = 16;
259 pfd->cAccumAlphaBits = 0;
260 pfd->cDepthBits = 16;
261 pfd->cStencilBits = 8;
262 pfd->cAuxBuffers = 0;
263 pfd->iLayerType = PFD_MAIN_PLANE;
264 pfd->bReserved = 0;
265 pfd->dwLayerMask = 0;
266 pfd->dwVisibleMask = 0;
267 pfd->dwDamageMask = 0;
268 }
269
270 /* the max PFD index */
271 return 2;
272}
273
274BOOL APIENTRY DrvDeleteContext(HGLRC hglrc)
275{
276 CR_DDI_PROLOGUE();
277 /*crDebug( "DrvDeleteContext(0x%x) called", hglrc );*/
278 stubDestroyContext( (unsigned long) hglrc );
279 return 1;
280}
281
282BOOL APIENTRY DrvCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
283{
284 CR_DDI_PROLOGUE();
285 crWarning( "DrvCopyContext: unsupported" );
286 return 0;
287}
288
289BOOL APIENTRY DrvShareLists(HGLRC hglrc1, HGLRC hglrc2)
290{
291 CR_DDI_PROLOGUE();
292 crWarning( "DrvShareLists: unsupported" );
293 return 1;
294}
295
296int APIENTRY DrvSetLayerPaletteEntries(HDC hdc, int iLayerPlane,
297 int iStart, int cEntries,
298 CONST COLORREF *pcr)
299{
300 CR_DDI_PROLOGUE();
301 crWarning( "DrvSetLayerPaletteEntries: unsupported" );
302 return 0;
303}
304
305
306BOOL APIENTRY DrvRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
307{
308 CR_DDI_PROLOGUE();
309 crWarning( "DrvRealizeLayerPalette: unsupported" );
310 return 0;
311}
312
313BOOL APIENTRY DrvSwapLayerBuffers(HDC hdc, UINT fuPlanes)
314{
315 CR_DDI_PROLOGUE();
316 if (fuPlanes == 1)
317 {
318 return DrvSwapBuffers(hdc);
319 }
320 else
321 {
322 crWarning( "DrvSwapLayerBuffers: unsupported" );
323 CRASSERT(false);
324 return 0;
325 }
326}
327
328BOOL APIENTRY DrvSwapBuffers(HDC hdc)
329{
330 WindowInfo *window;
331
332 CR_DDI_PROLOGUE();
333 /*crDebug( "DrvSwapBuffers(0x%x) called", hdc );*/
334 window = stubGetWindowInfo(hdc);
335 stubSwapBuffers( window, 0 );
336 return 1;
337}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette