2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
41 #include "wine/library.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
45 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
66 /* Redefines the constants */
67 #define CALLBACK __stdcall
68 #define WINAPI __stdcall
69 #define APIENTRY WINAPI
72 WINE_DECLARE_DEBUG_CHANNEL(fps
);
74 typedef struct wine_glextension
{
83 const char *glVersion
;
88 const char *glxServerVersion
;
89 const char *glxServerVendor
;
90 const char *glxServerExtensions
;
92 const char *glxClientVersion
;
93 const char *glxClientVendor
;
94 const char *glxClientExtensions
;
96 const char *glxExtensions
;
99 char wglExtensions
[4096];
102 typedef struct wine_glpixelformat
{
104 GLXFBConfig fbconfig
;
108 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
111 typedef struct wine_glcontext
{
114 BOOL has_been_current
;
118 WineGLPixelFormat
*fmt
;
119 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
120 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
123 Drawable drawables
[2];
124 BOOL refresh_drawables
;
125 struct wine_glcontext
*next
;
126 struct wine_glcontext
*prev
;
129 typedef struct wine_glpbuffer
{
132 WineGLPixelFormat
* fmt
;
138 int use_render_texture
; /* This is also the internal texture format */
139 int texture_bind_target
;
141 GLint texture_format
;
142 GLuint texture_target
;
148 static Wine_GLContext
*context_list
;
149 static struct WineGLInfo WineGLInfo
= { 0 };
150 static int use_render_texture_emulation
= 1;
151 static int use_render_texture_ati
= 0;
152 static int swap_interval
= 1;
154 #define MAX_EXTENSIONS 16
155 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
156 static int WineGLExtensionListSize
;
158 static void X11DRV_WineGL_LoadExtensions(void);
159 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
160 static BOOL
glxRequireVersion(int requiredVersion
);
161 static BOOL
glxRequireExtension(const char *requiredExtension
);
163 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
164 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
165 TRACE(" - dwFlags : ");
166 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
173 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
174 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
175 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
176 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
177 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
178 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
179 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
180 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
181 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
182 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
183 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
184 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
185 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
189 TRACE(" - iPixelType : ");
190 switch (ppfd
->iPixelType
) {
191 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
192 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
196 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
197 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
198 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
199 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
200 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
201 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
202 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
203 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
204 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
206 TRACE(" - iLayerType : ");
207 switch (ppfd
->iLayerType
) {
208 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
209 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
210 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
215 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
216 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
218 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
220 MAKE_FUNCPTR(glXChooseVisual
)
221 MAKE_FUNCPTR(glXCopyContext
)
222 MAKE_FUNCPTR(glXCreateContext
)
223 MAKE_FUNCPTR(glXCreateGLXPixmap
)
224 MAKE_FUNCPTR(glXGetCurrentContext
)
225 MAKE_FUNCPTR(glXGetCurrentDrawable
)
226 MAKE_FUNCPTR(glXDestroyContext
)
227 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
228 MAKE_FUNCPTR(glXGetConfig
)
229 MAKE_FUNCPTR(glXIsDirect
)
230 MAKE_FUNCPTR(glXMakeCurrent
)
231 MAKE_FUNCPTR(glXSwapBuffers
)
232 MAKE_FUNCPTR(glXQueryExtension
)
233 MAKE_FUNCPTR(glXQueryVersion
)
234 MAKE_FUNCPTR(glXUseXFont
)
237 MAKE_FUNCPTR(glXGetClientString
)
238 MAKE_FUNCPTR(glXQueryExtensionsString
)
239 MAKE_FUNCPTR(glXQueryServerString
)
242 MAKE_FUNCPTR(glXGetFBConfigs
)
243 MAKE_FUNCPTR(glXChooseFBConfig
)
244 MAKE_FUNCPTR(glXCreatePbuffer
)
245 MAKE_FUNCPTR(glXCreateNewContext
)
246 MAKE_FUNCPTR(glXDestroyPbuffer
)
247 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
248 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
249 MAKE_FUNCPTR(glXMakeContextCurrent
)
250 MAKE_FUNCPTR(glXQueryDrawable
)
251 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
254 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
255 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
256 static int (*pglXSwapIntervalSGI
)(int);
258 /* ATI GLX Extensions */
259 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
260 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
261 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
263 /* NV GLX Extension */
264 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
265 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
267 /* MESA GLX Extensions */
268 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
270 /* Standard OpenGL */
271 MAKE_FUNCPTR(glBindTexture
)
272 MAKE_FUNCPTR(glBitmap
)
273 MAKE_FUNCPTR(glCopyTexSubImage1D
)
274 MAKE_FUNCPTR(glCopyTexImage2D
)
275 MAKE_FUNCPTR(glCopyTexSubImage2D
)
276 MAKE_FUNCPTR(glDrawBuffer
)
277 MAKE_FUNCPTR(glEndList
)
278 MAKE_FUNCPTR(glGetError
)
279 MAKE_FUNCPTR(glGetIntegerv
)
280 MAKE_FUNCPTR(glGetString
)
281 MAKE_FUNCPTR(glNewList
)
282 MAKE_FUNCPTR(glPixelStorei
)
283 MAKE_FUNCPTR(glReadPixels
)
284 MAKE_FUNCPTR(glTexImage2D
)
285 MAKE_FUNCPTR(glFinish
)
286 MAKE_FUNCPTR(glFlush
)
289 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
291 /* In the future we might want to find the exact X or GLX error to report back to the app */
295 static BOOL infoInitialized
= FALSE
;
296 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
298 int screen
= DefaultScreen(gdi_display
);
299 Window win
= RootWindow(gdi_display
, screen
);
302 GLXContext ctx
= NULL
;
303 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
307 infoInitialized
= TRUE
;
311 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
313 WORD old_fs
= wine_get_fs();
314 /* Create a GLX Context. Without one we can't query GL information */
315 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
316 if (wine_get_fs() != old_fs
)
318 wine_set_fs( old_fs
);
320 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
321 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
327 pglXMakeCurrent(gdi_display
, win
, ctx
);
329 ERR(" couldn't initialize OpenGL, expect problems\n");
334 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
335 str
= (const char *) pglGetString(GL_EXTENSIONS
);
336 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
337 strcpy(WineGLInfo
.glExtensions
, str
);
339 /* Get the common GLX version supported by GLX client and server ( major/minor) */
340 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
342 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
343 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
344 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
346 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
347 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
348 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
350 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
351 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
353 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
354 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
355 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
356 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
357 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
358 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
359 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
360 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
362 if(!WineGLInfo
.glxDirect
)
364 int fd
= ConnectionNumber(gdi_display
);
365 struct sockaddr_un uaddr
;
366 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
368 /* In general indirect rendering on a local X11 server indicates a driver problem.
369 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
371 if(!getsockname(fd
, &uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
372 ERR_(winediag
)("Direct rendering is disabled, most likely your OpenGL drivers haven't been installed correctly\n");
377 pglXMakeCurrent(gdi_display
, None
, NULL
);
378 pglXDestroyContext(gdi_display
, ctx
);
384 void X11DRV_OpenGL_Cleanup(void)
386 HeapFree(GetProcessHeap(), 0, WineGLInfo
.glExtensions
);
387 infoInitialized
= FALSE
;
390 static BOOL
has_opengl(void)
392 static int init_done
;
393 static void *opengl_handle
;
396 int error_base
, event_base
;
398 if (init_done
) return (opengl_handle
!= NULL
);
401 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
402 and include all dependencies */
403 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
404 if (opengl_handle
== NULL
)
406 ERR( "Failed to load libGL: %s\n", buffer
);
407 ERR( "OpenGL support is disabled.\n");
411 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
412 if (pglXGetProcAddressARB
== NULL
) {
413 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
417 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
419 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
424 LOAD_FUNCPTR(glXChooseVisual
);
425 LOAD_FUNCPTR(glXCopyContext
);
426 LOAD_FUNCPTR(glXCreateContext
);
427 LOAD_FUNCPTR(glXCreateGLXPixmap
);
428 LOAD_FUNCPTR(glXGetCurrentContext
);
429 LOAD_FUNCPTR(glXGetCurrentDrawable
);
430 LOAD_FUNCPTR(glXDestroyContext
);
431 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
432 LOAD_FUNCPTR(glXGetConfig
);
433 LOAD_FUNCPTR(glXIsDirect
);
434 LOAD_FUNCPTR(glXMakeCurrent
);
435 LOAD_FUNCPTR(glXSwapBuffers
);
436 LOAD_FUNCPTR(glXQueryExtension
);
437 LOAD_FUNCPTR(glXQueryVersion
);
438 LOAD_FUNCPTR(glXUseXFont
);
441 LOAD_FUNCPTR(glXGetClientString
);
442 LOAD_FUNCPTR(glXQueryExtensionsString
);
443 LOAD_FUNCPTR(glXQueryServerString
);
446 LOAD_FUNCPTR(glXCreatePbuffer
);
447 LOAD_FUNCPTR(glXCreateNewContext
);
448 LOAD_FUNCPTR(glXDestroyPbuffer
);
449 LOAD_FUNCPTR(glXMakeContextCurrent
);
450 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
451 LOAD_FUNCPTR(glXGetFBConfigs
);
453 /* Standard OpenGL calls */
454 LOAD_FUNCPTR(glBindTexture
);
455 LOAD_FUNCPTR(glBitmap
);
456 LOAD_FUNCPTR(glCopyTexSubImage1D
);
457 LOAD_FUNCPTR(glCopyTexImage2D
);
458 LOAD_FUNCPTR(glCopyTexSubImage2D
);
459 LOAD_FUNCPTR(glDrawBuffer
);
460 LOAD_FUNCPTR(glEndList
);
461 LOAD_FUNCPTR(glGetError
);
462 LOAD_FUNCPTR(glGetIntegerv
);
463 LOAD_FUNCPTR(glGetString
);
464 LOAD_FUNCPTR(glNewList
);
465 LOAD_FUNCPTR(glPixelStorei
);
466 LOAD_FUNCPTR(glReadPixels
);
467 LOAD_FUNCPTR(glTexImage2D
);
468 LOAD_FUNCPTR(glFinish
);
469 LOAD_FUNCPTR(glFlush
);
472 /* It doesn't matter if these fail. They'll only be used if the driver reports
473 the associated extension is available (and if a driver reports the extension
474 is available but fails to provide the functions, it's quite broken) */
475 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)
476 /* ARB GLX Extension */
477 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
478 /* NV GLX Extension */
479 LOAD_FUNCPTR(glXAllocateMemoryNV
);
480 LOAD_FUNCPTR(glXFreeMemoryNV
);
483 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
486 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
487 TRACE("GLX is up and running error_base = %d\n", error_base
);
490 ERR( "GLX extension is missing, disabling OpenGL.\n" );
494 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
495 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
498 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
499 * depends on the reported GLX client / server version and on the client / server extension list.
500 * Those don't have to be the same.
502 * In general the server GLX information lists the capabilities in case of indirect rendering.
503 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
504 * available and in that case the client GLX informat can be used.
505 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
506 * in the GLX version/extension list. When a program does this it works for certain for both
507 * direct and indirect rendering.
509 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
510 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
511 * extension list which causes this extension not to be listed. (Wine requires this extension).
512 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
513 * pbuffers is around.
515 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
516 * the ATI drivers and from then on use GLX client information for them.
519 if(glxRequireVersion(3)) {
520 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
521 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
522 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
523 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
524 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
525 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
526 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
527 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
529 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
530 * enable this function when the Xserver understand GLX 1.3 or newer
532 pglXQueryDrawable
= NULL
;
533 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
534 TRACE("Overriding ATI GLX capabilities!\n");
535 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
536 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
537 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
538 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
540 /* Use client GLX information in case of the ATI drivers. We override the
541 * capabilities over here and not somewhere else as ATI might better their
542 * life in the future. In case they release proper drivers this block of
543 * code won't be called. */
544 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
546 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
549 if(glxRequireExtension("GLX_ATI_render_texture")) {
550 use_render_texture_ati
= 1;
551 pglXBindTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
552 pglXReleaseTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
553 pglXDrawableAttribATI
= pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
556 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
557 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
560 X11DRV_WineGL_LoadExtensions();
566 wine_dlclose(opengl_handle
, NULL
, 0);
567 opengl_handle
= NULL
;
571 static inline Wine_GLContext
*alloc_context(void)
575 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
577 ret
->next
= context_list
;
578 if (context_list
) context_list
->prev
= ret
;
584 static inline void free_context(Wine_GLContext
*context
)
586 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
587 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
588 else context_list
= context
->next
;
590 if (context
->vis
) XFree(context
->vis
);
591 HeapFree(GetProcessHeap(), 0, context
);
594 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
597 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
598 return (ptr
!= NULL
);
601 static int describeContext(Wine_GLContext
* ctx
) {
604 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
605 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
606 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
607 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
608 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
613 static BOOL
describeDrawable(X11DRV_PDEVICE
*physDev
) {
615 WineGLPixelFormat
*fmt
;
618 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
/* Offscreen */, &fmt_count
);
619 if(!fmt
) return FALSE
;
621 TRACE(" HDC %p has:\n", physDev
->hdc
);
622 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
623 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev
));
624 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
626 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
627 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
632 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
637 int nvfloatattrib
= GLX_DONT_CARE
;
638 int pixelattrib
= ~0;
640 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
641 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
642 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
643 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
645 switch (iWGLAttr
[cur
]) {
646 case WGL_AUX_BUFFERS_ARB
:
647 pop
= iWGLAttr
[++cur
];
648 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
649 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
651 case WGL_COLOR_BITS_ARB
:
652 pop
= iWGLAttr
[++cur
];
653 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
654 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
656 case WGL_BLUE_BITS_ARB
:
657 pop
= iWGLAttr
[++cur
];
658 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
659 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
661 case WGL_RED_BITS_ARB
:
662 pop
= iWGLAttr
[++cur
];
663 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
664 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
666 case WGL_GREEN_BITS_ARB
:
667 pop
= iWGLAttr
[++cur
];
668 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
669 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
671 case WGL_ALPHA_BITS_ARB
:
672 pop
= iWGLAttr
[++cur
];
673 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
674 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
676 case WGL_DEPTH_BITS_ARB
:
677 pop
= iWGLAttr
[++cur
];
678 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
679 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
681 case WGL_STENCIL_BITS_ARB
:
682 pop
= iWGLAttr
[++cur
];
683 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
684 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
686 case WGL_DOUBLE_BUFFER_ARB
:
687 pop
= iWGLAttr
[++cur
];
688 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
689 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
692 pop
= iWGLAttr
[++cur
];
693 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
694 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
697 case WGL_PIXEL_TYPE_ARB
:
698 pop
= iWGLAttr
[++cur
];
699 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
701 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
702 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
703 /* 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 */
704 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
705 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
707 ERR("unexpected PixelType(%x)\n", pop
);
712 case WGL_SUPPORT_GDI_ARB
:
713 /* This flag is set in a WineGLPixelFormat */
714 pop
= iWGLAttr
[++cur
];
715 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
718 case WGL_DRAW_TO_BITMAP_ARB
:
719 /* This flag is set in a WineGLPixelFormat */
720 pop
= iWGLAttr
[++cur
];
721 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
724 case WGL_DRAW_TO_WINDOW_ARB
:
725 pop
= iWGLAttr
[++cur
];
726 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
727 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
729 drawattrib
|= GLX_WINDOW_BIT
;
733 case WGL_DRAW_TO_PBUFFER_ARB
:
734 pop
= iWGLAttr
[++cur
];
735 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
736 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
738 drawattrib
|= GLX_PBUFFER_BIT
;
742 case WGL_ACCELERATION_ARB
:
743 /* This flag is set in a WineGLPixelFormat */
744 pop
= iWGLAttr
[++cur
];
745 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
748 case WGL_SUPPORT_OPENGL_ARB
:
749 pop
= iWGLAttr
[++cur
];
750 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
751 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
754 case WGL_SWAP_METHOD_ARB
:
755 pop
= iWGLAttr
[++cur
];
756 /* For now we ignore this and just return SWAP_EXCHANGE */
757 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
760 case WGL_PBUFFER_LARGEST_ARB
:
761 pop
= iWGLAttr
[++cur
];
762 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
763 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
766 case WGL_SAMPLE_BUFFERS_ARB
:
767 pop
= iWGLAttr
[++cur
];
768 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
769 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
772 case WGL_SAMPLES_ARB
:
773 pop
= iWGLAttr
[++cur
];
774 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
775 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
778 case WGL_TEXTURE_FORMAT_ARB
:
779 case WGL_TEXTURE_TARGET_ARB
:
780 case WGL_MIPMAP_TEXTURE_ARB
:
781 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
782 pop
= iWGLAttr
[++cur
];
784 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
786 if (use_render_texture_ati
) {
787 /** nothing to do here */
789 else if (!use_render_texture_emulation
) {
790 if (WGL_NO_TEXTURE_ARB
!= pop
) {
791 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
792 return -1; /** error: don't support it */
794 drawattrib
|= GLX_PBUFFER_BIT
;
798 case WGL_FLOAT_COMPONENTS_NV
:
799 nvfloatattrib
= iWGLAttr
[++cur
];
800 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
802 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
803 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
804 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
805 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
806 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
807 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
808 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
809 pop
= iWGLAttr
[++cur
];
810 /** cannot be converted, see direct handling on
811 * - wglGetPixelFormatAttribivARB
812 * TODO: wglChoosePixelFormat
815 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
816 pop
= iWGLAttr
[++cur
];
817 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
818 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
821 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
822 pop
= iWGLAttr
[++cur
];
823 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
824 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
827 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
833 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
834 * all formats. Unless drawattrib is set to a non-zero value override it with ~0, so that pixmap and pbuffer
835 * formats appear as well. */
836 if(!drawattrib
) drawattrib
= ~0;
837 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
838 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
840 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
841 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to ~0 unless
842 * it is overridden. */
843 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
844 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
846 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
847 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
848 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
849 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
855 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
857 int render_type
=0, render_type_bit
;
858 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
859 switch(render_type_bit
)
862 render_type
= GLX_RGBA_TYPE
;
864 case GLX_COLOR_INDEX_BIT
:
865 render_type
= GLX_COLOR_INDEX_TYPE
;
867 case GLX_RGBA_FLOAT_BIT
:
868 render_type
= GLX_RGBA_FLOAT_TYPE
;
870 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
871 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
874 ERR("Unknown render_type: %x\n", render_type
);
879 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
880 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
883 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
884 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
886 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
887 * the GLX_PIXMAP_BIT set. */
888 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
891 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
893 static WineGLPixelFormat
*list
;
894 static int size
, onscreen_size
;
896 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
898 XVisualInfo
*visinfo
;
903 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
904 if (NULL
== cfgs
|| 0 == nCfgs
) {
905 if(cfgs
!= NULL
) XFree(cfgs
);
907 ERR("glXChooseFBConfig returns NULL\n");
911 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
912 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
913 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
914 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
916 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
918 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
920 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
923 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
925 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
927 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
928 * Do this as GLX doesn't guarantee that the list is sorted */
929 for(run
=0; run
< 2; run
++)
931 for(i
=0; i
<nCfgs
; i
++) {
932 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
933 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
935 /* The first run we only add onscreen formats (ones which have an associated X Visual).
936 * The second run we only set offscreen formats. */
939 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
940 * The contents is copied to the destination using XCopyArea. For the copying to work
941 * the depth of the source and destination window should be the same. In general this should
942 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
943 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
944 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
945 * list formats with the same depth. */
946 if(visinfo
->depth
!= screen_depth
)
952 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
953 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
954 list
[size
].fbconfig
= cfgs
[i
];
955 list
[size
].fmt_id
= fmt_id
;
956 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
957 list
[size
].offscreenOnly
= FALSE
;
958 list
[size
].dwFlags
= 0;
962 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
963 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
965 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
966 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
967 list
[size
].fbconfig
= cfgs
[i
];
968 list
[size
].fmt_id
= fmt_id
;
969 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
970 list
[size
].offscreenOnly
= FALSE
;
971 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
975 } else if(run
&& !visinfo
) {
976 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
977 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
978 list
[size
].fbconfig
= cfgs
[i
];
979 list
[size
].fmt_id
= fmt_id
;
980 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
981 list
[size
].offscreenOnly
= TRUE
;
982 list
[size
].dwFlags
= 0;
986 if (visinfo
) XFree(visinfo
);
990 if(cfgs
!= NULL
) XFree(cfgs
);
993 if (size_ret
) *size_ret
= size
;
994 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
999 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1000 * In our WGL implementation we only support a subset of these formats namely the format of
1001 * Wine's main visual and offscreen formats (if they are available).
1002 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1003 * and it returns the number of supported WGL formats in fmt_count.
1005 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
1007 WineGLPixelFormat
*list
, *res
= NULL
;
1008 int size
, onscreen_size
;
1010 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
1012 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1013 * iPixelFormat in case of probing the number of pixelformats.
1015 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
1016 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
1017 res
= &list
[iPixelFormat
-1];
1018 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
1024 *fmt_count
= onscreen_size
;
1026 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1031 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1032 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1034 WineGLPixelFormat
*list
;
1037 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1039 for(i
=0; i
<size
; i
++) {
1040 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1041 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1042 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1043 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1047 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1051 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1053 WineGLPixelFormat
*fmt
;
1055 if (!fbconfig_id
) return 0;
1057 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1059 return fmt
->iPixelFormat
;
1060 /* This will happen on hwnds without a pixel format set; it's ok */
1065 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1066 void mark_drawable_dirty(Drawable old
, Drawable
new)
1068 Wine_GLContext
*ctx
;
1069 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
1070 if (old
== ctx
->drawables
[0]) {
1071 ctx
->drawables
[0] = new;
1072 ctx
->refresh_drawables
= TRUE
;
1074 if (old
== ctx
->drawables
[1]) {
1075 ctx
->drawables
[1] = new;
1076 ctx
->refresh_drawables
= TRUE
;
1081 /* Given the current context, make sure its drawable is sync'd */
1082 static inline void sync_context(Wine_GLContext
*context
)
1084 if(context
&& context
->refresh_drawables
) {
1085 if (glxRequireVersion(3))
1086 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1087 context
->drawables
[1], context
->ctx
);
1089 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1090 context
->refresh_drawables
= FALSE
;
1095 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1099 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1100 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1102 if(context
->gl3_context
)
1104 if(context
->numAttribs
)
1105 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1107 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1109 else if(context
->vis
)
1110 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1111 else /* Create a GLX Context for a pbuffer */
1112 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1118 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1120 return pglXCreateGLXPixmap(display
, vis
, parent
);
1124 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1131 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1133 if(vis
->depth
== physDev
->bitmap
->pixmap_depth
)
1134 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1137 wine_tsx11_unlock();
1138 TRACE("return %lx\n", ret
);
1143 * X11DRV_ChoosePixelFormat
1145 * Equivalent to glXChooseVisual.
1147 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
1148 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1149 WineGLPixelFormat
*list
;
1154 int bestFormat
= -1;
1155 int bestDBuffer
= -1;
1156 int bestStereo
= -1;
1160 int bestStencil
= -1;
1163 if (!has_opengl()) return 0;
1165 if (TRACE_ON(wgl
)) {
1166 TRACE("(%p,%p)\n", physDev
, ppfd
);
1168 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1171 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1174 for(i
=0; i
<onscreen_size
; i
++)
1178 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1179 WineGLPixelFormat
*fmt
= &list
[i
];
1182 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1183 if (value
& GLX_RGBA_BIT
)
1184 iPixelType
= PFD_TYPE_RGBA
;
1186 iPixelType
= PFD_TYPE_COLORINDEX
;
1188 if (ppfd
->iPixelType
!= iPixelType
)
1190 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1194 /* Only use bitmap capable for formats for bitmap rendering.
1195 * See get_formats for more info. */
1196 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1198 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1202 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1203 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1204 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1205 if (value
) dwFlags
|= PFD_STEREO
;
1206 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1207 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1208 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1209 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1210 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1212 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1213 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1214 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1215 * formats without the given flag set.
1216 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1217 * has indicated that a format without stereo is returned when stereo is unavailable.
1218 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1219 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1221 * To summarize the following is most likely the correct behavior:
1222 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1223 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1224 * stereo don't care -> it doesn't matter whether we get stereo or not
1226 * In Wine we will treat no-stereo the same way as don't care because it makes
1227 * format selection even more complicated and second drivers with Stereo advertise
1228 * each format twice anyway.
1231 /* Doublebuffer, see the comments above */
1232 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1233 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1234 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1236 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1237 bestStereo
= dwFlags
& PFD_STEREO
;
1241 bestStencil
= stencil
;
1246 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1250 /* Stereo, see the comments above. */
1251 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1252 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1253 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1255 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1256 bestStereo
= dwFlags
& PFD_STEREO
;
1260 bestStencil
= stencil
;
1265 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1269 /* Below we will do a number of checks to select the 'best' pixelformat.
1270 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1271 * The code works by trying to match the most important options as close as possible.
1272 * When a reasonable format is found, we will try to match more options.
1273 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1274 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1275 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1278 if(ppfd
->cColorBits
) {
1279 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1280 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1282 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1283 bestStereo
= dwFlags
& PFD_STEREO
;
1287 bestStencil
= stencil
;
1291 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1292 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1298 if(ppfd
->cAlphaBits
) {
1299 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1300 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1302 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1303 bestStereo
= dwFlags
& PFD_STEREO
;
1307 bestStencil
= stencil
;
1311 } else if(bestAlpha
!= alpha
) {
1312 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1318 if(ppfd
->cDepthBits
) {
1319 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1320 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1322 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1323 bestStereo
= dwFlags
& PFD_STEREO
;
1327 bestStencil
= stencil
;
1331 } else if(bestDepth
!= depth
) {
1332 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1338 if(ppfd
->cStencilBits
) {
1339 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1340 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1342 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1343 bestStereo
= dwFlags
& PFD_STEREO
;
1347 bestStencil
= stencil
;
1351 } else if(bestStencil
!= stencil
) {
1352 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1358 if(ppfd
->cAuxBuffers
) {
1359 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1360 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1362 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1363 bestStereo
= dwFlags
& PFD_STEREO
;
1367 bestStencil
= stencil
;
1371 } else if(bestAux
!= aux
) {
1372 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1378 if(bestFormat
== -1) {
1379 TRACE("No matching mode was found returning 0\n");
1383 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1384 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1387 wine_tsx11_unlock();
1392 * X11DRV_DescribePixelFormat
1394 * Get the pixel-format descriptor associated to the given id
1396 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1399 PIXELFORMATDESCRIPTOR
*ppfd
) {
1400 /*XVisualInfo *vis;*/
1403 WineGLPixelFormat
*fmt
;
1407 if (!has_opengl()) return 0;
1409 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1411 /* 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 */
1412 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1414 /* The application is only querying the number of pixelformats */
1416 } else if(fmt
== NULL
) {
1417 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1421 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1422 ERR("Wrong structure size !\n");
1423 /* Should set error */
1429 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1430 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1433 /* These flags are always the same... */
1434 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1435 /* Now the flags extracted from the Visual */
1439 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1440 if(value
& GLX_WINDOW_BIT
)
1441 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1443 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1444 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1445 * 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
1446 * offered the GDI bit either. */
1447 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1449 /* PFD_GENERIC_FORMAT - gdi software rendering
1450 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1451 * none set - full hardware accelerated by a ICD
1453 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1454 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1456 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1458 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1459 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1461 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1464 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1465 if (value
& GLX_RGBA_BIT
)
1466 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1468 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1471 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1472 ppfd
->cColorBits
= value
;
1474 /* Red, green, blue and alpha bits / shifts */
1475 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1476 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1477 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1478 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1479 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1481 ppfd
->cRedBits
= rb
;
1482 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1483 ppfd
->cBlueBits
= bb
;
1484 ppfd
->cBlueShift
= ab
;
1485 ppfd
->cGreenBits
= gb
;
1486 ppfd
->cGreenShift
= bb
+ ab
;
1487 ppfd
->cAlphaBits
= ab
;
1488 ppfd
->cAlphaShift
= 0;
1491 ppfd
->cRedShift
= 0;
1492 ppfd
->cBlueBits
= 0;
1493 ppfd
->cBlueShift
= 0;
1494 ppfd
->cGreenBits
= 0;
1495 ppfd
->cGreenShift
= 0;
1496 ppfd
->cAlphaBits
= 0;
1497 ppfd
->cAlphaShift
= 0;
1500 /* Accum RGBA bits */
1501 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1502 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1503 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1504 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1506 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1507 ppfd
->cAccumRedBits
= rb
;
1508 ppfd
->cAccumGreenBits
= gb
;
1509 ppfd
->cAccumBlueBits
= bb
;
1510 ppfd
->cAccumAlphaBits
= ab
;
1513 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1514 ppfd
->cAuxBuffers
= value
;
1517 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1518 ppfd
->cDepthBits
= value
;
1521 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1522 ppfd
->cStencilBits
= value
;
1524 wine_tsx11_unlock();
1526 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1528 if (TRACE_ON(wgl
)) {
1529 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1536 * X11DRV_GetPixelFormat
1538 * Get the pixel-format id used by this DC
1540 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1541 WineGLPixelFormat
*fmt
;
1543 TRACE("(%p)\n", physDev
);
1545 if (!physDev
->current_pf
) return 0; /* not set yet */
1547 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1550 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1553 else if(fmt
->offscreenOnly
)
1555 /* Offscreen formats can't be used with traditional WGL calls.
1556 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1557 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1561 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1562 return physDev
->current_pf
;
1565 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1566 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1567 * set the pixel format multiple times. */
1568 static BOOL
internal_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1570 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1571 WineGLPixelFormat
*fmt
;
1575 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1576 if(get_glxdrawable(physDev
) == root_window
)
1578 ERR("Invalid operation on root_window\n");
1582 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1583 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1585 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1590 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1591 wine_tsx11_unlock();
1593 hwnd
= WindowFromDC(physDev
->hdc
);
1595 if(!(value
&GLX_WINDOW_BIT
)) {
1596 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1600 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, (WPARAM
)fmt
->fmt_id
, 0)) {
1601 ERR("Couldn't set format of the window, returning failure\n");
1605 else if(physDev
->bitmap
) {
1606 if(!(value
&GLX_PIXMAP_BIT
)) {
1607 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1611 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
, fmt
);
1612 if(!physDev
->bitmap
->glxpixmap
) {
1613 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1618 FIXME("called on a non-window, non-bitmap object?\n");
1621 physDev
->current_pf
= iPixelFormat
;
1623 if (TRACE_ON(wgl
)) {
1627 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1629 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1631 TRACE(" FBConfig have :\n");
1632 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1633 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1634 TRACE(" - VISUAL_ID 0x%x\n", value
);
1635 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1636 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1638 wine_tsx11_unlock();
1645 * X11DRV_SetPixelFormat
1647 * Set the pixel-format id used by this DC
1649 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1651 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1652 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1654 if (!has_opengl()) return FALSE
;
1656 if(physDev
->current_pf
) /* cannot change it if already set */
1657 return (physDev
->current_pf
== iPixelFormat
);
1659 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
1663 * X11DRV_wglCopyContext
1665 * For OpenGL32 wglCopyContext.
1667 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
1668 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1669 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1671 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1674 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1675 wine_tsx11_unlock();
1677 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1682 * X11DRV_wglCreateContext
1684 * For OpenGL32 wglCreateContext.
1686 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1688 Wine_GLContext
*ret
;
1689 WineGLPixelFormat
*fmt
;
1690 int hdcPF
= physDev
->current_pf
;
1692 HDC hdc
= physDev
->hdc
;
1694 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1696 if (!has_opengl()) return 0;
1698 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1699 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1700 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1701 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1702 * If this fails something is very wrong on the system. */
1704 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1705 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1710 ret
= alloc_context();
1713 ret
->has_been_current
= FALSE
;
1714 ret
->sharing
= FALSE
;
1716 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1717 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1718 wine_tsx11_unlock();
1720 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1725 * X11DRV_wglDeleteContext
1727 * For OpenGL32 wglDeleteContext.
1729 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1731 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1734 TRACE("(%p)\n", hglrc
);
1736 if (!has_opengl()) return 0;
1739 /* A game (Half Life not to name it) deletes twice the same context,
1740 * so make sure it is valid first */
1741 if (is_valid_context( ctx
))
1743 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1748 WARN("Error deleting context !\n");
1749 SetLastError(ERROR_INVALID_HANDLE
);
1752 wine_tsx11_unlock();
1758 * X11DRV_wglGetCurrentReadDCARB
1760 * For OpenGL32 wglGetCurrentReadDCARB.
1762 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1765 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1767 if (ctx
) ret
= ctx
->read_hdc
;
1769 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1774 * X11DRV_wglGetProcAddress
1776 * For OpenGL32 wglGetProcAddress.
1778 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1781 const WineGLExtension
*ext
;
1783 int padding
= 32 - strlen(lpszProc
);
1787 if (!has_opengl()) return NULL
;
1789 /* Check the table of WGL extensions to see if we need to return a WGL extension
1790 * or a function pointer to a native OpenGL function. */
1791 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1792 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1794 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1795 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1796 ext
= WineGLExtensionList
[i
];
1797 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1798 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1799 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1800 return ext
->extEntryPoints
[j
].funcAddress
;
1806 WARN("(%s) - not found\n", lpszProc
);
1811 * X11DRV_wglMakeCurrent
1813 * For OpenGL32 wglMakeCurrent.
1815 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1817 HDC hdc
= physDev
->hdc
;
1818 DWORD type
= GetObjectType(hdc
);
1819 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1821 TRACE("(%p,%p)\n", hdc
, hglrc
);
1823 if (!has_opengl()) return FALSE
;
1826 if (hglrc
== NULL
) {
1827 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1828 NtCurrentTeb()->glContext
= NULL
;
1829 } else if (ctx
->fmt
->iPixelFormat
!= physDev
->current_pf
) {
1830 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1831 hdc
, physDev
->current_pf
, ctx
, ctx
->fmt
->iPixelFormat
);
1832 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1835 Drawable drawable
= get_glxdrawable(physDev
);
1837 /* The describe lines below are for debugging purposes only */
1838 if (TRACE_ON(wgl
)) {
1839 describeDrawable(physDev
);
1840 describeContext(ctx
);
1843 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1844 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1845 NtCurrentTeb()->glContext
= ctx
;
1849 ctx
->has_been_current
= TRUE
;
1851 ctx
->read_hdc
= hdc
;
1852 ctx
->drawables
[0] = drawable
;
1853 ctx
->drawables
[1] = drawable
;
1854 ctx
->refresh_drawables
= FALSE
;
1856 if (type
== OBJ_MEMDC
)
1858 ctx
->do_escape
= TRUE
;
1859 pglDrawBuffer(GL_FRONT_LEFT
);
1863 wine_tsx11_unlock();
1864 TRACE(" returning %s\n", (ret
? "True" : "False"));
1869 * X11DRV_wglMakeContextCurrentARB
1871 * For OpenGL32 wglMakeContextCurrentARB
1873 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1877 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1879 if (!has_opengl()) return 0;
1882 if (hglrc
== NULL
) {
1883 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1884 NtCurrentTeb()->glContext
= NULL
;
1886 if (NULL
== pglXMakeContextCurrent
) {
1889 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1890 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1891 Drawable d_read
= get_glxdrawable(pReadDev
);
1893 ctx
->has_been_current
= TRUE
;
1894 ctx
->hdc
= pDrawDev
->hdc
;
1895 ctx
->read_hdc
= pReadDev
->hdc
;
1896 ctx
->drawables
[0] = d_draw
;
1897 ctx
->drawables
[1] = d_read
;
1898 ctx
->refresh_drawables
= FALSE
;
1899 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1900 NtCurrentTeb()->glContext
= ctx
;
1903 wine_tsx11_unlock();
1905 TRACE(" returning %s\n", (ret
? "True" : "False"));
1910 * X11DRV_wglShareLists
1912 * For OpenGL32 wglShareLists.
1914 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1915 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1916 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1918 TRACE("(%p, %p)\n", org
, dest
);
1920 if (!has_opengl()) return FALSE
;
1922 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1923 * at context creation time but in case of WGL it is done using wglShareLists.
1924 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1925 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1926 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1927 * so there delaying context creation doesn't work.
1929 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1930 * and when a program requests sharing we recreate the destination context if it hasn't been made
1931 * current or when it hasn't shared display lists before.
1934 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
1936 ERR("Could not share display lists, one of the contexts has been current already !\n");
1939 else if(dest
->sharing
)
1941 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1946 if((GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
))
1948 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1952 describeContext(org
);
1953 describeContext(dest
);
1955 /* Re-create the GLX context and share display lists */
1956 pglXDestroyContext(gdi_display
, dest
->ctx
);
1957 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1958 wine_tsx11_unlock();
1959 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1961 org
->sharing
= TRUE
;
1962 dest
->sharing
= TRUE
;
1968 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1970 /* We are running using client-side rendering fonts... */
1972 unsigned int glyph
, size
= 0;
1973 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1977 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1978 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1979 wine_tsx11_unlock();
1981 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1982 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
1983 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
1984 unsigned int height
, width_int
;
1986 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1987 if (needed_size
== GDI_ERROR
) {
1988 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1991 TRACE(" - needed size : %d\n", needed_size
);
1994 if (needed_size
> size
) {
1996 HeapFree(GetProcessHeap(), 0, bitmap
);
1997 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1998 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1999 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2001 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
2003 if (TRACE_ON(wgl
)) {
2004 unsigned int height
, width
, bitmask
;
2005 unsigned char *bitmap_
= bitmap
;
2007 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
2008 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2009 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
2010 if (needed_size
!= 0) {
2011 TRACE(" - bitmap :\n");
2012 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2014 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
2019 if (*bitmap_
& bitmask
)
2024 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2030 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2031 * glyph for it to be drawn properly.
2033 if (needed_size
!= 0) {
2034 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2035 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2037 for (width
= 0; width
< width_int
; width
++) {
2038 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2039 ((int *) bitmap
)[height
* width_int
+ width
];
2045 pglNewList(listBase
++, GL_COMPILE
);
2046 if (needed_size
!= 0) {
2047 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2048 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2049 gm
.gmCellIncX
, gm
.gmCellIncY
,
2052 /* This is the case of 'empty' glyphs like the space character */
2053 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2056 wine_tsx11_unlock();
2060 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2061 wine_tsx11_unlock();
2063 HeapFree(GetProcessHeap(), 0, bitmap
);
2064 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2069 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2070 wine_tsx11_unlock();
2072 HeapFree(GetProcessHeap(), 0, bitmap
);
2073 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2078 * X11DRV_wglUseFontBitmapsA
2080 * For OpenGL32 wglUseFontBitmapsA.
2082 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2084 Font fid
= physDev
->font
;
2086 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2088 if (!has_opengl()) return FALSE
;
2091 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2095 /* I assume that the glyphs are at the same position for X and for Windows */
2096 pglXUseXFont(fid
, first
, count
, listBase
);
2097 wine_tsx11_unlock();
2102 * X11DRV_wglUseFontBitmapsW
2104 * For OpenGL32 wglUseFontBitmapsW.
2106 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2108 Font fid
= physDev
->font
;
2110 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2112 if (!has_opengl()) return FALSE
;
2115 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2118 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2121 /* I assume that the glyphs are at the same position for X and for Windows */
2122 pglXUseXFont(fid
, first
, count
, listBase
);
2123 wine_tsx11_unlock();
2127 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2128 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2135 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2137 pglGetIntegerv(pname
, params
);
2139 * if we cannot find a Wine Context
2140 * we only have the default wine desktop context,
2141 * so if we have only a 24 depth say we have 32
2143 if (!ctx
&& *params
== 24) {
2146 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2151 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2153 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2154 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2158 pglGetIntegerv(pname
, params
);
2161 wine_tsx11_unlock();
2164 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
2168 if (!physDev
->gl_copy
)
2171 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
2172 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
2174 if(w
> 0 && h
> 0) {
2175 Drawable src
= physDev
->pixmap
;
2176 if(!src
) src
= physDev
->gl_drawable
;
2178 /* The GL drawable may be lagged behind if we don't flush first, so
2179 * flush the display make sure we copy up-to-date data */
2181 XFlush(gdi_display
);
2182 XSetFunction(gdi_display
, physDev
->gc
, GXcopy
);
2183 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
2184 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
2185 wine_tsx11_unlock();
2190 static void WINAPI
X11DRV_wglFinish(void)
2192 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2193 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2198 wine_tsx11_unlock();
2199 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2202 static void WINAPI
X11DRV_wglFlush(void)
2204 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2205 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2210 wine_tsx11_unlock();
2211 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2215 * X11DRV_wglCreateContextAttribsARB
2217 * WGL_ARB_create_context: wglCreateContextAttribsARB
2219 HGLRC
X11DRV_wglCreateContextAttribsARB(X11DRV_PDEVICE
*physDev
, HGLRC hShareContext
, const int* attribList
)
2221 Wine_GLContext
*ret
;
2222 WineGLPixelFormat
*fmt
;
2223 int hdcPF
= physDev
->current_pf
;
2226 TRACE("(%p %p %p)\n", physDev
, hShareContext
, attribList
);
2228 if (!has_opengl()) return 0;
2230 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
2231 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2232 * If this fails something is very wrong on the system. */
2235 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
2236 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2241 ret
= alloc_context();
2242 wine_tsx11_unlock();
2243 ret
->hdc
= physDev
->hdc
;
2245 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2246 ret
->gl3_context
= TRUE
;
2248 ret
->numAttribs
= 0;
2251 int *pAttribList
= (int*)attribList
;
2252 int *pContextAttribList
= &ret
->attribList
[0];
2253 /* attribList consists of pairs {token, value] terminated with 0 */
2254 while(pAttribList
[0] != 0)
2256 TRACE("%#x %#x\n", pAttribList
[0], pAttribList
[1]);
2257 switch(pAttribList
[0])
2259 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2260 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2261 pContextAttribList
[1] = pAttribList
[1];
2263 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2264 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2265 pContextAttribList
[1] = pAttribList
[1];
2267 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2269 case WGL_CONTEXT_FLAGS_ARB
:
2270 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2271 pContextAttribList
[1] = pAttribList
[1];
2273 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2274 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2275 pContextAttribList
[1] = pAttribList
[1];
2278 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList
[0], pAttribList
[1]);
2283 pContextAttribList
+= 2;
2288 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2289 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
2291 XSync(gdi_display
, False
);
2292 if(X11DRV_check_error() || !ret
->ctx
)
2294 /* In the future we should convert the GLX error to a win32 one here if needed */
2295 ERR("Context creation failed\n");
2297 wine_tsx11_unlock();
2301 wine_tsx11_unlock();
2302 TRACE(" creating context %p\n", ret
);
2307 * X11DRV_wglGetExtensionsStringARB
2309 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2311 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2312 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2313 return WineGLInfo
.wglExtensions
;
2317 * X11DRV_wglCreatePbufferARB
2319 * WGL_ARB_pbuffer: wglCreatePbufferARB
2321 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2323 Wine_GLPBuffer
* object
= NULL
;
2324 WineGLPixelFormat
*fmt
= NULL
;
2329 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2331 if (0 >= iPixelFormat
) {
2332 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2333 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2334 return NULL
; /* unexpected error */
2337 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2338 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2340 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2341 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2342 goto create_failed
; /* unexpected error */
2345 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2346 if (NULL
== object
) {
2347 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2348 goto create_failed
; /* unexpected error */
2351 object
->display
= gdi_display
;
2352 object
->width
= iWidth
;
2353 object
->height
= iHeight
;
2356 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2357 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2358 while (piAttribList
&& 0 != *piAttribList
) {
2360 switch (*piAttribList
) {
2361 case WGL_PBUFFER_LARGEST_ARB
: {
2363 attr_v
= *piAttribList
;
2364 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2365 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2369 case WGL_TEXTURE_FORMAT_ARB
: {
2371 attr_v
= *piAttribList
;
2372 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2373 if (use_render_texture_ati
) {
2376 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2377 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2378 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2380 SetLastError(ERROR_INVALID_DATA
);
2383 object
->use_render_texture
= 1;
2384 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2386 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2387 object
->use_render_texture
= 0;
2389 if (!use_render_texture_emulation
) {
2390 SetLastError(ERROR_INVALID_DATA
);
2394 case WGL_TEXTURE_RGB_ARB
:
2395 object
->use_render_texture
= GL_RGB
;
2396 object
->texture_bpp
= 3;
2397 object
->texture_format
= GL_RGB
;
2398 object
->texture_type
= GL_UNSIGNED_BYTE
;
2400 case WGL_TEXTURE_RGBA_ARB
:
2401 object
->use_render_texture
= GL_RGBA
;
2402 object
->texture_bpp
= 4;
2403 object
->texture_format
= GL_RGBA
;
2404 object
->texture_type
= GL_UNSIGNED_BYTE
;
2407 /* WGL_FLOAT_COMPONENTS_NV */
2408 case WGL_TEXTURE_FLOAT_R_NV
:
2409 object
->use_render_texture
= GL_FLOAT_R_NV
;
2410 object
->texture_bpp
= 4;
2411 object
->texture_format
= GL_RED
;
2412 object
->texture_type
= GL_FLOAT
;
2414 case WGL_TEXTURE_FLOAT_RG_NV
:
2415 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2416 object
->texture_bpp
= 8;
2417 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2418 object
->texture_type
= GL_FLOAT
;
2420 case WGL_TEXTURE_FLOAT_RGB_NV
:
2421 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2422 object
->texture_bpp
= 12;
2423 object
->texture_format
= GL_RGB
;
2424 object
->texture_type
= GL_FLOAT
;
2426 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2427 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2428 object
->texture_bpp
= 16;
2429 object
->texture_format
= GL_RGBA
;
2430 object
->texture_type
= GL_FLOAT
;
2433 ERR("Unknown texture format: %x\n", attr_v
);
2434 SetLastError(ERROR_INVALID_DATA
);
2442 case WGL_TEXTURE_TARGET_ARB
: {
2444 attr_v
= *piAttribList
;
2445 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2446 if (use_render_texture_ati
) {
2449 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2450 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2451 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2452 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2454 SetLastError(ERROR_INVALID_DATA
);
2457 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2459 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2460 object
->texture_target
= 0;
2462 if (!use_render_texture_emulation
) {
2463 SetLastError(ERROR_INVALID_DATA
);
2467 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2468 if (iWidth
!= iHeight
) {
2469 SetLastError(ERROR_INVALID_DATA
);
2472 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2473 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2476 case WGL_TEXTURE_1D_ARB
: {
2478 SetLastError(ERROR_INVALID_DATA
);
2481 object
->texture_target
= GL_TEXTURE_1D
;
2482 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2485 case WGL_TEXTURE_2D_ARB
: {
2486 object
->texture_target
= GL_TEXTURE_2D
;
2487 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2490 case WGL_TEXTURE_RECTANGLE_NV
: {
2491 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2492 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2496 ERR("Unknown texture target: %x\n", attr_v
);
2497 SetLastError(ERROR_INVALID_DATA
);
2505 case WGL_MIPMAP_TEXTURE_ARB
: {
2507 attr_v
= *piAttribList
;
2508 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2509 if (use_render_texture_ati
) {
2510 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2512 if (!use_render_texture_emulation
) {
2513 SetLastError(ERROR_INVALID_DATA
);
2523 PUSH1(attribs
, None
);
2525 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2526 wine_tsx11_unlock();
2527 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2528 if (!object
->drawable
) {
2529 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2530 goto create_failed
; /* unexpected error */
2532 TRACE("->(%p)\n", object
);
2536 HeapFree(GetProcessHeap(), 0, object
);
2537 TRACE("->(FAILED)\n");
2542 * X11DRV_wglDestroyPbufferARB
2544 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2546 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2548 Wine_GLPBuffer
* object
= hPbuffer
;
2549 TRACE("(%p)\n", hPbuffer
);
2550 if (NULL
== object
) {
2551 SetLastError(ERROR_INVALID_HANDLE
);
2555 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2556 wine_tsx11_unlock();
2557 HeapFree(GetProcessHeap(), 0, object
);
2562 * X11DRV_wglGetPbufferDCARB
2564 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2565 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2566 * Gdi32 implements the part of this function which creates a device context.
2567 * This part associates the physDev with the X drawable of the pbuffer.
2569 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2571 Wine_GLPBuffer
* object
= hPbuffer
;
2572 if (NULL
== object
) {
2573 SetLastError(ERROR_INVALID_HANDLE
);
2577 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2578 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2579 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2580 physDev
->drawable
= object
->drawable
;
2581 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2582 physDev
->dc_rect
= physDev
->drawable_rect
;
2584 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2585 return physDev
->hdc
;
2589 * X11DRV_wglQueryPbufferARB
2591 * WGL_ARB_pbuffer: wglQueryPbufferARB
2593 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2595 Wine_GLPBuffer
* object
= hPbuffer
;
2596 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2597 if (NULL
== object
) {
2598 SetLastError(ERROR_INVALID_HANDLE
);
2601 switch (iAttribute
) {
2602 case WGL_PBUFFER_WIDTH_ARB
:
2604 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2605 wine_tsx11_unlock();
2607 case WGL_PBUFFER_HEIGHT_ARB
:
2609 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2610 wine_tsx11_unlock();
2613 case WGL_PBUFFER_LOST_ARB
:
2614 /* GLX Pbuffers cannot be lost by default. We can support this by
2615 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2616 * to receive pixel buffer clobber events, however that may or may
2617 * not give any benefit */
2618 *piValue
= GL_FALSE
;
2621 case WGL_TEXTURE_FORMAT_ARB
:
2622 if (use_render_texture_ati
) {
2624 int type
= WGL_NO_TEXTURE_ARB
;
2626 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2627 wine_tsx11_unlock();
2629 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2630 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2631 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2635 if (!object
->use_render_texture
) {
2636 *piValue
= WGL_NO_TEXTURE_ARB
;
2638 if (!use_render_texture_emulation
) {
2639 SetLastError(ERROR_INVALID_HANDLE
);
2642 switch(object
->use_render_texture
) {
2644 *piValue
= WGL_TEXTURE_RGB_ARB
;
2647 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2649 /* WGL_FLOAT_COMPONENTS_NV */
2651 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2653 case GL_FLOAT_RG_NV
:
2654 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2656 case GL_FLOAT_RGB_NV
:
2657 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2659 case GL_FLOAT_RGBA_NV
:
2660 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2663 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2669 case WGL_TEXTURE_TARGET_ARB
:
2670 if (use_render_texture_ati
) {
2672 int type
= WGL_NO_TEXTURE_ARB
;
2674 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2675 wine_tsx11_unlock();
2677 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2678 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2679 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2680 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2684 if (!object
->texture_target
) {
2685 *piValue
= WGL_NO_TEXTURE_ARB
;
2687 if (!use_render_texture_emulation
) {
2688 SetLastError(ERROR_INVALID_DATA
);
2691 switch (object
->texture_target
) {
2692 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2693 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2694 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2695 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2701 case WGL_MIPMAP_TEXTURE_ARB
:
2702 if (use_render_texture_ati
) {
2704 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2705 wine_tsx11_unlock();
2707 *piValue
= GL_FALSE
; /** don't support that */
2708 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2713 FIXME("unexpected attribute %x\n", iAttribute
);
2721 * X11DRV_wglReleasePbufferDCARB
2723 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2725 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2727 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2728 return DeleteDC(hdc
);
2732 * X11DRV_wglSetPbufferAttribARB
2734 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2736 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2738 Wine_GLPBuffer
* object
= hPbuffer
;
2739 GLboolean ret
= GL_FALSE
;
2741 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2742 if (NULL
== object
) {
2743 SetLastError(ERROR_INVALID_HANDLE
);
2746 if (!object
->use_render_texture
) {
2747 SetLastError(ERROR_INVALID_HANDLE
);
2750 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2753 if (NULL
!= pglXDrawableAttribATI
) {
2754 if (use_render_texture_ati
) {
2755 FIXME("Need conversion for GLX_ATI_render_texture\n");
2758 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2759 wine_tsx11_unlock();
2765 * X11DRV_wglChoosePixelFormatARB
2767 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2769 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2774 GLXFBConfig
* cfgs
= NULL
;
2778 WineGLPixelFormat
*fmt
;
2784 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2785 if (NULL
!= pfAttribFList
) {
2786 FIXME("unused pfAttribFList\n");
2789 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2790 if (-1 == nAttribs
) {
2791 WARN("Cannot convert WGL to GLX attributes\n");
2794 PUSH1(attribs
, None
);
2796 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2797 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2798 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2799 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2801 switch(piAttribIList
[i
])
2803 case WGL_DRAW_TO_BITMAP_ARB
:
2804 if(piAttribIList
[i
+1])
2805 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2807 case WGL_ACCELERATION_ARB
:
2808 switch(piAttribIList
[i
+1])
2810 case WGL_NO_ACCELERATION_ARB
:
2811 dwFlags
|= PFD_GENERIC_FORMAT
;
2813 case WGL_GENERIC_ACCELERATION_ARB
:
2814 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2816 case WGL_FULL_ACCELERATION_ARB
:
2821 case WGL_SUPPORT_GDI_ARB
:
2822 if(piAttribIList
[i
+1])
2823 dwFlags
|= PFD_SUPPORT_GDI
;
2828 /* Search for FB configurations matching the requirements in attribs */
2830 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2832 wine_tsx11_unlock();
2833 WARN("Compatible Pixel Format not found\n");
2837 /* Loop through all matching formats and check if they are suitable.
2838 * Note that this function should at max return nMaxFormats different formats */
2839 for(run
=0; run
< 2; run
++)
2841 for (it
= 0; it
< nCfgs
; ++it
) {
2842 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2844 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2848 /* Search for the format in our list of compatible formats */
2849 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2853 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2854 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2857 if(pfmt_it
< nMaxFormats
) {
2858 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2859 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2865 *nNumFormats
= pfmt_it
;
2868 wine_tsx11_unlock();
2873 * X11DRV_wglGetPixelFormatAttribivARB
2875 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2877 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2880 WineGLPixelFormat
*fmt
= NULL
;
2884 int nWGLFormats
= 0;
2886 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2888 if (0 < iLayerPlane
) {
2889 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2893 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2894 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2895 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2896 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2898 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2902 for (i
= 0; i
< nAttributes
; ++i
) {
2903 const int curWGLAttr
= piAttributes
[i
];
2904 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2906 switch (curWGLAttr
) {
2907 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2908 piValues
[i
] = nWGLFormats
;
2911 case WGL_SUPPORT_OPENGL_ARB
:
2912 piValues
[i
] = GL_TRUE
;
2915 case WGL_ACCELERATION_ARB
:
2916 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2917 if (!fmt
) goto pix_error
;
2918 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2919 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2920 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2921 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2923 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2926 case WGL_TRANSPARENT_ARB
:
2927 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2928 if (!fmt
) goto pix_error
;
2929 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2930 if (hTest
) goto get_error
;
2931 piValues
[i
] = GL_FALSE
;
2932 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2935 case WGL_PIXEL_TYPE_ARB
:
2936 curGLXAttr
= GLX_RENDER_TYPE
;
2937 if (!fmt
) goto pix_error
;
2938 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2939 if (hTest
) goto get_error
;
2940 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2941 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2942 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2943 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2944 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2945 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2947 ERR("unexpected RenderType(%x)\n", tmp
);
2948 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2952 case WGL_COLOR_BITS_ARB
:
2953 curGLXAttr
= GLX_BUFFER_SIZE
;
2956 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2957 if (use_render_texture_ati
) {
2958 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2961 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2962 if (use_render_texture_ati
) {
2963 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2966 if (!use_render_texture_emulation
) {
2967 piValues
[i
] = GL_FALSE
;
2970 curGLXAttr
= GLX_RENDER_TYPE
;
2971 if (!fmt
) goto pix_error
;
2972 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2973 if (hTest
) goto get_error
;
2974 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2975 piValues
[i
] = GL_FALSE
;
2978 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2979 if (hTest
) goto get_error
;
2980 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2983 case WGL_BLUE_BITS_ARB
:
2984 curGLXAttr
= GLX_BLUE_SIZE
;
2986 case WGL_RED_BITS_ARB
:
2987 curGLXAttr
= GLX_RED_SIZE
;
2989 case WGL_GREEN_BITS_ARB
:
2990 curGLXAttr
= GLX_GREEN_SIZE
;
2992 case WGL_ALPHA_BITS_ARB
:
2993 curGLXAttr
= GLX_ALPHA_SIZE
;
2995 case WGL_DEPTH_BITS_ARB
:
2996 curGLXAttr
= GLX_DEPTH_SIZE
;
2998 case WGL_STENCIL_BITS_ARB
:
2999 curGLXAttr
= GLX_STENCIL_SIZE
;
3001 case WGL_DOUBLE_BUFFER_ARB
:
3002 curGLXAttr
= GLX_DOUBLEBUFFER
;
3004 case WGL_STEREO_ARB
:
3005 curGLXAttr
= GLX_STEREO
;
3007 case WGL_AUX_BUFFERS_ARB
:
3008 curGLXAttr
= GLX_AUX_BUFFERS
;
3011 case WGL_SUPPORT_GDI_ARB
:
3012 if (!fmt
) goto pix_error
;
3013 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
3016 case WGL_DRAW_TO_BITMAP_ARB
:
3017 if (!fmt
) goto pix_error
;
3018 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
3021 case WGL_DRAW_TO_WINDOW_ARB
:
3022 case WGL_DRAW_TO_PBUFFER_ARB
:
3023 if (!fmt
) goto pix_error
;
3024 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3025 if (hTest
) goto get_error
;
3026 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
3027 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
3028 piValues
[i
] = GL_TRUE
;
3030 piValues
[i
] = GL_FALSE
;
3033 case WGL_SWAP_METHOD_ARB
:
3034 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3035 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3036 * point only ATI offers this.
3038 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
3041 case WGL_PBUFFER_LARGEST_ARB
:
3042 curGLXAttr
= GLX_LARGEST_PBUFFER
;
3045 case WGL_SAMPLE_BUFFERS_ARB
:
3046 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
3049 case WGL_SAMPLES_ARB
:
3050 curGLXAttr
= GLX_SAMPLES_ARB
;
3053 case WGL_FLOAT_COMPONENTS_NV
:
3054 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
3057 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
3058 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
3061 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
3062 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
3065 case WGL_ACCUM_RED_BITS_ARB
:
3066 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
3068 case WGL_ACCUM_GREEN_BITS_ARB
:
3069 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
3071 case WGL_ACCUM_BLUE_BITS_ARB
:
3072 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
3074 case WGL_ACCUM_ALPHA_BITS_ARB
:
3075 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
3077 case WGL_ACCUM_BITS_ARB
:
3078 if (!fmt
) goto pix_error
;
3079 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
3080 if (hTest
) goto get_error
;
3082 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
3083 if (hTest
) goto get_error
;
3085 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
3086 if (hTest
) goto get_error
;
3088 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
3089 if (hTest
) goto get_error
;
3094 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
3097 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3098 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3099 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3101 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3102 * and check which options can work using iPixelFormat=0 and which not.
3103 * A problem would be that this function is an extension. This would
3104 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3106 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
3107 if (!fmt
) goto pix_error
;
3108 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
3109 if (hTest
) goto get_error
;
3112 piValues
[i
] = GL_FALSE
;
3115 wine_tsx11_unlock();
3119 wine_tsx11_unlock();
3120 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3124 wine_tsx11_unlock();
3125 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3130 * X11DRV_wglGetPixelFormatAttribfvARB
3132 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3134 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3140 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3142 /* Allocate a temporary array to store integer values */
3143 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3145 ERR("couldn't allocate %d array\n", nAttributes
);
3149 /* Piggy-back on wglGetPixelFormatAttribivARB */
3150 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3152 /* Convert integer values to float. Should also check for attributes
3153 that can give decimal values here */
3154 for (i
=0; i
<nAttributes
;i
++) {
3155 pfValues
[i
] = attr
[i
];
3159 HeapFree(GetProcessHeap(), 0, attr
);
3164 * X11DRV_wglBindTexImageARB
3166 * WGL_ARB_render_texture: wglBindTexImageARB
3168 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3170 Wine_GLPBuffer
* object
= hPbuffer
;
3171 GLboolean ret
= GL_FALSE
;
3173 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3174 if (NULL
== object
) {
3175 SetLastError(ERROR_INVALID_HANDLE
);
3178 if (!object
->use_render_texture
) {
3179 SetLastError(ERROR_INVALID_HANDLE
);
3183 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3184 static int init
= 0;
3185 int prev_binded_texture
= 0;
3186 GLXContext prev_context
;
3187 Drawable prev_drawable
;
3188 GLXContext tmp_context
;
3191 prev_context
= pglXGetCurrentContext();
3192 prev_drawable
= pglXGetCurrentDrawable();
3194 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3195 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3196 isn't ideal performance wise but I wasn't able to get other ways working.
3199 init
= 1; /* Only show the FIXME once for performance reasons */
3200 FIXME("partial stub!\n");
3203 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
3204 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3206 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3208 /* Switch to our pbuffer */
3209 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3211 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3212 * After that upload the pbuffer texture data. */
3213 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3214 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3216 /* Switch back to the original drawable and upload the pbuffer-texture */
3217 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3218 pglXDestroyContext(gdi_display
, tmp_context
);
3219 wine_tsx11_unlock();
3223 if (NULL
!= pglXBindTexImageATI
) {
3228 case WGL_FRONT_LEFT_ARB
:
3229 buffer
= GLX_FRONT_LEFT_ATI
;
3231 case WGL_FRONT_RIGHT_ARB
:
3232 buffer
= GLX_FRONT_RIGHT_ATI
;
3234 case WGL_BACK_LEFT_ARB
:
3235 buffer
= GLX_BACK_LEFT_ATI
;
3237 case WGL_BACK_RIGHT_ARB
:
3238 buffer
= GLX_BACK_RIGHT_ATI
;
3241 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3245 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3246 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3247 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3248 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3249 * works fine using our pbuffer emulation path.
3252 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3253 wine_tsx11_unlock();
3259 * X11DRV_wglReleaseTexImageARB
3261 * WGL_ARB_render_texture: wglReleaseTexImageARB
3263 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3265 Wine_GLPBuffer
* object
= hPbuffer
;
3266 GLboolean ret
= GL_FALSE
;
3268 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3269 if (NULL
== object
) {
3270 SetLastError(ERROR_INVALID_HANDLE
);
3273 if (!object
->use_render_texture
) {
3274 SetLastError(ERROR_INVALID_HANDLE
);
3277 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3280 if (NULL
!= pglXReleaseTexImageATI
) {
3285 case WGL_FRONT_LEFT_ARB
:
3286 buffer
= GLX_FRONT_LEFT_ATI
;
3288 case WGL_FRONT_RIGHT_ARB
:
3289 buffer
= GLX_FRONT_RIGHT_ATI
;
3291 case WGL_BACK_LEFT_ARB
:
3292 buffer
= GLX_BACK_LEFT_ATI
;
3294 case WGL_BACK_RIGHT_ARB
:
3295 buffer
= GLX_BACK_RIGHT_ATI
;
3298 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3302 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3303 wine_tsx11_unlock();
3309 * X11DRV_wglGetExtensionsStringEXT
3311 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3313 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3314 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3315 return WineGLInfo
.wglExtensions
;
3319 * X11DRV_wglGetSwapIntervalEXT
3321 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3323 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3324 FIXME("(),stub!\n");
3325 return swap_interval
;
3329 * X11DRV_wglSwapIntervalEXT
3331 * WGL_EXT_swap_control: wglSwapIntervalEXT
3333 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3336 TRACE("(%d)\n", interval
);
3337 swap_interval
= interval
;
3338 if (NULL
!= pglXSwapIntervalSGI
) {
3340 ret
= !pglXSwapIntervalSGI(interval
);
3341 wine_tsx11_unlock();
3343 else WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3348 * X11DRV_wglAllocateMemoryNV
3350 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3352 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3354 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3356 if (pglXAllocateMemoryNV
)
3359 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3360 wine_tsx11_unlock();
3366 * X11DRV_wglFreeMemoryNV
3368 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3370 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3371 TRACE("(%p)\n", pointer
);
3372 if (pglXFreeMemoryNV
== NULL
)
3376 pglXFreeMemoryNV(pointer
);
3377 wine_tsx11_unlock();
3381 * X11DRV_wglSetPixelFormatWINE
3383 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3384 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3386 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3388 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
3390 if (!has_opengl()) return FALSE
;
3392 if (physDev
->current_pf
== iPixelFormat
) return TRUE
;
3394 /* Relay to the core SetPixelFormat */
3395 TRACE("Changing iPixelFormat from %d to %d\n", physDev
->current_pf
, iPixelFormat
);
3396 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
3400 * glxRequireVersion (internal)
3402 * Check if the supported GLX version matches requiredVersion.
3404 static BOOL
glxRequireVersion(int requiredVersion
)
3406 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3407 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3413 static BOOL
glxRequireExtension(const char *requiredExtension
)
3415 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3422 static void register_extension_string(const char *ext
)
3424 if (WineGLInfo
.wglExtensions
[0])
3425 strcat(WineGLInfo
.wglExtensions
, " ");
3426 strcat(WineGLInfo
.wglExtensions
, ext
);
3428 TRACE("'%s'\n", ext
);
3431 static BOOL
register_extension(const WineGLExtension
* ext
)
3435 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3436 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3438 register_extension_string(ext
->extName
);
3440 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3441 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3446 static const WineGLExtension WGL_internal_functions
=
3450 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3451 { "wglFinish", X11DRV_wglFinish
},
3452 { "wglFlush", X11DRV_wglFlush
},
3457 static const WineGLExtension WGL_ARB_create_context
=
3459 "WGL_ARB_create_context",
3461 { "wglCreateContextAttribsARB", X11DRV_wglCreateContextAttribsARB
},
3465 static const WineGLExtension WGL_ARB_extensions_string
=
3467 "WGL_ARB_extensions_string",
3469 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3473 static const WineGLExtension WGL_ARB_make_current_read
=
3475 "WGL_ARB_make_current_read",
3477 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3478 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3482 static const WineGLExtension WGL_ARB_multisample
=
3484 "WGL_ARB_multisample",
3487 static const WineGLExtension WGL_ARB_pbuffer
=
3491 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3492 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3493 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3494 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3495 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3496 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3500 static const WineGLExtension WGL_ARB_pixel_format
=
3502 "WGL_ARB_pixel_format",
3504 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3505 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3506 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3510 static const WineGLExtension WGL_ARB_render_texture
=
3512 "WGL_ARB_render_texture",
3514 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3515 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3519 static const WineGLExtension WGL_EXT_extensions_string
=
3521 "WGL_EXT_extensions_string",
3523 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3527 static const WineGLExtension WGL_EXT_swap_control
=
3529 "WGL_EXT_swap_control",
3531 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3532 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3536 static const WineGLExtension WGL_NV_vertex_array_range
=
3538 "WGL_NV_vertex_array_range",
3540 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3541 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3545 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3547 "WGL_WINE_pixel_format_passthrough",
3549 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE
},
3554 * X11DRV_WineGL_LoadExtensions
3556 static void X11DRV_WineGL_LoadExtensions(void)
3558 WineGLInfo
.wglExtensions
[0] = 0;
3560 /* Load Wine internal functions */
3561 register_extension(&WGL_internal_functions
);
3563 /* ARB Extensions */
3565 if(glxRequireExtension("GLX_ARB_create_context"))
3567 register_extension(&WGL_ARB_create_context
);
3569 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3570 register_extension_string("WGL_ARB_create_context_profile");
3573 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3575 register_extension_string("WGL_ARB_pixel_format_float");
3576 register_extension_string("WGL_ATI_pixel_format_float");
3579 register_extension(&WGL_ARB_extensions_string
);
3581 if (glxRequireVersion(3))
3582 register_extension(&WGL_ARB_make_current_read
);
3584 if (glxRequireExtension("GLX_ARB_multisample"))
3585 register_extension(&WGL_ARB_multisample
);
3587 /* In general pbuffer functionality requires support in the X-server. The functionality is
3588 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3589 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3590 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3592 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3593 * without support in the X-server (which other Mesa based drivers require).
3595 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3596 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3597 * is available pbuffers must be available too. */
3598 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3599 register_extension(&WGL_ARB_pbuffer
);
3601 register_extension(&WGL_ARB_pixel_format
);
3603 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3604 if (glxRequireExtension("GLX_ATI_render_texture") ||
3605 glxRequireExtension("GLX_ARB_render_texture") ||
3606 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3608 register_extension(&WGL_ARB_render_texture
);
3610 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3611 if(glxRequireExtension("GLX_NV_float_buffer"))
3612 register_extension_string("WGL_NV_float_buffer");
3614 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3615 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3616 register_extension_string("WGL_NV_texture_rectangle");
3619 /* EXT Extensions */
3621 register_extension(&WGL_EXT_extensions_string
);
3623 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3624 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3625 register_extension(&WGL_EXT_swap_control
);
3627 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3628 register_extension_string("WGL_EXT_framebuffer_sRGB");
3630 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3631 register_extension_string("WGL_EXT_pixel_format_packed_float");
3633 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3634 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3635 register_extension(&WGL_NV_vertex_array_range
);
3637 /* WINE-specific WGL Extensions */
3639 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3640 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3642 register_extension(&WGL_WINE_pixel_format_passthrough
);
3646 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3652 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3653 ret
= physDev
->drawable
; /* PBuffer */
3655 ret
= physDev
->bitmap
->glxpixmap
;
3657 else if(physDev
->gl_drawable
)
3658 ret
= physDev
->gl_drawable
;
3660 ret
= physDev
->drawable
;
3664 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3667 pglXDestroyGLXPixmap(display
, glxpixmap
);
3668 wine_tsx11_unlock();
3673 * X11DRV_SwapBuffers
3675 * Swap the buffers of this DC
3677 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3679 GLXDrawable drawable
;
3680 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3682 if (!has_opengl()) return FALSE
;
3684 TRACE("(%p)\n", physDev
);
3686 drawable
= get_glxdrawable(physDev
);
3690 if(physDev
->pixmap
) {
3691 if(pglXCopySubBufferMESA
) {
3692 int w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
3693 int h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
3695 /* (glX)SwapBuffers has an implicit glFlush effect, however
3696 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3700 pglXCopySubBufferMESA(gdi_display
, drawable
, 0, 0, w
, h
);
3703 pglXSwapBuffers(gdi_display
, drawable
);
3706 pglXSwapBuffers(gdi_display
, drawable
);
3708 flush_gl_drawable(physDev
);
3709 wine_tsx11_unlock();
3714 static long prev_time
, start_time
;
3715 static unsigned long frames
, frames_total
;
3717 DWORD time
= GetTickCount();
3720 /* every 1.5 seconds */
3721 if (time
- prev_time
> 1500) {
3722 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3723 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3726 if(start_time
== 0) start_time
= time
;
3733 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3735 WineGLPixelFormat
*fmt
;
3738 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3743 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3744 wine_tsx11_unlock();
3748 #else /* no OpenGL includes */
3750 void X11DRV_OpenGL_Cleanup(void)
3754 static inline void opengl_error(void)
3757 if (!warned
++) ERR("No OpenGL support compiled in.\n");
3760 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3765 void mark_drawable_dirty(Drawable old
, Drawable
new)
3769 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
3773 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3778 /***********************************************************************
3779 * ChoosePixelFormat (X11DRV.@)
3781 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3782 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3787 /***********************************************************************
3788 * DescribePixelFormat (X11DRV.@)
3790 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3793 PIXELFORMATDESCRIPTOR
*ppfd
) {
3798 /***********************************************************************
3799 * GetPixelFormat (X11DRV.@)
3801 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3806 /***********************************************************************
3807 * SetPixelFormat (X11DRV.@)
3809 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3811 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3816 /***********************************************************************
3817 * SwapBuffers (X11DRV.@)
3819 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3825 * X11DRV_wglCopyContext
3827 * For OpenGL32 wglCopyContext.
3829 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
3835 * X11DRV_wglCreateContext
3837 * For OpenGL32 wglCreateContext.
3839 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3845 * X11DRV_wglCreateContextAttribsARB
3847 * WGL_ARB_create_context: wglCreateContextAttribsARB
3849 HGLRC
X11DRV_wglCreateContextAttribsARB(X11DRV_PDEVICE
*physDev
, HGLRC hShareContext
, const int* attribList
)
3856 * X11DRV_wglDeleteContext
3858 * For OpenGL32 wglDeleteContext.
3860 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3866 * X11DRV_wglGetProcAddress
3868 * For OpenGL32 wglGetProcAddress.
3870 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3875 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3881 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3887 * X11DRV_wglMakeCurrent
3889 * For OpenGL32 wglMakeCurrent.
3891 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3897 * X11DRV_wglShareLists
3899 * For OpenGL32 wglShareLists.
3901 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3907 * X11DRV_wglUseFontBitmapsA
3909 * For OpenGL32 wglUseFontBitmapsA.
3911 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3918 * X11DRV_wglUseFontBitmapsW
3920 * For OpenGL32 wglUseFontBitmapsW.
3922 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3929 * X11DRV_wglSetPixelFormatWINE
3931 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3932 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3934 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3940 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3945 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3950 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3955 #endif /* defined(HAVE_OPENGL) */