2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
38 WINE_DECLARE_DEBUG_CHANNEL(opengl
);
40 #if defined(HAVE_GL_GL_H) && defined(HAVE_GL_GLX_H)
52 #ifdef HAVE_GL_GLEXT_H
53 # include <GL/glext.h>
62 /* Redefines the constants */
63 #define CALLBACK __stdcall
64 #define WINAPI __stdcall
65 #define APIENTRY WINAPI
68 WINE_DECLARE_DEBUG_CHANNEL(fps
);
70 typedef struct wine_glcontext
{
77 struct wine_glcontext
*next
;
78 struct wine_glcontext
*prev
;
81 typedef struct wine_glpbuffer
{
90 int use_render_texture
;
91 GLuint texture_target
;
92 GLuint texture_bind_target
;
101 typedef struct wine_glextension
{
104 const char *funcName
;
110 const char *glVersion
;
111 const char *glExtensions
;
115 const char *glxServerVersion
;
116 const char *glxServerExtensions
;
118 const char *glxClientVersion
;
119 const char *glxClientExtensions
;
121 const char *glxExtensions
;
124 char wglExtensions
[4096];
127 typedef struct wine_glpixelformat
{
133 static Wine_GLContext
*context_list
;
134 static struct WineGLInfo WineGLInfo
= { 0 };
135 static int use_render_texture_emulation
= 0;
136 static int use_render_texture_ati
= 0;
137 static int swap_interval
= 1;
139 #define MAX_EXTENSIONS 16
140 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
141 static int WineGLExtensionListSize
;
143 #define MAX_GLPIXELFORMATS 32
144 static WineGLPixelFormat WineGLPixelFormatList
[MAX_GLPIXELFORMATS
];
145 static int WineGLPixelFormatListSize
= 0;
147 static void X11DRV_WineGL_LoadExtensions(void);
149 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
150 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
151 TRACE(" - dwFlags : ");
152 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
153 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
154 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
155 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
156 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
157 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
158 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
159 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
160 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
161 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
162 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
163 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
164 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
165 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
166 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
172 TRACE(" - iPixelType : ");
173 switch (ppfd
->iPixelType
) {
174 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
175 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
179 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
180 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
181 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
182 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
183 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
184 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
185 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
186 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
187 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
189 TRACE(" - iLayerType : ");
190 switch (ppfd
->iLayerType
) {
191 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
192 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
193 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
198 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and
199 include all dependencies
202 #define SONAME_LIBGL "libGL.so"
205 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
206 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
208 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
210 MAKE_FUNCPTR(glXChooseVisual
)
211 MAKE_FUNCPTR(glXCreateContext
)
212 MAKE_FUNCPTR(glXCreateGLXPixmap
)
213 MAKE_FUNCPTR(glXGetCurrentContext
)
214 MAKE_FUNCPTR(glXDestroyContext
)
215 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
216 MAKE_FUNCPTR(glXGetConfig
)
217 MAKE_FUNCPTR(glXIsDirect
)
218 MAKE_FUNCPTR(glXMakeCurrent
)
219 MAKE_FUNCPTR(glXSwapBuffers
)
220 MAKE_FUNCPTR(glXQueryExtension
)
221 MAKE_FUNCPTR(glXQueryVersion
)
222 MAKE_FUNCPTR(glXUseXFont
)
225 MAKE_FUNCPTR(glXGetClientString
)
226 MAKE_FUNCPTR(glXQueryExtensionsString
)
227 MAKE_FUNCPTR(glXQueryServerString
)
230 MAKE_FUNCPTR(glXGetFBConfigs
)
231 MAKE_FUNCPTR(glXChooseFBConfig
)
232 MAKE_FUNCPTR(glXCreatePbuffer
)
233 MAKE_FUNCPTR(glXDestroyPbuffer
)
234 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
235 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
236 MAKE_FUNCPTR(glXMakeContextCurrent
)
237 MAKE_FUNCPTR(glXQueryDrawable
)
238 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
241 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
242 static BOOL (*pglXBindTexImageARB
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
243 static BOOL (*pglXReleaseTexImageARB
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
244 static BOOL (*pglXDrawableAttribARB
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
245 static int (*pglXSwapIntervalSGI
)(int);
247 /* Standard OpenGL */
248 MAKE_FUNCPTR(glBindTexture
)
249 MAKE_FUNCPTR(glBitmap
)
250 MAKE_FUNCPTR(glCopyTexSubImage1D
)
251 MAKE_FUNCPTR(glCopyTexSubImage2D
)
252 MAKE_FUNCPTR(glDrawBuffer
)
253 MAKE_FUNCPTR(glEndList
)
254 MAKE_FUNCPTR(glGetError
)
255 MAKE_FUNCPTR(glGetIntegerv
)
256 MAKE_FUNCPTR(glGetString
)
257 MAKE_FUNCPTR(glNewList
)
258 MAKE_FUNCPTR(glPixelStorei
)
261 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
263 static BOOL infoInitialized
= FALSE
;
265 int screen
= DefaultScreen(gdi_display
);
266 Window win
= RootWindow(gdi_display
, screen
);
268 XVisualInfo
template;
271 GLXContext ctx
= NULL
;
275 infoInitialized
= TRUE
;
279 visual
= DefaultVisual(gdi_display
, screen
);
280 template.visualid
= XVisualIDFromVisual(visual
);
281 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
283 /* Create a GLX Context. Without one we can't query GL information */
284 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
288 pglXMakeCurrent(gdi_display
, win
, ctx
);
290 ERR(" couldn't initialize OpenGL, expect problems\n");
295 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
296 WineGLInfo
.glExtensions
= (const char *) pglGetString(GL_EXTENSIONS
);
298 /* Get the common GLX version supported by GLX client and server ( major/minor) */
299 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
301 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
302 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
304 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
305 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
307 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
308 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
310 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
311 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
312 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
313 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
314 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
318 pglXMakeCurrent(gdi_display
, None
, NULL
);
319 pglXDestroyContext(gdi_display
, ctx
);
325 static BOOL
has_opengl(void)
327 static int init_done
;
328 static void *opengl_handle
;
329 const char *glx_extensions
;
331 int error_base
, event_base
;
333 if (init_done
) return (opengl_handle
!= NULL
);
336 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0);
337 if (opengl_handle
== NULL
) return FALSE
;
339 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
340 if (pglXGetProcAddressARB
== NULL
) {
341 ERR("could not find glXGetProcAddressARB in libGL.\n");
345 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
347 LOAD_FUNCPTR(glXChooseVisual
)
348 LOAD_FUNCPTR(glXCreateContext
)
349 LOAD_FUNCPTR(glXCreateGLXPixmap
)
350 LOAD_FUNCPTR(glXGetCurrentContext
)
351 LOAD_FUNCPTR(glXDestroyContext
)
352 LOAD_FUNCPTR(glXDestroyGLXPixmap
)
353 LOAD_FUNCPTR(glXGetConfig
)
354 LOAD_FUNCPTR(glXIsDirect
)
355 LOAD_FUNCPTR(glXMakeCurrent
)
356 LOAD_FUNCPTR(glXSwapBuffers
)
357 LOAD_FUNCPTR(glXQueryExtension
)
358 LOAD_FUNCPTR(glXQueryVersion
)
359 LOAD_FUNCPTR(glXUseXFont
)
362 LOAD_FUNCPTR(glXGetClientString
)
363 LOAD_FUNCPTR(glXQueryExtensionsString
)
364 LOAD_FUNCPTR(glXQueryServerString
)
367 LOAD_FUNCPTR(glXCreatePbuffer
)
368 LOAD_FUNCPTR(glXDestroyPbuffer
)
369 LOAD_FUNCPTR(glXMakeContextCurrent
)
370 LOAD_FUNCPTR(glXGetCurrentReadDrawable
)
371 LOAD_FUNCPTR(glXGetFBConfigs
)
373 /* Standard OpenGL calls */
374 LOAD_FUNCPTR(glBindTexture
)
375 LOAD_FUNCPTR(glBitmap
)
376 LOAD_FUNCPTR(glEndList
)
377 LOAD_FUNCPTR(glCopyTexSubImage1D
)
378 LOAD_FUNCPTR(glCopyTexSubImage2D
)
379 LOAD_FUNCPTR(glDrawBuffer
)
380 LOAD_FUNCPTR(glGetError
)
381 LOAD_FUNCPTR(glGetIntegerv
)
382 LOAD_FUNCPTR(glGetString
)
383 LOAD_FUNCPTR(glNewList
)
384 LOAD_FUNCPTR(glPixelStorei
)
387 if(!X11DRV_WineGL_InitOpenglInfo()) {
388 ERR("Intialization of OpenGL info failed, disabling OpenGL!\n");
389 wine_dlclose(opengl_handle
, NULL
, 0);
390 opengl_handle
= NULL
;
395 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
) == True
) {
396 TRACE("GLX is up and running error_base = %d\n", error_base
);
398 wine_dlclose(opengl_handle
, NULL
, 0);
399 opengl_handle
= NULL
;
402 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
403 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
406 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
407 * depends on the reported GLX client / server version and on the client / server extension list.
408 * Those don't have to be the same.
410 * In general the server GLX information should be used in case of indirect rendering. When direct
411 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
412 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
413 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
414 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
415 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
416 * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
417 * is only available in the list of server extensions and not in the client list.
419 * The versioning checks below try to take into account the comments from above.
422 /* Depending on the use of direct or indirect rendering we need either the list of extensions
423 * exported by the client or by the server.
425 if(WineGLInfo
.glxDirect
)
426 glx_extensions
= WineGLInfo
.glxClientExtensions
;
428 glx_extensions
= WineGLInfo
.glxServerExtensions
;
430 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
431 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
432 * the client version is checked.
434 if ((!WineGLInfo
.glxDirect
&& !strcmp("1.2", WineGLInfo
.glxServerVersion
)) ||
435 (WineGLInfo
.glxDirect
&& !strcmp("1.2", WineGLInfo
.glxClientVersion
)))
437 if (NULL
!= strstr(glx_extensions
, "GLX_SGIX_fbconfig")) {
438 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
439 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
440 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
442 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxClientVersion
);
445 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
446 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
447 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
450 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
451 * enable this function when the Xserver understand GLX 1.3 or newer
453 if (!strcmp("1.2", WineGLInfo
.glxServerVersion
))
454 pglXQueryDrawable
= NULL
;
456 pglXQueryDrawable
= wine_dlsym(RTLD_DEFAULT
, "glXQueryDrawable", NULL
, 0);
458 if (NULL
!= strstr(glx_extensions
, "GLX_ATI_render_texture")) {
459 pglXBindTexImageARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageARB");
460 pglXReleaseTexImageARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageARB");
461 pglXDrawableAttribARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribARB");
464 X11DRV_WineGL_LoadExtensions();
467 return (opengl_handle
!= NULL
);
470 wine_dlclose(opengl_handle
, NULL
, 0);
471 opengl_handle
= NULL
;
475 static inline Wine_GLContext
*alloc_context(void)
479 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
481 ret
->next
= context_list
;
482 if (context_list
) context_list
->prev
= ret
;
488 static inline void free_context(Wine_GLContext
*context
)
490 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
491 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
492 else context_list
= context
->next
;
494 HeapFree(GetProcessHeap(), 0, context
);
497 static inline Wine_GLContext
*get_context_from_GLXContext(GLXContext ctx
)
500 if (!ctx
) return NULL
;
501 for (ret
= context_list
; ret
; ret
= ret
->next
) if (ctx
== ret
->ctx
) break;
506 * get_drawable (internal)
508 * Retrieve the GLX drawable to use on a given DC.
510 inline static Drawable
get_drawable( HDC hdc
)
512 GLXDrawable drawable
;
513 enum x11drv_escape_codes escape
= X11DRV_GET_GLX_DRAWABLE
;
515 if (!ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPCSTR
)&escape
,
516 sizeof(drawable
), (LPSTR
)&drawable
)) drawable
= 0;
520 inline static void set_drawable( HDC hdc
, Drawable drawable
)
522 struct x11drv_escape_set_drawable escape
;
524 escape
.code
= X11DRV_SET_DRAWABLE
;
525 escape
.drawable
= drawable
;
526 escape
.mode
= IncludeInferiors
;
527 escape
.org
.x
= escape
.org
.y
= 0;
528 escape
.drawable_org
.x
= escape
.drawable_org
.y
= 0;
530 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPCSTR
)&escape
, 0, NULL
);
534 * get_hdc_from_Drawable (internal)
536 * For use by wglGetCurrentReadDCARB.
538 inline static HDC
get_hdc_from_Drawable(GLXDrawable d
)
541 for (ret
= context_list
; ret
; ret
= ret
->next
) {
542 if (d
== get_drawable( ret
->hdc
)) {
549 inline static BOOL
is_valid_context( Wine_GLContext
*ctx
)
552 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
553 return (ptr
!= NULL
);
556 static int describeContext(Wine_GLContext
* ctx
) {
559 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
560 pglXGetFBConfigAttrib(ctx
->display
, ctx
->fb_conf
, GLX_FBCONFIG_ID
, &tmp
);
561 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
562 pglXGetFBConfigAttrib(ctx
->display
, ctx
->fb_conf
, GLX_VISUAL_ID
, &tmp
);
563 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
568 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
571 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
574 if (pglXQueryDrawable
== NULL
) {
575 /** glXQueryDrawable not available so returns not supported */
579 TRACE(" Drawable %p have :\n", (void*) drawable
);
580 pglXQueryDrawable(ctx
->display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
581 TRACE(" - WIDTH as %d\n", tmp
);
582 pglXQueryDrawable(ctx
->display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
583 TRACE(" - HEIGHT as %d\n", tmp
);
584 pglXQueryDrawable(ctx
->display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
585 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
588 fbCfgs
= pglXChooseFBConfig(ctx
->display
, DefaultScreen(ctx
->display
), attribList
, &nElements
);
589 if (fbCfgs
== NULL
) {
593 pglXGetFBConfigAttrib(ctx
->display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
594 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
601 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
606 int wantColorBits
= 0;
609 while (0 != iWGLAttr
[cur
]) {
610 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
612 switch (iWGLAttr
[cur
]) {
613 case WGL_COLOR_BITS_ARB
:
614 pop
= iWGLAttr
[++cur
];
615 wantColorBits
= pop
; /** see end */
617 case WGL_BLUE_BITS_ARB
:
618 pop
= iWGLAttr
[++cur
];
619 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
620 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
622 case WGL_RED_BITS_ARB
:
623 pop
= iWGLAttr
[++cur
];
624 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
625 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
627 case WGL_GREEN_BITS_ARB
:
628 pop
= iWGLAttr
[++cur
];
629 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
630 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
632 case WGL_ALPHA_BITS_ARB
:
633 pop
= iWGLAttr
[++cur
];
635 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
636 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
638 case WGL_DEPTH_BITS_ARB
:
639 pop
= iWGLAttr
[++cur
];
640 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
641 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
643 case WGL_STENCIL_BITS_ARB
:
644 pop
= iWGLAttr
[++cur
];
645 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
646 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
648 case WGL_DOUBLE_BUFFER_ARB
:
649 pop
= iWGLAttr
[++cur
];
650 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
651 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
654 case WGL_PIXEL_TYPE_ARB
:
655 pop
= iWGLAttr
[++cur
];
657 case WGL_TYPE_COLORINDEX_ARB
: pop
= GLX_COLOR_INDEX_BIT
; isColor
= 1; break ;
658 case WGL_TYPE_RGBA_ARB
: pop
= GLX_RGBA_BIT
; break ;
659 case WGL_TYPE_RGBA_FLOAT_ATI
: pop
= GLX_RGBA_FLOAT_ATI_BIT
; break ;
661 ERR("unexpected PixelType(%x)\n", pop
);
664 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pop
);
665 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur
, pop
);
668 case WGL_SUPPORT_GDI_ARB
:
669 pop
= iWGLAttr
[++cur
];
670 /* We only support a limited number of formats which are all renderable by X (similar to GDI).
671 * Ignore this attribute to prevent us from not finding a match due to the limited
672 * amount of formats supported right now. This option could be matched to GLX_X_RENDERABLE
673 * but the issue is that when a program asks for no GDI support, there's no format we can return
674 * as all our supported formats are renderable by X.
676 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
679 case WGL_DRAW_TO_BITMAP_ARB
:
680 pop
= iWGLAttr
[++cur
];
681 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
683 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, GLX_PIXMAP_BIT
);
684 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_PIXMAP_BIT\n", cur
);
688 case WGL_DRAW_TO_WINDOW_ARB
:
689 pop
= iWGLAttr
[++cur
];
691 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, GLX_WINDOW_BIT
);
692 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_WINDOW_BIT\n", cur
);
696 case WGL_DRAW_TO_PBUFFER_ARB
:
697 pop
= iWGLAttr
[++cur
];
699 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, GLX_PBUFFER_BIT
);
700 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_PBUFFER_BIT\n", cur
);
704 case WGL_ACCELERATION_ARB
:
705 case WGL_SUPPORT_OPENGL_ARB
:
706 pop
= iWGLAttr
[++cur
];
707 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
708 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
711 case WGL_PBUFFER_LARGEST_ARB
:
712 pop
= iWGLAttr
[++cur
];
713 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
714 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
717 case WGL_SAMPLE_BUFFERS_ARB
:
718 pop
= iWGLAttr
[++cur
];
719 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
720 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
723 case WGL_SAMPLES_ARB
:
724 pop
= iWGLAttr
[++cur
];
725 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
726 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
729 case WGL_TEXTURE_FORMAT_ARB
:
730 case WGL_TEXTURE_TARGET_ARB
:
731 case WGL_MIPMAP_TEXTURE_ARB
:
732 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
733 pop
= iWGLAttr
[++cur
];
735 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
737 if (use_render_texture_ati
) {
738 /** nothing to do here */
740 else if (!use_render_texture_emulation
) {
741 if (WGL_NO_TEXTURE_ARB
!= pop
) {
742 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
743 return -1; /** error: don't support it */
745 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
746 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, GLX_PBUFFER_BIT
);
751 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
752 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
753 pop
= iWGLAttr
[++cur
];
754 /** cannot be converted, see direct handling on
755 * - wglGetPixelFormatAttribivARB
756 * TODO: wglChoosePixelFormat
761 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
768 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
769 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
772 * The number of color bitplanes in each color buffer. For RGBA
773 * pixel types, it is the size of the color buffer, excluding the
774 * alpha bitplanes. For color-index pixels, it is the size of the
775 * color index buffer.
778 * This attribute defines the number of bits per color buffer.
779 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
780 * this is equal to the depth value reported in the X11 visual.
781 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
782 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
785 if (0 < wantColorBits
) {
787 wantColorBits
+= sz_alpha
;
789 if (32 < wantColorBits
) {
790 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits
);
793 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, wantColorBits
);
794 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur
, wantColorBits
);
800 BOOL
get_fbconfig_from_visualid(Display
*display
, Visual
*visual
, int *fmt_id
, int *fmt_index
)
802 GLXFBConfig
* cfgs
= NULL
;
809 if(!display
|| !display
) {
810 ERR("Invalid display or visual\n");
812 visualid
= XVisualIDFromVisual(visual
);
814 /* Get a list of all available framebuffer configurations */
815 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
816 if (NULL
== cfgs
|| 0 == nCfgs
) {
817 ERR("glXChooseFBConfig returns NULL\n");
818 if(cfgs
!= NULL
) XFree(cfgs
);
822 /* Find the requested offscreen format and count the number of offscreen formats */
823 for(i
=0; i
<nCfgs
; i
++) {
824 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
825 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
827 /* We are looking up the GLX index of our main visual and have found it :) */
828 if(visualid
== tmp_vis_id
) {
829 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id
, i
, tmp_vis_id
);
831 *fmt_id
= tmp_fmt_id
;
837 ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid
);
842 static BOOL
init_formats(Display
*display
, int screen
, Visual
*visual
)
844 int fmt_id
, fmt_index
;
846 /* Locate the fbconfig correspondig to our main visual */
847 if(!get_fbconfig_from_visualid(display
, visual
, &fmt_id
, &fmt_index
)) {
848 ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
852 /* Put Wine's internal format at the first index */
853 WineGLPixelFormatList
[0].iPixelFormat
= 1;
854 WineGLPixelFormatList
[0].fbconfig
= fmt_id
;
855 WineGLPixelFormatList
[0].fmt_index
= fmt_index
;
856 WineGLPixelFormatListSize
= 1;
858 /* In the future test for compatible formats here */
863 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
864 * In our WGL implementation we only support a subset of these formats namely the format of
865 * Wine's main visual and offscreen formats (if they are available).
866 * This function converts a WGL format to its corresponding GLX one. It returns the index (zero-based)
867 * into the GLX FB config table and it returns the number of supported WGL formats in fmt_count.
869 static BOOL
ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, int *fmt_index
, int *fmt_count
)
871 /* Init the list of pixel formats when we need it */
872 if(!WineGLPixelFormatListSize
)
873 init_formats(display
, DefaultScreen(display
), visual
);
875 if((iPixelFormat
<= 0) || (iPixelFormat
> WineGLPixelFormatListSize
)) {
876 ERR("invalid iPixelFormat %d\n", iPixelFormat
);
880 *fmt_index
= WineGLPixelFormatList
[iPixelFormat
-1].fmt_index
;
881 *fmt_count
= WineGLPixelFormatListSize
;
882 TRACE("Returning fmt_index=%d, fmt_count=%d for iPixelFormat=%d\n", *fmt_index
, *fmt_count
, iPixelFormat
);
887 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
888 static int ConvertPixelFormatGLXtoWGL(Display
*display
, int fbconfig
)
892 /* Init the list of pixel formats when we need it */
893 if(!WineGLPixelFormatListSize
)
894 init_formats(display
, DefaultScreen(display
), visual
);
896 for(i
=0; i
<WineGLPixelFormatListSize
; i
++) {
897 if(WineGLPixelFormatList
[i
].fbconfig
== fbconfig
) {
898 TRACE("Returning iPixelFormat %d for fbconfig 0x%x\n", WineGLPixelFormatList
[i
].iPixelFormat
, fbconfig
);
899 return WineGLPixelFormatList
[i
].iPixelFormat
;
902 TRACE("No compatible format found for FBCONFIG_ID=0x%x\n", fbconfig
);
907 * X11DRV_ChoosePixelFormat
909 * Equivalent to glXChooseVisual.
911 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
912 const PIXELFORMATDESCRIPTOR
*ppfd
) {
913 GLXFBConfig
* cfgs
= NULL
;
920 ERR("No libGL on this box - disabling OpenGL support !\n");
924 if (TRACE_ON(opengl
)) {
925 TRACE("(%p,%p)\n", physDev
, ppfd
);
927 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
932 ERR("Can't get an opengl visual!\n");
936 /* Get a list containing all supported FB configurations */
937 cfgs
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs
);
938 if (NULL
== cfgs
|| 0 == nCfgs
) {
939 ERR("glXGetFBConfigs returns NULL (glError: %d)\n", pglGetError());
943 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
944 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, 1 /* main visual */, &fmt_index
, &value
)) {
945 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual
->visualid
);
952 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_RENDER_TYPE
, &value
);
953 if (value
& GLX_RGBA_BIT
)
954 iPixelType
= PFD_TYPE_RGBA
;
956 iPixelType
= PFD_TYPE_COLORINDEX
;
958 if (ppfd
->iPixelType
!= iPixelType
) {
959 TRACE("pixel type mismatch\n");
964 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_DOUBLEBUFFER
, &value
); if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
965 if (!(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) && (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) {
966 if (!(dwFlags
& PFD_DOUBLEBUFFER
)) {
967 TRACE("dbl buffer mismatch\n");
973 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_STEREO
, &value
); if (value
) dwFlags
|= PFD_STEREO
;
974 if (!(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) && (ppfd
->dwFlags
& PFD_STEREO
)) {
975 if (!(dwFlags
& PFD_STEREO
)) {
976 TRACE("stereo mismatch\n");
982 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_ALPHA_SIZE
, &value
);
983 if (ppfd
->iPixelType
==PFD_TYPE_RGBA
&& ppfd
->cAlphaBits
&& !value
) {
984 TRACE("alpha mismatch\n");
989 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_DEPTH_SIZE
, &value
);
990 if (ppfd
->cDepthBits
&& !value
) {
991 TRACE("depth mismatch\n");
996 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_STENCIL_SIZE
, &value
);
997 if (ppfd
->cStencilBits
&& !value
) {
998 TRACE("stencil mismatch\n");
1003 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_AUX_BUFFERS
, &value
);
1004 if (ppfd
->cAuxBuffers
&& !value
) {
1005 TRACE("aux mismatch\n");
1009 /* When we pass all the checks we have found a matching format :) */
1011 TRACE("Successfully found a matching mode, returning index: %d\n", ret
);
1016 TRACE("No matching mode was found returning 0\n");
1018 if (NULL
!= cfgs
) XFree(cfgs
);
1019 wine_tsx11_unlock();
1024 * X11DRV_DescribePixelFormat
1026 * Get the pixel-format descriptor associated to the given id
1028 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1031 PIXELFORMATDESCRIPTOR
*ppfd
) {
1032 /*XVisualInfo *vis;*/
1036 GLXFBConfig
* cfgs
= NULL
;
1042 if (!has_opengl()) {
1043 ERR("No libGL on this box - disabling OpenGL support !\n");
1047 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1050 cfgs
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs
);
1051 wine_tsx11_unlock();
1053 if (NULL
== cfgs
|| 0 == nCfgs
) {
1054 ERR("unexpected iPixelFormat(%d), returns NULL\n", iPixelFormat
);
1055 return 0; /* unespected error */
1058 /* This function always reports the total number of supported pixel formats.
1059 * At the moment we only support the pixel format corresponding to the main
1060 * visual which got created at x11drv initialization. More formats could be
1061 * supported if there was a way to recreate x11 windows in x11drv.
1062 * Because we only support one format nCfgs needs to be set to 1.
1067 /* The application is only querying the number of visuals */
1069 if (NULL
!= cfgs
) XFree(cfgs
);
1070 wine_tsx11_unlock();
1074 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1075 ERR("Wrong structure size !\n");
1076 /* Should set error */
1080 if (nCfgs
< iPixelFormat
|| 1 > iPixelFormat
) {
1081 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL\n", iPixelFormat
, nCfgs
);
1085 /* Retrieve the index in the FBConfig table corresponding to the visual ID from the main visual */
1086 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, &fmt_index
, &value
)) {
1087 ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
1092 cur
= cfgs
[fmt_index
];
1094 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1095 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1098 /* These flags are always the same... */
1099 ppfd
->dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
1100 /* Now the flags extracted from the Visual */
1104 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_CONFIG_CAVEAT
, &value
);
1105 if(value
== GLX_SLOW_CONFIG
)
1106 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1108 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_DOUBLEBUFFER
, &value
); if (value
) ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1109 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1112 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_RENDER_TYPE
, &value
);
1113 if (value
& GLX_RGBA_BIT
)
1114 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1116 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1119 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_BUFFER_SIZE
, &value
);
1120 ppfd
->cColorBits
= value
;
1122 /* Red, green, blue and alpha bits / shifts */
1123 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1124 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_RED_SIZE
, &rb
);
1125 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_GREEN_SIZE
, &gb
);
1126 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_BLUE_SIZE
, &bb
);
1127 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_ALPHA_SIZE
, &ab
);
1129 ppfd
->cRedBits
= rb
;
1130 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1131 ppfd
->cBlueBits
= bb
;
1132 ppfd
->cBlueShift
= ab
;
1133 ppfd
->cGreenBits
= gb
;
1134 ppfd
->cGreenShift
= bb
+ ab
;
1135 ppfd
->cAlphaBits
= ab
;
1136 ppfd
->cAlphaShift
= 0;
1139 ppfd
->cRedShift
= 0;
1140 ppfd
->cBlueBits
= 0;
1141 ppfd
->cBlueShift
= 0;
1142 ppfd
->cGreenBits
= 0;
1143 ppfd
->cGreenShift
= 0;
1144 ppfd
->cAlphaBits
= 0;
1145 ppfd
->cAlphaShift
= 0;
1147 /* Accums : to do ... */
1150 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_DEPTH_SIZE
, &value
);
1151 ppfd
->cDepthBits
= value
;
1154 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_STENCIL_SIZE
, &value
);
1155 ppfd
->cStencilBits
= value
;
1157 wine_tsx11_unlock();
1159 /* Aux : to do ... */
1161 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1163 if (TRACE_ON(opengl
)) {
1164 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1168 if (NULL
!= cfgs
) XFree(cfgs
);
1169 wine_tsx11_unlock();
1175 * X11DRV_GetPixelFormat
1177 * Get the pixel-format id used by this DC
1179 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1180 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1182 return physDev
->current_pf
;
1186 * X11DRV_SetPixelFormat
1188 * Set the pixel-format id used by this DC
1190 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1192 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1193 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1195 if (!has_opengl()) {
1196 ERR("No libGL on this box - disabling OpenGL support !\n");
1200 /* At the moment we only support the pixelformat corresponding to the main
1201 * x11drv visual which got created at x11drv initialization. More formats
1202 * could be supported if there was a way to recreate x11 windows in x11drv
1204 if(iPixelFormat
!= 1) {
1205 TRACE("Invalid iPixelFormat: %d\n", iPixelFormat
);
1209 physDev
->current_pf
= iPixelFormat
;
1211 if (TRACE_ON(opengl
)) {
1213 GLXFBConfig
* cfgs_fmt
= NULL
;
1214 GLXFBConfig cur_cfg
;
1219 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, &fmt_index
, &value
)) {
1220 ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
1221 return TRUE
; /* Return true because the SetPixelFormat stuff itself passed */
1225 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1227 * in case of root window created HDCs we crash here :(
1229 Drawable drawable = get_drawable( physDev->hdc );
1230 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1231 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1232 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1233 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1234 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1235 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1236 TRACE(" - WIDTH as %d\n", tmp);
1237 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1238 TRACE(" - HEIGHT as %d\n", tmp);
1240 cfgs_fmt
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs_fmt
);
1241 cur_cfg
= cfgs_fmt
[fmt_index
];
1242 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cur_cfg
, GLX_FBCONFIG_ID
, &value
);
1244 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1246 TRACE(" FBConfig have :\n");
1247 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1248 pglXGetFBConfigAttrib(gdi_display
, cur_cfg
, GLX_VISUAL_ID
, &value
);
1249 TRACE(" - VISUAL_ID 0x%x\n", value
);
1250 pglXGetFBConfigAttrib(gdi_display
, cur_cfg
, GLX_DRAWABLE_TYPE
, &value
);
1251 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1259 * X11DRV_wglCreateContext
1261 * For OpenGL32 wglCreateContext.
1263 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1265 Wine_GLContext
*ret
;
1266 GLXFBConfig
* cfgs_fmt
= NULL
;
1267 GLXFBConfig cur_cfg
;
1268 int hdcPF
= 1; /* We can only use Wine's main visual which has an index of 1 */
1274 HDC hdc
= physDev
->hdc
;
1276 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1278 if (!has_opengl()) {
1279 ERR("No libGL on this box - disabling OpenGL support !\n");
1283 /* First, get the visual in use by the X11DRV */
1284 if (!gdi_display
) return 0;
1286 /* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the corresponding GLX format.
1287 * If this fails something is very wrong on the system. */
1288 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, &fmt_index
, &tmp
)) {
1289 ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n");
1290 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1294 cfgs_fmt
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs_fmt
);
1295 if (NULL
== cfgs_fmt
|| 0 == nCfgs_fmt
) {
1296 ERR("Cannot get FB Configs, expect problems.\n");
1297 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1301 if (nCfgs_fmt
< fmt_index
) {
1302 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, fmt_index
, nCfgs_fmt
);
1303 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1307 cur_cfg
= cfgs_fmt
[fmt_index
];
1308 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cur_cfg
, GLX_FBCONFIG_ID
, &value
);
1310 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1311 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1316 /* The context will be allocated in the wglMakeCurrent call */
1318 ret
= alloc_context();
1319 wine_tsx11_unlock();
1321 ret
->display
= gdi_display
;
1322 ret
->fb_conf
= cur_cfg
;
1324 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, cur_cfg
);
1326 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1331 * X11DRV_wglDeleteContext
1333 * For OpenGL32 wglDeleteContext.
1335 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1337 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1340 TRACE("(%p)\n", hglrc
);
1342 if (!has_opengl()) {
1343 ERR("No libGL on this box - disabling OpenGL support !\n");
1348 /* A game (Half Life not to name it) deletes twice the same context,
1349 * so make sure it is valid first */
1350 if (is_valid_context( ctx
))
1352 if (ctx
->ctx
) pglXDestroyContext(ctx
->display
, ctx
->ctx
);
1357 WARN("Error deleting context !\n");
1358 SetLastError(ERROR_INVALID_HANDLE
);
1361 wine_tsx11_unlock();
1367 * X11DRV_wglGetCurrentReadDCARB
1369 * For OpenGL32 wglGetCurrentReadDCARB.
1371 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1379 gl_d
= pglXGetCurrentReadDrawable();
1380 ret
= get_hdc_from_Drawable(gl_d
);
1381 wine_tsx11_unlock();
1383 TRACE(" returning %p (GL drawable %lu)\n", ret
, gl_d
);
1388 * X11DRV_wglGetProcAddress
1390 * For OpenGL32 wglGetProcAddress.
1392 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1395 const WineGLExtension
*ext
;
1397 int padding
= 32 - strlen(lpszProc
);
1401 if (!has_opengl()) {
1402 ERR("No libGL on this box - disabling OpenGL support !\n");
1406 /* Check the table of WGL extensions to see if we need to return a WGL extension
1407 * or a function pointer to a native OpenGL function. */
1408 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1409 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1411 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1412 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1413 ext
= WineGLExtensionList
[i
];
1414 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1415 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1416 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1417 return ext
->extEntryPoints
[j
].funcAddress
;
1423 ERR("(%s) - not found\n", lpszProc
);
1429 * X11DRV_wglMakeCurrent
1431 * For OpenGL32 wglMakeCurrent.
1433 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1435 HDC hdc
= physDev
->hdc
;
1436 DWORD type
= GetObjectType(hdc
);
1438 TRACE("(%p,%p)\n", hdc
, hglrc
);
1440 if (!has_opengl()) {
1441 ERR("No libGL on this box - disabling OpenGL support !\n");
1446 if (hglrc
== NULL
) {
1447 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1448 NtCurrentTeb()->glContext
= NULL
;
1450 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1451 Drawable drawable
= physDev
->drawable
;
1452 if (ctx
->ctx
== NULL
) {
1453 int draw_vis_id
, ctx_vis_id
;
1454 VisualID visualid
= (VisualID
)GetPropA( GetDesktopWindow(), "__wine_x11_visual_id" );
1455 TRACE(" Wine desktop VISUAL_ID is 0x%x\n", (unsigned int) visualid
);
1456 draw_vis_id
= describeDrawable(ctx
, drawable
);
1457 ctx_vis_id
= describeContext(ctx
);
1459 if (-1 == draw_vis_id
|| (draw_vis_id
== visualid
&& draw_vis_id
!= ctx_vis_id
)) {
1461 * Inherits from root window so reuse desktop visual
1463 XVisualInfo
template;
1466 template.visualid
= visualid
;
1467 vis
= XGetVisualInfo(ctx
->display
, VisualIDMask
, &template, &num
);
1469 TRACE(" Creating GLX Context\n");
1470 ctx
->ctx
= pglXCreateContext(ctx
->display
, vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1472 TRACE(" Creating GLX Context\n");
1473 ctx
->ctx
= pglXCreateContext(ctx
->display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1475 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1477 TRACE(" make current for dis %p, drawable %p, ctx %p\n", ctx
->display
, (void*) drawable
, ctx
->ctx
);
1478 ret
= pglXMakeCurrent(ctx
->display
, drawable
, ctx
->ctx
);
1479 NtCurrentTeb()->glContext
= ctx
;
1480 if(ret
&& type
== OBJ_MEMDC
)
1482 ctx
->do_escape
= TRUE
;
1483 pglDrawBuffer(GL_FRONT_LEFT
);
1486 wine_tsx11_unlock();
1487 TRACE(" returning %s\n", (ret
? "True" : "False"));
1492 * X11DRV_wglMakeContextCurrentARB
1494 * For OpenGL32 wglMakeContextCurrentARB
1496 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
)
1499 TRACE("(%p,%p,%p)\n", hDrawDev
, hReadDev
, hglrc
);
1501 if (!has_opengl()) {
1502 ERR("No libGL on this box - disabling OpenGL support !\n");
1507 if (hglrc
== NULL
) {
1508 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1509 NtCurrentTeb()->glContext
= NULL
;
1511 if (NULL
== pglXMakeContextCurrent
) {
1514 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1515 Drawable d_draw
= get_glxdrawable(hDrawDev
);
1516 Drawable d_read
= get_glxdrawable(hReadDev
);
1518 if (ctx
->ctx
== NULL
) {
1519 ctx
->ctx
= pglXCreateContext(ctx
->display
, ctx
->vis
, NULL
, GetObjectType(hDrawDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1520 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1522 ret
= pglXMakeContextCurrent(ctx
->display
, d_draw
, d_read
, ctx
->ctx
);
1523 NtCurrentTeb()->glContext
= ctx
;
1526 wine_tsx11_unlock();
1528 TRACE(" returning %s\n", (ret
? "True" : "False"));
1533 * X11DRV_wglShareLists
1535 * For OpenGL32 wglShaderLists.
1537 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1538 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1539 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1541 TRACE("(%p, %p)\n", org
, dest
);
1543 if (!has_opengl()) {
1544 ERR("No libGL on this box - disabling OpenGL support !\n");
1548 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1549 ERR("Could not share display lists, context already created !\n");
1552 if (org
->ctx
== NULL
) {
1554 describeContext(org
);
1555 org
->ctx
= pglXCreateContext(org
->display
, org
->vis
, NULL
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1556 wine_tsx11_unlock();
1557 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1561 describeContext(dest
);
1562 /* Create the destination context with display lists shared */
1563 dest
->ctx
= pglXCreateContext(org
->display
, dest
->vis
, org
->ctx
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1564 wine_tsx11_unlock();
1565 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1572 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1574 /* We are running using client-side rendering fonts... */
1578 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1582 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1583 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1584 wine_tsx11_unlock();
1586 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1587 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1588 int height
, width_int
;
1590 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1591 if (needed_size
== GDI_ERROR
) {
1592 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1595 TRACE(" - needed size : %d\n", needed_size
);
1598 if (needed_size
> size
) {
1600 HeapFree(GetProcessHeap(), 0, bitmap
);
1601 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1602 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1603 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1605 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1606 if (TRACE_ON(opengl
)) {
1607 unsigned int height
, width
, bitmask
;
1608 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1610 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1611 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1612 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1613 if (needed_size
!= 0) {
1614 TRACE(" - bitmap :\n");
1615 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1617 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1622 if (*bitmap_
& bitmask
)
1627 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1633 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1634 * glyph for it to be drawn properly.
1636 if (needed_size
!= 0) {
1637 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1638 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1640 for (width
= 0; width
< width_int
; width
++) {
1641 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1642 ((int *) bitmap
)[height
* width_int
+ width
];
1648 pglNewList(listBase
++, GL_COMPILE
);
1649 if (needed_size
!= 0) {
1650 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1651 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1652 gm
.gmCellIncX
, gm
.gmCellIncY
,
1655 /* This is the case of 'empty' glyphs like the space character */
1656 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1659 wine_tsx11_unlock();
1663 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1664 wine_tsx11_unlock();
1666 HeapFree(GetProcessHeap(), 0, bitmap
);
1667 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1672 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1673 wine_tsx11_unlock();
1675 HeapFree(GetProcessHeap(), 0, bitmap
);
1676 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1681 * X11DRV_wglUseFontBitmapsA
1683 * For OpenGL32 wglUseFontBitmapsA.
1685 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1687 Font fid
= physDev
->font
;
1689 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1691 if (!has_opengl()) {
1692 ERR("No libGL on this box - disabling OpenGL support !\n");
1697 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
1701 /* I assume that the glyphs are at the same position for X and for Windows */
1702 pglXUseXFont(fid
, first
, count
, listBase
);
1703 wine_tsx11_unlock();
1708 * X11DRV_wglUseFontBitmapsW
1710 * For OpenGL32 wglUseFontBitmapsW.
1712 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1714 Font fid
= physDev
->font
;
1716 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1718 if (!has_opengl()) {
1719 ERR("No libGL on this box - disabling OpenGL support !\n");
1724 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1727 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1730 /* I assume that the glyphs are at the same position for X and for Windows */
1731 pglXUseXFont(fid
, first
, count
, listBase
);
1732 wine_tsx11_unlock();
1736 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1737 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
) {
1738 TRACE("pname: 0x%x, params: %p\n", pname
, params
);
1739 if (pname
== GL_DEPTH_BITS
) {
1740 GLXContext gl_ctx
= pglXGetCurrentContext();
1741 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1742 /*TRACE("returns Wine Ctx as %p\n", ret);*/
1744 * if we cannot find a Wine Context
1745 * we only have the default wine desktop context,
1746 * so if we have only a 24 depth say we have 32
1748 if (NULL
== ret
&& 24 == *params
) {
1751 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
1753 if (pname
== GL_ALPHA_BITS
) {
1755 GLXContext gl_ctx
= pglXGetCurrentContext();
1756 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1757 pglXGetFBConfigAttrib(ret
->display
, ret
->fb_conf
, GLX_ALPHA_SIZE
, &tmp
);
1758 TRACE("returns GL_ALPHA_BITS as '%d'\n", tmp
);
1764 * X11DRV_wglGetExtensionsStringARB
1766 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1768 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
1769 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
1770 return WineGLInfo
.wglExtensions
;
1774 * X11DRV_wglCreatePbufferARB
1776 * WGL_ARB_pbuffer: wglCreatePbufferARB
1778 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
1780 Wine_GLPBuffer
* object
= NULL
;
1781 GLXFBConfig
* cfgs
= NULL
;
1784 unsigned nAttribs
= 0;
1787 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
1789 if (0 >= iPixelFormat
) {
1790 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
1791 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1792 return NULL
; /* unexpected error */
1795 cfgs
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs
);
1797 if (NULL
== cfgs
|| 0 == nCfgs
) {
1798 ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc
, iPixelFormat
);
1799 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1800 return NULL
; /* unexpected error */
1803 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1804 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, &fmt_index
, &nCfgs
)) {
1805 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
1806 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1807 goto create_failed
; /* unexpected error */
1810 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
1811 if (NULL
== object
) {
1812 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1813 goto create_failed
; /* unexpected error */
1816 object
->display
= gdi_display
;
1817 object
->width
= iWidth
;
1818 object
->height
= iHeight
;
1820 nAttribs
= ConvertAttribWGLtoGLX(piAttribList
, attribs
, object
);
1821 if (-1 == nAttribs
) {
1822 WARN("Cannot convert WGL to GLX attributes\n");
1825 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
1826 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
1827 while (0 != *piAttribList
) {
1829 switch (*piAttribList
) {
1830 case WGL_TEXTURE_FORMAT_ARB
: {
1832 attr_v
= *piAttribList
;
1833 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
1834 if (use_render_texture_ati
) {
1837 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
1838 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
1839 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
1841 SetLastError(ERROR_INVALID_DATA
);
1844 object
->use_render_texture
= 1;
1845 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
1847 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
1848 object
->use_render_texture
= 0;
1850 if (!use_render_texture_emulation
) {
1851 SetLastError(ERROR_INVALID_DATA
);
1855 case WGL_TEXTURE_RGB_ARB
:
1856 object
->use_render_texture
= GL_RGB
;
1858 case WGL_TEXTURE_RGBA_ARB
:
1859 object
->use_render_texture
= GL_RGBA
;
1862 SetLastError(ERROR_INVALID_DATA
);
1870 case WGL_TEXTURE_TARGET_ARB
: {
1872 attr_v
= *piAttribList
;
1873 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
1874 if (use_render_texture_ati
) {
1877 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
1878 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
1879 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
1880 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
1882 SetLastError(ERROR_INVALID_DATA
);
1885 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
1887 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
1888 object
->texture_target
= 0;
1890 if (!use_render_texture_emulation
) {
1891 SetLastError(ERROR_INVALID_DATA
);
1895 case WGL_TEXTURE_CUBE_MAP_ARB
: {
1896 if (iWidth
!= iHeight
) {
1897 SetLastError(ERROR_INVALID_DATA
);
1900 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
1901 object
->texture_bind_target
= GL_TEXTURE_CUBE_MAP
;
1904 case WGL_TEXTURE_1D_ARB
: {
1906 SetLastError(ERROR_INVALID_DATA
);
1909 object
->texture_target
= GL_TEXTURE_1D
;
1910 object
->texture_bind_target
= GL_TEXTURE_1D
;
1913 case WGL_TEXTURE_2D_ARB
: {
1914 object
->texture_target
= GL_TEXTURE_2D
;
1915 object
->texture_bind_target
= GL_TEXTURE_2D
;
1919 SetLastError(ERROR_INVALID_DATA
);
1927 case WGL_MIPMAP_TEXTURE_ARB
: {
1929 attr_v
= *piAttribList
;
1930 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
1931 if (use_render_texture_ati
) {
1932 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
1934 if (!use_render_texture_emulation
) {
1935 SetLastError(ERROR_INVALID_DATA
);
1945 PUSH1(attribs
, None
);
1946 object
->drawable
= pglXCreatePbuffer(gdi_display
, cfgs
[fmt_index
], attribs
);
1947 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
1948 if (!object
->drawable
) {
1949 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1950 goto create_failed
; /* unexpected error */
1952 TRACE("->(%p)\n", object
);
1956 return (HPBUFFERARB
) object
;
1959 if (NULL
!= cfgs
) XFree(cfgs
);
1960 HeapFree(GetProcessHeap(), 0, object
);
1961 TRACE("->(FAILED)\n");
1962 return (HPBUFFERARB
) NULL
;
1966 * X11DRV_wglDestroyPbufferARB
1968 * WGL_ARB_pbuffer: wglDestroyPbufferARB
1970 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
1972 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
1973 TRACE("(%p)\n", hPbuffer
);
1974 if (NULL
== object
) {
1975 SetLastError(ERROR_INVALID_HANDLE
);
1978 pglXDestroyPbuffer(object
->display
, object
->drawable
);
1979 HeapFree(GetProcessHeap(), 0, object
);
1984 * X11DRV_wglGetPbufferDCARB
1986 * WGL_ARB_pbuffer: wglGetPbufferDCARB
1987 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
1988 * Gdi32 implements the part of this function which creates a device context.
1989 * This part associates the physDev with the X drawable of the pbuffer.
1991 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
1993 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
1994 if (NULL
== object
) {
1995 SetLastError(ERROR_INVALID_HANDLE
);
1999 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2000 * We only support one onscreen rendering format (the one from the main visual), so use that. */
2001 physDev
->current_pf
= 1;
2002 physDev
->drawable
= object
->drawable
;
2004 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2005 return physDev
->hdc
;
2009 * X11DRV_wglQueryPbufferARB
2011 * WGL_ARB_pbuffer: wglQueryPbufferARB
2013 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2015 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2016 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2017 if (NULL
== object
) {
2018 SetLastError(ERROR_INVALID_HANDLE
);
2021 switch (iAttribute
) {
2022 case WGL_PBUFFER_WIDTH_ARB
:
2023 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2025 case WGL_PBUFFER_HEIGHT_ARB
:
2026 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2029 case WGL_PBUFFER_LOST_ARB
:
2030 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
2033 case WGL_TEXTURE_FORMAT_ARB
:
2034 if (use_render_texture_ati
) {
2036 int type
= WGL_NO_TEXTURE_ARB
;
2037 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2039 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2040 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2041 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2045 if (!object
->use_render_texture
) {
2046 *piValue
= WGL_NO_TEXTURE_ARB
;
2048 if (!use_render_texture_emulation
) {
2049 SetLastError(ERROR_INVALID_HANDLE
);
2052 if (GL_RGBA
== object
->use_render_texture
) {
2053 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2055 *piValue
= WGL_TEXTURE_RGB_ARB
;
2061 case WGL_TEXTURE_TARGET_ARB
:
2062 if (use_render_texture_ati
) {
2064 int type
= WGL_NO_TEXTURE_ARB
;
2065 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2067 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2068 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2069 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2070 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2074 if (!object
->texture_target
) {
2075 *piValue
= WGL_NO_TEXTURE_ARB
;
2077 if (!use_render_texture_emulation
) {
2078 SetLastError(ERROR_INVALID_DATA
);
2081 switch (object
->texture_target
) {
2082 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2083 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2084 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2090 case WGL_MIPMAP_TEXTURE_ARB
:
2091 if (use_render_texture_ati
) {
2092 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2094 *piValue
= GL_FALSE
; /** don't support that */
2095 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2100 FIXME("unexpected attribute %x\n", iAttribute
);
2108 * X11DRV_wglReleasePbufferDCARB
2110 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2112 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2114 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2120 * X11DRV_wglSetPbufferAttribARB
2122 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2124 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2126 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2127 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2128 if (NULL
== object
) {
2129 SetLastError(ERROR_INVALID_HANDLE
);
2132 if (!object
->use_render_texture
) {
2133 SetLastError(ERROR_INVALID_HANDLE
);
2136 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2139 if (NULL
!= pglXDrawableAttribARB
) {
2140 if (use_render_texture_ati
) {
2141 FIXME("Need conversion for GLX_ATI_render_texture\n");
2143 return pglXDrawableAttribARB(object
->display
, object
->drawable
, piAttribList
);
2149 * X11DRV_wglChoosePixelFormatARB
2151 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2153 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2158 GLXFBConfig
* cfgs
= NULL
;
2163 GLXFBConfig
* cfgs_fmt
= NULL
;
2169 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2170 if (NULL
!= pfAttribFList
) {
2171 FIXME("unused pfAttribFList\n");
2174 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2175 if (-1 == nAttribs
) {
2176 WARN("Cannot convert WGL to GLX attributes\n");
2179 PUSH1(attribs
, None
);
2181 /* Search for FB configurations matching the requirements in attribs */
2182 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2184 WARN("Compatible Pixel Format not found\n");
2188 /* Get a list of all FB configurations */
2189 cfgs_fmt
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs_fmt
);
2190 if (NULL
== cfgs_fmt
) {
2191 ERR("Failed to get All FB Configs\n");
2196 /* Loop through all matching formats and check if they are suitable.
2197 * Note that this function should at max return nMaxFormats different formats */
2198 for (it
= 0; pfmt_it
< nMaxFormats
&& it
< nCfgs
; ++it
) {
2199 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2201 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2205 /* Search for the format in our list of compatible formats */
2206 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
);
2210 piFormats
[pfmt_it
] = fmt
;
2211 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d/%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
], nCfgs_fmt
);
2215 *nNumFormats
= pfmt_it
;
2223 * X11DRV_wglGetPixelFormatAttribfvARB
2225 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2227 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2229 FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2234 * X11DRV_wglGetPixelFormatAttribivARB
2236 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2238 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2241 GLXFBConfig
* cfgs
= NULL
;
2242 GLXFBConfig curCfg
= NULL
;
2247 int nWGLFormats
= 0;
2250 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2252 if (0 < iLayerPlane
) {
2253 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2257 cfgs
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs
);
2259 ERR("no FB Configs found for display(%p)\n", gdi_display
);
2263 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2264 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2265 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2266 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, &fmt_index
, &nWGLFormats
)) {
2267 ERR("Unable to convert iPixelFormat %d to a GLX one, expect problems!\n", iPixelFormat
);
2270 for (i
= 0; i
< nAttributes
; ++i
) {
2271 const int curWGLAttr
= piAttributes
[i
];
2272 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2274 switch (curWGLAttr
) {
2275 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2276 piValues
[i
] = nWGLFormats
;
2279 case WGL_SUPPORT_OPENGL_ARB
:
2280 piValues
[i
] = GL_TRUE
;
2283 case WGL_ACCELERATION_ARB
:
2284 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2286 if (nCfgs
< iPixelFormat
|| 0 >= iPixelFormat
) goto pix_error
;
2287 curCfg
= cfgs
[iPixelFormat
- 1];
2289 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, &tmp
);
2290 if (hTest
) goto get_error
;
2292 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2293 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_NO_ACCELERATION_ARB
; break;
2294 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2296 ERR("unexpected Config Caveat(%x)\n", tmp
);
2297 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2301 case WGL_TRANSPARENT_ARB
:
2302 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2303 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2304 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2305 if((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
)) goto pix_error
;
2306 curCfg
= cfgs
[fmt_index
];
2307 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, &tmp
);
2308 if (hTest
) goto get_error
;
2309 piValues
[i
] = GL_FALSE
;
2310 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2313 case WGL_PIXEL_TYPE_ARB
:
2314 curGLXAttr
= GLX_RENDER_TYPE
;
2315 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2316 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2317 if((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
)) goto pix_error
;
2318 curCfg
= cfgs
[fmt_index
];
2319 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, &tmp
);
2320 if (hTest
) goto get_error
;
2321 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2322 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2323 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2324 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2325 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2327 ERR("unexpected RenderType(%x)\n", tmp
);
2328 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2332 case WGL_COLOR_BITS_ARB
:
2333 /** see ConvertAttribWGLtoGLX for explain */
2334 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2335 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2336 if((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
)) goto pix_error
;
2337 curCfg
= cfgs
[fmt_index
];
2338 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, GLX_BUFFER_SIZE
, piValues
+ i
);
2339 if (hTest
) goto get_error
;
2340 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues
[i
]);
2341 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, GLX_ALPHA_SIZE
, &tmp
);
2342 if (hTest
) goto get_error
;
2343 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp
);
2344 piValues
[i
] = piValues
[i
] - tmp
;
2347 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2348 if (use_render_texture_ati
) {
2349 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2352 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2353 if (use_render_texture_ati
) {
2354 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2357 if (!use_render_texture_emulation
) {
2358 piValues
[i
] = GL_FALSE
;
2361 curGLXAttr
= GLX_RENDER_TYPE
;
2362 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2363 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2364 if((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
)) goto pix_error
;
2365 curCfg
= cfgs
[fmt_index
];
2366 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, &tmp
);
2367 if (hTest
) goto get_error
;
2368 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2369 piValues
[i
] = GL_FALSE
;
2372 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, GLX_DRAWABLE_TYPE
, &tmp
);
2373 if (hTest
) goto get_error
;
2374 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2377 case WGL_BLUE_BITS_ARB
:
2378 curGLXAttr
= GLX_BLUE_SIZE
;
2380 case WGL_RED_BITS_ARB
:
2381 curGLXAttr
= GLX_RED_SIZE
;
2383 case WGL_GREEN_BITS_ARB
:
2384 curGLXAttr
= GLX_GREEN_SIZE
;
2386 case WGL_ALPHA_BITS_ARB
:
2387 curGLXAttr
= GLX_ALPHA_SIZE
;
2389 case WGL_DEPTH_BITS_ARB
:
2390 curGLXAttr
= GLX_DEPTH_SIZE
;
2392 case WGL_STENCIL_BITS_ARB
:
2393 curGLXAttr
= GLX_STENCIL_SIZE
;
2395 case WGL_DOUBLE_BUFFER_ARB
:
2396 curGLXAttr
= GLX_DOUBLEBUFFER
;
2398 case WGL_STEREO_ARB
:
2399 curGLXAttr
= GLX_STEREO
;
2401 case WGL_AUX_BUFFERS_ARB
:
2402 curGLXAttr
= GLX_AUX_BUFFERS
;
2404 case WGL_SUPPORT_GDI_ARB
:
2405 case WGL_DRAW_TO_WINDOW_ARB
:
2406 case WGL_DRAW_TO_BITMAP_ARB
:
2407 /* We only supported a limited number of formats right now which are all renderable by X 'GLX_X_RENDERABLE' */
2408 piValues
[i
] = GL_TRUE
;
2410 case WGL_DRAW_TO_PBUFFER_ARB
:
2411 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, GLX_DRAWABLE_TYPE
, &tmp
);
2412 if (hTest
) goto get_error
;
2413 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2416 case WGL_PBUFFER_LARGEST_ARB
:
2417 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2420 case WGL_SAMPLE_BUFFERS_ARB
:
2421 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2424 case WGL_SAMPLES_ARB
:
2425 curGLXAttr
= GLX_SAMPLES_ARB
;
2429 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2432 if (0 != curGLXAttr
) {
2433 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2434 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2435 if((iPixelFormat
> 0) && ((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
))) goto pix_error
;
2436 curCfg
= cfgs
[fmt_index
];
2437 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, piValues
+ i
);
2438 if (hTest
) goto get_error
;
2440 piValues
[i
] = GL_FALSE
;
2446 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2451 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nCfgs
);
2457 * X11DRV_wglBindTexImageARB
2459 * WGL_ARB_render_texture: wglBindTexImageARB
2461 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2463 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2464 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2465 if (NULL
== object
) {
2466 SetLastError(ERROR_INVALID_HANDLE
);
2469 if (!object
->use_render_texture
) {
2470 SetLastError(ERROR_INVALID_HANDLE
);
2473 /* Disable WGL_ARB_render_texture support until it is implemented properly
2474 * using pbuffers or FBOs */
2476 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2478 GLint prev_binded_tex
;
2479 pglGetIntegerv(object
->texture_target
, &prev_binded_tex
);
2480 if (NULL
== object
->render_ctx
) {
2481 object
->render_hdc
= X11DRV_wglGetPbufferDCARB(hPbuffer
);
2482 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2483 object
->render_ctx
= wglCreateContext(object
->render_hdc
);
2486 object
->prev_hdc
= wglGetCurrentDC();
2487 object
->prev_ctx
= wglGetCurrentContext();
2488 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2489 wglMakeCurrent(object
->render_hdc
, object
->render_ctx
);
2492 glBindTexture(object->texture_target, object->texture);
2493 if (GL_RGBA == object->use_render_texture) {
2494 glTexImage2D(object->texture_target, 0, GL_RGBA8, object->width, object->height, 0, GL_RGBA, GL_FLOAT, NULL);
2496 glTexImage2D(object->texture_target, 0, GL_RGB8, object->width, object->height, 0, GL_RGB, GL_FLOAT, NULL);
2500 object
->texture
= prev_binded_tex
;
2504 if (NULL
!= pglXBindTexImageARB
) {
2505 return pglXBindTexImageARB(object
->display
, object
->drawable
, iBuffer
);
2511 * X11DRV_wglReleaseTexImageARB
2513 * WGL_ARB_render_texture: wglReleaseTexImageARB
2515 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2517 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2518 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2519 if (NULL
== object
) {
2520 SetLastError(ERROR_INVALID_HANDLE
);
2523 if (!object
->use_render_texture
) {
2524 SetLastError(ERROR_INVALID_HANDLE
);
2527 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2529 GLint prev_binded_tex;
2530 glGetIntegerv(object->texture_target, &prev_binded_tex);
2531 if (GL_TEXTURE_1D == object->texture_target) {
2532 glCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2534 glCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2536 glBindTexture(object->texture_target, prev_binded_tex);
2537 SwapBuffers(object->render_hdc);
2539 pglBindTexture(object
->texture_target
, object
->texture
);
2540 if (GL_TEXTURE_1D
== object
->texture_target
) {
2541 pglCopyTexSubImage1D(object
->texture_target
, object
->texture_level
, 0, 0, 0, object
->width
);
2543 pglCopyTexSubImage2D(object
->texture_target
, object
->texture_level
, 0, 0, 0, 0, object
->width
, object
->height
);
2546 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2547 wglMakeCurrent(object
->prev_hdc
, object
->prev_ctx
);
2550 if (NULL
!= pglXReleaseTexImageARB
) {
2551 return pglXReleaseTexImageARB(object
->display
, object
->drawable
, iBuffer
);
2557 * X11DRV_wglGetExtensionsStringEXT
2559 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2561 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
2562 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2563 return WineGLInfo
.wglExtensions
;
2567 * X11DRV_wglGetSwapIntervalEXT
2569 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2571 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
2572 FIXME("(),stub!\n");
2573 return swap_interval
;
2577 * X11DRV_wglSwapIntervalEXT
2579 * WGL_EXT_swap_control: wglSwapIntervalEXT
2581 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
2582 TRACE("(%d)\n", interval
);
2583 swap_interval
= interval
;
2584 if (NULL
!= pglXSwapIntervalSGI
) {
2585 return 0 == pglXSwapIntervalSGI(interval
);
2587 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2592 * glxRequireVersion (internal)
2594 * Check if the supported GLX version matches requiredVersion.
2596 static BOOL
glxRequireVersion(int requiredVersion
)
2598 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2599 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
2605 static BOOL
glxRequireExtension(const char *requiredExtension
)
2607 if (strstr(WineGLInfo
.glxClientExtensions
, requiredExtension
) == NULL
) {
2614 static BOOL
register_extension(const WineGLExtension
* ext
)
2618 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
2619 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
2621 strcat(WineGLInfo
.wglExtensions
, " ");
2622 strcat(WineGLInfo
.wglExtensions
, ext
->extName
);
2624 TRACE("'%s'\n", ext
->extName
);
2626 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
2627 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
2632 static const WineGLExtension WGL_internal_functions
=
2636 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
2641 static const WineGLExtension WGL_ARB_extensions_string
=
2643 "WGL_ARB_extensions_string",
2645 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
2649 static const WineGLExtension WGL_ARB_make_current_read
=
2651 "WGL_ARB_make_current_read",
2653 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
2654 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
2658 static const WineGLExtension WGL_ARB_multisample
=
2660 "WGL_ARB_multisample",
2663 static const WineGLExtension WGL_ARB_pbuffer
=
2667 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
2668 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
2669 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
2670 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
2671 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
2672 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
2676 static const WineGLExtension WGL_ARB_pixel_format
=
2678 "WGL_ARB_pixel_format",
2680 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
2681 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
2682 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
2686 static const WineGLExtension WGL_ARB_render_texture
=
2688 "WGL_ARB_render_texture",
2690 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
2691 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
2695 static const WineGLExtension WGL_EXT_extensions_string
=
2697 "WGL_EXT_extensions_string",
2699 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
2703 static const WineGLExtension WGL_EXT_swap_control
=
2705 "WGL_EXT_swap_control",
2707 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
2708 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
2714 * X11DRV_WineGL_LoadExtensions
2716 static void X11DRV_WineGL_LoadExtensions(void)
2718 WineGLInfo
.wglExtensions
[0] = 0;
2720 /* Load Wine internal functions */
2721 register_extension(&WGL_internal_functions
);
2723 /* ARB Extensions */
2725 register_extension(&WGL_ARB_extensions_string
);
2727 if (glxRequireVersion(3))
2728 register_extension(&WGL_ARB_make_current_read
);
2730 if (glxRequireExtension("GLX_ARB_multisample"))
2731 register_extension(&WGL_ARB_multisample
);
2733 if (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer"))
2734 register_extension(&WGL_ARB_pbuffer
);
2736 register_extension(&WGL_ARB_pixel_format
);
2738 if (glxRequireExtension("GLX_ATI_render_texture") ||
2739 glxRequireExtension("GLX_ARB_render_texture"))
2740 register_extension(&WGL_ARB_render_texture
);
2742 /* EXT Extensions */
2744 register_extension(&WGL_EXT_extensions_string
);
2746 if (glxRequireExtension("GLX_SGI_swap_control"))
2747 register_extension(&WGL_EXT_swap_control
);
2751 static XID
create_glxpixmap(X11DRV_PDEVICE
*physDev
)
2755 XVisualInfo
template;
2760 /* Retrieve the visualid from our main visual which is the only visual we can use */
2761 template.visualid
= XVisualIDFromVisual(visual
);
2762 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
2764 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
2766 wine_tsx11_unlock();
2767 TRACE("return %lx\n", ret
);
2771 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
2777 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
2778 ret
= physDev
->drawable
; /* PBuffer */
2781 if(!physDev
->bitmap
->glxpixmap
)
2782 physDev
->bitmap
->glxpixmap
= create_glxpixmap(physDev
);
2783 ret
= physDev
->bitmap
->glxpixmap
;
2787 ret
= physDev
->drawable
;
2791 BOOL
destroy_glxpixmap(XID glxpixmap
)
2794 pglXDestroyGLXPixmap(gdi_display
, glxpixmap
);
2795 wine_tsx11_unlock();
2800 * X11DRV_SwapBuffers
2802 * Swap the buffers of this DC
2804 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
2806 GLXDrawable drawable
;
2807 if (!has_opengl()) {
2808 ERR("No libGL on this box - disabling OpenGL support !\n");
2812 TRACE_(opengl
)("(%p)\n", physDev
);
2814 drawable
= get_glxdrawable(physDev
);
2816 pglXSwapBuffers(gdi_display
, drawable
);
2817 wine_tsx11_unlock();
2822 static long prev_time
, frames
;
2824 DWORD time
= GetTickCount();
2826 /* every 1.5 seconds */
2827 if (time
- prev_time
> 1500) {
2828 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
2837 /***********************************************************************
2838 * X11DRV_setup_opengl_visual
2840 * Setup the default visual used for OpenGL and Direct3D, and the desktop
2841 * window (if it exists). If OpenGL isn't available, the visual is simply
2842 * set to the default visual for the display
2844 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
2846 XVisualInfo
*visual
= NULL
;
2847 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support, */
2848 int dblBuf
[] = {GLX_RGBA
,GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_DOUBLEBUFFER
, None
};
2849 if (!has_opengl()) return NULL
;
2852 visual
= pglXChooseVisual(display
, DefaultScreen(display
), dblBuf
);
2853 wine_tsx11_unlock();
2854 if (visual
== NULL
) {
2855 /* fallback to 16 bits depth, no alpha */
2856 int dblBuf2
[] = {GLX_RGBA
,GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, GLX_DOUBLEBUFFER
, None
};
2857 WARN("Failed to get a visual with at least 24 bits depth\n");
2860 visual
= pglXChooseVisual(display
, DefaultScreen(display
), dblBuf2
);
2861 wine_tsx11_unlock();
2862 if (visual
== NULL
) {
2863 /* fallback to no stencil */
2864 int dblBuf2
[] = {GLX_RGBA
,GLX_DEPTH_SIZE
, 16, GLX_DOUBLEBUFFER
, None
};
2865 WARN("Failed to get a visual with at least 8 bits of stencil\n");
2868 visual
= pglXChooseVisual(display
, DefaultScreen(display
), dblBuf2
);
2869 wine_tsx11_unlock();
2870 if (visual
== NULL
) {
2871 /* This should only happen if we cannot find a match with a depth size 16 */
2872 FIXME("Failed to find a suitable visual\n");
2877 TRACE("Visual ID %lx Chosen\n",visual
->visualid
);
2881 #else /* no OpenGL includes */
2883 /***********************************************************************
2884 * ChoosePixelFormat (X11DRV.@)
2886 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
2887 const PIXELFORMATDESCRIPTOR
*ppfd
) {
2888 ERR("No OpenGL support compiled in.\n");
2893 /***********************************************************************
2894 * DescribePixelFormat (X11DRV.@)
2896 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
2899 PIXELFORMATDESCRIPTOR
*ppfd
) {
2900 ERR("No OpenGL support compiled in.\n");
2905 /***********************************************************************
2906 * GetPixelFormat (X11DRV.@)
2908 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
2909 ERR("No OpenGL support compiled in.\n");
2914 /***********************************************************************
2915 * SetPixelFormat (X11DRV.@)
2917 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
2919 const PIXELFORMATDESCRIPTOR
*ppfd
) {
2920 ERR("No OpenGL support compiled in.\n");
2925 /***********************************************************************
2926 * SwapBuffers (X11DRV.@)
2928 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
2929 ERR_(opengl
)("No OpenGL support compiled in.\n");
2935 * X11DRV_wglCreateContext
2937 * For OpenGL32 wglCreateContext.
2939 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
2940 ERR_(opengl
)("No OpenGL support compiled in.\n");
2945 * X11DRV_wglDeleteContext
2947 * For OpenGL32 wglDeleteContext.
2949 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
2950 ERR_(opengl
)("No OpenGL support compiled in.\n");
2955 * X11DRV_wglGetProcAddress
2957 * For OpenGL32 wglGetProcAddress.
2959 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
2960 ERR_(opengl
)("No OpenGL support compiled in.\n");
2964 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
2966 ERR_(opengl
)("No OpenGL support compiled in.\n");
2970 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
2971 ERR_(opengl
)("No OpenGL support compiled in.\n");
2976 * X11DRV_wglMakeCurrent
2978 * For OpenGL32 wglMakeCurrent.
2980 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
2981 ERR_(opengl
)("No OpenGL support compiled in.\n");
2986 * X11DRV_wglShareLists
2988 * For OpenGL32 wglShaderLists.
2990 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
2991 ERR_(opengl
)("No OpenGL support compiled in.\n");
2996 * X11DRV_wglUseFontBitmapsA
2998 * For OpenGL32 wglUseFontBitmapsA.
3000 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3002 ERR_(opengl
)("No OpenGL support compiled in.\n");
3007 * X11DRV_wglUseFontBitmapsW
3009 * For OpenGL32 wglUseFontBitmapsW.
3011 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3013 ERR_(opengl
)("No OpenGL support compiled in.\n");
3017 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3022 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3027 BOOL
destroy_glxpixmap(XID glxpixmap
)
3032 #endif /* defined(HAVE_OPENGL) */