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 Wine_GLContext
*get_context_from_GLXContext(GLXContext ctx
)
553 if (!ctx
) return NULL
;
554 for (ret
= context_list
; ret
; ret
= ret
->next
) if (ctx
== ret
->ctx
) break;
558 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
561 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
562 return (ptr
!= NULL
);
565 static int describeContext(Wine_GLContext
* ctx
) {
568 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
569 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
570 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
571 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
572 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
577 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
580 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
583 if (pglXQueryDrawable
== NULL
) {
584 /** glXQueryDrawable not available so returns not supported */
588 TRACE(" Drawable %p have :\n", (void*) drawable
);
589 pglXQueryDrawable(gdi_display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
590 TRACE(" - WIDTH as %d\n", tmp
);
591 pglXQueryDrawable(gdi_display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
592 TRACE(" - HEIGHT as %d\n", tmp
);
593 pglXQueryDrawable(gdi_display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
594 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
597 fbCfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribList
, &nElements
);
598 if (fbCfgs
== NULL
) {
602 pglXGetFBConfigAttrib(gdi_display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
603 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
610 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
615 int nvfloatattrib
= GLX_DONT_CARE
;
618 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
619 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
620 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
621 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
623 switch (iWGLAttr
[cur
]) {
624 case WGL_COLOR_BITS_ARB
:
625 pop
= iWGLAttr
[++cur
];
626 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
627 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
629 case WGL_BLUE_BITS_ARB
:
630 pop
= iWGLAttr
[++cur
];
631 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
632 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
634 case WGL_RED_BITS_ARB
:
635 pop
= iWGLAttr
[++cur
];
636 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
637 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
639 case WGL_GREEN_BITS_ARB
:
640 pop
= iWGLAttr
[++cur
];
641 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
642 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
644 case WGL_ALPHA_BITS_ARB
:
645 pop
= iWGLAttr
[++cur
];
646 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
647 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
649 case WGL_DEPTH_BITS_ARB
:
650 pop
= iWGLAttr
[++cur
];
651 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
652 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
654 case WGL_STENCIL_BITS_ARB
:
655 pop
= iWGLAttr
[++cur
];
656 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
657 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
659 case WGL_DOUBLE_BUFFER_ARB
:
660 pop
= iWGLAttr
[++cur
];
661 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
662 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
665 case WGL_PIXEL_TYPE_ARB
:
666 pop
= iWGLAttr
[++cur
];
667 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
669 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
670 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
671 /* 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 */
672 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
674 ERR("unexpected PixelType(%x)\n", pop
);
679 case WGL_SUPPORT_GDI_ARB
:
680 pop
= iWGLAttr
[++cur
];
681 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
682 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
685 case WGL_DRAW_TO_BITMAP_ARB
:
686 pop
= iWGLAttr
[++cur
];
687 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
688 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
690 drawattrib
|= GLX_PIXMAP_BIT
;
694 case WGL_DRAW_TO_WINDOW_ARB
:
695 pop
= iWGLAttr
[++cur
];
696 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
697 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
699 drawattrib
|= GLX_WINDOW_BIT
;
703 case WGL_DRAW_TO_PBUFFER_ARB
:
704 pop
= iWGLAttr
[++cur
];
705 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
706 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
708 drawattrib
|= GLX_PBUFFER_BIT
;
712 case WGL_ACCELERATION_ARB
:
713 case WGL_SUPPORT_OPENGL_ARB
:
714 pop
= iWGLAttr
[++cur
];
715 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
716 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
719 case WGL_PBUFFER_LARGEST_ARB
:
720 pop
= iWGLAttr
[++cur
];
721 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
722 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
725 case WGL_SAMPLE_BUFFERS_ARB
:
726 pop
= iWGLAttr
[++cur
];
727 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
728 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
731 case WGL_SAMPLES_ARB
:
732 pop
= iWGLAttr
[++cur
];
733 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
734 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
737 case WGL_TEXTURE_FORMAT_ARB
:
738 case WGL_TEXTURE_TARGET_ARB
:
739 case WGL_MIPMAP_TEXTURE_ARB
:
740 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
741 pop
= iWGLAttr
[++cur
];
743 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
745 if (use_render_texture_ati
) {
746 /** nothing to do here */
748 else if (!use_render_texture_emulation
) {
749 if (WGL_NO_TEXTURE_ARB
!= pop
) {
750 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
751 return -1; /** error: don't support it */
753 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
754 drawattrib
|= GLX_PBUFFER_BIT
;
758 case WGL_FLOAT_COMPONENTS_NV
:
759 nvfloatattrib
= iWGLAttr
[++cur
];
760 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
762 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
763 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
764 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
765 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
766 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
767 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
768 pop
= iWGLAttr
[++cur
];
769 /** cannot be converted, see direct handling on
770 * - wglGetPixelFormatAttribivARB
771 * TODO: wglChoosePixelFormat
776 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
782 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
783 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
784 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
785 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
787 /* Set GLX_RENDER_TYPE all the time */
788 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
789 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
791 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
792 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
793 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
794 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
800 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
802 int render_type
=0, render_type_bit
;
803 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
804 switch(render_type_bit
)
807 render_type
= GLX_RGBA_TYPE
;
809 case GLX_COLOR_INDEX_BIT
:
810 render_type
= GLX_COLOR_INDEX_TYPE
;
812 case GLX_RGBA_FLOAT_BIT
:
813 render_type
= GLX_RGBA_FLOAT_TYPE
;
816 ERR("Unknown render_type: %x\n", render_type
);
821 static BOOL
init_formats(Display
*display
, int screen
, Visual
*visual
)
823 int fmt_id
, tmp_vis_id
, tmp_fmt_id
, nCfgs
, i
;
825 GLXFBConfig fbconfig
= NULL
;
826 VisualID visualid
= XVisualIDFromVisual(visual
);
827 int nOffscreenFormats
= 0;
829 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
830 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
831 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
832 * because this call lists both types of formats instead of only onscreen ones. */
833 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
834 if (NULL
== cfgs
|| 0 == nCfgs
) {
835 ERR("glXChooseFBConfig returns NULL\n");
836 if(cfgs
!= NULL
) XFree(cfgs
);
840 /* Count the number of offscreen formats to determine the size for our pixelformat list */
841 for(i
=0; i
<nCfgs
; i
++) {
842 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
844 /* We have found Wine's main visual */
845 if(tmp_vis_id
== visualid
) {
846 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
850 /* We have found an offscreen rendering format :) */
851 if(tmp_vis_id
== 0) {
855 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats
);
857 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
858 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (1+nOffscreenFormats
)*sizeof(WineGLPixelFormat
));
859 WineGLPixelFormatList
[0].iPixelFormat
= 1;
860 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
861 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
862 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
863 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
864 WineGLPixelFormatListSize
= 1;
866 /* Fill the list with offscreen formats */
867 for(i
=0; i
<nCfgs
; i
++) {
868 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
869 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
871 /* We have found an offscreen rendering format :) */
872 if(tmp_vis_id
== 0) {
873 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id
, WineGLPixelFormatListSize
+1, i
);
874 WineGLPixelFormatList
[WineGLPixelFormatListSize
].iPixelFormat
= WineGLPixelFormatListSize
+1; /* The index starts at 1 */
875 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fbconfig
= cfgs
[i
];
876 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fmt_id
= tmp_fmt_id
;
877 WineGLPixelFormatList
[WineGLPixelFormatListSize
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
878 WineGLPixelFormatList
[WineGLPixelFormatListSize
].offscreenOnly
= TRUE
;
879 WineGLPixelFormatListSize
++;
883 if(cfgs
!= NULL
) XFree(cfgs
);
888 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
889 * In our WGL implementation we only support a subset of these formats namely the format of
890 * Wine's main visual and offscreen formats (if they are available).
891 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
892 * and it returns the number of supported WGL formats in fmt_count.
894 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
896 WineGLPixelFormat
*res
= NULL
;
898 /* Init the list of pixel formats when we need it */
899 if(!WineGLPixelFormatListSize
)
900 init_formats(display
, DefaultScreen(display
), visual
);
902 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
903 * iPixelFormat in case of probing the number of pixelformats.
905 if((iPixelFormat
<= 0) || (iPixelFormat
> WineGLPixelFormatListSize
)) {
907 *fmt_count
= WineGLPixelFormatListSize
;
909 *fmt_count
= 1; /* Only show the format of our main visual */
911 else if(iPixelFormat
== 1) {
912 res
= &WineGLPixelFormatList
[0];
913 *fmt_count
= 1; /* Only show the format of our main visual */
915 else if((WineGLPixelFormatList
[iPixelFormat
-1].offscreenOnly
== TRUE
) && AllowOffscreen
) {
916 res
= &WineGLPixelFormatList
[iPixelFormat
-1];
917 *fmt_count
= WineGLPixelFormatListSize
;
918 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
921 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
926 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
927 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
)
931 /* Init the list of pixel formats when we need it */
932 if(!WineGLPixelFormatListSize
)
933 init_formats(display
, DefaultScreen(display
), visual
);
935 for(i
=0; i
<WineGLPixelFormatListSize
; i
++) {
936 if(WineGLPixelFormatList
[i
].fmt_id
== fmt_id
) {
937 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList
[i
].iPixelFormat
, fmt_id
);
938 return &WineGLPixelFormatList
[i
];
941 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
946 * X11DRV_ChoosePixelFormat
948 * Equivalent to glXChooseVisual.
950 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
951 const PIXELFORMATDESCRIPTOR
*ppfd
) {
952 WineGLPixelFormat
*fmt
= NULL
;
958 int bestDBuffer
= -1;
963 int bestStencil
= -1;
968 ERR("No libGL on this box - disabling OpenGL support !\n");
972 if (TRACE_ON(opengl
)) {
973 TRACE("(%p,%p)\n", physDev
, ppfd
);
975 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
979 ConvertPixelFormatWGLtoGLX(gdi_display
, 0, FALSE
/* offscreen */, &nPixelFormats
);
980 for(i
=0; i
<nPixelFormats
; i
++)
984 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
986 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, i
+1 /* 1-based index */, FALSE
/* offscreen */, &value
);
990 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
991 if (value
& GLX_RGBA_BIT
)
992 iPixelType
= PFD_TYPE_RGBA
;
994 iPixelType
= PFD_TYPE_COLORINDEX
;
996 if (ppfd
->iPixelType
!= iPixelType
)
998 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1002 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1003 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1004 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1005 if (value
) dwFlags
|= PFD_STEREO
;
1006 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1007 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1008 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1009 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1010 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1012 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1013 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1014 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1015 * formats without the given flag set.
1016 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1017 * has indicated that a format without stereo is returned when stereo is unavailable.
1018 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1019 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1021 * To summarize the following is most likely the correct behavior:
1022 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1023 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1024 * stereo don't care -> it doesn't matter whether we get stereo or not
1026 * In Wine we will treat no-stereo the same way as don't care because it makes
1027 * format selection even more complicated and second drivers with Stereo advertise
1028 * each format twice anyway.
1031 /* Doublebuffer, see the comments above */
1032 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1033 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1034 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1036 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1037 bestStereo
= dwFlags
& PFD_STEREO
;
1041 bestStencil
= stencil
;
1048 /* Stereo, see the comments above. */
1049 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1050 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1051 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1053 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1054 bestStereo
= dwFlags
& PFD_STEREO
;
1058 bestStencil
= stencil
;
1065 /* Below we will do a number of checks to select the 'best' pixelformat.
1066 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1067 * The code works by trying to match the most important options as close as possible.
1068 * When a reasonable format is found, we will try to match more options. */
1071 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1072 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1074 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1075 bestStereo
= dwFlags
& PFD_STEREO
;
1079 bestStencil
= stencil
;
1083 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1084 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1089 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1090 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1092 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1093 bestStereo
= dwFlags
& PFD_STEREO
;
1097 bestStencil
= stencil
;
1101 } else if(bestAlpha
!= alpha
) {
1102 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1107 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1108 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1110 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1111 bestStereo
= dwFlags
& PFD_STEREO
;
1115 bestStencil
= stencil
;
1119 } else if(bestDepth
!= depth
) {
1120 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1125 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1126 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1128 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1129 bestStereo
= dwFlags
& PFD_STEREO
;
1133 bestStencil
= stencil
;
1137 } else if(bestStencil
!= stencil
) {
1138 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1143 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1144 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1146 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1147 bestStereo
= dwFlags
& PFD_STEREO
;
1151 bestStencil
= stencil
;
1155 } else if(bestAux
!= aux
) {
1156 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1161 if(bestFormat
== -1) {
1162 TRACE("No matching mode was found returning 0\n");
1166 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1167 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, WineGLPixelFormatList
[bestFormat
].fmt_id
);
1170 wine_tsx11_unlock();
1175 * X11DRV_DescribePixelFormat
1177 * Get the pixel-format descriptor associated to the given id
1179 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1182 PIXELFORMATDESCRIPTOR
*ppfd
) {
1183 /*XVisualInfo *vis;*/
1186 WineGLPixelFormat
*fmt
;
1190 if (!has_opengl()) {
1191 ERR("No libGL on this box - disabling OpenGL support !\n");
1195 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1197 /* 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 */
1198 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1200 /* The application is only querying the number of pixelformats */
1202 } else if(fmt
== NULL
) {
1203 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1207 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1208 ERR("Wrong structure size !\n");
1209 /* Should set error */
1215 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1216 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1219 /* These flags are always the same... */
1220 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1221 /* Now the flags extracted from the Visual */
1225 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_X_RENDERABLE
, &value
);
1227 ppfd
->dwFlags
|= PFD_SUPPORT_GDI
;
1229 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1230 if(value
& GLX_WINDOW_BIT
)
1231 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1232 if(value
& GLX_PIXMAP_BIT
)
1233 ppfd
->dwFlags
|= PFD_DRAW_TO_BITMAP
;
1235 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_CONFIG_CAVEAT
, &value
);
1236 if(value
== GLX_SLOW_CONFIG
)
1237 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1239 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1241 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1242 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1244 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1247 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1248 if (value
& GLX_RGBA_BIT
)
1249 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1251 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1254 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1255 ppfd
->cColorBits
= value
;
1257 /* Red, green, blue and alpha bits / shifts */
1258 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1259 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1260 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1261 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1262 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1264 ppfd
->cRedBits
= rb
;
1265 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1266 ppfd
->cBlueBits
= bb
;
1267 ppfd
->cBlueShift
= ab
;
1268 ppfd
->cGreenBits
= gb
;
1269 ppfd
->cGreenShift
= bb
+ ab
;
1270 ppfd
->cAlphaBits
= ab
;
1271 ppfd
->cAlphaShift
= 0;
1274 ppfd
->cRedShift
= 0;
1275 ppfd
->cBlueBits
= 0;
1276 ppfd
->cBlueShift
= 0;
1277 ppfd
->cGreenBits
= 0;
1278 ppfd
->cGreenShift
= 0;
1279 ppfd
->cAlphaBits
= 0;
1280 ppfd
->cAlphaShift
= 0;
1283 /* Accum RGBA bits */
1284 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1285 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1286 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1287 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1289 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1290 ppfd
->cAccumRedBits
= rb
;
1291 ppfd
->cAccumGreenBits
= gb
;
1292 ppfd
->cAccumBlueBits
= bb
;
1293 ppfd
->cAccumAlphaBits
= ab
;
1296 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1297 ppfd
->cDepthBits
= value
;
1300 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1301 ppfd
->cStencilBits
= value
;
1303 wine_tsx11_unlock();
1305 /* Aux : to do ... */
1307 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1309 if (TRACE_ON(opengl
)) {
1310 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1317 * X11DRV_GetPixelFormat
1319 * Get the pixel-format id used by this DC
1321 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1322 WineGLPixelFormat
*fmt
;
1324 TRACE("(%p)\n", physDev
);
1326 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1329 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1330 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1333 else if(fmt
->offscreenOnly
)
1335 /* Offscreen formats can't be used with traditional WGL calls.
1336 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1337 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1341 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1342 return physDev
->current_pf
;
1346 * X11DRV_SetPixelFormat
1348 * Set the pixel-format id used by this DC
1350 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1352 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1353 WineGLPixelFormat
*fmt
;
1356 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1358 if (!has_opengl()) {
1359 ERR("No libGL on this box - disabling OpenGL support !\n");
1363 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1364 if(get_glxdrawable(physDev
) == root_window
)
1366 ERR("Invalid operation on root_window\n");
1370 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1371 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1373 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1377 physDev
->current_pf
= iPixelFormat
;
1379 if (TRACE_ON(opengl
)) {
1383 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1385 * in case of root window created HDCs we crash here :(
1387 Drawable drawable = get_drawable( physDev->hdc );
1388 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1389 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1390 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1391 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1392 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1393 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1394 TRACE(" - WIDTH as %d\n", tmp);
1395 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1396 TRACE(" - HEIGHT as %d\n", tmp);
1398 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1400 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1402 TRACE(" FBConfig have :\n");
1403 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1404 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1405 TRACE(" - VISUAL_ID 0x%x\n", value
);
1406 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1407 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1414 * X11DRV_wglCreateContext
1416 * For OpenGL32 wglCreateContext.
1418 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1420 Wine_GLContext
*ret
;
1421 WineGLPixelFormat
*fmt
;
1422 int hdcPF
= physDev
->current_pf
;
1426 HDC hdc
= physDev
->hdc
;
1428 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1430 if (!has_opengl()) {
1431 ERR("No libGL on this box - disabling OpenGL support !\n");
1435 /* First, get the visual in use by the X11DRV */
1436 if (!gdi_display
) return 0;
1438 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1439 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1440 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1441 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1442 * If this fails something is very wrong on the system. */
1444 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1445 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1449 if (fmt_count
< hdcPF
) {
1450 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, hdcPF
, fmt_count
);
1451 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1455 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1457 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1458 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1462 /* The context will be allocated in the wglMakeCurrent call */
1464 ret
= alloc_context();
1465 wine_tsx11_unlock();
1467 ret
->physDev
= physDev
;
1471 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1473 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1478 * X11DRV_wglDeleteContext
1480 * For OpenGL32 wglDeleteContext.
1482 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1484 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1487 TRACE("(%p)\n", hglrc
);
1489 if (!has_opengl()) {
1490 ERR("No libGL on this box - disabling OpenGL support !\n");
1495 /* A game (Half Life not to name it) deletes twice the same context,
1496 * so make sure it is valid first */
1497 if (is_valid_context( ctx
))
1499 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1504 WARN("Error deleting context !\n");
1505 SetLastError(ERROR_INVALID_HANDLE
);
1508 wine_tsx11_unlock();
1514 * X11DRV_wglGetCurrentReadDCARB
1516 * For OpenGL32 wglGetCurrentReadDCARB.
1518 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1521 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1522 X11DRV_PDEVICE
*physDev
= ctx
? ctx
->pReadDev
: NULL
;
1527 TRACE(" returning %p (GL drawable %lu)\n", ret
, physDev
? physDev
->drawable
: 0);
1532 * X11DRV_wglGetProcAddress
1534 * For OpenGL32 wglGetProcAddress.
1536 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1539 const WineGLExtension
*ext
;
1541 int padding
= 32 - strlen(lpszProc
);
1545 if (!has_opengl()) {
1546 ERR("No libGL on this box - disabling OpenGL support !\n");
1550 /* Check the table of WGL extensions to see if we need to return a WGL extension
1551 * or a function pointer to a native OpenGL function. */
1552 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1553 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1555 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1556 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1557 ext
= WineGLExtensionList
[i
];
1558 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1559 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1560 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1561 return ext
->extEntryPoints
[j
].funcAddress
;
1567 ERR("(%s) - not found\n", lpszProc
);
1571 /***********************************************************************
1572 * sync_current_drawable
1574 * Adjust the current viewport and scissor in order to position
1575 * and size the current drawable correctly on the parent window.
1577 static void sync_current_drawable(BOOL updatedc
)
1583 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1587 if (ctx
&& ctx
->physDev
)
1590 GetClipBox(ctx
->physDev
->hdc
, &rc
); /* Make sure physDev is up to date */
1592 dy
= ctx
->physDev
->drawable_rect
.bottom
- ctx
->physDev
->drawable_rect
.top
-
1593 ctx
->physDev
->dc_rect
.bottom
;
1594 width
= ctx
->physDev
->dc_rect
.right
- ctx
->physDev
->dc_rect
.left
;
1595 height
= ctx
->physDev
->dc_rect
.bottom
- ctx
->physDev
->dc_rect
.top
;
1599 pglViewport(ctx
->physDev
->dc_rect
.left
+ ctx
->viewport
.left
,
1600 dy
+ ctx
->viewport
.top
,
1601 ctx
->viewport
.right
? (ctx
->viewport
.right
- ctx
->viewport
.left
) : width
,
1602 ctx
->viewport
.bottom
? (ctx
->viewport
.bottom
- ctx
->viewport
.top
) : height
);
1604 pglEnable(GL_SCISSOR_TEST
);
1606 if (ctx
->scissor_enabled
)
1607 pglScissor(ctx
->physDev
->dc_rect
.left
+ min(width
, max(0, ctx
->scissor
.left
)),
1608 dy
+ min(height
, max(0, ctx
->scissor
.top
)),
1609 min(width
, max(0, ctx
->scissor
.right
- ctx
->scissor
.left
)),
1610 min(height
, max(0, ctx
->scissor
.bottom
- ctx
->scissor
.top
)));
1612 pglScissor(ctx
->physDev
->dc_rect
.left
, dy
, width
, height
);
1614 wine_tsx11_unlock();
1619 * X11DRV_wglMakeCurrent
1621 * For OpenGL32 wglMakeCurrent.
1623 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1625 HDC hdc
= physDev
->hdc
;
1626 DWORD type
= GetObjectType(hdc
);
1628 TRACE("(%p,%p)\n", hdc
, hglrc
);
1630 if (!has_opengl()) {
1631 ERR("No libGL on this box - disabling OpenGL support !\n");
1636 if (hglrc
== NULL
) {
1637 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1638 NtCurrentTeb()->glContext
= NULL
;
1640 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1641 Drawable drawable
= get_glxdrawable(physDev
);
1642 if (ctx
->ctx
== NULL
) {
1643 /* The describe lines below are for debugging purposes only */
1644 if (TRACE_ON(wgl
)) {
1645 describeDrawable(ctx
, drawable
);
1646 describeContext(ctx
);
1649 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1650 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1652 TRACE(" Creating GLX Context\n");
1654 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1655 else /* Create a GLX Context for a pbuffer */
1656 ctx
->ctx
= pglXCreateNewContext(gdi_display
, ctx
->fmt
->fbconfig
, ctx
->fmt
->render_type
, NULL
, True
);
1658 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1660 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1661 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1662 NtCurrentTeb()->glContext
= ctx
;
1666 ctx
->physDev
= physDev
;
1667 ctx
->pReadDev
= physDev
;
1669 if (type
== OBJ_MEMDC
)
1671 ctx
->do_escape
= TRUE
;
1672 pglDrawBuffer(GL_FRONT_LEFT
);
1676 sync_current_drawable(FALSE
);
1680 wine_tsx11_unlock();
1681 TRACE(" returning %s\n", (ret
? "True" : "False"));
1686 * X11DRV_wglMakeContextCurrentARB
1688 * For OpenGL32 wglMakeContextCurrentARB
1690 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1693 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1695 if (!has_opengl()) {
1696 ERR("No libGL on this box - disabling OpenGL support !\n");
1701 if (hglrc
== NULL
) {
1702 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1703 NtCurrentTeb()->glContext
= NULL
;
1705 if (NULL
== pglXMakeContextCurrent
) {
1708 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1709 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1710 Drawable d_read
= get_glxdrawable(pReadDev
);
1712 if (ctx
->ctx
== NULL
) {
1713 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, GetObjectType(pDrawDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1714 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1716 ctx
->hdc
= pDrawDev
->hdc
;
1717 ctx
->physDev
= pDrawDev
;
1718 ctx
->pReadDev
= pReadDev
;
1719 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1720 NtCurrentTeb()->glContext
= ctx
;
1723 wine_tsx11_unlock();
1725 TRACE(" returning %s\n", (ret
? "True" : "False"));
1730 * X11DRV_wglShareLists
1732 * For OpenGL32 wglShaderLists.
1734 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1735 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1736 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1738 TRACE("(%p, %p)\n", org
, dest
);
1740 if (!has_opengl()) {
1741 ERR("No libGL on this box - disabling OpenGL support !\n");
1745 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1746 ERR("Could not share display lists, context already created !\n");
1749 if (org
->ctx
== NULL
) {
1751 describeContext(org
);
1754 org
->ctx
= pglXCreateContext(gdi_display
, org
->vis
, NULL
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1755 else /* Create a GLX Context for a pbuffer */
1756 org
->ctx
= pglXCreateNewContext(gdi_display
, org
->fmt
->fbconfig
, org
->fmt
->render_type
, NULL
, True
);
1757 wine_tsx11_unlock();
1758 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1762 describeContext(dest
);
1763 /* Create the destination context with display lists shared */
1765 dest
->ctx
= pglXCreateContext(gdi_display
, dest
->vis
, org
->ctx
, GetObjectType(org
->hdc
) == OBJ_MEMDC
? False
: True
);
1766 else /* Create a GLX Context for a pbuffer */
1767 dest
->ctx
= pglXCreateNewContext(gdi_display
, dest
->fmt
->fbconfig
, dest
->fmt
->render_type
, org
->ctx
, True
);
1768 wine_tsx11_unlock();
1769 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1776 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1778 /* We are running using client-side rendering fonts... */
1782 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1786 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1787 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1788 wine_tsx11_unlock();
1790 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1791 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1792 int height
, width_int
;
1794 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1795 if (needed_size
== GDI_ERROR
) {
1796 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1799 TRACE(" - needed size : %d\n", needed_size
);
1802 if (needed_size
> size
) {
1804 HeapFree(GetProcessHeap(), 0, bitmap
);
1805 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1806 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1807 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1809 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1810 if (TRACE_ON(opengl
)) {
1811 unsigned int height
, width
, bitmask
;
1812 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1814 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1815 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1816 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1817 if (needed_size
!= 0) {
1818 TRACE(" - bitmap :\n");
1819 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1821 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1826 if (*bitmap_
& bitmask
)
1831 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1837 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1838 * glyph for it to be drawn properly.
1840 if (needed_size
!= 0) {
1841 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1842 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1844 for (width
= 0; width
< width_int
; width
++) {
1845 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1846 ((int *) bitmap
)[height
* width_int
+ width
];
1852 pglNewList(listBase
++, GL_COMPILE
);
1853 if (needed_size
!= 0) {
1854 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1855 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1856 gm
.gmCellIncX
, gm
.gmCellIncY
,
1859 /* This is the case of 'empty' glyphs like the space character */
1860 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1863 wine_tsx11_unlock();
1867 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1868 wine_tsx11_unlock();
1870 HeapFree(GetProcessHeap(), 0, bitmap
);
1871 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1876 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1877 wine_tsx11_unlock();
1879 HeapFree(GetProcessHeap(), 0, bitmap
);
1880 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1885 * X11DRV_wglUseFontBitmapsA
1887 * For OpenGL32 wglUseFontBitmapsA.
1889 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1891 Font fid
= physDev
->font
;
1893 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1895 if (!has_opengl()) {
1896 ERR("No libGL on this box - disabling OpenGL support !\n");
1901 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
1905 /* I assume that the glyphs are at the same position for X and for Windows */
1906 pglXUseXFont(fid
, first
, count
, listBase
);
1907 wine_tsx11_unlock();
1912 * X11DRV_wglUseFontBitmapsW
1914 * For OpenGL32 wglUseFontBitmapsW.
1916 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1918 Font fid
= physDev
->font
;
1920 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1922 if (!has_opengl()) {
1923 ERR("No libGL on this box - disabling OpenGL support !\n");
1928 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1931 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1934 /* I assume that the glyphs are at the same position for X and for Windows */
1935 pglXUseXFont(fid
, first
, count
, listBase
);
1936 wine_tsx11_unlock();
1940 static void WINAPI
X11DRV_wglDisable(GLenum cap
)
1942 if (cap
== GL_SCISSOR_TEST
)
1944 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1947 ctx
->scissor_enabled
= FALSE
;
1953 wine_tsx11_unlock();
1957 static void WINAPI
X11DRV_wglEnable(GLenum cap
)
1959 if (cap
== GL_SCISSOR_TEST
)
1961 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1964 ctx
->scissor_enabled
= TRUE
;
1970 wine_tsx11_unlock();
1974 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1975 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
1982 GLXContext gl_ctx
= pglXGetCurrentContext();
1983 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1985 pglGetIntegerv(pname
, params
);
1987 * if we cannot find a Wine Context
1988 * we only have the default wine desktop context,
1989 * so if we have only a 24 depth say we have 32
1991 if (NULL
== ret
&& 24 == *params
) {
1994 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
1999 GLXContext gl_ctx
= pglXGetCurrentContext();
2000 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
2002 pglXGetFBConfigAttrib(gdi_display
, ret
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2003 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2007 pglGetIntegerv(pname
, params
);
2010 wine_tsx11_unlock();
2013 static GLboolean WINAPI
X11DRV_wglIsEnabled(GLenum cap
)
2015 GLboolean enabled
= False
;
2017 if (cap
== GL_SCISSOR_TEST
)
2019 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2022 enabled
= ctx
->scissor_enabled
;
2027 enabled
= pglIsEnabled(cap
);
2028 wine_tsx11_unlock();
2033 static void WINAPI
X11DRV_wglScissor(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2035 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2039 ctx
->scissor
.left
= x
;
2040 ctx
->scissor
.top
= y
;
2041 ctx
->scissor
.right
= x
+ width
;
2042 ctx
->scissor
.bottom
= y
+ height
;
2044 sync_current_drawable(TRUE
);
2048 static void WINAPI
X11DRV_wglViewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2050 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2054 ctx
->viewport
.left
= x
;
2055 ctx
->viewport
.top
= y
;
2056 ctx
->viewport
.right
= x
+ width
;
2057 ctx
->viewport
.bottom
= y
+ height
;
2059 sync_current_drawable(TRUE
);
2064 * X11DRV_wglGetExtensionsStringARB
2066 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2068 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2069 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2070 return WineGLInfo
.wglExtensions
;
2074 * X11DRV_wglCreatePbufferARB
2076 * WGL_ARB_pbuffer: wglCreatePbufferARB
2078 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2080 Wine_GLPBuffer
* object
= NULL
;
2081 WineGLPixelFormat
*fmt
= NULL
;
2086 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2088 if (0 >= iPixelFormat
) {
2089 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2090 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2091 return NULL
; /* unexpected error */
2094 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2095 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2097 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2098 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2099 goto create_failed
; /* unexpected error */
2102 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2103 if (NULL
== object
) {
2104 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2105 goto create_failed
; /* unexpected error */
2108 object
->display
= gdi_display
;
2109 object
->width
= iWidth
;
2110 object
->height
= iHeight
;
2113 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2114 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2115 while (piAttribList
&& 0 != *piAttribList
) {
2117 switch (*piAttribList
) {
2118 case WGL_PBUFFER_LARGEST_ARB
: {
2120 attr_v
= *piAttribList
;
2121 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2122 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2126 case WGL_TEXTURE_FORMAT_ARB
: {
2128 attr_v
= *piAttribList
;
2129 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2130 if (use_render_texture_ati
) {
2133 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2134 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2135 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2137 SetLastError(ERROR_INVALID_DATA
);
2140 object
->use_render_texture
= 1;
2141 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2143 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2144 object
->use_render_texture
= 0;
2146 if (!use_render_texture_emulation
) {
2147 SetLastError(ERROR_INVALID_DATA
);
2151 case WGL_TEXTURE_RGB_ARB
:
2152 object
->use_render_texture
= GL_RGB
;
2153 object
->texture_bpp
= 3;
2154 object
->texture_format
= GL_RGB
;
2155 object
->texture_type
= GL_UNSIGNED_BYTE
;
2157 case WGL_TEXTURE_RGBA_ARB
:
2158 object
->use_render_texture
= GL_RGBA
;
2159 object
->texture_bpp
= 4;
2160 object
->texture_format
= GL_RGBA
;
2161 object
->texture_type
= GL_UNSIGNED_BYTE
;
2164 /* WGL_FLOAT_COMPONENTS_NV */
2165 case WGL_TEXTURE_FLOAT_R_NV
:
2166 object
->use_render_texture
= GL_FLOAT_R_NV
;
2167 object
->texture_bpp
= 4;
2168 object
->texture_format
= GL_RED
;
2169 object
->texture_type
= GL_FLOAT
;
2171 case WGL_TEXTURE_FLOAT_RG_NV
:
2172 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2173 object
->texture_bpp
= 8;
2174 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2175 object
->texture_type
= GL_FLOAT
;
2177 case WGL_TEXTURE_FLOAT_RGB_NV
:
2178 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2179 object
->texture_bpp
= 12;
2180 object
->texture_format
= GL_RGB
;
2181 object
->texture_type
= GL_FLOAT
;
2183 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2184 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2185 object
->texture_bpp
= 16;
2186 object
->texture_format
= GL_RGBA
;
2187 object
->texture_type
= GL_FLOAT
;
2190 ERR("Unknown texture format: %x\n", attr_v
);
2191 SetLastError(ERROR_INVALID_DATA
);
2199 case WGL_TEXTURE_TARGET_ARB
: {
2201 attr_v
= *piAttribList
;
2202 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2203 if (use_render_texture_ati
) {
2206 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2207 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2208 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2209 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2211 SetLastError(ERROR_INVALID_DATA
);
2214 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2216 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2217 object
->texture_target
= 0;
2219 if (!use_render_texture_emulation
) {
2220 SetLastError(ERROR_INVALID_DATA
);
2224 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2225 if (iWidth
!= iHeight
) {
2226 SetLastError(ERROR_INVALID_DATA
);
2229 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2230 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2233 case WGL_TEXTURE_1D_ARB
: {
2235 SetLastError(ERROR_INVALID_DATA
);
2238 object
->texture_target
= GL_TEXTURE_1D
;
2239 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2242 case WGL_TEXTURE_2D_ARB
: {
2243 object
->texture_target
= GL_TEXTURE_2D
;
2244 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2247 case WGL_TEXTURE_RECTANGLE_NV
: {
2248 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2249 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2253 ERR("Unknown texture target: %x\n", attr_v
);
2254 SetLastError(ERROR_INVALID_DATA
);
2262 case WGL_MIPMAP_TEXTURE_ARB
: {
2264 attr_v
= *piAttribList
;
2265 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2266 if (use_render_texture_ati
) {
2267 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2269 if (!use_render_texture_emulation
) {
2270 SetLastError(ERROR_INVALID_DATA
);
2280 PUSH1(attribs
, None
);
2281 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2282 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2283 if (!object
->drawable
) {
2284 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2285 goto create_failed
; /* unexpected error */
2287 TRACE("->(%p)\n", object
);
2288 return (HPBUFFERARB
) object
;
2291 HeapFree(GetProcessHeap(), 0, object
);
2292 TRACE("->(FAILED)\n");
2293 return (HPBUFFERARB
) NULL
;
2297 * X11DRV_wglDestroyPbufferARB
2299 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2301 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2303 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2304 TRACE("(%p)\n", hPbuffer
);
2305 if (NULL
== object
) {
2306 SetLastError(ERROR_INVALID_HANDLE
);
2309 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2310 HeapFree(GetProcessHeap(), 0, object
);
2315 * X11DRV_wglGetPbufferDCARB
2317 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2318 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2319 * Gdi32 implements the part of this function which creates a device context.
2320 * This part associates the physDev with the X drawable of the pbuffer.
2322 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2324 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2325 if (NULL
== object
) {
2326 SetLastError(ERROR_INVALID_HANDLE
);
2330 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2331 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2332 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2333 physDev
->drawable
= object
->drawable
;
2334 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2335 physDev
->dc_rect
= physDev
->drawable_rect
;
2337 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2338 return physDev
->hdc
;
2342 * X11DRV_wglQueryPbufferARB
2344 * WGL_ARB_pbuffer: wglQueryPbufferARB
2346 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2348 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2349 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2350 if (NULL
== object
) {
2351 SetLastError(ERROR_INVALID_HANDLE
);
2354 switch (iAttribute
) {
2355 case WGL_PBUFFER_WIDTH_ARB
:
2356 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2358 case WGL_PBUFFER_HEIGHT_ARB
:
2359 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2362 case WGL_PBUFFER_LOST_ARB
:
2363 /* GLX Pbuffers cannot be lost by default. We can support this by
2364 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2365 * to receive pixel buffer clobber events, however that may or may
2366 * not give any benefit */
2367 *piValue
= GL_FALSE
;
2370 case WGL_TEXTURE_FORMAT_ARB
:
2371 if (use_render_texture_ati
) {
2373 int type
= WGL_NO_TEXTURE_ARB
;
2374 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2376 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2377 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2378 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2382 if (!object
->use_render_texture
) {
2383 *piValue
= WGL_NO_TEXTURE_ARB
;
2385 if (!use_render_texture_emulation
) {
2386 SetLastError(ERROR_INVALID_HANDLE
);
2389 switch(object
->use_render_texture
) {
2391 *piValue
= WGL_TEXTURE_RGB_ARB
;
2394 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2396 /* WGL_FLOAT_COMPONENTS_NV */
2398 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2400 case GL_FLOAT_RG_NV
:
2401 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2403 case GL_FLOAT_RGB_NV
:
2404 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2406 case GL_FLOAT_RGBA_NV
:
2407 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2410 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2416 case WGL_TEXTURE_TARGET_ARB
:
2417 if (use_render_texture_ati
) {
2419 int type
= WGL_NO_TEXTURE_ARB
;
2420 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2422 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2423 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2424 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2425 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2429 if (!object
->texture_target
) {
2430 *piValue
= WGL_NO_TEXTURE_ARB
;
2432 if (!use_render_texture_emulation
) {
2433 SetLastError(ERROR_INVALID_DATA
);
2436 switch (object
->texture_target
) {
2437 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2438 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2439 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2440 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2446 case WGL_MIPMAP_TEXTURE_ARB
:
2447 if (use_render_texture_ati
) {
2448 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2450 *piValue
= GL_FALSE
; /** don't support that */
2451 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2456 FIXME("unexpected attribute %x\n", iAttribute
);
2464 * X11DRV_wglReleasePbufferDCARB
2466 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2468 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2470 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2476 * X11DRV_wglSetPbufferAttribARB
2478 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2480 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2482 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2483 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2484 if (NULL
== object
) {
2485 SetLastError(ERROR_INVALID_HANDLE
);
2488 if (!object
->use_render_texture
) {
2489 SetLastError(ERROR_INVALID_HANDLE
);
2492 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2495 if (NULL
!= pglXDrawableAttribATI
) {
2496 if (use_render_texture_ati
) {
2497 FIXME("Need conversion for GLX_ATI_render_texture\n");
2499 return pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2505 * X11DRV_wglChoosePixelFormatARB
2507 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2509 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2514 GLXFBConfig
* cfgs
= NULL
;
2518 WineGLPixelFormat
*fmt
;
2522 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2523 if (NULL
!= pfAttribFList
) {
2524 FIXME("unused pfAttribFList\n");
2527 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2528 if (-1 == nAttribs
) {
2529 WARN("Cannot convert WGL to GLX attributes\n");
2532 PUSH1(attribs
, None
);
2534 /* Search for FB configurations matching the requirements in attribs */
2535 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2537 WARN("Compatible Pixel Format not found\n");
2541 /* Loop through all matching formats and check if they are suitable.
2542 * Note that this function should at max return nMaxFormats different formats */
2543 for(run
=0; run
< 2; run
++)
2545 for (it
= 0; it
< nCfgs
; ++it
) {
2546 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2548 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2552 /* Search for the format in our list of compatible formats */
2553 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
);
2557 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2558 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2561 if(pfmt_it
< nMaxFormats
) {
2562 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2563 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2569 *nNumFormats
= pfmt_it
;
2576 * X11DRV_wglGetPixelFormatAttribivARB
2578 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2580 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2583 WineGLPixelFormat
*fmt
= NULL
;
2587 int nWGLFormats
= 0;
2589 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2591 if (0 < iLayerPlane
) {
2592 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2596 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2597 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2598 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2599 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2601 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2604 for (i
= 0; i
< nAttributes
; ++i
) {
2605 const int curWGLAttr
= piAttributes
[i
];
2606 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2608 switch (curWGLAttr
) {
2609 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2610 piValues
[i
] = nWGLFormats
;
2613 case WGL_SUPPORT_OPENGL_ARB
:
2614 piValues
[i
] = GL_TRUE
;
2617 case WGL_ACCELERATION_ARB
:
2618 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2619 if (!fmt
) goto pix_error
;
2620 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2621 if (hTest
) goto get_error
;
2623 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2624 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
; break;
2625 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2627 ERR("unexpected Config Caveat(%x)\n", tmp
);
2628 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2632 case WGL_TRANSPARENT_ARB
:
2633 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2634 if (!fmt
) goto pix_error
;
2635 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2636 if (hTest
) goto get_error
;
2637 piValues
[i
] = GL_FALSE
;
2638 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2641 case WGL_PIXEL_TYPE_ARB
:
2642 curGLXAttr
= GLX_RENDER_TYPE
;
2643 if (!fmt
) goto pix_error
;
2644 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2645 if (hTest
) goto get_error
;
2646 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2647 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2648 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2649 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2650 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2652 ERR("unexpected RenderType(%x)\n", tmp
);
2653 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2657 case WGL_COLOR_BITS_ARB
:
2658 curGLXAttr
= GLX_BUFFER_SIZE
;
2661 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2662 if (use_render_texture_ati
) {
2663 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2666 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2667 if (use_render_texture_ati
) {
2668 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2671 if (!use_render_texture_emulation
) {
2672 piValues
[i
] = GL_FALSE
;
2675 curGLXAttr
= GLX_RENDER_TYPE
;
2676 if (!fmt
) goto pix_error
;
2677 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2678 if (hTest
) goto get_error
;
2679 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2680 piValues
[i
] = GL_FALSE
;
2683 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2684 if (hTest
) goto get_error
;
2685 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2688 case WGL_BLUE_BITS_ARB
:
2689 curGLXAttr
= GLX_BLUE_SIZE
;
2691 case WGL_RED_BITS_ARB
:
2692 curGLXAttr
= GLX_RED_SIZE
;
2694 case WGL_GREEN_BITS_ARB
:
2695 curGLXAttr
= GLX_GREEN_SIZE
;
2697 case WGL_ALPHA_BITS_ARB
:
2698 curGLXAttr
= GLX_ALPHA_SIZE
;
2700 case WGL_DEPTH_BITS_ARB
:
2701 curGLXAttr
= GLX_DEPTH_SIZE
;
2703 case WGL_STENCIL_BITS_ARB
:
2704 curGLXAttr
= GLX_STENCIL_SIZE
;
2706 case WGL_DOUBLE_BUFFER_ARB
:
2707 curGLXAttr
= GLX_DOUBLEBUFFER
;
2709 case WGL_STEREO_ARB
:
2710 curGLXAttr
= GLX_STEREO
;
2712 case WGL_AUX_BUFFERS_ARB
:
2713 curGLXAttr
= GLX_AUX_BUFFERS
;
2716 case WGL_SUPPORT_GDI_ARB
:
2717 if (!fmt
) goto pix_error
;
2718 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &tmp
);
2719 if (hTest
) goto get_error
;
2721 piValues
[i
] = GL_FALSE
;
2724 curGLXAttr
= GLX_X_RENDERABLE
;
2727 case WGL_DRAW_TO_WINDOW_ARB
:
2728 case WGL_DRAW_TO_BITMAP_ARB
:
2729 case WGL_DRAW_TO_PBUFFER_ARB
:
2730 if (!fmt
) goto pix_error
;
2731 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2732 if (hTest
) goto get_error
;
2733 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2734 (curWGLAttr
== WGL_DRAW_TO_BITMAP_ARB
&& (tmp
&GLX_PIXMAP_BIT
)) ||
2735 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2736 piValues
[i
] = GL_TRUE
;
2738 piValues
[i
] = GL_FALSE
;
2741 case WGL_PBUFFER_LARGEST_ARB
:
2742 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2745 case WGL_SAMPLE_BUFFERS_ARB
:
2746 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2749 case WGL_SAMPLES_ARB
:
2750 curGLXAttr
= GLX_SAMPLES_ARB
;
2753 case WGL_FLOAT_COMPONENTS_NV
:
2754 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2757 case WGL_ACCUM_RED_BITS_ARB
:
2758 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2760 case WGL_ACCUM_GREEN_BITS_ARB
:
2761 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2763 case WGL_ACCUM_BLUE_BITS_ARB
:
2764 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2766 case WGL_ACCUM_ALPHA_BITS_ARB
:
2767 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2769 case WGL_ACCUM_BITS_ARB
:
2770 if (!fmt
) goto pix_error
;
2771 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2772 if (hTest
) goto get_error
;
2774 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2775 if (hTest
) goto get_error
;
2777 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2778 if (hTest
) goto get_error
;
2780 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2781 if (hTest
) goto get_error
;
2786 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2789 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2790 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2791 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2793 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2794 * and check which options can work using iPixelFormat=0 and which not.
2795 * A problem would be that this function is an extension. This would
2796 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2798 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2799 if (!fmt
) goto pix_error
;
2800 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2801 if (hTest
) goto get_error
;
2804 piValues
[i
] = GL_FALSE
;
2810 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2814 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2819 * X11DRV_wglGetPixelFormatAttribfvARB
2821 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2823 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2829 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2831 /* Allocate a temporary array to store integer values */
2832 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2834 ERR("couldn't allocate %d array\n", nAttributes
);
2838 /* Piggy-back on wglGetPixelFormatAttribivARB */
2839 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2841 /* Convert integer values to float. Should also check for attributes
2842 that can give decimal values here */
2843 for (i
=0; i
<nAttributes
;i
++) {
2844 pfValues
[i
] = attr
[i
];
2848 HeapFree(GetProcessHeap(), 0, attr
);
2853 * X11DRV_wglBindTexImageARB
2855 * WGL_ARB_render_texture: wglBindTexImageARB
2857 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2859 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2860 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2861 if (NULL
== object
) {
2862 SetLastError(ERROR_INVALID_HANDLE
);
2865 if (!object
->use_render_texture
) {
2866 SetLastError(ERROR_INVALID_HANDLE
);
2870 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2871 static int init
= 0;
2872 int prev_binded_texture
= 0;
2873 GLXContext prev_context
= pglXGetCurrentContext();
2874 Drawable prev_drawable
= pglXGetCurrentDrawable();
2875 GLXContext tmp_context
;
2877 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2878 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2879 isn't ideal performance wise but I wasn't able to get other ways working.
2882 init
= 1; /* Only show the FIXME once for performance reasons */
2883 FIXME("partial stub!\n");
2886 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
2887 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2889 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2891 /* Switch to our pbuffer */
2892 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2894 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2895 * After that upload the pbuffer texture data. */
2896 pglBindTexture(object
->texture_target
, prev_binded_texture
);
2897 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2899 /* Switch back to the original drawable and upload the pbuffer-texture */
2900 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
2901 pglXDestroyContext(gdi_display
, tmp_context
);
2905 if (NULL
!= pglXBindTexImageATI
) {
2910 case WGL_FRONT_LEFT_ARB
:
2911 buffer
= GLX_FRONT_LEFT_ATI
;
2913 case WGL_FRONT_RIGHT_ARB
:
2914 buffer
= GLX_FRONT_RIGHT_ATI
;
2916 case WGL_BACK_LEFT_ARB
:
2917 buffer
= GLX_BACK_LEFT_ATI
;
2919 case WGL_BACK_RIGHT_ARB
:
2920 buffer
= GLX_BACK_RIGHT_ATI
;
2923 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2927 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
2928 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
2929 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
2930 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
2931 * works fine using our pbuffer emulation path.
2933 return pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
2939 * X11DRV_wglReleaseTexImageARB
2941 * WGL_ARB_render_texture: wglReleaseTexImageARB
2943 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2945 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2946 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2947 if (NULL
== object
) {
2948 SetLastError(ERROR_INVALID_HANDLE
);
2951 if (!object
->use_render_texture
) {
2952 SetLastError(ERROR_INVALID_HANDLE
);
2955 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2958 if (NULL
!= pglXReleaseTexImageATI
) {
2963 case WGL_FRONT_LEFT_ARB
:
2964 buffer
= GLX_FRONT_LEFT_ATI
;
2966 case WGL_FRONT_RIGHT_ARB
:
2967 buffer
= GLX_FRONT_RIGHT_ATI
;
2969 case WGL_BACK_LEFT_ARB
:
2970 buffer
= GLX_BACK_LEFT_ATI
;
2972 case WGL_BACK_RIGHT_ARB
:
2973 buffer
= GLX_BACK_RIGHT_ATI
;
2976 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2979 return pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
2985 * X11DRV_wglGetExtensionsStringEXT
2987 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2989 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
2990 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2991 return WineGLInfo
.wglExtensions
;
2995 * X11DRV_wglGetSwapIntervalEXT
2997 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2999 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3000 FIXME("(),stub!\n");
3001 return swap_interval
;
3005 * X11DRV_wglSwapIntervalEXT
3007 * WGL_EXT_swap_control: wglSwapIntervalEXT
3009 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3010 TRACE("(%d)\n", interval
);
3011 swap_interval
= interval
;
3012 if (NULL
!= pglXSwapIntervalSGI
) {
3013 return 0 == pglXSwapIntervalSGI(interval
);
3015 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3020 * X11DRV_wglAllocateMemoryNV
3022 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3024 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3025 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3026 if (pglXAllocateMemoryNV
== NULL
)
3029 return pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3033 * X11DRV_wglFreeMemoryNV
3035 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3037 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3038 TRACE("(%p)\n", pointer
);
3039 if (pglXFreeMemoryNV
== NULL
)
3042 pglXFreeMemoryNV(pointer
);
3046 * glxRequireVersion (internal)
3048 * Check if the supported GLX version matches requiredVersion.
3050 static BOOL
glxRequireVersion(int requiredVersion
)
3052 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3053 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3059 static BOOL
glxRequireExtension(const char *requiredExtension
)
3061 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3068 static void register_extension_string(const char *ext
)
3070 if (WineGLInfo
.wglExtensions
[0])
3071 strcat(WineGLInfo
.wglExtensions
, " ");
3072 strcat(WineGLInfo
.wglExtensions
, ext
);
3074 TRACE("'%s'\n", ext
);
3077 static BOOL
register_extension(const WineGLExtension
* ext
)
3081 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3082 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3084 register_extension_string(ext
->extName
);
3086 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3087 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3092 static const WineGLExtension WGL_internal_functions
=
3096 { "wglDisable", X11DRV_wglDisable
},
3097 { "wglEnable", X11DRV_wglEnable
},
3098 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3099 { "wglIsEnabled", X11DRV_wglIsEnabled
},
3100 { "wglScissor", X11DRV_wglScissor
},
3101 { "wglViewport", X11DRV_wglViewport
},
3106 static const WineGLExtension WGL_ARB_extensions_string
=
3108 "WGL_ARB_extensions_string",
3110 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3114 static const WineGLExtension WGL_ARB_make_current_read
=
3116 "WGL_ARB_make_current_read",
3118 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3119 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3123 static const WineGLExtension WGL_ARB_multisample
=
3125 "WGL_ARB_multisample",
3128 static const WineGLExtension WGL_ARB_pbuffer
=
3132 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3133 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3134 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3135 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3136 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3137 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3141 static const WineGLExtension WGL_ARB_pixel_format
=
3143 "WGL_ARB_pixel_format",
3145 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3146 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3147 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3151 static const WineGLExtension WGL_ARB_render_texture
=
3153 "WGL_ARB_render_texture",
3155 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3156 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3160 static const WineGLExtension WGL_EXT_extensions_string
=
3162 "WGL_EXT_extensions_string",
3164 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3168 static const WineGLExtension WGL_EXT_swap_control
=
3170 "WGL_EXT_swap_control",
3172 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3173 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3177 static const WineGLExtension WGL_NV_vertex_array_range
=
3179 "WGL_NV_vertex_array_range",
3181 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3182 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3187 * X11DRV_WineGL_LoadExtensions
3189 static void X11DRV_WineGL_LoadExtensions(void)
3191 WineGLInfo
.wglExtensions
[0] = 0;
3193 /* Load Wine internal functions */
3194 register_extension(&WGL_internal_functions
);
3196 /* ARB Extensions */
3198 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3200 register_extension_string("WGL_ARB_pixel_format_float");
3201 register_extension_string("WGL_ATI_pixel_format_float");
3204 register_extension(&WGL_ARB_extensions_string
);
3206 if (glxRequireVersion(3))
3207 register_extension(&WGL_ARB_make_current_read
);
3209 if (glxRequireExtension("GLX_ARB_multisample"))
3210 register_extension(&WGL_ARB_multisample
);
3212 /* In general pbuffer functionality requires support in the X-server. The functionality is
3213 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3214 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3215 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3217 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3218 * without support in the X-server (which other Mesa based drivers require).
3220 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3221 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3222 * is available pbuffers must be available too. */
3223 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3224 register_extension(&WGL_ARB_pbuffer
);
3226 register_extension(&WGL_ARB_pixel_format
);
3228 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3229 if (glxRequireExtension("GLX_ATI_render_texture") ||
3230 glxRequireExtension("GLX_ARB_render_texture") ||
3231 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3233 register_extension(&WGL_ARB_render_texture
);
3235 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3236 if(glxRequireExtension("GLX_NV_float_buffer"))
3237 register_extension_string("WGL_NV_float_buffer");
3239 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3240 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3241 register_extension_string("WGL_NV_texture_rectangle");
3244 /* EXT Extensions */
3246 register_extension(&WGL_EXT_extensions_string
);
3248 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3249 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3250 register_extension(&WGL_EXT_swap_control
);
3252 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3253 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3254 register_extension(&WGL_NV_vertex_array_range
);
3258 static XID
create_glxpixmap(X11DRV_PDEVICE
*physDev
)
3262 XVisualInfo
template;
3267 /* Retrieve the visualid from our main visual which is the only visual we can use */
3268 template.visualid
= XVisualIDFromVisual(visual
);
3269 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
3271 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
3273 wine_tsx11_unlock();
3274 TRACE("return %lx\n", ret
);
3278 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3284 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3285 ret
= physDev
->drawable
; /* PBuffer */
3288 if(!physDev
->bitmap
->glxpixmap
)
3289 physDev
->bitmap
->glxpixmap
= create_glxpixmap(physDev
);
3290 ret
= physDev
->bitmap
->glxpixmap
;
3294 ret
= physDev
->drawable
;
3298 BOOL
destroy_glxpixmap(XID glxpixmap
)
3301 pglXDestroyGLXPixmap(gdi_display
, glxpixmap
);
3302 wine_tsx11_unlock();
3307 * X11DRV_SwapBuffers
3309 * Swap the buffers of this DC
3311 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3313 GLXDrawable drawable
;
3314 if (!has_opengl()) {
3315 ERR("No libGL on this box - disabling OpenGL support !\n");
3319 TRACE_(opengl
)("(%p)\n", physDev
);
3321 drawable
= get_glxdrawable(physDev
);
3323 pglXSwapBuffers(gdi_display
, drawable
);
3324 wine_tsx11_unlock();
3329 static long prev_time
, frames
;
3331 DWORD time
= GetTickCount();
3333 /* every 1.5 seconds */
3334 if (time
- prev_time
> 1500) {
3335 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
3344 /***********************************************************************
3345 * X11DRV_setup_opengl_visual
3347 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3348 * window (if it exists). If OpenGL isn't available, the visual is simply
3349 * set to the default visual for the display
3351 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3353 XVisualInfo
*visual
= NULL
;
3356 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3357 * D3D and some applications can make use of aux buffers.
3359 int visualProperties
[][11] = {
3360 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_AUX_BUFFERS
, 1, None
},
3361 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, None
},
3362 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, None
},
3363 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, None
},
3370 for (i
= 0; i
< sizeof(visualProperties
)/sizeof(visualProperties
[0]); ++i
) {
3371 visual
= pglXChooseVisual(display
, DefaultScreen(display
), visualProperties
[i
]);
3375 wine_tsx11_unlock();
3378 TRACE("Visual ID %lx Chosen\n", visual
->visualid
);
3380 WARN("No suitable visual found\n");
3385 #else /* no OpenGL includes */
3387 /***********************************************************************
3388 * ChoosePixelFormat (X11DRV.@)
3390 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3391 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3392 ERR("No OpenGL support compiled in.\n");
3397 /***********************************************************************
3398 * DescribePixelFormat (X11DRV.@)
3400 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3403 PIXELFORMATDESCRIPTOR
*ppfd
) {
3404 ERR("No OpenGL support compiled in.\n");
3409 /***********************************************************************
3410 * GetPixelFormat (X11DRV.@)
3412 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3413 ERR("No OpenGL support compiled in.\n");
3418 /***********************************************************************
3419 * SetPixelFormat (X11DRV.@)
3421 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3423 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3424 ERR("No OpenGL support compiled in.\n");
3429 /***********************************************************************
3430 * SwapBuffers (X11DRV.@)
3432 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3433 ERR_(opengl
)("No OpenGL support compiled in.\n");
3439 * X11DRV_wglCreateContext
3441 * For OpenGL32 wglCreateContext.
3443 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3444 ERR_(opengl
)("No OpenGL support compiled in.\n");
3449 * X11DRV_wglDeleteContext
3451 * For OpenGL32 wglDeleteContext.
3453 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3454 ERR_(opengl
)("No OpenGL support compiled in.\n");
3459 * X11DRV_wglGetProcAddress
3461 * For OpenGL32 wglGetProcAddress.
3463 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3464 ERR_(opengl
)("No OpenGL support compiled in.\n");
3468 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3470 ERR_(opengl
)("No OpenGL support compiled in.\n");
3474 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3475 ERR_(opengl
)("No OpenGL support compiled in.\n");
3480 * X11DRV_wglMakeCurrent
3482 * For OpenGL32 wglMakeCurrent.
3484 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3485 ERR_(opengl
)("No OpenGL support compiled in.\n");
3490 * X11DRV_wglShareLists
3492 * For OpenGL32 wglShaderLists.
3494 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3495 ERR_(opengl
)("No OpenGL support compiled in.\n");
3500 * X11DRV_wglUseFontBitmapsA
3502 * For OpenGL32 wglUseFontBitmapsA.
3504 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3506 ERR_(opengl
)("No OpenGL support compiled in.\n");
3511 * X11DRV_wglUseFontBitmapsW
3513 * For OpenGL32 wglUseFontBitmapsW.
3515 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3517 ERR_(opengl
)("No OpenGL support compiled in.\n");
3521 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3526 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3531 BOOL
destroy_glxpixmap(XID glxpixmap
)
3536 #endif /* defined(HAVE_OPENGL) */