stw: move pixelformat_describe to shared
[mesa.git] / src / gallium / state_trackers / wgl / icd / stw_icd.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include <windows.h>
29 #include <stdio.h>
30
31 #include "GL/gl.h"
32
33 #include "pipe/p_debug.h"
34
35 #include "shared/stw_device.h"
36 #include "shared/stw_context.h"
37 #include "shared/stw_pixelformat.h"
38 #include "icd/stw_icd.h"
39 #include "wgl/stw_wgl.h"
40
41
42 static HGLRC
43 lookup_hglrc( DHGLRC dhglrc )
44 {
45 if (dhglrc == 0 ||
46 dhglrc >= DRV_CONTEXT_MAX)
47 return NULL;
48
49 return stw_dev->ctx_array[dhglrc - 1].hglrc;
50 }
51
52 BOOL APIENTRY
53 DrvCopyContext(
54 DHGLRC dhrcSource,
55 DHGLRC dhrcDest,
56 UINT fuMask )
57 {
58 HGLRC src = lookup_hglrc( dhrcSource );
59 HGLRC dst = lookup_hglrc( dhrcDest );
60
61 if (src == NULL ||
62 dst == NULL)
63 return FALSE;
64
65 return stw_wgl_copy_context( src, dst, fuMask );
66 }
67
68 DHGLRC APIENTRY
69 DrvCreateLayerContext(
70 HDC hdc,
71 INT iLayerPlane )
72 {
73 DWORD i;
74
75 for (i = 0; i < DRV_CONTEXT_MAX; i++) {
76 if (stw_dev->ctx_array[i].hglrc == NULL)
77 goto found_slot;
78 }
79
80 /* No slot available, fail:
81 */
82 return 0;
83
84 found_slot:
85 stw_dev->ctx_array[i].hglrc = stw_wgl_create_context( hdc, iLayerPlane );
86 if (stw_dev->ctx_array[i].hglrc == NULL)
87 return 0;
88
89 return (DHGLRC) i + 1;
90 }
91
92 DHGLRC APIENTRY
93 DrvCreateContext(
94 HDC hdc )
95 {
96 return DrvCreateLayerContext( hdc, 0 );
97 }
98
99 BOOL APIENTRY
100 DrvDeleteContext(
101 DHGLRC dhglrc )
102 {
103 HGLRC hglrc = lookup_hglrc( dhglrc );
104 BOOL success = FALSE;
105
106 if (hglrc != NULL) {
107 success = stw_wgl_delete_context( hglrc );
108 if (success)
109 stw_dev->ctx_array[dhglrc - 1].hglrc = NULL;
110 }
111
112 debug_printf( "%s( %u ) = %s\n", __FUNCTION__, dhglrc, success ? "TRUE" : "FALSE" );
113
114 return success;
115 }
116
117 BOOL APIENTRY
118 DrvDescribeLayerPlane(
119 HDC hdc,
120 INT iPixelFormat,
121 INT iLayerPlane,
122 UINT nBytes,
123 LPLAYERPLANEDESCRIPTOR plpd )
124 {
125 debug_printf( "%s\n", __FUNCTION__ );
126
127 return FALSE;
128 }
129
130 LONG APIENTRY
131 DrvDescribePixelFormat(
132 HDC hdc,
133 INT iPixelFormat,
134 ULONG cjpfd,
135 PIXELFORMATDESCRIPTOR *ppfd )
136 {
137 LONG r;
138
139 r = stw_pixelformat_describe( hdc, iPixelFormat, cjpfd, ppfd );
140
141 debug_printf( "%s( 0x%p, %d, %u, 0x%p ) = %d\n",
142 __FUNCTION__, hdc, iPixelFormat, cjpfd, ppfd, r );
143
144 return r;
145 }
146
147 int APIENTRY
148 DrvGetLayerPaletteEntries(
149 HDC hdc,
150 INT iLayerPlane,
151 INT iStart,
152 INT cEntries,
153 COLORREF *pcr )
154 {
155 debug_printf( "%s\n", __FUNCTION__ );
156
157 return 0;
158 }
159
160 PROC APIENTRY
161 DrvGetProcAddress(
162 LPCSTR lpszProc )
163 {
164 PROC r;
165
166 r = wglGetProcAddress( lpszProc );
167
168 debug_printf( "%s( \", __FUNCTION__%s\" ) = 0x%p\n", lpszProc, r );
169
170 return r;
171 }
172
173 BOOL APIENTRY
174 DrvRealizeLayerPalette(
175 HDC hdc,
176 INT iLayerPlane,
177 BOOL bRealize )
178 {
179 debug_printf( "%s\n", __FUNCTION__ );
180
181 return FALSE;
182 }
183
184 BOOL APIENTRY
185 DrvReleaseContext(
186 DHGLRC dhglrc )
187 {
188 BOOL success = FALSE;
189
190 if (dhglrc == stw_dev->ctx_current) {
191 HGLRC hglrc = lookup_hglrc( dhglrc );
192
193 if (hglrc != NULL) {
194 success = wglMakeCurrent( NULL, NULL );
195 if (success)
196 stw_dev->ctx_current = 0;
197 }
198 }
199
200 debug_printf( "%s( %u ) = %s\n", __FUNCTION__, dhglrc, success ? "TRUE" : "FALSE" );
201
202 return success;
203 }
204
205 void APIENTRY
206 DrvSetCallbackProcs(
207 INT nProcs,
208 PROC *pProcs )
209 {
210 debug_printf( "%s( %d, 0x%p )\n", __FUNCTION__, nProcs, pProcs );
211
212 return;
213 }
214
215 #define GPA_GL( NAME ) disp->NAME = gl##NAME
216
217 static GLCLTPROCTABLE cpt;
218
219 PGLCLTPROCTABLE APIENTRY
220 DrvSetContext(
221 HDC hdc,
222 DHGLRC dhglrc,
223 PFN_SETPROCTABLE pfnSetProcTable )
224 {
225 HGLRC hglrc = lookup_hglrc( dhglrc );
226 GLDISPATCHTABLE *disp = &cpt.glDispatchTable;
227
228 debug_printf( "%s( 0x%p, %u, 0x%p )\n", __FUNCTION__, hdc, dhglrc, pfnSetProcTable );
229
230 if (hglrc == NULL)
231 return NULL;
232
233 if (!wglMakeCurrent( hdc, hglrc ))
234 return NULL;
235
236 memset( &cpt, 0, sizeof( cpt ) );
237 cpt.cEntries = OPENGL_VERSION_110_ENTRIES;
238
239 GPA_GL( NewList );
240 GPA_GL( EndList );
241 GPA_GL( CallList );
242 GPA_GL( CallLists );
243 GPA_GL( DeleteLists );
244 GPA_GL( GenLists );
245 GPA_GL( ListBase );
246 GPA_GL( Begin );
247 GPA_GL( Bitmap );
248 GPA_GL( Color3b );
249 GPA_GL( Color3bv );
250 GPA_GL( Color3d );
251 GPA_GL( Color3dv );
252 GPA_GL( Color3f );
253 GPA_GL( Color3fv );
254 GPA_GL( Color3i );
255 GPA_GL( Color3iv );
256 GPA_GL( Color3s );
257 GPA_GL( Color3sv );
258 GPA_GL( Color3ub );
259 GPA_GL( Color3ubv );
260 GPA_GL( Color3ui );
261 GPA_GL( Color3uiv );
262 GPA_GL( Color3us );
263 GPA_GL( Color3usv );
264 GPA_GL( Color4b );
265 GPA_GL( Color4bv );
266 GPA_GL( Color4d );
267 GPA_GL( Color4dv );
268 GPA_GL( Color4f );
269 GPA_GL( Color4fv );
270 GPA_GL( Color4i );
271 GPA_GL( Color4iv );
272 GPA_GL( Color4s );
273 GPA_GL( Color4sv );
274 GPA_GL( Color4ub );
275 GPA_GL( Color4ubv );
276 GPA_GL( Color4ui );
277 GPA_GL( Color4uiv );
278 GPA_GL( Color4us );
279 GPA_GL( Color4usv );
280 GPA_GL( EdgeFlag );
281 GPA_GL( EdgeFlagv );
282 GPA_GL( End );
283 GPA_GL( Indexd );
284 GPA_GL( Indexdv );
285 GPA_GL( Indexf );
286 GPA_GL( Indexfv );
287 GPA_GL( Indexi );
288 GPA_GL( Indexiv );
289 GPA_GL( Indexs );
290 GPA_GL( Indexsv );
291 GPA_GL( Normal3b );
292 GPA_GL( Normal3bv );
293 GPA_GL( Normal3d );
294 GPA_GL( Normal3dv );
295 GPA_GL( Normal3f );
296 GPA_GL( Normal3fv );
297 GPA_GL( Normal3i );
298 GPA_GL( Normal3iv );
299 GPA_GL( Normal3s );
300 GPA_GL( Normal3sv );
301 GPA_GL( RasterPos2d );
302 GPA_GL( RasterPos2dv );
303 GPA_GL( RasterPos2f );
304 GPA_GL( RasterPos2fv );
305 GPA_GL( RasterPos2i );
306 GPA_GL( RasterPos2iv );
307 GPA_GL( RasterPos2s );
308 GPA_GL( RasterPos2sv );
309 GPA_GL( RasterPos3d );
310 GPA_GL( RasterPos3dv );
311 GPA_GL( RasterPos3f );
312 GPA_GL( RasterPos3fv );
313 GPA_GL( RasterPos3i );
314 GPA_GL( RasterPos3iv );
315 GPA_GL( RasterPos3s );
316 GPA_GL( RasterPos3sv );
317 GPA_GL( RasterPos4d );
318 GPA_GL( RasterPos4dv );
319 GPA_GL( RasterPos4f );
320 GPA_GL( RasterPos4fv );
321 GPA_GL( RasterPos4i );
322 GPA_GL( RasterPos4iv );
323 GPA_GL( RasterPos4s );
324 GPA_GL( RasterPos4sv );
325 GPA_GL( Rectd );
326 GPA_GL( Rectdv );
327 GPA_GL( Rectf );
328 GPA_GL( Rectfv );
329 GPA_GL( Recti );
330 GPA_GL( Rectiv );
331 GPA_GL( Rects );
332 GPA_GL( Rectsv );
333 GPA_GL( TexCoord1d );
334 GPA_GL( TexCoord1dv );
335 GPA_GL( TexCoord1f );
336 GPA_GL( TexCoord1fv );
337 GPA_GL( TexCoord1i );
338 GPA_GL( TexCoord1iv );
339 GPA_GL( TexCoord1s );
340 GPA_GL( TexCoord1sv );
341 GPA_GL( TexCoord2d );
342 GPA_GL( TexCoord2dv );
343 GPA_GL( TexCoord2f );
344 GPA_GL( TexCoord2fv );
345 GPA_GL( TexCoord2i );
346 GPA_GL( TexCoord2iv );
347 GPA_GL( TexCoord2s );
348 GPA_GL( TexCoord2sv );
349 GPA_GL( TexCoord3d );
350 GPA_GL( TexCoord3dv );
351 GPA_GL( TexCoord3f );
352 GPA_GL( TexCoord3fv );
353 GPA_GL( TexCoord3i );
354 GPA_GL( TexCoord3iv );
355 GPA_GL( TexCoord3s );
356 GPA_GL( TexCoord3sv );
357 GPA_GL( TexCoord4d );
358 GPA_GL( TexCoord4dv );
359 GPA_GL( TexCoord4f );
360 GPA_GL( TexCoord4fv );
361 GPA_GL( TexCoord4i );
362 GPA_GL( TexCoord4iv );
363 GPA_GL( TexCoord4s );
364 GPA_GL( TexCoord4sv );
365 GPA_GL( Vertex2d );
366 GPA_GL( Vertex2dv );
367 GPA_GL( Vertex2f );
368 GPA_GL( Vertex2fv );
369 GPA_GL( Vertex2i );
370 GPA_GL( Vertex2iv );
371 GPA_GL( Vertex2s );
372 GPA_GL( Vertex2sv );
373 GPA_GL( Vertex3d );
374 GPA_GL( Vertex3dv );
375 GPA_GL( Vertex3f );
376 GPA_GL( Vertex3fv );
377 GPA_GL( Vertex3i );
378 GPA_GL( Vertex3iv );
379 GPA_GL( Vertex3s );
380 GPA_GL( Vertex3sv );
381 GPA_GL( Vertex4d );
382 GPA_GL( Vertex4dv );
383 GPA_GL( Vertex4f );
384 GPA_GL( Vertex4fv );
385 GPA_GL( Vertex4i );
386 GPA_GL( Vertex4iv );
387 GPA_GL( Vertex4s );
388 GPA_GL( Vertex4sv );
389 GPA_GL( ClipPlane );
390 GPA_GL( ColorMaterial );
391 GPA_GL( CullFace );
392 GPA_GL( Fogf );
393 GPA_GL( Fogfv );
394 GPA_GL( Fogi );
395 GPA_GL( Fogiv );
396 GPA_GL( FrontFace );
397 GPA_GL( Hint );
398 GPA_GL( Lightf );
399 GPA_GL( Lightfv );
400 GPA_GL( Lighti );
401 GPA_GL( Lightiv );
402 GPA_GL( LightModelf );
403 GPA_GL( LightModelfv );
404 GPA_GL( LightModeli );
405 GPA_GL( LightModeliv );
406 GPA_GL( LineStipple );
407 GPA_GL( LineWidth );
408 GPA_GL( Materialf );
409 GPA_GL( Materialfv );
410 GPA_GL( Materiali );
411 GPA_GL( Materialiv );
412 GPA_GL( PointSize );
413 GPA_GL( PolygonMode );
414 GPA_GL( PolygonStipple );
415 GPA_GL( Scissor );
416 GPA_GL( ShadeModel );
417 GPA_GL( TexParameterf );
418 GPA_GL( TexParameterfv );
419 GPA_GL( TexParameteri );
420 GPA_GL( TexParameteriv );
421 GPA_GL( TexImage1D );
422 GPA_GL( TexImage2D );
423 GPA_GL( TexEnvf );
424 GPA_GL( TexEnvfv );
425 GPA_GL( TexEnvi );
426 GPA_GL( TexEnviv );
427 GPA_GL( TexGend );
428 GPA_GL( TexGendv );
429 GPA_GL( TexGenf );
430 GPA_GL( TexGenfv );
431 GPA_GL( TexGeni );
432 GPA_GL( TexGeniv );
433 GPA_GL( FeedbackBuffer );
434 GPA_GL( SelectBuffer );
435 GPA_GL( RenderMode );
436 GPA_GL( InitNames );
437 GPA_GL( LoadName );
438 GPA_GL( PassThrough );
439 GPA_GL( PopName );
440 GPA_GL( PushName );
441 GPA_GL( DrawBuffer );
442 GPA_GL( Clear );
443 GPA_GL( ClearAccum );
444 GPA_GL( ClearIndex );
445 GPA_GL( ClearColor );
446 GPA_GL( ClearStencil );
447 GPA_GL( ClearDepth );
448 GPA_GL( StencilMask );
449 GPA_GL( ColorMask );
450 GPA_GL( DepthMask );
451 GPA_GL( IndexMask );
452 GPA_GL( Accum );
453 GPA_GL( Disable );
454 GPA_GL( Enable );
455 GPA_GL( Finish );
456 GPA_GL( Flush );
457 GPA_GL( PopAttrib );
458 GPA_GL( PushAttrib );
459 GPA_GL( Map1d );
460 GPA_GL( Map1f );
461 GPA_GL( Map2d );
462 GPA_GL( Map2f );
463 GPA_GL( MapGrid1d );
464 GPA_GL( MapGrid1f );
465 GPA_GL( MapGrid2d );
466 GPA_GL( MapGrid2f );
467 GPA_GL( EvalCoord1d );
468 GPA_GL( EvalCoord1dv );
469 GPA_GL( EvalCoord1f );
470 GPA_GL( EvalCoord1fv );
471 GPA_GL( EvalCoord2d );
472 GPA_GL( EvalCoord2dv );
473 GPA_GL( EvalCoord2f );
474 GPA_GL( EvalCoord2fv );
475 GPA_GL( EvalMesh1 );
476 GPA_GL( EvalPoint1 );
477 GPA_GL( EvalMesh2 );
478 GPA_GL( EvalPoint2 );
479 GPA_GL( AlphaFunc );
480 GPA_GL( BlendFunc );
481 GPA_GL( LogicOp );
482 GPA_GL( StencilFunc );
483 GPA_GL( StencilOp );
484 GPA_GL( DepthFunc );
485 GPA_GL( PixelZoom );
486 GPA_GL( PixelTransferf );
487 GPA_GL( PixelTransferi );
488 GPA_GL( PixelStoref );
489 GPA_GL( PixelStorei );
490 GPA_GL( PixelMapfv );
491 GPA_GL( PixelMapuiv );
492 GPA_GL( PixelMapusv );
493 GPA_GL( ReadBuffer );
494 GPA_GL( CopyPixels );
495 GPA_GL( ReadPixels );
496 GPA_GL( DrawPixels );
497 GPA_GL( GetBooleanv );
498 GPA_GL( GetClipPlane );
499 GPA_GL( GetDoublev );
500 GPA_GL( GetError );
501 GPA_GL( GetFloatv );
502 GPA_GL( GetIntegerv );
503 GPA_GL( GetLightfv );
504 GPA_GL( GetLightiv );
505 GPA_GL( GetMapdv );
506 GPA_GL( GetMapfv );
507 GPA_GL( GetMapiv );
508 GPA_GL( GetMaterialfv );
509 GPA_GL( GetMaterialiv );
510 GPA_GL( GetPixelMapfv );
511 GPA_GL( GetPixelMapuiv );
512 GPA_GL( GetPixelMapusv );
513 GPA_GL( GetPolygonStipple );
514 GPA_GL( GetString );
515 GPA_GL( GetTexEnvfv );
516 GPA_GL( GetTexEnviv );
517 GPA_GL( GetTexGendv );
518 GPA_GL( GetTexGenfv );
519 GPA_GL( GetTexGeniv );
520 GPA_GL( GetTexImage );
521 GPA_GL( GetTexParameterfv );
522 GPA_GL( GetTexParameteriv );
523 GPA_GL( GetTexLevelParameterfv );
524 GPA_GL( GetTexLevelParameteriv );
525 GPA_GL( IsEnabled );
526 GPA_GL( IsList );
527 GPA_GL( DepthRange );
528 GPA_GL( Frustum );
529 GPA_GL( LoadIdentity );
530 GPA_GL( LoadMatrixf );
531 GPA_GL( LoadMatrixd );
532 GPA_GL( MatrixMode );
533 GPA_GL( MultMatrixf );
534 GPA_GL( MultMatrixd );
535 GPA_GL( Ortho );
536 GPA_GL( PopMatrix );
537 GPA_GL( PushMatrix );
538 GPA_GL( Rotated );
539 GPA_GL( Rotatef );
540 GPA_GL( Scaled );
541 GPA_GL( Scalef );
542 GPA_GL( Translated );
543 GPA_GL( Translatef );
544 GPA_GL( Viewport );
545 GPA_GL( ArrayElement );
546 GPA_GL( BindTexture );
547 GPA_GL( ColorPointer );
548 GPA_GL( DisableClientState );
549 GPA_GL( DrawArrays );
550 GPA_GL( DrawElements );
551 GPA_GL( EdgeFlagPointer );
552 GPA_GL( EnableClientState );
553 GPA_GL( IndexPointer );
554 GPA_GL( Indexub );
555 GPA_GL( Indexubv );
556 GPA_GL( InterleavedArrays );
557 GPA_GL( NormalPointer );
558 GPA_GL( PolygonOffset );
559 GPA_GL( TexCoordPointer );
560 GPA_GL( VertexPointer );
561 GPA_GL( AreTexturesResident );
562 GPA_GL( CopyTexImage1D );
563 GPA_GL( CopyTexImage2D );
564 GPA_GL( CopyTexSubImage1D );
565 GPA_GL( CopyTexSubImage2D );
566 GPA_GL( DeleteTextures );
567 GPA_GL( GenTextures );
568 GPA_GL( GetPointerv );
569 GPA_GL( IsTexture );
570 GPA_GL( PrioritizeTextures );
571 GPA_GL( TexSubImage1D );
572 GPA_GL( TexSubImage2D );
573 GPA_GL( PopClientAttrib );
574 GPA_GL( PushClientAttrib );
575
576 return &cpt;
577 }
578
579 int APIENTRY
580 DrvSetLayerPaletteEntries(
581 HDC hdc,
582 INT iLayerPlane,
583 INT iStart,
584 INT cEntries,
585 CONST COLORREF *pcr )
586 {
587 debug_printf( "%s\n", __FUNCTION__ );
588
589 return 0;
590 }
591
592 BOOL APIENTRY
593 DrvSetPixelFormat(
594 HDC hdc,
595 LONG iPixelFormat )
596 {
597 PIXELFORMATDESCRIPTOR pfd;
598 BOOL r;
599
600 stw_pixelformat_describe( hdc, iPixelFormat, sizeof( pfd ), &pfd );
601
602 r = wglSetPixelFormat( hdc, iPixelFormat, &pfd );
603
604 debug_printf( "%s( 0x%p, %d ) = %s\n", __FUNCTION__, hdc, iPixelFormat, r ? "TRUE" : "FALSE" );
605
606 return r;
607 }
608
609 BOOL APIENTRY
610 DrvShareLists(
611 DHGLRC dhglrc1,
612 DHGLRC dhglrc2 )
613 {
614 debug_printf( "%s\n", __FUNCTION__ );
615
616 return FALSE;
617 }
618
619 BOOL APIENTRY
620 DrvSwapBuffers(
621 HDC hdc )
622 {
623 debug_printf( "%s( 0x%p )\n", __FUNCTION__, hdc );
624
625 return wglSwapBuffers( hdc );
626 }
627
628 BOOL APIENTRY
629 DrvSwapLayerBuffers(
630 HDC hdc,
631 UINT fuPlanes )
632 {
633 debug_printf( "%s\n", __FUNCTION__ );
634
635 return FALSE;
636 }
637
638 BOOL APIENTRY
639 DrvValidateVersion(
640 ULONG ulVersion )
641 {
642 debug_printf( "%s( %u )\n", __FUNCTION__, ulVersion );
643
644 return ulVersion == 1;
645 }