2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
41 #include "wine/library.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
45 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
66 /* Redefines the constants */
67 #define CALLBACK __stdcall
68 #define WINAPI __stdcall
69 #define APIENTRY WINAPI
72 WINE_DECLARE_DEBUG_CHANNEL(fps
);
74 typedef struct wine_glextension
{
83 const char *glVersion
;
88 const char *glxServerVersion
;
89 const char *glxServerVendor
;
90 const char *glxServerExtensions
;
92 const char *glxClientVersion
;
93 const char *glxClientVendor
;
94 const char *glxClientExtensions
;
96 const char *glxExtensions
;
99 char wglExtensions
[4096];
102 typedef struct wine_glpixelformat
{
104 GLXFBConfig fbconfig
;
108 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
111 typedef struct wine_glcontext
{
114 BOOL has_been_current
;
119 WineGLPixelFormat
*fmt
;
120 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
121 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
124 Drawable drawables
[2];
125 BOOL refresh_drawables
;
126 struct wine_glcontext
*next
;
127 struct wine_glcontext
*prev
;
130 typedef struct wine_glpbuffer
{
133 WineGLPixelFormat
* fmt
;
139 int use_render_texture
; /* This is also the internal texture format */
140 int texture_bind_target
;
142 GLint texture_format
;
143 GLuint texture_target
;
149 static Wine_GLContext
*context_list
;
150 static struct WineGLInfo WineGLInfo
= { 0 };
151 static int use_render_texture_emulation
= 1;
152 static int use_render_texture_ati
= 0;
153 static BOOL has_swap_control
;
154 static int swap_interval
= 1;
156 #define MAX_EXTENSIONS 16
157 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
158 static int WineGLExtensionListSize
;
160 static void X11DRV_WineGL_LoadExtensions(void);
161 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
162 static BOOL
glxRequireVersion(int requiredVersion
);
163 static BOOL
glxRequireExtension(const char *requiredExtension
);
165 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
166 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
167 TRACE(" - dwFlags : ");
168 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
173 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
174 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
175 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
176 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
177 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
178 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
179 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
180 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
181 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
182 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
183 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
184 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
185 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
186 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
187 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
191 TRACE(" - iPixelType : ");
192 switch (ppfd
->iPixelType
) {
193 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
194 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
198 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
199 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
200 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
201 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
202 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
203 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
204 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
205 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
206 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
208 TRACE(" - iLayerType : ");
209 switch (ppfd
->iLayerType
) {
210 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
211 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
212 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
217 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
218 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
220 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
222 MAKE_FUNCPTR(glXChooseVisual
)
223 MAKE_FUNCPTR(glXCopyContext
)
224 MAKE_FUNCPTR(glXCreateContext
)
225 MAKE_FUNCPTR(glXCreateGLXPixmap
)
226 MAKE_FUNCPTR(glXGetCurrentContext
)
227 MAKE_FUNCPTR(glXGetCurrentDrawable
)
228 MAKE_FUNCPTR(glXDestroyContext
)
229 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
230 MAKE_FUNCPTR(glXGetConfig
)
231 MAKE_FUNCPTR(glXIsDirect
)
232 MAKE_FUNCPTR(glXMakeCurrent
)
233 MAKE_FUNCPTR(glXSwapBuffers
)
234 MAKE_FUNCPTR(glXQueryExtension
)
235 MAKE_FUNCPTR(glXQueryVersion
)
236 MAKE_FUNCPTR(glXUseXFont
)
239 MAKE_FUNCPTR(glXGetClientString
)
240 MAKE_FUNCPTR(glXQueryExtensionsString
)
241 MAKE_FUNCPTR(glXQueryServerString
)
244 MAKE_FUNCPTR(glXGetFBConfigs
)
245 MAKE_FUNCPTR(glXChooseFBConfig
)
246 MAKE_FUNCPTR(glXCreatePbuffer
)
247 MAKE_FUNCPTR(glXCreateNewContext
)
248 MAKE_FUNCPTR(glXDestroyPbuffer
)
249 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
250 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
251 MAKE_FUNCPTR(glXMakeContextCurrent
)
252 MAKE_FUNCPTR(glXQueryDrawable
)
253 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
256 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
257 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
258 static int (*pglXSwapIntervalSGI
)(int);
260 /* ATI GLX Extensions */
261 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
262 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
263 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
265 /* NV GLX Extension */
266 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
267 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
269 /* MESA GLX Extensions */
270 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
272 /* Standard OpenGL */
273 MAKE_FUNCPTR(glBindTexture
)
274 MAKE_FUNCPTR(glBitmap
)
275 MAKE_FUNCPTR(glCopyTexSubImage1D
)
276 MAKE_FUNCPTR(glCopyTexImage2D
)
277 MAKE_FUNCPTR(glCopyTexSubImage2D
)
278 MAKE_FUNCPTR(glDrawBuffer
)
279 MAKE_FUNCPTR(glEndList
)
280 MAKE_FUNCPTR(glGetError
)
281 MAKE_FUNCPTR(glGetIntegerv
)
282 MAKE_FUNCPTR(glGetString
)
283 MAKE_FUNCPTR(glNewList
)
284 MAKE_FUNCPTR(glPixelStorei
)
285 MAKE_FUNCPTR(glReadPixels
)
286 MAKE_FUNCPTR(glTexImage2D
)
287 MAKE_FUNCPTR(glFinish
)
288 MAKE_FUNCPTR(glFlush
)
291 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
293 /* In the future we might want to find the exact X or GLX error to report back to the app */
297 static BOOL infoInitialized
= FALSE
;
298 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
300 int screen
= DefaultScreen(gdi_display
);
301 Window win
= 0, root
= 0;
304 GLXContext ctx
= NULL
;
305 XSetWindowAttributes attr
;
307 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
311 infoInitialized
= TRUE
;
313 attr
.override_redirect
= True
;
314 attr
.colormap
= None
;
315 attr
.border_pixel
= 0;
319 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
322 WORD old_fs
= wine_get_fs();
323 /* Create a GLX Context. Without one we can't query GL information */
324 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
325 if (wine_get_fs() != old_fs
)
327 wine_set_fs( old_fs
);
328 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
329 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
333 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
338 root
= RootWindow( gdi_display
, vis
->screen
);
339 if (vis
->visual
!= DefaultVisual( gdi_display
, vis
->screen
))
340 attr
.colormap
= XCreateColormap( gdi_display
, root
, vis
->visual
, AllocNone
);
341 if ((win
= XCreateWindow( gdi_display
, root
, -1, -1, 1, 1, 0, vis
->depth
, InputOutput
,
342 vis
->visual
, CWBorderPixel
| CWOverrideRedirect
| CWColormap
, &attr
)))
343 XMapWindow( gdi_display
, win
);
347 if(pglXMakeCurrent(gdi_display
, win
, ctx
) == 0)
349 ERR_(winediag
)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
352 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
353 str
= (const char *) pglGetString(GL_EXTENSIONS
);
354 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
355 strcpy(WineGLInfo
.glExtensions
, str
);
357 /* Get the common GLX version supported by GLX client and server ( major/minor) */
358 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
360 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
361 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
362 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
364 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
365 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
366 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
368 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
369 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
371 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
372 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
373 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
374 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
375 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
376 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
377 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
378 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
380 if(!WineGLInfo
.glxDirect
)
382 int fd
= ConnectionNumber(gdi_display
);
383 struct sockaddr_un uaddr
;
384 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
386 /* In general indirect rendering on a local X11 server indicates a driver problem.
387 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
389 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
390 ERR_(winediag
)("Direct rendering is disabled, most likely your OpenGL drivers haven't been installed correctly\n");
394 /* In general you would expect that if direct rendering is returned, that you receive hardware
395 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
396 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
397 * software rendering, it shows direct rendering.
399 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
400 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
401 * it shows 'Mesa X11'.
403 const char *gl_renderer
= (const char *)pglGetString(GL_RENDERER
);
404 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
405 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL drivers haven't been installed correctly\n");
412 pglXMakeCurrent(gdi_display
, None
, NULL
);
413 pglXDestroyContext(gdi_display
, ctx
);
415 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
416 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
418 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
422 void X11DRV_OpenGL_Cleanup(void)
424 HeapFree(GetProcessHeap(), 0, WineGLInfo
.glExtensions
);
425 infoInitialized
= FALSE
;
428 static BOOL
has_opengl(void)
430 static int init_done
;
431 static void *opengl_handle
;
434 int error_base
, event_base
;
436 if (init_done
) return (opengl_handle
!= NULL
);
439 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
440 and include all dependencies */
441 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
442 if (opengl_handle
== NULL
)
444 ERR( "Failed to load libGL: %s\n", buffer
);
445 ERR( "OpenGL support is disabled.\n");
449 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
450 if (pglXGetProcAddressARB
== NULL
) {
451 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
455 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
457 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
462 LOAD_FUNCPTR(glXChooseVisual
);
463 LOAD_FUNCPTR(glXCopyContext
);
464 LOAD_FUNCPTR(glXCreateContext
);
465 LOAD_FUNCPTR(glXCreateGLXPixmap
);
466 LOAD_FUNCPTR(glXGetCurrentContext
);
467 LOAD_FUNCPTR(glXGetCurrentDrawable
);
468 LOAD_FUNCPTR(glXDestroyContext
);
469 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
470 LOAD_FUNCPTR(glXGetConfig
);
471 LOAD_FUNCPTR(glXIsDirect
);
472 LOAD_FUNCPTR(glXMakeCurrent
);
473 LOAD_FUNCPTR(glXSwapBuffers
);
474 LOAD_FUNCPTR(glXQueryExtension
);
475 LOAD_FUNCPTR(glXQueryVersion
);
476 LOAD_FUNCPTR(glXUseXFont
);
479 LOAD_FUNCPTR(glXGetClientString
);
480 LOAD_FUNCPTR(glXQueryExtensionsString
);
481 LOAD_FUNCPTR(glXQueryServerString
);
484 LOAD_FUNCPTR(glXCreatePbuffer
);
485 LOAD_FUNCPTR(glXCreateNewContext
);
486 LOAD_FUNCPTR(glXDestroyPbuffer
);
487 LOAD_FUNCPTR(glXMakeContextCurrent
);
488 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
489 LOAD_FUNCPTR(glXGetFBConfigs
);
491 /* Standard OpenGL calls */
492 LOAD_FUNCPTR(glBindTexture
);
493 LOAD_FUNCPTR(glBitmap
);
494 LOAD_FUNCPTR(glCopyTexSubImage1D
);
495 LOAD_FUNCPTR(glCopyTexImage2D
);
496 LOAD_FUNCPTR(glCopyTexSubImage2D
);
497 LOAD_FUNCPTR(glDrawBuffer
);
498 LOAD_FUNCPTR(glEndList
);
499 LOAD_FUNCPTR(glGetError
);
500 LOAD_FUNCPTR(glGetIntegerv
);
501 LOAD_FUNCPTR(glGetString
);
502 LOAD_FUNCPTR(glNewList
);
503 LOAD_FUNCPTR(glPixelStorei
);
504 LOAD_FUNCPTR(glReadPixels
);
505 LOAD_FUNCPTR(glTexImage2D
);
506 LOAD_FUNCPTR(glFinish
);
507 LOAD_FUNCPTR(glFlush
);
510 /* It doesn't matter if these fail. They'll only be used if the driver reports
511 the associated extension is available (and if a driver reports the extension
512 is available but fails to provide the functions, it's quite broken) */
513 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
514 /* ARB GLX Extension */
515 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
516 /* SGI GLX Extension */
517 LOAD_FUNCPTR(glXSwapIntervalSGI
);
518 /* NV GLX Extension */
519 LOAD_FUNCPTR(glXAllocateMemoryNV
);
520 LOAD_FUNCPTR(glXFreeMemoryNV
);
523 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
526 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
527 TRACE("GLX is up and running error_base = %d\n", error_base
);
530 ERR( "GLX extension is missing, disabling OpenGL.\n" );
534 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
535 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
538 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
539 * depends on the reported GLX client / server version and on the client / server extension list.
540 * Those don't have to be the same.
542 * In general the server GLX information lists the capabilities in case of indirect rendering.
543 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
544 * available and in that case the client GLX informat can be used.
545 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
546 * in the GLX version/extension list. When a program does this it works for certain for both
547 * direct and indirect rendering.
549 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
550 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
551 * extension list which causes this extension not to be listed. (Wine requires this extension).
552 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
553 * pbuffers is around.
555 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
556 * the ATI drivers and from then on use GLX client information for them.
559 if(glxRequireVersion(3)) {
560 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
561 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
562 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
563 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
564 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
565 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
566 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
567 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
569 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
570 * enable this function when the Xserver understand GLX 1.3 or newer
572 pglXQueryDrawable
= NULL
;
573 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
574 TRACE("Overriding ATI GLX capabilities!\n");
575 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
576 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
577 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
578 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
580 /* Use client GLX information in case of the ATI drivers. We override the
581 * capabilities over here and not somewhere else as ATI might better their
582 * life in the future. In case they release proper drivers this block of
583 * code won't be called. */
584 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
586 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
589 if(glxRequireExtension("GLX_ATI_render_texture")) {
590 use_render_texture_ati
= 1;
591 pglXBindTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
592 pglXReleaseTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
593 pglXDrawableAttribATI
= pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
596 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
597 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
600 X11DRV_WineGL_LoadExtensions();
606 wine_dlclose(opengl_handle
, NULL
, 0);
607 opengl_handle
= NULL
;
611 static inline Wine_GLContext
*alloc_context(void)
615 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
617 ret
->next
= context_list
;
618 if (context_list
) context_list
->prev
= ret
;
624 static inline void free_context(Wine_GLContext
*context
)
626 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
627 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
628 else context_list
= context
->next
;
630 if (context
->vis
) XFree(context
->vis
);
631 HeapFree(GetProcessHeap(), 0, context
);
634 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
637 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
638 return (ptr
!= NULL
);
641 static int describeContext(Wine_GLContext
* ctx
) {
644 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
645 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
646 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
647 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
648 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
653 static BOOL
describeDrawable(X11DRV_PDEVICE
*physDev
) {
655 WineGLPixelFormat
*fmt
;
658 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
/* Offscreen */, &fmt_count
);
659 if(!fmt
) return FALSE
;
661 TRACE(" HDC %p has:\n", physDev
->dev
.hdc
);
662 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
663 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev
));
664 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
666 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
667 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
672 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
677 int nvfloatattrib
= GLX_DONT_CARE
;
678 int pixelattrib
= ~0;
680 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
681 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
682 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
683 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
685 switch (iWGLAttr
[cur
]) {
686 case WGL_AUX_BUFFERS_ARB
:
687 pop
= iWGLAttr
[++cur
];
688 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
689 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
691 case WGL_COLOR_BITS_ARB
:
692 pop
= iWGLAttr
[++cur
];
693 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
694 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
696 case WGL_BLUE_BITS_ARB
:
697 pop
= iWGLAttr
[++cur
];
698 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
699 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
701 case WGL_RED_BITS_ARB
:
702 pop
= iWGLAttr
[++cur
];
703 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
704 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
706 case WGL_GREEN_BITS_ARB
:
707 pop
= iWGLAttr
[++cur
];
708 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
709 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
711 case WGL_ALPHA_BITS_ARB
:
712 pop
= iWGLAttr
[++cur
];
713 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
714 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
716 case WGL_DEPTH_BITS_ARB
:
717 pop
= iWGLAttr
[++cur
];
718 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
719 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
721 case WGL_STENCIL_BITS_ARB
:
722 pop
= iWGLAttr
[++cur
];
723 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
724 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
726 case WGL_DOUBLE_BUFFER_ARB
:
727 pop
= iWGLAttr
[++cur
];
728 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
729 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
732 pop
= iWGLAttr
[++cur
];
733 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
734 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
737 case WGL_PIXEL_TYPE_ARB
:
738 pop
= iWGLAttr
[++cur
];
739 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
741 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
742 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
743 /* 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 */
744 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
745 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
747 ERR("unexpected PixelType(%x)\n", pop
);
752 case WGL_SUPPORT_GDI_ARB
:
753 /* This flag is set in a WineGLPixelFormat */
754 pop
= iWGLAttr
[++cur
];
755 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
758 case WGL_DRAW_TO_BITMAP_ARB
:
759 /* This flag is set in a WineGLPixelFormat */
760 pop
= iWGLAttr
[++cur
];
761 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
764 case WGL_DRAW_TO_WINDOW_ARB
:
765 pop
= iWGLAttr
[++cur
];
766 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
767 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
769 drawattrib
|= GLX_WINDOW_BIT
;
773 case WGL_DRAW_TO_PBUFFER_ARB
:
774 pop
= iWGLAttr
[++cur
];
775 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
776 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
778 drawattrib
|= GLX_PBUFFER_BIT
;
782 case WGL_ACCELERATION_ARB
:
783 /* This flag is set in a WineGLPixelFormat */
784 pop
= iWGLAttr
[++cur
];
785 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
788 case WGL_SUPPORT_OPENGL_ARB
:
789 pop
= iWGLAttr
[++cur
];
790 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
791 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
794 case WGL_SWAP_METHOD_ARB
:
795 pop
= iWGLAttr
[++cur
];
796 /* For now we ignore this and just return SWAP_EXCHANGE */
797 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
800 case WGL_PBUFFER_LARGEST_ARB
:
801 pop
= iWGLAttr
[++cur
];
802 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
803 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
806 case WGL_SAMPLE_BUFFERS_ARB
:
807 pop
= iWGLAttr
[++cur
];
808 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
809 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
812 case WGL_SAMPLES_ARB
:
813 pop
= iWGLAttr
[++cur
];
814 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
815 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
818 case WGL_TEXTURE_FORMAT_ARB
:
819 case WGL_TEXTURE_TARGET_ARB
:
820 case WGL_MIPMAP_TEXTURE_ARB
:
821 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
822 pop
= iWGLAttr
[++cur
];
824 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
826 if (use_render_texture_ati
) {
827 /** nothing to do here */
829 else if (!use_render_texture_emulation
) {
830 if (WGL_NO_TEXTURE_ARB
!= pop
) {
831 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
832 return -1; /** error: don't support it */
834 drawattrib
|= GLX_PBUFFER_BIT
;
838 case WGL_FLOAT_COMPONENTS_NV
:
839 nvfloatattrib
= iWGLAttr
[++cur
];
840 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
842 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
843 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
844 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
845 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
846 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
847 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
848 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
849 pop
= iWGLAttr
[++cur
];
850 /** cannot be converted, see direct handling on
851 * - wglGetPixelFormatAttribivARB
852 * TODO: wglChoosePixelFormat
855 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
856 pop
= iWGLAttr
[++cur
];
857 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
858 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
861 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
862 pop
= iWGLAttr
[++cur
];
863 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
864 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
867 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
873 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
874 * all formats. Unless drawattrib is set to a non-zero value override it with ~0, so that pixmap and pbuffer
875 * formats appear as well. */
876 if(!drawattrib
) drawattrib
= ~0;
877 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
878 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
880 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
881 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to ~0 unless
882 * it is overridden. */
883 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
884 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
886 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
887 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
888 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
889 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
895 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
897 int render_type
=0, render_type_bit
;
898 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
899 switch(render_type_bit
)
902 render_type
= GLX_RGBA_TYPE
;
904 case GLX_COLOR_INDEX_BIT
:
905 render_type
= GLX_COLOR_INDEX_TYPE
;
907 case GLX_RGBA_FLOAT_BIT
:
908 render_type
= GLX_RGBA_FLOAT_TYPE
;
910 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
911 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
914 ERR("Unknown render_type: %x\n", render_type_bit
);
919 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
920 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
923 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
924 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
926 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
927 * the GLX_PIXMAP_BIT set. */
928 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
931 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
933 static WineGLPixelFormat
*list
;
934 static int size
, onscreen_size
;
936 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
938 XVisualInfo
*visinfo
;
943 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
944 if (NULL
== cfgs
|| 0 == nCfgs
) {
945 if(cfgs
!= NULL
) XFree(cfgs
);
947 ERR("glXChooseFBConfig returns NULL\n");
951 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
952 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
953 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
954 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
956 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
958 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
960 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
963 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
965 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
967 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
968 * Do this as GLX doesn't guarantee that the list is sorted */
969 for(run
=0; run
< 2; run
++)
971 for(i
=0; i
<nCfgs
; i
++) {
972 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
973 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
975 /* The first run we only add onscreen formats (ones which have an associated X Visual).
976 * The second run we only set offscreen formats. */
979 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
980 * The contents is copied to the destination using XCopyArea. For the copying to work
981 * the depth of the source and destination window should be the same. In general this should
982 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
983 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
984 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
985 * list formats with the same depth. */
986 if(visinfo
->depth
!= screen_depth
)
992 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
993 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
994 list
[size
].fbconfig
= cfgs
[i
];
995 list
[size
].fmt_id
= fmt_id
;
996 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
997 list
[size
].offscreenOnly
= FALSE
;
998 list
[size
].dwFlags
= 0;
1002 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1003 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1005 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1006 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1007 list
[size
].fbconfig
= cfgs
[i
];
1008 list
[size
].fmt_id
= fmt_id
;
1009 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1010 list
[size
].offscreenOnly
= FALSE
;
1011 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
1015 } else if(run
&& !visinfo
) {
1016 int window_drawable
=0;
1017 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
1019 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1020 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1021 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1022 * likely make our child window opengl rendering more complicated since likely you can't use
1023 * XCopyArea on a GLX Window.
1024 * For now ignore fbconfigs which are window drawable but lack a visual. */
1025 if(window_drawable
& GLX_WINDOW_BIT
)
1027 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
1031 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1032 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1033 list
[size
].fbconfig
= cfgs
[i
];
1034 list
[size
].fmt_id
= fmt_id
;
1035 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1036 list
[size
].offscreenOnly
= TRUE
;
1037 list
[size
].dwFlags
= 0;
1041 if (visinfo
) XFree(visinfo
);
1048 if (size_ret
) *size_ret
= size
;
1049 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
1050 wine_tsx11_unlock();
1054 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1055 * In our WGL implementation we only support a subset of these formats namely the format of
1056 * Wine's main visual and offscreen formats (if they are available).
1057 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1058 * and it returns the number of supported WGL formats in fmt_count.
1060 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
1062 WineGLPixelFormat
*list
, *res
= NULL
;
1063 int size
, onscreen_size
;
1065 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
1067 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1068 * iPixelFormat in case of probing the number of pixelformats.
1070 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
1071 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
1072 res
= &list
[iPixelFormat
-1];
1073 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res
->fmt_id
, iPixelFormat
);
1079 *fmt_count
= onscreen_size
;
1081 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1086 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1087 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1089 WineGLPixelFormat
*list
;
1092 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1094 for(i
=0; i
<size
; i
++) {
1095 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1096 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1097 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1098 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1102 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1106 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1108 WineGLPixelFormat
*fmt
;
1110 if (!fbconfig_id
) return 0;
1112 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1114 return fmt
->iPixelFormat
;
1115 /* This will happen on hwnds without a pixel format set; it's ok */
1120 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1121 void mark_drawable_dirty(Drawable old
, Drawable
new)
1123 Wine_GLContext
*ctx
;
1124 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
1125 if (old
== ctx
->drawables
[0]) {
1126 ctx
->drawables
[0] = new;
1127 ctx
->refresh_drawables
= TRUE
;
1129 if (old
== ctx
->drawables
[1]) {
1130 ctx
->drawables
[1] = new;
1131 ctx
->refresh_drawables
= TRUE
;
1136 /* Given the current context, make sure its drawable is sync'd */
1137 static inline void sync_context(Wine_GLContext
*context
)
1139 if(context
&& context
->refresh_drawables
) {
1140 if (glxRequireVersion(3))
1141 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1142 context
->drawables
[1], context
->ctx
);
1144 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1145 context
->refresh_drawables
= FALSE
;
1150 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1154 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1155 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1157 if(context
->gl3_context
)
1159 if(context
->numAttribs
)
1160 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1162 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1164 else if(context
->vis
)
1165 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1166 else /* Create a GLX Context for a pbuffer */
1167 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1173 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1175 return pglXCreateGLXPixmap(display
, vis
, parent
);
1179 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1186 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1188 if(vis
->depth
== physDev
->bitmap
->pixmap_depth
)
1189 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1192 wine_tsx11_unlock();
1193 TRACE("return %lx\n", ret
);
1198 * X11DRV_ChoosePixelFormat
1200 * Equivalent to glXChooseVisual.
1202 int X11DRV_ChoosePixelFormat(PHYSDEV dev
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1204 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1205 WineGLPixelFormat
*list
;
1210 int bestFormat
= -1;
1211 int bestDBuffer
= -1;
1212 int bestStereo
= -1;
1216 int bestStencil
= -1;
1219 if (!has_opengl()) return 0;
1221 if (TRACE_ON(wgl
)) {
1222 TRACE("(%p,%p)\n", physDev
, ppfd
);
1224 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1227 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1230 for(i
=0; i
<onscreen_size
; i
++)
1234 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1235 WineGLPixelFormat
*fmt
= &list
[i
];
1238 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1239 if (value
& GLX_RGBA_BIT
)
1240 iPixelType
= PFD_TYPE_RGBA
;
1242 iPixelType
= PFD_TYPE_COLORINDEX
;
1244 if (ppfd
->iPixelType
!= iPixelType
)
1246 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1250 /* Only use bitmap capable for formats for bitmap rendering.
1251 * See get_formats for more info. */
1252 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1254 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1258 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1259 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1260 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1261 if (value
) dwFlags
|= PFD_STEREO
;
1262 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1263 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1264 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1265 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1266 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1268 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1269 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1270 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1271 * formats without the given flag set.
1272 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1273 * has indicated that a format without stereo is returned when stereo is unavailable.
1274 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1275 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1277 * To summarize the following is most likely the correct behavior:
1278 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1279 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1280 * stereo don't care -> it doesn't matter whether we get stereo or not
1282 * In Wine we will treat no-stereo the same way as don't care because it makes
1283 * format selection even more complicated and second drivers with Stereo advertise
1284 * each format twice anyway.
1287 /* Doublebuffer, see the comments above */
1288 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1289 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1290 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1292 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1293 bestStereo
= dwFlags
& PFD_STEREO
;
1297 bestStencil
= stencil
;
1302 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1306 /* Stereo, see the comments above. */
1307 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1308 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1309 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1311 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1312 bestStereo
= dwFlags
& PFD_STEREO
;
1316 bestStencil
= stencil
;
1321 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1325 /* Below we will do a number of checks to select the 'best' pixelformat.
1326 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1327 * The code works by trying to match the most important options as close as possible.
1328 * When a reasonable format is found, we will try to match more options.
1329 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1330 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1331 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1334 if(ppfd
->cColorBits
) {
1335 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1336 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1338 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1339 bestStereo
= dwFlags
& PFD_STEREO
;
1343 bestStencil
= stencil
;
1347 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1348 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1354 if(ppfd
->cAlphaBits
) {
1355 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1356 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1358 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1359 bestStereo
= dwFlags
& PFD_STEREO
;
1363 bestStencil
= stencil
;
1367 } else if(bestAlpha
!= alpha
) {
1368 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1374 if(ppfd
->cDepthBits
) {
1375 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1376 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1378 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1379 bestStereo
= dwFlags
& PFD_STEREO
;
1383 bestStencil
= stencil
;
1387 } else if(bestDepth
!= depth
) {
1388 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1394 if(ppfd
->cStencilBits
) {
1395 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1396 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1398 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1399 bestStereo
= dwFlags
& PFD_STEREO
;
1403 bestStencil
= stencil
;
1407 } else if(bestStencil
!= stencil
) {
1408 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1414 if(ppfd
->cAuxBuffers
) {
1415 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1416 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1418 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1419 bestStereo
= dwFlags
& PFD_STEREO
;
1423 bestStencil
= stencil
;
1427 } else if(bestAux
!= aux
) {
1428 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1434 if(bestFormat
== -1) {
1435 TRACE("No matching mode was found returning 0\n");
1439 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1440 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1443 wine_tsx11_unlock();
1448 * X11DRV_DescribePixelFormat
1450 * Get the pixel-format descriptor associated to the given id
1452 int X11DRV_DescribePixelFormat(PHYSDEV dev
, int iPixelFormat
,
1453 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1455 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1456 /*XVisualInfo *vis;*/
1459 WineGLPixelFormat
*fmt
;
1463 if (!has_opengl()) return 0;
1465 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1467 /* 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 */
1468 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1470 /* The application is only querying the number of pixelformats */
1472 } else if(fmt
== NULL
) {
1473 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1477 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1478 ERR("Wrong structure size !\n");
1479 /* Should set error */
1485 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1486 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1489 /* These flags are always the same... */
1490 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1491 /* Now the flags extracted from the Visual */
1495 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1496 if(value
& GLX_WINDOW_BIT
)
1497 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1499 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1500 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1501 * 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
1502 * offered the GDI bit either. */
1503 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1505 /* PFD_GENERIC_FORMAT - gdi software rendering
1506 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1507 * none set - full hardware accelerated by a ICD
1509 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1510 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1512 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1514 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1515 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1517 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1520 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1521 if (value
& GLX_RGBA_BIT
)
1522 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1524 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1527 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1528 ppfd
->cColorBits
= value
;
1530 /* Red, green, blue and alpha bits / shifts */
1531 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1532 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1533 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1534 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1535 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1537 ppfd
->cRedBits
= rb
;
1538 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1539 ppfd
->cBlueBits
= bb
;
1540 ppfd
->cBlueShift
= ab
;
1541 ppfd
->cGreenBits
= gb
;
1542 ppfd
->cGreenShift
= bb
+ ab
;
1543 ppfd
->cAlphaBits
= ab
;
1544 ppfd
->cAlphaShift
= 0;
1547 ppfd
->cRedShift
= 0;
1548 ppfd
->cBlueBits
= 0;
1549 ppfd
->cBlueShift
= 0;
1550 ppfd
->cGreenBits
= 0;
1551 ppfd
->cGreenShift
= 0;
1552 ppfd
->cAlphaBits
= 0;
1553 ppfd
->cAlphaShift
= 0;
1556 /* Accum RGBA bits */
1557 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1558 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1559 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1560 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1562 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1563 ppfd
->cAccumRedBits
= rb
;
1564 ppfd
->cAccumGreenBits
= gb
;
1565 ppfd
->cAccumBlueBits
= bb
;
1566 ppfd
->cAccumAlphaBits
= ab
;
1569 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1570 ppfd
->cAuxBuffers
= value
;
1573 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1574 ppfd
->cDepthBits
= value
;
1577 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1578 ppfd
->cStencilBits
= value
;
1580 wine_tsx11_unlock();
1582 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1584 if (TRACE_ON(wgl
)) {
1585 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1592 * X11DRV_GetPixelFormat
1594 * Get the pixel-format id used by this DC
1596 int X11DRV_GetPixelFormat(PHYSDEV dev
)
1598 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1599 WineGLPixelFormat
*fmt
;
1601 TRACE("(%p)\n", physDev
);
1603 if (!physDev
->current_pf
) return 0; /* not set yet */
1605 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1608 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1611 else if(fmt
->offscreenOnly
)
1613 /* Offscreen formats can't be used with traditional WGL calls.
1614 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1615 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1619 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1620 return physDev
->current_pf
;
1623 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1624 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1625 * set the pixel format multiple times. */
1626 static BOOL
internal_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1628 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1629 WineGLPixelFormat
*fmt
;
1633 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1634 if(get_glxdrawable(physDev
) == root_window
)
1636 ERR("Invalid operation on root_window\n");
1640 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1641 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1643 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1648 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1649 wine_tsx11_unlock();
1651 hwnd
= WindowFromDC(physDev
->dev
.hdc
);
1653 if(!(value
&GLX_WINDOW_BIT
)) {
1654 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1658 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, fmt
->fmt_id
, 0)) {
1659 ERR("Couldn't set format of the window, returning failure\n");
1663 else if(physDev
->bitmap
) {
1664 if(!(value
&GLX_PIXMAP_BIT
)) {
1665 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1669 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
, fmt
);
1670 if(!physDev
->bitmap
->glxpixmap
) {
1671 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1676 FIXME("called on a non-window, non-bitmap object?\n");
1679 physDev
->current_pf
= iPixelFormat
;
1681 if (TRACE_ON(wgl
)) {
1685 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1687 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1689 TRACE(" FBConfig have :\n");
1690 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1691 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1692 TRACE(" - VISUAL_ID 0x%x\n", value
);
1693 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1694 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1696 wine_tsx11_unlock();
1703 * X11DRV_SetPixelFormat
1705 * Set the pixel-format id used by this DC
1707 BOOL
X11DRV_SetPixelFormat(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1709 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1711 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1713 if (!has_opengl()) return FALSE
;
1715 if(physDev
->current_pf
) /* cannot change it if already set */
1716 return (physDev
->current_pf
== iPixelFormat
);
1718 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
1722 * X11DRV_wglCopyContext
1724 * For OpenGL32 wglCopyContext.
1726 BOOL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
1728 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1729 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1731 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1734 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1735 wine_tsx11_unlock();
1737 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1742 * X11DRV_wglCreateContext
1744 * For OpenGL32 wglCreateContext.
1746 HGLRC
X11DRV_wglCreateContext(PHYSDEV dev
)
1748 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1749 Wine_GLContext
*ret
;
1750 WineGLPixelFormat
*fmt
;
1751 int hdcPF
= physDev
->current_pf
;
1755 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1757 if (!has_opengl()) return 0;
1759 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1760 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1761 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1762 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1763 * If this fails something is very wrong on the system. */
1765 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1766 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1771 ret
= alloc_context();
1774 ret
->has_been_current
= FALSE
;
1775 ret
->sharing
= FALSE
;
1777 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1778 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1779 wine_tsx11_unlock();
1781 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1786 * X11DRV_wglDeleteContext
1788 * For OpenGL32 wglDeleteContext.
1790 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1792 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1794 TRACE("(%p)\n", hglrc
);
1796 if (!has_opengl()) return 0;
1798 if (!is_valid_context(ctx
))
1800 WARN("Error deleting context !\n");
1801 SetLastError(ERROR_INVALID_HANDLE
);
1805 /* WGL doesn't allow deletion of a context which is current in another thread */
1806 if (ctx
->tid
!= 0 && ctx
->tid
!= GetCurrentThreadId())
1808 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx
);
1809 SetLastError(ERROR_BUSY
);
1813 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1814 if (ctx
== NtCurrentTeb()->glContext
)
1815 wglMakeCurrent(ctx
->hdc
, NULL
);
1820 pglXDestroyContext(gdi_display
, ctx
->ctx
);
1821 wine_tsx11_unlock();
1829 * X11DRV_wglGetCurrentReadDCARB
1831 * For OpenGL32 wglGetCurrentReadDCARB.
1833 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1836 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1838 if (ctx
) ret
= ctx
->read_hdc
;
1840 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1845 * X11DRV_wglGetProcAddress
1847 * For OpenGL32 wglGetProcAddress.
1849 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1852 const WineGLExtension
*ext
;
1854 int padding
= 32 - strlen(lpszProc
);
1858 if (!has_opengl()) return NULL
;
1860 /* Check the table of WGL extensions to see if we need to return a WGL extension
1861 * or a function pointer to a native OpenGL function. */
1862 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1863 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1865 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1866 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1867 ext
= WineGLExtensionList
[i
];
1868 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1869 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1870 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1871 return ext
->extEntryPoints
[j
].funcAddress
;
1877 WARN("(%s) - not found\n", lpszProc
);
1882 * X11DRV_wglMakeCurrent
1884 * For OpenGL32 wglMakeCurrent.
1886 BOOL
X11DRV_wglMakeCurrent(PHYSDEV dev
, HGLRC hglrc
)
1888 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1891 DWORD type
= GetObjectType(hdc
);
1892 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1894 TRACE("(%p,%p)\n", hdc
, hglrc
);
1896 if (!has_opengl()) return FALSE
;
1901 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1902 if (prev_ctx
) prev_ctx
->tid
= 0;
1904 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1905 NtCurrentTeb()->glContext
= NULL
;
1907 else if (!physDev
->current_pf
)
1909 WARN("Trying to use an invalid drawable\n");
1910 SetLastError(ERROR_INVALID_HANDLE
);
1913 else if (ctx
->fmt
->iPixelFormat
!= physDev
->current_pf
)
1915 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1916 hdc
, physDev
->current_pf
, ctx
, ctx
->fmt
->iPixelFormat
);
1917 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1922 Drawable drawable
= get_glxdrawable(physDev
);
1923 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1925 /* The describe lines below are for debugging purposes only */
1926 if (TRACE_ON(wgl
)) {
1927 describeDrawable(physDev
);
1928 describeContext(ctx
);
1931 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1932 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1936 if (prev_ctx
) prev_ctx
->tid
= 0;
1937 NtCurrentTeb()->glContext
= ctx
;
1939 ctx
->has_been_current
= TRUE
;
1940 ctx
->tid
= GetCurrentThreadId();
1942 ctx
->read_hdc
= hdc
;
1943 ctx
->drawables
[0] = drawable
;
1944 ctx
->drawables
[1] = drawable
;
1945 ctx
->refresh_drawables
= FALSE
;
1947 if (type
== OBJ_MEMDC
)
1949 ctx
->do_escape
= TRUE
;
1950 pglDrawBuffer(GL_FRONT_LEFT
);
1954 SetLastError(ERROR_INVALID_HANDLE
);
1956 wine_tsx11_unlock();
1957 TRACE(" returning %s\n", (ret
? "True" : "False"));
1962 * X11DRV_wglMakeContextCurrentARB
1964 * For OpenGL32 wglMakeContextCurrentARB
1966 BOOL
X11DRV_wglMakeContextCurrentARB( PHYSDEV draw_dev
, PHYSDEV read_dev
, HGLRC hglrc
)
1968 X11DRV_PDEVICE
*pDrawDev
= get_x11drv_dev( draw_dev
);
1969 X11DRV_PDEVICE
*pReadDev
= get_x11drv_dev( read_dev
);
1972 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1974 if (!has_opengl()) return 0;
1979 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1980 if (prev_ctx
) prev_ctx
->tid
= 0;
1982 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1983 NtCurrentTeb()->glContext
= NULL
;
1985 else if (!pDrawDev
->current_pf
)
1987 WARN("Trying to use an invalid drawable\n");
1988 SetLastError(ERROR_INVALID_HANDLE
);
1993 if (NULL
== pglXMakeContextCurrent
) {
1996 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1997 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1998 Drawable d_read
= get_glxdrawable(pReadDev
);
2000 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
2003 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
2004 if (prev_ctx
) prev_ctx
->tid
= 0;
2006 ctx
->has_been_current
= TRUE
;
2007 ctx
->tid
= GetCurrentThreadId();
2008 ctx
->hdc
= draw_dev
->hdc
;
2009 ctx
->read_hdc
= read_dev
->hdc
;
2010 ctx
->drawables
[0] = d_draw
;
2011 ctx
->drawables
[1] = d_read
;
2012 ctx
->refresh_drawables
= FALSE
;
2013 NtCurrentTeb()->glContext
= ctx
;
2016 SetLastError(ERROR_INVALID_HANDLE
);
2019 wine_tsx11_unlock();
2021 TRACE(" returning %s\n", (ret
? "True" : "False"));
2026 * X11DRV_wglShareLists
2028 * For OpenGL32 wglShareLists.
2030 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
2032 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
2033 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
2035 TRACE("(%p, %p)\n", org
, dest
);
2037 if (!has_opengl()) return FALSE
;
2039 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
2040 * at context creation time but in case of WGL it is done using wglShareLists.
2041 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
2042 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
2043 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
2044 * so there delaying context creation doesn't work.
2046 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
2047 * and when a program requests sharing we recreate the destination context if it hasn't been made
2048 * current or when it hasn't shared display lists before.
2051 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
2053 ERR("Could not share display lists, one of the contexts has been current already !\n");
2056 else if(dest
->sharing
)
2058 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
2063 if((GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
))
2065 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
2069 describeContext(org
);
2070 describeContext(dest
);
2072 /* Re-create the GLX context and share display lists */
2073 pglXDestroyContext(gdi_display
, dest
->ctx
);
2074 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
2075 wine_tsx11_unlock();
2076 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
2078 org
->sharing
= TRUE
;
2079 dest
->sharing
= TRUE
;
2085 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
2087 /* We are running using client-side rendering fonts... */
2089 unsigned int glyph
, size
= 0;
2090 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
2094 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
2095 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
2096 wine_tsx11_unlock();
2098 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
2099 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
2100 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
2101 unsigned int height
, width_int
;
2103 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
2104 if (needed_size
== GDI_ERROR
) {
2105 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
2108 TRACE(" - needed size : %d\n", needed_size
);
2111 if (needed_size
> size
) {
2113 HeapFree(GetProcessHeap(), 0, bitmap
);
2114 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2115 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2116 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2118 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
2120 if (TRACE_ON(wgl
)) {
2121 unsigned int height
, width
, bitmask
;
2122 unsigned char *bitmap_
= bitmap
;
2124 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
2125 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2126 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
2127 if (needed_size
!= 0) {
2128 TRACE(" - bitmap :\n");
2129 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2131 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
2136 if (*bitmap_
& bitmask
)
2141 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2147 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2148 * glyph for it to be drawn properly.
2150 if (needed_size
!= 0) {
2151 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2152 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2154 for (width
= 0; width
< width_int
; width
++) {
2155 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2156 ((int *) bitmap
)[height
* width_int
+ width
];
2162 pglNewList(listBase
++, GL_COMPILE
);
2163 if (needed_size
!= 0) {
2164 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2165 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2166 gm
.gmCellIncX
, gm
.gmCellIncY
,
2169 /* This is the case of 'empty' glyphs like the space character */
2170 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2173 wine_tsx11_unlock();
2177 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2178 wine_tsx11_unlock();
2180 HeapFree(GetProcessHeap(), 0, bitmap
);
2181 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2186 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2187 wine_tsx11_unlock();
2189 HeapFree(GetProcessHeap(), 0, bitmap
);
2190 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2195 * X11DRV_wglUseFontBitmapsA
2197 * For OpenGL32 wglUseFontBitmapsA.
2199 BOOL
X11DRV_wglUseFontBitmapsA(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
2201 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2202 Font fid
= physDev
->font
;
2204 TRACE("(%p, %d, %d, %d) using font %ld\n", dev
->hdc
, first
, count
, listBase
, fid
);
2206 if (!has_opengl()) return FALSE
;
2209 return internal_wglUseFontBitmaps(dev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2213 /* I assume that the glyphs are at the same position for X and for Windows */
2214 pglXUseXFont(fid
, first
, count
, listBase
);
2215 wine_tsx11_unlock();
2220 * X11DRV_wglUseFontBitmapsW
2222 * For OpenGL32 wglUseFontBitmapsW.
2224 BOOL
X11DRV_wglUseFontBitmapsW(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
2226 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2227 Font fid
= physDev
->font
;
2229 TRACE("(%p, %d, %d, %d) using font %ld\n", dev
->hdc
, first
, count
, listBase
, fid
);
2231 if (!has_opengl()) return FALSE
;
2234 return internal_wglUseFontBitmaps(dev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2237 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2240 /* I assume that the glyphs are at the same position for X and for Windows */
2241 pglXUseXFont(fid
, first
, count
, listBase
);
2242 wine_tsx11_unlock();
2246 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2247 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2254 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2256 pglGetIntegerv(pname
, params
);
2258 * if we cannot find a Wine Context
2259 * we only have the default wine desktop context,
2260 * so if we have only a 24 depth say we have 32
2262 if (!ctx
&& *params
== 24) {
2265 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2270 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2272 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2273 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2277 pglGetIntegerv(pname
, params
);
2280 wine_tsx11_unlock();
2283 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
2287 if (!physDev
->gl_copy
|| !physDev
->current_pf
)
2290 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
2291 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
2293 if(w
> 0 && h
> 0) {
2294 Drawable src
= physDev
->pixmap
;
2295 if(!src
) src
= physDev
->gl_drawable
;
2297 /* The GL drawable may be lagged behind if we don't flush first, so
2298 * flush the display make sure we copy up-to-date data */
2300 XFlush(gdi_display
);
2301 XSetFunction(gdi_display
, physDev
->gc
, GXcopy
);
2302 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
2303 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
2304 wine_tsx11_unlock();
2309 static void WINAPI
X11DRV_wglFinish(void)
2311 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2312 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2317 wine_tsx11_unlock();
2318 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2321 static void WINAPI
X11DRV_wglFlush(void)
2323 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2324 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2329 wine_tsx11_unlock();
2330 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2334 * X11DRV_wglCreateContextAttribsARB
2336 * WGL_ARB_create_context: wglCreateContextAttribsARB
2338 HGLRC
X11DRV_wglCreateContextAttribsARB(PHYSDEV dev
, HGLRC hShareContext
, const int* attribList
)
2340 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2341 Wine_GLContext
*ret
;
2342 WineGLPixelFormat
*fmt
;
2343 int hdcPF
= physDev
->current_pf
;
2346 TRACE("(%p %p %p)\n", physDev
, hShareContext
, attribList
);
2348 if (!has_opengl()) return 0;
2350 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
2351 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2352 * If this fails something is very wrong on the system. */
2355 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
2356 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2361 ret
= alloc_context();
2362 wine_tsx11_unlock();
2363 ret
->hdc
= dev
->hdc
;
2365 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2366 ret
->gl3_context
= TRUE
;
2368 ret
->numAttribs
= 0;
2371 int *pAttribList
= (int*)attribList
;
2372 int *pContextAttribList
= &ret
->attribList
[0];
2373 /* attribList consists of pairs {token, value] terminated with 0 */
2374 while(pAttribList
[0] != 0)
2376 TRACE("%#x %#x\n", pAttribList
[0], pAttribList
[1]);
2377 switch(pAttribList
[0])
2379 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2380 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2381 pContextAttribList
[1] = pAttribList
[1];
2383 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2384 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2385 pContextAttribList
[1] = pAttribList
[1];
2387 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2389 case WGL_CONTEXT_FLAGS_ARB
:
2390 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2391 pContextAttribList
[1] = pAttribList
[1];
2393 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2394 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2395 pContextAttribList
[1] = pAttribList
[1];
2398 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList
[0], pAttribList
[1]);
2403 pContextAttribList
+= 2;
2408 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2409 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
2411 XSync(gdi_display
, False
);
2412 if(X11DRV_check_error() || !ret
->ctx
)
2414 /* In the future we should convert the GLX error to a win32 one here if needed */
2415 ERR("Context creation failed\n");
2417 wine_tsx11_unlock();
2421 wine_tsx11_unlock();
2422 TRACE(" creating context %p\n", ret
);
2427 * X11DRV_wglGetExtensionsStringARB
2429 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2431 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2432 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2433 return WineGLInfo
.wglExtensions
;
2437 * X11DRV_wglCreatePbufferARB
2439 * WGL_ARB_pbuffer: wglCreatePbufferARB
2441 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2443 Wine_GLPBuffer
* object
= NULL
;
2444 WineGLPixelFormat
*fmt
= NULL
;
2449 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2451 if (0 >= iPixelFormat
) {
2452 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2453 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2454 return NULL
; /* unexpected error */
2457 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2458 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2460 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2461 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2462 goto create_failed
; /* unexpected error */
2465 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2466 if (NULL
== object
) {
2467 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2468 goto create_failed
; /* unexpected error */
2471 object
->display
= gdi_display
;
2472 object
->width
= iWidth
;
2473 object
->height
= iHeight
;
2476 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2477 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2478 while (piAttribList
&& 0 != *piAttribList
) {
2480 switch (*piAttribList
) {
2481 case WGL_PBUFFER_LARGEST_ARB
: {
2483 attr_v
= *piAttribList
;
2484 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2485 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2489 case WGL_TEXTURE_FORMAT_ARB
: {
2491 attr_v
= *piAttribList
;
2492 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2493 if (use_render_texture_ati
) {
2496 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2497 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2498 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2500 SetLastError(ERROR_INVALID_DATA
);
2503 object
->use_render_texture
= 1;
2504 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2506 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2507 object
->use_render_texture
= 0;
2509 if (!use_render_texture_emulation
) {
2510 SetLastError(ERROR_INVALID_DATA
);
2514 case WGL_TEXTURE_RGB_ARB
:
2515 object
->use_render_texture
= GL_RGB
;
2516 object
->texture_bpp
= 3;
2517 object
->texture_format
= GL_RGB
;
2518 object
->texture_type
= GL_UNSIGNED_BYTE
;
2520 case WGL_TEXTURE_RGBA_ARB
:
2521 object
->use_render_texture
= GL_RGBA
;
2522 object
->texture_bpp
= 4;
2523 object
->texture_format
= GL_RGBA
;
2524 object
->texture_type
= GL_UNSIGNED_BYTE
;
2527 /* WGL_FLOAT_COMPONENTS_NV */
2528 case WGL_TEXTURE_FLOAT_R_NV
:
2529 object
->use_render_texture
= GL_FLOAT_R_NV
;
2530 object
->texture_bpp
= 4;
2531 object
->texture_format
= GL_RED
;
2532 object
->texture_type
= GL_FLOAT
;
2534 case WGL_TEXTURE_FLOAT_RG_NV
:
2535 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2536 object
->texture_bpp
= 8;
2537 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2538 object
->texture_type
= GL_FLOAT
;
2540 case WGL_TEXTURE_FLOAT_RGB_NV
:
2541 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2542 object
->texture_bpp
= 12;
2543 object
->texture_format
= GL_RGB
;
2544 object
->texture_type
= GL_FLOAT
;
2546 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2547 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2548 object
->texture_bpp
= 16;
2549 object
->texture_format
= GL_RGBA
;
2550 object
->texture_type
= GL_FLOAT
;
2553 ERR("Unknown texture format: %x\n", attr_v
);
2554 SetLastError(ERROR_INVALID_DATA
);
2562 case WGL_TEXTURE_TARGET_ARB
: {
2564 attr_v
= *piAttribList
;
2565 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2566 if (use_render_texture_ati
) {
2569 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2570 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2571 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2572 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2574 SetLastError(ERROR_INVALID_DATA
);
2577 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2579 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2580 object
->texture_target
= 0;
2582 if (!use_render_texture_emulation
) {
2583 SetLastError(ERROR_INVALID_DATA
);
2587 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2588 if (iWidth
!= iHeight
) {
2589 SetLastError(ERROR_INVALID_DATA
);
2592 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2593 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2596 case WGL_TEXTURE_1D_ARB
: {
2598 SetLastError(ERROR_INVALID_DATA
);
2601 object
->texture_target
= GL_TEXTURE_1D
;
2602 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2605 case WGL_TEXTURE_2D_ARB
: {
2606 object
->texture_target
= GL_TEXTURE_2D
;
2607 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2610 case WGL_TEXTURE_RECTANGLE_NV
: {
2611 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2612 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2616 ERR("Unknown texture target: %x\n", attr_v
);
2617 SetLastError(ERROR_INVALID_DATA
);
2625 case WGL_MIPMAP_TEXTURE_ARB
: {
2627 attr_v
= *piAttribList
;
2628 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2629 if (use_render_texture_ati
) {
2630 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2632 if (!use_render_texture_emulation
) {
2633 SetLastError(ERROR_INVALID_DATA
);
2643 PUSH1(attribs
, None
);
2645 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2646 wine_tsx11_unlock();
2647 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2648 if (!object
->drawable
) {
2649 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2650 goto create_failed
; /* unexpected error */
2652 TRACE("->(%p)\n", object
);
2656 HeapFree(GetProcessHeap(), 0, object
);
2657 TRACE("->(FAILED)\n");
2662 * X11DRV_wglDestroyPbufferARB
2664 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2666 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2668 Wine_GLPBuffer
* object
= hPbuffer
;
2669 TRACE("(%p)\n", hPbuffer
);
2670 if (NULL
== object
) {
2671 SetLastError(ERROR_INVALID_HANDLE
);
2675 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2676 wine_tsx11_unlock();
2677 HeapFree(GetProcessHeap(), 0, object
);
2682 * X11DRV_wglGetPbufferDCARB
2684 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2685 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2686 * Gdi32 implements the part of this function which creates a device context.
2687 * This part associates the physDev with the X drawable of the pbuffer.
2689 HDC
X11DRV_wglGetPbufferDCARB(PHYSDEV dev
, HPBUFFERARB hPbuffer
)
2691 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2692 Wine_GLPBuffer
* object
= hPbuffer
;
2694 if (NULL
== object
) {
2695 SetLastError(ERROR_INVALID_HANDLE
);
2699 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2700 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2701 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2702 physDev
->drawable
= object
->drawable
;
2703 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2704 physDev
->dc_rect
= physDev
->drawable_rect
;
2706 TRACE("(%p)->(%p)\n", hPbuffer
, dev
->hdc
);
2711 * X11DRV_wglQueryPbufferARB
2713 * WGL_ARB_pbuffer: wglQueryPbufferARB
2715 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2717 Wine_GLPBuffer
* object
= hPbuffer
;
2718 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2719 if (NULL
== object
) {
2720 SetLastError(ERROR_INVALID_HANDLE
);
2723 switch (iAttribute
) {
2724 case WGL_PBUFFER_WIDTH_ARB
:
2726 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2727 wine_tsx11_unlock();
2729 case WGL_PBUFFER_HEIGHT_ARB
:
2731 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2732 wine_tsx11_unlock();
2735 case WGL_PBUFFER_LOST_ARB
:
2736 /* GLX Pbuffers cannot be lost by default. We can support this by
2737 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2738 * to receive pixel buffer clobber events, however that may or may
2739 * not give any benefit */
2740 *piValue
= GL_FALSE
;
2743 case WGL_TEXTURE_FORMAT_ARB
:
2744 if (use_render_texture_ati
) {
2746 int type
= WGL_NO_TEXTURE_ARB
;
2748 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2749 wine_tsx11_unlock();
2751 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2752 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2753 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2757 if (!object
->use_render_texture
) {
2758 *piValue
= WGL_NO_TEXTURE_ARB
;
2760 if (!use_render_texture_emulation
) {
2761 SetLastError(ERROR_INVALID_HANDLE
);
2764 switch(object
->use_render_texture
) {
2766 *piValue
= WGL_TEXTURE_RGB_ARB
;
2769 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2771 /* WGL_FLOAT_COMPONENTS_NV */
2773 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2775 case GL_FLOAT_RG_NV
:
2776 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2778 case GL_FLOAT_RGB_NV
:
2779 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2781 case GL_FLOAT_RGBA_NV
:
2782 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2785 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2791 case WGL_TEXTURE_TARGET_ARB
:
2792 if (use_render_texture_ati
) {
2794 int type
= WGL_NO_TEXTURE_ARB
;
2796 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2797 wine_tsx11_unlock();
2799 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2800 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2801 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2802 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2806 if (!object
->texture_target
) {
2807 *piValue
= WGL_NO_TEXTURE_ARB
;
2809 if (!use_render_texture_emulation
) {
2810 SetLastError(ERROR_INVALID_DATA
);
2813 switch (object
->texture_target
) {
2814 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2815 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2816 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2817 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2823 case WGL_MIPMAP_TEXTURE_ARB
:
2824 if (use_render_texture_ati
) {
2826 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2827 wine_tsx11_unlock();
2829 *piValue
= GL_FALSE
; /** don't support that */
2830 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2835 FIXME("unexpected attribute %x\n", iAttribute
);
2843 * X11DRV_wglReleasePbufferDCARB
2845 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2847 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2849 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2850 return DeleteDC(hdc
);
2854 * X11DRV_wglSetPbufferAttribARB
2856 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2858 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2860 Wine_GLPBuffer
* object
= hPbuffer
;
2861 GLboolean ret
= GL_FALSE
;
2863 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2864 if (NULL
== object
) {
2865 SetLastError(ERROR_INVALID_HANDLE
);
2868 if (!object
->use_render_texture
) {
2869 SetLastError(ERROR_INVALID_HANDLE
);
2872 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2875 if (NULL
!= pglXDrawableAttribATI
) {
2876 if (use_render_texture_ati
) {
2877 FIXME("Need conversion for GLX_ATI_render_texture\n");
2880 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2881 wine_tsx11_unlock();
2887 * X11DRV_wglChoosePixelFormatARB
2889 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2891 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2896 GLXFBConfig
* cfgs
= NULL
;
2900 WineGLPixelFormat
*fmt
;
2906 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2907 if (NULL
!= pfAttribFList
) {
2908 FIXME("unused pfAttribFList\n");
2911 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2912 if (-1 == nAttribs
) {
2913 WARN("Cannot convert WGL to GLX attributes\n");
2916 PUSH1(attribs
, None
);
2918 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2919 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2920 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2921 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2923 switch(piAttribIList
[i
])
2925 case WGL_DRAW_TO_BITMAP_ARB
:
2926 if(piAttribIList
[i
+1])
2927 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2929 case WGL_ACCELERATION_ARB
:
2930 switch(piAttribIList
[i
+1])
2932 case WGL_NO_ACCELERATION_ARB
:
2933 dwFlags
|= PFD_GENERIC_FORMAT
;
2935 case WGL_GENERIC_ACCELERATION_ARB
:
2936 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2938 case WGL_FULL_ACCELERATION_ARB
:
2943 case WGL_SUPPORT_GDI_ARB
:
2944 if(piAttribIList
[i
+1])
2945 dwFlags
|= PFD_SUPPORT_GDI
;
2950 /* Search for FB configurations matching the requirements in attribs */
2952 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2954 wine_tsx11_unlock();
2955 WARN("Compatible Pixel Format not found\n");
2959 /* Loop through all matching formats and check if they are suitable.
2960 * Note that this function should at max return nMaxFormats different formats */
2961 for(run
=0; run
< 2; run
++)
2963 for (it
= 0; it
< nCfgs
; ++it
) {
2964 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2966 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2970 /* Search for the format in our list of compatible formats */
2971 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2975 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2976 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2979 if(pfmt_it
< nMaxFormats
) {
2980 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2981 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2987 *nNumFormats
= pfmt_it
;
2990 wine_tsx11_unlock();
2995 * X11DRV_wglGetPixelFormatAttribivARB
2997 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2999 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
3002 WineGLPixelFormat
*fmt
= NULL
;
3006 int nWGLFormats
= 0;
3008 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
3010 if (0 < iLayerPlane
) {
3011 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
3015 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
3016 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
3017 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
3018 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
3020 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
3024 for (i
= 0; i
< nAttributes
; ++i
) {
3025 const int curWGLAttr
= piAttributes
[i
];
3026 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
3028 switch (curWGLAttr
) {
3029 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
3030 piValues
[i
] = nWGLFormats
;
3033 case WGL_SUPPORT_OPENGL_ARB
:
3034 piValues
[i
] = GL_TRUE
;
3037 case WGL_ACCELERATION_ARB
:
3038 curGLXAttr
= GLX_CONFIG_CAVEAT
;
3039 if (!fmt
) goto pix_error
;
3040 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
3041 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
3042 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
3043 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
3045 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
3048 case WGL_TRANSPARENT_ARB
:
3049 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
3050 if (!fmt
) goto pix_error
;
3051 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3052 if (hTest
) goto get_error
;
3053 piValues
[i
] = GL_FALSE
;
3054 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
3057 case WGL_PIXEL_TYPE_ARB
:
3058 curGLXAttr
= GLX_RENDER_TYPE
;
3059 if (!fmt
) goto pix_error
;
3060 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3061 if (hTest
) goto get_error
;
3062 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
3063 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
3064 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
3065 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
3066 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
3067 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
3069 ERR("unexpected RenderType(%x)\n", tmp
);
3070 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
3074 case WGL_COLOR_BITS_ARB
:
3075 curGLXAttr
= GLX_BUFFER_SIZE
;
3078 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
3079 if (use_render_texture_ati
) {
3080 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
3083 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
3084 if (use_render_texture_ati
) {
3085 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
3088 if (!use_render_texture_emulation
) {
3089 piValues
[i
] = GL_FALSE
;
3092 curGLXAttr
= GLX_RENDER_TYPE
;
3093 if (!fmt
) goto pix_error
;
3094 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3095 if (hTest
) goto get_error
;
3096 if (GLX_COLOR_INDEX_BIT
== tmp
) {
3097 piValues
[i
] = GL_FALSE
;
3100 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3101 if (hTest
) goto get_error
;
3102 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
3105 case WGL_BLUE_BITS_ARB
:
3106 curGLXAttr
= GLX_BLUE_SIZE
;
3108 case WGL_RED_BITS_ARB
:
3109 curGLXAttr
= GLX_RED_SIZE
;
3111 case WGL_GREEN_BITS_ARB
:
3112 curGLXAttr
= GLX_GREEN_SIZE
;
3114 case WGL_ALPHA_BITS_ARB
:
3115 curGLXAttr
= GLX_ALPHA_SIZE
;
3117 case WGL_DEPTH_BITS_ARB
:
3118 curGLXAttr
= GLX_DEPTH_SIZE
;
3120 case WGL_STENCIL_BITS_ARB
:
3121 curGLXAttr
= GLX_STENCIL_SIZE
;
3123 case WGL_DOUBLE_BUFFER_ARB
:
3124 curGLXAttr
= GLX_DOUBLEBUFFER
;
3126 case WGL_STEREO_ARB
:
3127 curGLXAttr
= GLX_STEREO
;
3129 case WGL_AUX_BUFFERS_ARB
:
3130 curGLXAttr
= GLX_AUX_BUFFERS
;
3133 case WGL_SUPPORT_GDI_ARB
:
3134 if (!fmt
) goto pix_error
;
3135 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
3138 case WGL_DRAW_TO_BITMAP_ARB
:
3139 if (!fmt
) goto pix_error
;
3140 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
3143 case WGL_DRAW_TO_WINDOW_ARB
:
3144 case WGL_DRAW_TO_PBUFFER_ARB
:
3145 if (!fmt
) goto pix_error
;
3146 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3147 if (hTest
) goto get_error
;
3148 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
3149 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
3150 piValues
[i
] = GL_TRUE
;
3152 piValues
[i
] = GL_FALSE
;
3155 case WGL_SWAP_METHOD_ARB
:
3156 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3157 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3158 * point only ATI offers this.
3160 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
3163 case WGL_PBUFFER_LARGEST_ARB
:
3164 curGLXAttr
= GLX_LARGEST_PBUFFER
;
3167 case WGL_SAMPLE_BUFFERS_ARB
:
3168 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
3171 case WGL_SAMPLES_ARB
:
3172 curGLXAttr
= GLX_SAMPLES_ARB
;
3175 case WGL_FLOAT_COMPONENTS_NV
:
3176 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
3179 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
3180 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
3183 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
3184 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
3187 case WGL_ACCUM_RED_BITS_ARB
:
3188 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
3190 case WGL_ACCUM_GREEN_BITS_ARB
:
3191 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
3193 case WGL_ACCUM_BLUE_BITS_ARB
:
3194 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
3196 case WGL_ACCUM_ALPHA_BITS_ARB
:
3197 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
3199 case WGL_ACCUM_BITS_ARB
:
3200 if (!fmt
) goto pix_error
;
3201 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
3202 if (hTest
) goto get_error
;
3204 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
3205 if (hTest
) goto get_error
;
3207 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
3208 if (hTest
) goto get_error
;
3210 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
3211 if (hTest
) goto get_error
;
3216 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
3219 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3220 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3221 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3223 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3224 * and check which options can work using iPixelFormat=0 and which not.
3225 * A problem would be that this function is an extension. This would
3226 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3228 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
3229 if (!fmt
) goto pix_error
;
3230 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
3231 if (hTest
) goto get_error
;
3234 piValues
[i
] = GL_FALSE
;
3237 wine_tsx11_unlock();
3241 wine_tsx11_unlock();
3242 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3246 wine_tsx11_unlock();
3247 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3252 * X11DRV_wglGetPixelFormatAttribfvARB
3254 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3256 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3262 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3264 /* Allocate a temporary array to store integer values */
3265 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3267 ERR("couldn't allocate %d array\n", nAttributes
);
3271 /* Piggy-back on wglGetPixelFormatAttribivARB */
3272 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3274 /* Convert integer values to float. Should also check for attributes
3275 that can give decimal values here */
3276 for (i
=0; i
<nAttributes
;i
++) {
3277 pfValues
[i
] = attr
[i
];
3281 HeapFree(GetProcessHeap(), 0, attr
);
3286 * X11DRV_wglBindTexImageARB
3288 * WGL_ARB_render_texture: wglBindTexImageARB
3290 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3292 Wine_GLPBuffer
* object
= hPbuffer
;
3293 GLboolean ret
= GL_FALSE
;
3295 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3296 if (NULL
== object
) {
3297 SetLastError(ERROR_INVALID_HANDLE
);
3300 if (!object
->use_render_texture
) {
3301 SetLastError(ERROR_INVALID_HANDLE
);
3305 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3306 static int init
= 0;
3307 int prev_binded_texture
= 0;
3308 GLXContext prev_context
;
3309 Drawable prev_drawable
;
3310 GLXContext tmp_context
;
3313 prev_context
= pglXGetCurrentContext();
3314 prev_drawable
= pglXGetCurrentDrawable();
3316 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3317 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3318 isn't ideal performance wise but I wasn't able to get other ways working.
3321 init
= 1; /* Only show the FIXME once for performance reasons */
3322 FIXME("partial stub!\n");
3325 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
3326 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3328 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3330 /* Switch to our pbuffer */
3331 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3333 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3334 * After that upload the pbuffer texture data. */
3335 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3336 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3338 /* Switch back to the original drawable and upload the pbuffer-texture */
3339 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3340 pglXDestroyContext(gdi_display
, tmp_context
);
3341 wine_tsx11_unlock();
3345 if (NULL
!= pglXBindTexImageATI
) {
3350 case WGL_FRONT_LEFT_ARB
:
3351 buffer
= GLX_FRONT_LEFT_ATI
;
3353 case WGL_FRONT_RIGHT_ARB
:
3354 buffer
= GLX_FRONT_RIGHT_ATI
;
3356 case WGL_BACK_LEFT_ARB
:
3357 buffer
= GLX_BACK_LEFT_ATI
;
3359 case WGL_BACK_RIGHT_ARB
:
3360 buffer
= GLX_BACK_RIGHT_ATI
;
3363 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3367 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3368 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3369 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3370 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3371 * works fine using our pbuffer emulation path.
3374 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3375 wine_tsx11_unlock();
3381 * X11DRV_wglReleaseTexImageARB
3383 * WGL_ARB_render_texture: wglReleaseTexImageARB
3385 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3387 Wine_GLPBuffer
* object
= hPbuffer
;
3388 GLboolean ret
= GL_FALSE
;
3390 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3391 if (NULL
== object
) {
3392 SetLastError(ERROR_INVALID_HANDLE
);
3395 if (!object
->use_render_texture
) {
3396 SetLastError(ERROR_INVALID_HANDLE
);
3399 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3402 if (NULL
!= pglXReleaseTexImageATI
) {
3407 case WGL_FRONT_LEFT_ARB
:
3408 buffer
= GLX_FRONT_LEFT_ATI
;
3410 case WGL_FRONT_RIGHT_ARB
:
3411 buffer
= GLX_FRONT_RIGHT_ATI
;
3413 case WGL_BACK_LEFT_ARB
:
3414 buffer
= GLX_BACK_LEFT_ATI
;
3416 case WGL_BACK_RIGHT_ARB
:
3417 buffer
= GLX_BACK_RIGHT_ATI
;
3420 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3424 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3425 wine_tsx11_unlock();
3431 * X11DRV_wglGetExtensionsStringEXT
3433 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3435 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3436 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3437 return WineGLInfo
.wglExtensions
;
3441 * X11DRV_wglGetSwapIntervalEXT
3443 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3445 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3446 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
3447 * interval, so the swap interval has to be tracked. */
3449 return swap_interval
;
3453 * X11DRV_wglSwapIntervalEXT
3455 * WGL_EXT_swap_control: wglSwapIntervalEXT
3457 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3460 TRACE("(%d)\n", interval
);
3464 SetLastError(ERROR_INVALID_DATA
);
3467 else if (!has_swap_control
&& interval
== 0)
3469 /* wglSwapIntervalEXT considers an interval value of zero to mean that
3470 * vsync should be disabled, but glXSwapIntervalSGI considers such a
3471 * value to be an error. Just silently ignore the request for now. */
3472 WARN("Request to disable vertical sync is not handled\n");
3477 if (pglXSwapIntervalSGI
)
3480 ret
= !pglXSwapIntervalSGI(interval
);
3481 wine_tsx11_unlock();
3484 WARN("GLX_SGI_swap_control extension is not available\n");
3487 swap_interval
= interval
;
3489 SetLastError(ERROR_DC_NOT_FOUND
);
3496 * X11DRV_wglAllocateMemoryNV
3498 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3500 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3502 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3504 if (pglXAllocateMemoryNV
)
3507 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3508 wine_tsx11_unlock();
3514 * X11DRV_wglFreeMemoryNV
3516 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3518 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3519 TRACE("(%p)\n", pointer
);
3520 if (pglXFreeMemoryNV
== NULL
)
3524 pglXFreeMemoryNV(pointer
);
3525 wine_tsx11_unlock();
3529 * X11DRV_wglSetPixelFormatWINE
3531 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3532 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3534 BOOL
X11DRV_wglSetPixelFormatWINE(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3536 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3538 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
3540 if (!has_opengl()) return FALSE
;
3542 if (physDev
->current_pf
== iPixelFormat
) return TRUE
;
3544 /* Relay to the core SetPixelFormat */
3545 TRACE("Changing iPixelFormat from %d to %d\n", physDev
->current_pf
, iPixelFormat
);
3546 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
3550 * glxRequireVersion (internal)
3552 * Check if the supported GLX version matches requiredVersion.
3554 static BOOL
glxRequireVersion(int requiredVersion
)
3556 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3557 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3563 static BOOL
glxRequireExtension(const char *requiredExtension
)
3565 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3572 static void register_extension_string(const char *ext
)
3574 if (WineGLInfo
.wglExtensions
[0])
3575 strcat(WineGLInfo
.wglExtensions
, " ");
3576 strcat(WineGLInfo
.wglExtensions
, ext
);
3578 TRACE("'%s'\n", ext
);
3581 static BOOL
register_extension(const WineGLExtension
* ext
)
3585 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3586 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3588 register_extension_string(ext
->extName
);
3590 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3591 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3596 static const WineGLExtension WGL_internal_functions
=
3600 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3601 { "wglFinish", X11DRV_wglFinish
},
3602 { "wglFlush", X11DRV_wglFlush
},
3607 static const WineGLExtension WGL_ARB_create_context
=
3609 "WGL_ARB_create_context",
3611 { "wglCreateContextAttribsARB", X11DRV_wglCreateContextAttribsARB
},
3615 static const WineGLExtension WGL_ARB_extensions_string
=
3617 "WGL_ARB_extensions_string",
3619 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3623 static const WineGLExtension WGL_ARB_make_current_read
=
3625 "WGL_ARB_make_current_read",
3627 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3628 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3632 static const WineGLExtension WGL_ARB_multisample
=
3634 "WGL_ARB_multisample",
3637 static const WineGLExtension WGL_ARB_pbuffer
=
3641 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3642 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3643 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3644 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3645 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3646 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3650 static const WineGLExtension WGL_ARB_pixel_format
=
3652 "WGL_ARB_pixel_format",
3654 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3655 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3656 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3660 static const WineGLExtension WGL_ARB_render_texture
=
3662 "WGL_ARB_render_texture",
3664 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3665 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3669 static const WineGLExtension WGL_EXT_extensions_string
=
3671 "WGL_EXT_extensions_string",
3673 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3677 static const WineGLExtension WGL_EXT_swap_control
=
3679 "WGL_EXT_swap_control",
3681 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3682 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3686 static const WineGLExtension WGL_NV_vertex_array_range
=
3688 "WGL_NV_vertex_array_range",
3690 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3691 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3695 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3697 "WGL_WINE_pixel_format_passthrough",
3699 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE
},
3704 * X11DRV_WineGL_LoadExtensions
3706 static void X11DRV_WineGL_LoadExtensions(void)
3708 WineGLInfo
.wglExtensions
[0] = 0;
3710 /* Load Wine internal functions */
3711 register_extension(&WGL_internal_functions
);
3713 /* ARB Extensions */
3715 if(glxRequireExtension("GLX_ARB_create_context"))
3717 register_extension(&WGL_ARB_create_context
);
3719 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3720 register_extension_string("WGL_ARB_create_context_profile");
3723 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3725 register_extension_string("WGL_ARB_pixel_format_float");
3726 register_extension_string("WGL_ATI_pixel_format_float");
3729 register_extension(&WGL_ARB_extensions_string
);
3731 if (glxRequireVersion(3))
3732 register_extension(&WGL_ARB_make_current_read
);
3734 if (glxRequireExtension("GLX_ARB_multisample"))
3735 register_extension(&WGL_ARB_multisample
);
3737 /* In general pbuffer functionality requires support in the X-server. The functionality is
3738 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3739 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3740 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3742 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3743 * without support in the X-server (which other Mesa based drivers require).
3745 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3746 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3747 * is available pbuffers must be available too. */
3748 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3749 register_extension(&WGL_ARB_pbuffer
);
3751 register_extension(&WGL_ARB_pixel_format
);
3753 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3754 if (glxRequireExtension("GLX_ATI_render_texture") ||
3755 glxRequireExtension("GLX_ARB_render_texture") ||
3756 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3758 register_extension(&WGL_ARB_render_texture
);
3760 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3761 if(glxRequireExtension("GLX_NV_float_buffer"))
3762 register_extension_string("WGL_NV_float_buffer");
3764 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3765 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3766 register_extension_string("WGL_NV_texture_rectangle");
3769 /* EXT Extensions */
3771 register_extension(&WGL_EXT_extensions_string
);
3773 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3774 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3775 register_extension(&WGL_EXT_swap_control
);
3777 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3778 register_extension_string("WGL_EXT_framebuffer_sRGB");
3780 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3781 register_extension_string("WGL_EXT_pixel_format_packed_float");
3783 if (glxRequireExtension("GLX_EXT_swap_control"))
3784 has_swap_control
= TRUE
;
3786 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3787 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3788 register_extension(&WGL_NV_vertex_array_range
);
3790 /* WINE-specific WGL Extensions */
3792 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3793 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3795 register_extension(&WGL_WINE_pixel_format_passthrough
);
3799 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3805 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3806 ret
= physDev
->drawable
; /* PBuffer */
3808 ret
= physDev
->bitmap
->glxpixmap
;
3810 else if(physDev
->gl_drawable
)
3811 ret
= physDev
->gl_drawable
;
3813 ret
= physDev
->drawable
;
3817 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3820 pglXDestroyGLXPixmap(display
, glxpixmap
);
3821 wine_tsx11_unlock();
3826 * X11DRV_SwapBuffers
3828 * Swap the buffers of this DC
3830 BOOL
X11DRV_SwapBuffers(PHYSDEV dev
)
3832 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3833 GLXDrawable drawable
;
3834 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3836 if (!has_opengl()) return FALSE
;
3838 TRACE("(%p)\n", physDev
);
3842 WARN("Using a NULL context, skipping\n");
3843 SetLastError(ERROR_INVALID_HANDLE
);
3847 if (!physDev
->current_pf
)
3849 WARN("Using an invalid drawable, skipping\n");
3850 SetLastError(ERROR_INVALID_HANDLE
);
3854 drawable
= get_glxdrawable(physDev
);
3858 if(physDev
->pixmap
) {
3859 if(pglXCopySubBufferMESA
) {
3860 int w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
3861 int h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
3863 /* (glX)SwapBuffers has an implicit glFlush effect, however
3864 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3868 pglXCopySubBufferMESA(gdi_display
, drawable
, 0, 0, w
, h
);
3871 pglXSwapBuffers(gdi_display
, drawable
);
3874 pglXSwapBuffers(gdi_display
, drawable
);
3876 flush_gl_drawable(physDev
);
3877 wine_tsx11_unlock();
3882 static long prev_time
, start_time
;
3883 static unsigned long frames
, frames_total
;
3885 DWORD time
= GetTickCount();
3888 /* every 1.5 seconds */
3889 if (time
- prev_time
> 1500) {
3890 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3891 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3894 if(start_time
== 0) start_time
= time
;
3901 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3903 WineGLPixelFormat
*fmt
;
3906 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3911 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3912 wine_tsx11_unlock();
3916 #else /* no OpenGL includes */
3918 void X11DRV_OpenGL_Cleanup(void)
3922 static inline void opengl_error(void)
3925 if (!warned
++) ERR("No OpenGL support compiled in.\n");
3928 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3933 void mark_drawable_dirty(Drawable old
, Drawable
new)
3937 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
3941 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3946 /***********************************************************************
3947 * ChoosePixelFormat (X11DRV.@)
3949 int X11DRV_ChoosePixelFormat(PHYSDEV dev
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3955 /***********************************************************************
3956 * DescribePixelFormat (X11DRV.@)
3958 int X11DRV_DescribePixelFormat(PHYSDEV dev
, int iPixelFormat
, UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
3964 /***********************************************************************
3965 * GetPixelFormat (X11DRV.@)
3967 int X11DRV_GetPixelFormat(PHYSDEV dev
)
3973 /***********************************************************************
3974 * SetPixelFormat (X11DRV.@)
3976 BOOL
X11DRV_SetPixelFormat(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3982 /***********************************************************************
3983 * SwapBuffers (X11DRV.@)
3985 BOOL
X11DRV_SwapBuffers(PHYSDEV dev
)
3992 * X11DRV_wglCopyContext
3994 * For OpenGL32 wglCopyContext.
3996 BOOL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
4003 * X11DRV_wglCreateContext
4005 * For OpenGL32 wglCreateContext.
4007 HGLRC
X11DRV_wglCreateContext(PHYSDEV dev
)
4014 * X11DRV_wglCreateContextAttribsARB
4016 * WGL_ARB_create_context: wglCreateContextAttribsARB
4018 HGLRC
X11DRV_wglCreateContextAttribsARB(PHYSDEV dev
, HGLRC hShareContext
, const int* attribList
)
4025 * X11DRV_wglDeleteContext
4027 * For OpenGL32 wglDeleteContext.
4029 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
4036 * X11DRV_wglGetProcAddress
4038 * For OpenGL32 wglGetProcAddress.
4040 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
4046 HDC
X11DRV_wglGetPbufferDCARB(PHYSDEV dev
, void *hPbuffer
)
4052 BOOL
X11DRV_wglMakeContextCurrentARB(PHYSDEV draw_dev
, PHYSDEV read_dev
, HGLRC hglrc
)
4059 * X11DRV_wglMakeCurrent
4061 * For OpenGL32 wglMakeCurrent.
4063 BOOL
X11DRV_wglMakeCurrent(PHYSDEV dev
, HGLRC hglrc
)
4070 * X11DRV_wglShareLists
4072 * For OpenGL32 wglShareLists.
4074 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
4081 * X11DRV_wglUseFontBitmapsA
4083 * For OpenGL32 wglUseFontBitmapsA.
4085 BOOL
X11DRV_wglUseFontBitmapsA(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
4092 * X11DRV_wglUseFontBitmapsW
4094 * For OpenGL32 wglUseFontBitmapsW.
4096 BOOL
X11DRV_wglUseFontBitmapsW(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
4103 * X11DRV_wglSetPixelFormatWINE
4105 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
4106 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
4108 BOOL
X11DRV_wglSetPixelFormatWINE(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
4114 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
4119 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
4124 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
4129 #endif /* defined(SONAME_LIBGL) */