2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(opengl
);
40 #define XMD_H /* This is to prevent the Xmd.h inclusion bug :-/ */
47 #ifdef HAVE_GL_GLEXT_H
48 # include <GL/glext.h>
56 /* Redefines the constants */
57 #define CALLBACK __stdcall
58 #define WINAPI __stdcall
59 #define APIENTRY WINAPI
62 static void dump_PIXELFORMATDESCRIPTOR(PIXELFORMATDESCRIPTOR
*ppfd
) {
63 DPRINTF(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
64 DPRINTF(" - dwFlags : ");
65 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) DPRINTF(#tv " ")
66 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
67 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
68 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
69 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
70 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
71 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
72 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
73 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
74 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
75 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
76 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
77 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
78 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
79 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
80 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
81 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
85 DPRINTF(" - iPixelType : ");
86 switch (ppfd
->iPixelType
) {
87 case PFD_TYPE_RGBA
: DPRINTF("PFD_TYPE_RGBA"); break;
88 case PFD_TYPE_COLORINDEX
: DPRINTF("PFD_TYPE_COLORINDEX"); break;
92 DPRINTF(" - Color : %d\n", ppfd
->cColorBits
);
93 DPRINTF(" - Alpha : %d\n", ppfd
->cAlphaBits
);
94 DPRINTF(" - Accum : %d\n", ppfd
->cAccumBits
);
95 DPRINTF(" - Depth : %d\n", ppfd
->cDepthBits
);
96 DPRINTF(" - Stencil : %d\n", ppfd
->cStencilBits
);
97 DPRINTF(" - Aux : %d\n", ppfd
->cAuxBuffers
);
99 DPRINTF(" - iLayerType : ");
100 switch (ppfd
->iLayerType
) {
101 case PFD_MAIN_PLANE
: DPRINTF("PFD_MAIN_PLANE"); break;
102 case PFD_OVERLAY_PLANE
: DPRINTF("PFD_OVERLAY_PLANE"); break;
103 case PFD_UNDERLAY_PLANE
: DPRINTF("PFD_UNDERLAY_PLANE"); break;
108 /* X11DRV_ChoosePixelFormat
110 Equivalent of glXChooseVisual
112 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
113 const PIXELFORMATDESCRIPTOR
*ppfd
) {
114 #define TEST_AND_ADD1(t,a) if (t) att_list[att_pos++] = a
115 #define TEST_AND_ADD2(t,a,b) if (t) { att_list[att_pos++] = a; att_list[att_pos++] = b; }
116 #define NULL_TEST_AND_ADD2(tv,a,b) att_list[att_pos++] = a; att_list[att_pos++] = ((tv) == 0 ? 0 : b)
117 #define ADD2(a,b) att_list[att_pos++] = a; att_list[att_pos++] = b
124 if (TRACE_ON(opengl
)) {
125 TRACE("(%p,%p)\n", physDev
, ppfd
);
127 dump_PIXELFORMATDESCRIPTOR((PIXELFORMATDESCRIPTOR
*) ppfd
);
130 if (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) {
131 ERR("Flag not supported !\n");
132 /* Should SetError here... */
136 /* Now, build the request to GLX */
137 TEST_AND_ADD1(ppfd
->dwFlags
& PFD_DOUBLEBUFFER
, GLX_DOUBLEBUFFER
);
138 TEST_AND_ADD1(ppfd
->dwFlags
& PFD_STEREO
, GLX_STEREO
);
139 TEST_AND_ADD1(ppfd
->iPixelType
== PFD_TYPE_RGBA
, GLX_RGBA
);
140 TEST_AND_ADD2(ppfd
->iPixelType
== PFD_TYPE_COLORINDEX
, GLX_BUFFER_SIZE
, ppfd
->cColorBits
);
142 NULL_TEST_AND_ADD2(ppfd
->cDepthBits
, GLX_DEPTH_SIZE
, 8);
143 /* These flags are not supported yet...
145 NULL_TEST_AND_ADD2(ppfd->cAlphaBits, GLX_ALPHA_SIZE, 8);
146 ADD2(GLX_ACCUM_SIZE, ppfd->cAccumBits); */
147 ADD2(GLX_STENCIL_SIZE
, ppfd
->cStencilBits
); /* now suported */
148 /* ADD2(GLX_AUX_BUFFERS, ppfd->cAuxBuffers); */
149 att_list
[att_pos
] = None
;
153 This command cannot be used as we need to use the default visual...
154 Let's hope it at least contains some OpenGL functionnalities
156 vis = glXChooseVisual(gdi_display, DefaultScreen(gdi_display), att_list);
159 XVisualInfo
template;
161 template.visualid
= XVisualIDFromVisual(visual
);
162 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
164 TRACE("Found visual : %p - returns %d\n", vis
, physDev
->used_visuals
+ 1);
169 ERR("No visual found !\n");
170 /* Should SetError here... */
173 /* try to find the visualid in the already created visuals */
174 for( i
=0; i
<physDev
->used_visuals
; i
++ ) {
175 if ( vis
->visualid
== physDev
->visuals
[i
]->visualid
) {
180 /* now give up, if the maximum is reached */
181 if (physDev
->used_visuals
== MAX_PIXELFORMATS
) {
182 ERR("Maximum number of visuals reached !\n");
183 /* Should SetError here... */
186 physDev
->visuals
[physDev
->used_visuals
++] = vis
;
188 return physDev
->used_visuals
;
191 /* X11DRV_DescribePixelFormat
193 Get the pixel-format descriptor associated to the given id
195 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
198 PIXELFORMATDESCRIPTOR
*ppfd
) {
203 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
206 /* The application is only querying the number of visuals */
207 return MAX_PIXELFORMATS
;
210 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
211 ERR("Wrong structure size !\n");
212 /* Should set error */
215 if ((iPixelFormat
> MAX_PIXELFORMATS
) ||
216 (iPixelFormat
> physDev
->used_visuals
+ 1) ||
217 (iPixelFormat
<= 0)) {
218 ERR("Wrong pixel format !\n");
219 /* Should set error */
223 if (iPixelFormat
== physDev
->used_visuals
+ 1) {
224 int dblBuf
[]={GLX_RGBA
,GLX_DEPTH_SIZE
,16,GLX_DOUBLEBUFFER
,None
};
226 /* Create a 'standard' X Visual */
228 vis
= glXChooseVisual(gdi_display
, DefaultScreen(gdi_display
), dblBuf
);
231 WARN("Uninitialized Visual. Creating standard (%p) !\n", vis
);
234 ERR("Could not create standard visual !\n");
235 /* Should set error */
239 physDev
->visuals
[physDev
->used_visuals
++] = vis
;
241 vis
= physDev
->visuals
[iPixelFormat
- 1];
243 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
244 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
247 /* These flags are always the same... */
248 ppfd
->dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_GENERIC_ACCELERATED
;
249 /* Now the flags extraced from the Visual */
251 glXGetConfig(gdi_display
, vis
, GLX_DOUBLEBUFFER
, &value
); if (value
) ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
252 glXGetConfig(gdi_display
, vis
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
255 glXGetConfig(gdi_display
, vis
, GLX_RGBA
, &value
);
257 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
259 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
262 glXGetConfig(gdi_display
, vis
, GLX_BUFFER_SIZE
, &value
);
263 ppfd
->cColorBits
= value
;
265 /* Red, green, blue and alpha bits / shifts */
266 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
267 glXGetConfig(gdi_display
, vis
, GLX_RED_SIZE
, &rb
);
268 glXGetConfig(gdi_display
, vis
, GLX_GREEN_SIZE
, &gb
);
269 glXGetConfig(gdi_display
, vis
, GLX_BLUE_SIZE
, &bb
);
270 glXGetConfig(gdi_display
, vis
, GLX_ALPHA_SIZE
, &ab
);
273 ppfd
->cRedShift
= gb
+ bb
+ ab
;
274 ppfd
->cBlueBits
= bb
;
275 ppfd
->cBlueShift
= ab
;
276 ppfd
->cGreenBits
= gb
;
277 ppfd
->cGreenShift
= bb
+ ab
;
278 ppfd
->cAlphaBits
= ab
;
279 ppfd
->cAlphaShift
= 0;
284 ppfd
->cBlueShift
= 0;
285 ppfd
->cGreenBits
= 0;
286 ppfd
->cGreenShift
= 0;
287 ppfd
->cAlphaBits
= 0;
288 ppfd
->cAlphaShift
= 0;
290 /* Accums : to do ... */
293 glXGetConfig(gdi_display
, vis
, GLX_DEPTH_SIZE
, &value
);
294 ppfd
->cDepthBits
= value
;
297 glXGetConfig( gdi_display
, vis
, GLX_STENCIL_SIZE
, &value
);
298 ppfd
->cStencilBits
= value
;
302 /* Aux : to do ... */
304 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
306 if (TRACE_ON(opengl
)) {
307 dump_PIXELFORMATDESCRIPTOR(ppfd
);
310 return MAX_PIXELFORMATS
;
313 /* X11DRV_GetPixelFormat
315 Get the pixel-format id used by this DC
317 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
318 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
320 return physDev
->current_pf
;
323 /* X11DRV_SetPixelFormat
325 Set the pixel-format id used by this DC
327 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
329 const PIXELFORMATDESCRIPTOR
*ppfd
) {
330 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
332 physDev
->current_pf
= iPixelFormat
;
337 /* X11DRV_SwapBuffers
339 Swap the buffers of this DC
341 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
342 TRACE("(%p)\n", physDev
);
345 glXSwapBuffers(gdi_display
, physDev
->drawable
);
351 /***********************************************************************
352 * X11DRV_setup_opengl_visual
354 * Setup the default visual used for OpenGL and Direct3D, and the desktop
355 * window (if it exists). If OpenGL isn't available, the visual is simply
356 * set to the default visual for the display
358 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
360 int err_base
, evt_base
;
361 XVisualInfo
*visual
= NULL
;
363 /* In order to support OpenGL or D3D, we require a double-buffered
366 if (glXQueryExtension(display
, &err_base
, &evt_base
) == True
)
368 int dblBuf
[]={GLX_RGBA
,GLX_DEPTH_SIZE
,16,GLX_DOUBLEBUFFER
,None
};
369 visual
= glXChooseVisual(display
, DefaultScreen(display
), dblBuf
);
375 #else /* defined(HAVE_OPENGL) */
377 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
378 const PIXELFORMATDESCRIPTOR
*ppfd
) {
379 ERR("No OpenGL support compiled in.\n");
384 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
387 PIXELFORMATDESCRIPTOR
*ppfd
) {
388 ERR("No OpenGL support compiled in.\n");
393 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
394 ERR("No OpenGL support compiled in.\n");
399 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
401 const PIXELFORMATDESCRIPTOR
*ppfd
) {
402 ERR("No OpenGL support compiled in.\n");
407 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
408 ERR("No OpenGL support compiled in.\n");
413 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
418 #endif /* defined(HAVE_OPENGL) */