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
;
115 BOOL scissor_enabled
;
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;
152 static void X11DRV_WineGL_LoadExtensions(void);
153 static BOOL
glxRequireVersion(int requiredVersion
);
154 static BOOL
glxRequireExtension(const char *requiredExtension
);
156 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
157 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
158 TRACE(" - dwFlags : ");
159 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
160 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
161 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
162 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
163 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
164 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
165 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
166 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
172 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
173 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
174 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
175 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
176 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
177 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
178 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
182 TRACE(" - iPixelType : ");
183 switch (ppfd
->iPixelType
) {
184 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
185 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
189 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
190 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
191 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
192 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
193 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
194 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
195 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
196 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
197 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
199 TRACE(" - iLayerType : ");
200 switch (ppfd
->iLayerType
) {
201 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
202 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
203 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
208 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
209 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
211 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
213 MAKE_FUNCPTR(glXChooseVisual
)
214 MAKE_FUNCPTR(glXCreateContext
)
215 MAKE_FUNCPTR(glXCreateGLXPixmap
)
216 MAKE_FUNCPTR(glXGetCurrentContext
)
217 MAKE_FUNCPTR(glXGetCurrentDrawable
)
218 MAKE_FUNCPTR(glXDestroyContext
)
219 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
220 MAKE_FUNCPTR(glXGetConfig
)
221 MAKE_FUNCPTR(glXIsDirect
)
222 MAKE_FUNCPTR(glXMakeCurrent
)
223 MAKE_FUNCPTR(glXSwapBuffers
)
224 MAKE_FUNCPTR(glXQueryExtension
)
225 MAKE_FUNCPTR(glXQueryVersion
)
226 MAKE_FUNCPTR(glXUseXFont
)
229 MAKE_FUNCPTR(glXGetClientString
)
230 MAKE_FUNCPTR(glXQueryExtensionsString
)
231 MAKE_FUNCPTR(glXQueryServerString
)
234 MAKE_FUNCPTR(glXGetFBConfigs
)
235 MAKE_FUNCPTR(glXChooseFBConfig
)
236 MAKE_FUNCPTR(glXCreatePbuffer
)
237 MAKE_FUNCPTR(glXCreateNewContext
)
238 MAKE_FUNCPTR(glXDestroyPbuffer
)
239 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
240 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
241 MAKE_FUNCPTR(glXMakeContextCurrent
)
242 MAKE_FUNCPTR(glXQueryDrawable
)
243 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
246 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
247 static int (*pglXSwapIntervalSGI
)(int);
249 /* ATI GLX Extensions */
250 static BOOL (*pglXBindTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
251 static BOOL (*pglXReleaseTexImageATI
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
252 static BOOL (*pglXDrawableAttribATI
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
254 /* NV GLX Extension */
255 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
256 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
258 /* Standard OpenGL */
259 MAKE_FUNCPTR(glBindTexture
)
260 MAKE_FUNCPTR(glBitmap
)
261 MAKE_FUNCPTR(glCopyTexSubImage1D
)
262 MAKE_FUNCPTR(glCopyTexImage2D
)
263 MAKE_FUNCPTR(glCopyTexSubImage2D
)
264 MAKE_FUNCPTR(glDisable
)
265 MAKE_FUNCPTR(glDrawBuffer
)
266 MAKE_FUNCPTR(glEnable
)
267 MAKE_FUNCPTR(glEndList
)
268 MAKE_FUNCPTR(glGetError
)
269 MAKE_FUNCPTR(glGetIntegerv
)
270 MAKE_FUNCPTR(glGetString
)
271 MAKE_FUNCPTR(glIsEnabled
)
272 MAKE_FUNCPTR(glNewList
)
273 MAKE_FUNCPTR(glPixelStorei
)
274 MAKE_FUNCPTR(glReadPixels
)
275 MAKE_FUNCPTR(glScissor
)
276 MAKE_FUNCPTR(glTexImage2D
)
277 MAKE_FUNCPTR(glViewport
)
280 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
282 static BOOL infoInitialized
= FALSE
;
284 int screen
= DefaultScreen(gdi_display
);
285 Window win
= RootWindow(gdi_display
, screen
);
287 XVisualInfo
template;
290 GLXContext ctx
= NULL
;
294 infoInitialized
= TRUE
;
298 visual
= DefaultVisual(gdi_display
, screen
);
299 template.visualid
= XVisualIDFromVisual(visual
);
300 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
302 WORD old_fs
= wine_get_fs();
303 /* Create a GLX Context. Without one we can't query GL information */
304 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
305 if (wine_get_fs() != old_fs
)
307 wine_set_fs( old_fs
);
309 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
310 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
316 pglXMakeCurrent(gdi_display
, win
, ctx
);
318 ERR(" couldn't initialize OpenGL, expect problems\n");
323 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
324 WineGLInfo
.glExtensions
= strdup((const char *) pglGetString(GL_EXTENSIONS
));
326 /* Get the common GLX version supported by GLX client and server ( major/minor) */
327 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
329 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
330 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
331 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
333 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
334 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
335 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
337 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
338 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
340 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
341 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
342 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
343 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
344 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
345 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
346 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
347 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
351 pglXMakeCurrent(gdi_display
, None
, NULL
);
352 pglXDestroyContext(gdi_display
, ctx
);
358 static BOOL
has_opengl(void)
360 static int init_done
;
361 static void *opengl_handle
;
363 int error_base
, event_base
;
365 if (init_done
) return (opengl_handle
!= NULL
);
368 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
369 and include all dependencies */
370 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0);
371 if (opengl_handle
== NULL
) return FALSE
;
373 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
374 if (pglXGetProcAddressARB
== NULL
) {
375 ERR("could not find glXGetProcAddressARB in libGL.\n");
379 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
381 LOAD_FUNCPTR(glXChooseVisual
)
382 LOAD_FUNCPTR(glXCreateContext
)
383 LOAD_FUNCPTR(glXCreateGLXPixmap
)
384 LOAD_FUNCPTR(glXGetCurrentContext
)
385 LOAD_FUNCPTR(glXGetCurrentDrawable
)
386 LOAD_FUNCPTR(glXDestroyContext
)
387 LOAD_FUNCPTR(glXDestroyGLXPixmap
)
388 LOAD_FUNCPTR(glXGetConfig
)
389 LOAD_FUNCPTR(glXIsDirect
)
390 LOAD_FUNCPTR(glXMakeCurrent
)
391 LOAD_FUNCPTR(glXSwapBuffers
)
392 LOAD_FUNCPTR(glXQueryExtension
)
393 LOAD_FUNCPTR(glXQueryVersion
)
394 LOAD_FUNCPTR(glXUseXFont
)
397 LOAD_FUNCPTR(glXGetClientString
)
398 LOAD_FUNCPTR(glXQueryExtensionsString
)
399 LOAD_FUNCPTR(glXQueryServerString
)
402 LOAD_FUNCPTR(glXCreatePbuffer
)
403 LOAD_FUNCPTR(glXCreateNewContext
)
404 LOAD_FUNCPTR(glXDestroyPbuffer
)
405 LOAD_FUNCPTR(glXMakeContextCurrent
)
406 LOAD_FUNCPTR(glXGetCurrentReadDrawable
)
407 LOAD_FUNCPTR(glXGetFBConfigs
)
409 /* Standard OpenGL calls */
410 LOAD_FUNCPTR(glBindTexture
)
411 LOAD_FUNCPTR(glBitmap
)
412 LOAD_FUNCPTR(glCopyTexSubImage1D
)
413 LOAD_FUNCPTR(glCopyTexImage2D
)
414 LOAD_FUNCPTR(glCopyTexSubImage2D
)
415 LOAD_FUNCPTR(glDisable
)
416 LOAD_FUNCPTR(glDrawBuffer
)
417 LOAD_FUNCPTR(glEnable
)
418 LOAD_FUNCPTR(glEndList
)
419 LOAD_FUNCPTR(glGetError
)
420 LOAD_FUNCPTR(glGetIntegerv
)
421 LOAD_FUNCPTR(glGetString
)
422 LOAD_FUNCPTR(glIsEnabled
)
423 LOAD_FUNCPTR(glNewList
)
424 LOAD_FUNCPTR(glPixelStorei
)
425 LOAD_FUNCPTR(glReadPixels
)
426 LOAD_FUNCPTR(glScissor
)
427 LOAD_FUNCPTR(glTexImage2D
)
428 LOAD_FUNCPTR(glViewport
)
431 /* It doesn't matter if these fail. They'll only be used if the driver reports
432 the associated extension is available (and if a driver reports the extension
433 is available but fails to provide the functions, it's quite broken) */
434 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
435 /* NV GLX Extension */
436 LOAD_FUNCPTR(glXAllocateMemoryNV
)
437 LOAD_FUNCPTR(glXFreeMemoryNV
)
440 if(!X11DRV_WineGL_InitOpenglInfo()) {
441 wine_dlclose(opengl_handle
, NULL
, 0);
442 opengl_handle
= NULL
;
447 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
) == True
) {
448 TRACE("GLX is up and running error_base = %d\n", error_base
);
450 wine_dlclose(opengl_handle
, NULL
, 0);
451 opengl_handle
= NULL
;
454 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
455 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
458 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
459 * depends on the reported GLX client / server version and on the client / server extension list.
460 * Those don't have to be the same.
462 * In general the server GLX information lists the capabilities in case of indirect rendering.
463 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
464 * available and in that case the client GLX informat can be used.
465 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
466 * in the GLX version/extension list. When a program does this it works for certain for both
467 * direct and indirect rendering.
469 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
470 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
471 * extension list which causes this extension not to be listed. (Wine requires this extension).
472 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
473 * pbuffers is around.
475 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
476 * the ATI drivers and from then on use GLX client information for them.
479 if(glxRequireVersion(3)) {
480 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
481 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
482 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
483 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
484 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
485 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
486 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
487 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
489 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
490 * enable this function when the Xserver understand GLX 1.3 or newer
492 pglXQueryDrawable
= NULL
;
493 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
494 TRACE("Overriding ATI GLX capabilities!\n");
495 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
496 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
497 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
498 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
500 /* Use client GLX information in case of the ATI drivers. We override the
501 * capabilities over here and not somewhere else as ATI might better their
502 * life in the future. In case they release proper drivers this block of
503 * code won't be called. */
504 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
506 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
509 if(glxRequireExtension("GLX_ATI_render_texture")) {
510 use_render_texture_ati
= 1;
511 pglXBindTexImageATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageATI");
512 pglXReleaseTexImageATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageATI");
513 pglXDrawableAttribATI
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribATI");
516 X11DRV_WineGL_LoadExtensions();
519 return (opengl_handle
!= NULL
);
522 wine_dlclose(opengl_handle
, NULL
, 0);
523 opengl_handle
= NULL
;
527 static inline Wine_GLContext
*alloc_context(void)
531 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
533 ret
->next
= context_list
;
534 if (context_list
) context_list
->prev
= ret
;
540 static inline void free_context(Wine_GLContext
*context
)
542 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
543 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
544 else context_list
= context
->next
;
546 HeapFree(GetProcessHeap(), 0, context
);
549 static inline Wine_GLContext
*get_context_from_GLXContext(GLXContext ctx
)
552 if (!ctx
) return NULL
;
553 for (ret
= context_list
; ret
; ret
= ret
->next
) if (ctx
== ret
->ctx
) break;
558 * get_hdc_from_Drawable (internal)
560 * For use by wglGetCurrentReadDCARB.
562 static inline HDC
get_hdc_from_Drawable(GLXDrawable d
)
565 for (ret
= context_list
; ret
; ret
= ret
->next
) {
566 if (d
== ret
->physDev
->drawable
) {
573 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
576 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
577 return (ptr
!= NULL
);
580 static int describeContext(Wine_GLContext
* ctx
) {
583 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
584 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
585 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
586 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
587 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
592 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
595 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
598 if (pglXQueryDrawable
== NULL
) {
599 /** glXQueryDrawable not available so returns not supported */
603 TRACE(" Drawable %p have :\n", (void*) drawable
);
604 pglXQueryDrawable(gdi_display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
605 TRACE(" - WIDTH as %d\n", tmp
);
606 pglXQueryDrawable(gdi_display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
607 TRACE(" - HEIGHT as %d\n", tmp
);
608 pglXQueryDrawable(gdi_display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
609 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
612 fbCfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribList
, &nElements
);
613 if (fbCfgs
== NULL
) {
617 pglXGetFBConfigAttrib(gdi_display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
618 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
625 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
630 int nvfloatattrib
= GLX_DONT_CARE
;
633 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
634 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
635 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
636 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
638 switch (iWGLAttr
[cur
]) {
639 case WGL_COLOR_BITS_ARB
:
640 pop
= iWGLAttr
[++cur
];
641 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
642 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
644 case WGL_BLUE_BITS_ARB
:
645 pop
= iWGLAttr
[++cur
];
646 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
647 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
649 case WGL_RED_BITS_ARB
:
650 pop
= iWGLAttr
[++cur
];
651 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
652 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
654 case WGL_GREEN_BITS_ARB
:
655 pop
= iWGLAttr
[++cur
];
656 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
657 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
659 case WGL_ALPHA_BITS_ARB
:
660 pop
= iWGLAttr
[++cur
];
661 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
662 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
664 case WGL_DEPTH_BITS_ARB
:
665 pop
= iWGLAttr
[++cur
];
666 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
667 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
669 case WGL_STENCIL_BITS_ARB
:
670 pop
= iWGLAttr
[++cur
];
671 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
672 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
674 case WGL_DOUBLE_BUFFER_ARB
:
675 pop
= iWGLAttr
[++cur
];
676 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
677 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
680 case WGL_PIXEL_TYPE_ARB
:
681 pop
= iWGLAttr
[++cur
];
682 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
684 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
685 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
686 /* 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 */
687 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
689 ERR("unexpected PixelType(%x)\n", pop
);
694 case WGL_SUPPORT_GDI_ARB
:
695 pop
= iWGLAttr
[++cur
];
696 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
697 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
700 case WGL_DRAW_TO_BITMAP_ARB
:
701 pop
= iWGLAttr
[++cur
];
702 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
703 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
705 drawattrib
|= GLX_PIXMAP_BIT
;
709 case WGL_DRAW_TO_WINDOW_ARB
:
710 pop
= iWGLAttr
[++cur
];
711 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
712 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
714 drawattrib
|= GLX_WINDOW_BIT
;
718 case WGL_DRAW_TO_PBUFFER_ARB
:
719 pop
= iWGLAttr
[++cur
];
720 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
721 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
723 drawattrib
|= GLX_PBUFFER_BIT
;
727 case WGL_ACCELERATION_ARB
:
728 case WGL_SUPPORT_OPENGL_ARB
:
729 pop
= iWGLAttr
[++cur
];
730 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
731 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
734 case WGL_PBUFFER_LARGEST_ARB
:
735 pop
= iWGLAttr
[++cur
];
736 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
737 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
740 case WGL_SAMPLE_BUFFERS_ARB
:
741 pop
= iWGLAttr
[++cur
];
742 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
743 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
746 case WGL_SAMPLES_ARB
:
747 pop
= iWGLAttr
[++cur
];
748 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
749 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
752 case WGL_TEXTURE_FORMAT_ARB
:
753 case WGL_TEXTURE_TARGET_ARB
:
754 case WGL_MIPMAP_TEXTURE_ARB
:
755 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
756 pop
= iWGLAttr
[++cur
];
758 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
760 if (use_render_texture_ati
) {
761 /** nothing to do here */
763 else if (!use_render_texture_emulation
) {
764 if (WGL_NO_TEXTURE_ARB
!= pop
) {
765 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
766 return -1; /** error: don't support it */
768 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
769 drawattrib
|= GLX_PBUFFER_BIT
;
773 case WGL_FLOAT_COMPONENTS_NV
:
774 nvfloatattrib
= iWGLAttr
[++cur
];
775 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
777 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
778 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
779 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
780 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
781 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
782 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
783 pop
= iWGLAttr
[++cur
];
784 /** cannot be converted, see direct handling on
785 * - wglGetPixelFormatAttribivARB
786 * TODO: wglChoosePixelFormat
791 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
797 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
798 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
799 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
800 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
802 /* Set GLX_RENDER_TYPE all the time */
803 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
804 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
806 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
807 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
808 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
809 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
815 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
817 int render_type
=0, render_type_bit
;
818 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
819 switch(render_type_bit
)
822 render_type
= GLX_RGBA_TYPE
;
824 case GLX_COLOR_INDEX_BIT
:
825 render_type
= GLX_COLOR_INDEX_TYPE
;
827 case GLX_RGBA_FLOAT_BIT
:
828 render_type
= GLX_RGBA_FLOAT_TYPE
;
831 ERR("Unknown render_type: %x\n", render_type
);
836 static BOOL
init_formats(Display
*display
, int screen
, Visual
*visual
)
838 int fmt_id
, tmp_vis_id
, tmp_fmt_id
, nCfgs
, i
;
840 GLXFBConfig fbconfig
= NULL
;
841 VisualID visualid
= XVisualIDFromVisual(visual
);
842 int nOffscreenFormats
= 0;
844 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
845 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
846 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
847 * because this call lists both types of formats instead of only onscreen ones. */
848 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
849 if (NULL
== cfgs
|| 0 == nCfgs
) {
850 ERR("glXChooseFBConfig returns NULL\n");
851 if(cfgs
!= NULL
) XFree(cfgs
);
855 /* Count the number of offscreen formats to determine the size for our pixelformat list */
856 for(i
=0; i
<nCfgs
; i
++) {
857 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
859 /* We have found Wine's main visual */
860 if(tmp_vis_id
== visualid
) {
861 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
865 /* We have found an offscreen rendering format :) */
866 if(tmp_vis_id
== 0) {
870 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats
);
872 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
873 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (1+nOffscreenFormats
)*sizeof(WineGLPixelFormat
));
874 WineGLPixelFormatList
[0].iPixelFormat
= 1;
875 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
876 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
877 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
878 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
879 WineGLPixelFormatListSize
= 1;
881 /* Fill the list with offscreen formats */
882 for(i
=0; i
<nCfgs
; i
++) {
883 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
884 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
886 /* We have found an offscreen rendering format :) */
887 if(tmp_vis_id
== 0) {
888 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id
, WineGLPixelFormatListSize
+1, i
);
889 WineGLPixelFormatList
[WineGLPixelFormatListSize
].iPixelFormat
= WineGLPixelFormatListSize
+1; /* The index starts at 1 */
890 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fbconfig
= cfgs
[i
];
891 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fmt_id
= tmp_fmt_id
;
892 WineGLPixelFormatList
[WineGLPixelFormatListSize
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
893 WineGLPixelFormatList
[WineGLPixelFormatListSize
].offscreenOnly
= TRUE
;
894 WineGLPixelFormatListSize
++;
898 if(cfgs
!= NULL
) XFree(cfgs
);
903 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
904 * In our WGL implementation we only support a subset of these formats namely the format of
905 * Wine's main visual and offscreen formats (if they are available).
906 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
907 * and it returns the number of supported WGL formats in fmt_count.
909 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
911 WineGLPixelFormat
*res
= NULL
;
913 /* Init the list of pixel formats when we need it */
914 if(!WineGLPixelFormatListSize
)
915 init_formats(display
, DefaultScreen(display
), visual
);
917 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
918 * iPixelFormat in case of probing the number of pixelformats.
920 if((iPixelFormat
<= 0) || (iPixelFormat
> WineGLPixelFormatListSize
)) {
922 *fmt_count
= WineGLPixelFormatListSize
;
924 *fmt_count
= 1; /* Only show the format of our main visual */
926 else if(iPixelFormat
== 1) {
927 res
= &WineGLPixelFormatList
[0];
928 *fmt_count
= 1; /* Only show the format of our main visual */
930 else if((WineGLPixelFormatList
[iPixelFormat
-1].offscreenOnly
== TRUE
) && AllowOffscreen
) {
931 res
= &WineGLPixelFormatList
[iPixelFormat
-1];
932 *fmt_count
= WineGLPixelFormatListSize
;
933 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
936 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
941 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
942 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
)
946 /* Init the list of pixel formats when we need it */
947 if(!WineGLPixelFormatListSize
)
948 init_formats(display
, DefaultScreen(display
), visual
);
950 for(i
=0; i
<WineGLPixelFormatListSize
; i
++) {
951 if(WineGLPixelFormatList
[i
].fmt_id
== fmt_id
) {
952 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList
[i
].iPixelFormat
, fmt_id
);
953 return &WineGLPixelFormatList
[i
];
956 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
961 * X11DRV_ChoosePixelFormat
963 * Equivalent to glXChooseVisual.
965 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
966 const PIXELFORMATDESCRIPTOR
*ppfd
) {
967 WineGLPixelFormat
*fmt
= NULL
;
973 int bestDBuffer
= -1;
978 int bestStencil
= -1;
983 ERR("No libGL on this box - disabling OpenGL support !\n");
987 if (TRACE_ON(opengl
)) {
988 TRACE("(%p,%p)\n", physDev
, ppfd
);
990 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
994 ConvertPixelFormatWGLtoGLX(gdi_display
, 0, FALSE
/* offscreen */, &nPixelFormats
);
995 for(i
=0; i
<nPixelFormats
; i
++)
999 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1001 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, i
+1 /* 1-based index */, FALSE
/* offscreen */, &value
);
1005 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1006 if (value
& GLX_RGBA_BIT
)
1007 iPixelType
= PFD_TYPE_RGBA
;
1009 iPixelType
= PFD_TYPE_COLORINDEX
;
1011 if (ppfd
->iPixelType
!= iPixelType
)
1013 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1017 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1018 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1019 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1020 if (value
) dwFlags
|= PFD_STEREO
;
1021 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1022 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1023 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1024 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1025 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1027 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1028 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1029 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1030 * formats without the given flag set.
1031 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1032 * has indicated that a format without stereo is returned when stereo is unavailable.
1033 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1034 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1036 * To summarize the following is most likely the correct behavior:
1037 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1038 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1039 * stereo don't care -> it doesn't matter whether we get stereo or not
1041 * In Wine we will treat no-stereo the same way as don't care because it makes
1042 * format selection even more complicated and second drivers with Stereo advertise
1043 * each format twice anyway.
1046 /* Doublebuffer, see the comments above */
1047 if( !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) ) {
1048 if( ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
1049 ((dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) )
1051 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1052 bestStereo
= dwFlags
& PFD_STEREO
;
1056 bestStencil
= stencil
;
1063 /* Stereo, see the comments above. */
1064 if( !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) ) {
1065 if( ((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
1066 ((dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)) )
1068 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1069 bestStereo
= dwFlags
& PFD_STEREO
;
1073 bestStencil
= stencil
;
1080 /* Below we will do a number of checks to select the 'best' pixelformat.
1081 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1082 * The code works by trying to match the most important options as close as possible.
1083 * When a reasonable format is found, we will try to match more options. */
1086 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1087 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1089 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1090 bestStereo
= dwFlags
& PFD_STEREO
;
1094 bestStencil
= stencil
;
1098 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1099 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1104 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1105 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1107 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1108 bestStereo
= dwFlags
& PFD_STEREO
;
1112 bestStencil
= stencil
;
1116 } else if(bestAlpha
!= alpha
) {
1117 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1122 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1123 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1125 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1126 bestStereo
= dwFlags
& PFD_STEREO
;
1130 bestStencil
= stencil
;
1134 } else if(bestDepth
!= depth
) {
1135 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1140 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1141 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
1143 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1144 bestStereo
= dwFlags
& PFD_STEREO
;
1148 bestStencil
= stencil
;
1152 } else if(bestStencil
!= stencil
) {
1153 TRACE("stencil mismatch for iPixelFormat=%d\n", i
+1);
1158 if( ((ppfd
->cAuxBuffers
> bestAux
) && (aux
> bestAux
)) ||
1159 ((aux
>= ppfd
->cAuxBuffers
) && (aux
< bestAux
)) )
1161 bestDBuffer
= dwFlags
& PFD_DOUBLEBUFFER
;
1162 bestStereo
= dwFlags
& PFD_STEREO
;
1166 bestStencil
= stencil
;
1170 } else if(bestAux
!= aux
) {
1171 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1176 if(bestFormat
== -1) {
1177 TRACE("No matching mode was found returning 0\n");
1181 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1182 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, WineGLPixelFormatList
[bestFormat
].fmt_id
);
1185 wine_tsx11_unlock();
1190 * X11DRV_DescribePixelFormat
1192 * Get the pixel-format descriptor associated to the given id
1194 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1197 PIXELFORMATDESCRIPTOR
*ppfd
) {
1198 /*XVisualInfo *vis;*/
1201 WineGLPixelFormat
*fmt
;
1205 if (!has_opengl()) {
1206 ERR("No libGL on this box - disabling OpenGL support !\n");
1210 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1212 /* Look for the iPixelFormat in our list of supported formats. If it is supported we get the index in the FBConfig table and the number of supported formats back */
1213 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1215 /* The application is only querying the number of pixelformats */
1217 } else if(fmt
== NULL
) {
1218 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1222 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1223 ERR("Wrong structure size !\n");
1224 /* Should set error */
1230 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1231 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1234 /* These flags are always the same... */
1235 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1236 /* Now the flags extracted from the Visual */
1240 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_X_RENDERABLE
, &value
);
1242 ppfd
->dwFlags
|= PFD_SUPPORT_GDI
;
1244 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1245 if(value
& GLX_WINDOW_BIT
)
1246 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1247 if(value
& GLX_PIXMAP_BIT
)
1248 ppfd
->dwFlags
|= PFD_DRAW_TO_BITMAP
;
1250 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_CONFIG_CAVEAT
, &value
);
1251 if(value
== GLX_SLOW_CONFIG
)
1252 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1254 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1256 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1257 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1259 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1262 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1263 if (value
& GLX_RGBA_BIT
)
1264 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1266 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1269 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1270 ppfd
->cColorBits
= value
;
1272 /* Red, green, blue and alpha bits / shifts */
1273 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1274 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1275 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1276 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1277 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1279 ppfd
->cRedBits
= rb
;
1280 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1281 ppfd
->cBlueBits
= bb
;
1282 ppfd
->cBlueShift
= ab
;
1283 ppfd
->cGreenBits
= gb
;
1284 ppfd
->cGreenShift
= bb
+ ab
;
1285 ppfd
->cAlphaBits
= ab
;
1286 ppfd
->cAlphaShift
= 0;
1289 ppfd
->cRedShift
= 0;
1290 ppfd
->cBlueBits
= 0;
1291 ppfd
->cBlueShift
= 0;
1292 ppfd
->cGreenBits
= 0;
1293 ppfd
->cGreenShift
= 0;
1294 ppfd
->cAlphaBits
= 0;
1295 ppfd
->cAlphaShift
= 0;
1298 /* Accum RGBA bits */
1299 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1300 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1301 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1302 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1304 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1305 ppfd
->cAccumRedBits
= rb
;
1306 ppfd
->cAccumGreenBits
= gb
;
1307 ppfd
->cAccumBlueBits
= bb
;
1308 ppfd
->cAccumAlphaBits
= ab
;
1311 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1312 ppfd
->cDepthBits
= value
;
1315 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1316 ppfd
->cStencilBits
= value
;
1318 wine_tsx11_unlock();
1320 /* Aux : to do ... */
1322 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1324 if (TRACE_ON(opengl
)) {
1325 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1332 * X11DRV_GetPixelFormat
1334 * Get the pixel-format id used by this DC
1336 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1337 WineGLPixelFormat
*fmt
;
1339 TRACE("(%p)\n", physDev
);
1341 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1344 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1345 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1348 else if(fmt
->offscreenOnly
)
1350 /* Offscreen formats can't be used with traditional WGL calls.
1351 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1352 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1356 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1357 return physDev
->current_pf
;
1361 * X11DRV_SetPixelFormat
1363 * Set the pixel-format id used by this DC
1365 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1367 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1368 WineGLPixelFormat
*fmt
;
1371 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1373 if (!has_opengl()) {
1374 ERR("No libGL on this box - disabling OpenGL support !\n");
1378 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1379 if(get_glxdrawable(physDev
) == root_window
)
1381 ERR("Invalid operation on root_window\n");
1385 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1386 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1388 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1392 physDev
->current_pf
= iPixelFormat
;
1394 if (TRACE_ON(opengl
)) {
1398 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1400 * in case of root window created HDCs we crash here :(
1402 Drawable drawable = get_drawable( physDev->hdc );
1403 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1404 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1405 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1406 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1407 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1408 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1409 TRACE(" - WIDTH as %d\n", tmp);
1410 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1411 TRACE(" - HEIGHT as %d\n", tmp);
1413 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1415 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1417 TRACE(" FBConfig have :\n");
1418 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1419 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1420 TRACE(" - VISUAL_ID 0x%x\n", value
);
1421 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1422 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1429 * X11DRV_wglCreateContext
1431 * For OpenGL32 wglCreateContext.
1433 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1435 Wine_GLContext
*ret
;
1436 WineGLPixelFormat
*fmt
;
1437 int hdcPF
= physDev
->current_pf
;
1441 HDC hdc
= physDev
->hdc
;
1443 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1445 if (!has_opengl()) {
1446 ERR("No libGL on this box - disabling OpenGL support !\n");
1450 /* First, get the visual in use by the X11DRV */
1451 if (!gdi_display
) return 0;
1453 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1454 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1455 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1456 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1457 * If this fails something is very wrong on the system. */
1459 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1460 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1464 if (fmt_count
< hdcPF
) {
1465 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, hdcPF
, fmt_count
);
1466 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1470 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1472 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1473 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1477 /* The context will be allocated in the wglMakeCurrent call */
1479 ret
= alloc_context();
1480 wine_tsx11_unlock();
1482 ret
->physDev
= physDev
;
1486 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1488 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1493 * X11DRV_wglDeleteContext
1495 * For OpenGL32 wglDeleteContext.
1497 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1499 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1502 TRACE("(%p)\n", hglrc
);
1504 if (!has_opengl()) {
1505 ERR("No libGL on this box - disabling OpenGL support !\n");
1510 /* A game (Half Life not to name it) deletes twice the same context,
1511 * so make sure it is valid first */
1512 if (is_valid_context( ctx
))
1514 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1519 WARN("Error deleting context !\n");
1520 SetLastError(ERROR_INVALID_HANDLE
);
1523 wine_tsx11_unlock();
1529 * X11DRV_wglGetCurrentReadDCARB
1531 * For OpenGL32 wglGetCurrentReadDCARB.
1533 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1541 gl_d
= pglXGetCurrentReadDrawable();
1542 ret
= get_hdc_from_Drawable(gl_d
);
1543 wine_tsx11_unlock();
1545 TRACE(" returning %p (GL drawable %lu)\n", ret
, gl_d
);
1550 * X11DRV_wglGetProcAddress
1552 * For OpenGL32 wglGetProcAddress.
1554 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1557 const WineGLExtension
*ext
;
1559 int padding
= 32 - strlen(lpszProc
);
1563 if (!has_opengl()) {
1564 ERR("No libGL on this box - disabling OpenGL support !\n");
1568 /* Check the table of WGL extensions to see if we need to return a WGL extension
1569 * or a function pointer to a native OpenGL function. */
1570 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1571 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1573 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1574 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1575 ext
= WineGLExtensionList
[i
];
1576 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1577 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1578 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1579 return ext
->extEntryPoints
[j
].funcAddress
;
1585 ERR("(%s) - not found\n", lpszProc
);
1589 /***********************************************************************
1590 * sync_current_drawable
1592 * Adjust the current viewport and scissor in order to position
1593 * and size the current drawable correctly on the parent window.
1595 static void sync_current_drawable(BOOL updatedc
)
1601 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1605 if (ctx
&& ctx
->physDev
)
1608 GetClipBox(ctx
->physDev
->hdc
, &rc
); /* Make sure physDev is up to date */
1610 dy
= ctx
->physDev
->drawable_rect
.bottom
- ctx
->physDev
->drawable_rect
.top
-
1611 ctx
->physDev
->dc_rect
.bottom
;
1612 width
= ctx
->physDev
->dc_rect
.right
- ctx
->physDev
->dc_rect
.left
;
1613 height
= ctx
->physDev
->dc_rect
.bottom
- ctx
->physDev
->dc_rect
.top
;
1617 pglViewport(ctx
->physDev
->dc_rect
.left
+ ctx
->viewport
.left
,
1618 dy
+ ctx
->viewport
.top
,
1619 ctx
->viewport
.right
? (ctx
->viewport
.right
- ctx
->viewport
.left
) : width
,
1620 ctx
->viewport
.bottom
? (ctx
->viewport
.bottom
- ctx
->viewport
.top
) : height
);
1622 pglEnable(GL_SCISSOR_TEST
);
1624 if (ctx
->scissor_enabled
)
1625 pglScissor(ctx
->physDev
->dc_rect
.left
+ min(width
, max(0, ctx
->scissor
.left
)),
1626 dy
+ min(height
, max(0, ctx
->scissor
.top
)),
1627 min(width
, max(0, ctx
->scissor
.right
- ctx
->scissor
.left
)),
1628 min(height
, max(0, ctx
->scissor
.bottom
- ctx
->scissor
.top
)));
1630 pglScissor(ctx
->physDev
->dc_rect
.left
, dy
, width
, height
);
1632 wine_tsx11_unlock();
1637 * X11DRV_wglMakeCurrent
1639 * For OpenGL32 wglMakeCurrent.
1641 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1643 HDC hdc
= physDev
->hdc
;
1644 DWORD type
= GetObjectType(hdc
);
1646 TRACE("(%p,%p)\n", hdc
, hglrc
);
1648 if (!has_opengl()) {
1649 ERR("No libGL on this box - disabling OpenGL support !\n");
1654 if (hglrc
== NULL
) {
1655 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1656 NtCurrentTeb()->glContext
= NULL
;
1658 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1659 Drawable drawable
= get_glxdrawable(physDev
);
1660 if (ctx
->ctx
== NULL
) {
1661 /* The describe lines below are for debugging purposes only */
1662 if (TRACE_ON(wgl
)) {
1663 describeDrawable(ctx
, drawable
);
1664 describeContext(ctx
);
1667 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1668 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1670 TRACE(" Creating GLX Context\n");
1672 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1673 else /* Create a GLX Context for a pbuffer */
1674 ctx
->ctx
= pglXCreateNewContext(gdi_display
, ctx
->fmt
->fbconfig
, ctx
->fmt
->render_type
, NULL
, True
);
1676 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1678 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1679 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1680 NtCurrentTeb()->glContext
= ctx
;
1683 ctx
->physDev
= physDev
;
1685 if (type
== OBJ_MEMDC
)
1687 ctx
->do_escape
= TRUE
;
1688 pglDrawBuffer(GL_FRONT_LEFT
);
1692 sync_current_drawable(FALSE
);
1696 wine_tsx11_unlock();
1697 TRACE(" returning %s\n", (ret
? "True" : "False"));
1702 * X11DRV_wglMakeContextCurrentARB
1704 * For OpenGL32 wglMakeContextCurrentARB
1706 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
)
1709 TRACE("(%p,%p,%p)\n", hDrawDev
, hReadDev
, hglrc
);
1711 if (!has_opengl()) {
1712 ERR("No libGL on this box - disabling OpenGL support !\n");
1717 if (hglrc
== NULL
) {
1718 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1719 NtCurrentTeb()->glContext
= NULL
;
1721 if (NULL
== pglXMakeContextCurrent
) {
1724 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1725 Drawable d_draw
= get_glxdrawable(hDrawDev
);
1726 Drawable d_read
= get_glxdrawable(hReadDev
);
1728 if (ctx
->ctx
== NULL
) {
1729 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, GetObjectType(hDrawDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1730 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1732 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1733 NtCurrentTeb()->glContext
= ctx
;
1736 wine_tsx11_unlock();
1738 TRACE(" returning %s\n", (ret
? "True" : "False"));
1743 * X11DRV_wglShareLists
1745 * For OpenGL32 wglShaderLists.
1747 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1748 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1749 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1751 TRACE("(%p, %p)\n", org
, dest
);
1753 if (!has_opengl()) {
1754 ERR("No libGL on this box - disabling OpenGL support !\n");
1758 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1759 ERR("Could not share display lists, context already created !\n");
1762 if (org
->ctx
== NULL
) {
1764 describeContext(org
);
1767 org
->ctx
= pglXCreateContext(gdi_display
, org
->vis
, NULL
, GetObjectType(org
->physDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1768 else /* Create a GLX Context for a pbuffer */
1769 org
->ctx
= pglXCreateNewContext(gdi_display
, org
->fmt
->fbconfig
, org
->fmt
->render_type
, NULL
, True
);
1770 wine_tsx11_unlock();
1771 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1775 describeContext(dest
);
1776 /* Create the destination context with display lists shared */
1778 dest
->ctx
= pglXCreateContext(gdi_display
, dest
->vis
, org
->ctx
, GetObjectType(org
->physDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1779 else /* Create a GLX Context for a pbuffer */
1780 dest
->ctx
= pglXCreateNewContext(gdi_display
, dest
->fmt
->fbconfig
, dest
->fmt
->render_type
, org
->ctx
, True
);
1781 wine_tsx11_unlock();
1782 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1789 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1791 /* We are running using client-side rendering fonts... */
1795 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1799 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1800 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1801 wine_tsx11_unlock();
1803 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1804 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1805 int height
, width_int
;
1807 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1808 if (needed_size
== GDI_ERROR
) {
1809 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1812 TRACE(" - needed size : %d\n", needed_size
);
1815 if (needed_size
> size
) {
1817 HeapFree(GetProcessHeap(), 0, bitmap
);
1818 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1819 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1820 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1822 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1823 if (TRACE_ON(opengl
)) {
1824 unsigned int height
, width
, bitmask
;
1825 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1827 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1828 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1829 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1830 if (needed_size
!= 0) {
1831 TRACE(" - bitmap :\n");
1832 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1834 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1839 if (*bitmap_
& bitmask
)
1844 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1850 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1851 * glyph for it to be drawn properly.
1853 if (needed_size
!= 0) {
1854 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1855 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1857 for (width
= 0; width
< width_int
; width
++) {
1858 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1859 ((int *) bitmap
)[height
* width_int
+ width
];
1865 pglNewList(listBase
++, GL_COMPILE
);
1866 if (needed_size
!= 0) {
1867 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1868 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1869 gm
.gmCellIncX
, gm
.gmCellIncY
,
1872 /* This is the case of 'empty' glyphs like the space character */
1873 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1876 wine_tsx11_unlock();
1880 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1881 wine_tsx11_unlock();
1883 HeapFree(GetProcessHeap(), 0, bitmap
);
1884 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1889 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1890 wine_tsx11_unlock();
1892 HeapFree(GetProcessHeap(), 0, bitmap
);
1893 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1898 * X11DRV_wglUseFontBitmapsA
1900 * For OpenGL32 wglUseFontBitmapsA.
1902 BOOL
X11DRV_wglUseFontBitmapsA(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
, GetGlyphOutlineA
);
1918 /* I assume that the glyphs are at the same position for X and for Windows */
1919 pglXUseXFont(fid
, first
, count
, listBase
);
1920 wine_tsx11_unlock();
1925 * X11DRV_wglUseFontBitmapsW
1927 * For OpenGL32 wglUseFontBitmapsW.
1929 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1931 Font fid
= physDev
->font
;
1933 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1935 if (!has_opengl()) {
1936 ERR("No libGL on this box - disabling OpenGL support !\n");
1941 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1944 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1947 /* I assume that the glyphs are at the same position for X and for Windows */
1948 pglXUseXFont(fid
, first
, count
, listBase
);
1949 wine_tsx11_unlock();
1953 static void WINAPI
X11DRV_wglDisable(GLenum cap
)
1955 if (cap
== GL_SCISSOR_TEST
)
1957 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1960 ctx
->scissor_enabled
= FALSE
;
1966 wine_tsx11_unlock();
1970 static void WINAPI
X11DRV_wglEnable(GLenum cap
)
1972 if (cap
== GL_SCISSOR_TEST
)
1974 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1977 ctx
->scissor_enabled
= TRUE
;
1983 wine_tsx11_unlock();
1987 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1988 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
1995 GLXContext gl_ctx
= pglXGetCurrentContext();
1996 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1998 pglGetIntegerv(pname
, params
);
2000 * if we cannot find a Wine Context
2001 * we only have the default wine desktop context,
2002 * so if we have only a 24 depth say we have 32
2004 if (NULL
== ret
&& 24 == *params
) {
2007 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
2012 GLXContext gl_ctx
= pglXGetCurrentContext();
2013 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
2015 pglXGetFBConfigAttrib(gdi_display
, ret
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2016 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2020 pglGetIntegerv(pname
, params
);
2023 wine_tsx11_unlock();
2026 static GLboolean WINAPI
X11DRV_wglIsEnabled(GLenum cap
)
2028 GLboolean enabled
= False
;
2030 if (cap
== GL_SCISSOR_TEST
)
2032 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2035 enabled
= ctx
->scissor_enabled
;
2040 enabled
= pglIsEnabled(cap
);
2041 wine_tsx11_unlock();
2046 static void WINAPI
X11DRV_wglScissor(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2048 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2052 ctx
->scissor
.left
= x
;
2053 ctx
->scissor
.top
= y
;
2054 ctx
->scissor
.right
= x
+ width
;
2055 ctx
->scissor
.bottom
= y
+ height
;
2057 sync_current_drawable(TRUE
);
2061 static void WINAPI
X11DRV_wglViewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2063 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2067 ctx
->viewport
.left
= x
;
2068 ctx
->viewport
.top
= y
;
2069 ctx
->viewport
.right
= x
+ width
;
2070 ctx
->viewport
.bottom
= y
+ height
;
2072 sync_current_drawable(TRUE
);
2077 * X11DRV_wglGetExtensionsStringARB
2079 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2081 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2082 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2083 return WineGLInfo
.wglExtensions
;
2087 * X11DRV_wglCreatePbufferARB
2089 * WGL_ARB_pbuffer: wglCreatePbufferARB
2091 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2093 Wine_GLPBuffer
* object
= NULL
;
2094 WineGLPixelFormat
*fmt
= NULL
;
2099 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2101 if (0 >= iPixelFormat
) {
2102 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2103 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2104 return NULL
; /* unexpected error */
2107 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2108 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2110 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2111 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2112 goto create_failed
; /* unexpected error */
2115 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2116 if (NULL
== object
) {
2117 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2118 goto create_failed
; /* unexpected error */
2121 object
->display
= gdi_display
;
2122 object
->width
= iWidth
;
2123 object
->height
= iHeight
;
2126 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2127 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2128 while (piAttribList
&& 0 != *piAttribList
) {
2130 switch (*piAttribList
) {
2131 case WGL_PBUFFER_LARGEST_ARB
: {
2133 attr_v
= *piAttribList
;
2134 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2135 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2139 case WGL_TEXTURE_FORMAT_ARB
: {
2141 attr_v
= *piAttribList
;
2142 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2143 if (use_render_texture_ati
) {
2146 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2147 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2148 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2150 SetLastError(ERROR_INVALID_DATA
);
2153 object
->use_render_texture
= 1;
2154 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2156 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2157 object
->use_render_texture
= 0;
2159 if (!use_render_texture_emulation
) {
2160 SetLastError(ERROR_INVALID_DATA
);
2164 case WGL_TEXTURE_RGB_ARB
:
2165 object
->use_render_texture
= GL_RGB
;
2166 object
->texture_bpp
= 3;
2167 object
->texture_format
= GL_RGB
;
2168 object
->texture_type
= GL_UNSIGNED_BYTE
;
2170 case WGL_TEXTURE_RGBA_ARB
:
2171 object
->use_render_texture
= GL_RGBA
;
2172 object
->texture_bpp
= 4;
2173 object
->texture_format
= GL_RGBA
;
2174 object
->texture_type
= GL_UNSIGNED_BYTE
;
2177 /* WGL_FLOAT_COMPONENTS_NV */
2178 case WGL_TEXTURE_FLOAT_R_NV
:
2179 object
->use_render_texture
= GL_FLOAT_R_NV
;
2180 object
->texture_bpp
= 4;
2181 object
->texture_format
= GL_RED
;
2182 object
->texture_type
= GL_FLOAT
;
2184 case WGL_TEXTURE_FLOAT_RG_NV
:
2185 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2186 object
->texture_bpp
= 8;
2187 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2188 object
->texture_type
= GL_FLOAT
;
2190 case WGL_TEXTURE_FLOAT_RGB_NV
:
2191 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2192 object
->texture_bpp
= 12;
2193 object
->texture_format
= GL_RGB
;
2194 object
->texture_type
= GL_FLOAT
;
2196 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2197 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2198 object
->texture_bpp
= 16;
2199 object
->texture_format
= GL_RGBA
;
2200 object
->texture_type
= GL_FLOAT
;
2203 ERR("Unknown texture format: %x\n", attr_v
);
2204 SetLastError(ERROR_INVALID_DATA
);
2212 case WGL_TEXTURE_TARGET_ARB
: {
2214 attr_v
= *piAttribList
;
2215 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2216 if (use_render_texture_ati
) {
2219 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2220 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2221 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2222 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2224 SetLastError(ERROR_INVALID_DATA
);
2227 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2229 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2230 object
->texture_target
= 0;
2232 if (!use_render_texture_emulation
) {
2233 SetLastError(ERROR_INVALID_DATA
);
2237 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2238 if (iWidth
!= iHeight
) {
2239 SetLastError(ERROR_INVALID_DATA
);
2242 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2243 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2246 case WGL_TEXTURE_1D_ARB
: {
2248 SetLastError(ERROR_INVALID_DATA
);
2251 object
->texture_target
= GL_TEXTURE_1D
;
2252 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2255 case WGL_TEXTURE_2D_ARB
: {
2256 object
->texture_target
= GL_TEXTURE_2D
;
2257 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2260 case WGL_TEXTURE_RECTANGLE_NV
: {
2261 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2262 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2266 ERR("Unknown texture target: %x\n", attr_v
);
2267 SetLastError(ERROR_INVALID_DATA
);
2275 case WGL_MIPMAP_TEXTURE_ARB
: {
2277 attr_v
= *piAttribList
;
2278 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2279 if (use_render_texture_ati
) {
2280 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2282 if (!use_render_texture_emulation
) {
2283 SetLastError(ERROR_INVALID_DATA
);
2293 PUSH1(attribs
, None
);
2294 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2295 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2296 if (!object
->drawable
) {
2297 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2298 goto create_failed
; /* unexpected error */
2300 TRACE("->(%p)\n", object
);
2301 return (HPBUFFERARB
) object
;
2304 HeapFree(GetProcessHeap(), 0, object
);
2305 TRACE("->(FAILED)\n");
2306 return (HPBUFFERARB
) NULL
;
2310 * X11DRV_wglDestroyPbufferARB
2312 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2314 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2316 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2317 TRACE("(%p)\n", hPbuffer
);
2318 if (NULL
== object
) {
2319 SetLastError(ERROR_INVALID_HANDLE
);
2322 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2323 HeapFree(GetProcessHeap(), 0, object
);
2328 * X11DRV_wglGetPbufferDCARB
2330 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2331 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2332 * Gdi32 implements the part of this function which creates a device context.
2333 * This part associates the physDev with the X drawable of the pbuffer.
2335 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2337 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2338 if (NULL
== object
) {
2339 SetLastError(ERROR_INVALID_HANDLE
);
2343 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2344 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2345 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2346 physDev
->drawable
= object
->drawable
;
2347 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2348 physDev
->dc_rect
= physDev
->drawable_rect
;
2350 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2351 return physDev
->hdc
;
2355 * X11DRV_wglQueryPbufferARB
2357 * WGL_ARB_pbuffer: wglQueryPbufferARB
2359 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2361 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2362 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2363 if (NULL
== object
) {
2364 SetLastError(ERROR_INVALID_HANDLE
);
2367 switch (iAttribute
) {
2368 case WGL_PBUFFER_WIDTH_ARB
:
2369 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2371 case WGL_PBUFFER_HEIGHT_ARB
:
2372 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2375 case WGL_PBUFFER_LOST_ARB
:
2376 /* GLX Pbuffers cannot be lost by default. We can support this by
2377 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2378 * to receive pixel buffer clobber events, however that may or may
2379 * not give any benefit */
2380 *piValue
= GL_FALSE
;
2383 case WGL_TEXTURE_FORMAT_ARB
:
2384 if (use_render_texture_ati
) {
2386 int type
= WGL_NO_TEXTURE_ARB
;
2387 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2389 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2390 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2391 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2395 if (!object
->use_render_texture
) {
2396 *piValue
= WGL_NO_TEXTURE_ARB
;
2398 if (!use_render_texture_emulation
) {
2399 SetLastError(ERROR_INVALID_HANDLE
);
2402 switch(object
->use_render_texture
) {
2404 *piValue
= WGL_TEXTURE_RGB_ARB
;
2407 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2409 /* WGL_FLOAT_COMPONENTS_NV */
2411 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2413 case GL_FLOAT_RG_NV
:
2414 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2416 case GL_FLOAT_RGB_NV
:
2417 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2419 case GL_FLOAT_RGBA_NV
:
2420 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2423 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2429 case WGL_TEXTURE_TARGET_ARB
:
2430 if (use_render_texture_ati
) {
2432 int type
= WGL_NO_TEXTURE_ARB
;
2433 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2435 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2436 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2437 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2438 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2442 if (!object
->texture_target
) {
2443 *piValue
= WGL_NO_TEXTURE_ARB
;
2445 if (!use_render_texture_emulation
) {
2446 SetLastError(ERROR_INVALID_DATA
);
2449 switch (object
->texture_target
) {
2450 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2451 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2452 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2453 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2459 case WGL_MIPMAP_TEXTURE_ARB
:
2460 if (use_render_texture_ati
) {
2461 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2463 *piValue
= GL_FALSE
; /** don't support that */
2464 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2469 FIXME("unexpected attribute %x\n", iAttribute
);
2477 * X11DRV_wglReleasePbufferDCARB
2479 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2481 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2483 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2489 * X11DRV_wglSetPbufferAttribARB
2491 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2493 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2495 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2496 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2497 if (NULL
== object
) {
2498 SetLastError(ERROR_INVALID_HANDLE
);
2501 if (!object
->use_render_texture
) {
2502 SetLastError(ERROR_INVALID_HANDLE
);
2505 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2508 if (NULL
!= pglXDrawableAttribATI
) {
2509 if (use_render_texture_ati
) {
2510 FIXME("Need conversion for GLX_ATI_render_texture\n");
2512 return pglXDrawableAttribATI(object
->display
, object
->drawable
, piAttribList
);
2518 * X11DRV_wglChoosePixelFormatARB
2520 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2522 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2527 GLXFBConfig
* cfgs
= NULL
;
2531 WineGLPixelFormat
*fmt
;
2535 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2536 if (NULL
!= pfAttribFList
) {
2537 FIXME("unused pfAttribFList\n");
2540 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2541 if (-1 == nAttribs
) {
2542 WARN("Cannot convert WGL to GLX attributes\n");
2545 PUSH1(attribs
, None
);
2547 /* Search for FB configurations matching the requirements in attribs */
2548 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2550 WARN("Compatible Pixel Format not found\n");
2554 /* Loop through all matching formats and check if they are suitable.
2555 * Note that this function should at max return nMaxFormats different formats */
2556 for(run
=0; run
< 2; run
++)
2558 for (it
= 0; it
< nCfgs
; ++it
) {
2559 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2561 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2565 /* Search for the format in our list of compatible formats */
2566 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
);
2570 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2571 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2574 if(pfmt_it
< nMaxFormats
) {
2575 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2576 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2582 *nNumFormats
= pfmt_it
;
2589 * X11DRV_wglGetPixelFormatAttribivARB
2591 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2593 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2596 WineGLPixelFormat
*fmt
= NULL
;
2600 int nWGLFormats
= 0;
2602 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2604 if (0 < iLayerPlane
) {
2605 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2609 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2610 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2611 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2612 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2614 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2617 for (i
= 0; i
< nAttributes
; ++i
) {
2618 const int curWGLAttr
= piAttributes
[i
];
2619 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2621 switch (curWGLAttr
) {
2622 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2623 piValues
[i
] = nWGLFormats
;
2626 case WGL_SUPPORT_OPENGL_ARB
:
2627 piValues
[i
] = GL_TRUE
;
2630 case WGL_ACCELERATION_ARB
:
2631 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2632 if (!fmt
) goto pix_error
;
2633 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2634 if (hTest
) goto get_error
;
2636 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2637 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
; break;
2638 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2640 ERR("unexpected Config Caveat(%x)\n", tmp
);
2641 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2645 case WGL_TRANSPARENT_ARB
:
2646 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2647 if (!fmt
) goto pix_error
;
2648 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2649 if (hTest
) goto get_error
;
2650 piValues
[i
] = GL_FALSE
;
2651 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2654 case WGL_PIXEL_TYPE_ARB
:
2655 curGLXAttr
= GLX_RENDER_TYPE
;
2656 if (!fmt
) goto pix_error
;
2657 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2658 if (hTest
) goto get_error
;
2659 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2660 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2661 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2662 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2663 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2665 ERR("unexpected RenderType(%x)\n", tmp
);
2666 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2670 case WGL_COLOR_BITS_ARB
:
2671 curGLXAttr
= GLX_BUFFER_SIZE
;
2674 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2675 if (use_render_texture_ati
) {
2676 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2679 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2680 if (use_render_texture_ati
) {
2681 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2684 if (!use_render_texture_emulation
) {
2685 piValues
[i
] = GL_FALSE
;
2688 curGLXAttr
= GLX_RENDER_TYPE
;
2689 if (!fmt
) goto pix_error
;
2690 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2691 if (hTest
) goto get_error
;
2692 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2693 piValues
[i
] = GL_FALSE
;
2696 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2697 if (hTest
) goto get_error
;
2698 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2701 case WGL_BLUE_BITS_ARB
:
2702 curGLXAttr
= GLX_BLUE_SIZE
;
2704 case WGL_RED_BITS_ARB
:
2705 curGLXAttr
= GLX_RED_SIZE
;
2707 case WGL_GREEN_BITS_ARB
:
2708 curGLXAttr
= GLX_GREEN_SIZE
;
2710 case WGL_ALPHA_BITS_ARB
:
2711 curGLXAttr
= GLX_ALPHA_SIZE
;
2713 case WGL_DEPTH_BITS_ARB
:
2714 curGLXAttr
= GLX_DEPTH_SIZE
;
2716 case WGL_STENCIL_BITS_ARB
:
2717 curGLXAttr
= GLX_STENCIL_SIZE
;
2719 case WGL_DOUBLE_BUFFER_ARB
:
2720 curGLXAttr
= GLX_DOUBLEBUFFER
;
2722 case WGL_STEREO_ARB
:
2723 curGLXAttr
= GLX_STEREO
;
2725 case WGL_AUX_BUFFERS_ARB
:
2726 curGLXAttr
= GLX_AUX_BUFFERS
;
2729 case WGL_SUPPORT_GDI_ARB
:
2730 if (!fmt
) goto pix_error
;
2731 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &tmp
);
2732 if (hTest
) goto get_error
;
2734 piValues
[i
] = GL_FALSE
;
2737 curGLXAttr
= GLX_X_RENDERABLE
;
2740 case WGL_DRAW_TO_WINDOW_ARB
:
2741 case WGL_DRAW_TO_BITMAP_ARB
:
2742 case WGL_DRAW_TO_PBUFFER_ARB
:
2743 if (!fmt
) goto pix_error
;
2744 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2745 if (hTest
) goto get_error
;
2746 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2747 (curWGLAttr
== WGL_DRAW_TO_BITMAP_ARB
&& (tmp
&GLX_PIXMAP_BIT
)) ||
2748 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2749 piValues
[i
] = GL_TRUE
;
2751 piValues
[i
] = GL_FALSE
;
2754 case WGL_PBUFFER_LARGEST_ARB
:
2755 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2758 case WGL_SAMPLE_BUFFERS_ARB
:
2759 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2762 case WGL_SAMPLES_ARB
:
2763 curGLXAttr
= GLX_SAMPLES_ARB
;
2766 case WGL_FLOAT_COMPONENTS_NV
:
2767 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2770 case WGL_ACCUM_RED_BITS_ARB
:
2771 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2773 case WGL_ACCUM_GREEN_BITS_ARB
:
2774 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2776 case WGL_ACCUM_BLUE_BITS_ARB
:
2777 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2779 case WGL_ACCUM_ALPHA_BITS_ARB
:
2780 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2782 case WGL_ACCUM_BITS_ARB
:
2783 if (!fmt
) goto pix_error
;
2784 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2785 if (hTest
) goto get_error
;
2787 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2788 if (hTest
) goto get_error
;
2790 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2791 if (hTest
) goto get_error
;
2793 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2794 if (hTest
) goto get_error
;
2799 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2802 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2803 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2804 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2806 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2807 * and check which options can work using iPixelFormat=0 and which not.
2808 * A problem would be that this function is an extension. This would
2809 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2811 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2812 if (!fmt
) goto pix_error
;
2813 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2814 if (hTest
) goto get_error
;
2817 piValues
[i
] = GL_FALSE
;
2823 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2827 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2832 * X11DRV_wglGetPixelFormatAttribfvARB
2834 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2836 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2842 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2844 /* Allocate a temporary array to store integer values */
2845 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2847 ERR("couldn't allocate %d array\n", nAttributes
);
2851 /* Piggy-back on wglGetPixelFormatAttribivARB */
2852 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2854 /* Convert integer values to float. Should also check for attributes
2855 that can give decimal values here */
2856 for (i
=0; i
<nAttributes
;i
++) {
2857 pfValues
[i
] = attr
[i
];
2861 HeapFree(GetProcessHeap(), 0, attr
);
2866 * X11DRV_wglBindTexImageARB
2868 * WGL_ARB_render_texture: wglBindTexImageARB
2870 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2872 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2873 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2874 if (NULL
== object
) {
2875 SetLastError(ERROR_INVALID_HANDLE
);
2878 if (!object
->use_render_texture
) {
2879 SetLastError(ERROR_INVALID_HANDLE
);
2883 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2884 static int init
= 0;
2885 int prev_binded_texture
= 0;
2886 GLXContext prev_context
= pglXGetCurrentContext();
2887 Drawable prev_drawable
= pglXGetCurrentDrawable();
2888 GLXContext tmp_context
;
2890 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2891 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2892 isn't ideal performance wise but I wasn't able to get other ways working.
2895 init
= 1; /* Only show the FIXME once for performance reasons */
2896 FIXME("partial stub!\n");
2899 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
2900 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2902 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2904 /* Switch to our pbuffer */
2905 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2907 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2908 * After that upload the pbuffer texture data. */
2909 pglBindTexture(object
->texture_target
, prev_binded_texture
);
2910 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2912 /* Switch back to the original drawable and upload the pbuffer-texture */
2913 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
2914 pglXDestroyContext(gdi_display
, tmp_context
);
2918 if (NULL
!= pglXBindTexImageATI
) {
2923 case WGL_FRONT_LEFT_ARB
:
2924 buffer
= GLX_FRONT_LEFT_ATI
;
2926 case WGL_FRONT_RIGHT_ARB
:
2927 buffer
= GLX_FRONT_RIGHT_ATI
;
2929 case WGL_BACK_LEFT_ARB
:
2930 buffer
= GLX_BACK_LEFT_ATI
;
2932 case WGL_BACK_RIGHT_ARB
:
2933 buffer
= GLX_BACK_RIGHT_ATI
;
2936 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2940 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
2941 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
2942 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
2943 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
2944 * works fine using our pbuffer emulation path.
2946 return pglXBindTexImageATI(object
->display
, object
->drawable
, buffer
);
2952 * X11DRV_wglReleaseTexImageARB
2954 * WGL_ARB_render_texture: wglReleaseTexImageARB
2956 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2958 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2959 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2960 if (NULL
== object
) {
2961 SetLastError(ERROR_INVALID_HANDLE
);
2964 if (!object
->use_render_texture
) {
2965 SetLastError(ERROR_INVALID_HANDLE
);
2968 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2971 if (NULL
!= pglXReleaseTexImageATI
) {
2976 case WGL_FRONT_LEFT_ARB
:
2977 buffer
= GLX_FRONT_LEFT_ATI
;
2979 case WGL_FRONT_RIGHT_ARB
:
2980 buffer
= GLX_FRONT_RIGHT_ATI
;
2982 case WGL_BACK_LEFT_ARB
:
2983 buffer
= GLX_BACK_LEFT_ATI
;
2985 case WGL_BACK_RIGHT_ARB
:
2986 buffer
= GLX_BACK_RIGHT_ATI
;
2989 ERR("Unknown iBuffer=%#x\n", iBuffer
);
2992 return pglXReleaseTexImageATI(object
->display
, object
->drawable
, buffer
);
2998 * X11DRV_wglGetExtensionsStringEXT
3000 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3002 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
3003 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3004 return WineGLInfo
.wglExtensions
;
3008 * X11DRV_wglGetSwapIntervalEXT
3010 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3012 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
3013 FIXME("(),stub!\n");
3014 return swap_interval
;
3018 * X11DRV_wglSwapIntervalEXT
3020 * WGL_EXT_swap_control: wglSwapIntervalEXT
3022 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
3023 TRACE("(%d)\n", interval
);
3024 swap_interval
= interval
;
3025 if (NULL
!= pglXSwapIntervalSGI
) {
3026 return 0 == pglXSwapIntervalSGI(interval
);
3028 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3033 * X11DRV_wglAllocateMemoryNV
3035 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3037 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
3038 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
3039 if (pglXAllocateMemoryNV
== NULL
)
3042 return pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
3046 * X11DRV_wglFreeMemoryNV
3048 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3050 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
3051 TRACE("(%p)\n", pointer
);
3052 if (pglXFreeMemoryNV
== NULL
)
3055 pglXFreeMemoryNV(pointer
);
3059 * glxRequireVersion (internal)
3061 * Check if the supported GLX version matches requiredVersion.
3063 static BOOL
glxRequireVersion(int requiredVersion
)
3065 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3066 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3072 static BOOL
glxRequireExtension(const char *requiredExtension
)
3074 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3081 static void register_extension_string(const char *ext
)
3083 if (WineGLInfo
.wglExtensions
[0])
3084 strcat(WineGLInfo
.wglExtensions
, " ");
3085 strcat(WineGLInfo
.wglExtensions
, ext
);
3087 TRACE("'%s'\n", ext
);
3090 static BOOL
register_extension(const WineGLExtension
* ext
)
3094 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3095 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3097 register_extension_string(ext
->extName
);
3099 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3100 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3105 static const WineGLExtension WGL_internal_functions
=
3109 { "wglDisable", X11DRV_wglDisable
},
3110 { "wglEnable", X11DRV_wglEnable
},
3111 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3112 { "wglIsEnabled", X11DRV_wglIsEnabled
},
3113 { "wglScissor", X11DRV_wglScissor
},
3114 { "wglViewport", X11DRV_wglViewport
},
3119 static const WineGLExtension WGL_ARB_extensions_string
=
3121 "WGL_ARB_extensions_string",
3123 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3127 static const WineGLExtension WGL_ARB_make_current_read
=
3129 "WGL_ARB_make_current_read",
3131 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3132 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3136 static const WineGLExtension WGL_ARB_multisample
=
3138 "WGL_ARB_multisample",
3141 static const WineGLExtension WGL_ARB_pbuffer
=
3145 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3146 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3147 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3148 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3149 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3150 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3154 static const WineGLExtension WGL_ARB_pixel_format
=
3156 "WGL_ARB_pixel_format",
3158 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3159 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3160 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3164 static const WineGLExtension WGL_ARB_render_texture
=
3166 "WGL_ARB_render_texture",
3168 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3169 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3173 static const WineGLExtension WGL_EXT_extensions_string
=
3175 "WGL_EXT_extensions_string",
3177 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3181 static const WineGLExtension WGL_EXT_swap_control
=
3183 "WGL_EXT_swap_control",
3185 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3186 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3190 static const WineGLExtension WGL_NV_vertex_array_range
=
3192 "WGL_NV_vertex_array_range",
3194 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3195 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3200 * X11DRV_WineGL_LoadExtensions
3202 static void X11DRV_WineGL_LoadExtensions(void)
3204 WineGLInfo
.wglExtensions
[0] = 0;
3206 /* Load Wine internal functions */
3207 register_extension(&WGL_internal_functions
);
3209 /* ARB Extensions */
3211 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3213 register_extension_string("WGL_ARB_pixel_format_float");
3214 register_extension_string("WGL_ATI_pixel_format_float");
3217 register_extension(&WGL_ARB_extensions_string
);
3219 if (glxRequireVersion(3))
3220 register_extension(&WGL_ARB_make_current_read
);
3222 if (glxRequireExtension("GLX_ARB_multisample"))
3223 register_extension(&WGL_ARB_multisample
);
3225 /* In general pbuffer functionality requires support in the X-server. The functionality is
3226 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3227 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3228 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3230 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3231 * without support in the X-server (which other Mesa based drivers require).
3233 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3234 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3235 * is available pbuffers must be available too. */
3236 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3237 register_extension(&WGL_ARB_pbuffer
);
3239 register_extension(&WGL_ARB_pixel_format
);
3241 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3242 if (glxRequireExtension("GLX_ATI_render_texture") ||
3243 glxRequireExtension("GLX_ARB_render_texture") ||
3244 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3246 register_extension(&WGL_ARB_render_texture
);
3248 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3249 if(glxRequireExtension("GLX_NV_float_buffer"))
3250 register_extension_string("WGL_NV_float_buffer");
3252 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3253 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3254 register_extension_string("WGL_NV_texture_rectangle");
3257 /* EXT Extensions */
3259 register_extension(&WGL_EXT_extensions_string
);
3261 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3262 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3263 register_extension(&WGL_EXT_swap_control
);
3265 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3266 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3267 register_extension(&WGL_NV_vertex_array_range
);
3271 static XID
create_glxpixmap(X11DRV_PDEVICE
*physDev
)
3275 XVisualInfo
template;
3280 /* Retrieve the visualid from our main visual which is the only visual we can use */
3281 template.visualid
= XVisualIDFromVisual(visual
);
3282 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
3284 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
3286 wine_tsx11_unlock();
3287 TRACE("return %lx\n", ret
);
3291 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3297 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3298 ret
= physDev
->drawable
; /* PBuffer */
3301 if(!physDev
->bitmap
->glxpixmap
)
3302 physDev
->bitmap
->glxpixmap
= create_glxpixmap(physDev
);
3303 ret
= physDev
->bitmap
->glxpixmap
;
3307 ret
= physDev
->drawable
;
3311 BOOL
destroy_glxpixmap(XID glxpixmap
)
3314 pglXDestroyGLXPixmap(gdi_display
, glxpixmap
);
3315 wine_tsx11_unlock();
3320 * X11DRV_SwapBuffers
3322 * Swap the buffers of this DC
3324 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3326 GLXDrawable drawable
;
3327 if (!has_opengl()) {
3328 ERR("No libGL on this box - disabling OpenGL support !\n");
3332 TRACE_(opengl
)("(%p)\n", physDev
);
3334 drawable
= get_glxdrawable(physDev
);
3336 pglXSwapBuffers(gdi_display
, drawable
);
3337 wine_tsx11_unlock();
3342 static long prev_time
, frames
;
3344 DWORD time
= GetTickCount();
3346 /* every 1.5 seconds */
3347 if (time
- prev_time
> 1500) {
3348 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
3357 /***********************************************************************
3358 * X11DRV_setup_opengl_visual
3360 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3361 * window (if it exists). If OpenGL isn't available, the visual is simply
3362 * set to the default visual for the display
3364 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3366 XVisualInfo
*visual
= NULL
;
3369 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3370 * D3D and some applications can make use of aux buffers.
3372 int visualProperties
[][11] = {
3373 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_AUX_BUFFERS
, 1, None
},
3374 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, None
},
3375 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, None
},
3376 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, None
},
3383 for (i
= 0; i
< sizeof(visualProperties
)/sizeof(visualProperties
[0]); ++i
) {
3384 visual
= pglXChooseVisual(display
, DefaultScreen(display
), visualProperties
[i
]);
3388 wine_tsx11_unlock();
3391 TRACE("Visual ID %lx Chosen\n", visual
->visualid
);
3393 WARN("No suitable visual found\n");
3398 #else /* no OpenGL includes */
3400 /***********************************************************************
3401 * ChoosePixelFormat (X11DRV.@)
3403 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3404 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3405 ERR("No OpenGL support compiled in.\n");
3410 /***********************************************************************
3411 * DescribePixelFormat (X11DRV.@)
3413 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3416 PIXELFORMATDESCRIPTOR
*ppfd
) {
3417 ERR("No OpenGL support compiled in.\n");
3422 /***********************************************************************
3423 * GetPixelFormat (X11DRV.@)
3425 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3426 ERR("No OpenGL support compiled in.\n");
3431 /***********************************************************************
3432 * SetPixelFormat (X11DRV.@)
3434 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3436 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3437 ERR("No OpenGL support compiled in.\n");
3442 /***********************************************************************
3443 * SwapBuffers (X11DRV.@)
3445 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3446 ERR_(opengl
)("No OpenGL support compiled in.\n");
3452 * X11DRV_wglCreateContext
3454 * For OpenGL32 wglCreateContext.
3456 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3457 ERR_(opengl
)("No OpenGL support compiled in.\n");
3462 * X11DRV_wglDeleteContext
3464 * For OpenGL32 wglDeleteContext.
3466 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3467 ERR_(opengl
)("No OpenGL support compiled in.\n");
3472 * X11DRV_wglGetProcAddress
3474 * For OpenGL32 wglGetProcAddress.
3476 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3477 ERR_(opengl
)("No OpenGL support compiled in.\n");
3481 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3483 ERR_(opengl
)("No OpenGL support compiled in.\n");
3487 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3488 ERR_(opengl
)("No OpenGL support compiled in.\n");
3493 * X11DRV_wglMakeCurrent
3495 * For OpenGL32 wglMakeCurrent.
3497 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3498 ERR_(opengl
)("No OpenGL support compiled in.\n");
3503 * X11DRV_wglShareLists
3505 * For OpenGL32 wglShaderLists.
3507 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3508 ERR_(opengl
)("No OpenGL support compiled in.\n");
3513 * X11DRV_wglUseFontBitmapsA
3515 * For OpenGL32 wglUseFontBitmapsA.
3517 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3519 ERR_(opengl
)("No OpenGL support compiled in.\n");
3524 * X11DRV_wglUseFontBitmapsW
3526 * For OpenGL32 wglUseFontBitmapsW.
3528 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3530 ERR_(opengl
)("No OpenGL support compiled in.\n");
3534 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3539 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3544 BOOL
destroy_glxpixmap(XID glxpixmap
)
3549 #endif /* defined(HAVE_OPENGL) */