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
;
603 int pixelattrib
= ~0;
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 drawattrib
|= GLX_PBUFFER_BIT
;
763 case WGL_FLOAT_COMPONENTS_NV
:
764 nvfloatattrib
= iWGLAttr
[++cur
];
765 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
767 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
768 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
769 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
770 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
771 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
772 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
773 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
774 pop
= iWGLAttr
[++cur
];
775 /** cannot be converted, see direct handling on
776 * - wglGetPixelFormatAttribivARB
777 * TODO: wglChoosePixelFormat
780 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
781 pop
= iWGLAttr
[++cur
];
782 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
783 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
786 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
787 pop
= iWGLAttr
[++cur
];
788 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
789 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
792 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
798 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
799 * all formats. Unless drawattrib is set to a non-zero value override it with ~0, so that pixmap and pbuffer
800 * formats appear as well. */
801 if(!drawattrib
) drawattrib
= ~0;
802 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
803 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
805 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
806 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to ~0 unless
807 * it is overridden. */
808 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
809 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
811 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
812 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
813 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
814 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
820 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
822 int render_type
=0, render_type_bit
;
823 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
824 switch(render_type_bit
)
827 render_type
= GLX_RGBA_TYPE
;
829 case GLX_COLOR_INDEX_BIT
:
830 render_type
= GLX_COLOR_INDEX_TYPE
;
832 case GLX_RGBA_FLOAT_BIT
:
833 render_type
= GLX_RGBA_FLOAT_TYPE
;
835 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
836 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
839 ERR("Unknown render_type: %x\n", render_type
);
844 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
845 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
848 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
849 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
851 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
852 * the GLX_PIXMAP_BIT set. */
853 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
856 static WineGLPixelFormat
*get_formats(Display
*display
, int *size_ret
, int *onscreen_size_ret
)
858 static WineGLPixelFormat
*list
;
859 static int size
, onscreen_size
;
861 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
863 XVisualInfo
*visinfo
;
868 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
869 if (NULL
== cfgs
|| 0 == nCfgs
) {
870 if(cfgs
!= NULL
) XFree(cfgs
);
872 ERR("glXChooseFBConfig returns NULL\n");
876 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
877 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
878 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
879 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
881 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
883 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
885 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
888 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
890 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
)*sizeof(WineGLPixelFormat
));
892 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
893 * Do this as GLX doesn't guarantee that the list is sorted */
894 for(run
=0; run
< 2; run
++)
896 for(i
=0; i
<nCfgs
; i
++) {
897 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
898 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
900 /* The first run we only add onscreen formats (ones which have an associated X Visual).
901 * The second run we only set offscreen formats. */
904 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
905 * The contents is copied to the destination using XCopyArea. For the copying to work
906 * the depth of the source and destination window should be the same. In general this should
907 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
908 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
909 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
910 * list formats with the same depth. */
911 if(visinfo
->depth
!= screen_depth
)
917 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
918 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
919 list
[size
].fbconfig
= cfgs
[i
];
920 list
[size
].fmt_id
= fmt_id
;
921 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
922 list
[size
].offscreenOnly
= FALSE
;
923 list
[size
].dwFlags
= 0;
927 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
928 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
930 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
931 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
932 list
[size
].fbconfig
= cfgs
[i
];
933 list
[size
].fmt_id
= fmt_id
;
934 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
935 list
[size
].offscreenOnly
= FALSE
;
936 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
940 } else if(run
&& !visinfo
) {
941 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
942 list
[size
].iPixelFormat
= size
+1; /* The index starts at 1 */
943 list
[size
].fbconfig
= cfgs
[i
];
944 list
[size
].fmt_id
= fmt_id
;
945 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
946 list
[size
].offscreenOnly
= TRUE
;
947 list
[size
].dwFlags
= 0;
951 if (visinfo
) XFree(visinfo
);
955 if(cfgs
!= NULL
) XFree(cfgs
);
958 if (size_ret
) *size_ret
= size
;
959 if (onscreen_size_ret
) *onscreen_size_ret
= onscreen_size
;
964 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
965 * In our WGL implementation we only support a subset of these formats namely the format of
966 * Wine's main visual and offscreen formats (if they are available).
967 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
968 * and it returns the number of supported WGL formats in fmt_count.
970 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
972 WineGLPixelFormat
*list
, *res
= NULL
;
973 int size
, onscreen_size
;
975 if (!(list
= get_formats(display
, &size
, &onscreen_size
))) return NULL
;
977 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
978 * iPixelFormat in case of probing the number of pixelformats.
980 if((iPixelFormat
> 0) && (iPixelFormat
<= size
) &&
981 (!list
[iPixelFormat
-1].offscreenOnly
|| AllowOffscreen
)) {
982 res
= &list
[iPixelFormat
-1];
983 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
989 *fmt_count
= onscreen_size
;
991 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
996 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
997 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
, DWORD dwFlags
)
999 WineGLPixelFormat
*list
;
1002 if (!(list
= get_formats(display
, &size
, NULL
))) return NULL
;
1004 for(i
=0; i
<size
; i
++) {
1005 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1006 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1007 if( (list
[i
].fmt_id
== fmt_id
) && ((list
[i
].dwFlags
& dwFlags
) == dwFlags
) ) {
1008 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list
[i
].iPixelFormat
, fmt_id
);
1012 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1016 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
1018 WineGLPixelFormat
*fmt
;
1020 if (!fbconfig_id
) return 0;
1022 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
1024 return fmt
->iPixelFormat
;
1025 /* This will happen on hwnds without a pixel format set; it's ok */
1030 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1031 void mark_drawable_dirty(Drawable old
, Drawable
new)
1033 Wine_GLContext
*ctx
;
1034 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
1035 if (old
== ctx
->drawables
[0]) {
1036 ctx
->drawables
[0] = new;
1037 ctx
->refresh_drawables
= TRUE
;
1039 if (old
== ctx
->drawables
[1]) {
1040 ctx
->drawables
[1] = new;
1041 ctx
->refresh_drawables
= TRUE
;
1046 /* Given the current context, make sure its drawable is sync'd */
1047 static inline void sync_context(Wine_GLContext
*context
)
1049 if(context
&& context
->refresh_drawables
) {
1050 if (glxRequireVersion(3))
1051 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1052 context
->drawables
[1], context
->ctx
);
1054 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1055 context
->refresh_drawables
= FALSE
;
1060 static GLXContext
create_glxcontext(Display
*display
, Wine_GLContext
*context
, GLXContext shareList
)
1064 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1065 BOOL indirect
= (context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? FALSE
: TRUE
;
1068 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1069 else /* Create a GLX Context for a pbuffer */
1070 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1076 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
1078 return pglXCreateGLXPixmap(display
, vis
, parent
);
1082 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
, WineGLPixelFormat
*fmt
)
1089 vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1091 if(vis
->depth
== physDev
->bitmap
->pixmap_depth
)
1092 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
1095 wine_tsx11_unlock();
1096 TRACE("return %lx\n", ret
);
1101 * X11DRV_ChoosePixelFormat
1103 * Equivalent to glXChooseVisual.
1105 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
1106 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1107 WineGLPixelFormat
*list
;
1112 int bestFormat
= -1;
1113 int bestDBuffer
= -1;
1114 int bestStereo
= -1;
1118 int bestStencil
= -1;
1121 if (!has_opengl()) return 0;
1123 if (TRACE_ON(wgl
)) {
1124 TRACE("(%p,%p)\n", physDev
, ppfd
);
1126 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1129 if (!(list
= get_formats(gdi_display
, NULL
, &onscreen_size
))) return 0;
1132 for(i
=0; i
<onscreen_size
; i
++)
1136 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1137 WineGLPixelFormat
*fmt
= &list
[i
];
1140 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1141 if (value
& GLX_RGBA_BIT
)
1142 iPixelType
= PFD_TYPE_RGBA
;
1144 iPixelType
= PFD_TYPE_COLORINDEX
;
1146 if (ppfd
->iPixelType
!= iPixelType
)
1148 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1152 /* Only use bitmap capable for formats for bitmap rendering.
1153 * See get_formats for more info. */
1154 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
))
1156 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
+1);
1160 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1161 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1162 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1163 if (value
) dwFlags
|= PFD_STEREO
;
1164 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1165 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1166 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1167 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1168 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1170 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1171 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1172 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1173 * formats without the given flag set.
1174 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1175 * has indicated that a format without stereo is returned when stereo is unavailable.
1176 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1177 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1179 * To summarize the following is most likely the correct behavior:
1180 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1181 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1182 * stereo don't care -> it doesn't matter whether we get stereo or not
1184 * In Wine we will treat no-stereo the same way as don't care because it makes
1185 * format selection even more complicated and second drivers with Stereo advertise
1186 * each format twice anyway.
1189 /* Doublebuffer, see the comments above */
1190 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1191 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1192 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1194 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1195 bestStereo
= dwFlags
& PFD_STEREO
;
1199 bestStencil
= stencil
;
1204 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1208 /* Stereo, see the comments above. */
1209 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1210 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1211 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1213 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1214 bestStereo
= dwFlags
& PFD_STEREO
;
1218 bestStencil
= stencil
;
1223 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1227 /* Below we will do a number of checks to select the 'best' pixelformat.
1228 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1229 * The code works by trying to match the most important options as close as possible.
1230 * When a reasonable format is found, we will try to match more options.
1231 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1232 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1233 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1236 if(ppfd
->cColorBits
) {
1237 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1238 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1240 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1241 bestStereo
= dwFlags
& PFD_STEREO
;
1245 bestStencil
= stencil
;
1249 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1250 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1256 if(ppfd
->cAlphaBits
) {
1257 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1258 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1260 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1261 bestStereo
= dwFlags
& PFD_STEREO
;
1265 bestStencil
= stencil
;
1269 } else if(bestAlpha
!= alpha
) {
1270 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1276 if(ppfd
->cDepthBits
) {
1277 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1278 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1280 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1281 bestStereo
= dwFlags
& PFD_STEREO
;
1285 bestStencil
= stencil
;
1289 } else if(bestDepth
!= depth
) {
1290 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1296 if(ppfd
->cStencilBits
) {
1297 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1298 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1300 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1301 bestStereo
= dwFlags
& PFD_STEREO
;
1305 bestStencil
= stencil
;
1309 } else if(bestStencil
!= stencil
) {
1310 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1316 if(ppfd
->cAuxBuffers
) {
1317 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1318 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1320 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1321 bestStereo
= dwFlags
& PFD_STEREO
;
1325 bestStencil
= stencil
;
1329 } else if(bestAux
!= aux
) {
1330 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1336 if(bestFormat
== -1) {
1337 TRACE("No matching mode was found returning 0\n");
1341 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1342 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, list
[bestFormat
].fmt_id
);
1345 wine_tsx11_unlock();
1350 * X11DRV_DescribePixelFormat
1352 * Get the pixel-format descriptor associated to the given id
1354 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1357 PIXELFORMATDESCRIPTOR
*ppfd
) {
1358 /*XVisualInfo *vis;*/
1361 WineGLPixelFormat
*fmt
;
1365 if (!has_opengl()) return 0;
1367 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1369 /* 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 */
1370 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1372 /* The application is only querying the number of pixelformats */
1374 } else if(fmt
== NULL
) {
1375 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1379 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1380 ERR("Wrong structure size !\n");
1381 /* Should set error */
1387 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1388 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1391 /* These flags are always the same... */
1392 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1393 /* Now the flags extracted from the Visual */
1397 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1398 if(value
& GLX_WINDOW_BIT
)
1399 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1401 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1402 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1403 * 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
1404 * offered the GDI bit either. */
1405 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1407 /* PFD_GENERIC_FORMAT - gdi software rendering
1408 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1409 * none set - full hardware accelerated by a ICD
1411 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1412 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1414 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1416 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1417 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1419 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1422 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1423 if (value
& GLX_RGBA_BIT
)
1424 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1426 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1429 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1430 ppfd
->cColorBits
= value
;
1432 /* Red, green, blue and alpha bits / shifts */
1433 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1434 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1435 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1436 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1437 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1439 ppfd
->cRedBits
= rb
;
1440 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1441 ppfd
->cBlueBits
= bb
;
1442 ppfd
->cBlueShift
= ab
;
1443 ppfd
->cGreenBits
= gb
;
1444 ppfd
->cGreenShift
= bb
+ ab
;
1445 ppfd
->cAlphaBits
= ab
;
1446 ppfd
->cAlphaShift
= 0;
1449 ppfd
->cRedShift
= 0;
1450 ppfd
->cBlueBits
= 0;
1451 ppfd
->cBlueShift
= 0;
1452 ppfd
->cGreenBits
= 0;
1453 ppfd
->cGreenShift
= 0;
1454 ppfd
->cAlphaBits
= 0;
1455 ppfd
->cAlphaShift
= 0;
1458 /* Accum RGBA bits */
1459 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1460 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1461 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1462 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1464 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1465 ppfd
->cAccumRedBits
= rb
;
1466 ppfd
->cAccumGreenBits
= gb
;
1467 ppfd
->cAccumBlueBits
= bb
;
1468 ppfd
->cAccumAlphaBits
= ab
;
1471 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1472 ppfd
->cAuxBuffers
= value
;
1475 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1476 ppfd
->cDepthBits
= value
;
1479 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1480 ppfd
->cStencilBits
= value
;
1482 wine_tsx11_unlock();
1484 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1486 if (TRACE_ON(wgl
)) {
1487 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1494 * X11DRV_GetPixelFormat
1496 * Get the pixel-format id used by this DC
1498 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1499 WineGLPixelFormat
*fmt
;
1501 TRACE("(%p)\n", physDev
);
1503 if (!physDev
->current_pf
) return 0; /* not set yet */
1505 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1508 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1511 else if(fmt
->offscreenOnly
)
1513 /* Offscreen formats can't be used with traditional WGL calls.
1514 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1515 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1519 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1520 return physDev
->current_pf
;
1523 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1524 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1525 * set the pixel format multiple times. */
1526 static BOOL
internal_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1528 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1529 WineGLPixelFormat
*fmt
;
1533 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1534 if(get_glxdrawable(physDev
) == root_window
)
1536 ERR("Invalid operation on root_window\n");
1540 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1541 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1543 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1548 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1549 wine_tsx11_unlock();
1551 hwnd
= WindowFromDC(physDev
->hdc
);
1553 if(!(value
&GLX_WINDOW_BIT
)) {
1554 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1558 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, (WPARAM
)fmt
->fmt_id
, 0)) {
1559 ERR("Couldn't set format of the window, returning failure\n");
1563 else if(physDev
->bitmap
) {
1564 if(!(value
&GLX_PIXMAP_BIT
)) {
1565 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat
);
1569 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
, fmt
);
1570 if(!physDev
->bitmap
->glxpixmap
) {
1571 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat
);
1576 FIXME("called on a non-window, non-bitmap object?\n");
1579 physDev
->current_pf
= iPixelFormat
;
1581 if (TRACE_ON(wgl
)) {
1585 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1587 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1589 TRACE(" FBConfig have :\n");
1590 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1591 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1592 TRACE(" - VISUAL_ID 0x%x\n", value
);
1593 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1594 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1596 wine_tsx11_unlock();
1603 * X11DRV_SetPixelFormat
1605 * Set the pixel-format id used by this DC
1607 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1609 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1610 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1612 if (!has_opengl()) return FALSE
;
1614 if(physDev
->current_pf
) /* cannot change it if already set */
1615 return (physDev
->current_pf
== iPixelFormat
);
1617 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
1621 * X11DRV_wglCopyContext
1623 * For OpenGL32 wglCopyContext.
1625 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
1626 Wine_GLContext
*src
= (Wine_GLContext
*)hglrcSrc
;
1627 Wine_GLContext
*dst
= (Wine_GLContext
*)hglrcDst
;
1629 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc
, hglrcDst
, mask
);
1631 /* There is a slight difference in the way GL contexts share display lists in WGL and GLX.
1632 * In case of GLX you need to specify this at context creation time but in case of WGL you
1633 * do this using wglShareLists which you can call after creating the context.
1634 * To emulate WGL we try to delay the creation of the context until wglShareLists or wglMakeCurrent.
1635 * Up to now that works fine.
1637 * The delayed GLX context creation could cause issues for wglCopyContext as it might get called
1638 * when there is no GLX context yet. The chance this will cause problems is small as at the time of
1639 * writing Wine has had OpenGL support for more than 7 years and this function has remained a stub
1642 if(!src
->ctx
|| !dst
->ctx
) {
1643 /* NOTE: As a special case, if both GLX contexts are NULL, that means
1644 * neither WGL context was made current. In that case, both contexts
1645 * are in a default state, so any copy would no-op.
1647 if(!src
->ctx
&& !dst
->ctx
) {
1648 TRACE("No source or destination contexts set. No-op.\n");
1654 src
->ctx
= create_glxcontext(gdi_display
, src
, NULL
);
1655 TRACE(" created a delayed OpenGL context (%p)\n", src
->ctx
);
1657 else if (!dst
->ctx
) {
1659 dst
->ctx
= create_glxcontext(gdi_display
, dst
, NULL
);
1660 TRACE(" created a delayed OpenGL context (%p)\n", dst
->ctx
);
1666 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1667 wine_tsx11_unlock();
1669 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1674 * X11DRV_wglCreateContext
1676 * For OpenGL32 wglCreateContext.
1678 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1680 Wine_GLContext
*ret
;
1681 WineGLPixelFormat
*fmt
;
1682 int hdcPF
= physDev
->current_pf
;
1684 HDC hdc
= physDev
->hdc
;
1686 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1688 if (!has_opengl()) return 0;
1690 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1691 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1692 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1693 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1694 * If this fails something is very wrong on the system. */
1696 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1697 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1701 /* The context will be allocated in the wglMakeCurrent call */
1703 ret
= alloc_context();
1704 wine_tsx11_unlock();
1709 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1711 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1716 * X11DRV_wglDeleteContext
1718 * For OpenGL32 wglDeleteContext.
1720 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1722 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1725 TRACE("(%p)\n", hglrc
);
1727 if (!has_opengl()) return 0;
1730 /* A game (Half Life not to name it) deletes twice the same context,
1731 * so make sure it is valid first */
1732 if (is_valid_context( ctx
))
1734 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1739 WARN("Error deleting context !\n");
1740 SetLastError(ERROR_INVALID_HANDLE
);
1743 wine_tsx11_unlock();
1749 * X11DRV_wglGetCurrentReadDCARB
1751 * For OpenGL32 wglGetCurrentReadDCARB.
1753 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1756 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1758 if (ctx
) ret
= ctx
->read_hdc
;
1760 TRACE(" returning %p (GL drawable %lu)\n", ret
, ctx
? ctx
->drawables
[1] : 0);
1765 * X11DRV_wglGetProcAddress
1767 * For OpenGL32 wglGetProcAddress.
1769 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1772 const WineGLExtension
*ext
;
1774 int padding
= 32 - strlen(lpszProc
);
1778 if (!has_opengl()) return NULL
;
1780 /* Check the table of WGL extensions to see if we need to return a WGL extension
1781 * or a function pointer to a native OpenGL function. */
1782 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1783 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1785 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1786 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1787 ext
= WineGLExtensionList
[i
];
1788 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1789 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1790 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1791 return ext
->extEntryPoints
[j
].funcAddress
;
1797 WARN("(%s) - not found\n", lpszProc
);
1802 * X11DRV_wglMakeCurrent
1804 * For OpenGL32 wglMakeCurrent.
1806 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1808 HDC hdc
= physDev
->hdc
;
1809 DWORD type
= GetObjectType(hdc
);
1810 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1812 TRACE("(%p,%p)\n", hdc
, hglrc
);
1814 if (!has_opengl()) return FALSE
;
1817 if (hglrc
== NULL
) {
1818 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1819 NtCurrentTeb()->glContext
= NULL
;
1820 } else if (ctx
->fmt
->iPixelFormat
!= physDev
->current_pf
) {
1821 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1822 hdc
, physDev
->current_pf
, ctx
, ctx
->fmt
->iPixelFormat
);
1823 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1826 Drawable drawable
= get_glxdrawable(physDev
);
1827 if (ctx
->ctx
== NULL
) {
1828 /* The describe lines below are for debugging purposes only */
1829 if (TRACE_ON(wgl
)) {
1830 describeDrawable(physDev
);
1831 describeContext(ctx
);
1834 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1835 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1837 TRACE(" Creating GLX Context\n");
1838 ctx
->ctx
= create_glxcontext(gdi_display
, ctx
, NULL
);
1839 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1841 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1842 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1843 NtCurrentTeb()->glContext
= ctx
;
1847 ctx
->read_hdc
= hdc
;
1848 ctx
->drawables
[0] = drawable
;
1849 ctx
->drawables
[1] = drawable
;
1850 ctx
->refresh_drawables
= FALSE
;
1852 if (type
== OBJ_MEMDC
)
1854 ctx
->do_escape
= TRUE
;
1855 pglDrawBuffer(GL_FRONT_LEFT
);
1859 wine_tsx11_unlock();
1860 TRACE(" returning %s\n", (ret
? "True" : "False"));
1865 * X11DRV_wglMakeContextCurrentARB
1867 * For OpenGL32 wglMakeContextCurrentARB
1869 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1873 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1875 if (!has_opengl()) return 0;
1878 if (hglrc
== NULL
) {
1879 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1880 NtCurrentTeb()->glContext
= NULL
;
1882 if (NULL
== pglXMakeContextCurrent
) {
1885 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1886 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1887 Drawable d_read
= get_glxdrawable(pReadDev
);
1889 if (ctx
->ctx
== NULL
) {
1890 ctx
->ctx
= create_glxcontext(gdi_display
, ctx
, NULL
);
1891 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1893 ctx
->hdc
= pDrawDev
->hdc
;
1894 ctx
->read_hdc
= pReadDev
->hdc
;
1895 ctx
->drawables
[0] = d_draw
;
1896 ctx
->drawables
[1] = d_read
;
1897 ctx
->refresh_drawables
= FALSE
;
1898 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1899 NtCurrentTeb()->glContext
= ctx
;
1902 wine_tsx11_unlock();
1904 TRACE(" returning %s\n", (ret
? "True" : "False"));
1909 * X11DRV_wglShareLists
1911 * For OpenGL32 wglShareLists.
1913 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1914 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1915 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1917 TRACE("(%p, %p)\n", org
, dest
);
1919 if (!has_opengl()) return FALSE
;
1921 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1922 ERR("Could not share display lists, context already created !\n");
1925 if(org
&& dest
&& (GetObjectType(org
->hdc
) == OBJ_MEMDC
) ^ (GetObjectType(dest
->hdc
) == OBJ_MEMDC
)) {
1926 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1929 if (org
->ctx
== NULL
) {
1931 describeContext(org
);
1933 org
->ctx
= create_glxcontext(gdi_display
, org
, NULL
);
1934 wine_tsx11_unlock();
1935 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1939 describeContext(dest
);
1940 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1941 wine_tsx11_unlock();
1942 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1949 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1951 /* We are running using client-side rendering fonts... */
1953 unsigned int glyph
, size
= 0;
1954 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1958 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1959 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1960 wine_tsx11_unlock();
1962 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1963 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
1964 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
1965 unsigned int height
, width_int
;
1967 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1968 if (needed_size
== GDI_ERROR
) {
1969 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1972 TRACE(" - needed size : %d\n", needed_size
);
1975 if (needed_size
> size
) {
1977 HeapFree(GetProcessHeap(), 0, bitmap
);
1978 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1979 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1980 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1982 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) == GDI_ERROR
)
1984 if (TRACE_ON(wgl
)) {
1985 unsigned int height
, width
, bitmask
;
1986 unsigned char *bitmap_
= bitmap
;
1988 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1989 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1990 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1991 if (needed_size
!= 0) {
1992 TRACE(" - bitmap :\n");
1993 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1995 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
2000 if (*bitmap_
& bitmask
)
2005 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
2011 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2012 * glyph for it to be drawn properly.
2014 if (needed_size
!= 0) {
2015 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
2016 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
2018 for (width
= 0; width
< width_int
; width
++) {
2019 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
2020 ((int *) bitmap
)[height
* width_int
+ width
];
2026 pglNewList(listBase
++, GL_COMPILE
);
2027 if (needed_size
!= 0) {
2028 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2029 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
2030 gm
.gmCellIncX
, gm
.gmCellIncY
,
2033 /* This is the case of 'empty' glyphs like the space character */
2034 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
2037 wine_tsx11_unlock();
2041 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2042 wine_tsx11_unlock();
2044 HeapFree(GetProcessHeap(), 0, bitmap
);
2045 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2050 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
2051 wine_tsx11_unlock();
2053 HeapFree(GetProcessHeap(), 0, bitmap
);
2054 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
2059 * X11DRV_wglUseFontBitmapsA
2061 * For OpenGL32 wglUseFontBitmapsA.
2063 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2065 Font fid
= physDev
->font
;
2067 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2069 if (!has_opengl()) return FALSE
;
2072 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
2076 /* I assume that the glyphs are at the same position for X and for Windows */
2077 pglXUseXFont(fid
, first
, count
, listBase
);
2078 wine_tsx11_unlock();
2083 * X11DRV_wglUseFontBitmapsW
2085 * For OpenGL32 wglUseFontBitmapsW.
2087 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
2089 Font fid
= physDev
->font
;
2091 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
2093 if (!has_opengl()) return FALSE
;
2096 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
2099 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2102 /* I assume that the glyphs are at the same position for X and for Windows */
2103 pglXUseXFont(fid
, first
, count
, listBase
);
2104 wine_tsx11_unlock();
2108 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2109 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
2116 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2118 pglGetIntegerv(pname
, params
);
2120 * if we cannot find a Wine Context
2121 * we only have the default wine desktop context,
2122 * so if we have only a 24 depth say we have 32
2124 if (!ctx
&& *params
== 24) {
2127 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2132 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2134 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2135 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2139 pglGetIntegerv(pname
, params
);
2142 wine_tsx11_unlock();
2145 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
2149 if (!physDev
->gl_copy
)
2152 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
2153 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
2155 if(w
> 0 && h
> 0) {
2156 Drawable src
= physDev
->pixmap
;
2157 if(!src
) src
= physDev
->gl_drawable
;
2159 /* The GL drawable may be lagged behind if we don't flush first, so
2160 * flush the display make sure we copy up-to-date data */
2162 XFlush(gdi_display
);
2163 XSetFunction(gdi_display
, physDev
->gc
, GXcopy
);
2164 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
2165 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
2166 wine_tsx11_unlock();
2171 static void WINAPI
X11DRV_wglFinish(void)
2173 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2174 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2179 wine_tsx11_unlock();
2180 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2183 static void WINAPI
X11DRV_wglFlush(void)
2185 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2186 enum x11drv_escape_codes code
= X11DRV_FLUSH_GL_DRAWABLE
;
2191 wine_tsx11_unlock();
2192 if (ctx
) ExtEscape(ctx
->hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2196 * X11DRV_wglGetExtensionsStringARB
2198 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2200 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2201 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2202 return WineGLInfo
.wglExtensions
;
2206 * X11DRV_wglCreatePbufferARB
2208 * WGL_ARB_pbuffer: wglCreatePbufferARB
2210 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2212 Wine_GLPBuffer
* object
= NULL
;
2213 WineGLPixelFormat
*fmt
= NULL
;
2218 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2220 if (0 >= iPixelFormat
) {
2221 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2222 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2223 return NULL
; /* unexpected error */
2226 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2227 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2229 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2230 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2231 goto create_failed
; /* unexpected error */
2234 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2235 if (NULL
== object
) {
2236 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2237 goto create_failed
; /* unexpected error */
2240 object
->display
= gdi_display
;
2241 object
->width
= iWidth
;
2242 object
->height
= iHeight
;
2245 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2246 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2247 while (piAttribList
&& 0 != *piAttribList
) {
2249 switch (*piAttribList
) {
2250 case WGL_PBUFFER_LARGEST_ARB
: {
2252 attr_v
= *piAttribList
;
2253 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2254 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2258 case WGL_TEXTURE_FORMAT_ARB
: {
2260 attr_v
= *piAttribList
;
2261 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2262 if (use_render_texture_ati
) {
2265 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2266 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2267 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2269 SetLastError(ERROR_INVALID_DATA
);
2272 object
->use_render_texture
= 1;
2273 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2275 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2276 object
->use_render_texture
= 0;
2278 if (!use_render_texture_emulation
) {
2279 SetLastError(ERROR_INVALID_DATA
);
2283 case WGL_TEXTURE_RGB_ARB
:
2284 object
->use_render_texture
= GL_RGB
;
2285 object
->texture_bpp
= 3;
2286 object
->texture_format
= GL_RGB
;
2287 object
->texture_type
= GL_UNSIGNED_BYTE
;
2289 case WGL_TEXTURE_RGBA_ARB
:
2290 object
->use_render_texture
= GL_RGBA
;
2291 object
->texture_bpp
= 4;
2292 object
->texture_format
= GL_RGBA
;
2293 object
->texture_type
= GL_UNSIGNED_BYTE
;
2296 /* WGL_FLOAT_COMPONENTS_NV */
2297 case WGL_TEXTURE_FLOAT_R_NV
:
2298 object
->use_render_texture
= GL_FLOAT_R_NV
;
2299 object
->texture_bpp
= 4;
2300 object
->texture_format
= GL_RED
;
2301 object
->texture_type
= GL_FLOAT
;
2303 case WGL_TEXTURE_FLOAT_RG_NV
:
2304 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2305 object
->texture_bpp
= 8;
2306 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2307 object
->texture_type
= GL_FLOAT
;
2309 case WGL_TEXTURE_FLOAT_RGB_NV
:
2310 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2311 object
->texture_bpp
= 12;
2312 object
->texture_format
= GL_RGB
;
2313 object
->texture_type
= GL_FLOAT
;
2315 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2316 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2317 object
->texture_bpp
= 16;
2318 object
->texture_format
= GL_RGBA
;
2319 object
->texture_type
= GL_FLOAT
;
2322 ERR("Unknown texture format: %x\n", attr_v
);
2323 SetLastError(ERROR_INVALID_DATA
);
2331 case WGL_TEXTURE_TARGET_ARB
: {
2333 attr_v
= *piAttribList
;
2334 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2335 if (use_render_texture_ati
) {
2338 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2339 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2340 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2341 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2343 SetLastError(ERROR_INVALID_DATA
);
2346 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2348 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2349 object
->texture_target
= 0;
2351 if (!use_render_texture_emulation
) {
2352 SetLastError(ERROR_INVALID_DATA
);
2356 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2357 if (iWidth
!= iHeight
) {
2358 SetLastError(ERROR_INVALID_DATA
);
2361 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2362 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2365 case WGL_TEXTURE_1D_ARB
: {
2367 SetLastError(ERROR_INVALID_DATA
);
2370 object
->texture_target
= GL_TEXTURE_1D
;
2371 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2374 case WGL_TEXTURE_2D_ARB
: {
2375 object
->texture_target
= GL_TEXTURE_2D
;
2376 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2379 case WGL_TEXTURE_RECTANGLE_NV
: {
2380 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2381 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2385 ERR("Unknown texture target: %x\n", attr_v
);
2386 SetLastError(ERROR_INVALID_DATA
);
2394 case WGL_MIPMAP_TEXTURE_ARB
: {
2396 attr_v
= *piAttribList
;
2397 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2398 if (use_render_texture_ati
) {
2399 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2401 if (!use_render_texture_emulation
) {
2402 SetLastError(ERROR_INVALID_DATA
);
2412 PUSH1(attribs
, None
);
2414 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2415 wine_tsx11_unlock();
2416 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2417 if (!object
->drawable
) {
2418 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2419 goto create_failed
; /* unexpected error */
2421 TRACE("->(%p)\n", object
);
2425 HeapFree(GetProcessHeap(), 0, object
);
2426 TRACE("->(FAILED)\n");
2431 * X11DRV_wglDestroyPbufferARB
2433 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2435 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2437 Wine_GLPBuffer
* object
= hPbuffer
;
2438 TRACE("(%p)\n", hPbuffer
);
2439 if (NULL
== object
) {
2440 SetLastError(ERROR_INVALID_HANDLE
);
2444 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2445 wine_tsx11_unlock();
2446 HeapFree(GetProcessHeap(), 0, object
);
2451 * X11DRV_wglGetPbufferDCARB
2453 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2454 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2455 * Gdi32 implements the part of this function which creates a device context.
2456 * This part associates the physDev with the X drawable of the pbuffer.
2458 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2460 Wine_GLPBuffer
* object
= hPbuffer
;
2461 if (NULL
== object
) {
2462 SetLastError(ERROR_INVALID_HANDLE
);
2466 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2467 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2468 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2469 physDev
->drawable
= object
->drawable
;
2470 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2471 physDev
->dc_rect
= physDev
->drawable_rect
;
2473 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2474 return physDev
->hdc
;
2478 * X11DRV_wglQueryPbufferARB
2480 * WGL_ARB_pbuffer: wglQueryPbufferARB
2482 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2484 Wine_GLPBuffer
* object
= hPbuffer
;
2485 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2486 if (NULL
== object
) {
2487 SetLastError(ERROR_INVALID_HANDLE
);
2490 switch (iAttribute
) {
2491 case WGL_PBUFFER_WIDTH_ARB
:
2493 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2494 wine_tsx11_unlock();
2496 case WGL_PBUFFER_HEIGHT_ARB
:
2498 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2499 wine_tsx11_unlock();
2502 case WGL_PBUFFER_LOST_ARB
:
2503 /* GLX Pbuffers cannot be lost by default. We can support this by
2504 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2505 * to receive pixel buffer clobber events, however that may or may
2506 * not give any benefit */
2507 *piValue
= GL_FALSE
;
2510 case WGL_TEXTURE_FORMAT_ARB
:
2511 if (use_render_texture_ati
) {
2513 int type
= WGL_NO_TEXTURE_ARB
;
2515 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2516 wine_tsx11_unlock();
2518 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2519 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2520 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2524 if (!object
->use_render_texture
) {
2525 *piValue
= WGL_NO_TEXTURE_ARB
;
2527 if (!use_render_texture_emulation
) {
2528 SetLastError(ERROR_INVALID_HANDLE
);
2531 switch(object
->use_render_texture
) {
2533 *piValue
= WGL_TEXTURE_RGB_ARB
;
2536 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2538 /* WGL_FLOAT_COMPONENTS_NV */
2540 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2542 case GL_FLOAT_RG_NV
:
2543 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2545 case GL_FLOAT_RGB_NV
:
2546 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2548 case GL_FLOAT_RGBA_NV
:
2549 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2552 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2558 case WGL_TEXTURE_TARGET_ARB
:
2559 if (use_render_texture_ati
) {
2561 int type
= WGL_NO_TEXTURE_ARB
;
2563 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2564 wine_tsx11_unlock();
2566 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2567 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2568 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2569 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2573 if (!object
->texture_target
) {
2574 *piValue
= WGL_NO_TEXTURE_ARB
;
2576 if (!use_render_texture_emulation
) {
2577 SetLastError(ERROR_INVALID_DATA
);
2580 switch (object
->texture_target
) {
2581 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2582 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2583 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2584 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2590 case WGL_MIPMAP_TEXTURE_ARB
:
2591 if (use_render_texture_ati
) {
2593 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2594 wine_tsx11_unlock();
2596 *piValue
= GL_FALSE
; /** don't support that */
2597 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2602 FIXME("unexpected attribute %x\n", iAttribute
);
2610 * X11DRV_wglReleasePbufferDCARB
2612 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2614 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2616 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2617 return DeleteDC(hdc
);
2621 * X11DRV_wglSetPbufferAttribARB
2623 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2625 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2627 Wine_GLPBuffer
* object
= hPbuffer
;
2628 GLboolean ret
= GL_FALSE
;
2630 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2631 if (NULL
== object
) {
2632 SetLastError(ERROR_INVALID_HANDLE
);
2635 if (!object
->use_render_texture
) {
2636 SetLastError(ERROR_INVALID_HANDLE
);
2639 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2642 if (NULL
!= pglXDrawableAttribATI
) {
2643 if (use_render_texture_ati
) {
2644 FIXME("Need conversion for GLX_ATI_render_texture\n");
2647 ret
= pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2648 wine_tsx11_unlock();
2654 * X11DRV_wglChoosePixelFormatARB
2656 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2658 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2663 GLXFBConfig
* cfgs
= NULL
;
2667 WineGLPixelFormat
*fmt
;
2673 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2674 if (NULL
!= pfAttribFList
) {
2675 FIXME("unused pfAttribFList\n");
2678 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2679 if (-1 == nAttribs
) {
2680 WARN("Cannot convert WGL to GLX attributes\n");
2683 PUSH1(attribs
, None
);
2685 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2686 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2687 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2688 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2690 switch(piAttribIList
[i
])
2692 case WGL_DRAW_TO_BITMAP_ARB
:
2693 if(piAttribIList
[i
+1])
2694 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2696 case WGL_ACCELERATION_ARB
:
2697 switch(piAttribIList
[i
+1])
2699 case WGL_NO_ACCELERATION_ARB
:
2700 dwFlags
|= PFD_GENERIC_FORMAT
;
2702 case WGL_GENERIC_ACCELERATION_ARB
:
2703 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2705 case WGL_FULL_ACCELERATION_ARB
:
2710 case WGL_SUPPORT_GDI_ARB
:
2711 if(piAttribIList
[i
+1])
2712 dwFlags
|= PFD_SUPPORT_GDI
;
2717 /* Search for FB configurations matching the requirements in attribs */
2719 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2721 wine_tsx11_unlock();
2722 WARN("Compatible Pixel Format not found\n");
2726 /* Loop through all matching formats and check if they are suitable.
2727 * Note that this function should at max return nMaxFormats different formats */
2728 for(run
=0; run
< 2; run
++)
2730 for (it
= 0; it
< nCfgs
; ++it
) {
2731 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2733 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2737 /* Search for the format in our list of compatible formats */
2738 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
, dwFlags
);
2742 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2743 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2746 if(pfmt_it
< nMaxFormats
) {
2747 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2748 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2754 *nNumFormats
= pfmt_it
;
2757 wine_tsx11_unlock();
2762 * X11DRV_wglGetPixelFormatAttribivARB
2764 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2766 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2769 WineGLPixelFormat
*fmt
= NULL
;
2773 int nWGLFormats
= 0;
2775 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2777 if (0 < iLayerPlane
) {
2778 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2782 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2783 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2784 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2785 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2787 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2791 for (i
= 0; i
< nAttributes
; ++i
) {
2792 const int curWGLAttr
= piAttributes
[i
];
2793 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2795 switch (curWGLAttr
) {
2796 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2797 piValues
[i
] = nWGLFormats
;
2800 case WGL_SUPPORT_OPENGL_ARB
:
2801 piValues
[i
] = GL_TRUE
;
2804 case WGL_ACCELERATION_ARB
:
2805 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2806 if (!fmt
) goto pix_error
;
2807 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2808 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2809 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2810 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2812 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2815 case WGL_TRANSPARENT_ARB
:
2816 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2817 if (!fmt
) goto pix_error
;
2818 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2819 if (hTest
) goto get_error
;
2820 piValues
[i
] = GL_FALSE
;
2821 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2824 case WGL_PIXEL_TYPE_ARB
:
2825 curGLXAttr
= GLX_RENDER_TYPE
;
2826 if (!fmt
) goto pix_error
;
2827 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2828 if (hTest
) goto get_error
;
2829 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2830 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2831 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2832 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2833 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2834 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2836 ERR("unexpected RenderType(%x)\n", tmp
);
2837 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2841 case WGL_COLOR_BITS_ARB
:
2842 curGLXAttr
= GLX_BUFFER_SIZE
;
2845 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2846 if (use_render_texture_ati
) {
2847 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2850 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2851 if (use_render_texture_ati
) {
2852 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2855 if (!use_render_texture_emulation
) {
2856 piValues
[i
] = GL_FALSE
;
2859 curGLXAttr
= GLX_RENDER_TYPE
;
2860 if (!fmt
) goto pix_error
;
2861 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2862 if (hTest
) goto get_error
;
2863 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2864 piValues
[i
] = GL_FALSE
;
2867 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2868 if (hTest
) goto get_error
;
2869 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2872 case WGL_BLUE_BITS_ARB
:
2873 curGLXAttr
= GLX_BLUE_SIZE
;
2875 case WGL_RED_BITS_ARB
:
2876 curGLXAttr
= GLX_RED_SIZE
;
2878 case WGL_GREEN_BITS_ARB
:
2879 curGLXAttr
= GLX_GREEN_SIZE
;
2881 case WGL_ALPHA_BITS_ARB
:
2882 curGLXAttr
= GLX_ALPHA_SIZE
;
2884 case WGL_DEPTH_BITS_ARB
:
2885 curGLXAttr
= GLX_DEPTH_SIZE
;
2887 case WGL_STENCIL_BITS_ARB
:
2888 curGLXAttr
= GLX_STENCIL_SIZE
;
2890 case WGL_DOUBLE_BUFFER_ARB
:
2891 curGLXAttr
= GLX_DOUBLEBUFFER
;
2893 case WGL_STEREO_ARB
:
2894 curGLXAttr
= GLX_STEREO
;
2896 case WGL_AUX_BUFFERS_ARB
:
2897 curGLXAttr
= GLX_AUX_BUFFERS
;
2900 case WGL_SUPPORT_GDI_ARB
:
2901 if (!fmt
) goto pix_error
;
2902 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) ? TRUE
: FALSE
;
2905 case WGL_DRAW_TO_BITMAP_ARB
:
2906 if (!fmt
) goto pix_error
;
2907 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) ? TRUE
: FALSE
;
2910 case WGL_DRAW_TO_WINDOW_ARB
:
2911 case WGL_DRAW_TO_PBUFFER_ARB
:
2912 if (!fmt
) goto pix_error
;
2913 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2914 if (hTest
) goto get_error
;
2915 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2916 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2917 piValues
[i
] = GL_TRUE
;
2919 piValues
[i
] = GL_FALSE
;
2922 case WGL_SWAP_METHOD_ARB
:
2923 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2924 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2925 * point only ATI offers this.
2927 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2930 case WGL_PBUFFER_LARGEST_ARB
:
2931 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2934 case WGL_SAMPLE_BUFFERS_ARB
:
2935 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2938 case WGL_SAMPLES_ARB
:
2939 curGLXAttr
= GLX_SAMPLES_ARB
;
2942 case WGL_FLOAT_COMPONENTS_NV
:
2943 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2946 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
2947 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
2950 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
2951 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
2954 case WGL_ACCUM_RED_BITS_ARB
:
2955 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2957 case WGL_ACCUM_GREEN_BITS_ARB
:
2958 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2960 case WGL_ACCUM_BLUE_BITS_ARB
:
2961 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2963 case WGL_ACCUM_ALPHA_BITS_ARB
:
2964 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2966 case WGL_ACCUM_BITS_ARB
:
2967 if (!fmt
) goto pix_error
;
2968 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2969 if (hTest
) goto get_error
;
2971 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2972 if (hTest
) goto get_error
;
2974 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2975 if (hTest
) goto get_error
;
2977 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2978 if (hTest
) goto get_error
;
2983 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2986 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2987 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2988 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2990 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2991 * and check which options can work using iPixelFormat=0 and which not.
2992 * A problem would be that this function is an extension. This would
2993 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2995 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2996 if (!fmt
) goto pix_error
;
2997 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2998 if (hTest
) goto get_error
;
3001 piValues
[i
] = GL_FALSE
;
3004 wine_tsx11_unlock();
3008 wine_tsx11_unlock();
3009 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
3013 wine_tsx11_unlock();
3014 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
3019 * X11DRV_wglGetPixelFormatAttribfvARB
3021 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3023 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
3029 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
3031 /* Allocate a temporary array to store integer values */
3032 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
3034 ERR("couldn't allocate %d array\n", nAttributes
);
3038 /* Piggy-back on wglGetPixelFormatAttribivARB */
3039 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
3041 /* Convert integer values to float. Should also check for attributes
3042 that can give decimal values here */
3043 for (i
=0; i
<nAttributes
;i
++) {
3044 pfValues
[i
] = attr
[i
];
3048 HeapFree(GetProcessHeap(), 0, attr
);
3053 * X11DRV_wglBindTexImageARB
3055 * WGL_ARB_render_texture: wglBindTexImageARB
3057 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3059 Wine_GLPBuffer
* object
= hPbuffer
;
3060 GLboolean ret
= GL_FALSE
;
3062 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3063 if (NULL
== object
) {
3064 SetLastError(ERROR_INVALID_HANDLE
);
3067 if (!object
->use_render_texture
) {
3068 SetLastError(ERROR_INVALID_HANDLE
);
3072 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3073 static int init
= 0;
3074 int prev_binded_texture
= 0;
3075 GLXContext prev_context
;
3076 Drawable prev_drawable
;
3077 GLXContext tmp_context
;
3080 prev_context
= pglXGetCurrentContext();
3081 prev_drawable
= pglXGetCurrentDrawable();
3083 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3084 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3085 isn't ideal performance wise but I wasn't able to get other ways working.
3088 init
= 1; /* Only show the FIXME once for performance reasons */
3089 FIXME("partial stub!\n");
3092 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
3093 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
3095 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
3097 /* Switch to our pbuffer */
3098 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
3100 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3101 * After that upload the pbuffer texture data. */
3102 pglBindTexture(object
->texture_target
, prev_binded_texture
);
3103 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
3105 /* Switch back to the original drawable and upload the pbuffer-texture */
3106 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
3107 pglXDestroyContext(gdi_display
, tmp_context
);
3108 wine_tsx11_unlock();
3112 if (NULL
!= pglXBindTexImageATI
) {
3117 case WGL_FRONT_LEFT_ARB
:
3118 buffer
= GLX_FRONT_LEFT_ATI
;
3120 case WGL_FRONT_RIGHT_ARB
:
3121 buffer
= GLX_FRONT_RIGHT_ATI
;
3123 case WGL_BACK_LEFT_ARB
:
3124 buffer
= GLX_BACK_LEFT_ATI
;
3126 case WGL_BACK_RIGHT_ARB
:
3127 buffer
= GLX_BACK_RIGHT_ATI
;
3130 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3134 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3135 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3136 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3137 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3138 * works fine using our pbuffer emulation path.
3141 ret
= pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
3142 wine_tsx11_unlock();
3148 * X11DRV_wglReleaseTexImageARB
3150 * WGL_ARB_render_texture: wglReleaseTexImageARB
3152 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
3154 Wine_GLPBuffer
* object
= hPbuffer
;
3155 GLboolean ret
= GL_FALSE
;
3157 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
3158 if (NULL
== object
) {
3159 SetLastError(ERROR_INVALID_HANDLE
);
3162 if (!object
->use_render_texture
) {
3163 SetLastError(ERROR_INVALID_HANDLE
);
3166 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
3169 if (NULL
!= pglXReleaseTexImageATI
) {
3174 case WGL_FRONT_LEFT_ARB
:
3175 buffer
= GLX_FRONT_LEFT_ATI
;
3177 case WGL_FRONT_RIGHT_ARB
:
3178 buffer
= GLX_FRONT_RIGHT_ATI
;
3180 case WGL_BACK_LEFT_ARB
:
3181 buffer
= GLX_BACK_LEFT_ATI
;
3183 case WGL_BACK_RIGHT_ARB
:
3184 buffer
= GLX_BACK_RIGHT_ATI
;
3187 ERR("Unknown iBuffer=%#x\n", iBuffer
);
3191 ret
= pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
3192 wine_tsx11_unlock();
3198 * X11DRV_wglGetExtensionsStringEXT
3200 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3202 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3203 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3204 return WineGLInfo
.wglExtensions
;
3208 * X11DRV_wglGetSwapIntervalEXT
3210 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3212 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3213 FIXME("(),stub!\n");
3214 return swap_interval
;
3218 * X11DRV_wglSwapIntervalEXT
3220 * WGL_EXT_swap_control: wglSwapIntervalEXT
3222 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3225 TRACE("(%d)\n", interval
);
3226 swap_interval
= interval
;
3227 if (NULL
!= pglXSwapIntervalSGI
) {
3229 ret
= !pglXSwapIntervalSGI(interval
);
3230 wine_tsx11_unlock();
3232 else WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3237 * X11DRV_wglAllocateMemoryNV
3239 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3241 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3243 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3245 if (pglXAllocateMemoryNV
)
3248 ret
= pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3249 wine_tsx11_unlock();
3255 * X11DRV_wglFreeMemoryNV
3257 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3259 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3260 TRACE("(%p)\n", pointer
);
3261 if (pglXFreeMemoryNV
== NULL
)
3265 pglXFreeMemoryNV(pointer
);
3266 wine_tsx11_unlock();
3270 * X11DRV_wglSetPixelFormatWINE
3272 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3273 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3275 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3277 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
3279 if (!has_opengl()) return FALSE
;
3281 if (physDev
->current_pf
== iPixelFormat
) return TRUE
;
3283 /* Relay to the core SetPixelFormat */
3284 TRACE("Changing iPixelFormat from %d to %d\n", physDev
->current_pf
, iPixelFormat
);
3285 return internal_SetPixelFormat(physDev
, iPixelFormat
, ppfd
);
3289 * glxRequireVersion (internal)
3291 * Check if the supported GLX version matches requiredVersion.
3293 static BOOL
glxRequireVersion(int requiredVersion
)
3295 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3296 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3302 static BOOL
glxRequireExtension(const char *requiredExtension
)
3304 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3311 static void register_extension_string(const char *ext
)
3313 if (WineGLInfo
.wglExtensions
[0])
3314 strcat(WineGLInfo
.wglExtensions
, " ");
3315 strcat(WineGLInfo
.wglExtensions
, ext
);
3317 TRACE("'%s'\n", ext
);
3320 static BOOL
register_extension(const WineGLExtension
* ext
)
3324 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3325 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3327 register_extension_string(ext
->extName
);
3329 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3330 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3335 static const WineGLExtension WGL_internal_functions
=
3339 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3340 { "wglFinish", X11DRV_wglFinish
},
3341 { "wglFlush", X11DRV_wglFlush
},
3346 static const WineGLExtension WGL_ARB_extensions_string
=
3348 "WGL_ARB_extensions_string",
3350 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3354 static const WineGLExtension WGL_ARB_make_current_read
=
3356 "WGL_ARB_make_current_read",
3358 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3359 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3363 static const WineGLExtension WGL_ARB_multisample
=
3365 "WGL_ARB_multisample",
3368 static const WineGLExtension WGL_ARB_pbuffer
=
3372 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3373 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3374 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3375 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3376 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3377 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3381 static const WineGLExtension WGL_ARB_pixel_format
=
3383 "WGL_ARB_pixel_format",
3385 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3386 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3387 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3391 static const WineGLExtension WGL_ARB_render_texture
=
3393 "WGL_ARB_render_texture",
3395 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3396 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3400 static const WineGLExtension WGL_EXT_extensions_string
=
3402 "WGL_EXT_extensions_string",
3404 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3408 static const WineGLExtension WGL_EXT_swap_control
=
3410 "WGL_EXT_swap_control",
3412 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3413 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3417 static const WineGLExtension WGL_NV_vertex_array_range
=
3419 "WGL_NV_vertex_array_range",
3421 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3422 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3426 static const WineGLExtension WGL_WINE_pixel_format_passthrough
=
3428 "WGL_WINE_pixel_format_passthrough",
3430 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE
},
3435 * X11DRV_WineGL_LoadExtensions
3437 static void X11DRV_WineGL_LoadExtensions(void)
3439 WineGLInfo
.wglExtensions
[0] = 0;
3441 /* Load Wine internal functions */
3442 register_extension(&WGL_internal_functions
);
3444 /* ARB Extensions */
3446 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3448 register_extension_string("WGL_ARB_pixel_format_float");
3449 register_extension_string("WGL_ATI_pixel_format_float");
3452 register_extension(&WGL_ARB_extensions_string
);
3454 if (glxRequireVersion(3))
3455 register_extension(&WGL_ARB_make_current_read
);
3457 if (glxRequireExtension("GLX_ARB_multisample"))
3458 register_extension(&WGL_ARB_multisample
);
3460 /* In general pbuffer functionality requires support in the X-server. The functionality is
3461 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3462 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3463 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3465 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3466 * without support in the X-server (which other Mesa based drivers require).
3468 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3469 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3470 * is available pbuffers must be available too. */
3471 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3472 register_extension(&WGL_ARB_pbuffer
);
3474 register_extension(&WGL_ARB_pixel_format
);
3476 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3477 if (glxRequireExtension("GLX_ATI_render_texture") ||
3478 glxRequireExtension("GLX_ARB_render_texture") ||
3479 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3481 register_extension(&WGL_ARB_render_texture
);
3483 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3484 if(glxRequireExtension("GLX_NV_float_buffer"))
3485 register_extension_string("WGL_NV_float_buffer");
3487 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3488 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3489 register_extension_string("WGL_NV_texture_rectangle");
3492 /* EXT Extensions */
3494 register_extension(&WGL_EXT_extensions_string
);
3496 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3497 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3498 register_extension(&WGL_EXT_swap_control
);
3500 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3501 register_extension_string("WGL_EXT_framebuffer_sRGB");
3503 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3504 register_extension_string("WGL_EXT_pixel_format_packed_float");
3506 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3507 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3508 register_extension(&WGL_NV_vertex_array_range
);
3510 /* WINE-specific WGL Extensions */
3512 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3513 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3515 register_extension(&WGL_WINE_pixel_format_passthrough
);
3519 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3525 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3526 ret
= physDev
->drawable
; /* PBuffer */
3528 ret
= physDev
->bitmap
->glxpixmap
;
3530 else if(physDev
->gl_drawable
)
3531 ret
= physDev
->gl_drawable
;
3533 ret
= physDev
->drawable
;
3537 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3540 pglXDestroyGLXPixmap(display
, glxpixmap
);
3541 wine_tsx11_unlock();
3546 * X11DRV_SwapBuffers
3548 * Swap the buffers of this DC
3550 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3552 GLXDrawable drawable
;
3553 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3555 if (!has_opengl()) return FALSE
;
3557 TRACE("(%p)\n", physDev
);
3559 drawable
= get_glxdrawable(physDev
);
3563 if(physDev
->pixmap
) {
3564 if(pglXCopySubBufferMESA
) {
3565 int w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
3566 int h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
3568 /* (glX)SwapBuffers has an implicit glFlush effect, however
3569 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3573 pglXCopySubBufferMESA(gdi_display
, drawable
, 0, 0, w
, h
);
3576 pglXSwapBuffers(gdi_display
, drawable
);
3579 pglXSwapBuffers(gdi_display
, drawable
);
3581 flush_gl_drawable(physDev
);
3582 wine_tsx11_unlock();
3587 static long prev_time
, start_time
;
3588 static unsigned long frames
, frames_total
;
3590 DWORD time
= GetTickCount();
3593 /* every 1.5 seconds */
3594 if (time
- prev_time
> 1500) {
3595 TRACE_(fps
)("@ approx %.2ffps, total %.2ffps\n",
3596 1000.0*frames
/(time
- prev_time
), 1000.0*frames_total
/(time
- start_time
));
3599 if(start_time
== 0) start_time
= time
;
3606 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3608 WineGLPixelFormat
*fmt
;
3611 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
, 0 /* no flags */);
3616 ret
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3617 wine_tsx11_unlock();
3621 #else /* no OpenGL includes */
3623 void X11DRV_OpenGL_Cleanup(void)
3627 static inline void opengl_error(void)
3630 if (!warned
++) ERR("No OpenGL support compiled in.\n");
3633 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3638 void mark_drawable_dirty(Drawable old
, Drawable
new)
3642 void flush_gl_drawable(X11DRV_PDEVICE
*physDev
)
3646 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3651 /***********************************************************************
3652 * ChoosePixelFormat (X11DRV.@)
3654 int CDECL
X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3655 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3660 /***********************************************************************
3661 * DescribePixelFormat (X11DRV.@)
3663 int CDECL
X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3666 PIXELFORMATDESCRIPTOR
*ppfd
) {
3671 /***********************************************************************
3672 * GetPixelFormat (X11DRV.@)
3674 int CDECL
X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3679 /***********************************************************************
3680 * SetPixelFormat (X11DRV.@)
3682 BOOL CDECL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3684 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3689 /***********************************************************************
3690 * SwapBuffers (X11DRV.@)
3692 BOOL CDECL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3698 * X11DRV_wglCopyContext
3700 * For OpenGL32 wglCopyContext.
3702 BOOL CDECL
X11DRV_wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
) {
3708 * X11DRV_wglCreateContext
3710 * For OpenGL32 wglCreateContext.
3712 HGLRC CDECL
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3718 * X11DRV_wglDeleteContext
3720 * For OpenGL32 wglDeleteContext.
3722 BOOL CDECL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3728 * X11DRV_wglGetProcAddress
3730 * For OpenGL32 wglGetProcAddress.
3732 PROC CDECL
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3737 HDC CDECL
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3743 BOOL CDECL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3749 * X11DRV_wglMakeCurrent
3751 * For OpenGL32 wglMakeCurrent.
3753 BOOL CDECL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3759 * X11DRV_wglShareLists
3761 * For OpenGL32 wglShareLists.
3763 BOOL CDECL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3769 * X11DRV_wglUseFontBitmapsA
3771 * For OpenGL32 wglUseFontBitmapsA.
3773 BOOL CDECL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3780 * X11DRV_wglUseFontBitmapsW
3782 * For OpenGL32 wglUseFontBitmapsW.
3784 BOOL CDECL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3791 * X11DRV_wglSetPixelFormatWINE
3793 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3794 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3796 BOOL CDECL
X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE
*physDev
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
3802 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3807 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3812 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3817 #endif /* defined(HAVE_OPENGL) */