2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
41 #include "wine/library.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
48 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
67 /* Redefines the constants */
68 #define CALLBACK __stdcall
69 #define WINAPI __stdcall
70 #define APIENTRY WINAPI
73 WINE_DECLARE_DEBUG_CHANNEL(fps
);
75 typedef struct wine_glextension
{
84 const char *glVersion
;
89 const char *glxServerVersion
;
90 const char *glxServerVendor
;
91 const char *glxServerExtensions
;
93 const char *glxClientVersion
;
94 const char *glxClientVendor
;
95 const char *glxClientExtensions
;
97 const char *glxExtensions
;
100 char wglExtensions
[4096];
103 typedef struct wine_glpixelformat
{
105 GLXFBConfig fbconfig
;
109 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
112 typedef struct wine_glcontext
{
114 BOOL has_been_current
;
119 WineGLPixelFormat
*fmt
;
120 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
121 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
124 Drawable drawables
[2];
125 BOOL refresh_drawables
;
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
)
238 MAKE_FUNCPTR(glXGetClientString
)
239 MAKE_FUNCPTR(glXQueryExtensionsString
)
240 MAKE_FUNCPTR(glXQueryServerString
)
243 MAKE_FUNCPTR(glXGetFBConfigs
)
244 MAKE_FUNCPTR(glXChooseFBConfig
)
245 MAKE_FUNCPTR(glXCreatePbuffer
)
246 MAKE_FUNCPTR(glXCreateNewContext
)
247 MAKE_FUNCPTR(glXDestroyPbuffer
)
248 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
249 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
250 MAKE_FUNCPTR(glXMakeContextCurrent
)
251 MAKE_FUNCPTR(glXQueryDrawable
)
252 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
255 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
256 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
257 static int (*pglXSwapIntervalSGI
)(int);
259 /* ATI GLX Extensions */
260 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
261 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
262 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
264 /* NV GLX Extension */
265 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
266 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
268 /* MESA GLX Extensions */
269 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
271 /* Standard OpenGL */
272 MAKE_FUNCPTR(glBindTexture
)
273 MAKE_FUNCPTR(glBitmap
)
274 MAKE_FUNCPTR(glCopyTexSubImage1D
)
275 MAKE_FUNCPTR(glCopyTexImage2D
)
276 MAKE_FUNCPTR(glCopyTexSubImage2D
)
277 MAKE_FUNCPTR(glDrawBuffer
)
278 MAKE_FUNCPTR(glEndList
)
279 MAKE_FUNCPTR(glGetError
)
280 MAKE_FUNCPTR(glGetIntegerv
)
281 MAKE_FUNCPTR(glGetString
)
282 MAKE_FUNCPTR(glNewList
)
283 MAKE_FUNCPTR(glPixelStorei
)
284 MAKE_FUNCPTR(glReadPixels
)
285 MAKE_FUNCPTR(glTexImage2D
)
286 MAKE_FUNCPTR(glFinish
)
287 MAKE_FUNCPTR(glFlush
)
290 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
292 /* In the future we might want to find the exact X or GLX error to report back to the app */
296 static BOOL infoInitialized
= FALSE
;
297 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
299 int screen
= DefaultScreen(gdi_display
);
300 Window win
= 0, root
= 0;
301 const char *gl_renderer
;
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 gl_renderer
= (const char *)pglGetString(GL_RENDERER
);
353 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
354 str
= (const char *) pglGetString(GL_EXTENSIONS
);
355 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
356 strcpy(WineGLInfo
.glExtensions
, str
);
358 /* Get the common GLX version supported by GLX client and server ( major/minor) */
359 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
361 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
362 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
363 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
365 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
366 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
367 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
369 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
370 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
372 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
373 TRACE("GL renderer : %s.\n", gl_renderer
);
374 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
375 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
376 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
377 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
378 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
379 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
381 if(!WineGLInfo
.glxDirect
)
383 int fd
= ConnectionNumber(gdi_display
);
384 struct sockaddr_un uaddr
;
385 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
387 /* In general indirect rendering on a local X11 server indicates a driver problem.
388 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
390 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
391 ERR_(winediag
)("Direct rendering is disabled, most likely your OpenGL drivers "
392 "haven't been installed correctly (using GL renderer %s, version %s).\n",
393 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
397 /* In general you would expect that if direct rendering is returned, that you receive hardware
398 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
399 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
400 * software rendering, it shows direct rendering.
402 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
403 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
404 * it shows 'Mesa X11'.
406 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
407 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
408 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
409 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
416 pglXMakeCurrent(gdi_display
, None
, NULL
);
417 pglXDestroyContext(gdi_display
, ctx
);
419 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
420 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
422 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
426 void X11DRV_OpenGL_Cleanup(void)
428 HeapFree(GetProcessHeap(), 0, WineGLInfo
.glExtensions
);
429 infoInitialized
= FALSE
;
432 static BOOL
has_opengl(void)
434 static int init_done
;
435 static void *opengl_handle
;
438 int error_base
, event_base
;
440 if (init_done
) return (opengl_handle
!= NULL
);
443 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
444 and include all dependencies */
445 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
446 if (opengl_handle
== NULL
)
448 ERR( "Failed to load libGL: %s\n", buffer
);
449 ERR( "OpenGL support is disabled.\n");
453 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
454 if (pglXGetProcAddressARB
== NULL
) {
455 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
459 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
461 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
466 LOAD_FUNCPTR(glXChooseVisual
);
467 LOAD_FUNCPTR(glXCopyContext
);
468 LOAD_FUNCPTR(glXCreateContext
);
469 LOAD_FUNCPTR(glXCreateGLXPixmap
);
470 LOAD_FUNCPTR(glXGetCurrentContext
);
471 LOAD_FUNCPTR(glXGetCurrentDrawable
);
472 LOAD_FUNCPTR(glXDestroyContext
);
473 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
474 LOAD_FUNCPTR(glXGetConfig
);
475 LOAD_FUNCPTR(glXIsDirect
);
476 LOAD_FUNCPTR(glXMakeCurrent
);
477 LOAD_FUNCPTR(glXSwapBuffers
);
478 LOAD_FUNCPTR(glXQueryExtension
);
479 LOAD_FUNCPTR(glXQueryVersion
);
482 LOAD_FUNCPTR(glXGetClientString
);
483 LOAD_FUNCPTR(glXQueryExtensionsString
);
484 LOAD_FUNCPTR(glXQueryServerString
);
487 LOAD_FUNCPTR(glXCreatePbuffer
);
488 LOAD_FUNCPTR(glXCreateNewContext
);
489 LOAD_FUNCPTR(glXDestroyPbuffer
);
490 LOAD_FUNCPTR(glXMakeContextCurrent
);
491 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
492 LOAD_FUNCPTR(glXGetFBConfigs
);
494 /* Standard OpenGL calls */
495 LOAD_FUNCPTR(glBindTexture
);
496 LOAD_FUNCPTR(glBitmap
);
497 LOAD_FUNCPTR(glCopyTexSubImage1D
);
498 LOAD_FUNCPTR(glCopyTexImage2D
);
499 LOAD_FUNCPTR(glCopyTexSubImage2D
);
500 LOAD_FUNCPTR(glDrawBuffer
);
501 LOAD_FUNCPTR(glEndList
);
502 LOAD_FUNCPTR(glGetError
);
503 LOAD_FUNCPTR(glGetIntegerv
);
504 LOAD_FUNCPTR(glGetString
);
505 LOAD_FUNCPTR(glNewList
);
506 LOAD_FUNCPTR(glPixelStorei
);
507 LOAD_FUNCPTR(glReadPixels
);
508 LOAD_FUNCPTR(glTexImage2D
);
509 LOAD_FUNCPTR(glFinish
);
510 LOAD_FUNCPTR(glFlush
);
513 /* It doesn't matter if these fail. They'll only be used if the driver reports
514 the associated extension is available (and if a driver reports the extension
515 is available but fails to provide the functions, it's quite broken) */
516 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
517 /* ARB GLX Extension */
518 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
519 /* SGI GLX Extension */
520 LOAD_FUNCPTR(glXSwapIntervalSGI
);
521 /* NV GLX Extension */
522 LOAD_FUNCPTR(glXAllocateMemoryNV
);
523 LOAD_FUNCPTR(glXFreeMemoryNV
);
526 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
529 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
530 TRACE("GLX is up and running error_base = %d\n", error_base
);
533 ERR( "GLX extension is missing, disabling OpenGL.\n" );
537 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
538 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
541 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
542 * depends on the reported GLX client / server version and on the client / server extension list.
543 * Those don't have to be the same.
545 * In general the server GLX information lists the capabilities in case of indirect rendering.
546 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
547 * available and in that case the client GLX informat can be used.
548 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
549 * in the GLX version/extension list. When a program does this it works for certain for both
550 * direct and indirect rendering.
552 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
553 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
554 * extension list which causes this extension not to be listed. (Wine requires this extension).
555 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
556 * pbuffers is around.
558 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
559 * the ATI drivers and from then on use GLX client information for them.
562 if(glxRequireVersion(3)) {
563 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
564 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
565 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
566 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
567 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
568 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
569 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
570 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
572 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
573 * enable this function when the Xserver understand GLX 1.3 or newer
575 pglXQueryDrawable
= NULL
;
576 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
577 TRACE("Overriding ATI GLX capabilities!\n");
578 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
579 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
580 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
581 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
583 /* Use client GLX information in case of the ATI drivers. We override the
584 * capabilities over here and not somewhere else as ATI might better their
585 * life in the future. In case they release proper drivers this block of
586 * code won't be called. */
587 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
589 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
592 if(glxRequireExtension("GLX_ATI_render_texture")) {
593 use_render_texture_ati
= 1;
594 pglXBindTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
595 pglXReleaseTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
596 pglXDrawableAttribATI
= pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
599 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
600 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
603 X11DRV_WineGL_LoadExtensions();
609 wine_dlclose(opengl_handle
, NULL
, 0);
610 opengl_handle
= NULL
;
614 static inline Wine_GLContext
*alloc_context(void)
618 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
620 ret
->next
= context_list
;
621 if (context_list
) context_list
->prev
= ret
;
627 static inline void free_context(Wine_GLContext
*context
)
629 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
630 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
631 else context_list
= context
->next
;
633 if (context
->vis
) XFree(context
->vis
);
634 HeapFree(GetProcessHeap(), 0, context
);
637 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
640 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
641 return (ptr
!= NULL
);
644 static int describeContext(Wine_GLContext
* ctx
) {
647 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
648 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
649 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
650 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
651 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
656 static BOOL
describeDrawable(X11DRV_PDEVICE
*physDev
) {
658 WineGLPixelFormat
*fmt
;
661 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
/* Offscreen */, &fmt_count
);
662 if(!fmt
) return FALSE
;
664 TRACE(" HDC %p has:\n", physDev
->dev
.hdc
);
665 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
666 TRACE(" - Drawable %lx\n", physDev
->gl_drawable
);
667 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
669 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
670 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
675 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
680 int nvfloatattrib
= GLX_DONT_CARE
;
681 int pixelattrib
= GLX_DONT_CARE
;
683 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
684 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
685 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
686 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
688 switch (iWGLAttr
[cur
]) {
689 case WGL_AUX_BUFFERS_ARB
:
690 pop
= iWGLAttr
[++cur
];
691 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
692 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
694 case WGL_COLOR_BITS_ARB
:
695 pop
= iWGLAttr
[++cur
];
696 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
697 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
699 case WGL_BLUE_BITS_ARB
:
700 pop
= iWGLAttr
[++cur
];
701 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
702 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
704 case WGL_RED_BITS_ARB
:
705 pop
= iWGLAttr
[++cur
];
706 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
707 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
709 case WGL_GREEN_BITS_ARB
:
710 pop
= iWGLAttr
[++cur
];
711 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
712 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
714 case WGL_ALPHA_BITS_ARB
:
715 pop
= iWGLAttr
[++cur
];
716 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
717 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
719 case WGL_DEPTH_BITS_ARB
:
720 pop
= iWGLAttr
[++cur
];
721 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
722 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
724 case WGL_STENCIL_BITS_ARB
:
725 pop
= iWGLAttr
[++cur
];
726 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
727 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
729 case WGL_DOUBLE_BUFFER_ARB
:
730 pop
= iWGLAttr
[++cur
];
731 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
732 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
735 pop
= iWGLAttr
[++cur
];
736 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
737 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
740 case WGL_PIXEL_TYPE_ARB
:
741 pop
= iWGLAttr
[++cur
];
742 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
744 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
745 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
746 /* 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 */
747 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
748 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
750 ERR("unexpected PixelType(%x)\n", pop
);
755 case WGL_SUPPORT_GDI_ARB
:
756 /* This flag is set in a WineGLPixelFormat */
757 pop
= iWGLAttr
[++cur
];
758 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
761 case WGL_DRAW_TO_BITMAP_ARB
:
762 /* This flag is set in a WineGLPixelFormat */
763 pop
= iWGLAttr
[++cur
];
764 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
767 case WGL_DRAW_TO_WINDOW_ARB
:
768 pop
= iWGLAttr
[++cur
];
769 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
770 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
772 drawattrib
|= GLX_WINDOW_BIT
;
776 case WGL_DRAW_TO_PBUFFER_ARB
:
777 pop
= iWGLAttr
[++cur
];
778 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
779 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
781 drawattrib
|= GLX_PBUFFER_BIT
;
785 case WGL_ACCELERATION_ARB
:
786 /* This flag is set in a WineGLPixelFormat */
787 pop
= iWGLAttr
[++cur
];
788 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
791 case WGL_SUPPORT_OPENGL_ARB
:
792 pop
= iWGLAttr
[++cur
];
793 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
794 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
797 case WGL_SWAP_METHOD_ARB
:
798 pop
= iWGLAttr
[++cur
];
799 /* For now we ignore this and just return SWAP_EXCHANGE */
800 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
803 case WGL_PBUFFER_LARGEST_ARB
:
804 pop
= iWGLAttr
[++cur
];
805 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
806 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
809 case WGL_SAMPLE_BUFFERS_ARB
:
810 pop
= iWGLAttr
[++cur
];
811 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
812 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
815 case WGL_SAMPLES_ARB
:
816 pop
= iWGLAttr
[++cur
];
817 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
818 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
821 case WGL_TEXTURE_FORMAT_ARB
:
822 case WGL_TEXTURE_TARGET_ARB
:
823 case WGL_MIPMAP_TEXTURE_ARB
:
824 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
825 pop
= iWGLAttr
[++cur
];
827 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
829 if (use_render_texture_ati
) {
830 /** nothing to do here */
832 else if (!use_render_texture_emulation
) {
833 if (WGL_NO_TEXTURE_ARB
!= pop
) {
834 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
835 return -1; /** error: don't support it */
837 drawattrib
|= GLX_PBUFFER_BIT
;
841 case WGL_FLOAT_COMPONENTS_NV
:
842 nvfloatattrib
= iWGLAttr
[++cur
];
843 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
845 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
846 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
847 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
848 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
849 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
850 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
851 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
852 pop
= iWGLAttr
[++cur
];
853 /** cannot be converted, see direct handling on
854 * - wglGetPixelFormatAttribivARB
855 * TODO: wglChoosePixelFormat
858 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
859 pop
= iWGLAttr
[++cur
];
860 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
861 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
864 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
865 pop
= iWGLAttr
[++cur
];
866 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
867 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
870 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
876 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
877 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
878 * pixmap and pbuffer formats appear as well. */
879 if (!drawattrib
) drawattrib
= GLX_DONT_CARE
;
880 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
881 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
883 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
884 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
885 * GLX_DONT_CARE unless it is overridden. */
886 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
887 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
889 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
890 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
891 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
892 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
898 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
900 int render_type
=0, render_type_bit
;
901 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
902 switch(render_type_bit
)
905 render_type
= GLX_RGBA_TYPE
;
907 case GLX_COLOR_INDEX_BIT
:
908 render_type
= GLX_COLOR_INDEX_TYPE
;
910 case GLX_RGBA_FLOAT_BIT
:
911 render_type
= GLX_RGBA_FLOAT_TYPE
;
913 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
914 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
917 ERR("Unknown render_type: %x\n", render_type_bit
);
922 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
923 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
926 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
927 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
929 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
930 * the GLX_PIXMAP_BIT set. */
931 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
934 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
936 static WineGLPixelFormat
*list
;
937 static int size
, onscreen_size
;
939 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
941 XVisualInfo
*visinfo
;
946 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
947 if (NULL
== cfgs
|| 0 == nCfgs
) {
948 if(cfgs
!= NULL
) XFree(cfgs
);
950 ERR("glXChooseFBConfig returns NULL\n");
954 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
955 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
956 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
957 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
959 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
961 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
963 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
966 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
968 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
970 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
971 * Do this as GLX doesn't guarantee that the list is sorted */
972 for(run
=0; run
< 2; run
++)
974 for(i
=0; i
<nCfgs
; i
++) {
975 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
976 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
978 /* The first run we only add onscreen formats (ones which have an associated X Visual).
979 * The second run we only set offscreen formats. */
982 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
983 * The contents is copied to the destination using XCopyArea. For the copying to work
984 * the depth of the source and destination window should be the same. In general this should
985 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
986 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
987 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
988 * list formats with the same depth. */
989 if(visinfo
->depth
!= screen_depth
)
995 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
996 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
997 list
[size
].fbconfig
= cfgs
[i
];
998 list
[size
].fmt_id
= fmt_id
;
999 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1000 list
[size
].offscreenOnly
= FALSE
;
1001 list
[size
].dwFlags
= 0;
1005 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1006 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1008 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1009 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1010 list
[size
].fbconfig
= cfgs
[i
];
1011 list
[size
].fmt_id
= fmt_id
;
1012 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1013 list
[size
].offscreenOnly
= FALSE
;
1014 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
1018 } else if(run
&& !visinfo
) {
1019 int window_drawable
=0;
1020 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
1022 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1023 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1024 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1025 * likely make our child window opengl rendering more complicated since likely you can't use
1026 * XCopyArea on a GLX Window.
1027 * For now ignore fbconfigs which are window drawable but lack a visual. */
1028 if(window_drawable
& GLX_WINDOW_BIT
)
1030 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
1034 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1035 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1036 list
[size
].fbconfig
= cfgs
[i
];
1037 list
[size
].fmt_id
= fmt_id
;
1038 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1039 list
[size
].offscreenOnly
= TRUE
;
1040 list
[size
].dwFlags
= 0;
1044 if (visinfo
) XFree(visinfo
);
1051 if (size_ret
) *size_ret
= size
;
1052 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
1053 wine_tsx11_unlock();
1057 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1058 * In our WGL implementation we only support a subset of these formats namely the format of
1059 * Wine's main visual and offscreen formats (if they are available).
1060 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1061 * and it returns the number of supported WGL formats in fmt_count.
1063 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
1065 WineGLPixelFormat
*list
, *res
= NULL
;
1066 int size
, onscreen_size
;
1068 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
1070 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1071 * iPixelFormat in case of probing the number of pixelformats.
1073 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
1074 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
1075 res
= &list
[iPixelFormat
-1];
1076 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res
->fmt_id
, iPixelFormat
);
1082 *fmt_count
= onscreen_size
;
1084 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1089 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1090 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1092 WineGLPixelFormat
*list
;
1095 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1097 for(i
=0; i
<size
; i
++) {
1098 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1099 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1100 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1101 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1105 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1109 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1111 WineGLPixelFormat
*fmt
;
1113 if (!fbconfig_id
) return 0;
1115 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1117 return fmt
->iPixelFormat
;
1118 /* This will happen on hwnds without a pixel format set; it's ok */
1123 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1124 void mark_drawable_dirty(Drawable old
, Drawable
new)
1126 Wine_GLContext
*ctx
;
1127 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
1128 if (old
== ctx
->drawables
[0]) {
1129 ctx
->drawables
[0] = new;
1130 ctx
->refresh_drawables
= TRUE
;
1132 if (old
== ctx
->drawables
[1]) {
1133 ctx
->drawables
[1] = new;
1134 ctx
->refresh_drawables
= TRUE
;
1139 /* Given the current context, make sure its drawable is sync'd */
1140 static inline void sync_context(Wine_GLContext
*context
)
1142 if(context
&& context
->refresh_drawables
) {
1143 if (glxRequireVersion(3))
1144 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1145 context
->drawables
[1], context
->ctx
);
1147 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1148 context
->refresh_drawables
= FALSE
;
1153 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1157 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1158 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1160 if(context
->gl3_context
)
1162 if(context
->numAttribs
)
1163 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1165 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1167 else if(context
->vis
)
1168 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1169 else /* Create a GLX Context for a pbuffer */
1170 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1176 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1178 return pglXCreateGLXPixmap(display
, vis
, parent
);
1182 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1189 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1191 if(vis
->depth
== physDev
->bitmap
->depth
)
1192 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1195 wine_tsx11_unlock();
1196 TRACE("return %lx\n", ret
);
1201 * X11DRV_ChoosePixelFormat
1203 * Equivalent to glXChooseVisual.
1205 int X11DRV_ChoosePixelFormat(PHYSDEV dev
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1207 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1208 WineGLPixelFormat
*list
;
1213 int bestFormat
= -1;
1214 int bestDBuffer
= -1;
1215 int bestStereo
= -1;
1219 int bestStencil
= -1;
1222 if (!has_opengl()) return 0;
1224 if (TRACE_ON(wgl
)) {
1225 TRACE("(%p,%p)\n", physDev
, ppfd
);
1227 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1230 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1233 for(i
=0; i
<onscreen_size
; i
++)
1237 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1238 WineGLPixelFormat
*fmt
= &list
[i
];
1241 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1242 if (value
& GLX_RGBA_BIT
)
1243 iPixelType
= PFD_TYPE_RGBA
;
1245 iPixelType
= PFD_TYPE_COLORINDEX
;
1247 if (ppfd
->iPixelType
!= iPixelType
)
1249 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1253 /* Only use bitmap capable for formats for bitmap rendering.
1254 * See get_formats for more info. */
1255 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1257 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1261 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1262 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1263 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1264 if (value
) dwFlags
|= PFD_STEREO
;
1265 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1266 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1267 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1268 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1269 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1271 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1272 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1273 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1274 * formats without the given flag set.
1275 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1276 * has indicated that a format without stereo is returned when stereo is unavailable.
1277 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1278 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1280 * To summarize the following is most likely the correct behavior:
1281 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1282 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1283 * stereo don't care -> it doesn't matter whether we get stereo or not
1285 * In Wine we will treat no-stereo the same way as don't care because it makes
1286 * format selection even more complicated and second drivers with Stereo advertise
1287 * each format twice anyway.
1290 /* Doublebuffer, see the comments above */
1291 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1292 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1293 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1295 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1296 bestStereo
= dwFlags
& PFD_STEREO
;
1300 bestStencil
= stencil
;
1305 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1309 /* Stereo, see the comments above. */
1310 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1311 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1312 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1314 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1315 bestStereo
= dwFlags
& PFD_STEREO
;
1319 bestStencil
= stencil
;
1324 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1328 /* Below we will do a number of checks to select the 'best' pixelformat.
1329 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1330 * The code works by trying to match the most important options as close as possible.
1331 * When a reasonable format is found, we will try to match more options.
1332 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1333 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1334 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1337 if(ppfd
->cColorBits
) {
1338 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1339 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1341 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1342 bestStereo
= dwFlags
& PFD_STEREO
;
1346 bestStencil
= stencil
;
1350 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1351 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1357 if(ppfd
->cAlphaBits
) {
1358 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1359 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1361 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1362 bestStereo
= dwFlags
& PFD_STEREO
;
1366 bestStencil
= stencil
;
1370 } else if(bestAlpha
!= alpha
) {
1371 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1377 if(ppfd
->cDepthBits
) {
1378 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1379 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1381 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1382 bestStereo
= dwFlags
& PFD_STEREO
;
1386 bestStencil
= stencil
;
1390 } else if(bestDepth
!= depth
) {
1391 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1397 if(ppfd
->cStencilBits
) {
1398 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1399 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1401 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1402 bestStereo
= dwFlags
& PFD_STEREO
;
1406 bestStencil
= stencil
;
1410 } else if(bestStencil
!= stencil
) {
1411 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1417 if(ppfd
->cAuxBuffers
) {
1418 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1419 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1421 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1422 bestStereo
= dwFlags
& PFD_STEREO
;
1426 bestStencil
= stencil
;
1430 } else if(bestAux
!= aux
) {
1431 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1437 if(bestFormat
== -1) {
1438 TRACE("No matching mode was found returning 0\n");
1442 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1443 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1446 wine_tsx11_unlock();
1451 * X11DRV_DescribePixelFormat
1453 * Get the pixel-format descriptor associated to the given id
1455 int X11DRV_DescribePixelFormat(PHYSDEV dev
, int iPixelFormat
,
1456 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1458 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1459 /*XVisualInfo *vis;*/
1462 WineGLPixelFormat
*fmt
;
1466 if (!has_opengl()) return 0;
1468 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1470 /* 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 */
1471 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1473 /* The application is only querying the number of pixelformats */
1475 } else if(fmt
== NULL
) {
1476 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1480 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1481 ERR("Wrong structure size !\n");
1482 /* Should set error */
1488 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1489 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1492 /* These flags are always the same... */
1493 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1494 /* Now the flags extracted from the Visual */
1498 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1499 if(value
& GLX_WINDOW_BIT
)
1500 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1502 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1503 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1504 * 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
1505 * offered the GDI bit either. */
1506 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1508 /* PFD_GENERIC_FORMAT - gdi software rendering
1509 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1510 * none set - full hardware accelerated by a ICD
1512 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1513 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1515 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1517 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1518 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1520 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1523 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1524 if (value
& GLX_RGBA_BIT
)
1525 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1527 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1530 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1531 ppfd
->cColorBits
= value
;
1533 /* Red, green, blue and alpha bits / shifts */
1534 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1535 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1536 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1537 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1538 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1540 ppfd
->cRedBits
= rb
;
1541 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1542 ppfd
->cBlueBits
= bb
;
1543 ppfd
->cBlueShift
= ab
;
1544 ppfd
->cGreenBits
= gb
;
1545 ppfd
->cGreenShift
= bb
+ ab
;
1546 ppfd
->cAlphaBits
= ab
;
1547 ppfd
->cAlphaShift
= 0;
1550 ppfd
->cRedShift
= 0;
1551 ppfd
->cBlueBits
= 0;
1552 ppfd
->cBlueShift
= 0;
1553 ppfd
->cGreenBits
= 0;
1554 ppfd
->cGreenShift
= 0;
1555 ppfd
->cAlphaBits
= 0;
1556 ppfd
->cAlphaShift
= 0;
1559 /* Accum RGBA bits */
1560 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1561 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1562 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1563 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1565 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1566 ppfd
->cAccumRedBits
= rb
;
1567 ppfd
->cAccumGreenBits
= gb
;
1568 ppfd
->cAccumBlueBits
= bb
;
1569 ppfd
->cAccumAlphaBits
= ab
;
1572 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1573 ppfd
->cAuxBuffers
= value
;
1576 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1577 ppfd
->cDepthBits
= value
;
1580 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1581 ppfd
->cStencilBits
= value
;
1583 wine_tsx11_unlock();
1585 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1587 if (TRACE_ON(wgl
)) {
1588 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1595 * X11DRV_GetPixelFormat
1597 * Get the pixel-format id used by this DC
1599 int X11DRV_GetPixelFormat(PHYSDEV dev
)
1601 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1602 WineGLPixelFormat
*fmt
;
1604 TRACE("(%p)\n", physDev
);
1606 if (!physDev
->current_pf
) return 0; /* not set yet */
1608 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1611 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1614 else if(fmt
->offscreenOnly
)
1616 /* Offscreen formats can't be used with traditional WGL calls.
1617 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1618 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1622 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1623 return physDev
->current_pf
;
1626 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1627 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1628 * set the pixel format multiple times. */
1629 static BOOL
internal_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1631 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1632 WineGLPixelFormat
*fmt
;
1636 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1637 if(physDev
->drawable
== root_window
)
1639 ERR("Invalid operation on root_window\n");
1643 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1644 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1646 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1651 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1652 wine_tsx11_unlock();
1654 hwnd
= WindowFromDC(physDev
->dev
.hdc
);
1656 if(!(value
&GLX_WINDOW_BIT
)) {
1657 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1661 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, fmt
->fmt_id
, 0)) {
1662 ERR("Couldn't set format of the window, returning failure\n");
1665 /* physDev->current_pf will be set by the DCE update */
1667 else if(physDev
->bitmap
) {
1668 if(!(value
&GLX_PIXMAP_BIT
)) {
1669 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1673 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
, fmt
);
1674 if(!physDev
->bitmap
->glxpixmap
) {
1675 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1678 physDev
->current_pf
= iPixelFormat
;
1681 FIXME("called on a non-window, non-bitmap object?\n");
1684 if (TRACE_ON(wgl
)) {
1688 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1690 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1692 TRACE(" FBConfig have :\n");
1693 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1694 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1695 TRACE(" - VISUAL_ID 0x%x\n", value
);
1696 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1697 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1699 wine_tsx11_unlock();
1706 * X11DRV_SetPixelFormat
1708 * Set the pixel-format id used by this DC
1710 BOOL
X11DRV_SetPixelFormat(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1712 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1714 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1716 if (!has_opengl()) return FALSE
;
1718 if(physDev
->current_pf
) /* cannot change it if already set */
1719 return (physDev
->current_pf
== iPixelFormat
);
1721 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
1725 * X11DRV_wglCopyContext
1727 * For OpenGL32 wglCopyContext.
1729 BOOL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
1731 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1732 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1734 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1737 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1738 wine_tsx11_unlock();
1740 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1745 * X11DRV_wglCreateContext
1747 * For OpenGL32 wglCreateContext.
1749 HGLRC
X11DRV_wglCreateContext(PHYSDEV dev
)
1751 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1752 Wine_GLContext
*ret
;
1753 WineGLPixelFormat
*fmt
;
1754 int hdcPF
= physDev
->current_pf
;
1758 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1760 if (!has_opengl()) return 0;
1762 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1763 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1764 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1765 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1766 * If this fails something is very wrong on the system. */
1768 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1769 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1774 ret
= alloc_context();
1777 ret
->has_been_current
= FALSE
;
1778 ret
->sharing
= FALSE
;
1780 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1781 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1782 wine_tsx11_unlock();
1784 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1789 * X11DRV_wglDeleteContext
1791 * For OpenGL32 wglDeleteContext.
1793 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1795 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1797 TRACE("(%p)\n", hglrc
);
1799 if (!has_opengl()) return 0;
1801 if (!is_valid_context(ctx
))
1803 WARN("Error deleting context !\n");
1804 SetLastError(ERROR_INVALID_HANDLE
);
1808 /* WGL doesn't allow deletion of a context which is current in another thread */
1809 if (ctx
->tid
!= 0 && ctx
->tid
!= GetCurrentThreadId())
1811 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx
);
1812 SetLastError(ERROR_BUSY
);
1816 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1817 if (ctx
== NtCurrentTeb()->glContext
)
1818 wglMakeCurrent(ctx
->hdc
, NULL
);
1823 pglXDestroyContext(gdi_display
, ctx
->ctx
);
1824 wine_tsx11_unlock();
1832 * X11DRV_wglGetCurrentReadDCARB
1834 * For OpenGL32 wglGetCurrentReadDCARB.
1836 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1839 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1841 if (ctx
) ret
= ctx
->read_hdc
;
1843 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1848 * X11DRV_wglGetProcAddress
1850 * For OpenGL32 wglGetProcAddress.
1852 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1855 const WineGLExtension
*ext
;
1857 int padding
= 32 - strlen(lpszProc
);
1861 if (!has_opengl()) return NULL
;
1863 /* Check the table of WGL extensions to see if we need to return a WGL extension
1864 * or a function pointer to a native OpenGL function. */
1865 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1866 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1868 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1869 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1870 ext
= WineGLExtensionList
[i
];
1871 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1872 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1873 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1874 return ext
->extEntryPoints
[j
].funcAddress
;
1880 WARN("(%s) - not found\n", lpszProc
);
1885 * X11DRV_wglMakeCurrent
1887 * For OpenGL32 wglMakeCurrent.
1889 BOOL
X11DRV_wglMakeCurrent(PHYSDEV dev
, HGLRC hglrc
)
1891 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1894 DWORD type
= GetObjectType(hdc
);
1895 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1897 TRACE("(%p,%p)\n", hdc
, hglrc
);
1899 if (!has_opengl()) return FALSE
;
1904 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1905 if (prev_ctx
) prev_ctx
->tid
= 0;
1907 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1908 NtCurrentTeb()->glContext
= NULL
;
1910 else if (!physDev
->current_pf
)
1912 WARN("Trying to use an invalid drawable\n");
1913 SetLastError(ERROR_INVALID_HANDLE
);
1916 else if (ctx
->fmt
->iPixelFormat
!= physDev
->current_pf
)
1918 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1919 hdc
, physDev
->current_pf
, ctx
, ctx
->fmt
->iPixelFormat
);
1920 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1925 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1927 /* The describe lines below are for debugging purposes only */
1928 if (TRACE_ON(wgl
)) {
1929 describeDrawable(physDev
);
1930 describeContext(ctx
);
1933 TRACE(" make current for drawable %lx, ctx %p\n", physDev
->gl_drawable
, ctx
->ctx
);
1934 ret
= pglXMakeCurrent(gdi_display
, physDev
->gl_drawable
, ctx
->ctx
);
1938 if (prev_ctx
) prev_ctx
->tid
= 0;
1939 NtCurrentTeb()->glContext
= ctx
;
1941 ctx
->has_been_current
= TRUE
;
1942 ctx
->tid
= GetCurrentThreadId();
1944 ctx
->read_hdc
= hdc
;
1945 ctx
->drawables
[0] = physDev
->gl_drawable
;
1946 ctx
->drawables
[1] = physDev
->gl_drawable
;
1947 ctx
->refresh_drawables
= FALSE
;
1949 if (type
== OBJ_MEMDC
) pglDrawBuffer(GL_FRONT_LEFT
);
1952 SetLastError(ERROR_INVALID_HANDLE
);
1954 wine_tsx11_unlock();
1955 TRACE(" returning %s\n", (ret
? "True" : "False"));
1960 * X11DRV_wglMakeContextCurrentARB
1962 * For OpenGL32 wglMakeContextCurrentARB
1964 BOOL
X11DRV_wglMakeContextCurrentARB( PHYSDEV draw_dev
, PHYSDEV read_dev
, HGLRC hglrc
)
1966 X11DRV_PDEVICE
*pDrawDev
= get_x11drv_dev( draw_dev
);
1967 X11DRV_PDEVICE
*pReadDev
= get_x11drv_dev( read_dev
);
1970 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1972 if (!has_opengl()) return 0;
1977 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1978 if (prev_ctx
) prev_ctx
->tid
= 0;
1980 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1981 NtCurrentTeb()->glContext
= NULL
;
1983 else if (!pDrawDev
->current_pf
)
1985 WARN("Trying to use an invalid drawable\n");
1986 SetLastError(ERROR_INVALID_HANDLE
);
1991 if (NULL
== pglXMakeContextCurrent
) {
1994 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1996 ret
= pglXMakeContextCurrent(gdi_display
, pDrawDev
->gl_drawable
, pReadDev
->gl_drawable
, ctx
->ctx
);
1999 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
2000 if (prev_ctx
) prev_ctx
->tid
= 0;
2002 ctx
->has_been_current
= TRUE
;
2003 ctx
->tid
= GetCurrentThreadId();
2004 ctx
->hdc
= draw_dev
->hdc
;
2005 ctx
->read_hdc
= read_dev
->hdc
;
2006 ctx
->drawables
[0] = pDrawDev
->gl_drawable
;
2007 ctx
->drawables
[1] = pReadDev
->gl_drawable
;
2008 ctx
->refresh_drawables
= FALSE
;
2009 NtCurrentTeb()->glContext
= ctx
;
2012 SetLastError(ERROR_INVALID_HANDLE
);
2015 wine_tsx11_unlock();
2017 TRACE(" returning %s\n", (ret
? "True" : "False"));
2022 * X11DRV_wglShareLists
2024 * For OpenGL32 wglShareLists.
2026 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
2028 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
2029 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
2031 TRACE("(%p, %p)\n", org
, dest
);
2033 if (!has_opengl()) return FALSE
;
2035 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
2036 * at context creation time but in case of WGL it is done using wglShareLists.
2037 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
2038 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
2039 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
2040 * so there delaying context creation doesn't work.
2042 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
2043 * and when a program requests sharing we recreate the destination context if it hasn't been made
2044 * current or when it hasn't shared display lists before.
2047 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
2049 ERR("Could not share display lists, one of the contexts has been current already !\n");
2052 else if(dest
->sharing
)
2054 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
2059 if((GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
))
2061 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
2065 describeContext(org
);
2066 describeContext(dest
);
2068 /* Re-create the GLX context and share display lists */
2069 pglXDestroyContext(gdi_display
, dest
->ctx
);
2070 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
2071 wine_tsx11_unlock();
2072 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
2074 org
->sharing
= TRUE
;
2075 dest
->sharing
= TRUE
;
2081 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
2083 /* We are running using client-side rendering fonts... */
2085 unsigned int glyph
, size
= 0;
2086 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
2090 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
2091 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
2092 wine_tsx11_unlock();
2094 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
2095 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
2096 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
2097 unsigned int height
, width_int
;
2099 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
2100 if (needed_size
== GDI_ERROR
) {
2101 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
2104 TRACE(" - needed size : %d\n", needed_size
);
2107 if (needed_size
> size
) {
2109 HeapFree(GetProcessHeap(), 0, bitmap
);
2110 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2111 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2112 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2114 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
2116 if (TRACE_ON(wgl
)) {
2117 unsigned int height
, width
, bitmask
;
2118 unsigned char *bitmap_
= bitmap
;
2120 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
2121 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2122 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
2123 if (needed_size
!= 0) {
2124 TRACE(" - bitmap :\n");
2125 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2127 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
2132 if (*bitmap_
& bitmask
)
2137 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2143 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2144 * glyph for it to be drawn properly.
2146 if (needed_size
!= 0) {
2147 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2148 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2150 for (width
= 0; width
< width_int
; width
++) {
2151 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2152 ((int *) bitmap
)[height
* width_int
+ width
];
2158 pglNewList(listBase
++, GL_COMPILE
);
2159 if (needed_size
!= 0) {
2160 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2161 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2162 gm
.gmCellIncX
, gm
.gmCellIncY
,
2165 /* This is the case of 'empty' glyphs like the space character */
2166 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2169 wine_tsx11_unlock();
2173 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2174 wine_tsx11_unlock();
2176 HeapFree(GetProcessHeap(), 0, bitmap
);
2177 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2182 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2183 wine_tsx11_unlock();
2185 HeapFree(GetProcessHeap(), 0, bitmap
);
2186 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2191 * X11DRV_wglUseFontBitmapsA
2193 * For OpenGL32 wglUseFontBitmapsA.
2195 BOOL
X11DRV_wglUseFontBitmapsA(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
2197 TRACE("(%p, %d, %d, %d)\n", dev
->hdc
, first
, count
, listBase
);
2199 if (!has_opengl()) return FALSE
;
2200 return internal_wglUseFontBitmaps(dev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2204 * X11DRV_wglUseFontBitmapsW
2206 * For OpenGL32 wglUseFontBitmapsW.
2208 BOOL
X11DRV_wglUseFontBitmapsW(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
2210 TRACE("(%p, %d, %d, %d)\n", dev
->hdc
, first
, count
, listBase
);
2212 if (!has_opengl()) return FALSE
;
2213 return internal_wglUseFontBitmaps(dev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2216 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2217 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2224 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2226 pglGetIntegerv(pname
, params
);
2228 * if we cannot find a Wine Context
2229 * we only have the default wine desktop context,
2230 * so if we have only a 24 depth say we have 32
2232 if (!ctx
&& *params
== 24) {
2235 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2240 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2242 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2243 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2247 pglGetIntegerv(pname
, params
);
2250 wine_tsx11_unlock();
2253 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
2258 if (!physDev
->gl_copy
|| !physDev
->gl_drawable
)
2261 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
2262 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
2264 if(w
> 0 && h
> 0) {
2265 Drawable src
= physDev
->pixmap
;
2266 if(!src
) src
= physDev
->gl_drawable
;
2268 /* The GL drawable may be lagged behind if we don't flush first, so
2269 * flush the display make sure we copy up-to-date data */
2271 XFlush(gdi_display
);
2272 XSetFunction(gdi_display
, physDev
->gc
, GXcopy
);
2273 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
2274 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
2275 wine_tsx11_unlock();
2276 SetRect( &rect
, 0, 0, w
, h
);
2277 add_device_bounds( physDev
, &rect
);
2282 static void WINAPI
X11DRV_wglFinish(void)
2284 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2285 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2290 wine_tsx11_unlock();
2291 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2294 static void WINAPI
X11DRV_wglFlush(void)
2296 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2297 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2302 wine_tsx11_unlock();
2303 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2307 * X11DRV_wglCreateContextAttribsARB
2309 * WGL_ARB_create_context: wglCreateContextAttribsARB
2311 HGLRC
X11DRV_wglCreateContextAttribsARB(PHYSDEV dev
, HGLRC hShareContext
, const int* attribList
)
2313 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2314 Wine_GLContext
*ret
;
2315 WineGLPixelFormat
*fmt
;
2316 int hdcPF
= physDev
->current_pf
;
2319 TRACE("(%p %p %p)\n", physDev
, hShareContext
, attribList
);
2321 if (!has_opengl()) return 0;
2323 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
2324 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2325 * If this fails something is very wrong on the system. */
2328 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
2329 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2334 ret
= alloc_context();
2335 wine_tsx11_unlock();
2336 ret
->hdc
= dev
->hdc
;
2338 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2339 ret
->gl3_context
= TRUE
;
2341 ret
->numAttribs
= 0;
2344 int *pAttribList
= (int*)attribList
;
2345 int *pContextAttribList
= &ret
->attribList
[0];
2346 /* attribList consists of pairs {token, value] terminated with 0 */
2347 while(pAttribList
[0] != 0)
2349 TRACE("%#x %#x\n", pAttribList
[0], pAttribList
[1]);
2350 switch(pAttribList
[0])
2352 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2353 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2354 pContextAttribList
[1] = pAttribList
[1];
2356 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2357 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2358 pContextAttribList
[1] = pAttribList
[1];
2360 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2362 case WGL_CONTEXT_FLAGS_ARB
:
2363 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2364 pContextAttribList
[1] = pAttribList
[1];
2366 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2367 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2368 pContextAttribList
[1] = pAttribList
[1];
2371 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList
[0], pAttribList
[1]);
2376 pContextAttribList
+= 2;
2381 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2382 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
2384 XSync(gdi_display
, False
);
2385 if(X11DRV_check_error() || !ret
->ctx
)
2387 /* In the future we should convert the GLX error to a win32 one here if needed */
2388 ERR("Context creation failed\n");
2390 wine_tsx11_unlock();
2394 wine_tsx11_unlock();
2395 TRACE(" creating context %p\n", ret
);
2400 * X11DRV_wglGetExtensionsStringARB
2402 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2404 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2405 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2406 return WineGLInfo
.wglExtensions
;
2410 * X11DRV_wglCreatePbufferARB
2412 * WGL_ARB_pbuffer: wglCreatePbufferARB
2414 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2416 Wine_GLPBuffer
* object
= NULL
;
2417 WineGLPixelFormat
*fmt
= NULL
;
2422 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2424 if (0 >= iPixelFormat
) {
2425 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2426 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2427 return NULL
; /* unexpected error */
2430 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2431 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2433 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2434 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2435 goto create_failed
; /* unexpected error */
2438 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2439 if (NULL
== object
) {
2440 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2441 goto create_failed
; /* unexpected error */
2444 object
->display
= gdi_display
;
2445 object
->width
= iWidth
;
2446 object
->height
= iHeight
;
2449 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2450 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2451 while (piAttribList
&& 0 != *piAttribList
) {
2453 switch (*piAttribList
) {
2454 case WGL_PBUFFER_LARGEST_ARB
: {
2456 attr_v
= *piAttribList
;
2457 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2458 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2462 case WGL_TEXTURE_FORMAT_ARB
: {
2464 attr_v
= *piAttribList
;
2465 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2466 if (use_render_texture_ati
) {
2469 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2470 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2471 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2473 SetLastError(ERROR_INVALID_DATA
);
2476 object
->use_render_texture
= 1;
2477 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2479 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2480 object
->use_render_texture
= 0;
2482 if (!use_render_texture_emulation
) {
2483 SetLastError(ERROR_INVALID_DATA
);
2487 case WGL_TEXTURE_RGB_ARB
:
2488 object
->use_render_texture
= GL_RGB
;
2489 object
->texture_bpp
= 3;
2490 object
->texture_format
= GL_RGB
;
2491 object
->texture_type
= GL_UNSIGNED_BYTE
;
2493 case WGL_TEXTURE_RGBA_ARB
:
2494 object
->use_render_texture
= GL_RGBA
;
2495 object
->texture_bpp
= 4;
2496 object
->texture_format
= GL_RGBA
;
2497 object
->texture_type
= GL_UNSIGNED_BYTE
;
2500 /* WGL_FLOAT_COMPONENTS_NV */
2501 case WGL_TEXTURE_FLOAT_R_NV
:
2502 object
->use_render_texture
= GL_FLOAT_R_NV
;
2503 object
->texture_bpp
= 4;
2504 object
->texture_format
= GL_RED
;
2505 object
->texture_type
= GL_FLOAT
;
2507 case WGL_TEXTURE_FLOAT_RG_NV
:
2508 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2509 object
->texture_bpp
= 8;
2510 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2511 object
->texture_type
= GL_FLOAT
;
2513 case WGL_TEXTURE_FLOAT_RGB_NV
:
2514 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2515 object
->texture_bpp
= 12;
2516 object
->texture_format
= GL_RGB
;
2517 object
->texture_type
= GL_FLOAT
;
2519 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2520 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2521 object
->texture_bpp
= 16;
2522 object
->texture_format
= GL_RGBA
;
2523 object
->texture_type
= GL_FLOAT
;
2526 ERR("Unknown texture format: %x\n", attr_v
);
2527 SetLastError(ERROR_INVALID_DATA
);
2535 case WGL_TEXTURE_TARGET_ARB
: {
2537 attr_v
= *piAttribList
;
2538 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2539 if (use_render_texture_ati
) {
2542 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2543 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2544 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2545 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2547 SetLastError(ERROR_INVALID_DATA
);
2550 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2552 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2553 object
->texture_target
= 0;
2555 if (!use_render_texture_emulation
) {
2556 SetLastError(ERROR_INVALID_DATA
);
2560 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2561 if (iWidth
!= iHeight
) {
2562 SetLastError(ERROR_INVALID_DATA
);
2565 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2566 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2569 case WGL_TEXTURE_1D_ARB
: {
2571 SetLastError(ERROR_INVALID_DATA
);
2574 object
->texture_target
= GL_TEXTURE_1D
;
2575 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2578 case WGL_TEXTURE_2D_ARB
: {
2579 object
->texture_target
= GL_TEXTURE_2D
;
2580 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2583 case WGL_TEXTURE_RECTANGLE_NV
: {
2584 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2585 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2589 ERR("Unknown texture target: %x\n", attr_v
);
2590 SetLastError(ERROR_INVALID_DATA
);
2598 case WGL_MIPMAP_TEXTURE_ARB
: {
2600 attr_v
= *piAttribList
;
2601 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2602 if (use_render_texture_ati
) {
2603 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2605 if (!use_render_texture_emulation
) {
2606 SetLastError(ERROR_INVALID_DATA
);
2616 PUSH1(attribs
, None
);
2618 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2619 wine_tsx11_unlock();
2620 TRACE("new Pbuffer drawable as %lx\n", object
->drawable
);
2621 if (!object
->drawable
) {
2622 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2623 goto create_failed
; /* unexpected error */
2625 TRACE("->(%p)\n", object
);
2629 HeapFree(GetProcessHeap(), 0, object
);
2630 TRACE("->(FAILED)\n");
2635 * X11DRV_wglDestroyPbufferARB
2637 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2639 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2641 Wine_GLPBuffer
* object
= hPbuffer
;
2642 TRACE("(%p)\n", hPbuffer
);
2643 if (NULL
== object
) {
2644 SetLastError(ERROR_INVALID_HANDLE
);
2648 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2649 wine_tsx11_unlock();
2650 HeapFree(GetProcessHeap(), 0, object
);
2655 * X11DRV_wglGetPbufferDCARB
2657 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2658 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2659 * Gdi32 implements the part of this function which creates a device context.
2660 * This part associates the physDev with the X drawable of the pbuffer.
2662 HDC
X11DRV_wglGetPbufferDCARB(PHYSDEV dev
, HPBUFFERARB hPbuffer
)
2664 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2665 Wine_GLPBuffer
* object
= hPbuffer
;
2667 if (NULL
== object
) {
2668 SetLastError(ERROR_INVALID_HANDLE
);
2672 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2673 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2674 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2675 physDev
->drawable
= object
->drawable
;
2676 physDev
->gl_drawable
= object
->drawable
;
2677 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2678 physDev
->dc_rect
= physDev
->drawable_rect
;
2680 TRACE("(%p)->(%p)\n", hPbuffer
, dev
->hdc
);
2685 * X11DRV_wglQueryPbufferARB
2687 * WGL_ARB_pbuffer: wglQueryPbufferARB
2689 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2691 Wine_GLPBuffer
* object
= hPbuffer
;
2692 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2693 if (NULL
== object
) {
2694 SetLastError(ERROR_INVALID_HANDLE
);
2697 switch (iAttribute
) {
2698 case WGL_PBUFFER_WIDTH_ARB
:
2700 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2701 wine_tsx11_unlock();
2703 case WGL_PBUFFER_HEIGHT_ARB
:
2705 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2706 wine_tsx11_unlock();
2709 case WGL_PBUFFER_LOST_ARB
:
2710 /* GLX Pbuffers cannot be lost by default. We can support this by
2711 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2712 * to receive pixel buffer clobber events, however that may or may
2713 * not give any benefit */
2714 *piValue
= GL_FALSE
;
2717 case WGL_TEXTURE_FORMAT_ARB
:
2718 if (use_render_texture_ati
) {
2720 int type
= WGL_NO_TEXTURE_ARB
;
2722 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2723 wine_tsx11_unlock();
2725 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2726 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2727 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2731 if (!object
->use_render_texture
) {
2732 *piValue
= WGL_NO_TEXTURE_ARB
;
2734 if (!use_render_texture_emulation
) {
2735 SetLastError(ERROR_INVALID_HANDLE
);
2738 switch(object
->use_render_texture
) {
2740 *piValue
= WGL_TEXTURE_RGB_ARB
;
2743 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2745 /* WGL_FLOAT_COMPONENTS_NV */
2747 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2749 case GL_FLOAT_RG_NV
:
2750 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2752 case GL_FLOAT_RGB_NV
:
2753 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2755 case GL_FLOAT_RGBA_NV
:
2756 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2759 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2765 case WGL_TEXTURE_TARGET_ARB
:
2766 if (use_render_texture_ati
) {
2768 int type
= WGL_NO_TEXTURE_ARB
;
2770 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2771 wine_tsx11_unlock();
2773 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2774 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2775 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2776 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2780 if (!object
->texture_target
) {
2781 *piValue
= WGL_NO_TEXTURE_ARB
;
2783 if (!use_render_texture_emulation
) {
2784 SetLastError(ERROR_INVALID_DATA
);
2787 switch (object
->texture_target
) {
2788 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2789 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2790 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2791 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2797 case WGL_MIPMAP_TEXTURE_ARB
:
2798 if (use_render_texture_ati
) {
2800 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2801 wine_tsx11_unlock();
2803 *piValue
= GL_FALSE
; /** don't support that */
2804 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2809 FIXME("unexpected attribute %x\n", iAttribute
);
2817 * X11DRV_wglReleasePbufferDCARB
2819 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2821 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2823 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2824 return DeleteDC(hdc
);
2828 * X11DRV_wglSetPbufferAttribARB
2830 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2832 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2834 Wine_GLPBuffer
* object
= hPbuffer
;
2835 GLboolean ret
= GL_FALSE
;
2837 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2838 if (NULL
== object
) {
2839 SetLastError(ERROR_INVALID_HANDLE
);
2842 if (!object
->use_render_texture
) {
2843 SetLastError(ERROR_INVALID_HANDLE
);
2846 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2849 if (NULL
!= pglXDrawableAttribATI
) {
2850 if (use_render_texture_ati
) {
2851 FIXME("Need conversion for GLX_ATI_render_texture\n");
2854 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2855 wine_tsx11_unlock();
2861 * X11DRV_wglChoosePixelFormatARB
2863 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2865 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2870 GLXFBConfig
* cfgs
= NULL
;
2874 WineGLPixelFormat
*fmt
;
2880 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2881 if (NULL
!= pfAttribFList
) {
2882 FIXME("unused pfAttribFList\n");
2885 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2886 if (-1 == nAttribs
) {
2887 WARN("Cannot convert WGL to GLX attributes\n");
2890 PUSH1(attribs
, None
);
2892 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2893 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2894 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2895 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2897 switch(piAttribIList
[i
])
2899 case WGL_DRAW_TO_BITMAP_ARB
:
2900 if(piAttribIList
[i
+1])
2901 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2903 case WGL_ACCELERATION_ARB
:
2904 switch(piAttribIList
[i
+1])
2906 case WGL_NO_ACCELERATION_ARB
:
2907 dwFlags
|= PFD_GENERIC_FORMAT
;
2909 case WGL_GENERIC_ACCELERATION_ARB
:
2910 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2912 case WGL_FULL_ACCELERATION_ARB
:
2917 case WGL_SUPPORT_GDI_ARB
:
2918 if(piAttribIList
[i
+1])
2919 dwFlags
|= PFD_SUPPORT_GDI
;
2924 /* Search for FB configurations matching the requirements in attribs */
2926 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2928 wine_tsx11_unlock();
2929 WARN("Compatible Pixel Format not found\n");
2933 /* Loop through all matching formats and check if they are suitable.
2934 * Note that this function should at max return nMaxFormats different formats */
2935 for(run
=0; run
< 2; run
++)
2937 for (it
= 0; it
< nCfgs
; ++it
) {
2938 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2940 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2944 /* Search for the format in our list of compatible formats */
2945 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2949 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2950 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2953 if(pfmt_it
< nMaxFormats
) {
2954 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2955 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2961 *nNumFormats
= pfmt_it
;
2964 wine_tsx11_unlock();
2969 * X11DRV_wglGetPixelFormatAttribivARB
2971 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2973 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2976 WineGLPixelFormat
*fmt
= NULL
;
2980 int nWGLFormats
= 0;
2982 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2984 if (0 < iLayerPlane
) {
2985 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2989 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2990 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2991 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2992 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2994 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2998 for (i
= 0; i
< nAttributes
; ++i
) {
2999 const int curWGLAttr
= piAttributes
[i
];
3000 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
3002 switch (curWGLAttr
) {
3003 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
3004 piValues
[i
] = nWGLFormats
;
3007 case WGL_SUPPORT_OPENGL_ARB
:
3008 piValues
[i
] = GL_TRUE
;
3011 case WGL_ACCELERATION_ARB
:
3012 curGLXAttr
= GLX_CONFIG_CAVEAT
;
3013 if (!fmt
) goto pix_error
;
3014 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
3015 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
3016 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
3017 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
3019 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
3022 case WGL_TRANSPARENT_ARB
:
3023 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
3024 if (!fmt
) goto pix_error
;
3025 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3026 if (hTest
) goto get_error
;
3027 piValues
[i
] = GL_FALSE
;
3028 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
3031 case WGL_PIXEL_TYPE_ARB
:
3032 curGLXAttr
= GLX_RENDER_TYPE
;
3033 if (!fmt
) goto pix_error
;
3034 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3035 if (hTest
) goto get_error
;
3036 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
3037 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
3038 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
3039 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
3040 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
3041 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
3043 ERR("unexpected RenderType(%x)\n", tmp
);
3044 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
3048 case WGL_COLOR_BITS_ARB
:
3049 curGLXAttr
= GLX_BUFFER_SIZE
;
3052 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
3053 if (use_render_texture_ati
) {
3054 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
3057 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
3058 if (use_render_texture_ati
) {
3059 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
3062 if (!use_render_texture_emulation
) {
3063 piValues
[i
] = GL_FALSE
;
3066 curGLXAttr
= GLX_RENDER_TYPE
;
3067 if (!fmt
) goto pix_error
;
3068 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3069 if (hTest
) goto get_error
;
3070 if (GLX_COLOR_INDEX_BIT
== tmp
) {
3071 piValues
[i
] = GL_FALSE
;
3074 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3075 if (hTest
) goto get_error
;
3076 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
3079 case WGL_BLUE_BITS_ARB
:
3080 curGLXAttr
= GLX_BLUE_SIZE
;
3082 case WGL_RED_BITS_ARB
:
3083 curGLXAttr
= GLX_RED_SIZE
;
3085 case WGL_GREEN_BITS_ARB
:
3086 curGLXAttr
= GLX_GREEN_SIZE
;
3088 case WGL_ALPHA_BITS_ARB
:
3089 curGLXAttr
= GLX_ALPHA_SIZE
;
3091 case WGL_DEPTH_BITS_ARB
:
3092 curGLXAttr
= GLX_DEPTH_SIZE
;
3094 case WGL_STENCIL_BITS_ARB
:
3095 curGLXAttr
= GLX_STENCIL_SIZE
;
3097 case WGL_DOUBLE_BUFFER_ARB
:
3098 curGLXAttr
= GLX_DOUBLEBUFFER
;
3100 case WGL_STEREO_ARB
:
3101 curGLXAttr
= GLX_STEREO
;
3103 case WGL_AUX_BUFFERS_ARB
:
3104 curGLXAttr
= GLX_AUX_BUFFERS
;
3107 case WGL_SUPPORT_GDI_ARB
:
3108 if (!fmt
) goto pix_error
;
3109 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
3112 case WGL_DRAW_TO_BITMAP_ARB
:
3113 if (!fmt
) goto pix_error
;
3114 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
3117 case WGL_DRAW_TO_WINDOW_ARB
:
3118 case WGL_DRAW_TO_PBUFFER_ARB
:
3119 if (!fmt
) goto pix_error
;
3120 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3121 if (hTest
) goto get_error
;
3122 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
3123 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
3124 piValues
[i
] = GL_TRUE
;
3126 piValues
[i
] = GL_FALSE
;
3129 case WGL_SWAP_METHOD_ARB
:
3130 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3131 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3132 * point only ATI offers this.
3134 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
3137 case WGL_PBUFFER_LARGEST_ARB
:
3138 curGLXAttr
= GLX_LARGEST_PBUFFER
;
3141 case WGL_SAMPLE_BUFFERS_ARB
:
3142 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
3145 case WGL_SAMPLES_ARB
:
3146 curGLXAttr
= GLX_SAMPLES_ARB
;
3149 case WGL_FLOAT_COMPONENTS_NV
:
3150 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
3153 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
3154 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
3157 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
3158 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
3161 case WGL_ACCUM_RED_BITS_ARB
:
3162 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
3164 case WGL_ACCUM_GREEN_BITS_ARB
:
3165 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
3167 case WGL_ACCUM_BLUE_BITS_ARB
:
3168 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
3170 case WGL_ACCUM_ALPHA_BITS_ARB
:
3171 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
3173 case WGL_ACCUM_BITS_ARB
:
3174 if (!fmt
) goto pix_error
;
3175 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
3176 if (hTest
) goto get_error
;
3178 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
3179 if (hTest
) goto get_error
;
3181 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
3182 if (hTest
) goto get_error
;
3184 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
3185 if (hTest
) goto get_error
;
3190 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
3193 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3194 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3195 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3197 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3198 * and check which options can work using iPixelFormat=0 and which not.
3199 * A problem would be that this function is an extension. This would
3200 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3202 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
3203 if (!fmt
) goto pix_error
;
3204 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
3205 if (hTest
) goto get_error
;
3208 piValues
[i
] = GL_FALSE
;
3211 wine_tsx11_unlock();
3215 wine_tsx11_unlock();
3216 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3220 wine_tsx11_unlock();
3221 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3226 * X11DRV_wglGetPixelFormatAttribfvARB
3228 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3230 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3236 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3238 /* Allocate a temporary array to store integer values */
3239 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3241 ERR("couldn't allocate %d array\n", nAttributes
);
3245 /* Piggy-back on wglGetPixelFormatAttribivARB */
3246 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3248 /* Convert integer values to float. Should also check for attributes
3249 that can give decimal values here */
3250 for (i
=0; i
<nAttributes
;i
++) {
3251 pfValues
[i
] = attr
[i
];
3255 HeapFree(GetProcessHeap(), 0, attr
);
3260 * X11DRV_wglBindTexImageARB
3262 * WGL_ARB_render_texture: wglBindTexImageARB
3264 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3266 Wine_GLPBuffer
* object
= hPbuffer
;
3267 GLboolean ret
= GL_FALSE
;
3269 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3270 if (NULL
== object
) {
3271 SetLastError(ERROR_INVALID_HANDLE
);
3274 if (!object
->use_render_texture
) {
3275 SetLastError(ERROR_INVALID_HANDLE
);
3279 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3280 static int init
= 0;
3281 int prev_binded_texture
= 0;
3282 GLXContext prev_context
;
3283 Drawable prev_drawable
;
3284 GLXContext tmp_context
;
3287 prev_context
= pglXGetCurrentContext();
3288 prev_drawable
= pglXGetCurrentDrawable();
3290 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3291 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3292 isn't ideal performance wise but I wasn't able to get other ways working.
3295 init
= 1; /* Only show the FIXME once for performance reasons */
3296 FIXME("partial stub!\n");
3299 TRACE("drawable=%lx, context=%p\n", object
->drawable
, prev_context
);
3300 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3302 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3304 /* Switch to our pbuffer */
3305 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3307 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3308 * After that upload the pbuffer texture data. */
3309 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3310 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3312 /* Switch back to the original drawable and upload the pbuffer-texture */
3313 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3314 pglXDestroyContext(gdi_display
, tmp_context
);
3315 wine_tsx11_unlock();
3319 if (NULL
!= pglXBindTexImageATI
) {
3324 case WGL_FRONT_LEFT_ARB
:
3325 buffer
= GLX_FRONT_LEFT_ATI
;
3327 case WGL_FRONT_RIGHT_ARB
:
3328 buffer
= GLX_FRONT_RIGHT_ATI
;
3330 case WGL_BACK_LEFT_ARB
:
3331 buffer
= GLX_BACK_LEFT_ATI
;
3333 case WGL_BACK_RIGHT_ARB
:
3334 buffer
= GLX_BACK_RIGHT_ATI
;
3337 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3341 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3342 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3343 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3344 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3345 * works fine using our pbuffer emulation path.
3348 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3349 wine_tsx11_unlock();
3355 * X11DRV_wglReleaseTexImageARB
3357 * WGL_ARB_render_texture: wglReleaseTexImageARB
3359 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3361 Wine_GLPBuffer
* object
= hPbuffer
;
3362 GLboolean ret
= GL_FALSE
;
3364 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3365 if (NULL
== object
) {
3366 SetLastError(ERROR_INVALID_HANDLE
);
3369 if (!object
->use_render_texture
) {
3370 SetLastError(ERROR_INVALID_HANDLE
);
3373 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3376 if (NULL
!= pglXReleaseTexImageATI
) {
3381 case WGL_FRONT_LEFT_ARB
:
3382 buffer
= GLX_FRONT_LEFT_ATI
;
3384 case WGL_FRONT_RIGHT_ARB
:
3385 buffer
= GLX_FRONT_RIGHT_ATI
;
3387 case WGL_BACK_LEFT_ARB
:
3388 buffer
= GLX_BACK_LEFT_ATI
;
3390 case WGL_BACK_RIGHT_ARB
:
3391 buffer
= GLX_BACK_RIGHT_ATI
;
3394 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3398 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3399 wine_tsx11_unlock();
3405 * X11DRV_wglGetExtensionsStringEXT
3407 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3409 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3410 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3411 return WineGLInfo
.wglExtensions
;
3415 * X11DRV_wglGetSwapIntervalEXT
3417 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3419 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3420 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
3421 * interval, so the swap interval has to be tracked. */
3423 return swap_interval
;
3427 * X11DRV_wglSwapIntervalEXT
3429 * WGL_EXT_swap_control: wglSwapIntervalEXT
3431 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3434 TRACE("(%d)\n", interval
);
3438 SetLastError(ERROR_INVALID_DATA
);
3441 else if (!has_swap_control
&& interval
== 0)
3443 /* wglSwapIntervalEXT considers an interval value of zero to mean that
3444 * vsync should be disabled, but glXSwapIntervalSGI considers such a
3445 * value to be an error. Just silently ignore the request for now. */
3446 WARN("Request to disable vertical sync is not handled\n");
3451 if (pglXSwapIntervalSGI
)
3454 ret
= !pglXSwapIntervalSGI(interval
);
3455 wine_tsx11_unlock();
3458 WARN("GLX_SGI_swap_control extension is not available\n");
3461 swap_interval
= interval
;
3463 SetLastError(ERROR_DC_NOT_FOUND
);
3470 * X11DRV_wglAllocateMemoryNV
3472 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3474 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3476 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3478 if (pglXAllocateMemoryNV
)
3481 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3482 wine_tsx11_unlock();
3488 * X11DRV_wglFreeMemoryNV
3490 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3492 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3493 TRACE("(%p)\n", pointer
);
3494 if (pglXFreeMemoryNV
== NULL
)
3498 pglXFreeMemoryNV(pointer
);
3499 wine_tsx11_unlock();
3503 * X11DRV_wglSetPixelFormatWINE
3505 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3506 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3508 BOOL
X11DRV_wglSetPixelFormatWINE(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3510 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3512 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
3514 if (!has_opengl()) return FALSE
;
3516 if (physDev
->current_pf
== iPixelFormat
) return TRUE
;
3518 /* Relay to the core SetPixelFormat */
3519 TRACE("Changing iPixelFormat from %d to %d\n", physDev
->current_pf
, iPixelFormat
);
3520 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
3524 * glxRequireVersion (internal)
3526 * Check if the supported GLX version matches requiredVersion.
3528 static BOOL
glxRequireVersion(int requiredVersion
)
3530 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3531 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3537 static BOOL
glxRequireExtension(const char *requiredExtension
)
3539 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3546 static void register_extension_string(const char *ext
)
3548 if (WineGLInfo
.wglExtensions
[0])
3549 strcat(WineGLInfo
.wglExtensions
, " ");
3550 strcat(WineGLInfo
.wglExtensions
, ext
);
3552 TRACE("'%s'\n", ext
);
3555 static BOOL
register_extension(const WineGLExtension
* ext
)
3559 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3560 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3562 register_extension_string(ext
->extName
);
3564 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3565 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3570 static const WineGLExtension WGL_internal_functions
=
3574 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3575 { "wglFinish", X11DRV_wglFinish
},
3576 { "wglFlush", X11DRV_wglFlush
},
3581 static const WineGLExtension WGL_ARB_create_context
=
3583 "WGL_ARB_create_context",
3585 { "wglCreateContextAttribsARB", X11DRV_wglCreateContextAttribsARB
},
3589 static const WineGLExtension WGL_ARB_extensions_string
=
3591 "WGL_ARB_extensions_string",
3593 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3597 static const WineGLExtension WGL_ARB_make_current_read
=
3599 "WGL_ARB_make_current_read",
3601 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3602 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3606 static const WineGLExtension WGL_ARB_multisample
=
3608 "WGL_ARB_multisample",
3611 static const WineGLExtension WGL_ARB_pbuffer
=
3615 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3616 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3617 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3618 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3619 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3620 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3624 static const WineGLExtension WGL_ARB_pixel_format
=
3626 "WGL_ARB_pixel_format",
3628 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3629 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3630 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3634 static const WineGLExtension WGL_ARB_render_texture
=
3636 "WGL_ARB_render_texture",
3638 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3639 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3643 static const WineGLExtension WGL_EXT_extensions_string
=
3645 "WGL_EXT_extensions_string",
3647 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3651 static const WineGLExtension WGL_EXT_swap_control
=
3653 "WGL_EXT_swap_control",
3655 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3656 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3660 static const WineGLExtension WGL_NV_vertex_array_range
=
3662 "WGL_NV_vertex_array_range",
3664 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3665 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3669 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3671 "WGL_WINE_pixel_format_passthrough",
3673 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE
},
3678 * X11DRV_WineGL_LoadExtensions
3680 static void X11DRV_WineGL_LoadExtensions(void)
3682 WineGLInfo
.wglExtensions
[0] = 0;
3684 /* Load Wine internal functions */
3685 register_extension(&WGL_internal_functions
);
3687 /* ARB Extensions */
3689 if(glxRequireExtension("GLX_ARB_create_context"))
3691 register_extension(&WGL_ARB_create_context
);
3693 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3694 register_extension_string("WGL_ARB_create_context_profile");
3697 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3699 register_extension_string("WGL_ARB_pixel_format_float");
3700 register_extension_string("WGL_ATI_pixel_format_float");
3703 register_extension(&WGL_ARB_extensions_string
);
3705 if (glxRequireVersion(3))
3706 register_extension(&WGL_ARB_make_current_read
);
3708 if (glxRequireExtension("GLX_ARB_multisample"))
3709 register_extension(&WGL_ARB_multisample
);
3711 /* In general pbuffer functionality requires support in the X-server. The functionality is
3712 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3713 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3714 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3716 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3717 * without support in the X-server (which other Mesa based drivers require).
3719 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3720 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3721 * is available pbuffers must be available too. */
3722 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3723 register_extension(&WGL_ARB_pbuffer
);
3725 register_extension(&WGL_ARB_pixel_format
);
3727 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3728 if (glxRequireExtension("GLX_ATI_render_texture") ||
3729 glxRequireExtension("GLX_ARB_render_texture") ||
3730 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3732 register_extension(&WGL_ARB_render_texture
);
3734 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3735 if(glxRequireExtension("GLX_NV_float_buffer"))
3736 register_extension_string("WGL_NV_float_buffer");
3738 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3739 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3740 register_extension_string("WGL_NV_texture_rectangle");
3743 /* EXT Extensions */
3745 register_extension(&WGL_EXT_extensions_string
);
3747 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3748 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3749 register_extension(&WGL_EXT_swap_control
);
3751 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3752 register_extension_string("WGL_EXT_framebuffer_sRGB");
3754 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3755 register_extension_string("WGL_EXT_pixel_format_packed_float");
3757 if (glxRequireExtension("GLX_EXT_swap_control"))
3758 has_swap_control
= TRUE
;
3760 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3761 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3762 register_extension(&WGL_NV_vertex_array_range
);
3764 /* WINE-specific WGL Extensions */
3766 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3767 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3769 register_extension(&WGL_WINE_pixel_format_passthrough
);
3773 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3776 pglXDestroyGLXPixmap(display
, glxpixmap
);
3777 wine_tsx11_unlock();
3782 * X11DRV_SwapBuffers
3784 * Swap the buffers of this DC
3786 BOOL
X11DRV_SwapBuffers(PHYSDEV dev
)
3788 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3789 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3791 if (!has_opengl()) return FALSE
;
3793 TRACE("(%p)\n", physDev
);
3797 WARN("Using a NULL context, skipping\n");
3798 SetLastError(ERROR_INVALID_HANDLE
);
3802 if (!physDev
->gl_drawable
)
3804 WARN("Using an invalid drawable, skipping\n");
3805 SetLastError(ERROR_INVALID_HANDLE
);
3811 if(physDev
->pixmap
) {
3812 if(pglXCopySubBufferMESA
) {
3813 int w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
3814 int h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
3816 /* (glX)SwapBuffers has an implicit glFlush effect, however
3817 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3821 pglXCopySubBufferMESA(gdi_display
, physDev
->gl_drawable
, 0, 0, w
, h
);
3824 pglXSwapBuffers(gdi_display
, physDev
->gl_drawable
);
3827 pglXSwapBuffers(gdi_display
, physDev
->gl_drawable
);
3829 flush_gl_drawable(physDev
);
3830 wine_tsx11_unlock();
3835 static long prev_time
, start_time
;
3836 static unsigned long frames
, frames_total
;
3838 DWORD time
= GetTickCount();
3841 /* every 1.5 seconds */
3842 if (time
- prev_time
> 1500) {
3843 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3844 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3847 if(start_time
== 0) start_time
= time
;
3854 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3856 WineGLPixelFormat
*fmt
;
3859 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3864 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3865 wine_tsx11_unlock();
3869 #else /* no OpenGL includes */
3871 void X11DRV_OpenGL_Cleanup(void)
3875 static inline void opengl_error(void)
3878 if (!warned
++) ERR("No OpenGL support compiled in.\n");
3881 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3886 void mark_drawable_dirty(Drawable old
, Drawable
new)
3890 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
3894 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3899 /***********************************************************************
3900 * ChoosePixelFormat (X11DRV.@)
3902 int X11DRV_ChoosePixelFormat(PHYSDEV dev
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3908 /***********************************************************************
3909 * DescribePixelFormat (X11DRV.@)
3911 int X11DRV_DescribePixelFormat(PHYSDEV dev
, int iPixelFormat
, UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
3917 /***********************************************************************
3918 * GetPixelFormat (X11DRV.@)
3920 int X11DRV_GetPixelFormat(PHYSDEV dev
)
3926 /***********************************************************************
3927 * SetPixelFormat (X11DRV.@)
3929 BOOL
X11DRV_SetPixelFormat(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3935 /***********************************************************************
3936 * SwapBuffers (X11DRV.@)
3938 BOOL
X11DRV_SwapBuffers(PHYSDEV dev
)
3945 * X11DRV_wglCopyContext
3947 * For OpenGL32 wglCopyContext.
3949 BOOL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
3956 * X11DRV_wglCreateContext
3958 * For OpenGL32 wglCreateContext.
3960 HGLRC
X11DRV_wglCreateContext(PHYSDEV dev
)
3967 * X11DRV_wglCreateContextAttribsARB
3969 * WGL_ARB_create_context: wglCreateContextAttribsARB
3971 HGLRC
X11DRV_wglCreateContextAttribsARB(PHYSDEV dev
, HGLRC hShareContext
, const int* attribList
)
3978 * X11DRV_wglDeleteContext
3980 * For OpenGL32 wglDeleteContext.
3982 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
3989 * X11DRV_wglGetProcAddress
3991 * For OpenGL32 wglGetProcAddress.
3993 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
3999 HDC
X11DRV_wglGetPbufferDCARB(PHYSDEV dev
, void *hPbuffer
)
4005 BOOL
X11DRV_wglMakeContextCurrentARB(PHYSDEV draw_dev
, PHYSDEV read_dev
, HGLRC hglrc
)
4012 * X11DRV_wglMakeCurrent
4014 * For OpenGL32 wglMakeCurrent.
4016 BOOL
X11DRV_wglMakeCurrent(PHYSDEV dev
, HGLRC hglrc
)
4023 * X11DRV_wglShareLists
4025 * For OpenGL32 wglShareLists.
4027 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
4034 * X11DRV_wglUseFontBitmapsA
4036 * For OpenGL32 wglUseFontBitmapsA.
4038 BOOL
X11DRV_wglUseFontBitmapsA(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
4045 * X11DRV_wglUseFontBitmapsW
4047 * For OpenGL32 wglUseFontBitmapsW.
4049 BOOL
X11DRV_wglUseFontBitmapsW(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
4056 * X11DRV_wglSetPixelFormatWINE
4058 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
4059 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
4061 BOOL
X11DRV_wglSetPixelFormatWINE(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
4067 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
4072 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
4077 #endif /* defined(SONAME_LIBGL) */