2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
41 #include "wine/library.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
48 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
67 /* Redefines the constants */
68 #define CALLBACK __stdcall
69 #define WINAPI __stdcall
70 #define APIENTRY WINAPI
73 WINE_DECLARE_DEBUG_CHANNEL(fps
);
75 typedef struct wine_glextension
{
84 const char *glVersion
;
89 const char *glxServerVersion
;
90 const char *glxServerVendor
;
91 const char *glxServerExtensions
;
93 const char *glxClientVersion
;
94 const char *glxClientVendor
;
95 const char *glxClientExtensions
;
97 const char *glxExtensions
;
100 char wglExtensions
[4096];
103 typedef struct wine_glpixelformat
{
105 GLXFBConfig fbconfig
;
109 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
112 typedef struct wine_glcontext
{
114 BOOL has_been_current
;
119 WineGLPixelFormat
*fmt
;
120 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
121 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
124 Drawable drawables
[2];
125 BOOL refresh_drawables
;
126 Pixmap pixmap
; /* pixmap for memory DCs */
127 GLXPixmap glxpixmap
; /* GLX pixmap for memory DCs */
128 SIZE pixmap_size
; /* pixmap size for memory DCs */
132 typedef struct wine_glpbuffer
{
135 WineGLPixelFormat
* fmt
;
141 int use_render_texture
; /* This is also the internal texture format */
142 int texture_bind_target
;
144 GLint texture_format
;
145 GLuint texture_target
;
153 struct gdi_physdev dev
;
154 X11DRV_PDEVICE
*x11dev
;
155 enum dc_gl_type type
; /* type of GL device context */
158 Pixmap pixmap
; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
161 static const struct gdi_dc_funcs glxdrv_funcs
;
163 static inline struct glx_physdev
*get_glxdrv_dev( PHYSDEV dev
)
165 return (struct glx_physdev
*)dev
;
168 static struct list context_list
= LIST_INIT( context_list
);
169 static struct WineGLInfo WineGLInfo
= { 0 };
170 static int use_render_texture_emulation
= 1;
171 static BOOL has_swap_control
;
172 static int swap_interval
= 1;
174 #define MAX_EXTENSIONS 16
175 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
176 static int WineGLExtensionListSize
;
178 static void X11DRV_WineGL_LoadExtensions(void);
179 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
180 static BOOL
glxRequireVersion(int requiredVersion
);
181 static BOOL
glxRequireExtension(const char *requiredExtension
);
183 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
184 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
185 TRACE(" - dwFlags : ");
186 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
187 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
188 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
189 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
190 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
191 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
192 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
193 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
194 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
195 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
196 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
197 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
198 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
199 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
200 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
201 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
202 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
203 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
204 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
205 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
209 TRACE(" - iPixelType : ");
210 switch (ppfd
->iPixelType
) {
211 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
212 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
216 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
217 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
218 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
219 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
220 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
221 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
222 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
223 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
224 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
226 TRACE(" - iLayerType : ");
227 switch (ppfd
->iLayerType
) {
228 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
229 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
230 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
235 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
236 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
238 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
240 MAKE_FUNCPTR(glXChooseVisual
)
241 MAKE_FUNCPTR(glXCopyContext
)
242 MAKE_FUNCPTR(glXCreateContext
)
243 MAKE_FUNCPTR(glXCreateGLXPixmap
)
244 MAKE_FUNCPTR(glXGetCurrentContext
)
245 MAKE_FUNCPTR(glXGetCurrentDrawable
)
246 MAKE_FUNCPTR(glXDestroyContext
)
247 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
248 MAKE_FUNCPTR(glXGetConfig
)
249 MAKE_FUNCPTR(glXIsDirect
)
250 MAKE_FUNCPTR(glXMakeCurrent
)
251 MAKE_FUNCPTR(glXSwapBuffers
)
252 MAKE_FUNCPTR(glXQueryExtension
)
253 MAKE_FUNCPTR(glXQueryVersion
)
256 MAKE_FUNCPTR(glXGetClientString
)
257 MAKE_FUNCPTR(glXQueryExtensionsString
)
258 MAKE_FUNCPTR(glXQueryServerString
)
261 MAKE_FUNCPTR(glXGetFBConfigs
)
262 MAKE_FUNCPTR(glXChooseFBConfig
)
263 MAKE_FUNCPTR(glXCreatePbuffer
)
264 MAKE_FUNCPTR(glXCreateNewContext
)
265 MAKE_FUNCPTR(glXDestroyPbuffer
)
266 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
267 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
268 MAKE_FUNCPTR(glXMakeContextCurrent
)
269 MAKE_FUNCPTR(glXQueryDrawable
)
270 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
273 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
274 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
275 static int (*pglXSwapIntervalSGI
)(int);
277 /* NV GLX Extension */
278 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
279 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
281 /* MESA GLX Extensions */
282 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
284 /* Standard OpenGL */
285 MAKE_FUNCPTR(glBindTexture
)
286 MAKE_FUNCPTR(glBitmap
)
287 MAKE_FUNCPTR(glCopyTexSubImage1D
)
288 MAKE_FUNCPTR(glCopyTexImage2D
)
289 MAKE_FUNCPTR(glCopyTexSubImage2D
)
290 MAKE_FUNCPTR(glDrawBuffer
)
291 MAKE_FUNCPTR(glEndList
)
292 MAKE_FUNCPTR(glGetError
)
293 MAKE_FUNCPTR(glGetIntegerv
)
294 MAKE_FUNCPTR(glGetString
)
295 MAKE_FUNCPTR(glNewList
)
296 MAKE_FUNCPTR(glPixelStorei
)
297 MAKE_FUNCPTR(glReadPixels
)
298 MAKE_FUNCPTR(glTexImage2D
)
299 MAKE_FUNCPTR(glFinish
)
300 MAKE_FUNCPTR(glFlush
)
303 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
305 /* In the future we might want to find the exact X or GLX error to report back to the app */
309 static BOOL infoInitialized
= FALSE
;
310 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
312 int screen
= DefaultScreen(gdi_display
);
313 Window win
= 0, root
= 0;
314 const char *gl_renderer
;
317 GLXContext ctx
= NULL
;
318 XSetWindowAttributes attr
;
320 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
324 infoInitialized
= TRUE
;
326 attr
.override_redirect
= True
;
327 attr
.colormap
= None
;
328 attr
.border_pixel
= 0;
332 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
335 WORD old_fs
= wine_get_fs();
336 /* Create a GLX Context. Without one we can't query GL information */
337 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
338 if (wine_get_fs() != old_fs
)
340 wine_set_fs( old_fs
);
341 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
342 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
346 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
351 root
= RootWindow( gdi_display
, vis
->screen
);
352 if (vis
->visual
!= DefaultVisual( gdi_display
, vis
->screen
))
353 attr
.colormap
= XCreateColormap( gdi_display
, root
, vis
->visual
, AllocNone
);
354 if ((win
= XCreateWindow( gdi_display
, root
, -1, -1, 1, 1, 0, vis
->depth
, InputOutput
,
355 vis
->visual
, CWBorderPixel
| CWOverrideRedirect
| CWColormap
, &attr
)))
356 XMapWindow( gdi_display
, win
);
360 if(pglXMakeCurrent(gdi_display
, win
, ctx
) == 0)
362 ERR_(winediag
)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
365 gl_renderer
= (const char *)pglGetString(GL_RENDERER
);
366 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
367 str
= (const char *) pglGetString(GL_EXTENSIONS
);
368 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
369 strcpy(WineGLInfo
.glExtensions
, str
);
371 /* Get the common GLX version supported by GLX client and server ( major/minor) */
372 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
374 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
375 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
376 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
378 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
379 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
380 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
382 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
383 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
385 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
386 TRACE("GL renderer : %s.\n", gl_renderer
);
387 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
388 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
389 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
390 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
391 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
392 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
394 if(!WineGLInfo
.glxDirect
)
396 int fd
= ConnectionNumber(gdi_display
);
397 struct sockaddr_un uaddr
;
398 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
400 /* In general indirect rendering on a local X11 server indicates a driver problem.
401 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
403 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
404 ERR_(winediag
)("Direct rendering is disabled, most likely your OpenGL drivers "
405 "haven't been installed correctly (using GL renderer %s, version %s).\n",
406 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
410 /* In general you would expect that if direct rendering is returned, that you receive hardware
411 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
412 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
413 * software rendering, it shows direct rendering.
415 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
416 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
417 * it shows 'Mesa X11'.
419 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
420 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
421 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
422 debugstr_a(gl_renderer
), debugstr_a(WineGLInfo
.glVersion
));
429 pglXMakeCurrent(gdi_display
, None
, NULL
);
430 pglXDestroyContext(gdi_display
, ctx
);
432 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
433 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
435 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
439 static BOOL
has_opengl(void)
441 static int init_done
;
442 static void *opengl_handle
;
445 int error_base
, event_base
;
447 if (init_done
) return (opengl_handle
!= NULL
);
450 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
451 and include all dependencies */
452 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
453 if (opengl_handle
== NULL
)
455 ERR( "Failed to load libGL: %s\n", buffer
);
456 ERR( "OpenGL support is disabled.\n");
460 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
461 if (pglXGetProcAddressARB
== NULL
) {
462 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
466 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
468 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
473 LOAD_FUNCPTR(glXChooseVisual
);
474 LOAD_FUNCPTR(glXCopyContext
);
475 LOAD_FUNCPTR(glXCreateContext
);
476 LOAD_FUNCPTR(glXCreateGLXPixmap
);
477 LOAD_FUNCPTR(glXGetCurrentContext
);
478 LOAD_FUNCPTR(glXGetCurrentDrawable
);
479 LOAD_FUNCPTR(glXDestroyContext
);
480 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
481 LOAD_FUNCPTR(glXGetConfig
);
482 LOAD_FUNCPTR(glXIsDirect
);
483 LOAD_FUNCPTR(glXMakeCurrent
);
484 LOAD_FUNCPTR(glXSwapBuffers
);
485 LOAD_FUNCPTR(glXQueryExtension
);
486 LOAD_FUNCPTR(glXQueryVersion
);
489 LOAD_FUNCPTR(glXGetClientString
);
490 LOAD_FUNCPTR(glXQueryExtensionsString
);
491 LOAD_FUNCPTR(glXQueryServerString
);
494 LOAD_FUNCPTR(glXCreatePbuffer
);
495 LOAD_FUNCPTR(glXCreateNewContext
);
496 LOAD_FUNCPTR(glXDestroyPbuffer
);
497 LOAD_FUNCPTR(glXMakeContextCurrent
);
498 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
499 LOAD_FUNCPTR(glXGetFBConfigs
);
501 /* Standard OpenGL calls */
502 LOAD_FUNCPTR(glBindTexture
);
503 LOAD_FUNCPTR(glBitmap
);
504 LOAD_FUNCPTR(glCopyTexSubImage1D
);
505 LOAD_FUNCPTR(glCopyTexImage2D
);
506 LOAD_FUNCPTR(glCopyTexSubImage2D
);
507 LOAD_FUNCPTR(glDrawBuffer
);
508 LOAD_FUNCPTR(glEndList
);
509 LOAD_FUNCPTR(glGetError
);
510 LOAD_FUNCPTR(glGetIntegerv
);
511 LOAD_FUNCPTR(glGetString
);
512 LOAD_FUNCPTR(glNewList
);
513 LOAD_FUNCPTR(glPixelStorei
);
514 LOAD_FUNCPTR(glReadPixels
);
515 LOAD_FUNCPTR(glTexImage2D
);
516 LOAD_FUNCPTR(glFinish
);
517 LOAD_FUNCPTR(glFlush
);
520 /* It doesn't matter if these fail. They'll only be used if the driver reports
521 the associated extension is available (and if a driver reports the extension
522 is available but fails to provide the functions, it's quite broken) */
523 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
524 /* ARB GLX Extension */
525 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
526 /* SGI GLX Extension */
527 LOAD_FUNCPTR(glXSwapIntervalSGI
);
528 /* NV GLX Extension */
529 LOAD_FUNCPTR(glXAllocateMemoryNV
);
530 LOAD_FUNCPTR(glXFreeMemoryNV
);
533 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
536 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
537 TRACE("GLX is up and running error_base = %d\n", error_base
);
540 ERR( "GLX extension is missing, disabling OpenGL.\n" );
544 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
545 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
548 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
549 * depends on the reported GLX client / server version and on the client / server extension list.
550 * Those don't have to be the same.
552 * In general the server GLX information lists the capabilities in case of indirect rendering.
553 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
554 * available and in that case the client GLX informat can be used.
555 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
556 * in the GLX version/extension list. When a program does this it works for certain for both
557 * direct and indirect rendering.
559 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
560 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
561 * extension list which causes this extension not to be listed. (Wine requires this extension).
562 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
563 * pbuffers is around.
565 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
566 * the ATI drivers and from then on use GLX client information for them.
569 if(glxRequireVersion(3)) {
570 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
571 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
572 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
573 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
574 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
575 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
576 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
577 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
579 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
580 * enable this function when the Xserver understand GLX 1.3 or newer
582 pglXQueryDrawable
= NULL
;
583 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
584 TRACE("Overriding ATI GLX capabilities!\n");
585 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
586 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
587 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
588 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
590 /* Use client GLX information in case of the ATI drivers. We override the
591 * capabilities over here and not somewhere else as ATI might better their
592 * life in the future. In case they release proper drivers this block of
593 * code won't be called. */
594 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
596 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
599 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
600 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
603 X11DRV_WineGL_LoadExtensions();
609 wine_dlclose(opengl_handle
, NULL
, 0);
610 opengl_handle
= NULL
;
614 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
617 LIST_FOR_EACH_ENTRY( ptr
, &context_list
, struct wine_glcontext
, entry
)
618 if (ptr
== ctx
) return TRUE
;
622 static int describeContext(Wine_GLContext
* ctx
) {
625 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
626 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
627 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
628 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
629 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
634 static BOOL
describeDrawable( struct glx_physdev
*physdev
)
637 WineGLPixelFormat
*fmt
;
640 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physdev
->pixel_format
, TRUE
/* Offscreen */, &fmt_count
);
641 if(!fmt
) return FALSE
;
643 TRACE(" HDC %p has:\n", physdev
->dev
.hdc
);
644 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
645 TRACE(" - Drawable %lx\n", physdev
->drawable
);
646 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
648 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
649 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
654 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
659 int nvfloatattrib
= GLX_DONT_CARE
;
660 int pixelattrib
= GLX_DONT_CARE
;
662 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
663 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
664 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
665 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
667 switch (iWGLAttr
[cur
]) {
668 case WGL_AUX_BUFFERS_ARB
:
669 pop
= iWGLAttr
[++cur
];
670 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
671 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
673 case WGL_COLOR_BITS_ARB
:
674 pop
= iWGLAttr
[++cur
];
675 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
676 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
678 case WGL_BLUE_BITS_ARB
:
679 pop
= iWGLAttr
[++cur
];
680 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
681 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
683 case WGL_RED_BITS_ARB
:
684 pop
= iWGLAttr
[++cur
];
685 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
686 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
688 case WGL_GREEN_BITS_ARB
:
689 pop
= iWGLAttr
[++cur
];
690 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
691 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
693 case WGL_ALPHA_BITS_ARB
:
694 pop
= iWGLAttr
[++cur
];
695 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
696 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
698 case WGL_DEPTH_BITS_ARB
:
699 pop
= iWGLAttr
[++cur
];
700 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
701 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
703 case WGL_STENCIL_BITS_ARB
:
704 pop
= iWGLAttr
[++cur
];
705 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
706 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
708 case WGL_DOUBLE_BUFFER_ARB
:
709 pop
= iWGLAttr
[++cur
];
710 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
711 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
714 pop
= iWGLAttr
[++cur
];
715 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
716 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
719 case WGL_PIXEL_TYPE_ARB
:
720 pop
= iWGLAttr
[++cur
];
721 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
723 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
724 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
725 /* 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 */
726 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
727 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
729 ERR("unexpected PixelType(%x)\n", pop
);
734 case WGL_SUPPORT_GDI_ARB
:
735 /* This flag is set in a WineGLPixelFormat */
736 pop
= iWGLAttr
[++cur
];
737 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
740 case WGL_DRAW_TO_BITMAP_ARB
:
741 /* This flag is set in a WineGLPixelFormat */
742 pop
= iWGLAttr
[++cur
];
743 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
746 case WGL_DRAW_TO_WINDOW_ARB
:
747 pop
= iWGLAttr
[++cur
];
748 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
749 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
751 drawattrib
|= GLX_WINDOW_BIT
;
755 case WGL_DRAW_TO_PBUFFER_ARB
:
756 pop
= iWGLAttr
[++cur
];
757 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
758 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
760 drawattrib
|= GLX_PBUFFER_BIT
;
764 case WGL_ACCELERATION_ARB
:
765 /* This flag is set in a WineGLPixelFormat */
766 pop
= iWGLAttr
[++cur
];
767 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
770 case WGL_SUPPORT_OPENGL_ARB
:
771 pop
= iWGLAttr
[++cur
];
772 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
773 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
776 case WGL_SWAP_METHOD_ARB
:
777 pop
= iWGLAttr
[++cur
];
778 /* For now we ignore this and just return SWAP_EXCHANGE */
779 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
782 case WGL_PBUFFER_LARGEST_ARB
:
783 pop
= iWGLAttr
[++cur
];
784 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
785 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
788 case WGL_SAMPLE_BUFFERS_ARB
:
789 pop
= iWGLAttr
[++cur
];
790 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
791 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
794 case WGL_SAMPLES_ARB
:
795 pop
= iWGLAttr
[++cur
];
796 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
797 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
800 case WGL_TEXTURE_FORMAT_ARB
:
801 case WGL_TEXTURE_TARGET_ARB
:
802 case WGL_MIPMAP_TEXTURE_ARB
:
803 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
804 pop
= iWGLAttr
[++cur
];
806 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
808 if (!use_render_texture_emulation
) {
809 if (WGL_NO_TEXTURE_ARB
!= pop
) {
810 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
811 return -1; /** error: don't support it */
813 drawattrib
|= GLX_PBUFFER_BIT
;
817 case WGL_FLOAT_COMPONENTS_NV
:
818 nvfloatattrib
= iWGLAttr
[++cur
];
819 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
821 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
822 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
823 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
824 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
825 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
826 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
827 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
828 pop
= iWGLAttr
[++cur
];
829 /** cannot be converted, see direct handling on
830 * - wglGetPixelFormatAttribivARB
831 * TODO: wglChoosePixelFormat
834 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
835 pop
= iWGLAttr
[++cur
];
836 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
837 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
840 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
841 pop
= iWGLAttr
[++cur
];
842 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
843 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
846 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
852 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
853 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
854 * pixmap and pbuffer formats appear as well. */
855 if (!drawattrib
) drawattrib
= GLX_DONT_CARE
;
856 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
857 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
859 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
860 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
861 * GLX_DONT_CARE unless it is overridden. */
862 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
863 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
865 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
866 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
867 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
868 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
874 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
876 int render_type
=0, render_type_bit
;
877 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
878 switch(render_type_bit
)
881 render_type
= GLX_RGBA_TYPE
;
883 case GLX_COLOR_INDEX_BIT
:
884 render_type
= GLX_COLOR_INDEX_TYPE
;
886 case GLX_RGBA_FLOAT_BIT
:
887 render_type
= GLX_RGBA_FLOAT_TYPE
;
889 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
890 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
893 ERR("Unknown render_type: %x\n", render_type_bit
);
898 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
899 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
902 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
903 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
905 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
906 * the GLX_PIXMAP_BIT set. */
907 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
910 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
912 static WineGLPixelFormat
*list
;
913 static int size
, onscreen_size
;
915 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
917 XVisualInfo
*visinfo
;
922 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
923 if (NULL
== cfgs
|| 0 == nCfgs
) {
924 if(cfgs
!= NULL
) XFree(cfgs
);
926 ERR("glXChooseFBConfig returns NULL\n");
930 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
931 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
932 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
933 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
935 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
937 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
939 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
942 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
944 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
946 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
947 * Do this as GLX doesn't guarantee that the list is sorted */
948 for(run
=0; run
< 2; run
++)
950 for(i
=0; i
<nCfgs
; i
++) {
951 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
952 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
954 /* The first run we only add onscreen formats (ones which have an associated X Visual).
955 * The second run we only set offscreen formats. */
958 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
959 * The contents is copied to the destination using XCopyArea. For the copying to work
960 * the depth of the source and destination window should be the same. In general this should
961 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
962 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
963 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
964 * list formats with the same depth. */
965 if(visinfo
->depth
!= screen_depth
)
971 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
972 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
973 list
[size
].fbconfig
= cfgs
[i
];
974 list
[size
].fmt_id
= fmt_id
;
975 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
976 list
[size
].offscreenOnly
= FALSE
;
977 list
[size
].dwFlags
= 0;
981 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
982 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
984 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
985 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
986 list
[size
].fbconfig
= cfgs
[i
];
987 list
[size
].fmt_id
= fmt_id
;
988 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
989 list
[size
].offscreenOnly
= FALSE
;
990 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
994 } else if(run
&& !visinfo
) {
995 int window_drawable
=0;
996 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
998 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
999 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1000 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1001 * likely make our child window opengl rendering more complicated since likely you can't use
1002 * XCopyArea on a GLX Window.
1003 * For now ignore fbconfigs which are window drawable but lack a visual. */
1004 if(window_drawable
& GLX_WINDOW_BIT
)
1006 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
1010 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1011 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
1012 list
[size
].fbconfig
= cfgs
[i
];
1013 list
[size
].fmt_id
= fmt_id
;
1014 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1015 list
[size
].offscreenOnly
= TRUE
;
1016 list
[size
].dwFlags
= 0;
1020 if (visinfo
) XFree(visinfo
);
1027 if (size_ret
) *size_ret
= size
;
1028 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
1029 wine_tsx11_unlock();
1033 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1034 * In our WGL implementation we only support a subset of these formats namely the format of
1035 * Wine's main visual and offscreen formats (if they are available).
1036 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1037 * and it returns the number of supported WGL formats in fmt_count.
1039 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
1041 WineGLPixelFormat
*list
, *res
= NULL
;
1042 int size
, onscreen_size
;
1044 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
1046 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1047 * iPixelFormat in case of probing the number of pixelformats.
1049 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
1050 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
1051 res
= &list
[iPixelFormat
-1];
1052 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res
->fmt_id
, iPixelFormat
);
1058 *fmt_count
= onscreen_size
;
1060 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1065 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1066 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1068 WineGLPixelFormat
*list
;
1071 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1073 for(i
=0; i
<size
; i
++) {
1074 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1075 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1076 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1077 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1081 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1085 static int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1087 WineGLPixelFormat
*fmt
;
1089 if (!fbconfig_id
) return 0;
1091 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1093 return fmt
->iPixelFormat
;
1094 /* This will happen on hwnds without a pixel format set; it's ok */
1099 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1100 void mark_drawable_dirty(Drawable old
, Drawable
new)
1102 Wine_GLContext
*ctx
;
1103 LIST_FOR_EACH_ENTRY( ctx
, &context_list
, struct wine_glcontext
, entry
)
1105 if (old
== ctx
->drawables
[0]) {
1106 ctx
->drawables
[0] = new;
1107 ctx
->refresh_drawables
= TRUE
;
1109 if (old
== ctx
->drawables
[1]) {
1110 ctx
->drawables
[1] = new;
1111 ctx
->refresh_drawables
= TRUE
;
1116 /* Given the current context, make sure its drawable is sync'd */
1117 static inline void sync_context(Wine_GLContext
*context
)
1119 if(context
&& context
->refresh_drawables
) {
1120 if (glxRequireVersion(3))
1121 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1122 context
->drawables
[1], context
->ctx
);
1124 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1125 context
->refresh_drawables
= FALSE
;
1130 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1134 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1135 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1137 if(context
->gl3_context
)
1139 if(context
->numAttribs
)
1140 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1142 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1144 else if(context
->vis
)
1145 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1146 else /* Create a GLX Context for a pbuffer */
1147 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1153 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1155 return pglXCreateGLXPixmap(display
, vis
, parent
);
1160 * glxdrv_ChoosePixelFormat
1162 * Equivalent to glXChooseVisual.
1164 static int glxdrv_ChoosePixelFormat(PHYSDEV dev
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1166 WineGLPixelFormat
*list
;
1171 int bestFormat
= -1;
1172 int bestDBuffer
= -1;
1173 int bestStereo
= -1;
1177 int bestStencil
= -1;
1180 if (!has_opengl()) return 0;
1182 if (TRACE_ON(wgl
)) {
1183 TRACE("(%p,%p)\n", dev
->hdc
, ppfd
);
1185 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1188 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1191 for(i
=0; i
<onscreen_size
; i
++)
1195 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1196 WineGLPixelFormat
*fmt
= &list
[i
];
1199 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1200 if (value
& GLX_RGBA_BIT
)
1201 iPixelType
= PFD_TYPE_RGBA
;
1203 iPixelType
= PFD_TYPE_COLORINDEX
;
1205 if (ppfd
->iPixelType
!= iPixelType
)
1207 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1211 /* Only use bitmap capable for formats for bitmap rendering.
1212 * See get_formats for more info. */
1213 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1215 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1219 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1220 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1221 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1222 if (value
) dwFlags
|= PFD_STEREO
;
1223 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1224 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1225 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1226 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1227 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1229 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1230 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1231 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1232 * formats without the given flag set.
1233 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1234 * has indicated that a format without stereo is returned when stereo is unavailable.
1235 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1236 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1238 * To summarize the following is most likely the correct behavior:
1239 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1240 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1241 * stereo don't care -> it doesn't matter whether we get stereo or not
1243 * In Wine we will treat no-stereo the same way as don't care because it makes
1244 * format selection even more complicated and second drivers with Stereo advertise
1245 * each format twice anyway.
1248 /* Doublebuffer, see the comments above */
1249 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1250 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1251 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1254 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1258 /* Stereo, see the comments above. */
1259 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1260 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1261 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1264 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1268 /* Below we will do a number of checks to select the 'best' pixelformat.
1269 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1270 * The code works by trying to match the most important options as close as possible.
1271 * When a reasonable format is found, we will try to match more options.
1272 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1273 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1274 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1276 if(ppfd
->cColorBits
) {
1277 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1278 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1281 if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1282 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1287 if(ppfd
->cAlphaBits
) {
1288 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1289 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1292 if(bestAlpha
!= alpha
) {
1293 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1298 if(ppfd
->cDepthBits
) {
1299 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1300 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1303 if(bestDepth
!= depth
) {
1304 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1309 if(ppfd
->cStencilBits
) {
1310 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1311 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1314 if(bestStencil
!= stencil
) {
1315 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1320 if(ppfd
->cAuxBuffers
) {
1321 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1322 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1325 if(bestAux
!= aux
) {
1326 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1333 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1334 bestStereo
= dwFlags
& PFD_STEREO
;
1338 bestStencil
= stencil
;
1343 if(bestFormat
== -1) {
1344 TRACE("No matching mode was found returning 0\n");
1348 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1349 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1352 wine_tsx11_unlock();
1358 * glxdrv_DescribePixelFormat
1360 * Get the pixel-format descriptor associated to the given id
1362 static int glxdrv_DescribePixelFormat(PHYSDEV dev
, int iPixelFormat
,
1363 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1365 /*XVisualInfo *vis;*/
1368 WineGLPixelFormat
*fmt
;
1372 if (!has_opengl()) return 0;
1374 TRACE("(%p,%d,%d,%p)\n", dev
->hdc
, iPixelFormat
, nBytes
, ppfd
);
1376 /* 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 */
1377 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1379 /* The application is only querying the number of pixelformats */
1381 } else if(fmt
== NULL
) {
1382 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1386 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1387 ERR("Wrong structure size !\n");
1388 /* Should set error */
1394 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1395 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1398 /* These flags are always the same... */
1399 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1400 /* Now the flags extracted from the Visual */
1404 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1405 if(value
& GLX_WINDOW_BIT
)
1406 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1408 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1409 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1410 * 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
1411 * offered the GDI bit either. */
1412 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1414 /* PFD_GENERIC_FORMAT - gdi software rendering
1415 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1416 * none set - full hardware accelerated by a ICD
1418 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1419 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1421 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1423 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1424 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1426 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1429 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1430 if (value
& GLX_RGBA_BIT
)
1431 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1433 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1436 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1437 ppfd
->cColorBits
= value
;
1439 /* Red, green, blue and alpha bits / shifts */
1440 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1441 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1442 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1443 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1444 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1446 ppfd
->cRedBits
= rb
;
1447 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1448 ppfd
->cBlueBits
= bb
;
1449 ppfd
->cBlueShift
= ab
;
1450 ppfd
->cGreenBits
= gb
;
1451 ppfd
->cGreenShift
= bb
+ ab
;
1452 ppfd
->cAlphaBits
= ab
;
1453 ppfd
->cAlphaShift
= 0;
1456 ppfd
->cRedShift
= 0;
1457 ppfd
->cBlueBits
= 0;
1458 ppfd
->cBlueShift
= 0;
1459 ppfd
->cGreenBits
= 0;
1460 ppfd
->cGreenShift
= 0;
1461 ppfd
->cAlphaBits
= 0;
1462 ppfd
->cAlphaShift
= 0;
1465 /* Accum RGBA bits */
1466 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1467 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1468 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1469 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1471 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1472 ppfd
->cAccumRedBits
= rb
;
1473 ppfd
->cAccumGreenBits
= gb
;
1474 ppfd
->cAccumBlueBits
= bb
;
1475 ppfd
->cAccumAlphaBits
= ab
;
1478 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1479 ppfd
->cAuxBuffers
= value
;
1482 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1483 ppfd
->cDepthBits
= value
;
1486 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1487 ppfd
->cStencilBits
= value
;
1489 wine_tsx11_unlock();
1491 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1493 if (TRACE_ON(wgl
)) {
1494 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1501 * glxdrv_GetPixelFormat
1503 * Get the pixel-format id used by this DC
1505 static int glxdrv_GetPixelFormat(PHYSDEV dev
)
1507 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
1508 WineGLPixelFormat
*fmt
;
1511 if (!physdev
->pixel_format
) return 0; /* not set yet */
1513 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physdev
->pixel_format
, TRUE
, &tmp
);
1516 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physdev
->pixel_format
);
1519 else if(fmt
->offscreenOnly
)
1521 /* Offscreen formats can't be used with traditional WGL calls.
1522 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1523 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1527 TRACE("(%p): returns %d\n", dev
->hdc
, physdev
->pixel_format
);
1528 return physdev
->pixel_format
;
1531 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1532 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1533 * set the pixel format multiple times. */
1534 static BOOL
internal_SetPixelFormat( struct glx_physdev
*physdev
,
1536 const PIXELFORMATDESCRIPTOR
*ppfd
)
1538 WineGLPixelFormat
*fmt
;
1542 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1543 if(physdev
->x11dev
->drawable
== root_window
)
1545 ERR("Invalid operation on root_window\n");
1549 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1550 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1552 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1557 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1558 wine_tsx11_unlock();
1560 hwnd
= WindowFromDC(physdev
->dev
.hdc
);
1562 if(!(value
&GLX_WINDOW_BIT
)) {
1563 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1567 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, fmt
->fmt_id
, 0)) {
1568 ERR("Couldn't set format of the window, returning failure\n");
1571 /* physDev->current_pf will be set by the DCE update */
1573 else if (GetObjectType( physdev
->dev
.hdc
) == OBJ_MEMDC
) {
1574 if(!(value
&GLX_PIXMAP_BIT
)) {
1575 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1579 physdev
->pixel_format
= iPixelFormat
;
1580 physdev
->type
= DC_GL_BITMAP
;
1583 FIXME("called on a non-window, non-bitmap object?\n");
1586 if (TRACE_ON(wgl
)) {
1590 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1592 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1594 TRACE(" FBConfig have :\n");
1595 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1596 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1597 TRACE(" - VISUAL_ID 0x%x\n", value
);
1598 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1599 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1601 wine_tsx11_unlock();
1608 * glxdrv_SetPixelFormat
1610 * Set the pixel-format id used by this DC
1612 static BOOL
glxdrv_SetPixelFormat(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1614 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
1616 TRACE("(%p,%d,%p)\n", dev
->hdc
, iPixelFormat
, ppfd
);
1618 if (!has_opengl()) return FALSE
;
1620 if(physdev
->pixel_format
) /* cannot change it if already set */
1621 return (physdev
->pixel_format
== iPixelFormat
);
1623 return internal_SetPixelFormat(physdev
, iPixelFormat
, ppfd
);
1627 * X11DRV_wglCopyContext
1629 * For OpenGL32 wglCopyContext.
1631 static BOOL WINAPI
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
1633 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1634 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1636 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1639 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1640 wine_tsx11_unlock();
1642 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1647 * X11DRV_wglCreateContext
1649 * For OpenGL32 wglCreateContext.
1651 static HGLRC
glxdrv_wglCreateContext(PHYSDEV dev
)
1653 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
1654 Wine_GLContext
*ret
;
1655 WineGLPixelFormat
*fmt
;
1658 TRACE("(%p)->(PF:%d)\n", dev
->hdc
, physdev
->pixel_format
);
1660 if (!has_opengl()) return 0;
1662 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physdev
->pixel_format
, TRUE
/* Offscreen */, &fmt_count
);
1663 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1664 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1665 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1666 * If this fails something is very wrong on the system. */
1668 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", physdev
->pixel_format
);
1669 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1673 if (!(ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
)))) return 0;
1675 ret
->hdc
= dev
->hdc
;
1677 ret
->has_been_current
= FALSE
;
1678 ret
->sharing
= FALSE
;
1681 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1682 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1683 list_add_head( &context_list
, &ret
->entry
);
1684 wine_tsx11_unlock();
1686 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1691 * X11DRV_wglDeleteContext
1693 * For OpenGL32 wglDeleteContext.
1695 static BOOL WINAPI
X11DRV_wglDeleteContext(HGLRC hglrc
)
1697 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1699 TRACE("(%p)\n", hglrc
);
1701 if (!is_valid_context(ctx
))
1703 WARN("Error deleting context !\n");
1704 SetLastError(ERROR_INVALID_HANDLE
);
1708 /* WGL doesn't allow deletion of a context which is current in another thread */
1709 if (ctx
->tid
!= 0 && ctx
->tid
!= GetCurrentThreadId())
1711 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx
);
1712 SetLastError(ERROR_BUSY
);
1716 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1717 if (ctx
== NtCurrentTeb()->glContext
)
1718 wglMakeCurrent(ctx
->hdc
, NULL
);
1721 list_remove( &ctx
->entry
);
1722 if (ctx
->ctx
) pglXDestroyContext( gdi_display
, ctx
->ctx
);
1723 if (ctx
->glxpixmap
) pglXDestroyGLXPixmap( gdi_display
, ctx
->glxpixmap
);
1724 if (ctx
->pixmap
) XFreePixmap( gdi_display
, ctx
->pixmap
);
1725 if (ctx
->vis
) XFree( ctx
->vis
);
1726 wine_tsx11_unlock();
1728 HeapFree( GetProcessHeap(), 0, ctx
);
1733 * X11DRV_wglGetCurrentReadDCARB
1735 * For OpenGL32 wglGetCurrentReadDCARB.
1737 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1740 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1742 if (ctx
) ret
= ctx
->read_hdc
;
1744 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1749 * glxdrv_wglGetProcAddress
1751 * For OpenGL32 wglGetProcAddress.
1753 static PROC
glxdrv_wglGetProcAddress(LPCSTR lpszProc
)
1756 const WineGLExtension
*ext
;
1758 int padding
= 32 - strlen(lpszProc
);
1762 if (!has_opengl()) return NULL
;
1764 /* Check the table of WGL extensions to see if we need to return a WGL extension
1765 * or a function pointer to a native OpenGL function. */
1766 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1767 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1769 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1770 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1771 ext
= WineGLExtensionList
[i
];
1772 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1773 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1774 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1775 return ext
->extEntryPoints
[j
].funcAddress
;
1781 WARN("(%s) - not found\n", lpszProc
);
1785 static GLXPixmap
get_context_pixmap( struct glx_physdev
*physdev
, struct wine_glcontext
*ctx
)
1791 GetObjectW( GetCurrentObject( physdev
->dev
.hdc
, OBJ_BITMAP
), sizeof(bmp
), &bmp
);
1794 ctx
->pixmap
= XCreatePixmap( gdi_display
, root_window
,
1795 bmp
.bmWidth
, bmp
.bmHeight
, ctx
->vis
->depth
);
1796 ctx
->glxpixmap
= pglXCreateGLXPixmap( gdi_display
, ctx
->vis
, ctx
->pixmap
);
1797 wine_tsx11_unlock();
1798 ctx
->pixmap_size
.cx
= bmp
.bmWidth
;
1799 ctx
->pixmap_size
.cy
= bmp
.bmHeight
;
1801 return ctx
->glxpixmap
;
1805 * glxdrv_wglMakeCurrent
1807 * For OpenGL32 wglMakeCurrent.
1809 static BOOL
glxdrv_wglMakeCurrent(PHYSDEV dev
, HGLRC hglrc
)
1811 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
1813 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1814 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1816 TRACE("(%p,%p)\n", dev
->hdc
, hglrc
);
1818 if (!has_opengl()) return FALSE
;
1822 if (prev_ctx
) prev_ctx
->tid
= 0;
1825 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1826 wine_tsx11_unlock();
1827 NtCurrentTeb()->glContext
= NULL
;
1829 else if (!physdev
->pixel_format
)
1831 WARN("Trying to use an invalid drawable\n");
1832 SetLastError(ERROR_INVALID_HANDLE
);
1835 else if (ctx
->fmt
->iPixelFormat
!= physdev
->pixel_format
)
1837 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1838 dev
->hdc
, physdev
->pixel_format
, ctx
, ctx
->fmt
->iPixelFormat
);
1839 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1844 Drawable drawable
= physdev
->drawable
;
1846 if (physdev
->type
== DC_GL_BITMAP
) drawable
= get_context_pixmap( physdev
, ctx
);
1850 if (TRACE_ON(wgl
)) {
1851 describeDrawable( physdev
);
1852 describeContext(ctx
);
1855 TRACE(" make current for drawable %lx, ctx %p\n", drawable
, ctx
->ctx
);
1857 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1861 if (prev_ctx
) prev_ctx
->tid
= 0;
1862 NtCurrentTeb()->glContext
= ctx
;
1864 ctx
->has_been_current
= TRUE
;
1865 ctx
->tid
= GetCurrentThreadId();
1866 ctx
->hdc
= dev
->hdc
;
1867 ctx
->read_hdc
= dev
->hdc
;
1868 ctx
->drawables
[0] = drawable
;
1869 ctx
->drawables
[1] = drawable
;
1870 ctx
->refresh_drawables
= FALSE
;
1872 if (physdev
->type
== DC_GL_BITMAP
) pglDrawBuffer(GL_FRONT_LEFT
);
1875 SetLastError(ERROR_INVALID_HANDLE
);
1876 wine_tsx11_unlock();
1878 TRACE(" returning %s\n", (ret
? "True" : "False"));
1883 * glxdrv_wglMakeContextCurrentARB
1885 * For OpenGL32 wglMakeContextCurrentARB
1887 static BOOL
glxdrv_wglMakeContextCurrentARB( PHYSDEV draw_dev
, PHYSDEV read_dev
, HGLRC hglrc
)
1889 Wine_GLContext
*prev_ctx
= NtCurrentTeb()->glContext
;
1890 struct glx_physdev
*draw_physdev
= get_glxdrv_dev( draw_dev
);
1891 struct glx_physdev
*read_physdev
= get_glxdrv_dev( read_dev
);
1894 TRACE("(%p,%p,%p)\n", draw_dev
->hdc
, read_dev
->hdc
, hglrc
);
1896 if (!has_opengl()) return 0;
1900 if (prev_ctx
) prev_ctx
->tid
= 0;
1903 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1904 wine_tsx11_unlock();
1905 NtCurrentTeb()->glContext
= NULL
;
1907 else if (!draw_physdev
->pixel_format
)
1909 WARN("Trying to use an invalid drawable\n");
1910 SetLastError(ERROR_INVALID_HANDLE
);
1915 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1916 Drawable draw_drawable
= draw_physdev
->drawable
;
1917 Drawable read_drawable
= read_physdev
->drawable
;
1919 if (!pglXMakeContextCurrent
) return FALSE
;
1921 if (draw_physdev
->type
== DC_GL_BITMAP
) draw_drawable
= get_context_pixmap( draw_physdev
, ctx
);
1922 if (read_physdev
->type
== DC_GL_BITMAP
) read_drawable
= get_context_pixmap( read_physdev
, ctx
);
1925 ret
= pglXMakeContextCurrent(gdi_display
, draw_drawable
, read_drawable
, ctx
->ctx
);
1928 if (prev_ctx
) prev_ctx
->tid
= 0;
1930 ctx
->has_been_current
= TRUE
;
1931 ctx
->tid
= GetCurrentThreadId();
1932 ctx
->hdc
= draw_dev
->hdc
;
1933 ctx
->read_hdc
= read_dev
->hdc
;
1934 ctx
->drawables
[0] = draw_drawable
;
1935 ctx
->drawables
[1] = read_drawable
;
1936 ctx
->refresh_drawables
= FALSE
;
1937 NtCurrentTeb()->glContext
= ctx
;
1940 SetLastError(ERROR_INVALID_HANDLE
);
1941 wine_tsx11_unlock();
1944 TRACE(" returning %s\n", (ret
? "True" : "False"));
1949 * X11DRV_wglShareLists
1951 * For OpenGL32 wglShareLists.
1953 static BOOL WINAPI
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
1955 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1956 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1958 TRACE("(%p, %p)\n", org
, dest
);
1960 if (!has_opengl()) return FALSE
;
1962 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1963 * at context creation time but in case of WGL it is done using wglShareLists.
1964 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1965 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1966 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1967 * so there delaying context creation doesn't work.
1969 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1970 * and when a program requests sharing we recreate the destination context if it hasn't been made
1971 * current or when it hasn't shared display lists before.
1974 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
1976 ERR("Could not share display lists, one of the contexts has been current already !\n");
1979 else if(dest
->sharing
)
1981 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1986 if((GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
))
1988 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1992 describeContext(org
);
1993 describeContext(dest
);
1995 /* Re-create the GLX context and share display lists */
1996 pglXDestroyContext(gdi_display
, dest
->ctx
);
1997 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1998 wine_tsx11_unlock();
1999 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
2001 org
->sharing
= TRUE
;
2002 dest
->sharing
= TRUE
;
2008 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2009 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2016 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2018 pglGetIntegerv(pname
, params
);
2020 * if we cannot find a Wine Context
2021 * we only have the default wine desktop context,
2022 * so if we have only a 24 depth say we have 32
2024 if (!ctx
&& *params
== 24) {
2027 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2032 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2034 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2035 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2039 pglGetIntegerv(pname
, params
);
2042 wine_tsx11_unlock();
2045 static void flush_pixmap( struct wine_glcontext
*ctx
)
2047 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
2048 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
2049 struct gdi_image_bits bits
;
2051 if (!get_pixmap_image( ctx
->pixmap
, ctx
->pixmap_size
.cx
, ctx
->pixmap_size
.cy
, ctx
->vis
, info
, &bits
))
2053 HBITMAP bitmap
= GetCurrentObject( ctx
->hdc
, OBJ_BITMAP
);
2054 SetDIBits( 0, bitmap
, 0, ctx
->pixmap_size
.cy
, bits
.ptr
, info
, DIB_RGB_COLORS
);
2055 if (bits
.free
) bits
.free( &bits
);
2059 static void flush_gl_drawable( struct glx_physdev
*physdev
)
2062 int w
= physdev
->x11dev
->dc_rect
.right
- physdev
->x11dev
->dc_rect
.left
;
2063 int h
= physdev
->x11dev
->dc_rect
.bottom
- physdev
->x11dev
->dc_rect
.top
;
2064 Drawable src
= physdev
->drawable
;
2066 if (w
<= 0 || h
<= 0) return;
2068 switch (physdev
->type
)
2070 case DC_GL_PIXMAP_WIN
:
2071 src
= physdev
->pixmap
;
2073 case DC_GL_CHILD_WIN
:
2074 /* The GL drawable may be lagged behind if we don't flush first, so
2075 * flush the display make sure we copy up-to-date data */
2077 XFlush(gdi_display
);
2078 XSetFunction(gdi_display
, physdev
->x11dev
->gc
, GXcopy
);
2079 XCopyArea(gdi_display
, src
, physdev
->x11dev
->drawable
, physdev
->x11dev
->gc
, 0, 0, w
, h
,
2080 physdev
->x11dev
->dc_rect
.left
, physdev
->x11dev
->dc_rect
.top
);
2081 wine_tsx11_unlock();
2082 SetRect( &rect
, 0, 0, w
, h
);
2083 add_device_bounds( physdev
->x11dev
, &rect
);
2090 static void WINAPI
X11DRV_wglFinish(void)
2092 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2093 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2098 wine_tsx11_unlock();
2101 if (ctx
->pixmap
) flush_pixmap( ctx
);
2102 else ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2106 static void WINAPI
X11DRV_wglFlush(void)
2108 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2109 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2114 wine_tsx11_unlock();
2117 if (ctx
->pixmap
) flush_pixmap( ctx
);
2118 else ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2123 * glxdrv_wglCreateContextAttribsARB
2125 * WGL_ARB_create_context: wglCreateContextAttribsARB
2127 static HGLRC
glxdrv_wglCreateContextAttribsARB(PHYSDEV dev
, HGLRC hShareContext
, const int* attribList
)
2129 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
2130 Wine_GLContext
*ret
;
2131 WineGLPixelFormat
*fmt
;
2134 TRACE("(%p %p %p)\n", dev
->hdc
, hShareContext
, attribList
);
2136 if (!has_opengl()) return 0;
2138 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physdev
->pixel_format
, TRUE
/* Offscreen */, &fmt_count
);
2139 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2140 * If this fails something is very wrong on the system. */
2143 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", physdev
->pixel_format
);
2144 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2148 if (!(ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
)))) return 0;
2150 ret
->hdc
= dev
->hdc
;
2152 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2153 ret
->gl3_context
= TRUE
;
2155 ret
->numAttribs
= 0;
2158 int *pAttribList
= (int*)attribList
;
2159 int *pContextAttribList
= &ret
->attribList
[0];
2160 /* attribList consists of pairs {token, value] terminated with 0 */
2161 while(pAttribList
[0] != 0)
2163 TRACE("%#x %#x\n", pAttribList
[0], pAttribList
[1]);
2164 switch(pAttribList
[0])
2166 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2167 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2168 pContextAttribList
[1] = pAttribList
[1];
2170 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2171 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2172 pContextAttribList
[1] = pAttribList
[1];
2174 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2176 case WGL_CONTEXT_FLAGS_ARB
:
2177 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2178 pContextAttribList
[1] = pAttribList
[1];
2180 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2181 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2182 pContextAttribList
[1] = pAttribList
[1];
2185 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList
[0], pAttribList
[1]);
2190 pContextAttribList
+= 2;
2195 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2196 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
2198 XSync(gdi_display
, False
);
2199 if(X11DRV_check_error() || !ret
->ctx
)
2201 /* In the future we should convert the GLX error to a win32 one here if needed */
2202 ERR("Context creation failed\n");
2203 HeapFree( GetProcessHeap(), 0, ret
);
2204 wine_tsx11_unlock();
2208 list_add_head( &context_list
, &ret
->entry
);
2209 wine_tsx11_unlock();
2210 TRACE(" creating context %p\n", ret
);
2215 * X11DRV_wglGetExtensionsStringARB
2217 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2219 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2220 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2221 return WineGLInfo
.wglExtensions
;
2225 * X11DRV_wglCreatePbufferARB
2227 * WGL_ARB_pbuffer: wglCreatePbufferARB
2229 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2231 Wine_GLPBuffer
* object
= NULL
;
2232 WineGLPixelFormat
*fmt
= NULL
;
2237 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2239 if (0 >= iPixelFormat
) {
2240 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2241 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2242 return NULL
; /* unexpected error */
2245 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2246 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2248 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2249 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2250 goto create_failed
; /* unexpected error */
2253 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2254 if (NULL
== object
) {
2255 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2256 goto create_failed
; /* unexpected error */
2259 object
->display
= gdi_display
;
2260 object
->width
= iWidth
;
2261 object
->height
= iHeight
;
2264 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2265 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2266 while (piAttribList
&& 0 != *piAttribList
) {
2268 switch (*piAttribList
) {
2269 case WGL_PBUFFER_LARGEST_ARB
: {
2271 attr_v
= *piAttribList
;
2272 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2273 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2277 case WGL_TEXTURE_FORMAT_ARB
: {
2279 attr_v
= *piAttribList
;
2280 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2281 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2282 object
->use_render_texture
= 0;
2284 if (!use_render_texture_emulation
) {
2285 SetLastError(ERROR_INVALID_DATA
);
2289 case WGL_TEXTURE_RGB_ARB
:
2290 object
->use_render_texture
= GL_RGB
;
2291 object
->texture_bpp
= 3;
2292 object
->texture_format
= GL_RGB
;
2293 object
->texture_type
= GL_UNSIGNED_BYTE
;
2295 case WGL_TEXTURE_RGBA_ARB
:
2296 object
->use_render_texture
= GL_RGBA
;
2297 object
->texture_bpp
= 4;
2298 object
->texture_format
= GL_RGBA
;
2299 object
->texture_type
= GL_UNSIGNED_BYTE
;
2302 /* WGL_FLOAT_COMPONENTS_NV */
2303 case WGL_TEXTURE_FLOAT_R_NV
:
2304 object
->use_render_texture
= GL_FLOAT_R_NV
;
2305 object
->texture_bpp
= 4;
2306 object
->texture_format
= GL_RED
;
2307 object
->texture_type
= GL_FLOAT
;
2309 case WGL_TEXTURE_FLOAT_RG_NV
:
2310 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2311 object
->texture_bpp
= 8;
2312 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2313 object
->texture_type
= GL_FLOAT
;
2315 case WGL_TEXTURE_FLOAT_RGB_NV
:
2316 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2317 object
->texture_bpp
= 12;
2318 object
->texture_format
= GL_RGB
;
2319 object
->texture_type
= GL_FLOAT
;
2321 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2322 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2323 object
->texture_bpp
= 16;
2324 object
->texture_format
= GL_RGBA
;
2325 object
->texture_type
= GL_FLOAT
;
2328 ERR("Unknown texture format: %x\n", attr_v
);
2329 SetLastError(ERROR_INVALID_DATA
);
2336 case WGL_TEXTURE_TARGET_ARB
: {
2338 attr_v
= *piAttribList
;
2339 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2340 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2341 object
->texture_target
= 0;
2343 if (!use_render_texture_emulation
) {
2344 SetLastError(ERROR_INVALID_DATA
);
2348 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2349 if (iWidth
!= iHeight
) {
2350 SetLastError(ERROR_INVALID_DATA
);
2353 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2354 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2357 case WGL_TEXTURE_1D_ARB
: {
2359 SetLastError(ERROR_INVALID_DATA
);
2362 object
->texture_target
= GL_TEXTURE_1D
;
2363 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2366 case WGL_TEXTURE_2D_ARB
: {
2367 object
->texture_target
= GL_TEXTURE_2D
;
2368 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2371 case WGL_TEXTURE_RECTANGLE_NV
: {
2372 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2373 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2377 ERR("Unknown texture target: %x\n", attr_v
);
2378 SetLastError(ERROR_INVALID_DATA
);
2385 case WGL_MIPMAP_TEXTURE_ARB
: {
2387 attr_v
= *piAttribList
;
2388 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2389 if (!use_render_texture_emulation
) {
2390 SetLastError(ERROR_INVALID_DATA
);
2399 PUSH1(attribs
, None
);
2401 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2402 wine_tsx11_unlock();
2403 TRACE("new Pbuffer drawable as %lx\n", object
->drawable
);
2404 if (!object
->drawable
) {
2405 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2406 goto create_failed
; /* unexpected error */
2408 TRACE("->(%p)\n", object
);
2412 HeapFree(GetProcessHeap(), 0, object
);
2413 TRACE("->(FAILED)\n");
2418 * X11DRV_wglDestroyPbufferARB
2420 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2422 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2424 Wine_GLPBuffer
* object
= hPbuffer
;
2425 TRACE("(%p)\n", hPbuffer
);
2426 if (NULL
== object
) {
2427 SetLastError(ERROR_INVALID_HANDLE
);
2431 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2432 wine_tsx11_unlock();
2433 HeapFree(GetProcessHeap(), 0, object
);
2438 * X11DRV_wglGetPbufferDCARB
2440 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2442 static HDC WINAPI
X11DRV_wglGetPbufferDCARB(HPBUFFERARB hPbuffer
)
2444 struct x11drv_escape_set_drawable escape
;
2445 Wine_GLPBuffer
* object
= hPbuffer
;
2448 if (NULL
== object
) {
2449 SetLastError(ERROR_INVALID_HANDLE
);
2453 hdc
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
);
2456 escape
.code
= X11DRV_SET_DRAWABLE
;
2457 escape
.drawable
= object
->drawable
;
2458 escape
.mode
= IncludeInferiors
;
2459 SetRect( &escape
.drawable_rect
, 0, 0, object
->width
, object
->height
);
2460 escape
.dc_rect
= escape
.drawable_rect
;
2461 escape
.fbconfig_id
= object
->fmt
->fmt_id
;
2462 escape
.gl_drawable
= object
->drawable
;
2464 escape
.gl_type
= DC_GL_PBUFFER
;
2465 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2467 TRACE( "(%p)->(%p)\n", hPbuffer
, hdc
);
2472 * X11DRV_wglQueryPbufferARB
2474 * WGL_ARB_pbuffer: wglQueryPbufferARB
2476 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2478 Wine_GLPBuffer
* object
= hPbuffer
;
2479 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2480 if (NULL
== object
) {
2481 SetLastError(ERROR_INVALID_HANDLE
);
2484 switch (iAttribute
) {
2485 case WGL_PBUFFER_WIDTH_ARB
:
2487 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2488 wine_tsx11_unlock();
2490 case WGL_PBUFFER_HEIGHT_ARB
:
2492 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2493 wine_tsx11_unlock();
2496 case WGL_PBUFFER_LOST_ARB
:
2497 /* GLX Pbuffers cannot be lost by default. We can support this by
2498 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2499 * to receive pixel buffer clobber events, however that may or may
2500 * not give any benefit */
2501 *piValue
= GL_FALSE
;
2504 case WGL_TEXTURE_FORMAT_ARB
:
2505 if (!object
->use_render_texture
) {
2506 *piValue
= WGL_NO_TEXTURE_ARB
;
2508 if (!use_render_texture_emulation
) {
2509 SetLastError(ERROR_INVALID_HANDLE
);
2512 switch(object
->use_render_texture
) {
2514 *piValue
= WGL_TEXTURE_RGB_ARB
;
2517 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2519 /* WGL_FLOAT_COMPONENTS_NV */
2521 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2523 case GL_FLOAT_RG_NV
:
2524 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2526 case GL_FLOAT_RGB_NV
:
2527 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2529 case GL_FLOAT_RGBA_NV
:
2530 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2533 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2538 case WGL_TEXTURE_TARGET_ARB
:
2539 if (!object
->texture_target
){
2540 *piValue
= WGL_NO_TEXTURE_ARB
;
2542 if (!use_render_texture_emulation
) {
2543 SetLastError(ERROR_INVALID_DATA
);
2546 switch (object
->texture_target
) {
2547 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2548 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2549 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2550 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2555 case WGL_MIPMAP_TEXTURE_ARB
:
2556 *piValue
= GL_FALSE
; /** don't support that */
2557 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2561 FIXME("unexpected attribute %x\n", iAttribute
);
2569 * X11DRV_wglReleasePbufferDCARB
2571 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2573 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2575 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2576 return DeleteDC(hdc
);
2580 * X11DRV_wglSetPbufferAttribARB
2582 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2584 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2586 Wine_GLPBuffer
* object
= hPbuffer
;
2587 GLboolean ret
= GL_FALSE
;
2589 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2590 if (NULL
== object
) {
2591 SetLastError(ERROR_INVALID_HANDLE
);
2594 if (!object
->use_render_texture
) {
2595 SetLastError(ERROR_INVALID_HANDLE
);
2598 if (1 == use_render_texture_emulation
) {
2605 * X11DRV_wglChoosePixelFormatARB
2607 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2609 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2614 GLXFBConfig
* cfgs
= NULL
;
2618 WineGLPixelFormat
*fmt
;
2624 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2625 if (NULL
!= pfAttribFList
) {
2626 FIXME("unused pfAttribFList\n");
2629 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2630 if (-1 == nAttribs
) {
2631 WARN("Cannot convert WGL to GLX attributes\n");
2634 PUSH1(attribs
, None
);
2636 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2637 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2638 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2639 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2641 switch(piAttribIList
[i
])
2643 case WGL_DRAW_TO_BITMAP_ARB
:
2644 if(piAttribIList
[i
+1])
2645 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2647 case WGL_ACCELERATION_ARB
:
2648 switch(piAttribIList
[i
+1])
2650 case WGL_NO_ACCELERATION_ARB
:
2651 dwFlags
|= PFD_GENERIC_FORMAT
;
2653 case WGL_GENERIC_ACCELERATION_ARB
:
2654 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2656 case WGL_FULL_ACCELERATION_ARB
:
2661 case WGL_SUPPORT_GDI_ARB
:
2662 if(piAttribIList
[i
+1])
2663 dwFlags
|= PFD_SUPPORT_GDI
;
2668 /* Search for FB configurations matching the requirements in attribs */
2670 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2672 wine_tsx11_unlock();
2673 WARN("Compatible Pixel Format not found\n");
2677 /* Loop through all matching formats and check if they are suitable.
2678 * Note that this function should at max return nMaxFormats different formats */
2679 for(run
=0; run
< 2; run
++)
2681 for (it
= 0; it
< nCfgs
&& pfmt_it
< nMaxFormats
; ++it
)
2683 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2685 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2689 /* Search for the format in our list of compatible formats */
2690 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2694 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2695 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2698 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2699 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2704 *nNumFormats
= pfmt_it
;
2707 wine_tsx11_unlock();
2712 * X11DRV_wglGetPixelFormatAttribivARB
2714 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2716 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2719 WineGLPixelFormat
*fmt
= NULL
;
2723 int nWGLFormats
= 0;
2725 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2727 if (0 < iLayerPlane
) {
2728 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2732 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2733 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2734 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2735 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2737 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2741 for (i
= 0; i
< nAttributes
; ++i
) {
2742 const int curWGLAttr
= piAttributes
[i
];
2743 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2745 switch (curWGLAttr
) {
2746 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2747 piValues
[i
] = nWGLFormats
;
2750 case WGL_SUPPORT_OPENGL_ARB
:
2751 piValues
[i
] = GL_TRUE
;
2754 case WGL_ACCELERATION_ARB
:
2755 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2756 if (!fmt
) goto pix_error
;
2757 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2758 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2759 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2760 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2762 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2765 case WGL_TRANSPARENT_ARB
:
2766 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2767 if (!fmt
) goto pix_error
;
2768 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2769 if (hTest
) goto get_error
;
2770 piValues
[i
] = GL_FALSE
;
2771 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2774 case WGL_PIXEL_TYPE_ARB
:
2775 curGLXAttr
= GLX_RENDER_TYPE
;
2776 if (!fmt
) goto pix_error
;
2777 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2778 if (hTest
) goto get_error
;
2779 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2780 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2781 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2782 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2783 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2784 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2786 ERR("unexpected RenderType(%x)\n", tmp
);
2787 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2791 case WGL_COLOR_BITS_ARB
:
2792 curGLXAttr
= GLX_BUFFER_SIZE
;
2795 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2796 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2797 if (!use_render_texture_emulation
) {
2798 piValues
[i
] = GL_FALSE
;
2801 curGLXAttr
= GLX_RENDER_TYPE
;
2802 if (!fmt
) goto pix_error
;
2803 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2804 if (hTest
) goto get_error
;
2805 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2806 piValues
[i
] = GL_FALSE
;
2809 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2810 if (hTest
) goto get_error
;
2811 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2814 case WGL_BLUE_BITS_ARB
:
2815 curGLXAttr
= GLX_BLUE_SIZE
;
2817 case WGL_RED_BITS_ARB
:
2818 curGLXAttr
= GLX_RED_SIZE
;
2820 case WGL_GREEN_BITS_ARB
:
2821 curGLXAttr
= GLX_GREEN_SIZE
;
2823 case WGL_ALPHA_BITS_ARB
:
2824 curGLXAttr
= GLX_ALPHA_SIZE
;
2826 case WGL_DEPTH_BITS_ARB
:
2827 curGLXAttr
= GLX_DEPTH_SIZE
;
2829 case WGL_STENCIL_BITS_ARB
:
2830 curGLXAttr
= GLX_STENCIL_SIZE
;
2832 case WGL_DOUBLE_BUFFER_ARB
:
2833 curGLXAttr
= GLX_DOUBLEBUFFER
;
2835 case WGL_STEREO_ARB
:
2836 curGLXAttr
= GLX_STEREO
;
2838 case WGL_AUX_BUFFERS_ARB
:
2839 curGLXAttr
= GLX_AUX_BUFFERS
;
2842 case WGL_SUPPORT_GDI_ARB
:
2843 if (!fmt
) goto pix_error
;
2844 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
2847 case WGL_DRAW_TO_BITMAP_ARB
:
2848 if (!fmt
) goto pix_error
;
2849 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
2852 case WGL_DRAW_TO_WINDOW_ARB
:
2853 case WGL_DRAW_TO_PBUFFER_ARB
:
2854 if (!fmt
) goto pix_error
;
2855 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2856 if (hTest
) goto get_error
;
2857 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2858 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2859 piValues
[i
] = GL_TRUE
;
2861 piValues
[i
] = GL_FALSE
;
2864 case WGL_SWAP_METHOD_ARB
:
2865 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2866 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2867 * point only ATI offers this.
2869 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2872 case WGL_PBUFFER_LARGEST_ARB
:
2873 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2876 case WGL_SAMPLE_BUFFERS_ARB
:
2877 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2880 case WGL_SAMPLES_ARB
:
2881 curGLXAttr
= GLX_SAMPLES_ARB
;
2884 case WGL_FLOAT_COMPONENTS_NV
:
2885 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2888 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
2889 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
2892 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
2893 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
2896 case WGL_ACCUM_RED_BITS_ARB
:
2897 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2899 case WGL_ACCUM_GREEN_BITS_ARB
:
2900 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2902 case WGL_ACCUM_BLUE_BITS_ARB
:
2903 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2905 case WGL_ACCUM_ALPHA_BITS_ARB
:
2906 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2908 case WGL_ACCUM_BITS_ARB
:
2909 if (!fmt
) goto pix_error
;
2910 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2911 if (hTest
) goto get_error
;
2913 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2914 if (hTest
) goto get_error
;
2916 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2917 if (hTest
) goto get_error
;
2919 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2920 if (hTest
) goto get_error
;
2925 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2928 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2929 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2930 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2932 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2933 * and check which options can work using iPixelFormat=0 and which not.
2934 * A problem would be that this function is an extension. This would
2935 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2937 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2938 if (!fmt
) goto pix_error
;
2939 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2940 if (hTest
) goto get_error
;
2943 piValues
[i
] = GL_FALSE
;
2946 wine_tsx11_unlock();
2950 wine_tsx11_unlock();
2951 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2955 wine_tsx11_unlock();
2956 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2961 * X11DRV_wglGetPixelFormatAttribfvARB
2963 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2965 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2971 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2973 /* Allocate a temporary array to store integer values */
2974 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2976 ERR("couldn't allocate %d array\n", nAttributes
);
2980 /* Piggy-back on wglGetPixelFormatAttribivARB */
2981 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2983 /* Convert integer values to float. Should also check for attributes
2984 that can give decimal values here */
2985 for (i
=0; i
<nAttributes
;i
++) {
2986 pfValues
[i
] = attr
[i
];
2990 HeapFree(GetProcessHeap(), 0, attr
);
2995 * X11DRV_wglBindTexImageARB
2997 * WGL_ARB_render_texture: wglBindTexImageARB
2999 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3001 Wine_GLPBuffer
* object
= hPbuffer
;
3002 GLboolean ret
= GL_FALSE
;
3004 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3005 if (NULL
== object
) {
3006 SetLastError(ERROR_INVALID_HANDLE
);
3009 if (!object
->use_render_texture
) {
3010 SetLastError(ERROR_INVALID_HANDLE
);
3014 if (1 == use_render_texture_emulation
) {
3015 static int init
= 0;
3016 int prev_binded_texture
= 0;
3017 GLXContext prev_context
;
3018 Drawable prev_drawable
;
3019 GLXContext tmp_context
;
3022 prev_context
= pglXGetCurrentContext();
3023 prev_drawable
= pglXGetCurrentDrawable();
3025 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3026 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3027 isn't ideal performance wise but I wasn't able to get other ways working.
3030 init
= 1; /* Only show the FIXME once for performance reasons */
3031 FIXME("partial stub!\n");
3034 TRACE("drawable=%lx, context=%p\n", object
->drawable
, prev_context
);
3035 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3037 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3039 /* Switch to our pbuffer */
3040 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3042 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3043 * After that upload the pbuffer texture data. */
3044 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3045 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3047 /* Switch back to the original drawable and upload the pbuffer-texture */
3048 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3049 pglXDestroyContext(gdi_display
, tmp_context
);
3050 wine_tsx11_unlock();
3058 * X11DRV_wglReleaseTexImageARB
3060 * WGL_ARB_render_texture: wglReleaseTexImageARB
3062 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3064 Wine_GLPBuffer
* object
= hPbuffer
;
3065 GLboolean ret
= GL_FALSE
;
3067 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3068 if (NULL
== object
) {
3069 SetLastError(ERROR_INVALID_HANDLE
);
3072 if (!object
->use_render_texture
) {
3073 SetLastError(ERROR_INVALID_HANDLE
);
3076 if (1 == use_render_texture_emulation
) {
3083 * X11DRV_wglGetExtensionsStringEXT
3085 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3087 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3088 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3089 return WineGLInfo
.wglExtensions
;
3093 * X11DRV_wglGetSwapIntervalEXT
3095 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3097 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3098 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
3099 * interval, so the swap interval has to be tracked. */
3101 return swap_interval
;
3105 * X11DRV_wglSwapIntervalEXT
3107 * WGL_EXT_swap_control: wglSwapIntervalEXT
3109 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3112 TRACE("(%d)\n", interval
);
3116 SetLastError(ERROR_INVALID_DATA
);
3119 else if (!has_swap_control
&& interval
== 0)
3121 /* wglSwapIntervalEXT considers an interval value of zero to mean that
3122 * vsync should be disabled, but glXSwapIntervalSGI considers such a
3123 * value to be an error. Just silently ignore the request for now. */
3124 WARN("Request to disable vertical sync is not handled\n");
3129 if (pglXSwapIntervalSGI
)
3132 ret
= !pglXSwapIntervalSGI(interval
);
3133 wine_tsx11_unlock();
3136 WARN("GLX_SGI_swap_control extension is not available\n");
3139 swap_interval
= interval
;
3141 SetLastError(ERROR_DC_NOT_FOUND
);
3148 * X11DRV_wglAllocateMemoryNV
3150 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3152 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3154 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3156 if (pglXAllocateMemoryNV
)
3159 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3160 wine_tsx11_unlock();
3166 * X11DRV_wglFreeMemoryNV
3168 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3170 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3171 TRACE("(%p)\n", pointer
);
3172 if (pglXFreeMemoryNV
== NULL
)
3176 pglXFreeMemoryNV(pointer
);
3177 wine_tsx11_unlock();
3181 * glxdrv_wglSetPixelFormatWINE
3183 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3184 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3186 static BOOL
glxdrv_wglSetPixelFormatWINE(PHYSDEV dev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3188 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3190 TRACE("(%p,%d,%p)\n", dev
->hdc
, iPixelFormat
, ppfd
);
3192 if (!has_opengl()) return FALSE
;
3194 if (physdev
->pixel_format
== iPixelFormat
) return TRUE
;
3196 /* Relay to the core SetPixelFormat */
3197 TRACE("Changing iPixelFormat from %d to %d\n", physdev
->pixel_format
, iPixelFormat
);
3198 return internal_SetPixelFormat(physdev
, iPixelFormat
, ppfd
);
3202 * glxRequireVersion (internal)
3204 * Check if the supported GLX version matches requiredVersion.
3206 static BOOL
glxRequireVersion(int requiredVersion
)
3208 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3209 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3215 static BOOL
glxRequireExtension(const char *requiredExtension
)
3217 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3224 static void register_extension_string(const char *ext
)
3226 if (WineGLInfo
.wglExtensions
[0])
3227 strcat(WineGLInfo
.wglExtensions
, " ");
3228 strcat(WineGLInfo
.wglExtensions
, ext
);
3230 TRACE("'%s'\n", ext
);
3233 static BOOL
register_extension(const WineGLExtension
* ext
)
3237 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3238 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3240 register_extension_string(ext
->extName
);
3242 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3243 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3248 static const WineGLExtension WGL_internal_functions
=
3252 { "wglCopyContext", X11DRV_wglCopyContext
},
3253 { "wglDeleteContext", X11DRV_wglDeleteContext
},
3254 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3255 { "wglFinish", X11DRV_wglFinish
},
3256 { "wglFlush", X11DRV_wglFlush
},
3257 { "wglShareLists", X11DRV_wglShareLists
},
3262 static const WineGLExtension WGL_ARB_create_context
=
3264 "WGL_ARB_create_context",
3266 { "wglCreateContextAttribsARB", (void *)1 /* not called directly */ },
3270 static const WineGLExtension WGL_ARB_extensions_string
=
3272 "WGL_ARB_extensions_string",
3274 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3278 static const WineGLExtension WGL_ARB_make_current_read
=
3280 "WGL_ARB_make_current_read",
3282 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3283 { "wglMakeContextCurrentARB", (void *)1 /* not called directly */ },
3287 static const WineGLExtension WGL_ARB_multisample
=
3289 "WGL_ARB_multisample",
3292 static const WineGLExtension WGL_ARB_pbuffer
=
3296 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3297 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3298 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3299 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3300 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3301 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3305 static const WineGLExtension WGL_ARB_pixel_format
=
3307 "WGL_ARB_pixel_format",
3309 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3310 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3311 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3315 static const WineGLExtension WGL_ARB_render_texture
=
3317 "WGL_ARB_render_texture",
3319 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3320 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3324 static const WineGLExtension WGL_EXT_extensions_string
=
3326 "WGL_EXT_extensions_string",
3328 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3332 static const WineGLExtension WGL_EXT_swap_control
=
3334 "WGL_EXT_swap_control",
3336 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3337 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3341 static const WineGLExtension WGL_NV_vertex_array_range
=
3343 "WGL_NV_vertex_array_range",
3345 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3346 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3350 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3352 "WGL_WINE_pixel_format_passthrough",
3354 { "wglSetPixelFormatWINE", (void *)1 /* not called directly */ },
3359 * X11DRV_WineGL_LoadExtensions
3361 static void X11DRV_WineGL_LoadExtensions(void)
3363 WineGLInfo
.wglExtensions
[0] = 0;
3365 /* Load Wine internal functions */
3366 register_extension(&WGL_internal_functions
);
3368 /* ARB Extensions */
3370 if(glxRequireExtension("GLX_ARB_create_context"))
3372 register_extension(&WGL_ARB_create_context
);
3374 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3375 register_extension_string("WGL_ARB_create_context_profile");
3378 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3380 register_extension_string("WGL_ARB_pixel_format_float");
3381 register_extension_string("WGL_ATI_pixel_format_float");
3384 register_extension(&WGL_ARB_extensions_string
);
3386 if (glxRequireVersion(3))
3387 register_extension(&WGL_ARB_make_current_read
);
3389 if (glxRequireExtension("GLX_ARB_multisample"))
3390 register_extension(&WGL_ARB_multisample
);
3392 /* In general pbuffer functionality requires support in the X-server. The functionality is
3393 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3395 if ( glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") )
3396 register_extension(&WGL_ARB_pbuffer
);
3398 register_extension(&WGL_ARB_pixel_format
);
3400 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3401 if (glxRequireExtension("GLX_ARB_render_texture") ||
3402 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3404 register_extension(&WGL_ARB_render_texture
);
3406 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3407 if(glxRequireExtension("GLX_NV_float_buffer"))
3408 register_extension_string("WGL_NV_float_buffer");
3410 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3411 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3412 register_extension_string("WGL_NV_texture_rectangle");
3415 /* EXT Extensions */
3417 register_extension(&WGL_EXT_extensions_string
);
3419 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3420 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3421 register_extension(&WGL_EXT_swap_control
);
3423 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3424 register_extension_string("WGL_EXT_framebuffer_sRGB");
3426 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3427 register_extension_string("WGL_EXT_pixel_format_packed_float");
3429 if (glxRequireExtension("GLX_EXT_swap_control"))
3430 has_swap_control
= TRUE
;
3432 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3433 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3434 register_extension(&WGL_NV_vertex_array_range
);
3436 /* WINE-specific WGL Extensions */
3438 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3439 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3441 register_extension(&WGL_WINE_pixel_format_passthrough
);
3445 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3448 pglXDestroyGLXPixmap(display
, glxpixmap
);
3449 wine_tsx11_unlock();
3454 * glxdrv_SwapBuffers
3456 * Swap the buffers of this DC
3458 static BOOL
glxdrv_SwapBuffers(PHYSDEV dev
)
3460 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3461 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3463 if (!has_opengl()) return FALSE
;
3465 TRACE("(%p)\n", dev
->hdc
);
3469 WARN("Using a NULL context, skipping\n");
3470 SetLastError(ERROR_INVALID_HANDLE
);
3474 if (!physdev
->drawable
)
3476 WARN("Using an invalid drawable, skipping\n");
3477 SetLastError(ERROR_INVALID_HANDLE
);
3483 switch (physdev
->type
)
3485 case DC_GL_PIXMAP_WIN
:
3486 if(pglXCopySubBufferMESA
) {
3487 int w
= physdev
->x11dev
->dc_rect
.right
- physdev
->x11dev
->dc_rect
.left
;
3488 int h
= physdev
->x11dev
->dc_rect
.bottom
- physdev
->x11dev
->dc_rect
.top
;
3490 /* (glX)SwapBuffers has an implicit glFlush effect, however
3491 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3495 pglXCopySubBufferMESA(gdi_display
, physdev
->drawable
, 0, 0, w
, h
);
3500 pglXSwapBuffers(gdi_display
, physdev
->drawable
);
3504 flush_gl_drawable( physdev
);
3505 wine_tsx11_unlock();
3510 static long prev_time
, start_time
;
3511 static unsigned long frames
, frames_total
;
3513 DWORD time
= GetTickCount();
3516 /* every 1.5 seconds */
3517 if (time
- prev_time
> 1500) {
3518 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3519 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3522 if(start_time
== 0) start_time
= time
;
3529 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3531 WineGLPixelFormat
*fmt
;
3534 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3539 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3540 wine_tsx11_unlock();
3544 static BOOL
create_glx_dc( PHYSDEV
*pdev
)
3546 /* assume that only the main x11 device implements GetDeviceCaps */
3547 X11DRV_PDEVICE
*x11dev
= get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev
, pGetDeviceCaps
));
3548 struct glx_physdev
*physdev
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*physdev
) );
3550 if (!physdev
) return FALSE
;
3551 physdev
->x11dev
= x11dev
;
3552 push_dc_driver( pdev
, &physdev
->dev
, &glxdrv_funcs
);
3556 /**********************************************************************
3559 static BOOL
glxdrv_CreateDC( PHYSDEV
*pdev
, LPCWSTR driver
, LPCWSTR device
,
3560 LPCWSTR output
, const DEVMODEW
* initData
)
3562 return create_glx_dc( pdev
);
3565 /**********************************************************************
3566 * glxdrv_CreateCompatibleDC
3568 static BOOL
glxdrv_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
)
3570 if (orig
) /* chain to next driver first */
3572 orig
= GET_NEXT_PHYSDEV( orig
, pCreateCompatibleDC
);
3573 if (!orig
->funcs
->pCreateCompatibleDC( orig
, pdev
)) return FALSE
;
3575 /* otherwise we have been called by x11drv */
3576 return create_glx_dc( pdev
);
3579 /**********************************************************************
3582 static BOOL
glxdrv_DeleteDC( PHYSDEV dev
)
3584 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3585 HeapFree( GetProcessHeap(), 0, physdev
);
3589 /**********************************************************************
3592 static INT
glxdrv_ExtEscape( PHYSDEV dev
, INT escape
, INT in_count
, LPCVOID in_data
,
3593 INT out_count
, LPVOID out_data
)
3595 struct glx_physdev
*physdev
= get_glxdrv_dev( dev
);
3597 dev
= GET_NEXT_PHYSDEV( dev
, pExtEscape
);
3599 if (escape
== X11DRV_ESCAPE
&& in_data
&& in_count
>= sizeof(enum x11drv_escape_codes
))
3601 switch (*(const enum x11drv_escape_codes
*)in_data
)
3603 case X11DRV_SET_DRAWABLE
:
3604 if (in_count
>= sizeof(struct x11drv_escape_set_drawable
))
3606 const struct x11drv_escape_set_drawable
*data
= in_data
;
3607 physdev
->pixel_format
= pixelformat_from_fbconfig_id( data
->fbconfig_id
);
3608 physdev
->type
= data
->gl_type
;
3609 physdev
->drawable
= data
->gl_drawable
;
3610 physdev
->pixmap
= data
->pixmap
;
3611 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %u type %u\n",
3612 dev
->hdc
, physdev
->drawable
, physdev
->pixel_format
, physdev
->type
);
3615 case X11DRV_FLUSH_GL_DRAWABLE
:
3616 flush_gl_drawable( physdev
);
3622 return dev
->funcs
->pExtEscape( dev
, escape
, in_count
, in_data
, out_count
, out_data
);
3625 static const struct gdi_dc_funcs glxdrv_funcs
=
3627 NULL
, /* pAbortDoc */
3628 NULL
, /* pAbortPath */
3629 NULL
, /* pAlphaBlend */
3630 NULL
, /* pAngleArc */
3633 NULL
, /* pBeginPath */
3634 NULL
, /* pBlendImage */
3635 glxdrv_ChoosePixelFormat
, /* pChoosePixelFormat */
3637 NULL
, /* pCloseFigure */
3638 glxdrv_CreateCompatibleDC
, /* pCreateCompatibleDC */
3639 glxdrv_CreateDC
, /* pCreateDC */
3640 glxdrv_DeleteDC
, /* pDeleteDC */
3641 NULL
, /* pDeleteObject */
3642 glxdrv_DescribePixelFormat
, /* pDescribePixelFormat */
3643 NULL
, /* pDeviceCapabilities */
3644 NULL
, /* pEllipse */
3646 NULL
, /* pEndPage */
3647 NULL
, /* pEndPath */
3648 NULL
, /* pEnumFonts */
3649 NULL
, /* pEnumICMProfiles */
3650 NULL
, /* pExcludeClipRect */
3651 NULL
, /* pExtDeviceMode */
3652 glxdrv_ExtEscape
, /* pExtEscape */
3653 NULL
, /* pExtFloodFill */
3654 NULL
, /* pExtSelectClipRgn */
3655 NULL
, /* pExtTextOut */
3656 NULL
, /* pFillPath */
3657 NULL
, /* pFillRgn */
3658 NULL
, /* pFlattenPath */
3659 NULL
, /* pFontIsLinked */
3660 NULL
, /* pFrameRgn */
3661 NULL
, /* pGdiComment */
3662 NULL
, /* pGdiRealizationInfo */
3663 NULL
, /* pGetBoundsRect */
3664 NULL
, /* pGetCharABCWidths */
3665 NULL
, /* pGetCharABCWidthsI */
3666 NULL
, /* pGetCharWidth */
3667 NULL
, /* pGetDeviceCaps */
3668 NULL
, /* pGetDeviceGammaRamp */
3669 NULL
, /* pGetFontData */
3670 NULL
, /* pGetFontUnicodeRanges */
3671 NULL
, /* pGetGlyphIndices */
3672 NULL
, /* pGetGlyphOutline */
3673 NULL
, /* pGetICMProfile */
3674 NULL
, /* pGetImage */
3675 NULL
, /* pGetKerningPairs */
3676 NULL
, /* pGetNearestColor */
3677 NULL
, /* pGetOutlineTextMetrics */
3678 NULL
, /* pGetPixel */
3679 glxdrv_GetPixelFormat
, /* pGetPixelFormat */
3680 NULL
, /* pGetSystemPaletteEntries */
3681 NULL
, /* pGetTextCharsetInfo */
3682 NULL
, /* pGetTextExtentExPoint */
3683 NULL
, /* pGetTextExtentExPointI */
3684 NULL
, /* pGetTextFace */
3685 NULL
, /* pGetTextMetrics */
3686 NULL
, /* pGradientFill */
3687 NULL
, /* pIntersectClipRect */
3688 NULL
, /* pInvertRgn */
3690 NULL
, /* pModifyWorldTransform */
3692 NULL
, /* pOffsetClipRgn */
3693 NULL
, /* pOffsetViewportOrg */
3694 NULL
, /* pOffsetWindowOrg */
3695 NULL
, /* pPaintRgn */
3698 NULL
, /* pPolyBezier */
3699 NULL
, /* pPolyBezierTo */
3700 NULL
, /* pPolyDraw */
3701 NULL
, /* pPolyPolygon */
3702 NULL
, /* pPolyPolyline */
3703 NULL
, /* pPolygon */
3704 NULL
, /* pPolyline */
3705 NULL
, /* pPolylineTo */
3706 NULL
, /* pPutImage */
3707 NULL
, /* pRealizeDefaultPalette */
3708 NULL
, /* pRealizePalette */
3709 NULL
, /* pRectangle */
3710 NULL
, /* pResetDC */
3711 NULL
, /* pRestoreDC */
3712 NULL
, /* pRoundRect */
3714 NULL
, /* pScaleViewportExt */
3715 NULL
, /* pScaleWindowExt */
3716 NULL
, /* pSelectBitmap */
3717 NULL
, /* pSelectBrush */
3718 NULL
, /* pSelectClipPath */
3719 NULL
, /* pSelectFont */
3720 NULL
, /* pSelectPalette */
3721 NULL
, /* pSelectPen */
3722 NULL
, /* pSetArcDirection */
3723 NULL
, /* pSetBkColor */
3724 NULL
, /* pSetBkMode */
3725 NULL
, /* pSetBoundsRect */
3726 NULL
, /* pSetDCBrushColor */
3727 NULL
, /* pSetDCPenColor */
3728 NULL
, /* pSetDIBitsToDevice */
3729 NULL
, /* pSetDeviceClipping */
3730 NULL
, /* pSetDeviceGammaRamp */
3731 NULL
, /* pSetLayout */
3732 NULL
, /* pSetMapMode */
3733 NULL
, /* pSetMapperFlags */
3734 NULL
, /* pSetPixel */
3735 glxdrv_SetPixelFormat
, /* pSetPixelFormat */
3736 NULL
, /* pSetPolyFillMode */
3737 NULL
, /* pSetROP2 */
3738 NULL
, /* pSetRelAbs */
3739 NULL
, /* pSetStretchBltMode */
3740 NULL
, /* pSetTextAlign */
3741 NULL
, /* pSetTextCharacterExtra */
3742 NULL
, /* pSetTextColor */
3743 NULL
, /* pSetTextJustification */
3744 NULL
, /* pSetViewportExt */
3745 NULL
, /* pSetViewportOrg */
3746 NULL
, /* pSetWindowExt */
3747 NULL
, /* pSetWindowOrg */
3748 NULL
, /* pSetWorldTransform */
3749 NULL
, /* pStartDoc */
3750 NULL
, /* pStartPage */
3751 NULL
, /* pStretchBlt */
3752 NULL
, /* pStretchDIBits */
3753 NULL
, /* pStrokeAndFillPath */
3754 NULL
, /* pStrokePath */
3755 glxdrv_SwapBuffers
, /* pSwapBuffers */
3756 NULL
, /* pUnrealizePalette */
3757 NULL
, /* pWidenPath */
3758 NULL
, /* pwglCopyContext */
3759 glxdrv_wglCreateContext
, /* pwglCreateContext */
3760 glxdrv_wglCreateContextAttribsARB
, /* pwglCreateContextAttribsARB */
3761 NULL
, /* pwglDeleteContext */
3762 glxdrv_wglGetProcAddress
, /* pwglGetProcAddress */
3763 glxdrv_wglMakeContextCurrentARB
, /* pwglMakeContextCurrentARB */
3764 glxdrv_wglMakeCurrent
, /* pwglMakeCurrent */
3765 glxdrv_wglSetPixelFormatWINE
, /* pwglSetPixelFormatWINE */
3766 NULL
, /* pwglShareLists */
3767 NULL
, /* pwglUseFontBitmapsA */
3768 NULL
, /* pwglUseFontBitmapsW */
3769 GDI_PRIORITY_GRAPHICS_DRV
+ 20 /* priority */
3772 const struct gdi_dc_funcs
*get_glx_driver(void)
3774 return &glxdrv_funcs
;
3777 #else /* no OpenGL includes */
3779 const struct gdi_dc_funcs
*get_glx_driver(void)
3784 void mark_drawable_dirty(Drawable old
, Drawable
new)
3788 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3794 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3799 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3804 #endif /* defined(SONAME_LIBGL) */