opengl32: Add the concept of a WGL driver.
[wine/multimedia.git] / dlls / winex11.drv / opengl.c
blob4c1ce9c7d69f5ceffb439e95fc619e7c8ca941d8
1 /*
2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
9 * Copyright 2012 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
35 #endif
36 #ifdef HAVE_SYS_UN_H
37 #include <sys/un.h>
38 #endif
40 #include "x11drv.h"
41 #include "winternl.h"
42 #include "wine/library.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
47 #ifdef SONAME_LIBGL
49 WINE_DECLARE_DEBUG_CHANNEL(winediag);
51 #undef APIENTRY
52 #undef CALLBACK
53 #undef WINAPI
55 #ifdef HAVE_GL_GL_H
56 # include <GL/gl.h>
57 #endif
58 #ifdef HAVE_GL_GLX_H
59 # include <GL/glx.h>
60 #endif
62 #include "wine/wgl.h"
64 #undef APIENTRY
65 #undef CALLBACK
66 #undef WINAPI
68 /* Redefines the constants */
69 #define CALLBACK __stdcall
70 #define WINAPI __stdcall
71 #define APIENTRY WINAPI
74 WINE_DECLARE_DEBUG_CHANNEL(fps);
76 typedef struct wine_glextension {
77 const char *extName;
78 struct {
79 const char *funcName;
80 void *funcAddress;
81 } extEntryPoints[9];
82 } WineGLExtension;
84 struct WineGLInfo {
85 const char *glVersion;
86 char *glExtensions;
88 int glxVersion[2];
90 const char *glxServerVersion;
91 const char *glxServerVendor;
92 const char *glxServerExtensions;
94 const char *glxClientVersion;
95 const char *glxClientVendor;
96 const char *glxClientExtensions;
98 const char *glxExtensions;
100 BOOL glxDirect;
101 char wglExtensions[4096];
104 typedef struct wine_glpixelformat {
105 int iPixelFormat;
106 GLXFBConfig fbconfig;
107 int fmt_id;
108 int render_type;
109 BOOL offscreenOnly;
110 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
111 } WineGLPixelFormat;
113 typedef struct wine_glcontext {
114 HDC hdc;
115 BOOL has_been_current;
116 BOOL sharing;
117 DWORD tid;
118 BOOL gl3_context;
119 XVisualInfo *vis;
120 WineGLPixelFormat *fmt;
121 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
122 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
123 GLXContext ctx;
124 HDC read_hdc;
125 Drawable drawables[2];
126 BOOL refresh_drawables;
127 Pixmap pixmap; /* pixmap for memory DCs */
128 GLXPixmap glxpixmap; /* GLX pixmap for memory DCs */
129 SIZE pixmap_size; /* pixmap size for memory DCs */
130 struct list entry;
131 } Wine_GLContext;
133 typedef struct wine_glpbuffer {
134 Drawable drawable;
135 Display* display;
136 WineGLPixelFormat* fmt;
137 int width;
138 int height;
139 int* attribList;
140 HDC hdc;
142 int use_render_texture; /* This is also the internal texture format */
143 int texture_bind_target;
144 int texture_bpp;
145 GLint texture_format;
146 GLuint texture_target;
147 GLenum texture_type;
148 GLuint texture;
149 int texture_level;
150 } Wine_GLPBuffer;
152 struct glx_physdev
154 struct gdi_physdev dev;
155 X11DRV_PDEVICE *x11dev;
156 enum dc_gl_type type; /* type of GL device context */
157 int pixel_format;
158 Drawable drawable;
159 Pixmap pixmap; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
162 static const struct wgl_funcs glxdrv_wgl_funcs;
163 static const struct gdi_dc_funcs glxdrv_funcs;
165 static inline struct glx_physdev *get_glxdrv_dev( PHYSDEV dev )
167 return (struct glx_physdev *)dev;
170 static struct list context_list = LIST_INIT( context_list );
171 static struct WineGLInfo WineGLInfo = { 0 };
172 static int use_render_texture_emulation = 1;
173 static BOOL has_swap_control;
174 static int swap_interval = 1;
176 #define MAX_EXTENSIONS 16
177 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
178 static int WineGLExtensionListSize;
180 static void X11DRV_WineGL_LoadExtensions(void);
181 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count);
182 static BOOL glxRequireVersion(int requiredVersion);
183 static BOOL glxRequireExtension(const char *requiredExtension);
185 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
186 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
187 TRACE(" - dwFlags : ");
188 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
189 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
190 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
191 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
192 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
193 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
194 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
195 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
196 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
197 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
198 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
199 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
200 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
201 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
202 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
203 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
204 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
205 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
206 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
207 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
208 #undef TEST_AND_DUMP
209 TRACE("\n");
211 TRACE(" - iPixelType : ");
212 switch (ppfd->iPixelType) {
213 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
214 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
216 TRACE("\n");
218 TRACE(" - Color : %d\n", ppfd->cColorBits);
219 TRACE(" - Red : %d\n", ppfd->cRedBits);
220 TRACE(" - Green : %d\n", ppfd->cGreenBits);
221 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
222 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
223 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
224 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
225 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
226 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
228 TRACE(" - iLayerType : ");
229 switch (ppfd->iLayerType) {
230 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
231 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
232 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
234 TRACE("\n");
237 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
238 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
240 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
241 /* GLX 1.0 */
242 MAKE_FUNCPTR(glXChooseVisual)
243 MAKE_FUNCPTR(glXCopyContext)
244 MAKE_FUNCPTR(glXCreateContext)
245 MAKE_FUNCPTR(glXCreateGLXPixmap)
246 MAKE_FUNCPTR(glXGetCurrentContext)
247 MAKE_FUNCPTR(glXGetCurrentDrawable)
248 MAKE_FUNCPTR(glXDestroyContext)
249 MAKE_FUNCPTR(glXDestroyGLXPixmap)
250 MAKE_FUNCPTR(glXGetConfig)
251 MAKE_FUNCPTR(glXIsDirect)
252 MAKE_FUNCPTR(glXMakeCurrent)
253 MAKE_FUNCPTR(glXSwapBuffers)
254 MAKE_FUNCPTR(glXQueryExtension)
255 MAKE_FUNCPTR(glXQueryVersion)
257 /* GLX 1.1 */
258 MAKE_FUNCPTR(glXGetClientString)
259 MAKE_FUNCPTR(glXQueryExtensionsString)
260 MAKE_FUNCPTR(glXQueryServerString)
262 /* GLX 1.3 */
263 MAKE_FUNCPTR(glXGetFBConfigs)
264 MAKE_FUNCPTR(glXChooseFBConfig)
265 MAKE_FUNCPTR(glXCreatePbuffer)
266 MAKE_FUNCPTR(glXCreateNewContext)
267 MAKE_FUNCPTR(glXDestroyPbuffer)
268 MAKE_FUNCPTR(glXGetFBConfigAttrib)
269 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
270 MAKE_FUNCPTR(glXMakeContextCurrent)
271 MAKE_FUNCPTR(glXQueryDrawable)
272 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
274 /* GLX Extensions */
275 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
276 static void* (*pglXGetProcAddressARB)(const GLubyte *);
277 static int (*pglXSwapIntervalSGI)(int);
279 /* NV GLX Extension */
280 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
281 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
283 /* MESA GLX Extensions */
284 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
286 /* Standard OpenGL */
287 MAKE_FUNCPTR(glBindTexture)
288 MAKE_FUNCPTR(glBitmap)
289 MAKE_FUNCPTR(glCopyTexSubImage1D)
290 MAKE_FUNCPTR(glCopyTexImage2D)
291 MAKE_FUNCPTR(glCopyTexSubImage2D)
292 MAKE_FUNCPTR(glDrawBuffer)
293 MAKE_FUNCPTR(glEndList)
294 MAKE_FUNCPTR(glGetError)
295 MAKE_FUNCPTR(glGetIntegerv)
296 MAKE_FUNCPTR(glGetString)
297 MAKE_FUNCPTR(glNewList)
298 MAKE_FUNCPTR(glPixelStorei)
299 MAKE_FUNCPTR(glReadPixels)
300 MAKE_FUNCPTR(glTexImage2D)
301 MAKE_FUNCPTR(glFinish)
302 MAKE_FUNCPTR(glFlush)
303 #undef MAKE_FUNCPTR
305 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
307 /* In the future we might want to find the exact X or GLX error to report back to the app */
308 return 1;
311 static BOOL infoInitialized = FALSE;
312 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
314 int screen = DefaultScreen(gdi_display);
315 Window win = 0, root = 0;
316 const char *gl_renderer;
317 const char* str;
318 XVisualInfo *vis;
319 GLXContext ctx = NULL;
320 XSetWindowAttributes attr;
321 BOOL ret = FALSE;
322 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
324 if (infoInitialized)
325 return TRUE;
326 infoInitialized = TRUE;
328 attr.override_redirect = True;
329 attr.colormap = None;
330 attr.border_pixel = 0;
332 wine_tsx11_lock();
334 vis = pglXChooseVisual(gdi_display, screen, attribList);
335 if (vis) {
336 #ifdef __i386__
337 WORD old_fs = wine_get_fs();
338 /* Create a GLX Context. Without one we can't query GL information */
339 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
340 if (wine_get_fs() != old_fs)
342 wine_set_fs( old_fs );
343 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
344 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
345 goto done;
347 #else
348 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
349 #endif
351 if (!ctx) goto done;
353 root = RootWindow( gdi_display, vis->screen );
354 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
355 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
356 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
357 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
358 XMapWindow( gdi_display, win );
359 else
360 win = root;
362 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
364 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
365 goto done;
367 gl_renderer = (const char *)pglGetString(GL_RENDERER);
368 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
369 str = (const char *) pglGetString(GL_EXTENSIONS);
370 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
371 strcpy(WineGLInfo.glExtensions, str);
373 /* Get the common GLX version supported by GLX client and server ( major/minor) */
374 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
376 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
377 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
378 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
380 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
381 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
382 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
384 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
385 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
387 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
388 TRACE("GL renderer : %s.\n", gl_renderer);
389 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
390 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
391 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
392 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
393 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
394 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
396 if(!WineGLInfo.glxDirect)
398 int fd = ConnectionNumber(gdi_display);
399 struct sockaddr_un uaddr;
400 unsigned int uaddrlen = sizeof(struct sockaddr_un);
402 /* In general indirect rendering on a local X11 server indicates a driver problem.
403 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
405 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
406 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
407 "haven't been installed correctly (using GL renderer %s, version %s).\n",
408 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
410 else
412 /* In general you would expect that if direct rendering is returned, that you receive hardware
413 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
414 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
415 * software rendering, it shows direct rendering.
417 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
418 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
419 * it shows 'Mesa X11'.
421 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
422 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
423 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
424 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
426 ret = TRUE;
428 done:
429 if(vis) XFree(vis);
430 if(ctx) {
431 pglXMakeCurrent(gdi_display, None, NULL);
432 pglXDestroyContext(gdi_display, ctx);
434 if (win != root) XDestroyWindow( gdi_display, win );
435 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
436 wine_tsx11_unlock();
437 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
438 return ret;
441 static BOOL has_opengl(void)
443 static int init_done;
444 static void *opengl_handle;
446 char buffer[200];
447 int error_base, event_base;
449 if (init_done) return (opengl_handle != NULL);
450 init_done = 1;
452 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
453 and include all dependencies */
454 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
455 if (opengl_handle == NULL)
457 ERR( "Failed to load libGL: %s\n", buffer );
458 ERR( "OpenGL support is disabled.\n");
459 return FALSE;
462 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
463 if (pglXGetProcAddressARB == NULL) {
464 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
465 goto failed;
468 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
470 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
471 goto failed; \
472 } while(0)
474 /* GLX 1.0 */
475 LOAD_FUNCPTR(glXChooseVisual);
476 LOAD_FUNCPTR(glXCopyContext);
477 LOAD_FUNCPTR(glXCreateContext);
478 LOAD_FUNCPTR(glXCreateGLXPixmap);
479 LOAD_FUNCPTR(glXGetCurrentContext);
480 LOAD_FUNCPTR(glXGetCurrentDrawable);
481 LOAD_FUNCPTR(glXDestroyContext);
482 LOAD_FUNCPTR(glXDestroyGLXPixmap);
483 LOAD_FUNCPTR(glXGetConfig);
484 LOAD_FUNCPTR(glXIsDirect);
485 LOAD_FUNCPTR(glXMakeCurrent);
486 LOAD_FUNCPTR(glXSwapBuffers);
487 LOAD_FUNCPTR(glXQueryExtension);
488 LOAD_FUNCPTR(glXQueryVersion);
490 /* GLX 1.1 */
491 LOAD_FUNCPTR(glXGetClientString);
492 LOAD_FUNCPTR(glXQueryExtensionsString);
493 LOAD_FUNCPTR(glXQueryServerString);
495 /* GLX 1.3 */
496 LOAD_FUNCPTR(glXCreatePbuffer);
497 LOAD_FUNCPTR(glXCreateNewContext);
498 LOAD_FUNCPTR(glXDestroyPbuffer);
499 LOAD_FUNCPTR(glXMakeContextCurrent);
500 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
501 LOAD_FUNCPTR(glXGetFBConfigs);
503 /* Standard OpenGL calls */
504 LOAD_FUNCPTR(glBindTexture);
505 LOAD_FUNCPTR(glBitmap);
506 LOAD_FUNCPTR(glCopyTexSubImage1D);
507 LOAD_FUNCPTR(glCopyTexImage2D);
508 LOAD_FUNCPTR(glCopyTexSubImage2D);
509 LOAD_FUNCPTR(glDrawBuffer);
510 LOAD_FUNCPTR(glEndList);
511 LOAD_FUNCPTR(glGetError);
512 LOAD_FUNCPTR(glGetIntegerv);
513 LOAD_FUNCPTR(glGetString);
514 LOAD_FUNCPTR(glNewList);
515 LOAD_FUNCPTR(glPixelStorei);
516 LOAD_FUNCPTR(glReadPixels);
517 LOAD_FUNCPTR(glTexImage2D);
518 LOAD_FUNCPTR(glFinish);
519 LOAD_FUNCPTR(glFlush);
520 #undef LOAD_FUNCPTR
522 /* It doesn't matter if these fail. They'll only be used if the driver reports
523 the associated extension is available (and if a driver reports the extension
524 is available but fails to provide the functions, it's quite broken) */
525 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
526 /* ARB GLX Extension */
527 LOAD_FUNCPTR(glXCreateContextAttribsARB);
528 /* SGI GLX Extension */
529 LOAD_FUNCPTR(glXSwapIntervalSGI);
530 /* NV GLX Extension */
531 LOAD_FUNCPTR(glXAllocateMemoryNV);
532 LOAD_FUNCPTR(glXFreeMemoryNV);
533 #undef LOAD_FUNCPTR
535 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
537 wine_tsx11_lock();
538 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
539 TRACE("GLX is up and running error_base = %d\n", error_base);
540 } else {
541 wine_tsx11_unlock();
542 ERR( "GLX extension is missing, disabling OpenGL.\n" );
543 goto failed;
546 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
547 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
548 * rendering is used.
550 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
551 * depends on the reported GLX client / server version and on the client / server extension list.
552 * Those don't have to be the same.
554 * In general the server GLX information lists the capabilities in case of indirect rendering.
555 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
556 * available and in that case the client GLX informat can be used.
557 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
558 * in the GLX version/extension list. When a program does this it works for certain for both
559 * direct and indirect rendering.
561 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
562 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
563 * extension list which causes this extension not to be listed. (Wine requires this extension).
564 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
565 * pbuffers is around.
567 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
568 * the ATI drivers and from then on use GLX client information for them.
571 if(glxRequireVersion(3)) {
572 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
573 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
574 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
575 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
576 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
577 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
578 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
579 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
581 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
582 * enable this function when the Xserver understand GLX 1.3 or newer
584 pglXQueryDrawable = NULL;
585 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
586 TRACE("Overriding ATI GLX capabilities!\n");
587 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
588 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
589 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
590 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
592 /* Use client GLX information in case of the ATI drivers. We override the
593 * capabilities over here and not somewhere else as ATI might better their
594 * life in the future. In case they release proper drivers this block of
595 * code won't be called. */
596 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
597 } else {
598 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
601 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
602 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
605 X11DRV_WineGL_LoadExtensions();
607 wine_tsx11_unlock();
608 return TRUE;
610 failed:
611 wine_dlclose(opengl_handle, NULL, 0);
612 opengl_handle = NULL;
613 return FALSE;
616 static inline BOOL is_valid_context( Wine_GLContext *ctx )
618 Wine_GLContext *ptr;
619 LIST_FOR_EACH_ENTRY( ptr, &context_list, struct wine_glcontext, entry )
620 if (ptr == ctx) return TRUE;
621 return FALSE;
624 static int describeContext(Wine_GLContext* ctx) {
625 int tmp;
626 int ctx_vis_id;
627 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
628 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
629 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
630 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
631 TRACE(" - VISUAL_ID 0x%x\n", tmp);
632 ctx_vis_id = tmp;
633 return ctx_vis_id;
636 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
637 int nAttribs = 0;
638 unsigned cur = 0;
639 int pop;
640 int drawattrib = 0;
641 int nvfloatattrib = GLX_DONT_CARE;
642 int pixelattrib = GLX_DONT_CARE;
644 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
645 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
646 while (iWGLAttr && 0 != iWGLAttr[cur]) {
647 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
649 switch (iWGLAttr[cur]) {
650 case WGL_AUX_BUFFERS_ARB:
651 pop = iWGLAttr[++cur];
652 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
653 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
654 break;
655 case WGL_COLOR_BITS_ARB:
656 pop = iWGLAttr[++cur];
657 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
658 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
659 break;
660 case WGL_BLUE_BITS_ARB:
661 pop = iWGLAttr[++cur];
662 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
663 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
664 break;
665 case WGL_RED_BITS_ARB:
666 pop = iWGLAttr[++cur];
667 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
668 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
669 break;
670 case WGL_GREEN_BITS_ARB:
671 pop = iWGLAttr[++cur];
672 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
673 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
674 break;
675 case WGL_ALPHA_BITS_ARB:
676 pop = iWGLAttr[++cur];
677 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
678 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
679 break;
680 case WGL_DEPTH_BITS_ARB:
681 pop = iWGLAttr[++cur];
682 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
683 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
684 break;
685 case WGL_STENCIL_BITS_ARB:
686 pop = iWGLAttr[++cur];
687 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
688 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
689 break;
690 case WGL_DOUBLE_BUFFER_ARB:
691 pop = iWGLAttr[++cur];
692 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
693 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
694 break;
695 case WGL_STEREO_ARB:
696 pop = iWGLAttr[++cur];
697 PUSH2(oGLXAttr, GLX_STEREO, pop);
698 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
699 break;
701 case WGL_PIXEL_TYPE_ARB:
702 pop = iWGLAttr[++cur];
703 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
704 switch (pop) {
705 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
706 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
707 /* 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 */
708 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
709 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
710 default:
711 ERR("unexpected PixelType(%x)\n", pop);
712 pop = 0;
714 break;
716 case WGL_SUPPORT_GDI_ARB:
717 /* This flag is set in a WineGLPixelFormat */
718 pop = iWGLAttr[++cur];
719 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
720 break;
722 case WGL_DRAW_TO_BITMAP_ARB:
723 /* This flag is set in a WineGLPixelFormat */
724 pop = iWGLAttr[++cur];
725 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
726 break;
728 case WGL_DRAW_TO_WINDOW_ARB:
729 pop = iWGLAttr[++cur];
730 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
731 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
732 if (pop) {
733 drawattrib |= GLX_WINDOW_BIT;
735 break;
737 case WGL_DRAW_TO_PBUFFER_ARB:
738 pop = iWGLAttr[++cur];
739 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
740 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
741 if (pop) {
742 drawattrib |= GLX_PBUFFER_BIT;
744 break;
746 case WGL_ACCELERATION_ARB:
747 /* This flag is set in a WineGLPixelFormat */
748 pop = iWGLAttr[++cur];
749 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
750 break;
752 case WGL_SUPPORT_OPENGL_ARB:
753 pop = iWGLAttr[++cur];
754 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
755 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
756 break;
758 case WGL_SWAP_METHOD_ARB:
759 pop = iWGLAttr[++cur];
760 /* For now we ignore this and just return SWAP_EXCHANGE */
761 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
762 break;
764 case WGL_PBUFFER_LARGEST_ARB:
765 pop = iWGLAttr[++cur];
766 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
767 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
768 break;
770 case WGL_SAMPLE_BUFFERS_ARB:
771 pop = iWGLAttr[++cur];
772 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
773 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
774 break;
776 case WGL_SAMPLES_ARB:
777 pop = iWGLAttr[++cur];
778 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
779 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
780 break;
782 case WGL_TEXTURE_FORMAT_ARB:
783 case WGL_TEXTURE_TARGET_ARB:
784 case WGL_MIPMAP_TEXTURE_ARB:
785 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
786 pop = iWGLAttr[++cur];
787 if (NULL == pbuf) {
788 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
790 if (!use_render_texture_emulation) {
791 if (WGL_NO_TEXTURE_ARB != pop) {
792 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
793 return -1; /** error: don't support it */
794 } else {
795 drawattrib |= GLX_PBUFFER_BIT;
798 break ;
799 case WGL_FLOAT_COMPONENTS_NV:
800 nvfloatattrib = iWGLAttr[++cur];
801 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
802 break ;
803 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
804 case WGL_BIND_TO_TEXTURE_RGB_ARB:
805 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
806 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
807 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
808 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
809 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
810 pop = iWGLAttr[++cur];
811 /** cannot be converted, see direct handling on
812 * - wglGetPixelFormatAttribivARB
813 * TODO: wglChoosePixelFormat
815 break ;
816 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
817 pop = iWGLAttr[++cur];
818 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
819 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
820 break ;
822 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
823 pop = iWGLAttr[++cur];
824 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
825 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
826 break ;
827 default:
828 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
829 break;
831 ++cur;
834 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
835 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
836 * pixmap and pbuffer formats appear as well. */
837 if (!drawattrib) drawattrib = GLX_DONT_CARE;
838 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
839 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
841 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
842 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
843 * GLX_DONT_CARE unless it is overridden. */
844 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
845 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
847 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
848 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
849 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
850 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
853 return nAttribs;
856 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
858 int render_type=0, render_type_bit;
859 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
860 switch(render_type_bit)
862 case GLX_RGBA_BIT:
863 render_type = GLX_RGBA_TYPE;
864 break;
865 case GLX_COLOR_INDEX_BIT:
866 render_type = GLX_COLOR_INDEX_TYPE;
867 break;
868 case GLX_RGBA_FLOAT_BIT:
869 render_type = GLX_RGBA_FLOAT_TYPE;
870 break;
871 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
872 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
873 break;
874 default:
875 ERR("Unknown render_type: %x\n", render_type_bit);
877 return render_type;
880 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
881 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
883 int dbuf, value;
884 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
885 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
887 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
888 * the GLX_PIXMAP_BIT set. */
889 return !dbuf && (value & GLX_PIXMAP_BIT);
892 static WineGLPixelFormat *get_formats(Display *display, int *size_ret, int *onscreen_size_ret)
894 static WineGLPixelFormat *list;
895 static int size, onscreen_size;
897 int fmt_id, nCfgs, i, run, bmp_formats;
898 GLXFBConfig* cfgs;
899 XVisualInfo *visinfo;
901 wine_tsx11_lock();
902 if (list) goto done;
904 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
905 if (NULL == cfgs || 0 == nCfgs) {
906 if(cfgs != NULL) XFree(cfgs);
907 wine_tsx11_unlock();
908 ERR("glXChooseFBConfig returns NULL\n");
909 return NULL;
912 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
913 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
914 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
915 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
917 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
919 for(i=0, bmp_formats=0; i<nCfgs; i++)
921 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
922 bmp_formats++;
924 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
926 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats)*sizeof(WineGLPixelFormat));
928 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
929 * Do this as GLX doesn't guarantee that the list is sorted */
930 for(run=0; run < 2; run++)
932 for(i=0; i<nCfgs; i++) {
933 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
934 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
936 /* The first run we only add onscreen formats (ones which have an associated X Visual).
937 * The second run we only set offscreen formats. */
938 if(!run && visinfo)
940 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
941 * The contents is copied to the destination using XCopyArea. For the copying to work
942 * the depth of the source and destination window should be the same. In general this should
943 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
944 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
945 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
946 * list formats with the same depth. */
947 if(visinfo->depth != screen_depth)
949 XFree(visinfo);
950 continue;
953 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
954 list[size].iPixelFormat = size+1; /* The index starts at 1 */
955 list[size].fbconfig = cfgs[i];
956 list[size].fmt_id = fmt_id;
957 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
958 list[size].offscreenOnly = FALSE;
959 list[size].dwFlags = 0;
960 size++;
961 onscreen_size++;
963 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
964 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
966 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
967 list[size].iPixelFormat = size+1; /* The index starts at 1 */
968 list[size].fbconfig = cfgs[i];
969 list[size].fmt_id = fmt_id;
970 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
971 list[size].offscreenOnly = FALSE;
972 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
973 size++;
974 onscreen_size++;
976 } else if(run && !visinfo) {
977 int window_drawable=0;
978 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
980 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
981 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
982 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
983 * likely make our child window opengl rendering more complicated since likely you can't use
984 * XCopyArea on a GLX Window.
985 * For now ignore fbconfigs which are window drawable but lack a visual. */
986 if(window_drawable & GLX_WINDOW_BIT)
988 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
989 continue;
992 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
993 list[size].iPixelFormat = size+1; /* The index starts at 1 */
994 list[size].fbconfig = cfgs[i];
995 list[size].fmt_id = fmt_id;
996 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
997 list[size].offscreenOnly = TRUE;
998 list[size].dwFlags = 0;
999 size++;
1002 if (visinfo) XFree(visinfo);
1006 XFree(cfgs);
1008 done:
1009 if (size_ret) *size_ret = size;
1010 if (onscreen_size_ret) *onscreen_size_ret = onscreen_size;
1011 wine_tsx11_unlock();
1012 return list;
1015 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1016 * In our WGL implementation we only support a subset of these formats namely the format of
1017 * Wine's main visual and offscreen formats (if they are available).
1018 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1019 * and it returns the number of supported WGL formats in fmt_count.
1021 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
1023 WineGLPixelFormat *list, *res = NULL;
1024 int size, onscreen_size;
1026 if (!(list = get_formats(display, &size, &onscreen_size ))) return NULL;
1028 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1029 * iPixelFormat in case of probing the number of pixelformats.
1031 if((iPixelFormat > 0) && (iPixelFormat <= size) &&
1032 (!list[iPixelFormat-1].offscreenOnly || AllowOffscreen)) {
1033 res = &list[iPixelFormat-1];
1034 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res->fmt_id, iPixelFormat);
1037 if(AllowOffscreen)
1038 *fmt_count = size;
1039 else
1040 *fmt_count = onscreen_size;
1042 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
1044 return res;
1047 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1048 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id, DWORD dwFlags)
1050 WineGLPixelFormat *list;
1051 int i, size;
1053 if (!(list = get_formats(display, &size, NULL ))) return NULL;
1055 for(i=0; i<size; i++) {
1056 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1057 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1058 if( (list[i].fmt_id == fmt_id) && ((list[i].dwFlags & dwFlags) == dwFlags) ) {
1059 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list[i].iPixelFormat, fmt_id);
1060 return &list[i];
1063 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
1064 return NULL;
1067 static int pixelformat_from_fbconfig_id(XID fbconfig_id)
1069 WineGLPixelFormat *fmt;
1071 if (!fbconfig_id) return 0;
1073 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
1074 if(fmt)
1075 return fmt->iPixelFormat;
1076 /* This will happen on hwnds without a pixel format set; it's ok */
1077 return 0;
1081 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1082 void mark_drawable_dirty(Drawable old, Drawable new)
1084 Wine_GLContext *ctx;
1085 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wine_glcontext, entry )
1087 if (old == ctx->drawables[0]) {
1088 ctx->drawables[0] = new;
1089 ctx->refresh_drawables = TRUE;
1091 if (old == ctx->drawables[1]) {
1092 ctx->drawables[1] = new;
1093 ctx->refresh_drawables = TRUE;
1098 /* Given the current context, make sure its drawable is sync'd */
1099 static inline void sync_context(Wine_GLContext *context)
1101 if(context && context->refresh_drawables) {
1102 if (glxRequireVersion(3))
1103 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1104 context->drawables[1], context->ctx);
1105 else
1106 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1107 context->refresh_drawables = FALSE;
1112 static GLXContext create_glxcontext(Display *display, Wine_GLContext *context, GLXContext shareList)
1114 GLXContext ctx;
1116 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1117 BOOL indirect = (context->fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? FALSE : TRUE;
1119 if(context->gl3_context)
1121 if(context->numAttribs)
1122 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1123 else
1124 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1126 else if(context->vis)
1127 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1128 else /* Create a GLX Context for a pbuffer */
1129 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1131 return ctx;
1135 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1137 return pglXCreateGLXPixmap(display, vis, parent);
1142 * glxdrv_DescribePixelFormat
1144 * Get the pixel-format descriptor associated to the given id
1146 static int glxdrv_DescribePixelFormat(PHYSDEV dev, int iPixelFormat,
1147 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1149 /*XVisualInfo *vis;*/
1150 int value;
1151 int rb,gb,bb,ab;
1152 WineGLPixelFormat *fmt;
1153 int ret = 0;
1154 int fmt_count = 0;
1156 if (!has_opengl()) return 0;
1158 TRACE("(%p,%d,%d,%p)\n", dev->hdc, 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);
1162 if (ppfd == NULL) {
1163 /* The application is only querying the number of pixelformats */
1164 return fmt_count;
1165 } else if(fmt == NULL) {
1166 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1167 return 0;
1170 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1171 ERR("Wrong structure size !\n");
1172 /* Should set error */
1173 return 0;
1176 ret = fmt_count;
1178 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1179 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1180 ppfd->nVersion = 1;
1182 /* These flags are always the same... */
1183 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1184 /* Now the flags extracted from the Visual */
1186 wine_tsx11_lock();
1188 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1189 if(value & GLX_WINDOW_BIT)
1190 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1192 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1193 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1194 * Radeon 9000 indicated that all bitmap formats have PFD_SUPPORT_GDI. Except for 2 formats on the Radeon 9000 none of the hw accelerated formats
1195 * offered the GDI bit either. */
1196 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1198 /* PFD_GENERIC_FORMAT - gdi software rendering
1199 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1200 * none set - full hardware accelerated by a ICD
1202 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1203 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1205 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1206 if (value) {
1207 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1208 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1210 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1212 /* Pixel type */
1213 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1214 if (value & GLX_RGBA_BIT)
1215 ppfd->iPixelType = PFD_TYPE_RGBA;
1216 else
1217 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1219 /* Color bits */
1220 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1221 ppfd->cColorBits = value;
1223 /* Red, green, blue and alpha bits / shifts */
1224 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1225 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1226 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1227 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1228 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1230 ppfd->cRedBits = rb;
1231 ppfd->cRedShift = gb + bb + ab;
1232 ppfd->cBlueBits = bb;
1233 ppfd->cBlueShift = ab;
1234 ppfd->cGreenBits = gb;
1235 ppfd->cGreenShift = bb + ab;
1236 ppfd->cAlphaBits = ab;
1237 ppfd->cAlphaShift = 0;
1238 } else {
1239 ppfd->cRedBits = 0;
1240 ppfd->cRedShift = 0;
1241 ppfd->cBlueBits = 0;
1242 ppfd->cBlueShift = 0;
1243 ppfd->cGreenBits = 0;
1244 ppfd->cGreenShift = 0;
1245 ppfd->cAlphaBits = 0;
1246 ppfd->cAlphaShift = 0;
1249 /* Accum RGBA bits */
1250 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1251 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1252 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1253 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1255 ppfd->cAccumBits = rb+gb+bb+ab;
1256 ppfd->cAccumRedBits = rb;
1257 ppfd->cAccumGreenBits = gb;
1258 ppfd->cAccumBlueBits = bb;
1259 ppfd->cAccumAlphaBits = ab;
1261 /* Aux bits */
1262 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1263 ppfd->cAuxBuffers = value;
1265 /* Depth bits */
1266 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1267 ppfd->cDepthBits = value;
1269 /* stencil bits */
1270 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1271 ppfd->cStencilBits = value;
1273 wine_tsx11_unlock();
1275 ppfd->iLayerType = PFD_MAIN_PLANE;
1277 if (TRACE_ON(wgl)) {
1278 dump_PIXELFORMATDESCRIPTOR(ppfd);
1281 return ret;
1285 * glxdrv_GetPixelFormat
1287 * Get the pixel-format id used by this DC
1289 static int glxdrv_GetPixelFormat(PHYSDEV dev)
1291 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1292 WineGLPixelFormat *fmt;
1293 int tmp;
1295 if (!physdev->pixel_format) return 0; /* not set yet */
1297 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physdev->pixel_format, TRUE, &tmp);
1298 if(!fmt)
1300 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physdev->pixel_format);
1301 return 0;
1303 else if(fmt->offscreenOnly)
1305 /* Offscreen formats can't be used with traditional WGL calls.
1306 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1307 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1308 return 1;
1311 TRACE("(%p): returns %d\n", dev->hdc, physdev->pixel_format);
1312 return physdev->pixel_format;
1316 * glxdrv_SetPixelFormat
1318 * Set the pixel-format id used by this DC
1320 static BOOL glxdrv_SetPixelFormat(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
1322 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1323 WineGLPixelFormat *fmt;
1324 int value;
1325 HWND hwnd;
1327 TRACE("(%p,%d,%p)\n", dev->hdc, iPixelFormat, ppfd);
1329 if (!has_opengl()) return FALSE;
1331 if(physdev->pixel_format) /* cannot change it if already set */
1332 return (physdev->pixel_format == iPixelFormat);
1334 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1335 if(physdev->x11dev->drawable == root_window)
1337 ERR("Invalid operation on root_window\n");
1338 return FALSE;
1341 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1342 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1343 if(!fmt) {
1344 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1345 return FALSE;
1348 wine_tsx11_lock();
1349 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1350 wine_tsx11_unlock();
1352 hwnd = WindowFromDC(physdev->dev.hdc);
1353 if(hwnd) {
1354 if(!(value&GLX_WINDOW_BIT)) {
1355 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1356 return FALSE;
1359 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1360 ERR("Couldn't set format of the window, returning failure\n");
1361 return FALSE;
1363 /* physDev->current_pf will be set by the DCE update */
1365 else if (GetObjectType( physdev->dev.hdc ) == OBJ_MEMDC) {
1366 if(!(value&GLX_PIXMAP_BIT)) {
1367 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1368 return FALSE;
1371 physdev->pixel_format = iPixelFormat;
1372 physdev->type = DC_GL_BITMAP;
1374 else {
1375 FIXME("called on a non-window, non-bitmap object?\n");
1378 if (TRACE_ON(wgl)) {
1379 int gl_test = 0;
1381 wine_tsx11_lock();
1382 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1383 if (gl_test) {
1384 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1385 } else {
1386 TRACE(" FBConfig have :\n");
1387 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1388 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1389 TRACE(" - VISUAL_ID 0x%x\n", value);
1390 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1391 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1393 wine_tsx11_unlock();
1395 return TRUE;
1398 /***********************************************************************
1399 * glxdrv_wglCopyContext
1401 static BOOL glxdrv_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
1403 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1404 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1406 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1408 wine_tsx11_lock();
1409 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1410 wine_tsx11_unlock();
1412 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1413 return TRUE;
1417 * X11DRV_wglCreateContext
1419 * For OpenGL32 wglCreateContext.
1421 static HGLRC glxdrv_wglCreateContext(PHYSDEV dev)
1423 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1424 Wine_GLContext *ret;
1425 WineGLPixelFormat *fmt;
1426 int fmt_count = 0;
1428 TRACE("(%p)->(PF:%d)\n", dev->hdc, physdev->pixel_format);
1430 if (!has_opengl()) return 0;
1432 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physdev->pixel_format, TRUE /* Offscreen */, &fmt_count);
1433 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1434 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1435 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1436 * If this fails something is very wrong on the system. */
1437 if(!fmt) {
1438 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", physdev->pixel_format);
1439 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1440 return NULL;
1443 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1445 ret->hdc = dev->hdc;
1446 ret->fmt = fmt;
1447 ret->has_been_current = FALSE;
1448 ret->sharing = FALSE;
1450 wine_tsx11_lock();
1451 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1452 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1453 list_add_head( &context_list, &ret->entry );
1454 wine_tsx11_unlock();
1456 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1457 return (HGLRC) ret;
1460 /***********************************************************************
1461 * glxdrv_wglDeleteContext
1463 static BOOL glxdrv_wglDeleteContext(HGLRC hglrc)
1465 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1467 TRACE("(%p)\n", hglrc);
1469 if (!is_valid_context(ctx))
1471 WARN("Error deleting context !\n");
1472 SetLastError(ERROR_INVALID_HANDLE);
1473 return FALSE;
1476 /* WGL doesn't allow deletion of a context which is current in another thread */
1477 if (ctx->tid != 0 && ctx->tid != GetCurrentThreadId())
1479 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx);
1480 SetLastError(ERROR_BUSY);
1481 return FALSE;
1484 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1485 if (ctx == NtCurrentTeb()->glContext)
1487 wine_tsx11_lock();
1488 pglXMakeCurrent(gdi_display, None, NULL);
1489 wine_tsx11_unlock();
1490 NtCurrentTeb()->glContext = NULL;
1493 wine_tsx11_lock();
1494 list_remove( &ctx->entry );
1495 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1496 if (ctx->glxpixmap) pglXDestroyGLXPixmap( gdi_display, ctx->glxpixmap );
1497 if (ctx->pixmap) XFreePixmap( gdi_display, ctx->pixmap );
1498 if (ctx->vis) XFree( ctx->vis );
1499 wine_tsx11_unlock();
1501 HeapFree( GetProcessHeap(), 0, ctx );
1502 return TRUE;
1506 * X11DRV_wglGetCurrentReadDCARB
1508 * For OpenGL32 wglGetCurrentReadDCARB.
1510 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1512 HDC ret = 0;
1513 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1515 if (ctx) ret = ctx->read_hdc;
1517 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1518 return ret;
1522 * glxdrv_wglGetProcAddress
1524 * For OpenGL32 wglGetProcAddress.
1526 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1528 int i, j;
1529 const WineGLExtension *ext;
1531 int padding = 32 - strlen(lpszProc);
1532 if (padding < 0)
1533 padding = 0;
1535 if (!has_opengl()) return NULL;
1537 /* Check the table of WGL extensions to see if we need to return a WGL extension
1538 * or a function pointer to a native OpenGL function. */
1539 if(strncmp(lpszProc, "wgl", 3) != 0) {
1540 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1541 } else {
1542 TRACE("('%s'):%*s", lpszProc, padding, " ");
1543 for (i = 0; i < WineGLExtensionListSize; ++i) {
1544 ext = WineGLExtensionList[i];
1545 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1546 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1547 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1548 return ext->extEntryPoints[j].funcAddress;
1554 WARN("(%s) - not found\n", lpszProc);
1555 return NULL;
1558 static GLXPixmap get_context_pixmap( HDC hdc, struct wine_glcontext *ctx )
1560 if (!ctx->pixmap)
1562 BITMAP bmp;
1564 GetObjectW( GetCurrentObject( hdc, OBJ_BITMAP ), sizeof(bmp), &bmp );
1566 wine_tsx11_lock();
1567 ctx->pixmap = XCreatePixmap( gdi_display, root_window,
1568 bmp.bmWidth, bmp.bmHeight, ctx->vis->depth );
1569 ctx->glxpixmap = pglXCreateGLXPixmap( gdi_display, ctx->vis, ctx->pixmap );
1570 wine_tsx11_unlock();
1571 ctx->pixmap_size.cx = bmp.bmWidth;
1572 ctx->pixmap_size.cy = bmp.bmHeight;
1574 return ctx->glxpixmap;
1577 /***********************************************************************
1578 * glxdrv_wglMakeCurrent
1580 static BOOL glxdrv_wglMakeCurrent(HDC hdc, HGLRC hglrc)
1582 BOOL ret;
1583 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1584 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1585 struct x11drv_escape_get_drawable escape;
1587 TRACE("(%p,%p)\n", hdc, hglrc);
1589 if (hglrc == NULL)
1591 if (prev_ctx) prev_ctx->tid = 0;
1593 wine_tsx11_lock();
1594 ret = pglXMakeCurrent(gdi_display, None, NULL);
1595 wine_tsx11_unlock();
1596 NtCurrentTeb()->glContext = NULL;
1597 return TRUE;
1600 escape.code = X11DRV_GET_DRAWABLE;
1601 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1602 sizeof(escape), (LPSTR)&escape ))
1603 return FALSE;
1605 if (!escape.pixel_format)
1607 WARN("Trying to use an invalid drawable\n");
1608 SetLastError(ERROR_INVALID_HANDLE);
1609 return FALSE;
1611 if (ctx->fmt->iPixelFormat != escape.pixel_format)
1613 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1614 hdc, escape.pixel_format, ctx, ctx->fmt->iPixelFormat );
1615 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1616 return FALSE;
1618 else
1620 if (escape.gl_type == DC_GL_BITMAP) escape.drawable = get_context_pixmap( hdc, ctx );
1622 wine_tsx11_lock();
1624 if (TRACE_ON(wgl)) {
1625 int vis_id;
1626 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &vis_id);
1627 describeContext(ctx);
1628 TRACE("hdc %p drawable %lx fmt %u vis %x ctx %p\n", hdc,
1629 escape.drawable, escape.pixel_format, vis_id, ctx->ctx);
1632 ret = pglXMakeCurrent(gdi_display, escape.drawable, ctx->ctx);
1634 if (ret)
1636 if (prev_ctx) prev_ctx->tid = 0;
1637 NtCurrentTeb()->glContext = ctx;
1639 ctx->has_been_current = TRUE;
1640 ctx->tid = GetCurrentThreadId();
1641 ctx->hdc = hdc;
1642 ctx->read_hdc = hdc;
1643 ctx->drawables[0] = escape.drawable;
1644 ctx->drawables[1] = escape.drawable;
1645 ctx->refresh_drawables = FALSE;
1647 if (escape.gl_type == DC_GL_BITMAP) pglDrawBuffer(GL_FRONT_LEFT);
1649 else
1650 SetLastError(ERROR_INVALID_HANDLE);
1651 wine_tsx11_unlock();
1653 TRACE(" returning %s\n", (ret ? "True" : "False"));
1654 return ret;
1658 * X11DRV_wglMakeContextCurrentARB
1660 * For OpenGL32 wglMakeContextCurrentARB
1662 static BOOL WINAPI X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, HGLRC hglrc )
1664 Wine_GLContext *ctx = (Wine_GLContext *)hglrc;
1665 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1666 struct x11drv_escape_get_drawable escape_draw, escape_read;
1667 BOOL ret;
1669 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, hglrc);
1671 if (hglrc == NULL)
1673 if (prev_ctx) prev_ctx->tid = 0;
1675 wine_tsx11_lock();
1676 ret = pglXMakeCurrent(gdi_display, None, NULL);
1677 wine_tsx11_unlock();
1678 NtCurrentTeb()->glContext = NULL;
1681 escape_draw.code = X11DRV_GET_DRAWABLE;
1682 if (!ExtEscape( draw_hdc, X11DRV_ESCAPE, sizeof(escape_draw.code), (LPCSTR)&escape_draw.code,
1683 sizeof(escape_draw), (LPSTR)&escape_draw ))
1684 return FALSE;
1686 escape_read.code = X11DRV_GET_DRAWABLE;
1687 if (!ExtEscape( read_hdc, X11DRV_ESCAPE, sizeof(escape_read.code), (LPCSTR)&escape_read.code,
1688 sizeof(escape_read), (LPSTR)&escape_read ))
1689 return FALSE;
1691 if (!escape_draw.pixel_format)
1693 WARN("Trying to use an invalid drawable\n");
1694 SetLastError(ERROR_INVALID_HANDLE);
1695 return FALSE;
1697 else
1699 if (!pglXMakeContextCurrent) return FALSE;
1701 if (escape_draw.gl_type == DC_GL_BITMAP) escape_draw.drawable = get_context_pixmap( draw_hdc, ctx );
1702 if (escape_read.gl_type == DC_GL_BITMAP) escape_read.drawable = get_context_pixmap( read_hdc, ctx );
1704 wine_tsx11_lock();
1705 ret = pglXMakeContextCurrent(gdi_display, escape_draw.drawable, escape_read.drawable, ctx->ctx);
1706 if (ret)
1708 if (prev_ctx) prev_ctx->tid = 0;
1710 ctx->has_been_current = TRUE;
1711 ctx->tid = GetCurrentThreadId();
1712 ctx->hdc = draw_hdc;
1713 ctx->read_hdc = read_hdc;
1714 ctx->drawables[0] = escape_draw.drawable;
1715 ctx->drawables[1] = escape_read.drawable;
1716 ctx->refresh_drawables = FALSE;
1717 NtCurrentTeb()->glContext = ctx;
1719 else
1720 SetLastError(ERROR_INVALID_HANDLE);
1721 wine_tsx11_unlock();
1724 TRACE(" returning %s\n", (ret ? "True" : "False"));
1725 return ret;
1728 /***********************************************************************
1729 * glxdrv_wglShareLists
1731 static BOOL glxdrv_wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
1733 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1734 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1736 TRACE("(%p, %p)\n", org, dest);
1738 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1739 * at context creation time but in case of WGL it is done using wglShareLists.
1740 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1741 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1742 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1743 * so there delaying context creation doesn't work.
1745 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1746 * and when a program requests sharing we recreate the destination context if it hasn't been made
1747 * current or when it hasn't shared display lists before.
1750 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1752 ERR("Could not share display lists, one of the contexts has been current already !\n");
1753 return FALSE;
1755 else if(dest->sharing)
1757 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1758 return FALSE;
1760 else
1762 if((GetObjectType(org->hdc) == OBJ_MEMDC) ^ (GetObjectType(dest->hdc) == OBJ_MEMDC))
1764 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1767 wine_tsx11_lock();
1768 describeContext(org);
1769 describeContext(dest);
1771 /* Re-create the GLX context and share display lists */
1772 pglXDestroyContext(gdi_display, dest->ctx);
1773 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1774 wine_tsx11_unlock();
1775 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1777 org->sharing = TRUE;
1778 dest->sharing = TRUE;
1779 return TRUE;
1781 return FALSE;
1784 /***********************************************************************
1785 * X11DRV_wglGetCurrentContext
1787 static HGLRC WINAPI X11DRV_wglGetCurrentContext(void)
1789 return NtCurrentTeb()->glContext;
1792 /***********************************************************************
1793 * glxdrv_wglGetCurrentDC
1795 static HDC glxdrv_wglGetCurrentDC(void)
1797 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1799 if (!ctx) return NULL;
1800 TRACE("hdc %p\n", ctx->hdc);
1801 return ctx->hdc;
1804 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1805 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
1807 wine_tsx11_lock();
1808 switch(pname)
1810 case GL_DEPTH_BITS:
1812 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1814 pglGetIntegerv(pname, params);
1816 * if we cannot find a Wine Context
1817 * we only have the default wine desktop context,
1818 * so if we have only a 24 depth say we have 32
1820 if (!ctx && *params == 24) {
1821 *params = 32;
1823 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1824 break;
1826 case GL_ALPHA_BITS:
1828 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1830 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
1831 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
1832 break;
1834 default:
1835 pglGetIntegerv(pname, params);
1836 break;
1838 wine_tsx11_unlock();
1841 static void flush_pixmap( struct wine_glcontext *ctx )
1843 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1844 BITMAPINFO *info = (BITMAPINFO *)buffer;
1845 struct gdi_image_bits bits;
1847 if (!get_pixmap_image( ctx->pixmap, ctx->pixmap_size.cx, ctx->pixmap_size.cy, ctx->vis, info, &bits ))
1849 HBITMAP bitmap = GetCurrentObject( ctx->hdc, OBJ_BITMAP );
1850 SetDIBits( 0, bitmap, 0, ctx->pixmap_size.cy, bits.ptr, info, DIB_RGB_COLORS );
1851 if (bits.free) bits.free( &bits );
1855 static void flush_gl_drawable( struct glx_physdev *physdev )
1857 RECT rect;
1858 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
1859 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
1860 Drawable src = physdev->drawable;
1862 if (w <= 0 || h <= 0) return;
1864 switch (physdev->type)
1866 case DC_GL_PIXMAP_WIN:
1867 src = physdev->pixmap;
1868 /* fall through */
1869 case DC_GL_CHILD_WIN:
1870 /* The GL drawable may be lagged behind if we don't flush first, so
1871 * flush the display make sure we copy up-to-date data */
1872 wine_tsx11_lock();
1873 XFlush(gdi_display);
1874 XSetFunction(gdi_display, physdev->x11dev->gc, GXcopy);
1875 XCopyArea(gdi_display, src, physdev->x11dev->drawable, physdev->x11dev->gc, 0, 0, w, h,
1876 physdev->x11dev->dc_rect.left, physdev->x11dev->dc_rect.top);
1877 wine_tsx11_unlock();
1878 SetRect( &rect, 0, 0, w, h );
1879 add_device_bounds( physdev->x11dev, &rect );
1880 default:
1881 break;
1886 static void WINAPI X11DRV_wglFinish(void)
1888 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1889 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1891 wine_tsx11_lock();
1892 sync_context(ctx);
1893 pglFinish();
1894 wine_tsx11_unlock();
1895 if (ctx)
1897 if (ctx->pixmap) flush_pixmap( ctx );
1898 else ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1902 static void WINAPI X11DRV_wglFlush(void)
1904 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1905 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1907 wine_tsx11_lock();
1908 sync_context(ctx);
1909 pglFlush();
1910 wine_tsx11_unlock();
1911 if (ctx)
1913 if (ctx->pixmap) flush_pixmap( ctx );
1914 else ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1919 * glxdrv_wglCreateContextAttribsARB
1921 * WGL_ARB_create_context: wglCreateContextAttribsARB
1923 static HGLRC glxdrv_wglCreateContextAttribsARB(PHYSDEV dev, HGLRC hShareContext, const int* attribList)
1925 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1926 Wine_GLContext *ret;
1927 WineGLPixelFormat *fmt;
1928 int fmt_count = 0;
1930 TRACE("(%p %p %p)\n", dev->hdc, hShareContext, attribList);
1932 if (!has_opengl()) return 0;
1934 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physdev->pixel_format, TRUE /* Offscreen */, &fmt_count);
1935 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
1936 * If this fails something is very wrong on the system. */
1937 if(!fmt)
1939 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", physdev->pixel_format);
1940 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1941 return NULL;
1944 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1946 ret->hdc = dev->hdc;
1947 ret->fmt = fmt;
1948 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1949 ret->gl3_context = TRUE;
1951 ret->numAttribs = 0;
1952 if(attribList)
1954 int *pAttribList = (int*)attribList;
1955 int *pContextAttribList = &ret->attribList[0];
1956 /* attribList consists of pairs {token, value] terminated with 0 */
1957 while(pAttribList[0] != 0)
1959 TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]);
1960 switch(pAttribList[0])
1962 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1963 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1964 pContextAttribList[1] = pAttribList[1];
1965 break;
1966 case WGL_CONTEXT_MINOR_VERSION_ARB:
1967 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1968 pContextAttribList[1] = pAttribList[1];
1969 break;
1970 case WGL_CONTEXT_LAYER_PLANE_ARB:
1971 break;
1972 case WGL_CONTEXT_FLAGS_ARB:
1973 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1974 pContextAttribList[1] = pAttribList[1];
1975 break;
1976 case WGL_CONTEXT_PROFILE_MASK_ARB:
1977 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1978 pContextAttribList[1] = pAttribList[1];
1979 break;
1980 default:
1981 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]);
1984 ret->numAttribs++;
1985 pAttribList += 2;
1986 pContextAttribList += 2;
1990 wine_tsx11_lock();
1991 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1992 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1994 XSync(gdi_display, False);
1995 if(X11DRV_check_error() || !ret->ctx)
1997 /* In the future we should convert the GLX error to a win32 one here if needed */
1998 ERR("Context creation failed\n");
1999 HeapFree( GetProcessHeap(), 0, ret );
2000 wine_tsx11_unlock();
2001 return NULL;
2004 list_add_head( &context_list, &ret->entry );
2005 wine_tsx11_unlock();
2006 TRACE(" creating context %p\n", ret);
2007 return (HGLRC) ret;
2011 * X11DRV_wglGetExtensionsStringARB
2013 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2015 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2016 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2017 return WineGLInfo.wglExtensions;
2021 * X11DRV_wglCreatePbufferARB
2023 * WGL_ARB_pbuffer: wglCreatePbufferARB
2025 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2027 Wine_GLPBuffer* object = NULL;
2028 WineGLPixelFormat *fmt = NULL;
2029 int nCfgs = 0;
2030 int attribs[256];
2031 int nAttribs = 0;
2033 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2035 if (0 >= iPixelFormat) {
2036 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2037 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2038 return NULL; /* unexpected error */
2041 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2042 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2043 if(!fmt) {
2044 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2045 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2046 goto create_failed; /* unexpected error */
2049 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2050 if (NULL == object) {
2051 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2052 goto create_failed; /* unexpected error */
2054 object->hdc = hdc;
2055 object->display = gdi_display;
2056 object->width = iWidth;
2057 object->height = iHeight;
2058 object->fmt = fmt;
2060 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2061 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2062 while (piAttribList && 0 != *piAttribList) {
2063 int attr_v;
2064 switch (*piAttribList) {
2065 case WGL_PBUFFER_LARGEST_ARB: {
2066 ++piAttribList;
2067 attr_v = *piAttribList;
2068 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2069 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2070 break;
2073 case WGL_TEXTURE_FORMAT_ARB: {
2074 ++piAttribList;
2075 attr_v = *piAttribList;
2076 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2077 if (WGL_NO_TEXTURE_ARB == attr_v) {
2078 object->use_render_texture = 0;
2079 } else {
2080 if (!use_render_texture_emulation) {
2081 SetLastError(ERROR_INVALID_DATA);
2082 goto create_failed;
2084 switch (attr_v) {
2085 case WGL_TEXTURE_RGB_ARB:
2086 object->use_render_texture = GL_RGB;
2087 object->texture_bpp = 3;
2088 object->texture_format = GL_RGB;
2089 object->texture_type = GL_UNSIGNED_BYTE;
2090 break;
2091 case WGL_TEXTURE_RGBA_ARB:
2092 object->use_render_texture = GL_RGBA;
2093 object->texture_bpp = 4;
2094 object->texture_format = GL_RGBA;
2095 object->texture_type = GL_UNSIGNED_BYTE;
2096 break;
2098 /* WGL_FLOAT_COMPONENTS_NV */
2099 case WGL_TEXTURE_FLOAT_R_NV:
2100 object->use_render_texture = GL_FLOAT_R_NV;
2101 object->texture_bpp = 4;
2102 object->texture_format = GL_RED;
2103 object->texture_type = GL_FLOAT;
2104 break;
2105 case WGL_TEXTURE_FLOAT_RG_NV:
2106 object->use_render_texture = GL_FLOAT_RG_NV;
2107 object->texture_bpp = 8;
2108 object->texture_format = GL_LUMINANCE_ALPHA;
2109 object->texture_type = GL_FLOAT;
2110 break;
2111 case WGL_TEXTURE_FLOAT_RGB_NV:
2112 object->use_render_texture = GL_FLOAT_RGB_NV;
2113 object->texture_bpp = 12;
2114 object->texture_format = GL_RGB;
2115 object->texture_type = GL_FLOAT;
2116 break;
2117 case WGL_TEXTURE_FLOAT_RGBA_NV:
2118 object->use_render_texture = GL_FLOAT_RGBA_NV;
2119 object->texture_bpp = 16;
2120 object->texture_format = GL_RGBA;
2121 object->texture_type = GL_FLOAT;
2122 break;
2123 default:
2124 ERR("Unknown texture format: %x\n", attr_v);
2125 SetLastError(ERROR_INVALID_DATA);
2126 goto create_failed;
2129 break;
2132 case WGL_TEXTURE_TARGET_ARB: {
2133 ++piAttribList;
2134 attr_v = *piAttribList;
2135 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2136 if (WGL_NO_TEXTURE_ARB == attr_v) {
2137 object->texture_target = 0;
2138 } else {
2139 if (!use_render_texture_emulation) {
2140 SetLastError(ERROR_INVALID_DATA);
2141 goto create_failed;
2143 switch (attr_v) {
2144 case WGL_TEXTURE_CUBE_MAP_ARB: {
2145 if (iWidth != iHeight) {
2146 SetLastError(ERROR_INVALID_DATA);
2147 goto create_failed;
2149 object->texture_target = GL_TEXTURE_CUBE_MAP;
2150 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2151 break;
2153 case WGL_TEXTURE_1D_ARB: {
2154 if (1 != iHeight) {
2155 SetLastError(ERROR_INVALID_DATA);
2156 goto create_failed;
2158 object->texture_target = GL_TEXTURE_1D;
2159 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2160 break;
2162 case WGL_TEXTURE_2D_ARB: {
2163 object->texture_target = GL_TEXTURE_2D;
2164 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2165 break;
2167 case WGL_TEXTURE_RECTANGLE_NV: {
2168 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2169 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2170 break;
2172 default:
2173 ERR("Unknown texture target: %x\n", attr_v);
2174 SetLastError(ERROR_INVALID_DATA);
2175 goto create_failed;
2178 break;
2181 case WGL_MIPMAP_TEXTURE_ARB: {
2182 ++piAttribList;
2183 attr_v = *piAttribList;
2184 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2185 if (!use_render_texture_emulation) {
2186 SetLastError(ERROR_INVALID_DATA);
2187 goto create_failed;
2189 break;
2192 ++piAttribList;
2195 PUSH1(attribs, None);
2196 wine_tsx11_lock();
2197 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2198 wine_tsx11_unlock();
2199 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2200 if (!object->drawable) {
2201 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2202 goto create_failed; /* unexpected error */
2204 TRACE("->(%p)\n", object);
2205 return object;
2207 create_failed:
2208 HeapFree(GetProcessHeap(), 0, object);
2209 TRACE("->(FAILED)\n");
2210 return NULL;
2214 * X11DRV_wglDestroyPbufferARB
2216 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2218 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2220 Wine_GLPBuffer* object = hPbuffer;
2221 TRACE("(%p)\n", hPbuffer);
2222 if (NULL == object) {
2223 SetLastError(ERROR_INVALID_HANDLE);
2224 return GL_FALSE;
2226 wine_tsx11_lock();
2227 pglXDestroyPbuffer(object->display, object->drawable);
2228 wine_tsx11_unlock();
2229 HeapFree(GetProcessHeap(), 0, object);
2230 return GL_TRUE;
2234 * X11DRV_wglGetPbufferDCARB
2236 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2238 static HDC WINAPI X11DRV_wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
2240 struct x11drv_escape_set_drawable escape;
2241 Wine_GLPBuffer* object = hPbuffer;
2242 HDC hdc;
2244 if (NULL == object) {
2245 SetLastError(ERROR_INVALID_HANDLE);
2246 return NULL;
2249 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2250 if (!hdc) return 0;
2252 escape.code = X11DRV_SET_DRAWABLE;
2253 escape.drawable = object->drawable;
2254 escape.mode = IncludeInferiors;
2255 SetRect( &escape.drawable_rect, 0, 0, object->width, object->height );
2256 escape.dc_rect = escape.drawable_rect;
2257 escape.fbconfig_id = object->fmt->fmt_id;
2258 escape.gl_drawable = object->drawable;
2259 escape.pixmap = 0;
2260 escape.gl_type = DC_GL_PBUFFER;
2261 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2263 TRACE( "(%p)->(%p)\n", hPbuffer, hdc );
2264 return hdc;
2268 * X11DRV_wglQueryPbufferARB
2270 * WGL_ARB_pbuffer: wglQueryPbufferARB
2272 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2274 Wine_GLPBuffer* object = hPbuffer;
2275 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2276 if (NULL == object) {
2277 SetLastError(ERROR_INVALID_HANDLE);
2278 return GL_FALSE;
2280 switch (iAttribute) {
2281 case WGL_PBUFFER_WIDTH_ARB:
2282 wine_tsx11_lock();
2283 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2284 wine_tsx11_unlock();
2285 break;
2286 case WGL_PBUFFER_HEIGHT_ARB:
2287 wine_tsx11_lock();
2288 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2289 wine_tsx11_unlock();
2290 break;
2292 case WGL_PBUFFER_LOST_ARB:
2293 /* GLX Pbuffers cannot be lost by default. We can support this by
2294 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2295 * to receive pixel buffer clobber events, however that may or may
2296 * not give any benefit */
2297 *piValue = GL_FALSE;
2298 break;
2300 case WGL_TEXTURE_FORMAT_ARB:
2301 if (!object->use_render_texture) {
2302 *piValue = WGL_NO_TEXTURE_ARB;
2303 } else {
2304 if (!use_render_texture_emulation) {
2305 SetLastError(ERROR_INVALID_HANDLE);
2306 return GL_FALSE;
2308 switch(object->use_render_texture) {
2309 case GL_RGB:
2310 *piValue = WGL_TEXTURE_RGB_ARB;
2311 break;
2312 case GL_RGBA:
2313 *piValue = WGL_TEXTURE_RGBA_ARB;
2314 break;
2315 /* WGL_FLOAT_COMPONENTS_NV */
2316 case GL_FLOAT_R_NV:
2317 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2318 break;
2319 case GL_FLOAT_RG_NV:
2320 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2321 break;
2322 case GL_FLOAT_RGB_NV:
2323 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2324 break;
2325 case GL_FLOAT_RGBA_NV:
2326 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2327 break;
2328 default:
2329 ERR("Unknown texture format: %x\n", object->use_render_texture);
2332 break;
2334 case WGL_TEXTURE_TARGET_ARB:
2335 if (!object->texture_target){
2336 *piValue = WGL_NO_TEXTURE_ARB;
2337 } else {
2338 if (!use_render_texture_emulation) {
2339 SetLastError(ERROR_INVALID_DATA);
2340 return GL_FALSE;
2342 switch (object->texture_target) {
2343 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2344 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2345 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2346 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2349 break;
2351 case WGL_MIPMAP_TEXTURE_ARB:
2352 *piValue = GL_FALSE; /** don't support that */
2353 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2354 break;
2356 default:
2357 FIXME("unexpected attribute %x\n", iAttribute);
2358 break;
2361 return GL_TRUE;
2365 * X11DRV_wglReleasePbufferDCARB
2367 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2369 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2371 TRACE("(%p, %p)\n", hPbuffer, hdc);
2372 return DeleteDC(hdc);
2376 * X11DRV_wglSetPbufferAttribARB
2378 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2380 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2382 Wine_GLPBuffer* object = hPbuffer;
2383 GLboolean ret = GL_FALSE;
2385 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2386 if (NULL == object) {
2387 SetLastError(ERROR_INVALID_HANDLE);
2388 return GL_FALSE;
2390 if (!object->use_render_texture) {
2391 SetLastError(ERROR_INVALID_HANDLE);
2392 return GL_FALSE;
2394 if (1 == use_render_texture_emulation) {
2395 return GL_TRUE;
2397 return ret;
2401 * X11DRV_wglChoosePixelFormatARB
2403 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2405 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2407 int gl_test = 0;
2408 int attribs[256];
2409 int nAttribs = 0;
2410 GLXFBConfig* cfgs = NULL;
2411 int nCfgs = 0;
2412 int it;
2413 int fmt_id;
2414 WineGLPixelFormat *fmt;
2415 UINT pfmt_it = 0;
2416 int run;
2417 int i;
2418 DWORD dwFlags = 0;
2420 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2421 if (NULL != pfAttribFList) {
2422 FIXME("unused pfAttribFList\n");
2425 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2426 if (-1 == nAttribs) {
2427 WARN("Cannot convert WGL to GLX attributes\n");
2428 return GL_FALSE;
2430 PUSH1(attribs, None);
2432 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2433 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2434 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2435 for(i=0; piAttribIList[i] != 0; i+=2)
2437 switch(piAttribIList[i])
2439 case WGL_DRAW_TO_BITMAP_ARB:
2440 if(piAttribIList[i+1])
2441 dwFlags |= PFD_DRAW_TO_BITMAP;
2442 break;
2443 case WGL_ACCELERATION_ARB:
2444 switch(piAttribIList[i+1])
2446 case WGL_NO_ACCELERATION_ARB:
2447 dwFlags |= PFD_GENERIC_FORMAT;
2448 break;
2449 case WGL_GENERIC_ACCELERATION_ARB:
2450 dwFlags |= PFD_GENERIC_ACCELERATED;
2451 break;
2452 case WGL_FULL_ACCELERATION_ARB:
2453 /* Nothing to do */
2454 break;
2456 break;
2457 case WGL_SUPPORT_GDI_ARB:
2458 if(piAttribIList[i+1])
2459 dwFlags |= PFD_SUPPORT_GDI;
2460 break;
2464 /* Search for FB configurations matching the requirements in attribs */
2465 wine_tsx11_lock();
2466 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2467 if (NULL == cfgs) {
2468 wine_tsx11_unlock();
2469 WARN("Compatible Pixel Format not found\n");
2470 return GL_FALSE;
2473 /* Loop through all matching formats and check if they are suitable.
2474 * Note that this function should at max return nMaxFormats different formats */
2475 for(run=0; run < 2; run++)
2477 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2479 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2480 if (gl_test) {
2481 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2482 continue;
2485 /* Search for the format in our list of compatible formats */
2486 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id, dwFlags);
2487 if(!fmt)
2488 continue;
2490 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2491 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2492 continue;
2494 piFormats[pfmt_it] = fmt->iPixelFormat;
2495 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2496 pfmt_it++;
2500 *nNumFormats = pfmt_it;
2501 /** free list */
2502 XFree(cfgs);
2503 wine_tsx11_unlock();
2504 return GL_TRUE;
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)
2514 UINT i;
2515 WineGLPixelFormat *fmt = NULL;
2516 int hTest;
2517 int tmp;
2518 int curGLXAttr = 0;
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);
2525 return GL_FALSE;
2528 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2529 * We don't have to fail yet as a program can specify an invalid 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);
2532 if(!fmt) {
2533 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2536 wine_tsx11_lock();
2537 for (i = 0; i < nAttributes; ++i) {
2538 const int curWGLAttr = piAttributes[i];
2539 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2541 switch (curWGLAttr) {
2542 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2543 piValues[i] = nWGLFormats;
2544 continue;
2546 case WGL_SUPPORT_OPENGL_ARB:
2547 piValues[i] = GL_TRUE;
2548 continue;
2550 case WGL_ACCELERATION_ARB:
2551 curGLXAttr = GLX_CONFIG_CAVEAT;
2552 if (!fmt) goto pix_error;
2553 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2554 piValues[i] = WGL_NO_ACCELERATION_ARB;
2555 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2556 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2557 else
2558 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2559 continue;
2561 case WGL_TRANSPARENT_ARB:
2562 curGLXAttr = GLX_TRANSPARENT_TYPE;
2563 if (!fmt) goto pix_error;
2564 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2565 if (hTest) goto get_error;
2566 piValues[i] = GL_FALSE;
2567 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2568 continue;
2570 case WGL_PIXEL_TYPE_ARB:
2571 curGLXAttr = GLX_RENDER_TYPE;
2572 if (!fmt) goto pix_error;
2573 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2574 if (hTest) goto get_error;
2575 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2576 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2577 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2578 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2579 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2580 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2581 else {
2582 ERR("unexpected RenderType(%x)\n", tmp);
2583 piValues[i] = WGL_TYPE_RGBA_ARB;
2585 continue;
2587 case WGL_COLOR_BITS_ARB:
2588 curGLXAttr = GLX_BUFFER_SIZE;
2589 break;
2591 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2592 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2593 if (!use_render_texture_emulation) {
2594 piValues[i] = GL_FALSE;
2595 continue;
2597 curGLXAttr = GLX_RENDER_TYPE;
2598 if (!fmt) goto pix_error;
2599 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2600 if (hTest) goto get_error;
2601 if (GLX_COLOR_INDEX_BIT == tmp) {
2602 piValues[i] = GL_FALSE;
2603 continue;
2605 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2606 if (hTest) goto get_error;
2607 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2608 continue;
2610 case WGL_BLUE_BITS_ARB:
2611 curGLXAttr = GLX_BLUE_SIZE;
2612 break;
2613 case WGL_RED_BITS_ARB:
2614 curGLXAttr = GLX_RED_SIZE;
2615 break;
2616 case WGL_GREEN_BITS_ARB:
2617 curGLXAttr = GLX_GREEN_SIZE;
2618 break;
2619 case WGL_ALPHA_BITS_ARB:
2620 curGLXAttr = GLX_ALPHA_SIZE;
2621 break;
2622 case WGL_DEPTH_BITS_ARB:
2623 curGLXAttr = GLX_DEPTH_SIZE;
2624 break;
2625 case WGL_STENCIL_BITS_ARB:
2626 curGLXAttr = GLX_STENCIL_SIZE;
2627 break;
2628 case WGL_DOUBLE_BUFFER_ARB:
2629 curGLXAttr = GLX_DOUBLEBUFFER;
2630 break;
2631 case WGL_STEREO_ARB:
2632 curGLXAttr = GLX_STEREO;
2633 break;
2634 case WGL_AUX_BUFFERS_ARB:
2635 curGLXAttr = GLX_AUX_BUFFERS;
2636 break;
2638 case WGL_SUPPORT_GDI_ARB:
2639 if (!fmt) goto pix_error;
2640 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
2641 continue;
2643 case WGL_DRAW_TO_BITMAP_ARB:
2644 if (!fmt) goto pix_error;
2645 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? TRUE : FALSE;
2646 continue;
2648 case WGL_DRAW_TO_WINDOW_ARB:
2649 case WGL_DRAW_TO_PBUFFER_ARB:
2650 if (!fmt) goto pix_error;
2651 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2652 if (hTest) goto get_error;
2653 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2654 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2655 piValues[i] = GL_TRUE;
2656 else
2657 piValues[i] = GL_FALSE;
2658 continue;
2660 case WGL_SWAP_METHOD_ARB:
2661 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2662 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2663 * point only ATI offers this.
2665 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2666 break;
2668 case WGL_PBUFFER_LARGEST_ARB:
2669 curGLXAttr = GLX_LARGEST_PBUFFER;
2670 break;
2672 case WGL_SAMPLE_BUFFERS_ARB:
2673 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2674 break;
2676 case WGL_SAMPLES_ARB:
2677 curGLXAttr = GLX_SAMPLES_ARB;
2678 break;
2680 case WGL_FLOAT_COMPONENTS_NV:
2681 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2682 break;
2684 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2685 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2686 break;
2688 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2689 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2690 break;
2692 case WGL_ACCUM_RED_BITS_ARB:
2693 curGLXAttr = GLX_ACCUM_RED_SIZE;
2694 break;
2695 case WGL_ACCUM_GREEN_BITS_ARB:
2696 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2697 break;
2698 case WGL_ACCUM_BLUE_BITS_ARB:
2699 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2700 break;
2701 case WGL_ACCUM_ALPHA_BITS_ARB:
2702 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2703 break;
2704 case WGL_ACCUM_BITS_ARB:
2705 if (!fmt) goto pix_error;
2706 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2707 if (hTest) goto get_error;
2708 piValues[i] = tmp;
2709 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2710 if (hTest) goto get_error;
2711 piValues[i] += tmp;
2712 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2713 if (hTest) goto get_error;
2714 piValues[i] += tmp;
2715 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2716 if (hTest) goto get_error;
2717 piValues[i] += tmp;
2718 continue;
2720 default:
2721 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2724 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2725 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2726 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2728 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2729 * and check which options can work using iPixelFormat=0 and which not.
2730 * A problem would be that this function is an extension. This would
2731 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2733 if (0 != curGLXAttr && iPixelFormat != 0) {
2734 if (!fmt) goto pix_error;
2735 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2736 if (hTest) goto get_error;
2737 curGLXAttr = 0;
2738 } else {
2739 piValues[i] = GL_FALSE;
2742 wine_tsx11_unlock();
2743 return GL_TRUE;
2745 get_error:
2746 wine_tsx11_unlock();
2747 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2748 return GL_FALSE;
2750 pix_error:
2751 wine_tsx11_unlock();
2752 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2753 return GL_FALSE;
2757 * X11DRV_wglGetPixelFormatAttribfvARB
2759 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2761 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2763 int *attr;
2764 int ret;
2765 UINT i;
2767 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2769 /* Allocate a temporary array to store integer values */
2770 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2771 if (!attr) {
2772 ERR("couldn't allocate %d array\n", nAttributes);
2773 return GL_FALSE;
2776 /* Piggy-back on wglGetPixelFormatAttribivARB */
2777 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2778 if (ret) {
2779 /* Convert integer values to float. Should also check for attributes
2780 that can give decimal values here */
2781 for (i=0; i<nAttributes;i++) {
2782 pfValues[i] = attr[i];
2786 HeapFree(GetProcessHeap(), 0, attr);
2787 return ret;
2791 * X11DRV_wglBindTexImageARB
2793 * WGL_ARB_render_texture: wglBindTexImageARB
2795 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2797 Wine_GLPBuffer* object = hPbuffer;
2798 GLboolean ret = GL_FALSE;
2800 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2801 if (NULL == object) {
2802 SetLastError(ERROR_INVALID_HANDLE);
2803 return GL_FALSE;
2805 if (!object->use_render_texture) {
2806 SetLastError(ERROR_INVALID_HANDLE);
2807 return GL_FALSE;
2810 if (1 == use_render_texture_emulation) {
2811 static int init = 0;
2812 int prev_binded_texture = 0;
2813 GLXContext prev_context;
2814 Drawable prev_drawable;
2815 GLXContext tmp_context;
2817 wine_tsx11_lock();
2818 prev_context = pglXGetCurrentContext();
2819 prev_drawable = pglXGetCurrentDrawable();
2821 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2822 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2823 isn't ideal performance wise but I wasn't able to get other ways working.
2825 if(!init) {
2826 init = 1; /* Only show the FIXME once for performance reasons */
2827 FIXME("partial stub!\n");
2830 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2831 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2833 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2835 /* Switch to our pbuffer */
2836 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2838 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2839 * After that upload the pbuffer texture data. */
2840 pglBindTexture(object->texture_target, prev_binded_texture);
2841 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2843 /* Switch back to the original drawable and upload the pbuffer-texture */
2844 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2845 pglXDestroyContext(gdi_display, tmp_context);
2846 wine_tsx11_unlock();
2847 return GL_TRUE;
2850 return ret;
2854 * X11DRV_wglReleaseTexImageARB
2856 * WGL_ARB_render_texture: wglReleaseTexImageARB
2858 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2860 Wine_GLPBuffer* object = hPbuffer;
2861 GLboolean ret = GL_FALSE;
2863 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2864 if (NULL == object) {
2865 SetLastError(ERROR_INVALID_HANDLE);
2866 return GL_FALSE;
2868 if (!object->use_render_texture) {
2869 SetLastError(ERROR_INVALID_HANDLE);
2870 return GL_FALSE;
2872 if (1 == use_render_texture_emulation) {
2873 return GL_TRUE;
2875 return ret;
2879 * X11DRV_wglGetExtensionsStringEXT
2881 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2883 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2884 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2885 return WineGLInfo.wglExtensions;
2889 * X11DRV_wglGetSwapIntervalEXT
2891 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2893 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2894 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2895 * interval, so the swap interval has to be tracked. */
2896 TRACE("()\n");
2897 return swap_interval;
2901 * X11DRV_wglSwapIntervalEXT
2903 * WGL_EXT_swap_control: wglSwapIntervalEXT
2905 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2906 BOOL ret = TRUE;
2908 TRACE("(%d)\n", interval);
2910 if (interval < 0)
2912 SetLastError(ERROR_INVALID_DATA);
2913 return FALSE;
2915 else if (!has_swap_control && interval == 0)
2917 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2918 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2919 * value to be an error. Just silently ignore the request for now. */
2920 WARN("Request to disable vertical sync is not handled\n");
2921 swap_interval = 0;
2923 else
2925 if (pglXSwapIntervalSGI)
2927 wine_tsx11_lock();
2928 ret = !pglXSwapIntervalSGI(interval);
2929 wine_tsx11_unlock();
2931 else
2932 WARN("GLX_SGI_swap_control extension is not available\n");
2934 if (ret)
2935 swap_interval = interval;
2936 else
2937 SetLastError(ERROR_DC_NOT_FOUND);
2940 return ret;
2944 * X11DRV_wglAllocateMemoryNV
2946 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2948 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2949 void *ret = NULL;
2950 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2952 if (pglXAllocateMemoryNV)
2954 wine_tsx11_lock();
2955 ret = pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2956 wine_tsx11_unlock();
2958 return ret;
2962 * X11DRV_wglFreeMemoryNV
2964 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2966 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2967 TRACE("(%p)\n", pointer);
2968 if (pglXFreeMemoryNV == NULL)
2969 return;
2971 wine_tsx11_lock();
2972 pglXFreeMemoryNV(pointer);
2973 wine_tsx11_unlock();
2977 * X11DRV_wglSetPixelFormatWINE
2979 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2980 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2982 static BOOL WINAPI X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2984 WineGLPixelFormat *fmt;
2985 int value;
2986 HWND hwnd;
2988 TRACE("(%p,%d)\n", hdc, format);
2990 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, format, FALSE /* Offscreen */, &value);
2991 if (!fmt)
2993 ERR( "Invalid format %d\n", format );
2994 return FALSE;
2997 hwnd = WindowFromDC( hdc );
2998 if (!hwnd || hwnd == GetDesktopWindow())
3000 ERR( "not a valid window DC %p\n", hdc );
3001 return FALSE;
3004 wine_tsx11_lock();
3005 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
3006 wine_tsx11_unlock();
3008 if (!(value & GLX_WINDOW_BIT))
3010 WARN( "Pixel format %d is not compatible for window rendering\n", format );
3011 return FALSE;
3014 return SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0);
3015 /* DC pixel format will be set by the DCE update */
3019 * glxRequireVersion (internal)
3021 * Check if the supported GLX version matches requiredVersion.
3023 static BOOL glxRequireVersion(int requiredVersion)
3025 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3026 if(requiredVersion <= WineGLInfo.glxVersion[1])
3027 return TRUE;
3029 return FALSE;
3032 static BOOL glxRequireExtension(const char *requiredExtension)
3034 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3035 return FALSE;
3038 return TRUE;
3041 static void register_extension_string(const char *ext)
3043 if (WineGLInfo.wglExtensions[0])
3044 strcat(WineGLInfo.wglExtensions, " ");
3045 strcat(WineGLInfo.wglExtensions, ext);
3047 TRACE("'%s'\n", ext);
3050 static BOOL register_extension(const WineGLExtension * ext)
3052 int i;
3054 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3055 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3057 register_extension_string(ext->extName);
3059 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3060 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3062 return TRUE;
3065 static const WineGLExtension WGL_internal_functions =
3069 { "wglFinish", X11DRV_wglFinish },
3070 { "wglFlush", X11DRV_wglFlush },
3071 { "wglGetCurrentContext", X11DRV_wglGetCurrentContext },
3072 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3077 static const WineGLExtension WGL_ARB_create_context =
3079 "WGL_ARB_create_context",
3081 { "wglCreateContextAttribsARB", (void *)1 /* not called directly */ },
3085 static const WineGLExtension WGL_ARB_extensions_string =
3087 "WGL_ARB_extensions_string",
3089 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3093 static const WineGLExtension WGL_ARB_make_current_read =
3095 "WGL_ARB_make_current_read",
3097 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3098 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3102 static const WineGLExtension WGL_ARB_multisample =
3104 "WGL_ARB_multisample",
3107 static const WineGLExtension WGL_ARB_pbuffer =
3109 "WGL_ARB_pbuffer",
3111 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3112 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3113 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3114 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3115 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3116 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3120 static const WineGLExtension WGL_ARB_pixel_format =
3122 "WGL_ARB_pixel_format",
3124 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3125 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3126 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3130 static const WineGLExtension WGL_ARB_render_texture =
3132 "WGL_ARB_render_texture",
3134 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3135 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3139 static const WineGLExtension WGL_EXT_extensions_string =
3141 "WGL_EXT_extensions_string",
3143 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3147 static const WineGLExtension WGL_EXT_swap_control =
3149 "WGL_EXT_swap_control",
3151 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3152 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3156 static const WineGLExtension WGL_NV_vertex_array_range =
3158 "WGL_NV_vertex_array_range",
3160 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3161 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3165 static const WineGLExtension WGL_WINE_pixel_format_passthrough =
3167 "WGL_WINE_pixel_format_passthrough",
3169 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE },
3174 * X11DRV_WineGL_LoadExtensions
3176 static void X11DRV_WineGL_LoadExtensions(void)
3178 WineGLInfo.wglExtensions[0] = 0;
3180 /* Load Wine internal functions */
3181 register_extension(&WGL_internal_functions);
3183 /* ARB Extensions */
3185 if(glxRequireExtension("GLX_ARB_create_context"))
3187 register_extension(&WGL_ARB_create_context);
3189 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3190 register_extension_string("WGL_ARB_create_context_profile");
3193 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3195 register_extension_string("WGL_ARB_pixel_format_float");
3196 register_extension_string("WGL_ATI_pixel_format_float");
3199 register_extension(&WGL_ARB_extensions_string);
3201 if (glxRequireVersion(3))
3202 register_extension(&WGL_ARB_make_current_read);
3204 if (glxRequireExtension("GLX_ARB_multisample"))
3205 register_extension(&WGL_ARB_multisample);
3207 /* In general pbuffer functionality requires support in the X-server. The functionality is
3208 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3210 if ( glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") )
3211 register_extension(&WGL_ARB_pbuffer);
3213 register_extension(&WGL_ARB_pixel_format);
3215 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3216 if (glxRequireExtension("GLX_ARB_render_texture") ||
3217 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3219 register_extension(&WGL_ARB_render_texture);
3221 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3222 if(glxRequireExtension("GLX_NV_float_buffer"))
3223 register_extension_string("WGL_NV_float_buffer");
3225 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3226 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3227 register_extension_string("WGL_NV_texture_rectangle");
3230 /* EXT Extensions */
3232 register_extension(&WGL_EXT_extensions_string);
3234 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3235 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3236 register_extension(&WGL_EXT_swap_control);
3238 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3239 register_extension_string("WGL_EXT_framebuffer_sRGB");
3241 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3242 register_extension_string("WGL_EXT_pixel_format_packed_float");
3244 if (glxRequireExtension("GLX_EXT_swap_control"))
3245 has_swap_control = TRUE;
3247 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3248 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3249 register_extension(&WGL_NV_vertex_array_range);
3251 /* WINE-specific WGL Extensions */
3253 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3254 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3256 register_extension(&WGL_WINE_pixel_format_passthrough);
3260 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3262 wine_tsx11_lock();
3263 pglXDestroyGLXPixmap(display, glxpixmap);
3264 wine_tsx11_unlock();
3265 return TRUE;
3269 * glxdrv_SwapBuffers
3271 * Swap the buffers of this DC
3273 static BOOL glxdrv_SwapBuffers(PHYSDEV dev)
3275 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3276 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3278 TRACE("(%p)\n", dev->hdc);
3280 if (!ctx)
3282 WARN("Using a NULL context, skipping\n");
3283 SetLastError(ERROR_INVALID_HANDLE);
3284 return FALSE;
3287 if (!physdev->drawable)
3289 WARN("Using an invalid drawable, skipping\n");
3290 SetLastError(ERROR_INVALID_HANDLE);
3291 return FALSE;
3294 wine_tsx11_lock();
3295 sync_context(ctx);
3296 switch (physdev->type)
3298 case DC_GL_PIXMAP_WIN:
3299 if(pglXCopySubBufferMESA) {
3300 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
3301 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
3303 /* (glX)SwapBuffers has an implicit glFlush effect, however
3304 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3305 * copying */
3306 pglFlush();
3307 if(w > 0 && h > 0)
3308 pglXCopySubBufferMESA(gdi_display, physdev->drawable, 0, 0, w, h);
3309 break;
3311 /* fall through */
3312 default:
3313 pglXSwapBuffers(gdi_display, physdev->drawable);
3314 break;
3317 flush_gl_drawable( physdev );
3318 wine_tsx11_unlock();
3320 /* FPS support */
3321 if (TRACE_ON(fps))
3323 static long prev_time, start_time;
3324 static unsigned long frames, frames_total;
3326 DWORD time = GetTickCount();
3327 frames++;
3328 frames_total++;
3329 /* every 1.5 seconds */
3330 if (time - prev_time > 1500) {
3331 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3332 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3333 prev_time = time;
3334 frames = 0;
3335 if(start_time == 0) start_time = time;
3339 return TRUE;
3342 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3344 WineGLPixelFormat *fmt;
3345 XVisualInfo *ret;
3347 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
3348 if(fmt == NULL)
3349 return NULL;
3351 wine_tsx11_lock();
3352 ret = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3353 wine_tsx11_unlock();
3354 return ret;
3357 static BOOL create_glx_dc( PHYSDEV *pdev )
3359 /* assume that only the main x11 device implements GetDeviceCaps */
3360 X11DRV_PDEVICE *x11dev = get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev, pGetDeviceCaps ));
3361 struct glx_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) );
3363 if (!physdev) return FALSE;
3364 physdev->x11dev = x11dev;
3365 push_dc_driver( pdev, &physdev->dev, &glxdrv_funcs );
3366 return TRUE;
3369 /**********************************************************************
3370 * glxdrv_CreateDC
3372 static BOOL glxdrv_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
3373 LPCWSTR output, const DEVMODEW* initData )
3375 return create_glx_dc( pdev );
3378 /**********************************************************************
3379 * glxdrv_CreateCompatibleDC
3381 static BOOL glxdrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
3383 if (orig) /* chain to next driver first */
3385 orig = GET_NEXT_PHYSDEV( orig, pCreateCompatibleDC );
3386 if (!orig->funcs->pCreateCompatibleDC( orig, pdev )) return FALSE;
3388 /* otherwise we have been called by x11drv */
3389 return create_glx_dc( pdev );
3392 /**********************************************************************
3393 * glxdrv_DeleteDC
3395 static BOOL glxdrv_DeleteDC( PHYSDEV dev )
3397 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3398 HeapFree( GetProcessHeap(), 0, physdev );
3399 return TRUE;
3402 /**********************************************************************
3403 * glxdrv_ExtEscape
3405 static INT glxdrv_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
3406 INT out_count, LPVOID out_data )
3408 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3410 dev = GET_NEXT_PHYSDEV( dev, pExtEscape );
3412 if (escape == X11DRV_ESCAPE && in_data && in_count >= sizeof(enum x11drv_escape_codes))
3414 switch (*(const enum x11drv_escape_codes *)in_data)
3416 case X11DRV_SET_DRAWABLE:
3417 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
3419 const struct x11drv_escape_set_drawable *data = in_data;
3420 physdev->pixel_format = pixelformat_from_fbconfig_id( data->fbconfig_id );
3421 physdev->type = data->gl_type;
3422 physdev->drawable = data->gl_drawable;
3423 physdev->pixmap = data->pixmap;
3424 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %u type %u\n",
3425 dev->hdc, physdev->drawable, physdev->pixel_format, physdev->type );
3427 break;
3428 case X11DRV_GET_DRAWABLE:
3429 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
3431 struct x11drv_escape_get_drawable *data = out_data;
3432 data->pixel_format = physdev->pixel_format;
3433 data->gl_type = physdev->type;
3434 data->gl_drawable = physdev->drawable;
3435 data->pixmap = physdev->pixmap;
3437 break;
3438 case X11DRV_FLUSH_GL_DRAWABLE:
3439 flush_gl_drawable( physdev );
3440 return TRUE;
3441 default:
3442 break;
3445 return dev->funcs->pExtEscape( dev, escape, in_count, in_data, out_count, out_data );
3448 /**********************************************************************
3449 * glxdrv_wine_get_wgl_driver
3451 static const struct wgl_funcs * glxdrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
3453 if (version != WINE_GDI_DRIVER_VERSION)
3455 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_GDI_DRIVER_VERSION );
3456 return NULL;
3458 if (!has_opengl()) return NULL;
3459 return &glxdrv_wgl_funcs;
3462 static const struct gdi_dc_funcs glxdrv_funcs =
3464 NULL, /* pAbortDoc */
3465 NULL, /* pAbortPath */
3466 NULL, /* pAlphaBlend */
3467 NULL, /* pAngleArc */
3468 NULL, /* pArc */
3469 NULL, /* pArcTo */
3470 NULL, /* pBeginPath */
3471 NULL, /* pBlendImage */
3472 NULL, /* pChoosePixelFormat */
3473 NULL, /* pChord */
3474 NULL, /* pCloseFigure */
3475 glxdrv_CreateCompatibleDC, /* pCreateCompatibleDC */
3476 glxdrv_CreateDC, /* pCreateDC */
3477 glxdrv_DeleteDC, /* pDeleteDC */
3478 NULL, /* pDeleteObject */
3479 glxdrv_DescribePixelFormat, /* pDescribePixelFormat */
3480 NULL, /* pDeviceCapabilities */
3481 NULL, /* pEllipse */
3482 NULL, /* pEndDoc */
3483 NULL, /* pEndPage */
3484 NULL, /* pEndPath */
3485 NULL, /* pEnumFonts */
3486 NULL, /* pEnumICMProfiles */
3487 NULL, /* pExcludeClipRect */
3488 NULL, /* pExtDeviceMode */
3489 glxdrv_ExtEscape, /* pExtEscape */
3490 NULL, /* pExtFloodFill */
3491 NULL, /* pExtSelectClipRgn */
3492 NULL, /* pExtTextOut */
3493 NULL, /* pFillPath */
3494 NULL, /* pFillRgn */
3495 NULL, /* pFlattenPath */
3496 NULL, /* pFontIsLinked */
3497 NULL, /* pFrameRgn */
3498 NULL, /* pGdiComment */
3499 NULL, /* pGdiRealizationInfo */
3500 NULL, /* pGetBoundsRect */
3501 NULL, /* pGetCharABCWidths */
3502 NULL, /* pGetCharABCWidthsI */
3503 NULL, /* pGetCharWidth */
3504 NULL, /* pGetDeviceCaps */
3505 NULL, /* pGetDeviceGammaRamp */
3506 NULL, /* pGetFontData */
3507 NULL, /* pGetFontUnicodeRanges */
3508 NULL, /* pGetGlyphIndices */
3509 NULL, /* pGetGlyphOutline */
3510 NULL, /* pGetICMProfile */
3511 NULL, /* pGetImage */
3512 NULL, /* pGetKerningPairs */
3513 NULL, /* pGetNearestColor */
3514 NULL, /* pGetOutlineTextMetrics */
3515 NULL, /* pGetPixel */
3516 glxdrv_GetPixelFormat, /* pGetPixelFormat */
3517 NULL, /* pGetSystemPaletteEntries */
3518 NULL, /* pGetTextCharsetInfo */
3519 NULL, /* pGetTextExtentExPoint */
3520 NULL, /* pGetTextExtentExPointI */
3521 NULL, /* pGetTextFace */
3522 NULL, /* pGetTextMetrics */
3523 NULL, /* pGradientFill */
3524 NULL, /* pIntersectClipRect */
3525 NULL, /* pInvertRgn */
3526 NULL, /* pLineTo */
3527 NULL, /* pModifyWorldTransform */
3528 NULL, /* pMoveTo */
3529 NULL, /* pOffsetClipRgn */
3530 NULL, /* pOffsetViewportOrg */
3531 NULL, /* pOffsetWindowOrg */
3532 NULL, /* pPaintRgn */
3533 NULL, /* pPatBlt */
3534 NULL, /* pPie */
3535 NULL, /* pPolyBezier */
3536 NULL, /* pPolyBezierTo */
3537 NULL, /* pPolyDraw */
3538 NULL, /* pPolyPolygon */
3539 NULL, /* pPolyPolyline */
3540 NULL, /* pPolygon */
3541 NULL, /* pPolyline */
3542 NULL, /* pPolylineTo */
3543 NULL, /* pPutImage */
3544 NULL, /* pRealizeDefaultPalette */
3545 NULL, /* pRealizePalette */
3546 NULL, /* pRectangle */
3547 NULL, /* pResetDC */
3548 NULL, /* pRestoreDC */
3549 NULL, /* pRoundRect */
3550 NULL, /* pSaveDC */
3551 NULL, /* pScaleViewportExt */
3552 NULL, /* pScaleWindowExt */
3553 NULL, /* pSelectBitmap */
3554 NULL, /* pSelectBrush */
3555 NULL, /* pSelectClipPath */
3556 NULL, /* pSelectFont */
3557 NULL, /* pSelectPalette */
3558 NULL, /* pSelectPen */
3559 NULL, /* pSetArcDirection */
3560 NULL, /* pSetBkColor */
3561 NULL, /* pSetBkMode */
3562 NULL, /* pSetBoundsRect */
3563 NULL, /* pSetDCBrushColor */
3564 NULL, /* pSetDCPenColor */
3565 NULL, /* pSetDIBitsToDevice */
3566 NULL, /* pSetDeviceClipping */
3567 NULL, /* pSetDeviceGammaRamp */
3568 NULL, /* pSetLayout */
3569 NULL, /* pSetMapMode */
3570 NULL, /* pSetMapperFlags */
3571 NULL, /* pSetPixel */
3572 glxdrv_SetPixelFormat, /* pSetPixelFormat */
3573 NULL, /* pSetPolyFillMode */
3574 NULL, /* pSetROP2 */
3575 NULL, /* pSetRelAbs */
3576 NULL, /* pSetStretchBltMode */
3577 NULL, /* pSetTextAlign */
3578 NULL, /* pSetTextCharacterExtra */
3579 NULL, /* pSetTextColor */
3580 NULL, /* pSetTextJustification */
3581 NULL, /* pSetViewportExt */
3582 NULL, /* pSetViewportOrg */
3583 NULL, /* pSetWindowExt */
3584 NULL, /* pSetWindowOrg */
3585 NULL, /* pSetWorldTransform */
3586 NULL, /* pStartDoc */
3587 NULL, /* pStartPage */
3588 NULL, /* pStretchBlt */
3589 NULL, /* pStretchDIBits */
3590 NULL, /* pStrokeAndFillPath */
3591 NULL, /* pStrokePath */
3592 glxdrv_SwapBuffers, /* pSwapBuffers */
3593 NULL, /* pUnrealizePalette */
3594 NULL, /* pWidenPath */
3595 glxdrv_wglCreateContext, /* pwglCreateContext */
3596 glxdrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
3597 glxdrv_wglGetProcAddress, /* pwglGetProcAddress */
3598 glxdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
3599 GDI_PRIORITY_GRAPHICS_DRV + 20 /* priority */
3602 static const struct wgl_funcs glxdrv_wgl_funcs =
3604 glxdrv_wglCopyContext, /* p_wglCopyContext */
3605 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3606 glxdrv_wglGetCurrentDC, /* p_wglGetCurrentDC */
3607 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3608 glxdrv_wglShareLists, /* p_wglShareLists */
3611 const struct gdi_dc_funcs *get_glx_driver(void)
3613 return &glxdrv_funcs;
3616 #else /* no OpenGL includes */
3618 const struct gdi_dc_funcs *get_glx_driver(void)
3620 return NULL;
3623 void mark_drawable_dirty(Drawable old, Drawable new)
3627 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3629 return 0;
3633 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3635 return FALSE;
3638 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3640 return NULL;
3643 #endif /* defined(SONAME_LIBGL) */