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
;
114 Drawable drawables
[2];
115 BOOL refresh_drawables
;
116 struct wine_glcontext
*next
;
117 struct wine_glcontext
*prev
;
120 typedef struct wine_glpbuffer
{
123 WineGLPixelFormat
* fmt
;
129 int use_render_texture
; /* This is also the internal texture format */
130 int texture_bind_target
;
132 GLint texture_format
;
133 GLuint texture_target
;
139 static Wine_GLContext
*context_list
;
140 static struct WineGLInfo WineGLInfo
= { 0 };
141 static int use_render_texture_emulation
= 1;
142 static int use_render_texture_ati
= 0;
143 static int swap_interval
= 1;
145 #define MAX_EXTENSIONS 16
146 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
147 static int WineGLExtensionListSize
;
149 static WineGLPixelFormat
*WineGLPixelFormatList
;
150 static int WineGLPixelFormatListSize
= 0;
151 static int WineGLPixelFormatOnScreenSize
= 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(glDrawBuffer
)
266 MAKE_FUNCPTR(glEndList
)
267 MAKE_FUNCPTR(glGetError
)
268 MAKE_FUNCPTR(glGetIntegerv
)
269 MAKE_FUNCPTR(glGetString
)
270 MAKE_FUNCPTR(glNewList
)
271 MAKE_FUNCPTR(glPixelStorei
)
272 MAKE_FUNCPTR(glReadPixels
)
273 MAKE_FUNCPTR(glTexImage2D
)
274 MAKE_FUNCPTR(glFinish
)
275 MAKE_FUNCPTR(glFlush
)
278 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
280 static BOOL infoInitialized
= FALSE
;
282 int screen
= DefaultScreen(gdi_display
);
283 Window win
= RootWindow(gdi_display
, screen
);
285 XVisualInfo
template;
288 GLXContext ctx
= NULL
;
292 infoInitialized
= TRUE
;
296 visual
= DefaultVisual(gdi_display
, screen
);
297 template.visualid
= XVisualIDFromVisual(visual
);
298 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
300 WORD old_fs
= wine_get_fs();
301 /* Create a GLX Context. Without one we can't query GL information */
302 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
303 if (wine_get_fs() != old_fs
)
305 wine_set_fs( old_fs
);
307 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
308 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
314 pglXMakeCurrent(gdi_display
, win
, ctx
);
316 ERR(" couldn't initialize OpenGL, expect problems\n");
321 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
322 WineGLInfo
.glExtensions
= strdup((const char *) pglGetString(GL_EXTENSIONS
));
324 /* Get the common GLX version supported by GLX client and server ( major/minor) */
325 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
327 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
328 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
329 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
331 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
332 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
333 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
335 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
336 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
338 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
339 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
340 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
341 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
342 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
343 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
344 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
345 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
349 pglXMakeCurrent(gdi_display
, None
, NULL
);
350 pglXDestroyContext(gdi_display
, ctx
);
356 static BOOL
has_opengl(void)
358 static int init_done
;
359 static void *opengl_handle
;
361 int error_base
, event_base
;
363 if (init_done
) return (opengl_handle
!= NULL
);
366 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
367 and include all dependencies */
368 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0);
369 if (opengl_handle
== NULL
) return FALSE
;
371 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
372 if (pglXGetProcAddressARB
== NULL
) {
373 ERR("could not find glXGetProcAddressARB in libGL.\n");
377 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
379 LOAD_FUNCPTR(glXChooseVisual
)
380 LOAD_FUNCPTR(glXCreateContext
)
381 LOAD_FUNCPTR(glXCreateGLXPixmap
)
382 LOAD_FUNCPTR(glXGetCurrentContext
)
383 LOAD_FUNCPTR(glXGetCurrentDrawable
)
384 LOAD_FUNCPTR(glXDestroyContext
)
385 LOAD_FUNCPTR(glXDestroyGLXPixmap
)
386 LOAD_FUNCPTR(glXGetConfig
)
387 LOAD_FUNCPTR(glXIsDirect
)
388 LOAD_FUNCPTR(glXMakeCurrent
)
389 LOAD_FUNCPTR(glXSwapBuffers
)
390 LOAD_FUNCPTR(glXQueryExtension
)
391 LOAD_FUNCPTR(glXQueryVersion
)
392 LOAD_FUNCPTR(glXUseXFont
)
395 LOAD_FUNCPTR(glXGetClientString
)
396 LOAD_FUNCPTR(glXQueryExtensionsString
)
397 LOAD_FUNCPTR(glXQueryServerString
)
400 LOAD_FUNCPTR(glXCreatePbuffer
)
401 LOAD_FUNCPTR(glXCreateNewContext
)
402 LOAD_FUNCPTR(glXDestroyPbuffer
)
403 LOAD_FUNCPTR(glXMakeContextCurrent
)
404 LOAD_FUNCPTR(glXGetCurrentReadDrawable
)
405 LOAD_FUNCPTR(glXGetFBConfigs
)
407 /* Standard OpenGL calls */
408 LOAD_FUNCPTR(glBindTexture
)
409 LOAD_FUNCPTR(glBitmap
)
410 LOAD_FUNCPTR(glCopyTexSubImage1D
)
411 LOAD_FUNCPTR(glCopyTexImage2D
)
412 LOAD_FUNCPTR(glCopyTexSubImage2D
)
413 LOAD_FUNCPTR(glDrawBuffer
)
414 LOAD_FUNCPTR(glEndList
)
415 LOAD_FUNCPTR(glGetError
)
416 LOAD_FUNCPTR(glGetIntegerv
)
417 LOAD_FUNCPTR(glGetString
)
418 LOAD_FUNCPTR(glNewList
)
419 LOAD_FUNCPTR(glPixelStorei
)
420 LOAD_FUNCPTR(glReadPixels
)
421 LOAD_FUNCPTR(glTexImage2D
)
422 LOAD_FUNCPTR(glFinish
)
423 LOAD_FUNCPTR(glFlush
)
426 /* It doesn't matter if these fail. They'll only be used if the driver reports
427 the associated extension is available (and if a driver reports the extension
428 is available but fails to provide the functions, it's quite broken) */
429 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
430 /* NV GLX Extension */
431 LOAD_FUNCPTR(glXAllocateMemoryNV
)
432 LOAD_FUNCPTR(glXFreeMemoryNV
)
435 if(!X11DRV_WineGL_InitOpenglInfo()) {
436 wine_dlclose(opengl_handle
, NULL
, 0);
437 opengl_handle
= NULL
;
442 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
) == True
) {
443 TRACE("GLX is up and running error_base = %d\n", error_base
);
445 wine_dlclose(opengl_handle
, NULL
, 0);
446 opengl_handle
= NULL
;
449 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
450 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
453 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
454 * depends on the reported GLX client / server version and on the client / server extension list.
455 * Those don't have to be the same.
457 * In general the server GLX information lists the capabilities in case of indirect rendering.
458 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
459 * available and in that case the client GLX informat can be used.
460 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
461 * in the GLX version/extension list. When a program does this it works for certain for both
462 * direct and indirect rendering.
464 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
465 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
466 * extension list which causes this extension not to be listed. (Wine requires this extension).
467 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
468 * pbuffers is around.
470 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
471 * the ATI drivers and from then on use GLX client information for them.
474 if(glxRequireVersion(3)) {
475 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
476 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
477 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
478 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
479 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
480 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
481 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
482 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
484 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
485 * enable this function when the Xserver understand GLX 1.3 or newer
487 pglXQueryDrawable
= NULL
;
488 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
489 TRACE("Overriding ATI GLX capabilities!\n");
490 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
491 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
492 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
493 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
495 /* Use client GLX information in case of the ATI drivers. We override the
496 * capabilities over here and not somewhere else as ATI might better their
497 * life in the future. In case they release proper drivers this block of
498 * code won't be called. */
499 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
501 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
504 if(glxRequireExtension("GLX_ATI_render_texture")) {
505 use_render_texture_ati
= 1;
506 pglXBindTexImageATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
507 pglXReleaseTexImageATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
508 pglXDrawableAttribATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
511 X11DRV_WineGL_LoadExtensions();
514 return (opengl_handle
!= NULL
);
517 wine_dlclose(opengl_handle
, NULL
, 0);
518 opengl_handle
= NULL
;
522 static inline Wine_GLContext
*alloc_context(void)
526 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
528 ret
->next
= context_list
;
529 if (context_list
) context_list
->prev
= ret
;
535 static inline void free_context(Wine_GLContext
*context
)
537 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
538 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
539 else context_list
= context
->next
;
541 if (context
->vis
) XFree(context
->vis
);
542 HeapFree(GetProcessHeap(), 0, context
);
545 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
548 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
549 return (ptr
!= NULL
);
552 static int describeContext(Wine_GLContext
* ctx
) {
555 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
556 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
557 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
558 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
559 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
564 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
567 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
570 if (pglXQueryDrawable
== NULL
) {
571 /** glXQueryDrawable not available so returns not supported */
575 TRACE(" Drawable %p have :\n", (void*) drawable
);
576 pglXQueryDrawable(gdi_display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
577 TRACE(" - WIDTH as %d\n", tmp
);
578 pglXQueryDrawable(gdi_display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
579 TRACE(" - HEIGHT as %d\n", tmp
);
580 pglXQueryDrawable(gdi_display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
581 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
584 fbCfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribList
, &nElements
);
585 if (fbCfgs
== NULL
) {
589 pglXGetFBConfigAttrib(gdi_display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
590 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
597 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
602 int nvfloatattrib
= GLX_DONT_CARE
;
605 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
606 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
607 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
608 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
610 switch (iWGLAttr
[cur
]) {
611 case WGL_COLOR_BITS_ARB
:
612 pop
= iWGLAttr
[++cur
];
613 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
614 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
616 case WGL_BLUE_BITS_ARB
:
617 pop
= iWGLAttr
[++cur
];
618 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
619 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
621 case WGL_RED_BITS_ARB
:
622 pop
= iWGLAttr
[++cur
];
623 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
624 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
626 case WGL_GREEN_BITS_ARB
:
627 pop
= iWGLAttr
[++cur
];
628 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
629 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
631 case WGL_ALPHA_BITS_ARB
:
632 pop
= iWGLAttr
[++cur
];
633 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
634 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
636 case WGL_DEPTH_BITS_ARB
:
637 pop
= iWGLAttr
[++cur
];
638 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
639 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
641 case WGL_STENCIL_BITS_ARB
:
642 pop
= iWGLAttr
[++cur
];
643 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
644 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
646 case WGL_DOUBLE_BUFFER_ARB
:
647 pop
= iWGLAttr
[++cur
];
648 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
649 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
652 case WGL_PIXEL_TYPE_ARB
:
653 pop
= iWGLAttr
[++cur
];
654 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
656 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
657 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
658 /* 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 */
659 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
661 ERR("unexpected PixelType(%x)\n", pop
);
666 case WGL_SUPPORT_GDI_ARB
:
667 pop
= iWGLAttr
[++cur
];
668 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
669 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
672 case WGL_DRAW_TO_BITMAP_ARB
:
673 pop
= iWGLAttr
[++cur
];
674 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
675 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
677 drawattrib
|= GLX_PIXMAP_BIT
;
681 case WGL_DRAW_TO_WINDOW_ARB
:
682 pop
= iWGLAttr
[++cur
];
683 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
684 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
686 drawattrib
|= GLX_WINDOW_BIT
;
690 case WGL_DRAW_TO_PBUFFER_ARB
:
691 pop
= iWGLAttr
[++cur
];
692 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
693 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
695 drawattrib
|= GLX_PBUFFER_BIT
;
699 case WGL_ACCELERATION_ARB
:
700 case WGL_SUPPORT_OPENGL_ARB
:
701 pop
= iWGLAttr
[++cur
];
702 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
703 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
706 case WGL_PBUFFER_LARGEST_ARB
:
707 pop
= iWGLAttr
[++cur
];
708 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
709 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
712 case WGL_SAMPLE_BUFFERS_ARB
:
713 pop
= iWGLAttr
[++cur
];
714 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
715 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
718 case WGL_SAMPLES_ARB
:
719 pop
= iWGLAttr
[++cur
];
720 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
721 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
724 case WGL_TEXTURE_FORMAT_ARB
:
725 case WGL_TEXTURE_TARGET_ARB
:
726 case WGL_MIPMAP_TEXTURE_ARB
:
727 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
728 pop
= iWGLAttr
[++cur
];
730 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
732 if (use_render_texture_ati
) {
733 /** nothing to do here */
735 else if (!use_render_texture_emulation
) {
736 if (WGL_NO_TEXTURE_ARB
!= pop
) {
737 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
738 return -1; /** error: don't support it */
740 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
741 drawattrib
|= GLX_PBUFFER_BIT
;
745 case WGL_FLOAT_COMPONENTS_NV
:
746 nvfloatattrib
= iWGLAttr
[++cur
];
747 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
749 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
750 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
751 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
752 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
753 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
754 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
755 pop
= iWGLAttr
[++cur
];
756 /** cannot be converted, see direct handling on
757 * - wglGetPixelFormatAttribivARB
758 * TODO: wglChoosePixelFormat
763 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
769 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
770 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
771 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
772 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
774 /* Set GLX_RENDER_TYPE all the time */
775 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
776 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
778 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
779 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
780 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
781 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
787 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
789 int render_type
=0, render_type_bit
;
790 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
791 switch(render_type_bit
)
794 render_type
= GLX_RGBA_TYPE
;
796 case GLX_COLOR_INDEX_BIT
:
797 render_type
= GLX_COLOR_INDEX_TYPE
;
799 case GLX_RGBA_FLOAT_BIT
:
800 render_type
= GLX_RGBA_FLOAT_TYPE
;
803 ERR("Unknown render_type: %x\n", render_type
);
808 static BOOL
init_formats(Display
*display
, int screen
, Visual
*visual
)
810 int fmt_id
, tmp_fmt_id
, nCfgs
, i
;
812 GLXFBConfig fbconfig
= NULL
;
813 XVisualInfo
*visinfo
;
814 VisualID visualid
= XVisualIDFromVisual(visual
);
815 int nOffscreenFormats
= 0;
817 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
818 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
819 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
820 * because this call lists both types of formats instead of only onscreen ones. */
821 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
822 if (NULL
== cfgs
|| 0 == nCfgs
) {
823 ERR("glXChooseFBConfig returns NULL\n");
824 if(cfgs
!= NULL
) XFree(cfgs
);
828 /* Count the number of offscreen formats to determine the size for our pixelformat list */
829 for(i
=0; i
<nCfgs
; i
++) {
830 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
832 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
833 /* Onscreen formats have a corresponding XVisual, offscreen ones don't */
836 } else if(visinfo
&& visinfo
->visualid
== visualid
) {
837 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
842 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats
);
844 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
845 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (1+nOffscreenFormats
)*sizeof(WineGLPixelFormat
));
846 WineGLPixelFormatList
[0].iPixelFormat
= 1;
847 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
848 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
849 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
850 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
851 WineGLPixelFormatListSize
= 1;
852 WineGLPixelFormatOnScreenSize
= 1;
854 /* Fill the list with offscreen formats */
855 for(i
=0; i
<nCfgs
; i
++) {
856 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
858 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
859 /* We have found an offscreen rendering format when there is no visualinfo :) */
861 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id
, WineGLPixelFormatListSize
+1, i
);
862 WineGLPixelFormatList
[WineGLPixelFormatListSize
].iPixelFormat
= WineGLPixelFormatListSize
+1; /* The index starts at 1 */
863 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fbconfig
= cfgs
[i
];
864 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fmt_id
= tmp_fmt_id
;
865 WineGLPixelFormatList
[WineGLPixelFormatListSize
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
866 WineGLPixelFormatList
[WineGLPixelFormatListSize
].offscreenOnly
= TRUE
;
867 WineGLPixelFormatListSize
++;
873 if(cfgs
!= NULL
) XFree(cfgs
);
878 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
879 * In our WGL implementation we only support a subset of these formats namely the format of
880 * Wine's main visual and offscreen formats (if they are available).
881 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
882 * and it returns the number of supported WGL formats in fmt_count.
884 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
886 WineGLPixelFormat
*res
= NULL
;
888 /* Init the list of pixel formats when we need it */
889 if(!WineGLPixelFormatListSize
)
890 init_formats(display
, DefaultScreen(display
), visual
);
892 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
893 * iPixelFormat in case of probing the number of pixelformats.
895 if((iPixelFormat
> 0) && (iPixelFormat
<= WineGLPixelFormatListSize
) &&
896 ((WineGLPixelFormatList
[iPixelFormat
-1].offscreenOnly
== FALSE
) ||
898 res
= &WineGLPixelFormatList
[iPixelFormat
-1];
899 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
903 *fmt_count
= WineGLPixelFormatListSize
;
905 *fmt_count
= WineGLPixelFormatOnScreenSize
;
907 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
912 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
913 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
)
917 /* Init the list of pixel formats when we need it */
918 if(!WineGLPixelFormatListSize
)
919 init_formats(display
, DefaultScreen(display
), visual
);
921 for(i
=0; i
<WineGLPixelFormatListSize
; i
++) {
922 if(WineGLPixelFormatList
[i
].fmt_id
== fmt_id
) {
923 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList
[i
].iPixelFormat
, fmt_id
);
924 return &WineGLPixelFormatList
[i
];
927 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
931 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
933 WineGLPixelFormat
*fmt
;
935 if (!fbconfig_id
) return 0;
937 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
);
939 return fmt
->iPixelFormat
;
940 /* This will happen on hwnds without a pixel format set; it's ok */
945 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
946 void mark_drawable_dirty(Drawable old
, Drawable
new)
949 for (ctx
= context_list
; ctx
; ctx
= ctx
->next
) {
950 if (old
== ctx
->drawables
[0]) {
951 ctx
->drawables
[0] = new;
952 ctx
->refresh_drawables
= TRUE
;
954 if (old
== ctx
->drawables
[1]) {
955 ctx
->drawables
[1] = new;
956 ctx
->refresh_drawables
= TRUE
;
961 /* Given the current context, make sure its drawable is sync'd */
962 static inline void sync_context(Wine_GLContext
*context
)
964 if(context
&& context
->refresh_drawables
) {
965 if (glxRequireVersion(3))
966 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
967 context
->drawables
[1], context
->ctx
);
969 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
970 context
->refresh_drawables
= FALSE
;
975 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
977 return pglXCreateGLXPixmap(display
, vis
, parent
);
982 * X11DRV_ChoosePixelFormat
984 * Equivalent to glXChooseVisual.
986 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
987 const PIXELFORMATDESCRIPTOR
*ppfd
) {
988 WineGLPixelFormat
*fmt
= NULL
;
994 int bestDBuffer
= -1;
999 int bestStencil
= -1;
1003 if (!has_opengl()) {
1004 ERR("No libGL on this box - disabling OpenGL support !\n");
1008 if (TRACE_ON(opengl
)) {
1009 TRACE("(%p,%p)\n", physDev
, ppfd
);
1011 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
1015 ConvertPixelFormatWGLtoGLX(gdi_display
, 0, FALSE
/* offscreen */, &nPixelFormats
);
1016 for(i
=0; i
<nPixelFormats
; i
++)
1020 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1022 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, i
+1 /* 1-based index */, FALSE
/* offscreen */, &value
);
1026 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1027 if (value
& GLX_RGBA_BIT
)
1028 iPixelType
= PFD_TYPE_RGBA
;
1030 iPixelType
= PFD_TYPE_COLORINDEX
;
1032 if (ppfd
->iPixelType
!= iPixelType
)
1034 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1038 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1039 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1040 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1041 if (value
) dwFlags
|= PFD_STEREO
;
1042 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1043 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1044 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1045 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1046 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1048 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1049 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1050 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1051 * formats without the given flag set.
1052 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1053 * has indicated that a format without stereo is returned when stereo is unavailable.
1054 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1055 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1057 * To summarize the following is most likely the correct behavior:
1058 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1059 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1060 * stereo don't care -> it doesn't matter whether we get stereo or not
1062 * In Wine we will treat no-stereo the same way as don't care because it makes
1063 * format selection even more complicated and second drivers with Stereo advertise
1064 * each format twice anyway.
1067 /* Doublebuffer, see the comments above */
1068 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1069 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1070 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1072 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1073 bestStereo
= dwFlags
& PFD_STEREO
;
1077 bestStencil
= stencil
;
1082 if(bestDBuffer
!= -1 && (dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
)
1086 /* Stereo, see the comments above. */
1087 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1088 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1089 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1091 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1092 bestStereo
= dwFlags
& PFD_STEREO
;
1096 bestStencil
= stencil
;
1101 if(bestStereo
!= -1 && (dwFlags
& PFD_STEREO
) != bestStereo
)
1105 /* Below we will do a number of checks to select the 'best' pixelformat.
1106 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1107 * The code works by trying to match the most important options as close as possible.
1108 * When a reasonable format is found, we will try to match more options. */
1111 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1112 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1114 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1115 bestStereo
= dwFlags
& PFD_STEREO
;
1119 bestStencil
= stencil
;
1123 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1124 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1129 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1130 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1132 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1133 bestStereo
= dwFlags
& PFD_STEREO
;
1137 bestStencil
= stencil
;
1141 } else if(bestAlpha
!= alpha
) {
1142 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1147 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1148 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1150 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1151 bestStereo
= dwFlags
& PFD_STEREO
;
1155 bestStencil
= stencil
;
1159 } else if(bestDepth
!= depth
) {
1160 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1165 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1166 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1168 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1169 bestStereo
= dwFlags
& PFD_STEREO
;
1173 bestStencil
= stencil
;
1177 } else if(bestStencil
!= stencil
) {
1178 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1183 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1184 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1186 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1187 bestStereo
= dwFlags
& PFD_STEREO
;
1191 bestStencil
= stencil
;
1195 } else if(bestAux
!= aux
) {
1196 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1201 if(bestFormat
== -1) {
1202 TRACE("No matching mode was found returning 0\n");
1206 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1207 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, WineGLPixelFormatList
[bestFormat
].fmt_id
);
1210 wine_tsx11_unlock();
1215 * X11DRV_DescribePixelFormat
1217 * Get the pixel-format descriptor associated to the given id
1219 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1222 PIXELFORMATDESCRIPTOR
*ppfd
) {
1223 /*XVisualInfo *vis;*/
1226 WineGLPixelFormat
*fmt
;
1230 if (!has_opengl()) {
1231 ERR("No libGL on this box - disabling OpenGL support !\n");
1235 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1237 /* 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 */
1238 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1240 /* The application is only querying the number of pixelformats */
1242 } else if(fmt
== NULL
) {
1243 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1247 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1248 ERR("Wrong structure size !\n");
1249 /* Should set error */
1255 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1256 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1259 /* These flags are always the same... */
1260 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1261 /* Now the flags extracted from the Visual */
1265 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_X_RENDERABLE
, &value
);
1267 ppfd
->dwFlags
|= PFD_SUPPORT_GDI
;
1269 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1270 if(value
& GLX_WINDOW_BIT
)
1271 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1272 if(value
& GLX_PIXMAP_BIT
)
1273 ppfd
->dwFlags
|= PFD_DRAW_TO_BITMAP
;
1275 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_CONFIG_CAVEAT
, &value
);
1276 if(value
== GLX_SLOW_CONFIG
)
1277 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1279 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1281 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1282 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1284 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1287 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1288 if (value
& GLX_RGBA_BIT
)
1289 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1291 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1294 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1295 ppfd
->cColorBits
= value
;
1297 /* Red, green, blue and alpha bits / shifts */
1298 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1299 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1300 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1301 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1302 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1304 ppfd
->cRedBits
= rb
;
1305 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1306 ppfd
->cBlueBits
= bb
;
1307 ppfd
->cBlueShift
= ab
;
1308 ppfd
->cGreenBits
= gb
;
1309 ppfd
->cGreenShift
= bb
+ ab
;
1310 ppfd
->cAlphaBits
= ab
;
1311 ppfd
->cAlphaShift
= 0;
1314 ppfd
->cRedShift
= 0;
1315 ppfd
->cBlueBits
= 0;
1316 ppfd
->cBlueShift
= 0;
1317 ppfd
->cGreenBits
= 0;
1318 ppfd
->cGreenShift
= 0;
1319 ppfd
->cAlphaBits
= 0;
1320 ppfd
->cAlphaShift
= 0;
1323 /* Accum RGBA bits */
1324 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1325 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1326 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1327 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1329 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1330 ppfd
->cAccumRedBits
= rb
;
1331 ppfd
->cAccumGreenBits
= gb
;
1332 ppfd
->cAccumBlueBits
= bb
;
1333 ppfd
->cAccumAlphaBits
= ab
;
1336 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1337 ppfd
->cDepthBits
= value
;
1340 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1341 ppfd
->cStencilBits
= value
;
1343 wine_tsx11_unlock();
1345 /* Aux : to do ... */
1347 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1349 if (TRACE_ON(opengl
)) {
1350 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1357 * X11DRV_GetPixelFormat
1359 * Get the pixel-format id used by this DC
1361 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1362 WineGLPixelFormat
*fmt
;
1364 TRACE("(%p)\n", physDev
);
1366 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1369 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1370 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1373 else if(fmt
->offscreenOnly
)
1375 /* Offscreen formats can't be used with traditional WGL calls.
1376 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1377 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1381 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1382 return physDev
->current_pf
;
1386 * X11DRV_SetPixelFormat
1388 * Set the pixel-format id used by this DC
1390 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1392 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1393 WineGLPixelFormat
*fmt
;
1397 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1399 if (!has_opengl()) {
1400 ERR("No libGL on this box - disabling OpenGL support !\n");
1404 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1405 if(get_glxdrawable(physDev
) == root_window
)
1407 ERR("Invalid operation on root_window\n");
1411 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1412 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1414 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1418 if(physDev
->current_pf
) /* cannot change it if already set */
1419 return (physDev
->current_pf
== iPixelFormat
);
1421 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1423 hwnd
= WindowFromDC(physDev
->hdc
);
1425 if(!(value
&GLX_WINDOW_BIT
)) {
1426 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1430 if(!SendMessageW(hwnd
, WM_X11DRV_SET_WIN_FORMAT
, (WPARAM
)fmt
->fmt_id
, 0)) {
1431 ERR("Couldn't set format of the window, returning failure\n");
1435 physDev
->gl_drawable
= X11DRV_get_gl_drawable(hwnd
);
1438 physDev
->current_pf
= iPixelFormat
;
1440 if (TRACE_ON(opengl
)) {
1443 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1445 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1447 TRACE(" FBConfig have :\n");
1448 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1449 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1450 TRACE(" - VISUAL_ID 0x%x\n", value
);
1451 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1452 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1459 * X11DRV_wglCreateContext
1461 * For OpenGL32 wglCreateContext.
1463 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1465 Wine_GLContext
*ret
;
1466 WineGLPixelFormat
*fmt
;
1467 int hdcPF
= physDev
->current_pf
;
1469 HDC hdc
= physDev
->hdc
;
1471 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1473 if (!has_opengl()) {
1474 ERR("No libGL on this box - disabling OpenGL support !\n");
1478 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1479 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1480 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1481 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1482 * If this fails something is very wrong on the system. */
1484 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1485 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1489 /* The context will be allocated in the wglMakeCurrent call */
1491 ret
= alloc_context();
1492 wine_tsx11_unlock();
1494 ret
->physDev
= physDev
;
1498 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1500 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1505 * X11DRV_wglDeleteContext
1507 * For OpenGL32 wglDeleteContext.
1509 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1511 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1514 TRACE("(%p)\n", hglrc
);
1516 if (!has_opengl()) {
1517 ERR("No libGL on this box - disabling OpenGL support !\n");
1522 /* A game (Half Life not to name it) deletes twice the same context,
1523 * so make sure it is valid first */
1524 if (is_valid_context( ctx
))
1526 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1531 WARN("Error deleting context !\n");
1532 SetLastError(ERROR_INVALID_HANDLE
);
1535 wine_tsx11_unlock();
1541 * X11DRV_wglGetCurrentReadDCARB
1543 * For OpenGL32 wglGetCurrentReadDCARB.
1545 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1548 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1549 X11DRV_PDEVICE
*physDev
= ctx
? ctx
->pReadDev
: NULL
;
1554 TRACE(" returning %p (GL drawable %lu)\n", ret
, physDev
? physDev
->drawable
: 0);
1559 * X11DRV_wglGetProcAddress
1561 * For OpenGL32 wglGetProcAddress.
1563 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1566 const WineGLExtension
*ext
;
1568 int padding
= 32 - strlen(lpszProc
);
1572 if (!has_opengl()) {
1573 ERR("No libGL on this box - disabling OpenGL support !\n");
1577 /* Check the table of WGL extensions to see if we need to return a WGL extension
1578 * or a function pointer to a native OpenGL function. */
1579 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1580 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1582 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1583 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1584 ext
= WineGLExtensionList
[i
];
1585 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1586 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1587 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1588 return ext
->extEntryPoints
[j
].funcAddress
;
1594 WARN("(%s) - not found\n", lpszProc
);
1599 * X11DRV_wglMakeCurrent
1601 * For OpenGL32 wglMakeCurrent.
1603 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1605 HDC hdc
= physDev
->hdc
;
1606 DWORD type
= GetObjectType(hdc
);
1608 TRACE("(%p,%p)\n", hdc
, hglrc
);
1610 if (!has_opengl()) {
1611 ERR("No libGL on this box - disabling OpenGL support !\n");
1616 if (hglrc
== NULL
) {
1617 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1618 NtCurrentTeb()->glContext
= NULL
;
1620 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1621 Drawable drawable
= get_glxdrawable(physDev
);
1622 if (ctx
->ctx
== NULL
) {
1623 /* The describe lines below are for debugging purposes only */
1624 if (TRACE_ON(wgl
)) {
1625 describeDrawable(ctx
, drawable
);
1626 describeContext(ctx
);
1629 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1630 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1632 TRACE(" Creating GLX Context\n");
1634 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1635 else /* Create a GLX Context for a pbuffer */
1636 ctx
->ctx
= pglXCreateNewContext(gdi_display
, ctx
->fmt
->fbconfig
, ctx
->fmt
->render_type
, NULL
, True
);
1638 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1640 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1641 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1642 NtCurrentTeb()->glContext
= ctx
;
1646 ctx
->physDev
= physDev
;
1647 ctx
->pReadDev
= physDev
;
1648 ctx
->drawables
[0] = drawable
;
1649 ctx
->drawables
[1] = drawable
;
1650 ctx
->refresh_drawables
= FALSE
;
1652 if (type
== OBJ_MEMDC
)
1654 ctx
->do_escape
= TRUE
;
1655 pglDrawBuffer(GL_FRONT_LEFT
);
1659 wine_tsx11_unlock();
1660 TRACE(" returning %s\n", (ret
? "True" : "False"));
1665 * X11DRV_wglMakeContextCurrentARB
1667 * For OpenGL32 wglMakeContextCurrentARB
1669 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* pDrawDev
, X11DRV_PDEVICE
* pReadDev
, HGLRC hglrc
)
1672 int indirect
= (GetObjectType(pDrawDev
->hdc
) == OBJ_MEMDC
);
1674 TRACE("(%p,%p,%p)\n", pDrawDev
, pReadDev
, hglrc
);
1676 if (!has_opengl()) {
1677 ERR("No libGL on this box - disabling OpenGL support !\n");
1682 if (hglrc
== NULL
) {
1683 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1684 NtCurrentTeb()->glContext
= NULL
;
1686 if (NULL
== pglXMakeContextCurrent
) {
1689 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1690 Drawable d_draw
= get_glxdrawable(pDrawDev
);
1691 Drawable d_read
= get_glxdrawable(pReadDev
);
1693 if (ctx
->ctx
== NULL
) {
1694 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, !indirect
);
1695 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1697 ctx
->hdc
= pDrawDev
->hdc
;
1698 ctx
->physDev
= pDrawDev
;
1699 ctx
->pReadDev
= pReadDev
;
1700 ctx
->drawables
[0] = d_draw
;
1701 ctx
->drawables
[1] = d_read
;
1702 ctx
->refresh_drawables
= FALSE
;
1703 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1704 NtCurrentTeb()->glContext
= ctx
;
1707 wine_tsx11_unlock();
1709 TRACE(" returning %s\n", (ret
? "True" : "False"));
1714 * X11DRV_wglShareLists
1716 * For OpenGL32 wglShaderLists.
1718 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1719 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1720 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1722 TRACE("(%p, %p)\n", org
, dest
);
1724 if (!has_opengl()) {
1725 ERR("No libGL on this box - disabling OpenGL support !\n");
1729 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1730 ERR("Could not share display lists, context already created !\n");
1733 if (org
->ctx
== NULL
) {
1734 int indirect
= (GetObjectType(org
->hdc
) == OBJ_MEMDC
);
1736 describeContext(org
);
1739 org
->ctx
= pglXCreateContext(gdi_display
, org
->vis
, NULL
, !indirect
);
1740 else /* Create a GLX Context for a pbuffer */
1741 org
->ctx
= pglXCreateNewContext(gdi_display
, org
->fmt
->fbconfig
, org
->fmt
->render_type
, NULL
, True
);
1742 wine_tsx11_unlock();
1743 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1746 int indirect
= (GetObjectType(dest
->hdc
) == OBJ_MEMDC
);
1748 describeContext(dest
);
1749 /* Create the destination context with display lists shared */
1751 dest
->ctx
= pglXCreateContext(gdi_display
, dest
->vis
, org
->ctx
, !indirect
);
1752 else /* Create a GLX Context for a pbuffer */
1753 dest
->ctx
= pglXCreateNewContext(gdi_display
, dest
->fmt
->fbconfig
, dest
->fmt
->render_type
, org
->ctx
, True
);
1754 wine_tsx11_unlock();
1755 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1762 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1764 /* We are running using client-side rendering fonts... */
1768 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1772 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1773 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1774 wine_tsx11_unlock();
1776 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1777 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1778 int height
, width_int
;
1780 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1781 if (needed_size
== GDI_ERROR
) {
1782 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1785 TRACE(" - needed size : %d\n", needed_size
);
1788 if (needed_size
> size
) {
1790 HeapFree(GetProcessHeap(), 0, bitmap
);
1791 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1792 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1793 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1795 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1796 if (TRACE_ON(opengl
)) {
1797 unsigned int height
, width
, bitmask
;
1798 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1800 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1801 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1802 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1803 if (needed_size
!= 0) {
1804 TRACE(" - bitmap :\n");
1805 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1807 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1812 if (*bitmap_
& bitmask
)
1817 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1823 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1824 * glyph for it to be drawn properly.
1826 if (needed_size
!= 0) {
1827 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1828 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1830 for (width
= 0; width
< width_int
; width
++) {
1831 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1832 ((int *) bitmap
)[height
* width_int
+ width
];
1838 pglNewList(listBase
++, GL_COMPILE
);
1839 if (needed_size
!= 0) {
1840 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1841 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1842 gm
.gmCellIncX
, gm
.gmCellIncY
,
1845 /* This is the case of 'empty' glyphs like the space character */
1846 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1849 wine_tsx11_unlock();
1853 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1854 wine_tsx11_unlock();
1856 HeapFree(GetProcessHeap(), 0, bitmap
);
1857 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1862 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1863 wine_tsx11_unlock();
1865 HeapFree(GetProcessHeap(), 0, bitmap
);
1866 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1871 * X11DRV_wglUseFontBitmapsA
1873 * For OpenGL32 wglUseFontBitmapsA.
1875 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1877 Font fid
= physDev
->font
;
1879 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1881 if (!has_opengl()) {
1882 ERR("No libGL on this box - disabling OpenGL support !\n");
1887 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
1891 /* I assume that the glyphs are at the same position for X and for Windows */
1892 pglXUseXFont(fid
, first
, count
, listBase
);
1893 wine_tsx11_unlock();
1898 * X11DRV_wglUseFontBitmapsW
1900 * For OpenGL32 wglUseFontBitmapsW.
1902 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1904 Font fid
= physDev
->font
;
1906 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1908 if (!has_opengl()) {
1909 ERR("No libGL on this box - disabling OpenGL support !\n");
1914 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1917 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1920 /* I assume that the glyphs are at the same position for X and for Windows */
1921 pglXUseXFont(fid
, first
, count
, listBase
);
1922 wine_tsx11_unlock();
1926 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1927 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
1934 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1936 pglGetIntegerv(pname
, params
);
1938 * if we cannot find a Wine Context
1939 * we only have the default wine desktop context,
1940 * so if we have only a 24 depth say we have 32
1942 if (!ctx
&& *params
== 24) {
1945 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
1950 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1952 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
1953 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
1957 pglGetIntegerv(pname
, params
);
1960 wine_tsx11_unlock();
1963 static inline void update_drawable(X11DRV_PDEVICE
*physDev
)
1967 if(!physDev
->gl_drawable
)
1970 w
= physDev
->dc_rect
.right
- physDev
->dc_rect
.left
;
1971 h
= physDev
->dc_rect
.bottom
- physDev
->dc_rect
.top
;
1973 if(w
> 0 && h
> 0) {
1974 Drawable src
= physDev
->pixmap
;
1975 if(!src
) src
= physDev
->gl_drawable
;
1977 /* The GL drawable may be lagged behind if we don't flush first, so
1978 * flush the display make sure we copy up-to-date data */
1979 XFlush(gdi_display
);
1980 XCopyArea(gdi_display
, src
, physDev
->drawable
, physDev
->gc
, 0, 0, w
, h
,
1981 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
1986 static void WINAPI
X11DRV_wglFinish(void)
1988 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
1993 update_drawable(ctx
->physDev
);
1994 wine_tsx11_unlock();
1997 static void WINAPI
X11DRV_wglFlush(void)
1999 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
2004 update_drawable(ctx
->physDev
);
2005 wine_tsx11_unlock();
2009 * X11DRV_wglGetExtensionsStringARB
2011 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2013 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2014 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2015 return WineGLInfo
.wglExtensions
;
2019 * X11DRV_wglCreatePbufferARB
2021 * WGL_ARB_pbuffer: wglCreatePbufferARB
2023 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2025 Wine_GLPBuffer
* object
= NULL
;
2026 WineGLPixelFormat
*fmt
= NULL
;
2031 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2033 if (0 >= iPixelFormat
) {
2034 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2035 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2036 return NULL
; /* unexpected error */
2039 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2040 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2042 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2043 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2044 goto create_failed
; /* unexpected error */
2047 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2048 if (NULL
== object
) {
2049 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2050 goto create_failed
; /* unexpected error */
2053 object
->display
= gdi_display
;
2054 object
->width
= iWidth
;
2055 object
->height
= iHeight
;
2058 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2059 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2060 while (piAttribList
&& 0 != *piAttribList
) {
2062 switch (*piAttribList
) {
2063 case WGL_PBUFFER_LARGEST_ARB
: {
2065 attr_v
= *piAttribList
;
2066 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2067 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2071 case WGL_TEXTURE_FORMAT_ARB
: {
2073 attr_v
= *piAttribList
;
2074 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2075 if (use_render_texture_ati
) {
2078 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2079 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2080 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2082 SetLastError(ERROR_INVALID_DATA
);
2085 object
->use_render_texture
= 1;
2086 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2088 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2089 object
->use_render_texture
= 0;
2091 if (!use_render_texture_emulation
) {
2092 SetLastError(ERROR_INVALID_DATA
);
2096 case WGL_TEXTURE_RGB_ARB
:
2097 object
->use_render_texture
= GL_RGB
;
2098 object
->texture_bpp
= 3;
2099 object
->texture_format
= GL_RGB
;
2100 object
->texture_type
= GL_UNSIGNED_BYTE
;
2102 case WGL_TEXTURE_RGBA_ARB
:
2103 object
->use_render_texture
= GL_RGBA
;
2104 object
->texture_bpp
= 4;
2105 object
->texture_format
= GL_RGBA
;
2106 object
->texture_type
= GL_UNSIGNED_BYTE
;
2109 /* WGL_FLOAT_COMPONENTS_NV */
2110 case WGL_TEXTURE_FLOAT_R_NV
:
2111 object
->use_render_texture
= GL_FLOAT_R_NV
;
2112 object
->texture_bpp
= 4;
2113 object
->texture_format
= GL_RED
;
2114 object
->texture_type
= GL_FLOAT
;
2116 case WGL_TEXTURE_FLOAT_RG_NV
:
2117 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2118 object
->texture_bpp
= 8;
2119 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2120 object
->texture_type
= GL_FLOAT
;
2122 case WGL_TEXTURE_FLOAT_RGB_NV
:
2123 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2124 object
->texture_bpp
= 12;
2125 object
->texture_format
= GL_RGB
;
2126 object
->texture_type
= GL_FLOAT
;
2128 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2129 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2130 object
->texture_bpp
= 16;
2131 object
->texture_format
= GL_RGBA
;
2132 object
->texture_type
= GL_FLOAT
;
2135 ERR("Unknown texture format: %x\n", attr_v
);
2136 SetLastError(ERROR_INVALID_DATA
);
2144 case WGL_TEXTURE_TARGET_ARB
: {
2146 attr_v
= *piAttribList
;
2147 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2148 if (use_render_texture_ati
) {
2151 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2152 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2153 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2154 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2156 SetLastError(ERROR_INVALID_DATA
);
2159 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2161 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2162 object
->texture_target
= 0;
2164 if (!use_render_texture_emulation
) {
2165 SetLastError(ERROR_INVALID_DATA
);
2169 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2170 if (iWidth
!= iHeight
) {
2171 SetLastError(ERROR_INVALID_DATA
);
2174 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2175 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2178 case WGL_TEXTURE_1D_ARB
: {
2180 SetLastError(ERROR_INVALID_DATA
);
2183 object
->texture_target
= GL_TEXTURE_1D
;
2184 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2187 case WGL_TEXTURE_2D_ARB
: {
2188 object
->texture_target
= GL_TEXTURE_2D
;
2189 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2192 case WGL_TEXTURE_RECTANGLE_NV
: {
2193 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2194 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2198 ERR("Unknown texture target: %x\n", attr_v
);
2199 SetLastError(ERROR_INVALID_DATA
);
2207 case WGL_MIPMAP_TEXTURE_ARB
: {
2209 attr_v
= *piAttribList
;
2210 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2211 if (use_render_texture_ati
) {
2212 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2214 if (!use_render_texture_emulation
) {
2215 SetLastError(ERROR_INVALID_DATA
);
2225 PUSH1(attribs
, None
);
2226 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2227 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2228 if (!object
->drawable
) {
2229 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2230 goto create_failed
; /* unexpected error */
2232 TRACE("->(%p)\n", object
);
2233 return (HPBUFFERARB
) object
;
2236 HeapFree(GetProcessHeap(), 0, object
);
2237 TRACE("->(FAILED)\n");
2238 return (HPBUFFERARB
) NULL
;
2242 * X11DRV_wglDestroyPbufferARB
2244 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2246 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2248 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2249 TRACE("(%p)\n", hPbuffer
);
2250 if (NULL
== object
) {
2251 SetLastError(ERROR_INVALID_HANDLE
);
2254 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2255 HeapFree(GetProcessHeap(), 0, object
);
2260 * X11DRV_wglGetPbufferDCARB
2262 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2263 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2264 * Gdi32 implements the part of this function which creates a device context.
2265 * This part associates the physDev with the X drawable of the pbuffer.
2267 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2269 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2270 if (NULL
== object
) {
2271 SetLastError(ERROR_INVALID_HANDLE
);
2275 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2276 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2277 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2278 physDev
->drawable
= object
->drawable
;
2279 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2280 physDev
->dc_rect
= physDev
->drawable_rect
;
2282 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2283 return physDev
->hdc
;
2287 * X11DRV_wglQueryPbufferARB
2289 * WGL_ARB_pbuffer: wglQueryPbufferARB
2291 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2293 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2294 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2295 if (NULL
== object
) {
2296 SetLastError(ERROR_INVALID_HANDLE
);
2299 switch (iAttribute
) {
2300 case WGL_PBUFFER_WIDTH_ARB
:
2301 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2303 case WGL_PBUFFER_HEIGHT_ARB
:
2304 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2307 case WGL_PBUFFER_LOST_ARB
:
2308 /* GLX Pbuffers cannot be lost by default. We can support this by
2309 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2310 * to receive pixel buffer clobber events, however that may or may
2311 * not give any benefit */
2312 *piValue
= GL_FALSE
;
2315 case WGL_TEXTURE_FORMAT_ARB
:
2316 if (use_render_texture_ati
) {
2318 int type
= WGL_NO_TEXTURE_ARB
;
2319 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2321 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2322 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2323 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2327 if (!object
->use_render_texture
) {
2328 *piValue
= WGL_NO_TEXTURE_ARB
;
2330 if (!use_render_texture_emulation
) {
2331 SetLastError(ERROR_INVALID_HANDLE
);
2334 switch(object
->use_render_texture
) {
2336 *piValue
= WGL_TEXTURE_RGB_ARB
;
2339 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2341 /* WGL_FLOAT_COMPONENTS_NV */
2343 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2345 case GL_FLOAT_RG_NV
:
2346 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2348 case GL_FLOAT_RGB_NV
:
2349 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2351 case GL_FLOAT_RGBA_NV
:
2352 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2355 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2361 case WGL_TEXTURE_TARGET_ARB
:
2362 if (use_render_texture_ati
) {
2364 int type
= WGL_NO_TEXTURE_ARB
;
2365 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2367 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2368 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2369 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2370 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2374 if (!object
->texture_target
) {
2375 *piValue
= WGL_NO_TEXTURE_ARB
;
2377 if (!use_render_texture_emulation
) {
2378 SetLastError(ERROR_INVALID_DATA
);
2381 switch (object
->texture_target
) {
2382 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2383 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2384 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2385 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2391 case WGL_MIPMAP_TEXTURE_ARB
:
2392 if (use_render_texture_ati
) {
2393 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2395 *piValue
= GL_FALSE
; /** don't support that */
2396 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2401 FIXME("unexpected attribute %x\n", iAttribute
);
2409 * X11DRV_wglReleasePbufferDCARB
2411 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2413 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2415 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2421 * X11DRV_wglSetPbufferAttribARB
2423 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2425 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2427 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2428 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2429 if (NULL
== object
) {
2430 SetLastError(ERROR_INVALID_HANDLE
);
2433 if (!object
->use_render_texture
) {
2434 SetLastError(ERROR_INVALID_HANDLE
);
2437 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2440 if (NULL
!= pglXDrawableAttribATI
) {
2441 if (use_render_texture_ati
) {
2442 FIXME("Need conversion for GLX_ATI_render_texture\n");
2444 return pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2450 * X11DRV_wglChoosePixelFormatARB
2452 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2454 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2459 GLXFBConfig
* cfgs
= NULL
;
2463 WineGLPixelFormat
*fmt
;
2467 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2468 if (NULL
!= pfAttribFList
) {
2469 FIXME("unused pfAttribFList\n");
2472 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2473 if (-1 == nAttribs
) {
2474 WARN("Cannot convert WGL to GLX attributes\n");
2477 PUSH1(attribs
, None
);
2479 /* Search for FB configurations matching the requirements in attribs */
2480 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2482 WARN("Compatible Pixel Format not found\n");
2486 /* Loop through all matching formats and check if they are suitable.
2487 * Note that this function should at max return nMaxFormats different formats */
2488 for(run
=0; run
< 2; run
++)
2490 for (it
= 0; it
< nCfgs
; ++it
) {
2491 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2493 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2497 /* Search for the format in our list of compatible formats */
2498 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
);
2502 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2503 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2506 if(pfmt_it
< nMaxFormats
) {
2507 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2508 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2514 *nNumFormats
= pfmt_it
;
2521 * X11DRV_wglGetPixelFormatAttribivARB
2523 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2525 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2528 WineGLPixelFormat
*fmt
= NULL
;
2532 int nWGLFormats
= 0;
2534 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2536 if (0 < iLayerPlane
) {
2537 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2541 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2542 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2543 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2544 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2546 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2549 for (i
= 0; i
< nAttributes
; ++i
) {
2550 const int curWGLAttr
= piAttributes
[i
];
2551 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2553 switch (curWGLAttr
) {
2554 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2555 piValues
[i
] = nWGLFormats
;
2558 case WGL_SUPPORT_OPENGL_ARB
:
2559 piValues
[i
] = GL_TRUE
;
2562 case WGL_ACCELERATION_ARB
:
2563 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2564 if (!fmt
) goto pix_error
;
2565 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2566 if (hTest
) goto get_error
;
2568 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2569 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
; break;
2570 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2572 ERR("unexpected Config Caveat(%x)\n", tmp
);
2573 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2577 case WGL_TRANSPARENT_ARB
:
2578 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2579 if (!fmt
) goto pix_error
;
2580 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2581 if (hTest
) goto get_error
;
2582 piValues
[i
] = GL_FALSE
;
2583 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2586 case WGL_PIXEL_TYPE_ARB
:
2587 curGLXAttr
= GLX_RENDER_TYPE
;
2588 if (!fmt
) goto pix_error
;
2589 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2590 if (hTest
) goto get_error
;
2591 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2592 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2593 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2594 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2595 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2597 ERR("unexpected RenderType(%x)\n", tmp
);
2598 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2602 case WGL_COLOR_BITS_ARB
:
2603 curGLXAttr
= GLX_BUFFER_SIZE
;
2606 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2607 if (use_render_texture_ati
) {
2608 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2611 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2612 if (use_render_texture_ati
) {
2613 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2616 if (!use_render_texture_emulation
) {
2617 piValues
[i
] = GL_FALSE
;
2620 curGLXAttr
= GLX_RENDER_TYPE
;
2621 if (!fmt
) goto pix_error
;
2622 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2623 if (hTest
) goto get_error
;
2624 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2625 piValues
[i
] = GL_FALSE
;
2628 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2629 if (hTest
) goto get_error
;
2630 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2633 case WGL_BLUE_BITS_ARB
:
2634 curGLXAttr
= GLX_BLUE_SIZE
;
2636 case WGL_RED_BITS_ARB
:
2637 curGLXAttr
= GLX_RED_SIZE
;
2639 case WGL_GREEN_BITS_ARB
:
2640 curGLXAttr
= GLX_GREEN_SIZE
;
2642 case WGL_ALPHA_BITS_ARB
:
2643 curGLXAttr
= GLX_ALPHA_SIZE
;
2645 case WGL_DEPTH_BITS_ARB
:
2646 curGLXAttr
= GLX_DEPTH_SIZE
;
2648 case WGL_STENCIL_BITS_ARB
:
2649 curGLXAttr
= GLX_STENCIL_SIZE
;
2651 case WGL_DOUBLE_BUFFER_ARB
:
2652 curGLXAttr
= GLX_DOUBLEBUFFER
;
2654 case WGL_STEREO_ARB
:
2655 curGLXAttr
= GLX_STEREO
;
2657 case WGL_AUX_BUFFERS_ARB
:
2658 curGLXAttr
= GLX_AUX_BUFFERS
;
2661 case WGL_SUPPORT_GDI_ARB
:
2662 if (!fmt
) goto pix_error
;
2663 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &tmp
);
2664 if (hTest
) goto get_error
;
2666 piValues
[i
] = GL_FALSE
;
2669 curGLXAttr
= GLX_X_RENDERABLE
;
2672 case WGL_DRAW_TO_WINDOW_ARB
:
2673 case WGL_DRAW_TO_BITMAP_ARB
:
2674 case WGL_DRAW_TO_PBUFFER_ARB
:
2675 if (!fmt
) goto pix_error
;
2676 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2677 if (hTest
) goto get_error
;
2678 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2679 (curWGLAttr
== WGL_DRAW_TO_BITMAP_ARB
&& (tmp
&GLX_PIXMAP_BIT
)) ||
2680 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2681 piValues
[i
] = GL_TRUE
;
2683 piValues
[i
] = GL_FALSE
;
2686 case WGL_PBUFFER_LARGEST_ARB
:
2687 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2690 case WGL_SAMPLE_BUFFERS_ARB
:
2691 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2694 case WGL_SAMPLES_ARB
:
2695 curGLXAttr
= GLX_SAMPLES_ARB
;
2698 case WGL_FLOAT_COMPONENTS_NV
:
2699 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2702 case WGL_ACCUM_RED_BITS_ARB
:
2703 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2705 case WGL_ACCUM_GREEN_BITS_ARB
:
2706 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2708 case WGL_ACCUM_BLUE_BITS_ARB
:
2709 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2711 case WGL_ACCUM_ALPHA_BITS_ARB
:
2712 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2714 case WGL_ACCUM_BITS_ARB
:
2715 if (!fmt
) goto pix_error
;
2716 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2717 if (hTest
) goto get_error
;
2719 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2720 if (hTest
) goto get_error
;
2722 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2723 if (hTest
) goto get_error
;
2725 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2726 if (hTest
) goto get_error
;
2731 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2734 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2735 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2736 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2738 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2739 * and check which options can work using iPixelFormat=0 and which not.
2740 * A problem would be that this function is an extension. This would
2741 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2743 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2744 if (!fmt
) goto pix_error
;
2745 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2746 if (hTest
) goto get_error
;
2749 piValues
[i
] = GL_FALSE
;
2755 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2759 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2764 * X11DRV_wglGetPixelFormatAttribfvARB
2766 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2768 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2774 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2776 /* Allocate a temporary array to store integer values */
2777 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2779 ERR("couldn't allocate %d array\n", nAttributes
);
2783 /* Piggy-back on wglGetPixelFormatAttribivARB */
2784 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2786 /* Convert integer values to float. Should also check for attributes
2787 that can give decimal values here */
2788 for (i
=0; i
<nAttributes
;i
++) {
2789 pfValues
[i
] = attr
[i
];
2793 HeapFree(GetProcessHeap(), 0, attr
);
2798 * X11DRV_wglBindTexImageARB
2800 * WGL_ARB_render_texture: wglBindTexImageARB
2802 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2804 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2805 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2806 if (NULL
== object
) {
2807 SetLastError(ERROR_INVALID_HANDLE
);
2810 if (!object
->use_render_texture
) {
2811 SetLastError(ERROR_INVALID_HANDLE
);
2815 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2816 static int init
= 0;
2817 int prev_binded_texture
= 0;
2818 GLXContext prev_context
= pglXGetCurrentContext();
2819 Drawable prev_drawable
= pglXGetCurrentDrawable();
2820 GLXContext tmp_context
;
2822 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2823 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2824 isn't ideal performance wise but I wasn't able to get other ways working.
2827 init
= 1; /* Only show the FIXME once for performance reasons */
2828 FIXME("partial stub!\n");
2831 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
2832 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2834 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2836 /* Switch to our pbuffer */
2837 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2839 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2840 * After that upload the pbuffer texture data. */
2841 pglBindTexture(object
->texture_target
, prev_binded_texture
);
2842 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2844 /* Switch back to the original drawable and upload the pbuffer-texture */
2845 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
2846 pglXDestroyContext(gdi_display
, tmp_context
);
2850 if (NULL
!= pglXBindTexImageATI
) {
2855 case WGL_FRONT_LEFT_ARB
:
2856 buffer
= GLX_FRONT_LEFT_ATI
;
2858 case WGL_FRONT_RIGHT_ARB
:
2859 buffer
= GLX_FRONT_RIGHT_ATI
;
2861 case WGL_BACK_LEFT_ARB
:
2862 buffer
= GLX_BACK_LEFT_ATI
;
2864 case WGL_BACK_RIGHT_ARB
:
2865 buffer
= GLX_BACK_RIGHT_ATI
;
2868 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2872 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
2873 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
2874 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
2875 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
2876 * works fine using our pbuffer emulation path.
2878 return pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
2884 * X11DRV_wglReleaseTexImageARB
2886 * WGL_ARB_render_texture: wglReleaseTexImageARB
2888 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2890 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2891 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2892 if (NULL
== object
) {
2893 SetLastError(ERROR_INVALID_HANDLE
);
2896 if (!object
->use_render_texture
) {
2897 SetLastError(ERROR_INVALID_HANDLE
);
2900 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2903 if (NULL
!= pglXReleaseTexImageATI
) {
2908 case WGL_FRONT_LEFT_ARB
:
2909 buffer
= GLX_FRONT_LEFT_ATI
;
2911 case WGL_FRONT_RIGHT_ARB
:
2912 buffer
= GLX_FRONT_RIGHT_ATI
;
2914 case WGL_BACK_LEFT_ARB
:
2915 buffer
= GLX_BACK_LEFT_ATI
;
2917 case WGL_BACK_RIGHT_ARB
:
2918 buffer
= GLX_BACK_RIGHT_ATI
;
2921 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2924 return pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
2930 * X11DRV_wglGetExtensionsStringEXT
2932 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2934 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
2935 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2936 return WineGLInfo
.wglExtensions
;
2940 * X11DRV_wglGetSwapIntervalEXT
2942 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2944 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
2945 FIXME("(),stub!\n");
2946 return swap_interval
;
2950 * X11DRV_wglSwapIntervalEXT
2952 * WGL_EXT_swap_control: wglSwapIntervalEXT
2954 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
2955 TRACE("(%d)\n", interval
);
2956 swap_interval
= interval
;
2957 if (NULL
!= pglXSwapIntervalSGI
) {
2958 return 0 == pglXSwapIntervalSGI(interval
);
2960 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2965 * X11DRV_wglAllocateMemoryNV
2967 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2969 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
2970 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
2971 if (pglXAllocateMemoryNV
== NULL
)
2974 return pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
2978 * X11DRV_wglFreeMemoryNV
2980 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2982 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
2983 TRACE("(%p)\n", pointer
);
2984 if (pglXFreeMemoryNV
== NULL
)
2987 pglXFreeMemoryNV(pointer
);
2991 * glxRequireVersion (internal)
2993 * Check if the supported GLX version matches requiredVersion.
2995 static BOOL
glxRequireVersion(int requiredVersion
)
2997 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2998 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3004 static BOOL
glxRequireExtension(const char *requiredExtension
)
3006 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3013 static void register_extension_string(const char *ext
)
3015 if (WineGLInfo
.wglExtensions
[0])
3016 strcat(WineGLInfo
.wglExtensions
, " ");
3017 strcat(WineGLInfo
.wglExtensions
, ext
);
3019 TRACE("'%s'\n", ext
);
3022 static BOOL
register_extension(const WineGLExtension
* ext
)
3026 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3027 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3029 register_extension_string(ext
->extName
);
3031 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3032 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3037 static const WineGLExtension WGL_internal_functions
=
3041 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3042 { "wglFinish", X11DRV_wglFinish
},
3043 { "wglFlush", X11DRV_wglFlush
},
3048 static const WineGLExtension WGL_ARB_extensions_string
=
3050 "WGL_ARB_extensions_string",
3052 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3056 static const WineGLExtension WGL_ARB_make_current_read
=
3058 "WGL_ARB_make_current_read",
3060 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3061 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3065 static const WineGLExtension WGL_ARB_multisample
=
3067 "WGL_ARB_multisample",
3070 static const WineGLExtension WGL_ARB_pbuffer
=
3074 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3075 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3076 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3077 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3078 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3079 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3083 static const WineGLExtension WGL_ARB_pixel_format
=
3085 "WGL_ARB_pixel_format",
3087 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3088 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3089 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3093 static const WineGLExtension WGL_ARB_render_texture
=
3095 "WGL_ARB_render_texture",
3097 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3098 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3102 static const WineGLExtension WGL_EXT_extensions_string
=
3104 "WGL_EXT_extensions_string",
3106 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3110 static const WineGLExtension WGL_EXT_swap_control
=
3112 "WGL_EXT_swap_control",
3114 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3115 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3119 static const WineGLExtension WGL_NV_vertex_array_range
=
3121 "WGL_NV_vertex_array_range",
3123 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3124 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3129 * X11DRV_WineGL_LoadExtensions
3131 static void X11DRV_WineGL_LoadExtensions(void)
3133 WineGLInfo
.wglExtensions
[0] = 0;
3135 /* Load Wine internal functions */
3136 register_extension(&WGL_internal_functions
);
3138 /* ARB Extensions */
3140 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3142 register_extension_string("WGL_ARB_pixel_format_float");
3143 register_extension_string("WGL_ATI_pixel_format_float");
3146 register_extension(&WGL_ARB_extensions_string
);
3148 if (glxRequireVersion(3))
3149 register_extension(&WGL_ARB_make_current_read
);
3151 if (glxRequireExtension("GLX_ARB_multisample"))
3152 register_extension(&WGL_ARB_multisample
);
3154 /* In general pbuffer functionality requires support in the X-server. The functionality is
3155 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3156 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3157 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3159 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3160 * without support in the X-server (which other Mesa based drivers require).
3162 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3163 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3164 * is available pbuffers must be available too. */
3165 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3166 register_extension(&WGL_ARB_pbuffer
);
3168 register_extension(&WGL_ARB_pixel_format
);
3170 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3171 if (glxRequireExtension("GLX_ATI_render_texture") ||
3172 glxRequireExtension("GLX_ARB_render_texture") ||
3173 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3175 register_extension(&WGL_ARB_render_texture
);
3177 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3178 if(glxRequireExtension("GLX_NV_float_buffer"))
3179 register_extension_string("WGL_NV_float_buffer");
3181 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3182 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3183 register_extension_string("WGL_NV_texture_rectangle");
3186 /* EXT Extensions */
3188 register_extension(&WGL_EXT_extensions_string
);
3190 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3191 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3192 register_extension(&WGL_EXT_swap_control
);
3194 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3195 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3196 register_extension(&WGL_NV_vertex_array_range
);
3200 static XID
create_bitmap_glxpixmap(X11DRV_PDEVICE
*physDev
)
3204 XVisualInfo
template;
3209 /* Retrieve the visualid from our main visual which is the only visual we can use */
3210 template.visualid
= XVisualIDFromVisual(visual
);
3211 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
3213 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
3215 wine_tsx11_unlock();
3216 TRACE("return %lx\n", ret
);
3220 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3226 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3227 ret
= physDev
->drawable
; /* PBuffer */
3230 if(!physDev
->bitmap
->glxpixmap
)
3231 physDev
->bitmap
->glxpixmap
= create_bitmap_glxpixmap(physDev
);
3232 ret
= physDev
->bitmap
->glxpixmap
;
3235 else if(physDev
->gl_drawable
)
3236 ret
= physDev
->gl_drawable
;
3238 ret
= physDev
->drawable
;
3242 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3245 pglXDestroyGLXPixmap(display
, glxpixmap
);
3246 wine_tsx11_unlock();
3251 * X11DRV_SwapBuffers
3253 * Swap the buffers of this DC
3255 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3257 GLXDrawable drawable
;
3258 Wine_GLContext
*ctx
= NtCurrentTeb()->glContext
;
3260 if (!has_opengl()) {
3261 ERR("No libGL on this box - disabling OpenGL support !\n");
3265 TRACE_(opengl
)("(%p)\n", physDev
);
3267 drawable
= get_glxdrawable(physDev
);
3271 pglXSwapBuffers(gdi_display
, drawable
);
3272 update_drawable(physDev
);
3273 wine_tsx11_unlock();
3278 static long prev_time
, frames
;
3280 DWORD time
= GetTickCount();
3282 /* every 1.5 seconds */
3283 if (time
- prev_time
> 1500) {
3284 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
3293 /***********************************************************************
3294 * X11DRV_setup_opengl_visual
3296 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3297 * window (if it exists). If OpenGL isn't available, the visual is simply
3298 * set to the default visual for the display
3300 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3302 XVisualInfo
*visual
= NULL
;
3305 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3306 * D3D and some applications can make use of aux buffers.
3308 int visualProperties
[][11] = {
3309 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_AUX_BUFFERS
, 1, None
},
3310 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, None
},
3311 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, None
},
3312 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, None
},
3319 for (i
= 0; i
< sizeof(visualProperties
)/sizeof(visualProperties
[0]); ++i
) {
3320 visual
= pglXChooseVisual(display
, DefaultScreen(display
), visualProperties
[i
]);
3324 wine_tsx11_unlock();
3327 TRACE("Visual ID %lx Chosen\n", visual
->visualid
);
3329 WARN("No suitable visual found\n");
3334 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3336 WineGLPixelFormat
*fmt
;
3338 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fbconfig_id
);
3341 return pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
3344 #else /* no OpenGL includes */
3346 int pixelformat_from_fbconfig_id(XID fbconfig_id
)
3351 void mark_drawable_dirty(Drawable old
, Drawable
new)
3355 Drawable
create_glxpixmap(Display
*display
, XVisualInfo
*vis
, Pixmap parent
)
3360 /***********************************************************************
3361 * ChoosePixelFormat (X11DRV.@)
3363 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3364 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3365 ERR("No OpenGL support compiled in.\n");
3370 /***********************************************************************
3371 * DescribePixelFormat (X11DRV.@)
3373 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3376 PIXELFORMATDESCRIPTOR
*ppfd
) {
3377 ERR("No OpenGL support compiled in.\n");
3382 /***********************************************************************
3383 * GetPixelFormat (X11DRV.@)
3385 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3386 ERR("No OpenGL support compiled in.\n");
3391 /***********************************************************************
3392 * SetPixelFormat (X11DRV.@)
3394 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3396 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3397 ERR("No OpenGL support compiled in.\n");
3402 /***********************************************************************
3403 * SwapBuffers (X11DRV.@)
3405 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3406 ERR_(opengl
)("No OpenGL support compiled in.\n");
3412 * X11DRV_wglCreateContext
3414 * For OpenGL32 wglCreateContext.
3416 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3417 ERR_(opengl
)("No OpenGL support compiled in.\n");
3422 * X11DRV_wglDeleteContext
3424 * For OpenGL32 wglDeleteContext.
3426 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3427 ERR_(opengl
)("No OpenGL support compiled in.\n");
3432 * X11DRV_wglGetProcAddress
3434 * For OpenGL32 wglGetProcAddress.
3436 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3437 ERR_(opengl
)("No OpenGL support compiled in.\n");
3441 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3443 ERR_(opengl
)("No OpenGL support compiled in.\n");
3447 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3448 ERR_(opengl
)("No OpenGL support compiled in.\n");
3453 * X11DRV_wglMakeCurrent
3455 * For OpenGL32 wglMakeCurrent.
3457 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3458 ERR_(opengl
)("No OpenGL support compiled in.\n");
3463 * X11DRV_wglShareLists
3465 * For OpenGL32 wglShaderLists.
3467 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3468 ERR_(opengl
)("No OpenGL support compiled in.\n");
3473 * X11DRV_wglUseFontBitmapsA
3475 * For OpenGL32 wglUseFontBitmapsA.
3477 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3479 ERR_(opengl
)("No OpenGL support compiled in.\n");
3484 * X11DRV_wglUseFontBitmapsW
3486 * For OpenGL32 wglUseFontBitmapsW.
3488 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3490 ERR_(opengl
)("No OpenGL support compiled in.\n");
3494 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3499 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3504 BOOL
destroy_glxpixmap(Display
*display
, XID glxpixmap
)
3509 XVisualInfo
*visual_from_fbconfig_id( XID fbconfig_id
)
3514 #endif /* defined(HAVE_OPENGL) */