2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 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"
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
41 #include "wine/library.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
48 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
67 /* Redefines the constants */
68 #define CALLBACK __stdcall
69 #define WINAPI __stdcall
70 #define APIENTRY WINAPI
73 WINE_DECLARE_DEBUG_CHANNEL(fps
);
75 typedef struct wine_glextension
{
84 const char *glVersion
;
89 const char *glxServerVersion
;
90 const char *glxServerVendor
;
91 const char *glxServerExtensions
;
93 const char *glxClientVersion
;
94 const char *glxClientVendor
;
95 const char *glxClientExtensions
;
97 const char *glxExtensions
;
100 char wglExtensions
[4096];
103 typedef struct wine_glpixelformat
{
105 GLXFBConfig fbconfig
;
109 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
112 typedef struct wine_glcontext
{
114 BOOL has_been_current
;
119 WineGLPixelFormat
*fmt
;
120 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
121 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
124 Drawable drawables
[2];
125 BOOL refresh_drawables
;
129 typedef struct wine_glpbuffer
{
132 WineGLPixelFormat
* fmt
;
138 int use_render_texture
; /* This is also the internal texture format */
139 int texture_bind_target
;
141 GLint texture_format
;
142 GLuint texture_target
;
150 struct gdi_physdev dev
;
151 X11DRV_PDEVICE
*x11dev
;
152 enum dc_gl_type type
; /* type of GL device context */
155 Pixmap pixmap
; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
158 static const struct gdi_dc_funcs glxdrv_funcs
;
160 static inline struct glx_physdev
*get_glxdrv_dev( PHYSDEV dev
)
162 return (struct glx_physdev
*)dev
;
165 static struct list context_list
= LIST_INIT( context_list
);
166 static struct WineGLInfo WineGLInfo
= { 0 };
167 static int use_render_texture_emulation
= 1;
168 static int use_render_texture_ati
= 0;
169 static BOOL has_swap_control
;
170 static int swap_interval
= 1;
172 #define MAX_EXTENSIONS 16
173 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
174 static int WineGLExtensionListSize
;
176 static void X11DRV_WineGL_LoadExtensions(void);
177 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
178 static BOOL
glxRequireVersion(int requiredVersion
);
179 static BOOL
glxRequireExtension(const char *requiredExtension
);
181 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
182 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
183 TRACE(" - dwFlags : ");
184 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
185 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
186 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
187 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
188 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
189 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
190 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
191 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
192 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
193 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
194 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
195 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
196 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
197 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
198 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
199 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
200 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
201 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
202 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
203 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
207 TRACE(" - iPixelType : ");
208 switch (ppfd
->iPixelType
) {
209 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
210 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
214 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
215 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
216 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
217 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
218 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
219 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
220 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
221 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
222 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
224 TRACE(" - iLayerType : ");
225 switch (ppfd
->iLayerType
) {
226 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
227 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
228 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
233 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
234 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
236 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
238 MAKE_FUNCPTR(glXChooseVisual
)
239 MAKE_FUNCPTR(glXCopyContext
)
240 MAKE_FUNCPTR(glXCreateContext
)
241 MAKE_FUNCPTR(glXCreateGLXPixmap
)
242 MAKE_FUNCPTR(glXGetCurrentContext
)
243 MAKE_FUNCPTR(glXGetCurrentDrawable
)
244 MAKE_FUNCPTR(glXDestroyContext
)
245 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
246 MAKE_FUNCPTR(glXGetConfig
)
247 MAKE_FUNCPTR(glXIsDirect
)
248 MAKE_FUNCPTR(glXMakeCurrent
)
249 MAKE_FUNCPTR(glXSwapBuffers
)
250 MAKE_FUNCPTR(glXQueryExtension
)
251 MAKE_FUNCPTR(glXQueryVersion
)
254 MAKE_FUNCPTR(glXGetClientString
)
255 MAKE_FUNCPTR(glXQueryExtensionsString
)
256 MAKE_FUNCPTR(glXQueryServerString
)
259 MAKE_FUNCPTR(glXGetFBConfigs
)
260 MAKE_FUNCPTR(glXChooseFBConfig
)
261 MAKE_FUNCPTR(glXCreatePbuffer
)
262 MAKE_FUNCPTR(glXCreateNewContext
)
263 MAKE_FUNCPTR(glXDestroyPbuffer
)
264 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
265 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
266 MAKE_FUNCPTR(glXMakeContextCurrent
)
267 MAKE_FUNCPTR(glXQueryDrawable
)
268 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
271 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
272 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
273 static int (*pglXSwapIntervalSGI
)(int);
275 /* ATI GLX Extensions */
276 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
277 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
278 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
280 /* NV GLX Extension */
281 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
282 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
284 /* MESA GLX Extensions */
285 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
287 /* Standard OpenGL */
288 MAKE_FUNCPTR(glBindTexture
)
289 MAKE_FUNCPTR(glBitmap
)
290 MAKE_FUNCPTR(glCopyTexSubImage1D
)
291 MAKE_FUNCPTR(glCopyTexImage2D
)
292 MAKE_FUNCPTR(glCopyTexSubImage2D
)
293 MAKE_FUNCPTR(glDrawBuffer
)
294 MAKE_FUNCPTR(glEndList
)
295 MAKE_FUNCPTR(glGetError
)
296 MAKE_FUNCPTR(glGetIntegerv
)
297 MAKE_FUNCPTR(glGetString
)
298 MAKE_FUNCPTR(glNewList
)
299 MAKE_FUNCPTR(glPixelStorei
)
300 MAKE_FUNCPTR(glReadPixels
)
301 MAKE_FUNCPTR(glTexImage2D
)
302 MAKE_FUNCPTR(glFinish
)
303 MAKE_FUNCPTR(glFlush
)
306 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
308 /* In the future we might want to find the exact X or GLX error to report back to the app */
312 static BOOL infoInitialized
= FALSE
;
313 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
315 int screen
= DefaultScreen(gdi_display
);
316 Window win
= 0, root
= 0;
317 const char *gl_renderer
;
320 GLXContext ctx
= NULL
;
321 XSetWindowAttributes attr
;
323 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
327 infoInitialized
= TRUE
;
329 attr
.override_redirect
= True
;
330 attr
.colormap
= None
;
331 attr
.border_pixel
= 0;
335 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
338 WORD old_fs
= wine_get_fs();
339 /* Create a GLX Context. Without one we can't query GL information */
340 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
341 if (wine_get_fs() != old_fs
)
343 wine_set_fs( old_fs
);
344 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
345 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
349 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
354 root
= RootWindow( gdi_display
, vis
->screen
);
355 if (vis
->visual
!= DefaultVisual( gdi_display
, vis
->screen
))
356 attr
.colormap
= XCreateColormap( gdi_display
, root
, vis
->visual
, AllocNone
);
357 if ((win
= XCreateWindow( gdi_display
, root
, -1, -1, 1, 1, 0, vis
->depth
, InputOutput
,
358 vis
->visual
, CWBorderPixel
| CWOverrideRedirect
| CWColormap
, &attr
)))
359 XMapWindow( gdi_display
, win
);
363 if(pglXMakeCurrent(gdi_display
, win
, ctx
) == 0)
365 ERR_(winediag
)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
368 gl_renderer
= (const char *)pglGetString(GL_RENDERER
);
369 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
370 str
= (const char *) pglGetString(GL_EXTENSIONS
);
371 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
372 strcpy(WineGLInfo
.glExtensions
, str
);
374 /* Get the common GLX version supported by GLX client and server ( major/minor) */
375 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
377 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
378 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
379 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
381 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
382 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
383 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
385 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
386 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
388 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
389 TRACE("GL renderer : %s.\n", gl_renderer
);
390 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
391 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
392 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
393 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
394 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
395 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
397 if(!WineGLInfo
.glxDirect
)
399 int fd
= ConnectionNumber(gdi_display
);
400 struct sockaddr_un uaddr
;
401 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
403 /* In general indirect rendering on a local X11 server indicates a driver problem.
404 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
406 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
407 ERR_(winediag
)("Direct rendering is disabled, most likely your OpenGL drivers "
408 "haven't been installed correctly (using GL renderer %s, version %s).\n",
409 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
413 /* In general you would expect that if direct rendering is returned, that you receive hardware
414 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
415 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
416 * software rendering, it shows direct rendering.
418 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
419 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
420 * it shows 'Mesa X11'.
422 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
423 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
424 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
425 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
432 pglXMakeCurrent(gdi_display
, None
, NULL
);
433 pglXDestroyContext(gdi_display
, ctx
);
435 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
436 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
438 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
442 static BOOL
has_opengl(void)
444 static int init_done
;
445 static void *opengl_handle
;
448 int error_base
, event_base
;
450 if (init_done
) return (opengl_handle
!= NULL
);
453 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
454 and include all dependencies */
455 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
456 if (opengl_handle
== NULL
)
458 ERR( "Failed to load libGL: %s\n", buffer
);
459 ERR( "OpenGL support is disabled.\n");
463 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
464 if (pglXGetProcAddressARB
== NULL
) {
465 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
469 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
471 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
476 LOAD_FUNCPTR(glXChooseVisual
);
477 LOAD_FUNCPTR(glXCopyContext
);
478 LOAD_FUNCPTR(glXCreateContext
);
479 LOAD_FUNCPTR(glXCreateGLXPixmap
);
480 LOAD_FUNCPTR(glXGetCurrentContext
);
481 LOAD_FUNCPTR(glXGetCurrentDrawable
);
482 LOAD_FUNCPTR(glXDestroyContext
);
483 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
484 LOAD_FUNCPTR(glXGetConfig
);
485 LOAD_FUNCPTR(glXIsDirect
);
486 LOAD_FUNCPTR(glXMakeCurrent
);
487 LOAD_FUNCPTR(glXSwapBuffers
);
488 LOAD_FUNCPTR(glXQueryExtension
);
489 LOAD_FUNCPTR(glXQueryVersion
);
492 LOAD_FUNCPTR(glXGetClientString
);
493 LOAD_FUNCPTR(glXQueryExtensionsString
);
494 LOAD_FUNCPTR(glXQueryServerString
);
497 LOAD_FUNCPTR(glXCreatePbuffer
);
498 LOAD_FUNCPTR(glXCreateNewContext
);
499 LOAD_FUNCPTR(glXDestroyPbuffer
);
500 LOAD_FUNCPTR(glXMakeContextCurrent
);
501 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
502 LOAD_FUNCPTR(glXGetFBConfigs
);
504 /* Standard OpenGL calls */
505 LOAD_FUNCPTR(glBindTexture
);
506 LOAD_FUNCPTR(glBitmap
);
507 LOAD_FUNCPTR(glCopyTexSubImage1D
);
508 LOAD_FUNCPTR(glCopyTexImage2D
);
509 LOAD_FUNCPTR(glCopyTexSubImage2D
);
510 LOAD_FUNCPTR(glDrawBuffer
);
511 LOAD_FUNCPTR(glEndList
);
512 LOAD_FUNCPTR(glGetError
);
513 LOAD_FUNCPTR(glGetIntegerv
);
514 LOAD_FUNCPTR(glGetString
);
515 LOAD_FUNCPTR(glNewList
);
516 LOAD_FUNCPTR(glPixelStorei
);
517 LOAD_FUNCPTR(glReadPixels
);
518 LOAD_FUNCPTR(glTexImage2D
);
519 LOAD_FUNCPTR(glFinish
);
520 LOAD_FUNCPTR(glFlush
);
523 /* It doesn't matter if these fail. They'll only be used if the driver reports
524 the associated extension is available (and if a driver reports the extension
525 is available but fails to provide the functions, it's quite broken) */
526 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
527 /* ARB GLX Extension */
528 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
529 /* SGI GLX Extension */
530 LOAD_FUNCPTR(glXSwapIntervalSGI
);
531 /* NV GLX Extension */
532 LOAD_FUNCPTR(glXAllocateMemoryNV
);
533 LOAD_FUNCPTR(glXFreeMemoryNV
);
536 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
539 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
540 TRACE("GLX is up and running error_base = %d\n", error_base
);
543 ERR( "GLX extension is missing, disabling OpenGL.\n" );
547 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
548 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
551 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
552 * depends on the reported GLX client / server version and on the client / server extension list.
553 * Those don't have to be the same.
555 * In general the server GLX information lists the capabilities in case of indirect rendering.
556 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
557 * available and in that case the client GLX informat can be used.
558 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
559 * in the GLX version/extension list. When a program does this it works for certain for both
560 * direct and indirect rendering.
562 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
563 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
564 * extension list which causes this extension not to be listed. (Wine requires this extension).
565 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
566 * pbuffers is around.
568 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
569 * the ATI drivers and from then on use GLX client information for them.
572 if(glxRequireVersion(3)) {
573 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
574 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
575 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
576 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
577 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
578 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
579 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
580 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
582 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
583 * enable this function when the Xserver understand GLX 1.3 or newer
585 pglXQueryDrawable
= NULL
;
586 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
587 TRACE("Overriding ATI GLX capabilities!\n");
588 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
589 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
590 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
591 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
593 /* Use client GLX information in case of the ATI drivers. We override the
594 * capabilities over here and not somewhere else as ATI might better their
595 * life in the future. In case they release proper drivers this block of
596 * code won't be called. */
597 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
599 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
602 if(glxRequireExtension("GLX_ATI_render_texture")) {
603 use_render_texture_ati
= 1;
604 pglXBindTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
605 pglXReleaseTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
606 pglXDrawableAttribATI
= pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
609 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
610 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
613 X11DRV_WineGL_LoadExtensions();
619 wine_dlclose(opengl_handle
, NULL
, 0);
620 opengl_handle
= NULL
;
624 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
627 LIST_FOR_EACH_ENTRY( ptr
, &context_list
, struct wine_glcontext
, entry
)
628 if (ptr
== ctx
) return TRUE
;
632 static int describeContext(Wine_GLContext
* ctx
) {
635 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
636 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
637 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
638 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
639 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
644 static BOOL
describeDrawable( struct glx_physdev
*physdev
)
647 WineGLPixelFormat
*fmt
;
650 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physdev
->pixel_format
, TRUE
/* Offscreen */, &fmt_count
);
651 if(!fmt
) return FALSE
;
653 TRACE(" HDC %p has:\n", physdev
->dev
.hdc
);
654 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
655 TRACE(" - Drawable %lx\n", physdev
->drawable
);
656 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
658 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
659 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
664 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
669 int nvfloatattrib
= GLX_DONT_CARE
;
670 int pixelattrib
= GLX_DONT_CARE
;
672 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
673 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
674 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
675 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
677 switch (iWGLAttr
[cur
]) {
678 case WGL_AUX_BUFFERS_ARB
:
679 pop
= iWGLAttr
[++cur
];
680 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
681 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
683 case WGL_COLOR_BITS_ARB
:
684 pop
= iWGLAttr
[++cur
];
685 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
686 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
688 case WGL_BLUE_BITS_ARB
:
689 pop
= iWGLAttr
[++cur
];
690 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
691 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
693 case WGL_RED_BITS_ARB
:
694 pop
= iWGLAttr
[++cur
];
695 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
696 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
698 case WGL_GREEN_BITS_ARB
:
699 pop
= iWGLAttr
[++cur
];
700 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
701 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
703 case WGL_ALPHA_BITS_ARB
:
704 pop
= iWGLAttr
[++cur
];
705 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
706 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
708 case WGL_DEPTH_BITS_ARB
:
709 pop
= iWGLAttr
[++cur
];
710 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
711 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
713 case WGL_STENCIL_BITS_ARB
:
714 pop
= iWGLAttr
[++cur
];
715 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
716 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
718 case WGL_DOUBLE_BUFFER_ARB
:
719 pop
= iWGLAttr
[++cur
];
720 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
721 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
724 pop
= iWGLAttr
[++cur
];
725 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
726 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
729 case WGL_PIXEL_TYPE_ARB
:
730 pop
= iWGLAttr
[++cur
];
731 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
733 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
734 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
735 /* This is the same as WGL_TYPE_RGBA_FLOAT_ATI but the GLX constants differ, only the ARB GLX one is widely supported so use that */
736 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
737 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
739 ERR("unexpected PixelType(%x)\n", pop
);
744 case WGL_SUPPORT_GDI_ARB
:
745 /* This flag is set in a WineGLPixelFormat */
746 pop
= iWGLAttr
[++cur
];
747 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
750 case WGL_DRAW_TO_BITMAP_ARB
:
751 /* This flag is set in a WineGLPixelFormat */
752 pop
= iWGLAttr
[++cur
];
753 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
756 case WGL_DRAW_TO_WINDOW_ARB
:
757 pop
= iWGLAttr
[++cur
];
758 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
759 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
761 drawattrib
|= GLX_WINDOW_BIT
;
765 case WGL_DRAW_TO_PBUFFER_ARB
:
766 pop
= iWGLAttr
[++cur
];
767 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
768 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
770 drawattrib
|= GLX_PBUFFER_BIT
;
774 case WGL_ACCELERATION_ARB
:
775 /* This flag is set in a WineGLPixelFormat */
776 pop
= iWGLAttr
[++cur
];
777 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
780 case WGL_SUPPORT_OPENGL_ARB
:
781 pop
= iWGLAttr
[++cur
];
782 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
783 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
786 case WGL_SWAP_METHOD_ARB
:
787 pop
= iWGLAttr
[++cur
];
788 /* For now we ignore this and just return SWAP_EXCHANGE */
789 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
792 case WGL_PBUFFER_LARGEST_ARB
:
793 pop
= iWGLAttr
[++cur
];
794 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
795 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
798 case WGL_SAMPLE_BUFFERS_ARB
:
799 pop
= iWGLAttr
[++cur
];
800 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
801 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
804 case WGL_SAMPLES_ARB
:
805 pop
= iWGLAttr
[++cur
];
806 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
807 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
810 case WGL_TEXTURE_FORMAT_ARB
:
811 case WGL_TEXTURE_TARGET_ARB
:
812 case WGL_MIPMAP_TEXTURE_ARB
:
813 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
814 pop
= iWGLAttr
[++cur
];
816 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
818 if (use_render_texture_ati
) {
819 /** nothing to do here */
821 else if (!use_render_texture_emulation
) {
822 if (WGL_NO_TEXTURE_ARB
!= pop
) {
823 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
824 return -1; /** error: don't support it */
826 drawattrib
|= GLX_PBUFFER_BIT
;
830 case WGL_FLOAT_COMPONENTS_NV
:
831 nvfloatattrib
= iWGLAttr
[++cur
];
832 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
834 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
835 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
836 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
837 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
838 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
839 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
840 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
841 pop
= iWGLAttr
[++cur
];
842 /** cannot be converted, see direct handling on
843 * - wglGetPixelFormatAttribivARB
844 * TODO: wglChoosePixelFormat
847 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
848 pop
= iWGLAttr
[++cur
];
849 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
850 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
853 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
854 pop
= iWGLAttr
[++cur
];
855 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
856 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
859 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
865 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
866 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
867 * pixmap and pbuffer formats appear as well. */
868 if (!drawattrib
) drawattrib
= GLX_DONT_CARE
;
869 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
870 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
872 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
873 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
874 * GLX_DONT_CARE unless it is overridden. */
875 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
876 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
878 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
879 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
880 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
881 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
887 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
889 int render_type
=0, render_type_bit
;
890 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
891 switch(render_type_bit
)
894 render_type
= GLX_RGBA_TYPE
;
896 case GLX_COLOR_INDEX_BIT
:
897 render_type
= GLX_COLOR_INDEX_TYPE
;
899 case GLX_RGBA_FLOAT_BIT
:
900 render_type
= GLX_RGBA_FLOAT_TYPE
;
902 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
903 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
906 ERR("Unknown render_type: %x\n", render_type_bit
);
911 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
912 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
915 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
916 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
918 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
919 * the GLX_PIXMAP_BIT set. */
920 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
923 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
925 static WineGLPixelFormat
*list
;
926 static int size
, onscreen_size
;
928 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
930 XVisualInfo
*visinfo
;
935 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
936 if (NULL
== cfgs
|| 0 == nCfgs
) {
937 if(cfgs
!= NULL
) XFree(cfgs
);
939 ERR("glXChooseFBConfig returns NULL\n");
943 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
944 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
945 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
946 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
948 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
950 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
952 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
955 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
957 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
959 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
960 * Do this as GLX doesn't guarantee that the list is sorted */
961 for(run
=0; run
< 2; run
++)
963 for(i
=0; i
<nCfgs
; i
++) {
964 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
965 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
967 /* The first run we only add onscreen formats (ones which have an associated X Visual).
968 * The second run we only set offscreen formats. */
971 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
972 * The contents is copied to the destination using XCopyArea. For the copying to work
973 * the depth of the source and destination window should be the same. In general this should
974 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
975 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
976 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
977 * list formats with the same depth. */
978 if(visinfo
->depth
!= screen_depth
)
984 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
985 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
986 list
[size
].fbconfig
= cfgs
[i
];
987 list
[size
].fmt_id
= fmt_id
;
988 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
989 list
[size
].offscreenOnly
= FALSE
;
990 list
[size
].dwFlags
= 0;
994 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
995 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
997 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
998 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
999 list
[size
].fbconfig
= cfgs
[i
];
1000 list
[size
].fmt_id
= fmt_id
;
1001 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1002 list
[size
].offscreenOnly
= FALSE
;
1003 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
1007 } else if(run
&& !visinfo
) {
1008 int window_drawable
=0;
1009 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
1011 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1012 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1013 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1014 * likely make our child window opengl rendering more complicated since likely you can't use
1015 * XCopyArea on a GLX Window.
1016 * For now ignore fbconfigs which are window drawable but lack a visual. */
1017 if(window_drawable
& GLX_WINDOW_BIT
)
1019 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
1023 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1024 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1025 list
[size
].fbconfig
= cfgs
[i
];
1026 list
[size
].fmt_id
= fmt_id
;
1027 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1028 list
[size
].offscreenOnly
= TRUE
;
1029 list
[size
].dwFlags
= 0;
1033 if (visinfo
) XFree(visinfo
);
1040 if (size_ret
) *size_ret
= size
;
1041 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
1042 wine_tsx11_unlock();
1046 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1047 * In our WGL implementation we only support a subset of these formats namely the format of
1048 * Wine's main visual and offscreen formats (if they are available).
1049 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1050 * and it returns the number of supported WGL formats in fmt_count.
1052 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
1054 WineGLPixelFormat
*list
, *res
= NULL
;
1055 int size
, onscreen_size
;
1057 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
1059 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1060 * iPixelFormat in case of probing the number of pixelformats.
1062 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
1063 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
1064 res
= &list
[iPixelFormat
-1];
1065 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res
->fmt_id
, iPixelFormat
);
1071 *fmt_count
= onscreen_size
;
1073 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1078 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1079 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1081 WineGLPixelFormat
*list
;
1084 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1086 for(i
=0; i
<size
; i
++) {
1087 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1088 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1089 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1090 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1094 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1098 static int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1100 WineGLPixelFormat
*fmt
;
1102 if (!fbconfig_id
) return 0;
1104 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1106 return fmt
->iPixelFormat
;
1107 /* This will happen on hwnds without a pixel format set; it's ok */
1112 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1113 void mark_drawable_dirty(Drawable old
, Drawable
new)
1115 Wine_GLContext
*ctx
;
1116 LIST_FOR_EACH_ENTRY( ctx
, &context_list
, struct wine_glcontext
, entry
)
1118 if (old
== ctx
->drawables
[0]) {
1119 ctx
->drawables
[0] = new;
1120 ctx
->refresh_drawables
= TRUE
;
1122 if (old
== ctx
->drawables
[1]) {
1123 ctx
->drawables
[1] = new;
1124 ctx
->refresh_drawables
= TRUE
;
1129 /* Given the current context, make sure its drawable is sync'd */
1130 static inline void sync_context(Wine_GLContext
*context
)
1132 if(context
&& context
->refresh_drawables
) {
1133 if (glxRequireVersion(3))
1134 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1135 context
->drawables
[1], context
->ctx
);
1137 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1138 context
->refresh_drawables
= FALSE
;
1143 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1147 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1148 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1150 if(context
->gl3_context
)
1152 if(context
->numAttribs
)
1153 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1155 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1157 else if(context
->vis
)
1158 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1159 else /* Create a GLX Context for a pbuffer */
1160 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1166 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1168 return pglXCreateGLXPixmap(display
, vis
, parent
);
1172 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1179 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1181 if(vis
->depth
== physDev
->bitmap
->depth
)
1182 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1185 wine_tsx11_unlock();
1186 TRACE("return %lx\n", ret
);
1191 * glxdrv_ChoosePixelFormat
1193 * Equivalent to glXChooseVisual.
1195 static int glxdrv_ChoosePixelFormat(PHYSDEV dev
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1197 WineGLPixelFormat
*list
;
1202 int bestFormat
= -1;
1203 int bestDBuffer
= -1;
1204 int bestStereo
= -1;
1208 int bestStencil
= -1;
1211 if (!has_opengl()) return 0;
1213 if (TRACE_ON(wgl
)) {
1214 TRACE("(%p,%p)\n", dev
->hdc
, ppfd
);
1216 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1219 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1222 for(i
=0; i
<onscreen_size
; i
++)
1226 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1227 WineGLPixelFormat
*fmt
= &list
[i
];
1230 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1231 if (value
& GLX_RGBA_BIT
)
1232 iPixelType
= PFD_TYPE_RGBA
;
1234 iPixelType
= PFD_TYPE_COLORINDEX
;
1236 if (ppfd
->iPixelType
!= iPixelType
)
1238 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1242 /* Only use bitmap capable for formats for bitmap rendering.
1243 * See get_formats for more info. */
1244 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1246 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1250 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1251 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1252 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1253 if (value
) dwFlags
|= PFD_STEREO
;
1254 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1255 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1256 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1257 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1258 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1260 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1261 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1262 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1263 * formats without the given flag set.
1264 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1265 * has indicated that a format without stereo is returned when stereo is unavailable.
1266 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1267 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1269 * To summarize the following is most likely the correct behavior:
1270 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1271 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1272 * stereo don't care -> it doesn't matter whether we get stereo or not
1274 * In Wine we will treat no-stereo the same way as don't care because it makes
1275 * format selection even more complicated and second drivers with Stereo advertise
1276 * each format twice anyway.
1279 /* Doublebuffer, see the comments above */
1280 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1281 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1282 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1285 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1289 /* Stereo, see the comments above. */
1290 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1291 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1292 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1295 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1299 /* Below we will do a number of checks to select the 'best' pixelformat.
1300 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1301 * The code works by trying to match the most important options as close as possible.
1302 * When a reasonable format is found, we will try to match more options.
1303 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1304 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1305 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1307 if(ppfd
->cColorBits
) {
1308 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1309 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1312 if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1313 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1318 if(ppfd
->cAlphaBits
) {
1319 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1320 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1323 if(bestAlpha
!= alpha
) {
1324 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1329 if(ppfd
->cDepthBits
) {
1330 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1331 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1334 if(bestDepth
!= depth
) {
1335 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1340 if(ppfd
->cStencilBits
) {
1341 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1342 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1345 if(bestStencil
!= stencil
) {
1346 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1351 if(ppfd
->cAuxBuffers
) {
1352 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1353 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1356 if(bestAux
!= aux
) {
1357 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1364 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1365 bestStereo
= dwFlags
& PFD_STEREO
;
1369 bestStencil
= stencil
;
1374 if(bestFormat
== -1) {
1375 TRACE("No matching mode was found returning 0\n");
1379 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1380 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1383 wine_tsx11_unlock();
1389 * glxdrv_DescribePixelFormat
1391 * Get the pixel-format descriptor associated to the given id
1393 static int glxdrv_DescribePixelFormat(PHYSDEV dev
, int iPixelFormat
,
1394 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1396 /*XVisualInfo *vis;*/
1399 WineGLPixelFormat
*fmt
;
1403 if (!has_opengl()) return 0;
1405 TRACE("(%p,%d,%d,%p)\n", dev
->hdc
, iPixelFormat
, nBytes
, ppfd
);
1407 /* Look for the iPixelFormat in our list of supported formats. If it is supported we get the index in the FBConfig table and the number of supported formats back */
1408 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1410 /* The application is only querying the number of pixelformats */
1412 } else if(fmt
== NULL
) {
1413 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1417 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1418 ERR("Wrong structure size !\n");
1419 /* Should set error */
1425 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1426 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1429 /* These flags are always the same... */
1430 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1431 /* Now the flags extracted from the Visual */
1435 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1436 if(value
& GLX_WINDOW_BIT
)
1437 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1439 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1440 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1441 * Radeon 9000 indicated that all bitmap formats have PFD_SUPPORT_GDI. Except for 2 formats on the Radeon 9000 none of the hw accelerated formats
1442 * offered the GDI bit either. */
1443 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1445 /* PFD_GENERIC_FORMAT - gdi software rendering
1446 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1447 * none set - full hardware accelerated by a ICD
1449 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1450 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1452 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1454 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1455 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1457 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1460 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1461 if (value
& GLX_RGBA_BIT
)
1462 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1464 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1467 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1468 ppfd
->cColorBits
= value
;
1470 /* Red, green, blue and alpha bits / shifts */
1471 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1472 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1473 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1474 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1475 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1477 ppfd
->cRedBits
= rb
;
1478 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1479 ppfd
->cBlueBits
= bb
;
1480 ppfd
->cBlueShift
= ab
;
1481 ppfd
->cGreenBits
= gb
;
1482 ppfd
->cGreenShift
= bb
+ ab
;
1483 ppfd
->cAlphaBits
= ab
;
1484 ppfd
->cAlphaShift
= 0;
1487 ppfd
->cRedShift
= 0;
1488 ppfd
->cBlueBits
= 0;
1489 ppfd
->cBlueShift
= 0;
1490 ppfd
->cGreenBits
= 0;
1491 ppfd
->cGreenShift
= 0;
1492 ppfd
->cAlphaBits
= 0;
1493 ppfd
->cAlphaShift
= 0;
1496 /* Accum RGBA bits */
1497 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1498 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1499 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1500 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1502 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1503 ppfd
->cAccumRedBits
= rb
;
1504 ppfd
->cAccumGreenBits
= gb
;
1505 ppfd
->cAccumBlueBits
= bb
;
1506 ppfd
->cAccumAlphaBits
= ab
;
1509 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1510 ppfd
->cAuxBuffers
= value
;
1513 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1514 ppfd
->cDepthBits
= value
;
1517 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1518 ppfd
->cStencilBits
= value
;
1520 wine_tsx11_unlock();
1522 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1524 if (TRACE_ON(wgl
)) {
1525 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1532 * glxdrv_GetPixelFormat
1534 * Get the pixel-format id used by this DC
1536 static int glxdrv_GetPixelFormat(PHYSDEV dev
)
1538 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
1539 WineGLPixelFormat
*fmt
;
1542 if (!physdev
->pixel_format
) return 0; /* not set yet */
1544 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physdev
->pixel_format
, TRUE
, &tmp
);
1547 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physdev
->pixel_format
);
1550 else if(fmt
->offscreenOnly
)
1552 /* Offscreen formats can't be used with traditional WGL calls.
1553 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1554 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1558 TRACE("(%p): returns %d\n", dev
->hdc
, physdev
->pixel_format
);
1559 return physdev
->pixel_format
;
1562 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1563 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1564 * set the pixel format multiple times. */
1565 static BOOL
internal_SetPixelFormat( struct glx_physdev
*physdev
,
1567 const PIXELFORMATDESCRIPTOR
*ppfd
)
1569 WineGLPixelFormat
*fmt
;
1573 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1574 if(physdev
->x11dev
->drawable
== root_window
)
1576 ERR("Invalid operation on root_window\n");
1580 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1581 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1583 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1588 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1589 wine_tsx11_unlock();
1591 hwnd
= WindowFromDC(physdev
->dev
.hdc
);
1593 if(!(value
&GLX_WINDOW_BIT
)) {
1594 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1598 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, fmt
->fmt_id
, 0)) {
1599 ERR("Couldn't set format of the window, returning failure\n");
1602 /* physDev->current_pf will be set by the DCE update */
1604 else if(physdev
->x11dev
->bitmap
) {
1605 if(!(value
&GLX_PIXMAP_BIT
)) {
1606 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1610 physdev
->x11dev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physdev
->x11dev
, fmt
);
1611 if(!physdev
->x11dev
->bitmap
->glxpixmap
) {
1612 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1615 physdev
->pixel_format
= iPixelFormat
;
1616 physdev
->type
= DC_GL_BITMAP
;
1619 FIXME("called on a non-window, non-bitmap object?\n");
1622 if (TRACE_ON(wgl
)) {
1626 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1628 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1630 TRACE(" FBConfig have :\n");
1631 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1632 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1633 TRACE(" - VISUAL_ID 0x%x\n", value
);
1634 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1635 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1637 wine_tsx11_unlock();
1644 * glxdrv_SetPixelFormat
1646 * Set the pixel-format id used by this DC
1648 static BOOL
glxdrv_SetPixelFormat(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1650 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
1652 TRACE("(%p,%d,%p)\n", dev
->hdc
, iPixelFormat
, ppfd
);
1654 if (!has_opengl()) return FALSE
;
1656 if(physdev
->pixel_format
) /* cannot change it if already set */
1657 return (physdev
->pixel_format
== iPixelFormat
);
1659 return internal_SetPixelFormat(physdev
, iPixelFormat
, ppfd
);
1663 * glxdrv_wglCopyContext
1665 * For OpenGL32 wglCopyContext.
1667 static BOOL
glxdrv_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
1669 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1670 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1672 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1675 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1676 wine_tsx11_unlock();
1678 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1683 * X11DRV_wglCreateContext
1685 * For OpenGL32 wglCreateContext.
1687 static HGLRC
glxdrv_wglCreateContext(PHYSDEV dev
)
1689 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
1690 Wine_GLContext
*ret
;
1691 WineGLPixelFormat
*fmt
;
1694 TRACE("(%p)->(PF:%d)\n", dev
->hdc
, physdev
->pixel_format
);
1696 if (!has_opengl()) return 0;
1698 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physdev
->pixel_format
, TRUE
/* Offscreen */, &fmt_count
);
1699 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1700 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1701 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1702 * If this fails something is very wrong on the system. */
1704 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", physdev
->pixel_format
);
1705 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1709 if (!(ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
)))) return 0;
1711 ret
->hdc
= dev
->hdc
;
1713 ret
->has_been_current
= FALSE
;
1714 ret
->sharing
= FALSE
;
1717 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1718 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1719 list_add_head( &context_list
, &ret
->entry
);
1720 wine_tsx11_unlock();
1722 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1727 * glxdrv_wglDeleteContext
1729 * For OpenGL32 wglDeleteContext.
1731 static BOOL
glxdrv_wglDeleteContext(HGLRC hglrc
)
1733 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1735 TRACE("(%p)\n", hglrc
);
1737 if (!has_opengl()) return 0;
1739 if (!is_valid_context(ctx
))
1741 WARN("Error deleting context !\n");
1742 SetLastError(ERROR_INVALID_HANDLE
);
1746 /* WGL doesn't allow deletion of a context which is current in another thread */
1747 if (ctx
->tid
!= 0 && ctx
->tid
!= GetCurrentThreadId())
1749 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx
);
1750 SetLastError(ERROR_BUSY
);
1754 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1755 if (ctx
== NtCurrentTeb()->glContext
)
1756 wglMakeCurrent(ctx
->hdc
, NULL
);
1759 list_remove( &ctx
->entry
);
1760 if (ctx
->ctx
) pglXDestroyContext( gdi_display
, ctx
->ctx
);
1761 if (ctx
->vis
) XFree( ctx
->vis
);
1762 wine_tsx11_unlock();
1764 HeapFree( GetProcessHeap(), 0, ctx
);
1769 * X11DRV_wglGetCurrentReadDCARB
1771 * For OpenGL32 wglGetCurrentReadDCARB.
1773 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1776 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1778 if (ctx
) ret
= ctx
->read_hdc
;
1780 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1785 * glxdrv_wglGetProcAddress
1787 * For OpenGL32 wglGetProcAddress.
1789 static PROC
glxdrv_wglGetProcAddress(LPCSTR lpszProc
)
1792 const WineGLExtension
*ext
;
1794 int padding
= 32 - strlen(lpszProc
);
1798 if (!has_opengl()) return NULL
;
1800 /* Check the table of WGL extensions to see if we need to return a WGL extension
1801 * or a function pointer to a native OpenGL function. */
1802 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1803 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1805 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1806 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1807 ext
= WineGLExtensionList
[i
];
1808 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1809 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1810 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1811 return ext
->extEntryPoints
[j
].funcAddress
;
1817 WARN("(%s) - not found\n", lpszProc
);
1822 * glxdrv_wglMakeCurrent
1824 * For OpenGL32 wglMakeCurrent.
1826 static BOOL
glxdrv_wglMakeCurrent(PHYSDEV dev
, HGLRC hglrc
)
1828 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
1830 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1832 TRACE("(%p,%p)\n", dev
->hdc
, hglrc
);
1834 if (!has_opengl()) return FALSE
;
1839 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1840 if (prev_ctx
) prev_ctx
->tid
= 0;
1842 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1843 NtCurrentTeb()->glContext
= NULL
;
1845 else if (!physdev
->pixel_format
)
1847 WARN("Trying to use an invalid drawable\n");
1848 SetLastError(ERROR_INVALID_HANDLE
);
1851 else if (ctx
->fmt
->iPixelFormat
!= physdev
->pixel_format
)
1853 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1854 dev
->hdc
, physdev
->pixel_format
, ctx
, ctx
->fmt
->iPixelFormat
);
1855 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1860 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1862 /* The describe lines below are for debugging purposes only */
1863 if (TRACE_ON(wgl
)) {
1864 describeDrawable( physdev
);
1865 describeContext(ctx
);
1868 TRACE(" make current for drawable %lx, ctx %p\n", physdev
->drawable
, ctx
->ctx
);
1869 ret
= pglXMakeCurrent(gdi_display
, physdev
->drawable
, ctx
->ctx
);
1873 if (prev_ctx
) prev_ctx
->tid
= 0;
1874 NtCurrentTeb()->glContext
= ctx
;
1876 ctx
->has_been_current
= TRUE
;
1877 ctx
->tid
= GetCurrentThreadId();
1878 ctx
->hdc
= dev
->hdc
;
1879 ctx
->read_hdc
= dev
->hdc
;
1880 ctx
->drawables
[0] = physdev
->drawable
;
1881 ctx
->drawables
[1] = physdev
->drawable
;
1882 ctx
->refresh_drawables
= FALSE
;
1884 if (physdev
->type
== DC_GL_BITMAP
) pglDrawBuffer(GL_FRONT_LEFT
);
1887 SetLastError(ERROR_INVALID_HANDLE
);
1889 wine_tsx11_unlock();
1890 TRACE(" returning %s\n", (ret
? "True" : "False"));
1895 * glxdrv_wglMakeContextCurrentARB
1897 * For OpenGL32 wglMakeContextCurrentARB
1899 static BOOL
glxdrv_wglMakeContextCurrentARB( PHYSDEV draw_dev
, PHYSDEV read_dev
, HGLRC hglrc
)
1901 struct glx_physdev
*draw_physdev
= get_glxdrv_dev( draw_dev
);
1902 struct glx_physdev
*read_physdev
= get_glxdrv_dev( read_dev
);
1905 TRACE("(%p,%p,%p)\n", draw_dev
->hdc
, read_dev
->hdc
, hglrc
);
1907 if (!has_opengl()) return 0;
1912 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1913 if (prev_ctx
) prev_ctx
->tid
= 0;
1915 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1916 NtCurrentTeb()->glContext
= NULL
;
1918 else if (!draw_physdev
->pixel_format
)
1920 WARN("Trying to use an invalid drawable\n");
1921 SetLastError(ERROR_INVALID_HANDLE
);
1926 if (NULL
== pglXMakeContextCurrent
) {
1929 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1931 ret
= pglXMakeContextCurrent(gdi_display
, draw_physdev
->drawable
,
1932 read_physdev
->drawable
, ctx
->ctx
);
1935 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1936 if (prev_ctx
) prev_ctx
->tid
= 0;
1938 ctx
->has_been_current
= TRUE
;
1939 ctx
->tid
= GetCurrentThreadId();
1940 ctx
->hdc
= draw_dev
->hdc
;
1941 ctx
->read_hdc
= read_dev
->hdc
;
1942 ctx
->drawables
[0] = draw_physdev
->drawable
;
1943 ctx
->drawables
[1] = read_physdev
->drawable
;
1944 ctx
->refresh_drawables
= FALSE
;
1945 NtCurrentTeb()->glContext
= ctx
;
1948 SetLastError(ERROR_INVALID_HANDLE
);
1951 wine_tsx11_unlock();
1953 TRACE(" returning %s\n", (ret
? "True" : "False"));
1958 * glxdrv_wglShareLists
1960 * For OpenGL32 wglShareLists.
1962 static BOOL
glxdrv_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
1964 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1965 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1967 TRACE("(%p, %p)\n", org
, dest
);
1969 if (!has_opengl()) return FALSE
;
1971 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1972 * at context creation time but in case of WGL it is done using wglShareLists.
1973 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1974 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1975 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1976 * so there delaying context creation doesn't work.
1978 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1979 * and when a program requests sharing we recreate the destination context if it hasn't been made
1980 * current or when it hasn't shared display lists before.
1983 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
1985 ERR("Could not share display lists, one of the contexts has been current already !\n");
1988 else if(dest
->sharing
)
1990 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1995 if((GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
))
1997 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
2001 describeContext(org
);
2002 describeContext(dest
);
2004 /* Re-create the GLX context and share display lists */
2005 pglXDestroyContext(gdi_display
, dest
->ctx
);
2006 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
2007 wine_tsx11_unlock();
2008 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
2010 org
->sharing
= TRUE
;
2011 dest
->sharing
= TRUE
;
2017 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
2019 /* We are running using client-side rendering fonts... */
2021 unsigned int glyph
, size
= 0;
2022 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
2026 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
2027 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
2028 wine_tsx11_unlock();
2030 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
2031 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
2032 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
2033 unsigned int height
, width_int
;
2035 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
2036 if (needed_size
== GDI_ERROR
) {
2037 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
2040 TRACE(" - needed size : %d\n", needed_size
);
2043 if (needed_size
> size
) {
2045 HeapFree(GetProcessHeap(), 0, bitmap
);
2046 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2047 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2048 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2050 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
2052 if (TRACE_ON(wgl
)) {
2053 unsigned int height
, width
, bitmask
;
2054 unsigned char *bitmap_
= bitmap
;
2056 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
2057 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2058 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
2059 if (needed_size
!= 0) {
2060 TRACE(" - bitmap :\n");
2061 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2063 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
2068 if (*bitmap_
& bitmask
)
2073 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2079 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2080 * glyph for it to be drawn properly.
2082 if (needed_size
!= 0) {
2083 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2084 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2086 for (width
= 0; width
< width_int
; width
++) {
2087 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2088 ((int *) bitmap
)[height
* width_int
+ width
];
2094 pglNewList(listBase
++, GL_COMPILE
);
2095 if (needed_size
!= 0) {
2096 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2097 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2098 gm
.gmCellIncX
, gm
.gmCellIncY
,
2101 /* This is the case of 'empty' glyphs like the space character */
2102 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2105 wine_tsx11_unlock();
2109 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2110 wine_tsx11_unlock();
2112 HeapFree(GetProcessHeap(), 0, bitmap
);
2113 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2118 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2119 wine_tsx11_unlock();
2121 HeapFree(GetProcessHeap(), 0, bitmap
);
2122 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2127 * glxdrv_wglUseFontBitmapsA
2129 * For OpenGL32 wglUseFontBitmapsA.
2131 static BOOL
glxdrv_wglUseFontBitmapsA(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
2133 TRACE("(%p, %d, %d, %d)\n", dev
->hdc
, first
, count
, listBase
);
2135 if (!has_opengl()) return FALSE
;
2136 return internal_wglUseFontBitmaps(dev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2140 * glxdrv_wglUseFontBitmapsW
2142 * For OpenGL32 wglUseFontBitmapsW.
2144 static BOOL
glxdrv_wglUseFontBitmapsW(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
2146 TRACE("(%p, %d, %d, %d)\n", dev
->hdc
, first
, count
, listBase
);
2148 if (!has_opengl()) return FALSE
;
2149 return internal_wglUseFontBitmaps(dev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2152 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2153 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2160 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2162 pglGetIntegerv(pname
, params
);
2164 * if we cannot find a Wine Context
2165 * we only have the default wine desktop context,
2166 * so if we have only a 24 depth say we have 32
2168 if (!ctx
&& *params
== 24) {
2171 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2176 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2178 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2179 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2183 pglGetIntegerv(pname
, params
);
2186 wine_tsx11_unlock();
2189 static void flush_gl_drawable( struct glx_physdev
*physdev
)
2192 int w
= physdev
->x11dev
->dc_rect
.right
- physdev
->x11dev
->dc_rect
.left
;
2193 int h
= physdev
->x11dev
->dc_rect
.bottom
- physdev
->x11dev
->dc_rect
.top
;
2194 Drawable src
= physdev
->drawable
;
2196 if (w
<= 0 || h
<= 0) return;
2198 switch (physdev
->type
)
2200 case DC_GL_PIXMAP_WIN
:
2201 src
= physdev
->pixmap
;
2203 case DC_GL_CHILD_WIN
:
2204 /* The GL drawable may be lagged behind if we don't flush first, so
2205 * flush the display make sure we copy up-to-date data */
2207 XFlush(gdi_display
);
2208 XSetFunction(gdi_display
, physdev
->x11dev
->gc
, GXcopy
);
2209 XCopyArea(gdi_display
, src
, physdev
->x11dev
->drawable
, physdev
->x11dev
->gc
, 0, 0, w
, h
,
2210 physdev
->x11dev
->dc_rect
.left
, physdev
->x11dev
->dc_rect
.top
);
2211 wine_tsx11_unlock();
2212 SetRect( &rect
, 0, 0, w
, h
);
2213 add_device_bounds( physdev
->x11dev
, &rect
);
2220 static void WINAPI
X11DRV_wglFinish(void)
2222 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2223 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2228 wine_tsx11_unlock();
2229 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2232 static void WINAPI
X11DRV_wglFlush(void)
2234 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2235 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2240 wine_tsx11_unlock();
2241 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2245 * glxdrv_wglCreateContextAttribsARB
2247 * WGL_ARB_create_context: wglCreateContextAttribsARB
2249 static HGLRC
glxdrv_wglCreateContextAttribsARB(PHYSDEV dev
, HGLRC hShareContext
, const int* attribList
)
2251 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
2252 Wine_GLContext
*ret
;
2253 WineGLPixelFormat
*fmt
;
2256 TRACE("(%p %p %p)\n", dev
->hdc
, hShareContext
, attribList
);
2258 if (!has_opengl()) return 0;
2260 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physdev
->pixel_format
, TRUE
/* Offscreen */, &fmt_count
);
2261 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2262 * If this fails something is very wrong on the system. */
2265 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", physdev
->pixel_format
);
2266 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2270 if (!(ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
)))) return 0;
2272 ret
->hdc
= dev
->hdc
;
2274 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2275 ret
->gl3_context
= TRUE
;
2277 ret
->numAttribs
= 0;
2280 int *pAttribList
= (int*)attribList
;
2281 int *pContextAttribList
= &ret
->attribList
[0];
2282 /* attribList consists of pairs {token, value] terminated with 0 */
2283 while(pAttribList
[0] != 0)
2285 TRACE("%#x %#x\n", pAttribList
[0], pAttribList
[1]);
2286 switch(pAttribList
[0])
2288 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2289 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2290 pContextAttribList
[1] = pAttribList
[1];
2292 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2293 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2294 pContextAttribList
[1] = pAttribList
[1];
2296 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2298 case WGL_CONTEXT_FLAGS_ARB
:
2299 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2300 pContextAttribList
[1] = pAttribList
[1];
2302 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2303 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2304 pContextAttribList
[1] = pAttribList
[1];
2307 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList
[0], pAttribList
[1]);
2312 pContextAttribList
+= 2;
2317 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2318 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
2320 XSync(gdi_display
, False
);
2321 if(X11DRV_check_error() || !ret
->ctx
)
2323 /* In the future we should convert the GLX error to a win32 one here if needed */
2324 ERR("Context creation failed\n");
2325 HeapFree( GetProcessHeap(), 0, ret
);
2326 wine_tsx11_unlock();
2330 list_add_head( &context_list
, &ret
->entry
);
2331 wine_tsx11_unlock();
2332 TRACE(" creating context %p\n", ret
);
2337 * X11DRV_wglGetExtensionsStringARB
2339 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2341 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2342 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2343 return WineGLInfo
.wglExtensions
;
2347 * X11DRV_wglCreatePbufferARB
2349 * WGL_ARB_pbuffer: wglCreatePbufferARB
2351 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2353 Wine_GLPBuffer
* object
= NULL
;
2354 WineGLPixelFormat
*fmt
= NULL
;
2359 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2361 if (0 >= iPixelFormat
) {
2362 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2363 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2364 return NULL
; /* unexpected error */
2367 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2368 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2370 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2371 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2372 goto create_failed
; /* unexpected error */
2375 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2376 if (NULL
== object
) {
2377 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2378 goto create_failed
; /* unexpected error */
2381 object
->display
= gdi_display
;
2382 object
->width
= iWidth
;
2383 object
->height
= iHeight
;
2386 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2387 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2388 while (piAttribList
&& 0 != *piAttribList
) {
2390 switch (*piAttribList
) {
2391 case WGL_PBUFFER_LARGEST_ARB
: {
2393 attr_v
= *piAttribList
;
2394 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2395 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2399 case WGL_TEXTURE_FORMAT_ARB
: {
2401 attr_v
= *piAttribList
;
2402 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2403 if (use_render_texture_ati
) {
2406 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2407 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2408 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2410 SetLastError(ERROR_INVALID_DATA
);
2413 object
->use_render_texture
= 1;
2414 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2416 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2417 object
->use_render_texture
= 0;
2419 if (!use_render_texture_emulation
) {
2420 SetLastError(ERROR_INVALID_DATA
);
2424 case WGL_TEXTURE_RGB_ARB
:
2425 object
->use_render_texture
= GL_RGB
;
2426 object
->texture_bpp
= 3;
2427 object
->texture_format
= GL_RGB
;
2428 object
->texture_type
= GL_UNSIGNED_BYTE
;
2430 case WGL_TEXTURE_RGBA_ARB
:
2431 object
->use_render_texture
= GL_RGBA
;
2432 object
->texture_bpp
= 4;
2433 object
->texture_format
= GL_RGBA
;
2434 object
->texture_type
= GL_UNSIGNED_BYTE
;
2437 /* WGL_FLOAT_COMPONENTS_NV */
2438 case WGL_TEXTURE_FLOAT_R_NV
:
2439 object
->use_render_texture
= GL_FLOAT_R_NV
;
2440 object
->texture_bpp
= 4;
2441 object
->texture_format
= GL_RED
;
2442 object
->texture_type
= GL_FLOAT
;
2444 case WGL_TEXTURE_FLOAT_RG_NV
:
2445 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2446 object
->texture_bpp
= 8;
2447 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2448 object
->texture_type
= GL_FLOAT
;
2450 case WGL_TEXTURE_FLOAT_RGB_NV
:
2451 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2452 object
->texture_bpp
= 12;
2453 object
->texture_format
= GL_RGB
;
2454 object
->texture_type
= GL_FLOAT
;
2456 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2457 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2458 object
->texture_bpp
= 16;
2459 object
->texture_format
= GL_RGBA
;
2460 object
->texture_type
= GL_FLOAT
;
2463 ERR("Unknown texture format: %x\n", attr_v
);
2464 SetLastError(ERROR_INVALID_DATA
);
2472 case WGL_TEXTURE_TARGET_ARB
: {
2474 attr_v
= *piAttribList
;
2475 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2476 if (use_render_texture_ati
) {
2479 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2480 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2481 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2482 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2484 SetLastError(ERROR_INVALID_DATA
);
2487 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2489 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2490 object
->texture_target
= 0;
2492 if (!use_render_texture_emulation
) {
2493 SetLastError(ERROR_INVALID_DATA
);
2497 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2498 if (iWidth
!= iHeight
) {
2499 SetLastError(ERROR_INVALID_DATA
);
2502 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2503 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2506 case WGL_TEXTURE_1D_ARB
: {
2508 SetLastError(ERROR_INVALID_DATA
);
2511 object
->texture_target
= GL_TEXTURE_1D
;
2512 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2515 case WGL_TEXTURE_2D_ARB
: {
2516 object
->texture_target
= GL_TEXTURE_2D
;
2517 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2520 case WGL_TEXTURE_RECTANGLE_NV
: {
2521 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2522 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2526 ERR("Unknown texture target: %x\n", attr_v
);
2527 SetLastError(ERROR_INVALID_DATA
);
2535 case WGL_MIPMAP_TEXTURE_ARB
: {
2537 attr_v
= *piAttribList
;
2538 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2539 if (use_render_texture_ati
) {
2540 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2542 if (!use_render_texture_emulation
) {
2543 SetLastError(ERROR_INVALID_DATA
);
2553 PUSH1(attribs
, None
);
2555 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2556 wine_tsx11_unlock();
2557 TRACE("new Pbuffer drawable as %lx\n", object
->drawable
);
2558 if (!object
->drawable
) {
2559 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2560 goto create_failed
; /* unexpected error */
2562 TRACE("->(%p)\n", object
);
2566 HeapFree(GetProcessHeap(), 0, object
);
2567 TRACE("->(FAILED)\n");
2572 * X11DRV_wglDestroyPbufferARB
2574 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2576 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2578 Wine_GLPBuffer
* object
= hPbuffer
;
2579 TRACE("(%p)\n", hPbuffer
);
2580 if (NULL
== object
) {
2581 SetLastError(ERROR_INVALID_HANDLE
);
2585 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2586 wine_tsx11_unlock();
2587 HeapFree(GetProcessHeap(), 0, object
);
2592 * X11DRV_wglGetPbufferDCARB
2594 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2596 static HDC WINAPI
X11DRV_wglGetPbufferDCARB(HPBUFFERARB hPbuffer
)
2598 struct x11drv_escape_set_drawable escape
;
2599 Wine_GLPBuffer
* object
= hPbuffer
;
2602 if (NULL
== object
) {
2603 SetLastError(ERROR_INVALID_HANDLE
);
2607 hdc
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
);
2610 escape
.code
= X11DRV_SET_DRAWABLE
;
2611 escape
.drawable
= object
->drawable
;
2612 escape
.mode
= IncludeInferiors
;
2613 SetRect( &escape
.drawable_rect
, 0, 0, object
->width
, object
->height
);
2614 escape
.dc_rect
= escape
.drawable_rect
;
2615 escape
.fbconfig_id
= object
->fmt
->fmt_id
;
2616 escape
.gl_drawable
= object
->drawable
;
2618 escape
.gl_type
= DC_GL_PBUFFER
;
2619 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2621 TRACE( "(%p)->(%p)\n", hPbuffer
, hdc
);
2626 * X11DRV_wglQueryPbufferARB
2628 * WGL_ARB_pbuffer: wglQueryPbufferARB
2630 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2632 Wine_GLPBuffer
* object
= hPbuffer
;
2633 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2634 if (NULL
== object
) {
2635 SetLastError(ERROR_INVALID_HANDLE
);
2638 switch (iAttribute
) {
2639 case WGL_PBUFFER_WIDTH_ARB
:
2641 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2642 wine_tsx11_unlock();
2644 case WGL_PBUFFER_HEIGHT_ARB
:
2646 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2647 wine_tsx11_unlock();
2650 case WGL_PBUFFER_LOST_ARB
:
2651 /* GLX Pbuffers cannot be lost by default. We can support this by
2652 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2653 * to receive pixel buffer clobber events, however that may or may
2654 * not give any benefit */
2655 *piValue
= GL_FALSE
;
2658 case WGL_TEXTURE_FORMAT_ARB
:
2659 if (use_render_texture_ati
) {
2661 int type
= WGL_NO_TEXTURE_ARB
;
2663 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2664 wine_tsx11_unlock();
2666 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2667 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2668 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2672 if (!object
->use_render_texture
) {
2673 *piValue
= WGL_NO_TEXTURE_ARB
;
2675 if (!use_render_texture_emulation
) {
2676 SetLastError(ERROR_INVALID_HANDLE
);
2679 switch(object
->use_render_texture
) {
2681 *piValue
= WGL_TEXTURE_RGB_ARB
;
2684 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2686 /* WGL_FLOAT_COMPONENTS_NV */
2688 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2690 case GL_FLOAT_RG_NV
:
2691 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2693 case GL_FLOAT_RGB_NV
:
2694 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2696 case GL_FLOAT_RGBA_NV
:
2697 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2700 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2706 case WGL_TEXTURE_TARGET_ARB
:
2707 if (use_render_texture_ati
) {
2709 int type
= WGL_NO_TEXTURE_ARB
;
2711 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2712 wine_tsx11_unlock();
2714 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2715 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2716 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2717 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2721 if (!object
->texture_target
) {
2722 *piValue
= WGL_NO_TEXTURE_ARB
;
2724 if (!use_render_texture_emulation
) {
2725 SetLastError(ERROR_INVALID_DATA
);
2728 switch (object
->texture_target
) {
2729 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2730 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2731 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2732 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2738 case WGL_MIPMAP_TEXTURE_ARB
:
2739 if (use_render_texture_ati
) {
2741 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2742 wine_tsx11_unlock();
2744 *piValue
= GL_FALSE
; /** don't support that */
2745 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2750 FIXME("unexpected attribute %x\n", iAttribute
);
2758 * X11DRV_wglReleasePbufferDCARB
2760 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2762 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2764 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2765 return DeleteDC(hdc
);
2769 * X11DRV_wglSetPbufferAttribARB
2771 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2773 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2775 Wine_GLPBuffer
* object
= hPbuffer
;
2776 GLboolean ret
= GL_FALSE
;
2778 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2779 if (NULL
== object
) {
2780 SetLastError(ERROR_INVALID_HANDLE
);
2783 if (!object
->use_render_texture
) {
2784 SetLastError(ERROR_INVALID_HANDLE
);
2787 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2790 if (NULL
!= pglXDrawableAttribATI
) {
2791 if (use_render_texture_ati
) {
2792 FIXME("Need conversion for GLX_ATI_render_texture\n");
2795 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2796 wine_tsx11_unlock();
2802 * X11DRV_wglChoosePixelFormatARB
2804 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2806 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2811 GLXFBConfig
* cfgs
= NULL
;
2815 WineGLPixelFormat
*fmt
;
2821 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2822 if (NULL
!= pfAttribFList
) {
2823 FIXME("unused pfAttribFList\n");
2826 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2827 if (-1 == nAttribs
) {
2828 WARN("Cannot convert WGL to GLX attributes\n");
2831 PUSH1(attribs
, None
);
2833 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2834 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2835 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2836 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2838 switch(piAttribIList
[i
])
2840 case WGL_DRAW_TO_BITMAP_ARB
:
2841 if(piAttribIList
[i
+1])
2842 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2844 case WGL_ACCELERATION_ARB
:
2845 switch(piAttribIList
[i
+1])
2847 case WGL_NO_ACCELERATION_ARB
:
2848 dwFlags
|= PFD_GENERIC_FORMAT
;
2850 case WGL_GENERIC_ACCELERATION_ARB
:
2851 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2853 case WGL_FULL_ACCELERATION_ARB
:
2858 case WGL_SUPPORT_GDI_ARB
:
2859 if(piAttribIList
[i
+1])
2860 dwFlags
|= PFD_SUPPORT_GDI
;
2865 /* Search for FB configurations matching the requirements in attribs */
2867 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2869 wine_tsx11_unlock();
2870 WARN("Compatible Pixel Format not found\n");
2874 /* Loop through all matching formats and check if they are suitable.
2875 * Note that this function should at max return nMaxFormats different formats */
2876 for(run
=0; run
< 2; run
++)
2878 for (it
= 0; it
< nCfgs
; ++it
) {
2879 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2881 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2885 /* Search for the format in our list of compatible formats */
2886 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2890 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2891 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2894 if(pfmt_it
< nMaxFormats
) {
2895 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2896 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2902 *nNumFormats
= pfmt_it
;
2905 wine_tsx11_unlock();
2910 * X11DRV_wglGetPixelFormatAttribivARB
2912 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2914 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2917 WineGLPixelFormat
*fmt
= NULL
;
2921 int nWGLFormats
= 0;
2923 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2925 if (0 < iLayerPlane
) {
2926 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2930 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2931 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2932 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2933 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2935 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2939 for (i
= 0; i
< nAttributes
; ++i
) {
2940 const int curWGLAttr
= piAttributes
[i
];
2941 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2943 switch (curWGLAttr
) {
2944 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2945 piValues
[i
] = nWGLFormats
;
2948 case WGL_SUPPORT_OPENGL_ARB
:
2949 piValues
[i
] = GL_TRUE
;
2952 case WGL_ACCELERATION_ARB
:
2953 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2954 if (!fmt
) goto pix_error
;
2955 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2956 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2957 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2958 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2960 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2963 case WGL_TRANSPARENT_ARB
:
2964 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2965 if (!fmt
) goto pix_error
;
2966 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2967 if (hTest
) goto get_error
;
2968 piValues
[i
] = GL_FALSE
;
2969 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2972 case WGL_PIXEL_TYPE_ARB
:
2973 curGLXAttr
= GLX_RENDER_TYPE
;
2974 if (!fmt
) goto pix_error
;
2975 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2976 if (hTest
) goto get_error
;
2977 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2978 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2979 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2980 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2981 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2982 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2984 ERR("unexpected RenderType(%x)\n", tmp
);
2985 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2989 case WGL_COLOR_BITS_ARB
:
2990 curGLXAttr
= GLX_BUFFER_SIZE
;
2993 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2994 if (use_render_texture_ati
) {
2995 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2998 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2999 if (use_render_texture_ati
) {
3000 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
3003 if (!use_render_texture_emulation
) {
3004 piValues
[i
] = GL_FALSE
;
3007 curGLXAttr
= GLX_RENDER_TYPE
;
3008 if (!fmt
) goto pix_error
;
3009 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3010 if (hTest
) goto get_error
;
3011 if (GLX_COLOR_INDEX_BIT
== tmp
) {
3012 piValues
[i
] = GL_FALSE
;
3015 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3016 if (hTest
) goto get_error
;
3017 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
3020 case WGL_BLUE_BITS_ARB
:
3021 curGLXAttr
= GLX_BLUE_SIZE
;
3023 case WGL_RED_BITS_ARB
:
3024 curGLXAttr
= GLX_RED_SIZE
;
3026 case WGL_GREEN_BITS_ARB
:
3027 curGLXAttr
= GLX_GREEN_SIZE
;
3029 case WGL_ALPHA_BITS_ARB
:
3030 curGLXAttr
= GLX_ALPHA_SIZE
;
3032 case WGL_DEPTH_BITS_ARB
:
3033 curGLXAttr
= GLX_DEPTH_SIZE
;
3035 case WGL_STENCIL_BITS_ARB
:
3036 curGLXAttr
= GLX_STENCIL_SIZE
;
3038 case WGL_DOUBLE_BUFFER_ARB
:
3039 curGLXAttr
= GLX_DOUBLEBUFFER
;
3041 case WGL_STEREO_ARB
:
3042 curGLXAttr
= GLX_STEREO
;
3044 case WGL_AUX_BUFFERS_ARB
:
3045 curGLXAttr
= GLX_AUX_BUFFERS
;
3048 case WGL_SUPPORT_GDI_ARB
:
3049 if (!fmt
) goto pix_error
;
3050 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
3053 case WGL_DRAW_TO_BITMAP_ARB
:
3054 if (!fmt
) goto pix_error
;
3055 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
3058 case WGL_DRAW_TO_WINDOW_ARB
:
3059 case WGL_DRAW_TO_PBUFFER_ARB
:
3060 if (!fmt
) goto pix_error
;
3061 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3062 if (hTest
) goto get_error
;
3063 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
3064 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
3065 piValues
[i
] = GL_TRUE
;
3067 piValues
[i
] = GL_FALSE
;
3070 case WGL_SWAP_METHOD_ARB
:
3071 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3072 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3073 * point only ATI offers this.
3075 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
3078 case WGL_PBUFFER_LARGEST_ARB
:
3079 curGLXAttr
= GLX_LARGEST_PBUFFER
;
3082 case WGL_SAMPLE_BUFFERS_ARB
:
3083 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
3086 case WGL_SAMPLES_ARB
:
3087 curGLXAttr
= GLX_SAMPLES_ARB
;
3090 case WGL_FLOAT_COMPONENTS_NV
:
3091 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
3094 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
3095 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
3098 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
3099 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
3102 case WGL_ACCUM_RED_BITS_ARB
:
3103 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
3105 case WGL_ACCUM_GREEN_BITS_ARB
:
3106 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
3108 case WGL_ACCUM_BLUE_BITS_ARB
:
3109 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
3111 case WGL_ACCUM_ALPHA_BITS_ARB
:
3112 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
3114 case WGL_ACCUM_BITS_ARB
:
3115 if (!fmt
) goto pix_error
;
3116 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
3117 if (hTest
) goto get_error
;
3119 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
3120 if (hTest
) goto get_error
;
3122 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
3123 if (hTest
) goto get_error
;
3125 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
3126 if (hTest
) goto get_error
;
3131 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
3134 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3135 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3136 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3138 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3139 * and check which options can work using iPixelFormat=0 and which not.
3140 * A problem would be that this function is an extension. This would
3141 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3143 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
3144 if (!fmt
) goto pix_error
;
3145 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
3146 if (hTest
) goto get_error
;
3149 piValues
[i
] = GL_FALSE
;
3152 wine_tsx11_unlock();
3156 wine_tsx11_unlock();
3157 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3161 wine_tsx11_unlock();
3162 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3167 * X11DRV_wglGetPixelFormatAttribfvARB
3169 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3171 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3177 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3179 /* Allocate a temporary array to store integer values */
3180 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3182 ERR("couldn't allocate %d array\n", nAttributes
);
3186 /* Piggy-back on wglGetPixelFormatAttribivARB */
3187 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3189 /* Convert integer values to float. Should also check for attributes
3190 that can give decimal values here */
3191 for (i
=0; i
<nAttributes
;i
++) {
3192 pfValues
[i
] = attr
[i
];
3196 HeapFree(GetProcessHeap(), 0, attr
);
3201 * X11DRV_wglBindTexImageARB
3203 * WGL_ARB_render_texture: wglBindTexImageARB
3205 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3207 Wine_GLPBuffer
* object
= hPbuffer
;
3208 GLboolean ret
= GL_FALSE
;
3210 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3211 if (NULL
== object
) {
3212 SetLastError(ERROR_INVALID_HANDLE
);
3215 if (!object
->use_render_texture
) {
3216 SetLastError(ERROR_INVALID_HANDLE
);
3220 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3221 static int init
= 0;
3222 int prev_binded_texture
= 0;
3223 GLXContext prev_context
;
3224 Drawable prev_drawable
;
3225 GLXContext tmp_context
;
3228 prev_context
= pglXGetCurrentContext();
3229 prev_drawable
= pglXGetCurrentDrawable();
3231 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3232 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3233 isn't ideal performance wise but I wasn't able to get other ways working.
3236 init
= 1; /* Only show the FIXME once for performance reasons */
3237 FIXME("partial stub!\n");
3240 TRACE("drawable=%lx, context=%p\n", object
->drawable
, prev_context
);
3241 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3243 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3245 /* Switch to our pbuffer */
3246 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3248 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3249 * After that upload the pbuffer texture data. */
3250 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3251 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3253 /* Switch back to the original drawable and upload the pbuffer-texture */
3254 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3255 pglXDestroyContext(gdi_display
, tmp_context
);
3256 wine_tsx11_unlock();
3260 if (NULL
!= pglXBindTexImageATI
) {
3265 case WGL_FRONT_LEFT_ARB
:
3266 buffer
= GLX_FRONT_LEFT_ATI
;
3268 case WGL_FRONT_RIGHT_ARB
:
3269 buffer
= GLX_FRONT_RIGHT_ATI
;
3271 case WGL_BACK_LEFT_ARB
:
3272 buffer
= GLX_BACK_LEFT_ATI
;
3274 case WGL_BACK_RIGHT_ARB
:
3275 buffer
= GLX_BACK_RIGHT_ATI
;
3278 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3282 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3283 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3284 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3285 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3286 * works fine using our pbuffer emulation path.
3289 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3290 wine_tsx11_unlock();
3296 * X11DRV_wglReleaseTexImageARB
3298 * WGL_ARB_render_texture: wglReleaseTexImageARB
3300 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3302 Wine_GLPBuffer
* object
= hPbuffer
;
3303 GLboolean ret
= GL_FALSE
;
3305 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3306 if (NULL
== object
) {
3307 SetLastError(ERROR_INVALID_HANDLE
);
3310 if (!object
->use_render_texture
) {
3311 SetLastError(ERROR_INVALID_HANDLE
);
3314 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3317 if (NULL
!= pglXReleaseTexImageATI
) {
3322 case WGL_FRONT_LEFT_ARB
:
3323 buffer
= GLX_FRONT_LEFT_ATI
;
3325 case WGL_FRONT_RIGHT_ARB
:
3326 buffer
= GLX_FRONT_RIGHT_ATI
;
3328 case WGL_BACK_LEFT_ARB
:
3329 buffer
= GLX_BACK_LEFT_ATI
;
3331 case WGL_BACK_RIGHT_ARB
:
3332 buffer
= GLX_BACK_RIGHT_ATI
;
3335 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3339 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3340 wine_tsx11_unlock();
3346 * X11DRV_wglGetExtensionsStringEXT
3348 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3350 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3351 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3352 return WineGLInfo
.wglExtensions
;
3356 * X11DRV_wglGetSwapIntervalEXT
3358 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3360 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3361 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
3362 * interval, so the swap interval has to be tracked. */
3364 return swap_interval
;
3368 * X11DRV_wglSwapIntervalEXT
3370 * WGL_EXT_swap_control: wglSwapIntervalEXT
3372 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3375 TRACE("(%d)\n", interval
);
3379 SetLastError(ERROR_INVALID_DATA
);
3382 else if (!has_swap_control
&& interval
== 0)
3384 /* wglSwapIntervalEXT considers an interval value of zero to mean that
3385 * vsync should be disabled, but glXSwapIntervalSGI considers such a
3386 * value to be an error. Just silently ignore the request for now. */
3387 WARN("Request to disable vertical sync is not handled\n");
3392 if (pglXSwapIntervalSGI
)
3395 ret
= !pglXSwapIntervalSGI(interval
);
3396 wine_tsx11_unlock();
3399 WARN("GLX_SGI_swap_control extension is not available\n");
3402 swap_interval
= interval
;
3404 SetLastError(ERROR_DC_NOT_FOUND
);
3411 * X11DRV_wglAllocateMemoryNV
3413 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3415 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3417 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3419 if (pglXAllocateMemoryNV
)
3422 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3423 wine_tsx11_unlock();
3429 * X11DRV_wglFreeMemoryNV
3431 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3433 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3434 TRACE("(%p)\n", pointer
);
3435 if (pglXFreeMemoryNV
== NULL
)
3439 pglXFreeMemoryNV(pointer
);
3440 wine_tsx11_unlock();
3444 * glxdrv_wglSetPixelFormatWINE
3446 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3447 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3449 static BOOL
glxdrv_wglSetPixelFormatWINE(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3451 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3453 TRACE("(%p,%d,%p)\n", dev
->hdc
, iPixelFormat
, ppfd
);
3455 if (!has_opengl()) return FALSE
;
3457 if (physdev
->pixel_format
== iPixelFormat
) return TRUE
;
3459 /* Relay to the core SetPixelFormat */
3460 TRACE("Changing iPixelFormat from %d to %d\n", physdev
->pixel_format
, iPixelFormat
);
3461 return internal_SetPixelFormat(physdev
, iPixelFormat
, ppfd
);
3465 * glxRequireVersion (internal)
3467 * Check if the supported GLX version matches requiredVersion.
3469 static BOOL
glxRequireVersion(int requiredVersion
)
3471 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3472 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3478 static BOOL
glxRequireExtension(const char *requiredExtension
)
3480 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3487 static void register_extension_string(const char *ext
)
3489 if (WineGLInfo
.wglExtensions
[0])
3490 strcat(WineGLInfo
.wglExtensions
, " ");
3491 strcat(WineGLInfo
.wglExtensions
, ext
);
3493 TRACE("'%s'\n", ext
);
3496 static BOOL
register_extension(const WineGLExtension
* ext
)
3500 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3501 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3503 register_extension_string(ext
->extName
);
3505 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3506 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3511 static const WineGLExtension WGL_internal_functions
=
3515 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3516 { "wglFinish", X11DRV_wglFinish
},
3517 { "wglFlush", X11DRV_wglFlush
},
3522 static const WineGLExtension WGL_ARB_create_context
=
3524 "WGL_ARB_create_context",
3526 { "wglCreateContextAttribsARB", (void *)1 /* not called directly */ },
3530 static const WineGLExtension WGL_ARB_extensions_string
=
3532 "WGL_ARB_extensions_string",
3534 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3538 static const WineGLExtension WGL_ARB_make_current_read
=
3540 "WGL_ARB_make_current_read",
3542 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3543 { "wglMakeContextCurrentARB", (void *)1 /* not called directly */ },
3547 static const WineGLExtension WGL_ARB_multisample
=
3549 "WGL_ARB_multisample",
3552 static const WineGLExtension WGL_ARB_pbuffer
=
3556 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3557 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3558 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3559 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3560 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3561 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3565 static const WineGLExtension WGL_ARB_pixel_format
=
3567 "WGL_ARB_pixel_format",
3569 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3570 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3571 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3575 static const WineGLExtension WGL_ARB_render_texture
=
3577 "WGL_ARB_render_texture",
3579 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3580 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3584 static const WineGLExtension WGL_EXT_extensions_string
=
3586 "WGL_EXT_extensions_string",
3588 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3592 static const WineGLExtension WGL_EXT_swap_control
=
3594 "WGL_EXT_swap_control",
3596 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3597 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3601 static const WineGLExtension WGL_NV_vertex_array_range
=
3603 "WGL_NV_vertex_array_range",
3605 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3606 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3610 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3612 "WGL_WINE_pixel_format_passthrough",
3614 { "wglSetPixelFormatWINE", (void *)1 /* not called directly */ },
3619 * X11DRV_WineGL_LoadExtensions
3621 static void X11DRV_WineGL_LoadExtensions(void)
3623 WineGLInfo
.wglExtensions
[0] = 0;
3625 /* Load Wine internal functions */
3626 register_extension(&WGL_internal_functions
);
3628 /* ARB Extensions */
3630 if(glxRequireExtension("GLX_ARB_create_context"))
3632 register_extension(&WGL_ARB_create_context
);
3634 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3635 register_extension_string("WGL_ARB_create_context_profile");
3638 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3640 register_extension_string("WGL_ARB_pixel_format_float");
3641 register_extension_string("WGL_ATI_pixel_format_float");
3644 register_extension(&WGL_ARB_extensions_string
);
3646 if (glxRequireVersion(3))
3647 register_extension(&WGL_ARB_make_current_read
);
3649 if (glxRequireExtension("GLX_ARB_multisample"))
3650 register_extension(&WGL_ARB_multisample
);
3652 /* In general pbuffer functionality requires support in the X-server. The functionality is
3653 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3654 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3655 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3657 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3658 * without support in the X-server (which other Mesa based drivers require).
3660 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3661 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3662 * is available pbuffers must be available too. */
3663 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3664 register_extension(&WGL_ARB_pbuffer
);
3666 register_extension(&WGL_ARB_pixel_format
);
3668 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3669 if (glxRequireExtension("GLX_ATI_render_texture") ||
3670 glxRequireExtension("GLX_ARB_render_texture") ||
3671 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3673 register_extension(&WGL_ARB_render_texture
);
3675 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3676 if(glxRequireExtension("GLX_NV_float_buffer"))
3677 register_extension_string("WGL_NV_float_buffer");
3679 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3680 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3681 register_extension_string("WGL_NV_texture_rectangle");
3684 /* EXT Extensions */
3686 register_extension(&WGL_EXT_extensions_string
);
3688 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3689 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3690 register_extension(&WGL_EXT_swap_control
);
3692 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3693 register_extension_string("WGL_EXT_framebuffer_sRGB");
3695 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3696 register_extension_string("WGL_EXT_pixel_format_packed_float");
3698 if (glxRequireExtension("GLX_EXT_swap_control"))
3699 has_swap_control
= TRUE
;
3701 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3702 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3703 register_extension(&WGL_NV_vertex_array_range
);
3705 /* WINE-specific WGL Extensions */
3707 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3708 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3710 register_extension(&WGL_WINE_pixel_format_passthrough
);
3714 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3717 pglXDestroyGLXPixmap(display
, glxpixmap
);
3718 wine_tsx11_unlock();
3723 * glxdrv_SwapBuffers
3725 * Swap the buffers of this DC
3727 static BOOL
glxdrv_SwapBuffers(PHYSDEV dev
)
3729 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3730 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3732 if (!has_opengl()) return FALSE
;
3734 TRACE("(%p)\n", dev
->hdc
);
3738 WARN("Using a NULL context, skipping\n");
3739 SetLastError(ERROR_INVALID_HANDLE
);
3743 if (!physdev
->drawable
)
3745 WARN("Using an invalid drawable, skipping\n");
3746 SetLastError(ERROR_INVALID_HANDLE
);
3752 switch (physdev
->type
)
3754 case DC_GL_PIXMAP_WIN
:
3755 if(pglXCopySubBufferMESA
) {
3756 int w
= physdev
->x11dev
->dc_rect
.right
- physdev
->x11dev
->dc_rect
.left
;
3757 int h
= physdev
->x11dev
->dc_rect
.bottom
- physdev
->x11dev
->dc_rect
.top
;
3759 /* (glX)SwapBuffers has an implicit glFlush effect, however
3760 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3764 pglXCopySubBufferMESA(gdi_display
, physdev
->drawable
, 0, 0, w
, h
);
3769 pglXSwapBuffers(gdi_display
, physdev
->drawable
);
3773 flush_gl_drawable( physdev
);
3774 wine_tsx11_unlock();
3779 static long prev_time
, start_time
;
3780 static unsigned long frames
, frames_total
;
3782 DWORD time
= GetTickCount();
3785 /* every 1.5 seconds */
3786 if (time
- prev_time
> 1500) {
3787 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3788 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3791 if(start_time
== 0) start_time
= time
;
3798 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3800 WineGLPixelFormat
*fmt
;
3803 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3808 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3809 wine_tsx11_unlock();
3813 static BOOL
create_glx_dc( PHYSDEV
*pdev
)
3815 /* assume that only the main x11 device implements GetDeviceCaps */
3816 X11DRV_PDEVICE
*x11dev
= get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev
, pGetDeviceCaps
));
3817 struct glx_physdev
*physdev
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*physdev
) );
3819 if (!physdev
) return FALSE
;
3820 physdev
->x11dev
= x11dev
;
3821 push_dc_driver( pdev
, &physdev
->dev
, &glxdrv_funcs
);
3825 /**********************************************************************
3828 static BOOL
glxdrv_CreateDC( PHYSDEV
*pdev
, LPCWSTR driver
, LPCWSTR device
,
3829 LPCWSTR output
, const DEVMODEW
* initData
)
3831 return create_glx_dc( pdev
);
3834 /**********************************************************************
3835 * glxdrv_CreateCompatibleDC
3837 static BOOL
glxdrv_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
)
3839 if (orig
) /* chain to next driver first */
3841 orig
= GET_NEXT_PHYSDEV( orig
, pCreateCompatibleDC
);
3842 if (!orig
->funcs
->pCreateCompatibleDC( orig
, pdev
)) return FALSE
;
3844 /* otherwise we have been called by x11drv */
3845 return create_glx_dc( pdev
);
3848 /**********************************************************************
3851 static BOOL
glxdrv_DeleteDC( PHYSDEV dev
)
3853 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3854 HeapFree( GetProcessHeap(), 0, physdev
);
3858 /***********************************************************************
3859 * glxdrv_SelectBitmap
3861 static HBITMAP
glxdrv_SelectBitmap( PHYSDEV dev
, HBITMAP hbitmap
)
3864 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3866 dev
= GET_NEXT_PHYSDEV( dev
, pSelectBitmap
);
3867 ret
= dev
->funcs
->pSelectBitmap( dev
, hbitmap
);
3870 if (hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
) physdev
->drawable
= 0;
3871 else physdev
->drawable
= X11DRV_get_phys_bitmap(hbitmap
)->glxpixmap
;
3876 /**********************************************************************
3879 static INT
glxdrv_ExtEscape( PHYSDEV dev
, INT escape
, INT in_count
, LPCVOID in_data
,
3880 INT out_count
, LPVOID out_data
)
3882 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3884 dev
= GET_NEXT_PHYSDEV( dev
, pExtEscape
);
3886 if (escape
== X11DRV_ESCAPE
&& in_data
&& in_count
>= sizeof(enum x11drv_escape_codes
))
3888 switch (*(const enum x11drv_escape_codes
*)in_data
)
3890 case X11DRV_SET_DRAWABLE
:
3891 if (in_count
>= sizeof(struct x11drv_escape_set_drawable
))
3893 const struct x11drv_escape_set_drawable
*data
= in_data
;
3894 physdev
->pixel_format
= pixelformat_from_fbconfig_id( data
->fbconfig_id
);
3895 physdev
->type
= data
->gl_type
;
3896 physdev
->drawable
= data
->gl_drawable
;
3897 physdev
->pixmap
= data
->pixmap
;
3898 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %u type %u\n",
3899 dev
->hdc
, physdev
->drawable
, physdev
->pixel_format
, physdev
->type
);
3902 case X11DRV_FLUSH_GL_DRAWABLE
:
3903 flush_gl_drawable( physdev
);
3909 return dev
->funcs
->pExtEscape( dev
, escape
, in_count
, in_data
, out_count
, out_data
);
3912 static const struct gdi_dc_funcs glxdrv_funcs
=
3914 NULL
, /* pAbortDoc */
3915 NULL
, /* pAbortPath */
3916 NULL
, /* pAlphaBlend */
3917 NULL
, /* pAngleArc */
3920 NULL
, /* pBeginPath */
3921 NULL
, /* pBlendImage */
3922 glxdrv_ChoosePixelFormat
, /* pChoosePixelFormat */
3924 NULL
, /* pCloseFigure */
3925 NULL
, /* pCopyBitmap */
3926 NULL
, /* pCreateBitmap */
3927 glxdrv_CreateCompatibleDC
, /* pCreateCompatibleDC */
3928 glxdrv_CreateDC
, /* pCreateDC */
3929 NULL
, /* pDeleteBitmap */
3930 glxdrv_DeleteDC
, /* pDeleteDC */
3931 NULL
, /* pDeleteObject */
3932 glxdrv_DescribePixelFormat
, /* pDescribePixelFormat */
3933 NULL
, /* pDeviceCapabilities */
3934 NULL
, /* pEllipse */
3936 NULL
, /* pEndPage */
3937 NULL
, /* pEndPath */
3938 NULL
, /* pEnumFonts */
3939 NULL
, /* pEnumICMProfiles */
3940 NULL
, /* pExcludeClipRect */
3941 NULL
, /* pExtDeviceMode */
3942 glxdrv_ExtEscape
, /* pExtEscape */
3943 NULL
, /* pExtFloodFill */
3944 NULL
, /* pExtSelectClipRgn */
3945 NULL
, /* pExtTextOut */
3946 NULL
, /* pFillPath */
3947 NULL
, /* pFillRgn */
3948 NULL
, /* pFlattenPath */
3949 NULL
, /* pFontIsLinked */
3950 NULL
, /* pFrameRgn */
3951 NULL
, /* pGdiComment */
3952 NULL
, /* pGdiRealizationInfo */
3953 NULL
, /* pGetBoundsRect */
3954 NULL
, /* pGetCharABCWidths */
3955 NULL
, /* pGetCharABCWidthsI */
3956 NULL
, /* pGetCharWidth */
3957 NULL
, /* pGetDeviceCaps */
3958 NULL
, /* pGetDeviceGammaRamp */
3959 NULL
, /* pGetFontData */
3960 NULL
, /* pGetFontUnicodeRanges */
3961 NULL
, /* pGetGlyphIndices */
3962 NULL
, /* pGetGlyphOutline */
3963 NULL
, /* pGetICMProfile */
3964 NULL
, /* pGetImage */
3965 NULL
, /* pGetKerningPairs */
3966 NULL
, /* pGetNearestColor */
3967 NULL
, /* pGetOutlineTextMetrics */
3968 NULL
, /* pGetPixel */
3969 glxdrv_GetPixelFormat
, /* pGetPixelFormat */
3970 NULL
, /* pGetSystemPaletteEntries */
3971 NULL
, /* pGetTextCharsetInfo */
3972 NULL
, /* pGetTextExtentExPoint */
3973 NULL
, /* pGetTextExtentExPointI */
3974 NULL
, /* pGetTextFace */
3975 NULL
, /* pGetTextMetrics */
3976 NULL
, /* pGradientFill */
3977 NULL
, /* pIntersectClipRect */
3978 NULL
, /* pInvertRgn */
3980 NULL
, /* pModifyWorldTransform */
3982 NULL
, /* pOffsetClipRgn */
3983 NULL
, /* pOffsetViewportOrg */
3984 NULL
, /* pOffsetWindowOrg */
3985 NULL
, /* pPaintRgn */
3988 NULL
, /* pPolyBezier */
3989 NULL
, /* pPolyBezierTo */
3990 NULL
, /* pPolyDraw */
3991 NULL
, /* pPolyPolygon */
3992 NULL
, /* pPolyPolyline */
3993 NULL
, /* pPolygon */
3994 NULL
, /* pPolyline */
3995 NULL
, /* pPolylineTo */
3996 NULL
, /* pPutImage */
3997 NULL
, /* pRealizeDefaultPalette */
3998 NULL
, /* pRealizePalette */
3999 NULL
, /* pRectangle */
4000 NULL
, /* pResetDC */
4001 NULL
, /* pRestoreDC */
4002 NULL
, /* pRoundRect */
4004 NULL
, /* pScaleViewportExt */
4005 NULL
, /* pScaleWindowExt */
4006 glxdrv_SelectBitmap
, /* pSelectBitmap */
4007 NULL
, /* pSelectBrush */
4008 NULL
, /* pSelectClipPath */
4009 NULL
, /* pSelectFont */
4010 NULL
, /* pSelectPalette */
4011 NULL
, /* pSelectPen */
4012 NULL
, /* pSetArcDirection */
4013 NULL
, /* pSetBkColor */
4014 NULL
, /* pSetBkMode */
4015 NULL
, /* pSetBoundsRect */
4016 NULL
, /* pSetDCBrushColor */
4017 NULL
, /* pSetDCPenColor */
4018 NULL
, /* pSetDIBitsToDevice */
4019 NULL
, /* pSetDeviceClipping */
4020 NULL
, /* pSetDeviceGammaRamp */
4021 NULL
, /* pSetLayout */
4022 NULL
, /* pSetMapMode */
4023 NULL
, /* pSetMapperFlags */
4024 NULL
, /* pSetPixel */
4025 glxdrv_SetPixelFormat
, /* pSetPixelFormat */
4026 NULL
, /* pSetPolyFillMode */
4027 NULL
, /* pSetROP2 */
4028 NULL
, /* pSetRelAbs */
4029 NULL
, /* pSetStretchBltMode */
4030 NULL
, /* pSetTextAlign */
4031 NULL
, /* pSetTextCharacterExtra */
4032 NULL
, /* pSetTextColor */
4033 NULL
, /* pSetTextJustification */
4034 NULL
, /* pSetViewportExt */
4035 NULL
, /* pSetViewportOrg */
4036 NULL
, /* pSetWindowExt */
4037 NULL
, /* pSetWindowOrg */
4038 NULL
, /* pSetWorldTransform */
4039 NULL
, /* pStartDoc */
4040 NULL
, /* pStartPage */
4041 NULL
, /* pStretchBlt */
4042 NULL
, /* pStretchDIBits */
4043 NULL
, /* pStrokeAndFillPath */
4044 NULL
, /* pStrokePath */
4045 glxdrv_SwapBuffers
, /* pSwapBuffers */
4046 NULL
, /* pUnrealizePalette */
4047 NULL
, /* pWidenPath */
4048 glxdrv_wglCopyContext
, /* pwglCopyContext */
4049 glxdrv_wglCreateContext
, /* pwglCreateContext */
4050 glxdrv_wglCreateContextAttribsARB
, /* pwglCreateContextAttribsARB */
4051 glxdrv_wglDeleteContext
, /* pwglDeleteContext */
4052 glxdrv_wglGetProcAddress
, /* pwglGetProcAddress */
4053 glxdrv_wglMakeContextCurrentARB
, /* pwglMakeContextCurrentARB */
4054 glxdrv_wglMakeCurrent
, /* pwglMakeCurrent */
4055 glxdrv_wglSetPixelFormatWINE
, /* pwglSetPixelFormatWINE */
4056 glxdrv_wglShareLists
, /* pwglShareLists */
4057 glxdrv_wglUseFontBitmapsA
, /* pwglUseFontBitmapsA */
4058 glxdrv_wglUseFontBitmapsW
, /* pwglUseFontBitmapsW */
4059 GDI_PRIORITY_GRAPHICS_DRV
+ 20 /* priority */
4062 const struct gdi_dc_funcs
*get_glx_driver(void)
4064 return &glxdrv_funcs
;
4067 #else /* no OpenGL includes */
4069 const struct gdi_dc_funcs
*get_glx_driver(void)
4074 void mark_drawable_dirty(Drawable old
, Drawable
new)
4078 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
4084 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
4089 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
4094 #endif /* defined(SONAME_LIBGL) */