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
);
51 #ifdef HAVE_GL_GLEXT_H
52 # include <GL/glext.h>
61 /* Redefines the constants */
62 #define CALLBACK __stdcall
63 #define WINAPI __stdcall
64 #define APIENTRY WINAPI
67 WINE_DECLARE_DEBUG_CHANNEL(fps
);
69 typedef struct wine_glextension
{
78 const char *glVersion
;
83 const char *glxServerVersion
;
84 const char *glxServerVendor
;
85 const char *glxServerExtensions
;
87 const char *glxClientVersion
;
88 const char *glxClientVendor
;
89 const char *glxClientExtensions
;
91 const char *glxExtensions
;
94 char wglExtensions
[4096];
97 typedef struct wine_glpixelformat
{
103 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
106 typedef struct wine_glcontext
{
110 WineGLPixelFormat
*fmt
;
113 Drawable drawables
[2];
114 BOOL refresh_drawables
;
115 struct wine_glcontext
*next
;
116 struct wine_glcontext
*prev
;
119 typedef struct wine_glpbuffer
{
122 WineGLPixelFormat
* fmt
;
128 int use_render_texture
; /* This is also the internal texture format */
129 int texture_bind_target
;
131 GLint texture_format
;
132 GLuint texture_target
;
138 static Wine_GLContext
*context_list
;
139 static struct WineGLInfo WineGLInfo
= { 0 };
140 static int use_render_texture_emulation
= 1;
141 static int use_render_texture_ati
= 0;
142 static int swap_interval
= 1;
144 #define MAX_EXTENSIONS 16
145 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
146 static int WineGLExtensionListSize
;
148 static void X11DRV_WineGL_LoadExtensions(void);
149 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
150 static BOOL
glxRequireVersion(int requiredVersion
);
151 static BOOL
glxRequireExtension(const char *requiredExtension
);
153 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
154 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
155 TRACE(" - dwFlags : ");
156 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
157 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
158 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
159 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
160 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
161 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
162 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
163 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
164 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
165 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
166 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
173 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
174 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
175 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
179 TRACE(" - iPixelType : ");
180 switch (ppfd
->iPixelType
) {
181 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
182 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
186 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
187 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
188 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
189 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
190 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
191 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
192 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
193 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
194 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
196 TRACE(" - iLayerType : ");
197 switch (ppfd
->iLayerType
) {
198 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
199 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
200 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
205 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
206 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
208 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
210 MAKE_FUNCPTR(glXChooseVisual
)
211 MAKE_FUNCPTR(glXCopyContext
)
212 MAKE_FUNCPTR(glXCreateContext
)
213 MAKE_FUNCPTR(glXCreateGLXPixmap
)
214 MAKE_FUNCPTR(glXGetCurrentContext
)
215 MAKE_FUNCPTR(glXGetCurrentDrawable
)
216 MAKE_FUNCPTR(glXDestroyContext
)
217 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
218 MAKE_FUNCPTR(glXGetConfig
)
219 MAKE_FUNCPTR(glXIsDirect
)
220 MAKE_FUNCPTR(glXMakeCurrent
)
221 MAKE_FUNCPTR(glXSwapBuffers
)
222 MAKE_FUNCPTR(glXQueryExtension
)
223 MAKE_FUNCPTR(glXQueryVersion
)
224 MAKE_FUNCPTR(glXUseXFont
)
227 MAKE_FUNCPTR(glXGetClientString
)
228 MAKE_FUNCPTR(glXQueryExtensionsString
)
229 MAKE_FUNCPTR(glXQueryServerString
)
232 MAKE_FUNCPTR(glXGetFBConfigs
)
233 MAKE_FUNCPTR(glXChooseFBConfig
)
234 MAKE_FUNCPTR(glXCreatePbuffer
)
235 MAKE_FUNCPTR(glXCreateNewContext
)
236 MAKE_FUNCPTR(glXDestroyPbuffer
)
237 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
238 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
239 MAKE_FUNCPTR(glXMakeContextCurrent
)
240 MAKE_FUNCPTR(glXQueryDrawable
)
241 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
244 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
245 static int (*pglXSwapIntervalSGI
)(int);
247 /* ATI GLX Extensions */
248 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
249 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
250 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
252 /* NV GLX Extension */
253 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
254 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
256 /* MESA GLX Extensions */
257 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
259 /* Standard OpenGL */
260 MAKE_FUNCPTR(glBindTexture
)
261 MAKE_FUNCPTR(glBitmap
)
262 MAKE_FUNCPTR(glCopyTexSubImage1D
)
263 MAKE_FUNCPTR(glCopyTexImage2D
)
264 MAKE_FUNCPTR(glCopyTexSubImage2D
)
265 MAKE_FUNCPTR(glDrawBuffer
)
266 MAKE_FUNCPTR(glEndList
)
267 MAKE_FUNCPTR(glGetError
)
268 MAKE_FUNCPTR(glGetIntegerv
)
269 MAKE_FUNCPTR(glGetString
)
270 MAKE_FUNCPTR(glNewList
)
271 MAKE_FUNCPTR(glPixelStorei
)
272 MAKE_FUNCPTR(glReadPixels
)
273 MAKE_FUNCPTR(glTexImage2D
)
274 MAKE_FUNCPTR(glFinish
)
275 MAKE_FUNCPTR(glFlush
)
278 static BOOL infoInitialized
= FALSE
;
279 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
282 int screen
= DefaultScreen(gdi_display
);
283 Window win
= RootWindow(gdi_display
, screen
);
286 XVisualInfo
template;
289 GLXContext ctx
= NULL
;
293 infoInitialized
= TRUE
;
297 visual
= DefaultVisual(gdi_display
, screen
);
298 template.visualid
= XVisualIDFromVisual(visual
);
299 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
301 WORD old_fs
= wine_get_fs();
302 /* Create a GLX Context. Without one we can't query GL information */
303 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
304 if (wine_get_fs() != old_fs
)
306 wine_set_fs( old_fs
);
308 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
309 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
315 pglXMakeCurrent(gdi_display
, win
, ctx
);
317 ERR(" couldn't initialize OpenGL, expect problems\n");
322 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
323 str
= (const char *) pglGetString(GL_EXTENSIONS
);
324 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
325 strcpy(WineGLInfo
.glExtensions
, str
);
327 /* Get the common GLX version supported by GLX client and server ( major/minor) */
328 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
330 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
331 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
332 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
334 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
335 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
336 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
338 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
339 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
341 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
342 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
343 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
344 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
345 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
346 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
347 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
348 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
352 pglXMakeCurrent(gdi_display
, None
, NULL
);
353 pglXDestroyContext(gdi_display
, ctx
);
359 void X11DRV_OpenGL_Cleanup(void)
361 HeapFree(GetProcessHeap(), 0, WineGLInfo
.glExtensions
);
362 infoInitialized
= FALSE
;
365 static BOOL
has_opengl(void)
367 static int init_done
;
368 static void *opengl_handle
;
371 int error_base
, event_base
;
373 if (init_done
) return (opengl_handle
!= NULL
);
376 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
377 and include all dependencies */
378 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
379 if (opengl_handle
== NULL
)
381 ERR( "Failed to load libGL: %s\n", buffer
);
382 ERR( "OpenGL support is disabled.\n");
386 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
387 if (pglXGetProcAddressARB
== NULL
) {
388 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
392 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
394 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
399 LOAD_FUNCPTR(glXChooseVisual
);
400 LOAD_FUNCPTR(glXCopyContext
);
401 LOAD_FUNCPTR(glXCreateContext
);
402 LOAD_FUNCPTR(glXCreateGLXPixmap
);
403 LOAD_FUNCPTR(glXGetCurrentContext
);
404 LOAD_FUNCPTR(glXGetCurrentDrawable
);
405 LOAD_FUNCPTR(glXDestroyContext
);
406 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
407 LOAD_FUNCPTR(glXGetConfig
);
408 LOAD_FUNCPTR(glXIsDirect
);
409 LOAD_FUNCPTR(glXMakeCurrent
);
410 LOAD_FUNCPTR(glXSwapBuffers
);
411 LOAD_FUNCPTR(glXQueryExtension
);
412 LOAD_FUNCPTR(glXQueryVersion
);
413 LOAD_FUNCPTR(glXUseXFont
);
416 LOAD_FUNCPTR(glXGetClientString
);
417 LOAD_FUNCPTR(glXQueryExtensionsString
);
418 LOAD_FUNCPTR(glXQueryServerString
);
421 LOAD_FUNCPTR(glXCreatePbuffer
);
422 LOAD_FUNCPTR(glXCreateNewContext
);
423 LOAD_FUNCPTR(glXDestroyPbuffer
);
424 LOAD_FUNCPTR(glXMakeContextCurrent
);
425 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
426 LOAD_FUNCPTR(glXGetFBConfigs
);
428 /* Standard OpenGL calls */
429 LOAD_FUNCPTR(glBindTexture
);
430 LOAD_FUNCPTR(glBitmap
);
431 LOAD_FUNCPTR(glCopyTexSubImage1D
);
432 LOAD_FUNCPTR(glCopyTexImage2D
);
433 LOAD_FUNCPTR(glCopyTexSubImage2D
);
434 LOAD_FUNCPTR(glDrawBuffer
);
435 LOAD_FUNCPTR(glEndList
);
436 LOAD_FUNCPTR(glGetError
);
437 LOAD_FUNCPTR(glGetIntegerv
);
438 LOAD_FUNCPTR(glGetString
);
439 LOAD_FUNCPTR(glNewList
);
440 LOAD_FUNCPTR(glPixelStorei
);
441 LOAD_FUNCPTR(glReadPixels
);
442 LOAD_FUNCPTR(glTexImage2D
);
443 LOAD_FUNCPTR(glFinish
);
444 LOAD_FUNCPTR(glFlush
);
447 /* It doesn't matter if these fail. They'll only be used if the driver reports
448 the associated extension is available (and if a driver reports the extension
449 is available but fails to provide the functions, it's quite broken) */
450 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)
451 /* NV GLX Extension */
452 LOAD_FUNCPTR(glXAllocateMemoryNV
);
453 LOAD_FUNCPTR(glXFreeMemoryNV
);
456 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
459 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
460 TRACE("GLX is up and running error_base = %d\n", error_base
);
463 ERR( "GLX extension is missing, disabling OpenGL.\n" );
467 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
468 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
471 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
472 * depends on the reported GLX client / server version and on the client / server extension list.
473 * Those don't have to be the same.
475 * In general the server GLX information lists the capabilities in case of indirect rendering.
476 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
477 * available and in that case the client GLX informat can be used.
478 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
479 * in the GLX version/extension list. When a program does this it works for certain for both
480 * direct and indirect rendering.
482 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
483 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
484 * extension list which causes this extension not to be listed. (Wine requires this extension).
485 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
486 * pbuffers is around.
488 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
489 * the ATI drivers and from then on use GLX client information for them.
492 if(glxRequireVersion(3)) {
493 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
494 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
495 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
496 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
497 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
498 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
499 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
500 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
502 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
503 * enable this function when the Xserver understand GLX 1.3 or newer
505 pglXQueryDrawable
= NULL
;
506 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
507 TRACE("Overriding ATI GLX capabilities!\n");
508 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
509 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
510 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
511 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
513 /* Use client GLX information in case of the ATI drivers. We override the
514 * capabilities over here and not somewhere else as ATI might better their
515 * life in the future. In case they release proper drivers this block of
516 * code won't be called. */
517 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
519 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
522 if(glxRequireExtension("GLX_ATI_render_texture")) {
523 use_render_texture_ati
= 1;
524 pglXBindTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
525 pglXReleaseTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
526 pglXDrawableAttribATI
= pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
529 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
530 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
533 X11DRV_WineGL_LoadExtensions();
539 wine_dlclose(opengl_handle
, NULL
, 0);
540 opengl_handle
= NULL
;
544 static inline Wine_GLContext
*alloc_context(void)
548 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
550 ret
->next
= context_list
;
551 if (context_list
) context_list
->prev
= ret
;
557 static inline void free_context(Wine_GLContext
*context
)
559 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
560 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
561 else context_list
= context
->next
;
563 if (context
->vis
) XFree(context
->vis
);
564 HeapFree(GetProcessHeap(), 0, context
);
567 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
570 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
571 return (ptr
!= NULL
);
574 static int describeContext(Wine_GLContext
* ctx
) {
577 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
578 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
579 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
580 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
581 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
586 static BOOL
describeDrawable(X11DRV_PDEVICE
*physDev
) {
588 WineGLPixelFormat
*fmt
;
591 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
/* Offscreen */, &fmt_count
);
592 if(!fmt
) return FALSE
;
594 TRACE(" HDC %p has:\n", physDev
->hdc
);
595 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
596 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev
));
597 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
599 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
600 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
605 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
610 int nvfloatattrib
= GLX_DONT_CARE
;
613 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
614 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
615 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
616 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
618 switch (iWGLAttr
[cur
]) {
619 case WGL_AUX_BUFFERS_ARB
:
620 pop
= iWGLAttr
[++cur
];
621 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
622 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
624 case WGL_COLOR_BITS_ARB
:
625 pop
= iWGLAttr
[++cur
];
626 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
627 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
629 case WGL_BLUE_BITS_ARB
:
630 pop
= iWGLAttr
[++cur
];
631 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
632 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
634 case WGL_RED_BITS_ARB
:
635 pop
= iWGLAttr
[++cur
];
636 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
637 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
639 case WGL_GREEN_BITS_ARB
:
640 pop
= iWGLAttr
[++cur
];
641 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
642 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
644 case WGL_ALPHA_BITS_ARB
:
645 pop
= iWGLAttr
[++cur
];
646 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
647 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
649 case WGL_DEPTH_BITS_ARB
:
650 pop
= iWGLAttr
[++cur
];
651 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
652 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
654 case WGL_STENCIL_BITS_ARB
:
655 pop
= iWGLAttr
[++cur
];
656 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
657 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
659 case WGL_DOUBLE_BUFFER_ARB
:
660 pop
= iWGLAttr
[++cur
];
661 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
662 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
665 pop
= iWGLAttr
[++cur
];
666 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
667 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
670 case WGL_PIXEL_TYPE_ARB
:
671 pop
= iWGLAttr
[++cur
];
672 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
674 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
675 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
676 /* 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 */
677 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
678 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
680 ERR("unexpected PixelType(%x)\n", pop
);
685 case WGL_SUPPORT_GDI_ARB
:
686 /* This flag is set in a WineGLPixelFormat */
687 pop
= iWGLAttr
[++cur
];
688 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
691 case WGL_DRAW_TO_BITMAP_ARB
:
692 /* This flag is set in a WineGLPixelFormat */
693 pop
= iWGLAttr
[++cur
];
694 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
697 case WGL_DRAW_TO_WINDOW_ARB
:
698 pop
= iWGLAttr
[++cur
];
699 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
700 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
702 drawattrib
|= GLX_WINDOW_BIT
;
706 case WGL_DRAW_TO_PBUFFER_ARB
:
707 pop
= iWGLAttr
[++cur
];
708 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
709 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
711 drawattrib
|= GLX_PBUFFER_BIT
;
715 case WGL_ACCELERATION_ARB
:
716 /* This flag is set in a WineGLPixelFormat */
717 pop
= iWGLAttr
[++cur
];
718 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
721 case WGL_SUPPORT_OPENGL_ARB
:
722 pop
= iWGLAttr
[++cur
];
723 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
724 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
727 case WGL_SWAP_METHOD_ARB
:
728 pop
= iWGLAttr
[++cur
];
729 /* For now we ignore this and just return SWAP_EXCHANGE */
730 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
733 case WGL_PBUFFER_LARGEST_ARB
:
734 pop
= iWGLAttr
[++cur
];
735 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
736 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
739 case WGL_SAMPLE_BUFFERS_ARB
:
740 pop
= iWGLAttr
[++cur
];
741 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
742 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
745 case WGL_SAMPLES_ARB
:
746 pop
= iWGLAttr
[++cur
];
747 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
748 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
751 case WGL_TEXTURE_FORMAT_ARB
:
752 case WGL_TEXTURE_TARGET_ARB
:
753 case WGL_MIPMAP_TEXTURE_ARB
:
754 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
755 pop
= iWGLAttr
[++cur
];
757 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
759 if (use_render_texture_ati
) {
760 /** nothing to do here */
762 else if (!use_render_texture_emulation
) {
763 if (WGL_NO_TEXTURE_ARB
!= pop
) {
764 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
765 return -1; /** error: don't support it */
767 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
768 drawattrib
|= GLX_PBUFFER_BIT
;
772 case WGL_FLOAT_COMPONENTS_NV
:
773 nvfloatattrib
= iWGLAttr
[++cur
];
774 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
776 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
777 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
778 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
779 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
780 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
781 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
782 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
783 pop
= iWGLAttr
[++cur
];
784 /** cannot be converted, see direct handling on
785 * - wglGetPixelFormatAttribivARB
786 * TODO: wglChoosePixelFormat
789 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
790 pop
= iWGLAttr
[++cur
];
791 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
792 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
795 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
796 pop
= iWGLAttr
[++cur
];
797 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
798 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
801 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
807 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
808 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
809 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
810 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
812 /* Set GLX_RENDER_TYPE all the time */
813 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
814 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
816 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
817 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
818 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
819 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
825 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
827 int render_type
=0, render_type_bit
;
828 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
829 switch(render_type_bit
)
832 render_type
= GLX_RGBA_TYPE
;
834 case GLX_COLOR_INDEX_BIT
:
835 render_type
= GLX_COLOR_INDEX_TYPE
;
837 case GLX_RGBA_FLOAT_BIT
:
838 render_type
= GLX_RGBA_FLOAT_TYPE
;
840 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
841 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
844 ERR("Unknown render_type: %x\n", render_type
);
849 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
850 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
853 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
854 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
856 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
857 * the GLX_PIXMAP_BIT set. */
858 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
861 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
863 static WineGLPixelFormat
*list
;
864 static int size
, onscreen_size
;
866 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
868 XVisualInfo
*visinfo
;
873 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
874 if (NULL
== cfgs
|| 0 == nCfgs
) {
875 if(cfgs
!= NULL
) XFree(cfgs
);
877 ERR("glXChooseFBConfig returns NULL\n");
881 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
882 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
883 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
884 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
886 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
888 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
890 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
893 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
895 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
897 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
898 * Do this as GLX doesn't guarantee that the list is sorted */
899 for(run
=0; run
< 2; run
++)
901 for(i
=0; i
<nCfgs
; i
++) {
902 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
903 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
905 /* The first run we only add onscreen formats (ones which have an associated X Visual).
906 * The second run we only set offscreen formats. */
909 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
910 * The contents is copied to the destination using XCopyArea. For the copying to work
911 * the depth of the source and destination window should be the same. In general this should
912 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
913 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
914 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
915 * list formats with the same depth. */
916 if(visinfo
->depth
!= screen_depth
)
919 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
920 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
921 list
[size
].fbconfig
= cfgs
[i
];
922 list
[size
].fmt_id
= fmt_id
;
923 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
924 list
[size
].offscreenOnly
= FALSE
;
925 list
[size
].dwFlags
= 0;
929 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
930 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
932 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
933 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
934 list
[size
].fbconfig
= cfgs
[i
];
935 list
[size
].fmt_id
= fmt_id
;
936 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
937 list
[size
].offscreenOnly
= FALSE
;
938 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
944 } else if(run
&& !visinfo
) {
945 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
946 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
947 list
[size
].fbconfig
= cfgs
[i
];
948 list
[size
].fmt_id
= fmt_id
;
949 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
950 list
[size
].offscreenOnly
= TRUE
;
951 list
[size
].dwFlags
= 0;
957 if(cfgs
!= NULL
) XFree(cfgs
);
960 if (size_ret
) *size_ret
= size
;
961 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
966 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
967 * In our WGL implementation we only support a subset of these formats namely the format of
968 * Wine's main visual and offscreen formats (if they are available).
969 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
970 * and it returns the number of supported WGL formats in fmt_count.
972 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
974 WineGLPixelFormat
*list
, *res
= NULL
;
975 int size
, onscreen_size
;
977 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
979 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
980 * iPixelFormat in case of probing the number of pixelformats.
982 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
983 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
984 res
= &list
[iPixelFormat
-1];
985 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
991 *fmt_count
= onscreen_size
;
993 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
998 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
999 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
1001 WineGLPixelFormat
*list
;
1004 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1006 for(i
=0; i
<size
; i
++) {
1007 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1008 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1009 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1010 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1014 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1018 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1020 WineGLPixelFormat
*fmt
;
1022 if (!fbconfig_id
) return 0;
1024 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1026 return fmt
->iPixelFormat
;
1027 /* This will happen on hwnds without a pixel format set; it's ok */
1032 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1033 void mark_drawable_dirty(Drawable old
, Drawable
new)
1035 Wine_GLContext
*ctx
;
1036 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
1037 if (old
== ctx
->drawables
[0]) {
1038 ctx
->drawables
[0] = new;
1039 ctx
->refresh_drawables
= TRUE
;
1041 if (old
== ctx
->drawables
[1]) {
1042 ctx
->drawables
[1] = new;
1043 ctx
->refresh_drawables
= TRUE
;
1048 /* Given the current context, make sure its drawable is sync'd */
1049 static inline void sync_context(Wine_GLContext
*context
)
1051 if(context
&& context
->refresh_drawables
) {
1052 if (glxRequireVersion(3))
1053 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1054 context
->drawables
[1], context
->ctx
);
1056 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1057 context
->refresh_drawables
= FALSE
;
1062 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1066 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1067 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1070 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1071 else /* Create a GLX Context for a pbuffer */
1072 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1078 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1080 return pglXCreateGLXPixmap(display
, vis
, parent
);
1084 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1091 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1093 if(vis
->depth
== physDev
->bitmap
->pixmap_depth
)
1094 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1097 wine_tsx11_unlock();
1098 TRACE("return %lx\n", ret
);
1103 * X11DRV_ChoosePixelFormat
1105 * Equivalent to glXChooseVisual.
1107 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
1108 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1109 WineGLPixelFormat
*list
;
1114 int bestFormat
= -1;
1115 int bestDBuffer
= -1;
1116 int bestStereo
= -1;
1120 int bestStencil
= -1;
1123 if (!has_opengl()) return 0;
1125 if (TRACE_ON(wgl
)) {
1126 TRACE("(%p,%p)\n", physDev
, ppfd
);
1128 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1131 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1134 for(i
=0; i
<onscreen_size
; i
++)
1138 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1139 WineGLPixelFormat
*fmt
= &list
[i
];
1142 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1143 if (value
& GLX_RGBA_BIT
)
1144 iPixelType
= PFD_TYPE_RGBA
;
1146 iPixelType
= PFD_TYPE_COLORINDEX
;
1148 if (ppfd
->iPixelType
!= iPixelType
)
1150 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1154 /* Only use bitmap capable for formats for bitmap rendering.
1155 * See get_formats for more info. */
1156 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1158 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1162 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1163 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1164 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1165 if (value
) dwFlags
|= PFD_STEREO
;
1166 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1167 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1168 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1169 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1170 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1172 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1173 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1174 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1175 * formats without the given flag set.
1176 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1177 * has indicated that a format without stereo is returned when stereo is unavailable.
1178 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1179 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1181 * To summarize the following is most likely the correct behavior:
1182 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1183 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1184 * stereo don't care -> it doesn't matter whether we get stereo or not
1186 * In Wine we will treat no-stereo the same way as don't care because it makes
1187 * format selection even more complicated and second drivers with Stereo advertise
1188 * each format twice anyway.
1191 /* Doublebuffer, see the comments above */
1192 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1193 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1194 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1196 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1197 bestStereo
= dwFlags
& PFD_STEREO
;
1201 bestStencil
= stencil
;
1206 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1210 /* Stereo, see the comments above. */
1211 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1212 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1213 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1215 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1216 bestStereo
= dwFlags
& PFD_STEREO
;
1220 bestStencil
= stencil
;
1225 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1229 /* Below we will do a number of checks to select the 'best' pixelformat.
1230 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1231 * The code works by trying to match the most important options as close as possible.
1232 * When a reasonable format is found, we will try to match more options.
1233 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1234 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1235 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1238 if(ppfd
->cColorBits
) {
1239 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1240 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1242 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1243 bestStereo
= dwFlags
& PFD_STEREO
;
1247 bestStencil
= stencil
;
1251 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1252 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1258 if(ppfd
->cAlphaBits
) {
1259 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1260 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1262 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1263 bestStereo
= dwFlags
& PFD_STEREO
;
1267 bestStencil
= stencil
;
1271 } else if(bestAlpha
!= alpha
) {
1272 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1278 if(ppfd
->cDepthBits
) {
1279 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1280 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1282 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1283 bestStereo
= dwFlags
& PFD_STEREO
;
1287 bestStencil
= stencil
;
1291 } else if(bestDepth
!= depth
) {
1292 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1298 if(ppfd
->cStencilBits
) {
1299 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1300 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1302 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1303 bestStereo
= dwFlags
& PFD_STEREO
;
1307 bestStencil
= stencil
;
1311 } else if(bestStencil
!= stencil
) {
1312 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1318 if(ppfd
->cAuxBuffers
) {
1319 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1320 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1322 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1323 bestStereo
= dwFlags
& PFD_STEREO
;
1327 bestStencil
= stencil
;
1331 } else if(bestAux
!= aux
) {
1332 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1338 if(bestFormat
== -1) {
1339 TRACE("No matching mode was found returning 0\n");
1343 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1344 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1347 wine_tsx11_unlock();
1352 * X11DRV_DescribePixelFormat
1354 * Get the pixel-format descriptor associated to the given id
1356 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1359 PIXELFORMATDESCRIPTOR
*ppfd
) {
1360 /*XVisualInfo *vis;*/
1363 WineGLPixelFormat
*fmt
;
1367 if (!has_opengl()) return 0;
1369 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1371 /* 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 */
1372 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1374 /* The application is only querying the number of pixelformats */
1376 } else if(fmt
== NULL
) {
1377 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1381 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1382 ERR("Wrong structure size !\n");
1383 /* Should set error */
1389 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1390 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1393 /* These flags are always the same... */
1394 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1395 /* Now the flags extracted from the Visual */
1399 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1400 if(value
& GLX_WINDOW_BIT
)
1401 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1403 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1404 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1405 * 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
1406 * offered the GDI bit either. */
1407 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1409 /* PFD_GENERIC_FORMAT - gdi software rendering
1410 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1411 * none set - full hardware accelerated by a ICD
1413 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1414 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1416 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1418 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1419 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1421 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1424 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1425 if (value
& GLX_RGBA_BIT
)
1426 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1428 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1431 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1432 ppfd
->cColorBits
= value
;
1434 /* Red, green, blue and alpha bits / shifts */
1435 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1436 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1437 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1438 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1439 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1441 ppfd
->cRedBits
= rb
;
1442 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1443 ppfd
->cBlueBits
= bb
;
1444 ppfd
->cBlueShift
= ab
;
1445 ppfd
->cGreenBits
= gb
;
1446 ppfd
->cGreenShift
= bb
+ ab
;
1447 ppfd
->cAlphaBits
= ab
;
1448 ppfd
->cAlphaShift
= 0;
1451 ppfd
->cRedShift
= 0;
1452 ppfd
->cBlueBits
= 0;
1453 ppfd
->cBlueShift
= 0;
1454 ppfd
->cGreenBits
= 0;
1455 ppfd
->cGreenShift
= 0;
1456 ppfd
->cAlphaBits
= 0;
1457 ppfd
->cAlphaShift
= 0;
1460 /* Accum RGBA bits */
1461 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1462 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1463 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1464 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1466 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1467 ppfd
->cAccumRedBits
= rb
;
1468 ppfd
->cAccumGreenBits
= gb
;
1469 ppfd
->cAccumBlueBits
= bb
;
1470 ppfd
->cAccumAlphaBits
= ab
;
1473 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1474 ppfd
->cAuxBuffers
= value
;
1477 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1478 ppfd
->cDepthBits
= value
;
1481 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1482 ppfd
->cStencilBits
= value
;
1484 wine_tsx11_unlock();
1486 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1488 if (TRACE_ON(wgl
)) {
1489 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1496 * X11DRV_GetPixelFormat
1498 * Get the pixel-format id used by this DC
1500 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1501 WineGLPixelFormat
*fmt
;
1503 TRACE("(%p)\n", physDev
);
1505 if (!physDev
->current_pf
) return 0; /* not set yet */
1507 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1510 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1513 else if(fmt
->offscreenOnly
)
1515 /* Offscreen formats can't be used with traditional WGL calls.
1516 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1517 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1521 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1522 return physDev
->current_pf
;
1525 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1526 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1527 * set the pixel format multiple times. */
1528 static BOOL
internal_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1530 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1531 WineGLPixelFormat
*fmt
;
1535 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1536 if(get_glxdrawable(physDev
) == root_window
)
1538 ERR("Invalid operation on root_window\n");
1542 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1543 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1545 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1550 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1551 wine_tsx11_unlock();
1553 hwnd
= WindowFromDC(physDev
->hdc
);
1555 if(!(value
&GLX_WINDOW_BIT
)) {
1556 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1560 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, (WPARAM
)fmt
->fmt_id
, 0)) {
1561 ERR("Couldn't set format of the window, returning failure\n");
1565 else if(physDev
->bitmap
) {
1566 if(!(value
&GLX_PIXMAP_BIT
)) {
1567 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1571 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
, fmt
);
1572 if(!physDev
->bitmap
->glxpixmap
) {
1573 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1578 FIXME("called on a non-window, non-bitmap object?\n");
1581 physDev
->current_pf
= iPixelFormat
;
1583 if (TRACE_ON(wgl
)) {
1587 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1589 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1591 TRACE(" FBConfig have :\n");
1592 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1593 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1594 TRACE(" - VISUAL_ID 0x%x\n", value
);
1595 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1596 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1598 wine_tsx11_unlock();
1605 * X11DRV_SetPixelFormat
1607 * Set the pixel-format id used by this DC
1609 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1611 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1612 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1614 if (!has_opengl()) return FALSE
;
1616 if(physDev
->current_pf
) /* cannot change it if already set */
1617 return (physDev
->current_pf
== iPixelFormat
);
1619 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
1623 * X11DRV_wglCopyContext
1625 * For OpenGL32 wglCopyContext.
1627 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
1628 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1629 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1631 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1633 /* There is a slight difference in the way GL contexts share display lists in WGL and GLX.
1634 * In case of GLX you need to specify this at context creation time but in case of WGL you
1635 * do this using wglShareLists which you can call after creating the context.
1636 * To emulate WGL we try to delay the creation of the context until wglShareLists or wglMakeCurrent.
1637 * Up to now that works fine.
1639 * The delayed GLX context creation could cause issues for wglCopyContext as it might get called
1640 * when there is no GLX context yet. The chance this will cause problems is small as at the time of
1641 * writing Wine has had OpenGL support for more than 7 years and this function has remained a stub
1644 if(!src
->ctx
|| !dst
->ctx
) {
1645 /* NOTE: As a special case, if both GLX contexts are NULL, that means
1646 * neither WGL context was made current. In that case, both contexts
1647 * are in a default state, so any copy would no-op.
1649 if(!src
->ctx
&& !dst
->ctx
) {
1650 TRACE("No source or destination contexts set. No-op.\n");
1656 src
->ctx
= create_glxcontext(gdi_display
, src
, NULL
);
1657 TRACE(" created a delayed OpenGL context (%p)\n", src
->ctx
);
1659 else if (!dst
->ctx
) {
1661 dst
->ctx
= create_glxcontext(gdi_display
, dst
, NULL
);
1662 TRACE(" created a delayed OpenGL context (%p)\n", dst
->ctx
);
1668 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1669 wine_tsx11_unlock();
1671 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1676 * X11DRV_wglCreateContext
1678 * For OpenGL32 wglCreateContext.
1680 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1682 Wine_GLContext
*ret
;
1683 WineGLPixelFormat
*fmt
;
1684 int hdcPF
= physDev
->current_pf
;
1686 HDC hdc
= physDev
->hdc
;
1688 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1690 if (!has_opengl()) return 0;
1692 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1693 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1694 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1695 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1696 * If this fails something is very wrong on the system. */
1698 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1699 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1703 /* The context will be allocated in the wglMakeCurrent call */
1705 ret
= alloc_context();
1706 wine_tsx11_unlock();
1711 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1713 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1718 * X11DRV_wglDeleteContext
1720 * For OpenGL32 wglDeleteContext.
1722 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1724 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1727 TRACE("(%p)\n", hglrc
);
1729 if (!has_opengl()) return 0;
1732 /* A game (Half Life not to name it) deletes twice the same context,
1733 * so make sure it is valid first */
1734 if (is_valid_context( ctx
))
1736 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1741 WARN("Error deleting context !\n");
1742 SetLastError(ERROR_INVALID_HANDLE
);
1745 wine_tsx11_unlock();
1751 * X11DRV_wglGetCurrentReadDCARB
1753 * For OpenGL32 wglGetCurrentReadDCARB.
1755 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1758 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1760 if (ctx
) ret
= ctx
->read_hdc
;
1762 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1767 * X11DRV_wglGetProcAddress
1769 * For OpenGL32 wglGetProcAddress.
1771 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1774 const WineGLExtension
*ext
;
1776 int padding
= 32 - strlen(lpszProc
);
1780 if (!has_opengl()) return NULL
;
1782 /* Check the table of WGL extensions to see if we need to return a WGL extension
1783 * or a function pointer to a native OpenGL function. */
1784 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1785 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1787 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1788 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1789 ext
= WineGLExtensionList
[i
];
1790 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1791 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1792 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1793 return ext
->extEntryPoints
[j
].funcAddress
;
1799 WARN("(%s) - not found\n", lpszProc
);
1804 * X11DRV_wglMakeCurrent
1806 * For OpenGL32 wglMakeCurrent.
1808 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1810 HDC hdc
= physDev
->hdc
;
1811 DWORD type
= GetObjectType(hdc
);
1812 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1814 TRACE("(%p,%p)\n", hdc
, hglrc
);
1816 if (!has_opengl()) return FALSE
;
1819 if (hglrc
== NULL
) {
1820 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1821 NtCurrentTeb()->glContext
= NULL
;
1822 } else if (ctx
->fmt
->iPixelFormat
!= physDev
->current_pf
) {
1823 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1824 hdc
, physDev
->current_pf
, ctx
, ctx
->fmt
->iPixelFormat
);
1825 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1828 Drawable drawable
= get_glxdrawable(physDev
);
1829 if (ctx
->ctx
== NULL
) {
1830 /* The describe lines below are for debugging purposes only */
1831 if (TRACE_ON(wgl
)) {
1832 describeDrawable(physDev
);
1833 describeContext(ctx
);
1836 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1837 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1839 TRACE(" Creating GLX Context\n");
1840 ctx
->ctx
= create_glxcontext(gdi_display
, ctx
, NULL
);
1841 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1843 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1844 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1845 NtCurrentTeb()->glContext
= ctx
;
1849 ctx
->read_hdc
= hdc
;
1850 ctx
->drawables
[0] = drawable
;
1851 ctx
->drawables
[1] = drawable
;
1852 ctx
->refresh_drawables
= FALSE
;
1854 if (type
== OBJ_MEMDC
)
1856 ctx
->do_escape
= TRUE
;
1857 pglDrawBuffer(GL_FRONT_LEFT
);
1861 wine_tsx11_unlock();
1862 TRACE(" returning %s\n", (ret
? "True" : "False"));
1867 * X11DRV_wglMakeContextCurrentARB
1869 * For OpenGL32 wglMakeContextCurrentARB
1871 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1875 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1877 if (!has_opengl()) return 0;
1880 if (hglrc
== NULL
) {
1881 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1882 NtCurrentTeb()->glContext
= NULL
;
1884 if (NULL
== pglXMakeContextCurrent
) {
1887 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1888 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1889 Drawable d_read
= get_glxdrawable(pReadDev
);
1891 if (ctx
->ctx
== NULL
) {
1892 ctx
->ctx
= create_glxcontext(gdi_display
, ctx
, NULL
);
1893 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1895 ctx
->hdc
= pDrawDev
->hdc
;
1896 ctx
->read_hdc
= pReadDev
->hdc
;
1897 ctx
->drawables
[0] = d_draw
;
1898 ctx
->drawables
[1] = d_read
;
1899 ctx
->refresh_drawables
= FALSE
;
1900 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1901 NtCurrentTeb()->glContext
= ctx
;
1904 wine_tsx11_unlock();
1906 TRACE(" returning %s\n", (ret
? "True" : "False"));
1911 * X11DRV_wglShareLists
1913 * For OpenGL32 wglShareLists.
1915 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1916 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1917 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1919 TRACE("(%p, %p)\n", org
, dest
);
1921 if (!has_opengl()) return FALSE
;
1923 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1924 ERR("Could not share display lists, context already created !\n");
1927 if(org
&& dest
&& (GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
)) {
1928 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1931 if (org
->ctx
== NULL
) {
1933 describeContext(org
);
1935 org
->ctx
= create_glxcontext(gdi_display
, org
, NULL
);
1936 wine_tsx11_unlock();
1937 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1941 describeContext(dest
);
1942 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1943 wine_tsx11_unlock();
1944 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1951 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1953 /* We are running using client-side rendering fonts... */
1955 unsigned int glyph
, size
= 0;
1956 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1960 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1961 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1962 wine_tsx11_unlock();
1964 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1965 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
1966 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
1967 unsigned int height
, width_int
;
1969 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1970 if (needed_size
== GDI_ERROR
) {
1971 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1974 TRACE(" - needed size : %d\n", needed_size
);
1977 if (needed_size
> size
) {
1979 HeapFree(GetProcessHeap(), 0, bitmap
);
1980 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1981 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1982 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1984 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
1986 if (TRACE_ON(wgl
)) {
1987 unsigned int height
, width
, bitmask
;
1988 unsigned char *bitmap_
= bitmap
;
1990 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1991 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1992 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1993 if (needed_size
!= 0) {
1994 TRACE(" - bitmap :\n");
1995 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1997 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
2002 if (*bitmap_
& bitmask
)
2007 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2013 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2014 * glyph for it to be drawn properly.
2016 if (needed_size
!= 0) {
2017 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2018 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2020 for (width
= 0; width
< width_int
; width
++) {
2021 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2022 ((int *) bitmap
)[height
* width_int
+ width
];
2028 pglNewList(listBase
++, GL_COMPILE
);
2029 if (needed_size
!= 0) {
2030 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2031 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2032 gm
.gmCellIncX
, gm
.gmCellIncY
,
2035 /* This is the case of 'empty' glyphs like the space character */
2036 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2039 wine_tsx11_unlock();
2043 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2044 wine_tsx11_unlock();
2046 HeapFree(GetProcessHeap(), 0, bitmap
);
2047 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2052 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2053 wine_tsx11_unlock();
2055 HeapFree(GetProcessHeap(), 0, bitmap
);
2056 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2061 * X11DRV_wglUseFontBitmapsA
2063 * For OpenGL32 wglUseFontBitmapsA.
2065 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2067 Font fid
= physDev
->font
;
2069 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2071 if (!has_opengl()) return FALSE
;
2074 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2078 /* I assume that the glyphs are at the same position for X and for Windows */
2079 pglXUseXFont(fid
, first
, count
, listBase
);
2080 wine_tsx11_unlock();
2085 * X11DRV_wglUseFontBitmapsW
2087 * For OpenGL32 wglUseFontBitmapsW.
2089 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2091 Font fid
= physDev
->font
;
2093 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2095 if (!has_opengl()) return FALSE
;
2098 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2101 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2104 /* I assume that the glyphs are at the same position for X and for Windows */
2105 pglXUseXFont(fid
, first
, count
, listBase
);
2106 wine_tsx11_unlock();
2110 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2111 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2118 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2120 pglGetIntegerv(pname
, params
);
2122 * if we cannot find a Wine Context
2123 * we only have the default wine desktop context,
2124 * so if we have only a 24 depth say we have 32
2126 if (!ctx
&& *params
== 24) {
2129 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2134 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2136 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2137 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2141 pglGetIntegerv(pname
, params
);
2144 wine_tsx11_unlock();
2147 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
2151 if (!physDev
->gl_copy
)
2154 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
2155 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
2157 if(w
> 0 && h
> 0) {
2158 Drawable src
= physDev
->pixmap
;
2159 if(!src
) src
= physDev
->gl_drawable
;
2161 /* The GL drawable may be lagged behind if we don't flush first, so
2162 * flush the display make sure we copy up-to-date data */
2164 XFlush(gdi_display
);
2165 XSetFunction(gdi_display
, physDev
->gc
, GXcopy
);
2166 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
2167 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
2168 wine_tsx11_unlock();
2173 static void WINAPI
X11DRV_wglFinish(void)
2175 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2176 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2181 wine_tsx11_unlock();
2182 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2185 static void WINAPI
X11DRV_wglFlush(void)
2187 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2188 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2193 wine_tsx11_unlock();
2194 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2198 * X11DRV_wglGetExtensionsStringARB
2200 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2202 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2203 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2204 return WineGLInfo
.wglExtensions
;
2208 * X11DRV_wglCreatePbufferARB
2210 * WGL_ARB_pbuffer: wglCreatePbufferARB
2212 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2214 Wine_GLPBuffer
* object
= NULL
;
2215 WineGLPixelFormat
*fmt
= NULL
;
2220 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2222 if (0 >= iPixelFormat
) {
2223 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2224 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2225 return NULL
; /* unexpected error */
2228 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2229 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2231 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2232 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2233 goto create_failed
; /* unexpected error */
2236 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2237 if (NULL
== object
) {
2238 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2239 goto create_failed
; /* unexpected error */
2242 object
->display
= gdi_display
;
2243 object
->width
= iWidth
;
2244 object
->height
= iHeight
;
2247 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2248 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2249 while (piAttribList
&& 0 != *piAttribList
) {
2251 switch (*piAttribList
) {
2252 case WGL_PBUFFER_LARGEST_ARB
: {
2254 attr_v
= *piAttribList
;
2255 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2256 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2260 case WGL_TEXTURE_FORMAT_ARB
: {
2262 attr_v
= *piAttribList
;
2263 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2264 if (use_render_texture_ati
) {
2267 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2268 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2269 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2271 SetLastError(ERROR_INVALID_DATA
);
2274 object
->use_render_texture
= 1;
2275 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2277 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2278 object
->use_render_texture
= 0;
2280 if (!use_render_texture_emulation
) {
2281 SetLastError(ERROR_INVALID_DATA
);
2285 case WGL_TEXTURE_RGB_ARB
:
2286 object
->use_render_texture
= GL_RGB
;
2287 object
->texture_bpp
= 3;
2288 object
->texture_format
= GL_RGB
;
2289 object
->texture_type
= GL_UNSIGNED_BYTE
;
2291 case WGL_TEXTURE_RGBA_ARB
:
2292 object
->use_render_texture
= GL_RGBA
;
2293 object
->texture_bpp
= 4;
2294 object
->texture_format
= GL_RGBA
;
2295 object
->texture_type
= GL_UNSIGNED_BYTE
;
2298 /* WGL_FLOAT_COMPONENTS_NV */
2299 case WGL_TEXTURE_FLOAT_R_NV
:
2300 object
->use_render_texture
= GL_FLOAT_R_NV
;
2301 object
->texture_bpp
= 4;
2302 object
->texture_format
= GL_RED
;
2303 object
->texture_type
= GL_FLOAT
;
2305 case WGL_TEXTURE_FLOAT_RG_NV
:
2306 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2307 object
->texture_bpp
= 8;
2308 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2309 object
->texture_type
= GL_FLOAT
;
2311 case WGL_TEXTURE_FLOAT_RGB_NV
:
2312 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2313 object
->texture_bpp
= 12;
2314 object
->texture_format
= GL_RGB
;
2315 object
->texture_type
= GL_FLOAT
;
2317 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2318 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2319 object
->texture_bpp
= 16;
2320 object
->texture_format
= GL_RGBA
;
2321 object
->texture_type
= GL_FLOAT
;
2324 ERR("Unknown texture format: %x\n", attr_v
);
2325 SetLastError(ERROR_INVALID_DATA
);
2333 case WGL_TEXTURE_TARGET_ARB
: {
2335 attr_v
= *piAttribList
;
2336 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2337 if (use_render_texture_ati
) {
2340 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2341 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2342 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2343 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2345 SetLastError(ERROR_INVALID_DATA
);
2348 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2350 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2351 object
->texture_target
= 0;
2353 if (!use_render_texture_emulation
) {
2354 SetLastError(ERROR_INVALID_DATA
);
2358 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2359 if (iWidth
!= iHeight
) {
2360 SetLastError(ERROR_INVALID_DATA
);
2363 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2364 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2367 case WGL_TEXTURE_1D_ARB
: {
2369 SetLastError(ERROR_INVALID_DATA
);
2372 object
->texture_target
= GL_TEXTURE_1D
;
2373 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2376 case WGL_TEXTURE_2D_ARB
: {
2377 object
->texture_target
= GL_TEXTURE_2D
;
2378 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2381 case WGL_TEXTURE_RECTANGLE_NV
: {
2382 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2383 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2387 ERR("Unknown texture target: %x\n", attr_v
);
2388 SetLastError(ERROR_INVALID_DATA
);
2396 case WGL_MIPMAP_TEXTURE_ARB
: {
2398 attr_v
= *piAttribList
;
2399 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2400 if (use_render_texture_ati
) {
2401 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2403 if (!use_render_texture_emulation
) {
2404 SetLastError(ERROR_INVALID_DATA
);
2414 PUSH1(attribs
, None
);
2416 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2417 wine_tsx11_unlock();
2418 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2419 if (!object
->drawable
) {
2420 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2421 goto create_failed
; /* unexpected error */
2423 TRACE("->(%p)\n", object
);
2427 HeapFree(GetProcessHeap(), 0, object
);
2428 TRACE("->(FAILED)\n");
2433 * X11DRV_wglDestroyPbufferARB
2435 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2437 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2439 Wine_GLPBuffer
* object
= hPbuffer
;
2440 TRACE("(%p)\n", hPbuffer
);
2441 if (NULL
== object
) {
2442 SetLastError(ERROR_INVALID_HANDLE
);
2446 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2447 wine_tsx11_unlock();
2448 HeapFree(GetProcessHeap(), 0, object
);
2453 * X11DRV_wglGetPbufferDCARB
2455 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2456 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2457 * Gdi32 implements the part of this function which creates a device context.
2458 * This part associates the physDev with the X drawable of the pbuffer.
2460 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2462 Wine_GLPBuffer
* object
= hPbuffer
;
2463 if (NULL
== object
) {
2464 SetLastError(ERROR_INVALID_HANDLE
);
2468 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2469 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2470 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2471 physDev
->drawable
= object
->drawable
;
2472 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2473 physDev
->dc_rect
= physDev
->drawable_rect
;
2475 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2476 return physDev
->hdc
;
2480 * X11DRV_wglQueryPbufferARB
2482 * WGL_ARB_pbuffer: wglQueryPbufferARB
2484 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2486 Wine_GLPBuffer
* object
= hPbuffer
;
2487 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2488 if (NULL
== object
) {
2489 SetLastError(ERROR_INVALID_HANDLE
);
2492 switch (iAttribute
) {
2493 case WGL_PBUFFER_WIDTH_ARB
:
2495 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2496 wine_tsx11_unlock();
2498 case WGL_PBUFFER_HEIGHT_ARB
:
2500 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2501 wine_tsx11_unlock();
2504 case WGL_PBUFFER_LOST_ARB
:
2505 /* GLX Pbuffers cannot be lost by default. We can support this by
2506 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2507 * to receive pixel buffer clobber events, however that may or may
2508 * not give any benefit */
2509 *piValue
= GL_FALSE
;
2512 case WGL_TEXTURE_FORMAT_ARB
:
2513 if (use_render_texture_ati
) {
2515 int type
= WGL_NO_TEXTURE_ARB
;
2517 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2518 wine_tsx11_unlock();
2520 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2521 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2522 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2526 if (!object
->use_render_texture
) {
2527 *piValue
= WGL_NO_TEXTURE_ARB
;
2529 if (!use_render_texture_emulation
) {
2530 SetLastError(ERROR_INVALID_HANDLE
);
2533 switch(object
->use_render_texture
) {
2535 *piValue
= WGL_TEXTURE_RGB_ARB
;
2538 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2540 /* WGL_FLOAT_COMPONENTS_NV */
2542 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2544 case GL_FLOAT_RG_NV
:
2545 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2547 case GL_FLOAT_RGB_NV
:
2548 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2550 case GL_FLOAT_RGBA_NV
:
2551 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2554 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2560 case WGL_TEXTURE_TARGET_ARB
:
2561 if (use_render_texture_ati
) {
2563 int type
= WGL_NO_TEXTURE_ARB
;
2565 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2566 wine_tsx11_unlock();
2568 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2569 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2570 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2571 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2575 if (!object
->texture_target
) {
2576 *piValue
= WGL_NO_TEXTURE_ARB
;
2578 if (!use_render_texture_emulation
) {
2579 SetLastError(ERROR_INVALID_DATA
);
2582 switch (object
->texture_target
) {
2583 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2584 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2585 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2586 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2592 case WGL_MIPMAP_TEXTURE_ARB
:
2593 if (use_render_texture_ati
) {
2595 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2596 wine_tsx11_unlock();
2598 *piValue
= GL_FALSE
; /** don't support that */
2599 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2604 FIXME("unexpected attribute %x\n", iAttribute
);
2612 * X11DRV_wglReleasePbufferDCARB
2614 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2616 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2618 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2619 return DeleteDC(hdc
);
2623 * X11DRV_wglSetPbufferAttribARB
2625 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2627 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2629 Wine_GLPBuffer
* object
= hPbuffer
;
2630 GLboolean ret
= GL_FALSE
;
2632 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2633 if (NULL
== object
) {
2634 SetLastError(ERROR_INVALID_HANDLE
);
2637 if (!object
->use_render_texture
) {
2638 SetLastError(ERROR_INVALID_HANDLE
);
2641 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2644 if (NULL
!= pglXDrawableAttribATI
) {
2645 if (use_render_texture_ati
) {
2646 FIXME("Need conversion for GLX_ATI_render_texture\n");
2649 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2650 wine_tsx11_unlock();
2656 * X11DRV_wglChoosePixelFormatARB
2658 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2660 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2665 GLXFBConfig
* cfgs
= NULL
;
2669 WineGLPixelFormat
*fmt
;
2675 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2676 if (NULL
!= pfAttribFList
) {
2677 FIXME("unused pfAttribFList\n");
2680 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2681 if (-1 == nAttribs
) {
2682 WARN("Cannot convert WGL to GLX attributes\n");
2685 PUSH1(attribs
, None
);
2687 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2688 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2689 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2690 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2692 switch(piAttribIList
[i
])
2694 case WGL_DRAW_TO_BITMAP_ARB
:
2695 if(piAttribIList
[i
+1])
2696 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2698 case WGL_ACCELERATION_ARB
:
2699 switch(piAttribIList
[i
+1])
2701 case WGL_NO_ACCELERATION_ARB
:
2702 dwFlags
|= PFD_GENERIC_FORMAT
;
2704 case WGL_GENERIC_ACCELERATION_ARB
:
2705 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2707 case WGL_FULL_ACCELERATION_ARB
:
2712 case WGL_SUPPORT_GDI_ARB
:
2713 if(piAttribIList
[i
+1])
2714 dwFlags
|= PFD_SUPPORT_GDI
;
2719 /* Search for FB configurations matching the requirements in attribs */
2721 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2723 wine_tsx11_unlock();
2724 WARN("Compatible Pixel Format not found\n");
2728 /* Loop through all matching formats and check if they are suitable.
2729 * Note that this function should at max return nMaxFormats different formats */
2730 for(run
=0; run
< 2; run
++)
2732 for (it
= 0; it
< nCfgs
; ++it
) {
2733 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2735 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2739 /* Search for the format in our list of compatible formats */
2740 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2744 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2745 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2748 if(pfmt_it
< nMaxFormats
) {
2749 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2750 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2756 *nNumFormats
= pfmt_it
;
2759 wine_tsx11_unlock();
2764 * X11DRV_wglGetPixelFormatAttribivARB
2766 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2768 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2771 WineGLPixelFormat
*fmt
= NULL
;
2775 int nWGLFormats
= 0;
2777 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2779 if (0 < iLayerPlane
) {
2780 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2784 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2785 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2786 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2787 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2789 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2793 for (i
= 0; i
< nAttributes
; ++i
) {
2794 const int curWGLAttr
= piAttributes
[i
];
2795 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2797 switch (curWGLAttr
) {
2798 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2799 piValues
[i
] = nWGLFormats
;
2802 case WGL_SUPPORT_OPENGL_ARB
:
2803 piValues
[i
] = GL_TRUE
;
2806 case WGL_ACCELERATION_ARB
:
2807 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2808 if (!fmt
) goto pix_error
;
2809 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2810 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2811 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2812 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2814 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2817 case WGL_TRANSPARENT_ARB
:
2818 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2819 if (!fmt
) goto pix_error
;
2820 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2821 if (hTest
) goto get_error
;
2822 piValues
[i
] = GL_FALSE
;
2823 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2826 case WGL_PIXEL_TYPE_ARB
:
2827 curGLXAttr
= GLX_RENDER_TYPE
;
2828 if (!fmt
) goto pix_error
;
2829 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2830 if (hTest
) goto get_error
;
2831 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2832 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2833 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2834 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2835 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2836 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2838 ERR("unexpected RenderType(%x)\n", tmp
);
2839 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2843 case WGL_COLOR_BITS_ARB
:
2844 curGLXAttr
= GLX_BUFFER_SIZE
;
2847 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2848 if (use_render_texture_ati
) {
2849 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2852 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2853 if (use_render_texture_ati
) {
2854 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2857 if (!use_render_texture_emulation
) {
2858 piValues
[i
] = GL_FALSE
;
2861 curGLXAttr
= GLX_RENDER_TYPE
;
2862 if (!fmt
) goto pix_error
;
2863 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2864 if (hTest
) goto get_error
;
2865 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2866 piValues
[i
] = GL_FALSE
;
2869 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2870 if (hTest
) goto get_error
;
2871 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2874 case WGL_BLUE_BITS_ARB
:
2875 curGLXAttr
= GLX_BLUE_SIZE
;
2877 case WGL_RED_BITS_ARB
:
2878 curGLXAttr
= GLX_RED_SIZE
;
2880 case WGL_GREEN_BITS_ARB
:
2881 curGLXAttr
= GLX_GREEN_SIZE
;
2883 case WGL_ALPHA_BITS_ARB
:
2884 curGLXAttr
= GLX_ALPHA_SIZE
;
2886 case WGL_DEPTH_BITS_ARB
:
2887 curGLXAttr
= GLX_DEPTH_SIZE
;
2889 case WGL_STENCIL_BITS_ARB
:
2890 curGLXAttr
= GLX_STENCIL_SIZE
;
2892 case WGL_DOUBLE_BUFFER_ARB
:
2893 curGLXAttr
= GLX_DOUBLEBUFFER
;
2895 case WGL_STEREO_ARB
:
2896 curGLXAttr
= GLX_STEREO
;
2898 case WGL_AUX_BUFFERS_ARB
:
2899 curGLXAttr
= GLX_AUX_BUFFERS
;
2902 case WGL_SUPPORT_GDI_ARB
:
2903 if (!fmt
) goto pix_error
;
2904 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
2907 case WGL_DRAW_TO_BITMAP_ARB
:
2908 if (!fmt
) goto pix_error
;
2909 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
2912 case WGL_DRAW_TO_WINDOW_ARB
:
2913 case WGL_DRAW_TO_PBUFFER_ARB
:
2914 if (!fmt
) goto pix_error
;
2915 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2916 if (hTest
) goto get_error
;
2917 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2918 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2919 piValues
[i
] = GL_TRUE
;
2921 piValues
[i
] = GL_FALSE
;
2924 case WGL_SWAP_METHOD_ARB
:
2925 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2926 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2927 * point only ATI offers this.
2929 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2932 case WGL_PBUFFER_LARGEST_ARB
:
2933 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2936 case WGL_SAMPLE_BUFFERS_ARB
:
2937 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2940 case WGL_SAMPLES_ARB
:
2941 curGLXAttr
= GLX_SAMPLES_ARB
;
2944 case WGL_FLOAT_COMPONENTS_NV
:
2945 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2948 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
2949 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
2952 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
2953 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
2956 case WGL_ACCUM_RED_BITS_ARB
:
2957 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2959 case WGL_ACCUM_GREEN_BITS_ARB
:
2960 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2962 case WGL_ACCUM_BLUE_BITS_ARB
:
2963 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2965 case WGL_ACCUM_ALPHA_BITS_ARB
:
2966 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2968 case WGL_ACCUM_BITS_ARB
:
2969 if (!fmt
) goto pix_error
;
2970 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2971 if (hTest
) goto get_error
;
2973 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2974 if (hTest
) goto get_error
;
2976 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2977 if (hTest
) goto get_error
;
2979 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2980 if (hTest
) goto get_error
;
2985 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2988 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2989 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2990 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2992 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2993 * and check which options can work using iPixelFormat=0 and which not.
2994 * A problem would be that this function is an extension. This would
2995 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2997 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2998 if (!fmt
) goto pix_error
;
2999 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
3000 if (hTest
) goto get_error
;
3003 piValues
[i
] = GL_FALSE
;
3006 wine_tsx11_unlock();
3010 wine_tsx11_unlock();
3011 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3015 wine_tsx11_unlock();
3016 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3021 * X11DRV_wglGetPixelFormatAttribfvARB
3023 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3025 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3031 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3033 /* Allocate a temporary array to store integer values */
3034 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3036 ERR("couldn't allocate %d array\n", nAttributes
);
3040 /* Piggy-back on wglGetPixelFormatAttribivARB */
3041 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3043 /* Convert integer values to float. Should also check for attributes
3044 that can give decimal values here */
3045 for (i
=0; i
<nAttributes
;i
++) {
3046 pfValues
[i
] = attr
[i
];
3050 HeapFree(GetProcessHeap(), 0, attr
);
3055 * X11DRV_wglBindTexImageARB
3057 * WGL_ARB_render_texture: wglBindTexImageARB
3059 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3061 Wine_GLPBuffer
* object
= hPbuffer
;
3062 GLboolean ret
= GL_FALSE
;
3064 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3065 if (NULL
== object
) {
3066 SetLastError(ERROR_INVALID_HANDLE
);
3069 if (!object
->use_render_texture
) {
3070 SetLastError(ERROR_INVALID_HANDLE
);
3074 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3075 static int init
= 0;
3076 int prev_binded_texture
= 0;
3077 GLXContext prev_context
;
3078 Drawable prev_drawable
;
3079 GLXContext tmp_context
;
3082 prev_context
= pglXGetCurrentContext();
3083 prev_drawable
= pglXGetCurrentDrawable();
3085 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3086 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3087 isn't ideal performance wise but I wasn't able to get other ways working.
3090 init
= 1; /* Only show the FIXME once for performance reasons */
3091 FIXME("partial stub!\n");
3094 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
3095 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3097 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3099 /* Switch to our pbuffer */
3100 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3102 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3103 * After that upload the pbuffer texture data. */
3104 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3105 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3107 /* Switch back to the original drawable and upload the pbuffer-texture */
3108 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3109 pglXDestroyContext(gdi_display
, tmp_context
);
3110 wine_tsx11_unlock();
3114 if (NULL
!= pglXBindTexImageATI
) {
3119 case WGL_FRONT_LEFT_ARB
:
3120 buffer
= GLX_FRONT_LEFT_ATI
;
3122 case WGL_FRONT_RIGHT_ARB
:
3123 buffer
= GLX_FRONT_RIGHT_ATI
;
3125 case WGL_BACK_LEFT_ARB
:
3126 buffer
= GLX_BACK_LEFT_ATI
;
3128 case WGL_BACK_RIGHT_ARB
:
3129 buffer
= GLX_BACK_RIGHT_ATI
;
3132 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3136 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3137 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3138 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3139 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3140 * works fine using our pbuffer emulation path.
3143 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3144 wine_tsx11_unlock();
3150 * X11DRV_wglReleaseTexImageARB
3152 * WGL_ARB_render_texture: wglReleaseTexImageARB
3154 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3156 Wine_GLPBuffer
* object
= hPbuffer
;
3157 GLboolean ret
= GL_FALSE
;
3159 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3160 if (NULL
== object
) {
3161 SetLastError(ERROR_INVALID_HANDLE
);
3164 if (!object
->use_render_texture
) {
3165 SetLastError(ERROR_INVALID_HANDLE
);
3168 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3171 if (NULL
!= pglXReleaseTexImageATI
) {
3176 case WGL_FRONT_LEFT_ARB
:
3177 buffer
= GLX_FRONT_LEFT_ATI
;
3179 case WGL_FRONT_RIGHT_ARB
:
3180 buffer
= GLX_FRONT_RIGHT_ATI
;
3182 case WGL_BACK_LEFT_ARB
:
3183 buffer
= GLX_BACK_LEFT_ATI
;
3185 case WGL_BACK_RIGHT_ARB
:
3186 buffer
= GLX_BACK_RIGHT_ATI
;
3189 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3193 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3194 wine_tsx11_unlock();
3200 * X11DRV_wglGetExtensionsStringEXT
3202 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3204 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3205 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3206 return WineGLInfo
.wglExtensions
;
3210 * X11DRV_wglGetSwapIntervalEXT
3212 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3214 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3215 FIXME("(),stub!\n");
3216 return swap_interval
;
3220 * X11DRV_wglSwapIntervalEXT
3222 * WGL_EXT_swap_control: wglSwapIntervalEXT
3224 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3227 TRACE("(%d)\n", interval
);
3228 swap_interval
= interval
;
3229 if (NULL
!= pglXSwapIntervalSGI
) {
3231 ret
= !pglXSwapIntervalSGI(interval
);
3232 wine_tsx11_unlock();
3234 else WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3239 * X11DRV_wglAllocateMemoryNV
3241 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3243 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3245 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3247 if (pglXAllocateMemoryNV
)
3250 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3251 wine_tsx11_unlock();
3257 * X11DRV_wglFreeMemoryNV
3259 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3261 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3262 TRACE("(%p)\n", pointer
);
3263 if (pglXFreeMemoryNV
== NULL
)
3267 pglXFreeMemoryNV(pointer
);
3268 wine_tsx11_unlock();
3272 * X11DRV_wglSetPixelFormatWINE
3274 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3275 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3277 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3279 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
3281 if (!has_opengl()) return FALSE
;
3283 if (physDev
->current_pf
== iPixelFormat
) return TRUE
;
3285 /* Relay to the core SetPixelFormat */
3286 TRACE("Changing iPixelFormat from %d to %d\n", physDev
->current_pf
, iPixelFormat
);
3287 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
3291 * glxRequireVersion (internal)
3293 * Check if the supported GLX version matches requiredVersion.
3295 static BOOL
glxRequireVersion(int requiredVersion
)
3297 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3298 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3304 static BOOL
glxRequireExtension(const char *requiredExtension
)
3306 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3313 static void register_extension_string(const char *ext
)
3315 if (WineGLInfo
.wglExtensions
[0])
3316 strcat(WineGLInfo
.wglExtensions
, " ");
3317 strcat(WineGLInfo
.wglExtensions
, ext
);
3319 TRACE("'%s'\n", ext
);
3322 static BOOL
register_extension(const WineGLExtension
* ext
)
3326 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3327 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3329 register_extension_string(ext
->extName
);
3331 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3332 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3337 static const WineGLExtension WGL_internal_functions
=
3341 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3342 { "wglFinish", X11DRV_wglFinish
},
3343 { "wglFlush", X11DRV_wglFlush
},
3348 static const WineGLExtension WGL_ARB_extensions_string
=
3350 "WGL_ARB_extensions_string",
3352 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3356 static const WineGLExtension WGL_ARB_make_current_read
=
3358 "WGL_ARB_make_current_read",
3360 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3361 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3365 static const WineGLExtension WGL_ARB_multisample
=
3367 "WGL_ARB_multisample",
3370 static const WineGLExtension WGL_ARB_pbuffer
=
3374 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3375 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3376 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3377 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3378 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3379 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3383 static const WineGLExtension WGL_ARB_pixel_format
=
3385 "WGL_ARB_pixel_format",
3387 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3388 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3389 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3393 static const WineGLExtension WGL_ARB_render_texture
=
3395 "WGL_ARB_render_texture",
3397 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3398 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3402 static const WineGLExtension WGL_EXT_extensions_string
=
3404 "WGL_EXT_extensions_string",
3406 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3410 static const WineGLExtension WGL_EXT_swap_control
=
3412 "WGL_EXT_swap_control",
3414 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3415 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3419 static const WineGLExtension WGL_NV_vertex_array_range
=
3421 "WGL_NV_vertex_array_range",
3423 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3424 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3428 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3430 "WGL_WINE_pixel_format_passthrough",
3432 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE
},
3437 * X11DRV_WineGL_LoadExtensions
3439 static void X11DRV_WineGL_LoadExtensions(void)
3441 WineGLInfo
.wglExtensions
[0] = 0;
3443 /* Load Wine internal functions */
3444 register_extension(&WGL_internal_functions
);
3446 /* ARB Extensions */
3448 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3450 register_extension_string("WGL_ARB_pixel_format_float");
3451 register_extension_string("WGL_ATI_pixel_format_float");
3454 register_extension(&WGL_ARB_extensions_string
);
3456 if (glxRequireVersion(3))
3457 register_extension(&WGL_ARB_make_current_read
);
3459 if (glxRequireExtension("GLX_ARB_multisample"))
3460 register_extension(&WGL_ARB_multisample
);
3462 /* In general pbuffer functionality requires support in the X-server. The functionality is
3463 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3464 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3465 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3467 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3468 * without support in the X-server (which other Mesa based drivers require).
3470 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3471 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3472 * is available pbuffers must be available too. */
3473 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3474 register_extension(&WGL_ARB_pbuffer
);
3476 register_extension(&WGL_ARB_pixel_format
);
3478 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3479 if (glxRequireExtension("GLX_ATI_render_texture") ||
3480 glxRequireExtension("GLX_ARB_render_texture") ||
3481 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3483 register_extension(&WGL_ARB_render_texture
);
3485 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3486 if(glxRequireExtension("GLX_NV_float_buffer"))
3487 register_extension_string("WGL_NV_float_buffer");
3489 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3490 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3491 register_extension_string("WGL_NV_texture_rectangle");
3494 /* EXT Extensions */
3496 register_extension(&WGL_EXT_extensions_string
);
3498 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3499 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3500 register_extension(&WGL_EXT_swap_control
);
3502 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3503 register_extension_string("WGL_EXT_framebuffer_sRGB");
3505 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3506 register_extension_string("WGL_EXT_pixel_format_packed_float");
3508 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3509 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3510 register_extension(&WGL_NV_vertex_array_range
);
3512 /* WINE-specific WGL Extensions */
3514 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3515 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3517 register_extension(&WGL_WINE_pixel_format_passthrough
);
3521 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3527 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3528 ret
= physDev
->drawable
; /* PBuffer */
3530 ret
= physDev
->bitmap
->glxpixmap
;
3532 else if(physDev
->gl_drawable
)
3533 ret
= physDev
->gl_drawable
;
3535 ret
= physDev
->drawable
;
3539 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3542 pglXDestroyGLXPixmap(display
, glxpixmap
);
3543 wine_tsx11_unlock();
3548 * X11DRV_SwapBuffers
3550 * Swap the buffers of this DC
3552 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3554 GLXDrawable drawable
;
3555 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3557 if (!has_opengl()) return FALSE
;
3559 TRACE("(%p)\n", physDev
);
3561 drawable
= get_glxdrawable(physDev
);
3565 if(physDev
->pixmap
) {
3566 if(pglXCopySubBufferMESA
) {
3567 int w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
3568 int h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
3570 /* (glX)SwapBuffers has an implicit glFlush effect, however
3571 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3575 pglXCopySubBufferMESA(gdi_display
, drawable
, 0, 0, w
, h
);
3578 pglXSwapBuffers(gdi_display
, drawable
);
3581 pglXSwapBuffers(gdi_display
, drawable
);
3583 flush_gl_drawable(physDev
);
3584 wine_tsx11_unlock();
3589 static long prev_time
, start_time
;
3590 static unsigned long frames
, frames_total
;
3592 DWORD time
= GetTickCount();
3595 /* every 1.5 seconds */
3596 if (time
- prev_time
> 1500) {
3597 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3598 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3601 if(start_time
== 0) start_time
= time
;
3608 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3610 WineGLPixelFormat
*fmt
;
3613 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3618 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3619 wine_tsx11_unlock();
3623 #else /* no OpenGL includes */
3625 void X11DRV_OpenGL_Cleanup(void)
3629 static inline void opengl_error(void)
3632 if (!warned
++) ERR("No OpenGL support compiled in.\n");
3635 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3640 void mark_drawable_dirty(Drawable old
, Drawable
new)
3644 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
3648 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3653 /***********************************************************************
3654 * ChoosePixelFormat (X11DRV.@)
3656 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3657 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3662 /***********************************************************************
3663 * DescribePixelFormat (X11DRV.@)
3665 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3668 PIXELFORMATDESCRIPTOR
*ppfd
) {
3673 /***********************************************************************
3674 * GetPixelFormat (X11DRV.@)
3676 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3681 /***********************************************************************
3682 * SetPixelFormat (X11DRV.@)
3684 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3686 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3691 /***********************************************************************
3692 * SwapBuffers (X11DRV.@)
3694 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3700 * X11DRV_wglCopyContext
3702 * For OpenGL32 wglCopyContext.
3704 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
3710 * X11DRV_wglCreateContext
3712 * For OpenGL32 wglCreateContext.
3714 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3720 * X11DRV_wglDeleteContext
3722 * For OpenGL32 wglDeleteContext.
3724 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3730 * X11DRV_wglGetProcAddress
3732 * For OpenGL32 wglGetProcAddress.
3734 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3739 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3745 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3751 * X11DRV_wglMakeCurrent
3753 * For OpenGL32 wglMakeCurrent.
3755 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3761 * X11DRV_wglShareLists
3763 * For OpenGL32 wglShareLists.
3765 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3771 * X11DRV_wglUseFontBitmapsA
3773 * For OpenGL32 wglUseFontBitmapsA.
3775 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3782 * X11DRV_wglUseFontBitmapsW
3784 * For OpenGL32 wglUseFontBitmapsW.
3786 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3793 * X11DRV_wglSetPixelFormatWINE
3795 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3796 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3798 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3804 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3809 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3814 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3819 #endif /* defined(HAVE_OPENGL) */