VirtualBox

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

Last change on this file since 20509 was 20398, checked in by vboxsync, 15 years ago

crOpenGL: make icd recognizeable by glew library, +fix issue with mixing wgl/gdi calls

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

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