2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
58 /* Redefines the constants */
59 #define CALLBACK __stdcall
60 #define WINAPI __stdcall
61 #define APIENTRY WINAPI
64 WINE_DECLARE_DEBUG_CHANNEL(fps
);
66 typedef struct wine_glextension
{
75 const char *glVersion
;
80 const char *glxServerVersion
;
81 const char *glxServerVendor
;
82 const char *glxServerExtensions
;
84 const char *glxClientVersion
;
85 const char *glxClientVendor
;
86 const char *glxClientExtensions
;
88 const char *glxExtensions
;
91 char wglExtensions
[4096];
94 typedef struct wine_glpixelformat
{
100 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
103 typedef struct wine_glcontext
{
107 WineGLPixelFormat
*fmt
;
110 Drawable drawables
[2];
111 BOOL refresh_drawables
;
112 struct wine_glcontext
*next
;
113 struct wine_glcontext
*prev
;
116 typedef struct wine_glpbuffer
{
119 WineGLPixelFormat
* fmt
;
125 int use_render_texture
; /* This is also the internal texture format */
126 int texture_bind_target
;
128 GLint texture_format
;
129 GLuint texture_target
;
135 static Wine_GLContext
*context_list
;
136 static struct WineGLInfo WineGLInfo
= { 0 };
137 static int use_render_texture_emulation
= 1;
138 static int use_render_texture_ati
= 0;
139 static int swap_interval
= 1;
141 #define MAX_EXTENSIONS 16
142 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
143 static int WineGLExtensionListSize
;
145 static void X11DRV_WineGL_LoadExtensions(void);
146 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
);
147 static BOOL
glxRequireVersion(int requiredVersion
);
148 static BOOL
glxRequireExtension(const char *requiredExtension
);
150 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
151 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
152 TRACE(" - dwFlags : ");
153 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
154 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
155 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
156 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
157 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
158 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
159 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
160 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
161 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
162 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
163 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
164 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
165 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
166 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
170 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
171 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
176 TRACE(" - iPixelType : ");
177 switch (ppfd
->iPixelType
) {
178 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
179 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
183 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
184 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
185 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
186 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
187 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
188 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
189 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
190 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
191 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
193 TRACE(" - iLayerType : ");
194 switch (ppfd
->iLayerType
) {
195 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
196 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
197 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
202 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
203 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
205 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
207 MAKE_FUNCPTR(glXChooseVisual
)
208 MAKE_FUNCPTR(glXCopyContext
)
209 MAKE_FUNCPTR(glXCreateContext
)
210 MAKE_FUNCPTR(glXCreateGLXPixmap
)
211 MAKE_FUNCPTR(glXGetCurrentContext
)
212 MAKE_FUNCPTR(glXGetCurrentDrawable
)
213 MAKE_FUNCPTR(glXDestroyContext
)
214 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
215 MAKE_FUNCPTR(glXGetConfig
)
216 MAKE_FUNCPTR(glXIsDirect
)
217 MAKE_FUNCPTR(glXMakeCurrent
)
218 MAKE_FUNCPTR(glXSwapBuffers
)
219 MAKE_FUNCPTR(glXQueryExtension
)
220 MAKE_FUNCPTR(glXQueryVersion
)
221 MAKE_FUNCPTR(glXUseXFont
)
224 MAKE_FUNCPTR(glXGetClientString
)
225 MAKE_FUNCPTR(glXQueryExtensionsString
)
226 MAKE_FUNCPTR(glXQueryServerString
)
229 MAKE_FUNCPTR(glXGetFBConfigs
)
230 MAKE_FUNCPTR(glXChooseFBConfig
)
231 MAKE_FUNCPTR(glXCreatePbuffer
)
232 MAKE_FUNCPTR(glXCreateNewContext
)
233 MAKE_FUNCPTR(glXDestroyPbuffer
)
234 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
235 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
236 MAKE_FUNCPTR(glXMakeContextCurrent
)
237 MAKE_FUNCPTR(glXQueryDrawable
)
238 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
241 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
242 static int (*pglXSwapIntervalSGI
)(int);
244 /* ATI GLX Extensions */
245 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
246 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
247 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
249 /* NV GLX Extension */
250 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
251 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
253 /* MESA GLX Extensions */
254 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
256 /* Standard OpenGL */
257 MAKE_FUNCPTR(glBindTexture
)
258 MAKE_FUNCPTR(glBitmap
)
259 MAKE_FUNCPTR(glCopyTexSubImage1D
)
260 MAKE_FUNCPTR(glCopyTexImage2D
)
261 MAKE_FUNCPTR(glCopyTexSubImage2D
)
262 MAKE_FUNCPTR(glDrawBuffer
)
263 MAKE_FUNCPTR(glEndList
)
264 MAKE_FUNCPTR(glGetError
)
265 MAKE_FUNCPTR(glGetIntegerv
)
266 MAKE_FUNCPTR(glGetString
)
267 MAKE_FUNCPTR(glNewList
)
268 MAKE_FUNCPTR(glPixelStorei
)
269 MAKE_FUNCPTR(glReadPixels
)
270 MAKE_FUNCPTR(glTexImage2D
)
271 MAKE_FUNCPTR(glFinish
)
272 MAKE_FUNCPTR(glFlush
)
275 static BOOL infoInitialized
= FALSE
;
276 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
278 int screen
= DefaultScreen(gdi_display
);
279 Window win
= RootWindow(gdi_display
, screen
);
282 GLXContext ctx
= NULL
;
283 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
287 infoInitialized
= TRUE
;
291 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
293 WORD old_fs
= wine_get_fs();
294 /* Create a GLX Context. Without one we can't query GL information */
295 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
296 if (wine_get_fs() != old_fs
)
298 wine_set_fs( old_fs
);
300 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
301 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
307 pglXMakeCurrent(gdi_display
, win
, ctx
);
309 ERR(" couldn't initialize OpenGL, expect problems\n");
314 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
315 str
= (const char *) pglGetString(GL_EXTENSIONS
);
316 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
317 strcpy(WineGLInfo
.glExtensions
, str
);
319 /* Get the common GLX version supported by GLX client and server ( major/minor) */
320 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
322 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
323 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
324 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
326 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
327 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
328 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
330 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
331 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
333 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
334 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
335 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
336 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
337 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
338 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
339 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
340 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
344 pglXMakeCurrent(gdi_display
, None
, NULL
);
345 pglXDestroyContext(gdi_display
, ctx
);
351 void X11DRV_OpenGL_Cleanup(void)
353 HeapFree(GetProcessHeap(), 0, WineGLInfo
.glExtensions
);
354 infoInitialized
= FALSE
;
357 static BOOL
has_opengl(void)
359 static int init_done
;
360 static void *opengl_handle
;
363 int error_base
, event_base
;
365 if (init_done
) return (opengl_handle
!= NULL
);
368 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
369 and include all dependencies */
370 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
371 if (opengl_handle
== NULL
)
373 ERR( "Failed to load libGL: %s\n", buffer
);
374 ERR( "OpenGL support is disabled.\n");
378 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
379 if (pglXGetProcAddressARB
== NULL
) {
380 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
384 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
386 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
391 LOAD_FUNCPTR(glXChooseVisual
);
392 LOAD_FUNCPTR(glXCopyContext
);
393 LOAD_FUNCPTR(glXCreateContext
);
394 LOAD_FUNCPTR(glXCreateGLXPixmap
);
395 LOAD_FUNCPTR(glXGetCurrentContext
);
396 LOAD_FUNCPTR(glXGetCurrentDrawable
);
397 LOAD_FUNCPTR(glXDestroyContext
);
398 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
399 LOAD_FUNCPTR(glXGetConfig
);
400 LOAD_FUNCPTR(glXIsDirect
);
401 LOAD_FUNCPTR(glXMakeCurrent
);
402 LOAD_FUNCPTR(glXSwapBuffers
);
403 LOAD_FUNCPTR(glXQueryExtension
);
404 LOAD_FUNCPTR(glXQueryVersion
);
405 LOAD_FUNCPTR(glXUseXFont
);
408 LOAD_FUNCPTR(glXGetClientString
);
409 LOAD_FUNCPTR(glXQueryExtensionsString
);
410 LOAD_FUNCPTR(glXQueryServerString
);
413 LOAD_FUNCPTR(glXCreatePbuffer
);
414 LOAD_FUNCPTR(glXCreateNewContext
);
415 LOAD_FUNCPTR(glXDestroyPbuffer
);
416 LOAD_FUNCPTR(glXMakeContextCurrent
);
417 LOAD_FUNCPTR(glXGetCurrentReadDrawable
);
418 LOAD_FUNCPTR(glXGetFBConfigs
);
420 /* Standard OpenGL calls */
421 LOAD_FUNCPTR(glBindTexture
);
422 LOAD_FUNCPTR(glBitmap
);
423 LOAD_FUNCPTR(glCopyTexSubImage1D
);
424 LOAD_FUNCPTR(glCopyTexImage2D
);
425 LOAD_FUNCPTR(glCopyTexSubImage2D
);
426 LOAD_FUNCPTR(glDrawBuffer
);
427 LOAD_FUNCPTR(glEndList
);
428 LOAD_FUNCPTR(glGetError
);
429 LOAD_FUNCPTR(glGetIntegerv
);
430 LOAD_FUNCPTR(glGetString
);
431 LOAD_FUNCPTR(glNewList
);
432 LOAD_FUNCPTR(glPixelStorei
);
433 LOAD_FUNCPTR(glReadPixels
);
434 LOAD_FUNCPTR(glTexImage2D
);
435 LOAD_FUNCPTR(glFinish
);
436 LOAD_FUNCPTR(glFlush
);
439 /* It doesn't matter if these fail. They'll only be used if the driver reports
440 the associated extension is available (and if a driver reports the extension
441 is available but fails to provide the functions, it's quite broken) */
442 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)
443 /* NV GLX Extension */
444 LOAD_FUNCPTR(glXAllocateMemoryNV
);
445 LOAD_FUNCPTR(glXFreeMemoryNV
);
448 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
451 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
452 TRACE("GLX is up and running error_base = %d\n", error_base
);
455 ERR( "GLX extension is missing, disabling OpenGL.\n" );
459 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
460 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
463 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
464 * depends on the reported GLX client / server version and on the client / server extension list.
465 * Those don't have to be the same.
467 * In general the server GLX information lists the capabilities in case of indirect rendering.
468 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
469 * available and in that case the client GLX informat can be used.
470 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
471 * in the GLX version/extension list. When a program does this it works for certain for both
472 * direct and indirect rendering.
474 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
475 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
476 * extension list which causes this extension not to be listed. (Wine requires this extension).
477 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
478 * pbuffers is around.
480 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
481 * the ATI drivers and from then on use GLX client information for them.
484 if(glxRequireVersion(3)) {
485 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
486 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
487 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
488 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
489 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
490 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
491 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
492 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
494 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
495 * enable this function when the Xserver understand GLX 1.3 or newer
497 pglXQueryDrawable
= NULL
;
498 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
499 TRACE("Overriding ATI GLX capabilities!\n");
500 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
501 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
502 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
503 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
505 /* Use client GLX information in case of the ATI drivers. We override the
506 * capabilities over here and not somewhere else as ATI might better their
507 * life in the future. In case they release proper drivers this block of
508 * code won't be called. */
509 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
511 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
514 if(glxRequireExtension("GLX_ATI_render_texture")) {
515 use_render_texture_ati
= 1;
516 pglXBindTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
517 pglXReleaseTexImageATI
= pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
518 pglXDrawableAttribATI
= pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
521 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
522 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
525 X11DRV_WineGL_LoadExtensions();
531 wine_dlclose(opengl_handle
, NULL
, 0);
532 opengl_handle
= NULL
;
536 static inline Wine_GLContext
*alloc_context(void)
540 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
542 ret
->next
= context_list
;
543 if (context_list
) context_list
->prev
= ret
;
549 static inline void free_context(Wine_GLContext
*context
)
551 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
552 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
553 else context_list
= context
->next
;
555 if (context
->vis
) XFree(context
->vis
);
556 HeapFree(GetProcessHeap(), 0, context
);
559 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
562 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
563 return (ptr
!= NULL
);
566 static int describeContext(Wine_GLContext
* ctx
) {
569 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
570 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
571 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
572 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
573 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
578 static BOOL
describeDrawable(X11DRV_PDEVICE
*physDev
) {
580 WineGLPixelFormat
*fmt
;
583 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
/* Offscreen */, &fmt_count
);
584 if(!fmt
) return FALSE
;
586 TRACE(" HDC %p has:\n", physDev
->hdc
);
587 TRACE(" - iPixelFormat %d\n", fmt
->iPixelFormat
);
588 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev
));
589 TRACE(" - FBCONFIG_ID 0x%x\n", fmt
->fmt_id
);
591 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
592 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
597 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
602 int nvfloatattrib
= GLX_DONT_CARE
;
605 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
606 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
607 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
608 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
610 switch (iWGLAttr
[cur
]) {
611 case WGL_AUX_BUFFERS_ARB
:
612 pop
= iWGLAttr
[++cur
];
613 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
614 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
616 case WGL_COLOR_BITS_ARB
:
617 pop
= iWGLAttr
[++cur
];
618 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
619 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
621 case WGL_BLUE_BITS_ARB
:
622 pop
= iWGLAttr
[++cur
];
623 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
624 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
626 case WGL_RED_BITS_ARB
:
627 pop
= iWGLAttr
[++cur
];
628 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
629 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
631 case WGL_GREEN_BITS_ARB
:
632 pop
= iWGLAttr
[++cur
];
633 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
634 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
636 case WGL_ALPHA_BITS_ARB
:
637 pop
= iWGLAttr
[++cur
];
638 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
639 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
641 case WGL_DEPTH_BITS_ARB
:
642 pop
= iWGLAttr
[++cur
];
643 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
644 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
646 case WGL_STENCIL_BITS_ARB
:
647 pop
= iWGLAttr
[++cur
];
648 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
649 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
651 case WGL_DOUBLE_BUFFER_ARB
:
652 pop
= iWGLAttr
[++cur
];
653 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
654 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
657 pop
= iWGLAttr
[++cur
];
658 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
659 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
662 case WGL_PIXEL_TYPE_ARB
:
663 pop
= iWGLAttr
[++cur
];
664 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
666 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
667 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
668 /* 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 */
669 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
670 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
672 ERR("unexpected PixelType(%x)\n", pop
);
677 case WGL_SUPPORT_GDI_ARB
:
678 /* This flag is set in a WineGLPixelFormat */
679 pop
= iWGLAttr
[++cur
];
680 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
683 case WGL_DRAW_TO_BITMAP_ARB
:
684 /* This flag is set in a WineGLPixelFormat */
685 pop
= iWGLAttr
[++cur
];
686 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
689 case WGL_DRAW_TO_WINDOW_ARB
:
690 pop
= iWGLAttr
[++cur
];
691 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
692 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
694 drawattrib
|= GLX_WINDOW_BIT
;
698 case WGL_DRAW_TO_PBUFFER_ARB
:
699 pop
= iWGLAttr
[++cur
];
700 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
701 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
703 drawattrib
|= GLX_PBUFFER_BIT
;
707 case WGL_ACCELERATION_ARB
:
708 /* This flag is set in a WineGLPixelFormat */
709 pop
= iWGLAttr
[++cur
];
710 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
713 case WGL_SUPPORT_OPENGL_ARB
:
714 pop
= iWGLAttr
[++cur
];
715 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
716 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
719 case WGL_SWAP_METHOD_ARB
:
720 pop
= iWGLAttr
[++cur
];
721 /* For now we ignore this and just return SWAP_EXCHANGE */
722 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
725 case WGL_PBUFFER_LARGEST_ARB
:
726 pop
= iWGLAttr
[++cur
];
727 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
728 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
731 case WGL_SAMPLE_BUFFERS_ARB
:
732 pop
= iWGLAttr
[++cur
];
733 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
734 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
737 case WGL_SAMPLES_ARB
:
738 pop
= iWGLAttr
[++cur
];
739 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
740 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
743 case WGL_TEXTURE_FORMAT_ARB
:
744 case WGL_TEXTURE_TARGET_ARB
:
745 case WGL_MIPMAP_TEXTURE_ARB
:
746 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
747 pop
= iWGLAttr
[++cur
];
749 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
751 if (use_render_texture_ati
) {
752 /** nothing to do here */
754 else if (!use_render_texture_emulation
) {
755 if (WGL_NO_TEXTURE_ARB
!= pop
) {
756 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
757 return -1; /** error: don't support it */
759 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
760 drawattrib
|= GLX_PBUFFER_BIT
;
764 case WGL_FLOAT_COMPONENTS_NV
:
765 nvfloatattrib
= iWGLAttr
[++cur
];
766 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
768 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
769 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
770 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
771 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
772 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
773 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
774 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
775 pop
= iWGLAttr
[++cur
];
776 /** cannot be converted, see direct handling on
777 * - wglGetPixelFormatAttribivARB
778 * TODO: wglChoosePixelFormat
781 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
782 pop
= iWGLAttr
[++cur
];
783 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
784 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
787 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
788 pop
= iWGLAttr
[++cur
];
789 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
790 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
793 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
799 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
800 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
801 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
802 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
804 /* Set GLX_RENDER_TYPE all the time */
805 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
806 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
808 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
809 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
810 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
811 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
817 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
819 int render_type
=0, render_type_bit
;
820 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
821 switch(render_type_bit
)
824 render_type
= GLX_RGBA_TYPE
;
826 case GLX_COLOR_INDEX_BIT
:
827 render_type
= GLX_COLOR_INDEX_TYPE
;
829 case GLX_RGBA_FLOAT_BIT
:
830 render_type
= GLX_RGBA_FLOAT_TYPE
;
832 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
833 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
836 ERR("Unknown render_type: %x\n", render_type
);
841 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
842 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
845 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
846 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
848 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
849 * the GLX_PIXMAP_BIT set. */
850 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
853 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
855 static WineGLPixelFormat
*list
;
856 static int size
, onscreen_size
;
858 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
860 XVisualInfo
*visinfo
;
865 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
866 if (NULL
== cfgs
|| 0 == nCfgs
) {
867 if(cfgs
!= NULL
) XFree(cfgs
);
869 ERR("glXChooseFBConfig returns NULL\n");
873 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
874 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
875 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
876 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
878 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
880 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
882 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
885 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
887 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
889 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
890 * Do this as GLX doesn't guarantee that the list is sorted */
891 for(run
=0; run
< 2; run
++)
893 for(i
=0; i
<nCfgs
; i
++) {
894 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
895 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
897 /* The first run we only add onscreen formats (ones which have an associated X Visual).
898 * The second run we only set offscreen formats. */
901 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
902 * The contents is copied to the destination using XCopyArea. For the copying to work
903 * the depth of the source and destination window should be the same. In general this should
904 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
905 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
906 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
907 * list formats with the same depth. */
908 if(visinfo
->depth
!= screen_depth
)
911 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
912 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
913 list
[size
].fbconfig
= cfgs
[i
];
914 list
[size
].fmt_id
= fmt_id
;
915 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
916 list
[size
].offscreenOnly
= FALSE
;
917 list
[size
].dwFlags
= 0;
921 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
922 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
924 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
925 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
926 list
[size
].fbconfig
= cfgs
[i
];
927 list
[size
].fmt_id
= fmt_id
;
928 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
929 list
[size
].offscreenOnly
= FALSE
;
930 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
936 } else if(run
&& !visinfo
) {
937 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
938 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
939 list
[size
].fbconfig
= cfgs
[i
];
940 list
[size
].fmt_id
= fmt_id
;
941 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
942 list
[size
].offscreenOnly
= TRUE
;
943 list
[size
].dwFlags
= 0;
949 if(cfgs
!= NULL
) XFree(cfgs
);
952 if (size_ret
) *size_ret
= size
;
953 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
958 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
959 * In our WGL implementation we only support a subset of these formats namely the format of
960 * Wine's main visual and offscreen formats (if they are available).
961 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
962 * and it returns the number of supported WGL formats in fmt_count.
964 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
966 WineGLPixelFormat
*list
, *res
= NULL
;
967 int size
, onscreen_size
;
969 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
971 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
972 * iPixelFormat in case of probing the number of pixelformats.
974 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
975 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
976 res
= &list
[iPixelFormat
-1];
977 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
983 *fmt_count
= onscreen_size
;
985 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
990 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
991 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
993 WineGLPixelFormat
*list
;
996 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
998 for(i
=0; i
<size
; i
++) {
999 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1000 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1001 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1002 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1006 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1010 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1012 WineGLPixelFormat
*fmt
;
1014 if (!fbconfig_id
) return 0;
1016 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1018 return fmt
->iPixelFormat
;
1019 /* This will happen on hwnds without a pixel format set; it's ok */
1024 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1025 void mark_drawable_dirty(Drawable old
, Drawable
new)
1027 Wine_GLContext
*ctx
;
1028 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
1029 if (old
== ctx
->drawables
[0]) {
1030 ctx
->drawables
[0] = new;
1031 ctx
->refresh_drawables
= TRUE
;
1033 if (old
== ctx
->drawables
[1]) {
1034 ctx
->drawables
[1] = new;
1035 ctx
->refresh_drawables
= TRUE
;
1040 /* Given the current context, make sure its drawable is sync'd */
1041 static inline void sync_context(Wine_GLContext
*context
)
1043 if(context
&& context
->refresh_drawables
) {
1044 if (glxRequireVersion(3))
1045 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1046 context
->drawables
[1], context
->ctx
);
1048 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1049 context
->refresh_drawables
= FALSE
;
1054 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1058 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1059 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1062 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1063 else /* Create a GLX Context for a pbuffer */
1064 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1070 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1072 return pglXCreateGLXPixmap(display
, vis
, parent
);
1076 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1083 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1085 if(vis
->depth
== physDev
->bitmap
->pixmap_depth
)
1086 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1089 wine_tsx11_unlock();
1090 TRACE("return %lx\n", ret
);
1095 * X11DRV_ChoosePixelFormat
1097 * Equivalent to glXChooseVisual.
1099 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
1100 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1101 WineGLPixelFormat
*list
;
1106 int bestFormat
= -1;
1107 int bestDBuffer
= -1;
1108 int bestStereo
= -1;
1112 int bestStencil
= -1;
1115 if (!has_opengl()) return 0;
1117 if (TRACE_ON(wgl
)) {
1118 TRACE("(%p,%p)\n", physDev
, ppfd
);
1120 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1123 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1126 for(i
=0; i
<onscreen_size
; i
++)
1130 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1131 WineGLPixelFormat
*fmt
= &list
[i
];
1134 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1135 if (value
& GLX_RGBA_BIT
)
1136 iPixelType
= PFD_TYPE_RGBA
;
1138 iPixelType
= PFD_TYPE_COLORINDEX
;
1140 if (ppfd
->iPixelType
!= iPixelType
)
1142 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1146 /* Only use bitmap capable for formats for bitmap rendering.
1147 * See get_formats for more info. */
1148 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1150 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1154 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1155 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1156 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1157 if (value
) dwFlags
|= PFD_STEREO
;
1158 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1159 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1160 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1161 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1162 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1164 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1165 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1166 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1167 * formats without the given flag set.
1168 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1169 * has indicated that a format without stereo is returned when stereo is unavailable.
1170 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1171 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1173 * To summarize the following is most likely the correct behavior:
1174 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1175 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1176 * stereo don't care -> it doesn't matter whether we get stereo or not
1178 * In Wine we will treat no-stereo the same way as don't care because it makes
1179 * format selection even more complicated and second drivers with Stereo advertise
1180 * each format twice anyway.
1183 /* Doublebuffer, see the comments above */
1184 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1185 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1186 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1188 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1189 bestStereo
= dwFlags
& PFD_STEREO
;
1193 bestStencil
= stencil
;
1198 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1202 /* Stereo, see the comments above. */
1203 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1204 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1205 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1207 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1208 bestStereo
= dwFlags
& PFD_STEREO
;
1212 bestStencil
= stencil
;
1217 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1221 /* Below we will do a number of checks to select the 'best' pixelformat.
1222 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1223 * The code works by trying to match the most important options as close as possible.
1224 * When a reasonable format is found, we will try to match more options.
1225 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1226 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1227 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1230 if(ppfd
->cColorBits
) {
1231 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1232 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1234 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1235 bestStereo
= dwFlags
& PFD_STEREO
;
1239 bestStencil
= stencil
;
1243 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1244 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1250 if(ppfd
->cAlphaBits
) {
1251 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1252 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1254 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1255 bestStereo
= dwFlags
& PFD_STEREO
;
1259 bestStencil
= stencil
;
1263 } else if(bestAlpha
!= alpha
) {
1264 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1270 if(ppfd
->cDepthBits
) {
1271 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1272 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1274 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1275 bestStereo
= dwFlags
& PFD_STEREO
;
1279 bestStencil
= stencil
;
1283 } else if(bestDepth
!= depth
) {
1284 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1290 if(ppfd
->cStencilBits
) {
1291 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1292 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1294 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1295 bestStereo
= dwFlags
& PFD_STEREO
;
1299 bestStencil
= stencil
;
1303 } else if(bestStencil
!= stencil
) {
1304 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1310 if(ppfd
->cAuxBuffers
) {
1311 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1312 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1314 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1315 bestStereo
= dwFlags
& PFD_STEREO
;
1319 bestStencil
= stencil
;
1323 } else if(bestAux
!= aux
) {
1324 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1330 if(bestFormat
== -1) {
1331 TRACE("No matching mode was found returning 0\n");
1335 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1336 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1339 wine_tsx11_unlock();
1344 * X11DRV_DescribePixelFormat
1346 * Get the pixel-format descriptor associated to the given id
1348 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1351 PIXELFORMATDESCRIPTOR
*ppfd
) {
1352 /*XVisualInfo *vis;*/
1355 WineGLPixelFormat
*fmt
;
1359 if (!has_opengl()) return 0;
1361 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1363 /* 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 */
1364 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1366 /* The application is only querying the number of pixelformats */
1368 } else if(fmt
== NULL
) {
1369 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1373 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1374 ERR("Wrong structure size !\n");
1375 /* Should set error */
1381 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1382 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1385 /* These flags are always the same... */
1386 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1387 /* Now the flags extracted from the Visual */
1391 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1392 if(value
& GLX_WINDOW_BIT
)
1393 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1395 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1396 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1397 * 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
1398 * offered the GDI bit either. */
1399 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1401 /* PFD_GENERIC_FORMAT - gdi software rendering
1402 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1403 * none set - full hardware accelerated by a ICD
1405 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1406 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1408 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1410 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1411 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1413 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1416 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1417 if (value
& GLX_RGBA_BIT
)
1418 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1420 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1423 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1424 ppfd
->cColorBits
= value
;
1426 /* Red, green, blue and alpha bits / shifts */
1427 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1428 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1429 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1430 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1431 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1433 ppfd
->cRedBits
= rb
;
1434 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1435 ppfd
->cBlueBits
= bb
;
1436 ppfd
->cBlueShift
= ab
;
1437 ppfd
->cGreenBits
= gb
;
1438 ppfd
->cGreenShift
= bb
+ ab
;
1439 ppfd
->cAlphaBits
= ab
;
1440 ppfd
->cAlphaShift
= 0;
1443 ppfd
->cRedShift
= 0;
1444 ppfd
->cBlueBits
= 0;
1445 ppfd
->cBlueShift
= 0;
1446 ppfd
->cGreenBits
= 0;
1447 ppfd
->cGreenShift
= 0;
1448 ppfd
->cAlphaBits
= 0;
1449 ppfd
->cAlphaShift
= 0;
1452 /* Accum RGBA bits */
1453 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1454 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1455 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1456 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1458 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1459 ppfd
->cAccumRedBits
= rb
;
1460 ppfd
->cAccumGreenBits
= gb
;
1461 ppfd
->cAccumBlueBits
= bb
;
1462 ppfd
->cAccumAlphaBits
= ab
;
1465 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1466 ppfd
->cAuxBuffers
= value
;
1469 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1470 ppfd
->cDepthBits
= value
;
1473 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1474 ppfd
->cStencilBits
= value
;
1476 wine_tsx11_unlock();
1478 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1480 if (TRACE_ON(wgl
)) {
1481 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1488 * X11DRV_GetPixelFormat
1490 * Get the pixel-format id used by this DC
1492 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1493 WineGLPixelFormat
*fmt
;
1495 TRACE("(%p)\n", physDev
);
1497 if (!physDev
->current_pf
) return 0; /* not set yet */
1499 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1502 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1505 else if(fmt
->offscreenOnly
)
1507 /* Offscreen formats can't be used with traditional WGL calls.
1508 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1509 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1513 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1514 return physDev
->current_pf
;
1517 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1518 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1519 * set the pixel format multiple times. */
1520 static BOOL
internal_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1522 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1523 WineGLPixelFormat
*fmt
;
1527 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1528 if(get_glxdrawable(physDev
) == root_window
)
1530 ERR("Invalid operation on root_window\n");
1534 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1535 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1537 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1542 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1543 wine_tsx11_unlock();
1545 hwnd
= WindowFromDC(physDev
->hdc
);
1547 if(!(value
&GLX_WINDOW_BIT
)) {
1548 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1552 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, (WPARAM
)fmt
->fmt_id
, 0)) {
1553 ERR("Couldn't set format of the window, returning failure\n");
1557 else if(physDev
->bitmap
) {
1558 if(!(value
&GLX_PIXMAP_BIT
)) {
1559 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1563 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
, fmt
);
1564 if(!physDev
->bitmap
->glxpixmap
) {
1565 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1570 FIXME("called on a non-window, non-bitmap object?\n");
1573 physDev
->current_pf
= iPixelFormat
;
1575 if (TRACE_ON(wgl
)) {
1579 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1581 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1583 TRACE(" FBConfig have :\n");
1584 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1585 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1586 TRACE(" - VISUAL_ID 0x%x\n", value
);
1587 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1588 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1590 wine_tsx11_unlock();
1597 * X11DRV_SetPixelFormat
1599 * Set the pixel-format id used by this DC
1601 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1603 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1604 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1606 if (!has_opengl()) return FALSE
;
1608 if(physDev
->current_pf
) /* cannot change it if already set */
1609 return (physDev
->current_pf
== iPixelFormat
);
1611 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
1615 * X11DRV_wglCopyContext
1617 * For OpenGL32 wglCopyContext.
1619 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
1620 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1621 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1623 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1625 /* There is a slight difference in the way GL contexts share display lists in WGL and GLX.
1626 * In case of GLX you need to specify this at context creation time but in case of WGL you
1627 * do this using wglShareLists which you can call after creating the context.
1628 * To emulate WGL we try to delay the creation of the context until wglShareLists or wglMakeCurrent.
1629 * Up to now that works fine.
1631 * The delayed GLX context creation could cause issues for wglCopyContext as it might get called
1632 * when there is no GLX context yet. The chance this will cause problems is small as at the time of
1633 * writing Wine has had OpenGL support for more than 7 years and this function has remained a stub
1636 if(!src
->ctx
|| !dst
->ctx
) {
1637 /* NOTE: As a special case, if both GLX contexts are NULL, that means
1638 * neither WGL context was made current. In that case, both contexts
1639 * are in a default state, so any copy would no-op.
1641 if(!src
->ctx
&& !dst
->ctx
) {
1642 TRACE("No source or destination contexts set. No-op.\n");
1648 src
->ctx
= create_glxcontext(gdi_display
, src
, NULL
);
1649 TRACE(" created a delayed OpenGL context (%p)\n", src
->ctx
);
1651 else if (!dst
->ctx
) {
1653 dst
->ctx
= create_glxcontext(gdi_display
, dst
, NULL
);
1654 TRACE(" created a delayed OpenGL context (%p)\n", dst
->ctx
);
1660 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1661 wine_tsx11_unlock();
1663 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1668 * X11DRV_wglCreateContext
1670 * For OpenGL32 wglCreateContext.
1672 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1674 Wine_GLContext
*ret
;
1675 WineGLPixelFormat
*fmt
;
1676 int hdcPF
= physDev
->current_pf
;
1678 HDC hdc
= physDev
->hdc
;
1680 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1682 if (!has_opengl()) return 0;
1684 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1685 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1686 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1687 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1688 * If this fails something is very wrong on the system. */
1690 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1691 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1695 /* The context will be allocated in the wglMakeCurrent call */
1697 ret
= alloc_context();
1698 wine_tsx11_unlock();
1703 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1705 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1710 * X11DRV_wglDeleteContext
1712 * For OpenGL32 wglDeleteContext.
1714 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1716 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1719 TRACE("(%p)\n", hglrc
);
1721 if (!has_opengl()) return 0;
1724 /* A game (Half Life not to name it) deletes twice the same context,
1725 * so make sure it is valid first */
1726 if (is_valid_context( ctx
))
1728 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1733 WARN("Error deleting context !\n");
1734 SetLastError(ERROR_INVALID_HANDLE
);
1737 wine_tsx11_unlock();
1743 * X11DRV_wglGetCurrentReadDCARB
1745 * For OpenGL32 wglGetCurrentReadDCARB.
1747 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1750 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1752 if (ctx
) ret
= ctx
->read_hdc
;
1754 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1759 * X11DRV_wglGetProcAddress
1761 * For OpenGL32 wglGetProcAddress.
1763 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1766 const WineGLExtension
*ext
;
1768 int padding
= 32 - strlen(lpszProc
);
1772 if (!has_opengl()) return NULL
;
1774 /* Check the table of WGL extensions to see if we need to return a WGL extension
1775 * or a function pointer to a native OpenGL function. */
1776 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1777 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1779 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1780 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1781 ext
= WineGLExtensionList
[i
];
1782 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1783 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1784 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1785 return ext
->extEntryPoints
[j
].funcAddress
;
1791 WARN("(%s) - not found\n", lpszProc
);
1796 * X11DRV_wglMakeCurrent
1798 * For OpenGL32 wglMakeCurrent.
1800 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1802 HDC hdc
= physDev
->hdc
;
1803 DWORD type
= GetObjectType(hdc
);
1804 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1806 TRACE("(%p,%p)\n", hdc
, hglrc
);
1808 if (!has_opengl()) return FALSE
;
1811 if (hglrc
== NULL
) {
1812 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1813 NtCurrentTeb()->glContext
= NULL
;
1814 } else if (ctx
->fmt
->iPixelFormat
!= physDev
->current_pf
) {
1815 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1816 hdc
, physDev
->current_pf
, ctx
, ctx
->fmt
->iPixelFormat
);
1817 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1820 Drawable drawable
= get_glxdrawable(physDev
);
1821 if (ctx
->ctx
== NULL
) {
1822 /* The describe lines below are for debugging purposes only */
1823 if (TRACE_ON(wgl
)) {
1824 describeDrawable(physDev
);
1825 describeContext(ctx
);
1828 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1829 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1831 TRACE(" Creating GLX Context\n");
1832 ctx
->ctx
= create_glxcontext(gdi_display
, ctx
, NULL
);
1833 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1835 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1836 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1837 NtCurrentTeb()->glContext
= ctx
;
1841 ctx
->read_hdc
= hdc
;
1842 ctx
->drawables
[0] = drawable
;
1843 ctx
->drawables
[1] = drawable
;
1844 ctx
->refresh_drawables
= FALSE
;
1846 if (type
== OBJ_MEMDC
)
1848 ctx
->do_escape
= TRUE
;
1849 pglDrawBuffer(GL_FRONT_LEFT
);
1853 wine_tsx11_unlock();
1854 TRACE(" returning %s\n", (ret
? "True" : "False"));
1859 * X11DRV_wglMakeContextCurrentARB
1861 * For OpenGL32 wglMakeContextCurrentARB
1863 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1867 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1869 if (!has_opengl()) return 0;
1872 if (hglrc
== NULL
) {
1873 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1874 NtCurrentTeb()->glContext
= NULL
;
1876 if (NULL
== pglXMakeContextCurrent
) {
1879 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1880 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1881 Drawable d_read
= get_glxdrawable(pReadDev
);
1883 if (ctx
->ctx
== NULL
) {
1884 ctx
->ctx
= create_glxcontext(gdi_display
, ctx
, NULL
);
1885 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1887 ctx
->hdc
= pDrawDev
->hdc
;
1888 ctx
->read_hdc
= pReadDev
->hdc
;
1889 ctx
->drawables
[0] = d_draw
;
1890 ctx
->drawables
[1] = d_read
;
1891 ctx
->refresh_drawables
= FALSE
;
1892 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1893 NtCurrentTeb()->glContext
= ctx
;
1896 wine_tsx11_unlock();
1898 TRACE(" returning %s\n", (ret
? "True" : "False"));
1903 * X11DRV_wglShareLists
1905 * For OpenGL32 wglShareLists.
1907 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1908 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1909 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1911 TRACE("(%p, %p)\n", org
, dest
);
1913 if (!has_opengl()) return FALSE
;
1915 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1916 ERR("Could not share display lists, context already created !\n");
1919 if(org
&& dest
&& (GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
)) {
1920 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1923 if (org
->ctx
== NULL
) {
1925 describeContext(org
);
1927 org
->ctx
= create_glxcontext(gdi_display
, org
, NULL
);
1928 wine_tsx11_unlock();
1929 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1933 describeContext(dest
);
1934 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1935 wine_tsx11_unlock();
1936 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1943 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1945 /* We are running using client-side rendering fonts... */
1947 unsigned int glyph
, size
= 0;
1948 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1952 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1953 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1954 wine_tsx11_unlock();
1956 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1957 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
1958 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
1959 unsigned int height
, width_int
;
1961 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1962 if (needed_size
== GDI_ERROR
) {
1963 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1966 TRACE(" - needed size : %d\n", needed_size
);
1969 if (needed_size
> size
) {
1971 HeapFree(GetProcessHeap(), 0, bitmap
);
1972 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1973 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1974 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1976 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
1978 if (TRACE_ON(wgl
)) {
1979 unsigned int height
, width
, bitmask
;
1980 unsigned char *bitmap_
= bitmap
;
1982 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1983 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1984 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1985 if (needed_size
!= 0) {
1986 TRACE(" - bitmap :\n");
1987 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1989 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1994 if (*bitmap_
& bitmask
)
1999 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2005 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2006 * glyph for it to be drawn properly.
2008 if (needed_size
!= 0) {
2009 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2010 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2012 for (width
= 0; width
< width_int
; width
++) {
2013 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2014 ((int *) bitmap
)[height
* width_int
+ width
];
2020 pglNewList(listBase
++, GL_COMPILE
);
2021 if (needed_size
!= 0) {
2022 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2023 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2024 gm
.gmCellIncX
, gm
.gmCellIncY
,
2027 /* This is the case of 'empty' glyphs like the space character */
2028 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2031 wine_tsx11_unlock();
2035 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2036 wine_tsx11_unlock();
2038 HeapFree(GetProcessHeap(), 0, bitmap
);
2039 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2044 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2045 wine_tsx11_unlock();
2047 HeapFree(GetProcessHeap(), 0, bitmap
);
2048 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2053 * X11DRV_wglUseFontBitmapsA
2055 * For OpenGL32 wglUseFontBitmapsA.
2057 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2059 Font fid
= physDev
->font
;
2061 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2063 if (!has_opengl()) return FALSE
;
2066 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2070 /* I assume that the glyphs are at the same position for X and for Windows */
2071 pglXUseXFont(fid
, first
, count
, listBase
);
2072 wine_tsx11_unlock();
2077 * X11DRV_wglUseFontBitmapsW
2079 * For OpenGL32 wglUseFontBitmapsW.
2081 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2083 Font fid
= physDev
->font
;
2085 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2087 if (!has_opengl()) return FALSE
;
2090 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2093 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2096 /* I assume that the glyphs are at the same position for X and for Windows */
2097 pglXUseXFont(fid
, first
, count
, listBase
);
2098 wine_tsx11_unlock();
2102 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2103 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2110 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2112 pglGetIntegerv(pname
, params
);
2114 * if we cannot find a Wine Context
2115 * we only have the default wine desktop context,
2116 * so if we have only a 24 depth say we have 32
2118 if (!ctx
&& *params
== 24) {
2121 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2126 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2128 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2129 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2133 pglGetIntegerv(pname
, params
);
2136 wine_tsx11_unlock();
2139 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
2143 if (!physDev
->gl_copy
)
2146 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
2147 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
2149 if(w
> 0 && h
> 0) {
2150 Drawable src
= physDev
->pixmap
;
2151 if(!src
) src
= physDev
->gl_drawable
;
2153 /* The GL drawable may be lagged behind if we don't flush first, so
2154 * flush the display make sure we copy up-to-date data */
2156 XFlush(gdi_display
);
2157 XSetFunction(gdi_display
, physDev
->gc
, GXcopy
);
2158 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
2159 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
2160 wine_tsx11_unlock();
2165 static void WINAPI
X11DRV_wglFinish(void)
2167 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2168 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2173 wine_tsx11_unlock();
2174 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2177 static void WINAPI
X11DRV_wglFlush(void)
2179 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2180 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2185 wine_tsx11_unlock();
2186 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2190 * X11DRV_wglGetExtensionsStringARB
2192 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2194 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2195 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2196 return WineGLInfo
.wglExtensions
;
2200 * X11DRV_wglCreatePbufferARB
2202 * WGL_ARB_pbuffer: wglCreatePbufferARB
2204 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2206 Wine_GLPBuffer
* object
= NULL
;
2207 WineGLPixelFormat
*fmt
= NULL
;
2212 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2214 if (0 >= iPixelFormat
) {
2215 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2216 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2217 return NULL
; /* unexpected error */
2220 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2221 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2223 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2224 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2225 goto create_failed
; /* unexpected error */
2228 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2229 if (NULL
== object
) {
2230 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2231 goto create_failed
; /* unexpected error */
2234 object
->display
= gdi_display
;
2235 object
->width
= iWidth
;
2236 object
->height
= iHeight
;
2239 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2240 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2241 while (piAttribList
&& 0 != *piAttribList
) {
2243 switch (*piAttribList
) {
2244 case WGL_PBUFFER_LARGEST_ARB
: {
2246 attr_v
= *piAttribList
;
2247 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2248 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2252 case WGL_TEXTURE_FORMAT_ARB
: {
2254 attr_v
= *piAttribList
;
2255 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2256 if (use_render_texture_ati
) {
2259 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2260 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2261 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2263 SetLastError(ERROR_INVALID_DATA
);
2266 object
->use_render_texture
= 1;
2267 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2269 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2270 object
->use_render_texture
= 0;
2272 if (!use_render_texture_emulation
) {
2273 SetLastError(ERROR_INVALID_DATA
);
2277 case WGL_TEXTURE_RGB_ARB
:
2278 object
->use_render_texture
= GL_RGB
;
2279 object
->texture_bpp
= 3;
2280 object
->texture_format
= GL_RGB
;
2281 object
->texture_type
= GL_UNSIGNED_BYTE
;
2283 case WGL_TEXTURE_RGBA_ARB
:
2284 object
->use_render_texture
= GL_RGBA
;
2285 object
->texture_bpp
= 4;
2286 object
->texture_format
= GL_RGBA
;
2287 object
->texture_type
= GL_UNSIGNED_BYTE
;
2290 /* WGL_FLOAT_COMPONENTS_NV */
2291 case WGL_TEXTURE_FLOAT_R_NV
:
2292 object
->use_render_texture
= GL_FLOAT_R_NV
;
2293 object
->texture_bpp
= 4;
2294 object
->texture_format
= GL_RED
;
2295 object
->texture_type
= GL_FLOAT
;
2297 case WGL_TEXTURE_FLOAT_RG_NV
:
2298 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2299 object
->texture_bpp
= 8;
2300 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2301 object
->texture_type
= GL_FLOAT
;
2303 case WGL_TEXTURE_FLOAT_RGB_NV
:
2304 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2305 object
->texture_bpp
= 12;
2306 object
->texture_format
= GL_RGB
;
2307 object
->texture_type
= GL_FLOAT
;
2309 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2310 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2311 object
->texture_bpp
= 16;
2312 object
->texture_format
= GL_RGBA
;
2313 object
->texture_type
= GL_FLOAT
;
2316 ERR("Unknown texture format: %x\n", attr_v
);
2317 SetLastError(ERROR_INVALID_DATA
);
2325 case WGL_TEXTURE_TARGET_ARB
: {
2327 attr_v
= *piAttribList
;
2328 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2329 if (use_render_texture_ati
) {
2332 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2333 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2334 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2335 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2337 SetLastError(ERROR_INVALID_DATA
);
2340 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2342 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2343 object
->texture_target
= 0;
2345 if (!use_render_texture_emulation
) {
2346 SetLastError(ERROR_INVALID_DATA
);
2350 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2351 if (iWidth
!= iHeight
) {
2352 SetLastError(ERROR_INVALID_DATA
);
2355 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2356 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2359 case WGL_TEXTURE_1D_ARB
: {
2361 SetLastError(ERROR_INVALID_DATA
);
2364 object
->texture_target
= GL_TEXTURE_1D
;
2365 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2368 case WGL_TEXTURE_2D_ARB
: {
2369 object
->texture_target
= GL_TEXTURE_2D
;
2370 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2373 case WGL_TEXTURE_RECTANGLE_NV
: {
2374 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2375 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2379 ERR("Unknown texture target: %x\n", attr_v
);
2380 SetLastError(ERROR_INVALID_DATA
);
2388 case WGL_MIPMAP_TEXTURE_ARB
: {
2390 attr_v
= *piAttribList
;
2391 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2392 if (use_render_texture_ati
) {
2393 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2395 if (!use_render_texture_emulation
) {
2396 SetLastError(ERROR_INVALID_DATA
);
2406 PUSH1(attribs
, None
);
2408 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2409 wine_tsx11_unlock();
2410 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2411 if (!object
->drawable
) {
2412 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2413 goto create_failed
; /* unexpected error */
2415 TRACE("->(%p)\n", object
);
2419 HeapFree(GetProcessHeap(), 0, object
);
2420 TRACE("->(FAILED)\n");
2425 * X11DRV_wglDestroyPbufferARB
2427 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2429 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2431 Wine_GLPBuffer
* object
= hPbuffer
;
2432 TRACE("(%p)\n", hPbuffer
);
2433 if (NULL
== object
) {
2434 SetLastError(ERROR_INVALID_HANDLE
);
2438 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2439 wine_tsx11_unlock();
2440 HeapFree(GetProcessHeap(), 0, object
);
2445 * X11DRV_wglGetPbufferDCARB
2447 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2448 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2449 * Gdi32 implements the part of this function which creates a device context.
2450 * This part associates the physDev with the X drawable of the pbuffer.
2452 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2454 Wine_GLPBuffer
* object
= hPbuffer
;
2455 if (NULL
== object
) {
2456 SetLastError(ERROR_INVALID_HANDLE
);
2460 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2461 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2462 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2463 physDev
->drawable
= object
->drawable
;
2464 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2465 physDev
->dc_rect
= physDev
->drawable_rect
;
2467 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2468 return physDev
->hdc
;
2472 * X11DRV_wglQueryPbufferARB
2474 * WGL_ARB_pbuffer: wglQueryPbufferARB
2476 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2478 Wine_GLPBuffer
* object
= hPbuffer
;
2479 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2480 if (NULL
== object
) {
2481 SetLastError(ERROR_INVALID_HANDLE
);
2484 switch (iAttribute
) {
2485 case WGL_PBUFFER_WIDTH_ARB
:
2487 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2488 wine_tsx11_unlock();
2490 case WGL_PBUFFER_HEIGHT_ARB
:
2492 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2493 wine_tsx11_unlock();
2496 case WGL_PBUFFER_LOST_ARB
:
2497 /* GLX Pbuffers cannot be lost by default. We can support this by
2498 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2499 * to receive pixel buffer clobber events, however that may or may
2500 * not give any benefit */
2501 *piValue
= GL_FALSE
;
2504 case WGL_TEXTURE_FORMAT_ARB
:
2505 if (use_render_texture_ati
) {
2507 int type
= WGL_NO_TEXTURE_ARB
;
2509 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2510 wine_tsx11_unlock();
2512 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2513 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2514 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2518 if (!object
->use_render_texture
) {
2519 *piValue
= WGL_NO_TEXTURE_ARB
;
2521 if (!use_render_texture_emulation
) {
2522 SetLastError(ERROR_INVALID_HANDLE
);
2525 switch(object
->use_render_texture
) {
2527 *piValue
= WGL_TEXTURE_RGB_ARB
;
2530 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2532 /* WGL_FLOAT_COMPONENTS_NV */
2534 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2536 case GL_FLOAT_RG_NV
:
2537 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2539 case GL_FLOAT_RGB_NV
:
2540 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2542 case GL_FLOAT_RGBA_NV
:
2543 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2546 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2552 case WGL_TEXTURE_TARGET_ARB
:
2553 if (use_render_texture_ati
) {
2555 int type
= WGL_NO_TEXTURE_ARB
;
2557 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2558 wine_tsx11_unlock();
2560 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2561 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2562 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2563 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2567 if (!object
->texture_target
) {
2568 *piValue
= WGL_NO_TEXTURE_ARB
;
2570 if (!use_render_texture_emulation
) {
2571 SetLastError(ERROR_INVALID_DATA
);
2574 switch (object
->texture_target
) {
2575 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2576 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2577 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2578 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2584 case WGL_MIPMAP_TEXTURE_ARB
:
2585 if (use_render_texture_ati
) {
2587 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2588 wine_tsx11_unlock();
2590 *piValue
= GL_FALSE
; /** don't support that */
2591 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2596 FIXME("unexpected attribute %x\n", iAttribute
);
2604 * X11DRV_wglReleasePbufferDCARB
2606 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2608 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2610 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2611 return DeleteDC(hdc
);
2615 * X11DRV_wglSetPbufferAttribARB
2617 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2619 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2621 Wine_GLPBuffer
* object
= hPbuffer
;
2622 GLboolean ret
= GL_FALSE
;
2624 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2625 if (NULL
== object
) {
2626 SetLastError(ERROR_INVALID_HANDLE
);
2629 if (!object
->use_render_texture
) {
2630 SetLastError(ERROR_INVALID_HANDLE
);
2633 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2636 if (NULL
!= pglXDrawableAttribATI
) {
2637 if (use_render_texture_ati
) {
2638 FIXME("Need conversion for GLX_ATI_render_texture\n");
2641 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2642 wine_tsx11_unlock();
2648 * X11DRV_wglChoosePixelFormatARB
2650 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2652 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2657 GLXFBConfig
* cfgs
= NULL
;
2661 WineGLPixelFormat
*fmt
;
2667 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2668 if (NULL
!= pfAttribFList
) {
2669 FIXME("unused pfAttribFList\n");
2672 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2673 if (-1 == nAttribs
) {
2674 WARN("Cannot convert WGL to GLX attributes\n");
2677 PUSH1(attribs
, None
);
2679 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2680 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2681 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2682 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2684 switch(piAttribIList
[i
])
2686 case WGL_DRAW_TO_BITMAP_ARB
:
2687 if(piAttribIList
[i
+1])
2688 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2690 case WGL_ACCELERATION_ARB
:
2691 switch(piAttribIList
[i
+1])
2693 case WGL_NO_ACCELERATION_ARB
:
2694 dwFlags
|= PFD_GENERIC_FORMAT
;
2696 case WGL_GENERIC_ACCELERATION_ARB
:
2697 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2699 case WGL_FULL_ACCELERATION_ARB
:
2704 case WGL_SUPPORT_GDI_ARB
:
2705 if(piAttribIList
[i
+1])
2706 dwFlags
|= PFD_SUPPORT_GDI
;
2711 /* Search for FB configurations matching the requirements in attribs */
2713 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2715 wine_tsx11_unlock();
2716 WARN("Compatible Pixel Format not found\n");
2720 /* Loop through all matching formats and check if they are suitable.
2721 * Note that this function should at max return nMaxFormats different formats */
2722 for(run
=0; run
< 2; run
++)
2724 for (it
= 0; it
< nCfgs
; ++it
) {
2725 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2727 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2731 /* Search for the format in our list of compatible formats */
2732 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2736 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2737 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2740 if(pfmt_it
< nMaxFormats
) {
2741 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2742 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2748 *nNumFormats
= pfmt_it
;
2751 wine_tsx11_unlock();
2756 * X11DRV_wglGetPixelFormatAttribivARB
2758 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2760 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2763 WineGLPixelFormat
*fmt
= NULL
;
2767 int nWGLFormats
= 0;
2769 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2771 if (0 < iLayerPlane
) {
2772 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2776 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2777 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2778 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2779 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2781 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2785 for (i
= 0; i
< nAttributes
; ++i
) {
2786 const int curWGLAttr
= piAttributes
[i
];
2787 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2789 switch (curWGLAttr
) {
2790 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2791 piValues
[i
] = nWGLFormats
;
2794 case WGL_SUPPORT_OPENGL_ARB
:
2795 piValues
[i
] = GL_TRUE
;
2798 case WGL_ACCELERATION_ARB
:
2799 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2800 if (!fmt
) goto pix_error
;
2801 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2802 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2803 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2804 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2806 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2809 case WGL_TRANSPARENT_ARB
:
2810 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2811 if (!fmt
) goto pix_error
;
2812 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2813 if (hTest
) goto get_error
;
2814 piValues
[i
] = GL_FALSE
;
2815 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2818 case WGL_PIXEL_TYPE_ARB
:
2819 curGLXAttr
= GLX_RENDER_TYPE
;
2820 if (!fmt
) goto pix_error
;
2821 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2822 if (hTest
) goto get_error
;
2823 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2824 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2825 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2826 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2827 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2828 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2830 ERR("unexpected RenderType(%x)\n", tmp
);
2831 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2835 case WGL_COLOR_BITS_ARB
:
2836 curGLXAttr
= GLX_BUFFER_SIZE
;
2839 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2840 if (use_render_texture_ati
) {
2841 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2844 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2845 if (use_render_texture_ati
) {
2846 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2849 if (!use_render_texture_emulation
) {
2850 piValues
[i
] = GL_FALSE
;
2853 curGLXAttr
= GLX_RENDER_TYPE
;
2854 if (!fmt
) goto pix_error
;
2855 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2856 if (hTest
) goto get_error
;
2857 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2858 piValues
[i
] = GL_FALSE
;
2861 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2862 if (hTest
) goto get_error
;
2863 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2866 case WGL_BLUE_BITS_ARB
:
2867 curGLXAttr
= GLX_BLUE_SIZE
;
2869 case WGL_RED_BITS_ARB
:
2870 curGLXAttr
= GLX_RED_SIZE
;
2872 case WGL_GREEN_BITS_ARB
:
2873 curGLXAttr
= GLX_GREEN_SIZE
;
2875 case WGL_ALPHA_BITS_ARB
:
2876 curGLXAttr
= GLX_ALPHA_SIZE
;
2878 case WGL_DEPTH_BITS_ARB
:
2879 curGLXAttr
= GLX_DEPTH_SIZE
;
2881 case WGL_STENCIL_BITS_ARB
:
2882 curGLXAttr
= GLX_STENCIL_SIZE
;
2884 case WGL_DOUBLE_BUFFER_ARB
:
2885 curGLXAttr
= GLX_DOUBLEBUFFER
;
2887 case WGL_STEREO_ARB
:
2888 curGLXAttr
= GLX_STEREO
;
2890 case WGL_AUX_BUFFERS_ARB
:
2891 curGLXAttr
= GLX_AUX_BUFFERS
;
2894 case WGL_SUPPORT_GDI_ARB
:
2895 if (!fmt
) goto pix_error
;
2896 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
2899 case WGL_DRAW_TO_BITMAP_ARB
:
2900 if (!fmt
) goto pix_error
;
2901 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
2904 case WGL_DRAW_TO_WINDOW_ARB
:
2905 case WGL_DRAW_TO_PBUFFER_ARB
:
2906 if (!fmt
) goto pix_error
;
2907 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2908 if (hTest
) goto get_error
;
2909 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2910 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2911 piValues
[i
] = GL_TRUE
;
2913 piValues
[i
] = GL_FALSE
;
2916 case WGL_SWAP_METHOD_ARB
:
2917 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2918 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2919 * point only ATI offers this.
2921 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2924 case WGL_PBUFFER_LARGEST_ARB
:
2925 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2928 case WGL_SAMPLE_BUFFERS_ARB
:
2929 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2932 case WGL_SAMPLES_ARB
:
2933 curGLXAttr
= GLX_SAMPLES_ARB
;
2936 case WGL_FLOAT_COMPONENTS_NV
:
2937 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2940 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
2941 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
2944 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
2945 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
2948 case WGL_ACCUM_RED_BITS_ARB
:
2949 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2951 case WGL_ACCUM_GREEN_BITS_ARB
:
2952 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2954 case WGL_ACCUM_BLUE_BITS_ARB
:
2955 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2957 case WGL_ACCUM_ALPHA_BITS_ARB
:
2958 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2960 case WGL_ACCUM_BITS_ARB
:
2961 if (!fmt
) goto pix_error
;
2962 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2963 if (hTest
) goto get_error
;
2965 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2966 if (hTest
) goto get_error
;
2968 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2969 if (hTest
) goto get_error
;
2971 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2972 if (hTest
) goto get_error
;
2977 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2980 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2981 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2982 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2984 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2985 * and check which options can work using iPixelFormat=0 and which not.
2986 * A problem would be that this function is an extension. This would
2987 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2989 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2990 if (!fmt
) goto pix_error
;
2991 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2992 if (hTest
) goto get_error
;
2995 piValues
[i
] = GL_FALSE
;
2998 wine_tsx11_unlock();
3002 wine_tsx11_unlock();
3003 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3007 wine_tsx11_unlock();
3008 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3013 * X11DRV_wglGetPixelFormatAttribfvARB
3015 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3017 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3023 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3025 /* Allocate a temporary array to store integer values */
3026 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3028 ERR("couldn't allocate %d array\n", nAttributes
);
3032 /* Piggy-back on wglGetPixelFormatAttribivARB */
3033 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3035 /* Convert integer values to float. Should also check for attributes
3036 that can give decimal values here */
3037 for (i
=0; i
<nAttributes
;i
++) {
3038 pfValues
[i
] = attr
[i
];
3042 HeapFree(GetProcessHeap(), 0, attr
);
3047 * X11DRV_wglBindTexImageARB
3049 * WGL_ARB_render_texture: wglBindTexImageARB
3051 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3053 Wine_GLPBuffer
* object
= hPbuffer
;
3054 GLboolean ret
= GL_FALSE
;
3056 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3057 if (NULL
== object
) {
3058 SetLastError(ERROR_INVALID_HANDLE
);
3061 if (!object
->use_render_texture
) {
3062 SetLastError(ERROR_INVALID_HANDLE
);
3066 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3067 static int init
= 0;
3068 int prev_binded_texture
= 0;
3069 GLXContext prev_context
;
3070 Drawable prev_drawable
;
3071 GLXContext tmp_context
;
3074 prev_context
= pglXGetCurrentContext();
3075 prev_drawable
= pglXGetCurrentDrawable();
3077 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3078 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3079 isn't ideal performance wise but I wasn't able to get other ways working.
3082 init
= 1; /* Only show the FIXME once for performance reasons */
3083 FIXME("partial stub!\n");
3086 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
3087 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3089 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3091 /* Switch to our pbuffer */
3092 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3094 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3095 * After that upload the pbuffer texture data. */
3096 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3097 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3099 /* Switch back to the original drawable and upload the pbuffer-texture */
3100 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3101 pglXDestroyContext(gdi_display
, tmp_context
);
3102 wine_tsx11_unlock();
3106 if (NULL
!= pglXBindTexImageATI
) {
3111 case WGL_FRONT_LEFT_ARB
:
3112 buffer
= GLX_FRONT_LEFT_ATI
;
3114 case WGL_FRONT_RIGHT_ARB
:
3115 buffer
= GLX_FRONT_RIGHT_ATI
;
3117 case WGL_BACK_LEFT_ARB
:
3118 buffer
= GLX_BACK_LEFT_ATI
;
3120 case WGL_BACK_RIGHT_ARB
:
3121 buffer
= GLX_BACK_RIGHT_ATI
;
3124 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3128 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3129 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3130 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3131 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3132 * works fine using our pbuffer emulation path.
3135 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3136 wine_tsx11_unlock();
3142 * X11DRV_wglReleaseTexImageARB
3144 * WGL_ARB_render_texture: wglReleaseTexImageARB
3146 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3148 Wine_GLPBuffer
* object
= hPbuffer
;
3149 GLboolean ret
= GL_FALSE
;
3151 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3152 if (NULL
== object
) {
3153 SetLastError(ERROR_INVALID_HANDLE
);
3156 if (!object
->use_render_texture
) {
3157 SetLastError(ERROR_INVALID_HANDLE
);
3160 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3163 if (NULL
!= pglXReleaseTexImageATI
) {
3168 case WGL_FRONT_LEFT_ARB
:
3169 buffer
= GLX_FRONT_LEFT_ATI
;
3171 case WGL_FRONT_RIGHT_ARB
:
3172 buffer
= GLX_FRONT_RIGHT_ATI
;
3174 case WGL_BACK_LEFT_ARB
:
3175 buffer
= GLX_BACK_LEFT_ATI
;
3177 case WGL_BACK_RIGHT_ARB
:
3178 buffer
= GLX_BACK_RIGHT_ATI
;
3181 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3185 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3186 wine_tsx11_unlock();
3192 * X11DRV_wglGetExtensionsStringEXT
3194 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3196 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3197 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3198 return WineGLInfo
.wglExtensions
;
3202 * X11DRV_wglGetSwapIntervalEXT
3204 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3206 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3207 FIXME("(),stub!\n");
3208 return swap_interval
;
3212 * X11DRV_wglSwapIntervalEXT
3214 * WGL_EXT_swap_control: wglSwapIntervalEXT
3216 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3219 TRACE("(%d)\n", interval
);
3220 swap_interval
= interval
;
3221 if (NULL
!= pglXSwapIntervalSGI
) {
3223 ret
= !pglXSwapIntervalSGI(interval
);
3224 wine_tsx11_unlock();
3226 else WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3231 * X11DRV_wglAllocateMemoryNV
3233 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3235 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3237 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3239 if (pglXAllocateMemoryNV
)
3242 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3243 wine_tsx11_unlock();
3249 * X11DRV_wglFreeMemoryNV
3251 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3253 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3254 TRACE("(%p)\n", pointer
);
3255 if (pglXFreeMemoryNV
== NULL
)
3259 pglXFreeMemoryNV(pointer
);
3260 wine_tsx11_unlock();
3264 * X11DRV_wglSetPixelFormatWINE
3266 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3267 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3269 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3271 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
3273 if (!has_opengl()) return FALSE
;
3275 if (physDev
->current_pf
== iPixelFormat
) return TRUE
;
3277 /* Relay to the core SetPixelFormat */
3278 TRACE("Changing iPixelFormat from %d to %d\n", physDev
->current_pf
, iPixelFormat
);
3279 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
3283 * glxRequireVersion (internal)
3285 * Check if the supported GLX version matches requiredVersion.
3287 static BOOL
glxRequireVersion(int requiredVersion
)
3289 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3290 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3296 static BOOL
glxRequireExtension(const char *requiredExtension
)
3298 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3305 static void register_extension_string(const char *ext
)
3307 if (WineGLInfo
.wglExtensions
[0])
3308 strcat(WineGLInfo
.wglExtensions
, " ");
3309 strcat(WineGLInfo
.wglExtensions
, ext
);
3311 TRACE("'%s'\n", ext
);
3314 static BOOL
register_extension(const WineGLExtension
* ext
)
3318 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3319 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3321 register_extension_string(ext
->extName
);
3323 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3324 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3329 static const WineGLExtension WGL_internal_functions
=
3333 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3334 { "wglFinish", X11DRV_wglFinish
},
3335 { "wglFlush", X11DRV_wglFlush
},
3340 static const WineGLExtension WGL_ARB_extensions_string
=
3342 "WGL_ARB_extensions_string",
3344 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3348 static const WineGLExtension WGL_ARB_make_current_read
=
3350 "WGL_ARB_make_current_read",
3352 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3353 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3357 static const WineGLExtension WGL_ARB_multisample
=
3359 "WGL_ARB_multisample",
3362 static const WineGLExtension WGL_ARB_pbuffer
=
3366 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3367 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3368 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3369 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3370 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3371 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3375 static const WineGLExtension WGL_ARB_pixel_format
=
3377 "WGL_ARB_pixel_format",
3379 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3380 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3381 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3385 static const WineGLExtension WGL_ARB_render_texture
=
3387 "WGL_ARB_render_texture",
3389 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3390 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3394 static const WineGLExtension WGL_EXT_extensions_string
=
3396 "WGL_EXT_extensions_string",
3398 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3402 static const WineGLExtension WGL_EXT_swap_control
=
3404 "WGL_EXT_swap_control",
3406 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3407 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3411 static const WineGLExtension WGL_NV_vertex_array_range
=
3413 "WGL_NV_vertex_array_range",
3415 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3416 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3420 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3422 "WGL_WINE_pixel_format_passthrough",
3424 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE
},
3429 * X11DRV_WineGL_LoadExtensions
3431 static void X11DRV_WineGL_LoadExtensions(void)
3433 WineGLInfo
.wglExtensions
[0] = 0;
3435 /* Load Wine internal functions */
3436 register_extension(&WGL_internal_functions
);
3438 /* ARB Extensions */
3440 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3442 register_extension_string("WGL_ARB_pixel_format_float");
3443 register_extension_string("WGL_ATI_pixel_format_float");
3446 register_extension(&WGL_ARB_extensions_string
);
3448 if (glxRequireVersion(3))
3449 register_extension(&WGL_ARB_make_current_read
);
3451 if (glxRequireExtension("GLX_ARB_multisample"))
3452 register_extension(&WGL_ARB_multisample
);
3454 /* In general pbuffer functionality requires support in the X-server. The functionality is
3455 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3456 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3457 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3459 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3460 * without support in the X-server (which other Mesa based drivers require).
3462 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3463 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3464 * is available pbuffers must be available too. */
3465 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3466 register_extension(&WGL_ARB_pbuffer
);
3468 register_extension(&WGL_ARB_pixel_format
);
3470 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3471 if (glxRequireExtension("GLX_ATI_render_texture") ||
3472 glxRequireExtension("GLX_ARB_render_texture") ||
3473 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3475 register_extension(&WGL_ARB_render_texture
);
3477 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3478 if(glxRequireExtension("GLX_NV_float_buffer"))
3479 register_extension_string("WGL_NV_float_buffer");
3481 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3482 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3483 register_extension_string("WGL_NV_texture_rectangle");
3486 /* EXT Extensions */
3488 register_extension(&WGL_EXT_extensions_string
);
3490 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3491 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3492 register_extension(&WGL_EXT_swap_control
);
3494 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3495 register_extension_string("WGL_EXT_framebuffer_sRGB");
3497 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3498 register_extension_string("WGL_EXT_pixel_format_packed_float");
3500 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3501 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3502 register_extension(&WGL_NV_vertex_array_range
);
3504 /* WINE-specific WGL Extensions */
3506 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3507 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3509 register_extension(&WGL_WINE_pixel_format_passthrough
);
3513 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3519 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3520 ret
= physDev
->drawable
; /* PBuffer */
3522 ret
= physDev
->bitmap
->glxpixmap
;
3524 else if(physDev
->gl_drawable
)
3525 ret
= physDev
->gl_drawable
;
3527 ret
= physDev
->drawable
;
3531 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3534 pglXDestroyGLXPixmap(display
, glxpixmap
);
3535 wine_tsx11_unlock();
3540 * X11DRV_SwapBuffers
3542 * Swap the buffers of this DC
3544 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3546 GLXDrawable drawable
;
3547 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3549 if (!has_opengl()) return FALSE
;
3551 TRACE("(%p)\n", physDev
);
3553 drawable
= get_glxdrawable(physDev
);
3557 if(physDev
->pixmap
) {
3558 if(pglXCopySubBufferMESA
) {
3559 int w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
3560 int h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
3562 /* (glX)SwapBuffers has an implicit glFlush effect, however
3563 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3567 pglXCopySubBufferMESA(gdi_display
, drawable
, 0, 0, w
, h
);
3570 pglXSwapBuffers(gdi_display
, drawable
);
3573 pglXSwapBuffers(gdi_display
, drawable
);
3575 flush_gl_drawable(physDev
);
3576 wine_tsx11_unlock();
3581 static long prev_time
, start_time
;
3582 static unsigned long frames
, frames_total
;
3584 DWORD time
= GetTickCount();
3587 /* every 1.5 seconds */
3588 if (time
- prev_time
> 1500) {
3589 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3590 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3593 if(start_time
== 0) start_time
= time
;
3600 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3602 WineGLPixelFormat
*fmt
;
3605 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3610 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3611 wine_tsx11_unlock();
3615 #else /* no OpenGL includes */
3617 void X11DRV_OpenGL_Cleanup(void)
3621 static inline void opengl_error(void)
3624 if (!warned
++) ERR("No OpenGL support compiled in.\n");
3627 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3632 void mark_drawable_dirty(Drawable old
, Drawable
new)
3636 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
3640 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3645 /***********************************************************************
3646 * ChoosePixelFormat (X11DRV.@)
3648 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3649 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3654 /***********************************************************************
3655 * DescribePixelFormat (X11DRV.@)
3657 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3660 PIXELFORMATDESCRIPTOR
*ppfd
) {
3665 /***********************************************************************
3666 * GetPixelFormat (X11DRV.@)
3668 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3673 /***********************************************************************
3674 * SetPixelFormat (X11DRV.@)
3676 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3678 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3683 /***********************************************************************
3684 * SwapBuffers (X11DRV.@)
3686 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3692 * X11DRV_wglCopyContext
3694 * For OpenGL32 wglCopyContext.
3696 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
3702 * X11DRV_wglCreateContext
3704 * For OpenGL32 wglCreateContext.
3706 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3712 * X11DRV_wglDeleteContext
3714 * For OpenGL32 wglDeleteContext.
3716 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3722 * X11DRV_wglGetProcAddress
3724 * For OpenGL32 wglGetProcAddress.
3726 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3731 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3737 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3743 * X11DRV_wglMakeCurrent
3745 * For OpenGL32 wglMakeCurrent.
3747 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3753 * X11DRV_wglShareLists
3755 * For OpenGL32 wglShareLists.
3757 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3763 * X11DRV_wglUseFontBitmapsA
3765 * For OpenGL32 wglUseFontBitmapsA.
3767 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3774 * X11DRV_wglUseFontBitmapsW
3776 * For OpenGL32 wglUseFontBitmapsW.
3778 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3785 * X11DRV_wglSetPixelFormatWINE
3787 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3788 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3790 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3796 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3801 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3806 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3811 #endif /* defined(HAVE_OPENGL) */