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;
153 static void X11DRV_WineGL_LoadExtensions(void);
154 static BOOL
glxRequireVersion(int requiredVersion
);
155 static BOOL
glxRequireExtension(const char *requiredExtension
);
157 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
158 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
159 TRACE(" - dwFlags : ");
160 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
161 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
162 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
163 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
164 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
165 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
166 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
173 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
174 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
175 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
176 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
177 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
178 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
179 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
183 TRACE(" - iPixelType : ");
184 switch (ppfd
->iPixelType
) {
185 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
186 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
190 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
191 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
192 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
193 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
194 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
195 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
196 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
197 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
198 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
200 TRACE(" - iLayerType : ");
201 switch (ppfd
->iLayerType
) {
202 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
203 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
204 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
209 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
210 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
212 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
214 MAKE_FUNCPTR(glXChooseVisual
)
215 MAKE_FUNCPTR(glXCreateContext
)
216 MAKE_FUNCPTR(glXCreateGLXPixmap
)
217 MAKE_FUNCPTR(glXGetCurrentContext
)
218 MAKE_FUNCPTR(glXGetCurrentDrawable
)
219 MAKE_FUNCPTR(glXDestroyContext
)
220 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
221 MAKE_FUNCPTR(glXGetConfig
)
222 MAKE_FUNCPTR(glXIsDirect
)
223 MAKE_FUNCPTR(glXMakeCurrent
)
224 MAKE_FUNCPTR(glXSwapBuffers
)
225 MAKE_FUNCPTR(glXQueryExtension
)
226 MAKE_FUNCPTR(glXQueryVersion
)
227 MAKE_FUNCPTR(glXUseXFont
)
230 MAKE_FUNCPTR(glXGetClientString
)
231 MAKE_FUNCPTR(glXQueryExtensionsString
)
232 MAKE_FUNCPTR(glXQueryServerString
)
235 MAKE_FUNCPTR(glXGetFBConfigs
)
236 MAKE_FUNCPTR(glXChooseFBConfig
)
237 MAKE_FUNCPTR(glXCreatePbuffer
)
238 MAKE_FUNCPTR(glXCreateNewContext
)
239 MAKE_FUNCPTR(glXDestroyPbuffer
)
240 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
241 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
242 MAKE_FUNCPTR(glXMakeContextCurrent
)
243 MAKE_FUNCPTR(glXQueryDrawable
)
244 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
247 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
248 static int (*pglXSwapIntervalSGI
)(int);
250 /* ATI GLX Extensions */
251 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
252 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
253 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
255 /* NV GLX Extension */
256 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
257 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
259 /* Standard OpenGL */
260 MAKE_FUNCPTR(glBindTexture
)
261 MAKE_FUNCPTR(glBitmap
)
262 MAKE_FUNCPTR(glCopyTexSubImage1D
)
263 MAKE_FUNCPTR(glCopyTexImage2D
)
264 MAKE_FUNCPTR(glCopyTexSubImage2D
)
265 MAKE_FUNCPTR(glDisable
)
266 MAKE_FUNCPTR(glDrawBuffer
)
267 MAKE_FUNCPTR(glEnable
)
268 MAKE_FUNCPTR(glEndList
)
269 MAKE_FUNCPTR(glGetError
)
270 MAKE_FUNCPTR(glGetIntegerv
)
271 MAKE_FUNCPTR(glGetString
)
272 MAKE_FUNCPTR(glIsEnabled
)
273 MAKE_FUNCPTR(glNewList
)
274 MAKE_FUNCPTR(glPixelStorei
)
275 MAKE_FUNCPTR(glReadPixels
)
276 MAKE_FUNCPTR(glScissor
)
277 MAKE_FUNCPTR(glTexImage2D
)
278 MAKE_FUNCPTR(glViewport
)
281 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
283 static BOOL infoInitialized
= FALSE
;
285 int screen
= DefaultScreen(gdi_display
);
286 Window win
= RootWindow(gdi_display
, screen
);
288 XVisualInfo
template;
291 GLXContext ctx
= NULL
;
295 infoInitialized
= TRUE
;
299 visual
= DefaultVisual(gdi_display
, screen
);
300 template.visualid
= XVisualIDFromVisual(visual
);
301 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
303 WORD old_fs
= wine_get_fs();
304 /* Create a GLX Context. Without one we can't query GL information */
305 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
306 if (wine_get_fs() != old_fs
)
308 wine_set_fs( old_fs
);
310 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
311 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
317 pglXMakeCurrent(gdi_display
, win
, ctx
);
319 ERR(" couldn't initialize OpenGL, expect problems\n");
324 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
325 WineGLInfo
.glExtensions
= strdup((const char *) pglGetString(GL_EXTENSIONS
));
327 /* Get the common GLX version supported by GLX client and server ( major/minor) */
328 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
330 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
331 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
332 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
334 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
335 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
336 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
338 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
339 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
341 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
342 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
343 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
344 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
345 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
346 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
347 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
348 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
352 pglXMakeCurrent(gdi_display
, None
, NULL
);
353 pglXDestroyContext(gdi_display
, ctx
);
359 static BOOL
has_opengl(void)
361 static int init_done
;
362 static void *opengl_handle
;
364 int error_base
, event_base
;
366 if (init_done
) return (opengl_handle
!= NULL
);
369 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
370 and include all dependencies */
371 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0);
372 if (opengl_handle
== NULL
) return FALSE
;
374 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
375 if (pglXGetProcAddressARB
== NULL
) {
376 ERR("could not find glXGetProcAddressARB in libGL.\n");
380 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
382 LOAD_FUNCPTR(glXChooseVisual
)
383 LOAD_FUNCPTR(glXCreateContext
)
384 LOAD_FUNCPTR(glXCreateGLXPixmap
)
385 LOAD_FUNCPTR(glXGetCurrentContext
)
386 LOAD_FUNCPTR(glXGetCurrentDrawable
)
387 LOAD_FUNCPTR(glXDestroyContext
)
388 LOAD_FUNCPTR(glXDestroyGLXPixmap
)
389 LOAD_FUNCPTR(glXGetConfig
)
390 LOAD_FUNCPTR(glXIsDirect
)
391 LOAD_FUNCPTR(glXMakeCurrent
)
392 LOAD_FUNCPTR(glXSwapBuffers
)
393 LOAD_FUNCPTR(glXQueryExtension
)
394 LOAD_FUNCPTR(glXQueryVersion
)
395 LOAD_FUNCPTR(glXUseXFont
)
398 LOAD_FUNCPTR(glXGetClientString
)
399 LOAD_FUNCPTR(glXQueryExtensionsString
)
400 LOAD_FUNCPTR(glXQueryServerString
)
403 LOAD_FUNCPTR(glXCreatePbuffer
)
404 LOAD_FUNCPTR(glXCreateNewContext
)
405 LOAD_FUNCPTR(glXDestroyPbuffer
)
406 LOAD_FUNCPTR(glXMakeContextCurrent
)
407 LOAD_FUNCPTR(glXGetCurrentReadDrawable
)
408 LOAD_FUNCPTR(glXGetFBConfigs
)
410 /* Standard OpenGL calls */
411 LOAD_FUNCPTR(glBindTexture
)
412 LOAD_FUNCPTR(glBitmap
)
413 LOAD_FUNCPTR(glCopyTexSubImage1D
)
414 LOAD_FUNCPTR(glCopyTexImage2D
)
415 LOAD_FUNCPTR(glCopyTexSubImage2D
)
416 LOAD_FUNCPTR(glDisable
)
417 LOAD_FUNCPTR(glDrawBuffer
)
418 LOAD_FUNCPTR(glEnable
)
419 LOAD_FUNCPTR(glEndList
)
420 LOAD_FUNCPTR(glGetError
)
421 LOAD_FUNCPTR(glGetIntegerv
)
422 LOAD_FUNCPTR(glGetString
)
423 LOAD_FUNCPTR(glIsEnabled
)
424 LOAD_FUNCPTR(glNewList
)
425 LOAD_FUNCPTR(glPixelStorei
)
426 LOAD_FUNCPTR(glReadPixels
)
427 LOAD_FUNCPTR(glScissor
)
428 LOAD_FUNCPTR(glTexImage2D
)
429 LOAD_FUNCPTR(glViewport
)
432 /* It doesn't matter if these fail. They'll only be used if the driver reports
433 the associated extension is available (and if a driver reports the extension
434 is available but fails to provide the functions, it's quite broken) */
435 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
436 /* NV GLX Extension */
437 LOAD_FUNCPTR(glXAllocateMemoryNV
)
438 LOAD_FUNCPTR(glXFreeMemoryNV
)
441 if(!X11DRV_WineGL_InitOpenglInfo()) {
442 wine_dlclose(opengl_handle
, NULL
, 0);
443 opengl_handle
= NULL
;
448 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
) == True
) {
449 TRACE("GLX is up and running error_base = %d\n", error_base
);
451 wine_dlclose(opengl_handle
, NULL
, 0);
452 opengl_handle
= NULL
;
455 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
456 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
459 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
460 * depends on the reported GLX client / server version and on the client / server extension list.
461 * Those don't have to be the same.
463 * In general the server GLX information lists the capabilities in case of indirect rendering.
464 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
465 * available and in that case the client GLX informat can be used.
466 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
467 * in the GLX version/extension list. When a program does this it works for certain for both
468 * direct and indirect rendering.
470 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
471 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
472 * extension list which causes this extension not to be listed. (Wine requires this extension).
473 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
474 * pbuffers is around.
476 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
477 * the ATI drivers and from then on use GLX client information for them.
480 if(glxRequireVersion(3)) {
481 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
482 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
483 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
484 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
485 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
486 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
487 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
488 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
490 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
491 * enable this function when the Xserver understand GLX 1.3 or newer
493 pglXQueryDrawable
= NULL
;
494 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
495 TRACE("Overriding ATI GLX capabilities!\n");
496 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
497 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
498 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
499 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
501 /* Use client GLX information in case of the ATI drivers. We override the
502 * capabilities over here and not somewhere else as ATI might better their
503 * life in the future. In case they release proper drivers this block of
504 * code won't be called. */
505 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
507 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
510 if(glxRequireExtension("GLX_ATI_render_texture")) {
511 use_render_texture_ati
= 1;
512 pglXBindTexImageATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
513 pglXReleaseTexImageATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
514 pglXDrawableAttribATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
517 X11DRV_WineGL_LoadExtensions();
520 return (opengl_handle
!= NULL
);
523 wine_dlclose(opengl_handle
, NULL
, 0);
524 opengl_handle
= NULL
;
528 static inline Wine_GLContext
*alloc_context(void)
532 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
534 ret
->next
= context_list
;
535 if (context_list
) context_list
->prev
= ret
;
541 static inline void free_context(Wine_GLContext
*context
)
543 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
544 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
545 else context_list
= context
->next
;
547 HeapFree(GetProcessHeap(), 0, context
);
550 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
553 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
554 return (ptr
!= NULL
);
557 static int describeContext(Wine_GLContext
* ctx
) {
560 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
561 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
562 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
563 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
564 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
569 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
572 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
575 if (pglXQueryDrawable
== NULL
) {
576 /** glXQueryDrawable not available so returns not supported */
580 TRACE(" Drawable %p have :\n", (void*) drawable
);
581 pglXQueryDrawable(gdi_display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
582 TRACE(" - WIDTH as %d\n", tmp
);
583 pglXQueryDrawable(gdi_display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
584 TRACE(" - HEIGHT as %d\n", tmp
);
585 pglXQueryDrawable(gdi_display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
586 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
589 fbCfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribList
, &nElements
);
590 if (fbCfgs
== NULL
) {
594 pglXGetFBConfigAttrib(gdi_display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
595 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
602 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
607 int nvfloatattrib
= GLX_DONT_CARE
;
610 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
611 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
612 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
613 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
615 switch (iWGLAttr
[cur
]) {
616 case WGL_COLOR_BITS_ARB
:
617 pop
= iWGLAttr
[++cur
];
618 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
619 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
621 case WGL_BLUE_BITS_ARB
:
622 pop
= iWGLAttr
[++cur
];
623 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
624 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
626 case WGL_RED_BITS_ARB
:
627 pop
= iWGLAttr
[++cur
];
628 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
629 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
631 case WGL_GREEN_BITS_ARB
:
632 pop
= iWGLAttr
[++cur
];
633 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
634 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
636 case WGL_ALPHA_BITS_ARB
:
637 pop
= iWGLAttr
[++cur
];
638 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
639 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
641 case WGL_DEPTH_BITS_ARB
:
642 pop
= iWGLAttr
[++cur
];
643 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
644 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
646 case WGL_STENCIL_BITS_ARB
:
647 pop
= iWGLAttr
[++cur
];
648 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
649 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
651 case WGL_DOUBLE_BUFFER_ARB
:
652 pop
= iWGLAttr
[++cur
];
653 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
654 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
657 case WGL_PIXEL_TYPE_ARB
:
658 pop
= iWGLAttr
[++cur
];
659 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
661 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
662 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
663 /* 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 */
664 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
666 ERR("unexpected PixelType(%x)\n", pop
);
671 case WGL_SUPPORT_GDI_ARB
:
672 pop
= iWGLAttr
[++cur
];
673 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
674 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
677 case WGL_DRAW_TO_BITMAP_ARB
:
678 pop
= iWGLAttr
[++cur
];
679 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
680 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
682 drawattrib
|= GLX_PIXMAP_BIT
;
686 case WGL_DRAW_TO_WINDOW_ARB
:
687 pop
= iWGLAttr
[++cur
];
688 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
689 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
691 drawattrib
|= GLX_WINDOW_BIT
;
695 case WGL_DRAW_TO_PBUFFER_ARB
:
696 pop
= iWGLAttr
[++cur
];
697 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
698 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
700 drawattrib
|= GLX_PBUFFER_BIT
;
704 case WGL_ACCELERATION_ARB
:
705 case WGL_SUPPORT_OPENGL_ARB
:
706 pop
= iWGLAttr
[++cur
];
707 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
708 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
711 case WGL_PBUFFER_LARGEST_ARB
:
712 pop
= iWGLAttr
[++cur
];
713 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
714 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
717 case WGL_SAMPLE_BUFFERS_ARB
:
718 pop
= iWGLAttr
[++cur
];
719 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
720 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
723 case WGL_SAMPLES_ARB
:
724 pop
= iWGLAttr
[++cur
];
725 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
726 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
729 case WGL_TEXTURE_FORMAT_ARB
:
730 case WGL_TEXTURE_TARGET_ARB
:
731 case WGL_MIPMAP_TEXTURE_ARB
:
732 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
733 pop
= iWGLAttr
[++cur
];
735 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
737 if (use_render_texture_ati
) {
738 /** nothing to do here */
740 else if (!use_render_texture_emulation
) {
741 if (WGL_NO_TEXTURE_ARB
!= pop
) {
742 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
743 return -1; /** error: don't support it */
745 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
746 drawattrib
|= GLX_PBUFFER_BIT
;
750 case WGL_FLOAT_COMPONENTS_NV
:
751 nvfloatattrib
= iWGLAttr
[++cur
];
752 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
754 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
755 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
756 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
757 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
758 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
759 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
760 pop
= iWGLAttr
[++cur
];
761 /** cannot be converted, see direct handling on
762 * - wglGetPixelFormatAttribivARB
763 * TODO: wglChoosePixelFormat
768 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
774 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
775 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
776 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
777 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
779 /* Set GLX_RENDER_TYPE all the time */
780 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
781 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
783 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
784 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
785 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
786 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
792 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
794 int render_type
=0, render_type_bit
;
795 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
796 switch(render_type_bit
)
799 render_type
= GLX_RGBA_TYPE
;
801 case GLX_COLOR_INDEX_BIT
:
802 render_type
= GLX_COLOR_INDEX_TYPE
;
804 case GLX_RGBA_FLOAT_BIT
:
805 render_type
= GLX_RGBA_FLOAT_TYPE
;
808 ERR("Unknown render_type: %x\n", render_type
);
813 static BOOL
init_formats(Display
*display
, int screen
, Visual
*visual
)
815 int fmt_id
, tmp_vis_id
, tmp_fmt_id
, nCfgs
, i
;
817 GLXFBConfig fbconfig
= NULL
;
818 VisualID visualid
= XVisualIDFromVisual(visual
);
819 int nOffscreenFormats
= 0;
821 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
822 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
823 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
824 * because this call lists both types of formats instead of only onscreen ones. */
825 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
826 if (NULL
== cfgs
|| 0 == nCfgs
) {
827 ERR("glXChooseFBConfig returns NULL\n");
828 if(cfgs
!= NULL
) XFree(cfgs
);
832 /* Count the number of offscreen formats to determine the size for our pixelformat list */
833 for(i
=0; i
<nCfgs
; i
++) {
834 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
836 /* We have found Wine's main visual */
837 if(tmp_vis_id
== visualid
) {
838 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
842 /* We have found an offscreen rendering format :) */
843 if(tmp_vis_id
== 0) {
847 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats
);
849 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
850 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (1+nOffscreenFormats
)*sizeof(WineGLPixelFormat
));
851 WineGLPixelFormatList
[0].iPixelFormat
= 1;
852 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
853 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
854 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
855 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
856 WineGLPixelFormatListSize
= 1;
858 /* Fill the list with offscreen formats */
859 for(i
=0; i
<nCfgs
; i
++) {
860 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
861 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
863 /* We have found an offscreen rendering format :) */
864 if(tmp_vis_id
== 0) {
865 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id
, WineGLPixelFormatListSize
+1, i
);
866 WineGLPixelFormatList
[WineGLPixelFormatListSize
].iPixelFormat
= WineGLPixelFormatListSize
+1; /* The index starts at 1 */
867 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fbconfig
= cfgs
[i
];
868 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fmt_id
= tmp_fmt_id
;
869 WineGLPixelFormatList
[WineGLPixelFormatListSize
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
870 WineGLPixelFormatList
[WineGLPixelFormatListSize
].offscreenOnly
= TRUE
;
871 WineGLPixelFormatListSize
++;
875 if(cfgs
!= NULL
) XFree(cfgs
);
880 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
881 * In our WGL implementation we only support a subset of these formats namely the format of
882 * Wine's main visual and offscreen formats (if they are available).
883 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
884 * and it returns the number of supported WGL formats in fmt_count.
886 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
888 WineGLPixelFormat
*res
= NULL
;
890 /* Init the list of pixel formats when we need it */
891 if(!WineGLPixelFormatListSize
)
892 init_formats(display
, DefaultScreen(display
), visual
);
894 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
895 * iPixelFormat in case of probing the number of pixelformats.
897 if((iPixelFormat
<= 0) || (iPixelFormat
> WineGLPixelFormatListSize
)) {
899 *fmt_count
= WineGLPixelFormatListSize
;
901 *fmt_count
= 1; /* Only show the format of our main visual */
903 else if(iPixelFormat
== 1) {
904 res
= &WineGLPixelFormatList
[0];
905 *fmt_count
= 1; /* Only show the format of our main visual */
907 else if((WineGLPixelFormatList
[iPixelFormat
-1].offscreenOnly
== TRUE
) && AllowOffscreen
) {
908 res
= &WineGLPixelFormatList
[iPixelFormat
-1];
909 *fmt_count
= WineGLPixelFormatListSize
;
910 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
913 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
918 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
919 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
)
923 /* Init the list of pixel formats when we need it */
924 if(!WineGLPixelFormatListSize
)
925 init_formats(display
, DefaultScreen(display
), visual
);
927 for(i
=0; i
<WineGLPixelFormatListSize
; i
++) {
928 if(WineGLPixelFormatList
[i
].fmt_id
== fmt_id
) {
929 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList
[i
].iPixelFormat
, fmt_id
);
930 return &WineGLPixelFormatList
[i
];
933 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
938 * X11DRV_ChoosePixelFormat
940 * Equivalent to glXChooseVisual.
942 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
943 const PIXELFORMATDESCRIPTOR
*ppfd
) {
944 WineGLPixelFormat
*fmt
= NULL
;
950 int bestDBuffer
= -1;
955 int bestStencil
= -1;
960 ERR("No libGL on this box - disabling OpenGL support !\n");
964 if (TRACE_ON(opengl
)) {
965 TRACE("(%p,%p)\n", physDev
, ppfd
);
967 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
971 ConvertPixelFormatWGLtoGLX(gdi_display
, 0, FALSE
/* offscreen */, &nPixelFormats
);
972 for(i
=0; i
<nPixelFormats
; i
++)
976 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
978 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, i
+1 /* 1-based index */, FALSE
/* offscreen */, &value
);
982 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
983 if (value
& GLX_RGBA_BIT
)
984 iPixelType
= PFD_TYPE_RGBA
;
986 iPixelType
= PFD_TYPE_COLORINDEX
;
988 if (ppfd
->iPixelType
!= iPixelType
)
990 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
994 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
995 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
996 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
997 if (value
) dwFlags
|= PFD_STEREO
;
998 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
999 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1000 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1001 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1002 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1004 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1005 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1006 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1007 * formats without the given flag set.
1008 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1009 * has indicated that a format without stereo is returned when stereo is unavailable.
1010 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1011 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1013 * To summarize the following is most likely the correct behavior:
1014 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1015 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1016 * stereo don't care -> it doesn't matter whether we get stereo or not
1018 * In Wine we will treat no-stereo the same way as don't care because it makes
1019 * format selection even more complicated and second drivers with Stereo advertise
1020 * each format twice anyway.
1023 /* Doublebuffer, see the comments above */
1024 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1025 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1026 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1028 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1029 bestStereo
= dwFlags
& PFD_STEREO
;
1033 bestStencil
= stencil
;
1040 /* Stereo, see the comments above. */
1041 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1042 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1043 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1045 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1046 bestStereo
= dwFlags
& PFD_STEREO
;
1050 bestStencil
= stencil
;
1057 /* Below we will do a number of checks to select the 'best' pixelformat.
1058 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1059 * The code works by trying to match the most important options as close as possible.
1060 * When a reasonable format is found, we will try to match more options. */
1063 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1064 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1066 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1067 bestStereo
= dwFlags
& PFD_STEREO
;
1071 bestStencil
= stencil
;
1075 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1076 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1081 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1082 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1084 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1085 bestStereo
= dwFlags
& PFD_STEREO
;
1089 bestStencil
= stencil
;
1093 } else if(bestAlpha
!= alpha
) {
1094 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1099 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1100 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1102 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1103 bestStereo
= dwFlags
& PFD_STEREO
;
1107 bestStencil
= stencil
;
1111 } else if(bestDepth
!= depth
) {
1112 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1117 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1118 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1120 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1121 bestStereo
= dwFlags
& PFD_STEREO
;
1125 bestStencil
= stencil
;
1129 } else if(bestStencil
!= stencil
) {
1130 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1135 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1136 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1138 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1139 bestStereo
= dwFlags
& PFD_STEREO
;
1143 bestStencil
= stencil
;
1147 } else if(bestAux
!= aux
) {
1148 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1153 if(bestFormat
== -1) {
1154 TRACE("No matching mode was found returning 0\n");
1158 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1159 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, WineGLPixelFormatList
[bestFormat
].fmt_id
);
1162 wine_tsx11_unlock();
1167 * X11DRV_DescribePixelFormat
1169 * Get the pixel-format descriptor associated to the given id
1171 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1174 PIXELFORMATDESCRIPTOR
*ppfd
) {
1175 /*XVisualInfo *vis;*/
1178 WineGLPixelFormat
*fmt
;
1182 if (!has_opengl()) {
1183 ERR("No libGL on this box - disabling OpenGL support !\n");
1187 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1189 /* 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 */
1190 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1192 /* The application is only querying the number of pixelformats */
1194 } else if(fmt
== NULL
) {
1195 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1199 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1200 ERR("Wrong structure size !\n");
1201 /* Should set error */
1207 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1208 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1211 /* These flags are always the same... */
1212 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1213 /* Now the flags extracted from the Visual */
1217 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_X_RENDERABLE
, &value
);
1219 ppfd
->dwFlags
|= PFD_SUPPORT_GDI
;
1221 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1222 if(value
& GLX_WINDOW_BIT
)
1223 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1224 if(value
& GLX_PIXMAP_BIT
)
1225 ppfd
->dwFlags
|= PFD_DRAW_TO_BITMAP
;
1227 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_CONFIG_CAVEAT
, &value
);
1228 if(value
== GLX_SLOW_CONFIG
)
1229 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1231 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1233 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1234 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1236 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1239 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1240 if (value
& GLX_RGBA_BIT
)
1241 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1243 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1246 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1247 ppfd
->cColorBits
= value
;
1249 /* Red, green, blue and alpha bits / shifts */
1250 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1251 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1252 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1253 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1254 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1256 ppfd
->cRedBits
= rb
;
1257 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1258 ppfd
->cBlueBits
= bb
;
1259 ppfd
->cBlueShift
= ab
;
1260 ppfd
->cGreenBits
= gb
;
1261 ppfd
->cGreenShift
= bb
+ ab
;
1262 ppfd
->cAlphaBits
= ab
;
1263 ppfd
->cAlphaShift
= 0;
1266 ppfd
->cRedShift
= 0;
1267 ppfd
->cBlueBits
= 0;
1268 ppfd
->cBlueShift
= 0;
1269 ppfd
->cGreenBits
= 0;
1270 ppfd
->cGreenShift
= 0;
1271 ppfd
->cAlphaBits
= 0;
1272 ppfd
->cAlphaShift
= 0;
1275 /* Accum RGBA bits */
1276 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1277 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1278 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1279 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1281 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1282 ppfd
->cAccumRedBits
= rb
;
1283 ppfd
->cAccumGreenBits
= gb
;
1284 ppfd
->cAccumBlueBits
= bb
;
1285 ppfd
->cAccumAlphaBits
= ab
;
1288 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1289 ppfd
->cDepthBits
= value
;
1292 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1293 ppfd
->cStencilBits
= value
;
1295 wine_tsx11_unlock();
1297 /* Aux : to do ... */
1299 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1301 if (TRACE_ON(opengl
)) {
1302 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1309 * X11DRV_GetPixelFormat
1311 * Get the pixel-format id used by this DC
1313 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1314 WineGLPixelFormat
*fmt
;
1316 TRACE("(%p)\n", physDev
);
1318 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1321 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1322 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1325 else if(fmt
->offscreenOnly
)
1327 /* Offscreen formats can't be used with traditional WGL calls.
1328 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1329 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1333 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1334 return physDev
->current_pf
;
1338 * X11DRV_SetPixelFormat
1340 * Set the pixel-format id used by this DC
1342 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1344 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1345 WineGLPixelFormat
*fmt
;
1348 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1350 if (!has_opengl()) {
1351 ERR("No libGL on this box - disabling OpenGL support !\n");
1355 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1356 if(get_glxdrawable(physDev
) == root_window
)
1358 ERR("Invalid operation on root_window\n");
1362 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1363 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1365 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1369 physDev
->current_pf
= iPixelFormat
;
1371 if (TRACE_ON(opengl
)) {
1375 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1377 * in case of root window created HDCs we crash here :(
1379 Drawable drawable = get_drawable( physDev->hdc );
1380 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1381 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1382 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1383 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1384 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1385 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1386 TRACE(" - WIDTH as %d\n", tmp);
1387 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1388 TRACE(" - HEIGHT as %d\n", tmp);
1390 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1392 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1394 TRACE(" FBConfig have :\n");
1395 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1396 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1397 TRACE(" - VISUAL_ID 0x%x\n", value
);
1398 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1399 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1406 * X11DRV_wglCreateContext
1408 * For OpenGL32 wglCreateContext.
1410 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1412 Wine_GLContext
*ret
;
1413 WineGLPixelFormat
*fmt
;
1414 int hdcPF
= physDev
->current_pf
;
1418 HDC hdc
= physDev
->hdc
;
1420 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1422 if (!has_opengl()) {
1423 ERR("No libGL on this box - disabling OpenGL support !\n");
1427 /* First, get the visual in use by the X11DRV */
1428 if (!gdi_display
) return 0;
1430 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1431 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1432 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1433 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1434 * If this fails something is very wrong on the system. */
1436 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1437 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1441 if (fmt_count
< hdcPF
) {
1442 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, hdcPF
, fmt_count
);
1443 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1447 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1449 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1450 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1454 /* The context will be allocated in the wglMakeCurrent call */
1456 ret
= alloc_context();
1457 wine_tsx11_unlock();
1459 ret
->physDev
= physDev
;
1463 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1465 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1470 * X11DRV_wglDeleteContext
1472 * For OpenGL32 wglDeleteContext.
1474 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1476 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1479 TRACE("(%p)\n", hglrc
);
1481 if (!has_opengl()) {
1482 ERR("No libGL on this box - disabling OpenGL support !\n");
1487 /* A game (Half Life not to name it) deletes twice the same context,
1488 * so make sure it is valid first */
1489 if (is_valid_context( ctx
))
1491 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1496 WARN("Error deleting context !\n");
1497 SetLastError(ERROR_INVALID_HANDLE
);
1500 wine_tsx11_unlock();
1506 * X11DRV_wglGetCurrentReadDCARB
1508 * For OpenGL32 wglGetCurrentReadDCARB.
1510 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1513 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1514 X11DRV_PDEVICE
*physDev
= ctx
? ctx
->pReadDev
: NULL
;
1519 TRACE(" returning %p (GL drawable %lu)\n", ret
, physDev
? physDev
->drawable
: 0);
1524 * X11DRV_wglGetProcAddress
1526 * For OpenGL32 wglGetProcAddress.
1528 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1531 const WineGLExtension
*ext
;
1533 int padding
= 32 - strlen(lpszProc
);
1537 if (!has_opengl()) {
1538 ERR("No libGL on this box - disabling OpenGL support !\n");
1542 /* Check the table of WGL extensions to see if we need to return a WGL extension
1543 * or a function pointer to a native OpenGL function. */
1544 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1545 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1547 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1548 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1549 ext
= WineGLExtensionList
[i
];
1550 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1551 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1552 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1553 return ext
->extEntryPoints
[j
].funcAddress
;
1559 ERR("(%s) - not found\n", lpszProc
);
1563 /***********************************************************************
1564 * sync_current_drawable
1566 * Adjust the current viewport and scissor in order to position
1567 * and size the current drawable correctly on the parent window.
1569 static void sync_current_drawable(BOOL updatedc
)
1575 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1579 if (ctx
&& ctx
->physDev
)
1582 GetClipBox(ctx
->physDev
->hdc
, &rc
); /* Make sure physDev is up to date */
1584 dy
= ctx
->physDev
->drawable_rect
.bottom
- ctx
->physDev
->drawable_rect
.top
-
1585 ctx
->physDev
->dc_rect
.bottom
;
1586 width
= ctx
->physDev
->dc_rect
.right
- ctx
->physDev
->dc_rect
.left
;
1587 height
= ctx
->physDev
->dc_rect
.bottom
- ctx
->physDev
->dc_rect
.top
;
1591 pglViewport(ctx
->physDev
->dc_rect
.left
+ ctx
->viewport
.left
,
1592 dy
+ ctx
->viewport
.top
,
1593 ctx
->viewport
.right
? (ctx
->viewport
.right
- ctx
->viewport
.left
) : width
,
1594 ctx
->viewport
.bottom
? (ctx
->viewport
.bottom
- ctx
->viewport
.top
) : height
);
1596 pglEnable(GL_SCISSOR_TEST
);
1598 if (ctx
->scissor_enabled
)
1599 pglScissor(ctx
->physDev
->dc_rect
.left
+ min(width
, max(0, ctx
->scissor
.left
)),
1600 dy
+ min(height
, max(0, ctx
->scissor
.top
)),
1601 min(width
, max(0, ctx
->scissor
.right
- ctx
->scissor
.left
)),
1602 min(height
, max(0, ctx
->scissor
.bottom
- ctx
->scissor
.top
)));
1604 pglScissor(ctx
->physDev
->dc_rect
.left
, dy
, width
, height
);
1606 wine_tsx11_unlock();
1611 * X11DRV_wglMakeCurrent
1613 * For OpenGL32 wglMakeCurrent.
1615 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1617 HDC hdc
= physDev
->hdc
;
1618 DWORD type
= GetObjectType(hdc
);
1620 TRACE("(%p,%p)\n", hdc
, hglrc
);
1622 if (!has_opengl()) {
1623 ERR("No libGL on this box - disabling OpenGL support !\n");
1628 if (hglrc
== NULL
) {
1629 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1630 NtCurrentTeb()->glContext
= NULL
;
1632 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1633 Drawable drawable
= get_glxdrawable(physDev
);
1634 if (ctx
->ctx
== NULL
) {
1635 /* The describe lines below are for debugging purposes only */
1636 if (TRACE_ON(wgl
)) {
1637 describeDrawable(ctx
, drawable
);
1638 describeContext(ctx
);
1641 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1642 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1644 TRACE(" Creating GLX Context\n");
1646 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1647 else /* Create a GLX Context for a pbuffer */
1648 ctx
->ctx
= pglXCreateNewContext(gdi_display
, ctx
->fmt
->fbconfig
, ctx
->fmt
->render_type
, NULL
, True
);
1650 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1652 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1653 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1654 NtCurrentTeb()->glContext
= ctx
;
1658 ctx
->physDev
= physDev
;
1659 ctx
->pReadDev
= physDev
;
1661 if (type
== OBJ_MEMDC
)
1663 ctx
->do_escape
= TRUE
;
1664 pglDrawBuffer(GL_FRONT_LEFT
);
1668 sync_current_drawable(FALSE
);
1672 wine_tsx11_unlock();
1673 TRACE(" returning %s\n", (ret
? "True" : "False"));
1678 * X11DRV_wglMakeContextCurrentARB
1680 * For OpenGL32 wglMakeContextCurrentARB
1682 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1685 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1687 if (!has_opengl()) {
1688 ERR("No libGL on this box - disabling OpenGL support !\n");
1693 if (hglrc
== NULL
) {
1694 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1695 NtCurrentTeb()->glContext
= NULL
;
1697 if (NULL
== pglXMakeContextCurrent
) {
1700 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1701 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1702 Drawable d_read
= get_glxdrawable(pReadDev
);
1704 if (ctx
->ctx
== NULL
) {
1705 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, GetObjectType(pDrawDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1706 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1708 ctx
->hdc
= pDrawDev
->hdc
;
1709 ctx
->physDev
= pDrawDev
;
1710 ctx
->pReadDev
= pReadDev
;
1711 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1712 NtCurrentTeb()->glContext
= ctx
;
1715 wine_tsx11_unlock();
1717 TRACE(" returning %s\n", (ret
? "True" : "False"));
1722 * X11DRV_wglShareLists
1724 * For OpenGL32 wglShaderLists.
1726 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1727 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1728 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1730 TRACE("(%p, %p)\n", org
, dest
);
1732 if (!has_opengl()) {
1733 ERR("No libGL on this box - disabling OpenGL support !\n");
1737 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1738 ERR("Could not share display lists, context already created !\n");
1741 if (org
->ctx
== NULL
) {
1743 describeContext(org
);
1746 org
->ctx
= pglXCreateContext(gdi_display
, org
->vis
, NULL
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1747 else /* Create a GLX Context for a pbuffer */
1748 org
->ctx
= pglXCreateNewContext(gdi_display
, org
->fmt
->fbconfig
, org
->fmt
->render_type
, NULL
, True
);
1749 wine_tsx11_unlock();
1750 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1754 describeContext(dest
);
1755 /* Create the destination context with display lists shared */
1757 dest
->ctx
= pglXCreateContext(gdi_display
, dest
->vis
, org
->ctx
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1758 else /* Create a GLX Context for a pbuffer */
1759 dest
->ctx
= pglXCreateNewContext(gdi_display
, dest
->fmt
->fbconfig
, dest
->fmt
->render_type
, org
->ctx
, True
);
1760 wine_tsx11_unlock();
1761 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1768 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1770 /* We are running using client-side rendering fonts... */
1774 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1778 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1779 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1780 wine_tsx11_unlock();
1782 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1783 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1784 int height
, width_int
;
1786 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1787 if (needed_size
== GDI_ERROR
) {
1788 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1791 TRACE(" - needed size : %d\n", needed_size
);
1794 if (needed_size
> size
) {
1796 HeapFree(GetProcessHeap(), 0, bitmap
);
1797 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1798 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1799 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1801 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1802 if (TRACE_ON(opengl
)) {
1803 unsigned int height
, width
, bitmask
;
1804 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1806 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1807 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1808 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1809 if (needed_size
!= 0) {
1810 TRACE(" - bitmap :\n");
1811 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1813 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1818 if (*bitmap_
& bitmask
)
1823 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1829 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1830 * glyph for it to be drawn properly.
1832 if (needed_size
!= 0) {
1833 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1834 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1836 for (width
= 0; width
< width_int
; width
++) {
1837 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1838 ((int *) bitmap
)[height
* width_int
+ width
];
1844 pglNewList(listBase
++, GL_COMPILE
);
1845 if (needed_size
!= 0) {
1846 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1847 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1848 gm
.gmCellIncX
, gm
.gmCellIncY
,
1851 /* This is the case of 'empty' glyphs like the space character */
1852 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1855 wine_tsx11_unlock();
1859 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1860 wine_tsx11_unlock();
1862 HeapFree(GetProcessHeap(), 0, bitmap
);
1863 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1868 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1869 wine_tsx11_unlock();
1871 HeapFree(GetProcessHeap(), 0, bitmap
);
1872 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1877 * X11DRV_wglUseFontBitmapsA
1879 * For OpenGL32 wglUseFontBitmapsA.
1881 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1883 Font fid
= physDev
->font
;
1885 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1887 if (!has_opengl()) {
1888 ERR("No libGL on this box - disabling OpenGL support !\n");
1893 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
1897 /* I assume that the glyphs are at the same position for X and for Windows */
1898 pglXUseXFont(fid
, first
, count
, listBase
);
1899 wine_tsx11_unlock();
1904 * X11DRV_wglUseFontBitmapsW
1906 * For OpenGL32 wglUseFontBitmapsW.
1908 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1910 Font fid
= physDev
->font
;
1912 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1914 if (!has_opengl()) {
1915 ERR("No libGL on this box - disabling OpenGL support !\n");
1920 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1923 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1926 /* I assume that the glyphs are at the same position for X and for Windows */
1927 pglXUseXFont(fid
, first
, count
, listBase
);
1928 wine_tsx11_unlock();
1932 static void WINAPI
X11DRV_wglDisable(GLenum cap
)
1934 if (cap
== GL_SCISSOR_TEST
)
1936 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1939 ctx
->scissor_enabled
= FALSE
;
1945 wine_tsx11_unlock();
1949 static void WINAPI
X11DRV_wglEnable(GLenum cap
)
1951 if (cap
== GL_SCISSOR_TEST
)
1953 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1956 ctx
->scissor_enabled
= TRUE
;
1962 wine_tsx11_unlock();
1966 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1967 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
1974 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1976 pglGetIntegerv(pname
, params
);
1978 * if we cannot find a Wine Context
1979 * we only have the default wine desktop context,
1980 * so if we have only a 24 depth say we have 32
1982 if (!ctx
&& *params
== 24) {
1985 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
1990 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1992 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
1993 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
1997 pglGetIntegerv(pname
, params
);
2000 wine_tsx11_unlock();
2003 static GLboolean WINAPI
X11DRV_wglIsEnabled(GLenum cap
)
2005 GLboolean enabled
= False
;
2007 if (cap
== GL_SCISSOR_TEST
)
2009 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2012 enabled
= ctx
->scissor_enabled
;
2017 enabled
= pglIsEnabled(cap
);
2018 wine_tsx11_unlock();
2023 static void WINAPI
X11DRV_wglScissor(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2025 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2029 ctx
->scissor
.left
= x
;
2030 ctx
->scissor
.top
= y
;
2031 ctx
->scissor
.right
= x
+ width
;
2032 ctx
->scissor
.bottom
= y
+ height
;
2034 sync_current_drawable(TRUE
);
2038 static void WINAPI
X11DRV_wglViewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2040 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2044 ctx
->viewport
.left
= x
;
2045 ctx
->viewport
.top
= y
;
2046 ctx
->viewport
.right
= x
+ width
;
2047 ctx
->viewport
.bottom
= y
+ height
;
2049 sync_current_drawable(TRUE
);
2054 * X11DRV_wglGetExtensionsStringARB
2056 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2058 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2059 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2060 return WineGLInfo
.wglExtensions
;
2064 * X11DRV_wglCreatePbufferARB
2066 * WGL_ARB_pbuffer: wglCreatePbufferARB
2068 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2070 Wine_GLPBuffer
* object
= NULL
;
2071 WineGLPixelFormat
*fmt
= NULL
;
2076 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2078 if (0 >= iPixelFormat
) {
2079 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2080 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2081 return NULL
; /* unexpected error */
2084 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2085 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2087 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2088 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2089 goto create_failed
; /* unexpected error */
2092 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2093 if (NULL
== object
) {
2094 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2095 goto create_failed
; /* unexpected error */
2098 object
->display
= gdi_display
;
2099 object
->width
= iWidth
;
2100 object
->height
= iHeight
;
2103 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2104 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2105 while (piAttribList
&& 0 != *piAttribList
) {
2107 switch (*piAttribList
) {
2108 case WGL_PBUFFER_LARGEST_ARB
: {
2110 attr_v
= *piAttribList
;
2111 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2112 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2116 case WGL_TEXTURE_FORMAT_ARB
: {
2118 attr_v
= *piAttribList
;
2119 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2120 if (use_render_texture_ati
) {
2123 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2124 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2125 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2127 SetLastError(ERROR_INVALID_DATA
);
2130 object
->use_render_texture
= 1;
2131 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2133 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2134 object
->use_render_texture
= 0;
2136 if (!use_render_texture_emulation
) {
2137 SetLastError(ERROR_INVALID_DATA
);
2141 case WGL_TEXTURE_RGB_ARB
:
2142 object
->use_render_texture
= GL_RGB
;
2143 object
->texture_bpp
= 3;
2144 object
->texture_format
= GL_RGB
;
2145 object
->texture_type
= GL_UNSIGNED_BYTE
;
2147 case WGL_TEXTURE_RGBA_ARB
:
2148 object
->use_render_texture
= GL_RGBA
;
2149 object
->texture_bpp
= 4;
2150 object
->texture_format
= GL_RGBA
;
2151 object
->texture_type
= GL_UNSIGNED_BYTE
;
2154 /* WGL_FLOAT_COMPONENTS_NV */
2155 case WGL_TEXTURE_FLOAT_R_NV
:
2156 object
->use_render_texture
= GL_FLOAT_R_NV
;
2157 object
->texture_bpp
= 4;
2158 object
->texture_format
= GL_RED
;
2159 object
->texture_type
= GL_FLOAT
;
2161 case WGL_TEXTURE_FLOAT_RG_NV
:
2162 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2163 object
->texture_bpp
= 8;
2164 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2165 object
->texture_type
= GL_FLOAT
;
2167 case WGL_TEXTURE_FLOAT_RGB_NV
:
2168 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2169 object
->texture_bpp
= 12;
2170 object
->texture_format
= GL_RGB
;
2171 object
->texture_type
= GL_FLOAT
;
2173 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2174 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2175 object
->texture_bpp
= 16;
2176 object
->texture_format
= GL_RGBA
;
2177 object
->texture_type
= GL_FLOAT
;
2180 ERR("Unknown texture format: %x\n", attr_v
);
2181 SetLastError(ERROR_INVALID_DATA
);
2189 case WGL_TEXTURE_TARGET_ARB
: {
2191 attr_v
= *piAttribList
;
2192 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2193 if (use_render_texture_ati
) {
2196 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2197 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2198 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2199 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2201 SetLastError(ERROR_INVALID_DATA
);
2204 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2206 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2207 object
->texture_target
= 0;
2209 if (!use_render_texture_emulation
) {
2210 SetLastError(ERROR_INVALID_DATA
);
2214 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2215 if (iWidth
!= iHeight
) {
2216 SetLastError(ERROR_INVALID_DATA
);
2219 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2220 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2223 case WGL_TEXTURE_1D_ARB
: {
2225 SetLastError(ERROR_INVALID_DATA
);
2228 object
->texture_target
= GL_TEXTURE_1D
;
2229 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2232 case WGL_TEXTURE_2D_ARB
: {
2233 object
->texture_target
= GL_TEXTURE_2D
;
2234 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2237 case WGL_TEXTURE_RECTANGLE_NV
: {
2238 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2239 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2243 ERR("Unknown texture target: %x\n", attr_v
);
2244 SetLastError(ERROR_INVALID_DATA
);
2252 case WGL_MIPMAP_TEXTURE_ARB
: {
2254 attr_v
= *piAttribList
;
2255 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2256 if (use_render_texture_ati
) {
2257 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2259 if (!use_render_texture_emulation
) {
2260 SetLastError(ERROR_INVALID_DATA
);
2270 PUSH1(attribs
, None
);
2271 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2272 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2273 if (!object
->drawable
) {
2274 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2275 goto create_failed
; /* unexpected error */
2277 TRACE("->(%p)\n", object
);
2278 return (HPBUFFERARB
) object
;
2281 HeapFree(GetProcessHeap(), 0, object
);
2282 TRACE("->(FAILED)\n");
2283 return (HPBUFFERARB
) NULL
;
2287 * X11DRV_wglDestroyPbufferARB
2289 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2291 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2293 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2294 TRACE("(%p)\n", hPbuffer
);
2295 if (NULL
== object
) {
2296 SetLastError(ERROR_INVALID_HANDLE
);
2299 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2300 HeapFree(GetProcessHeap(), 0, object
);
2305 * X11DRV_wglGetPbufferDCARB
2307 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2308 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2309 * Gdi32 implements the part of this function which creates a device context.
2310 * This part associates the physDev with the X drawable of the pbuffer.
2312 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2314 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2315 if (NULL
== object
) {
2316 SetLastError(ERROR_INVALID_HANDLE
);
2320 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2321 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2322 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2323 physDev
->drawable
= object
->drawable
;
2324 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2325 physDev
->dc_rect
= physDev
->drawable_rect
;
2327 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2328 return physDev
->hdc
;
2332 * X11DRV_wglQueryPbufferARB
2334 * WGL_ARB_pbuffer: wglQueryPbufferARB
2336 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2338 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2339 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2340 if (NULL
== object
) {
2341 SetLastError(ERROR_INVALID_HANDLE
);
2344 switch (iAttribute
) {
2345 case WGL_PBUFFER_WIDTH_ARB
:
2346 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2348 case WGL_PBUFFER_HEIGHT_ARB
:
2349 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2352 case WGL_PBUFFER_LOST_ARB
:
2353 /* GLX Pbuffers cannot be lost by default. We can support this by
2354 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2355 * to receive pixel buffer clobber events, however that may or may
2356 * not give any benefit */
2357 *piValue
= GL_FALSE
;
2360 case WGL_TEXTURE_FORMAT_ARB
:
2361 if (use_render_texture_ati
) {
2363 int type
= WGL_NO_TEXTURE_ARB
;
2364 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2366 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2367 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2368 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2372 if (!object
->use_render_texture
) {
2373 *piValue
= WGL_NO_TEXTURE_ARB
;
2375 if (!use_render_texture_emulation
) {
2376 SetLastError(ERROR_INVALID_HANDLE
);
2379 switch(object
->use_render_texture
) {
2381 *piValue
= WGL_TEXTURE_RGB_ARB
;
2384 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2386 /* WGL_FLOAT_COMPONENTS_NV */
2388 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2390 case GL_FLOAT_RG_NV
:
2391 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2393 case GL_FLOAT_RGB_NV
:
2394 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2396 case GL_FLOAT_RGBA_NV
:
2397 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2400 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2406 case WGL_TEXTURE_TARGET_ARB
:
2407 if (use_render_texture_ati
) {
2409 int type
= WGL_NO_TEXTURE_ARB
;
2410 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2412 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2413 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2414 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2415 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2419 if (!object
->texture_target
) {
2420 *piValue
= WGL_NO_TEXTURE_ARB
;
2422 if (!use_render_texture_emulation
) {
2423 SetLastError(ERROR_INVALID_DATA
);
2426 switch (object
->texture_target
) {
2427 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2428 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2429 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2430 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2436 case WGL_MIPMAP_TEXTURE_ARB
:
2437 if (use_render_texture_ati
) {
2438 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2440 *piValue
= GL_FALSE
; /** don't support that */
2441 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2446 FIXME("unexpected attribute %x\n", iAttribute
);
2454 * X11DRV_wglReleasePbufferDCARB
2456 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2458 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2460 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2466 * X11DRV_wglSetPbufferAttribARB
2468 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2470 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2472 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2473 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2474 if (NULL
== object
) {
2475 SetLastError(ERROR_INVALID_HANDLE
);
2478 if (!object
->use_render_texture
) {
2479 SetLastError(ERROR_INVALID_HANDLE
);
2482 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2485 if (NULL
!= pglXDrawableAttribATI
) {
2486 if (use_render_texture_ati
) {
2487 FIXME("Need conversion for GLX_ATI_render_texture\n");
2489 return pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2495 * X11DRV_wglChoosePixelFormatARB
2497 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2499 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2504 GLXFBConfig
* cfgs
= NULL
;
2508 WineGLPixelFormat
*fmt
;
2512 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2513 if (NULL
!= pfAttribFList
) {
2514 FIXME("unused pfAttribFList\n");
2517 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2518 if (-1 == nAttribs
) {
2519 WARN("Cannot convert WGL to GLX attributes\n");
2522 PUSH1(attribs
, None
);
2524 /* Search for FB configurations matching the requirements in attribs */
2525 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2527 WARN("Compatible Pixel Format not found\n");
2531 /* Loop through all matching formats and check if they are suitable.
2532 * Note that this function should at max return nMaxFormats different formats */
2533 for(run
=0; run
< 2; run
++)
2535 for (it
= 0; it
< nCfgs
; ++it
) {
2536 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2538 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2542 /* Search for the format in our list of compatible formats */
2543 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
);
2547 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2548 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2551 if(pfmt_it
< nMaxFormats
) {
2552 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2553 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2559 *nNumFormats
= pfmt_it
;
2566 * X11DRV_wglGetPixelFormatAttribivARB
2568 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2570 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2573 WineGLPixelFormat
*fmt
= NULL
;
2577 int nWGLFormats
= 0;
2579 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2581 if (0 < iLayerPlane
) {
2582 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2586 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2587 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2588 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2589 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2591 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2594 for (i
= 0; i
< nAttributes
; ++i
) {
2595 const int curWGLAttr
= piAttributes
[i
];
2596 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2598 switch (curWGLAttr
) {
2599 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2600 piValues
[i
] = nWGLFormats
;
2603 case WGL_SUPPORT_OPENGL_ARB
:
2604 piValues
[i
] = GL_TRUE
;
2607 case WGL_ACCELERATION_ARB
:
2608 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2609 if (!fmt
) goto pix_error
;
2610 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2611 if (hTest
) goto get_error
;
2613 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2614 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
; break;
2615 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2617 ERR("unexpected Config Caveat(%x)\n", tmp
);
2618 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2622 case WGL_TRANSPARENT_ARB
:
2623 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2624 if (!fmt
) goto pix_error
;
2625 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2626 if (hTest
) goto get_error
;
2627 piValues
[i
] = GL_FALSE
;
2628 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2631 case WGL_PIXEL_TYPE_ARB
:
2632 curGLXAttr
= GLX_RENDER_TYPE
;
2633 if (!fmt
) goto pix_error
;
2634 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2635 if (hTest
) goto get_error
;
2636 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2637 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2638 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2639 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2640 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2642 ERR("unexpected RenderType(%x)\n", tmp
);
2643 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2647 case WGL_COLOR_BITS_ARB
:
2648 curGLXAttr
= GLX_BUFFER_SIZE
;
2651 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2652 if (use_render_texture_ati
) {
2653 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2656 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2657 if (use_render_texture_ati
) {
2658 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2661 if (!use_render_texture_emulation
) {
2662 piValues
[i
] = GL_FALSE
;
2665 curGLXAttr
= GLX_RENDER_TYPE
;
2666 if (!fmt
) goto pix_error
;
2667 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2668 if (hTest
) goto get_error
;
2669 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2670 piValues
[i
] = GL_FALSE
;
2673 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2674 if (hTest
) goto get_error
;
2675 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2678 case WGL_BLUE_BITS_ARB
:
2679 curGLXAttr
= GLX_BLUE_SIZE
;
2681 case WGL_RED_BITS_ARB
:
2682 curGLXAttr
= GLX_RED_SIZE
;
2684 case WGL_GREEN_BITS_ARB
:
2685 curGLXAttr
= GLX_GREEN_SIZE
;
2687 case WGL_ALPHA_BITS_ARB
:
2688 curGLXAttr
= GLX_ALPHA_SIZE
;
2690 case WGL_DEPTH_BITS_ARB
:
2691 curGLXAttr
= GLX_DEPTH_SIZE
;
2693 case WGL_STENCIL_BITS_ARB
:
2694 curGLXAttr
= GLX_STENCIL_SIZE
;
2696 case WGL_DOUBLE_BUFFER_ARB
:
2697 curGLXAttr
= GLX_DOUBLEBUFFER
;
2699 case WGL_STEREO_ARB
:
2700 curGLXAttr
= GLX_STEREO
;
2702 case WGL_AUX_BUFFERS_ARB
:
2703 curGLXAttr
= GLX_AUX_BUFFERS
;
2706 case WGL_SUPPORT_GDI_ARB
:
2707 if (!fmt
) goto pix_error
;
2708 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &tmp
);
2709 if (hTest
) goto get_error
;
2711 piValues
[i
] = GL_FALSE
;
2714 curGLXAttr
= GLX_X_RENDERABLE
;
2717 case WGL_DRAW_TO_WINDOW_ARB
:
2718 case WGL_DRAW_TO_BITMAP_ARB
:
2719 case WGL_DRAW_TO_PBUFFER_ARB
:
2720 if (!fmt
) goto pix_error
;
2721 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2722 if (hTest
) goto get_error
;
2723 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2724 (curWGLAttr
== WGL_DRAW_TO_BITMAP_ARB
&& (tmp
&GLX_PIXMAP_BIT
)) ||
2725 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2726 piValues
[i
] = GL_TRUE
;
2728 piValues
[i
] = GL_FALSE
;
2731 case WGL_PBUFFER_LARGEST_ARB
:
2732 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2735 case WGL_SAMPLE_BUFFERS_ARB
:
2736 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2739 case WGL_SAMPLES_ARB
:
2740 curGLXAttr
= GLX_SAMPLES_ARB
;
2743 case WGL_FLOAT_COMPONENTS_NV
:
2744 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2747 case WGL_ACCUM_RED_BITS_ARB
:
2748 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2750 case WGL_ACCUM_GREEN_BITS_ARB
:
2751 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2753 case WGL_ACCUM_BLUE_BITS_ARB
:
2754 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2756 case WGL_ACCUM_ALPHA_BITS_ARB
:
2757 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2759 case WGL_ACCUM_BITS_ARB
:
2760 if (!fmt
) goto pix_error
;
2761 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2762 if (hTest
) goto get_error
;
2764 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2765 if (hTest
) goto get_error
;
2767 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2768 if (hTest
) goto get_error
;
2770 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2771 if (hTest
) goto get_error
;
2776 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2779 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2780 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2781 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2783 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2784 * and check which options can work using iPixelFormat=0 and which not.
2785 * A problem would be that this function is an extension. This would
2786 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2788 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2789 if (!fmt
) goto pix_error
;
2790 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2791 if (hTest
) goto get_error
;
2794 piValues
[i
] = GL_FALSE
;
2800 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2804 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2809 * X11DRV_wglGetPixelFormatAttribfvARB
2811 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2813 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2819 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2821 /* Allocate a temporary array to store integer values */
2822 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2824 ERR("couldn't allocate %d array\n", nAttributes
);
2828 /* Piggy-back on wglGetPixelFormatAttribivARB */
2829 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2831 /* Convert integer values to float. Should also check for attributes
2832 that can give decimal values here */
2833 for (i
=0; i
<nAttributes
;i
++) {
2834 pfValues
[i
] = attr
[i
];
2838 HeapFree(GetProcessHeap(), 0, attr
);
2843 * X11DRV_wglBindTexImageARB
2845 * WGL_ARB_render_texture: wglBindTexImageARB
2847 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2849 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2850 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2851 if (NULL
== object
) {
2852 SetLastError(ERROR_INVALID_HANDLE
);
2855 if (!object
->use_render_texture
) {
2856 SetLastError(ERROR_INVALID_HANDLE
);
2860 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2861 static int init
= 0;
2862 int prev_binded_texture
= 0;
2863 GLXContext prev_context
= pglXGetCurrentContext();
2864 Drawable prev_drawable
= pglXGetCurrentDrawable();
2865 GLXContext tmp_context
;
2867 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2868 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2869 isn't ideal performance wise but I wasn't able to get other ways working.
2872 init
= 1; /* Only show the FIXME once for performance reasons */
2873 FIXME("partial stub!\n");
2876 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
2877 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2879 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2881 /* Switch to our pbuffer */
2882 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2884 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2885 * After that upload the pbuffer texture data. */
2886 pglBindTexture(object
->texture_target
, prev_binded_texture
);
2887 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2889 /* Switch back to the original drawable and upload the pbuffer-texture */
2890 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
2891 pglXDestroyContext(gdi_display
, tmp_context
);
2895 if (NULL
!= pglXBindTexImageATI
) {
2900 case WGL_FRONT_LEFT_ARB
:
2901 buffer
= GLX_FRONT_LEFT_ATI
;
2903 case WGL_FRONT_RIGHT_ARB
:
2904 buffer
= GLX_FRONT_RIGHT_ATI
;
2906 case WGL_BACK_LEFT_ARB
:
2907 buffer
= GLX_BACK_LEFT_ATI
;
2909 case WGL_BACK_RIGHT_ARB
:
2910 buffer
= GLX_BACK_RIGHT_ATI
;
2913 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2917 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
2918 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
2919 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
2920 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
2921 * works fine using our pbuffer emulation path.
2923 return pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
2929 * X11DRV_wglReleaseTexImageARB
2931 * WGL_ARB_render_texture: wglReleaseTexImageARB
2933 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2935 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2936 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2937 if (NULL
== object
) {
2938 SetLastError(ERROR_INVALID_HANDLE
);
2941 if (!object
->use_render_texture
) {
2942 SetLastError(ERROR_INVALID_HANDLE
);
2945 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2948 if (NULL
!= pglXReleaseTexImageATI
) {
2953 case WGL_FRONT_LEFT_ARB
:
2954 buffer
= GLX_FRONT_LEFT_ATI
;
2956 case WGL_FRONT_RIGHT_ARB
:
2957 buffer
= GLX_FRONT_RIGHT_ATI
;
2959 case WGL_BACK_LEFT_ARB
:
2960 buffer
= GLX_BACK_LEFT_ATI
;
2962 case WGL_BACK_RIGHT_ARB
:
2963 buffer
= GLX_BACK_RIGHT_ATI
;
2966 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2969 return pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
2975 * X11DRV_wglGetExtensionsStringEXT
2977 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2979 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
2980 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2981 return WineGLInfo
.wglExtensions
;
2985 * X11DRV_wglGetSwapIntervalEXT
2987 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2989 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
2990 FIXME("(),stub!\n");
2991 return swap_interval
;
2995 * X11DRV_wglSwapIntervalEXT
2997 * WGL_EXT_swap_control: wglSwapIntervalEXT
2999 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3000 TRACE("(%d)\n", interval
);
3001 swap_interval
= interval
;
3002 if (NULL
!= pglXSwapIntervalSGI
) {
3003 return 0 == pglXSwapIntervalSGI(interval
);
3005 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3010 * X11DRV_wglAllocateMemoryNV
3012 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3014 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3015 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3016 if (pglXAllocateMemoryNV
== NULL
)
3019 return pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3023 * X11DRV_wglFreeMemoryNV
3025 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3027 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3028 TRACE("(%p)\n", pointer
);
3029 if (pglXFreeMemoryNV
== NULL
)
3032 pglXFreeMemoryNV(pointer
);
3036 * glxRequireVersion (internal)
3038 * Check if the supported GLX version matches requiredVersion.
3040 static BOOL
glxRequireVersion(int requiredVersion
)
3042 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3043 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3049 static BOOL
glxRequireExtension(const char *requiredExtension
)
3051 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3058 static void register_extension_string(const char *ext
)
3060 if (WineGLInfo
.wglExtensions
[0])
3061 strcat(WineGLInfo
.wglExtensions
, " ");
3062 strcat(WineGLInfo
.wglExtensions
, ext
);
3064 TRACE("'%s'\n", ext
);
3067 static BOOL
register_extension(const WineGLExtension
* ext
)
3071 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3072 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3074 register_extension_string(ext
->extName
);
3076 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3077 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3082 static const WineGLExtension WGL_internal_functions
=
3086 { "wglDisable", X11DRV_wglDisable
},
3087 { "wglEnable", X11DRV_wglEnable
},
3088 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3089 { "wglIsEnabled", X11DRV_wglIsEnabled
},
3090 { "wglScissor", X11DRV_wglScissor
},
3091 { "wglViewport", X11DRV_wglViewport
},
3096 static const WineGLExtension WGL_ARB_extensions_string
=
3098 "WGL_ARB_extensions_string",
3100 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3104 static const WineGLExtension WGL_ARB_make_current_read
=
3106 "WGL_ARB_make_current_read",
3108 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3109 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3113 static const WineGLExtension WGL_ARB_multisample
=
3115 "WGL_ARB_multisample",
3118 static const WineGLExtension WGL_ARB_pbuffer
=
3122 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3123 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3124 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3125 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3126 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3127 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3131 static const WineGLExtension WGL_ARB_pixel_format
=
3133 "WGL_ARB_pixel_format",
3135 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3136 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3137 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3141 static const WineGLExtension WGL_ARB_render_texture
=
3143 "WGL_ARB_render_texture",
3145 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3146 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3150 static const WineGLExtension WGL_EXT_extensions_string
=
3152 "WGL_EXT_extensions_string",
3154 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3158 static const WineGLExtension WGL_EXT_swap_control
=
3160 "WGL_EXT_swap_control",
3162 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3163 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3167 static const WineGLExtension WGL_NV_vertex_array_range
=
3169 "WGL_NV_vertex_array_range",
3171 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3172 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3177 * X11DRV_WineGL_LoadExtensions
3179 static void X11DRV_WineGL_LoadExtensions(void)
3181 WineGLInfo
.wglExtensions
[0] = 0;
3183 /* Load Wine internal functions */
3184 register_extension(&WGL_internal_functions
);
3186 /* ARB Extensions */
3188 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3190 register_extension_string("WGL_ARB_pixel_format_float");
3191 register_extension_string("WGL_ATI_pixel_format_float");
3194 register_extension(&WGL_ARB_extensions_string
);
3196 if (glxRequireVersion(3))
3197 register_extension(&WGL_ARB_make_current_read
);
3199 if (glxRequireExtension("GLX_ARB_multisample"))
3200 register_extension(&WGL_ARB_multisample
);
3202 /* In general pbuffer functionality requires support in the X-server. The functionality is
3203 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3204 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3205 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3207 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3208 * without support in the X-server (which other Mesa based drivers require).
3210 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3211 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3212 * is available pbuffers must be available too. */
3213 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3214 register_extension(&WGL_ARB_pbuffer
);
3216 register_extension(&WGL_ARB_pixel_format
);
3218 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3219 if (glxRequireExtension("GLX_ATI_render_texture") ||
3220 glxRequireExtension("GLX_ARB_render_texture") ||
3221 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3223 register_extension(&WGL_ARB_render_texture
);
3225 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3226 if(glxRequireExtension("GLX_NV_float_buffer"))
3227 register_extension_string("WGL_NV_float_buffer");
3229 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3230 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3231 register_extension_string("WGL_NV_texture_rectangle");
3234 /* EXT Extensions */
3236 register_extension(&WGL_EXT_extensions_string
);
3238 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3239 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3240 register_extension(&WGL_EXT_swap_control
);
3242 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3243 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3244 register_extension(&WGL_NV_vertex_array_range
);
3248 static XID
create_glxpixmap(X11DRV_PDEVICE
*physDev
)
3252 XVisualInfo
template;
3257 /* Retrieve the visualid from our main visual which is the only visual we can use */
3258 template.visualid
= XVisualIDFromVisual(visual
);
3259 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
3261 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
3263 wine_tsx11_unlock();
3264 TRACE("return %lx\n", ret
);
3268 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3274 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3275 ret
= physDev
->drawable
; /* PBuffer */
3278 if(!physDev
->bitmap
->glxpixmap
)
3279 physDev
->bitmap
->glxpixmap
= create_glxpixmap(physDev
);
3280 ret
= physDev
->bitmap
->glxpixmap
;
3284 ret
= physDev
->drawable
;
3288 BOOL
destroy_glxpixmap(XID glxpixmap
)
3291 pglXDestroyGLXPixmap(gdi_display
, glxpixmap
);
3292 wine_tsx11_unlock();
3297 * X11DRV_SwapBuffers
3299 * Swap the buffers of this DC
3301 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3303 GLXDrawable drawable
;
3304 if (!has_opengl()) {
3305 ERR("No libGL on this box - disabling OpenGL support !\n");
3309 TRACE_(opengl
)("(%p)\n", physDev
);
3311 drawable
= get_glxdrawable(physDev
);
3313 pglXSwapBuffers(gdi_display
, drawable
);
3314 wine_tsx11_unlock();
3319 static long prev_time
, frames
;
3321 DWORD time
= GetTickCount();
3323 /* every 1.5 seconds */
3324 if (time
- prev_time
> 1500) {
3325 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
3334 /***********************************************************************
3335 * X11DRV_setup_opengl_visual
3337 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3338 * window (if it exists). If OpenGL isn't available, the visual is simply
3339 * set to the default visual for the display
3341 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3343 XVisualInfo
*visual
= NULL
;
3346 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3347 * D3D and some applications can make use of aux buffers.
3349 int visualProperties
[][11] = {
3350 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_AUX_BUFFERS
, 1, None
},
3351 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, None
},
3352 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, None
},
3353 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, None
},
3360 for (i
= 0; i
< sizeof(visualProperties
)/sizeof(visualProperties
[0]); ++i
) {
3361 visual
= pglXChooseVisual(display
, DefaultScreen(display
), visualProperties
[i
]);
3365 wine_tsx11_unlock();
3368 TRACE("Visual ID %lx Chosen\n", visual
->visualid
);
3370 WARN("No suitable visual found\n");
3375 #else /* no OpenGL includes */
3377 /***********************************************************************
3378 * ChoosePixelFormat (X11DRV.@)
3380 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3381 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3382 ERR("No OpenGL support compiled in.\n");
3387 /***********************************************************************
3388 * DescribePixelFormat (X11DRV.@)
3390 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3393 PIXELFORMATDESCRIPTOR
*ppfd
) {
3394 ERR("No OpenGL support compiled in.\n");
3399 /***********************************************************************
3400 * GetPixelFormat (X11DRV.@)
3402 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3403 ERR("No OpenGL support compiled in.\n");
3408 /***********************************************************************
3409 * SetPixelFormat (X11DRV.@)
3411 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3413 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3414 ERR("No OpenGL support compiled in.\n");
3419 /***********************************************************************
3420 * SwapBuffers (X11DRV.@)
3422 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3423 ERR_(opengl
)("No OpenGL support compiled in.\n");
3429 * X11DRV_wglCreateContext
3431 * For OpenGL32 wglCreateContext.
3433 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3434 ERR_(opengl
)("No OpenGL support compiled in.\n");
3439 * X11DRV_wglDeleteContext
3441 * For OpenGL32 wglDeleteContext.
3443 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3444 ERR_(opengl
)("No OpenGL support compiled in.\n");
3449 * X11DRV_wglGetProcAddress
3451 * For OpenGL32 wglGetProcAddress.
3453 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3454 ERR_(opengl
)("No OpenGL support compiled in.\n");
3458 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3460 ERR_(opengl
)("No OpenGL support compiled in.\n");
3464 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3465 ERR_(opengl
)("No OpenGL support compiled in.\n");
3470 * X11DRV_wglMakeCurrent
3472 * For OpenGL32 wglMakeCurrent.
3474 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3475 ERR_(opengl
)("No OpenGL support compiled in.\n");
3480 * X11DRV_wglShareLists
3482 * For OpenGL32 wglShaderLists.
3484 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3485 ERR_(opengl
)("No OpenGL support compiled in.\n");
3490 * X11DRV_wglUseFontBitmapsA
3492 * For OpenGL32 wglUseFontBitmapsA.
3494 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3496 ERR_(opengl
)("No OpenGL support compiled in.\n");
3501 * X11DRV_wglUseFontBitmapsW
3503 * For OpenGL32 wglUseFontBitmapsW.
3505 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3507 ERR_(opengl
)("No OpenGL support compiled in.\n");
3511 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3516 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3521 BOOL
destroy_glxpixmap(XID glxpixmap
)
3526 #endif /* defined(HAVE_OPENGL) */