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
);
179 TRACE(" - iPixelType : ");
180 switch (ppfd
->iPixelType
) {
181 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
182 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
186 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
187 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
188 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
189 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
190 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
191 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
192 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
193 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
194 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
196 TRACE(" - iLayerType : ");
197 switch (ppfd
->iLayerType
) {
198 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
199 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
200 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
205 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
206 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
208 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
210 MAKE_FUNCPTR(glXChooseVisual
)
211 MAKE_FUNCPTR(glXCreateContext
)
212 MAKE_FUNCPTR(glXCreateGLXPixmap
)
213 MAKE_FUNCPTR(glXGetCurrentContext
)
214 MAKE_FUNCPTR(glXGetCurrentDrawable
)
215 MAKE_FUNCPTR(glXDestroyContext
)
216 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
217 MAKE_FUNCPTR(glXGetConfig
)
218 MAKE_FUNCPTR(glXIsDirect
)
219 MAKE_FUNCPTR(glXMakeCurrent
)
220 MAKE_FUNCPTR(glXSwapBuffers
)
221 MAKE_FUNCPTR(glXQueryExtension
)
222 MAKE_FUNCPTR(glXQueryVersion
)
223 MAKE_FUNCPTR(glXUseXFont
)
226 MAKE_FUNCPTR(glXGetClientString
)
227 MAKE_FUNCPTR(glXQueryExtensionsString
)
228 MAKE_FUNCPTR(glXQueryServerString
)
231 MAKE_FUNCPTR(glXGetFBConfigs
)
232 MAKE_FUNCPTR(glXChooseFBConfig
)
233 MAKE_FUNCPTR(glXCreatePbuffer
)
234 MAKE_FUNCPTR(glXCreateNewContext
)
235 MAKE_FUNCPTR(glXDestroyPbuffer
)
236 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
237 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
238 MAKE_FUNCPTR(glXMakeContextCurrent
)
239 MAKE_FUNCPTR(glXQueryDrawable
)
240 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
243 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
244 static BOOL (*pglXBindTexImageARB
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
245 static BOOL (*pglXReleaseTexImageARB
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
246 static BOOL (*pglXDrawableAttribARB
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
247 static int (*pglXSwapIntervalSGI
)(int);
249 /* NV GLX Extension */
250 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
251 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
253 /* Standard OpenGL */
254 MAKE_FUNCPTR(glBindTexture
)
255 MAKE_FUNCPTR(glBitmap
)
256 MAKE_FUNCPTR(glCopyTexSubImage1D
)
257 MAKE_FUNCPTR(glCopyTexImage2D
)
258 MAKE_FUNCPTR(glCopyTexSubImage2D
)
259 MAKE_FUNCPTR(glDisable
)
260 MAKE_FUNCPTR(glDrawBuffer
)
261 MAKE_FUNCPTR(glEnable
)
262 MAKE_FUNCPTR(glEndList
)
263 MAKE_FUNCPTR(glGetError
)
264 MAKE_FUNCPTR(glGetIntegerv
)
265 MAKE_FUNCPTR(glGetString
)
266 MAKE_FUNCPTR(glIsEnabled
)
267 MAKE_FUNCPTR(glNewList
)
268 MAKE_FUNCPTR(glPixelStorei
)
269 MAKE_FUNCPTR(glReadPixels
)
270 MAKE_FUNCPTR(glScissor
)
271 MAKE_FUNCPTR(glTexImage2D
)
272 MAKE_FUNCPTR(glViewport
)
275 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
277 static BOOL infoInitialized
= FALSE
;
279 int screen
= DefaultScreen(gdi_display
);
280 Window win
= RootWindow(gdi_display
, screen
);
282 XVisualInfo
template;
285 GLXContext ctx
= NULL
;
289 infoInitialized
= TRUE
;
293 visual
= DefaultVisual(gdi_display
, screen
);
294 template.visualid
= XVisualIDFromVisual(visual
);
295 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
297 WORD old_fs
= wine_get_fs();
298 /* Create a GLX Context. Without one we can't query GL information */
299 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
300 if (wine_get_fs() != old_fs
)
302 wine_set_fs( old_fs
);
304 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
305 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
311 pglXMakeCurrent(gdi_display
, win
, ctx
);
313 ERR(" couldn't initialize OpenGL, expect problems\n");
318 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
319 WineGLInfo
.glExtensions
= strdup((const char *) pglGetString(GL_EXTENSIONS
));
321 /* Get the common GLX version supported by GLX client and server ( major/minor) */
322 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
324 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
325 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
326 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
328 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
329 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
330 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
332 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
333 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
335 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
336 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER
));
337 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
338 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
339 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
340 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
341 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
342 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
346 pglXMakeCurrent(gdi_display
, None
, NULL
);
347 pglXDestroyContext(gdi_display
, ctx
);
353 static BOOL
has_opengl(void)
355 static int init_done
;
356 static void *opengl_handle
;
358 int error_base
, event_base
;
360 if (init_done
) return (opengl_handle
!= NULL
);
363 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
364 and include all dependencies */
365 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0);
366 if (opengl_handle
== NULL
) return FALSE
;
368 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
369 if (pglXGetProcAddressARB
== NULL
) {
370 ERR("could not find glXGetProcAddressARB in libGL.\n");
374 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
376 LOAD_FUNCPTR(glXChooseVisual
)
377 LOAD_FUNCPTR(glXCreateContext
)
378 LOAD_FUNCPTR(glXCreateGLXPixmap
)
379 LOAD_FUNCPTR(glXGetCurrentContext
)
380 LOAD_FUNCPTR(glXGetCurrentDrawable
)
381 LOAD_FUNCPTR(glXDestroyContext
)
382 LOAD_FUNCPTR(glXDestroyGLXPixmap
)
383 LOAD_FUNCPTR(glXGetConfig
)
384 LOAD_FUNCPTR(glXIsDirect
)
385 LOAD_FUNCPTR(glXMakeCurrent
)
386 LOAD_FUNCPTR(glXSwapBuffers
)
387 LOAD_FUNCPTR(glXQueryExtension
)
388 LOAD_FUNCPTR(glXQueryVersion
)
389 LOAD_FUNCPTR(glXUseXFont
)
392 LOAD_FUNCPTR(glXGetClientString
)
393 LOAD_FUNCPTR(glXQueryExtensionsString
)
394 LOAD_FUNCPTR(glXQueryServerString
)
397 LOAD_FUNCPTR(glXCreatePbuffer
)
398 LOAD_FUNCPTR(glXCreateNewContext
)
399 LOAD_FUNCPTR(glXDestroyPbuffer
)
400 LOAD_FUNCPTR(glXMakeContextCurrent
)
401 LOAD_FUNCPTR(glXGetCurrentReadDrawable
)
402 LOAD_FUNCPTR(glXGetFBConfigs
)
404 /* Standard OpenGL calls */
405 LOAD_FUNCPTR(glBindTexture
)
406 LOAD_FUNCPTR(glBitmap
)
407 LOAD_FUNCPTR(glCopyTexSubImage1D
)
408 LOAD_FUNCPTR(glCopyTexImage2D
)
409 LOAD_FUNCPTR(glCopyTexSubImage2D
)
410 LOAD_FUNCPTR(glDisable
)
411 LOAD_FUNCPTR(glDrawBuffer
)
412 LOAD_FUNCPTR(glEnable
)
413 LOAD_FUNCPTR(glEndList
)
414 LOAD_FUNCPTR(glGetError
)
415 LOAD_FUNCPTR(glGetIntegerv
)
416 LOAD_FUNCPTR(glGetString
)
417 LOAD_FUNCPTR(glIsEnabled
)
418 LOAD_FUNCPTR(glNewList
)
419 LOAD_FUNCPTR(glPixelStorei
)
420 LOAD_FUNCPTR(glReadPixels
)
421 LOAD_FUNCPTR(glScissor
)
422 LOAD_FUNCPTR(glTexImage2D
)
423 LOAD_FUNCPTR(glViewport
)
426 /* It doesn't matter if these fail. They'll only be used if the driver reports
427 the associated extension is available (and if a driver reports the extension
428 is available but fails to provide the functions, it's quite broken) */
429 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
430 /* NV GLX Extension */
431 LOAD_FUNCPTR(glXAllocateMemoryNV
)
432 LOAD_FUNCPTR(glXFreeMemoryNV
)
435 if(!X11DRV_WineGL_InitOpenglInfo()) {
436 wine_dlclose(opengl_handle
, NULL
, 0);
437 opengl_handle
= NULL
;
442 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
) == True
) {
443 TRACE("GLX is up and running error_base = %d\n", error_base
);
445 wine_dlclose(opengl_handle
, NULL
, 0);
446 opengl_handle
= NULL
;
449 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
450 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
453 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
454 * depends on the reported GLX client / server version and on the client / server extension list.
455 * Those don't have to be the same.
457 * In general the server GLX information lists the capabilities in case of indirect rendering.
458 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
459 * available and in that case the client GLX informat can be used.
460 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
461 * in the GLX version/extension list. When a program does this it works for certain for both
462 * direct and indirect rendering.
464 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
465 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
466 * extension list which causes this extension not to be listed. (Wine requires this extension).
467 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
468 * pbuffers is around.
470 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
471 * the ATI drivers and from then on use GLX client information for them.
474 if(glxRequireVersion(3)) {
475 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
476 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
477 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
478 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
479 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
480 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
481 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
482 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
484 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
485 * enable this function when the Xserver understand GLX 1.3 or newer
487 pglXQueryDrawable
= NULL
;
488 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
489 TRACE("Overriding ATI GLX capabilities!\n");
490 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
491 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
492 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
493 pglXQueryDrawable
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
495 /* Use client GLX information in case of the ATI drivers. We override the
496 * capabilities over here and not somewhere else as ATI might better their
497 * life in the future. In case they release proper drivers this block of
498 * code won't be called. */
499 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
501 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
504 if(glxRequireExtension("GLX_ATI_render_texture")) {
505 pglXBindTexImageARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageARB");
506 pglXReleaseTexImageARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageARB");
507 pglXDrawableAttribARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribARB");
510 X11DRV_WineGL_LoadExtensions();
513 return (opengl_handle
!= NULL
);
516 wine_dlclose(opengl_handle
, NULL
, 0);
517 opengl_handle
= NULL
;
521 static inline Wine_GLContext
*alloc_context(void)
525 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
527 ret
->next
= context_list
;
528 if (context_list
) context_list
->prev
= ret
;
534 static inline void free_context(Wine_GLContext
*context
)
536 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
537 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
538 else context_list
= context
->next
;
540 HeapFree(GetProcessHeap(), 0, context
);
543 static inline Wine_GLContext
*get_context_from_GLXContext(GLXContext ctx
)
546 if (!ctx
) return NULL
;
547 for (ret
= context_list
; ret
; ret
= ret
->next
) if (ctx
== ret
->ctx
) break;
552 * get_hdc_from_Drawable (internal)
554 * For use by wglGetCurrentReadDCARB.
556 static inline HDC
get_hdc_from_Drawable(GLXDrawable d
)
559 for (ret
= context_list
; ret
; ret
= ret
->next
) {
560 if (d
== ret
->physDev
->drawable
) {
567 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
570 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
571 return (ptr
!= NULL
);
574 static int describeContext(Wine_GLContext
* ctx
) {
577 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
578 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
579 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
580 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
581 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
586 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
589 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
592 if (pglXQueryDrawable
== NULL
) {
593 /** glXQueryDrawable not available so returns not supported */
597 TRACE(" Drawable %p have :\n", (void*) drawable
);
598 pglXQueryDrawable(gdi_display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
599 TRACE(" - WIDTH as %d\n", tmp
);
600 pglXQueryDrawable(gdi_display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
601 TRACE(" - HEIGHT as %d\n", tmp
);
602 pglXQueryDrawable(gdi_display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
603 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
606 fbCfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribList
, &nElements
);
607 if (fbCfgs
== NULL
) {
611 pglXGetFBConfigAttrib(gdi_display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
612 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
619 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
624 int nvfloatattrib
= GLX_DONT_CARE
;
627 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
628 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
629 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
630 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
632 switch (iWGLAttr
[cur
]) {
633 case WGL_COLOR_BITS_ARB
:
634 pop
= iWGLAttr
[++cur
];
635 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
636 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
638 case WGL_BLUE_BITS_ARB
:
639 pop
= iWGLAttr
[++cur
];
640 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
641 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
643 case WGL_RED_BITS_ARB
:
644 pop
= iWGLAttr
[++cur
];
645 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
646 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
648 case WGL_GREEN_BITS_ARB
:
649 pop
= iWGLAttr
[++cur
];
650 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
651 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
653 case WGL_ALPHA_BITS_ARB
:
654 pop
= iWGLAttr
[++cur
];
655 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
656 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
658 case WGL_DEPTH_BITS_ARB
:
659 pop
= iWGLAttr
[++cur
];
660 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
661 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
663 case WGL_STENCIL_BITS_ARB
:
664 pop
= iWGLAttr
[++cur
];
665 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
666 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
668 case WGL_DOUBLE_BUFFER_ARB
:
669 pop
= iWGLAttr
[++cur
];
670 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
671 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
674 case WGL_PIXEL_TYPE_ARB
:
675 pop
= iWGLAttr
[++cur
];
676 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
678 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
679 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
680 /* 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 */
681 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
683 ERR("unexpected PixelType(%x)\n", pop
);
688 case WGL_SUPPORT_GDI_ARB
:
689 pop
= iWGLAttr
[++cur
];
690 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
691 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
694 case WGL_DRAW_TO_BITMAP_ARB
:
695 pop
= iWGLAttr
[++cur
];
696 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
697 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
699 drawattrib
|= GLX_PIXMAP_BIT
;
703 case WGL_DRAW_TO_WINDOW_ARB
:
704 pop
= iWGLAttr
[++cur
];
705 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
706 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
708 drawattrib
|= GLX_WINDOW_BIT
;
712 case WGL_DRAW_TO_PBUFFER_ARB
:
713 pop
= iWGLAttr
[++cur
];
714 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
715 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
717 drawattrib
|= GLX_PBUFFER_BIT
;
721 case WGL_ACCELERATION_ARB
:
722 case WGL_SUPPORT_OPENGL_ARB
:
723 pop
= iWGLAttr
[++cur
];
724 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
725 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
728 case WGL_PBUFFER_LARGEST_ARB
:
729 pop
= iWGLAttr
[++cur
];
730 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
731 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
734 case WGL_SAMPLE_BUFFERS_ARB
:
735 pop
= iWGLAttr
[++cur
];
736 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
737 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
740 case WGL_SAMPLES_ARB
:
741 pop
= iWGLAttr
[++cur
];
742 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
743 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
746 case WGL_TEXTURE_FORMAT_ARB
:
747 case WGL_TEXTURE_TARGET_ARB
:
748 case WGL_MIPMAP_TEXTURE_ARB
:
749 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
750 pop
= iWGLAttr
[++cur
];
752 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
754 if (use_render_texture_ati
) {
755 /** nothing to do here */
757 else if (!use_render_texture_emulation
) {
758 if (WGL_NO_TEXTURE_ARB
!= pop
) {
759 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
760 return -1; /** error: don't support it */
762 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
763 drawattrib
|= GLX_PBUFFER_BIT
;
767 case WGL_FLOAT_COMPONENTS_NV
:
768 nvfloatattrib
= iWGLAttr
[++cur
];
769 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
771 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
772 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
773 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
774 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
775 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
776 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
777 pop
= iWGLAttr
[++cur
];
778 /** cannot be converted, see direct handling on
779 * - wglGetPixelFormatAttribivARB
780 * TODO: wglChoosePixelFormat
785 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
791 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
792 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
793 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
794 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
796 /* Set GLX_RENDER_TYPE all the time */
797 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
798 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
800 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
801 if(strstr(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
802 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
803 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
809 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
811 int render_type
=0, render_type_bit
;
812 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
813 switch(render_type_bit
)
816 render_type
= GLX_RGBA_TYPE
;
818 case GLX_COLOR_INDEX_BIT
:
819 render_type
= GLX_COLOR_INDEX_TYPE
;
821 case GLX_RGBA_FLOAT_BIT
:
822 render_type
= GLX_RGBA_FLOAT_TYPE
;
825 ERR("Unknown render_type: %x\n", render_type
);
830 static BOOL
get_fbconfig_from_visualid(Display
*display
, Visual
*visual
, GLXFBConfig
*fbconfig
, int *fmt_id
)
832 GLXFBConfig
* cfgs
= NULL
;
839 if(!display
|| !visual
) {
840 ERR("Invalid display or visual\n");
843 visualid
= XVisualIDFromVisual(visual
);
845 /* Get a list of all available framebuffer configurations */
846 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
847 if (NULL
== cfgs
|| 0 == nCfgs
) {
848 ERR("glXChooseFBConfig returns NULL\n");
849 if(cfgs
!= NULL
) XFree(cfgs
);
853 /* Find the requested offscreen format and count the number of offscreen formats */
854 for(i
=0; i
<nCfgs
; i
++) {
855 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
856 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
858 /* We are looking up the GLX index of our main visual and have found it :) */
859 if(visualid
== tmp_vis_id
) {
860 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id
, i
, tmp_vis_id
);
862 *fmt_id
= tmp_fmt_id
;
868 ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid
);
873 static BOOL
init_formats(Display
*display
, int screen
, Visual
*visual
)
875 int fmt_id
, tmp_vis_id
, tmp_fmt_id
, nCfgs
, i
;
877 GLXFBConfig fbconfig
;
878 int nOffscreenFormats
= 0;
880 /* Locate the fbconfig correspondig to our main visual */
881 if(!get_fbconfig_from_visualid(display
, visual
, &fbconfig
, &fmt_id
)) {
882 ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
886 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
887 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
888 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
889 * because this call lists both types of formats instead of only onscreen ones. */
890 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
891 if (NULL
== cfgs
|| 0 == nCfgs
) {
892 WARN("glXChooseFBConfig returns NULL\n");
893 if(cfgs
!= NULL
) XFree(cfgs
);
895 /* We only have the single format of Wine's main visual */
896 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WineGLPixelFormat
));
897 WineGLPixelFormatList
[0].iPixelFormat
= 1;
898 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
899 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
900 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
901 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
902 WineGLPixelFormatListSize
= 1;
905 /* Count the number of offscreen formats to determine the size for our pixelformat list */
906 for(i
=0; i
<nCfgs
; i
++) {
907 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
909 /* We have found an offscreen rendering format :) */
910 if(tmp_vis_id
== 0) {
914 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats
);
916 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
917 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (1+nOffscreenFormats
)*sizeof(WineGLPixelFormat
));
918 WineGLPixelFormatList
[0].iPixelFormat
= 1;
919 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
920 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
921 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
922 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
923 WineGLPixelFormatListSize
= 1;
925 /* Fill the list with offscreen formats */
926 for(i
=0; i
<nCfgs
; i
++) {
927 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
928 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
930 /* We have found an offscreen rendering format :) */
931 if(tmp_vis_id
== 0) {
932 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id
, WineGLPixelFormatListSize
+1, i
);
933 WineGLPixelFormatList
[WineGLPixelFormatListSize
].iPixelFormat
= WineGLPixelFormatListSize
+1; /* The index starts at 1 */
934 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fbconfig
= cfgs
[i
];
935 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fmt_id
= tmp_fmt_id
;
936 WineGLPixelFormatList
[WineGLPixelFormatListSize
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
937 WineGLPixelFormatList
[WineGLPixelFormatListSize
].offscreenOnly
= TRUE
;
938 WineGLPixelFormatListSize
++;
943 if(cfgs
!= NULL
) XFree(cfgs
);
948 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
949 * In our WGL implementation we only support a subset of these formats namely the format of
950 * Wine's main visual and offscreen formats (if they are available).
951 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
952 * and it returns the number of supported WGL formats in fmt_count.
954 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
956 WineGLPixelFormat
*res
= NULL
;
958 /* Init the list of pixel formats when we need it */
959 if(!WineGLPixelFormatListSize
)
960 init_formats(display
, DefaultScreen(display
), visual
);
962 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
963 * iPixelFormat in case of probing the number of pixelformats.
965 if((iPixelFormat
<= 0) || (iPixelFormat
> WineGLPixelFormatListSize
)) {
967 *fmt_count
= WineGLPixelFormatListSize
;
969 *fmt_count
= 1; /* Only show the format of our main visual */
971 else if(iPixelFormat
== 1) {
972 res
= &WineGLPixelFormatList
[0];
973 *fmt_count
= 1; /* Only show the format of our main visual */
975 else if((WineGLPixelFormatList
[iPixelFormat
-1].offscreenOnly
== TRUE
) && AllowOffscreen
) {
976 res
= &WineGLPixelFormatList
[iPixelFormat
-1];
977 *fmt_count
= WineGLPixelFormatListSize
;
978 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
981 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
986 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
987 static WineGLPixelFormat
* ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
)
991 /* Init the list of pixel formats when we need it */
992 if(!WineGLPixelFormatListSize
)
993 init_formats(display
, DefaultScreen(display
), visual
);
995 for(i
=0; i
<WineGLPixelFormatListSize
; i
++) {
996 if(WineGLPixelFormatList
[i
].fmt_id
== fmt_id
) {
997 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList
[i
].iPixelFormat
, fmt_id
);
998 return &WineGLPixelFormatList
[i
];
1001 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1006 * X11DRV_ChoosePixelFormat
1008 * Equivalent to glXChooseVisual.
1010 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
1011 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1012 WineGLPixelFormat
*fmt
= NULL
;
1017 int bestFormat
= -1;
1021 int bestStencil
= -1;
1025 if (!has_opengl()) {
1026 ERR("No libGL on this box - disabling OpenGL support !\n");
1030 if (TRACE_ON(opengl
)) {
1031 TRACE("(%p,%p)\n", physDev
, ppfd
);
1033 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
1037 ConvertPixelFormatWGLtoGLX(gdi_display
, 0, FALSE
/* offscreen */, &nPixelFormats
);
1038 for(i
=0; i
<nPixelFormats
; i
++)
1042 int alpha
=0, color
=0, depth
=0, stencil
=0, aux
=0;
1044 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, i
+1 /* 1-based index */, FALSE
/* offscreen */, &value
);
1048 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1049 if (value
& GLX_RGBA_BIT
)
1050 iPixelType
= PFD_TYPE_RGBA
;
1052 iPixelType
= PFD_TYPE_COLORINDEX
;
1054 if (ppfd
->iPixelType
!= iPixelType
)
1056 TRACE("pixel type mismatch for iPixelFormat=%d\n", i
+1);
1061 * Ignore doublebuffer when PFD_DOUBLEBUFFER_DONTCARE is set. Further if the flag
1062 * is not set, we must return a format without double buffering. */
1063 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1064 if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1065 if (!(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) && ((ppfd
->dwFlags
^dwFlags
) & PFD_DOUBLEBUFFER
))
1067 TRACE("dbl buffer mismatch for iPixelFormat=%d\n", i
+1);
1072 * Ignore stereo when PFD_STEREO_DONTCARE is set. Further if the flag
1073 * is not set, we must return a format without stereo support. */
1074 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
);
1075 if (value
) dwFlags
|= PFD_STEREO
;
1076 if (!(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) && ((ppfd
->dwFlags
^dwFlags
) & PFD_STEREO
))
1078 TRACE("stereo mismatch for iPixelFormat=%d\n", i
+1);
1082 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &color
); /* cColorBits */
1083 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &alpha
); /* cAlphaBits */
1084 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &depth
); /* cDepthBits */
1085 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &stencil
); /* cStencilBits */
1086 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &aux
); /* cAuxBuffers */
1088 /* Below we will do a number of checks to select the 'best' pixelformat.
1089 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1090 * The code works by trying to match the most important options as close as possible.
1091 * When a reasonable format is found, we will try to match more options. */
1094 if( ((ppfd
->cColorBits
> bestColor
) && (color
> bestColor
)) ||
1095 ((color
>= ppfd
->cColorBits
) && (color
< bestColor
)) )
1100 bestStencil
= stencil
;
1104 } else if(bestColor
!= color
) { /* Do further checks if the format is compatible */
1105 TRACE("color mismatch for iPixelFormat=%d\n", i
+1);
1110 if( ((ppfd
->cAlphaBits
> bestAlpha
) && (alpha
> bestAlpha
)) ||
1111 ((alpha
>= ppfd
->cAlphaBits
) && (alpha
< bestAlpha
)) )
1116 bestStencil
= stencil
;
1120 } else if(bestAlpha
!= alpha
) {
1121 TRACE("alpha mismatch for iPixelFormat=%d\n", i
+1);
1126 if( ((ppfd
->cDepthBits
> bestDepth
) && (depth
> bestDepth
)) ||
1127 ((depth
>= ppfd
->cDepthBits
) && (depth
< bestDepth
)) )
1132 bestStencil
= stencil
;
1136 } else if(bestDepth
!= depth
) {
1137 TRACE("depth mismatch for iPixelFormat=%d\n", i
+1);
1142 if( ((ppfd
->cStencilBits
> bestStencil
) && (stencil
> bestStencil
)) ||
1143 ((stencil
>= ppfd
->cStencilBits
) && (stencil
< bestStencil
)) )
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
)) )
1164 bestStencil
= stencil
;
1168 } else if(bestAux
!= aux
) {
1169 TRACE("aux mismatch for iPixelFormat=%d\n", i
+1);
1174 if(bestFormat
== -1) {
1175 TRACE("No matching mode was found returning 0\n");
1179 ret
= bestFormat
+1; /* the return value should be a 1-based index */
1180 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret
, WineGLPixelFormatList
[bestFormat
-1].fmt_id
);
1183 wine_tsx11_unlock();
1189 * X11DRV_DescribePixelFormat
1191 * Get the pixel-format descriptor associated to the given id
1193 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1196 PIXELFORMATDESCRIPTOR
*ppfd
) {
1197 /*XVisualInfo *vis;*/
1200 WineGLPixelFormat
*fmt
;
1204 if (!has_opengl()) {
1205 ERR("No libGL on this box - disabling OpenGL support !\n");
1209 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1211 /* 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 */
1212 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1214 /* The application is only querying the number of pixelformats */
1216 } else if(fmt
== NULL
) {
1217 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1221 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1222 ERR("Wrong structure size !\n");
1223 /* Should set error */
1229 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1230 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1233 /* These flags are always the same... */
1234 ppfd
->dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
1235 /* Now the flags extracted from the Visual */
1239 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_CONFIG_CAVEAT
, &value
);
1240 if(value
== GLX_SLOW_CONFIG
)
1241 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1243 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
); if (value
) ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1244 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1247 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1248 if (value
& GLX_RGBA_BIT
)
1249 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1251 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1254 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1255 ppfd
->cColorBits
= value
;
1257 /* Red, green, blue and alpha bits / shifts */
1258 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1259 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1260 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1261 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1262 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1264 ppfd
->cRedBits
= rb
;
1265 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1266 ppfd
->cBlueBits
= bb
;
1267 ppfd
->cBlueShift
= ab
;
1268 ppfd
->cGreenBits
= gb
;
1269 ppfd
->cGreenShift
= bb
+ ab
;
1270 ppfd
->cAlphaBits
= ab
;
1271 ppfd
->cAlphaShift
= 0;
1274 ppfd
->cRedShift
= 0;
1275 ppfd
->cBlueBits
= 0;
1276 ppfd
->cBlueShift
= 0;
1277 ppfd
->cGreenBits
= 0;
1278 ppfd
->cGreenShift
= 0;
1279 ppfd
->cAlphaBits
= 0;
1280 ppfd
->cAlphaShift
= 0;
1283 /* Accum RGBA bits */
1284 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1285 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1286 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1287 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1289 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1290 ppfd
->cAccumRedBits
= rb
;
1291 ppfd
->cAccumGreenBits
= gb
;
1292 ppfd
->cAccumBlueBits
= bb
;
1293 ppfd
->cAccumAlphaBits
= ab
;
1296 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1297 ppfd
->cDepthBits
= value
;
1300 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1301 ppfd
->cStencilBits
= value
;
1303 wine_tsx11_unlock();
1305 /* Aux : to do ... */
1307 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1309 if (TRACE_ON(opengl
)) {
1310 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1317 * X11DRV_GetPixelFormat
1319 * Get the pixel-format id used by this DC
1321 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1322 WineGLPixelFormat
*fmt
;
1324 TRACE("(%p)\n", physDev
);
1326 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1329 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1330 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1333 else if(fmt
->offscreenOnly
)
1335 /* Offscreen formats can't be used with traditional WGL calls.
1336 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1337 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1341 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1342 return physDev
->current_pf
;
1346 * X11DRV_SetPixelFormat
1348 * Set the pixel-format id used by this DC
1350 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1352 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1353 WineGLPixelFormat
*fmt
;
1356 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1358 if (!has_opengl()) {
1359 ERR("No libGL on this box - disabling OpenGL support !\n");
1363 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1364 if(get_glxdrawable(physDev
) == root_window
)
1366 ERR("Invalid operation on root_window\n");
1370 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1371 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1373 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1377 physDev
->current_pf
= iPixelFormat
;
1379 if (TRACE_ON(opengl
)) {
1383 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1385 * in case of root window created HDCs we crash here :(
1387 Drawable drawable = get_drawable( physDev->hdc );
1388 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1389 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1390 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1391 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1392 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1393 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1394 TRACE(" - WIDTH as %d\n", tmp);
1395 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1396 TRACE(" - HEIGHT as %d\n", tmp);
1398 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1400 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1402 TRACE(" FBConfig have :\n");
1403 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1404 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1405 TRACE(" - VISUAL_ID 0x%x\n", value
);
1406 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1407 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1414 * X11DRV_wglCreateContext
1416 * For OpenGL32 wglCreateContext.
1418 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1420 Wine_GLContext
*ret
;
1421 WineGLPixelFormat
*fmt
;
1422 int hdcPF
= physDev
->current_pf
;
1426 HDC hdc
= physDev
->hdc
;
1428 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1430 if (!has_opengl()) {
1431 ERR("No libGL on this box - disabling OpenGL support !\n");
1435 /* First, get the visual in use by the X11DRV */
1436 if (!gdi_display
) return 0;
1438 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1439 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1440 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1441 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1442 * If this fails something is very wrong on the system. */
1444 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1445 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1449 if (fmt_count
< hdcPF
) {
1450 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, hdcPF
, fmt_count
);
1451 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1455 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1457 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1458 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1462 /* The context will be allocated in the wglMakeCurrent call */
1464 ret
= alloc_context();
1465 wine_tsx11_unlock();
1467 ret
->physDev
= physDev
;
1471 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1473 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1478 * X11DRV_wglDeleteContext
1480 * For OpenGL32 wglDeleteContext.
1482 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1484 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1487 TRACE("(%p)\n", hglrc
);
1489 if (!has_opengl()) {
1490 ERR("No libGL on this box - disabling OpenGL support !\n");
1495 /* A game (Half Life not to name it) deletes twice the same context,
1496 * so make sure it is valid first */
1497 if (is_valid_context( ctx
))
1499 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1504 WARN("Error deleting context !\n");
1505 SetLastError(ERROR_INVALID_HANDLE
);
1508 wine_tsx11_unlock();
1514 * X11DRV_wglGetCurrentReadDCARB
1516 * For OpenGL32 wglGetCurrentReadDCARB.
1518 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1526 gl_d
= pglXGetCurrentReadDrawable();
1527 ret
= get_hdc_from_Drawable(gl_d
);
1528 wine_tsx11_unlock();
1530 TRACE(" returning %p (GL drawable %lu)\n", ret
, gl_d
);
1535 * X11DRV_wglGetProcAddress
1537 * For OpenGL32 wglGetProcAddress.
1539 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1542 const WineGLExtension
*ext
;
1544 int padding
= 32 - strlen(lpszProc
);
1548 if (!has_opengl()) {
1549 ERR("No libGL on this box - disabling OpenGL support !\n");
1553 /* Check the table of WGL extensions to see if we need to return a WGL extension
1554 * or a function pointer to a native OpenGL function. */
1555 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1556 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1558 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1559 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1560 ext
= WineGLExtensionList
[i
];
1561 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1562 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1563 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1564 return ext
->extEntryPoints
[j
].funcAddress
;
1570 ERR("(%s) - not found\n", lpszProc
);
1574 /***********************************************************************
1575 * sync_current_drawable
1577 * Adjust the current viewport and scissor in order to position
1578 * and size the current drawable correctly on the parent window.
1580 static void sync_current_drawable(BOOL updatedc
)
1586 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1590 if (ctx
&& ctx
->physDev
)
1593 GetClipBox(ctx
->physDev
->hdc
, &rc
); /* Make sure physDev is up to date */
1595 dy
= ctx
->physDev
->drawable_rect
.bottom
- ctx
->physDev
->drawable_rect
.top
-
1596 ctx
->physDev
->dc_rect
.bottom
;
1597 width
= ctx
->physDev
->dc_rect
.right
- ctx
->physDev
->dc_rect
.left
;
1598 height
= ctx
->physDev
->dc_rect
.bottom
- ctx
->physDev
->dc_rect
.top
;
1602 pglViewport(ctx
->physDev
->dc_rect
.left
+ ctx
->viewport
.left
,
1603 dy
+ ctx
->viewport
.top
,
1604 ctx
->viewport
.right
? (ctx
->viewport
.right
- ctx
->viewport
.left
) : width
,
1605 ctx
->viewport
.bottom
? (ctx
->viewport
.bottom
- ctx
->viewport
.top
) : height
);
1607 pglEnable(GL_SCISSOR_TEST
);
1609 if (ctx
->scissor_enabled
)
1610 pglScissor(ctx
->physDev
->dc_rect
.left
+ min(width
, max(0, ctx
->scissor
.left
)),
1611 dy
+ min(height
, max(0, ctx
->scissor
.top
)),
1612 min(width
, max(0, ctx
->scissor
.right
- ctx
->scissor
.left
)),
1613 min(height
, max(0, ctx
->scissor
.bottom
- ctx
->scissor
.top
)));
1615 pglScissor(ctx
->physDev
->dc_rect
.left
, dy
, width
, height
);
1617 wine_tsx11_unlock();
1622 * X11DRV_wglMakeCurrent
1624 * For OpenGL32 wglMakeCurrent.
1626 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1628 HDC hdc
= physDev
->hdc
;
1629 DWORD type
= GetObjectType(hdc
);
1631 TRACE("(%p,%p)\n", hdc
, hglrc
);
1633 if (!has_opengl()) {
1634 ERR("No libGL on this box - disabling OpenGL support !\n");
1639 if (hglrc
== NULL
) {
1640 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1641 NtCurrentTeb()->glContext
= NULL
;
1643 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1644 Drawable drawable
= get_glxdrawable(physDev
);
1645 if (ctx
->ctx
== NULL
) {
1646 /* The describe lines below are for debugging purposes only */
1647 if (TRACE_ON(wgl
)) {
1648 describeDrawable(ctx
, drawable
);
1649 describeContext(ctx
);
1652 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1653 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1655 TRACE(" Creating GLX Context\n");
1657 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1658 else /* Create a GLX Context for a pbuffer */
1659 ctx
->ctx
= pglXCreateNewContext(gdi_display
, ctx
->fmt
->fbconfig
, ctx
->fmt
->render_type
, NULL
, True
);
1661 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1663 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1664 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1665 NtCurrentTeb()->glContext
= ctx
;
1668 ctx
->physDev
= physDev
;
1670 if (type
== OBJ_MEMDC
)
1672 ctx
->do_escape
= TRUE
;
1673 pglDrawBuffer(GL_FRONT_LEFT
);
1677 sync_current_drawable(FALSE
);
1681 wine_tsx11_unlock();
1682 TRACE(" returning %s\n", (ret
? "True" : "False"));
1687 * X11DRV_wglMakeContextCurrentARB
1689 * For OpenGL32 wglMakeContextCurrentARB
1691 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
)
1694 TRACE("(%p,%p,%p)\n", hDrawDev
, hReadDev
, hglrc
);
1696 if (!has_opengl()) {
1697 ERR("No libGL on this box - disabling OpenGL support !\n");
1702 if (hglrc
== NULL
) {
1703 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1704 NtCurrentTeb()->glContext
= NULL
;
1706 if (NULL
== pglXMakeContextCurrent
) {
1709 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1710 Drawable d_draw
= get_glxdrawable(hDrawDev
);
1711 Drawable d_read
= get_glxdrawable(hReadDev
);
1713 if (ctx
->ctx
== NULL
) {
1714 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, GetObjectType(hDrawDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1715 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1717 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1718 NtCurrentTeb()->glContext
= ctx
;
1721 wine_tsx11_unlock();
1723 TRACE(" returning %s\n", (ret
? "True" : "False"));
1728 * X11DRV_wglShareLists
1730 * For OpenGL32 wglShaderLists.
1732 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1733 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1734 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1736 TRACE("(%p, %p)\n", org
, dest
);
1738 if (!has_opengl()) {
1739 ERR("No libGL on this box - disabling OpenGL support !\n");
1743 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1744 ERR("Could not share display lists, context already created !\n");
1747 if (org
->ctx
== NULL
) {
1749 describeContext(org
);
1752 org
->ctx
= pglXCreateContext(gdi_display
, org
->vis
, NULL
, GetObjectType(org
->physDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1753 else /* Create a GLX Context for a pbuffer */
1754 org
->ctx
= pglXCreateNewContext(gdi_display
, org
->fmt
->fbconfig
, org
->fmt
->render_type
, NULL
, True
);
1755 wine_tsx11_unlock();
1756 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1760 describeContext(dest
);
1761 /* Create the destination context with display lists shared */
1763 dest
->ctx
= pglXCreateContext(gdi_display
, dest
->vis
, org
->ctx
, GetObjectType(org
->physDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1764 else /* Create a GLX Context for a pbuffer */
1765 dest
->ctx
= pglXCreateNewContext(gdi_display
, dest
->fmt
->fbconfig
, dest
->fmt
->render_type
, org
->ctx
, True
);
1766 wine_tsx11_unlock();
1767 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1774 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1776 /* We are running using client-side rendering fonts... */
1780 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1784 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1785 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1786 wine_tsx11_unlock();
1788 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1789 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1790 int height
, width_int
;
1792 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1793 if (needed_size
== GDI_ERROR
) {
1794 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1797 TRACE(" - needed size : %d\n", needed_size
);
1800 if (needed_size
> size
) {
1802 HeapFree(GetProcessHeap(), 0, bitmap
);
1803 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1804 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1805 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1807 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1808 if (TRACE_ON(opengl
)) {
1809 unsigned int height
, width
, bitmask
;
1810 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1812 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1813 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1814 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1815 if (needed_size
!= 0) {
1816 TRACE(" - bitmap :\n");
1817 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1819 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1824 if (*bitmap_
& bitmask
)
1829 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1835 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1836 * glyph for it to be drawn properly.
1838 if (needed_size
!= 0) {
1839 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1840 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1842 for (width
= 0; width
< width_int
; width
++) {
1843 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1844 ((int *) bitmap
)[height
* width_int
+ width
];
1850 pglNewList(listBase
++, GL_COMPILE
);
1851 if (needed_size
!= 0) {
1852 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1853 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1854 gm
.gmCellIncX
, gm
.gmCellIncY
,
1857 /* This is the case of 'empty' glyphs like the space character */
1858 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1861 wine_tsx11_unlock();
1865 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1866 wine_tsx11_unlock();
1868 HeapFree(GetProcessHeap(), 0, bitmap
);
1869 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1874 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1875 wine_tsx11_unlock();
1877 HeapFree(GetProcessHeap(), 0, bitmap
);
1878 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1883 * X11DRV_wglUseFontBitmapsA
1885 * For OpenGL32 wglUseFontBitmapsA.
1887 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1889 Font fid
= physDev
->font
;
1891 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1893 if (!has_opengl()) {
1894 ERR("No libGL on this box - disabling OpenGL support !\n");
1899 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
1903 /* I assume that the glyphs are at the same position for X and for Windows */
1904 pglXUseXFont(fid
, first
, count
, listBase
);
1905 wine_tsx11_unlock();
1910 * X11DRV_wglUseFontBitmapsW
1912 * For OpenGL32 wglUseFontBitmapsW.
1914 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1916 Font fid
= physDev
->font
;
1918 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1920 if (!has_opengl()) {
1921 ERR("No libGL on this box - disabling OpenGL support !\n");
1926 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1929 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1932 /* I assume that the glyphs are at the same position for X and for Windows */
1933 pglXUseXFont(fid
, first
, count
, listBase
);
1934 wine_tsx11_unlock();
1938 static void WINAPI
X11DRV_wglDisable(GLenum cap
)
1940 if (cap
== GL_SCISSOR_TEST
)
1942 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1945 ctx
->scissor_enabled
= FALSE
;
1951 wine_tsx11_unlock();
1955 static void WINAPI
X11DRV_wglEnable(GLenum cap
)
1957 if (cap
== GL_SCISSOR_TEST
)
1959 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1962 ctx
->scissor_enabled
= TRUE
;
1968 wine_tsx11_unlock();
1972 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1973 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
1980 GLXContext gl_ctx
= pglXGetCurrentContext();
1981 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1983 pglGetIntegerv(pname
, params
);
1985 * if we cannot find a Wine Context
1986 * we only have the default wine desktop context,
1987 * so if we have only a 24 depth say we have 32
1989 if (NULL
== ret
&& 24 == *params
) {
1992 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
1997 GLXContext gl_ctx
= pglXGetCurrentContext();
1998 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
2000 pglXGetFBConfigAttrib(gdi_display
, ret
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
2001 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
2005 pglGetIntegerv(pname
, params
);
2008 wine_tsx11_unlock();
2011 static GLboolean WINAPI
X11DRV_wglIsEnabled(GLenum cap
)
2013 GLboolean enabled
= False
;
2015 if (cap
== GL_SCISSOR_TEST
)
2017 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2020 enabled
= ctx
->scissor_enabled
;
2025 enabled
= pglIsEnabled(cap
);
2026 wine_tsx11_unlock();
2031 static void WINAPI
X11DRV_wglScissor(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2033 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2037 ctx
->scissor
.left
= x
;
2038 ctx
->scissor
.top
= y
;
2039 ctx
->scissor
.right
= x
+ width
;
2040 ctx
->scissor
.bottom
= y
+ height
;
2042 sync_current_drawable(TRUE
);
2046 static void WINAPI
X11DRV_wglViewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2048 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
2052 ctx
->viewport
.left
= x
;
2053 ctx
->viewport
.top
= y
;
2054 ctx
->viewport
.right
= x
+ width
;
2055 ctx
->viewport
.bottom
= y
+ height
;
2057 sync_current_drawable(TRUE
);
2062 * X11DRV_wglGetExtensionsStringARB
2064 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2066 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2067 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2068 return WineGLInfo
.wglExtensions
;
2072 * X11DRV_wglCreatePbufferARB
2074 * WGL_ARB_pbuffer: wglCreatePbufferARB
2076 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2078 Wine_GLPBuffer
* object
= NULL
;
2079 WineGLPixelFormat
*fmt
= NULL
;
2084 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2086 if (0 >= iPixelFormat
) {
2087 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2088 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2089 return NULL
; /* unexpected error */
2092 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2093 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2095 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2096 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2097 goto create_failed
; /* unexpected error */
2100 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2101 if (NULL
== object
) {
2102 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2103 goto create_failed
; /* unexpected error */
2106 object
->display
= gdi_display
;
2107 object
->width
= iWidth
;
2108 object
->height
= iHeight
;
2111 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2112 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2113 while (piAttribList
&& 0 != *piAttribList
) {
2115 switch (*piAttribList
) {
2116 case WGL_PBUFFER_LARGEST_ARB
: {
2118 attr_v
= *piAttribList
;
2119 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2120 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2124 case WGL_TEXTURE_FORMAT_ARB
: {
2126 attr_v
= *piAttribList
;
2127 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2128 if (use_render_texture_ati
) {
2131 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2132 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2133 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2135 SetLastError(ERROR_INVALID_DATA
);
2138 object
->use_render_texture
= 1;
2139 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2141 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2142 object
->use_render_texture
= 0;
2144 if (!use_render_texture_emulation
) {
2145 SetLastError(ERROR_INVALID_DATA
);
2149 case WGL_TEXTURE_RGB_ARB
:
2150 object
->use_render_texture
= GL_RGB
;
2151 object
->texture_bpp
= 3;
2152 object
->texture_format
= GL_RGB
;
2153 object
->texture_type
= GL_UNSIGNED_BYTE
;
2155 case WGL_TEXTURE_RGBA_ARB
:
2156 object
->use_render_texture
= GL_RGBA
;
2157 object
->texture_bpp
= 4;
2158 object
->texture_format
= GL_RGBA
;
2159 object
->texture_type
= GL_UNSIGNED_BYTE
;
2162 /* WGL_FLOAT_COMPONENTS_NV */
2163 case WGL_TEXTURE_FLOAT_R_NV
:
2164 object
->use_render_texture
= GL_FLOAT_R_NV
;
2165 object
->texture_bpp
= 4;
2166 object
->texture_format
= GL_RED
;
2167 object
->texture_type
= GL_FLOAT
;
2169 case WGL_TEXTURE_FLOAT_RG_NV
:
2170 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2171 object
->texture_bpp
= 8;
2172 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2173 object
->texture_type
= GL_FLOAT
;
2175 case WGL_TEXTURE_FLOAT_RGB_NV
:
2176 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2177 object
->texture_bpp
= 12;
2178 object
->texture_format
= GL_RGB
;
2179 object
->texture_type
= GL_FLOAT
;
2181 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2182 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2183 object
->texture_bpp
= 16;
2184 object
->texture_format
= GL_RGBA
;
2185 object
->texture_type
= GL_FLOAT
;
2188 ERR("Unknown texture format: %x\n", attr_v
);
2189 SetLastError(ERROR_INVALID_DATA
);
2197 case WGL_TEXTURE_TARGET_ARB
: {
2199 attr_v
= *piAttribList
;
2200 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2201 if (use_render_texture_ati
) {
2204 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2205 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2206 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2207 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2209 SetLastError(ERROR_INVALID_DATA
);
2212 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2214 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2215 object
->texture_target
= 0;
2217 if (!use_render_texture_emulation
) {
2218 SetLastError(ERROR_INVALID_DATA
);
2222 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2223 if (iWidth
!= iHeight
) {
2224 SetLastError(ERROR_INVALID_DATA
);
2227 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2228 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2231 case WGL_TEXTURE_1D_ARB
: {
2233 SetLastError(ERROR_INVALID_DATA
);
2236 object
->texture_target
= GL_TEXTURE_1D
;
2237 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2240 case WGL_TEXTURE_2D_ARB
: {
2241 object
->texture_target
= GL_TEXTURE_2D
;
2242 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2245 case WGL_TEXTURE_RECTANGLE_NV
: {
2246 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2247 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2251 ERR("Unknown texture target: %x\n", attr_v
);
2252 SetLastError(ERROR_INVALID_DATA
);
2260 case WGL_MIPMAP_TEXTURE_ARB
: {
2262 attr_v
= *piAttribList
;
2263 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2264 if (use_render_texture_ati
) {
2265 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2267 if (!use_render_texture_emulation
) {
2268 SetLastError(ERROR_INVALID_DATA
);
2278 PUSH1(attribs
, None
);
2279 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2280 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2281 if (!object
->drawable
) {
2282 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2283 goto create_failed
; /* unexpected error */
2285 TRACE("->(%p)\n", object
);
2286 return (HPBUFFERARB
) object
;
2289 HeapFree(GetProcessHeap(), 0, object
);
2290 TRACE("->(FAILED)\n");
2291 return (HPBUFFERARB
) NULL
;
2295 * X11DRV_wglDestroyPbufferARB
2297 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2299 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2301 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2302 TRACE("(%p)\n", hPbuffer
);
2303 if (NULL
== object
) {
2304 SetLastError(ERROR_INVALID_HANDLE
);
2307 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2308 HeapFree(GetProcessHeap(), 0, object
);
2313 * X11DRV_wglGetPbufferDCARB
2315 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2316 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2317 * Gdi32 implements the part of this function which creates a device context.
2318 * This part associates the physDev with the X drawable of the pbuffer.
2320 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2322 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2323 if (NULL
== object
) {
2324 SetLastError(ERROR_INVALID_HANDLE
);
2328 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2329 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2330 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2331 physDev
->drawable
= object
->drawable
;
2332 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2333 physDev
->dc_rect
= physDev
->drawable_rect
;
2335 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2336 return physDev
->hdc
;
2340 * X11DRV_wglQueryPbufferARB
2342 * WGL_ARB_pbuffer: wglQueryPbufferARB
2344 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2346 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2347 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2348 if (NULL
== object
) {
2349 SetLastError(ERROR_INVALID_HANDLE
);
2352 switch (iAttribute
) {
2353 case WGL_PBUFFER_WIDTH_ARB
:
2354 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2356 case WGL_PBUFFER_HEIGHT_ARB
:
2357 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2360 case WGL_PBUFFER_LOST_ARB
:
2361 /* GLX Pbuffers cannot be lost by default. We can support this by
2362 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2363 * to receive pixel buffer clobber events, however that may or may
2364 * not give any benefit */
2365 *piValue
= GL_FALSE
;
2368 case WGL_TEXTURE_FORMAT_ARB
:
2369 if (use_render_texture_ati
) {
2371 int type
= WGL_NO_TEXTURE_ARB
;
2372 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2374 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2375 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2376 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2380 if (!object
->use_render_texture
) {
2381 *piValue
= WGL_NO_TEXTURE_ARB
;
2383 if (!use_render_texture_emulation
) {
2384 SetLastError(ERROR_INVALID_HANDLE
);
2387 switch(object
->use_render_texture
) {
2389 *piValue
= WGL_TEXTURE_RGB_ARB
;
2392 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2394 /* WGL_FLOAT_COMPONENTS_NV */
2396 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2398 case GL_FLOAT_RG_NV
:
2399 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2401 case GL_FLOAT_RGB_NV
:
2402 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2404 case GL_FLOAT_RGBA_NV
:
2405 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2408 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2414 case WGL_TEXTURE_TARGET_ARB
:
2415 if (use_render_texture_ati
) {
2417 int type
= WGL_NO_TEXTURE_ARB
;
2418 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2420 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2421 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2422 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2423 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2427 if (!object
->texture_target
) {
2428 *piValue
= WGL_NO_TEXTURE_ARB
;
2430 if (!use_render_texture_emulation
) {
2431 SetLastError(ERROR_INVALID_DATA
);
2434 switch (object
->texture_target
) {
2435 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2436 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2437 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2438 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2444 case WGL_MIPMAP_TEXTURE_ARB
:
2445 if (use_render_texture_ati
) {
2446 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2448 *piValue
= GL_FALSE
; /** don't support that */
2449 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2454 FIXME("unexpected attribute %x\n", iAttribute
);
2462 * X11DRV_wglReleasePbufferDCARB
2464 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2466 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2468 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2474 * X11DRV_wglSetPbufferAttribARB
2476 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2478 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2480 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2481 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2482 if (NULL
== object
) {
2483 SetLastError(ERROR_INVALID_HANDLE
);
2486 if (!object
->use_render_texture
) {
2487 SetLastError(ERROR_INVALID_HANDLE
);
2490 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2493 if (NULL
!= pglXDrawableAttribARB
) {
2494 if (use_render_texture_ati
) {
2495 FIXME("Need conversion for GLX_ATI_render_texture\n");
2497 return pglXDrawableAttribARB(object
->display
, object
->drawable
, piAttribList
);
2503 * X11DRV_wglChoosePixelFormatARB
2505 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2507 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2512 GLXFBConfig
* cfgs
= NULL
;
2516 WineGLPixelFormat
*fmt
;
2520 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2521 if (NULL
!= pfAttribFList
) {
2522 FIXME("unused pfAttribFList\n");
2525 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2526 if (-1 == nAttribs
) {
2527 WARN("Cannot convert WGL to GLX attributes\n");
2530 PUSH1(attribs
, None
);
2532 /* Search for FB configurations matching the requirements in attribs */
2533 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2535 WARN("Compatible Pixel Format not found\n");
2539 /* Loop through all matching formats and check if they are suitable.
2540 * Note that this function should at max return nMaxFormats different formats */
2541 for(run
=0; run
< 2; run
++)
2543 for (it
= 0; it
< nCfgs
; ++it
) {
2544 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2546 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2550 /* Search for the format in our list of compatible formats */
2551 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
);
2555 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2556 if( ((run
== 0) && fmt
->offscreenOnly
) || ((run
== 1) && !fmt
->offscreenOnly
) )
2559 if(pfmt_it
< nMaxFormats
) {
2560 piFormats
[pfmt_it
] = fmt
->iPixelFormat
;
2561 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
]);
2567 *nNumFormats
= pfmt_it
;
2574 * X11DRV_wglGetPixelFormatAttribivARB
2576 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2578 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2581 WineGLPixelFormat
*fmt
= NULL
;
2585 int nWGLFormats
= 0;
2587 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2589 if (0 < iLayerPlane
) {
2590 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2594 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2595 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2596 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2597 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2599 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2602 for (i
= 0; i
< nAttributes
; ++i
) {
2603 const int curWGLAttr
= piAttributes
[i
];
2604 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2606 switch (curWGLAttr
) {
2607 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2608 piValues
[i
] = nWGLFormats
;
2611 case WGL_SUPPORT_OPENGL_ARB
:
2612 piValues
[i
] = GL_TRUE
;
2615 case WGL_ACCELERATION_ARB
:
2616 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2617 if (!fmt
) goto pix_error
;
2618 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2619 if (hTest
) goto get_error
;
2621 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2622 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
; break;
2623 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2625 ERR("unexpected Config Caveat(%x)\n", tmp
);
2626 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2630 case WGL_TRANSPARENT_ARB
:
2631 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2632 if (!fmt
) goto pix_error
;
2633 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2634 if (hTest
) goto get_error
;
2635 piValues
[i
] = GL_FALSE
;
2636 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2639 case WGL_PIXEL_TYPE_ARB
:
2640 curGLXAttr
= GLX_RENDER_TYPE
;
2641 if (!fmt
) goto pix_error
;
2642 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2643 if (hTest
) goto get_error
;
2644 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2645 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2646 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2647 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2648 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2650 ERR("unexpected RenderType(%x)\n", tmp
);
2651 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2655 case WGL_COLOR_BITS_ARB
:
2656 curGLXAttr
= GLX_BUFFER_SIZE
;
2659 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2660 if (use_render_texture_ati
) {
2661 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2664 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2665 if (use_render_texture_ati
) {
2666 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2669 if (!use_render_texture_emulation
) {
2670 piValues
[i
] = GL_FALSE
;
2673 curGLXAttr
= GLX_RENDER_TYPE
;
2674 if (!fmt
) goto pix_error
;
2675 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2676 if (hTest
) goto get_error
;
2677 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2678 piValues
[i
] = GL_FALSE
;
2681 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2682 if (hTest
) goto get_error
;
2683 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2686 case WGL_BLUE_BITS_ARB
:
2687 curGLXAttr
= GLX_BLUE_SIZE
;
2689 case WGL_RED_BITS_ARB
:
2690 curGLXAttr
= GLX_RED_SIZE
;
2692 case WGL_GREEN_BITS_ARB
:
2693 curGLXAttr
= GLX_GREEN_SIZE
;
2695 case WGL_ALPHA_BITS_ARB
:
2696 curGLXAttr
= GLX_ALPHA_SIZE
;
2698 case WGL_DEPTH_BITS_ARB
:
2699 curGLXAttr
= GLX_DEPTH_SIZE
;
2701 case WGL_STENCIL_BITS_ARB
:
2702 curGLXAttr
= GLX_STENCIL_SIZE
;
2704 case WGL_DOUBLE_BUFFER_ARB
:
2705 curGLXAttr
= GLX_DOUBLEBUFFER
;
2707 case WGL_STEREO_ARB
:
2708 curGLXAttr
= GLX_STEREO
;
2710 case WGL_AUX_BUFFERS_ARB
:
2711 curGLXAttr
= GLX_AUX_BUFFERS
;
2714 case WGL_SUPPORT_GDI_ARB
:
2715 curGLXAttr
= GLX_X_RENDERABLE
;
2718 case WGL_DRAW_TO_WINDOW_ARB
:
2719 case WGL_DRAW_TO_BITMAP_ARB
:
2720 case WGL_DRAW_TO_PBUFFER_ARB
:
2721 if (!fmt
) goto pix_error
;
2722 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2723 if (hTest
) goto get_error
;
2724 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2725 (curWGLAttr
== WGL_DRAW_TO_BITMAP_ARB
&& (tmp
&GLX_PIXMAP_BIT
)) ||
2726 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2727 piValues
[i
] = GL_TRUE
;
2729 piValues
[i
] = GL_FALSE
;
2732 case WGL_PBUFFER_LARGEST_ARB
:
2733 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2736 case WGL_SAMPLE_BUFFERS_ARB
:
2737 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2740 case WGL_SAMPLES_ARB
:
2741 curGLXAttr
= GLX_SAMPLES_ARB
;
2744 case WGL_FLOAT_COMPONENTS_NV
:
2745 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2748 case WGL_ACCUM_RED_BITS_ARB
:
2749 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2751 case WGL_ACCUM_GREEN_BITS_ARB
:
2752 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2754 case WGL_ACCUM_BLUE_BITS_ARB
:
2755 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2757 case WGL_ACCUM_ALPHA_BITS_ARB
:
2758 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2760 case WGL_ACCUM_BITS_ARB
:
2761 if (!fmt
) goto pix_error
;
2762 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2763 if (hTest
) goto get_error
;
2765 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2766 if (hTest
) goto get_error
;
2768 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2769 if (hTest
) goto get_error
;
2771 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2772 if (hTest
) goto get_error
;
2777 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2780 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2781 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2782 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2784 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2785 * and check which options can work using iPixelFormat=0 and which not.
2786 * A problem would be that this function is an extension. This would
2787 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2789 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2790 if (!fmt
) goto pix_error
;
2791 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2792 if (hTest
) goto get_error
;
2795 piValues
[i
] = GL_FALSE
;
2801 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2805 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2810 * X11DRV_wglGetPixelFormatAttribfvARB
2812 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2814 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2820 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2822 /* Allocate a temporary array to store integer values */
2823 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2825 ERR("couldn't allocate %d array\n", nAttributes
);
2829 /* Piggy-back on wglGetPixelFormatAttribivARB */
2830 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2832 /* Convert integer values to float. Should also check for attributes
2833 that can give decimal values here */
2834 for (i
=0; i
<nAttributes
;i
++) {
2835 pfValues
[i
] = attr
[i
];
2839 HeapFree(GetProcessHeap(), 0, attr
);
2844 * X11DRV_wglBindTexImageARB
2846 * WGL_ARB_render_texture: wglBindTexImageARB
2848 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2850 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2851 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2852 if (NULL
== object
) {
2853 SetLastError(ERROR_INVALID_HANDLE
);
2856 if (!object
->use_render_texture
) {
2857 SetLastError(ERROR_INVALID_HANDLE
);
2861 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2862 static int init
= 0;
2863 int prev_binded_texture
= 0;
2864 GLXContext prev_context
= pglXGetCurrentContext();
2865 Drawable prev_drawable
= pglXGetCurrentDrawable();
2866 GLXContext tmp_context
;
2868 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2869 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2870 isn't ideal performance wise but I wasn't able to get other ways working.
2873 init
= 1; /* Only show the FIXME once for performance reasons */
2874 FIXME("partial stub!\n");
2877 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
2878 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2880 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2882 /* Switch to our pbuffer */
2883 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2885 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2886 * After that upload the pbuffer texture data. */
2887 pglBindTexture(object
->texture_target
, prev_binded_texture
);
2888 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2890 /* Switch back to the original drawable and upload the pbuffer-texture */
2891 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
2892 pglXDestroyContext(gdi_display
, tmp_context
);
2896 if (NULL
!= pglXBindTexImageARB
) {
2897 return pglXBindTexImageARB(object
->display
, object
->drawable
, iBuffer
);
2903 * X11DRV_wglReleaseTexImageARB
2905 * WGL_ARB_render_texture: wglReleaseTexImageARB
2907 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2909 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2910 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2911 if (NULL
== object
) {
2912 SetLastError(ERROR_INVALID_HANDLE
);
2915 if (!object
->use_render_texture
) {
2916 SetLastError(ERROR_INVALID_HANDLE
);
2919 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2922 if (NULL
!= pglXReleaseTexImageARB
) {
2923 return pglXReleaseTexImageARB(object
->display
, object
->drawable
, iBuffer
);
2929 * X11DRV_wglGetExtensionsStringEXT
2931 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2933 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
2934 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2935 return WineGLInfo
.wglExtensions
;
2939 * X11DRV_wglGetSwapIntervalEXT
2941 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2943 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
2944 FIXME("(),stub!\n");
2945 return swap_interval
;
2949 * X11DRV_wglSwapIntervalEXT
2951 * WGL_EXT_swap_control: wglSwapIntervalEXT
2953 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
2954 TRACE("(%d)\n", interval
);
2955 swap_interval
= interval
;
2956 if (NULL
!= pglXSwapIntervalSGI
) {
2957 return 0 == pglXSwapIntervalSGI(interval
);
2959 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2964 * X11DRV_wglAllocateMemoryNV
2966 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2968 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
2969 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
2970 if (pglXAllocateMemoryNV
== NULL
)
2973 return pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
2977 * X11DRV_wglFreeMemoryNV
2979 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2981 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
2982 TRACE("(%p)\n", pointer
);
2983 if (pglXFreeMemoryNV
== NULL
)
2986 pglXFreeMemoryNV(pointer
);
2990 * glxRequireVersion (internal)
2992 * Check if the supported GLX version matches requiredVersion.
2994 static BOOL
glxRequireVersion(int requiredVersion
)
2996 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2997 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3003 static BOOL
glxRequireExtension(const char *requiredExtension
)
3005 if (strstr(WineGLInfo
.glxExtensions
, requiredExtension
) == NULL
) {
3012 static void register_extension_string(const char *ext
)
3014 if (WineGLInfo
.wglExtensions
[0])
3015 strcat(WineGLInfo
.wglExtensions
, " ");
3016 strcat(WineGLInfo
.wglExtensions
, ext
);
3018 TRACE("'%s'\n", ext
);
3021 static BOOL
register_extension(const WineGLExtension
* ext
)
3025 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
3026 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
3028 register_extension_string(ext
->extName
);
3030 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
3031 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
3036 static const WineGLExtension WGL_internal_functions
=
3040 { "wglDisable", X11DRV_wglDisable
},
3041 { "wglEnable", X11DRV_wglEnable
},
3042 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
3043 { "wglIsEnabled", X11DRV_wglIsEnabled
},
3044 { "wglScissor", X11DRV_wglScissor
},
3045 { "wglViewport", X11DRV_wglViewport
},
3050 static const WineGLExtension WGL_ARB_extensions_string
=
3052 "WGL_ARB_extensions_string",
3054 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
3058 static const WineGLExtension WGL_ARB_make_current_read
=
3060 "WGL_ARB_make_current_read",
3062 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
3063 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
3067 static const WineGLExtension WGL_ARB_multisample
=
3069 "WGL_ARB_multisample",
3072 static const WineGLExtension WGL_ARB_pbuffer
=
3076 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
3077 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
3078 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
3079 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
3080 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
3081 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
3085 static const WineGLExtension WGL_ARB_pixel_format
=
3087 "WGL_ARB_pixel_format",
3089 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
3090 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
3091 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3095 static const WineGLExtension WGL_ARB_render_texture
=
3097 "WGL_ARB_render_texture",
3099 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3100 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3104 static const WineGLExtension WGL_EXT_extensions_string
=
3106 "WGL_EXT_extensions_string",
3108 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3112 static const WineGLExtension WGL_EXT_swap_control
=
3114 "WGL_EXT_swap_control",
3116 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3117 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3121 static const WineGLExtension WGL_NV_vertex_array_range
=
3123 "WGL_NV_vertex_array_range",
3125 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3126 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3131 * X11DRV_WineGL_LoadExtensions
3133 static void X11DRV_WineGL_LoadExtensions(void)
3135 WineGLInfo
.wglExtensions
[0] = 0;
3137 /* Load Wine internal functions */
3138 register_extension(&WGL_internal_functions
);
3140 /* ARB Extensions */
3142 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3144 register_extension_string("WGL_ARB_pixel_format_float");
3145 register_extension_string("WGL_ATI_pixel_format_float");
3148 register_extension(&WGL_ARB_extensions_string
);
3150 if (glxRequireVersion(3))
3151 register_extension(&WGL_ARB_make_current_read
);
3153 if (glxRequireExtension("GLX_ARB_multisample"))
3154 register_extension(&WGL_ARB_multisample
);
3156 /* In general pbuffer functionality requires support in the X-server. The functionality is
3157 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3158 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3159 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3161 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3162 * without support in the X-server (which other Mesa based drivers require).
3164 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3165 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3166 * is available pbuffers must be available too. */
3167 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3168 register_extension(&WGL_ARB_pbuffer
);
3170 register_extension(&WGL_ARB_pixel_format
);
3172 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3173 if (glxRequireExtension("GLX_ATI_render_texture") ||
3174 glxRequireExtension("GLX_ARB_render_texture") ||
3175 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3177 register_extension(&WGL_ARB_render_texture
);
3179 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3180 if(glxRequireExtension("GLX_NV_float_buffer"))
3181 register_extension_string("WGL_NV_float_buffer");
3183 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3184 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3185 register_extension_string("WGL_NV_texture_rectangle");
3188 /* EXT Extensions */
3190 register_extension(&WGL_EXT_extensions_string
);
3192 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3193 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3194 register_extension(&WGL_EXT_swap_control
);
3196 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3197 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3198 register_extension(&WGL_NV_vertex_array_range
);
3202 static XID
create_glxpixmap(X11DRV_PDEVICE
*physDev
)
3206 XVisualInfo
template;
3211 /* Retrieve the visualid from our main visual which is the only visual we can use */
3212 template.visualid
= XVisualIDFromVisual(visual
);
3213 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
3215 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
3217 wine_tsx11_unlock();
3218 TRACE("return %lx\n", ret
);
3222 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3228 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3229 ret
= physDev
->drawable
; /* PBuffer */
3232 if(!physDev
->bitmap
->glxpixmap
)
3233 physDev
->bitmap
->glxpixmap
= create_glxpixmap(physDev
);
3234 ret
= physDev
->bitmap
->glxpixmap
;
3238 ret
= physDev
->drawable
;
3242 BOOL
destroy_glxpixmap(XID glxpixmap
)
3245 pglXDestroyGLXPixmap(gdi_display
, glxpixmap
);
3246 wine_tsx11_unlock();
3251 * X11DRV_SwapBuffers
3253 * Swap the buffers of this DC
3255 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3257 GLXDrawable drawable
;
3258 if (!has_opengl()) {
3259 ERR("No libGL on this box - disabling OpenGL support !\n");
3263 TRACE_(opengl
)("(%p)\n", physDev
);
3265 drawable
= get_glxdrawable(physDev
);
3267 pglXSwapBuffers(gdi_display
, drawable
);
3268 wine_tsx11_unlock();
3273 static long prev_time
, frames
;
3275 DWORD time
= GetTickCount();
3277 /* every 1.5 seconds */
3278 if (time
- prev_time
> 1500) {
3279 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
3288 /***********************************************************************
3289 * X11DRV_setup_opengl_visual
3291 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3292 * window (if it exists). If OpenGL isn't available, the visual is simply
3293 * set to the default visual for the display
3295 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3297 XVisualInfo
*visual
= NULL
;
3300 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3301 * D3D and some applications can make use of aux buffers.
3303 int visualProperties
[][11] = {
3304 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_AUX_BUFFERS
, 1, None
},
3305 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, None
},
3306 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, None
},
3307 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, None
},
3314 for (i
= 0; i
< sizeof(visualProperties
)/sizeof(visualProperties
[0]); ++i
) {
3315 visual
= pglXChooseVisual(display
, DefaultScreen(display
), visualProperties
[i
]);
3319 wine_tsx11_unlock();
3322 TRACE("Visual ID %lx Chosen\n", visual
->visualid
);
3324 WARN("No suitable visual found\n");
3329 #else /* no OpenGL includes */
3331 /***********************************************************************
3332 * ChoosePixelFormat (X11DRV.@)
3334 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3335 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3336 ERR("No OpenGL support compiled in.\n");
3341 /***********************************************************************
3342 * DescribePixelFormat (X11DRV.@)
3344 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3347 PIXELFORMATDESCRIPTOR
*ppfd
) {
3348 ERR("No OpenGL support compiled in.\n");
3353 /***********************************************************************
3354 * GetPixelFormat (X11DRV.@)
3356 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3357 ERR("No OpenGL support compiled in.\n");
3362 /***********************************************************************
3363 * SetPixelFormat (X11DRV.@)
3365 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3367 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3368 ERR("No OpenGL support compiled in.\n");
3373 /***********************************************************************
3374 * SwapBuffers (X11DRV.@)
3376 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3377 ERR_(opengl
)("No OpenGL support compiled in.\n");
3383 * X11DRV_wglCreateContext
3385 * For OpenGL32 wglCreateContext.
3387 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3388 ERR_(opengl
)("No OpenGL support compiled in.\n");
3393 * X11DRV_wglDeleteContext
3395 * For OpenGL32 wglDeleteContext.
3397 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3398 ERR_(opengl
)("No OpenGL support compiled in.\n");
3403 * X11DRV_wglGetProcAddress
3405 * For OpenGL32 wglGetProcAddress.
3407 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3408 ERR_(opengl
)("No OpenGL support compiled in.\n");
3412 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3414 ERR_(opengl
)("No OpenGL support compiled in.\n");
3418 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3419 ERR_(opengl
)("No OpenGL support compiled in.\n");
3424 * X11DRV_wglMakeCurrent
3426 * For OpenGL32 wglMakeCurrent.
3428 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3429 ERR_(opengl
)("No OpenGL support compiled in.\n");
3434 * X11DRV_wglShareLists
3436 * For OpenGL32 wglShaderLists.
3438 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3439 ERR_(opengl
)("No OpenGL support compiled in.\n");
3444 * X11DRV_wglUseFontBitmapsA
3446 * For OpenGL32 wglUseFontBitmapsA.
3448 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3450 ERR_(opengl
)("No OpenGL support compiled in.\n");
3455 * X11DRV_wglUseFontBitmapsW
3457 * For OpenGL32 wglUseFontBitmapsW.
3459 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3461 ERR_(opengl
)("No OpenGL support compiled in.\n");
3465 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3470 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3475 BOOL
destroy_glxpixmap(XID glxpixmap
)
3480 #endif /* defined(HAVE_OPENGL) */