2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006 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
);
38 WINE_DECLARE_DEBUG_CHANNEL(opengl
);
52 #ifdef HAVE_GL_GLEXT_H
53 # include <GL/glext.h>
62 /* Redefines the constants */
63 #define CALLBACK __stdcall
64 #define WINAPI __stdcall
65 #define APIENTRY WINAPI
68 WINE_DECLARE_DEBUG_CHANNEL(fps
);
70 typedef struct wine_glextension
{
79 const char *glVersion
;
80 const char *glExtensions
;
84 const char *glxServerVersion
;
85 const char *glxServerVendor
;
86 const char *glxServerExtensions
;
88 const char *glxClientVersion
;
89 const char *glxClientVendor
;
90 const char *glxClientExtensions
;
92 const char *glxExtensions
;
95 char wglExtensions
[4096];
98 typedef struct wine_glpixelformat
{
100 GLXFBConfig fbconfig
;
106 typedef struct wine_glcontext
{
109 WineGLPixelFormat
*fmt
;
112 X11DRV_PDEVICE
*physDev
;
113 X11DRV_PDEVICE
*pReadDev
;
116 BOOL scissor_enabled
;
117 struct wine_glcontext
*next
;
118 struct wine_glcontext
*prev
;
121 typedef struct wine_glpbuffer
{
124 WineGLPixelFormat
* fmt
;
130 int use_render_texture
; /* This is also the internal texture format */
131 int texture_bind_target
;
133 GLint texture_format
;
134 GLuint texture_target
;
140 static Wine_GLContext
*context_list
;
141 static struct WineGLInfo WineGLInfo
= { 0 };
142 static int use_render_texture_emulation
= 1;
143 static int use_render_texture_ati
= 0;
144 static int swap_interval
= 1;
146 #define MAX_EXTENSIONS 16
147 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
148 static int WineGLExtensionListSize
;
150 static WineGLPixelFormat
*WineGLPixelFormatList
;
151 static int WineGLPixelFormatListSize
= 0;
152 static int WineGLPixelFormatOnScreenSize
= 0;
154 static void X11DRV_WineGL_LoadExtensions(void);
155 static BOOL
glxRequireVersion(int requiredVersion
);
156 static BOOL
glxRequireExtension(const char *requiredExtension
);
158 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
159 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
160 TRACE(" - dwFlags : ");
161 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
162 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
163 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
164 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
165 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
166 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
173 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
174 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
175 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
176 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
177 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
178 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
179 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
180 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
184 TRACE(" - iPixelType : ");
185 switch (ppfd
->iPixelType
) {
186 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
187 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
191 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
192 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
193 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
194 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
195 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
196 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
197 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
198 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
199 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
201 TRACE(" - iLayerType : ");
202 switch (ppfd
->iLayerType
) {
203 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
204 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
205 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
210 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
211 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
213 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
215 MAKE_FUNCPTR(glXChooseVisual
)
216 MAKE_FUNCPTR(glXCreateContext
)
217 MAKE_FUNCPTR(glXCreateGLXPixmap
)
218 MAKE_FUNCPTR(glXGetCurrentContext
)
219 MAKE_FUNCPTR(glXGetCurrentDrawable
)
220 MAKE_FUNCPTR(glXDestroyContext
)
221 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
222 MAKE_FUNCPTR(glXGetConfig
)
223 MAKE_FUNCPTR(glXIsDirect
)
224 MAKE_FUNCPTR(glXMakeCurrent
)
225 MAKE_FUNCPTR(glXSwapBuffers
)
226 MAKE_FUNCPTR(glXQueryExtension
)
227 MAKE_FUNCPTR(glXQueryVersion
)
228 MAKE_FUNCPTR(glXUseXFont
)
231 MAKE_FUNCPTR(glXGetClientString
)
232 MAKE_FUNCPTR(glXQueryExtensionsString
)
233 MAKE_FUNCPTR(glXQueryServerString
)
236 MAKE_FUNCPTR(glXGetFBConfigs
)
237 MAKE_FUNCPTR(glXChooseFBConfig
)
238 MAKE_FUNCPTR(glXCreatePbuffer
)
239 MAKE_FUNCPTR(glXCreateNewContext
)
240 MAKE_FUNCPTR(glXDestroyPbuffer
)
241 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
242 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
243 MAKE_FUNCPTR(glXMakeContextCurrent
)
244 MAKE_FUNCPTR(glXQueryDrawable
)
245 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
248 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
249 static int (*pglXSwapIntervalSGI
)(int);
251 /* ATI GLX Extensions */
252 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
253 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
254 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
256 /* NV GLX Extension */
257 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
258 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
260 /* Standard OpenGL */
261 MAKE_FUNCPTR(glBindTexture
)
262 MAKE_FUNCPTR(glBitmap
)
263 MAKE_FUNCPTR(glCopyTexSubImage1D
)
264 MAKE_FUNCPTR(glCopyTexImage2D
)
265 MAKE_FUNCPTR(glCopyTexSubImage2D
)
266 MAKE_FUNCPTR(glDisable
)
267 MAKE_FUNCPTR(glDrawBuffer
)
268 MAKE_FUNCPTR(glEnable
)
269 MAKE_FUNCPTR(glEndList
)
270 MAKE_FUNCPTR(glGetError
)
271 MAKE_FUNCPTR(glGetIntegerv
)
272 MAKE_FUNCPTR(glGetString
)
273 MAKE_FUNCPTR(glIsEnabled
)
274 MAKE_FUNCPTR(glNewList
)
275 MAKE_FUNCPTR(glPixelStorei
)
276 MAKE_FUNCPTR(glReadPixels
)
277 MAKE_FUNCPTR(glScissor
)
278 MAKE_FUNCPTR(glTexImage2D
)
279 MAKE_FUNCPTR(glViewport
)
280 MAKE_FUNCPTR(glFinish
)
281 MAKE_FUNCPTR(glFlush
)
284 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
286 static BOOL infoInitialized
= FALSE
;
288 int screen
= DefaultScreen(gdi_display
);
289 Window win
= RootWindow(gdi_display
, screen
);
291 XVisualInfo
template;
294 GLXContext ctx
= NULL
;
298 infoInitialized
= TRUE
;
302 visual
= DefaultVisual(gdi_display
, screen
);
303 template.visualid
= XVisualIDFromVisual(visual
);
304 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
306 WORD old_fs
= wine_get_fs();
307 /* Create a GLX Context. Without one we can't query GL information */
308 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
309 if (wine_get_fs() != old_fs
)
311 wine_set_fs( old_fs
);
313 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
314 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
320 pglXMakeCurrent(gdi_display
, win
, ctx
);
322 ERR(" couldn't initialize OpenGL, expect problems\n");
327 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
328 WineGLInfo
.glExtensions
= strdup((const char *) pglGetString(GL_EXTENSIONS
));
330 /* Get the common GLX version supported by GLX client and server ( major/minor) */
331 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
333 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
334 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
335 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
337 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
338 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
339 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
341 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
342 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
344 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
345 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
346 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
347 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
348 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
349 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
350 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
351 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
355 pglXMakeCurrent(gdi_display
, None
, NULL
);
356 pglXDestroyContext(gdi_display
, ctx
);
362 static BOOL
has_opengl(void)
364 static int init_done
;
365 static void *opengl_handle
;
367 int error_base
, event_base
;
369 if (init_done
) return (opengl_handle
!= NULL
);
372 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
373 and include all dependencies */
374 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0);
375 if (opengl_handle
== NULL
) return FALSE
;
377 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
378 if (pglXGetProcAddressARB
== NULL
) {
379 ERR("could not find glXGetProcAddressARB in libGL.\n");
383 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
385 LOAD_FUNCPTR(glXChooseVisual
)
386 LOAD_FUNCPTR(glXCreateContext
)
387 LOAD_FUNCPTR(glXCreateGLXPixmap
)
388 LOAD_FUNCPTR(glXGetCurrentContext
)
389 LOAD_FUNCPTR(glXGetCurrentDrawable
)
390 LOAD_FUNCPTR(glXDestroyContext
)
391 LOAD_FUNCPTR(glXDestroyGLXPixmap
)
392 LOAD_FUNCPTR(glXGetConfig
)
393 LOAD_FUNCPTR(glXIsDirect
)
394 LOAD_FUNCPTR(glXMakeCurrent
)
395 LOAD_FUNCPTR(glXSwapBuffers
)
396 LOAD_FUNCPTR(glXQueryExtension
)
397 LOAD_FUNCPTR(glXQueryVersion
)
398 LOAD_FUNCPTR(glXUseXFont
)
401 LOAD_FUNCPTR(glXGetClientString
)
402 LOAD_FUNCPTR(glXQueryExtensionsString
)
403 LOAD_FUNCPTR(glXQueryServerString
)
406 LOAD_FUNCPTR(glXCreatePbuffer
)
407 LOAD_FUNCPTR(glXCreateNewContext
)
408 LOAD_FUNCPTR(glXDestroyPbuffer
)
409 LOAD_FUNCPTR(glXMakeContextCurrent
)
410 LOAD_FUNCPTR(glXGetCurrentReadDrawable
)
411 LOAD_FUNCPTR(glXGetFBConfigs
)
413 /* Standard OpenGL calls */
414 LOAD_FUNCPTR(glBindTexture
)
415 LOAD_FUNCPTR(glBitmap
)
416 LOAD_FUNCPTR(glCopyTexSubImage1D
)
417 LOAD_FUNCPTR(glCopyTexImage2D
)
418 LOAD_FUNCPTR(glCopyTexSubImage2D
)
419 LOAD_FUNCPTR(glDisable
)
420 LOAD_FUNCPTR(glDrawBuffer
)
421 LOAD_FUNCPTR(glEnable
)
422 LOAD_FUNCPTR(glEndList
)
423 LOAD_FUNCPTR(glGetError
)
424 LOAD_FUNCPTR(glGetIntegerv
)
425 LOAD_FUNCPTR(glGetString
)
426 LOAD_FUNCPTR(glIsEnabled
)
427 LOAD_FUNCPTR(glNewList
)
428 LOAD_FUNCPTR(glPixelStorei
)
429 LOAD_FUNCPTR(glReadPixels
)
430 LOAD_FUNCPTR(glScissor
)
431 LOAD_FUNCPTR(glTexImage2D
)
432 LOAD_FUNCPTR(glViewport
)
433 LOAD_FUNCPTR(glFinish
)
434 LOAD_FUNCPTR(glFlush
)
437 /* It doesn't matter if these fail. They'll only be used if the driver reports
438 the associated extension is available (and if a driver reports the extension
439 is available but fails to provide the functions, it's quite broken) */
440 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
441 /* NV GLX Extension */
442 LOAD_FUNCPTR(glXAllocateMemoryNV
)
443 LOAD_FUNCPTR(glXFreeMemoryNV
)
446 if(!X11DRV_WineGL_InitOpenglInfo()) {
447 wine_dlclose(opengl_handle
, NULL
, 0);
448 opengl_handle
= NULL
;
453 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
) == True
) {
454 TRACE("GLX is up and running error_base = %d\n", error_base
);
456 wine_dlclose(opengl_handle
, NULL
, 0);
457 opengl_handle
= NULL
;
460 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
461 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
464 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
465 * depends on the reported GLX client / server version and on the client / server extension list.
466 * Those don't have to be the same.
468 * In general the server GLX information lists the capabilities in case of indirect rendering.
469 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
470 * available and in that case the client GLX informat can be used.
471 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
472 * in the GLX version/extension list. When a program does this it works for certain for both
473 * direct and indirect rendering.
475 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
476 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
477 * extension list which causes this extension not to be listed. (Wine requires this extension).
478 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
479 * pbuffers is around.
481 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
482 * the ATI drivers and from then on use GLX client information for them.
485 if(glxRequireVersion(3)) {
486 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
487 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
488 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
489 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
490 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
491 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
492 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
493 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
495 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
496 * enable this function when the Xserver understand GLX 1.3 or newer
498 pglXQueryDrawable
= NULL
;
499 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
500 TRACE("Overriding ATI GLX capabilities!\n");
501 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
502 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
503 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
504 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
506 /* Use client GLX information in case of the ATI drivers. We override the
507 * capabilities over here and not somewhere else as ATI might better their
508 * life in the future. In case they release proper drivers this block of
509 * code won't be called. */
510 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
512 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
515 if(glxRequireExtension("GLX_ATI_render_texture")) {
516 use_render_texture_ati
= 1;
517 pglXBindTexImageATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
518 pglXReleaseTexImageATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
519 pglXDrawableAttribATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
522 X11DRV_WineGL_LoadExtensions();
525 return (opengl_handle
!= NULL
);
528 wine_dlclose(opengl_handle
, NULL
, 0);
529 opengl_handle
= NULL
;
533 static inline Wine_GLContext
*alloc_context(void)
537 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
539 ret
->next
= context_list
;
540 if (context_list
) context_list
->prev
= ret
;
546 static inline void free_context(Wine_GLContext
*context
)
548 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
549 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
550 else context_list
= context
->next
;
552 if (context
->vis
) XFree(context
->vis
);
553 HeapFree(GetProcessHeap(), 0, context
);
556 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
559 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
560 return (ptr
!= NULL
);
563 static int describeContext(Wine_GLContext
* ctx
) {
566 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
567 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
568 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
569 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
570 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
575 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
578 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
581 if (pglXQueryDrawable
== NULL
) {
582 /** glXQueryDrawable not available so returns not supported */
586 TRACE(" Drawable %p have :\n", (void*) drawable
);
587 pglXQueryDrawable(gdi_display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
588 TRACE(" - WIDTH as %d\n", tmp
);
589 pglXQueryDrawable(gdi_display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
590 TRACE(" - HEIGHT as %d\n", tmp
);
591 pglXQueryDrawable(gdi_display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
592 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
595 fbCfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribList
, &nElements
);
596 if (fbCfgs
== NULL
) {
600 pglXGetFBConfigAttrib(gdi_display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
601 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
608 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
613 int nvfloatattrib
= GLX_DONT_CARE
;
616 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
617 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
618 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
619 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
621 switch (iWGLAttr
[cur
]) {
622 case WGL_COLOR_BITS_ARB
:
623 pop
= iWGLAttr
[++cur
];
624 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
625 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
627 case WGL_BLUE_BITS_ARB
:
628 pop
= iWGLAttr
[++cur
];
629 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
630 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
632 case WGL_RED_BITS_ARB
:
633 pop
= iWGLAttr
[++cur
];
634 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
635 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
637 case WGL_GREEN_BITS_ARB
:
638 pop
= iWGLAttr
[++cur
];
639 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
640 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
642 case WGL_ALPHA_BITS_ARB
:
643 pop
= iWGLAttr
[++cur
];
644 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
645 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
647 case WGL_DEPTH_BITS_ARB
:
648 pop
= iWGLAttr
[++cur
];
649 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
650 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
652 case WGL_STENCIL_BITS_ARB
:
653 pop
= iWGLAttr
[++cur
];
654 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
655 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
657 case WGL_DOUBLE_BUFFER_ARB
:
658 pop
= iWGLAttr
[++cur
];
659 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
660 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
663 case WGL_PIXEL_TYPE_ARB
:
664 pop
= iWGLAttr
[++cur
];
665 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
667 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
668 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
669 /* 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 */
670 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
672 ERR("unexpected PixelType(%x)\n", pop
);
677 case WGL_SUPPORT_GDI_ARB
:
678 pop
= iWGLAttr
[++cur
];
679 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
680 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
683 case WGL_DRAW_TO_BITMAP_ARB
:
684 pop
= iWGLAttr
[++cur
];
685 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
686 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
688 drawattrib
|= GLX_PIXMAP_BIT
;
692 case WGL_DRAW_TO_WINDOW_ARB
:
693 pop
= iWGLAttr
[++cur
];
694 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
695 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
697 drawattrib
|= GLX_WINDOW_BIT
;
701 case WGL_DRAW_TO_PBUFFER_ARB
:
702 pop
= iWGLAttr
[++cur
];
703 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
704 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
706 drawattrib
|= GLX_PBUFFER_BIT
;
710 case WGL_ACCELERATION_ARB
:
711 case WGL_SUPPORT_OPENGL_ARB
:
712 pop
= iWGLAttr
[++cur
];
713 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
714 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
717 case WGL_PBUFFER_LARGEST_ARB
:
718 pop
= iWGLAttr
[++cur
];
719 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
720 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
723 case WGL_SAMPLE_BUFFERS_ARB
:
724 pop
= iWGLAttr
[++cur
];
725 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
726 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
729 case WGL_SAMPLES_ARB
:
730 pop
= iWGLAttr
[++cur
];
731 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
732 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
735 case WGL_TEXTURE_FORMAT_ARB
:
736 case WGL_TEXTURE_TARGET_ARB
:
737 case WGL_MIPMAP_TEXTURE_ARB
:
738 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
739 pop
= iWGLAttr
[++cur
];
741 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
743 if (use_render_texture_ati
) {
744 /** nothing to do here */
746 else if (!use_render_texture_emulation
) {
747 if (WGL_NO_TEXTURE_ARB
!= pop
) {
748 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
749 return -1; /** error: don't support it */
751 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
752 drawattrib
|= GLX_PBUFFER_BIT
;
756 case WGL_FLOAT_COMPONENTS_NV
:
757 nvfloatattrib
= iWGLAttr
[++cur
];
758 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
760 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
761 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
762 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
763 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
764 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
765 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
766 pop
= iWGLAttr
[++cur
];
767 /** cannot be converted, see direct handling on
768 * - wglGetPixelFormatAttribivARB
769 * TODO: wglChoosePixelFormat
774 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
780 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
781 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
782 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
783 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
785 /* Set GLX_RENDER_TYPE all the time */
786 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
787 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
789 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
790 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
791 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
792 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
798 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
800 int render_type
=0, render_type_bit
;
801 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
802 switch(render_type_bit
)
805 render_type
= GLX_RGBA_TYPE
;
807 case GLX_COLOR_INDEX_BIT
:
808 render_type
= GLX_COLOR_INDEX_TYPE
;
810 case GLX_RGBA_FLOAT_BIT
:
811 render_type
= GLX_RGBA_FLOAT_TYPE
;
814 ERR("Unknown render_type: %x\n", render_type
);
819 static BOOL
init_formats(Display
*display
, int screen
, Visual
*visual
)
821 int fmt_id
, tmp_fmt_id
, nCfgs
, i
;
823 GLXFBConfig fbconfig
= NULL
;
824 XVisualInfo
*visinfo
;
825 VisualID visualid
= XVisualIDFromVisual(visual
);
826 int nOffscreenFormats
= 0;
828 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
829 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
830 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
831 * because this call lists both types of formats instead of only onscreen ones. */
832 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
833 if (NULL
== cfgs
|| 0 == nCfgs
) {
834 ERR("glXChooseFBConfig returns NULL\n");
835 if(cfgs
!= NULL
) XFree(cfgs
);
839 /* Count the number of offscreen formats to determine the size for our pixelformat list */
840 for(i
=0; i
<nCfgs
; i
++) {
841 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
843 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
844 /* Onscreen formats have a corresponding XVisual, offscreen ones don't */
847 } else if(visinfo
&& visinfo
->visualid
== visualid
) {
848 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
853 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats
);
855 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
856 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (1+nOffscreenFormats
)*sizeof(WineGLPixelFormat
));
857 WineGLPixelFormatList
[0].iPixelFormat
= 1;
858 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
859 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
860 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
861 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
862 WineGLPixelFormatListSize
= 1;
863 WineGLPixelFormatOnScreenSize
= 1;
865 /* Fill the list with offscreen formats */
866 for(i
=0; i
<nCfgs
; i
++) {
867 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
869 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
870 /* We have found an offscreen rendering format when there is no visualinfo :) */
872 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id
, WineGLPixelFormatListSize
+1, i
);
873 WineGLPixelFormatList
[WineGLPixelFormatListSize
].iPixelFormat
= WineGLPixelFormatListSize
+1; /* The index starts at 1 */
874 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fbconfig
= cfgs
[i
];
875 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fmt_id
= tmp_fmt_id
;
876 WineGLPixelFormatList
[WineGLPixelFormatListSize
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
877 WineGLPixelFormatList
[WineGLPixelFormatListSize
].offscreenOnly
= TRUE
;
878 WineGLPixelFormatListSize
++;
884 if(cfgs
!= NULL
) XFree(cfgs
);
889 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
890 * In our WGL implementation we only support a subset of these formats namely the format of
891 * Wine's main visual and offscreen formats (if they are available).
892 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
893 * and it returns the number of supported WGL formats in fmt_count.
895 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
897 WineGLPixelFormat
*res
= NULL
;
899 /* Init the list of pixel formats when we need it */
900 if(!WineGLPixelFormatListSize
)
901 init_formats(display
, DefaultScreen(display
), visual
);
903 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
904 * iPixelFormat in case of probing the number of pixelformats.
906 if((iPixelFormat
> 0) && (iPixelFormat
<= WineGLPixelFormatListSize
) &&
907 ((WineGLPixelFormatList
[iPixelFormat
-1].offscreenOnly
== FALSE
) ||
909 res
= &WineGLPixelFormatList
[iPixelFormat
-1];
910 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
914 *fmt_count
= WineGLPixelFormatListSize
;
916 *fmt_count
= WineGLPixelFormatOnScreenSize
;
918 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
923 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
924 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
)
928 /* Init the list of pixel formats when we need it */
929 if(!WineGLPixelFormatListSize
)
930 init_formats(display
, DefaultScreen(display
), visual
);
932 for(i
=0; i
<WineGLPixelFormatListSize
; i
++) {
933 if(WineGLPixelFormatList
[i
].fmt_id
== fmt_id
) {
934 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList
[i
].iPixelFormat
, fmt_id
);
935 return &WineGLPixelFormatList
[i
];
938 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
942 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
944 WineGLPixelFormat
*fmt
;
946 if (!fbconfig_id
) return 0;
948 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
);
950 return fmt
->iPixelFormat
;
951 /* This will happen on hwnds without a pixel format set; it's ok */
957 * X11DRV_ChoosePixelFormat
959 * Equivalent to glXChooseVisual.
961 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
962 const PIXELFORMATDESCRIPTOR
*ppfd
) {
963 WineGLPixelFormat
*fmt
= NULL
;
969 int bestDBuffer
= -1;
974 int bestStencil
= -1;
979 ERR("No libGL on this box - disabling OpenGL support !\n");
983 if (TRACE_ON(opengl
)) {
984 TRACE("(%p,%p)\n", physDev
, ppfd
);
986 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
990 ConvertPixelFormatWGLtoGLX(gdi_display
, 0, FALSE
/* offscreen */, &nPixelFormats
);
991 for(i
=0; i
<nPixelFormats
; i
++)
995 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
997 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, i
+1 /* 1-based index */, FALSE
/* offscreen */, &value
);
1001 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1002 if (value
& GLX_RGBA_BIT
)
1003 iPixelType
= PFD_TYPE_RGBA
;
1005 iPixelType
= PFD_TYPE_COLORINDEX
;
1007 if (ppfd
->iPixelType
!= iPixelType
)
1009 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1013 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1014 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1015 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1016 if (value
) dwFlags
|= PFD_STEREO
;
1017 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1018 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1019 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1020 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1021 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1023 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1024 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1025 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1026 * formats without the given flag set.
1027 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1028 * has indicated that a format without stereo is returned when stereo is unavailable.
1029 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1030 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1032 * To summarize the following is most likely the correct behavior:
1033 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1034 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1035 * stereo don't care -> it doesn't matter whether we get stereo or not
1037 * In Wine we will treat no-stereo the same way as don't care because it makes
1038 * format selection even more complicated and second drivers with Stereo advertise
1039 * each format twice anyway.
1042 /* Doublebuffer, see the comments above */
1043 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1044 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1045 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1047 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1048 bestStereo
= dwFlags
& PFD_STEREO
;
1052 bestStencil
= stencil
;
1057 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1061 /* Stereo, see the comments above. */
1062 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1063 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1064 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1066 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1067 bestStereo
= dwFlags
& PFD_STEREO
;
1071 bestStencil
= stencil
;
1076 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1080 /* Below we will do a number of checks to select the 'best' pixelformat.
1081 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1082 * The code works by trying to match the most important options as close as possible.
1083 * When a reasonable format is found, we will try to match more options. */
1086 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1087 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1089 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1090 bestStereo
= dwFlags
& PFD_STEREO
;
1094 bestStencil
= stencil
;
1098 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1099 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1104 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1105 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1107 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1108 bestStereo
= dwFlags
& PFD_STEREO
;
1112 bestStencil
= stencil
;
1116 } else if(bestAlpha
!= alpha
) {
1117 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1122 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1123 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1125 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1126 bestStereo
= dwFlags
& PFD_STEREO
;
1130 bestStencil
= stencil
;
1134 } else if(bestDepth
!= depth
) {
1135 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1140 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1141 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1143 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1144 bestStereo
= dwFlags
& PFD_STEREO
;
1148 bestStencil
= stencil
;
1152 } else if(bestStencil
!= stencil
) {
1153 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1158 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1159 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1161 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1162 bestStereo
= dwFlags
& PFD_STEREO
;
1166 bestStencil
= stencil
;
1170 } else if(bestAux
!= aux
) {
1171 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1176 if(bestFormat
== -1) {
1177 TRACE("No matching mode was found returning 0\n");
1181 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1182 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, WineGLPixelFormatList
[bestFormat
].fmt_id
);
1185 wine_tsx11_unlock();
1190 * X11DRV_DescribePixelFormat
1192 * Get the pixel-format descriptor associated to the given id
1194 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1197 PIXELFORMATDESCRIPTOR
*ppfd
) {
1198 /*XVisualInfo *vis;*/
1201 WineGLPixelFormat
*fmt
;
1205 if (!has_opengl()) {
1206 ERR("No libGL on this box - disabling OpenGL support !\n");
1210 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1212 /* 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 */
1213 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1215 /* The application is only querying the number of pixelformats */
1217 } else if(fmt
== NULL
) {
1218 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1222 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1223 ERR("Wrong structure size !\n");
1224 /* Should set error */
1230 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1231 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1234 /* These flags are always the same... */
1235 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1236 /* Now the flags extracted from the Visual */
1240 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_X_RENDERABLE
, &value
);
1242 ppfd
->dwFlags
|= PFD_SUPPORT_GDI
;
1244 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1245 if(value
& GLX_WINDOW_BIT
)
1246 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1247 if(value
& GLX_PIXMAP_BIT
)
1248 ppfd
->dwFlags
|= PFD_DRAW_TO_BITMAP
;
1250 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_CONFIG_CAVEAT
, &value
);
1251 if(value
== GLX_SLOW_CONFIG
)
1252 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1254 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1256 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1257 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1259 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1262 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1263 if (value
& GLX_RGBA_BIT
)
1264 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1266 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1269 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1270 ppfd
->cColorBits
= value
;
1272 /* Red, green, blue and alpha bits / shifts */
1273 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1274 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1275 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1276 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1277 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1279 ppfd
->cRedBits
= rb
;
1280 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1281 ppfd
->cBlueBits
= bb
;
1282 ppfd
->cBlueShift
= ab
;
1283 ppfd
->cGreenBits
= gb
;
1284 ppfd
->cGreenShift
= bb
+ ab
;
1285 ppfd
->cAlphaBits
= ab
;
1286 ppfd
->cAlphaShift
= 0;
1289 ppfd
->cRedShift
= 0;
1290 ppfd
->cBlueBits
= 0;
1291 ppfd
->cBlueShift
= 0;
1292 ppfd
->cGreenBits
= 0;
1293 ppfd
->cGreenShift
= 0;
1294 ppfd
->cAlphaBits
= 0;
1295 ppfd
->cAlphaShift
= 0;
1298 /* Accum RGBA bits */
1299 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1300 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1301 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1302 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1304 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1305 ppfd
->cAccumRedBits
= rb
;
1306 ppfd
->cAccumGreenBits
= gb
;
1307 ppfd
->cAccumBlueBits
= bb
;
1308 ppfd
->cAccumAlphaBits
= ab
;
1311 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1312 ppfd
->cDepthBits
= value
;
1315 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1316 ppfd
->cStencilBits
= value
;
1318 wine_tsx11_unlock();
1320 /* Aux : to do ... */
1322 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1324 if (TRACE_ON(opengl
)) {
1325 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1332 * X11DRV_GetPixelFormat
1334 * Get the pixel-format id used by this DC
1336 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1337 WineGLPixelFormat
*fmt
;
1339 TRACE("(%p)\n", physDev
);
1341 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1344 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1345 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1348 else if(fmt
->offscreenOnly
)
1350 /* Offscreen formats can't be used with traditional WGL calls.
1351 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1352 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1356 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1357 return physDev
->current_pf
;
1361 * X11DRV_SetPixelFormat
1363 * Set the pixel-format id used by this DC
1365 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1367 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1368 WineGLPixelFormat
*fmt
;
1372 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1374 if (!has_opengl()) {
1375 ERR("No libGL on this box - disabling OpenGL support !\n");
1379 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1380 if(get_glxdrawable(physDev
) == root_window
)
1382 ERR("Invalid operation on root_window\n");
1386 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1387 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1389 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1393 if(physDev
->current_pf
) /* cannot change it if already set */
1394 return (physDev
->current_pf
== iPixelFormat
);
1396 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1398 hwnd
= WindowFromDC(physDev
->hdc
);
1400 if(!(value
&GLX_WINDOW_BIT
)) {
1401 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1405 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, (WPARAM
)fmt
->fmt_id
, 0)) {
1406 ERR("Couldn't set format of the window, returning failure\n");
1411 physDev
->current_pf
= iPixelFormat
;
1413 if (TRACE_ON(opengl
)) {
1416 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1418 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1420 TRACE(" FBConfig have :\n");
1421 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1422 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1423 TRACE(" - VISUAL_ID 0x%x\n", value
);
1424 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1425 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1432 * X11DRV_wglCreateContext
1434 * For OpenGL32 wglCreateContext.
1436 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1438 Wine_GLContext
*ret
;
1439 WineGLPixelFormat
*fmt
;
1440 int hdcPF
= physDev
->current_pf
;
1442 HDC hdc
= physDev
->hdc
;
1444 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1446 if (!has_opengl()) {
1447 ERR("No libGL on this box - disabling OpenGL support !\n");
1451 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1452 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1453 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1454 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1455 * If this fails something is very wrong on the system. */
1457 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1458 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1462 /* The context will be allocated in the wglMakeCurrent call */
1464 ret
= alloc_context();
1465 wine_tsx11_unlock();
1467 ret
->physDev
= physDev
;
1471 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1473 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1478 * X11DRV_wglDeleteContext
1480 * For OpenGL32 wglDeleteContext.
1482 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1484 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1487 TRACE("(%p)\n", hglrc
);
1489 if (!has_opengl()) {
1490 ERR("No libGL on this box - disabling OpenGL support !\n");
1495 /* A game (Half Life not to name it) deletes twice the same context,
1496 * so make sure it is valid first */
1497 if (is_valid_context( ctx
))
1499 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1504 WARN("Error deleting context !\n");
1505 SetLastError(ERROR_INVALID_HANDLE
);
1508 wine_tsx11_unlock();
1514 * X11DRV_wglGetCurrentReadDCARB
1516 * For OpenGL32 wglGetCurrentReadDCARB.
1518 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1521 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1522 X11DRV_PDEVICE
*physDev
= ctx
? ctx
->pReadDev
: NULL
;
1527 TRACE(" returning %p (GL drawable %lu)\n", ret
, physDev
? physDev
->drawable
: 0);
1532 * X11DRV_wglGetProcAddress
1534 * For OpenGL32 wglGetProcAddress.
1536 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1539 const WineGLExtension
*ext
;
1541 int padding
= 32 - strlen(lpszProc
);
1545 if (!has_opengl()) {
1546 ERR("No libGL on this box - disabling OpenGL support !\n");
1550 /* Check the table of WGL extensions to see if we need to return a WGL extension
1551 * or a function pointer to a native OpenGL function. */
1552 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1553 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1555 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1556 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1557 ext
= WineGLExtensionList
[i
];
1558 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1559 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1560 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1561 return ext
->extEntryPoints
[j
].funcAddress
;
1567 WARN("(%s) - not found\n", lpszProc
);
1571 /***********************************************************************
1572 * sync_current_drawable
1574 * Adjust the current viewport and scissor in order to position
1575 * and size the current drawable correctly on the parent window.
1577 static void sync_current_drawable(BOOL updatedc
)
1583 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1587 if (ctx
&& ctx
->physDev
)
1590 GetClipBox(ctx
->physDev
->hdc
, &rc
); /* Make sure physDev is up to date */
1592 dy
= ctx
->physDev
->drawable_rect
.bottom
- ctx
->physDev
->drawable_rect
.top
-
1593 ctx
->physDev
->dc_rect
.bottom
;
1594 width
= ctx
->physDev
->dc_rect
.right
- ctx
->physDev
->dc_rect
.left
;
1595 height
= ctx
->physDev
->dc_rect
.bottom
- ctx
->physDev
->dc_rect
.top
;
1599 pglViewport(ctx
->physDev
->dc_rect
.left
+ ctx
->viewport
.left
,
1600 dy
+ ctx
->viewport
.top
,
1601 ctx
->viewport
.right
? (ctx
->viewport
.right
- ctx
->viewport
.left
) : width
,
1602 ctx
->viewport
.bottom
? (ctx
->viewport
.bottom
- ctx
->viewport
.top
) : height
);
1604 pglEnable(GL_SCISSOR_TEST
);
1606 if (ctx
->scissor_enabled
)
1607 pglScissor(ctx
->physDev
->dc_rect
.left
+ min(width
, max(0, ctx
->scissor
.left
)),
1608 dy
+ min(height
, max(0, ctx
->scissor
.top
)),
1609 min(width
, max(0, ctx
->scissor
.right
- ctx
->scissor
.left
)),
1610 min(height
, max(0, ctx
->scissor
.bottom
- ctx
->scissor
.top
)));
1612 pglScissor(ctx
->physDev
->dc_rect
.left
, dy
, width
, height
);
1614 wine_tsx11_unlock();
1619 * X11DRV_wglMakeCurrent
1621 * For OpenGL32 wglMakeCurrent.
1623 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1625 HDC hdc
= physDev
->hdc
;
1626 DWORD type
= GetObjectType(hdc
);
1628 TRACE("(%p,%p)\n", hdc
, hglrc
);
1630 if (!has_opengl()) {
1631 ERR("No libGL on this box - disabling OpenGL support !\n");
1636 if (hglrc
== NULL
) {
1637 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1638 NtCurrentTeb()->glContext
= NULL
;
1640 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1641 Drawable drawable
= get_glxdrawable(physDev
);
1642 if (ctx
->ctx
== NULL
) {
1643 /* The describe lines below are for debugging purposes only */
1644 if (TRACE_ON(wgl
)) {
1645 describeDrawable(ctx
, drawable
);
1646 describeContext(ctx
);
1649 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1650 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1652 TRACE(" Creating GLX Context\n");
1654 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1655 else /* Create a GLX Context for a pbuffer */
1656 ctx
->ctx
= pglXCreateNewContext(gdi_display
, ctx
->fmt
->fbconfig
, ctx
->fmt
->render_type
, NULL
, True
);
1658 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1660 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1661 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1662 NtCurrentTeb()->glContext
= ctx
;
1666 ctx
->physDev
= physDev
;
1667 ctx
->pReadDev
= physDev
;
1669 if (type
== OBJ_MEMDC
)
1671 ctx
->do_escape
= TRUE
;
1672 pglDrawBuffer(GL_FRONT_LEFT
);
1676 sync_current_drawable(FALSE
);
1680 wine_tsx11_unlock();
1681 TRACE(" returning %s\n", (ret
? "True" : "False"));
1686 * X11DRV_wglMakeContextCurrentARB
1688 * For OpenGL32 wglMakeContextCurrentARB
1690 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1693 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1695 if (!has_opengl()) {
1696 ERR("No libGL on this box - disabling OpenGL support !\n");
1701 if (hglrc
== NULL
) {
1702 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1703 NtCurrentTeb()->glContext
= NULL
;
1705 if (NULL
== pglXMakeContextCurrent
) {
1708 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1709 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1710 Drawable d_read
= get_glxdrawable(pReadDev
);
1712 if (ctx
->ctx
== NULL
) {
1713 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, GetObjectType(pDrawDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1714 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1716 ctx
->hdc
= pDrawDev
->hdc
;
1717 ctx
->physDev
= pDrawDev
;
1718 ctx
->pReadDev
= pReadDev
;
1719 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1720 NtCurrentTeb()->glContext
= ctx
;
1723 wine_tsx11_unlock();
1725 TRACE(" returning %s\n", (ret
? "True" : "False"));
1730 * X11DRV_wglShareLists
1732 * For OpenGL32 wglShaderLists.
1734 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1735 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1736 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1738 TRACE("(%p, %p)\n", org
, dest
);
1740 if (!has_opengl()) {
1741 ERR("No libGL on this box - disabling OpenGL support !\n");
1745 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1746 ERR("Could not share display lists, context already created !\n");
1749 if (org
->ctx
== NULL
) {
1751 describeContext(org
);
1754 org
->ctx
= pglXCreateContext(gdi_display
, org
->vis
, NULL
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1755 else /* Create a GLX Context for a pbuffer */
1756 org
->ctx
= pglXCreateNewContext(gdi_display
, org
->fmt
->fbconfig
, org
->fmt
->render_type
, NULL
, True
);
1757 wine_tsx11_unlock();
1758 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1762 describeContext(dest
);
1763 /* Create the destination context with display lists shared */
1765 dest
->ctx
= pglXCreateContext(gdi_display
, dest
->vis
, org
->ctx
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1766 else /* Create a GLX Context for a pbuffer */
1767 dest
->ctx
= pglXCreateNewContext(gdi_display
, dest
->fmt
->fbconfig
, dest
->fmt
->render_type
, org
->ctx
, True
);
1768 wine_tsx11_unlock();
1769 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1776 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1778 /* We are running using client-side rendering fonts... */
1782 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1786 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1787 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1788 wine_tsx11_unlock();
1790 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1791 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1792 int height
, width_int
;
1794 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1795 if (needed_size
== GDI_ERROR
) {
1796 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1799 TRACE(" - needed size : %d\n", needed_size
);
1802 if (needed_size
> size
) {
1804 HeapFree(GetProcessHeap(), 0, bitmap
);
1805 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1806 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1807 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1809 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1810 if (TRACE_ON(opengl
)) {
1811 unsigned int height
, width
, bitmask
;
1812 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1814 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1815 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1816 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1817 if (needed_size
!= 0) {
1818 TRACE(" - bitmap :\n");
1819 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1821 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1826 if (*bitmap_
& bitmask
)
1831 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1837 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1838 * glyph for it to be drawn properly.
1840 if (needed_size
!= 0) {
1841 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1842 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1844 for (width
= 0; width
< width_int
; width
++) {
1845 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1846 ((int *) bitmap
)[height
* width_int
+ width
];
1852 pglNewList(listBase
++, GL_COMPILE
);
1853 if (needed_size
!= 0) {
1854 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1855 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1856 gm
.gmCellIncX
, gm
.gmCellIncY
,
1859 /* This is the case of 'empty' glyphs like the space character */
1860 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1863 wine_tsx11_unlock();
1867 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1868 wine_tsx11_unlock();
1870 HeapFree(GetProcessHeap(), 0, bitmap
);
1871 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1876 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1877 wine_tsx11_unlock();
1879 HeapFree(GetProcessHeap(), 0, bitmap
);
1880 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1885 * X11DRV_wglUseFontBitmapsA
1887 * For OpenGL32 wglUseFontBitmapsA.
1889 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1891 Font fid
= physDev
->font
;
1893 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1895 if (!has_opengl()) {
1896 ERR("No libGL on this box - disabling OpenGL support !\n");
1901 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
1905 /* I assume that the glyphs are at the same position for X and for Windows */
1906 pglXUseXFont(fid
, first
, count
, listBase
);
1907 wine_tsx11_unlock();
1912 * X11DRV_wglUseFontBitmapsW
1914 * For OpenGL32 wglUseFontBitmapsW.
1916 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1918 Font fid
= physDev
->font
;
1920 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1922 if (!has_opengl()) {
1923 ERR("No libGL on this box - disabling OpenGL support !\n");
1928 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1931 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1934 /* I assume that the glyphs are at the same position for X and for Windows */
1935 pglXUseXFont(fid
, first
, count
, listBase
);
1936 wine_tsx11_unlock();
1940 static void WINAPI
X11DRV_wglDisable(GLenum cap
)
1942 if (cap
== GL_SCISSOR_TEST
)
1944 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1947 ctx
->scissor_enabled
= FALSE
;
1953 wine_tsx11_unlock();
1957 static void WINAPI
X11DRV_wglEnable(GLenum cap
)
1959 if (cap
== GL_SCISSOR_TEST
)
1961 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1964 ctx
->scissor_enabled
= TRUE
;
1970 wine_tsx11_unlock();
1974 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1975 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
1982 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1984 pglGetIntegerv(pname
, params
);
1986 * if we cannot find a Wine Context
1987 * we only have the default wine desktop context,
1988 * so if we have only a 24 depth say we have 32
1990 if (!ctx
&& *params
== 24) {
1993 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
1998 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2000 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2001 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2005 pglGetIntegerv(pname
, params
);
2008 wine_tsx11_unlock();
2011 static GLboolean WINAPI
X11DRV_wglIsEnabled(GLenum cap
)
2013 GLboolean enabled
= False
;
2015 if (cap
== GL_SCISSOR_TEST
)
2017 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2020 enabled
= ctx
->scissor_enabled
;
2025 enabled
= pglIsEnabled(cap
);
2026 wine_tsx11_unlock();
2031 static void WINAPI
X11DRV_wglScissor(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2033 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2037 ctx
->scissor
.left
= x
;
2038 ctx
->scissor
.top
= y
;
2039 ctx
->scissor
.right
= x
+ width
;
2040 ctx
->scissor
.bottom
= y
+ height
;
2042 sync_current_drawable(TRUE
);
2046 static void WINAPI
X11DRV_wglViewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2048 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2052 ctx
->viewport
.left
= x
;
2053 ctx
->viewport
.top
= y
;
2054 ctx
->viewport
.right
= x
+ width
;
2055 ctx
->viewport
.bottom
= y
+ height
;
2057 sync_current_drawable(TRUE
);
2061 static void WINAPI
X11DRV_wglFinish(void)
2065 wine_tsx11_unlock();
2068 static void WINAPI
X11DRV_wglFlush(void)
2072 wine_tsx11_unlock();
2076 * X11DRV_wglGetExtensionsStringARB
2078 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2080 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2081 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2082 return WineGLInfo
.wglExtensions
;
2086 * X11DRV_wglCreatePbufferARB
2088 * WGL_ARB_pbuffer: wglCreatePbufferARB
2090 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2092 Wine_GLPBuffer
* object
= NULL
;
2093 WineGLPixelFormat
*fmt
= NULL
;
2098 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2100 if (0 >= iPixelFormat
) {
2101 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2102 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2103 return NULL
; /* unexpected error */
2106 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2107 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2109 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2110 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2111 goto create_failed
; /* unexpected error */
2114 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2115 if (NULL
== object
) {
2116 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2117 goto create_failed
; /* unexpected error */
2120 object
->display
= gdi_display
;
2121 object
->width
= iWidth
;
2122 object
->height
= iHeight
;
2125 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2126 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2127 while (piAttribList
&& 0 != *piAttribList
) {
2129 switch (*piAttribList
) {
2130 case WGL_PBUFFER_LARGEST_ARB
: {
2132 attr_v
= *piAttribList
;
2133 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2134 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2138 case WGL_TEXTURE_FORMAT_ARB
: {
2140 attr_v
= *piAttribList
;
2141 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2142 if (use_render_texture_ati
) {
2145 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2146 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2147 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2149 SetLastError(ERROR_INVALID_DATA
);
2152 object
->use_render_texture
= 1;
2153 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2155 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2156 object
->use_render_texture
= 0;
2158 if (!use_render_texture_emulation
) {
2159 SetLastError(ERROR_INVALID_DATA
);
2163 case WGL_TEXTURE_RGB_ARB
:
2164 object
->use_render_texture
= GL_RGB
;
2165 object
->texture_bpp
= 3;
2166 object
->texture_format
= GL_RGB
;
2167 object
->texture_type
= GL_UNSIGNED_BYTE
;
2169 case WGL_TEXTURE_RGBA_ARB
:
2170 object
->use_render_texture
= GL_RGBA
;
2171 object
->texture_bpp
= 4;
2172 object
->texture_format
= GL_RGBA
;
2173 object
->texture_type
= GL_UNSIGNED_BYTE
;
2176 /* WGL_FLOAT_COMPONENTS_NV */
2177 case WGL_TEXTURE_FLOAT_R_NV
:
2178 object
->use_render_texture
= GL_FLOAT_R_NV
;
2179 object
->texture_bpp
= 4;
2180 object
->texture_format
= GL_RED
;
2181 object
->texture_type
= GL_FLOAT
;
2183 case WGL_TEXTURE_FLOAT_RG_NV
:
2184 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2185 object
->texture_bpp
= 8;
2186 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2187 object
->texture_type
= GL_FLOAT
;
2189 case WGL_TEXTURE_FLOAT_RGB_NV
:
2190 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2191 object
->texture_bpp
= 12;
2192 object
->texture_format
= GL_RGB
;
2193 object
->texture_type
= GL_FLOAT
;
2195 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2196 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2197 object
->texture_bpp
= 16;
2198 object
->texture_format
= GL_RGBA
;
2199 object
->texture_type
= GL_FLOAT
;
2202 ERR("Unknown texture format: %x\n", attr_v
);
2203 SetLastError(ERROR_INVALID_DATA
);
2211 case WGL_TEXTURE_TARGET_ARB
: {
2213 attr_v
= *piAttribList
;
2214 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2215 if (use_render_texture_ati
) {
2218 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2219 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2220 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2221 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2223 SetLastError(ERROR_INVALID_DATA
);
2226 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2228 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2229 object
->texture_target
= 0;
2231 if (!use_render_texture_emulation
) {
2232 SetLastError(ERROR_INVALID_DATA
);
2236 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2237 if (iWidth
!= iHeight
) {
2238 SetLastError(ERROR_INVALID_DATA
);
2241 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2242 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2245 case WGL_TEXTURE_1D_ARB
: {
2247 SetLastError(ERROR_INVALID_DATA
);
2250 object
->texture_target
= GL_TEXTURE_1D
;
2251 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2254 case WGL_TEXTURE_2D_ARB
: {
2255 object
->texture_target
= GL_TEXTURE_2D
;
2256 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2259 case WGL_TEXTURE_RECTANGLE_NV
: {
2260 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2261 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2265 ERR("Unknown texture target: %x\n", attr_v
);
2266 SetLastError(ERROR_INVALID_DATA
);
2274 case WGL_MIPMAP_TEXTURE_ARB
: {
2276 attr_v
= *piAttribList
;
2277 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2278 if (use_render_texture_ati
) {
2279 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2281 if (!use_render_texture_emulation
) {
2282 SetLastError(ERROR_INVALID_DATA
);
2292 PUSH1(attribs
, None
);
2293 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2294 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2295 if (!object
->drawable
) {
2296 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2297 goto create_failed
; /* unexpected error */
2299 TRACE("->(%p)\n", object
);
2300 return (HPBUFFERARB
) object
;
2303 HeapFree(GetProcessHeap(), 0, object
);
2304 TRACE("->(FAILED)\n");
2305 return (HPBUFFERARB
) NULL
;
2309 * X11DRV_wglDestroyPbufferARB
2311 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2313 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2315 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2316 TRACE("(%p)\n", hPbuffer
);
2317 if (NULL
== object
) {
2318 SetLastError(ERROR_INVALID_HANDLE
);
2321 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2322 HeapFree(GetProcessHeap(), 0, object
);
2327 * X11DRV_wglGetPbufferDCARB
2329 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2330 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2331 * Gdi32 implements the part of this function which creates a device context.
2332 * This part associates the physDev with the X drawable of the pbuffer.
2334 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2336 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2337 if (NULL
== object
) {
2338 SetLastError(ERROR_INVALID_HANDLE
);
2342 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2343 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2344 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2345 physDev
->drawable
= object
->drawable
;
2346 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2347 physDev
->dc_rect
= physDev
->drawable_rect
;
2349 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2350 return physDev
->hdc
;
2354 * X11DRV_wglQueryPbufferARB
2356 * WGL_ARB_pbuffer: wglQueryPbufferARB
2358 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2360 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2361 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2362 if (NULL
== object
) {
2363 SetLastError(ERROR_INVALID_HANDLE
);
2366 switch (iAttribute
) {
2367 case WGL_PBUFFER_WIDTH_ARB
:
2368 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2370 case WGL_PBUFFER_HEIGHT_ARB
:
2371 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2374 case WGL_PBUFFER_LOST_ARB
:
2375 /* GLX Pbuffers cannot be lost by default. We can support this by
2376 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2377 * to receive pixel buffer clobber events, however that may or may
2378 * not give any benefit */
2379 *piValue
= GL_FALSE
;
2382 case WGL_TEXTURE_FORMAT_ARB
:
2383 if (use_render_texture_ati
) {
2385 int type
= WGL_NO_TEXTURE_ARB
;
2386 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2388 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2389 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2390 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2394 if (!object
->use_render_texture
) {
2395 *piValue
= WGL_NO_TEXTURE_ARB
;
2397 if (!use_render_texture_emulation
) {
2398 SetLastError(ERROR_INVALID_HANDLE
);
2401 switch(object
->use_render_texture
) {
2403 *piValue
= WGL_TEXTURE_RGB_ARB
;
2406 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2408 /* WGL_FLOAT_COMPONENTS_NV */
2410 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2412 case GL_FLOAT_RG_NV
:
2413 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2415 case GL_FLOAT_RGB_NV
:
2416 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2418 case GL_FLOAT_RGBA_NV
:
2419 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2422 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2428 case WGL_TEXTURE_TARGET_ARB
:
2429 if (use_render_texture_ati
) {
2431 int type
= WGL_NO_TEXTURE_ARB
;
2432 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2434 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2435 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2436 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2437 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2441 if (!object
->texture_target
) {
2442 *piValue
= WGL_NO_TEXTURE_ARB
;
2444 if (!use_render_texture_emulation
) {
2445 SetLastError(ERROR_INVALID_DATA
);
2448 switch (object
->texture_target
) {
2449 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2450 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2451 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2452 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2458 case WGL_MIPMAP_TEXTURE_ARB
:
2459 if (use_render_texture_ati
) {
2460 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2462 *piValue
= GL_FALSE
; /** don't support that */
2463 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2468 FIXME("unexpected attribute %x\n", iAttribute
);
2476 * X11DRV_wglReleasePbufferDCARB
2478 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2480 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2482 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2488 * X11DRV_wglSetPbufferAttribARB
2490 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2492 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2494 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2495 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2496 if (NULL
== object
) {
2497 SetLastError(ERROR_INVALID_HANDLE
);
2500 if (!object
->use_render_texture
) {
2501 SetLastError(ERROR_INVALID_HANDLE
);
2504 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2507 if (NULL
!= pglXDrawableAttribATI
) {
2508 if (use_render_texture_ati
) {
2509 FIXME("Need conversion for GLX_ATI_render_texture\n");
2511 return pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2517 * X11DRV_wglChoosePixelFormatARB
2519 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2521 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2526 GLXFBConfig
* cfgs
= NULL
;
2530 WineGLPixelFormat
*fmt
;
2534 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2535 if (NULL
!= pfAttribFList
) {
2536 FIXME("unused pfAttribFList\n");
2539 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2540 if (-1 == nAttribs
) {
2541 WARN("Cannot convert WGL to GLX attributes\n");
2544 PUSH1(attribs
, None
);
2546 /* Search for FB configurations matching the requirements in attribs */
2547 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2549 WARN("Compatible Pixel Format not found\n");
2553 /* Loop through all matching formats and check if they are suitable.
2554 * Note that this function should at max return nMaxFormats different formats */
2555 for(run
=0; run
< 2; run
++)
2557 for (it
= 0; it
< nCfgs
; ++it
) {
2558 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2560 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2564 /* Search for the format in our list of compatible formats */
2565 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
);
2569 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2570 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2573 if(pfmt_it
< nMaxFormats
) {
2574 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2575 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2581 *nNumFormats
= pfmt_it
;
2588 * X11DRV_wglGetPixelFormatAttribivARB
2590 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2592 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2595 WineGLPixelFormat
*fmt
= NULL
;
2599 int nWGLFormats
= 0;
2601 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2603 if (0 < iLayerPlane
) {
2604 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2608 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2609 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2610 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2611 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2613 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2616 for (i
= 0; i
< nAttributes
; ++i
) {
2617 const int curWGLAttr
= piAttributes
[i
];
2618 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2620 switch (curWGLAttr
) {
2621 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2622 piValues
[i
] = nWGLFormats
;
2625 case WGL_SUPPORT_OPENGL_ARB
:
2626 piValues
[i
] = GL_TRUE
;
2629 case WGL_ACCELERATION_ARB
:
2630 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2631 if (!fmt
) goto pix_error
;
2632 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2633 if (hTest
) goto get_error
;
2635 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2636 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
; break;
2637 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2639 ERR("unexpected Config Caveat(%x)\n", tmp
);
2640 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2644 case WGL_TRANSPARENT_ARB
:
2645 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2646 if (!fmt
) goto pix_error
;
2647 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2648 if (hTest
) goto get_error
;
2649 piValues
[i
] = GL_FALSE
;
2650 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2653 case WGL_PIXEL_TYPE_ARB
:
2654 curGLXAttr
= GLX_RENDER_TYPE
;
2655 if (!fmt
) goto pix_error
;
2656 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2657 if (hTest
) goto get_error
;
2658 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2659 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2660 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2661 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2662 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2664 ERR("unexpected RenderType(%x)\n", tmp
);
2665 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2669 case WGL_COLOR_BITS_ARB
:
2670 curGLXAttr
= GLX_BUFFER_SIZE
;
2673 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2674 if (use_render_texture_ati
) {
2675 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2678 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2679 if (use_render_texture_ati
) {
2680 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2683 if (!use_render_texture_emulation
) {
2684 piValues
[i
] = GL_FALSE
;
2687 curGLXAttr
= GLX_RENDER_TYPE
;
2688 if (!fmt
) goto pix_error
;
2689 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2690 if (hTest
) goto get_error
;
2691 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2692 piValues
[i
] = GL_FALSE
;
2695 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2696 if (hTest
) goto get_error
;
2697 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2700 case WGL_BLUE_BITS_ARB
:
2701 curGLXAttr
= GLX_BLUE_SIZE
;
2703 case WGL_RED_BITS_ARB
:
2704 curGLXAttr
= GLX_RED_SIZE
;
2706 case WGL_GREEN_BITS_ARB
:
2707 curGLXAttr
= GLX_GREEN_SIZE
;
2709 case WGL_ALPHA_BITS_ARB
:
2710 curGLXAttr
= GLX_ALPHA_SIZE
;
2712 case WGL_DEPTH_BITS_ARB
:
2713 curGLXAttr
= GLX_DEPTH_SIZE
;
2715 case WGL_STENCIL_BITS_ARB
:
2716 curGLXAttr
= GLX_STENCIL_SIZE
;
2718 case WGL_DOUBLE_BUFFER_ARB
:
2719 curGLXAttr
= GLX_DOUBLEBUFFER
;
2721 case WGL_STEREO_ARB
:
2722 curGLXAttr
= GLX_STEREO
;
2724 case WGL_AUX_BUFFERS_ARB
:
2725 curGLXAttr
= GLX_AUX_BUFFERS
;
2728 case WGL_SUPPORT_GDI_ARB
:
2729 if (!fmt
) goto pix_error
;
2730 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &tmp
);
2731 if (hTest
) goto get_error
;
2733 piValues
[i
] = GL_FALSE
;
2736 curGLXAttr
= GLX_X_RENDERABLE
;
2739 case WGL_DRAW_TO_WINDOW_ARB
:
2740 case WGL_DRAW_TO_BITMAP_ARB
:
2741 case WGL_DRAW_TO_PBUFFER_ARB
:
2742 if (!fmt
) goto pix_error
;
2743 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2744 if (hTest
) goto get_error
;
2745 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2746 (curWGLAttr
== WGL_DRAW_TO_BITMAP_ARB
&& (tmp
&GLX_PIXMAP_BIT
)) ||
2747 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2748 piValues
[i
] = GL_TRUE
;
2750 piValues
[i
] = GL_FALSE
;
2753 case WGL_PBUFFER_LARGEST_ARB
:
2754 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2757 case WGL_SAMPLE_BUFFERS_ARB
:
2758 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2761 case WGL_SAMPLES_ARB
:
2762 curGLXAttr
= GLX_SAMPLES_ARB
;
2765 case WGL_FLOAT_COMPONENTS_NV
:
2766 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2769 case WGL_ACCUM_RED_BITS_ARB
:
2770 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2772 case WGL_ACCUM_GREEN_BITS_ARB
:
2773 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2775 case WGL_ACCUM_BLUE_BITS_ARB
:
2776 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2778 case WGL_ACCUM_ALPHA_BITS_ARB
:
2779 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2781 case WGL_ACCUM_BITS_ARB
:
2782 if (!fmt
) goto pix_error
;
2783 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2784 if (hTest
) goto get_error
;
2786 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2787 if (hTest
) goto get_error
;
2789 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2790 if (hTest
) goto get_error
;
2792 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2793 if (hTest
) goto get_error
;
2798 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2801 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2802 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2803 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2805 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2806 * and check which options can work using iPixelFormat=0 and which not.
2807 * A problem would be that this function is an extension. This would
2808 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2810 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2811 if (!fmt
) goto pix_error
;
2812 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2813 if (hTest
) goto get_error
;
2816 piValues
[i
] = GL_FALSE
;
2822 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2826 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2831 * X11DRV_wglGetPixelFormatAttribfvARB
2833 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2835 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2841 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2843 /* Allocate a temporary array to store integer values */
2844 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2846 ERR("couldn't allocate %d array\n", nAttributes
);
2850 /* Piggy-back on wglGetPixelFormatAttribivARB */
2851 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2853 /* Convert integer values to float. Should also check for attributes
2854 that can give decimal values here */
2855 for (i
=0; i
<nAttributes
;i
++) {
2856 pfValues
[i
] = attr
[i
];
2860 HeapFree(GetProcessHeap(), 0, attr
);
2865 * X11DRV_wglBindTexImageARB
2867 * WGL_ARB_render_texture: wglBindTexImageARB
2869 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2871 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2872 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2873 if (NULL
== object
) {
2874 SetLastError(ERROR_INVALID_HANDLE
);
2877 if (!object
->use_render_texture
) {
2878 SetLastError(ERROR_INVALID_HANDLE
);
2882 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2883 static int init
= 0;
2884 int prev_binded_texture
= 0;
2885 GLXContext prev_context
= pglXGetCurrentContext();
2886 Drawable prev_drawable
= pglXGetCurrentDrawable();
2887 GLXContext tmp_context
;
2889 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2890 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2891 isn't ideal performance wise but I wasn't able to get other ways working.
2894 init
= 1; /* Only show the FIXME once for performance reasons */
2895 FIXME("partial stub!\n");
2898 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
2899 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2901 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2903 /* Switch to our pbuffer */
2904 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2906 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2907 * After that upload the pbuffer texture data. */
2908 pglBindTexture(object
->texture_target
, prev_binded_texture
);
2909 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2911 /* Switch back to the original drawable and upload the pbuffer-texture */
2912 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
2913 pglXDestroyContext(gdi_display
, tmp_context
);
2917 if (NULL
!= pglXBindTexImageATI
) {
2922 case WGL_FRONT_LEFT_ARB
:
2923 buffer
= GLX_FRONT_LEFT_ATI
;
2925 case WGL_FRONT_RIGHT_ARB
:
2926 buffer
= GLX_FRONT_RIGHT_ATI
;
2928 case WGL_BACK_LEFT_ARB
:
2929 buffer
= GLX_BACK_LEFT_ATI
;
2931 case WGL_BACK_RIGHT_ARB
:
2932 buffer
= GLX_BACK_RIGHT_ATI
;
2935 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2939 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
2940 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
2941 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
2942 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
2943 * works fine using our pbuffer emulation path.
2945 return pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
2951 * X11DRV_wglReleaseTexImageARB
2953 * WGL_ARB_render_texture: wglReleaseTexImageARB
2955 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2957 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2958 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2959 if (NULL
== object
) {
2960 SetLastError(ERROR_INVALID_HANDLE
);
2963 if (!object
->use_render_texture
) {
2964 SetLastError(ERROR_INVALID_HANDLE
);
2967 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2970 if (NULL
!= pglXReleaseTexImageATI
) {
2975 case WGL_FRONT_LEFT_ARB
:
2976 buffer
= GLX_FRONT_LEFT_ATI
;
2978 case WGL_FRONT_RIGHT_ARB
:
2979 buffer
= GLX_FRONT_RIGHT_ATI
;
2981 case WGL_BACK_LEFT_ARB
:
2982 buffer
= GLX_BACK_LEFT_ATI
;
2984 case WGL_BACK_RIGHT_ARB
:
2985 buffer
= GLX_BACK_RIGHT_ATI
;
2988 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2991 return pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
2997 * X11DRV_wglGetExtensionsStringEXT
2999 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3001 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3002 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3003 return WineGLInfo
.wglExtensions
;
3007 * X11DRV_wglGetSwapIntervalEXT
3009 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3011 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3012 FIXME("(),stub!\n");
3013 return swap_interval
;
3017 * X11DRV_wglSwapIntervalEXT
3019 * WGL_EXT_swap_control: wglSwapIntervalEXT
3021 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3022 TRACE("(%d)\n", interval
);
3023 swap_interval
= interval
;
3024 if (NULL
!= pglXSwapIntervalSGI
) {
3025 return 0 == pglXSwapIntervalSGI(interval
);
3027 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3032 * X11DRV_wglAllocateMemoryNV
3034 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3036 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3037 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3038 if (pglXAllocateMemoryNV
== NULL
)
3041 return pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3045 * X11DRV_wglFreeMemoryNV
3047 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3049 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3050 TRACE("(%p)\n", pointer
);
3051 if (pglXFreeMemoryNV
== NULL
)
3054 pglXFreeMemoryNV(pointer
);
3058 * glxRequireVersion (internal)
3060 * Check if the supported GLX version matches requiredVersion.
3062 static BOOL
glxRequireVersion(int requiredVersion
)
3064 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3065 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3071 static BOOL
glxRequireExtension(const char *requiredExtension
)
3073 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3080 static void register_extension_string(const char *ext
)
3082 if (WineGLInfo
.wglExtensions
[0])
3083 strcat(WineGLInfo
.wglExtensions
, " ");
3084 strcat(WineGLInfo
.wglExtensions
, ext
);
3086 TRACE("'%s'\n", ext
);
3089 static BOOL
register_extension(const WineGLExtension
* ext
)
3093 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3094 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3096 register_extension_string(ext
->extName
);
3098 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3099 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3104 static const WineGLExtension WGL_internal_functions
=
3108 { "wglDisable", X11DRV_wglDisable
},
3109 { "wglEnable", X11DRV_wglEnable
},
3110 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3111 { "wglIsEnabled", X11DRV_wglIsEnabled
},
3112 { "wglScissor", X11DRV_wglScissor
},
3113 { "wglViewport", X11DRV_wglViewport
},
3114 { "wglFinish", X11DRV_wglFinish
},
3115 { "wglFlush", X11DRV_wglFlush
},
3120 static const WineGLExtension WGL_ARB_extensions_string
=
3122 "WGL_ARB_extensions_string",
3124 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3128 static const WineGLExtension WGL_ARB_make_current_read
=
3130 "WGL_ARB_make_current_read",
3132 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3133 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3137 static const WineGLExtension WGL_ARB_multisample
=
3139 "WGL_ARB_multisample",
3142 static const WineGLExtension WGL_ARB_pbuffer
=
3146 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3147 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3148 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3149 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3150 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3151 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3155 static const WineGLExtension WGL_ARB_pixel_format
=
3157 "WGL_ARB_pixel_format",
3159 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3160 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3161 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3165 static const WineGLExtension WGL_ARB_render_texture
=
3167 "WGL_ARB_render_texture",
3169 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3170 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3174 static const WineGLExtension WGL_EXT_extensions_string
=
3176 "WGL_EXT_extensions_string",
3178 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3182 static const WineGLExtension WGL_EXT_swap_control
=
3184 "WGL_EXT_swap_control",
3186 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3187 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3191 static const WineGLExtension WGL_NV_vertex_array_range
=
3193 "WGL_NV_vertex_array_range",
3195 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3196 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3201 * X11DRV_WineGL_LoadExtensions
3203 static void X11DRV_WineGL_LoadExtensions(void)
3205 WineGLInfo
.wglExtensions
[0] = 0;
3207 /* Load Wine internal functions */
3208 register_extension(&WGL_internal_functions
);
3210 /* ARB Extensions */
3212 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3214 register_extension_string("WGL_ARB_pixel_format_float");
3215 register_extension_string("WGL_ATI_pixel_format_float");
3218 register_extension(&WGL_ARB_extensions_string
);
3220 if (glxRequireVersion(3))
3221 register_extension(&WGL_ARB_make_current_read
);
3223 if (glxRequireExtension("GLX_ARB_multisample"))
3224 register_extension(&WGL_ARB_multisample
);
3226 /* In general pbuffer functionality requires support in the X-server. The functionality is
3227 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3228 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3229 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3231 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3232 * without support in the X-server (which other Mesa based drivers require).
3234 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3235 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3236 * is available pbuffers must be available too. */
3237 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3238 register_extension(&WGL_ARB_pbuffer
);
3240 register_extension(&WGL_ARB_pixel_format
);
3242 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3243 if (glxRequireExtension("GLX_ATI_render_texture") ||
3244 glxRequireExtension("GLX_ARB_render_texture") ||
3245 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3247 register_extension(&WGL_ARB_render_texture
);
3249 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3250 if(glxRequireExtension("GLX_NV_float_buffer"))
3251 register_extension_string("WGL_NV_float_buffer");
3253 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3254 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3255 register_extension_string("WGL_NV_texture_rectangle");
3258 /* EXT Extensions */
3260 register_extension(&WGL_EXT_extensions_string
);
3262 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3263 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3264 register_extension(&WGL_EXT_swap_control
);
3266 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3267 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3268 register_extension(&WGL_NV_vertex_array_range
);
3272 static XID
create_glxpixmap(X11DRV_PDEVICE
*physDev
)
3276 XVisualInfo
template;
3281 /* Retrieve the visualid from our main visual which is the only visual we can use */
3282 template.visualid
= XVisualIDFromVisual(visual
);
3283 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
3285 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
3287 wine_tsx11_unlock();
3288 TRACE("return %lx\n", ret
);
3292 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3298 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3299 ret
= physDev
->drawable
; /* PBuffer */
3302 if(!physDev
->bitmap
->glxpixmap
)
3303 physDev
->bitmap
->glxpixmap
= create_glxpixmap(physDev
);
3304 ret
= physDev
->bitmap
->glxpixmap
;
3308 ret
= physDev
->drawable
;
3312 BOOL
destroy_glxpixmap(XID glxpixmap
)
3315 pglXDestroyGLXPixmap(gdi_display
, glxpixmap
);
3316 wine_tsx11_unlock();
3321 * X11DRV_SwapBuffers
3323 * Swap the buffers of this DC
3325 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3327 GLXDrawable drawable
;
3328 if (!has_opengl()) {
3329 ERR("No libGL on this box - disabling OpenGL support !\n");
3333 TRACE_(opengl
)("(%p)\n", physDev
);
3335 drawable
= get_glxdrawable(physDev
);
3337 pglXSwapBuffers(gdi_display
, drawable
);
3338 wine_tsx11_unlock();
3343 static long prev_time
, frames
;
3345 DWORD time
= GetTickCount();
3347 /* every 1.5 seconds */
3348 if (time
- prev_time
> 1500) {
3349 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
3358 /***********************************************************************
3359 * X11DRV_setup_opengl_visual
3361 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3362 * window (if it exists). If OpenGL isn't available, the visual is simply
3363 * set to the default visual for the display
3365 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3367 XVisualInfo
*visual
= NULL
;
3370 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3371 * D3D and some applications can make use of aux buffers.
3373 int visualProperties
[][11] = {
3374 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_AUX_BUFFERS
, 1, None
},
3375 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, None
},
3376 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, None
},
3377 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, None
},
3384 for (i
= 0; i
< sizeof(visualProperties
)/sizeof(visualProperties
[0]); ++i
) {
3385 visual
= pglXChooseVisual(display
, DefaultScreen(display
), visualProperties
[i
]);
3389 wine_tsx11_unlock();
3392 TRACE("Visual ID %lx Chosen\n", visual
->visualid
);
3394 WARN("No suitable visual found\n");
3399 #else /* no OpenGL includes */
3401 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3406 /***********************************************************************
3407 * ChoosePixelFormat (X11DRV.@)
3409 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3410 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3411 ERR("No OpenGL support compiled in.\n");
3416 /***********************************************************************
3417 * DescribePixelFormat (X11DRV.@)
3419 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3422 PIXELFORMATDESCRIPTOR
*ppfd
) {
3423 ERR("No OpenGL support compiled in.\n");
3428 /***********************************************************************
3429 * GetPixelFormat (X11DRV.@)
3431 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3432 ERR("No OpenGL support compiled in.\n");
3437 /***********************************************************************
3438 * SetPixelFormat (X11DRV.@)
3440 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3442 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3443 ERR("No OpenGL support compiled in.\n");
3448 /***********************************************************************
3449 * SwapBuffers (X11DRV.@)
3451 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3452 ERR_(opengl
)("No OpenGL support compiled in.\n");
3458 * X11DRV_wglCreateContext
3460 * For OpenGL32 wglCreateContext.
3462 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3463 ERR_(opengl
)("No OpenGL support compiled in.\n");
3468 * X11DRV_wglDeleteContext
3470 * For OpenGL32 wglDeleteContext.
3472 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3473 ERR_(opengl
)("No OpenGL support compiled in.\n");
3478 * X11DRV_wglGetProcAddress
3480 * For OpenGL32 wglGetProcAddress.
3482 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3483 ERR_(opengl
)("No OpenGL support compiled in.\n");
3487 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3489 ERR_(opengl
)("No OpenGL support compiled in.\n");
3493 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3494 ERR_(opengl
)("No OpenGL support compiled in.\n");
3499 * X11DRV_wglMakeCurrent
3501 * For OpenGL32 wglMakeCurrent.
3503 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3504 ERR_(opengl
)("No OpenGL support compiled in.\n");
3509 * X11DRV_wglShareLists
3511 * For OpenGL32 wglShaderLists.
3513 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3514 ERR_(opengl
)("No OpenGL support compiled in.\n");
3519 * X11DRV_wglUseFontBitmapsA
3521 * For OpenGL32 wglUseFontBitmapsA.
3523 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3525 ERR_(opengl
)("No OpenGL support compiled in.\n");
3530 * X11DRV_wglUseFontBitmapsW
3532 * For OpenGL32 wglUseFontBitmapsW.
3534 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3536 ERR_(opengl
)("No OpenGL support compiled in.\n");
3540 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3545 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3550 BOOL
destroy_glxpixmap(XID glxpixmap
)
3555 #endif /* defined(HAVE_OPENGL) */