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 static Wine_GLContext
*context_list
;
128 static struct WineGLInfo WineGLInfo
= { 0 };
129 static int use_render_texture_emulation
= 0;
130 static int use_render_texture_ati
= 0;
131 static int swap_interval
= 1;
133 #define MAX_EXTENSIONS 16
134 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
135 static int WineGLExtensionListSize
;
137 static void X11DRV_WineGL_LoadExtensions(void);
139 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
140 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
141 TRACE(" - dwFlags : ");
142 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
143 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
144 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
145 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
146 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
147 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
148 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
149 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
150 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
151 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
152 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
153 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
154 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
155 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
156 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
157 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
158 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
162 TRACE(" - iPixelType : ");
163 switch (ppfd
->iPixelType
) {
164 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
165 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
169 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
170 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
171 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
172 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
173 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
174 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
175 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
176 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
177 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
179 TRACE(" - iLayerType : ");
180 switch (ppfd
->iLayerType
) {
181 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
182 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
183 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
188 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and
189 include all dependencies
192 #define SONAME_LIBGL "libGL.so"
195 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
196 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
198 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
200 MAKE_FUNCPTR(glXChooseVisual
)
201 MAKE_FUNCPTR(glXCreateContext
)
202 MAKE_FUNCPTR(glXCreateGLXPixmap
)
203 MAKE_FUNCPTR(glXGetCurrentContext
)
204 MAKE_FUNCPTR(glXDestroyContext
)
205 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
206 MAKE_FUNCPTR(glXGetConfig
)
207 MAKE_FUNCPTR(glXIsDirect
)
208 MAKE_FUNCPTR(glXMakeCurrent
)
209 MAKE_FUNCPTR(glXSwapBuffers
)
210 MAKE_FUNCPTR(glXQueryExtension
)
211 MAKE_FUNCPTR(glXQueryVersion
)
212 MAKE_FUNCPTR(glXUseXFont
)
215 MAKE_FUNCPTR(glXGetClientString
)
216 MAKE_FUNCPTR(glXQueryExtensionsString
)
217 MAKE_FUNCPTR(glXQueryServerString
)
220 MAKE_FUNCPTR(glXGetFBConfigs
)
221 MAKE_FUNCPTR(glXChooseFBConfig
)
222 MAKE_FUNCPTR(glXCreatePbuffer
)
223 MAKE_FUNCPTR(glXDestroyPbuffer
)
224 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
225 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
226 MAKE_FUNCPTR(glXMakeContextCurrent
)
227 MAKE_FUNCPTR(glXQueryDrawable
)
228 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
231 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
232 static BOOL (*pglXBindTexImageARB
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
233 static BOOL (*pglXReleaseTexImageARB
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
234 static BOOL (*pglXDrawableAttribARB
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
235 static int (*pglXSwapIntervalSGI
)(int);
237 /* Standard OpenGL */
238 MAKE_FUNCPTR(glBindTexture
)
239 MAKE_FUNCPTR(glBitmap
)
240 MAKE_FUNCPTR(glCopyTexSubImage1D
)
241 MAKE_FUNCPTR(glCopyTexSubImage2D
)
242 MAKE_FUNCPTR(glDrawBuffer
)
243 MAKE_FUNCPTR(glEndList
)
244 MAKE_FUNCPTR(glGetError
)
245 MAKE_FUNCPTR(glGetIntegerv
)
246 MAKE_FUNCPTR(glGetString
)
247 MAKE_FUNCPTR(glNewList
)
248 MAKE_FUNCPTR(glPixelStorei
)
251 BOOL
X11DRV_WineGL_InitOpenglInfo()
253 static BOOL infoInitialized
= FALSE
;
255 int screen
= DefaultScreen(gdi_display
);
256 Window win
= RootWindow(gdi_display
, screen
);
258 XVisualInfo
template;
261 GLXContext ctx
= NULL
;
265 infoInitialized
= TRUE
;
269 visual
= DefaultVisual(gdi_display
, screen
);
270 template.visualid
= XVisualIDFromVisual(visual
);
271 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
273 /* Create a GLX Context. Without one we can't query GL information */
274 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
278 pglXMakeCurrent(gdi_display
, win
, ctx
);
280 ERR(" couldn't initialize OpenGL, expect problems\n");
285 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
286 WineGLInfo
.glExtensions
= (const char *) pglGetString(GL_EXTENSIONS
);
288 /* Get the common GLX version supported by GLX client and server ( major/minor) */
289 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
291 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
292 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
294 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
295 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
297 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
298 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
300 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
301 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
302 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
303 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
304 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
308 pglXMakeCurrent(gdi_display
, None
, NULL
);
309 pglXDestroyContext(gdi_display
, ctx
);
315 static BOOL
has_opengl(void)
317 static int init_done
;
318 static void *opengl_handle
;
319 const char *glx_extensions
;
321 int error_base
, event_base
;
323 if (init_done
) return (opengl_handle
!= NULL
);
326 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0);
327 if (opengl_handle
== NULL
) return FALSE
;
329 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
330 if (pglXGetProcAddressARB
== NULL
) {
331 ERR("could not find glXGetProcAddressARB in libGL.\n");
335 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((unsigned char*)#f)) == NULL) goto sym_not_found;
337 LOAD_FUNCPTR(glXChooseVisual
)
338 LOAD_FUNCPTR(glXCreateContext
)
339 LOAD_FUNCPTR(glXCreateGLXPixmap
)
340 LOAD_FUNCPTR(glXGetCurrentContext
)
341 LOAD_FUNCPTR(glXDestroyContext
)
342 LOAD_FUNCPTR(glXDestroyGLXPixmap
)
343 LOAD_FUNCPTR(glXGetConfig
)
344 LOAD_FUNCPTR(glXIsDirect
)
345 LOAD_FUNCPTR(glXMakeCurrent
)
346 LOAD_FUNCPTR(glXSwapBuffers
)
347 LOAD_FUNCPTR(glXQueryExtension
)
348 LOAD_FUNCPTR(glXQueryVersion
)
349 LOAD_FUNCPTR(glXUseXFont
)
352 LOAD_FUNCPTR(glXGetClientString
)
353 LOAD_FUNCPTR(glXQueryExtensionsString
)
354 LOAD_FUNCPTR(glXQueryServerString
)
357 LOAD_FUNCPTR(glXCreatePbuffer
)
358 LOAD_FUNCPTR(glXDestroyPbuffer
)
359 LOAD_FUNCPTR(glXMakeContextCurrent
)
360 LOAD_FUNCPTR(glXGetCurrentReadDrawable
)
361 LOAD_FUNCPTR(glXGetFBConfigs
)
363 /* Standard OpenGL calls */
364 LOAD_FUNCPTR(glBindTexture
)
365 LOAD_FUNCPTR(glBitmap
)
366 LOAD_FUNCPTR(glEndList
)
367 LOAD_FUNCPTR(glCopyTexSubImage1D
)
368 LOAD_FUNCPTR(glCopyTexSubImage2D
)
369 LOAD_FUNCPTR(glDrawBuffer
)
370 LOAD_FUNCPTR(glGetError
)
371 LOAD_FUNCPTR(glGetIntegerv
)
372 LOAD_FUNCPTR(glGetString
)
373 LOAD_FUNCPTR(glNewList
)
374 LOAD_FUNCPTR(glPixelStorei
)
377 if(!X11DRV_WineGL_InitOpenglInfo()) {
378 ERR("Intialization of OpenGL info failed, disabling OpenGL!\n");
379 wine_dlclose(opengl_handle
, NULL
, 0);
380 opengl_handle
= NULL
;
385 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
) == True
) {
386 TRACE("GLX is up and running error_base = %d\n", error_base
);
388 wine_dlclose(opengl_handle
, NULL
, 0);
389 opengl_handle
= NULL
;
392 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
393 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
396 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
397 * depends on the reported GLX client / server version and on the client / server extension list.
398 * Those don't have to be the same.
400 * In general the server GLX information should be used in case of indirect rendering. When direct
401 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
402 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
403 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
404 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
405 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
406 * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
407 * is only available in the list of server extensions and not in the client list.
409 * The versioning checks below try to take into account the comments from above.
412 /* Depending on the use of direct or indirect rendering we need either the list of extensions
413 * exported by the client or by the server.
415 if(WineGLInfo
.glxDirect
)
416 glx_extensions
= WineGLInfo
.glxClientExtensions
;
418 glx_extensions
= WineGLInfo
.glxServerExtensions
;
420 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
421 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
422 * the client version is checked.
424 if ((!WineGLInfo
.glxDirect
&& !strcmp("1.2", WineGLInfo
.glxServerVersion
)) ||
425 (WineGLInfo
.glxDirect
&& !strcmp("1.2", WineGLInfo
.glxClientVersion
)))
427 if (NULL
!= strstr(glx_extensions
, "GLX_SGIX_fbconfig")) {
428 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
429 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
430 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
432 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxClientVersion
);
435 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
436 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
437 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
440 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
441 * enable this function when the Xserver understand GLX 1.3 or newer
443 if (!strcmp("1.2", WineGLInfo
.glxServerVersion
))
444 pglXQueryDrawable
= NULL
;
446 pglXQueryDrawable
= wine_dlsym(RTLD_DEFAULT
, "glXQueryDrawable", NULL
, 0);
448 if (NULL
!= strstr(glx_extensions
, "GLX_ATI_render_texture")) {
449 pglXBindTexImageARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageARB");
450 pglXReleaseTexImageARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageARB");
451 pglXDrawableAttribARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribARB");
454 X11DRV_WineGL_LoadExtensions();
457 return (opengl_handle
!= NULL
);
460 wine_dlclose(opengl_handle
, NULL
, 0);
461 opengl_handle
= NULL
;
465 static inline Wine_GLContext
*alloc_context(void)
469 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
471 ret
->next
= context_list
;
472 if (context_list
) context_list
->prev
= ret
;
478 static inline void free_context(Wine_GLContext
*context
)
480 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
481 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
482 else context_list
= context
->next
;
484 HeapFree(GetProcessHeap(), 0, context
);
487 static inline Wine_GLContext
*get_context_from_GLXContext(GLXContext ctx
)
490 if (!ctx
) return NULL
;
491 for (ret
= context_list
; ret
; ret
= ret
->next
) if (ctx
== ret
->ctx
) break;
495 /* retrieve the GLX drawable to use on a given DC */
496 inline static Drawable
get_drawable( HDC hdc
)
498 GLXDrawable drawable
;
499 enum x11drv_escape_codes escape
= X11DRV_GET_GLX_DRAWABLE
;
501 if (!ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPCSTR
)&escape
,
502 sizeof(drawable
), (LPSTR
)&drawable
)) drawable
= 0;
506 inline static void set_drawable( HDC hdc
, Drawable drawable
)
508 struct x11drv_escape_set_drawable escape
;
510 escape
.code
= X11DRV_SET_DRAWABLE
;
511 escape
.drawable
= drawable
;
512 escape
.mode
= IncludeInferiors
;
513 escape
.org
.x
= escape
.org
.y
= 0;
514 escape
.drawable_org
.x
= escape
.drawable_org
.y
= 0;
516 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPCSTR
)&escape
, 0, NULL
);
519 /** for use of wglGetCurrentReadDCARB */
520 inline static HDC
get_hdc_from_Drawable(GLXDrawable d
)
523 for (ret
= context_list
; ret
; ret
= ret
->next
) {
524 if (d
== get_drawable( ret
->hdc
)) {
531 inline static BOOL
is_valid_context( Wine_GLContext
*ctx
)
534 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
535 return (ptr
!= NULL
);
538 static int describeContext(Wine_GLContext
* ctx
) {
541 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
542 pglXGetFBConfigAttrib(ctx
->display
, ctx
->fb_conf
, GLX_FBCONFIG_ID
, &tmp
);
543 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
544 pglXGetFBConfigAttrib(ctx
->display
, ctx
->fb_conf
, GLX_VISUAL_ID
, &tmp
);
545 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
550 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
553 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
556 if (pglXQueryDrawable
== NULL
) {
557 /** glXQueryDrawable not available so returns not supported */
561 TRACE(" Drawable %p have :\n", (void*) drawable
);
562 pglXQueryDrawable(ctx
->display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
563 TRACE(" - WIDTH as %d\n", tmp
);
564 pglXQueryDrawable(ctx
->display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
565 TRACE(" - HEIGHT as %d\n", tmp
);
566 pglXQueryDrawable(ctx
->display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
567 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
570 fbCfgs
= pglXChooseFBConfig(ctx
->display
, DefaultScreen(ctx
->display
), attribList
, &nElements
);
571 if (fbCfgs
== NULL
) {
575 pglXGetFBConfigAttrib(ctx
->display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
576 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
583 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
588 int wantColorBits
= 0;
591 while (0 != iWGLAttr
[cur
]) {
592 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
594 switch (iWGLAttr
[cur
]) {
595 case WGL_COLOR_BITS_ARB
:
596 pop
= iWGLAttr
[++cur
];
597 wantColorBits
= pop
; /** see end */
599 case WGL_BLUE_BITS_ARB
:
600 pop
= iWGLAttr
[++cur
];
601 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
602 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
604 case WGL_RED_BITS_ARB
:
605 pop
= iWGLAttr
[++cur
];
606 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
607 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
609 case WGL_GREEN_BITS_ARB
:
610 pop
= iWGLAttr
[++cur
];
611 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
612 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
614 case WGL_ALPHA_BITS_ARB
:
615 pop
= iWGLAttr
[++cur
];
617 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
618 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
620 case WGL_DEPTH_BITS_ARB
:
621 pop
= iWGLAttr
[++cur
];
622 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
623 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
625 case WGL_STENCIL_BITS_ARB
:
626 pop
= iWGLAttr
[++cur
];
627 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
628 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
630 case WGL_DOUBLE_BUFFER_ARB
:
631 pop
= iWGLAttr
[++cur
];
632 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
633 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
636 case WGL_PIXEL_TYPE_ARB
:
637 pop
= iWGLAttr
[++cur
];
639 case WGL_TYPE_COLORINDEX_ARB
: pop
= GLX_COLOR_INDEX_BIT
; isColor
= 1; break ;
640 case WGL_TYPE_RGBA_ARB
: pop
= GLX_RGBA_BIT
; break ;
641 case WGL_TYPE_RGBA_FLOAT_ATI
: pop
= GLX_RGBA_FLOAT_ATI_BIT
; break ;
643 ERR("unexpected PixelType(%x)\n", pop
);
646 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pop
);
647 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur
, pop
);
650 case WGL_SUPPORT_GDI_ARB
:
651 pop
= iWGLAttr
[++cur
];
652 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
653 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur
, pop
);
656 case WGL_DRAW_TO_BITMAP_ARB
:
657 pop
= iWGLAttr
[++cur
];
658 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
659 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur
, pop
);
661 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, GLX_PIXMAP_BIT
);
662 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_PIXMAP_BIT\n", cur
);
666 case WGL_DRAW_TO_WINDOW_ARB
:
667 pop
= iWGLAttr
[++cur
];
669 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, GLX_WINDOW_BIT
);
670 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_WINDOW_BIT\n", cur
);
674 case WGL_DRAW_TO_PBUFFER_ARB
:
675 pop
= iWGLAttr
[++cur
];
676 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
677 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur
, pop
);
679 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, GLX_PBUFFER_BIT
);
680 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_PBUFFER_BIT\n", cur
);
684 case WGL_ACCELERATION_ARB
:
685 case WGL_SUPPORT_OPENGL_ARB
:
686 pop
= iWGLAttr
[++cur
];
687 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
688 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
691 case WGL_PBUFFER_LARGEST_ARB
:
692 pop
= iWGLAttr
[++cur
];
693 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
694 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
697 case WGL_SAMPLE_BUFFERS_ARB
:
698 pop
= iWGLAttr
[++cur
];
699 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
700 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
703 case WGL_SAMPLES_ARB
:
704 pop
= iWGLAttr
[++cur
];
705 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
706 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
709 case WGL_TEXTURE_FORMAT_ARB
:
710 case WGL_TEXTURE_TARGET_ARB
:
711 case WGL_MIPMAP_TEXTURE_ARB
:
712 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
713 pop
= iWGLAttr
[++cur
];
715 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
717 if (use_render_texture_ati
) {
718 /** nothing to do here */
720 else if (!use_render_texture_emulation
) {
721 if (WGL_NO_TEXTURE_ARB
!= pop
) {
722 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
723 return -1; /** error: don't support it */
725 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
726 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, GLX_PBUFFER_BIT
);
731 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
732 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
733 pop
= iWGLAttr
[++cur
];
734 /** cannot be converted, see direct handling on
735 * - wglGetPixelFormatAttribivARB
736 * TODO: wglChoosePixelFormat
741 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
748 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
749 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
752 * The number of color bitplanes in each color buffer. For RGBA
753 * pixel types, it is the size of the color buffer, excluding the
754 * alpha bitplanes. For color-index pixels, it is the size of the
755 * color index buffer.
758 * This attribute defines the number of bits per color buffer.
759 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
760 * this is equal to the depth value reported in the X11 visual.
761 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
762 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
765 if (0 < wantColorBits
) {
767 wantColorBits
+= sz_alpha
;
769 if (32 < wantColorBits
) {
770 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits
);
773 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, wantColorBits
);
774 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur
, wantColorBits
);
780 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
781 * In our WGL implementation we only support a subset of these formats namely the format of
782 * Wine's main visual and offscreen formats (if they are available).
783 * This function converts a WGL format to its corresponding GLX one. It returns the index (zero-based)
784 * into the GLX FB config table and it returns the number of supported WGL formats in fmt_count.
786 static BOOL
ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, int *fmt_index
, int *fmt_count
)
790 GLXFBConfig
* cfgs
= NULL
;
794 int nFormats
= 1; /* Start at 1 as we always have a main visual */
795 VisualID visualid
= 0;
797 /* Request to look up the format of the main visual when iPixelFormat = 1 */
798 if(iPixelFormat
== 1) visualid
= XVisualIDFromVisual(visual
);
800 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
801 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
802 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
803 * bas this call lists both types of formats instead of only onscreen ones. */
804 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
805 if (NULL
== cfgs
|| 0 == nCfgs
) {
806 ERR("glXChooseFBConfig returns NULL\n");
807 if(cfgs
!= NULL
) XFree(cfgs
);
811 /* Find the requested offscreen format and count the number of offscreen formats */
812 for(i
=0; i
<nCfgs
; i
++) {
813 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
814 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
816 /* We are looking up the GLX index of our main visual and have found it :) */
817 if(iPixelFormat
== 1 && visualid
== tmp_vis_id
) {
819 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id
, *fmt_index
, tmp_vis_id
);
822 /* We found an offscreen rendering format :) */
823 else if(tmp_vis_id
== 0) {
825 TRACE("Checking offscreen format FBCONFIG_ID 0x%x at index %d\n", tmp_fmt_id
, i
);
827 if(iPixelFormat
== nFormats
) {
829 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id
, iPixelFormat
, i
);
834 *fmt_count
= nFormats
;
835 TRACE("Number of offscreen formats: %d; returning index: %d\n", *fmt_count
, *fmt_index
);
837 if(cfgs
!= NULL
) XFree(cfgs
);
839 if(res
== FALSE
&& iPixelFormat
== 1)
840 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visualid
);
846 * X11DRV_ChoosePixelFormat
848 * Equivalent of glXChooseVisual
850 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
851 const PIXELFORMATDESCRIPTOR
*ppfd
) {
852 GLXFBConfig
* cfgs
= NULL
;
859 ERR("No libGL on this box - disabling OpenGL support !\n");
863 if (TRACE_ON(opengl
)) {
864 TRACE("(%p,%p)\n", physDev
, ppfd
);
866 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
871 ERR("Can't get an opengl visual!\n");
875 /* Get a list containing all supported FB configurations */
876 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), NULL
, &nCfgs
);
877 if (NULL
== cfgs
|| 0 == nCfgs
) {
878 ERR("glXChooseFBConfig returns NULL (glError: %d)\n", pglGetError());
882 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
883 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, 1 /* main visual */, &fmt_index
, &value
)) {
884 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual
->visualid
);
891 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_RENDER_TYPE
, &value
);
892 if (value
& GLX_RGBA_BIT
)
893 iPixelType
= PFD_TYPE_RGBA
;
895 iPixelType
= PFD_TYPE_COLORINDEX
;
897 if (ppfd
->iPixelType
!= iPixelType
) {
902 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_DOUBLEBUFFER
, &value
); if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
903 if (!(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
)) {
904 if ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != (dwFlags
& PFD_DOUBLEBUFFER
)) {
910 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_STEREO
, &value
); if (value
) dwFlags
|= PFD_STEREO
;
911 if (!(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
)) {
912 if ((ppfd
->dwFlags
& PFD_STEREO
) != (dwFlags
& PFD_STEREO
)) {
918 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_ALPHA_SIZE
, &value
);
919 if (ppfd
->iPixelType
==PFD_TYPE_RGBA
&& ppfd
->cAlphaBits
&& !value
) {
924 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_DEPTH_SIZE
, &value
);
925 if (ppfd
->cDepthBits
&& !value
) {
930 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_STENCIL_SIZE
, &value
);
931 if (ppfd
->cStencilBits
&& !value
) {
936 pglXGetFBConfigAttrib(gdi_display
, cfgs
[fmt_index
], GLX_AUX_BUFFERS
, &value
);
937 if (ppfd
->cAuxBuffers
&& !value
) {
941 /* When we pass all the checks we have found a matching format :) */
943 TRACE("Successfully found a matching mode, returning index: %d\n", ret
);
948 TRACE("No matching mode was found returning 0\n");
950 if (NULL
!= cfgs
) XFree(cfgs
);
956 * X11DRV_DescribePixelFormat
958 * Get the pixel-format descriptor associated to the given id
960 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
963 PIXELFORMATDESCRIPTOR
*ppfd
) {
964 /*XVisualInfo *vis;*/
968 GLXFBConfig
* cfgs
= NULL
;
975 ERR("No libGL on this box - disabling OpenGL support !\n");
979 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
982 cfgs
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs
);
985 if (NULL
== cfgs
|| 0 == nCfgs
) {
986 ERR("unexpected iPixelFormat(%d), returns NULL\n", iPixelFormat
);
987 return 0; /* unespected error */
990 /* This function always reports the total number of supported pixel formats.
991 * At the moment we only support the pixel format corresponding to the main
992 * visual which got created at x11drv initialization. More formats could be
993 * supported if there was a way to recreate x11 windows in x11drv.
994 * Because we only support one format nCfgs needs to be set to 1.
999 /* The application is only querying the number of visuals */
1001 if (NULL
!= cfgs
) XFree(cfgs
);
1002 wine_tsx11_unlock();
1006 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1007 ERR("Wrong structure size !\n");
1008 /* Should set error */
1012 if (nCfgs
< iPixelFormat
|| 1 > iPixelFormat
) {
1013 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL\n", iPixelFormat
, nCfgs
);
1017 /* Retrieve the index in the FBConfig table corresponding to the visual ID from the main visual */
1018 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, &fmt_index
, &value
)) {
1019 ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
1024 cur
= cfgs
[fmt_index
];
1026 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1027 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1030 /* These flags are always the same... */
1031 ppfd
->dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
1032 /* Now the flags extracted from the Visual */
1036 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_CONFIG_CAVEAT
, &value
);
1037 if(value
== GLX_SLOW_CONFIG
)
1038 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1040 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_DOUBLEBUFFER
, &value
); if (value
) ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1041 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1044 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_RENDER_TYPE
, &value
);
1045 if (value
& GLX_RGBA_BIT
)
1046 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1048 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1051 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_BUFFER_SIZE
, &value
);
1052 ppfd
->cColorBits
= value
;
1054 /* Red, green, blue and alpha bits / shifts */
1055 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1056 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_RED_SIZE
, &rb
);
1057 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_GREEN_SIZE
, &gb
);
1058 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_BLUE_SIZE
, &bb
);
1059 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_ALPHA_SIZE
, &ab
);
1061 ppfd
->cRedBits
= rb
;
1062 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1063 ppfd
->cBlueBits
= bb
;
1064 ppfd
->cBlueShift
= ab
;
1065 ppfd
->cGreenBits
= gb
;
1066 ppfd
->cGreenShift
= bb
+ ab
;
1067 ppfd
->cAlphaBits
= ab
;
1068 ppfd
->cAlphaShift
= 0;
1071 ppfd
->cRedShift
= 0;
1072 ppfd
->cBlueBits
= 0;
1073 ppfd
->cBlueShift
= 0;
1074 ppfd
->cGreenBits
= 0;
1075 ppfd
->cGreenShift
= 0;
1076 ppfd
->cAlphaBits
= 0;
1077 ppfd
->cAlphaShift
= 0;
1079 /* Accums : to do ... */
1082 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_DEPTH_SIZE
, &value
);
1083 ppfd
->cDepthBits
= value
;
1086 pglXGetFBConfigAttrib(gdi_display
, cur
, GLX_STENCIL_SIZE
, &value
);
1087 ppfd
->cStencilBits
= value
;
1089 wine_tsx11_unlock();
1091 /* Aux : to do ... */
1093 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1095 if (TRACE_ON(opengl
)) {
1096 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1100 if (NULL
!= cfgs
) XFree(cfgs
);
1101 wine_tsx11_unlock();
1107 * X11DRV_GetPixelFormat
1109 * Get the pixel-format id used by this DC
1111 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1112 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1114 return physDev
->current_pf
;
1118 * X11DRV_SetPixelFormat
1120 * Set the pixel-format id used by this DC
1122 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1124 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1125 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1127 /* At the moment we only support the pixelformat corresponding to the main
1128 * x11drv visual which got created at x11drv initialization. More formats
1129 * can be supported if there was a way to recreate x11 windows in x11drv
1131 if(iPixelFormat
!= 1) {
1132 TRACE("Invalid iPixelFormat: %d\n", iPixelFormat
);
1136 physDev
->current_pf
= iPixelFormat
;
1138 if (TRACE_ON(opengl
)) {
1140 GLXFBConfig
* cfgs_fmt
= NULL
;
1141 GLXFBConfig cur_cfg
;
1146 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, &fmt_index
, &value
)) {
1147 ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
1148 return TRUE
; /* Return true because the SetPixelFormat stuff itself passed */
1152 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1154 * in case of root window created HDCs we crash here :(
1156 Drawable drawable = get_drawable( physDev->hdc );
1157 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1158 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1159 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1160 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1161 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1162 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1163 TRACE(" - WIDTH as %d\n", tmp);
1164 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1165 TRACE(" - HEIGHT as %d\n", tmp);
1167 cfgs_fmt
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs_fmt
);
1168 cur_cfg
= cfgs_fmt
[fmt_index
];
1169 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cur_cfg
, GLX_FBCONFIG_ID
, &value
);
1171 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1173 TRACE(" FBConfig have :\n");
1174 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1175 pglXGetFBConfigAttrib(gdi_display
, cur_cfg
, GLX_VISUAL_ID
, &value
);
1176 TRACE(" - VISUAL_ID 0x%x\n", value
);
1177 pglXGetFBConfigAttrib(gdi_display
, cur_cfg
, GLX_DRAWABLE_TYPE
, &value
);
1178 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1185 /* OpenGL32 wglCreateContext */
1186 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1188 Wine_GLContext
*ret
;
1189 GLXFBConfig
* cfgs_fmt
= NULL
;
1190 GLXFBConfig cur_cfg
;
1191 int hdcPF
= 1; /* We can only use the Wine's main visual which has an index of 1 */
1197 HDC hdc
= physDev
->hdc
;
1199 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1201 /* First, get the visual in use by the X11DRV */
1202 if (!gdi_display
) return 0;
1204 /* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the correspondig GLX format.
1205 * If this fails something is very wrong on the system. */
1206 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, &fmt_index
, &tmp
)) {
1207 ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n");
1208 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1212 cfgs_fmt
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs_fmt
);
1213 if (NULL
== cfgs_fmt
|| 0 == nCfgs_fmt
) {
1214 ERR("Cannot get FB Configs, expect problems.\n");
1215 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1219 if (nCfgs_fmt
< fmt_index
) {
1220 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, fmt_index
, nCfgs_fmt
);
1221 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1225 cur_cfg
= cfgs_fmt
[fmt_index
];
1226 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cur_cfg
, GLX_FBCONFIG_ID
, &value
);
1228 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1229 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1234 /* The context will be allocated in the wglMakeCurrent call */
1236 ret
= alloc_context();
1237 wine_tsx11_unlock();
1239 ret
->display
= gdi_display
;
1240 ret
->fb_conf
= cur_cfg
;
1242 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, cur_cfg
);
1244 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1248 /* OpenGL32 wglDeleteContext */
1249 BOOL WINAPI
X11DRV_wglDeleteContext(HGLRC hglrc
)
1251 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1254 TRACE("(%p)\n", hglrc
);
1257 /* A game (Half Life not to name it) deletes twice the same context,
1258 * so make sure it is valid first */
1259 if (is_valid_context( ctx
))
1261 if (ctx
->ctx
) pglXDestroyContext(ctx
->display
, ctx
->ctx
);
1266 WARN("Error deleting context !\n");
1267 SetLastError(ERROR_INVALID_HANDLE
);
1270 wine_tsx11_unlock();
1275 /* OpenGL32 wglGetCurrentContext() */
1276 HGLRC WINAPI
X11DRV_wglGetCurrentContext(void) {
1278 Wine_GLContext
*ret
;
1283 gl_ctx
= pglXGetCurrentContext();
1284 ret
= get_context_from_GLXContext(gl_ctx
);
1285 wine_tsx11_unlock();
1287 TRACE(" returning %p (GL context %p)\n", ret
, gl_ctx
);
1292 /* OpenGL32 wglGetCurrentDC */
1293 HDC WINAPI
X11DRV_wglGetCurrentDC(void) {
1295 Wine_GLContext
*ret
;
1300 gl_ctx
= pglXGetCurrentContext();
1301 ret
= get_context_from_GLXContext(gl_ctx
);
1302 wine_tsx11_unlock();
1305 TRACE(" returning %p (GL context %p - Wine context %p)\n", ret
->hdc
, gl_ctx
, ret
);
1308 TRACE(" no Wine context found for GLX context %p\n", gl_ctx
);
1313 /* OpenGL32 wglGetCurrentReadDCARB */
1314 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1322 gl_d
= pglXGetCurrentReadDrawable();
1323 ret
= get_hdc_from_Drawable(gl_d
);
1324 wine_tsx11_unlock();
1326 TRACE(" returning %p (GL drawable %lu)\n", ret
, gl_d
);
1330 /* OpenGL32: wglGetProcAddress */
1331 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1334 const WineGLExtension
*ext
;
1336 int padding
= 32 - strlen(lpszProc
);
1340 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1341 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1342 ext
= WineGLExtensionList
[i
];
1343 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1344 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1345 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1346 return ext
->extEntryPoints
[j
].funcAddress
;
1351 ERR("(%s) - not found\n", lpszProc
);
1357 /* OpenGL32 wglMakeCurrent */
1358 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1360 HDC hdc
= physDev
->hdc
;
1361 DWORD type
= GetObjectType(hdc
);
1363 TRACE("(%p,%p)\n", hdc
, hglrc
);
1366 if (hglrc
== NULL
) {
1367 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1368 NtCurrentTeb()->glContext
= NULL
;
1370 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1371 Drawable drawable
= physDev
->drawable
;
1372 if (ctx
->ctx
== NULL
) {
1373 int draw_vis_id
, ctx_vis_id
;
1374 VisualID visualid
= (VisualID
)GetPropA( GetDesktopWindow(), "__wine_x11_visual_id" );
1375 TRACE(" Wine desktop VISUAL_ID is 0x%x\n", (unsigned int) visualid
);
1376 draw_vis_id
= describeDrawable(ctx
, drawable
);
1377 ctx_vis_id
= describeContext(ctx
);
1379 if (-1 == draw_vis_id
|| (draw_vis_id
== visualid
&& draw_vis_id
!= ctx_vis_id
)) {
1381 * Inherits from root window so reuse desktop visual
1383 XVisualInfo
template;
1386 template.visualid
= visualid
;
1387 vis
= XGetVisualInfo(ctx
->display
, VisualIDMask
, &template, &num
);
1389 TRACE(" Creating GLX Context\n");
1390 ctx
->ctx
= pglXCreateContext(ctx
->display
, vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1392 TRACE(" Creating GLX Context\n");
1393 ctx
->ctx
= pglXCreateContext(ctx
->display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1395 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1397 TRACE(" make current for dis %p, drawable %p, ctx %p\n", ctx
->display
, (void*) drawable
, ctx
->ctx
);
1398 ret
= pglXMakeCurrent(ctx
->display
, drawable
, ctx
->ctx
);
1399 NtCurrentTeb()->glContext
= ctx
;
1400 if(ret
&& type
== OBJ_MEMDC
)
1402 ctx
->do_escape
= TRUE
;
1403 pglDrawBuffer(GL_FRONT_LEFT
);
1406 wine_tsx11_unlock();
1407 TRACE(" returning %s\n", (ret
? "True" : "False"));
1411 /* OpenGL32 wglMakeContextCurrentARB */
1412 static BOOL WINAPI
X11DRV_wglMakeContextCurrentARB(HDC hDrawDC
, HDC hReadDC
, HGLRC hglrc
)
1415 TRACE("(%p,%p,%p)\n", hDrawDC
, hReadDC
, hglrc
);
1418 if (hglrc
== NULL
) {
1419 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1421 if (NULL
== pglXMakeContextCurrent
) {
1424 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1425 Drawable d_draw
= get_drawable( hDrawDC
);
1426 Drawable d_read
= get_drawable( hReadDC
);
1428 if (ctx
->ctx
== NULL
) {
1429 ctx
->ctx
= pglXCreateContext(ctx
->display
, ctx
->vis
, NULL
, GetObjectType(hDrawDC
) == OBJ_MEMDC
? False
: True
);
1430 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1432 ret
= pglXMakeContextCurrent(ctx
->display
, d_draw
, d_read
, ctx
->ctx
);
1435 wine_tsx11_unlock();
1437 TRACE(" returning %s\n", (ret
? "True" : "False"));
1441 /* OpenGL32 wglShaderLists */
1442 BOOL WINAPI
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1443 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1444 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1446 TRACE("(%p, %p)\n", org
, dest
);
1448 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1449 ERR("Could not share display lists, context already created !\n");
1452 if (org
->ctx
== NULL
) {
1454 describeContext(org
);
1455 org
->ctx
= pglXCreateContext(org
->display
, org
->vis
, NULL
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1456 wine_tsx11_unlock();
1457 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1461 describeContext(dest
);
1462 /* Create the destination context with display lists shared */
1463 dest
->ctx
= pglXCreateContext(org
->display
, dest
->vis
, org
->ctx
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1464 wine_tsx11_unlock();
1465 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1472 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1474 /* We are running using client-side rendering fonts... */
1478 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1482 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1483 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1484 wine_tsx11_unlock();
1486 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1487 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1488 int height
, width_int
;
1490 TRACE("Glyph : %3d / List : %ld\n", glyph
, listBase
);
1491 if (needed_size
== GDI_ERROR
) {
1492 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1495 TRACE(" - needed size : %d\n", needed_size
);
1498 if (needed_size
> size
) {
1500 HeapFree(GetProcessHeap(), 0, bitmap
);
1501 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1502 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1503 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1505 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1506 if (TRACE_ON(opengl
)) {
1507 unsigned int height
, width
, bitmask
;
1508 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1510 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1511 TRACE(" - origin : (%ld , %ld)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1512 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1513 if (needed_size
!= 0) {
1514 TRACE(" - bitmap :\n");
1515 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1517 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1522 if (*bitmap_
& bitmask
)
1527 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1533 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1534 * glyph for it to be drawn properly.
1536 if (needed_size
!= 0) {
1537 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1538 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1540 for (width
= 0; width
< width_int
; width
++) {
1541 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1542 ((int *) bitmap
)[height
* width_int
+ width
];
1548 pglNewList(listBase
++, GL_COMPILE
);
1549 if (needed_size
!= 0) {
1550 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1551 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1552 gm
.gmCellIncX
, gm
.gmCellIncY
,
1555 /* This is the case of 'empty' glyphs like the space character */
1556 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1559 wine_tsx11_unlock();
1563 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1564 wine_tsx11_unlock();
1566 HeapFree(GetProcessHeap(), 0, bitmap
);
1567 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1572 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1573 wine_tsx11_unlock();
1575 HeapFree(GetProcessHeap(), 0, bitmap
);
1576 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1580 /* OpenGL32 wglUseFontBitmapsA */
1581 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1583 Font fid
= physDev
->font
;
1585 TRACE("(%p, %ld, %ld, %ld) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1588 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
1592 /* I assume that the glyphs are at the same position for X and for Windows */
1593 pglXUseXFont(fid
, first
, count
, listBase
);
1594 wine_tsx11_unlock();
1598 /* OpenGL32 wglUseFontBitmapsW */
1599 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1601 Font fid
= physDev
->font
;
1603 TRACE("(%p, %ld, %ld, %ld) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1606 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1609 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1612 /* I assume that the glyphs are at the same position for X and for Windows */
1613 pglXUseXFont(fid
, first
, count
, listBase
);
1614 wine_tsx11_unlock();
1618 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1619 void X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
) {
1620 TRACE("pname: 0x%x, params: %p\n", pname
, params
);
1621 if (pname
== GL_DEPTH_BITS
) {
1622 GLXContext gl_ctx
= pglXGetCurrentContext();
1623 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1624 /*TRACE("returns Wine Ctx as %p\n", ret);*/
1626 * if we cannot find a Wine Context
1627 * we only have the default wine desktop context,
1628 * so if we have only a 24 depth say we have 32
1630 if (NULL
== ret
&& 24 == *params
) {
1633 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
1635 if (pname
== GL_ALPHA_BITS
) {
1637 GLXContext gl_ctx
= pglXGetCurrentContext();
1638 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1639 pglXGetFBConfigAttrib(ret
->display
, ret
->fb_conf
, GLX_ALPHA_SIZE
, &tmp
);
1640 TRACE("returns GL_ALPHA_BITS as '%d'\n", tmp
);
1645 /* WGL_ARB_extensions_string: wglGetExtensionsStringARB */
1646 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
1647 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
1648 return WineGLInfo
.wglExtensions
;
1651 /* WGL_ARB_pbuffer: wglCreatePbufferARB */
1652 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
1654 Wine_GLPBuffer
* object
= NULL
;
1655 GLXFBConfig
* cfgs
= NULL
;
1658 unsigned nAttribs
= 0;
1661 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
1663 if (0 >= iPixelFormat
) {
1664 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
1665 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1666 return NULL
; /* unexpected error */
1669 cfgs
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs
);
1671 if (NULL
== cfgs
|| 0 == nCfgs
) {
1672 ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc
, iPixelFormat
);
1673 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1674 return NULL
; /* unexpected error */
1677 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1678 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, &fmt_index
, &nCfgs
)) {
1679 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
1680 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1681 goto create_failed
; /* unexpected error */
1684 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
1685 if (NULL
== object
) {
1686 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1687 goto create_failed
; /* unexpected error */
1690 object
->display
= gdi_display
;
1691 object
->width
= iWidth
;
1692 object
->height
= iHeight
;
1694 nAttribs
= ConvertAttribWGLtoGLX(piAttribList
, attribs
, object
);
1695 if (-1 == nAttribs
) {
1696 WARN("Cannot convert WGL to GLX attributes\n");
1699 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
1700 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
1701 while (0 != *piAttribList
) {
1703 switch (*piAttribList
) {
1704 case WGL_TEXTURE_FORMAT_ARB
: {
1706 attr_v
= *piAttribList
;
1707 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
1708 if (use_render_texture_ati
) {
1711 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
1712 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
1713 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
1715 SetLastError(ERROR_INVALID_DATA
);
1718 object
->use_render_texture
= 1;
1719 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
1721 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
1722 object
->use_render_texture
= 0;
1724 if (!use_render_texture_emulation
) {
1725 SetLastError(ERROR_INVALID_DATA
);
1729 case WGL_TEXTURE_RGB_ARB
:
1730 object
->use_render_texture
= GL_RGB
;
1732 case WGL_TEXTURE_RGBA_ARB
:
1733 object
->use_render_texture
= GL_RGBA
;
1736 SetLastError(ERROR_INVALID_DATA
);
1744 case WGL_TEXTURE_TARGET_ARB
: {
1746 attr_v
= *piAttribList
;
1747 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
1748 if (use_render_texture_ati
) {
1751 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
1752 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
1753 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
1754 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
1756 SetLastError(ERROR_INVALID_DATA
);
1759 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
1761 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
1762 object
->texture_target
= 0;
1764 if (!use_render_texture_emulation
) {
1765 SetLastError(ERROR_INVALID_DATA
);
1769 case WGL_TEXTURE_CUBE_MAP_ARB
: {
1770 if (iWidth
!= iHeight
) {
1771 SetLastError(ERROR_INVALID_DATA
);
1774 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
1775 object
->texture_bind_target
= GL_TEXTURE_CUBE_MAP
;
1778 case WGL_TEXTURE_1D_ARB
: {
1780 SetLastError(ERROR_INVALID_DATA
);
1783 object
->texture_target
= GL_TEXTURE_1D
;
1784 object
->texture_bind_target
= GL_TEXTURE_1D
;
1787 case WGL_TEXTURE_2D_ARB
: {
1788 object
->texture_target
= GL_TEXTURE_2D
;
1789 object
->texture_bind_target
= GL_TEXTURE_2D
;
1793 SetLastError(ERROR_INVALID_DATA
);
1801 case WGL_MIPMAP_TEXTURE_ARB
: {
1803 attr_v
= *piAttribList
;
1804 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
1805 if (use_render_texture_ati
) {
1806 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
1808 if (!use_render_texture_emulation
) {
1809 SetLastError(ERROR_INVALID_DATA
);
1819 PUSH1(attribs
, None
);
1820 object
->drawable
= pglXCreatePbuffer(gdi_display
, cfgs
[fmt_index
], attribs
);
1821 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
1822 if (!object
->drawable
) {
1823 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1824 goto create_failed
; /* unexpected error */
1826 TRACE("->(%p)\n", object
);
1830 return (HPBUFFERARB
) object
;
1833 if (NULL
!= cfgs
) XFree(cfgs
);
1834 HeapFree(GetProcessHeap(), 0, object
);
1835 TRACE("->(FAILED)\n");
1836 return (HPBUFFERARB
) NULL
;
1839 /* WGL_ARB_pbuffer: wglDestroyPbufferARB */
1840 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
1842 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
1843 TRACE("(%p)\n", hPbuffer
);
1844 if (NULL
== object
) {
1845 SetLastError(ERROR_INVALID_HANDLE
);
1848 pglXDestroyPbuffer(object
->display
, object
->drawable
);
1849 HeapFree(GetProcessHeap(), 0, object
);
1853 /* WGL_ARB_pbuffer: wglGetPbufferDCARB */
1854 static HDC WINAPI
X11DRV_wglGetPbufferDCARB(HPBUFFERARB hPbuffer
)
1856 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
1858 if (NULL
== object
) {
1859 SetLastError(ERROR_INVALID_HANDLE
);
1862 hDC
= CreateCompatibleDC(object
->hdc
);
1864 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
1865 * We only support one onscreen rendering format (the one from the main visual), so use that. */
1866 SetPixelFormat(hDC
, 1, NULL
);
1867 set_drawable(hDC
, object
->drawable
); /* works ?? */
1868 TRACE("(%p)->(%p)\n", hPbuffer
, hDC
);
1872 /* WGL_ARB_pbuffer: wglQueryPbufferARB */
1873 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
1875 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
1876 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
1877 if (NULL
== object
) {
1878 SetLastError(ERROR_INVALID_HANDLE
);
1881 switch (iAttribute
) {
1882 case WGL_PBUFFER_WIDTH_ARB
:
1883 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
1885 case WGL_PBUFFER_HEIGHT_ARB
:
1886 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
1889 case WGL_PBUFFER_LOST_ARB
:
1890 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
1893 case WGL_TEXTURE_FORMAT_ARB
:
1894 if (use_render_texture_ati
) {
1896 int type
= WGL_NO_TEXTURE_ARB
;
1897 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
1899 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
1900 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
1901 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
1905 if (!object
->use_render_texture
) {
1906 *piValue
= WGL_NO_TEXTURE_ARB
;
1908 if (!use_render_texture_emulation
) {
1909 SetLastError(ERROR_INVALID_HANDLE
);
1912 if (GL_RGBA
== object
->use_render_texture
) {
1913 *piValue
= WGL_TEXTURE_RGBA_ARB
;
1915 *piValue
= WGL_TEXTURE_RGB_ARB
;
1921 case WGL_TEXTURE_TARGET_ARB
:
1922 if (use_render_texture_ati
) {
1924 int type
= WGL_NO_TEXTURE_ARB
;
1925 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
1927 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
1928 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
1929 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
1930 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
1934 if (!object
->texture_target
) {
1935 *piValue
= WGL_NO_TEXTURE_ARB
;
1937 if (!use_render_texture_emulation
) {
1938 SetLastError(ERROR_INVALID_DATA
);
1941 switch (object
->texture_target
) {
1942 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
1943 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
1944 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
1950 case WGL_MIPMAP_TEXTURE_ARB
:
1951 if (use_render_texture_ati
) {
1952 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
1954 *piValue
= GL_FALSE
; /** don't support that */
1955 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
1960 FIXME("unexpected attribute %x\n", iAttribute
);
1967 /* WGL_ARB_pbuffer: wglReleasePbufferDCARB */
1968 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
1970 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
1975 /* WGL_ARB_pbuffer: wglSetPbufferAttribARB */
1976 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
1978 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
1979 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
1980 if (NULL
== object
) {
1981 SetLastError(ERROR_INVALID_HANDLE
);
1984 if (!object
->use_render_texture
) {
1985 SetLastError(ERROR_INVALID_HANDLE
);
1988 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
1991 if (NULL
!= pglXDrawableAttribARB
) {
1992 if (use_render_texture_ati
) {
1993 FIXME("Need conversion for GLX_ATI_render_texture\n");
1995 return pglXDrawableAttribARB(object
->display
, object
->drawable
, piAttribList
);
2000 /* WGL_ARB_pixel_format: wglChoosePixelFormatARB */
2001 GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2006 GLboolean res
= FALSE
;
2008 /* We need the visualid to check if the format is suitable */
2009 VisualID visualid
= XVisualIDFromVisual(visual
);
2011 GLXFBConfig
* cfgs
= NULL
;
2016 GLXFBConfig
* cfgs_fmt
= NULL
;
2023 int offscreen_index
= 1; /* Start at one because we always have a main visual at iPixelFormat=1 */
2025 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2026 if (NULL
!= pfAttribFList
) {
2027 FIXME("unused pfAttribFList\n");
2030 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2031 if (-1 == nAttribs
) {
2032 WARN("Cannot convert WGL to GLX attributes\n");
2035 PUSH1(attribs
, None
);
2037 /* Search for FB configurations matching the requirements in attribs */
2038 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2040 WARN("Compatible Pixel Format not found\n");
2044 /* Get a list of all FB configurations */
2045 cfgs_fmt
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs_fmt
);
2046 if (NULL
== cfgs_fmt
) {
2047 ERR("Failed to get All FB Configs\n");
2052 /* Loop through all matching formats and check if they are suitable.
2053 * Note that this function should at max return nMaxFormats different formats */
2054 for (it
= 0; pfmt_it
< nMaxFormats
&& it
< nCfgs
; ++it
) {
2055 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2057 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2061 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_VISUAL_ID
, &tmp_vis_id
);
2063 ERR("Failed to retrieve VISUAL_ID from GLXFBConfig, expect problems.\n");
2067 /* When the visualid of the GLXFBConfig matches the one of the main visual we have found our
2068 * only supported onscreen rendering format. This format has a WGL index of 1. */
2069 if(tmp_vis_id
== visualid
) {
2070 piFormats
[pfmt_it
] = 1;
2073 TRACE("Found compatible GLXFBConfig 0x%x with WGL index 1\n", fmt_id
);
2076 /* Only continue with this loop for offscreen rendering formats (visualid = 0) */
2077 else if(tmp_vis_id
!= 0) {
2078 TRACE("Discarded GLXFBConfig %0x with VisualID %x because the visualid is not the same as our main visual (%lx)\n", fmt_id
, tmp_vis_id
, visualid
);
2082 /* Find the index of the found format in the whole format table */
2083 for (it_fmt
= 0; it_fmt
< nCfgs_fmt
; ++it_fmt
) {
2084 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs_fmt
[it_fmt
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
2086 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2089 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_VISUAL_ID
, &tmp_vis_id
);
2091 ERR("Failed to retrieve VISUAL_ID from GLXFBConfig, expect problems.\n");
2094 /* The format of Wine's main visual is stored at index 1 of our WGL format table.
2095 * At higher indices we store offscreen rendering formats (visualid=0). Below we calculate
2096 * the index of the offscreen format. We do this by counting the number of offscreen formats
2097 * which we see until we reach our target format. */
2101 /* We have found the format in the table (note the format is offscreen) */
2102 if (fmt_id
== tmp_fmt_id
) {
2105 piFormats
[pfmt_it
] = offscreen_index
+ 1; /* Add 1 to get a one-based index */
2107 pglXGetFBConfigAttrib(gdi_display
, cfgs_fmt
[it_fmt
], GLX_ALPHA_SIZE
, &tmp
);
2108 TRACE("ALPHA_SIZE of FBCONFIG_ID(%d/%d) found as '%d'\n", it_fmt
+ 1, nCfgs_fmt
, tmp
);
2112 if (it_fmt
== nCfgs_fmt
) {
2113 ERR("Failed to get valid fmt for %d. Try next.\n", it
);
2116 TRACE("at %d/%d found FBCONFIG_ID(%d/%d)\n", it
+ 1, nCfgs
, piFormats
[it
], nCfgs_fmt
);
2119 *nNumFormats
= pfmt_it
;
2126 /* WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB */
2127 GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2129 FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2133 /* WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB */
2134 GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2137 GLXFBConfig
* cfgs
= NULL
;
2138 GLXFBConfig curCfg
= NULL
;
2143 int nWGLFormats
= 0;
2146 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2148 if (0 < iLayerPlane
) {
2149 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2153 cfgs
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs
);
2155 ERR("no FB Configs found for display(%p)\n", gdi_display
);
2159 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2160 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2161 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2162 if(!ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, &fmt_index
, &nWGLFormats
)) {
2163 ERR("Unable to convert iPixelFormat %d to a GLX one, expect problems!\n", iPixelFormat
);
2166 for (i
= 0; i
< nAttributes
; ++i
) {
2167 const int curWGLAttr
= piAttributes
[i
];
2168 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2170 switch (curWGLAttr
) {
2171 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2172 piValues
[i
] = nWGLFormats
;
2175 case WGL_SUPPORT_OPENGL_ARB
:
2176 piValues
[i
] = GL_TRUE
;
2179 case WGL_ACCELERATION_ARB
:
2180 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2182 if (nCfgs
< iPixelFormat
|| 0 >= iPixelFormat
) goto pix_error
;
2183 curCfg
= cfgs
[iPixelFormat
- 1];
2185 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, &tmp
);
2186 if (hTest
) goto get_error
;
2188 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2189 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_NO_ACCELERATION_ARB
; break;
2190 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2192 ERR("unexpected Config Caveat(%x)\n", tmp
);
2193 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2197 case WGL_TRANSPARENT_ARB
:
2198 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2199 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2200 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2201 if((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
)) goto pix_error
;
2202 curCfg
= cfgs
[fmt_index
];
2203 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, &tmp
);
2204 if (hTest
) goto get_error
;
2205 piValues
[i
] = GL_FALSE
;
2206 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2209 case WGL_PIXEL_TYPE_ARB
:
2210 curGLXAttr
= GLX_RENDER_TYPE
;
2211 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2212 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2213 if((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
)) goto pix_error
;
2214 curCfg
= cfgs
[fmt_index
];
2215 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, &tmp
);
2216 if (hTest
) goto get_error
;
2217 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2218 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2219 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2220 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2221 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2223 ERR("unexpected RenderType(%x)\n", tmp
);
2224 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2228 case WGL_COLOR_BITS_ARB
:
2229 /** see ConvertAttribWGLtoGLX for explain */
2230 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2231 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2232 if((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
)) goto pix_error
;
2233 curCfg
= cfgs
[fmt_index
];
2234 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, GLX_BUFFER_SIZE
, piValues
+ i
);
2235 if (hTest
) goto get_error
;
2236 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues
[i
]);
2237 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, GLX_ALPHA_SIZE
, &tmp
);
2238 if (hTest
) goto get_error
;
2239 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp
);
2240 piValues
[i
] = piValues
[i
] - tmp
;
2243 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2244 if (use_render_texture_ati
) {
2245 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2248 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2249 if (use_render_texture_ati
) {
2250 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2253 if (!use_render_texture_emulation
) {
2254 piValues
[i
] = GL_FALSE
;
2257 curGLXAttr
= GLX_RENDER_TYPE
;
2258 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2259 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2260 if((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
)) goto pix_error
;
2261 curCfg
= cfgs
[fmt_index
];
2262 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, &tmp
);
2263 if (hTest
) goto get_error
;
2264 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2265 piValues
[i
] = GL_FALSE
;
2268 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, GLX_DRAWABLE_TYPE
, &tmp
);
2269 if (hTest
) goto get_error
;
2270 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2273 case WGL_BLUE_BITS_ARB
:
2274 curGLXAttr
= GLX_BLUE_SIZE
;
2276 case WGL_RED_BITS_ARB
:
2277 curGLXAttr
= GLX_RED_SIZE
;
2279 case WGL_GREEN_BITS_ARB
:
2280 curGLXAttr
= GLX_GREEN_SIZE
;
2282 case WGL_ALPHA_BITS_ARB
:
2283 curGLXAttr
= GLX_ALPHA_SIZE
;
2285 case WGL_DEPTH_BITS_ARB
:
2286 curGLXAttr
= GLX_DEPTH_SIZE
;
2288 case WGL_STENCIL_BITS_ARB
:
2289 curGLXAttr
= GLX_STENCIL_SIZE
;
2291 case WGL_DOUBLE_BUFFER_ARB
:
2292 curGLXAttr
= GLX_DOUBLEBUFFER
;
2294 case WGL_STEREO_ARB
:
2295 curGLXAttr
= GLX_STEREO
;
2297 case WGL_AUX_BUFFERS_ARB
:
2298 curGLXAttr
= GLX_AUX_BUFFERS
;
2301 case WGL_SUPPORT_GDI_ARB
:
2302 case WGL_DRAW_TO_WINDOW_ARB
:
2303 case WGL_DRAW_TO_BITMAP_ARB
:
2304 case WGL_DRAW_TO_PBUFFER_ARB
:
2305 curGLXAttr
= GLX_X_RENDERABLE
;
2308 case WGL_PBUFFER_LARGEST_ARB
:
2309 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2312 case WGL_SAMPLE_BUFFERS_ARB
:
2313 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2316 case WGL_SAMPLES_ARB
:
2317 curGLXAttr
= GLX_SAMPLES_ARB
;
2321 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2324 if (0 != curGLXAttr
) {
2325 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2326 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2327 if((iPixelFormat
> 0) && ((iPixelFormat
> nWGLFormats
) || (fmt_index
> nCfgs
))) goto pix_error
;
2328 curCfg
= cfgs
[fmt_index
];
2329 hTest
= pglXGetFBConfigAttrib(gdi_display
, curCfg
, curGLXAttr
, piValues
+ i
);
2330 if (hTest
) goto get_error
;
2332 piValues
[i
] = GL_FALSE
;
2338 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2343 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nCfgs
);
2348 /* WGL_ARB_render_texture: wglBindTexImageARB */
2349 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2351 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2352 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2353 if (NULL
== object
) {
2354 SetLastError(ERROR_INVALID_HANDLE
);
2357 if (!object
->use_render_texture
) {
2358 SetLastError(ERROR_INVALID_HANDLE
);
2361 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2363 GLint prev_binded_tex
;
2364 pglGetIntegerv(object
->texture_target
, &prev_binded_tex
);
2365 if (NULL
== object
->render_ctx
) {
2366 object
->render_hdc
= X11DRV_wglGetPbufferDCARB(hPbuffer
);
2367 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2368 object
->render_ctx
= wglCreateContext(object
->render_hdc
);
2371 object
->prev_hdc
= X11DRV_wglGetCurrentDC();
2372 object
->prev_ctx
= X11DRV_wglGetCurrentContext();
2373 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2374 wglMakeCurrent(object
->render_hdc
, object
->render_ctx
);
2377 glBindTexture(object->texture_target, object->texture);
2378 if (GL_RGBA == object->use_render_texture) {
2379 glTexImage2D(object->texture_target, 0, GL_RGBA8, object->width, object->height, 0, GL_RGBA, GL_FLOAT, NULL);
2381 glTexImage2D(object->texture_target, 0, GL_RGB8, object->width, object->height, 0, GL_RGB, GL_FLOAT, NULL);
2385 object
->texture
= prev_binded_tex
;
2388 if (NULL
!= pglXBindTexImageARB
) {
2389 return pglXBindTexImageARB(object
->display
, object
->drawable
, iBuffer
);
2394 /* WGL_ARB_render_texture: wglReleaseTexImageARB */
2395 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2397 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2398 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2399 if (NULL
== object
) {
2400 SetLastError(ERROR_INVALID_HANDLE
);
2403 if (!object
->use_render_texture
) {
2404 SetLastError(ERROR_INVALID_HANDLE
);
2407 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2409 GLint prev_binded_tex;
2410 glGetIntegerv(object->texture_target, &prev_binded_tex);
2411 if (GL_TEXTURE_1D == object->texture_target) {
2412 glCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2414 glCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2416 glBindTexture(object->texture_target, prev_binded_tex);
2417 SwapBuffers(object->render_hdc);
2419 pglBindTexture(object
->texture_target
, object
->texture
);
2420 if (GL_TEXTURE_1D
== object
->texture_target
) {
2421 pglCopyTexSubImage1D(object
->texture_target
, object
->texture_level
, 0, 0, 0, object
->width
);
2423 pglCopyTexSubImage2D(object
->texture_target
, object
->texture_level
, 0, 0, 0, 0, object
->width
, object
->height
);
2426 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2427 wglMakeCurrent(object
->prev_hdc
, object
->prev_ctx
);
2430 if (NULL
!= pglXReleaseTexImageARB
) {
2431 return pglXReleaseTexImageARB(object
->display
, object
->drawable
, iBuffer
);
2436 /* WGL_EXT_extensions_string: wglGetExtensionsStringEXT */
2437 const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
2438 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2439 return WineGLInfo
.wglExtensions
;
2442 /* WGL_EXT_swap_control: wglGetSwapIntervalEXT */
2443 int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
2444 FIXME("(),stub!\n");
2445 return swap_interval
;
2448 /* WGL_EXT_swap_control: wglSwapIntervalEXT */
2449 BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
2450 TRACE("(%d)\n", interval
);
2451 swap_interval
= interval
;
2452 if (NULL
!= pglXSwapIntervalSGI
) {
2453 return 0 == pglXSwapIntervalSGI(interval
);
2455 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2459 /* Check if the supported GLX version matches requiredVersion */
2460 static BOOL
glxRequireVersion(int requiredVersion
)
2462 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2463 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
2469 static BOOL
glxRequireExtension(const char *requiredExtension
)
2471 if (strstr(WineGLInfo
.glxClientExtensions
, requiredExtension
) == NULL
) {
2478 static BOOL
register_extension(const WineGLExtension
* ext
)
2482 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
2483 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
2485 strcat(WineGLInfo
.wglExtensions
, " ");
2486 strcat(WineGLInfo
.wglExtensions
, ext
->extName
);
2488 TRACE("'%s'\n", ext
->extName
);
2490 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
2491 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
2496 static const WineGLExtension WGL_ARB_extensions_string
=
2498 "WGL_ARB_extensions_string",
2500 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
2504 static const WineGLExtension WGL_ARB_make_current_read
=
2506 "WGL_ARB_make_current_read",
2508 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
2509 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
2513 static const WineGLExtension WGL_ARB_multisample
=
2515 "WGL_ARB_multisample",
2518 static const WineGLExtension WGL_ARB_pbuffer
=
2522 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
2523 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
2524 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
2525 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
2526 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
2527 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
2531 static const WineGLExtension WGL_ARB_pixel_format
=
2533 "WGL_ARB_pixel_format",
2535 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
2536 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
2537 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
2541 static const WineGLExtension WGL_ARB_render_texture
=
2543 "WGL_ARB_render_texture",
2545 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
2546 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
2550 static const WineGLExtension WGL_EXT_extensions_string
=
2552 "WGL_EXT_extensions_string",
2554 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
2558 static const WineGLExtension WGL_EXT_swap_control
=
2560 "WGL_EXT_swap_control",
2562 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
2563 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
2569 * X11DRV_WineGL_LoadExtensions
2571 static void X11DRV_WineGL_LoadExtensions(void)
2573 WineGLInfo
.wglExtensions
[0] = 0;
2575 /* ARB Extensions */
2577 register_extension(&WGL_ARB_extensions_string
);
2579 if (glxRequireVersion(3))
2580 register_extension(&WGL_ARB_make_current_read
);
2582 if (glxRequireExtension("GLX_ARB_multisample"))
2583 register_extension(&WGL_ARB_multisample
);
2585 if (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer"))
2586 register_extension(&WGL_ARB_pbuffer
);
2588 register_extension(&WGL_ARB_pixel_format
);
2590 if (glxRequireExtension("GLX_ATI_render_texture") ||
2591 glxRequireExtension("GLX_ARB_render_texture"))
2592 register_extension(&WGL_ARB_render_texture
);
2594 /* EXT Extensions */
2596 register_extension(&WGL_EXT_extensions_string
);
2598 if (glxRequireExtension("GLX_SGI_swap_control"))
2599 register_extension(&WGL_EXT_swap_control
);
2603 static XID
create_glxpixmap(X11DRV_PDEVICE
*physDev
)
2607 XVisualInfo
template;
2612 /* Retrieve the visualid from our main visual which is the only visual we can use */
2613 template.visualid
= XVisualIDFromVisual(visual
);
2614 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
2616 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
2618 wine_tsx11_unlock();
2619 TRACE("return %lx\n", ret
);
2623 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
2629 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
2630 ret
= physDev
->drawable
; /* PBuffer */
2633 if(!physDev
->bitmap
->glxpixmap
)
2634 physDev
->bitmap
->glxpixmap
= create_glxpixmap(physDev
);
2635 ret
= physDev
->bitmap
->glxpixmap
;
2639 ret
= physDev
->drawable
;
2643 BOOL
destroy_glxpixmap(XID glxpixmap
)
2646 pglXDestroyGLXPixmap(gdi_display
, glxpixmap
);
2647 wine_tsx11_unlock();
2652 * X11DRV_SwapBuffers
2654 * Swap the buffers of this DC
2656 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
2658 GLXDrawable drawable
;
2659 if (!has_opengl()) {
2660 ERR("No libGL on this box - disabling OpenGL support !\n");
2664 TRACE_(opengl
)("(%p)\n", physDev
);
2666 drawable
= get_glxdrawable(physDev
);
2668 pglXSwapBuffers(gdi_display
, drawable
);
2669 wine_tsx11_unlock();
2674 static long prev_time
, frames
;
2676 DWORD time
= GetTickCount();
2678 /* every 1.5 seconds */
2679 if (time
- prev_time
> 1500) {
2680 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
2689 /***********************************************************************
2690 * X11DRV_setup_opengl_visual
2692 * Setup the default visual used for OpenGL and Direct3D, and the desktop
2693 * window (if it exists). If OpenGL isn't available, the visual is simply
2694 * set to the default visual for the display
2696 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
2698 XVisualInfo
*visual
= NULL
;
2699 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support, */
2700 int dblBuf
[] = {GLX_RGBA
,GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_DOUBLEBUFFER
, None
};
2701 if (!has_opengl()) return NULL
;
2704 visual
= pglXChooseVisual(display
, DefaultScreen(display
), dblBuf
);
2705 wine_tsx11_unlock();
2706 if (visual
== NULL
) {
2707 /* fallback to 16 bits depth, no alpha */
2708 int dblBuf2
[] = {GLX_RGBA
,GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, GLX_DOUBLEBUFFER
, None
};
2709 WARN("Failed to get a visual with at least 24 bits depth\n");
2712 visual
= pglXChooseVisual(display
, DefaultScreen(display
), dblBuf2
);
2713 wine_tsx11_unlock();
2714 if (visual
== NULL
) {
2715 /* fallback to no stencil */
2716 int dblBuf2
[] = {GLX_RGBA
,GLX_DEPTH_SIZE
, 16, GLX_DOUBLEBUFFER
, None
};
2717 WARN("Failed to get a visual with at least 8 bits of stencil\n");
2720 visual
= pglXChooseVisual(display
, DefaultScreen(display
), dblBuf2
);
2721 wine_tsx11_unlock();
2722 if (visual
== NULL
) {
2723 /* This should only happen if we cannot find a match with a depth size 16 */
2724 FIXME("Failed to find a suitable visual\n");
2729 TRACE("Visual ID %lx Chosen\n",visual
->visualid
);
2733 #else /* no OpenGL includes */
2735 void X11DRV_OpenGL_Init(Display
*display
)
2739 /***********************************************************************
2740 * ChoosePixelFormat (X11DRV.@)
2742 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
2743 const PIXELFORMATDESCRIPTOR
*ppfd
) {
2744 ERR("No OpenGL support compiled in.\n");
2749 /***********************************************************************
2750 * DescribePixelFormat (X11DRV.@)
2752 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
2755 PIXELFORMATDESCRIPTOR
*ppfd
) {
2756 ERR("No OpenGL support compiled in.\n");
2761 /***********************************************************************
2762 * GetPixelFormat (X11DRV.@)
2764 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
2765 ERR("No OpenGL support compiled in.\n");
2770 /***********************************************************************
2771 * SetPixelFormat (X11DRV.@)
2773 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
2775 const PIXELFORMATDESCRIPTOR
*ppfd
) {
2776 ERR("No OpenGL support compiled in.\n");
2781 /***********************************************************************
2782 * SwapBuffers (X11DRV.@)
2784 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
2785 ERR_(opengl
)("No OpenGL support compiled in.\n");
2790 /* OpenGL32 wglCreateContext */
2791 HGLRC WINAPI
X11DRV_wglCreateContext(HDC hdc
) {
2792 ERR_(opengl
)("No OpenGL support compiled in.\n");
2796 /* OpenGL32 wglDeleteContext */
2797 BOOL WINAPI
X11DRV_wglDeleteContext(HGLRC hglrc
) {
2798 ERR_(opengl
)("No OpenGL support compiled in.\n");
2802 /* OpenGL32 wglGetCurrentContext() */
2803 HGLRC WINAPI
X11DRV_wglGetCurrentContext(void) {
2804 ERR_(opengl
)("No OpenGL support compiled in.\n");
2808 /* OpenGL32 wglGetCurrentDC */
2809 HDC WINAPI
X11DRV_wglGetCurrentDC(void) {
2810 ERR_(opengl
)("No OpenGL support compiled in.\n");
2814 /* OpenGL32: wglGetProcAddress */
2815 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
2816 ERR_(opengl
)("No OpenGL support compiled in.\n");
2820 /* OpenGL32 wglMakeCurrent */
2821 BOOL WINAPI
X11DRV_wglMakeCurrent(HDC hdc
, HGLRC hglrc
) {
2822 ERR_(opengl
)("No OpenGL support compiled in.\n");
2826 /* OpenGL32 wglShaderLists */
2827 BOOL WINAPI
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
2828 ERR_(opengl
)("No OpenGL support compiled in.\n");
2832 /* OpenGL32 wglUseFontBitmapsA */
2833 BOOL WINAPI
X11DRV_wglUseFontBitmapsA(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
2835 ERR_(opengl
)("No OpenGL support compiled in.\n");
2839 /* OpenGL32 wglUseFontBitmapsW */
2840 BOOL WINAPI
X11DRV_wglUseFontBitmapsW(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
2842 ERR_(opengl
)("No OpenGL support compiled in.\n");
2846 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2847 void X11DRV_wglGetIntegerv(int pname
, int* params
) {
2848 ERR_(opengl
)("No OpenGL support compiled in.\n");
2851 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
2856 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
2861 BOOL
destroy_glxpixmap(XID glxpixmap
)
2866 #endif /* defined(HAVE_OPENGL) */