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 *glxServerExtensions
;
87 const char *glxClientVersion
;
88 const char *glxClientExtensions
;
90 const char *glxExtensions
;
93 char wglExtensions
[4096];
96 typedef struct wine_glpixelformat
{
104 typedef struct wine_glcontext
{
107 WineGLPixelFormat
*fmt
;
110 X11DRV_PDEVICE
*physDev
;
113 BOOL scissor_enabled
;
114 struct wine_glcontext
*next
;
115 struct wine_glcontext
*prev
;
118 typedef struct wine_glpbuffer
{
121 WineGLPixelFormat
* fmt
;
127 int use_render_texture
; /* This is also the internal texture format */
128 int texture_bind_target
;
130 GLint texture_format
;
131 GLuint texture_target
;
137 static Wine_GLContext
*context_list
;
138 static struct WineGLInfo WineGLInfo
= { 0 };
139 static int use_render_texture_emulation
= 1;
140 static int use_render_texture_ati
= 0;
141 static int swap_interval
= 1;
143 #define MAX_EXTENSIONS 16
144 static const WineGLExtension
*WineGLExtensionList
[MAX_EXTENSIONS
];
145 static int WineGLExtensionListSize
;
147 static WineGLPixelFormat
*WineGLPixelFormatList
;
148 static int WineGLPixelFormatListSize
= 0;
150 static void X11DRV_WineGL_LoadExtensions(void);
152 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
153 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
154 TRACE(" - dwFlags : ");
155 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
156 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
157 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
158 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
159 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
160 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
161 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
162 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
163 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
164 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
165 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
166 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
167 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
168 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
169 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
170 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
171 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
175 TRACE(" - iPixelType : ");
176 switch (ppfd
->iPixelType
) {
177 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
178 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
182 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
183 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
184 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
185 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
186 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
187 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
188 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
189 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
190 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
192 TRACE(" - iLayerType : ");
193 switch (ppfd
->iLayerType
) {
194 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
195 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
196 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
201 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
202 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
204 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
206 MAKE_FUNCPTR(glXChooseVisual
)
207 MAKE_FUNCPTR(glXCreateContext
)
208 MAKE_FUNCPTR(glXCreateGLXPixmap
)
209 MAKE_FUNCPTR(glXGetCurrentContext
)
210 MAKE_FUNCPTR(glXGetCurrentDrawable
)
211 MAKE_FUNCPTR(glXDestroyContext
)
212 MAKE_FUNCPTR(glXDestroyGLXPixmap
)
213 MAKE_FUNCPTR(glXGetConfig
)
214 MAKE_FUNCPTR(glXIsDirect
)
215 MAKE_FUNCPTR(glXMakeCurrent
)
216 MAKE_FUNCPTR(glXSwapBuffers
)
217 MAKE_FUNCPTR(glXQueryExtension
)
218 MAKE_FUNCPTR(glXQueryVersion
)
219 MAKE_FUNCPTR(glXUseXFont
)
222 MAKE_FUNCPTR(glXGetClientString
)
223 MAKE_FUNCPTR(glXQueryExtensionsString
)
224 MAKE_FUNCPTR(glXQueryServerString
)
227 MAKE_FUNCPTR(glXGetFBConfigs
)
228 MAKE_FUNCPTR(glXChooseFBConfig
)
229 MAKE_FUNCPTR(glXCreatePbuffer
)
230 MAKE_FUNCPTR(glXCreateNewContext
)
231 MAKE_FUNCPTR(glXDestroyPbuffer
)
232 MAKE_FUNCPTR(glXGetFBConfigAttrib
)
233 MAKE_FUNCPTR(glXGetVisualFromFBConfig
)
234 MAKE_FUNCPTR(glXMakeContextCurrent
)
235 MAKE_FUNCPTR(glXQueryDrawable
)
236 MAKE_FUNCPTR(glXGetCurrentReadDrawable
)
239 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
240 static BOOL (*pglXBindTexImageARB
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
241 static BOOL (*pglXReleaseTexImageARB
)(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
);
242 static BOOL (*pglXDrawableAttribARB
)(Display
*dpy
, GLXDrawable draw
, const int *attribList
);
243 static int (*pglXSwapIntervalSGI
)(int);
245 /* NV GLX Extension */
246 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
247 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
249 /* Standard OpenGL */
250 MAKE_FUNCPTR(glBindTexture
)
251 MAKE_FUNCPTR(glBitmap
)
252 MAKE_FUNCPTR(glCopyTexSubImage1D
)
253 MAKE_FUNCPTR(glCopyTexImage2D
)
254 MAKE_FUNCPTR(glCopyTexSubImage2D
)
255 MAKE_FUNCPTR(glDisable
)
256 MAKE_FUNCPTR(glDrawBuffer
)
257 MAKE_FUNCPTR(glEnable
)
258 MAKE_FUNCPTR(glEndList
)
259 MAKE_FUNCPTR(glGetError
)
260 MAKE_FUNCPTR(glGetIntegerv
)
261 MAKE_FUNCPTR(glGetString
)
262 MAKE_FUNCPTR(glIsEnabled
)
263 MAKE_FUNCPTR(glNewList
)
264 MAKE_FUNCPTR(glPixelStorei
)
265 MAKE_FUNCPTR(glReadPixels
)
266 MAKE_FUNCPTR(glScissor
)
267 MAKE_FUNCPTR(glTexImage2D
)
268 MAKE_FUNCPTR(glViewport
)
271 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
273 static BOOL infoInitialized
= FALSE
;
275 int screen
= DefaultScreen(gdi_display
);
276 Window win
= RootWindow(gdi_display
, screen
);
278 XVisualInfo
template;
281 GLXContext ctx
= NULL
;
285 infoInitialized
= TRUE
;
289 visual
= DefaultVisual(gdi_display
, screen
);
290 template.visualid
= XVisualIDFromVisual(visual
);
291 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
293 WORD old_fs
= wine_get_fs();
294 /* Create a GLX Context. Without one we can't query GL information */
295 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
296 if (wine_get_fs() != old_fs
)
298 wine_set_fs( old_fs
);
300 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
301 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
307 pglXMakeCurrent(gdi_display
, win
, ctx
);
309 ERR(" couldn't initialize OpenGL, expect problems\n");
314 WineGLInfo
.glVersion
= (const char *) pglGetString(GL_VERSION
);
315 WineGLInfo
.glExtensions
= strdup((const char *) pglGetString(GL_EXTENSIONS
));
317 /* Get the common GLX version supported by GLX client and server ( major/minor) */
318 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
320 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
321 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
323 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
324 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
326 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
327 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
329 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
330 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
331 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
332 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
333 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
337 pglXMakeCurrent(gdi_display
, None
, NULL
);
338 pglXDestroyContext(gdi_display
, ctx
);
344 static BOOL
has_opengl(void)
346 static int init_done
;
347 static void *opengl_handle
;
348 const char *glx_extensions
;
350 int error_base
, event_base
;
352 if (init_done
) return (opengl_handle
!= NULL
);
355 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
356 and include all dependencies */
357 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0);
358 if (opengl_handle
== NULL
) return FALSE
;
360 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
361 if (pglXGetProcAddressARB
== NULL
) {
362 ERR("could not find glXGetProcAddressARB in libGL.\n");
366 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
368 LOAD_FUNCPTR(glXChooseVisual
)
369 LOAD_FUNCPTR(glXCreateContext
)
370 LOAD_FUNCPTR(glXCreateGLXPixmap
)
371 LOAD_FUNCPTR(glXGetCurrentContext
)
372 LOAD_FUNCPTR(glXGetCurrentDrawable
)
373 LOAD_FUNCPTR(glXDestroyContext
)
374 LOAD_FUNCPTR(glXDestroyGLXPixmap
)
375 LOAD_FUNCPTR(glXGetConfig
)
376 LOAD_FUNCPTR(glXIsDirect
)
377 LOAD_FUNCPTR(glXMakeCurrent
)
378 LOAD_FUNCPTR(glXSwapBuffers
)
379 LOAD_FUNCPTR(glXQueryExtension
)
380 LOAD_FUNCPTR(glXQueryVersion
)
381 LOAD_FUNCPTR(glXUseXFont
)
384 LOAD_FUNCPTR(glXGetClientString
)
385 LOAD_FUNCPTR(glXQueryExtensionsString
)
386 LOAD_FUNCPTR(glXQueryServerString
)
389 LOAD_FUNCPTR(glXCreatePbuffer
)
390 LOAD_FUNCPTR(glXCreateNewContext
)
391 LOAD_FUNCPTR(glXDestroyPbuffer
)
392 LOAD_FUNCPTR(glXMakeContextCurrent
)
393 LOAD_FUNCPTR(glXGetCurrentReadDrawable
)
394 LOAD_FUNCPTR(glXGetFBConfigs
)
396 /* Standard OpenGL calls */
397 LOAD_FUNCPTR(glBindTexture
)
398 LOAD_FUNCPTR(glBitmap
)
399 LOAD_FUNCPTR(glCopyTexSubImage1D
)
400 LOAD_FUNCPTR(glCopyTexImage2D
)
401 LOAD_FUNCPTR(glCopyTexSubImage2D
)
402 LOAD_FUNCPTR(glDisable
)
403 LOAD_FUNCPTR(glDrawBuffer
)
404 LOAD_FUNCPTR(glEnable
)
405 LOAD_FUNCPTR(glEndList
)
406 LOAD_FUNCPTR(glGetError
)
407 LOAD_FUNCPTR(glGetIntegerv
)
408 LOAD_FUNCPTR(glGetString
)
409 LOAD_FUNCPTR(glIsEnabled
)
410 LOAD_FUNCPTR(glNewList
)
411 LOAD_FUNCPTR(glPixelStorei
)
412 LOAD_FUNCPTR(glReadPixels
)
413 LOAD_FUNCPTR(glScissor
)
414 LOAD_FUNCPTR(glTexImage2D
)
415 LOAD_FUNCPTR(glViewport
)
418 /* It doesn't matter if these fail. They'll only be used if the driver reports
419 the associated extension is available (and if a driver reports the extension
420 is available but fails to provide the functions, it's quite broken) */
421 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
422 /* NV GLX Extension */
423 LOAD_FUNCPTR(glXAllocateMemoryNV
)
424 LOAD_FUNCPTR(glXFreeMemoryNV
)
427 if(!X11DRV_WineGL_InitOpenglInfo()) {
428 wine_dlclose(opengl_handle
, NULL
, 0);
429 opengl_handle
= NULL
;
434 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
) == True
) {
435 TRACE("GLX is up and running error_base = %d\n", error_base
);
437 wine_dlclose(opengl_handle
, NULL
, 0);
438 opengl_handle
= NULL
;
441 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
442 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
445 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
446 * depends on the reported GLX client / server version and on the client / server extension list.
447 * Those don't have to be the same.
449 * In general the server GLX information should be used in case of indirect rendering. When direct
450 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
451 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
452 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
453 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
454 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
455 * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
456 * is only available in the list of server extensions and not in the client list.
458 * The versioning checks below try to take into account the comments from above.
461 /* Depending on the use of direct or indirect rendering we need either the list of extensions
462 * exported by the client or by the server.
464 if(WineGLInfo
.glxDirect
)
465 glx_extensions
= WineGLInfo
.glxClientExtensions
;
467 glx_extensions
= WineGLInfo
.glxServerExtensions
;
469 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
470 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
471 * the client version is checked.
473 if ((!WineGLInfo
.glxDirect
&& !strcmp("1.2", WineGLInfo
.glxServerVersion
)) ||
474 (WineGLInfo
.glxDirect
&& !strcmp("1.2", WineGLInfo
.glxClientVersion
)))
476 if (NULL
!= strstr(glx_extensions
, "GLX_SGIX_fbconfig")) {
477 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
478 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
479 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
481 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxClientVersion
);
484 pglXChooseFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
485 pglXGetFBConfigAttrib
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
486 pglXGetVisualFromFBConfig
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
489 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
490 * enable this function when the Xserver understand GLX 1.3 or newer
492 if (!strcmp("1.2", WineGLInfo
.glxServerVersion
))
493 pglXQueryDrawable
= NULL
;
495 pglXQueryDrawable
= wine_dlsym(RTLD_DEFAULT
, "glXQueryDrawable", NULL
, 0);
497 if (NULL
!= strstr(glx_extensions
, "GLX_ATI_render_texture")) {
498 pglXBindTexImageARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXBindTexImageARB");
499 pglXReleaseTexImageARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXReleaseTexImageARB");
500 pglXDrawableAttribARB
= (void*)pglXGetProcAddressARB((const GLubyte
*) "glXDrawableAttribARB");
503 X11DRV_WineGL_LoadExtensions();
506 return (opengl_handle
!= NULL
);
509 wine_dlclose(opengl_handle
, NULL
, 0);
510 opengl_handle
= NULL
;
514 static inline Wine_GLContext
*alloc_context(void)
518 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLContext
))))
520 ret
->next
= context_list
;
521 if (context_list
) context_list
->prev
= ret
;
527 static inline void free_context(Wine_GLContext
*context
)
529 if (context
->next
!= NULL
) context
->next
->prev
= context
->prev
;
530 if (context
->prev
!= NULL
) context
->prev
->next
= context
->next
;
531 else context_list
= context
->next
;
533 HeapFree(GetProcessHeap(), 0, context
);
536 static inline Wine_GLContext
*get_context_from_GLXContext(GLXContext ctx
)
539 if (!ctx
) return NULL
;
540 for (ret
= context_list
; ret
; ret
= ret
->next
) if (ctx
== ret
->ctx
) break;
545 * get_hdc_from_Drawable (internal)
547 * For use by wglGetCurrentReadDCARB.
549 static inline HDC
get_hdc_from_Drawable(GLXDrawable d
)
552 for (ret
= context_list
; ret
; ret
= ret
->next
) {
553 if (d
== ret
->physDev
->drawable
) {
560 static inline BOOL
is_valid_context( Wine_GLContext
*ctx
)
563 for (ptr
= context_list
; ptr
; ptr
= ptr
->next
) if (ptr
== ctx
) break;
564 return (ptr
!= NULL
);
567 static int describeContext(Wine_GLContext
* ctx
) {
570 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
571 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
572 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
573 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
574 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
579 static int describeDrawable(Wine_GLContext
* ctx
, Drawable drawable
) {
582 int attribList
[3] = { GLX_FBCONFIG_ID
, 0, None
};
585 if (pglXQueryDrawable
== NULL
) {
586 /** glXQueryDrawable not available so returns not supported */
590 TRACE(" Drawable %p have :\n", (void*) drawable
);
591 pglXQueryDrawable(gdi_display
, drawable
, GLX_WIDTH
, (unsigned int*) &tmp
);
592 TRACE(" - WIDTH as %d\n", tmp
);
593 pglXQueryDrawable(gdi_display
, drawable
, GLX_HEIGHT
, (unsigned int*) &tmp
);
594 TRACE(" - HEIGHT as %d\n", tmp
);
595 pglXQueryDrawable(gdi_display
, drawable
, GLX_FBCONFIG_ID
, (unsigned int*) &tmp
);
596 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp
);
599 fbCfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribList
, &nElements
);
600 if (fbCfgs
== NULL
) {
604 pglXGetFBConfigAttrib(gdi_display
, fbCfgs
[0], GLX_VISUAL_ID
, &tmp
);
605 TRACE(" - VISUAL_ID as 0x%x\n", tmp
);
612 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, Wine_GLPBuffer
* pbuf
) {
618 int wantColorBits
= 0;
621 /* The list of WGL attributes is allowed to be NULL, so don't return -1 (error) but just 0 */
625 while (0 != iWGLAttr
[cur
]) {
626 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
628 switch (iWGLAttr
[cur
]) {
629 case WGL_COLOR_BITS_ARB
:
630 pop
= iWGLAttr
[++cur
];
631 wantColorBits
= pop
; /** see end */
633 case WGL_BLUE_BITS_ARB
:
634 pop
= iWGLAttr
[++cur
];
635 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
636 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
638 case WGL_RED_BITS_ARB
:
639 pop
= iWGLAttr
[++cur
];
640 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
641 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
643 case WGL_GREEN_BITS_ARB
:
644 pop
= iWGLAttr
[++cur
];
645 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
646 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
648 case WGL_ALPHA_BITS_ARB
:
649 pop
= iWGLAttr
[++cur
];
651 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
652 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
654 case WGL_DEPTH_BITS_ARB
:
655 pop
= iWGLAttr
[++cur
];
656 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
657 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
659 case WGL_STENCIL_BITS_ARB
:
660 pop
= iWGLAttr
[++cur
];
661 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
662 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
664 case WGL_DOUBLE_BUFFER_ARB
:
665 pop
= iWGLAttr
[++cur
];
666 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
667 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
670 case WGL_PIXEL_TYPE_ARB
:
671 pop
= iWGLAttr
[++cur
];
673 case WGL_TYPE_COLORINDEX_ARB
: pop
= GLX_COLOR_INDEX_BIT
; isColor
= 1; break ;
674 case WGL_TYPE_RGBA_ARB
: pop
= GLX_RGBA_BIT
; break ;
675 /* 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 */
676 case WGL_TYPE_RGBA_FLOAT_ATI
: pop
= GLX_RGBA_FLOAT_BIT
; break ;
678 ERR("unexpected PixelType(%x)\n", pop
);
681 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pop
);
682 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur
, pop
);
685 case WGL_SUPPORT_GDI_ARB
:
686 pop
= iWGLAttr
[++cur
];
687 /* We only support a limited number of formats which are all renderable by X (similar to GDI).
688 * Ignore this attribute to prevent us from not finding a match due to the limited
689 * amount of formats supported right now. This option could be matched to GLX_X_RENDERABLE
690 * but the issue is that when a program asks for no GDI support, there's no format we can return
691 * as all our supported formats are renderable by X.
693 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
696 case WGL_DRAW_TO_BITMAP_ARB
:
697 pop
= iWGLAttr
[++cur
];
698 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
699 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
701 drawattrib
|= GLX_PIXMAP_BIT
;
705 case WGL_DRAW_TO_WINDOW_ARB
:
706 pop
= iWGLAttr
[++cur
];
707 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
708 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
710 drawattrib
|= GLX_WINDOW_BIT
;
714 case WGL_DRAW_TO_PBUFFER_ARB
:
715 pop
= iWGLAttr
[++cur
];
716 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
717 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
719 drawattrib
|= GLX_PBUFFER_BIT
;
723 case WGL_ACCELERATION_ARB
:
724 case WGL_SUPPORT_OPENGL_ARB
:
725 pop
= iWGLAttr
[++cur
];
726 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
727 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
730 case WGL_PBUFFER_LARGEST_ARB
:
731 pop
= iWGLAttr
[++cur
];
732 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
733 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
736 case WGL_SAMPLE_BUFFERS_ARB
:
737 pop
= iWGLAttr
[++cur
];
738 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
739 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
742 case WGL_SAMPLES_ARB
:
743 pop
= iWGLAttr
[++cur
];
744 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
745 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
748 case WGL_TEXTURE_FORMAT_ARB
:
749 case WGL_TEXTURE_TARGET_ARB
:
750 case WGL_MIPMAP_TEXTURE_ARB
:
751 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
752 pop
= iWGLAttr
[++cur
];
754 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
756 if (use_render_texture_ati
) {
757 /** nothing to do here */
759 else if (!use_render_texture_emulation
) {
760 if (WGL_NO_TEXTURE_ARB
!= pop
) {
761 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
762 return -1; /** error: don't support it */
764 PUSH2(oGLXAttr
, GLX_X_RENDERABLE
, pop
);
765 drawattrib
|= GLX_PBUFFER_BIT
;
769 case WGL_FLOAT_COMPONENTS_NV
:
770 pop
= iWGLAttr
[++cur
];
771 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, pop
);
772 TRACE("pAttr[%d] = GLX_FLOAT_COMPONENTS_NV: %x\n", cur
, pop
);
774 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
775 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
776 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
777 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
778 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
779 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
780 pop
= iWGLAttr
[++cur
];
781 /** cannot be converted, see direct handling on
782 * - wglGetPixelFormatAttribivARB
783 * TODO: wglChoosePixelFormat
788 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
795 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
796 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
799 * The number of color bitplanes in each color buffer. For RGBA
800 * pixel types, it is the size of the color buffer, excluding the
801 * alpha bitplanes. For color-index pixels, it is the size of the
802 * color index buffer.
805 * This attribute defines the number of bits per color buffer.
806 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
807 * this is equal to the depth value reported in the X11 visual.
808 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
809 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
812 if (0 < wantColorBits
) {
814 wantColorBits
+= sz_alpha
;
816 if (32 < wantColorBits
) {
817 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits
);
820 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, wantColorBits
);
821 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur
, wantColorBits
);
824 /* Apply the OR'd drawable type bitmask now. */
826 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
827 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
833 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
835 int render_type
=0, render_type_bit
;
836 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
837 switch(render_type_bit
)
840 render_type
= GLX_RGBA_TYPE
;
842 case GLX_COLOR_INDEX_BIT
:
843 render_type
= GLX_COLOR_INDEX_TYPE
;
845 case GLX_RGBA_FLOAT_BIT
:
846 render_type
= GLX_RGBA_FLOAT_TYPE
;
849 ERR("Unknown render_type: %x\n", render_type
);
854 static BOOL
get_fbconfig_from_visualid(Display
*display
, Visual
*visual
, GLXFBConfig
*fbconfig
, int *fmt_id
)
856 GLXFBConfig
* cfgs
= NULL
;
863 if(!display
|| !visual
) {
864 ERR("Invalid display or visual\n");
867 visualid
= XVisualIDFromVisual(visual
);
869 /* Get a list of all available framebuffer configurations */
870 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
871 if (NULL
== cfgs
|| 0 == nCfgs
) {
872 ERR("glXChooseFBConfig returns NULL\n");
873 if(cfgs
!= NULL
) XFree(cfgs
);
877 /* Find the requested offscreen format and count the number of offscreen formats */
878 for(i
=0; i
<nCfgs
; i
++) {
879 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
880 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
882 /* We are looking up the GLX index of our main visual and have found it :) */
883 if(visualid
== tmp_vis_id
) {
884 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id
, i
, tmp_vis_id
);
886 *fmt_id
= tmp_fmt_id
;
892 ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid
);
897 static BOOL
init_formats(Display
*display
, int screen
, Visual
*visual
)
899 int fmt_id
, tmp_vis_id
, tmp_fmt_id
, nCfgs
, i
;
901 GLXFBConfig fbconfig
;
902 int nOffscreenFormats
= 0;
904 /* Locate the fbconfig correspondig to our main visual */
905 if(!get_fbconfig_from_visualid(display
, visual
, &fbconfig
, &fmt_id
)) {
906 ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
910 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
911 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
912 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
913 * because this call lists both types of formats instead of only onscreen ones. */
914 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
915 if (NULL
== cfgs
|| 0 == nCfgs
) {
916 WARN("glXChooseFBConfig returns NULL\n");
917 if(cfgs
!= NULL
) XFree(cfgs
);
919 /* We only have the single format of Wine's main visual */
920 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WineGLPixelFormat
));
921 WineGLPixelFormatList
[0].iPixelFormat
= 1;
922 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
923 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
924 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
925 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
926 WineGLPixelFormatListSize
= 1;
929 /* Count the number of offscreen formats to determine the size for our pixelformat list */
930 for(i
=0; i
<nCfgs
; i
++) {
931 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
933 /* We have found an offscreen rendering format :) */
934 if(tmp_vis_id
== 0) {
938 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats
);
940 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
941 WineGLPixelFormatList
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (1+nOffscreenFormats
)*sizeof(WineGLPixelFormat
));
942 WineGLPixelFormatList
[0].iPixelFormat
= 1;
943 WineGLPixelFormatList
[0].fbconfig
= fbconfig
;
944 WineGLPixelFormatList
[0].fmt_id
= fmt_id
;
945 WineGLPixelFormatList
[0].render_type
= get_render_type_from_fbconfig(display
, fbconfig
);
946 WineGLPixelFormatList
[0].offscreenOnly
= FALSE
;
947 WineGLPixelFormatListSize
= 1;
949 /* Fill the list with offscreen formats */
950 for(i
=0; i
<nCfgs
; i
++) {
951 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_VISUAL_ID
, &tmp_vis_id
);
952 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &tmp_fmt_id
);
954 /* We have found an offscreen rendering format :) */
955 if(tmp_vis_id
== 0) {
956 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id
, WineGLPixelFormatListSize
+1, i
);
957 WineGLPixelFormatList
[WineGLPixelFormatListSize
].iPixelFormat
= WineGLPixelFormatListSize
+1; /* The index starts at 1 */
958 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fbconfig
= cfgs
[i
];
959 WineGLPixelFormatList
[WineGLPixelFormatListSize
].fmt_id
= tmp_fmt_id
;
960 WineGLPixelFormatList
[WineGLPixelFormatListSize
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
961 WineGLPixelFormatList
[WineGLPixelFormatListSize
].offscreenOnly
= TRUE
;
962 WineGLPixelFormatListSize
++;
967 if(cfgs
!= NULL
) XFree(cfgs
);
972 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
973 * In our WGL implementation we only support a subset of these formats namely the format of
974 * Wine's main visual and offscreen formats (if they are available).
975 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
976 * and it returns the number of supported WGL formats in fmt_count.
978 static WineGLPixelFormat
* ConvertPixelFormatWGLtoGLX(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
, int *fmt_count
)
980 WineGLPixelFormat
*res
= NULL
;
982 /* Init the list of pixel formats when we need it */
983 if(!WineGLPixelFormatListSize
)
984 init_formats(display
, DefaultScreen(display
), visual
);
986 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
987 * iPixelFormat in case of probing the number of pixelformats.
989 if((iPixelFormat
<= 0) || (iPixelFormat
> WineGLPixelFormatListSize
)) {
991 *fmt_count
= WineGLPixelFormatListSize
;
993 *fmt_count
= 1; /* Only show the format of our main visual */
995 else if(iPixelFormat
== 1) {
996 res
= &WineGLPixelFormatList
[0];
997 *fmt_count
= 1; /* Only show the format of our main visual */
999 else if((WineGLPixelFormatList
[iPixelFormat
-1].offscreenOnly
== TRUE
) && AllowOffscreen
) {
1000 res
= &WineGLPixelFormatList
[iPixelFormat
-1];
1001 *fmt_count
= WineGLPixelFormatListSize
;
1002 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res
->fbconfig
, iPixelFormat
);
1005 TRACE("Number of returned pixelformats=%d\n", *fmt_count
);
1010 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1011 static int ConvertPixelFormatGLXtoWGL(Display
*display
, int fmt_id
)
1015 /* Init the list of pixel formats when we need it */
1016 if(!WineGLPixelFormatListSize
)
1017 init_formats(display
, DefaultScreen(display
), visual
);
1019 for(i
=0; i
<WineGLPixelFormatListSize
; i
++) {
1020 if(WineGLPixelFormatList
[i
].fmt_id
== fmt_id
) {
1021 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList
[i
].iPixelFormat
, fmt_id
);
1022 return WineGLPixelFormatList
[i
].iPixelFormat
;
1025 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id
);
1030 * X11DRV_ChoosePixelFormat
1032 * Equivalent to glXChooseVisual.
1034 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
1035 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1036 WineGLPixelFormat
*fmt
;
1040 if (!has_opengl()) {
1041 ERR("No libGL on this box - disabling OpenGL support !\n");
1045 if (TRACE_ON(opengl
)) {
1046 TRACE("(%p,%p)\n", physDev
, ppfd
);
1048 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR
*) ppfd
);
1053 ERR("Can't get an opengl visual!\n");
1057 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, 1 /* main visual */, FALSE
/* offscreen */, &value
);
1058 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
1060 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual
->visualid
);
1067 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1068 if (value
& GLX_RGBA_BIT
)
1069 iPixelType
= PFD_TYPE_RGBA
;
1071 iPixelType
= PFD_TYPE_COLORINDEX
;
1073 if (ppfd
->iPixelType
!= iPixelType
) {
1074 TRACE("pixel type mismatch\n");
1079 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
); if (value
) dwFlags
|= PFD_DOUBLEBUFFER
;
1080 if (!(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) && (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)) {
1081 if (!(dwFlags
& PFD_DOUBLEBUFFER
)) {
1082 TRACE("dbl buffer mismatch\n");
1088 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) dwFlags
|= PFD_STEREO
;
1089 if (!(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) && (ppfd
->dwFlags
& PFD_STEREO
)) {
1090 if (!(dwFlags
& PFD_STEREO
)) {
1091 TRACE("stereo mismatch\n");
1097 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &value
);
1098 if (ppfd
->iPixelType
==PFD_TYPE_RGBA
&& ppfd
->cAlphaBits
&& !value
) {
1099 TRACE("alpha mismatch\n");
1104 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1105 if (ppfd
->cDepthBits
&& !value
) {
1106 TRACE("depth mismatch\n");
1111 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1112 if (ppfd
->cStencilBits
&& !value
) {
1113 TRACE("stencil mismatch\n");
1118 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1119 if (ppfd
->cAuxBuffers
&& !value
) {
1120 TRACE("aux mismatch\n");
1124 /* When we pass all the checks we have found a matching format :) */
1126 TRACE("Successfully found a matching mode, returning index: %d\n", ret
);
1131 TRACE("No matching mode was found returning 0\n");
1133 wine_tsx11_unlock();
1138 * X11DRV_DescribePixelFormat
1140 * Get the pixel-format descriptor associated to the given id
1142 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
1145 PIXELFORMATDESCRIPTOR
*ppfd
) {
1146 /*XVisualInfo *vis;*/
1149 WineGLPixelFormat
*fmt
;
1153 if (!has_opengl()) {
1154 ERR("No libGL on this box - disabling OpenGL support !\n");
1158 TRACE("(%p,%d,%d,%p)\n", physDev
, iPixelFormat
, nBytes
, ppfd
);
1160 /* 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 */
1161 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &fmt_count
);
1163 /* The application is only querying the number of pixelformats */
1165 } else if(fmt
== NULL
) {
1166 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat
, fmt_count
);
1170 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1171 ERR("Wrong structure size !\n");
1172 /* Should set error */
1178 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1179 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1182 /* These flags are always the same... */
1183 ppfd
->dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
1184 /* Now the flags extracted from the Visual */
1188 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_CONFIG_CAVEAT
, &value
);
1189 if(value
== GLX_SLOW_CONFIG
)
1190 ppfd
->dwFlags
|= PFD_GENERIC_ACCELERATED
;
1192 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
); if (value
) ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1193 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1196 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1197 if (value
& GLX_RGBA_BIT
)
1198 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1200 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1203 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1204 ppfd
->cColorBits
= value
;
1206 /* Red, green, blue and alpha bits / shifts */
1207 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1208 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1209 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1210 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1211 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1213 ppfd
->cRedBits
= rb
;
1214 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1215 ppfd
->cBlueBits
= bb
;
1216 ppfd
->cBlueShift
= ab
;
1217 ppfd
->cGreenBits
= gb
;
1218 ppfd
->cGreenShift
= bb
+ ab
;
1219 ppfd
->cAlphaBits
= ab
;
1220 ppfd
->cAlphaShift
= 0;
1223 ppfd
->cRedShift
= 0;
1224 ppfd
->cBlueBits
= 0;
1225 ppfd
->cBlueShift
= 0;
1226 ppfd
->cGreenBits
= 0;
1227 ppfd
->cGreenShift
= 0;
1228 ppfd
->cAlphaBits
= 0;
1229 ppfd
->cAlphaShift
= 0;
1231 /* Accums : to do ... */
1234 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1235 ppfd
->cDepthBits
= value
;
1238 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1239 ppfd
->cStencilBits
= value
;
1241 wine_tsx11_unlock();
1243 /* Aux : to do ... */
1245 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1247 if (TRACE_ON(opengl
)) {
1248 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1255 * X11DRV_GetPixelFormat
1257 * Get the pixel-format id used by this DC
1259 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
1260 WineGLPixelFormat
*fmt
;
1262 TRACE("(%p)\n", physDev
);
1264 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, physDev
->current_pf
, TRUE
, &tmp
);
1267 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1268 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev
->current_pf
);
1271 else if(fmt
->offscreenOnly
)
1273 /* Offscreen formats can't be used with traditional WGL calls.
1274 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1275 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt
->iPixelFormat
);
1279 return physDev
->current_pf
;
1280 TRACE("(%p): returns %d\n", physDev
, physDev
->current_pf
);
1284 * X11DRV_SetPixelFormat
1286 * Set the pixel-format id used by this DC
1288 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
1290 const PIXELFORMATDESCRIPTOR
*ppfd
) {
1291 WineGLPixelFormat
*fmt
;
1294 TRACE("(%p,%d,%p)\n", physDev
, iPixelFormat
, ppfd
);
1296 if (!has_opengl()) {
1297 ERR("No libGL on this box - disabling OpenGL support !\n");
1301 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1302 if(get_glxdrawable(physDev
) == root_window
)
1304 ERR("Invalid operation on root_window\n");
1308 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1309 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */, &value
);
1311 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1315 physDev
->current_pf
= iPixelFormat
;
1317 if (TRACE_ON(opengl
)) {
1321 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1323 * in case of root window created HDCs we crash here :(
1325 Drawable drawable = get_drawable( physDev->hdc );
1326 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1327 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1328 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1329 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1330 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1331 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1332 TRACE(" - WIDTH as %d\n", tmp);
1333 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1334 TRACE(" - HEIGHT as %d\n", tmp);
1336 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1338 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1340 TRACE(" FBConfig have :\n");
1341 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1342 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1343 TRACE(" - VISUAL_ID 0x%x\n", value
);
1344 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1345 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1352 * X11DRV_wglCreateContext
1354 * For OpenGL32 wglCreateContext.
1356 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
)
1358 Wine_GLContext
*ret
;
1359 WineGLPixelFormat
*fmt
;
1360 int hdcPF
= physDev
->current_pf
;
1364 HDC hdc
= physDev
->hdc
;
1366 TRACE("(%p)->(PF:%d)\n", hdc
, hdcPF
);
1368 if (!has_opengl()) {
1369 ERR("No libGL on this box - disabling OpenGL support !\n");
1373 /* First, get the visual in use by the X11DRV */
1374 if (!gdi_display
) return 0;
1376 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, hdcPF
, TRUE
/* Offscreen */, &fmt_count
);
1377 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1378 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1379 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1380 * If this fails something is very wrong on the system. */
1382 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF
);
1383 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1387 if (fmt_count
< hdcPF
) {
1388 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, hdcPF
, fmt_count
);
1389 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1393 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1395 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1396 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
1400 /* The context will be allocated in the wglMakeCurrent call */
1402 ret
= alloc_context();
1403 wine_tsx11_unlock();
1405 ret
->physDev
= physDev
;
1409 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, fmt
->fbconfig
);
1411 TRACE(" creating context %p (GL context creation delayed)\n", ret
);
1416 * X11DRV_wglDeleteContext
1418 * For OpenGL32 wglDeleteContext.
1420 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
)
1422 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1425 TRACE("(%p)\n", hglrc
);
1427 if (!has_opengl()) {
1428 ERR("No libGL on this box - disabling OpenGL support !\n");
1433 /* A game (Half Life not to name it) deletes twice the same context,
1434 * so make sure it is valid first */
1435 if (is_valid_context( ctx
))
1437 if (ctx
->ctx
) pglXDestroyContext(gdi_display
, ctx
->ctx
);
1442 WARN("Error deleting context !\n");
1443 SetLastError(ERROR_INVALID_HANDLE
);
1446 wine_tsx11_unlock();
1452 * X11DRV_wglGetCurrentReadDCARB
1454 * For OpenGL32 wglGetCurrentReadDCARB.
1456 static HDC WINAPI
X11DRV_wglGetCurrentReadDCARB(void)
1464 gl_d
= pglXGetCurrentReadDrawable();
1465 ret
= get_hdc_from_Drawable(gl_d
);
1466 wine_tsx11_unlock();
1468 TRACE(" returning %p (GL drawable %lu)\n", ret
, gl_d
);
1473 * X11DRV_wglGetProcAddress
1475 * For OpenGL32 wglGetProcAddress.
1477 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
)
1480 const WineGLExtension
*ext
;
1482 int padding
= 32 - strlen(lpszProc
);
1486 if (!has_opengl()) {
1487 ERR("No libGL on this box - disabling OpenGL support !\n");
1491 /* Check the table of WGL extensions to see if we need to return a WGL extension
1492 * or a function pointer to a native OpenGL function. */
1493 if(strncmp(lpszProc
, "wgl", 3) != 0) {
1494 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1496 TRACE("('%s'):%*s", lpszProc
, padding
, " ");
1497 for (i
= 0; i
< WineGLExtensionListSize
; ++i
) {
1498 ext
= WineGLExtensionList
[i
];
1499 for (j
= 0; ext
->extEntryPoints
[j
].funcName
; ++j
) {
1500 if (strcmp(ext
->extEntryPoints
[j
].funcName
, lpszProc
) == 0) {
1501 TRACE("(%p) - WineGL\n", ext
->extEntryPoints
[j
].funcAddress
);
1502 return ext
->extEntryPoints
[j
].funcAddress
;
1508 ERR("(%s) - not found\n", lpszProc
);
1512 /***********************************************************************
1513 * sync_current_drawable
1515 * Adjust the current viewport and scissor in order to position
1516 * and size the current drawable correctly on the parent window.
1518 static void sync_current_drawable(BOOL updatedc
)
1524 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1528 if (ctx
&& ctx
->physDev
)
1531 GetClipBox(ctx
->physDev
->hdc
, &rc
); /* Make sure physDev is up to date */
1533 dy
= ctx
->physDev
->drawable_rect
.bottom
- ctx
->physDev
->drawable_rect
.top
-
1534 ctx
->physDev
->dc_rect
.bottom
;
1535 width
= ctx
->physDev
->dc_rect
.right
- ctx
->physDev
->dc_rect
.left
;
1536 height
= ctx
->physDev
->dc_rect
.bottom
- ctx
->physDev
->dc_rect
.top
;
1540 pglViewport(ctx
->physDev
->dc_rect
.left
+ ctx
->viewport
.left
,
1541 dy
+ ctx
->viewport
.top
,
1542 ctx
->viewport
.right
? (ctx
->viewport
.right
- ctx
->viewport
.left
) : width
,
1543 ctx
->viewport
.bottom
? (ctx
->viewport
.bottom
- ctx
->viewport
.top
) : height
);
1545 pglEnable(GL_SCISSOR_TEST
);
1547 if (ctx
->scissor_enabled
)
1548 pglScissor(ctx
->physDev
->dc_rect
.left
+ min(width
, max(0, ctx
->scissor
.left
)),
1549 dy
+ min(height
, max(0, ctx
->scissor
.top
)),
1550 min(width
, max(0, ctx
->scissor
.right
- ctx
->scissor
.left
)),
1551 min(height
, max(0, ctx
->scissor
.bottom
- ctx
->scissor
.top
)));
1553 pglScissor(ctx
->physDev
->dc_rect
.left
, dy
, width
, height
);
1555 wine_tsx11_unlock();
1560 * X11DRV_wglMakeCurrent
1562 * For OpenGL32 wglMakeCurrent.
1564 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
1566 HDC hdc
= physDev
->hdc
;
1567 DWORD type
= GetObjectType(hdc
);
1569 TRACE("(%p,%p)\n", hdc
, hglrc
);
1571 if (!has_opengl()) {
1572 ERR("No libGL on this box - disabling OpenGL support !\n");
1577 if (hglrc
== NULL
) {
1578 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1579 NtCurrentTeb()->glContext
= NULL
;
1581 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1582 Drawable drawable
= get_glxdrawable(physDev
);
1583 if (ctx
->ctx
== NULL
) {
1584 /* The describe lines below are for debugging purposes only */
1585 if (TRACE_ON(wgl
)) {
1586 describeDrawable(ctx
, drawable
);
1587 describeContext(ctx
);
1590 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1591 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1593 TRACE(" Creating GLX Context\n");
1595 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, type
== OBJ_MEMDC
? False
: True
);
1596 else /* Create a GLX Context for a pbuffer */
1597 ctx
->ctx
= pglXCreateNewContext(gdi_display
, ctx
->fmt
->fbconfig
, ctx
->fmt
->render_type
, NULL
, True
);
1599 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1601 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display
, (void*) drawable
, ctx
->ctx
);
1602 ret
= pglXMakeCurrent(gdi_display
, drawable
, ctx
->ctx
);
1603 NtCurrentTeb()->glContext
= ctx
;
1606 ctx
->physDev
= physDev
;
1608 if (type
== OBJ_MEMDC
)
1610 ctx
->do_escape
= TRUE
;
1611 pglDrawBuffer(GL_FRONT_LEFT
);
1615 sync_current_drawable(FALSE
);
1619 wine_tsx11_unlock();
1620 TRACE(" returning %s\n", (ret
? "True" : "False"));
1625 * X11DRV_wglMakeContextCurrentARB
1627 * For OpenGL32 wglMakeContextCurrentARB
1629 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
)
1632 TRACE("(%p,%p,%p)\n", hDrawDev
, hReadDev
, hglrc
);
1634 if (!has_opengl()) {
1635 ERR("No libGL on this box - disabling OpenGL support !\n");
1640 if (hglrc
== NULL
) {
1641 ret
= pglXMakeCurrent(gdi_display
, None
, NULL
);
1642 NtCurrentTeb()->glContext
= NULL
;
1644 if (NULL
== pglXMakeContextCurrent
) {
1647 Wine_GLContext
*ctx
= (Wine_GLContext
*) hglrc
;
1648 Drawable d_draw
= get_glxdrawable(hDrawDev
);
1649 Drawable d_read
= get_glxdrawable(hReadDev
);
1651 if (ctx
->ctx
== NULL
) {
1652 ctx
->ctx
= pglXCreateContext(gdi_display
, ctx
->vis
, NULL
, GetObjectType(hDrawDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1653 TRACE(" created a delayed OpenGL context (%p)\n", ctx
->ctx
);
1655 ret
= pglXMakeContextCurrent(gdi_display
, d_draw
, d_read
, ctx
->ctx
);
1656 NtCurrentTeb()->glContext
= ctx
;
1659 wine_tsx11_unlock();
1661 TRACE(" returning %s\n", (ret
? "True" : "False"));
1666 * X11DRV_wglShareLists
1668 * For OpenGL32 wglShaderLists.
1670 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
1671 Wine_GLContext
*org
= (Wine_GLContext
*) hglrc1
;
1672 Wine_GLContext
*dest
= (Wine_GLContext
*) hglrc2
;
1674 TRACE("(%p, %p)\n", org
, dest
);
1676 if (!has_opengl()) {
1677 ERR("No libGL on this box - disabling OpenGL support !\n");
1681 if (NULL
!= dest
&& dest
->ctx
!= NULL
) {
1682 ERR("Could not share display lists, context already created !\n");
1685 if (org
->ctx
== NULL
) {
1687 describeContext(org
);
1690 org
->ctx
= pglXCreateContext(gdi_display
, org
->vis
, NULL
, GetObjectType(org
->physDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1691 else /* Create a GLX Context for a pbuffer */
1692 org
->ctx
= pglXCreateNewContext(gdi_display
, org
->fmt
->fbconfig
, org
->fmt
->render_type
, NULL
, True
);
1693 wine_tsx11_unlock();
1694 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org
->ctx
, org
);
1698 describeContext(dest
);
1699 /* Create the destination context with display lists shared */
1701 dest
->ctx
= pglXCreateContext(gdi_display
, dest
->vis
, org
->ctx
, GetObjectType(org
->physDev
->hdc
) == OBJ_MEMDC
? False
: True
);
1702 else /* Create a GLX Context for a pbuffer */
1703 dest
->ctx
= pglXCreateNewContext(gdi_display
, dest
->fmt
->fbconfig
, dest
->fmt
->render_type
, org
->ctx
, True
);
1704 wine_tsx11_unlock();
1705 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1712 static BOOL
internal_wglUseFontBitmaps(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, DWORD (WINAPI
*GetGlyphOutline_ptr
)(HDC
,UINT
,UINT
,LPGLYPHMETRICS
,DWORD
,LPVOID
,const MAT2
*))
1714 /* We are running using client-side rendering fonts... */
1718 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1722 pglGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1723 pglPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1724 wine_tsx11_unlock();
1726 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1727 unsigned int needed_size
= GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, NULL
);
1728 int height
, width_int
;
1730 TRACE("Glyph : %3d / List : %d\n", glyph
, listBase
);
1731 if (needed_size
== GDI_ERROR
) {
1732 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size
);
1735 TRACE(" - needed size : %d\n", needed_size
);
1738 if (needed_size
> size
) {
1740 HeapFree(GetProcessHeap(), 0, bitmap
);
1741 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1742 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1743 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1745 if (GetGlyphOutline_ptr(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, NULL
) == GDI_ERROR
) goto error
;
1746 if (TRACE_ON(opengl
)) {
1747 unsigned int height
, width
, bitmask
;
1748 unsigned char *bitmap_
= (unsigned char *) bitmap
;
1750 TRACE(" - bbox : %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1751 TRACE(" - origin : (%d , %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1752 TRACE(" - increment : %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1753 if (needed_size
!= 0) {
1754 TRACE(" - bitmap :\n");
1755 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1757 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1762 if (*bitmap_
& bitmask
)
1767 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1773 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1774 * glyph for it to be drawn properly.
1776 if (needed_size
!= 0) {
1777 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1778 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1780 for (width
= 0; width
< width_int
; width
++) {
1781 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1782 ((int *) bitmap
)[height
* width_int
+ width
];
1788 pglNewList(listBase
++, GL_COMPILE
);
1789 if (needed_size
!= 0) {
1790 pglBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1791 0 - (int) gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- (int) gm
.gmptGlyphOrigin
.y
,
1792 gm
.gmCellIncX
, gm
.gmCellIncY
,
1795 /* This is the case of 'empty' glyphs like the space character */
1796 pglBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1799 wine_tsx11_unlock();
1803 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1804 wine_tsx11_unlock();
1806 HeapFree(GetProcessHeap(), 0, bitmap
);
1807 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1812 pglPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1813 wine_tsx11_unlock();
1815 HeapFree(GetProcessHeap(), 0, bitmap
);
1816 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1821 * X11DRV_wglUseFontBitmapsA
1823 * For OpenGL32 wglUseFontBitmapsA.
1825 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1827 Font fid
= physDev
->font
;
1829 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1831 if (!has_opengl()) {
1832 ERR("No libGL on this box - disabling OpenGL support !\n");
1837 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineA
);
1841 /* I assume that the glyphs are at the same position for X and for Windows */
1842 pglXUseXFont(fid
, first
, count
, listBase
);
1843 wine_tsx11_unlock();
1848 * X11DRV_wglUseFontBitmapsW
1850 * For OpenGL32 wglUseFontBitmapsW.
1852 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
1854 Font fid
= physDev
->font
;
1856 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev
->hdc
, first
, count
, listBase
, fid
);
1858 if (!has_opengl()) {
1859 ERR("No libGL on this box - disabling OpenGL support !\n");
1864 return internal_wglUseFontBitmaps(physDev
->hdc
, first
, count
, listBase
, GetGlyphOutlineW
);
1867 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1870 /* I assume that the glyphs are at the same position for X and for Windows */
1871 pglXUseXFont(fid
, first
, count
, listBase
);
1872 wine_tsx11_unlock();
1876 static void WINAPI
X11DRV_wglDisable(GLenum cap
)
1878 if (cap
== GL_SCISSOR_TEST
)
1880 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1883 ctx
->scissor_enabled
= FALSE
;
1889 wine_tsx11_unlock();
1893 static void WINAPI
X11DRV_wglEnable(GLenum cap
)
1895 if (cap
== GL_SCISSOR_TEST
)
1897 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1900 ctx
->scissor_enabled
= TRUE
;
1906 wine_tsx11_unlock();
1910 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1911 static void WINAPI
X11DRV_wglGetIntegerv(GLenum pname
, GLint
* params
)
1918 GLXContext gl_ctx
= pglXGetCurrentContext();
1919 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1921 pglGetIntegerv(pname
, params
);
1923 * if we cannot find a Wine Context
1924 * we only have the default wine desktop context,
1925 * so if we have only a 24 depth say we have 32
1927 if (NULL
== ret
&& 24 == *params
) {
1930 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params
);
1935 GLXContext gl_ctx
= pglXGetCurrentContext();
1936 Wine_GLContext
* ret
= get_context_from_GLXContext(gl_ctx
);
1938 pglXGetFBConfigAttrib(gdi_display
, ret
->fmt
->fbconfig
, GLX_ALPHA_SIZE
, params
);
1939 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params
);
1943 pglGetIntegerv(pname
, params
);
1946 wine_tsx11_unlock();
1949 static GLboolean WINAPI
X11DRV_wglIsEnabled(GLenum cap
)
1951 GLboolean enabled
= False
;
1953 if (cap
== GL_SCISSOR_TEST
)
1955 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1958 enabled
= ctx
->scissor_enabled
;
1963 enabled
= pglIsEnabled(cap
);
1964 wine_tsx11_unlock();
1969 static void WINAPI
X11DRV_wglScissor(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
1971 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1975 ctx
->scissor
.left
= x
;
1976 ctx
->scissor
.top
= y
;
1977 ctx
->scissor
.right
= x
+ width
;
1978 ctx
->scissor
.bottom
= y
+ height
;
1980 sync_current_drawable(TRUE
);
1984 static void WINAPI
X11DRV_wglViewport(GLint x
, GLint y
, GLsizei width
, GLsizei height
)
1986 Wine_GLContext
*ctx
= (Wine_GLContext
*) NtCurrentTeb()->glContext
;
1990 ctx
->viewport
.left
= x
;
1991 ctx
->viewport
.top
= y
;
1992 ctx
->viewport
.right
= x
+ width
;
1993 ctx
->viewport
.bottom
= y
+ height
;
1995 sync_current_drawable(TRUE
);
2000 * X11DRV_wglGetExtensionsStringARB
2002 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2004 static const char * WINAPI
X11DRV_wglGetExtensionsStringARB(HDC hdc
) {
2005 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2006 return WineGLInfo
.wglExtensions
;
2010 * X11DRV_wglCreatePbufferARB
2012 * WGL_ARB_pbuffer: wglCreatePbufferARB
2014 static HPBUFFERARB WINAPI
X11DRV_wglCreatePbufferARB(HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
, const int *piAttribList
)
2016 Wine_GLPBuffer
* object
= NULL
;
2017 WineGLPixelFormat
*fmt
= NULL
;
2022 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2024 if (0 >= iPixelFormat
) {
2025 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc
, iPixelFormat
);
2026 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2027 return NULL
; /* unexpected error */
2030 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2031 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nCfgs
);
2033 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc
, iPixelFormat
, nCfgs
);
2034 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2035 goto create_failed
; /* unexpected error */
2038 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Wine_GLPBuffer
));
2039 if (NULL
== object
) {
2040 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2041 goto create_failed
; /* unexpected error */
2044 object
->display
= gdi_display
;
2045 object
->width
= iWidth
;
2046 object
->height
= iHeight
;
2049 nAttribs
= ConvertAttribWGLtoGLX(piAttribList
, attribs
, object
);
2050 if (-1 == nAttribs
) {
2051 WARN("Cannot convert WGL to GLX attributes\n");
2054 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2055 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2056 while (piAttribList
&& 0 != *piAttribList
) {
2058 switch (*piAttribList
) {
2059 case WGL_TEXTURE_FORMAT_ARB
: {
2061 attr_v
= *piAttribList
;
2062 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2063 if (use_render_texture_ati
) {
2066 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2067 case WGL_TEXTURE_RGB_ARB
: type
= GLX_TEXTURE_RGB_ATI
; break ;
2068 case WGL_TEXTURE_RGBA_ARB
: type
= GLX_TEXTURE_RGBA_ATI
; break ;
2070 SetLastError(ERROR_INVALID_DATA
);
2073 object
->use_render_texture
= 1;
2074 PUSH2(attribs
, GLX_TEXTURE_FORMAT_ATI
, type
);
2076 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2077 object
->use_render_texture
= 0;
2079 if (!use_render_texture_emulation
) {
2080 SetLastError(ERROR_INVALID_DATA
);
2084 case WGL_TEXTURE_RGB_ARB
:
2085 object
->use_render_texture
= GL_RGB
;
2086 object
->texture_bpp
= 3;
2087 object
->texture_format
= GL_RGB
;
2088 object
->texture_type
= GL_UNSIGNED_BYTE
;
2090 case WGL_TEXTURE_RGBA_ARB
:
2091 object
->use_render_texture
= GL_RGBA
;
2092 object
->texture_bpp
= 4;
2093 object
->texture_format
= GL_RGBA
;
2094 object
->texture_type
= GL_UNSIGNED_BYTE
;
2097 /* WGL_FLOAT_COMPONENTS_NV */
2098 case WGL_TEXTURE_FLOAT_R_NV
:
2099 object
->use_render_texture
= GL_FLOAT_R_NV
;
2100 object
->texture_bpp
= 4;
2101 object
->texture_format
= GL_RED
;
2102 object
->texture_type
= GL_FLOAT
;
2104 case WGL_TEXTURE_FLOAT_RG_NV
:
2105 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2106 object
->texture_bpp
= 8;
2107 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2108 object
->texture_type
= GL_FLOAT
;
2110 case WGL_TEXTURE_FLOAT_RGB_NV
:
2111 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2112 object
->texture_bpp
= 12;
2113 object
->texture_format
= GL_RGB
;
2114 object
->texture_type
= GL_FLOAT
;
2116 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2117 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2118 object
->texture_bpp
= 16;
2119 object
->texture_format
= GL_RGBA
;
2120 object
->texture_type
= GL_FLOAT
;
2123 ERR("Unknown texture format: %x\n", attr_v
);
2124 SetLastError(ERROR_INVALID_DATA
);
2132 case WGL_TEXTURE_TARGET_ARB
: {
2134 attr_v
= *piAttribList
;
2135 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2136 if (use_render_texture_ati
) {
2139 case WGL_NO_TEXTURE_ARB
: type
= GLX_NO_TEXTURE_ATI
; break ;
2140 case WGL_TEXTURE_CUBE_MAP_ARB
: type
= GLX_TEXTURE_CUBE_MAP_ATI
; break ;
2141 case WGL_TEXTURE_1D_ARB
: type
= GLX_TEXTURE_1D_ATI
; break ;
2142 case WGL_TEXTURE_2D_ARB
: type
= GLX_TEXTURE_2D_ATI
; break ;
2144 SetLastError(ERROR_INVALID_DATA
);
2147 PUSH2(attribs
, GLX_TEXTURE_TARGET_ATI
, type
);
2149 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2150 object
->texture_target
= 0;
2152 if (!use_render_texture_emulation
) {
2153 SetLastError(ERROR_INVALID_DATA
);
2157 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2158 if (iWidth
!= iHeight
) {
2159 SetLastError(ERROR_INVALID_DATA
);
2162 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2163 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2166 case WGL_TEXTURE_1D_ARB
: {
2168 SetLastError(ERROR_INVALID_DATA
);
2171 object
->texture_target
= GL_TEXTURE_1D
;
2172 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2175 case WGL_TEXTURE_2D_ARB
: {
2176 object
->texture_target
= GL_TEXTURE_2D
;
2177 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2180 case WGL_TEXTURE_RECTANGLE_NV
: {
2181 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2182 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2186 ERR("Unknown texture target: %x\n", attr_v
);
2187 SetLastError(ERROR_INVALID_DATA
);
2195 case WGL_MIPMAP_TEXTURE_ARB
: {
2197 attr_v
= *piAttribList
;
2198 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2199 if (use_render_texture_ati
) {
2200 PUSH2(attribs
, GLX_MIPMAP_TEXTURE_ATI
, attr_v
);
2202 if (!use_render_texture_emulation
) {
2203 SetLastError(ERROR_INVALID_DATA
);
2213 PUSH1(attribs
, None
);
2214 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2215 TRACE("new Pbuffer drawable as %p\n", (void*) object
->drawable
);
2216 if (!object
->drawable
) {
2217 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2218 goto create_failed
; /* unexpected error */
2220 TRACE("->(%p)\n", object
);
2221 return (HPBUFFERARB
) object
;
2224 HeapFree(GetProcessHeap(), 0, object
);
2225 TRACE("->(FAILED)\n");
2226 return (HPBUFFERARB
) NULL
;
2230 * X11DRV_wglDestroyPbufferARB
2232 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2234 static GLboolean WINAPI
X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
2236 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2237 TRACE("(%p)\n", hPbuffer
);
2238 if (NULL
== object
) {
2239 SetLastError(ERROR_INVALID_HANDLE
);
2242 pglXDestroyPbuffer(object
->display
, object
->drawable
);
2243 HeapFree(GetProcessHeap(), 0, object
);
2248 * X11DRV_wglGetPbufferDCARB
2250 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2251 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2252 * Gdi32 implements the part of this function which creates a device context.
2253 * This part associates the physDev with the X drawable of the pbuffer.
2255 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*physDev
, HPBUFFERARB hPbuffer
)
2257 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2258 if (NULL
== object
) {
2259 SetLastError(ERROR_INVALID_HANDLE
);
2263 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2264 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2265 physDev
->current_pf
= object
->fmt
->iPixelFormat
;
2266 physDev
->drawable
= object
->drawable
;
2267 SetRect( &physDev
->drawable_rect
, 0, 0, object
->width
, object
->height
);
2268 physDev
->dc_rect
= physDev
->drawable_rect
;
2270 TRACE("(%p)->(%p)\n", hPbuffer
, physDev
->hdc
);
2271 return physDev
->hdc
;
2275 * X11DRV_wglQueryPbufferARB
2277 * WGL_ARB_pbuffer: wglQueryPbufferARB
2279 static GLboolean WINAPI
X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer
, int iAttribute
, int *piValue
)
2281 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2282 TRACE("(%p, 0x%x, %p)\n", hPbuffer
, iAttribute
, piValue
);
2283 if (NULL
== object
) {
2284 SetLastError(ERROR_INVALID_HANDLE
);
2287 switch (iAttribute
) {
2288 case WGL_PBUFFER_WIDTH_ARB
:
2289 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2291 case WGL_PBUFFER_HEIGHT_ARB
:
2292 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2295 case WGL_PBUFFER_LOST_ARB
:
2296 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
2299 case WGL_TEXTURE_FORMAT_ARB
:
2300 if (use_render_texture_ati
) {
2302 int type
= WGL_NO_TEXTURE_ARB
;
2303 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_FORMAT_ATI
, &tmp
);
2305 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2306 case GLX_TEXTURE_RGB_ATI
: type
= WGL_TEXTURE_RGB_ARB
; break ;
2307 case GLX_TEXTURE_RGBA_ATI
: type
= WGL_TEXTURE_RGBA_ARB
; break ;
2311 if (!object
->use_render_texture
) {
2312 *piValue
= WGL_NO_TEXTURE_ARB
;
2314 if (!use_render_texture_emulation
) {
2315 SetLastError(ERROR_INVALID_HANDLE
);
2318 switch(object
->use_render_texture
) {
2320 *piValue
= WGL_TEXTURE_RGB_ARB
;
2323 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2325 /* WGL_FLOAT_COMPONENTS_NV */
2327 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2329 case GL_FLOAT_RG_NV
:
2330 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2332 case GL_FLOAT_RGB_NV
:
2333 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2335 case GL_FLOAT_RGBA_NV
:
2336 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2339 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2345 case WGL_TEXTURE_TARGET_ARB
:
2346 if (use_render_texture_ati
) {
2348 int type
= WGL_NO_TEXTURE_ARB
;
2349 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_TEXTURE_TARGET_ATI
, &tmp
);
2351 case GLX_NO_TEXTURE_ATI
: type
= WGL_NO_TEXTURE_ARB
; break ;
2352 case GLX_TEXTURE_CUBE_MAP_ATI
: type
= WGL_TEXTURE_CUBE_MAP_ARB
; break ;
2353 case GLX_TEXTURE_1D_ATI
: type
= WGL_TEXTURE_1D_ARB
; break ;
2354 case GLX_TEXTURE_2D_ATI
: type
= WGL_TEXTURE_2D_ARB
; break ;
2358 if (!object
->texture_target
) {
2359 *piValue
= WGL_NO_TEXTURE_ARB
;
2361 if (!use_render_texture_emulation
) {
2362 SetLastError(ERROR_INVALID_DATA
);
2365 switch (object
->texture_target
) {
2366 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2367 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2368 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2369 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2375 case WGL_MIPMAP_TEXTURE_ARB
:
2376 if (use_render_texture_ati
) {
2377 pglXQueryDrawable(object
->display
, object
->drawable
, GLX_MIPMAP_TEXTURE_ATI
, (unsigned int*) piValue
);
2379 *piValue
= GL_FALSE
; /** don't support that */
2380 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2385 FIXME("unexpected attribute %x\n", iAttribute
);
2393 * X11DRV_wglReleasePbufferDCARB
2395 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2397 static int WINAPI
X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
, HDC hdc
)
2399 TRACE("(%p, %p)\n", hPbuffer
, hdc
);
2405 * X11DRV_wglSetPbufferAttribARB
2407 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2409 static GLboolean WINAPI
X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer
, const int *piAttribList
)
2411 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2412 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer
, piAttribList
);
2413 if (NULL
== object
) {
2414 SetLastError(ERROR_INVALID_HANDLE
);
2417 if (!object
->use_render_texture
) {
2418 SetLastError(ERROR_INVALID_HANDLE
);
2421 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2424 if (NULL
!= pglXDrawableAttribARB
) {
2425 if (use_render_texture_ati
) {
2426 FIXME("Need conversion for GLX_ATI_render_texture\n");
2428 return pglXDrawableAttribARB(object
->display
, object
->drawable
, piAttribList
);
2434 * X11DRV_wglChoosePixelFormatARB
2436 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2438 static GLboolean WINAPI
X11DRV_wglChoosePixelFormatARB(HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
, UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2443 GLXFBConfig
* cfgs
= NULL
;
2448 GLXFBConfig
* cfgs_fmt
= NULL
;
2454 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2455 if (NULL
!= pfAttribFList
) {
2456 FIXME("unused pfAttribFList\n");
2459 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2460 if (-1 == nAttribs
) {
2461 WARN("Cannot convert WGL to GLX attributes\n");
2464 PUSH1(attribs
, None
);
2466 /* Search for FB configurations matching the requirements in attribs */
2467 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2469 WARN("Compatible Pixel Format not found\n");
2473 /* Get a list of all FB configurations */
2474 cfgs_fmt
= pglXGetFBConfigs(gdi_display
, DefaultScreen(gdi_display
), &nCfgs_fmt
);
2475 if (NULL
== cfgs_fmt
) {
2476 ERR("Failed to get All FB Configs\n");
2481 /* Loop through all matching formats and check if they are suitable.
2482 * Note that this function should at max return nMaxFormats different formats */
2483 for (it
= 0; pfmt_it
< nMaxFormats
&& it
< nCfgs
; ++it
) {
2484 gl_test
= pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
);
2486 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2490 /* Search for the format in our list of compatible formats */
2491 fmt
= ConvertPixelFormatGLXtoWGL(gdi_display
, fmt_id
);
2495 piFormats
[pfmt_it
] = fmt
;
2496 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d/%d)\n", it
+ 1, nCfgs
, fmt_id
, piFormats
[pfmt_it
], nCfgs_fmt
);
2500 *nNumFormats
= pfmt_it
;
2508 * X11DRV_wglGetPixelFormatAttribivARB
2510 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2512 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribivARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, int *piValues
)
2515 WineGLPixelFormat
*fmt
= NULL
;
2519 int nWGLFormats
= 0;
2521 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2523 if (0 < iLayerPlane
) {
2524 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2528 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2529 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2530 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2531 fmt
= ConvertPixelFormatWGLtoGLX(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */, &nWGLFormats
);
2533 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2536 for (i
= 0; i
< nAttributes
; ++i
) {
2537 const int curWGLAttr
= piAttributes
[i
];
2538 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2540 switch (curWGLAttr
) {
2541 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2542 piValues
[i
] = nWGLFormats
;
2545 case WGL_SUPPORT_OPENGL_ARB
:
2546 piValues
[i
] = GL_TRUE
;
2549 case WGL_ACCELERATION_ARB
:
2550 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2551 if (!fmt
) goto pix_error
;
2552 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2553 if (hTest
) goto get_error
;
2555 case GLX_NONE
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2556 case GLX_SLOW_CONFIG
: piValues
[i
] = WGL_NO_ACCELERATION_ARB
; break;
2557 case GLX_NON_CONFORMANT_CONFIG
: piValues
[i
] = WGL_FULL_ACCELERATION_ARB
; break;
2559 ERR("unexpected Config Caveat(%x)\n", tmp
);
2560 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2564 case WGL_TRANSPARENT_ARB
:
2565 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2566 if (!fmt
) goto pix_error
;
2567 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2568 if (hTest
) goto get_error
;
2569 piValues
[i
] = GL_FALSE
;
2570 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2573 case WGL_PIXEL_TYPE_ARB
:
2574 curGLXAttr
= GLX_RENDER_TYPE
;
2575 if (!fmt
) goto pix_error
;
2576 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2577 if (hTest
) goto get_error
;
2578 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2579 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2580 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2581 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2582 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2584 ERR("unexpected RenderType(%x)\n", tmp
);
2585 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2589 case WGL_COLOR_BITS_ARB
:
2590 /** see ConvertAttribWGLtoGLX for explain */
2591 if (!fmt
) goto pix_error
;
2592 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, piValues
+ i
);
2593 if (hTest
) goto get_error
;
2594 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues
[i
]);
2595 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &tmp
);
2596 if (hTest
) goto get_error
;
2597 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp
);
2598 piValues
[i
] = piValues
[i
] - tmp
;
2601 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2602 if (use_render_texture_ati
) {
2603 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGB_ATI
;
2606 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2607 if (use_render_texture_ati
) {
2608 curGLXAttr
= GLX_BIND_TO_TEXTURE_RGBA_ATI
;
2611 if (!use_render_texture_emulation
) {
2612 piValues
[i
] = GL_FALSE
;
2615 curGLXAttr
= GLX_RENDER_TYPE
;
2616 if (!fmt
) goto pix_error
;
2617 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2618 if (hTest
) goto get_error
;
2619 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2620 piValues
[i
] = GL_FALSE
;
2623 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2624 if (hTest
) goto get_error
;
2625 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2628 case WGL_BLUE_BITS_ARB
:
2629 curGLXAttr
= GLX_BLUE_SIZE
;
2631 case WGL_RED_BITS_ARB
:
2632 curGLXAttr
= GLX_RED_SIZE
;
2634 case WGL_GREEN_BITS_ARB
:
2635 curGLXAttr
= GLX_GREEN_SIZE
;
2637 case WGL_ALPHA_BITS_ARB
:
2638 curGLXAttr
= GLX_ALPHA_SIZE
;
2640 case WGL_DEPTH_BITS_ARB
:
2641 curGLXAttr
= GLX_DEPTH_SIZE
;
2643 case WGL_STENCIL_BITS_ARB
:
2644 curGLXAttr
= GLX_STENCIL_SIZE
;
2646 case WGL_DOUBLE_BUFFER_ARB
:
2647 curGLXAttr
= GLX_DOUBLEBUFFER
;
2649 case WGL_STEREO_ARB
:
2650 curGLXAttr
= GLX_STEREO
;
2652 case WGL_AUX_BUFFERS_ARB
:
2653 curGLXAttr
= GLX_AUX_BUFFERS
;
2655 case WGL_SUPPORT_GDI_ARB
:
2656 case WGL_DRAW_TO_WINDOW_ARB
:
2657 case WGL_DRAW_TO_BITMAP_ARB
:
2658 /* We only supported a limited number of formats right now which are all renderable by X 'GLX_X_RENDERABLE' */
2659 piValues
[i
] = GL_TRUE
;
2661 case WGL_DRAW_TO_PBUFFER_ARB
:
2662 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2663 if (hTest
) goto get_error
;
2664 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2667 case WGL_PBUFFER_LARGEST_ARB
:
2668 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2671 case WGL_SAMPLE_BUFFERS_ARB
:
2672 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2675 case WGL_SAMPLES_ARB
:
2676 curGLXAttr
= GLX_SAMPLES_ARB
;
2680 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2683 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2684 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2685 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2687 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2688 * and check which options can work using iPixelFormat=0 and which not.
2689 * A problem would be that this function is an extension. This would
2690 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2692 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2693 if (!fmt
) goto pix_error
;
2694 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2695 if (hTest
) goto get_error
;
2698 piValues
[i
] = GL_FALSE
;
2704 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2708 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nWGLFormats
);
2713 * X11DRV_wglGetPixelFormatAttribfvARB
2715 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2717 static GLboolean WINAPI
X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc
, int iPixelFormat
, int iLayerPlane
, UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2723 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2725 /* Allocate a temporary array to store integer values */
2726 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2728 ERR("couldn't allocate %d array\n", nAttributes
);
2732 /* Piggy-back on wglGetPixelFormatAttribivARB */
2733 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2735 /* Convert integer values to float. Should also check for attributes
2736 that can give decimal values here */
2737 for (i
=0; i
<nAttributes
;i
++) {
2738 pfValues
[i
] = attr
[i
];
2742 HeapFree(GetProcessHeap(), 0, attr
);
2747 * X11DRV_wglBindTexImageARB
2749 * WGL_ARB_render_texture: wglBindTexImageARB
2751 static GLboolean WINAPI
X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2753 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2754 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2755 if (NULL
== object
) {
2756 SetLastError(ERROR_INVALID_HANDLE
);
2759 if (!object
->use_render_texture
) {
2760 SetLastError(ERROR_INVALID_HANDLE
);
2764 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2765 static int init
= 0;
2766 int prev_binded_texture
= 0;
2767 GLXContext prev_context
= pglXGetCurrentContext();
2768 Drawable prev_drawable
= pglXGetCurrentDrawable();
2769 GLXContext tmp_context
;
2771 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2772 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2773 isn't ideal performance wise but I wasn't able to get other ways working.
2776 init
= 1; /* Only show the FIXME once for performance reasons */
2777 FIXME("partial stub!\n");
2780 TRACE("drawable=%p, context=%p\n", (void*)object
->drawable
, prev_context
);
2781 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2783 pglGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2785 /* Switch to our pbuffer */
2786 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2788 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2789 * After that upload the pbuffer texture data. */
2790 pglBindTexture(object
->texture_target
, prev_binded_texture
);
2791 pglCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2793 /* Switch back to the original drawable and upload the pbuffer-texture */
2794 pglXMakeCurrent(object
->display
, prev_drawable
, prev_context
);
2795 pglXDestroyContext(gdi_display
, tmp_context
);
2799 if (NULL
!= pglXBindTexImageARB
) {
2800 return pglXBindTexImageARB(object
->display
, object
->drawable
, iBuffer
);
2806 * X11DRV_wglReleaseTexImageARB
2808 * WGL_ARB_render_texture: wglReleaseTexImageARB
2810 static GLboolean WINAPI
X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer
, int iBuffer
)
2812 Wine_GLPBuffer
* object
= (Wine_GLPBuffer
*) hPbuffer
;
2813 TRACE("(%p, %d)\n", hPbuffer
, iBuffer
);
2814 if (NULL
== object
) {
2815 SetLastError(ERROR_INVALID_HANDLE
);
2818 if (!object
->use_render_texture
) {
2819 SetLastError(ERROR_INVALID_HANDLE
);
2822 if (!use_render_texture_ati
&& 1 == use_render_texture_emulation
) {
2825 if (NULL
!= pglXReleaseTexImageARB
) {
2826 return pglXReleaseTexImageARB(object
->display
, object
->drawable
, iBuffer
);
2832 * X11DRV_wglGetExtensionsStringEXT
2834 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2836 static const char * WINAPI
X11DRV_wglGetExtensionsStringEXT(void) {
2837 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2838 return WineGLInfo
.wglExtensions
;
2842 * X11DRV_wglGetSwapIntervalEXT
2844 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2846 static int WINAPI
X11DRV_wglGetSwapIntervalEXT(VOID
) {
2847 FIXME("(),stub!\n");
2848 return swap_interval
;
2852 * X11DRV_wglSwapIntervalEXT
2854 * WGL_EXT_swap_control: wglSwapIntervalEXT
2856 static BOOL WINAPI
X11DRV_wglSwapIntervalEXT(int interval
) {
2857 TRACE("(%d)\n", interval
);
2858 swap_interval
= interval
;
2859 if (NULL
!= pglXSwapIntervalSGI
) {
2860 return 0 == pglXSwapIntervalSGI(interval
);
2862 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2867 * X11DRV_wglAllocateMemoryNV
2869 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2871 static void* WINAPI
X11DRV_wglAllocateMemoryNV(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
) {
2872 TRACE("(%d, %f, %f, %f)\n", size
, readfreq
, writefreq
, priority
);
2873 if (pglXAllocateMemoryNV
== NULL
)
2876 return pglXAllocateMemoryNV(size
, readfreq
, writefreq
, priority
);
2880 * X11DRV_wglFreeMemoryNV
2882 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2884 static void WINAPI
X11DRV_wglFreeMemoryNV(GLvoid
* pointer
) {
2885 TRACE("(%p)\n", pointer
);
2886 if (pglXFreeMemoryNV
== NULL
)
2889 pglXFreeMemoryNV(pointer
);
2893 * glxRequireVersion (internal)
2895 * Check if the supported GLX version matches requiredVersion.
2897 static BOOL
glxRequireVersion(int requiredVersion
)
2899 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2900 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
2906 static BOOL
glxRequireExtension(const char *requiredExtension
)
2908 if (strstr(WineGLInfo
.glxClientExtensions
, requiredExtension
) == NULL
) {
2915 static void register_extension_string(const char *ext
)
2917 strcat(WineGLInfo
.wglExtensions
, " ");
2918 strcat(WineGLInfo
.wglExtensions
, ext
);
2920 TRACE("'%s'\n", ext
);
2923 static BOOL
register_extension(const WineGLExtension
* ext
)
2927 assert( WineGLExtensionListSize
< MAX_EXTENSIONS
);
2928 WineGLExtensionList
[WineGLExtensionListSize
++] = ext
;
2930 strcat(WineGLInfo
.wglExtensions
, " ");
2931 strcat(WineGLInfo
.wglExtensions
, ext
->extName
);
2933 TRACE("'%s'\n", ext
->extName
);
2935 for (i
= 0; ext
->extEntryPoints
[i
].funcName
; ++i
)
2936 TRACE(" - '%s'\n", ext
->extEntryPoints
[i
].funcName
);
2941 static const WineGLExtension WGL_internal_functions
=
2945 { "wglDisable", X11DRV_wglDisable
},
2946 { "wglEnable", X11DRV_wglEnable
},
2947 { "wglGetIntegerv", X11DRV_wglGetIntegerv
},
2948 { "wglIsEnabled", X11DRV_wglIsEnabled
},
2949 { "wglScissor", X11DRV_wglScissor
},
2950 { "wglViewport", X11DRV_wglViewport
},
2955 static const WineGLExtension WGL_ARB_extensions_string
=
2957 "WGL_ARB_extensions_string",
2959 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB
},
2963 static const WineGLExtension WGL_ARB_make_current_read
=
2965 "WGL_ARB_make_current_read",
2967 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB
},
2968 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB
},
2972 static const WineGLExtension WGL_ARB_multisample
=
2974 "WGL_ARB_multisample",
2977 static const WineGLExtension WGL_ARB_pbuffer
=
2981 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB
},
2982 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB
},
2983 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB
},
2984 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB
},
2985 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB
},
2986 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB
},
2990 static const WineGLExtension WGL_ARB_pixel_format
=
2992 "WGL_ARB_pixel_format",
2994 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB
},
2995 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB
},
2996 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB
},
3000 static const WineGLExtension WGL_ARB_render_texture
=
3002 "WGL_ARB_render_texture",
3004 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB
},
3005 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB
},
3009 static const WineGLExtension WGL_EXT_extensions_string
=
3011 "WGL_EXT_extensions_string",
3013 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT
},
3017 static const WineGLExtension WGL_EXT_swap_control
=
3019 "WGL_EXT_swap_control",
3021 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT
},
3022 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT
},
3026 static const WineGLExtension WGL_NV_vertex_array_range
=
3028 "WGL_NV_vertex_array_range",
3030 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV
},
3031 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV
},
3036 * X11DRV_WineGL_LoadExtensions
3038 static void X11DRV_WineGL_LoadExtensions(void)
3040 WineGLInfo
.wglExtensions
[0] = 0;
3042 /* Load Wine internal functions */
3043 register_extension(&WGL_internal_functions
);
3045 /* ARB Extensions */
3047 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3049 register_extension_string("WGL_ARB_pixel_format_float");
3050 register_extension_string("WGL_ATI_pixel_format_float");
3053 register_extension(&WGL_ARB_extensions_string
);
3055 if (glxRequireVersion(3))
3056 register_extension(&WGL_ARB_make_current_read
);
3058 if (glxRequireExtension("GLX_ARB_multisample"))
3059 register_extension(&WGL_ARB_multisample
);
3061 /* In general pbuffer functionality requires support in the X-server. The functionality is
3062 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3063 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3064 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3066 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3067 * without support in the X-server (which other Mesa based drivers require).
3069 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3070 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3071 * is available pbuffers must be available too. */
3072 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3073 register_extension(&WGL_ARB_pbuffer
);
3075 register_extension(&WGL_ARB_pixel_format
);
3077 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3078 if (glxRequireExtension("GLX_ATI_render_texture") ||
3079 glxRequireExtension("GLX_ARB_render_texture") ||
3080 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation
))
3082 register_extension(&WGL_ARB_render_texture
);
3084 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3085 if(glxRequireExtension("GLX_NV_float_buffer"))
3086 register_extension_string("WGL_NV_float_buffer");
3088 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3089 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle") != NULL
)
3090 register_extension_string("WGL_NV_texture_rectangle");
3093 /* EXT Extensions */
3095 register_extension(&WGL_EXT_extensions_string
);
3097 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3098 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3099 register_extension(&WGL_EXT_swap_control
);
3101 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3102 if(strstr(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range") != NULL
)
3103 register_extension(&WGL_NV_vertex_array_range
);
3107 static XID
create_glxpixmap(X11DRV_PDEVICE
*physDev
)
3111 XVisualInfo
template;
3116 /* Retrieve the visualid from our main visual which is the only visual we can use */
3117 template.visualid
= XVisualIDFromVisual(visual
);
3118 vis
= XGetVisualInfo(gdi_display
, VisualIDMask
, &template, &num
);
3120 ret
= pglXCreateGLXPixmap(gdi_display
, vis
, physDev
->bitmap
->pixmap
);
3122 wine_tsx11_unlock();
3123 TRACE("return %lx\n", ret
);
3127 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3133 if (physDev
->bitmap
->hbitmap
== BITMAP_stock_phys_bitmap
.hbitmap
)
3134 ret
= physDev
->drawable
; /* PBuffer */
3137 if(!physDev
->bitmap
->glxpixmap
)
3138 physDev
->bitmap
->glxpixmap
= create_glxpixmap(physDev
);
3139 ret
= physDev
->bitmap
->glxpixmap
;
3143 ret
= physDev
->drawable
;
3147 BOOL
destroy_glxpixmap(XID glxpixmap
)
3150 pglXDestroyGLXPixmap(gdi_display
, glxpixmap
);
3151 wine_tsx11_unlock();
3156 * X11DRV_SwapBuffers
3158 * Swap the buffers of this DC
3160 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
)
3162 GLXDrawable drawable
;
3163 if (!has_opengl()) {
3164 ERR("No libGL on this box - disabling OpenGL support !\n");
3168 TRACE_(opengl
)("(%p)\n", physDev
);
3170 drawable
= get_glxdrawable(physDev
);
3172 pglXSwapBuffers(gdi_display
, drawable
);
3173 wine_tsx11_unlock();
3178 static long prev_time
, frames
;
3180 DWORD time
= GetTickCount();
3182 /* every 1.5 seconds */
3183 if (time
- prev_time
> 1500) {
3184 TRACE_(fps
)("@ approx %.2ffps\n", 1000.0*frames
/(time
- prev_time
));
3193 /***********************************************************************
3194 * X11DRV_setup_opengl_visual
3196 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3197 * window (if it exists). If OpenGL isn't available, the visual is simply
3198 * set to the default visual for the display
3200 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3202 XVisualInfo
*visual
= NULL
;
3205 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3206 * D3D and some applications can make use of aux buffers.
3208 int visualProperties
[][11] = {
3209 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, GLX_AUX_BUFFERS
, 1, None
},
3210 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 24, GLX_STENCIL_SIZE
, 8, GLX_ALPHA_SIZE
, 8, None
},
3211 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, GLX_STENCIL_SIZE
, 8, None
},
3212 { GLX_RGBA
, GLX_DOUBLEBUFFER
, GLX_DEPTH_SIZE
, 16, None
},
3219 for (i
= 0; i
< sizeof(visualProperties
)/sizeof(visualProperties
[0]); ++i
) {
3220 visual
= pglXChooseVisual(display
, DefaultScreen(display
), visualProperties
[i
]);
3224 wine_tsx11_unlock();
3227 TRACE("Visual ID %lx Chosen\n", visual
->visualid
);
3229 WARN("No suitable visual found\n");
3234 #else /* no OpenGL includes */
3236 /***********************************************************************
3237 * ChoosePixelFormat (X11DRV.@)
3239 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE
*physDev
,
3240 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3241 ERR("No OpenGL support compiled in.\n");
3246 /***********************************************************************
3247 * DescribePixelFormat (X11DRV.@)
3249 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE
*physDev
,
3252 PIXELFORMATDESCRIPTOR
*ppfd
) {
3253 ERR("No OpenGL support compiled in.\n");
3258 /***********************************************************************
3259 * GetPixelFormat (X11DRV.@)
3261 int X11DRV_GetPixelFormat(X11DRV_PDEVICE
*physDev
) {
3262 ERR("No OpenGL support compiled in.\n");
3267 /***********************************************************************
3268 * SetPixelFormat (X11DRV.@)
3270 BOOL
X11DRV_SetPixelFormat(X11DRV_PDEVICE
*physDev
,
3272 const PIXELFORMATDESCRIPTOR
*ppfd
) {
3273 ERR("No OpenGL support compiled in.\n");
3278 /***********************************************************************
3279 * SwapBuffers (X11DRV.@)
3281 BOOL
X11DRV_SwapBuffers(X11DRV_PDEVICE
*physDev
) {
3282 ERR_(opengl
)("No OpenGL support compiled in.\n");
3288 * X11DRV_wglCreateContext
3290 * For OpenGL32 wglCreateContext.
3292 HGLRC
X11DRV_wglCreateContext(X11DRV_PDEVICE
*physDev
) {
3293 ERR_(opengl
)("No OpenGL support compiled in.\n");
3298 * X11DRV_wglDeleteContext
3300 * For OpenGL32 wglDeleteContext.
3302 BOOL
X11DRV_wglDeleteContext(HGLRC hglrc
) {
3303 ERR_(opengl
)("No OpenGL support compiled in.\n");
3308 * X11DRV_wglGetProcAddress
3310 * For OpenGL32 wglGetProcAddress.
3312 PROC
X11DRV_wglGetProcAddress(LPCSTR lpszProc
) {
3313 ERR_(opengl
)("No OpenGL support compiled in.\n");
3317 HDC
X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE
*hDevice
, void *hPbuffer
)
3319 ERR_(opengl
)("No OpenGL support compiled in.\n");
3323 BOOL
X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE
* hDrawDev
, X11DRV_PDEVICE
* hReadDev
, HGLRC hglrc
) {
3324 ERR_(opengl
)("No OpenGL support compiled in.\n");
3329 * X11DRV_wglMakeCurrent
3331 * For OpenGL32 wglMakeCurrent.
3333 BOOL
X11DRV_wglMakeCurrent(X11DRV_PDEVICE
*physDev
, HGLRC hglrc
) {
3334 ERR_(opengl
)("No OpenGL support compiled in.\n");
3339 * X11DRV_wglShareLists
3341 * For OpenGL32 wglShaderLists.
3343 BOOL
X11DRV_wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
) {
3344 ERR_(opengl
)("No OpenGL support compiled in.\n");
3349 * X11DRV_wglUseFontBitmapsA
3351 * For OpenGL32 wglUseFontBitmapsA.
3353 BOOL
X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3355 ERR_(opengl
)("No OpenGL support compiled in.\n");
3360 * X11DRV_wglUseFontBitmapsW
3362 * For OpenGL32 wglUseFontBitmapsW.
3364 BOOL
X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE
*physDev
, DWORD first
, DWORD count
, DWORD listBase
)
3366 ERR_(opengl
)("No OpenGL support compiled in.\n");
3370 XVisualInfo
*X11DRV_setup_opengl_visual( Display
*display
)
3375 Drawable
get_glxdrawable(X11DRV_PDEVICE
*physDev
)
3380 BOOL
destroy_glxpixmap(XID glxpixmap
)
3385 #endif /* defined(HAVE_OPENGL) */