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
{
115 BOOL has_been_current
;
120 WineGLPixelFormat
*fmt
;
121 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
122 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
125 Drawable drawables
[2];
126 BOOL refresh_drawables
;
127 struct wine_glcontext
*next
;
128 struct wine_glcontext
*prev
;
131 typedef struct wine_glpbuffer
{
134 WineGLPixelFormat
* fmt
;
140 int use_render_texture
; /* This is also the internal texture format */
141 int texture_bind_target
;
143 GLint texture_format
;
144 GLuint texture_target
;
150 static Wine_GLContext
*context_list
;
151 static struct WineGLInfo WineGLInfo
= { 0 };
152 static int use_render_texture_emulation
= 1;
153 static int use_render_texture_ati
= 0;
154 static BOOL has_swap_control
;
155 static int swap_interval
= 1;
157 #define MAX_EXTENSIONS 16
158 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
159 static int WineGLExtensionListSize
;
161 static void X11DRV_WineGL_LoadExtensions(void);
162 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
163 static BOOL
glxRequireVersion(int requiredVersion
);
164 static BOOL
glxRequireExtension(const char *requiredExtension
);
166 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
167 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
168 TRACE(" - dwFlags : ");
169 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
173 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
174 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
175 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
176 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
177 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
178 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
179 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
180 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
181 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
182 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
183 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
184 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
185 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
186 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
187 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
188 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
192 TRACE(" - iPixelType : ");
193 switch (ppfd
->iPixelType
) {
194 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
195 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
199 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
200 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
201 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
202 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
203 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
204 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
205 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
206 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
207 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
209 TRACE(" - iLayerType : ");
210 switch (ppfd
->iLayerType
) {
211 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
212 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
213 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
218 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
219 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
221 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
223 MAKE_FUNCPTR(glXChooseVisual
)
224 MAKE_FUNCPTR(glXCopyContext
)
225 MAKE_FUNCPTR(glXCreateContext
)
226 MAKE_FUNCPTR(glXCreateGLXPixmap
)
227 MAKE_FUNCPTR(glXGetCurrentContext
)
228 MAKE_FUNCPTR(glXGetCurrentDrawable
)
229 MAKE_FUNCPTR(glXDestroyContext
)
230 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
231 MAKE_FUNCPTR(glXGetConfig
)
232 MAKE_FUNCPTR(glXIsDirect
)
233 MAKE_FUNCPTR(glXMakeCurrent
)
234 MAKE_FUNCPTR(glXSwapBuffers
)
235 MAKE_FUNCPTR(glXQueryExtension
)
236 MAKE_FUNCPTR(glXQueryVersion
)
237 MAKE_FUNCPTR(glXUseXFont
)
240 MAKE_FUNCPTR(glXGetClientString
)
241 MAKE_FUNCPTR(glXQueryExtensionsString
)
242 MAKE_FUNCPTR(glXQueryServerString
)
245 MAKE_FUNCPTR(glXGetFBConfigs
)
246 MAKE_FUNCPTR(glXChooseFBConfig
)
247 MAKE_FUNCPTR(glXCreatePbuffer
)
248 MAKE_FUNCPTR(glXCreateNewContext
)
249 MAKE_FUNCPTR(glXDestroyPbuffer
)
250 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
251 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
252 MAKE_FUNCPTR(glXMakeContextCurrent
)
253 MAKE_FUNCPTR(glXQueryDrawable
)
254 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
257 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
258 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
259 static int (*pglXSwapIntervalSGI
)(int);
261 /* ATI GLX Extensions */
262 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
263 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
264 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
266 /* NV GLX Extension */
267 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
268 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
270 /* MESA GLX Extensions */
271 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
273 /* Standard OpenGL */
274 MAKE_FUNCPTR(glBindTexture
)
275 MAKE_FUNCPTR(glBitmap
)
276 MAKE_FUNCPTR(glCopyTexSubImage1D
)
277 MAKE_FUNCPTR(glCopyTexImage2D
)
278 MAKE_FUNCPTR(glCopyTexSubImage2D
)
279 MAKE_FUNCPTR(glDrawBuffer
)
280 MAKE_FUNCPTR(glEndList
)
281 MAKE_FUNCPTR(glGetError
)
282 MAKE_FUNCPTR(glGetIntegerv
)
283 MAKE_FUNCPTR(glGetString
)
284 MAKE_FUNCPTR(glNewList
)
285 MAKE_FUNCPTR(glPixelStorei
)
286 MAKE_FUNCPTR(glReadPixels
)
287 MAKE_FUNCPTR(glTexImage2D
)
288 MAKE_FUNCPTR(glFinish
)
289 MAKE_FUNCPTR(glFlush
)
292 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
294 /* In the future we might want to find the exact X or GLX error to report back to the app */
298 static BOOL infoInitialized
= FALSE
;
299 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
301 int screen
= DefaultScreen(gdi_display
);
302 Window win
= 0, root
= 0;
303 const char *gl_renderer
;
306 GLXContext ctx
= NULL
;
307 XSetWindowAttributes attr
;
309 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
313 infoInitialized
= TRUE
;
315 attr
.override_redirect
= True
;
316 attr
.colormap
= None
;
317 attr
.border_pixel
= 0;
321 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
324 WORD old_fs
= wine_get_fs();
325 /* Create a GLX Context. Without one we can't query GL information */
326 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
327 if (wine_get_fs() != old_fs
)
329 wine_set_fs( old_fs
);
330 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
331 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
335 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
340 root
= RootWindow( gdi_display
, vis
->screen
);
341 if (vis
->visual
!= DefaultVisual( gdi_display
, vis
->screen
))
342 attr
.colormap
= XCreateColormap( gdi_display
, root
, vis
->visual
, AllocNone
);
343 if ((win
= XCreateWindow( gdi_display
, root
, -1, -1, 1, 1, 0, vis
->depth
, InputOutput
,
344 vis
->visual
, CWBorderPixel
| CWOverrideRedirect
| CWColormap
, &attr
)))
345 XMapWindow( gdi_display
, win
);
349 if(pglXMakeCurrent(gdi_display
, win
, ctx
) == 0)
351 ERR_(winediag
)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
354 gl_renderer
= (const char *)pglGetString(GL_RENDERER
);
355 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
356 str
= (const char *) pglGetString(GL_EXTENSIONS
);
357 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
358 strcpy(WineGLInfo
.glExtensions
, str
);
360 /* Get the common GLX version supported by GLX client and server ( major/minor) */
361 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
363 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
364 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
365 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
367 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
368 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
369 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
371 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
372 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
374 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
375 TRACE("GL renderer : %s.\n", gl_renderer
);
376 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
377 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
378 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
379 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
380 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
381 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
383 if(!WineGLInfo
.glxDirect
)
385 int fd
= ConnectionNumber(gdi_display
);
386 struct sockaddr_un uaddr
;
387 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
389 /* In general indirect rendering on a local X11 server indicates a driver problem.
390 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
392 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
393 ERR_(winediag
)("Direct rendering is disabled, most likely your OpenGL drivers "
394 "haven't been installed correctly (using GL renderer %s, version %s).\n",
395 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
399 /* In general you would expect that if direct rendering is returned, that you receive hardware
400 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
401 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
402 * software rendering, it shows direct rendering.
404 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
405 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
406 * it shows 'Mesa X11'.
408 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
409 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
410 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
411 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
418 pglXMakeCurrent(gdi_display
, None
, NULL
);
419 pglXDestroyContext(gdi_display
, ctx
);
421 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
422 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
424 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
428 void X11DRV_OpenGL_Cleanup(void)
430 HeapFree(GetProcessHeap(), 0, WineGLInfo
.glExtensions
);
431 infoInitialized
= FALSE
;
434 static BOOL
has_opengl(void)
436 static int init_done
;
437 static void *opengl_handle
;
440 int error_base
, event_base
;
442 if (init_done
) return (opengl_handle
!= NULL
);
445 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
446 and include all dependencies */
447 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
448 if (opengl_handle
== NULL
)
450 ERR( "Failed to load libGL: %s\n", buffer
);
451 ERR( "OpenGL support is disabled.\n");
455 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
456 if (pglXGetProcAddressARB
== NULL
) {
457 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
461 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
463 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
468 LOAD_FUNCPTR(glXChooseVisual
);
469 LOAD_FUNCPTR(glXCopyContext
);
470 LOAD_FUNCPTR(glXCreateContext
);
471 LOAD_FUNCPTR(glXCreateGLXPixmap
);
472 LOAD_FUNCPTR(glXGetCurrentContext
);
473 LOAD_FUNCPTR(glXGetCurrentDrawable
);
474 LOAD_FUNCPTR(glXDestroyContext
);
475 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
476 LOAD_FUNCPTR(glXGetConfig
);
477 LOAD_FUNCPTR(glXIsDirect
);
478 LOAD_FUNCPTR(glXMakeCurrent
);
479 LOAD_FUNCPTR(glXSwapBuffers
);
480 LOAD_FUNCPTR(glXQueryExtension
);
481 LOAD_FUNCPTR(glXQueryVersion
);
482 LOAD_FUNCPTR(glXUseXFont
);
485 LOAD_FUNCPTR(glXGetClientString
);
486 LOAD_FUNCPTR(glXQueryExtensionsString
);
487 LOAD_FUNCPTR(glXQueryServerString
);
490 LOAD_FUNCPTR(glXCreatePbuffer
);
491 LOAD_FUNCPTR(glXCreateNewContext
);
492 LOAD_FUNCPTR(glXDestroyPbuffer
);
493 LOAD_FUNCPTR(glXMakeContextCurrent
);
494 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
495 LOAD_FUNCPTR(glXGetFBConfigs
);
497 /* Standard OpenGL calls */
498 LOAD_FUNCPTR(glBindTexture
);
499 LOAD_FUNCPTR(glBitmap
);
500 LOAD_FUNCPTR(glCopyTexSubImage1D
);
501 LOAD_FUNCPTR(glCopyTexImage2D
);
502 LOAD_FUNCPTR(glCopyTexSubImage2D
);
503 LOAD_FUNCPTR(glDrawBuffer
);
504 LOAD_FUNCPTR(glEndList
);
505 LOAD_FUNCPTR(glGetError
);
506 LOAD_FUNCPTR(glGetIntegerv
);
507 LOAD_FUNCPTR(glGetString
);
508 LOAD_FUNCPTR(glNewList
);
509 LOAD_FUNCPTR(glPixelStorei
);
510 LOAD_FUNCPTR(glReadPixels
);
511 LOAD_FUNCPTR(glTexImage2D
);
512 LOAD_FUNCPTR(glFinish
);
513 LOAD_FUNCPTR(glFlush
);
516 /* It doesn't matter if these fail. They'll only be used if the driver reports
517 the associated extension is available (and if a driver reports the extension
518 is available but fails to provide the functions, it's quite broken) */
519 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
520 /* ARB GLX Extension */
521 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
522 /* SGI GLX Extension */
523 LOAD_FUNCPTR(glXSwapIntervalSGI
);
524 /* NV GLX Extension */
525 LOAD_FUNCPTR(glXAllocateMemoryNV
);
526 LOAD_FUNCPTR(glXFreeMemoryNV
);
529 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
532 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
533 TRACE("GLX is up and running error_base = %d\n", error_base
);
536 ERR( "GLX extension is missing, disabling OpenGL.\n" );
540 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
541 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
544 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
545 * depends on the reported GLX client / server version and on the client / server extension list.
546 * Those don't have to be the same.
548 * In general the server GLX information lists the capabilities in case of indirect rendering.
549 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
550 * available and in that case the client GLX informat can be used.
551 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
552 * in the GLX version/extension list. When a program does this it works for certain for both
553 * direct and indirect rendering.
555 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
556 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
557 * extension list which causes this extension not to be listed. (Wine requires this extension).
558 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
559 * pbuffers is around.
561 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
562 * the ATI drivers and from then on use GLX client information for them.
565 if(glxRequireVersion(3)) {
566 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
567 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
568 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
569 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
570 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
571 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
572 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
573 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
575 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
576 * enable this function when the Xserver understand GLX 1.3 or newer
578 pglXQueryDrawable
= NULL
;
579 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
580 TRACE("Overriding ATI GLX capabilities!\n");
581 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
582 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
583 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
584 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
586 /* Use client GLX information in case of the ATI drivers. We override the
587 * capabilities over here and not somewhere else as ATI might better their
588 * life in the future. In case they release proper drivers this block of
589 * code won't be called. */
590 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
592 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
595 if(glxRequireExtension("GLX_ATI_render_texture")) {
596 use_render_texture_ati
= 1;
597 pglXBindTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
598 pglXReleaseTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
599 pglXDrawableAttribATI
= pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
602 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
603 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
606 X11DRV_WineGL_LoadExtensions();
612 wine_dlclose(opengl_handle
, NULL
, 0);
613 opengl_handle
= NULL
;
617 static inline Wine_GLContext
*alloc_context(void)
621 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
623 ret
->next
= context_list
;
624 if (context_list
) context_list
->prev
= ret
;
630 static inline void free_context(Wine_GLContext
*context
)
632 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
633 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
634 else context_list
= context
->next
;
636 if (context
->vis
) XFree(context
->vis
);
637 HeapFree(GetProcessHeap(), 0, context
);
640 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
643 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
644 return (ptr
!= NULL
);
647 static int describeContext(Wine_GLContext
* ctx
) {
650 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
651 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
652 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
653 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
654 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
659 static BOOL
describeDrawable(X11DRV_PDEVICE
*physDev
) {
661 WineGLPixelFormat
*fmt
;
664 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
/* Offscreen */, &fmt_count
);
665 if(!fmt
) return FALSE
;
667 TRACE(" HDC %p has:\n", physDev
->dev
.hdc
);
668 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
669 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev
));
670 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
672 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
673 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
678 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
683 int nvfloatattrib
= GLX_DONT_CARE
;
684 int pixelattrib
= ~0;
686 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
687 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
688 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
689 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
691 switch (iWGLAttr
[cur
]) {
692 case WGL_AUX_BUFFERS_ARB
:
693 pop
= iWGLAttr
[++cur
];
694 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
695 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
697 case WGL_COLOR_BITS_ARB
:
698 pop
= iWGLAttr
[++cur
];
699 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
700 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
702 case WGL_BLUE_BITS_ARB
:
703 pop
= iWGLAttr
[++cur
];
704 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
705 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
707 case WGL_RED_BITS_ARB
:
708 pop
= iWGLAttr
[++cur
];
709 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
710 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
712 case WGL_GREEN_BITS_ARB
:
713 pop
= iWGLAttr
[++cur
];
714 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
715 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
717 case WGL_ALPHA_BITS_ARB
:
718 pop
= iWGLAttr
[++cur
];
719 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
720 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
722 case WGL_DEPTH_BITS_ARB
:
723 pop
= iWGLAttr
[++cur
];
724 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
725 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
727 case WGL_STENCIL_BITS_ARB
:
728 pop
= iWGLAttr
[++cur
];
729 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
730 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
732 case WGL_DOUBLE_BUFFER_ARB
:
733 pop
= iWGLAttr
[++cur
];
734 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
735 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
738 pop
= iWGLAttr
[++cur
];
739 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
740 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
743 case WGL_PIXEL_TYPE_ARB
:
744 pop
= iWGLAttr
[++cur
];
745 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
747 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
748 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
749 /* 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 */
750 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
751 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
753 ERR("unexpected PixelType(%x)\n", pop
);
758 case WGL_SUPPORT_GDI_ARB
:
759 /* This flag is set in a WineGLPixelFormat */
760 pop
= iWGLAttr
[++cur
];
761 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
764 case WGL_DRAW_TO_BITMAP_ARB
:
765 /* This flag is set in a WineGLPixelFormat */
766 pop
= iWGLAttr
[++cur
];
767 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
770 case WGL_DRAW_TO_WINDOW_ARB
:
771 pop
= iWGLAttr
[++cur
];
772 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
773 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
775 drawattrib
|= GLX_WINDOW_BIT
;
779 case WGL_DRAW_TO_PBUFFER_ARB
:
780 pop
= iWGLAttr
[++cur
];
781 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
782 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
784 drawattrib
|= GLX_PBUFFER_BIT
;
788 case WGL_ACCELERATION_ARB
:
789 /* This flag is set in a WineGLPixelFormat */
790 pop
= iWGLAttr
[++cur
];
791 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
794 case WGL_SUPPORT_OPENGL_ARB
:
795 pop
= iWGLAttr
[++cur
];
796 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
797 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
800 case WGL_SWAP_METHOD_ARB
:
801 pop
= iWGLAttr
[++cur
];
802 /* For now we ignore this and just return SWAP_EXCHANGE */
803 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
806 case WGL_PBUFFER_LARGEST_ARB
:
807 pop
= iWGLAttr
[++cur
];
808 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
809 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
812 case WGL_SAMPLE_BUFFERS_ARB
:
813 pop
= iWGLAttr
[++cur
];
814 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
815 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
818 case WGL_SAMPLES_ARB
:
819 pop
= iWGLAttr
[++cur
];
820 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
821 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
824 case WGL_TEXTURE_FORMAT_ARB
:
825 case WGL_TEXTURE_TARGET_ARB
:
826 case WGL_MIPMAP_TEXTURE_ARB
:
827 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
828 pop
= iWGLAttr
[++cur
];
830 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
832 if (use_render_texture_ati
) {
833 /** nothing to do here */
835 else if (!use_render_texture_emulation
) {
836 if (WGL_NO_TEXTURE_ARB
!= pop
) {
837 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
838 return -1; /** error: don't support it */
840 drawattrib
|= GLX_PBUFFER_BIT
;
844 case WGL_FLOAT_COMPONENTS_NV
:
845 nvfloatattrib
= iWGLAttr
[++cur
];
846 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
848 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
849 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
850 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
851 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
852 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
853 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
854 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
855 pop
= iWGLAttr
[++cur
];
856 /** cannot be converted, see direct handling on
857 * - wglGetPixelFormatAttribivARB
858 * TODO: wglChoosePixelFormat
861 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
862 pop
= iWGLAttr
[++cur
];
863 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
864 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
867 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
868 pop
= iWGLAttr
[++cur
];
869 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
870 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
873 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
879 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
880 * all formats. Unless drawattrib is set to a non-zero value override it with ~0, so that pixmap and pbuffer
881 * formats appear as well. */
882 if(!drawattrib
) drawattrib
= ~0;
883 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
884 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
886 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
887 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to ~0 unless
888 * it is overridden. */
889 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
890 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
892 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
893 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
894 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
895 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
901 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
903 int render_type
=0, render_type_bit
;
904 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
905 switch(render_type_bit
)
908 render_type
= GLX_RGBA_TYPE
;
910 case GLX_COLOR_INDEX_BIT
:
911 render_type
= GLX_COLOR_INDEX_TYPE
;
913 case GLX_RGBA_FLOAT_BIT
:
914 render_type
= GLX_RGBA_FLOAT_TYPE
;
916 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
917 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
920 ERR("Unknown render_type: %x\n", render_type_bit
);
925 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
926 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
929 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
930 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
932 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
933 * the GLX_PIXMAP_BIT set. */
934 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
937 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
939 static WineGLPixelFormat
*list
;
940 static int size
, onscreen_size
;
942 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
944 XVisualInfo
*visinfo
;
949 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
950 if (NULL
== cfgs
|| 0 == nCfgs
) {
951 if(cfgs
!= NULL
) XFree(cfgs
);
953 ERR("glXChooseFBConfig returns NULL\n");
957 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
958 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
959 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
960 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
962 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
964 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
966 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
969 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
971 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
973 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
974 * Do this as GLX doesn't guarantee that the list is sorted */
975 for(run
=0; run
< 2; run
++)
977 for(i
=0; i
<nCfgs
; i
++) {
978 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
979 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
981 /* The first run we only add onscreen formats (ones which have an associated X Visual).
982 * The second run we only set offscreen formats. */
985 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
986 * The contents is copied to the destination using XCopyArea. For the copying to work
987 * the depth of the source and destination window should be the same. In general this should
988 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
989 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
990 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
991 * list formats with the same depth. */
992 if(visinfo
->depth
!= screen_depth
)
998 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
999 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1000 list
[size
].fbconfig
= cfgs
[i
];
1001 list
[size
].fmt_id
= fmt_id
;
1002 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1003 list
[size
].offscreenOnly
= FALSE
;
1004 list
[size
].dwFlags
= 0;
1008 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1009 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1011 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1012 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1013 list
[size
].fbconfig
= cfgs
[i
];
1014 list
[size
].fmt_id
= fmt_id
;
1015 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1016 list
[size
].offscreenOnly
= FALSE
;
1017 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
1021 } else if(run
&& !visinfo
) {
1022 int window_drawable
=0;
1023 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
1025 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1026 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1027 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1028 * likely make our child window opengl rendering more complicated since likely you can't use
1029 * XCopyArea on a GLX Window.
1030 * For now ignore fbconfigs which are window drawable but lack a visual. */
1031 if(window_drawable
& GLX_WINDOW_BIT
)
1033 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
1037 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1038 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1039 list
[size
].fbconfig
= cfgs
[i
];
1040 list
[size
].fmt_id
= fmt_id
;
1041 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1042 list
[size
].offscreenOnly
= TRUE
;
1043 list
[size
].dwFlags
= 0;
1047 if (visinfo
) XFree(visinfo
);
1054 if (size_ret
) *size_ret
= size
;
1055 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
1056 wine_tsx11_unlock();
1060 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1061 * In our WGL implementation we only support a subset of these formats namely the format of
1062 * Wine's main visual and offscreen formats (if they are available).
1063 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1064 * and it returns the number of supported WGL formats in fmt_count.
1066 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
1068 WineGLPixelFormat
*list
, *res
= NULL
;
1069 int size
, onscreen_size
;
1071 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
1073 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1074 * iPixelFormat in case of probing the number of pixelformats.
1076 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
1077 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
1078 res
= &list
[iPixelFormat
-1];
1079 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res
->fmt_id
, iPixelFormat
);
1085 *fmt_count
= onscreen_size
;
1087 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1092 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1093 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1095 WineGLPixelFormat
*list
;
1098 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1100 for(i
=0; i
<size
; i
++) {
1101 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1102 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1103 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1104 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1108 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1112 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1114 WineGLPixelFormat
*fmt
;
1116 if (!fbconfig_id
) return 0;
1118 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1120 return fmt
->iPixelFormat
;
1121 /* This will happen on hwnds without a pixel format set; it's ok */
1126 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1127 void mark_drawable_dirty(Drawable old
, Drawable
new)
1129 Wine_GLContext
*ctx
;
1130 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
1131 if (old
== ctx
->drawables
[0]) {
1132 ctx
->drawables
[0] = new;
1133 ctx
->refresh_drawables
= TRUE
;
1135 if (old
== ctx
->drawables
[1]) {
1136 ctx
->drawables
[1] = new;
1137 ctx
->refresh_drawables
= TRUE
;
1142 /* Given the current context, make sure its drawable is sync'd */
1143 static inline void sync_context(Wine_GLContext
*context
)
1145 if(context
&& context
->refresh_drawables
) {
1146 if (glxRequireVersion(3))
1147 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1148 context
->drawables
[1], context
->ctx
);
1150 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1151 context
->refresh_drawables
= FALSE
;
1156 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1160 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1161 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1163 if(context
->gl3_context
)
1165 if(context
->numAttribs
)
1166 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1168 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1170 else if(context
->vis
)
1171 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1172 else /* Create a GLX Context for a pbuffer */
1173 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1179 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1181 return pglXCreateGLXPixmap(display
, vis
, parent
);
1185 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1192 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1194 if(vis
->depth
== physDev
->bitmap
->depth
)
1195 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1198 wine_tsx11_unlock();
1199 TRACE("return %lx\n", ret
);
1204 * X11DRV_ChoosePixelFormat
1206 * Equivalent to glXChooseVisual.
1208 int X11DRV_ChoosePixelFormat(PHYSDEV dev
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1210 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1211 WineGLPixelFormat
*list
;
1216 int bestFormat
= -1;
1217 int bestDBuffer
= -1;
1218 int bestStereo
= -1;
1222 int bestStencil
= -1;
1225 if (!has_opengl()) return 0;
1227 if (TRACE_ON(wgl
)) {
1228 TRACE("(%p,%p)\n", physDev
, ppfd
);
1230 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1233 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1236 for(i
=0; i
<onscreen_size
; i
++)
1240 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1241 WineGLPixelFormat
*fmt
= &list
[i
];
1244 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1245 if (value
& GLX_RGBA_BIT
)
1246 iPixelType
= PFD_TYPE_RGBA
;
1248 iPixelType
= PFD_TYPE_COLORINDEX
;
1250 if (ppfd
->iPixelType
!= iPixelType
)
1252 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1256 /* Only use bitmap capable for formats for bitmap rendering.
1257 * See get_formats for more info. */
1258 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1260 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1264 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1265 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1266 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1267 if (value
) dwFlags
|= PFD_STEREO
;
1268 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1269 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1270 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1271 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1272 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1274 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1275 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1276 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1277 * formats without the given flag set.
1278 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1279 * has indicated that a format without stereo is returned when stereo is unavailable.
1280 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1281 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1283 * To summarize the following is most likely the correct behavior:
1284 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1285 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1286 * stereo don't care -> it doesn't matter whether we get stereo or not
1288 * In Wine we will treat no-stereo the same way as don't care because it makes
1289 * format selection even more complicated and second drivers with Stereo advertise
1290 * each format twice anyway.
1293 /* Doublebuffer, see the comments above */
1294 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1295 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1296 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1298 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1299 bestStereo
= dwFlags
& PFD_STEREO
;
1303 bestStencil
= stencil
;
1308 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1312 /* Stereo, see the comments above. */
1313 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1314 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1315 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1317 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1318 bestStereo
= dwFlags
& PFD_STEREO
;
1322 bestStencil
= stencil
;
1327 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1331 /* Below we will do a number of checks to select the 'best' pixelformat.
1332 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1333 * The code works by trying to match the most important options as close as possible.
1334 * When a reasonable format is found, we will try to match more options.
1335 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1336 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1337 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1340 if(ppfd
->cColorBits
) {
1341 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1342 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1344 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1345 bestStereo
= dwFlags
& PFD_STEREO
;
1349 bestStencil
= stencil
;
1353 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1354 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1360 if(ppfd
->cAlphaBits
) {
1361 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1362 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1364 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1365 bestStereo
= dwFlags
& PFD_STEREO
;
1369 bestStencil
= stencil
;
1373 } else if(bestAlpha
!= alpha
) {
1374 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1380 if(ppfd
->cDepthBits
) {
1381 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1382 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1384 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1385 bestStereo
= dwFlags
& PFD_STEREO
;
1389 bestStencil
= stencil
;
1393 } else if(bestDepth
!= depth
) {
1394 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1400 if(ppfd
->cStencilBits
) {
1401 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1402 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1404 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1405 bestStereo
= dwFlags
& PFD_STEREO
;
1409 bestStencil
= stencil
;
1413 } else if(bestStencil
!= stencil
) {
1414 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1420 if(ppfd
->cAuxBuffers
) {
1421 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1422 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1424 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1425 bestStereo
= dwFlags
& PFD_STEREO
;
1429 bestStencil
= stencil
;
1433 } else if(bestAux
!= aux
) {
1434 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1440 if(bestFormat
== -1) {
1441 TRACE("No matching mode was found returning 0\n");
1445 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1446 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1449 wine_tsx11_unlock();
1454 * X11DRV_DescribePixelFormat
1456 * Get the pixel-format descriptor associated to the given id
1458 int X11DRV_DescribePixelFormat(PHYSDEV dev
, int iPixelFormat
,
1459 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1461 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1462 /*XVisualInfo *vis;*/
1465 WineGLPixelFormat
*fmt
;
1469 if (!has_opengl()) return 0;
1471 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1473 /* 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 */
1474 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1476 /* The application is only querying the number of pixelformats */
1478 } else if(fmt
== NULL
) {
1479 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1483 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1484 ERR("Wrong structure size !\n");
1485 /* Should set error */
1491 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1492 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1495 /* These flags are always the same... */
1496 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1497 /* Now the flags extracted from the Visual */
1501 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1502 if(value
& GLX_WINDOW_BIT
)
1503 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1505 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1506 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1507 * 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
1508 * offered the GDI bit either. */
1509 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1511 /* PFD_GENERIC_FORMAT - gdi software rendering
1512 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1513 * none set - full hardware accelerated by a ICD
1515 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1516 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1518 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1520 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1521 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1523 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1526 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1527 if (value
& GLX_RGBA_BIT
)
1528 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1530 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1533 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1534 ppfd
->cColorBits
= value
;
1536 /* Red, green, blue and alpha bits / shifts */
1537 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1538 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1539 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1540 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1541 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1543 ppfd
->cRedBits
= rb
;
1544 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1545 ppfd
->cBlueBits
= bb
;
1546 ppfd
->cBlueShift
= ab
;
1547 ppfd
->cGreenBits
= gb
;
1548 ppfd
->cGreenShift
= bb
+ ab
;
1549 ppfd
->cAlphaBits
= ab
;
1550 ppfd
->cAlphaShift
= 0;
1553 ppfd
->cRedShift
= 0;
1554 ppfd
->cBlueBits
= 0;
1555 ppfd
->cBlueShift
= 0;
1556 ppfd
->cGreenBits
= 0;
1557 ppfd
->cGreenShift
= 0;
1558 ppfd
->cAlphaBits
= 0;
1559 ppfd
->cAlphaShift
= 0;
1562 /* Accum RGBA bits */
1563 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1564 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1565 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1566 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1568 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1569 ppfd
->cAccumRedBits
= rb
;
1570 ppfd
->cAccumGreenBits
= gb
;
1571 ppfd
->cAccumBlueBits
= bb
;
1572 ppfd
->cAccumAlphaBits
= ab
;
1575 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1576 ppfd
->cAuxBuffers
= value
;
1579 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1580 ppfd
->cDepthBits
= value
;
1583 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1584 ppfd
->cStencilBits
= value
;
1586 wine_tsx11_unlock();
1588 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1590 if (TRACE_ON(wgl
)) {
1591 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1598 * X11DRV_GetPixelFormat
1600 * Get the pixel-format id used by this DC
1602 int X11DRV_GetPixelFormat(PHYSDEV dev
)
1604 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1605 WineGLPixelFormat
*fmt
;
1607 TRACE("(%p)\n", physDev
);
1609 if (!physDev
->current_pf
) return 0; /* not set yet */
1611 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1614 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1617 else if(fmt
->offscreenOnly
)
1619 /* Offscreen formats can't be used with traditional WGL calls.
1620 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1621 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1625 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1626 return physDev
->current_pf
;
1629 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1630 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1631 * set the pixel format multiple times. */
1632 static BOOL
internal_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1634 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1635 WineGLPixelFormat
*fmt
;
1639 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1640 if(get_glxdrawable(physDev
) == root_window
)
1642 ERR("Invalid operation on root_window\n");
1646 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1647 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1649 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1654 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1655 wine_tsx11_unlock();
1657 hwnd
= WindowFromDC(physDev
->dev
.hdc
);
1659 if(!(value
&GLX_WINDOW_BIT
)) {
1660 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1664 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, fmt
->fmt_id
, 0)) {
1665 ERR("Couldn't set format of the window, returning failure\n");
1669 else if(physDev
->bitmap
) {
1670 if(!(value
&GLX_PIXMAP_BIT
)) {
1671 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1675 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
, fmt
);
1676 if(!physDev
->bitmap
->glxpixmap
) {
1677 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1682 FIXME("called on a non-window, non-bitmap object?\n");
1685 physDev
->current_pf
= iPixelFormat
;
1687 if (TRACE_ON(wgl
)) {
1691 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1693 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1695 TRACE(" FBConfig have :\n");
1696 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1697 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1698 TRACE(" - VISUAL_ID 0x%x\n", value
);
1699 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1700 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1702 wine_tsx11_unlock();
1709 * X11DRV_SetPixelFormat
1711 * Set the pixel-format id used by this DC
1713 BOOL
X11DRV_SetPixelFormat(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1715 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1717 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1719 if (!has_opengl()) return FALSE
;
1721 if(physDev
->current_pf
) /* cannot change it if already set */
1722 return (physDev
->current_pf
== iPixelFormat
);
1724 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
1728 * X11DRV_wglCopyContext
1730 * For OpenGL32 wglCopyContext.
1732 BOOL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
1734 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1735 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1737 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1740 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1741 wine_tsx11_unlock();
1743 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1748 * X11DRV_wglCreateContext
1750 * For OpenGL32 wglCreateContext.
1752 HGLRC
X11DRV_wglCreateContext(PHYSDEV dev
)
1754 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1755 Wine_GLContext
*ret
;
1756 WineGLPixelFormat
*fmt
;
1757 int hdcPF
= physDev
->current_pf
;
1761 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1763 if (!has_opengl()) return 0;
1765 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1766 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1767 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1768 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1769 * If this fails something is very wrong on the system. */
1771 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1772 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1777 ret
= alloc_context();
1780 ret
->has_been_current
= FALSE
;
1781 ret
->sharing
= FALSE
;
1783 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1784 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1785 wine_tsx11_unlock();
1787 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1792 * X11DRV_wglDeleteContext
1794 * For OpenGL32 wglDeleteContext.
1796 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1798 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1800 TRACE("(%p)\n", hglrc
);
1802 if (!has_opengl()) return 0;
1804 if (!is_valid_context(ctx
))
1806 WARN("Error deleting context !\n");
1807 SetLastError(ERROR_INVALID_HANDLE
);
1811 /* WGL doesn't allow deletion of a context which is current in another thread */
1812 if (ctx
->tid
!= 0 && ctx
->tid
!= GetCurrentThreadId())
1814 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx
);
1815 SetLastError(ERROR_BUSY
);
1819 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1820 if (ctx
== NtCurrentTeb()->glContext
)
1821 wglMakeCurrent(ctx
->hdc
, NULL
);
1826 pglXDestroyContext(gdi_display
, ctx
->ctx
);
1827 wine_tsx11_unlock();
1835 * X11DRV_wglGetCurrentReadDCARB
1837 * For OpenGL32 wglGetCurrentReadDCARB.
1839 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1842 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1844 if (ctx
) ret
= ctx
->read_hdc
;
1846 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1851 * X11DRV_wglGetProcAddress
1853 * For OpenGL32 wglGetProcAddress.
1855 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1858 const WineGLExtension
*ext
;
1860 int padding
= 32 - strlen(lpszProc
);
1864 if (!has_opengl()) return NULL
;
1866 /* Check the table of WGL extensions to see if we need to return a WGL extension
1867 * or a function pointer to a native OpenGL function. */
1868 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1869 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1871 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1872 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1873 ext
= WineGLExtensionList
[i
];
1874 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1875 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1876 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1877 return ext
->extEntryPoints
[j
].funcAddress
;
1883 WARN("(%s) - not found\n", lpszProc
);
1888 * X11DRV_wglMakeCurrent
1890 * For OpenGL32 wglMakeCurrent.
1892 BOOL
X11DRV_wglMakeCurrent(PHYSDEV dev
, HGLRC hglrc
)
1894 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1897 DWORD type
= GetObjectType(hdc
);
1898 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1900 TRACE("(%p,%p)\n", hdc
, hglrc
);
1902 if (!has_opengl()) return FALSE
;
1907 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1908 if (prev_ctx
) prev_ctx
->tid
= 0;
1910 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1911 NtCurrentTeb()->glContext
= NULL
;
1913 else if (!physDev
->current_pf
)
1915 WARN("Trying to use an invalid drawable\n");
1916 SetLastError(ERROR_INVALID_HANDLE
);
1919 else if (ctx
->fmt
->iPixelFormat
!= physDev
->current_pf
)
1921 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1922 hdc
, physDev
->current_pf
, ctx
, ctx
->fmt
->iPixelFormat
);
1923 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1928 Drawable drawable
= get_glxdrawable(physDev
);
1929 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1931 /* The describe lines below are for debugging purposes only */
1932 if (TRACE_ON(wgl
)) {
1933 describeDrawable(physDev
);
1934 describeContext(ctx
);
1937 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1938 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1942 if (prev_ctx
) prev_ctx
->tid
= 0;
1943 NtCurrentTeb()->glContext
= ctx
;
1945 ctx
->has_been_current
= TRUE
;
1946 ctx
->tid
= GetCurrentThreadId();
1948 ctx
->read_hdc
= hdc
;
1949 ctx
->drawables
[0] = drawable
;
1950 ctx
->drawables
[1] = drawable
;
1951 ctx
->refresh_drawables
= FALSE
;
1953 if (type
== OBJ_MEMDC
)
1955 ctx
->do_escape
= TRUE
;
1956 pglDrawBuffer(GL_FRONT_LEFT
);
1960 SetLastError(ERROR_INVALID_HANDLE
);
1962 wine_tsx11_unlock();
1963 TRACE(" returning %s\n", (ret
? "True" : "False"));
1968 * X11DRV_wglMakeContextCurrentARB
1970 * For OpenGL32 wglMakeContextCurrentARB
1972 BOOL
X11DRV_wglMakeContextCurrentARB( PHYSDEV draw_dev
, PHYSDEV read_dev
, HGLRC hglrc
)
1974 X11DRV_PDEVICE
*pDrawDev
= get_x11drv_dev( draw_dev
);
1975 X11DRV_PDEVICE
*pReadDev
= get_x11drv_dev( read_dev
);
1978 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1980 if (!has_opengl()) return 0;
1985 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1986 if (prev_ctx
) prev_ctx
->tid
= 0;
1988 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1989 NtCurrentTeb()->glContext
= NULL
;
1991 else if (!pDrawDev
->current_pf
)
1993 WARN("Trying to use an invalid drawable\n");
1994 SetLastError(ERROR_INVALID_HANDLE
);
1999 if (NULL
== pglXMakeContextCurrent
) {
2002 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
2003 Drawable d_draw
= get_glxdrawable(pDrawDev
);
2004 Drawable d_read
= get_glxdrawable(pReadDev
);
2006 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
2009 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
2010 if (prev_ctx
) prev_ctx
->tid
= 0;
2012 ctx
->has_been_current
= TRUE
;
2013 ctx
->tid
= GetCurrentThreadId();
2014 ctx
->hdc
= draw_dev
->hdc
;
2015 ctx
->read_hdc
= read_dev
->hdc
;
2016 ctx
->drawables
[0] = d_draw
;
2017 ctx
->drawables
[1] = d_read
;
2018 ctx
->refresh_drawables
= FALSE
;
2019 NtCurrentTeb()->glContext
= ctx
;
2022 SetLastError(ERROR_INVALID_HANDLE
);
2025 wine_tsx11_unlock();
2027 TRACE(" returning %s\n", (ret
? "True" : "False"));
2032 * X11DRV_wglShareLists
2034 * For OpenGL32 wglShareLists.
2036 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
2038 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
2039 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
2041 TRACE("(%p, %p)\n", org
, dest
);
2043 if (!has_opengl()) return FALSE
;
2045 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
2046 * at context creation time but in case of WGL it is done using wglShareLists.
2047 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
2048 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
2049 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
2050 * so there delaying context creation doesn't work.
2052 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
2053 * and when a program requests sharing we recreate the destination context if it hasn't been made
2054 * current or when it hasn't shared display lists before.
2057 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
2059 ERR("Could not share display lists, one of the contexts has been current already !\n");
2062 else if(dest
->sharing
)
2064 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
2069 if((GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
))
2071 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
2075 describeContext(org
);
2076 describeContext(dest
);
2078 /* Re-create the GLX context and share display lists */
2079 pglXDestroyContext(gdi_display
, dest
->ctx
);
2080 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
2081 wine_tsx11_unlock();
2082 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
2084 org
->sharing
= TRUE
;
2085 dest
->sharing
= TRUE
;
2091 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
2093 /* We are running using client-side rendering fonts... */
2095 unsigned int glyph
, size
= 0;
2096 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
2100 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
2101 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
2102 wine_tsx11_unlock();
2104 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
2105 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
2106 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
2107 unsigned int height
, width_int
;
2109 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
2110 if (needed_size
== GDI_ERROR
) {
2111 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
2114 TRACE(" - needed size : %d\n", needed_size
);
2117 if (needed_size
> size
) {
2119 HeapFree(GetProcessHeap(), 0, bitmap
);
2120 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2121 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2122 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2124 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
2126 if (TRACE_ON(wgl
)) {
2127 unsigned int height
, width
, bitmask
;
2128 unsigned char *bitmap_
= bitmap
;
2130 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
2131 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2132 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
2133 if (needed_size
!= 0) {
2134 TRACE(" - bitmap :\n");
2135 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2137 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
2142 if (*bitmap_
& bitmask
)
2147 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2153 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2154 * glyph for it to be drawn properly.
2156 if (needed_size
!= 0) {
2157 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2158 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2160 for (width
= 0; width
< width_int
; width
++) {
2161 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2162 ((int *) bitmap
)[height
* width_int
+ width
];
2168 pglNewList(listBase
++, GL_COMPILE
);
2169 if (needed_size
!= 0) {
2170 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2171 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2172 gm
.gmCellIncX
, gm
.gmCellIncY
,
2175 /* This is the case of 'empty' glyphs like the space character */
2176 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2179 wine_tsx11_unlock();
2183 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2184 wine_tsx11_unlock();
2186 HeapFree(GetProcessHeap(), 0, bitmap
);
2187 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2192 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2193 wine_tsx11_unlock();
2195 HeapFree(GetProcessHeap(), 0, bitmap
);
2196 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2201 * X11DRV_wglUseFontBitmapsA
2203 * For OpenGL32 wglUseFontBitmapsA.
2205 BOOL
X11DRV_wglUseFontBitmapsA(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
2207 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2208 Font fid
= physDev
->font
;
2210 TRACE("(%p, %d, %d, %d) using font %ld\n", dev
->hdc
, first
, count
, listBase
, fid
);
2212 if (!has_opengl()) return FALSE
;
2215 return internal_wglUseFontBitmaps(dev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2219 /* I assume that the glyphs are at the same position for X and for Windows */
2220 pglXUseXFont(fid
, first
, count
, listBase
);
2221 wine_tsx11_unlock();
2226 * X11DRV_wglUseFontBitmapsW
2228 * For OpenGL32 wglUseFontBitmapsW.
2230 BOOL
X11DRV_wglUseFontBitmapsW(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
2232 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2233 Font fid
= physDev
->font
;
2235 TRACE("(%p, %d, %d, %d) using font %ld\n", dev
->hdc
, first
, count
, listBase
, fid
);
2237 if (!has_opengl()) return FALSE
;
2240 return internal_wglUseFontBitmaps(dev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2243 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2246 /* I assume that the glyphs are at the same position for X and for Windows */
2247 pglXUseXFont(fid
, first
, count
, listBase
);
2248 wine_tsx11_unlock();
2252 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2253 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2260 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2262 pglGetIntegerv(pname
, params
);
2264 * if we cannot find a Wine Context
2265 * we only have the default wine desktop context,
2266 * so if we have only a 24 depth say we have 32
2268 if (!ctx
&& *params
== 24) {
2271 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2276 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2278 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2279 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2283 pglGetIntegerv(pname
, params
);
2286 wine_tsx11_unlock();
2289 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
2293 if (!physDev
->gl_copy
|| !physDev
->current_pf
)
2296 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
2297 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
2299 if(w
> 0 && h
> 0) {
2300 Drawable src
= physDev
->pixmap
;
2301 if(!src
) src
= physDev
->gl_drawable
;
2303 /* The GL drawable may be lagged behind if we don't flush first, so
2304 * flush the display make sure we copy up-to-date data */
2306 XFlush(gdi_display
);
2307 XSetFunction(gdi_display
, physDev
->gc
, GXcopy
);
2308 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
2309 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
2310 wine_tsx11_unlock();
2315 static void WINAPI
X11DRV_wglFinish(void)
2317 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2318 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2323 wine_tsx11_unlock();
2324 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2327 static void WINAPI
X11DRV_wglFlush(void)
2329 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2330 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2335 wine_tsx11_unlock();
2336 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2340 * X11DRV_wglCreateContextAttribsARB
2342 * WGL_ARB_create_context: wglCreateContextAttribsARB
2344 HGLRC
X11DRV_wglCreateContextAttribsARB(PHYSDEV dev
, HGLRC hShareContext
, const int* attribList
)
2346 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2347 Wine_GLContext
*ret
;
2348 WineGLPixelFormat
*fmt
;
2349 int hdcPF
= physDev
->current_pf
;
2352 TRACE("(%p %p %p)\n", physDev
, hShareContext
, attribList
);
2354 if (!has_opengl()) return 0;
2356 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
2357 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2358 * If this fails something is very wrong on the system. */
2361 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
2362 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2367 ret
= alloc_context();
2368 wine_tsx11_unlock();
2369 ret
->hdc
= dev
->hdc
;
2371 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2372 ret
->gl3_context
= TRUE
;
2374 ret
->numAttribs
= 0;
2377 int *pAttribList
= (int*)attribList
;
2378 int *pContextAttribList
= &ret
->attribList
[0];
2379 /* attribList consists of pairs {token, value] terminated with 0 */
2380 while(pAttribList
[0] != 0)
2382 TRACE("%#x %#x\n", pAttribList
[0], pAttribList
[1]);
2383 switch(pAttribList
[0])
2385 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2386 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2387 pContextAttribList
[1] = pAttribList
[1];
2389 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2390 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2391 pContextAttribList
[1] = pAttribList
[1];
2393 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2395 case WGL_CONTEXT_FLAGS_ARB
:
2396 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2397 pContextAttribList
[1] = pAttribList
[1];
2399 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2400 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2401 pContextAttribList
[1] = pAttribList
[1];
2404 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList
[0], pAttribList
[1]);
2409 pContextAttribList
+= 2;
2414 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2415 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
2417 XSync(gdi_display
, False
);
2418 if(X11DRV_check_error() || !ret
->ctx
)
2420 /* In the future we should convert the GLX error to a win32 one here if needed */
2421 ERR("Context creation failed\n");
2423 wine_tsx11_unlock();
2427 wine_tsx11_unlock();
2428 TRACE(" creating context %p\n", ret
);
2433 * X11DRV_wglGetExtensionsStringARB
2435 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2437 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2438 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2439 return WineGLInfo
.wglExtensions
;
2443 * X11DRV_wglCreatePbufferARB
2445 * WGL_ARB_pbuffer: wglCreatePbufferARB
2447 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2449 Wine_GLPBuffer
* object
= NULL
;
2450 WineGLPixelFormat
*fmt
= NULL
;
2455 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2457 if (0 >= iPixelFormat
) {
2458 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2459 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2460 return NULL
; /* unexpected error */
2463 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2464 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2466 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2467 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2468 goto create_failed
; /* unexpected error */
2471 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2472 if (NULL
== object
) {
2473 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2474 goto create_failed
; /* unexpected error */
2477 object
->display
= gdi_display
;
2478 object
->width
= iWidth
;
2479 object
->height
= iHeight
;
2482 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2483 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2484 while (piAttribList
&& 0 != *piAttribList
) {
2486 switch (*piAttribList
) {
2487 case WGL_PBUFFER_LARGEST_ARB
: {
2489 attr_v
= *piAttribList
;
2490 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2491 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2495 case WGL_TEXTURE_FORMAT_ARB
: {
2497 attr_v
= *piAttribList
;
2498 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2499 if (use_render_texture_ati
) {
2502 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2503 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2504 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2506 SetLastError(ERROR_INVALID_DATA
);
2509 object
->use_render_texture
= 1;
2510 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2512 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2513 object
->use_render_texture
= 0;
2515 if (!use_render_texture_emulation
) {
2516 SetLastError(ERROR_INVALID_DATA
);
2520 case WGL_TEXTURE_RGB_ARB
:
2521 object
->use_render_texture
= GL_RGB
;
2522 object
->texture_bpp
= 3;
2523 object
->texture_format
= GL_RGB
;
2524 object
->texture_type
= GL_UNSIGNED_BYTE
;
2526 case WGL_TEXTURE_RGBA_ARB
:
2527 object
->use_render_texture
= GL_RGBA
;
2528 object
->texture_bpp
= 4;
2529 object
->texture_format
= GL_RGBA
;
2530 object
->texture_type
= GL_UNSIGNED_BYTE
;
2533 /* WGL_FLOAT_COMPONENTS_NV */
2534 case WGL_TEXTURE_FLOAT_R_NV
:
2535 object
->use_render_texture
= GL_FLOAT_R_NV
;
2536 object
->texture_bpp
= 4;
2537 object
->texture_format
= GL_RED
;
2538 object
->texture_type
= GL_FLOAT
;
2540 case WGL_TEXTURE_FLOAT_RG_NV
:
2541 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2542 object
->texture_bpp
= 8;
2543 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2544 object
->texture_type
= GL_FLOAT
;
2546 case WGL_TEXTURE_FLOAT_RGB_NV
:
2547 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2548 object
->texture_bpp
= 12;
2549 object
->texture_format
= GL_RGB
;
2550 object
->texture_type
= GL_FLOAT
;
2552 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2553 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2554 object
->texture_bpp
= 16;
2555 object
->texture_format
= GL_RGBA
;
2556 object
->texture_type
= GL_FLOAT
;
2559 ERR("Unknown texture format: %x\n", attr_v
);
2560 SetLastError(ERROR_INVALID_DATA
);
2568 case WGL_TEXTURE_TARGET_ARB
: {
2570 attr_v
= *piAttribList
;
2571 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2572 if (use_render_texture_ati
) {
2575 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2576 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2577 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2578 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2580 SetLastError(ERROR_INVALID_DATA
);
2583 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2585 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2586 object
->texture_target
= 0;
2588 if (!use_render_texture_emulation
) {
2589 SetLastError(ERROR_INVALID_DATA
);
2593 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2594 if (iWidth
!= iHeight
) {
2595 SetLastError(ERROR_INVALID_DATA
);
2598 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2599 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2602 case WGL_TEXTURE_1D_ARB
: {
2604 SetLastError(ERROR_INVALID_DATA
);
2607 object
->texture_target
= GL_TEXTURE_1D
;
2608 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2611 case WGL_TEXTURE_2D_ARB
: {
2612 object
->texture_target
= GL_TEXTURE_2D
;
2613 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2616 case WGL_TEXTURE_RECTANGLE_NV
: {
2617 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2618 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2622 ERR("Unknown texture target: %x\n", attr_v
);
2623 SetLastError(ERROR_INVALID_DATA
);
2631 case WGL_MIPMAP_TEXTURE_ARB
: {
2633 attr_v
= *piAttribList
;
2634 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2635 if (use_render_texture_ati
) {
2636 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2638 if (!use_render_texture_emulation
) {
2639 SetLastError(ERROR_INVALID_DATA
);
2649 PUSH1(attribs
, None
);
2651 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2652 wine_tsx11_unlock();
2653 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2654 if (!object
->drawable
) {
2655 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2656 goto create_failed
; /* unexpected error */
2658 TRACE("->(%p)\n", object
);
2662 HeapFree(GetProcessHeap(), 0, object
);
2663 TRACE("->(FAILED)\n");
2668 * X11DRV_wglDestroyPbufferARB
2670 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2672 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2674 Wine_GLPBuffer
* object
= hPbuffer
;
2675 TRACE("(%p)\n", hPbuffer
);
2676 if (NULL
== object
) {
2677 SetLastError(ERROR_INVALID_HANDLE
);
2681 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2682 wine_tsx11_unlock();
2683 HeapFree(GetProcessHeap(), 0, object
);
2688 * X11DRV_wglGetPbufferDCARB
2690 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2691 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2692 * Gdi32 implements the part of this function which creates a device context.
2693 * This part associates the physDev with the X drawable of the pbuffer.
2695 HDC
X11DRV_wglGetPbufferDCARB(PHYSDEV dev
, HPBUFFERARB hPbuffer
)
2697 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
2698 Wine_GLPBuffer
* object
= hPbuffer
;
2700 if (NULL
== object
) {
2701 SetLastError(ERROR_INVALID_HANDLE
);
2705 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2706 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2707 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2708 physDev
->drawable
= object
->drawable
;
2709 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2710 physDev
->dc_rect
= physDev
->drawable_rect
;
2712 TRACE("(%p)->(%p)\n", hPbuffer
, dev
->hdc
);
2717 * X11DRV_wglQueryPbufferARB
2719 * WGL_ARB_pbuffer: wglQueryPbufferARB
2721 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2723 Wine_GLPBuffer
* object
= hPbuffer
;
2724 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2725 if (NULL
== object
) {
2726 SetLastError(ERROR_INVALID_HANDLE
);
2729 switch (iAttribute
) {
2730 case WGL_PBUFFER_WIDTH_ARB
:
2732 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2733 wine_tsx11_unlock();
2735 case WGL_PBUFFER_HEIGHT_ARB
:
2737 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2738 wine_tsx11_unlock();
2741 case WGL_PBUFFER_LOST_ARB
:
2742 /* GLX Pbuffers cannot be lost by default. We can support this by
2743 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2744 * to receive pixel buffer clobber events, however that may or may
2745 * not give any benefit */
2746 *piValue
= GL_FALSE
;
2749 case WGL_TEXTURE_FORMAT_ARB
:
2750 if (use_render_texture_ati
) {
2752 int type
= WGL_NO_TEXTURE_ARB
;
2754 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2755 wine_tsx11_unlock();
2757 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2758 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2759 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2763 if (!object
->use_render_texture
) {
2764 *piValue
= WGL_NO_TEXTURE_ARB
;
2766 if (!use_render_texture_emulation
) {
2767 SetLastError(ERROR_INVALID_HANDLE
);
2770 switch(object
->use_render_texture
) {
2772 *piValue
= WGL_TEXTURE_RGB_ARB
;
2775 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2777 /* WGL_FLOAT_COMPONENTS_NV */
2779 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2781 case GL_FLOAT_RG_NV
:
2782 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2784 case GL_FLOAT_RGB_NV
:
2785 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2787 case GL_FLOAT_RGBA_NV
:
2788 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2791 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2797 case WGL_TEXTURE_TARGET_ARB
:
2798 if (use_render_texture_ati
) {
2800 int type
= WGL_NO_TEXTURE_ARB
;
2802 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2803 wine_tsx11_unlock();
2805 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2806 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2807 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2808 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2812 if (!object
->texture_target
) {
2813 *piValue
= WGL_NO_TEXTURE_ARB
;
2815 if (!use_render_texture_emulation
) {
2816 SetLastError(ERROR_INVALID_DATA
);
2819 switch (object
->texture_target
) {
2820 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2821 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2822 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2823 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2829 case WGL_MIPMAP_TEXTURE_ARB
:
2830 if (use_render_texture_ati
) {
2832 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2833 wine_tsx11_unlock();
2835 *piValue
= GL_FALSE
; /** don't support that */
2836 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2841 FIXME("unexpected attribute %x\n", iAttribute
);
2849 * X11DRV_wglReleasePbufferDCARB
2851 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2853 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2855 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2856 return DeleteDC(hdc
);
2860 * X11DRV_wglSetPbufferAttribARB
2862 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2864 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2866 Wine_GLPBuffer
* object
= hPbuffer
;
2867 GLboolean ret
= GL_FALSE
;
2869 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2870 if (NULL
== object
) {
2871 SetLastError(ERROR_INVALID_HANDLE
);
2874 if (!object
->use_render_texture
) {
2875 SetLastError(ERROR_INVALID_HANDLE
);
2878 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2881 if (NULL
!= pglXDrawableAttribATI
) {
2882 if (use_render_texture_ati
) {
2883 FIXME("Need conversion for GLX_ATI_render_texture\n");
2886 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2887 wine_tsx11_unlock();
2893 * X11DRV_wglChoosePixelFormatARB
2895 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2897 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2902 GLXFBConfig
* cfgs
= NULL
;
2906 WineGLPixelFormat
*fmt
;
2912 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2913 if (NULL
!= pfAttribFList
) {
2914 FIXME("unused pfAttribFList\n");
2917 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2918 if (-1 == nAttribs
) {
2919 WARN("Cannot convert WGL to GLX attributes\n");
2922 PUSH1(attribs
, None
);
2924 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2925 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2926 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2927 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2929 switch(piAttribIList
[i
])
2931 case WGL_DRAW_TO_BITMAP_ARB
:
2932 if(piAttribIList
[i
+1])
2933 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2935 case WGL_ACCELERATION_ARB
:
2936 switch(piAttribIList
[i
+1])
2938 case WGL_NO_ACCELERATION_ARB
:
2939 dwFlags
|= PFD_GENERIC_FORMAT
;
2941 case WGL_GENERIC_ACCELERATION_ARB
:
2942 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2944 case WGL_FULL_ACCELERATION_ARB
:
2949 case WGL_SUPPORT_GDI_ARB
:
2950 if(piAttribIList
[i
+1])
2951 dwFlags
|= PFD_SUPPORT_GDI
;
2956 /* Search for FB configurations matching the requirements in attribs */
2958 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2960 wine_tsx11_unlock();
2961 WARN("Compatible Pixel Format not found\n");
2965 /* Loop through all matching formats and check if they are suitable.
2966 * Note that this function should at max return nMaxFormats different formats */
2967 for(run
=0; run
< 2; run
++)
2969 for (it
= 0; it
< nCfgs
; ++it
) {
2970 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2972 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2976 /* Search for the format in our list of compatible formats */
2977 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2981 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2982 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2985 if(pfmt_it
< nMaxFormats
) {
2986 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2987 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2993 *nNumFormats
= pfmt_it
;
2996 wine_tsx11_unlock();
3001 * X11DRV_wglGetPixelFormatAttribivARB
3003 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
3005 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
3008 WineGLPixelFormat
*fmt
= NULL
;
3012 int nWGLFormats
= 0;
3014 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
3016 if (0 < iLayerPlane
) {
3017 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
3021 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
3022 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
3023 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
3024 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
3026 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
3030 for (i
= 0; i
< nAttributes
; ++i
) {
3031 const int curWGLAttr
= piAttributes
[i
];
3032 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
3034 switch (curWGLAttr
) {
3035 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
3036 piValues
[i
] = nWGLFormats
;
3039 case WGL_SUPPORT_OPENGL_ARB
:
3040 piValues
[i
] = GL_TRUE
;
3043 case WGL_ACCELERATION_ARB
:
3044 curGLXAttr
= GLX_CONFIG_CAVEAT
;
3045 if (!fmt
) goto pix_error
;
3046 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
3047 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
3048 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
3049 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
3051 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
3054 case WGL_TRANSPARENT_ARB
:
3055 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
3056 if (!fmt
) goto pix_error
;
3057 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3058 if (hTest
) goto get_error
;
3059 piValues
[i
] = GL_FALSE
;
3060 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
3063 case WGL_PIXEL_TYPE_ARB
:
3064 curGLXAttr
= GLX_RENDER_TYPE
;
3065 if (!fmt
) goto pix_error
;
3066 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3067 if (hTest
) goto get_error
;
3068 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
3069 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
3070 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
3071 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
3072 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
3073 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
3075 ERR("unexpected RenderType(%x)\n", tmp
);
3076 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
3080 case WGL_COLOR_BITS_ARB
:
3081 curGLXAttr
= GLX_BUFFER_SIZE
;
3084 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
3085 if (use_render_texture_ati
) {
3086 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
3089 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
3090 if (use_render_texture_ati
) {
3091 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
3094 if (!use_render_texture_emulation
) {
3095 piValues
[i
] = GL_FALSE
;
3098 curGLXAttr
= GLX_RENDER_TYPE
;
3099 if (!fmt
) goto pix_error
;
3100 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
3101 if (hTest
) goto get_error
;
3102 if (GLX_COLOR_INDEX_BIT
== tmp
) {
3103 piValues
[i
] = GL_FALSE
;
3106 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3107 if (hTest
) goto get_error
;
3108 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
3111 case WGL_BLUE_BITS_ARB
:
3112 curGLXAttr
= GLX_BLUE_SIZE
;
3114 case WGL_RED_BITS_ARB
:
3115 curGLXAttr
= GLX_RED_SIZE
;
3117 case WGL_GREEN_BITS_ARB
:
3118 curGLXAttr
= GLX_GREEN_SIZE
;
3120 case WGL_ALPHA_BITS_ARB
:
3121 curGLXAttr
= GLX_ALPHA_SIZE
;
3123 case WGL_DEPTH_BITS_ARB
:
3124 curGLXAttr
= GLX_DEPTH_SIZE
;
3126 case WGL_STENCIL_BITS_ARB
:
3127 curGLXAttr
= GLX_STENCIL_SIZE
;
3129 case WGL_DOUBLE_BUFFER_ARB
:
3130 curGLXAttr
= GLX_DOUBLEBUFFER
;
3132 case WGL_STEREO_ARB
:
3133 curGLXAttr
= GLX_STEREO
;
3135 case WGL_AUX_BUFFERS_ARB
:
3136 curGLXAttr
= GLX_AUX_BUFFERS
;
3139 case WGL_SUPPORT_GDI_ARB
:
3140 if (!fmt
) goto pix_error
;
3141 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
3144 case WGL_DRAW_TO_BITMAP_ARB
:
3145 if (!fmt
) goto pix_error
;
3146 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
3149 case WGL_DRAW_TO_WINDOW_ARB
:
3150 case WGL_DRAW_TO_PBUFFER_ARB
:
3151 if (!fmt
) goto pix_error
;
3152 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3153 if (hTest
) goto get_error
;
3154 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
3155 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
3156 piValues
[i
] = GL_TRUE
;
3158 piValues
[i
] = GL_FALSE
;
3161 case WGL_SWAP_METHOD_ARB
:
3162 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3163 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3164 * point only ATI offers this.
3166 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
3169 case WGL_PBUFFER_LARGEST_ARB
:
3170 curGLXAttr
= GLX_LARGEST_PBUFFER
;
3173 case WGL_SAMPLE_BUFFERS_ARB
:
3174 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
3177 case WGL_SAMPLES_ARB
:
3178 curGLXAttr
= GLX_SAMPLES_ARB
;
3181 case WGL_FLOAT_COMPONENTS_NV
:
3182 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
3185 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
3186 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
3189 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
3190 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
3193 case WGL_ACCUM_RED_BITS_ARB
:
3194 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
3196 case WGL_ACCUM_GREEN_BITS_ARB
:
3197 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
3199 case WGL_ACCUM_BLUE_BITS_ARB
:
3200 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
3202 case WGL_ACCUM_ALPHA_BITS_ARB
:
3203 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
3205 case WGL_ACCUM_BITS_ARB
:
3206 if (!fmt
) goto pix_error
;
3207 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
3208 if (hTest
) goto get_error
;
3210 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
3211 if (hTest
) goto get_error
;
3213 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
3214 if (hTest
) goto get_error
;
3216 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
3217 if (hTest
) goto get_error
;
3222 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
3225 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3226 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3227 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3229 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3230 * and check which options can work using iPixelFormat=0 and which not.
3231 * A problem would be that this function is an extension. This would
3232 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3234 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
3235 if (!fmt
) goto pix_error
;
3236 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
3237 if (hTest
) goto get_error
;
3240 piValues
[i
] = GL_FALSE
;
3243 wine_tsx11_unlock();
3247 wine_tsx11_unlock();
3248 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3252 wine_tsx11_unlock();
3253 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3258 * X11DRV_wglGetPixelFormatAttribfvARB
3260 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3262 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3268 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3270 /* Allocate a temporary array to store integer values */
3271 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3273 ERR("couldn't allocate %d array\n", nAttributes
);
3277 /* Piggy-back on wglGetPixelFormatAttribivARB */
3278 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3280 /* Convert integer values to float. Should also check for attributes
3281 that can give decimal values here */
3282 for (i
=0; i
<nAttributes
;i
++) {
3283 pfValues
[i
] = attr
[i
];
3287 HeapFree(GetProcessHeap(), 0, attr
);
3292 * X11DRV_wglBindTexImageARB
3294 * WGL_ARB_render_texture: wglBindTexImageARB
3296 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3298 Wine_GLPBuffer
* object
= hPbuffer
;
3299 GLboolean ret
= GL_FALSE
;
3301 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3302 if (NULL
== object
) {
3303 SetLastError(ERROR_INVALID_HANDLE
);
3306 if (!object
->use_render_texture
) {
3307 SetLastError(ERROR_INVALID_HANDLE
);
3311 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3312 static int init
= 0;
3313 int prev_binded_texture
= 0;
3314 GLXContext prev_context
;
3315 Drawable prev_drawable
;
3316 GLXContext tmp_context
;
3319 prev_context
= pglXGetCurrentContext();
3320 prev_drawable
= pglXGetCurrentDrawable();
3322 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3323 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3324 isn't ideal performance wise but I wasn't able to get other ways working.
3327 init
= 1; /* Only show the FIXME once for performance reasons */
3328 FIXME("partial stub!\n");
3331 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
3332 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3334 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3336 /* Switch to our pbuffer */
3337 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3339 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3340 * After that upload the pbuffer texture data. */
3341 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3342 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3344 /* Switch back to the original drawable and upload the pbuffer-texture */
3345 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3346 pglXDestroyContext(gdi_display
, tmp_context
);
3347 wine_tsx11_unlock();
3351 if (NULL
!= pglXBindTexImageATI
) {
3356 case WGL_FRONT_LEFT_ARB
:
3357 buffer
= GLX_FRONT_LEFT_ATI
;
3359 case WGL_FRONT_RIGHT_ARB
:
3360 buffer
= GLX_FRONT_RIGHT_ATI
;
3362 case WGL_BACK_LEFT_ARB
:
3363 buffer
= GLX_BACK_LEFT_ATI
;
3365 case WGL_BACK_RIGHT_ARB
:
3366 buffer
= GLX_BACK_RIGHT_ATI
;
3369 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3373 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3374 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3375 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3376 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3377 * works fine using our pbuffer emulation path.
3380 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3381 wine_tsx11_unlock();
3387 * X11DRV_wglReleaseTexImageARB
3389 * WGL_ARB_render_texture: wglReleaseTexImageARB
3391 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3393 Wine_GLPBuffer
* object
= hPbuffer
;
3394 GLboolean ret
= GL_FALSE
;
3396 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3397 if (NULL
== object
) {
3398 SetLastError(ERROR_INVALID_HANDLE
);
3401 if (!object
->use_render_texture
) {
3402 SetLastError(ERROR_INVALID_HANDLE
);
3405 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3408 if (NULL
!= pglXReleaseTexImageATI
) {
3413 case WGL_FRONT_LEFT_ARB
:
3414 buffer
= GLX_FRONT_LEFT_ATI
;
3416 case WGL_FRONT_RIGHT_ARB
:
3417 buffer
= GLX_FRONT_RIGHT_ATI
;
3419 case WGL_BACK_LEFT_ARB
:
3420 buffer
= GLX_BACK_LEFT_ATI
;
3422 case WGL_BACK_RIGHT_ARB
:
3423 buffer
= GLX_BACK_RIGHT_ATI
;
3426 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3430 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3431 wine_tsx11_unlock();
3437 * X11DRV_wglGetExtensionsStringEXT
3439 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3441 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3442 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3443 return WineGLInfo
.wglExtensions
;
3447 * X11DRV_wglGetSwapIntervalEXT
3449 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3451 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3452 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
3453 * interval, so the swap interval has to be tracked. */
3455 return swap_interval
;
3459 * X11DRV_wglSwapIntervalEXT
3461 * WGL_EXT_swap_control: wglSwapIntervalEXT
3463 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3466 TRACE("(%d)\n", interval
);
3470 SetLastError(ERROR_INVALID_DATA
);
3473 else if (!has_swap_control
&& interval
== 0)
3475 /* wglSwapIntervalEXT considers an interval value of zero to mean that
3476 * vsync should be disabled, but glXSwapIntervalSGI considers such a
3477 * value to be an error. Just silently ignore the request for now. */
3478 WARN("Request to disable vertical sync is not handled\n");
3483 if (pglXSwapIntervalSGI
)
3486 ret
= !pglXSwapIntervalSGI(interval
);
3487 wine_tsx11_unlock();
3490 WARN("GLX_SGI_swap_control extension is not available\n");
3493 swap_interval
= interval
;
3495 SetLastError(ERROR_DC_NOT_FOUND
);
3502 * X11DRV_wglAllocateMemoryNV
3504 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3506 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3508 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3510 if (pglXAllocateMemoryNV
)
3513 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3514 wine_tsx11_unlock();
3520 * X11DRV_wglFreeMemoryNV
3522 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3524 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3525 TRACE("(%p)\n", pointer
);
3526 if (pglXFreeMemoryNV
== NULL
)
3530 pglXFreeMemoryNV(pointer
);
3531 wine_tsx11_unlock();
3535 * X11DRV_wglSetPixelFormatWINE
3537 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3538 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3540 BOOL
X11DRV_wglSetPixelFormatWINE(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3542 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3544 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
3546 if (!has_opengl()) return FALSE
;
3548 if (physDev
->current_pf
== iPixelFormat
) return TRUE
;
3550 /* Relay to the core SetPixelFormat */
3551 TRACE("Changing iPixelFormat from %d to %d\n", physDev
->current_pf
, iPixelFormat
);
3552 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
3556 * glxRequireVersion (internal)
3558 * Check if the supported GLX version matches requiredVersion.
3560 static BOOL
glxRequireVersion(int requiredVersion
)
3562 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3563 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3569 static BOOL
glxRequireExtension(const char *requiredExtension
)
3571 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3578 static void register_extension_string(const char *ext
)
3580 if (WineGLInfo
.wglExtensions
[0])
3581 strcat(WineGLInfo
.wglExtensions
, " ");
3582 strcat(WineGLInfo
.wglExtensions
, ext
);
3584 TRACE("'%s'\n", ext
);
3587 static BOOL
register_extension(const WineGLExtension
* ext
)
3591 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3592 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3594 register_extension_string(ext
->extName
);
3596 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3597 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3602 static const WineGLExtension WGL_internal_functions
=
3606 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3607 { "wglFinish", X11DRV_wglFinish
},
3608 { "wglFlush", X11DRV_wglFlush
},
3613 static const WineGLExtension WGL_ARB_create_context
=
3615 "WGL_ARB_create_context",
3617 { "wglCreateContextAttribsARB", X11DRV_wglCreateContextAttribsARB
},
3621 static const WineGLExtension WGL_ARB_extensions_string
=
3623 "WGL_ARB_extensions_string",
3625 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3629 static const WineGLExtension WGL_ARB_make_current_read
=
3631 "WGL_ARB_make_current_read",
3633 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3634 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3638 static const WineGLExtension WGL_ARB_multisample
=
3640 "WGL_ARB_multisample",
3643 static const WineGLExtension WGL_ARB_pbuffer
=
3647 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3648 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3649 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3650 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3651 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3652 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3656 static const WineGLExtension WGL_ARB_pixel_format
=
3658 "WGL_ARB_pixel_format",
3660 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3661 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3662 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3666 static const WineGLExtension WGL_ARB_render_texture
=
3668 "WGL_ARB_render_texture",
3670 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3671 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3675 static const WineGLExtension WGL_EXT_extensions_string
=
3677 "WGL_EXT_extensions_string",
3679 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3683 static const WineGLExtension WGL_EXT_swap_control
=
3685 "WGL_EXT_swap_control",
3687 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3688 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3692 static const WineGLExtension WGL_NV_vertex_array_range
=
3694 "WGL_NV_vertex_array_range",
3696 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3697 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3701 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3703 "WGL_WINE_pixel_format_passthrough",
3705 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE
},
3710 * X11DRV_WineGL_LoadExtensions
3712 static void X11DRV_WineGL_LoadExtensions(void)
3714 WineGLInfo
.wglExtensions
[0] = 0;
3716 /* Load Wine internal functions */
3717 register_extension(&WGL_internal_functions
);
3719 /* ARB Extensions */
3721 if(glxRequireExtension("GLX_ARB_create_context"))
3723 register_extension(&WGL_ARB_create_context
);
3725 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3726 register_extension_string("WGL_ARB_create_context_profile");
3729 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3731 register_extension_string("WGL_ARB_pixel_format_float");
3732 register_extension_string("WGL_ATI_pixel_format_float");
3735 register_extension(&WGL_ARB_extensions_string
);
3737 if (glxRequireVersion(3))
3738 register_extension(&WGL_ARB_make_current_read
);
3740 if (glxRequireExtension("GLX_ARB_multisample"))
3741 register_extension(&WGL_ARB_multisample
);
3743 /* In general pbuffer functionality requires support in the X-server. The functionality is
3744 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3745 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3746 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3748 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3749 * without support in the X-server (which other Mesa based drivers require).
3751 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3752 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3753 * is available pbuffers must be available too. */
3754 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3755 register_extension(&WGL_ARB_pbuffer
);
3757 register_extension(&WGL_ARB_pixel_format
);
3759 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3760 if (glxRequireExtension("GLX_ATI_render_texture") ||
3761 glxRequireExtension("GLX_ARB_render_texture") ||
3762 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3764 register_extension(&WGL_ARB_render_texture
);
3766 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3767 if(glxRequireExtension("GLX_NV_float_buffer"))
3768 register_extension_string("WGL_NV_float_buffer");
3770 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3771 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3772 register_extension_string("WGL_NV_texture_rectangle");
3775 /* EXT Extensions */
3777 register_extension(&WGL_EXT_extensions_string
);
3779 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3780 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3781 register_extension(&WGL_EXT_swap_control
);
3783 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3784 register_extension_string("WGL_EXT_framebuffer_sRGB");
3786 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3787 register_extension_string("WGL_EXT_pixel_format_packed_float");
3789 if (glxRequireExtension("GLX_EXT_swap_control"))
3790 has_swap_control
= TRUE
;
3792 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3793 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3794 register_extension(&WGL_NV_vertex_array_range
);
3796 /* WINE-specific WGL Extensions */
3798 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3799 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3801 register_extension(&WGL_WINE_pixel_format_passthrough
);
3805 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3811 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3812 ret
= physDev
->drawable
; /* PBuffer */
3814 ret
= physDev
->bitmap
->glxpixmap
;
3816 else if(physDev
->gl_drawable
)
3817 ret
= physDev
->gl_drawable
;
3819 ret
= physDev
->drawable
;
3823 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3826 pglXDestroyGLXPixmap(display
, glxpixmap
);
3827 wine_tsx11_unlock();
3832 * X11DRV_SwapBuffers
3834 * Swap the buffers of this DC
3836 BOOL
X11DRV_SwapBuffers(PHYSDEV dev
)
3838 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3839 GLXDrawable drawable
;
3840 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3842 if (!has_opengl()) return FALSE
;
3844 TRACE("(%p)\n", physDev
);
3848 WARN("Using a NULL context, skipping\n");
3849 SetLastError(ERROR_INVALID_HANDLE
);
3853 if (!physDev
->current_pf
)
3855 WARN("Using an invalid drawable, skipping\n");
3856 SetLastError(ERROR_INVALID_HANDLE
);
3860 drawable
= get_glxdrawable(physDev
);
3864 if(physDev
->pixmap
) {
3865 if(pglXCopySubBufferMESA
) {
3866 int w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
3867 int h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
3869 /* (glX)SwapBuffers has an implicit glFlush effect, however
3870 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3874 pglXCopySubBufferMESA(gdi_display
, drawable
, 0, 0, w
, h
);
3877 pglXSwapBuffers(gdi_display
, drawable
);
3880 pglXSwapBuffers(gdi_display
, drawable
);
3882 flush_gl_drawable(physDev
);
3883 wine_tsx11_unlock();
3888 static long prev_time
, start_time
;
3889 static unsigned long frames
, frames_total
;
3891 DWORD time
= GetTickCount();
3894 /* every 1.5 seconds */
3895 if (time
- prev_time
> 1500) {
3896 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3897 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3900 if(start_time
== 0) start_time
= time
;
3907 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3909 WineGLPixelFormat
*fmt
;
3912 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3917 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3918 wine_tsx11_unlock();
3922 #else /* no OpenGL includes */
3924 void X11DRV_OpenGL_Cleanup(void)
3928 static inline void opengl_error(void)
3931 if (!warned
++) ERR("No OpenGL support compiled in.\n");
3934 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3939 void mark_drawable_dirty(Drawable old
, Drawable
new)
3943 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
3947 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3952 /***********************************************************************
3953 * ChoosePixelFormat (X11DRV.@)
3955 int X11DRV_ChoosePixelFormat(PHYSDEV dev
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3961 /***********************************************************************
3962 * DescribePixelFormat (X11DRV.@)
3964 int X11DRV_DescribePixelFormat(PHYSDEV dev
, int iPixelFormat
, UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
3970 /***********************************************************************
3971 * GetPixelFormat (X11DRV.@)
3973 int X11DRV_GetPixelFormat(PHYSDEV dev
)
3979 /***********************************************************************
3980 * SetPixelFormat (X11DRV.@)
3982 BOOL
X11DRV_SetPixelFormat(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3988 /***********************************************************************
3989 * SwapBuffers (X11DRV.@)
3991 BOOL
X11DRV_SwapBuffers(PHYSDEV dev
)
3998 * X11DRV_wglCopyContext
4000 * For OpenGL32 wglCopyContext.
4002 BOOL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
4009 * X11DRV_wglCreateContext
4011 * For OpenGL32 wglCreateContext.
4013 HGLRC
X11DRV_wglCreateContext(PHYSDEV dev
)
4020 * X11DRV_wglCreateContextAttribsARB
4022 * WGL_ARB_create_context: wglCreateContextAttribsARB
4024 HGLRC
X11DRV_wglCreateContextAttribsARB(PHYSDEV dev
, HGLRC hShareContext
, const int* attribList
)
4031 * X11DRV_wglDeleteContext
4033 * For OpenGL32 wglDeleteContext.
4035 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
4042 * X11DRV_wglGetProcAddress
4044 * For OpenGL32 wglGetProcAddress.
4046 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
4052 HDC
X11DRV_wglGetPbufferDCARB(PHYSDEV dev
, void *hPbuffer
)
4058 BOOL
X11DRV_wglMakeContextCurrentARB(PHYSDEV draw_dev
, PHYSDEV read_dev
, HGLRC hglrc
)
4065 * X11DRV_wglMakeCurrent
4067 * For OpenGL32 wglMakeCurrent.
4069 BOOL
X11DRV_wglMakeCurrent(PHYSDEV dev
, HGLRC hglrc
)
4076 * X11DRV_wglShareLists
4078 * For OpenGL32 wglShareLists.
4080 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
4087 * X11DRV_wglUseFontBitmapsA
4089 * For OpenGL32 wglUseFontBitmapsA.
4091 BOOL
X11DRV_wglUseFontBitmapsA(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
4098 * X11DRV_wglUseFontBitmapsW
4100 * For OpenGL32 wglUseFontBitmapsW.
4102 BOOL
X11DRV_wglUseFontBitmapsW(PHYSDEV dev
, DWORD first
, DWORD count
, DWORD listBase
)
4109 * X11DRV_wglSetPixelFormatWINE
4111 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
4112 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
4114 BOOL
X11DRV_wglSetPixelFormatWINE(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
4120 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
4125 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
4130 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
4135 #endif /* defined(SONAME_LIBGL) */