1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "util/u_debug.h"
29 #include "stw_pixelformat.h"
30 #include "stw_public.h"
33 #define MAX_PIXELFORMATS 16
35 static struct pixelformat_info pixelformats
[MAX_PIXELFORMATS
];
36 static uint pixelformat_count
= 0;
37 static uint pixelformat_extended_count
= 0;
41 add_standard_pixelformats(
42 struct pixelformat_info
**ppf
,
45 struct pixelformat_info
*pf
= *ppf
;
46 struct pixelformat_color_info color24
= { 8, 0, 8, 8, 8, 16 };
47 struct pixelformat_alpha_info alpha8
= { 8, 24 };
48 struct pixelformat_alpha_info noalpha
= { 0, 0 };
49 struct pixelformat_depth_info depth24s8
= { 24, 8 };
50 struct pixelformat_depth_info depth16
= { 16, 0 };
52 pf
->flags
= PF_FLAG_DOUBLEBUFFER
| flags
;
58 pf
->flags
= PF_FLAG_DOUBLEBUFFER
| flags
;
61 pf
->depth
= depth24s8
;
64 pf
->flags
= PF_FLAG_DOUBLEBUFFER
| flags
;
70 pf
->flags
= PF_FLAG_DOUBLEBUFFER
| flags
;
73 pf
->depth
= depth24s8
;
85 pf
->depth
= depth24s8
;
97 pf
->depth
= depth24s8
;
104 pixelformat_init( void )
106 struct pixelformat_info
*pf
= pixelformats
;
108 add_standard_pixelformats( &pf
, 0 );
109 pixelformat_count
= pf
- pixelformats
;
111 add_standard_pixelformats( &pf
, PF_FLAG_MULTISAMPLED
);
112 pixelformat_extended_count
= pf
- pixelformats
;
114 assert( pixelformat_extended_count
<= MAX_PIXELFORMATS
);
118 pixelformat_get_count( void )
120 return pixelformat_count
;
124 pixelformat_get_extended_count( void )
126 return pixelformat_extended_count
;
129 const struct pixelformat_info
*
130 pixelformat_get_info( uint index
)
132 assert( index
< pixelformat_extended_count
);
134 return &pixelformats
[index
];
139 stw_pixelformat_describe(
143 LPPIXELFORMATDESCRIPTOR ppfd
)
147 const struct pixelformat_info
*pf
;
151 count
= pixelformat_get_extended_count();
152 index
= (uint
) iPixelFormat
- 1;
156 if (index
>= count
|| nBytes
!= sizeof( PIXELFORMATDESCRIPTOR
))
159 pf
= pixelformat_get_info( index
);
161 ppfd
->nSize
= sizeof( PIXELFORMATDESCRIPTOR
);
163 ppfd
->dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
164 if (pf
->flags
& PF_FLAG_DOUBLEBUFFER
)
165 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
| PFD_SWAP_COPY
;
166 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
167 ppfd
->cColorBits
= pf
->color
.redbits
+ pf
->color
.greenbits
+ pf
->color
.bluebits
;
168 ppfd
->cRedBits
= pf
->color
.redbits
;
169 ppfd
->cRedShift
= pf
->color
.redshift
;
170 ppfd
->cGreenBits
= pf
->color
.greenbits
;
171 ppfd
->cGreenShift
= pf
->color
.greenshift
;
172 ppfd
->cBlueBits
= pf
->color
.bluebits
;
173 ppfd
->cBlueShift
= pf
->color
.blueshift
;
174 ppfd
->cAlphaBits
= pf
->alpha
.alphabits
;
175 ppfd
->cAlphaShift
= pf
->alpha
.alphashift
;
176 ppfd
->cAccumBits
= 0;
177 ppfd
->cAccumRedBits
= 0;
178 ppfd
->cAccumGreenBits
= 0;
179 ppfd
->cAccumBlueBits
= 0;
180 ppfd
->cAccumAlphaBits
= 0;
181 ppfd
->cDepthBits
= pf
->depth
.depthbits
;
182 ppfd
->cStencilBits
= pf
->depth
.stencilbits
;
183 ppfd
->cAuxBuffers
= 0;
184 ppfd
->iLayerType
= 0;
186 ppfd
->dwLayerMask
= 0;
187 ppfd
->dwVisibleMask
= 0;
188 ppfd
->dwDamageMask
= 0;
193 /* Only used by the wgl code, but have it here to avoid exporting the
194 * pixelformat.h functionality.
196 int stw_pixelformat_choose( HDC hdc
,
197 CONST PIXELFORMATDESCRIPTOR
*ppfd
)
206 count
= pixelformat_get_count();
208 bestdelta
= 0xffffffff;
210 for (index
= 0; index
< count
; index
++) {
212 const struct pixelformat_info
*pf
= pixelformat_get_info( index
);
214 if (!(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) &&
215 !!(ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) !=
216 !!(pf
->flags
& PF_FLAG_DOUBLEBUFFER
))
219 if (ppfd
->cColorBits
!= pf
->color
.redbits
+ pf
->color
.greenbits
+ pf
->color
.bluebits
)
222 if (ppfd
->cDepthBits
!= pf
->depth
.depthbits
)
225 if (ppfd
->cStencilBits
!= pf
->depth
.stencilbits
)
228 if (ppfd
->cAlphaBits
!= pf
->alpha
.alphabits
)
231 if (delta
< bestdelta
) {
239 if (bestindex
== count
)
242 return bestindex
+ 1;
250 return stw_tls_get_data()->currentPixelFormat
;
264 index
= (uint
) iPixelFormat
- 1;
265 count
= pixelformat_get_extended_count();
269 stw_tls_get_data()->currentPixelFormat
= iPixelFormat
;
271 /* Some applications mistakenly use the undocumented wglSetPixelFormat
272 * function instead of SetPixelFormat, so we call SetPixelFormat here to
273 * avoid opengl32.dll's wglCreateContext to fail */
274 if (GetPixelFormat(hdc
) == 0) {
275 SetPixelFormat(hdc
, iPixelFormat
, NULL
);
283 /* XXX: this needs to be turned into queries on pipe_screen or
287 stw_query_sample_buffers( void )
293 stw_query_samples( void )