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"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
58 /* Redefines the constants */
59 #define CALLBACK __stdcall
60 #define WINAPI __stdcall
61 #define APIENTRY WINAPI
64 WINE_DECLARE_DEBUG_CHANNEL(fps
);
66 typedef struct wine_glextension
{
75 const char *glVersion
;
80 const char *glxServerVersion
;
81 const char *glxServerVendor
;
82 const char *glxServerExtensions
;
84 const char *glxClientVersion
;
85 const char *glxClientVendor
;
86 const char *glxClientExtensions
;
88 const char *glxExtensions
;
91 char wglExtensions
[4096];
94 typedef struct wine_glpixelformat
{
100 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
103 typedef struct wine_glcontext
{
106 BOOL has_been_current
;
110 WineGLPixelFormat
*fmt
;
111 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
112 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
115 Drawable drawables
[2];
116 BOOL refresh_drawables
;
117 struct wine_glcontext
*next
;
118 struct wine_glcontext
*prev
;
121 typedef struct wine_glpbuffer
{
124 WineGLPixelFormat
* fmt
;
130 int use_render_texture
; /* This is also the internal texture format */
131 int texture_bind_target
;
133 GLint texture_format
;
134 GLuint texture_target
;
140 static Wine_GLContext
*context_list
;
141 static struct WineGLInfo WineGLInfo
= { 0 };
142 static int use_render_texture_emulation
= 1;
143 static int use_render_texture_ati
= 0;
144 static int swap_interval
= 1;
146 #define MAX_EXTENSIONS 16
147 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
148 static int WineGLExtensionListSize
;
150 static void X11DRV_WineGL_LoadExtensions(void);
151 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
152 static BOOL
glxRequireVersion(int requiredVersion
);
153 static BOOL
glxRequireExtension(const char *requiredExtension
);
155 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
156 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
157 TRACE(" - dwFlags : ");
158 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
159 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
160 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
161 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
162 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
163 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
164 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
165 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
166 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
173 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
174 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
175 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
176 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
177 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
181 TRACE(" - iPixelType : ");
182 switch (ppfd
->iPixelType
) {
183 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
184 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
188 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
189 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
190 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
191 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
192 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
193 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
194 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
195 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
196 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
198 TRACE(" - iLayerType : ");
199 switch (ppfd
->iLayerType
) {
200 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
201 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
202 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
207 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
208 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
210 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
212 MAKE_FUNCPTR(glXChooseVisual
)
213 MAKE_FUNCPTR(glXCopyContext
)
214 MAKE_FUNCPTR(glXCreateContext
)
215 MAKE_FUNCPTR(glXCreateGLXPixmap
)
216 MAKE_FUNCPTR(glXGetCurrentContext
)
217 MAKE_FUNCPTR(glXGetCurrentDrawable
)
218 MAKE_FUNCPTR(glXDestroyContext
)
219 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
220 MAKE_FUNCPTR(glXGetConfig
)
221 MAKE_FUNCPTR(glXIsDirect
)
222 MAKE_FUNCPTR(glXMakeCurrent
)
223 MAKE_FUNCPTR(glXSwapBuffers
)
224 MAKE_FUNCPTR(glXQueryExtension
)
225 MAKE_FUNCPTR(glXQueryVersion
)
226 MAKE_FUNCPTR(glXUseXFont
)
229 MAKE_FUNCPTR(glXGetClientString
)
230 MAKE_FUNCPTR(glXQueryExtensionsString
)
231 MAKE_FUNCPTR(glXQueryServerString
)
234 MAKE_FUNCPTR(glXGetFBConfigs
)
235 MAKE_FUNCPTR(glXChooseFBConfig
)
236 MAKE_FUNCPTR(glXCreatePbuffer
)
237 MAKE_FUNCPTR(glXCreateNewContext
)
238 MAKE_FUNCPTR(glXDestroyPbuffer
)
239 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
240 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
241 MAKE_FUNCPTR(glXMakeContextCurrent
)
242 MAKE_FUNCPTR(glXQueryDrawable
)
243 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
246 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
247 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
248 static int (*pglXSwapIntervalSGI
)(int);
250 /* ATI GLX Extensions */
251 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
252 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
253 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
255 /* NV GLX Extension */
256 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
257 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
259 /* MESA GLX Extensions */
260 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
262 /* Standard OpenGL */
263 MAKE_FUNCPTR(glBindTexture
)
264 MAKE_FUNCPTR(glBitmap
)
265 MAKE_FUNCPTR(glCopyTexSubImage1D
)
266 MAKE_FUNCPTR(glCopyTexImage2D
)
267 MAKE_FUNCPTR(glCopyTexSubImage2D
)
268 MAKE_FUNCPTR(glDrawBuffer
)
269 MAKE_FUNCPTR(glEndList
)
270 MAKE_FUNCPTR(glGetError
)
271 MAKE_FUNCPTR(glGetIntegerv
)
272 MAKE_FUNCPTR(glGetString
)
273 MAKE_FUNCPTR(glNewList
)
274 MAKE_FUNCPTR(glPixelStorei
)
275 MAKE_FUNCPTR(glReadPixels
)
276 MAKE_FUNCPTR(glTexImage2D
)
277 MAKE_FUNCPTR(glFinish
)
278 MAKE_FUNCPTR(glFlush
)
281 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
283 /* In the future we might want to find the exact X or GLX error to report back to the app */
287 static BOOL infoInitialized
= FALSE
;
288 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
290 int screen
= DefaultScreen(gdi_display
);
291 Window win
= RootWindow(gdi_display
, screen
);
294 GLXContext ctx
= NULL
;
295 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
299 infoInitialized
= TRUE
;
303 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
305 WORD old_fs
= wine_get_fs();
306 /* Create a GLX Context. Without one we can't query GL information */
307 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
308 if (wine_get_fs() != old_fs
)
310 wine_set_fs( old_fs
);
312 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
313 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
319 pglXMakeCurrent(gdi_display
, win
, ctx
);
321 ERR(" couldn't initialize OpenGL, expect problems\n");
326 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
327 str
= (const char *) pglGetString(GL_EXTENSIONS
);
328 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
329 strcpy(WineGLInfo
.glExtensions
, str
);
331 /* Get the common GLX version supported by GLX client and server ( major/minor) */
332 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
334 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
335 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
336 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
338 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
339 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
340 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
342 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
343 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
345 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
346 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
347 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
348 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
349 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
350 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
351 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
352 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
356 pglXMakeCurrent(gdi_display
, None
, NULL
);
357 pglXDestroyContext(gdi_display
, ctx
);
363 void X11DRV_OpenGL_Cleanup(void)
365 HeapFree(GetProcessHeap(), 0, WineGLInfo
.glExtensions
);
366 infoInitialized
= FALSE
;
369 static BOOL
has_opengl(void)
371 static int init_done
;
372 static void *opengl_handle
;
375 int error_base
, event_base
;
377 if (init_done
) return (opengl_handle
!= NULL
);
380 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
381 and include all dependencies */
382 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
383 if (opengl_handle
== NULL
)
385 ERR( "Failed to load libGL: %s\n", buffer
);
386 ERR( "OpenGL support is disabled.\n");
390 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
391 if (pglXGetProcAddressARB
== NULL
) {
392 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
396 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
398 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
403 LOAD_FUNCPTR(glXChooseVisual
);
404 LOAD_FUNCPTR(glXCopyContext
);
405 LOAD_FUNCPTR(glXCreateContext
);
406 LOAD_FUNCPTR(glXCreateGLXPixmap
);
407 LOAD_FUNCPTR(glXGetCurrentContext
);
408 LOAD_FUNCPTR(glXGetCurrentDrawable
);
409 LOAD_FUNCPTR(glXDestroyContext
);
410 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
411 LOAD_FUNCPTR(glXGetConfig
);
412 LOAD_FUNCPTR(glXIsDirect
);
413 LOAD_FUNCPTR(glXMakeCurrent
);
414 LOAD_FUNCPTR(glXSwapBuffers
);
415 LOAD_FUNCPTR(glXQueryExtension
);
416 LOAD_FUNCPTR(glXQueryVersion
);
417 LOAD_FUNCPTR(glXUseXFont
);
420 LOAD_FUNCPTR(glXGetClientString
);
421 LOAD_FUNCPTR(glXQueryExtensionsString
);
422 LOAD_FUNCPTR(glXQueryServerString
);
425 LOAD_FUNCPTR(glXCreatePbuffer
);
426 LOAD_FUNCPTR(glXCreateNewContext
);
427 LOAD_FUNCPTR(glXDestroyPbuffer
);
428 LOAD_FUNCPTR(glXMakeContextCurrent
);
429 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
430 LOAD_FUNCPTR(glXGetFBConfigs
);
432 /* Standard OpenGL calls */
433 LOAD_FUNCPTR(glBindTexture
);
434 LOAD_FUNCPTR(glBitmap
);
435 LOAD_FUNCPTR(glCopyTexSubImage1D
);
436 LOAD_FUNCPTR(glCopyTexImage2D
);
437 LOAD_FUNCPTR(glCopyTexSubImage2D
);
438 LOAD_FUNCPTR(glDrawBuffer
);
439 LOAD_FUNCPTR(glEndList
);
440 LOAD_FUNCPTR(glGetError
);
441 LOAD_FUNCPTR(glGetIntegerv
);
442 LOAD_FUNCPTR(glGetString
);
443 LOAD_FUNCPTR(glNewList
);
444 LOAD_FUNCPTR(glPixelStorei
);
445 LOAD_FUNCPTR(glReadPixels
);
446 LOAD_FUNCPTR(glTexImage2D
);
447 LOAD_FUNCPTR(glFinish
);
448 LOAD_FUNCPTR(glFlush
);
451 /* It doesn't matter if these fail. They'll only be used if the driver reports
452 the associated extension is available (and if a driver reports the extension
453 is available but fails to provide the functions, it's quite broken) */
454 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)
455 /* ARB GLX Extension */
456 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
457 /* NV GLX Extension */
458 LOAD_FUNCPTR(glXAllocateMemoryNV
);
459 LOAD_FUNCPTR(glXFreeMemoryNV
);
462 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
465 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
466 TRACE("GLX is up and running error_base = %d\n", error_base
);
469 ERR( "GLX extension is missing, disabling OpenGL.\n" );
473 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
474 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
477 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
478 * depends on the reported GLX client / server version and on the client / server extension list.
479 * Those don't have to be the same.
481 * In general the server GLX information lists the capabilities in case of indirect rendering.
482 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
483 * available and in that case the client GLX informat can be used.
484 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
485 * in the GLX version/extension list. When a program does this it works for certain for both
486 * direct and indirect rendering.
488 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
489 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
490 * extension list which causes this extension not to be listed. (Wine requires this extension).
491 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
492 * pbuffers is around.
494 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
495 * the ATI drivers and from then on use GLX client information for them.
498 if(glxRequireVersion(3)) {
499 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
500 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
501 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
502 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
503 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
504 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
505 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
506 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
508 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
509 * enable this function when the Xserver understand GLX 1.3 or newer
511 pglXQueryDrawable
= NULL
;
512 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
513 TRACE("Overriding ATI GLX capabilities!\n");
514 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
515 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
516 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
517 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
519 /* Use client GLX information in case of the ATI drivers. We override the
520 * capabilities over here and not somewhere else as ATI might better their
521 * life in the future. In case they release proper drivers this block of
522 * code won't be called. */
523 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
525 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
528 if(glxRequireExtension("GLX_ATI_render_texture")) {
529 use_render_texture_ati
= 1;
530 pglXBindTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
531 pglXReleaseTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
532 pglXDrawableAttribATI
= pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
535 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
536 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
539 X11DRV_WineGL_LoadExtensions();
545 wine_dlclose(opengl_handle
, NULL
, 0);
546 opengl_handle
= NULL
;
550 static inline Wine_GLContext
*alloc_context(void)
554 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
556 ret
->next
= context_list
;
557 if (context_list
) context_list
->prev
= ret
;
563 static inline void free_context(Wine_GLContext
*context
)
565 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
566 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
567 else context_list
= context
->next
;
569 if (context
->vis
) XFree(context
->vis
);
570 HeapFree(GetProcessHeap(), 0, context
);
573 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
576 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
577 return (ptr
!= NULL
);
580 static int describeContext(Wine_GLContext
* ctx
) {
583 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
584 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
585 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
586 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
587 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
592 static BOOL
describeDrawable(X11DRV_PDEVICE
*physDev
) {
594 WineGLPixelFormat
*fmt
;
597 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
/* Offscreen */, &fmt_count
);
598 if(!fmt
) return FALSE
;
600 TRACE(" HDC %p has:\n", physDev
->hdc
);
601 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
602 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev
));
603 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
605 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
606 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
611 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
616 int nvfloatattrib
= GLX_DONT_CARE
;
617 int pixelattrib
= ~0;
619 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
620 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
621 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
622 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
624 switch (iWGLAttr
[cur
]) {
625 case WGL_AUX_BUFFERS_ARB
:
626 pop
= iWGLAttr
[++cur
];
627 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
628 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
630 case WGL_COLOR_BITS_ARB
:
631 pop
= iWGLAttr
[++cur
];
632 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
633 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
635 case WGL_BLUE_BITS_ARB
:
636 pop
= iWGLAttr
[++cur
];
637 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
638 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
640 case WGL_RED_BITS_ARB
:
641 pop
= iWGLAttr
[++cur
];
642 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
643 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
645 case WGL_GREEN_BITS_ARB
:
646 pop
= iWGLAttr
[++cur
];
647 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
648 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
650 case WGL_ALPHA_BITS_ARB
:
651 pop
= iWGLAttr
[++cur
];
652 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
653 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
655 case WGL_DEPTH_BITS_ARB
:
656 pop
= iWGLAttr
[++cur
];
657 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
658 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
660 case WGL_STENCIL_BITS_ARB
:
661 pop
= iWGLAttr
[++cur
];
662 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
663 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
665 case WGL_DOUBLE_BUFFER_ARB
:
666 pop
= iWGLAttr
[++cur
];
667 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
668 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
671 pop
= iWGLAttr
[++cur
];
672 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
673 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
676 case WGL_PIXEL_TYPE_ARB
:
677 pop
= iWGLAttr
[++cur
];
678 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
680 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
681 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
682 /* 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 */
683 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
684 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
686 ERR("unexpected PixelType(%x)\n", pop
);
691 case WGL_SUPPORT_GDI_ARB
:
692 /* This flag is set in a WineGLPixelFormat */
693 pop
= iWGLAttr
[++cur
];
694 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
697 case WGL_DRAW_TO_BITMAP_ARB
:
698 /* This flag is set in a WineGLPixelFormat */
699 pop
= iWGLAttr
[++cur
];
700 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
703 case WGL_DRAW_TO_WINDOW_ARB
:
704 pop
= iWGLAttr
[++cur
];
705 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
706 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
708 drawattrib
|= GLX_WINDOW_BIT
;
712 case WGL_DRAW_TO_PBUFFER_ARB
:
713 pop
= iWGLAttr
[++cur
];
714 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
715 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
717 drawattrib
|= GLX_PBUFFER_BIT
;
721 case WGL_ACCELERATION_ARB
:
722 /* This flag is set in a WineGLPixelFormat */
723 pop
= iWGLAttr
[++cur
];
724 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
727 case WGL_SUPPORT_OPENGL_ARB
:
728 pop
= iWGLAttr
[++cur
];
729 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
730 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
733 case WGL_SWAP_METHOD_ARB
:
734 pop
= iWGLAttr
[++cur
];
735 /* For now we ignore this and just return SWAP_EXCHANGE */
736 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
739 case WGL_PBUFFER_LARGEST_ARB
:
740 pop
= iWGLAttr
[++cur
];
741 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
742 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
745 case WGL_SAMPLE_BUFFERS_ARB
:
746 pop
= iWGLAttr
[++cur
];
747 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
748 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
751 case WGL_SAMPLES_ARB
:
752 pop
= iWGLAttr
[++cur
];
753 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
754 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
757 case WGL_TEXTURE_FORMAT_ARB
:
758 case WGL_TEXTURE_TARGET_ARB
:
759 case WGL_MIPMAP_TEXTURE_ARB
:
760 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
761 pop
= iWGLAttr
[++cur
];
763 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
765 if (use_render_texture_ati
) {
766 /** nothing to do here */
768 else if (!use_render_texture_emulation
) {
769 if (WGL_NO_TEXTURE_ARB
!= pop
) {
770 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
771 return -1; /** error: don't support it */
773 drawattrib
|= GLX_PBUFFER_BIT
;
777 case WGL_FLOAT_COMPONENTS_NV
:
778 nvfloatattrib
= iWGLAttr
[++cur
];
779 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
781 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
782 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
783 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
784 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
785 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
786 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
787 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
788 pop
= iWGLAttr
[++cur
];
789 /** cannot be converted, see direct handling on
790 * - wglGetPixelFormatAttribivARB
791 * TODO: wglChoosePixelFormat
794 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
795 pop
= iWGLAttr
[++cur
];
796 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
797 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
800 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
801 pop
= iWGLAttr
[++cur
];
802 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
803 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
806 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
812 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
813 * all formats. Unless drawattrib is set to a non-zero value override it with ~0, so that pixmap and pbuffer
814 * formats appear as well. */
815 if(!drawattrib
) drawattrib
= ~0;
816 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
817 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
819 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
820 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to ~0 unless
821 * it is overridden. */
822 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
823 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
825 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
826 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
827 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
828 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
834 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
836 int render_type
=0, render_type_bit
;
837 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
838 switch(render_type_bit
)
841 render_type
= GLX_RGBA_TYPE
;
843 case GLX_COLOR_INDEX_BIT
:
844 render_type
= GLX_COLOR_INDEX_TYPE
;
846 case GLX_RGBA_FLOAT_BIT
:
847 render_type
= GLX_RGBA_FLOAT_TYPE
;
849 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
850 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
853 ERR("Unknown render_type: %x\n", render_type
);
858 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
859 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
862 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
863 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
865 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
866 * the GLX_PIXMAP_BIT set. */
867 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
870 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
872 static WineGLPixelFormat
*list
;
873 static int size
, onscreen_size
;
875 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
877 XVisualInfo
*visinfo
;
882 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
883 if (NULL
== cfgs
|| 0 == nCfgs
) {
884 if(cfgs
!= NULL
) XFree(cfgs
);
886 ERR("glXChooseFBConfig returns NULL\n");
890 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
891 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
892 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
893 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
895 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
897 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
899 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
902 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
904 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
906 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
907 * Do this as GLX doesn't guarantee that the list is sorted */
908 for(run
=0; run
< 2; run
++)
910 for(i
=0; i
<nCfgs
; i
++) {
911 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
912 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
914 /* The first run we only add onscreen formats (ones which have an associated X Visual).
915 * The second run we only set offscreen formats. */
918 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
919 * The contents is copied to the destination using XCopyArea. For the copying to work
920 * the depth of the source and destination window should be the same. In general this should
921 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
922 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
923 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
924 * list formats with the same depth. */
925 if(visinfo
->depth
!= screen_depth
)
931 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
932 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
933 list
[size
].fbconfig
= cfgs
[i
];
934 list
[size
].fmt_id
= fmt_id
;
935 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
936 list
[size
].offscreenOnly
= FALSE
;
937 list
[size
].dwFlags
= 0;
941 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
942 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
944 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
945 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
946 list
[size
].fbconfig
= cfgs
[i
];
947 list
[size
].fmt_id
= fmt_id
;
948 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
949 list
[size
].offscreenOnly
= FALSE
;
950 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
954 } else if(run
&& !visinfo
) {
955 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
956 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
957 list
[size
].fbconfig
= cfgs
[i
];
958 list
[size
].fmt_id
= fmt_id
;
959 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
960 list
[size
].offscreenOnly
= TRUE
;
961 list
[size
].dwFlags
= 0;
965 if (visinfo
) XFree(visinfo
);
969 if(cfgs
!= NULL
) XFree(cfgs
);
972 if (size_ret
) *size_ret
= size
;
973 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
978 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
979 * In our WGL implementation we only support a subset of these formats namely the format of
980 * Wine's main visual and offscreen formats (if they are available).
981 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
982 * and it returns the number of supported WGL formats in fmt_count.
984 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
986 WineGLPixelFormat
*list
, *res
= NULL
;
987 int size
, onscreen_size
;
989 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
991 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
992 * iPixelFormat in case of probing the number of pixelformats.
994 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
995 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
996 res
= &list
[iPixelFormat
-1];
997 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
1003 *fmt_count
= onscreen_size
;
1005 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1010 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1011 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1013 WineGLPixelFormat
*list
;
1016 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1018 for(i
=0; i
<size
; i
++) {
1019 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1020 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1021 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1022 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1026 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1030 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1032 WineGLPixelFormat
*fmt
;
1034 if (!fbconfig_id
) return 0;
1036 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1038 return fmt
->iPixelFormat
;
1039 /* This will happen on hwnds without a pixel format set; it's ok */
1044 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1045 void mark_drawable_dirty(Drawable old
, Drawable
new)
1047 Wine_GLContext
*ctx
;
1048 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
1049 if (old
== ctx
->drawables
[0]) {
1050 ctx
->drawables
[0] = new;
1051 ctx
->refresh_drawables
= TRUE
;
1053 if (old
== ctx
->drawables
[1]) {
1054 ctx
->drawables
[1] = new;
1055 ctx
->refresh_drawables
= TRUE
;
1060 /* Given the current context, make sure its drawable is sync'd */
1061 static inline void sync_context(Wine_GLContext
*context
)
1063 if(context
&& context
->refresh_drawables
) {
1064 if (glxRequireVersion(3))
1065 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1066 context
->drawables
[1], context
->ctx
);
1068 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1069 context
->refresh_drawables
= FALSE
;
1074 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1078 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1079 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1081 if(context
->gl3_context
)
1083 if(context
->numAttribs
)
1084 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1086 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1088 else if(context
->vis
)
1089 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1090 else /* Create a GLX Context for a pbuffer */
1091 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1097 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1099 return pglXCreateGLXPixmap(display
, vis
, parent
);
1103 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1110 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1112 if(vis
->depth
== physDev
->bitmap
->pixmap_depth
)
1113 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1116 wine_tsx11_unlock();
1117 TRACE("return %lx\n", ret
);
1122 * X11DRV_ChoosePixelFormat
1124 * Equivalent to glXChooseVisual.
1126 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
1127 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1128 WineGLPixelFormat
*list
;
1133 int bestFormat
= -1;
1134 int bestDBuffer
= -1;
1135 int bestStereo
= -1;
1139 int bestStencil
= -1;
1142 if (!has_opengl()) return 0;
1144 if (TRACE_ON(wgl
)) {
1145 TRACE("(%p,%p)\n", physDev
, ppfd
);
1147 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1150 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1153 for(i
=0; i
<onscreen_size
; i
++)
1157 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1158 WineGLPixelFormat
*fmt
= &list
[i
];
1161 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1162 if (value
& GLX_RGBA_BIT
)
1163 iPixelType
= PFD_TYPE_RGBA
;
1165 iPixelType
= PFD_TYPE_COLORINDEX
;
1167 if (ppfd
->iPixelType
!= iPixelType
)
1169 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1173 /* Only use bitmap capable for formats for bitmap rendering.
1174 * See get_formats for more info. */
1175 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1177 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1181 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1182 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1183 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1184 if (value
) dwFlags
|= PFD_STEREO
;
1185 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1186 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1187 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1188 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1189 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1191 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1192 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1193 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1194 * formats without the given flag set.
1195 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1196 * has indicated that a format without stereo is returned when stereo is unavailable.
1197 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1198 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1200 * To summarize the following is most likely the correct behavior:
1201 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1202 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1203 * stereo don't care -> it doesn't matter whether we get stereo or not
1205 * In Wine we will treat no-stereo the same way as don't care because it makes
1206 * format selection even more complicated and second drivers with Stereo advertise
1207 * each format twice anyway.
1210 /* Doublebuffer, see the comments above */
1211 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1212 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1213 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1215 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1216 bestStereo
= dwFlags
& PFD_STEREO
;
1220 bestStencil
= stencil
;
1225 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1229 /* Stereo, see the comments above. */
1230 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1231 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1232 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1234 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1235 bestStereo
= dwFlags
& PFD_STEREO
;
1239 bestStencil
= stencil
;
1244 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1248 /* Below we will do a number of checks to select the 'best' pixelformat.
1249 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1250 * The code works by trying to match the most important options as close as possible.
1251 * When a reasonable format is found, we will try to match more options.
1252 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1253 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1254 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1257 if(ppfd
->cColorBits
) {
1258 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1259 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1261 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1262 bestStereo
= dwFlags
& PFD_STEREO
;
1266 bestStencil
= stencil
;
1270 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1271 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1277 if(ppfd
->cAlphaBits
) {
1278 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1279 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1281 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1282 bestStereo
= dwFlags
& PFD_STEREO
;
1286 bestStencil
= stencil
;
1290 } else if(bestAlpha
!= alpha
) {
1291 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1297 if(ppfd
->cDepthBits
) {
1298 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1299 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1301 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1302 bestStereo
= dwFlags
& PFD_STEREO
;
1306 bestStencil
= stencil
;
1310 } else if(bestDepth
!= depth
) {
1311 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1317 if(ppfd
->cStencilBits
) {
1318 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1319 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1321 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1322 bestStereo
= dwFlags
& PFD_STEREO
;
1326 bestStencil
= stencil
;
1330 } else if(bestStencil
!= stencil
) {
1331 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1337 if(ppfd
->cAuxBuffers
) {
1338 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1339 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1341 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1342 bestStereo
= dwFlags
& PFD_STEREO
;
1346 bestStencil
= stencil
;
1350 } else if(bestAux
!= aux
) {
1351 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1357 if(bestFormat
== -1) {
1358 TRACE("No matching mode was found returning 0\n");
1362 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1363 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1366 wine_tsx11_unlock();
1371 * X11DRV_DescribePixelFormat
1373 * Get the pixel-format descriptor associated to the given id
1375 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1378 PIXELFORMATDESCRIPTOR
*ppfd
) {
1379 /*XVisualInfo *vis;*/
1382 WineGLPixelFormat
*fmt
;
1386 if (!has_opengl()) return 0;
1388 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1390 /* 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 */
1391 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1393 /* The application is only querying the number of pixelformats */
1395 } else if(fmt
== NULL
) {
1396 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1400 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1401 ERR("Wrong structure size !\n");
1402 /* Should set error */
1408 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1409 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1412 /* These flags are always the same... */
1413 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1414 /* Now the flags extracted from the Visual */
1418 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1419 if(value
& GLX_WINDOW_BIT
)
1420 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1422 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1423 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1424 * 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
1425 * offered the GDI bit either. */
1426 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1428 /* PFD_GENERIC_FORMAT - gdi software rendering
1429 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1430 * none set - full hardware accelerated by a ICD
1432 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1433 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1435 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1437 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1438 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1440 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1443 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1444 if (value
& GLX_RGBA_BIT
)
1445 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1447 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1450 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1451 ppfd
->cColorBits
= value
;
1453 /* Red, green, blue and alpha bits / shifts */
1454 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1455 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1456 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1457 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1458 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1460 ppfd
->cRedBits
= rb
;
1461 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1462 ppfd
->cBlueBits
= bb
;
1463 ppfd
->cBlueShift
= ab
;
1464 ppfd
->cGreenBits
= gb
;
1465 ppfd
->cGreenShift
= bb
+ ab
;
1466 ppfd
->cAlphaBits
= ab
;
1467 ppfd
->cAlphaShift
= 0;
1470 ppfd
->cRedShift
= 0;
1471 ppfd
->cBlueBits
= 0;
1472 ppfd
->cBlueShift
= 0;
1473 ppfd
->cGreenBits
= 0;
1474 ppfd
->cGreenShift
= 0;
1475 ppfd
->cAlphaBits
= 0;
1476 ppfd
->cAlphaShift
= 0;
1479 /* Accum RGBA bits */
1480 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1481 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1482 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1483 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1485 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1486 ppfd
->cAccumRedBits
= rb
;
1487 ppfd
->cAccumGreenBits
= gb
;
1488 ppfd
->cAccumBlueBits
= bb
;
1489 ppfd
->cAccumAlphaBits
= ab
;
1492 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1493 ppfd
->cAuxBuffers
= value
;
1496 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1497 ppfd
->cDepthBits
= value
;
1500 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1501 ppfd
->cStencilBits
= value
;
1503 wine_tsx11_unlock();
1505 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1507 if (TRACE_ON(wgl
)) {
1508 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1515 * X11DRV_GetPixelFormat
1517 * Get the pixel-format id used by this DC
1519 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1520 WineGLPixelFormat
*fmt
;
1522 TRACE("(%p)\n", physDev
);
1524 if (!physDev
->current_pf
) return 0; /* not set yet */
1526 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1529 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1532 else if(fmt
->offscreenOnly
)
1534 /* Offscreen formats can't be used with traditional WGL calls.
1535 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1536 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1540 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1541 return physDev
->current_pf
;
1544 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1545 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1546 * set the pixel format multiple times. */
1547 static BOOL
internal_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1549 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1550 WineGLPixelFormat
*fmt
;
1554 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1555 if(get_glxdrawable(physDev
) == root_window
)
1557 ERR("Invalid operation on root_window\n");
1561 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1562 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1564 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1569 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1570 wine_tsx11_unlock();
1572 hwnd
= WindowFromDC(physDev
->hdc
);
1574 if(!(value
&GLX_WINDOW_BIT
)) {
1575 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1579 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, (WPARAM
)fmt
->fmt_id
, 0)) {
1580 ERR("Couldn't set format of the window, returning failure\n");
1584 else if(physDev
->bitmap
) {
1585 if(!(value
&GLX_PIXMAP_BIT
)) {
1586 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1590 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
, fmt
);
1591 if(!physDev
->bitmap
->glxpixmap
) {
1592 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1597 FIXME("called on a non-window, non-bitmap object?\n");
1600 physDev
->current_pf
= iPixelFormat
;
1602 if (TRACE_ON(wgl
)) {
1606 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1608 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1610 TRACE(" FBConfig have :\n");
1611 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1612 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1613 TRACE(" - VISUAL_ID 0x%x\n", value
);
1614 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1615 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1617 wine_tsx11_unlock();
1624 * X11DRV_SetPixelFormat
1626 * Set the pixel-format id used by this DC
1628 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1630 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1631 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1633 if (!has_opengl()) return FALSE
;
1635 if(physDev
->current_pf
) /* cannot change it if already set */
1636 return (physDev
->current_pf
== iPixelFormat
);
1638 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
1642 * X11DRV_wglCopyContext
1644 * For OpenGL32 wglCopyContext.
1646 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
1647 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1648 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1650 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1653 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1654 wine_tsx11_unlock();
1656 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1661 * X11DRV_wglCreateContext
1663 * For OpenGL32 wglCreateContext.
1665 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1667 Wine_GLContext
*ret
;
1668 WineGLPixelFormat
*fmt
;
1669 int hdcPF
= physDev
->current_pf
;
1671 HDC hdc
= physDev
->hdc
;
1673 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1675 if (!has_opengl()) return 0;
1677 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1678 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1679 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1680 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1681 * If this fails something is very wrong on the system. */
1683 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1684 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1689 ret
= alloc_context();
1692 ret
->has_been_current
= FALSE
;
1693 ret
->sharing
= FALSE
;
1695 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1696 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1697 wine_tsx11_unlock();
1699 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1704 * X11DRV_wglDeleteContext
1706 * For OpenGL32 wglDeleteContext.
1708 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1710 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1713 TRACE("(%p)\n", hglrc
);
1715 if (!has_opengl()) return 0;
1718 /* A game (Half Life not to name it) deletes twice the same context,
1719 * so make sure it is valid first */
1720 if (is_valid_context( ctx
))
1722 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1727 WARN("Error deleting context !\n");
1728 SetLastError(ERROR_INVALID_HANDLE
);
1731 wine_tsx11_unlock();
1737 * X11DRV_wglGetCurrentReadDCARB
1739 * For OpenGL32 wglGetCurrentReadDCARB.
1741 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1744 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1746 if (ctx
) ret
= ctx
->read_hdc
;
1748 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1753 * X11DRV_wglGetProcAddress
1755 * For OpenGL32 wglGetProcAddress.
1757 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1760 const WineGLExtension
*ext
;
1762 int padding
= 32 - strlen(lpszProc
);
1766 if (!has_opengl()) return NULL
;
1768 /* Check the table of WGL extensions to see if we need to return a WGL extension
1769 * or a function pointer to a native OpenGL function. */
1770 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1771 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1773 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1774 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1775 ext
= WineGLExtensionList
[i
];
1776 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1777 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1778 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1779 return ext
->extEntryPoints
[j
].funcAddress
;
1785 WARN("(%s) - not found\n", lpszProc
);
1790 * X11DRV_wglMakeCurrent
1792 * For OpenGL32 wglMakeCurrent.
1794 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1796 HDC hdc
= physDev
->hdc
;
1797 DWORD type
= GetObjectType(hdc
);
1798 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1800 TRACE("(%p,%p)\n", hdc
, hglrc
);
1802 if (!has_opengl()) return FALSE
;
1805 if (hglrc
== NULL
) {
1806 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1807 NtCurrentTeb()->glContext
= NULL
;
1808 } else if (ctx
->fmt
->iPixelFormat
!= physDev
->current_pf
) {
1809 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1810 hdc
, physDev
->current_pf
, ctx
, ctx
->fmt
->iPixelFormat
);
1811 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1814 Drawable drawable
= get_glxdrawable(physDev
);
1816 /* The describe lines below are for debugging purposes only */
1817 if (TRACE_ON(wgl
)) {
1818 describeDrawable(physDev
);
1819 describeContext(ctx
);
1822 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1823 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1824 NtCurrentTeb()->glContext
= ctx
;
1828 ctx
->has_been_current
= TRUE
;
1830 ctx
->read_hdc
= hdc
;
1831 ctx
->drawables
[0] = drawable
;
1832 ctx
->drawables
[1] = drawable
;
1833 ctx
->refresh_drawables
= FALSE
;
1835 if (type
== OBJ_MEMDC
)
1837 ctx
->do_escape
= TRUE
;
1838 pglDrawBuffer(GL_FRONT_LEFT
);
1842 wine_tsx11_unlock();
1843 TRACE(" returning %s\n", (ret
? "True" : "False"));
1848 * X11DRV_wglMakeContextCurrentARB
1850 * For OpenGL32 wglMakeContextCurrentARB
1852 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1856 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1858 if (!has_opengl()) return 0;
1861 if (hglrc
== NULL
) {
1862 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1863 NtCurrentTeb()->glContext
= NULL
;
1865 if (NULL
== pglXMakeContextCurrent
) {
1868 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1869 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1870 Drawable d_read
= get_glxdrawable(pReadDev
);
1872 ctx
->has_been_current
= TRUE
;
1873 ctx
->hdc
= pDrawDev
->hdc
;
1874 ctx
->read_hdc
= pReadDev
->hdc
;
1875 ctx
->drawables
[0] = d_draw
;
1876 ctx
->drawables
[1] = d_read
;
1877 ctx
->refresh_drawables
= FALSE
;
1878 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1879 NtCurrentTeb()->glContext
= ctx
;
1882 wine_tsx11_unlock();
1884 TRACE(" returning %s\n", (ret
? "True" : "False"));
1889 * X11DRV_wglShareLists
1891 * For OpenGL32 wglShareLists.
1893 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1894 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1895 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1897 TRACE("(%p, %p)\n", org
, dest
);
1899 if (!has_opengl()) return FALSE
;
1901 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1902 * at context creation time but in case of WGL it is done using wglShareLists.
1903 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1904 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1905 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1906 * so there delaying context creation doesn't work.
1908 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1909 * and when a program requests sharing we recreate the destination context if it hasn't been made
1910 * current or when it hasn't shared display lists before.
1913 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
1915 ERR("Could not share display lists, one of the contexts has been current already !\n");
1918 else if(dest
->sharing
)
1920 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1925 if((GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
))
1927 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1931 describeContext(org
);
1932 describeContext(dest
);
1934 /* Re-create the GLX context and share display lists */
1935 pglXDestroyContext(gdi_display
, dest
->ctx
);
1936 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1937 wine_tsx11_unlock();
1938 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1940 org
->sharing
= TRUE
;
1941 dest
->sharing
= TRUE
;
1947 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1949 /* We are running using client-side rendering fonts... */
1951 unsigned int glyph
, size
= 0;
1952 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1956 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1957 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1958 wine_tsx11_unlock();
1960 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1961 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
1962 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
1963 unsigned int height
, width_int
;
1965 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1966 if (needed_size
== GDI_ERROR
) {
1967 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1970 TRACE(" - needed size : %d\n", needed_size
);
1973 if (needed_size
> size
) {
1975 HeapFree(GetProcessHeap(), 0, bitmap
);
1976 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1977 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1978 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1980 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
1982 if (TRACE_ON(wgl
)) {
1983 unsigned int height
, width
, bitmask
;
1984 unsigned char *bitmap_
= bitmap
;
1986 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1987 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1988 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1989 if (needed_size
!= 0) {
1990 TRACE(" - bitmap :\n");
1991 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1993 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1998 if (*bitmap_
& bitmask
)
2003 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2009 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2010 * glyph for it to be drawn properly.
2012 if (needed_size
!= 0) {
2013 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2014 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2016 for (width
= 0; width
< width_int
; width
++) {
2017 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2018 ((int *) bitmap
)[height
* width_int
+ width
];
2024 pglNewList(listBase
++, GL_COMPILE
);
2025 if (needed_size
!= 0) {
2026 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2027 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2028 gm
.gmCellIncX
, gm
.gmCellIncY
,
2031 /* This is the case of 'empty' glyphs like the space character */
2032 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2035 wine_tsx11_unlock();
2039 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2040 wine_tsx11_unlock();
2042 HeapFree(GetProcessHeap(), 0, bitmap
);
2043 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2048 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2049 wine_tsx11_unlock();
2051 HeapFree(GetProcessHeap(), 0, bitmap
);
2052 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2057 * X11DRV_wglUseFontBitmapsA
2059 * For OpenGL32 wglUseFontBitmapsA.
2061 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2063 Font fid
= physDev
->font
;
2065 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2067 if (!has_opengl()) return FALSE
;
2070 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2074 /* I assume that the glyphs are at the same position for X and for Windows */
2075 pglXUseXFont(fid
, first
, count
, listBase
);
2076 wine_tsx11_unlock();
2081 * X11DRV_wglUseFontBitmapsW
2083 * For OpenGL32 wglUseFontBitmapsW.
2085 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2087 Font fid
= physDev
->font
;
2089 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2091 if (!has_opengl()) return FALSE
;
2094 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2097 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2100 /* I assume that the glyphs are at the same position for X and for Windows */
2101 pglXUseXFont(fid
, first
, count
, listBase
);
2102 wine_tsx11_unlock();
2106 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2107 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2114 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2116 pglGetIntegerv(pname
, params
);
2118 * if we cannot find a Wine Context
2119 * we only have the default wine desktop context,
2120 * so if we have only a 24 depth say we have 32
2122 if (!ctx
&& *params
== 24) {
2125 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2130 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2132 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2133 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2137 pglGetIntegerv(pname
, params
);
2140 wine_tsx11_unlock();
2143 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
2147 if (!physDev
->gl_copy
)
2150 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
2151 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
2153 if(w
> 0 && h
> 0) {
2154 Drawable src
= physDev
->pixmap
;
2155 if(!src
) src
= physDev
->gl_drawable
;
2157 /* The GL drawable may be lagged behind if we don't flush first, so
2158 * flush the display make sure we copy up-to-date data */
2160 XFlush(gdi_display
);
2161 XSetFunction(gdi_display
, physDev
->gc
, GXcopy
);
2162 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
2163 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
2164 wine_tsx11_unlock();
2169 static void WINAPI
X11DRV_wglFinish(void)
2171 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2172 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2177 wine_tsx11_unlock();
2178 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2181 static void WINAPI
X11DRV_wglFlush(void)
2183 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2184 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2189 wine_tsx11_unlock();
2190 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2194 * X11DRV_wglCreateContextAttribsARB
2196 * WGL_ARB_create_context: wglCreateContextAttribsARB
2198 HGLRC
X11DRV_wglCreateContextAttribsARB(X11DRV_PDEVICE
*physDev
, HGLRC hShareContext
, const int* attribList
)
2200 Wine_GLContext
*ret
;
2201 WineGLPixelFormat
*fmt
;
2202 int hdcPF
= physDev
->current_pf
;
2205 TRACE("(%p %p %p)\n", physDev
, hShareContext
, attribList
);
2207 if (!has_opengl()) return 0;
2209 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
2210 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2211 * If this fails something is very wrong on the system. */
2214 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
2215 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2220 ret
= alloc_context();
2221 wine_tsx11_unlock();
2222 ret
->hdc
= physDev
->hdc
;
2224 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2225 ret
->gl3_context
= TRUE
;
2227 ret
->numAttribs
= 0;
2230 int *pAttribList
= (int*)attribList
;
2231 int *pContextAttribList
= &ret
->attribList
[0];
2232 /* attribList consists of pairs {token, value] terminated with 0 */
2233 while(pAttribList
[0] != 0)
2235 TRACE("%#x %#x\n", pAttribList
[0], pAttribList
[1]);
2236 switch(pAttribList
[0])
2238 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2239 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2240 pContextAttribList
[1] = pAttribList
[1];
2242 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2243 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2244 pContextAttribList
[1] = pAttribList
[1];
2246 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2248 case WGL_CONTEXT_FLAGS_ARB
:
2249 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2250 pContextAttribList
[1] = pAttribList
[1];
2253 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList
[0], pAttribList
[1]);
2258 pContextAttribList
+= 2;
2263 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2264 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
2266 XSync(gdi_display
, False
);
2267 if(X11DRV_check_error() || !ret
->ctx
)
2269 /* In the future we should convert the GLX error to a win32 one here if needed */
2270 ERR("Context creation failed\n");
2272 wine_tsx11_unlock();
2276 wine_tsx11_unlock();
2277 TRACE(" creating context %p\n", ret
);
2282 * X11DRV_wglGetExtensionsStringARB
2284 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2286 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2287 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2288 return WineGLInfo
.wglExtensions
;
2292 * X11DRV_wglCreatePbufferARB
2294 * WGL_ARB_pbuffer: wglCreatePbufferARB
2296 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2298 Wine_GLPBuffer
* object
= NULL
;
2299 WineGLPixelFormat
*fmt
= NULL
;
2304 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2306 if (0 >= iPixelFormat
) {
2307 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2308 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2309 return NULL
; /* unexpected error */
2312 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2313 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2315 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2316 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2317 goto create_failed
; /* unexpected error */
2320 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2321 if (NULL
== object
) {
2322 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2323 goto create_failed
; /* unexpected error */
2326 object
->display
= gdi_display
;
2327 object
->width
= iWidth
;
2328 object
->height
= iHeight
;
2331 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2332 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2333 while (piAttribList
&& 0 != *piAttribList
) {
2335 switch (*piAttribList
) {
2336 case WGL_PBUFFER_LARGEST_ARB
: {
2338 attr_v
= *piAttribList
;
2339 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2340 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2344 case WGL_TEXTURE_FORMAT_ARB
: {
2346 attr_v
= *piAttribList
;
2347 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2348 if (use_render_texture_ati
) {
2351 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2352 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2353 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2355 SetLastError(ERROR_INVALID_DATA
);
2358 object
->use_render_texture
= 1;
2359 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2361 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2362 object
->use_render_texture
= 0;
2364 if (!use_render_texture_emulation
) {
2365 SetLastError(ERROR_INVALID_DATA
);
2369 case WGL_TEXTURE_RGB_ARB
:
2370 object
->use_render_texture
= GL_RGB
;
2371 object
->texture_bpp
= 3;
2372 object
->texture_format
= GL_RGB
;
2373 object
->texture_type
= GL_UNSIGNED_BYTE
;
2375 case WGL_TEXTURE_RGBA_ARB
:
2376 object
->use_render_texture
= GL_RGBA
;
2377 object
->texture_bpp
= 4;
2378 object
->texture_format
= GL_RGBA
;
2379 object
->texture_type
= GL_UNSIGNED_BYTE
;
2382 /* WGL_FLOAT_COMPONENTS_NV */
2383 case WGL_TEXTURE_FLOAT_R_NV
:
2384 object
->use_render_texture
= GL_FLOAT_R_NV
;
2385 object
->texture_bpp
= 4;
2386 object
->texture_format
= GL_RED
;
2387 object
->texture_type
= GL_FLOAT
;
2389 case WGL_TEXTURE_FLOAT_RG_NV
:
2390 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2391 object
->texture_bpp
= 8;
2392 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2393 object
->texture_type
= GL_FLOAT
;
2395 case WGL_TEXTURE_FLOAT_RGB_NV
:
2396 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2397 object
->texture_bpp
= 12;
2398 object
->texture_format
= GL_RGB
;
2399 object
->texture_type
= GL_FLOAT
;
2401 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2402 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2403 object
->texture_bpp
= 16;
2404 object
->texture_format
= GL_RGBA
;
2405 object
->texture_type
= GL_FLOAT
;
2408 ERR("Unknown texture format: %x\n", attr_v
);
2409 SetLastError(ERROR_INVALID_DATA
);
2417 case WGL_TEXTURE_TARGET_ARB
: {
2419 attr_v
= *piAttribList
;
2420 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2421 if (use_render_texture_ati
) {
2424 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2425 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2426 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2427 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2429 SetLastError(ERROR_INVALID_DATA
);
2432 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2434 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2435 object
->texture_target
= 0;
2437 if (!use_render_texture_emulation
) {
2438 SetLastError(ERROR_INVALID_DATA
);
2442 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2443 if (iWidth
!= iHeight
) {
2444 SetLastError(ERROR_INVALID_DATA
);
2447 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2448 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2451 case WGL_TEXTURE_1D_ARB
: {
2453 SetLastError(ERROR_INVALID_DATA
);
2456 object
->texture_target
= GL_TEXTURE_1D
;
2457 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2460 case WGL_TEXTURE_2D_ARB
: {
2461 object
->texture_target
= GL_TEXTURE_2D
;
2462 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2465 case WGL_TEXTURE_RECTANGLE_NV
: {
2466 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2467 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2471 ERR("Unknown texture target: %x\n", attr_v
);
2472 SetLastError(ERROR_INVALID_DATA
);
2480 case WGL_MIPMAP_TEXTURE_ARB
: {
2482 attr_v
= *piAttribList
;
2483 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2484 if (use_render_texture_ati
) {
2485 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2487 if (!use_render_texture_emulation
) {
2488 SetLastError(ERROR_INVALID_DATA
);
2498 PUSH1(attribs
, None
);
2500 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2501 wine_tsx11_unlock();
2502 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2503 if (!object
->drawable
) {
2504 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2505 goto create_failed
; /* unexpected error */
2507 TRACE("->(%p)\n", object
);
2511 HeapFree(GetProcessHeap(), 0, object
);
2512 TRACE("->(FAILED)\n");
2517 * X11DRV_wglDestroyPbufferARB
2519 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2521 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2523 Wine_GLPBuffer
* object
= hPbuffer
;
2524 TRACE("(%p)\n", hPbuffer
);
2525 if (NULL
== object
) {
2526 SetLastError(ERROR_INVALID_HANDLE
);
2530 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2531 wine_tsx11_unlock();
2532 HeapFree(GetProcessHeap(), 0, object
);
2537 * X11DRV_wglGetPbufferDCARB
2539 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2540 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2541 * Gdi32 implements the part of this function which creates a device context.
2542 * This part associates the physDev with the X drawable of the pbuffer.
2544 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2546 Wine_GLPBuffer
* object
= hPbuffer
;
2547 if (NULL
== object
) {
2548 SetLastError(ERROR_INVALID_HANDLE
);
2552 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2553 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2554 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2555 physDev
->drawable
= object
->drawable
;
2556 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2557 physDev
->dc_rect
= physDev
->drawable_rect
;
2559 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2560 return physDev
->hdc
;
2564 * X11DRV_wglQueryPbufferARB
2566 * WGL_ARB_pbuffer: wglQueryPbufferARB
2568 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2570 Wine_GLPBuffer
* object
= hPbuffer
;
2571 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2572 if (NULL
== object
) {
2573 SetLastError(ERROR_INVALID_HANDLE
);
2576 switch (iAttribute
) {
2577 case WGL_PBUFFER_WIDTH_ARB
:
2579 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2580 wine_tsx11_unlock();
2582 case WGL_PBUFFER_HEIGHT_ARB
:
2584 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2585 wine_tsx11_unlock();
2588 case WGL_PBUFFER_LOST_ARB
:
2589 /* GLX Pbuffers cannot be lost by default. We can support this by
2590 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2591 * to receive pixel buffer clobber events, however that may or may
2592 * not give any benefit */
2593 *piValue
= GL_FALSE
;
2596 case WGL_TEXTURE_FORMAT_ARB
:
2597 if (use_render_texture_ati
) {
2599 int type
= WGL_NO_TEXTURE_ARB
;
2601 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2602 wine_tsx11_unlock();
2604 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2605 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2606 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2610 if (!object
->use_render_texture
) {
2611 *piValue
= WGL_NO_TEXTURE_ARB
;
2613 if (!use_render_texture_emulation
) {
2614 SetLastError(ERROR_INVALID_HANDLE
);
2617 switch(object
->use_render_texture
) {
2619 *piValue
= WGL_TEXTURE_RGB_ARB
;
2622 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2624 /* WGL_FLOAT_COMPONENTS_NV */
2626 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2628 case GL_FLOAT_RG_NV
:
2629 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2631 case GL_FLOAT_RGB_NV
:
2632 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2634 case GL_FLOAT_RGBA_NV
:
2635 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2638 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2644 case WGL_TEXTURE_TARGET_ARB
:
2645 if (use_render_texture_ati
) {
2647 int type
= WGL_NO_TEXTURE_ARB
;
2649 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2650 wine_tsx11_unlock();
2652 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2653 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2654 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2655 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2659 if (!object
->texture_target
) {
2660 *piValue
= WGL_NO_TEXTURE_ARB
;
2662 if (!use_render_texture_emulation
) {
2663 SetLastError(ERROR_INVALID_DATA
);
2666 switch (object
->texture_target
) {
2667 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2668 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2669 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2670 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2676 case WGL_MIPMAP_TEXTURE_ARB
:
2677 if (use_render_texture_ati
) {
2679 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2680 wine_tsx11_unlock();
2682 *piValue
= GL_FALSE
; /** don't support that */
2683 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2688 FIXME("unexpected attribute %x\n", iAttribute
);
2696 * X11DRV_wglReleasePbufferDCARB
2698 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2700 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2702 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2703 return DeleteDC(hdc
);
2707 * X11DRV_wglSetPbufferAttribARB
2709 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2711 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2713 Wine_GLPBuffer
* object
= hPbuffer
;
2714 GLboolean ret
= GL_FALSE
;
2716 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2717 if (NULL
== object
) {
2718 SetLastError(ERROR_INVALID_HANDLE
);
2721 if (!object
->use_render_texture
) {
2722 SetLastError(ERROR_INVALID_HANDLE
);
2725 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2728 if (NULL
!= pglXDrawableAttribATI
) {
2729 if (use_render_texture_ati
) {
2730 FIXME("Need conversion for GLX_ATI_render_texture\n");
2733 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2734 wine_tsx11_unlock();
2740 * X11DRV_wglChoosePixelFormatARB
2742 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2744 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2749 GLXFBConfig
* cfgs
= NULL
;
2753 WineGLPixelFormat
*fmt
;
2759 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2760 if (NULL
!= pfAttribFList
) {
2761 FIXME("unused pfAttribFList\n");
2764 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2765 if (-1 == nAttribs
) {
2766 WARN("Cannot convert WGL to GLX attributes\n");
2769 PUSH1(attribs
, None
);
2771 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2772 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2773 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2774 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2776 switch(piAttribIList
[i
])
2778 case WGL_DRAW_TO_BITMAP_ARB
:
2779 if(piAttribIList
[i
+1])
2780 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2782 case WGL_ACCELERATION_ARB
:
2783 switch(piAttribIList
[i
+1])
2785 case WGL_NO_ACCELERATION_ARB
:
2786 dwFlags
|= PFD_GENERIC_FORMAT
;
2788 case WGL_GENERIC_ACCELERATION_ARB
:
2789 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2791 case WGL_FULL_ACCELERATION_ARB
:
2796 case WGL_SUPPORT_GDI_ARB
:
2797 if(piAttribIList
[i
+1])
2798 dwFlags
|= PFD_SUPPORT_GDI
;
2803 /* Search for FB configurations matching the requirements in attribs */
2805 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2807 wine_tsx11_unlock();
2808 WARN("Compatible Pixel Format not found\n");
2812 /* Loop through all matching formats and check if they are suitable.
2813 * Note that this function should at max return nMaxFormats different formats */
2814 for(run
=0; run
< 2; run
++)
2816 for (it
= 0; it
< nCfgs
; ++it
) {
2817 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2819 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2823 /* Search for the format in our list of compatible formats */
2824 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2828 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2829 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2832 if(pfmt_it
< nMaxFormats
) {
2833 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2834 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2840 *nNumFormats
= pfmt_it
;
2843 wine_tsx11_unlock();
2848 * X11DRV_wglGetPixelFormatAttribivARB
2850 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2852 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2855 WineGLPixelFormat
*fmt
= NULL
;
2859 int nWGLFormats
= 0;
2861 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2863 if (0 < iLayerPlane
) {
2864 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2868 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2869 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2870 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2871 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2873 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2877 for (i
= 0; i
< nAttributes
; ++i
) {
2878 const int curWGLAttr
= piAttributes
[i
];
2879 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2881 switch (curWGLAttr
) {
2882 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2883 piValues
[i
] = nWGLFormats
;
2886 case WGL_SUPPORT_OPENGL_ARB
:
2887 piValues
[i
] = GL_TRUE
;
2890 case WGL_ACCELERATION_ARB
:
2891 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2892 if (!fmt
) goto pix_error
;
2893 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2894 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2895 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2896 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2898 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2901 case WGL_TRANSPARENT_ARB
:
2902 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2903 if (!fmt
) goto pix_error
;
2904 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2905 if (hTest
) goto get_error
;
2906 piValues
[i
] = GL_FALSE
;
2907 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2910 case WGL_PIXEL_TYPE_ARB
:
2911 curGLXAttr
= GLX_RENDER_TYPE
;
2912 if (!fmt
) goto pix_error
;
2913 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2914 if (hTest
) goto get_error
;
2915 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2916 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2917 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2918 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2919 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2920 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2922 ERR("unexpected RenderType(%x)\n", tmp
);
2923 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2927 case WGL_COLOR_BITS_ARB
:
2928 curGLXAttr
= GLX_BUFFER_SIZE
;
2931 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2932 if (use_render_texture_ati
) {
2933 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2936 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2937 if (use_render_texture_ati
) {
2938 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2941 if (!use_render_texture_emulation
) {
2942 piValues
[i
] = GL_FALSE
;
2945 curGLXAttr
= GLX_RENDER_TYPE
;
2946 if (!fmt
) goto pix_error
;
2947 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2948 if (hTest
) goto get_error
;
2949 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2950 piValues
[i
] = GL_FALSE
;
2953 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2954 if (hTest
) goto get_error
;
2955 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2958 case WGL_BLUE_BITS_ARB
:
2959 curGLXAttr
= GLX_BLUE_SIZE
;
2961 case WGL_RED_BITS_ARB
:
2962 curGLXAttr
= GLX_RED_SIZE
;
2964 case WGL_GREEN_BITS_ARB
:
2965 curGLXAttr
= GLX_GREEN_SIZE
;
2967 case WGL_ALPHA_BITS_ARB
:
2968 curGLXAttr
= GLX_ALPHA_SIZE
;
2970 case WGL_DEPTH_BITS_ARB
:
2971 curGLXAttr
= GLX_DEPTH_SIZE
;
2973 case WGL_STENCIL_BITS_ARB
:
2974 curGLXAttr
= GLX_STENCIL_SIZE
;
2976 case WGL_DOUBLE_BUFFER_ARB
:
2977 curGLXAttr
= GLX_DOUBLEBUFFER
;
2979 case WGL_STEREO_ARB
:
2980 curGLXAttr
= GLX_STEREO
;
2982 case WGL_AUX_BUFFERS_ARB
:
2983 curGLXAttr
= GLX_AUX_BUFFERS
;
2986 case WGL_SUPPORT_GDI_ARB
:
2987 if (!fmt
) goto pix_error
;
2988 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
2991 case WGL_DRAW_TO_BITMAP_ARB
:
2992 if (!fmt
) goto pix_error
;
2993 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
2996 case WGL_DRAW_TO_WINDOW_ARB
:
2997 case WGL_DRAW_TO_PBUFFER_ARB
:
2998 if (!fmt
) goto pix_error
;
2999 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
3000 if (hTest
) goto get_error
;
3001 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
3002 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
3003 piValues
[i
] = GL_TRUE
;
3005 piValues
[i
] = GL_FALSE
;
3008 case WGL_SWAP_METHOD_ARB
:
3009 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3010 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3011 * point only ATI offers this.
3013 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
3016 case WGL_PBUFFER_LARGEST_ARB
:
3017 curGLXAttr
= GLX_LARGEST_PBUFFER
;
3020 case WGL_SAMPLE_BUFFERS_ARB
:
3021 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
3024 case WGL_SAMPLES_ARB
:
3025 curGLXAttr
= GLX_SAMPLES_ARB
;
3028 case WGL_FLOAT_COMPONENTS_NV
:
3029 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
3032 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
3033 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
3036 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
3037 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
3040 case WGL_ACCUM_RED_BITS_ARB
:
3041 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
3043 case WGL_ACCUM_GREEN_BITS_ARB
:
3044 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
3046 case WGL_ACCUM_BLUE_BITS_ARB
:
3047 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
3049 case WGL_ACCUM_ALPHA_BITS_ARB
:
3050 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
3052 case WGL_ACCUM_BITS_ARB
:
3053 if (!fmt
) goto pix_error
;
3054 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
3055 if (hTest
) goto get_error
;
3057 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
3058 if (hTest
) goto get_error
;
3060 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
3061 if (hTest
) goto get_error
;
3063 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
3064 if (hTest
) goto get_error
;
3069 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
3072 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3073 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3074 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3076 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3077 * and check which options can work using iPixelFormat=0 and which not.
3078 * A problem would be that this function is an extension. This would
3079 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3081 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
3082 if (!fmt
) goto pix_error
;
3083 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
3084 if (hTest
) goto get_error
;
3087 piValues
[i
] = GL_FALSE
;
3090 wine_tsx11_unlock();
3094 wine_tsx11_unlock();
3095 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3099 wine_tsx11_unlock();
3100 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3105 * X11DRV_wglGetPixelFormatAttribfvARB
3107 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3109 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3115 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3117 /* Allocate a temporary array to store integer values */
3118 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3120 ERR("couldn't allocate %d array\n", nAttributes
);
3124 /* Piggy-back on wglGetPixelFormatAttribivARB */
3125 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3127 /* Convert integer values to float. Should also check for attributes
3128 that can give decimal values here */
3129 for (i
=0; i
<nAttributes
;i
++) {
3130 pfValues
[i
] = attr
[i
];
3134 HeapFree(GetProcessHeap(), 0, attr
);
3139 * X11DRV_wglBindTexImageARB
3141 * WGL_ARB_render_texture: wglBindTexImageARB
3143 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3145 Wine_GLPBuffer
* object
= hPbuffer
;
3146 GLboolean ret
= GL_FALSE
;
3148 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3149 if (NULL
== object
) {
3150 SetLastError(ERROR_INVALID_HANDLE
);
3153 if (!object
->use_render_texture
) {
3154 SetLastError(ERROR_INVALID_HANDLE
);
3158 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3159 static int init
= 0;
3160 int prev_binded_texture
= 0;
3161 GLXContext prev_context
;
3162 Drawable prev_drawable
;
3163 GLXContext tmp_context
;
3166 prev_context
= pglXGetCurrentContext();
3167 prev_drawable
= pglXGetCurrentDrawable();
3169 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3170 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3171 isn't ideal performance wise but I wasn't able to get other ways working.
3174 init
= 1; /* Only show the FIXME once for performance reasons */
3175 FIXME("partial stub!\n");
3178 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
3179 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3181 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3183 /* Switch to our pbuffer */
3184 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3186 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3187 * After that upload the pbuffer texture data. */
3188 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3189 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3191 /* Switch back to the original drawable and upload the pbuffer-texture */
3192 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3193 pglXDestroyContext(gdi_display
, tmp_context
);
3194 wine_tsx11_unlock();
3198 if (NULL
!= pglXBindTexImageATI
) {
3203 case WGL_FRONT_LEFT_ARB
:
3204 buffer
= GLX_FRONT_LEFT_ATI
;
3206 case WGL_FRONT_RIGHT_ARB
:
3207 buffer
= GLX_FRONT_RIGHT_ATI
;
3209 case WGL_BACK_LEFT_ARB
:
3210 buffer
= GLX_BACK_LEFT_ATI
;
3212 case WGL_BACK_RIGHT_ARB
:
3213 buffer
= GLX_BACK_RIGHT_ATI
;
3216 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3220 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3221 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3222 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3223 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3224 * works fine using our pbuffer emulation path.
3227 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3228 wine_tsx11_unlock();
3234 * X11DRV_wglReleaseTexImageARB
3236 * WGL_ARB_render_texture: wglReleaseTexImageARB
3238 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3240 Wine_GLPBuffer
* object
= hPbuffer
;
3241 GLboolean ret
= GL_FALSE
;
3243 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3244 if (NULL
== object
) {
3245 SetLastError(ERROR_INVALID_HANDLE
);
3248 if (!object
->use_render_texture
) {
3249 SetLastError(ERROR_INVALID_HANDLE
);
3252 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3255 if (NULL
!= pglXReleaseTexImageATI
) {
3260 case WGL_FRONT_LEFT_ARB
:
3261 buffer
= GLX_FRONT_LEFT_ATI
;
3263 case WGL_FRONT_RIGHT_ARB
:
3264 buffer
= GLX_FRONT_RIGHT_ATI
;
3266 case WGL_BACK_LEFT_ARB
:
3267 buffer
= GLX_BACK_LEFT_ATI
;
3269 case WGL_BACK_RIGHT_ARB
:
3270 buffer
= GLX_BACK_RIGHT_ATI
;
3273 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3277 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3278 wine_tsx11_unlock();
3284 * X11DRV_wglGetExtensionsStringEXT
3286 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3288 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3289 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3290 return WineGLInfo
.wglExtensions
;
3294 * X11DRV_wglGetSwapIntervalEXT
3296 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3298 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3299 FIXME("(),stub!\n");
3300 return swap_interval
;
3304 * X11DRV_wglSwapIntervalEXT
3306 * WGL_EXT_swap_control: wglSwapIntervalEXT
3308 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3311 TRACE("(%d)\n", interval
);
3312 swap_interval
= interval
;
3313 if (NULL
!= pglXSwapIntervalSGI
) {
3315 ret
= !pglXSwapIntervalSGI(interval
);
3316 wine_tsx11_unlock();
3318 else WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3323 * X11DRV_wglAllocateMemoryNV
3325 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3327 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3329 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3331 if (pglXAllocateMemoryNV
)
3334 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3335 wine_tsx11_unlock();
3341 * X11DRV_wglFreeMemoryNV
3343 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3345 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3346 TRACE("(%p)\n", pointer
);
3347 if (pglXFreeMemoryNV
== NULL
)
3351 pglXFreeMemoryNV(pointer
);
3352 wine_tsx11_unlock();
3356 * X11DRV_wglSetPixelFormatWINE
3358 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3359 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3361 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3363 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
3365 if (!has_opengl()) return FALSE
;
3367 if (physDev
->current_pf
== iPixelFormat
) return TRUE
;
3369 /* Relay to the core SetPixelFormat */
3370 TRACE("Changing iPixelFormat from %d to %d\n", physDev
->current_pf
, iPixelFormat
);
3371 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
3375 * glxRequireVersion (internal)
3377 * Check if the supported GLX version matches requiredVersion.
3379 static BOOL
glxRequireVersion(int requiredVersion
)
3381 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3382 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3388 static BOOL
glxRequireExtension(const char *requiredExtension
)
3390 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3397 static void register_extension_string(const char *ext
)
3399 if (WineGLInfo
.wglExtensions
[0])
3400 strcat(WineGLInfo
.wglExtensions
, " ");
3401 strcat(WineGLInfo
.wglExtensions
, ext
);
3403 TRACE("'%s'\n", ext
);
3406 static BOOL
register_extension(const WineGLExtension
* ext
)
3410 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3411 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3413 register_extension_string(ext
->extName
);
3415 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3416 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3421 static const WineGLExtension WGL_internal_functions
=
3425 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3426 { "wglFinish", X11DRV_wglFinish
},
3427 { "wglFlush", X11DRV_wglFlush
},
3432 static const WineGLExtension WGL_ARB_create_context
=
3434 "WGL_ARB_create_context",
3436 { "wglCreateContextAttribsARB", X11DRV_wglCreateContextAttribsARB
},
3440 static const WineGLExtension WGL_ARB_extensions_string
=
3442 "WGL_ARB_extensions_string",
3444 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3448 static const WineGLExtension WGL_ARB_make_current_read
=
3450 "WGL_ARB_make_current_read",
3452 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3453 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3457 static const WineGLExtension WGL_ARB_multisample
=
3459 "WGL_ARB_multisample",
3462 static const WineGLExtension WGL_ARB_pbuffer
=
3466 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3467 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3468 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3469 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3470 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3471 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3475 static const WineGLExtension WGL_ARB_pixel_format
=
3477 "WGL_ARB_pixel_format",
3479 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3480 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3481 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3485 static const WineGLExtension WGL_ARB_render_texture
=
3487 "WGL_ARB_render_texture",
3489 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3490 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3494 static const WineGLExtension WGL_EXT_extensions_string
=
3496 "WGL_EXT_extensions_string",
3498 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3502 static const WineGLExtension WGL_EXT_swap_control
=
3504 "WGL_EXT_swap_control",
3506 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3507 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3511 static const WineGLExtension WGL_NV_vertex_array_range
=
3513 "WGL_NV_vertex_array_range",
3515 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3516 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3520 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3522 "WGL_WINE_pixel_format_passthrough",
3524 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE
},
3529 * X11DRV_WineGL_LoadExtensions
3531 static void X11DRV_WineGL_LoadExtensions(void)
3533 WineGLInfo
.wglExtensions
[0] = 0;
3535 /* Load Wine internal functions */
3536 register_extension(&WGL_internal_functions
);
3538 /* ARB Extensions */
3540 if(glxRequireExtension("GLX_ARB_create_context"))
3542 register_extension(&WGL_ARB_create_context
);
3545 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3547 register_extension_string("WGL_ARB_pixel_format_float");
3548 register_extension_string("WGL_ATI_pixel_format_float");
3551 register_extension(&WGL_ARB_extensions_string
);
3553 if (glxRequireVersion(3))
3554 register_extension(&WGL_ARB_make_current_read
);
3556 if (glxRequireExtension("GLX_ARB_multisample"))
3557 register_extension(&WGL_ARB_multisample
);
3559 /* In general pbuffer functionality requires support in the X-server. The functionality is
3560 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3561 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3562 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3564 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3565 * without support in the X-server (which other Mesa based drivers require).
3567 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3568 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3569 * is available pbuffers must be available too. */
3570 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3571 register_extension(&WGL_ARB_pbuffer
);
3573 register_extension(&WGL_ARB_pixel_format
);
3575 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3576 if (glxRequireExtension("GLX_ATI_render_texture") ||
3577 glxRequireExtension("GLX_ARB_render_texture") ||
3578 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3580 register_extension(&WGL_ARB_render_texture
);
3582 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3583 if(glxRequireExtension("GLX_NV_float_buffer"))
3584 register_extension_string("WGL_NV_float_buffer");
3586 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3587 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3588 register_extension_string("WGL_NV_texture_rectangle");
3591 /* EXT Extensions */
3593 register_extension(&WGL_EXT_extensions_string
);
3595 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3596 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3597 register_extension(&WGL_EXT_swap_control
);
3599 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3600 register_extension_string("WGL_EXT_framebuffer_sRGB");
3602 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3603 register_extension_string("WGL_EXT_pixel_format_packed_float");
3605 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3606 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3607 register_extension(&WGL_NV_vertex_array_range
);
3609 /* WINE-specific WGL Extensions */
3611 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3612 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3614 register_extension(&WGL_WINE_pixel_format_passthrough
);
3618 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3624 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3625 ret
= physDev
->drawable
; /* PBuffer */
3627 ret
= physDev
->bitmap
->glxpixmap
;
3629 else if(physDev
->gl_drawable
)
3630 ret
= physDev
->gl_drawable
;
3632 ret
= physDev
->drawable
;
3636 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3639 pglXDestroyGLXPixmap(display
, glxpixmap
);
3640 wine_tsx11_unlock();
3645 * X11DRV_SwapBuffers
3647 * Swap the buffers of this DC
3649 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3651 GLXDrawable drawable
;
3652 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3654 if (!has_opengl()) return FALSE
;
3656 TRACE("(%p)\n", physDev
);
3658 drawable
= get_glxdrawable(physDev
);
3662 if(physDev
->pixmap
) {
3663 if(pglXCopySubBufferMESA
) {
3664 int w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
3665 int h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
3667 /* (glX)SwapBuffers has an implicit glFlush effect, however
3668 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3672 pglXCopySubBufferMESA(gdi_display
, drawable
, 0, 0, w
, h
);
3675 pglXSwapBuffers(gdi_display
, drawable
);
3678 pglXSwapBuffers(gdi_display
, drawable
);
3680 flush_gl_drawable(physDev
);
3681 wine_tsx11_unlock();
3686 static long prev_time
, start_time
;
3687 static unsigned long frames
, frames_total
;
3689 DWORD time
= GetTickCount();
3692 /* every 1.5 seconds */
3693 if (time
- prev_time
> 1500) {
3694 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3695 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3698 if(start_time
== 0) start_time
= time
;
3705 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3707 WineGLPixelFormat
*fmt
;
3710 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3715 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3716 wine_tsx11_unlock();
3720 #else /* no OpenGL includes */
3722 void X11DRV_OpenGL_Cleanup(void)
3726 static inline void opengl_error(void)
3729 if (!warned
++) ERR("No OpenGL support compiled in.\n");
3732 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3737 void mark_drawable_dirty(Drawable old
, Drawable
new)
3741 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
3745 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3750 /***********************************************************************
3751 * ChoosePixelFormat (X11DRV.@)
3753 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3754 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3759 /***********************************************************************
3760 * DescribePixelFormat (X11DRV.@)
3762 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3765 PIXELFORMATDESCRIPTOR
*ppfd
) {
3770 /***********************************************************************
3771 * GetPixelFormat (X11DRV.@)
3773 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3778 /***********************************************************************
3779 * SetPixelFormat (X11DRV.@)
3781 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3783 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3788 /***********************************************************************
3789 * SwapBuffers (X11DRV.@)
3791 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3797 * X11DRV_wglCopyContext
3799 * For OpenGL32 wglCopyContext.
3801 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
3807 * X11DRV_wglCreateContext
3809 * For OpenGL32 wglCreateContext.
3811 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3817 * X11DRV_wglCreateContextAttribsARB
3819 * WGL_ARB_create_context: wglCreateContextAttribsARB
3821 HGLRC
X11DRV_wglCreateContextAttribsARB(X11DRV_PDEVICE
*physDev
, HGLRC hShareContext
, const int* attribList
)
3828 * X11DRV_wglDeleteContext
3830 * For OpenGL32 wglDeleteContext.
3832 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3838 * X11DRV_wglGetProcAddress
3840 * For OpenGL32 wglGetProcAddress.
3842 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3847 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3853 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3859 * X11DRV_wglMakeCurrent
3861 * For OpenGL32 wglMakeCurrent.
3863 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3869 * X11DRV_wglShareLists
3871 * For OpenGL32 wglShareLists.
3873 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3879 * X11DRV_wglUseFontBitmapsA
3881 * For OpenGL32 wglUseFontBitmapsA.
3883 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3890 * X11DRV_wglUseFontBitmapsW
3892 * For OpenGL32 wglUseFontBitmapsW.
3894 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3901 * X11DRV_wglSetPixelFormatWINE
3903 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3904 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3906 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3912 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3917 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3922 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3927 #endif /* defined(HAVE_OPENGL) */