2 /* Copyright (c) Nate Robins, 1997. */
4 /* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
10 #include "win32_glx.h"
12 /* global current HDC */
16 glXCreateContext(Display
* display
, XVisualInfo
* visinfo
,
17 GLXContext share
, Bool direct
)
19 /* KLUDGE: GLX really expects a display pointer to be passed
20 in as the first parameter, but Win32 needs an HDC instead,
21 so BE SURE that the global XHDC is set before calling this
25 context
= CreateContext(XHDC
);
28 /* XXX GLUT doesn't support it now, so don't worry about display list
29 and texture object sharing. */
31 wglShareLists(share
, context
);
35 /* Since direct rendering is implicit, the direct flag is
42 glXGetConfig(Display
* display
, XVisualInfo
* visual
, int attrib
, int *value
)
45 return GLX_BAD_VISUAL
;
49 if (visual
->dwFlags
& (PFD_SUPPORT_OPENGL
| PFD_DRAW_TO_WINDOW
)) {
50 /* XXX Brad's Matrix Millenium II has problems creating
51 color index windows in 24-bit mode (lead to GDI crash)
52 and 32-bit mode (lead to black window). The cColorBits
53 filed of the PIXELFORMATDESCRIPTOR returned claims to
54 have 24 and 32 bits respectively of color indices. 2^24
55 and 2^32 are ridiculously huge writable colormaps.
56 Assume that if we get back a color index
57 PIXELFORMATDESCRIPTOR with 24 or more bits, the
58 PIXELFORMATDESCRIPTOR doesn't really work and skip it.
60 if (visual
->iPixelType
== PFD_TYPE_COLORINDEX
61 && visual
->cColorBits
>= 24) {
71 /* KLUDGE: if we're RGBA, return the number of bits/pixel,
72 otherwise, return 8 (we guessed at 256 colors in CI
74 if (visual
->iPixelType
== PFD_TYPE_RGBA
)
75 *value
= visual
->cColorBits
;
80 /* The bReserved flag of the pfd contains the
81 overlay/underlay info. */
82 *value
= visual
->bReserved
;
85 *value
= visual
->iPixelType
== PFD_TYPE_RGBA
;
87 case GLX_DOUBLEBUFFER
:
88 *value
= visual
->dwFlags
& PFD_DOUBLEBUFFER
;
91 *value
= visual
->dwFlags
& PFD_STEREO
;
94 *value
= visual
->cAuxBuffers
;
97 *value
= visual
->cRedBits
;
100 *value
= visual
->cGreenBits
;
103 *value
= visual
->cBlueBits
;
106 *value
= visual
->cAlphaBits
;
109 *value
= visual
->cDepthBits
;
111 case GLX_STENCIL_SIZE
:
112 *value
= visual
->cStencilBits
;
114 case GLX_ACCUM_RED_SIZE
:
115 *value
= visual
->cAccumRedBits
;
117 case GLX_ACCUM_GREEN_SIZE
:
118 *value
= visual
->cAccumGreenBits
;
120 case GLX_ACCUM_BLUE_SIZE
:
121 *value
= visual
->cAccumBlueBits
;
123 case GLX_ACCUM_ALPHA_SIZE
:
124 *value
= visual
->cAccumAlphaBits
;
127 return GLX_BAD_ATTRIB
;
133 glXChooseVisual(Display
* display
, int screen
, int *attribList
)
135 /* KLUDGE: since we need the HDC, MAKE SURE to set XHDC
136 before calling this routine. */
140 PIXELFORMATDESCRIPTOR pfd
;
141 PIXELFORMATDESCRIPTOR
*match
= NULL
;
144 /* Avoid seg-faults. */
148 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
149 pfd
.nSize
= (sizeof(PIXELFORMATDESCRIPTOR
));
153 pfd
.dwFlags
= PFD_SUPPORT_OPENGL
| PFD_DRAW_TO_WINDOW
;
154 pfd
.iPixelType
= PFD_TYPE_COLORINDEX
;
161 pfd
.dwFlags
|= PFD_SUPPORT_OPENGL
;
163 case GLX_BUFFER_SIZE
:
164 pfd
.cColorBits
= *(++p
);
167 /* the bReserved flag of the pfd contains the
168 overlay/underlay info. */
169 pfd
.bReserved
= *(++p
);
172 pfd
.iPixelType
= PFD_TYPE_RGBA
;
174 case GLX_DOUBLEBUFFER
:
175 pfd
.dwFlags
|= PFD_DOUBLEBUFFER
;
179 pfd
.dwFlags
|= PFD_STEREO
;
181 case GLX_AUX_BUFFERS
:
182 pfd
.cAuxBuffers
= *(++p
);
185 pfd
.cRedBits
= 8; /* Try to get the maximum. */
204 case GLX_STENCIL_SIZE
:
205 pfd
.cStencilBits
= *(++p
);
207 case GLX_ACCUM_RED_SIZE
:
208 case GLX_ACCUM_GREEN_SIZE
:
209 case GLX_ACCUM_BLUE_SIZE
:
210 case GLX_ACCUM_ALPHA_SIZE
:
211 /* I believe that WGL only used the cAccumRedBits,
212 cAccumBlueBits, cAccumGreenBits, and cAccumAlphaBits fields
213 when returning info about the accumulation buffer precision.
214 Only cAccumBits is used for requesting an accumulation
223 /* Let Win32 choose one for us. */
224 pf
= ChoosePixelFormat(XHDC
, &pfd
);
226 match
= (PIXELFORMATDESCRIPTOR
*) malloc(sizeof(PIXELFORMATDESCRIPTOR
));
227 DescribePixelFormat(XHDC
, pf
, sizeof(PIXELFORMATDESCRIPTOR
), match
);
229 /* ChoosePixelFormat is dumb in that it will return a pixel
230 format that doesn't have stereo even if it was requested
231 so we need to make sure that if stereo was selected, we
234 if (!(match
->dwFlags
& PFD_STEREO
)) {
239 /* XXX Brad's Matrix Millenium II has problems creating
240 color index windows in 24-bit mode (lead to GDI crash)
241 and 32-bit mode (lead to black window). The cColorBits
242 filed of the PIXELFORMATDESCRIPTOR returned claims to
243 have 24 and 32 bits respectively of color indices. 2^24
244 and 2^32 are ridiculously huge writable colormaps.
245 Assume that if we get back a color index
246 PIXELFORMATDESCRIPTOR with 24 or more bits, the
247 PIXELFORMATDESCRIPTOR doesn't really work and skip it.
249 if (match
->iPixelType
== PFD_TYPE_COLORINDEX
250 && match
->cColorBits
>= 24) {