VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/crOpenGL/wgl.c@ 16220

Last change on this file since 16220 was 16220, checked in by vboxsync, 16 years ago

crOpenGL: add wglGetExtensionsStringARB extension

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.0 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "cr_error.h"
8#include "cr_spu.h"
9#include "cr_environment.h"
10#include "stub.h"
11
12/* I *know* most of the parameters are unused, dammit. */
13#pragma warning( disable: 4100 )
14
15#define WIN32_LEAN_AND_MEAN
16#include <windows.h>
17#include <stdio.h>
18
19static GLuint desiredVisual = CR_RGB_BIT;
20
21
22/**
23 * Compute a mask of CR_*_BIT flags which reflects the attributes of
24 * the pixel format of the given hdc.
25 */
26static GLuint ComputeVisBits( HDC hdc )
27{
28 PIXELFORMATDESCRIPTOR pfd;
29 int iPixelFormat;
30 GLuint b = 0;
31
32 iPixelFormat = GetPixelFormat( hdc );
33
34 DescribePixelFormat( hdc, iPixelFormat, sizeof(pfd), &pfd );
35
36 if (pfd.cDepthBits > 0)
37 b |= CR_DEPTH_BIT;
38 if (pfd.cAccumBits > 0)
39 b |= CR_ACCUM_BIT;
40 if (pfd.cColorBits > 8)
41 b |= CR_RGB_BIT;
42 if (pfd.cStencilBits > 0)
43 b |= CR_STENCIL_BIT;
44 if (pfd.cAlphaBits > 0)
45 b |= CR_ALPHA_BIT;
46 if (pfd.dwFlags & PFD_DOUBLEBUFFER)
47 b |= CR_DOUBLE_BIT;
48 if (pfd.dwFlags & PFD_STEREO)
49 b |= CR_STEREO_BIT;
50
51 return b;
52}
53
54int WINAPI wglChoosePixelFormat_prox( HDC hdc, CONST PIXELFORMATDESCRIPTOR *pfd )
55{
56 DWORD okayFlags;
57
58 stubInit();
59
60 /*
61 * NOTE!!!
62 * Here we're telling the renderspu not to use the GDI
63 * equivalent's of ChoosePixelFormat/DescribePixelFormat etc
64 * There are subtle differences in the use of these calls.
65 */
66 crSetenv("CR_WGL_DO_NOT_USE_GDI", "yes");
67
68 if ( pfd->nSize != sizeof(*pfd) || pfd->nVersion != 1 ) {
69 crError( "wglChoosePixelFormat: bad pfd\n" );
70 return 0;
71 }
72
73 okayFlags = ( PFD_DRAW_TO_WINDOW |
74 PFD_SUPPORT_GDI |
75 PFD_SUPPORT_OPENGL |
76 PFD_DOUBLEBUFFER |
77 PFD_DOUBLEBUFFER_DONTCARE |
78 PFD_SWAP_EXCHANGE |
79 PFD_SWAP_COPY |
80 PFD_STEREO |
81 PFD_STEREO_DONTCARE |
82 PFD_DEPTH_DONTCARE );
83 if ( pfd->dwFlags & ~okayFlags ) {
84 crWarning( "wglChoosePixelFormat: only support flags=0x%x, but you gave me flags=0x%x", okayFlags, pfd->dwFlags );
85 return 0;
86 }
87
88 if ( pfd->iPixelType != PFD_TYPE_RGBA ) {
89 crError( "wglChoosePixelFormat: only support RGBA\n" );
90 }
91
92 if ( pfd->cColorBits > 32 ||
93 pfd->cRedBits > 8 ||
94 pfd->cGreenBits > 8 ||
95 pfd->cBlueBits > 8 ||
96 pfd->cAlphaBits > 8 ) {
97 crWarning( "wglChoosePixelFormat: too much color precision requested\n" );
98 }
99
100 if ( pfd->dwFlags & PFD_DOUBLEBUFFER )
101 desiredVisual |= CR_DOUBLE_BIT;
102
103 if ( pfd->dwFlags & PFD_STEREO )
104 desiredVisual |= CR_STEREO_BIT;
105
106 if ( pfd->cColorBits > 8)
107 desiredVisual |= CR_RGB_BIT;
108
109 if ( pfd->cAccumBits > 0 ||
110 pfd->cAccumRedBits > 0 ||
111 pfd->cAccumGreenBits > 0 ||
112 pfd->cAccumBlueBits > 0 ||
113 pfd->cAccumAlphaBits > 0 ) {
114 crWarning( "wglChoosePixelFormat: asked for accumulation buffer, ignoring\n" );
115 }
116
117 if ( pfd->cAccumBits > 0 )
118 desiredVisual |= CR_ACCUM_BIT;
119
120 if ( pfd->cDepthBits > 32 ) {
121 crError( "wglChoosePixelFormat; asked for too many depth bits\n" );
122 }
123
124 if ( pfd->cDepthBits > 0 )
125 desiredVisual |= CR_DEPTH_BIT;
126
127 if ( pfd->cStencilBits > 8 ) {
128 crError( "wglChoosePixelFormat: asked for too many stencil bits\n" );
129 }
130
131 if ( pfd->cStencilBits > 0 )
132 desiredVisual |= CR_STENCIL_BIT;
133
134 if ( pfd->cAuxBuffers > 0 ) {
135 crError( "wglChoosePixelFormat: asked for aux buffers\n" );
136 }
137
138 if ( pfd->iLayerType != PFD_MAIN_PLANE ) {
139 crError( "wglChoosePixelFormat: asked for a strange layer\n" );
140 }
141
142 return 1;
143}
144
145BOOL WINAPI wglSetPixelFormat_prox( HDC hdc, int pixelFormat,
146 CONST PIXELFORMATDESCRIPTOR *pdf )
147{
148 if ( pixelFormat != 1 ) {
149 crError( "wglSetPixelFormat: pixelFormat=%d?\n", pixelFormat );
150 }
151
152 return 1;
153}
154
155BOOL WINAPI wglDeleteContext_prox( HGLRC hglrc )
156{
157 stubDestroyContext( (unsigned long) hglrc );
158 return 1;
159}
160
161BOOL WINAPI wglMakeCurrent_prox( HDC hdc, HGLRC hglrc )
162{
163 ContextInfo *context;
164 WindowInfo *window;
165
166 context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
167 window = stubGetWindowInfo(hdc);
168
169 return stubMakeCurrent( window, context );
170}
171
172HGLRC WINAPI wglGetCurrentContext_prox( void )
173{
174 return (HGLRC) stub.currentContext;
175}
176
177HDC WINAPI wglGetCurrentDC_prox( void )
178{
179 if (stub.currentContext && stub.currentContext->currentDrawable)
180 return (HDC) stub.currentContext->currentDrawable->drawable;
181 else
182 return (HDC) NULL;
183}
184
185int WINAPI wglGetPixelFormat_prox( HDC hdc )
186{
187 /* this is what we call our generic pixelformat, regardless of the HDC */
188 return 1;
189}
190
191int WINAPI wglDescribePixelFormat_prox( HDC hdc, int pixelFormat, UINT nBytes,
192 LPPIXELFORMATDESCRIPTOR pfd )
193{
194/* if ( pixelFormat != 1 ) {
195 * crError( "wglDescribePixelFormat: pixelFormat=%d?\n", pixelFormat );
196 * return 0;
197 * } */
198
199 if ( !pfd ) {
200 crWarning( "wglDescribePixelFormat: pfd=NULL\n" );
201 return 1; /* There's only one, baby */
202 }
203
204 if ( nBytes != sizeof(*pfd) ) {
205 crWarning( "wglDescribePixelFormat: nBytes=%u?\n", nBytes );
206 return 1; /* There's only one, baby */
207 }
208
209 pfd->nSize = sizeof(*pfd);
210 pfd->nVersion = 1;
211 pfd->dwFlags = ( PFD_DRAW_TO_WINDOW |
212 PFD_SUPPORT_GDI |
213 PFD_SUPPORT_OPENGL |
214 PFD_DOUBLEBUFFER );
215 pfd->iPixelType = PFD_TYPE_RGBA;
216 pfd->cColorBits = 32;
217 pfd->cRedBits = 8;
218 pfd->cRedShift = 24;
219 pfd->cGreenBits = 8;
220 pfd->cGreenShift = 16;
221 pfd->cBlueBits = 8;
222 pfd->cBlueShift = 8;
223 pfd->cAlphaBits = 8;
224 pfd->cAlphaShift = 0;
225 pfd->cAccumBits = 0;
226 pfd->cAccumRedBits = 0;
227 pfd->cAccumGreenBits = 0;
228 pfd->cAccumBlueBits = 0;
229 pfd->cAccumAlphaBits = 0;
230 pfd->cDepthBits = 32;
231 pfd->cStencilBits = 8;
232 pfd->cAuxBuffers = 0;
233 pfd->iLayerType = PFD_MAIN_PLANE;
234 pfd->bReserved = 0;
235 pfd->dwLayerMask = 0;
236 pfd->dwVisibleMask = 0;
237 pfd->dwDamageMask = 0;
238
239 /* the max PFD index */
240 return 1;
241}
242
243BOOL WINAPI wglShareLists_prox( HGLRC hglrc1, HGLRC hglrc2 )
244{
245 crWarning( "wglShareLists: unsupported" );
246 return 0;
247}
248
249
250HGLRC WINAPI wglCreateContext_prox( HDC hdc )
251{
252 char dpyName[MAX_DPY_NAME];
253 ContextInfo *context;
254
255 stubInit();
256
257 CRASSERT(stub.contextTable);
258
259 sprintf(dpyName, "%d", hdc);
260 if (stub.haveNativeOpenGL)
261 desiredVisual |= ComputeVisBits( hdc );
262
263 context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0);
264 if (!context)
265 return 0;
266
267 return (HGLRC) context->id;
268}
269
270BOOL WINAPI
271wglSwapBuffers_prox( HDC hdc )
272{
273 const WindowInfo *window = stubGetWindowInfo(hdc);
274 stubSwapBuffers( window, 0 );
275 return 1;
276}
277
278BOOL WINAPI wglCopyContext_prox( HGLRC src, HGLRC dst, UINT mask )
279{
280 crWarning( "wglCopyContext: unsupported" );
281 return 0;
282}
283
284HGLRC WINAPI wglCreateLayerContext_prox( HDC hdc, int layerPlane )
285{
286 stubInit();
287 crWarning( "wglCreateLayerContext: unsupported" );
288 return 0;
289}
290
291PROC WINAPI wglGetProcAddress_prox( LPCSTR name )
292{
293 return (PROC) crGetProcAddress( name );
294}
295
296BOOL WINAPI wglUseFontBitmapsA_prox( HDC hdc, DWORD first, DWORD count, DWORD listBase )
297{
298 crWarning( "wglUseFontBitmapsA: unsupported" );
299 return 0;
300}
301
302BOOL WINAPI wglUseFontBitmapsW_prox( HDC hdc, DWORD first, DWORD count, DWORD listBase )
303{
304 crWarning( "wglUseFontBitmapsW: unsupported" );
305 return 0;
306}
307
308BOOL WINAPI wglDescribeLayerPlane_prox( HDC hdc, int pixelFormat, int layerPlane,
309 UINT nBytes, LPLAYERPLANEDESCRIPTOR lpd )
310{
311 crWarning( "wglDescribeLayerPlane: unimplemented" );
312 return 0;
313}
314
315int WINAPI wglSetLayerPaletteEntries_prox( HDC hdc, int layerPlane, int start,
316 int entries, CONST COLORREF *cr )
317{
318 crWarning( "wglSetLayerPaletteEntries: unsupported" );
319 return 0;
320}
321
322int WINAPI wglGetLayerPaletteEntries_prox( HDC hdc, int layerPlane, int start,
323 int entries, COLORREF *cr )
324{
325 crWarning( "wglGetLayerPaletteEntries: unsupported" );
326 return 0;
327}
328
329BOOL WINAPI wglRealizeLayerPalette_prox( HDC hdc, int layerPlane, BOOL realize )
330{
331 crWarning( "wglRealizeLayerPalette: unsupported" );
332 return 0;
333}
334
335DWORD WINAPI wglSwapMultipleBuffers_prox( UINT a, CONST void *b )
336{
337 crWarning( "wglSwapMultipleBuffer: unsupported" );
338 return 0;
339}
340
341BOOL WINAPI wglUseFontOutlinesA_prox( HDC hdc, DWORD first, DWORD count, DWORD listBase,
342 FLOAT deviation, FLOAT extrusion, int format,
343 LPGLYPHMETRICSFLOAT gmf )
344{
345 crWarning( "wglUseFontOutlinesA: unsupported" );
346 return 0;
347}
348
349BOOL WINAPI wglUseFontOutlinesW_prox( HDC hdc, DWORD first, DWORD count, DWORD listBase,
350 FLOAT deviation, FLOAT extrusion, int format,
351 LPGLYPHMETRICSFLOAT gmf )
352{
353 crWarning( "wglUseFontOutlinesW: unsupported" );
354 return 0;
355}
356
357BOOL WINAPI wglSwapLayerBuffers_prox( HDC hdc, UINT planes )
358{
359 crWarning( "wglSwapLayerBuffers: unsupported" );
360 return 0;
361}
362
363BOOL WINAPI wglChoosePixelFormatEXT_prox(HDC hdc, const int *piAttributes, const FLOAT *pfAttributes, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
364{
365 int *pi;
366 int wants_rgb = 0;
367
368 stubInit();
369
370 /* TODO : Need to check pfAttributes too ! */
371
372 for ( pi = (int *)piAttributes; *pi != 0; pi++ )
373 {
374 switch ( *pi )
375 {
376 case WGL_COLOR_BITS_EXT:
377 if (pi[1] > 8)
378 wants_rgb = 1;
379 pi++;
380 break;
381
382 case WGL_RED_BITS_EXT:
383 case WGL_GREEN_BITS_EXT:
384 case WGL_BLUE_BITS_EXT:
385 if (pi[1] > 3)
386 wants_rgb = 1;
387 pi++;
388 break;
389
390 case WGL_ACCUM_ALPHA_BITS_EXT:
391 case WGL_ALPHA_BITS_EXT:
392 if (pi[1] > 0)
393 desiredVisual |= CR_ALPHA_BIT;
394 pi++;
395 break;
396
397 case WGL_DOUBLE_BUFFER_EXT:
398 if (pi[1] > 0)
399 desiredVisual |= CR_DOUBLE_BIT;
400 pi++;
401 break;
402
403 case WGL_STEREO_EXT:
404 if (pi[1] > 0)
405 desiredVisual |= CR_STEREO_BIT;
406 pi++;
407 break;
408
409 case WGL_DEPTH_BITS_EXT:
410 if (pi[1] > 0)
411 desiredVisual |= CR_DEPTH_BIT;
412 pi++;
413 break;
414
415 case WGL_STENCIL_BITS_EXT:
416 if (pi[1] > 0)
417 desiredVisual |= CR_STENCIL_BIT;
418 pi++;
419 break;
420
421 case WGL_ACCUM_RED_BITS_EXT:
422 case WGL_ACCUM_GREEN_BITS_EXT:
423 case WGL_ACCUM_BLUE_BITS_EXT:
424 if (pi[1] > 0)
425 desiredVisual |= CR_ACCUM_BIT;
426 pi++;
427 break;
428
429 case WGL_SAMPLE_BUFFERS_EXT:
430 case WGL_SAMPLES_EXT:
431 if (pi[1] > 0)
432 desiredVisual |= CR_MULTISAMPLE_BIT;
433 pi++;
434 break;
435
436
437 default:
438 crWarning( "wglChoosePixelFormatEXT: bad pi=0x%x", *pi );
439 return 0;
440 }
441 }
442
443 return 1;
444}
445
446BOOL WINAPI wglGetPixelFormatAttribivEXT_prox(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *pValues)
447{
448 /* TODO */
449
450 return 1;
451}
452
453BOOL WINAPI wglGetPixelFormatAttribfvEXT_prox(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *pValues)
454{
455 /* TODO */
456
457 return 1;
458}
459
460const GLubyte * WINAPI wglGetExtensionsStringEXT_prox( HDC hdc )
461{
462 /*static GLubyte *retval = "WGL_EXT_pixel_format WGL_ARB_multisample";*/
463 static GLubyte *retval = "WGL_ARB_multisample";
464
465 (void) hdc;
466
467 return retval;
468}
469
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