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
9 * Copyright 2012 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/port.h"
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
51 #include "wine/library.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
58 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
59 WINE_DECLARE_DEBUG_CHANNEL(fps
);
61 #include "wine/wgl_driver.h"
62 #include "wine/wglext.h"
64 /* For compatibility with old Mesa headers */
65 #ifndef GLX_SAMPLE_BUFFERS_ARB
66 # define GLX_SAMPLE_BUFFERS_ARB 100000
68 #ifndef GLX_SAMPLES_ARB
69 # define GLX_SAMPLES_ARB 100001
71 #ifndef GL_TEXTURE_CUBE_MAP
72 # define GL_TEXTURE_CUBE_MAP 0x8513
74 #ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
75 # define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
77 #ifndef GLX_EXT_fbconfig_packed_float
78 # define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
79 # define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
81 #ifndef GLX_ARB_create_context
82 # define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
83 # define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
84 # define GLX_CONTEXT_FLAGS_ARB 0x2094
86 #ifndef GLX_ARB_create_context_profile
87 # define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
89 /** GLX_ATI_pixel_format_float */
90 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
91 /** GLX_ARB_pixel_format_float */
92 #define GLX_RGBA_FLOAT_BIT 0x00000004
93 #define GLX_RGBA_FLOAT_TYPE 0x20B9
94 /** GL_NV_float_buffer */
95 #define GL_FLOAT_R_NV 0x8880
96 #define GL_FLOAT_RG_NV 0x8881
97 #define GL_FLOAT_RGB_NV 0x8882
98 #define GL_FLOAT_RGBA_NV 0x8883
99 #define GL_FLOAT_R16_NV 0x8884
100 #define GL_FLOAT_R32_NV 0x8885
101 #define GL_FLOAT_RG16_NV 0x8886
102 #define GL_FLOAT_RG32_NV 0x8887
103 #define GL_FLOAT_RGB16_NV 0x8888
104 #define GL_FLOAT_RGB32_NV 0x8889
105 #define GL_FLOAT_RGBA16_NV 0x888A
106 #define GL_FLOAT_RGBA32_NV 0x888B
107 #define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C
108 #define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D
109 #define GL_FLOAT_RGBA_MODE_NV 0x888E
110 /** GLX_NV_float_buffer */
111 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
115 const char *glVersion
;
120 const char *glxServerVersion
;
121 const char *glxServerVendor
;
122 const char *glxServerExtensions
;
124 const char *glxClientVersion
;
125 const char *glxClientVendor
;
126 const char *glxClientExtensions
;
128 const char *glxExtensions
;
131 char wglExtensions
[4096];
134 typedef struct wine_glpixelformat
{
136 GLXFBConfig fbconfig
;
140 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
146 BOOL has_been_current
;
150 WineGLPixelFormat
*fmt
;
151 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
152 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
154 Drawable drawables
[2];
155 BOOL refresh_drawables
;
162 WineGLPixelFormat
* fmt
;
166 int use_render_texture
; /* This is also the internal texture format */
167 int texture_bind_target
;
169 GLint texture_format
;
170 GLuint texture_target
;
178 struct gdi_physdev dev
;
179 X11DRV_PDEVICE
*x11dev
;
180 enum dc_gl_type type
; /* type of GL device context */
183 Pixmap pixmap
; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
186 static const struct gdi_dc_funcs glxdrv_funcs
;
188 static inline struct glx_physdev
*get_glxdrv_dev( PHYSDEV dev
)
190 return (struct glx_physdev
*)dev
;
193 static struct list context_list
= LIST_INIT( context_list
);
194 static struct WineGLInfo WineGLInfo
= { 0 };
195 static int use_render_texture_emulation
= 1;
196 static BOOL has_swap_control
;
197 static int swap_interval
= 1;
199 static struct opengl_funcs opengl_funcs
;
201 #define USE_GL_FUNC(name) #name,
202 static const char *opengl_func_names
[] = { ALL_WGL_FUNCS
};
205 static void X11DRV_WineGL_LoadExtensions(void);
206 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
207 static BOOL
glxRequireVersion(int requiredVersion
);
209 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
210 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
211 TRACE(" - dwFlags : ");
212 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
213 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
214 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
215 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
216 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
217 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
218 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
219 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
220 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
221 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
222 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
223 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
224 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
225 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
226 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
227 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
228 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
229 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
230 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
231 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
235 TRACE(" - iPixelType : ");
236 switch (ppfd
->iPixelType
) {
237 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
238 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
242 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
243 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
244 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
245 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
246 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
247 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
248 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
249 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
250 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
252 TRACE(" - iLayerType : ");
253 switch (ppfd
->iLayerType
) {
254 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
255 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
256 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
261 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
262 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
264 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
266 MAKE_FUNCPTR(glXChooseVisual
)
267 MAKE_FUNCPTR(glXCopyContext
)
268 MAKE_FUNCPTR(glXCreateContext
)
269 MAKE_FUNCPTR(glXCreateGLXPixmap
)
270 MAKE_FUNCPTR(glXGetCurrentContext
)
271 MAKE_FUNCPTR(glXGetCurrentDrawable
)
272 MAKE_FUNCPTR(glXDestroyContext
)
273 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
274 MAKE_FUNCPTR(glXGetConfig
)
275 MAKE_FUNCPTR(glXIsDirect
)
276 MAKE_FUNCPTR(glXMakeCurrent
)
277 MAKE_FUNCPTR(glXSwapBuffers
)
278 MAKE_FUNCPTR(glXQueryExtension
)
279 MAKE_FUNCPTR(glXQueryVersion
)
282 MAKE_FUNCPTR(glXGetClientString
)
283 MAKE_FUNCPTR(glXQueryExtensionsString
)
284 MAKE_FUNCPTR(glXQueryServerString
)
287 MAKE_FUNCPTR(glXGetFBConfigs
)
288 MAKE_FUNCPTR(glXChooseFBConfig
)
289 MAKE_FUNCPTR(glXCreatePbuffer
)
290 MAKE_FUNCPTR(glXCreateNewContext
)
291 MAKE_FUNCPTR(glXDestroyPbuffer
)
292 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
293 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
294 MAKE_FUNCPTR(glXMakeContextCurrent
)
295 MAKE_FUNCPTR(glXQueryDrawable
)
296 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
300 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
301 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
302 static int (*pglXSwapIntervalSGI
)(int);
304 /* NV GLX Extension */
305 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
306 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
308 /* MESA GLX Extensions */
309 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
311 /* Standard OpenGL */
312 static void (*pglFinish
)(void);
313 static void (*pglFlush
)(void);
315 static void wglFinish(void);
316 static void wglFlush(void);
318 /* check if the extension is present in the list */
319 static BOOL
has_extension( const char *list
, const char *ext
)
321 size_t len
= strlen( ext
);
325 while (*list
== ' ') list
++;
326 if (!strncmp( list
, ext
, len
) && (!list
[len
] || list
[len
] == ' ')) return TRUE
;
327 list
= strchr( list
, ' ' );
332 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
334 /* In the future we might want to find the exact X or GLX error to report back to the app */
338 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
340 int screen
= DefaultScreen(gdi_display
);
341 Window win
= 0, root
= 0;
342 const char *gl_renderer
;
345 GLXContext ctx
= NULL
;
346 XSetWindowAttributes attr
;
348 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
350 attr
.override_redirect
= True
;
351 attr
.colormap
= None
;
352 attr
.border_pixel
= 0;
354 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
357 WORD old_fs
= wine_get_fs();
358 /* Create a GLX Context. Without one we can't query GL information */
359 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
360 if (wine_get_fs() != old_fs
)
362 wine_set_fs( old_fs
);
363 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
364 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
368 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
373 root
= RootWindow( gdi_display
, vis
->screen
);
374 if (vis
->visual
!= DefaultVisual( gdi_display
, vis
->screen
))
375 attr
.colormap
= XCreateColormap( gdi_display
, root
, vis
->visual
, AllocNone
);
376 if ((win
= XCreateWindow( gdi_display
, root
, -1, -1, 1, 1, 0, vis
->depth
, InputOutput
,
377 vis
->visual
, CWBorderPixel
| CWOverrideRedirect
| CWColormap
, &attr
)))
378 XMapWindow( gdi_display
, win
);
382 if(pglXMakeCurrent(gdi_display
, win
, ctx
) == 0)
384 ERR_(winediag
)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
387 gl_renderer
= (const char *)opengl_funcs
.gl
.p_glGetString(GL_RENDERER
);
388 WineGLInfo
.glVersion
= (const char *) opengl_funcs
.gl
.p_glGetString(GL_VERSION
);
389 str
= (const char *) opengl_funcs
.gl
.p_glGetString(GL_EXTENSIONS
);
390 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
391 strcpy(WineGLInfo
.glExtensions
, str
);
393 /* Get the common GLX version supported by GLX client and server ( major/minor) */
394 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
396 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
397 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
398 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
400 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
401 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
402 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
404 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
405 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
407 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
408 TRACE("GL renderer : %s.\n", gl_renderer
);
409 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
410 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
411 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
412 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
413 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
414 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
416 if(!WineGLInfo
.glxDirect
)
418 int fd
= ConnectionNumber(gdi_display
);
419 struct sockaddr_un uaddr
;
420 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
422 /* In general indirect rendering on a local X11 server indicates a driver problem.
423 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
425 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
426 ERR_(winediag
)("Direct rendering is disabled, most likely your OpenGL drivers "
427 "haven't been installed correctly (using GL renderer %s, version %s).\n",
428 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
432 /* In general you would expect that if direct rendering is returned, that you receive hardware
433 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
434 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
435 * software rendering, it shows direct rendering.
437 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
438 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
439 * it shows 'Mesa X11'.
441 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
442 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
443 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
444 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
451 pglXMakeCurrent(gdi_display
, None
, NULL
);
452 pglXDestroyContext(gdi_display
, ctx
);
454 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
455 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
456 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
460 static BOOL
has_opengl(void)
462 static int init_done
;
463 static void *opengl_handle
;
466 int error_base
, event_base
;
469 if (init_done
) return (opengl_handle
!= NULL
);
472 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
473 and include all dependencies */
474 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
475 if (opengl_handle
== NULL
)
477 ERR( "Failed to load libGL: %s\n", buffer
);
478 ERR( "OpenGL support is disabled.\n");
482 for (i
= 0; i
< sizeof(opengl_func_names
)/sizeof(opengl_func_names
[0]); i
++)
484 if (!(((void **)&opengl_funcs
.gl
)[i
] = wine_dlsym( opengl_handle
, opengl_func_names
[i
], NULL
, 0 )))
486 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names
[i
] );
491 /* redirect some standard OpenGL functions */
492 #define REDIRECT(func) \
493 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
494 REDIRECT( glFinish
);
498 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
499 if (pglXGetProcAddressARB
== NULL
) {
500 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
504 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
506 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
511 LOAD_FUNCPTR(glXChooseVisual
);
512 LOAD_FUNCPTR(glXCopyContext
);
513 LOAD_FUNCPTR(glXCreateContext
);
514 LOAD_FUNCPTR(glXCreateGLXPixmap
);
515 LOAD_FUNCPTR(glXGetCurrentContext
);
516 LOAD_FUNCPTR(glXGetCurrentDrawable
);
517 LOAD_FUNCPTR(glXDestroyContext
);
518 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
519 LOAD_FUNCPTR(glXGetConfig
);
520 LOAD_FUNCPTR(glXIsDirect
);
521 LOAD_FUNCPTR(glXMakeCurrent
);
522 LOAD_FUNCPTR(glXSwapBuffers
);
523 LOAD_FUNCPTR(glXQueryExtension
);
524 LOAD_FUNCPTR(glXQueryVersion
);
527 LOAD_FUNCPTR(glXGetClientString
);
528 LOAD_FUNCPTR(glXQueryExtensionsString
);
529 LOAD_FUNCPTR(glXQueryServerString
);
532 LOAD_FUNCPTR(glXCreatePbuffer
);
533 LOAD_FUNCPTR(glXCreateNewContext
);
534 LOAD_FUNCPTR(glXDestroyPbuffer
);
535 LOAD_FUNCPTR(glXMakeContextCurrent
);
536 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
537 LOAD_FUNCPTR(glXGetFBConfigs
);
540 /* It doesn't matter if these fail. They'll only be used if the driver reports
541 the associated extension is available (and if a driver reports the extension
542 is available but fails to provide the functions, it's quite broken) */
543 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
544 /* ARB GLX Extension */
545 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
546 /* SGI GLX Extension */
547 LOAD_FUNCPTR(glXSwapIntervalSGI
);
548 /* NV GLX Extension */
549 LOAD_FUNCPTR(glXAllocateMemoryNV
);
550 LOAD_FUNCPTR(glXFreeMemoryNV
);
553 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
555 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
556 TRACE("GLX is up and running error_base = %d\n", error_base
);
558 ERR( "GLX extension is missing, disabling OpenGL.\n" );
562 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
563 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
566 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
567 * depends on the reported GLX client / server version and on the client / server extension list.
568 * Those don't have to be the same.
570 * In general the server GLX information lists the capabilities in case of indirect rendering.
571 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
572 * available and in that case the client GLX informat can be used.
573 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
574 * in the GLX version/extension list. When a program does this it works for certain for both
575 * direct and indirect rendering.
577 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
578 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
579 * extension list which causes this extension not to be listed. (Wine requires this extension).
580 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
581 * pbuffers is around.
583 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
584 * the ATI drivers and from then on use GLX client information for them.
587 if(glxRequireVersion(3)) {
588 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
589 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
590 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
591 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
592 } else if (has_extension( WineGLInfo
.glxExtensions
, "GLX_SGIX_fbconfig")) {
593 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
594 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
595 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
597 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
598 * enable this function when the Xserver understand GLX 1.3 or newer
600 pglXQueryDrawable
= NULL
;
601 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
602 TRACE("Overriding ATI GLX capabilities!\n");
603 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
604 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
605 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
606 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
608 /* Use client GLX information in case of the ATI drivers. We override the
609 * capabilities over here and not somewhere else as ATI might better their
610 * life in the future. In case they release proper drivers this block of
611 * code won't be called. */
612 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
614 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
617 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_MESA_copy_sub_buffer")) {
618 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
621 X11DRV_WineGL_LoadExtensions();
625 wine_dlclose(opengl_handle
, NULL
, 0);
626 opengl_handle
= NULL
;
630 static int describeContext( struct wgl_context
*ctx
) {
633 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
634 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
635 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
636 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
637 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
642 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, struct wgl_pbuffer
* pbuf
) {
647 int nvfloatattrib
= GLX_DONT_CARE
;
648 int pixelattrib
= GLX_DONT_CARE
;
650 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
651 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
652 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
653 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
655 switch (iWGLAttr
[cur
]) {
656 case WGL_AUX_BUFFERS_ARB
:
657 pop
= iWGLAttr
[++cur
];
658 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
659 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
661 case WGL_COLOR_BITS_ARB
:
662 pop
= iWGLAttr
[++cur
];
663 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
664 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
666 case WGL_BLUE_BITS_ARB
:
667 pop
= iWGLAttr
[++cur
];
668 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
669 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
671 case WGL_RED_BITS_ARB
:
672 pop
= iWGLAttr
[++cur
];
673 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
674 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
676 case WGL_GREEN_BITS_ARB
:
677 pop
= iWGLAttr
[++cur
];
678 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
679 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
681 case WGL_ALPHA_BITS_ARB
:
682 pop
= iWGLAttr
[++cur
];
683 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
684 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
686 case WGL_DEPTH_BITS_ARB
:
687 pop
= iWGLAttr
[++cur
];
688 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
689 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
691 case WGL_STENCIL_BITS_ARB
:
692 pop
= iWGLAttr
[++cur
];
693 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
694 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
696 case WGL_DOUBLE_BUFFER_ARB
:
697 pop
= iWGLAttr
[++cur
];
698 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
699 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
702 pop
= iWGLAttr
[++cur
];
703 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
704 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
707 case WGL_PIXEL_TYPE_ARB
:
708 pop
= iWGLAttr
[++cur
];
709 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
711 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
712 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
713 /* 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 */
714 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
715 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
717 ERR("unexpected PixelType(%x)\n", pop
);
722 case WGL_SUPPORT_GDI_ARB
:
723 /* This flag is set in a WineGLPixelFormat */
724 pop
= iWGLAttr
[++cur
];
725 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
728 case WGL_DRAW_TO_BITMAP_ARB
:
729 /* This flag is set in a WineGLPixelFormat */
730 pop
= iWGLAttr
[++cur
];
731 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
734 case WGL_DRAW_TO_WINDOW_ARB
:
735 pop
= iWGLAttr
[++cur
];
736 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
737 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
739 drawattrib
|= GLX_WINDOW_BIT
;
743 case WGL_DRAW_TO_PBUFFER_ARB
:
744 pop
= iWGLAttr
[++cur
];
745 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
746 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
748 drawattrib
|= GLX_PBUFFER_BIT
;
752 case WGL_ACCELERATION_ARB
:
753 /* This flag is set in a WineGLPixelFormat */
754 pop
= iWGLAttr
[++cur
];
755 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
758 case WGL_SUPPORT_OPENGL_ARB
:
759 pop
= iWGLAttr
[++cur
];
760 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
761 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
764 case WGL_SWAP_METHOD_ARB
:
765 pop
= iWGLAttr
[++cur
];
766 /* For now we ignore this and just return SWAP_EXCHANGE */
767 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
770 case WGL_PBUFFER_LARGEST_ARB
:
771 pop
= iWGLAttr
[++cur
];
772 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
773 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
776 case WGL_SAMPLE_BUFFERS_ARB
:
777 pop
= iWGLAttr
[++cur
];
778 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
779 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
782 case WGL_SAMPLES_ARB
:
783 pop
= iWGLAttr
[++cur
];
784 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
785 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
788 case WGL_TEXTURE_FORMAT_ARB
:
789 case WGL_TEXTURE_TARGET_ARB
:
790 case WGL_MIPMAP_TEXTURE_ARB
:
791 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
792 pop
= iWGLAttr
[++cur
];
794 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
796 if (!use_render_texture_emulation
) {
797 if (WGL_NO_TEXTURE_ARB
!= pop
) {
798 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
799 return -1; /** error: don't support it */
801 drawattrib
|= GLX_PBUFFER_BIT
;
805 case WGL_FLOAT_COMPONENTS_NV
:
806 nvfloatattrib
= iWGLAttr
[++cur
];
807 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
809 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
810 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
811 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
812 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
813 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
814 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
815 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
816 pop
= iWGLAttr
[++cur
];
817 /** cannot be converted, see direct handling on
818 * - wglGetPixelFormatAttribivARB
819 * TODO: wglChoosePixelFormat
822 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
823 pop
= iWGLAttr
[++cur
];
824 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
825 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
828 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
829 pop
= iWGLAttr
[++cur
];
830 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
831 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
834 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
840 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
841 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
842 * pixmap and pbuffer formats appear as well. */
843 if (!drawattrib
) drawattrib
= GLX_DONT_CARE
;
844 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
845 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
847 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
848 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
849 * GLX_DONT_CARE unless it is overridden. */
850 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
851 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
853 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
854 if (has_extension(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
855 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
856 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
862 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
864 int render_type
=0, render_type_bit
;
865 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
866 switch(render_type_bit
)
869 render_type
= GLX_RGBA_TYPE
;
871 case GLX_COLOR_INDEX_BIT
:
872 render_type
= GLX_COLOR_INDEX_TYPE
;
874 case GLX_RGBA_FLOAT_BIT
:
875 render_type
= GLX_RGBA_FLOAT_TYPE
;
877 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
878 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
881 ERR("Unknown render_type: %x\n", render_type_bit
);
886 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
887 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
890 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
891 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
893 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
894 * the GLX_PIXMAP_BIT set. */
895 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
898 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
900 static WineGLPixelFormat
*list
;
901 static int size
, onscreen_size
;
903 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
905 XVisualInfo
*visinfo
;
910 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
911 if (NULL
== cfgs
|| 0 == nCfgs
) {
912 if(cfgs
!= NULL
) XFree(cfgs
);
914 ERR("glXChooseFBConfig returns NULL\n");
918 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
919 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
920 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
921 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
923 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
925 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
927 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
930 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
932 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
934 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
935 * Do this as GLX doesn't guarantee that the list is sorted */
936 for(run
=0; run
< 2; run
++)
938 for(i
=0; i
<nCfgs
; i
++) {
939 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
940 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
942 /* The first run we only add onscreen formats (ones which have an associated X Visual).
943 * The second run we only set offscreen formats. */
946 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
947 * The contents is copied to the destination using XCopyArea. For the copying to work
948 * the depth of the source and destination window should be the same. In general this should
949 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
950 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
951 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
952 * list formats with the same depth. */
953 if(visinfo
->depth
!= screen_depth
)
959 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
960 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
961 list
[size
].fbconfig
= cfgs
[i
];
962 list
[size
].fmt_id
= fmt_id
;
963 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
964 list
[size
].offscreenOnly
= FALSE
;
965 list
[size
].dwFlags
= 0;
969 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
970 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
972 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
973 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
974 list
[size
].fbconfig
= cfgs
[i
];
975 list
[size
].fmt_id
= fmt_id
;
976 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
977 list
[size
].offscreenOnly
= FALSE
;
978 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
982 } else if(run
&& !visinfo
) {
983 int window_drawable
=0;
984 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
986 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
987 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
988 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
989 * likely make our child window opengl rendering more complicated since likely you can't use
990 * XCopyArea on a GLX Window.
991 * For now ignore fbconfigs which are window drawable but lack a visual. */
992 if(window_drawable
& GLX_WINDOW_BIT
)
994 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
998 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
999 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1000 list
[size
].fbconfig
= cfgs
[i
];
1001 list
[size
].fmt_id
= fmt_id
;
1002 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1003 list
[size
].offscreenOnly
= TRUE
;
1004 list
[size
].dwFlags
= 0;
1008 if (visinfo
) XFree(visinfo
);
1015 if (size_ret
) *size_ret
= size
;
1016 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
1017 wine_tsx11_unlock();
1021 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1022 * In our WGL implementation we only support a subset of these formats namely the format of
1023 * Wine's main visual and offscreen formats (if they are available).
1024 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1025 * and it returns the number of supported WGL formats in fmt_count.
1027 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
1029 WineGLPixelFormat
*list
, *res
= NULL
;
1030 int size
, onscreen_size
;
1032 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
1034 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1035 * iPixelFormat in case of probing the number of pixelformats.
1037 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
1038 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
1039 res
= &list
[iPixelFormat
-1];
1040 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res
->fmt_id
, iPixelFormat
);
1046 *fmt_count
= onscreen_size
;
1048 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1053 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1054 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1056 WineGLPixelFormat
*list
;
1059 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1061 for(i
=0; i
<size
; i
++) {
1062 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1063 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1064 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1065 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1069 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1073 static int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1075 WineGLPixelFormat
*fmt
;
1077 if (!fbconfig_id
) return 0;
1079 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1081 return fmt
->iPixelFormat
;
1082 /* This will happen on hwnds without a pixel format set; it's ok */
1087 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1088 void mark_drawable_dirty(Drawable old
, Drawable
new)
1090 struct wgl_context
*ctx
;
1091 LIST_FOR_EACH_ENTRY( ctx
, &context_list
, struct wgl_context
, entry
)
1093 if (old
== ctx
->drawables
[0]) {
1094 ctx
->drawables
[0] = new;
1095 ctx
->refresh_drawables
= TRUE
;
1097 if (old
== ctx
->drawables
[1]) {
1098 ctx
->drawables
[1] = new;
1099 ctx
->refresh_drawables
= TRUE
;
1104 /* Given the current context, make sure its drawable is sync'd */
1105 static inline void sync_context(struct wgl_context
*context
)
1107 if(context
&& context
->refresh_drawables
) {
1108 if (glxRequireVersion(3))
1109 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1110 context
->drawables
[1], context
->ctx
);
1112 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1113 context
->refresh_drawables
= FALSE
;
1118 static GLXContext
create_glxcontext(Display
*display
, struct wgl_context
*context
, GLXContext shareList
)
1122 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1123 BOOL indirect
= !(context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
);
1125 if(context
->gl3_context
)
1127 if(context
->numAttribs
)
1128 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1130 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1132 else if(context
->vis
)
1133 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1134 else /* Create a GLX Context for a pbuffer */
1135 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1141 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1143 return pglXCreateGLXPixmap(display
, vis
, parent
);
1148 * glxdrv_DescribePixelFormat
1150 * Get the pixel-format descriptor associated to the given id
1152 static int glxdrv_wglDescribePixelFormat( HDC hdc
, int iPixelFormat
,
1153 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1155 /*XVisualInfo *vis;*/
1158 WineGLPixelFormat
*fmt
;
1162 if (!has_opengl()) return 0;
1164 TRACE("(%p,%d,%d,%p)\n", hdc
, iPixelFormat
, nBytes
, ppfd
);
1166 /* 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 */
1167 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1169 /* The application is only querying the number of pixelformats */
1171 } else if(fmt
== NULL
) {
1172 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1176 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1177 ERR("Wrong structure size !\n");
1178 /* Should set error */
1184 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1185 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1188 /* These flags are always the same... */
1189 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1190 /* Now the flags extracted from the Visual */
1192 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1193 if(value
& GLX_WINDOW_BIT
)
1194 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1196 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1197 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1198 * 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
1199 * offered the GDI bit either. */
1200 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1202 /* PFD_GENERIC_FORMAT - gdi software rendering
1203 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1204 * none set - full hardware accelerated by a ICD
1206 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1207 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1209 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1211 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1212 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1214 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1217 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1218 if (value
& GLX_RGBA_BIT
)
1219 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1221 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1224 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1225 ppfd
->cColorBits
= value
;
1227 /* Red, green, blue and alpha bits / shifts */
1228 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1229 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1230 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1231 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1232 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1234 ppfd
->cRedBits
= rb
;
1235 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1236 ppfd
->cBlueBits
= bb
;
1237 ppfd
->cBlueShift
= ab
;
1238 ppfd
->cGreenBits
= gb
;
1239 ppfd
->cGreenShift
= bb
+ ab
;
1240 ppfd
->cAlphaBits
= ab
;
1241 ppfd
->cAlphaShift
= 0;
1244 ppfd
->cRedShift
= 0;
1245 ppfd
->cBlueBits
= 0;
1246 ppfd
->cBlueShift
= 0;
1247 ppfd
->cGreenBits
= 0;
1248 ppfd
->cGreenShift
= 0;
1249 ppfd
->cAlphaBits
= 0;
1250 ppfd
->cAlphaShift
= 0;
1253 /* Accum RGBA bits */
1254 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1255 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1256 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1257 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1259 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1260 ppfd
->cAccumRedBits
= rb
;
1261 ppfd
->cAccumGreenBits
= gb
;
1262 ppfd
->cAccumBlueBits
= bb
;
1263 ppfd
->cAccumAlphaBits
= ab
;
1266 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1267 ppfd
->cAuxBuffers
= value
;
1270 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1271 ppfd
->cDepthBits
= value
;
1274 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1275 ppfd
->cStencilBits
= value
;
1277 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1279 if (TRACE_ON(wgl
)) {
1280 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1286 /***********************************************************************
1287 * glxdrv_wglGetPixelFormat
1289 static int glxdrv_wglGetPixelFormat( HDC hdc
)
1291 struct x11drv_escape_get_drawable escape
;
1292 WineGLPixelFormat
*fmt
;
1295 TRACE( "(%p)\n", hdc
);
1297 escape
.code
= X11DRV_GET_DRAWABLE
;
1298 if (!ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
.code
), (LPCSTR
)&escape
.code
,
1299 sizeof(escape
), (LPSTR
)&escape
))
1302 if (!escape
.pixel_format
) return 0; /* not set yet */
1304 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, escape
.pixel_format
, TRUE
, &tmp
);
1307 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", escape
.pixel_format
);
1310 if (fmt
->offscreenOnly
)
1312 /* Offscreen formats can't be used with traditional WGL calls.
1313 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1314 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1317 TRACE("(%p): returns %d\n", hdc
, escape
.pixel_format
);
1318 return escape
.pixel_format
;
1321 /***********************************************************************
1322 * glxdrv_wglSetPixelFormat
1324 static BOOL
glxdrv_wglSetPixelFormat( HDC hdc
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1326 struct x11drv_escape_get_drawable escape
;
1327 WineGLPixelFormat
*fmt
;
1331 TRACE("(%p,%d,%p)\n", hdc
, iPixelFormat
, ppfd
);
1333 escape
.code
= X11DRV_GET_DRAWABLE
;
1334 if (!ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
.code
), (LPCSTR
)&escape
.code
,
1335 sizeof(escape
), (LPSTR
)&escape
))
1338 if (escape
.pixel_format
) /* cannot change it if already set */
1339 return (escape
.pixel_format
== iPixelFormat
);
1341 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1342 if (escape
.drawable
== root_window
)
1344 ERR("Invalid operation on root_window\n");
1348 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1349 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1351 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1355 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1357 hwnd
= WindowFromDC( hdc
);
1359 if(!(value
&GLX_WINDOW_BIT
)) {
1360 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1364 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, fmt
->fmt_id
, 0)) {
1365 ERR("Couldn't set format of the window, returning failure\n");
1368 /* physDev->current_pf will be set by the DCE update */
1370 else FIXME("called on a non-window object?\n");
1372 if (TRACE_ON(wgl
)) {
1375 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1377 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1379 TRACE(" FBConfig have :\n");
1380 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1381 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1382 TRACE(" - VISUAL_ID 0x%x\n", value
);
1383 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1384 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1390 /***********************************************************************
1391 * glxdrv_wglCopyContext
1393 static BOOL
glxdrv_wglCopyContext(struct wgl_context
*src
, struct wgl_context
*dst
, UINT mask
)
1395 TRACE("%p -> %p mask %#x\n", src
, dst
, mask
);
1397 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1399 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1403 /***********************************************************************
1404 * glxdrv_wglCreateContext
1406 static struct wgl_context
*glxdrv_wglCreateContext( HDC hdc
)
1408 struct x11drv_escape_get_drawable escape
;
1409 struct wgl_context
*ret
;
1410 WineGLPixelFormat
*fmt
;
1413 TRACE( "(%p)\n", hdc
);
1415 escape
.code
= X11DRV_GET_DRAWABLE
;
1416 if (!ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
.code
), (LPCSTR
)&escape
.code
,
1417 sizeof(escape
), (LPSTR
)&escape
))
1420 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, escape
.pixel_format
, TRUE
/* Offscreen */, &fmt_count
);
1421 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1422 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1423 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1424 * If this fails something is very wrong on the system. */
1426 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape
.pixel_format
);
1427 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1431 if (!(ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
)))) return 0;
1435 ret
->has_been_current
= FALSE
;
1436 ret
->sharing
= FALSE
;
1439 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1440 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1441 list_add_head( &context_list
, &ret
->entry
);
1442 wine_tsx11_unlock();
1444 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1448 /***********************************************************************
1449 * glxdrv_wglDeleteContext
1451 static void glxdrv_wglDeleteContext(struct wgl_context
*ctx
)
1453 TRACE("(%p)\n", ctx
);
1456 list_remove( &ctx
->entry
);
1457 if (ctx
->ctx
) pglXDestroyContext( gdi_display
, ctx
->ctx
);
1458 if (ctx
->vis
) XFree( ctx
->vis
);
1459 wine_tsx11_unlock();
1461 HeapFree( GetProcessHeap(), 0, ctx
);
1464 /***********************************************************************
1465 * glxdrv_wglGetProcAddress
1467 static PROC
glxdrv_wglGetProcAddress(LPCSTR lpszProc
)
1469 if (!strncmp(lpszProc
, "wgl", 3)) return NULL
;
1470 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1473 /***********************************************************************
1474 * glxdrv_wglMakeCurrent
1476 static BOOL
glxdrv_wglMakeCurrent(HDC hdc
, struct wgl_context
*ctx
)
1479 struct x11drv_escape_get_drawable escape
;
1481 TRACE("(%p,%p)\n", hdc
, ctx
);
1485 pglXMakeCurrent(gdi_display
, None
, NULL
);
1486 NtCurrentTeb()->glContext
= NULL
;
1490 escape
.code
= X11DRV_GET_DRAWABLE
;
1491 if (!ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
.code
), (LPCSTR
)&escape
.code
,
1492 sizeof(escape
), (LPSTR
)&escape
))
1495 if (!escape
.pixel_format
)
1497 WARN("Trying to use an invalid drawable\n");
1498 SetLastError(ERROR_INVALID_HANDLE
);
1501 if (ctx
->fmt
->iPixelFormat
!= escape
.pixel_format
)
1503 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1504 hdc
, escape
.pixel_format
, ctx
, ctx
->fmt
->iPixelFormat
);
1505 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1512 if (TRACE_ON(wgl
)) {
1514 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &vis_id
);
1515 describeContext(ctx
);
1516 TRACE("hdc %p drawable %lx fmt %u vis %x ctx %p\n", hdc
,
1517 escape
.gl_drawable
, escape
.pixel_format
, vis_id
, ctx
->ctx
);
1520 ret
= pglXMakeCurrent(gdi_display
, escape
.gl_drawable
, ctx
->ctx
);
1524 NtCurrentTeb()->glContext
= ctx
;
1526 ctx
->has_been_current
= TRUE
;
1528 ctx
->drawables
[0] = escape
.gl_drawable
;
1529 ctx
->drawables
[1] = escape
.gl_drawable
;
1530 ctx
->refresh_drawables
= FALSE
;
1533 SetLastError(ERROR_INVALID_HANDLE
);
1534 wine_tsx11_unlock();
1536 TRACE(" returning %s\n", (ret
? "True" : "False"));
1540 /***********************************************************************
1541 * X11DRV_wglMakeContextCurrentARB
1543 static BOOL
X11DRV_wglMakeContextCurrentARB( HDC draw_hdc
, HDC read_hdc
, struct wgl_context
*ctx
)
1545 struct x11drv_escape_get_drawable escape_draw
, escape_read
;
1548 TRACE("(%p,%p,%p)\n", draw_hdc
, read_hdc
, ctx
);
1552 pglXMakeCurrent(gdi_display
, None
, NULL
);
1553 NtCurrentTeb()->glContext
= NULL
;
1557 escape_draw
.code
= X11DRV_GET_DRAWABLE
;
1558 if (!ExtEscape( draw_hdc
, X11DRV_ESCAPE
, sizeof(escape_draw
.code
), (LPCSTR
)&escape_draw
.code
,
1559 sizeof(escape_draw
), (LPSTR
)&escape_draw
))
1562 escape_read
.code
= X11DRV_GET_DRAWABLE
;
1563 if (!ExtEscape( read_hdc
, X11DRV_ESCAPE
, sizeof(escape_read
.code
), (LPCSTR
)&escape_read
.code
,
1564 sizeof(escape_read
), (LPSTR
)&escape_read
))
1567 if (!escape_draw
.pixel_format
)
1569 WARN("Trying to use an invalid drawable\n");
1570 SetLastError(ERROR_INVALID_HANDLE
);
1575 if (!pglXMakeContextCurrent
) return FALSE
;
1578 ret
= pglXMakeContextCurrent(gdi_display
, escape_draw
.gl_drawable
, escape_read
.gl_drawable
, ctx
->ctx
);
1581 ctx
->has_been_current
= TRUE
;
1582 ctx
->hdc
= draw_hdc
;
1583 ctx
->drawables
[0] = escape_draw
.gl_drawable
;
1584 ctx
->drawables
[1] = escape_read
.gl_drawable
;
1585 ctx
->refresh_drawables
= FALSE
;
1586 NtCurrentTeb()->glContext
= ctx
;
1589 SetLastError(ERROR_INVALID_HANDLE
);
1590 wine_tsx11_unlock();
1593 TRACE(" returning %s\n", (ret
? "True" : "False"));
1597 /***********************************************************************
1598 * glxdrv_wglShareLists
1600 static BOOL
glxdrv_wglShareLists(struct wgl_context
*org
, struct wgl_context
*dest
)
1602 TRACE("(%p, %p)\n", org
, dest
);
1604 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1605 * at context creation time but in case of WGL it is done using wglShareLists.
1606 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1607 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1608 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1609 * so there delaying context creation doesn't work.
1611 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1612 * and when a program requests sharing we recreate the destination context if it hasn't been made
1613 * current or when it hasn't shared display lists before.
1616 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
1618 ERR("Could not share display lists, one of the contexts has been current already !\n");
1621 else if(dest
->sharing
)
1623 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1628 describeContext(org
);
1629 describeContext(dest
);
1631 /* Re-create the GLX context and share display lists */
1632 pglXDestroyContext(gdi_display
, dest
->ctx
);
1633 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1634 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1636 org
->sharing
= TRUE
;
1637 dest
->sharing
= TRUE
;
1643 static void flush_gl_drawable( struct glx_physdev
*physdev
)
1646 int w
= physdev
->x11dev
->dc_rect
.right
- physdev
->x11dev
->dc_rect
.left
;
1647 int h
= physdev
->x11dev
->dc_rect
.bottom
- physdev
->x11dev
->dc_rect
.top
;
1648 Drawable src
= physdev
->drawable
;
1650 if (w
<= 0 || h
<= 0) return;
1652 switch (physdev
->type
)
1654 case DC_GL_PIXMAP_WIN
:
1655 src
= physdev
->pixmap
;
1657 case DC_GL_CHILD_WIN
:
1658 /* The GL drawable may be lagged behind if we don't flush first, so
1659 * flush the display make sure we copy up-to-date data */
1660 XFlush(gdi_display
);
1661 XSetFunction(gdi_display
, physdev
->x11dev
->gc
, GXcopy
);
1662 XCopyArea(gdi_display
, src
, physdev
->x11dev
->drawable
, physdev
->x11dev
->gc
, 0, 0, w
, h
,
1663 physdev
->x11dev
->dc_rect
.left
, physdev
->x11dev
->dc_rect
.top
);
1664 SetRect( &rect
, 0, 0, w
, h
);
1665 add_device_bounds( physdev
->x11dev
, &rect
);
1672 static void wglFinish(void)
1674 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
1675 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
1680 wine_tsx11_unlock();
1681 ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1684 static void wglFlush(void)
1686 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
1687 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
1692 wine_tsx11_unlock();
1693 ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1696 /***********************************************************************
1697 * X11DRV_wglCreateContextAttribsARB
1699 static struct wgl_context
*X11DRV_wglCreateContextAttribsARB( HDC hdc
, struct wgl_context
*hShareContext
,
1700 const int* attribList
)
1702 struct x11drv_escape_get_drawable escape
;
1703 struct wgl_context
*ret
;
1704 WineGLPixelFormat
*fmt
;
1707 TRACE("(%p %p %p)\n", hdc
, hShareContext
, attribList
);
1709 escape
.code
= X11DRV_GET_DRAWABLE
;
1710 if (!ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
.code
), (LPCSTR
)&escape
.code
,
1711 sizeof(escape
), (LPSTR
)&escape
))
1714 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, escape
.pixel_format
, TRUE
/* Offscreen */, &fmt_count
);
1715 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
1716 * If this fails something is very wrong on the system. */
1719 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape
.pixel_format
);
1720 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1724 if (!(ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
)))) return 0;
1728 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1729 ret
->gl3_context
= TRUE
;
1731 ret
->numAttribs
= 0;
1734 int *pAttribList
= (int*)attribList
;
1735 int *pContextAttribList
= &ret
->attribList
[0];
1736 /* attribList consists of pairs {token, value] terminated with 0 */
1737 while(pAttribList
[0] != 0)
1739 TRACE("%#x %#x\n", pAttribList
[0], pAttribList
[1]);
1740 switch(pAttribList
[0])
1742 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
1743 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
1744 pContextAttribList
[1] = pAttribList
[1];
1746 case WGL_CONTEXT_MINOR_VERSION_ARB
:
1747 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
1748 pContextAttribList
[1] = pAttribList
[1];
1750 case WGL_CONTEXT_LAYER_PLANE_ARB
:
1752 case WGL_CONTEXT_FLAGS_ARB
:
1753 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
1754 pContextAttribList
[1] = pAttribList
[1];
1756 case WGL_CONTEXT_PROFILE_MASK_ARB
:
1757 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
1758 pContextAttribList
[1] = pAttribList
[1];
1761 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList
[0], pAttribList
[1]);
1766 pContextAttribList
+= 2;
1771 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
1772 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1774 XSync(gdi_display
, False
);
1775 if(X11DRV_check_error() || !ret
->ctx
)
1777 /* In the future we should convert the GLX error to a win32 one here if needed */
1778 ERR("Context creation failed\n");
1779 HeapFree( GetProcessHeap(), 0, ret
);
1780 wine_tsx11_unlock();
1784 list_add_head( &context_list
, &ret
->entry
);
1785 wine_tsx11_unlock();
1786 TRACE(" creating context %p\n", ret
);
1791 * X11DRV_wglGetExtensionsStringARB
1793 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1795 static const GLubyte
*X11DRV_wglGetExtensionsStringARB(HDC hdc
)
1797 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
1798 return (const GLubyte
*)WineGLInfo
.wglExtensions
;
1802 * X11DRV_wglCreatePbufferARB
1804 * WGL_ARB_pbuffer: wglCreatePbufferARB
1806 static struct wgl_pbuffer
*X11DRV_wglCreatePbufferARB( HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
,
1807 const int *piAttribList
)
1809 struct wgl_pbuffer
* object
= NULL
;
1810 WineGLPixelFormat
*fmt
= NULL
;
1815 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
1817 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1818 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
1820 ERR("(%p): invalid pixel format %d\n", hdc
, iPixelFormat
);
1821 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1825 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1826 if (NULL
== object
) {
1827 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1830 object
->width
= iWidth
;
1831 object
->height
= iHeight
;
1834 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
1835 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
1836 while (piAttribList
&& 0 != *piAttribList
) {
1838 switch (*piAttribList
) {
1839 case WGL_PBUFFER_LARGEST_ARB
: {
1841 attr_v
= *piAttribList
;
1842 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
1843 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
1847 case WGL_TEXTURE_FORMAT_ARB
: {
1849 attr_v
= *piAttribList
;
1850 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
1851 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
1852 object
->use_render_texture
= 0;
1854 if (!use_render_texture_emulation
) {
1855 SetLastError(ERROR_INVALID_DATA
);
1859 case WGL_TEXTURE_RGB_ARB
:
1860 object
->use_render_texture
= GL_RGB
;
1861 object
->texture_bpp
= 3;
1862 object
->texture_format
= GL_RGB
;
1863 object
->texture_type
= GL_UNSIGNED_BYTE
;
1865 case WGL_TEXTURE_RGBA_ARB
:
1866 object
->use_render_texture
= GL_RGBA
;
1867 object
->texture_bpp
= 4;
1868 object
->texture_format
= GL_RGBA
;
1869 object
->texture_type
= GL_UNSIGNED_BYTE
;
1872 /* WGL_FLOAT_COMPONENTS_NV */
1873 case WGL_TEXTURE_FLOAT_R_NV
:
1874 object
->use_render_texture
= GL_FLOAT_R_NV
;
1875 object
->texture_bpp
= 4;
1876 object
->texture_format
= GL_RED
;
1877 object
->texture_type
= GL_FLOAT
;
1879 case WGL_TEXTURE_FLOAT_RG_NV
:
1880 object
->use_render_texture
= GL_FLOAT_RG_NV
;
1881 object
->texture_bpp
= 8;
1882 object
->texture_format
= GL_LUMINANCE_ALPHA
;
1883 object
->texture_type
= GL_FLOAT
;
1885 case WGL_TEXTURE_FLOAT_RGB_NV
:
1886 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
1887 object
->texture_bpp
= 12;
1888 object
->texture_format
= GL_RGB
;
1889 object
->texture_type
= GL_FLOAT
;
1891 case WGL_TEXTURE_FLOAT_RGBA_NV
:
1892 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
1893 object
->texture_bpp
= 16;
1894 object
->texture_format
= GL_RGBA
;
1895 object
->texture_type
= GL_FLOAT
;
1898 ERR("Unknown texture format: %x\n", attr_v
);
1899 SetLastError(ERROR_INVALID_DATA
);
1906 case WGL_TEXTURE_TARGET_ARB
: {
1908 attr_v
= *piAttribList
;
1909 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
1910 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
1911 object
->texture_target
= 0;
1913 if (!use_render_texture_emulation
) {
1914 SetLastError(ERROR_INVALID_DATA
);
1918 case WGL_TEXTURE_CUBE_MAP_ARB
: {
1919 if (iWidth
!= iHeight
) {
1920 SetLastError(ERROR_INVALID_DATA
);
1923 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
1924 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
1927 case WGL_TEXTURE_1D_ARB
: {
1929 SetLastError(ERROR_INVALID_DATA
);
1932 object
->texture_target
= GL_TEXTURE_1D
;
1933 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
1936 case WGL_TEXTURE_2D_ARB
: {
1937 object
->texture_target
= GL_TEXTURE_2D
;
1938 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
1941 case WGL_TEXTURE_RECTANGLE_NV
: {
1942 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
1943 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
1947 ERR("Unknown texture target: %x\n", attr_v
);
1948 SetLastError(ERROR_INVALID_DATA
);
1955 case WGL_MIPMAP_TEXTURE_ARB
: {
1957 attr_v
= *piAttribList
;
1958 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
1959 if (!use_render_texture_emulation
) {
1960 SetLastError(ERROR_INVALID_DATA
);
1969 PUSH1(attribs
, None
);
1970 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
1971 TRACE("new Pbuffer drawable as %lx\n", object
->drawable
);
1972 if (!object
->drawable
) {
1973 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1974 goto create_failed
; /* unexpected error */
1976 TRACE("->(%p)\n", object
);
1980 HeapFree(GetProcessHeap(), 0, object
);
1981 TRACE("->(FAILED)\n");
1986 * X11DRV_wglDestroyPbufferARB
1988 * WGL_ARB_pbuffer: wglDestroyPbufferARB
1990 static BOOL
X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer
*object
)
1992 TRACE("(%p)\n", object
);
1994 pglXDestroyPbuffer(gdi_display
, object
->drawable
);
1995 HeapFree(GetProcessHeap(), 0, object
);
2000 * X11DRV_wglGetPbufferDCARB
2002 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2004 static HDC
X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer
*object
)
2006 struct x11drv_escape_set_drawable escape
;
2009 hdc
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
);
2012 escape
.code
= X11DRV_SET_DRAWABLE
;
2013 escape
.drawable
= object
->drawable
;
2014 escape
.mode
= IncludeInferiors
;
2015 SetRect( &escape
.dc_rect
, 0, 0, object
->width
, object
->height
);
2016 escape
.fbconfig_id
= object
->fmt
->fmt_id
;
2017 escape
.gl_drawable
= object
->drawable
;
2019 escape
.gl_type
= DC_GL_PBUFFER
;
2020 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2022 TRACE( "(%p)->(%p)\n", object
, hdc
);
2027 * X11DRV_wglQueryPbufferARB
2029 * WGL_ARB_pbuffer: wglQueryPbufferARB
2031 static BOOL
X11DRV_wglQueryPbufferARB( struct wgl_pbuffer
*object
, int iAttribute
, int *piValue
)
2033 TRACE("(%p, 0x%x, %p)\n", object
, iAttribute
, piValue
);
2035 switch (iAttribute
) {
2036 case WGL_PBUFFER_WIDTH_ARB
:
2037 pglXQueryDrawable(gdi_display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2039 case WGL_PBUFFER_HEIGHT_ARB
:
2040 pglXQueryDrawable(gdi_display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2043 case WGL_PBUFFER_LOST_ARB
:
2044 /* GLX Pbuffers cannot be lost by default. We can support this by
2045 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2046 * to receive pixel buffer clobber events, however that may or may
2047 * not give any benefit */
2048 *piValue
= GL_FALSE
;
2051 case WGL_TEXTURE_FORMAT_ARB
:
2052 if (!object
->use_render_texture
) {
2053 *piValue
= WGL_NO_TEXTURE_ARB
;
2055 if (!use_render_texture_emulation
) {
2056 SetLastError(ERROR_INVALID_HANDLE
);
2059 switch(object
->use_render_texture
) {
2061 *piValue
= WGL_TEXTURE_RGB_ARB
;
2064 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2066 /* WGL_FLOAT_COMPONENTS_NV */
2068 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2070 case GL_FLOAT_RG_NV
:
2071 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2073 case GL_FLOAT_RGB_NV
:
2074 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2076 case GL_FLOAT_RGBA_NV
:
2077 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2080 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2085 case WGL_TEXTURE_TARGET_ARB
:
2086 if (!object
->texture_target
){
2087 *piValue
= WGL_NO_TEXTURE_ARB
;
2089 if (!use_render_texture_emulation
) {
2090 SetLastError(ERROR_INVALID_DATA
);
2093 switch (object
->texture_target
) {
2094 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2095 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2096 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2097 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2102 case WGL_MIPMAP_TEXTURE_ARB
:
2103 *piValue
= GL_FALSE
; /** don't support that */
2104 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2108 FIXME("unexpected attribute %x\n", iAttribute
);
2116 * X11DRV_wglReleasePbufferDCARB
2118 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2120 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer
*object
, HDC hdc
)
2122 TRACE("(%p, %p)\n", object
, hdc
);
2123 return DeleteDC(hdc
);
2127 * X11DRV_wglSetPbufferAttribARB
2129 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2131 static BOOL
X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer
*object
, const int *piAttribList
)
2133 GLboolean ret
= GL_FALSE
;
2135 WARN("(%p, %p): alpha-testing, report any problem\n", object
, piAttribList
);
2137 if (!object
->use_render_texture
) {
2138 SetLastError(ERROR_INVALID_HANDLE
);
2141 if (1 == use_render_texture_emulation
) {
2148 * X11DRV_wglChoosePixelFormatARB
2150 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2152 static BOOL
X11DRV_wglChoosePixelFormatARB( HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
,
2153 UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2158 GLXFBConfig
* cfgs
= NULL
;
2162 WineGLPixelFormat
*fmt
;
2168 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2169 if (NULL
!= pfAttribFList
) {
2170 FIXME("unused pfAttribFList\n");
2173 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2174 if (-1 == nAttribs
) {
2175 WARN("Cannot convert WGL to GLX attributes\n");
2178 PUSH1(attribs
, None
);
2180 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2181 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2182 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2183 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2185 switch(piAttribIList
[i
])
2187 case WGL_DRAW_TO_BITMAP_ARB
:
2188 if(piAttribIList
[i
+1])
2189 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2191 case WGL_ACCELERATION_ARB
:
2192 switch(piAttribIList
[i
+1])
2194 case WGL_NO_ACCELERATION_ARB
:
2195 dwFlags
|= PFD_GENERIC_FORMAT
;
2197 case WGL_GENERIC_ACCELERATION_ARB
:
2198 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2200 case WGL_FULL_ACCELERATION_ARB
:
2205 case WGL_SUPPORT_GDI_ARB
:
2206 if(piAttribIList
[i
+1])
2207 dwFlags
|= PFD_SUPPORT_GDI
;
2212 /* Search for FB configurations matching the requirements in attribs */
2214 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2216 wine_tsx11_unlock();
2217 WARN("Compatible Pixel Format not found\n");
2221 /* Loop through all matching formats and check if they are suitable.
2222 * Note that this function should at max return nMaxFormats different formats */
2223 for(run
=0; run
< 2; run
++)
2225 for (it
= 0; it
< nCfgs
&& pfmt_it
< nMaxFormats
; ++it
)
2227 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2229 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2233 /* Search for the format in our list of compatible formats */
2234 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2238 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2239 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2242 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2243 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2248 *nNumFormats
= pfmt_it
;
2251 wine_tsx11_unlock();
2256 * X11DRV_wglGetPixelFormatAttribivARB
2258 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2260 static BOOL
X11DRV_wglGetPixelFormatAttribivARB( HDC hdc
, int iPixelFormat
, int iLayerPlane
,
2261 UINT nAttributes
, const int *piAttributes
, int *piValues
)
2264 WineGLPixelFormat
*fmt
= NULL
;
2268 int nWGLFormats
= 0;
2270 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2272 if (0 < iLayerPlane
) {
2273 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2277 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2278 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2279 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2280 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2282 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2285 for (i
= 0; i
< nAttributes
; ++i
) {
2286 const int curWGLAttr
= piAttributes
[i
];
2287 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2289 switch (curWGLAttr
) {
2290 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2291 piValues
[i
] = nWGLFormats
;
2294 case WGL_SUPPORT_OPENGL_ARB
:
2295 piValues
[i
] = GL_TRUE
;
2298 case WGL_ACCELERATION_ARB
:
2299 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2300 if (!fmt
) goto pix_error
;
2301 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2302 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2303 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2304 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2306 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2309 case WGL_TRANSPARENT_ARB
:
2310 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2311 if (!fmt
) goto pix_error
;
2312 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2313 if (hTest
) goto get_error
;
2314 piValues
[i
] = GL_FALSE
;
2315 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2318 case WGL_PIXEL_TYPE_ARB
:
2319 curGLXAttr
= GLX_RENDER_TYPE
;
2320 if (!fmt
) goto pix_error
;
2321 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2322 if (hTest
) goto get_error
;
2323 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2324 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2325 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2326 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2327 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2328 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2330 ERR("unexpected RenderType(%x)\n", tmp
);
2331 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2335 case WGL_COLOR_BITS_ARB
:
2336 curGLXAttr
= GLX_BUFFER_SIZE
;
2339 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2340 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2341 if (!use_render_texture_emulation
) {
2342 piValues
[i
] = GL_FALSE
;
2345 curGLXAttr
= GLX_RENDER_TYPE
;
2346 if (!fmt
) goto pix_error
;
2347 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2348 if (hTest
) goto get_error
;
2349 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2350 piValues
[i
] = GL_FALSE
;
2353 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2354 if (hTest
) goto get_error
;
2355 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2358 case WGL_BLUE_BITS_ARB
:
2359 curGLXAttr
= GLX_BLUE_SIZE
;
2361 case WGL_RED_BITS_ARB
:
2362 curGLXAttr
= GLX_RED_SIZE
;
2364 case WGL_GREEN_BITS_ARB
:
2365 curGLXAttr
= GLX_GREEN_SIZE
;
2367 case WGL_ALPHA_BITS_ARB
:
2368 curGLXAttr
= GLX_ALPHA_SIZE
;
2370 case WGL_DEPTH_BITS_ARB
:
2371 curGLXAttr
= GLX_DEPTH_SIZE
;
2373 case WGL_STENCIL_BITS_ARB
:
2374 curGLXAttr
= GLX_STENCIL_SIZE
;
2376 case WGL_DOUBLE_BUFFER_ARB
:
2377 curGLXAttr
= GLX_DOUBLEBUFFER
;
2379 case WGL_STEREO_ARB
:
2380 curGLXAttr
= GLX_STEREO
;
2382 case WGL_AUX_BUFFERS_ARB
:
2383 curGLXAttr
= GLX_AUX_BUFFERS
;
2386 case WGL_SUPPORT_GDI_ARB
:
2387 if (!fmt
) goto pix_error
;
2388 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) != 0;
2391 case WGL_DRAW_TO_BITMAP_ARB
:
2392 if (!fmt
) goto pix_error
;
2393 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) != 0;
2396 case WGL_DRAW_TO_WINDOW_ARB
:
2397 case WGL_DRAW_TO_PBUFFER_ARB
:
2398 if (!fmt
) goto pix_error
;
2399 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2400 if (hTest
) goto get_error
;
2401 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2402 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2403 piValues
[i
] = GL_TRUE
;
2405 piValues
[i
] = GL_FALSE
;
2408 case WGL_SWAP_METHOD_ARB
:
2409 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2410 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2411 * point only ATI offers this.
2413 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2416 case WGL_PBUFFER_LARGEST_ARB
:
2417 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2420 case WGL_SAMPLE_BUFFERS_ARB
:
2421 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2424 case WGL_SAMPLES_ARB
:
2425 curGLXAttr
= GLX_SAMPLES_ARB
;
2428 case WGL_FLOAT_COMPONENTS_NV
:
2429 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2432 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
2433 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
2436 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
2437 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
2440 case WGL_ACCUM_RED_BITS_ARB
:
2441 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2443 case WGL_ACCUM_GREEN_BITS_ARB
:
2444 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2446 case WGL_ACCUM_BLUE_BITS_ARB
:
2447 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2449 case WGL_ACCUM_ALPHA_BITS_ARB
:
2450 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2452 case WGL_ACCUM_BITS_ARB
:
2453 if (!fmt
) goto pix_error
;
2454 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2455 if (hTest
) goto get_error
;
2457 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2458 if (hTest
) goto get_error
;
2460 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2461 if (hTest
) goto get_error
;
2463 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2464 if (hTest
) goto get_error
;
2469 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2472 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2473 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2474 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2476 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2477 * and check which options can work using iPixelFormat=0 and which not.
2478 * A problem would be that this function is an extension. This would
2479 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2481 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2482 if (!fmt
) goto pix_error
;
2483 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2484 if (hTest
) goto get_error
;
2487 piValues
[i
] = GL_FALSE
;
2493 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2497 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2502 * X11DRV_wglGetPixelFormatAttribfvARB
2504 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2506 static BOOL
X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc
, int iPixelFormat
, int iLayerPlane
,
2507 UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2513 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2515 /* Allocate a temporary array to store integer values */
2516 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2518 ERR("couldn't allocate %d array\n", nAttributes
);
2522 /* Piggy-back on wglGetPixelFormatAttribivARB */
2523 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2525 /* Convert integer values to float. Should also check for attributes
2526 that can give decimal values here */
2527 for (i
=0; i
<nAttributes
;i
++) {
2528 pfValues
[i
] = attr
[i
];
2532 HeapFree(GetProcessHeap(), 0, attr
);
2537 * X11DRV_wglBindTexImageARB
2539 * WGL_ARB_render_texture: wglBindTexImageARB
2541 static BOOL
X11DRV_wglBindTexImageARB( struct wgl_pbuffer
*object
, int iBuffer
)
2543 GLboolean ret
= GL_FALSE
;
2545 TRACE("(%p, %d)\n", object
, iBuffer
);
2547 if (!object
->use_render_texture
) {
2548 SetLastError(ERROR_INVALID_HANDLE
);
2552 if (1 == use_render_texture_emulation
) {
2553 static int init
= 0;
2554 int prev_binded_texture
= 0;
2555 GLXContext prev_context
;
2556 Drawable prev_drawable
;
2557 GLXContext tmp_context
;
2559 prev_context
= pglXGetCurrentContext();
2560 prev_drawable
= pglXGetCurrentDrawable();
2562 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2563 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2564 isn't ideal performance wise but I wasn't able to get other ways working.
2567 init
= 1; /* Only show the FIXME once for performance reasons */
2568 FIXME("partial stub!\n");
2571 TRACE("drawable=%lx, context=%p\n", object
->drawable
, prev_context
);
2572 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2574 opengl_funcs
.gl
.p_glGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2576 /* Switch to our pbuffer */
2577 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2579 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2580 * After that upload the pbuffer texture data. */
2581 opengl_funcs
.gl
.p_glBindTexture(object
->texture_target
, prev_binded_texture
);
2582 opengl_funcs
.gl
.p_glCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2584 /* Switch back to the original drawable and upload the pbuffer-texture */
2585 pglXMakeCurrent(gdi_display
, prev_drawable
, prev_context
);
2586 pglXDestroyContext(gdi_display
, tmp_context
);
2594 * X11DRV_wglReleaseTexImageARB
2596 * WGL_ARB_render_texture: wglReleaseTexImageARB
2598 static BOOL
X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer
*object
, int iBuffer
)
2600 GLboolean ret
= GL_FALSE
;
2602 TRACE("(%p, %d)\n", object
, iBuffer
);
2604 if (!object
->use_render_texture
) {
2605 SetLastError(ERROR_INVALID_HANDLE
);
2608 if (1 == use_render_texture_emulation
) {
2615 * X11DRV_wglGetExtensionsStringEXT
2617 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2619 static const GLubyte
*X11DRV_wglGetExtensionsStringEXT(void)
2621 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2622 return (const GLubyte
*)WineGLInfo
.wglExtensions
;
2626 * X11DRV_wglGetSwapIntervalEXT
2628 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2630 static int X11DRV_wglGetSwapIntervalEXT(void)
2632 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2633 * interval, so the swap interval has to be tracked. */
2635 return swap_interval
;
2639 * X11DRV_wglSwapIntervalEXT
2641 * WGL_EXT_swap_control: wglSwapIntervalEXT
2643 static BOOL
X11DRV_wglSwapIntervalEXT(int interval
)
2647 TRACE("(%d)\n", interval
);
2651 SetLastError(ERROR_INVALID_DATA
);
2654 else if (!has_swap_control
&& interval
== 0)
2656 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2657 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2658 * value to be an error. Just silently ignore the request for now. */
2659 WARN("Request to disable vertical sync is not handled\n");
2664 if (pglXSwapIntervalSGI
)
2665 ret
= !pglXSwapIntervalSGI(interval
);
2667 WARN("GLX_SGI_swap_control extension is not available\n");
2670 swap_interval
= interval
;
2672 SetLastError(ERROR_DC_NOT_FOUND
);
2679 * X11DRV_wglSetPixelFormatWINE
2681 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2682 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2684 static BOOL
X11DRV_wglSetPixelFormatWINE(HDC hdc
, int format
)
2686 WineGLPixelFormat
*fmt
;
2690 TRACE("(%p,%d)\n", hdc
, format
);
2692 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, format
, FALSE
/* Offscreen */, &value
);
2695 ERR( "Invalid format %d\n", format
);
2699 hwnd
= WindowFromDC( hdc
);
2700 if (!hwnd
|| hwnd
== GetDesktopWindow())
2702 ERR( "not a valid window DC %p\n", hdc
);
2706 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
2707 if (!(value
& GLX_WINDOW_BIT
))
2709 WARN( "Pixel format %d is not compatible for window rendering\n", format
);
2713 return SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, fmt
->fmt_id
, 0);
2714 /* DC pixel format will be set by the DCE update */
2718 * glxRequireVersion (internal)
2720 * Check if the supported GLX version matches requiredVersion.
2722 static BOOL
glxRequireVersion(int requiredVersion
)
2724 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2725 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
2731 static void register_extension(const char *ext
)
2733 if (WineGLInfo
.wglExtensions
[0])
2734 strcat(WineGLInfo
.wglExtensions
, " ");
2735 strcat(WineGLInfo
.wglExtensions
, ext
);
2737 TRACE("'%s'\n", ext
);
2741 * X11DRV_WineGL_LoadExtensions
2743 static void X11DRV_WineGL_LoadExtensions(void)
2745 WineGLInfo
.wglExtensions
[0] = 0;
2747 /* ARB Extensions */
2749 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_create_context"))
2751 register_extension( "WGL_ARB_create_context" );
2752 opengl_funcs
.ext
.p_wglCreateContextAttribsARB
= X11DRV_wglCreateContextAttribsARB
;
2754 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_create_context_profile"))
2755 register_extension("WGL_ARB_create_context_profile");
2758 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_fbconfig_float"))
2760 register_extension("WGL_ARB_pixel_format_float");
2761 register_extension("WGL_ATI_pixel_format_float");
2764 register_extension( "WGL_ARB_extensions_string" );
2765 opengl_funcs
.ext
.p_wglGetExtensionsStringARB
= X11DRV_wglGetExtensionsStringARB
;
2767 if (glxRequireVersion(3))
2769 register_extension( "WGL_ARB_make_current_read" );
2770 opengl_funcs
.ext
.p_wglGetCurrentReadDCARB
= (void *)1; /* never called */
2771 opengl_funcs
.ext
.p_wglMakeContextCurrentARB
= X11DRV_wglMakeContextCurrentARB
;
2774 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
2776 /* In general pbuffer functionality requires support in the X-server. The functionality is
2777 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
2779 if ( glxRequireVersion(3) && has_extension( WineGLInfo
.glxExtensions
, "GLX_SGIX_pbuffer") )
2781 register_extension( "WGL_ARB_pbuffer" );
2782 opengl_funcs
.ext
.p_wglCreatePbufferARB
= X11DRV_wglCreatePbufferARB
;
2783 opengl_funcs
.ext
.p_wglDestroyPbufferARB
= X11DRV_wglDestroyPbufferARB
;
2784 opengl_funcs
.ext
.p_wglGetPbufferDCARB
= X11DRV_wglGetPbufferDCARB
;
2785 opengl_funcs
.ext
.p_wglQueryPbufferARB
= X11DRV_wglQueryPbufferARB
;
2786 opengl_funcs
.ext
.p_wglReleasePbufferDCARB
= X11DRV_wglReleasePbufferDCARB
;
2787 opengl_funcs
.ext
.p_wglSetPbufferAttribARB
= X11DRV_wglSetPbufferAttribARB
;
2790 register_extension( "WGL_ARB_pixel_format" );
2791 opengl_funcs
.ext
.p_wglChoosePixelFormatARB
= X11DRV_wglChoosePixelFormatARB
;
2792 opengl_funcs
.ext
.p_wglGetPixelFormatAttribfvARB
= X11DRV_wglGetPixelFormatAttribfvARB
;
2793 opengl_funcs
.ext
.p_wglGetPixelFormatAttribivARB
= X11DRV_wglGetPixelFormatAttribivARB
;
2795 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
2796 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_render_texture") ||
2797 (glxRequireVersion(3) && has_extension( WineGLInfo
.glxExtensions
, "GLX_SGIX_pbuffer") && use_render_texture_emulation
))
2799 register_extension( "WGL_ARB_render_texture" );
2800 opengl_funcs
.ext
.p_wglBindTexImageARB
= X11DRV_wglBindTexImageARB
;
2801 opengl_funcs
.ext
.p_wglReleaseTexImageARB
= X11DRV_wglReleaseTexImageARB
;
2803 /* The WGL version of GLX_NV_float_buffer requires render_texture */
2804 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer"))
2805 register_extension("WGL_NV_float_buffer");
2807 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
2808 if (has_extension(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle"))
2809 register_extension("WGL_NV_texture_rectangle");
2812 /* EXT Extensions */
2814 register_extension( "WGL_EXT_extensions_string" );
2815 opengl_funcs
.ext
.p_wglGetExtensionsStringEXT
= X11DRV_wglGetExtensionsStringEXT
;
2817 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
2818 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
2819 register_extension( "WGL_EXT_swap_control" );
2820 opengl_funcs
.ext
.p_wglSwapIntervalEXT
= X11DRV_wglSwapIntervalEXT
;
2821 opengl_funcs
.ext
.p_wglGetSwapIntervalEXT
= X11DRV_wglGetSwapIntervalEXT
;
2823 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_framebuffer_sRGB"))
2824 register_extension("WGL_EXT_framebuffer_sRGB");
2826 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_fbconfig_packed_float"))
2827 register_extension("WGL_EXT_pixel_format_packed_float");
2829 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_swap_control"))
2830 has_swap_control
= TRUE
;
2832 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2833 if (has_extension(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range"))
2835 register_extension( "WGL_NV_vertex_array_range" );
2836 opengl_funcs
.ext
.p_wglAllocateMemoryNV
= pglXAllocateMemoryNV
;
2837 opengl_funcs
.ext
.p_wglFreeMemoryNV
= pglXFreeMemoryNV
;
2840 /* WINE-specific WGL Extensions */
2842 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
2843 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
2845 register_extension( "WGL_WINE_pixel_format_passthrough" );
2846 opengl_funcs
.ext
.p_wglSetPixelFormatWINE
= X11DRV_wglSetPixelFormatWINE
;
2850 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
2852 pglXDestroyGLXPixmap(display
, glxpixmap
);
2857 * glxdrv_SwapBuffers
2859 * Swap the buffers of this DC
2861 static BOOL
glxdrv_SwapBuffers(PHYSDEV dev
)
2863 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
2864 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
2866 TRACE("(%p)\n", dev
->hdc
);
2870 WARN("Using a NULL context, skipping\n");
2871 SetLastError(ERROR_INVALID_HANDLE
);
2875 if (!physdev
->drawable
)
2877 WARN("Using an invalid drawable, skipping\n");
2878 SetLastError(ERROR_INVALID_HANDLE
);
2884 switch (physdev
->type
)
2886 case DC_GL_PIXMAP_WIN
:
2887 if(pglXCopySubBufferMESA
) {
2888 int w
= physdev
->x11dev
->dc_rect
.right
- physdev
->x11dev
->dc_rect
.left
;
2889 int h
= physdev
->x11dev
->dc_rect
.bottom
- physdev
->x11dev
->dc_rect
.top
;
2891 /* (glX)SwapBuffers has an implicit glFlush effect, however
2892 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
2896 pglXCopySubBufferMESA(gdi_display
, physdev
->drawable
, 0, 0, w
, h
);
2901 pglXSwapBuffers(gdi_display
, physdev
->drawable
);
2905 flush_gl_drawable( physdev
);
2906 wine_tsx11_unlock();
2911 static long prev_time
, start_time
;
2912 static unsigned long frames
, frames_total
;
2914 DWORD time
= GetTickCount();
2917 /* every 1.5 seconds */
2918 if (time
- prev_time
> 1500) {
2919 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
2920 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
2923 if(start_time
== 0) start_time
= time
;
2930 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
2932 WineGLPixelFormat
*fmt
;
2934 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
2938 return pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
2941 static BOOL
create_glx_dc( PHYSDEV
*pdev
)
2943 /* assume that only the main x11 device implements GetDeviceCaps */
2944 X11DRV_PDEVICE
*x11dev
= get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev
, pGetDeviceCaps
));
2945 struct glx_physdev
*physdev
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*physdev
) );
2947 if (!physdev
) return FALSE
;
2948 physdev
->x11dev
= x11dev
;
2949 push_dc_driver( pdev
, &physdev
->dev
, &glxdrv_funcs
);
2953 /**********************************************************************
2956 static BOOL
glxdrv_CreateDC( PHYSDEV
*pdev
, LPCWSTR driver
, LPCWSTR device
,
2957 LPCWSTR output
, const DEVMODEW
* initData
)
2959 return create_glx_dc( pdev
);
2962 /**********************************************************************
2963 * glxdrv_CreateCompatibleDC
2965 static BOOL
glxdrv_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
)
2967 if (orig
) /* chain to next driver first */
2969 orig
= GET_NEXT_PHYSDEV( orig
, pCreateCompatibleDC
);
2970 if (!orig
->funcs
->pCreateCompatibleDC( orig
, pdev
)) return FALSE
;
2972 /* otherwise we have been called by x11drv */
2973 return create_glx_dc( pdev
);
2976 /**********************************************************************
2979 static BOOL
glxdrv_DeleteDC( PHYSDEV dev
)
2981 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
2982 HeapFree( GetProcessHeap(), 0, physdev
);
2986 /**********************************************************************
2989 static INT
glxdrv_ExtEscape( PHYSDEV dev
, INT escape
, INT in_count
, LPCVOID in_data
,
2990 INT out_count
, LPVOID out_data
)
2992 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
2994 dev
= GET_NEXT_PHYSDEV( dev
, pExtEscape
);
2996 if (escape
== X11DRV_ESCAPE
&& in_data
&& in_count
>= sizeof(enum x11drv_escape_codes
))
2998 switch (*(const enum x11drv_escape_codes
*)in_data
)
3000 case X11DRV_SET_DRAWABLE
:
3001 if (in_count
>= sizeof(struct x11drv_escape_set_drawable
))
3003 const struct x11drv_escape_set_drawable
*data
= in_data
;
3004 physdev
->pixel_format
= pixelformat_from_fbconfig_id( data
->fbconfig_id
);
3005 physdev
->type
= data
->gl_type
;
3006 physdev
->drawable
= data
->gl_drawable
;
3007 physdev
->pixmap
= data
->pixmap
;
3008 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %u type %u\n",
3009 dev
->hdc
, physdev
->drawable
, physdev
->pixel_format
, physdev
->type
);
3012 case X11DRV_GET_DRAWABLE
:
3013 if (out_count
>= sizeof(struct x11drv_escape_get_drawable
))
3015 struct x11drv_escape_get_drawable
*data
= out_data
;
3016 data
->pixel_format
= physdev
->pixel_format
;
3017 data
->gl_type
= physdev
->type
;
3018 data
->gl_drawable
= physdev
->drawable
;
3019 data
->pixmap
= physdev
->pixmap
;
3022 case X11DRV_FLUSH_GL_DRAWABLE
:
3023 flush_gl_drawable( physdev
);
3029 return dev
->funcs
->pExtEscape( dev
, escape
, in_count
, in_data
, out_count
, out_data
);
3032 /**********************************************************************
3033 * glxdrv_wine_get_wgl_driver
3035 static struct opengl_funcs
* glxdrv_wine_get_wgl_driver( PHYSDEV dev
, UINT version
)
3037 if (version
!= WINE_WGL_DRIVER_VERSION
)
3039 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version
, WINE_WGL_DRIVER_VERSION
);
3043 if (has_opengl()) return &opengl_funcs
;
3045 dev
= GET_NEXT_PHYSDEV( dev
, wine_get_wgl_driver
);
3046 return dev
->funcs
->wine_get_wgl_driver( dev
, version
);
3049 static const struct gdi_dc_funcs glxdrv_funcs
=
3051 NULL
, /* pAbortDoc */
3052 NULL
, /* pAbortPath */
3053 NULL
, /* pAlphaBlend */
3054 NULL
, /* pAngleArc */
3057 NULL
, /* pBeginPath */
3058 NULL
, /* pBlendImage */
3060 NULL
, /* pCloseFigure */
3061 glxdrv_CreateCompatibleDC
, /* pCreateCompatibleDC */
3062 glxdrv_CreateDC
, /* pCreateDC */
3063 glxdrv_DeleteDC
, /* pDeleteDC */
3064 NULL
, /* pDeleteObject */
3065 NULL
, /* pDeviceCapabilities */
3066 NULL
, /* pEllipse */
3068 NULL
, /* pEndPage */
3069 NULL
, /* pEndPath */
3070 NULL
, /* pEnumFonts */
3071 NULL
, /* pEnumICMProfiles */
3072 NULL
, /* pExcludeClipRect */
3073 NULL
, /* pExtDeviceMode */
3074 glxdrv_ExtEscape
, /* pExtEscape */
3075 NULL
, /* pExtFloodFill */
3076 NULL
, /* pExtSelectClipRgn */
3077 NULL
, /* pExtTextOut */
3078 NULL
, /* pFillPath */
3079 NULL
, /* pFillRgn */
3080 NULL
, /* pFlattenPath */
3081 NULL
, /* pFontIsLinked */
3082 NULL
, /* pFrameRgn */
3083 NULL
, /* pGdiComment */
3084 NULL
, /* pGdiRealizationInfo */
3085 NULL
, /* pGetBoundsRect */
3086 NULL
, /* pGetCharABCWidths */
3087 NULL
, /* pGetCharABCWidthsI */
3088 NULL
, /* pGetCharWidth */
3089 NULL
, /* pGetDeviceCaps */
3090 NULL
, /* pGetDeviceGammaRamp */
3091 NULL
, /* pGetFontData */
3092 NULL
, /* pGetFontUnicodeRanges */
3093 NULL
, /* pGetGlyphIndices */
3094 NULL
, /* pGetGlyphOutline */
3095 NULL
, /* pGetICMProfile */
3096 NULL
, /* pGetImage */
3097 NULL
, /* pGetKerningPairs */
3098 NULL
, /* pGetNearestColor */
3099 NULL
, /* pGetOutlineTextMetrics */
3100 NULL
, /* pGetPixel */
3101 NULL
, /* pGetSystemPaletteEntries */
3102 NULL
, /* pGetTextCharsetInfo */
3103 NULL
, /* pGetTextExtentExPoint */
3104 NULL
, /* pGetTextExtentExPointI */
3105 NULL
, /* pGetTextFace */
3106 NULL
, /* pGetTextMetrics */
3107 NULL
, /* pGradientFill */
3108 NULL
, /* pIntersectClipRect */
3109 NULL
, /* pInvertRgn */
3111 NULL
, /* pModifyWorldTransform */
3113 NULL
, /* pOffsetClipRgn */
3114 NULL
, /* pOffsetViewportOrg */
3115 NULL
, /* pOffsetWindowOrg */
3116 NULL
, /* pPaintRgn */
3119 NULL
, /* pPolyBezier */
3120 NULL
, /* pPolyBezierTo */
3121 NULL
, /* pPolyDraw */
3122 NULL
, /* pPolyPolygon */
3123 NULL
, /* pPolyPolyline */
3124 NULL
, /* pPolygon */
3125 NULL
, /* pPolyline */
3126 NULL
, /* pPolylineTo */
3127 NULL
, /* pPutImage */
3128 NULL
, /* pRealizeDefaultPalette */
3129 NULL
, /* pRealizePalette */
3130 NULL
, /* pRectangle */
3131 NULL
, /* pResetDC */
3132 NULL
, /* pRestoreDC */
3133 NULL
, /* pRoundRect */
3135 NULL
, /* pScaleViewportExt */
3136 NULL
, /* pScaleWindowExt */
3137 NULL
, /* pSelectBitmap */
3138 NULL
, /* pSelectBrush */
3139 NULL
, /* pSelectClipPath */
3140 NULL
, /* pSelectFont */
3141 NULL
, /* pSelectPalette */
3142 NULL
, /* pSelectPen */
3143 NULL
, /* pSetArcDirection */
3144 NULL
, /* pSetBkColor */
3145 NULL
, /* pSetBkMode */
3146 NULL
, /* pSetBoundsRect */
3147 NULL
, /* pSetDCBrushColor */
3148 NULL
, /* pSetDCPenColor */
3149 NULL
, /* pSetDIBitsToDevice */
3150 NULL
, /* pSetDeviceClipping */
3151 NULL
, /* pSetDeviceGammaRamp */
3152 NULL
, /* pSetLayout */
3153 NULL
, /* pSetMapMode */
3154 NULL
, /* pSetMapperFlags */
3155 NULL
, /* pSetPixel */
3156 NULL
, /* pSetPolyFillMode */
3157 NULL
, /* pSetROP2 */
3158 NULL
, /* pSetRelAbs */
3159 NULL
, /* pSetStretchBltMode */
3160 NULL
, /* pSetTextAlign */
3161 NULL
, /* pSetTextCharacterExtra */
3162 NULL
, /* pSetTextColor */
3163 NULL
, /* pSetTextJustification */
3164 NULL
, /* pSetViewportExt */
3165 NULL
, /* pSetViewportOrg */
3166 NULL
, /* pSetWindowExt */
3167 NULL
, /* pSetWindowOrg */
3168 NULL
, /* pSetWorldTransform */
3169 NULL
, /* pStartDoc */
3170 NULL
, /* pStartPage */
3171 NULL
, /* pStretchBlt */
3172 NULL
, /* pStretchDIBits */
3173 NULL
, /* pStrokeAndFillPath */
3174 NULL
, /* pStrokePath */
3175 glxdrv_SwapBuffers
, /* pSwapBuffers */
3176 NULL
, /* pUnrealizePalette */
3177 NULL
, /* pWidenPath */
3178 glxdrv_wine_get_wgl_driver
, /* wine_get_wgl_driver */
3179 GDI_PRIORITY_GRAPHICS_DRV
+ 20 /* priority */
3182 static struct opengl_funcs opengl_funcs
=
3185 glxdrv_wglCopyContext
, /* p_wglCopyContext */
3186 glxdrv_wglCreateContext
, /* p_wglCreateContext */
3187 glxdrv_wglDeleteContext
, /* p_wglDeleteContext */
3188 glxdrv_wglDescribePixelFormat
, /* p_wglDescribePixelFormat */
3189 glxdrv_wglGetPixelFormat
, /* p_wglGetPixelFormat */
3190 glxdrv_wglGetProcAddress
, /* p_wglGetProcAddress */
3191 glxdrv_wglMakeCurrent
, /* p_wglMakeCurrent */
3192 glxdrv_wglSetPixelFormat
, /* p_wglSetPixelFormat */
3193 glxdrv_wglShareLists
, /* p_wglShareLists */
3197 const struct gdi_dc_funcs
*get_glx_driver(void)
3199 return &glxdrv_funcs
;
3202 #else /* no OpenGL includes */
3204 const struct gdi_dc_funcs
*get_glx_driver(void)
3209 void mark_drawable_dirty(Drawable old
, Drawable
new)
3213 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3219 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3224 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3229 #endif /* defined(SONAME_LIBGL) */