winex11: Move GLX definitions out of wgl.h.
[wine.git] / dlls / winex11.drv / opengl.c
blob3abb8a589d1867cc6dd3f7204cad3baf7e8fd063
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);
50 WINE_DECLARE_DEBUG_CHANNEL(fps);
52 #undef APIENTRY
53 #undef CALLBACK
54 #undef WINAPI
56 #ifdef HAVE_GL_GL_H
57 # include <GL/gl.h>
58 #endif
59 #ifdef HAVE_GL_GLX_H
60 # include <GL/glx.h>
61 #endif
63 #undef APIENTRY
64 #undef CALLBACK
65 #undef WINAPI
67 /* Redefines the constants */
68 #define CALLBACK __stdcall
69 #define WINAPI __stdcall
70 #define APIENTRY WINAPI
72 #include "wine/wgl.h"
74 /* For compatibility with old Mesa headers */
75 #ifndef GLX_SAMPLE_BUFFERS_ARB
76 # define GLX_SAMPLE_BUFFERS_ARB 100000
77 #endif
78 #ifndef GLX_SAMPLES_ARB
79 # define GLX_SAMPLES_ARB 100001
80 #endif
81 #ifndef GL_TEXTURE_CUBE_MAP
82 # define GL_TEXTURE_CUBE_MAP 0x8513
83 #endif
84 #ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
85 # define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
86 #endif
87 #ifndef GLX_EXT_fbconfig_packed_float
88 # define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
89 # define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
90 #endif
91 #ifndef GLX_ARB_create_context
92 # define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
93 # define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
94 # define GLX_CONTEXT_FLAGS_ARB 0x2094
95 #endif
96 #ifndef GLX_ARB_create_context_profile
97 # define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
98 #endif
99 /** GLX_ATI_pixel_format_float */
100 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
101 /** GLX_ARB_pixel_format_float */
102 #define GLX_RGBA_FLOAT_BIT 0x00000004
103 #define GLX_RGBA_FLOAT_TYPE 0x20B9
104 /** GL_NV_float_buffer */
105 #define GL_FLOAT_R_NV 0x8880
106 #define GL_FLOAT_RG_NV 0x8881
107 #define GL_FLOAT_RGB_NV 0x8882
108 #define GL_FLOAT_RGBA_NV 0x8883
109 #define GL_FLOAT_R16_NV 0x8884
110 #define GL_FLOAT_R32_NV 0x8885
111 #define GL_FLOAT_RG16_NV 0x8886
112 #define GL_FLOAT_RG32_NV 0x8887
113 #define GL_FLOAT_RGB16_NV 0x8888
114 #define GL_FLOAT_RGB32_NV 0x8889
115 #define GL_FLOAT_RGBA16_NV 0x888A
116 #define GL_FLOAT_RGBA32_NV 0x888B
117 #define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C
118 #define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D
119 #define GL_FLOAT_RGBA_MODE_NV 0x888E
120 /** GLX_NV_float_buffer */
121 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
124 typedef struct wine_glextension {
125 const char *extName;
126 struct {
127 const char *funcName;
128 void *funcAddress;
129 } extEntryPoints[9];
130 } WineGLExtension;
132 struct WineGLInfo {
133 const char *glVersion;
134 char *glExtensions;
136 int glxVersion[2];
138 const char *glxServerVersion;
139 const char *glxServerVendor;
140 const char *glxServerExtensions;
142 const char *glxClientVersion;
143 const char *glxClientVendor;
144 const char *glxClientExtensions;
146 const char *glxExtensions;
148 BOOL glxDirect;
149 char wglExtensions[4096];
152 typedef struct wine_glpixelformat {
153 int iPixelFormat;
154 GLXFBConfig fbconfig;
155 int fmt_id;
156 int render_type;
157 BOOL offscreenOnly;
158 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
159 } WineGLPixelFormat;
161 struct wgl_context
163 HDC hdc;
164 BOOL has_been_current;
165 BOOL sharing;
166 BOOL gl3_context;
167 XVisualInfo *vis;
168 WineGLPixelFormat *fmt;
169 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
170 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
171 GLXContext ctx;
172 HDC read_hdc;
173 Drawable drawables[2];
174 BOOL refresh_drawables;
175 Pixmap pixmap; /* pixmap for memory DCs */
176 GLXPixmap glxpixmap; /* GLX pixmap for memory DCs */
177 SIZE pixmap_size; /* pixmap size for memory DCs */
178 struct list entry;
181 typedef struct wine_glpbuffer {
182 Drawable drawable;
183 Display* display;
184 WineGLPixelFormat* fmt;
185 int width;
186 int height;
187 int* attribList;
188 HDC hdc;
190 int use_render_texture; /* This is also the internal texture format */
191 int texture_bind_target;
192 int texture_bpp;
193 GLint texture_format;
194 GLuint texture_target;
195 GLenum texture_type;
196 GLuint texture;
197 int texture_level;
198 } Wine_GLPBuffer;
200 struct glx_physdev
202 struct gdi_physdev dev;
203 X11DRV_PDEVICE *x11dev;
204 enum dc_gl_type type; /* type of GL device context */
205 int pixel_format;
206 Drawable drawable;
207 Pixmap pixmap; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
210 static const struct wgl_funcs glxdrv_wgl_funcs;
211 static const struct gdi_dc_funcs glxdrv_funcs;
213 static inline struct glx_physdev *get_glxdrv_dev( PHYSDEV dev )
215 return (struct glx_physdev *)dev;
218 static struct list context_list = LIST_INIT( context_list );
219 static struct WineGLInfo WineGLInfo = { 0 };
220 static int use_render_texture_emulation = 1;
221 static BOOL has_swap_control;
222 static int swap_interval = 1;
224 #define MAX_EXTENSIONS 16
225 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
226 static int WineGLExtensionListSize;
228 static void X11DRV_WineGL_LoadExtensions(void);
229 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count);
230 static BOOL glxRequireVersion(int requiredVersion);
231 static BOOL glxRequireExtension(const char *requiredExtension);
233 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
234 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
235 TRACE(" - dwFlags : ");
236 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
237 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
238 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
239 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
240 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
241 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
242 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
243 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
244 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
245 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
246 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
247 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
248 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
249 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
250 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
251 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
252 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
253 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
254 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
255 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
256 #undef TEST_AND_DUMP
257 TRACE("\n");
259 TRACE(" - iPixelType : ");
260 switch (ppfd->iPixelType) {
261 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
262 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
264 TRACE("\n");
266 TRACE(" - Color : %d\n", ppfd->cColorBits);
267 TRACE(" - Red : %d\n", ppfd->cRedBits);
268 TRACE(" - Green : %d\n", ppfd->cGreenBits);
269 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
270 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
271 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
272 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
273 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
274 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
276 TRACE(" - iLayerType : ");
277 switch (ppfd->iLayerType) {
278 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
279 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
280 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
282 TRACE("\n");
285 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
286 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
288 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
289 /* GLX 1.0 */
290 MAKE_FUNCPTR(glXChooseVisual)
291 MAKE_FUNCPTR(glXCopyContext)
292 MAKE_FUNCPTR(glXCreateContext)
293 MAKE_FUNCPTR(glXCreateGLXPixmap)
294 MAKE_FUNCPTR(glXGetCurrentContext)
295 MAKE_FUNCPTR(glXGetCurrentDrawable)
296 MAKE_FUNCPTR(glXDestroyContext)
297 MAKE_FUNCPTR(glXDestroyGLXPixmap)
298 MAKE_FUNCPTR(glXGetConfig)
299 MAKE_FUNCPTR(glXIsDirect)
300 MAKE_FUNCPTR(glXMakeCurrent)
301 MAKE_FUNCPTR(glXSwapBuffers)
302 MAKE_FUNCPTR(glXQueryExtension)
303 MAKE_FUNCPTR(glXQueryVersion)
305 /* GLX 1.1 */
306 MAKE_FUNCPTR(glXGetClientString)
307 MAKE_FUNCPTR(glXQueryExtensionsString)
308 MAKE_FUNCPTR(glXQueryServerString)
310 /* GLX 1.3 */
311 MAKE_FUNCPTR(glXGetFBConfigs)
312 MAKE_FUNCPTR(glXChooseFBConfig)
313 MAKE_FUNCPTR(glXCreatePbuffer)
314 MAKE_FUNCPTR(glXCreateNewContext)
315 MAKE_FUNCPTR(glXDestroyPbuffer)
316 MAKE_FUNCPTR(glXGetFBConfigAttrib)
317 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
318 MAKE_FUNCPTR(glXMakeContextCurrent)
319 MAKE_FUNCPTR(glXQueryDrawable)
320 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
322 /* GLX Extensions */
323 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
324 static void* (*pglXGetProcAddressARB)(const GLubyte *);
325 static int (*pglXSwapIntervalSGI)(int);
327 /* NV GLX Extension */
328 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
329 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
331 /* MESA GLX Extensions */
332 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
334 /* Standard OpenGL */
335 MAKE_FUNCPTR(glBindTexture)
336 MAKE_FUNCPTR(glBitmap)
337 MAKE_FUNCPTR(glCopyTexSubImage1D)
338 MAKE_FUNCPTR(glCopyTexImage2D)
339 MAKE_FUNCPTR(glCopyTexSubImage2D)
340 MAKE_FUNCPTR(glDrawBuffer)
341 MAKE_FUNCPTR(glEndList)
342 MAKE_FUNCPTR(glGetError)
343 MAKE_FUNCPTR(glGetIntegerv)
344 MAKE_FUNCPTR(glGetString)
345 MAKE_FUNCPTR(glNewList)
346 MAKE_FUNCPTR(glPixelStorei)
347 MAKE_FUNCPTR(glReadPixels)
348 MAKE_FUNCPTR(glTexImage2D)
349 MAKE_FUNCPTR(glFinish)
350 MAKE_FUNCPTR(glFlush)
351 #undef MAKE_FUNCPTR
353 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
355 /* In the future we might want to find the exact X or GLX error to report back to the app */
356 return 1;
359 static BOOL infoInitialized = FALSE;
360 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
362 int screen = DefaultScreen(gdi_display);
363 Window win = 0, root = 0;
364 const char *gl_renderer;
365 const char* str;
366 XVisualInfo *vis;
367 GLXContext ctx = NULL;
368 XSetWindowAttributes attr;
369 BOOL ret = FALSE;
370 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
372 if (infoInitialized)
373 return TRUE;
374 infoInitialized = TRUE;
376 attr.override_redirect = True;
377 attr.colormap = None;
378 attr.border_pixel = 0;
380 wine_tsx11_lock();
382 vis = pglXChooseVisual(gdi_display, screen, attribList);
383 if (vis) {
384 #ifdef __i386__
385 WORD old_fs = wine_get_fs();
386 /* Create a GLX Context. Without one we can't query GL information */
387 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
388 if (wine_get_fs() != old_fs)
390 wine_set_fs( old_fs );
391 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
392 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
393 goto done;
395 #else
396 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
397 #endif
399 if (!ctx) goto done;
401 root = RootWindow( gdi_display, vis->screen );
402 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
403 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
404 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
405 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
406 XMapWindow( gdi_display, win );
407 else
408 win = root;
410 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
412 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
413 goto done;
415 gl_renderer = (const char *)pglGetString(GL_RENDERER);
416 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
417 str = (const char *) pglGetString(GL_EXTENSIONS);
418 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
419 strcpy(WineGLInfo.glExtensions, str);
421 /* Get the common GLX version supported by GLX client and server ( major/minor) */
422 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
424 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
425 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
426 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
428 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
429 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
430 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
432 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
433 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
435 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
436 TRACE("GL renderer : %s.\n", gl_renderer);
437 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
438 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
439 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
440 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
441 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
442 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
444 if(!WineGLInfo.glxDirect)
446 int fd = ConnectionNumber(gdi_display);
447 struct sockaddr_un uaddr;
448 unsigned int uaddrlen = sizeof(struct sockaddr_un);
450 /* In general indirect rendering on a local X11 server indicates a driver problem.
451 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
453 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
454 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
455 "haven't been installed correctly (using GL renderer %s, version %s).\n",
456 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
458 else
460 /* In general you would expect that if direct rendering is returned, that you receive hardware
461 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
462 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
463 * software rendering, it shows direct rendering.
465 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
466 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
467 * it shows 'Mesa X11'.
469 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
470 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
471 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
472 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
474 ret = TRUE;
476 done:
477 if(vis) XFree(vis);
478 if(ctx) {
479 pglXMakeCurrent(gdi_display, None, NULL);
480 pglXDestroyContext(gdi_display, ctx);
482 if (win != root) XDestroyWindow( gdi_display, win );
483 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
484 wine_tsx11_unlock();
485 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
486 return ret;
489 static BOOL has_opengl(void)
491 static int init_done;
492 static void *opengl_handle;
494 char buffer[200];
495 int error_base, event_base;
497 if (init_done) return (opengl_handle != NULL);
498 init_done = 1;
500 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
501 and include all dependencies */
502 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
503 if (opengl_handle == NULL)
505 ERR( "Failed to load libGL: %s\n", buffer );
506 ERR( "OpenGL support is disabled.\n");
507 return FALSE;
510 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
511 if (pglXGetProcAddressARB == NULL) {
512 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
513 goto failed;
516 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
518 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
519 goto failed; \
520 } while(0)
522 /* GLX 1.0 */
523 LOAD_FUNCPTR(glXChooseVisual);
524 LOAD_FUNCPTR(glXCopyContext);
525 LOAD_FUNCPTR(glXCreateContext);
526 LOAD_FUNCPTR(glXCreateGLXPixmap);
527 LOAD_FUNCPTR(glXGetCurrentContext);
528 LOAD_FUNCPTR(glXGetCurrentDrawable);
529 LOAD_FUNCPTR(glXDestroyContext);
530 LOAD_FUNCPTR(glXDestroyGLXPixmap);
531 LOAD_FUNCPTR(glXGetConfig);
532 LOAD_FUNCPTR(glXIsDirect);
533 LOAD_FUNCPTR(glXMakeCurrent);
534 LOAD_FUNCPTR(glXSwapBuffers);
535 LOAD_FUNCPTR(glXQueryExtension);
536 LOAD_FUNCPTR(glXQueryVersion);
538 /* GLX 1.1 */
539 LOAD_FUNCPTR(glXGetClientString);
540 LOAD_FUNCPTR(glXQueryExtensionsString);
541 LOAD_FUNCPTR(glXQueryServerString);
543 /* GLX 1.3 */
544 LOAD_FUNCPTR(glXCreatePbuffer);
545 LOAD_FUNCPTR(glXCreateNewContext);
546 LOAD_FUNCPTR(glXDestroyPbuffer);
547 LOAD_FUNCPTR(glXMakeContextCurrent);
548 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
549 LOAD_FUNCPTR(glXGetFBConfigs);
551 /* Standard OpenGL calls */
552 LOAD_FUNCPTR(glBindTexture);
553 LOAD_FUNCPTR(glBitmap);
554 LOAD_FUNCPTR(glCopyTexSubImage1D);
555 LOAD_FUNCPTR(glCopyTexImage2D);
556 LOAD_FUNCPTR(glCopyTexSubImage2D);
557 LOAD_FUNCPTR(glDrawBuffer);
558 LOAD_FUNCPTR(glEndList);
559 LOAD_FUNCPTR(glGetError);
560 LOAD_FUNCPTR(glGetIntegerv);
561 LOAD_FUNCPTR(glGetString);
562 LOAD_FUNCPTR(glNewList);
563 LOAD_FUNCPTR(glPixelStorei);
564 LOAD_FUNCPTR(glReadPixels);
565 LOAD_FUNCPTR(glTexImage2D);
566 LOAD_FUNCPTR(glFinish);
567 LOAD_FUNCPTR(glFlush);
568 #undef LOAD_FUNCPTR
570 /* It doesn't matter if these fail. They'll only be used if the driver reports
571 the associated extension is available (and if a driver reports the extension
572 is available but fails to provide the functions, it's quite broken) */
573 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
574 /* ARB GLX Extension */
575 LOAD_FUNCPTR(glXCreateContextAttribsARB);
576 /* SGI GLX Extension */
577 LOAD_FUNCPTR(glXSwapIntervalSGI);
578 /* NV GLX Extension */
579 LOAD_FUNCPTR(glXAllocateMemoryNV);
580 LOAD_FUNCPTR(glXFreeMemoryNV);
581 #undef LOAD_FUNCPTR
583 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
585 wine_tsx11_lock();
586 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
587 TRACE("GLX is up and running error_base = %d\n", error_base);
588 } else {
589 wine_tsx11_unlock();
590 ERR( "GLX extension is missing, disabling OpenGL.\n" );
591 goto failed;
594 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
595 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
596 * rendering is used.
598 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
599 * depends on the reported GLX client / server version and on the client / server extension list.
600 * Those don't have to be the same.
602 * In general the server GLX information lists the capabilities in case of indirect rendering.
603 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
604 * available and in that case the client GLX informat can be used.
605 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
606 * in the GLX version/extension list. When a program does this it works for certain for both
607 * direct and indirect rendering.
609 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
610 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
611 * extension list which causes this extension not to be listed. (Wine requires this extension).
612 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
613 * pbuffers is around.
615 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
616 * the ATI drivers and from then on use GLX client information for them.
619 if(glxRequireVersion(3)) {
620 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
621 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
622 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
623 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
624 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
625 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
626 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
627 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
629 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
630 * enable this function when the Xserver understand GLX 1.3 or newer
632 pglXQueryDrawable = NULL;
633 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
634 TRACE("Overriding ATI GLX capabilities!\n");
635 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
636 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
637 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
638 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
640 /* Use client GLX information in case of the ATI drivers. We override the
641 * capabilities over here and not somewhere else as ATI might better their
642 * life in the future. In case they release proper drivers this block of
643 * code won't be called. */
644 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
645 } else {
646 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
649 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
650 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
653 X11DRV_WineGL_LoadExtensions();
655 wine_tsx11_unlock();
656 return TRUE;
658 failed:
659 wine_dlclose(opengl_handle, NULL, 0);
660 opengl_handle = NULL;
661 return FALSE;
664 static int describeContext( struct wgl_context *ctx ) {
665 int tmp;
666 int ctx_vis_id;
667 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
668 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
669 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
670 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
671 TRACE(" - VISUAL_ID 0x%x\n", tmp);
672 ctx_vis_id = tmp;
673 return ctx_vis_id;
676 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
677 int nAttribs = 0;
678 unsigned cur = 0;
679 int pop;
680 int drawattrib = 0;
681 int nvfloatattrib = GLX_DONT_CARE;
682 int pixelattrib = GLX_DONT_CARE;
684 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
685 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
686 while (iWGLAttr && 0 != iWGLAttr[cur]) {
687 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
689 switch (iWGLAttr[cur]) {
690 case WGL_AUX_BUFFERS_ARB:
691 pop = iWGLAttr[++cur];
692 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
693 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
694 break;
695 case WGL_COLOR_BITS_ARB:
696 pop = iWGLAttr[++cur];
697 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
698 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
699 break;
700 case WGL_BLUE_BITS_ARB:
701 pop = iWGLAttr[++cur];
702 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
703 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
704 break;
705 case WGL_RED_BITS_ARB:
706 pop = iWGLAttr[++cur];
707 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
708 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
709 break;
710 case WGL_GREEN_BITS_ARB:
711 pop = iWGLAttr[++cur];
712 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
713 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
714 break;
715 case WGL_ALPHA_BITS_ARB:
716 pop = iWGLAttr[++cur];
717 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
718 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
719 break;
720 case WGL_DEPTH_BITS_ARB:
721 pop = iWGLAttr[++cur];
722 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
723 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
724 break;
725 case WGL_STENCIL_BITS_ARB:
726 pop = iWGLAttr[++cur];
727 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
728 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
729 break;
730 case WGL_DOUBLE_BUFFER_ARB:
731 pop = iWGLAttr[++cur];
732 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
733 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
734 break;
735 case WGL_STEREO_ARB:
736 pop = iWGLAttr[++cur];
737 PUSH2(oGLXAttr, GLX_STEREO, pop);
738 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
739 break;
741 case WGL_PIXEL_TYPE_ARB:
742 pop = iWGLAttr[++cur];
743 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
744 switch (pop) {
745 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
746 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
747 /* 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 */
748 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
749 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
750 default:
751 ERR("unexpected PixelType(%x)\n", pop);
752 pop = 0;
754 break;
756 case WGL_SUPPORT_GDI_ARB:
757 /* This flag is set in a WineGLPixelFormat */
758 pop = iWGLAttr[++cur];
759 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
760 break;
762 case WGL_DRAW_TO_BITMAP_ARB:
763 /* This flag is set in a WineGLPixelFormat */
764 pop = iWGLAttr[++cur];
765 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
766 break;
768 case WGL_DRAW_TO_WINDOW_ARB:
769 pop = iWGLAttr[++cur];
770 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
771 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
772 if (pop) {
773 drawattrib |= GLX_WINDOW_BIT;
775 break;
777 case WGL_DRAW_TO_PBUFFER_ARB:
778 pop = iWGLAttr[++cur];
779 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
780 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
781 if (pop) {
782 drawattrib |= GLX_PBUFFER_BIT;
784 break;
786 case WGL_ACCELERATION_ARB:
787 /* This flag is set in a WineGLPixelFormat */
788 pop = iWGLAttr[++cur];
789 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
790 break;
792 case WGL_SUPPORT_OPENGL_ARB:
793 pop = iWGLAttr[++cur];
794 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
795 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
796 break;
798 case WGL_SWAP_METHOD_ARB:
799 pop = iWGLAttr[++cur];
800 /* For now we ignore this and just return SWAP_EXCHANGE */
801 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
802 break;
804 case WGL_PBUFFER_LARGEST_ARB:
805 pop = iWGLAttr[++cur];
806 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
807 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
808 break;
810 case WGL_SAMPLE_BUFFERS_ARB:
811 pop = iWGLAttr[++cur];
812 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
813 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
814 break;
816 case WGL_SAMPLES_ARB:
817 pop = iWGLAttr[++cur];
818 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
819 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
820 break;
822 case WGL_TEXTURE_FORMAT_ARB:
823 case WGL_TEXTURE_TARGET_ARB:
824 case WGL_MIPMAP_TEXTURE_ARB:
825 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
826 pop = iWGLAttr[++cur];
827 if (NULL == pbuf) {
828 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
830 if (!use_render_texture_emulation) {
831 if (WGL_NO_TEXTURE_ARB != pop) {
832 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
833 return -1; /** error: don't support it */
834 } else {
835 drawattrib |= GLX_PBUFFER_BIT;
838 break ;
839 case WGL_FLOAT_COMPONENTS_NV:
840 nvfloatattrib = iWGLAttr[++cur];
841 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
842 break ;
843 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
844 case WGL_BIND_TO_TEXTURE_RGB_ARB:
845 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
846 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
847 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
848 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
849 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
850 pop = iWGLAttr[++cur];
851 /** cannot be converted, see direct handling on
852 * - wglGetPixelFormatAttribivARB
853 * TODO: wglChoosePixelFormat
855 break ;
856 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
857 pop = iWGLAttr[++cur];
858 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
859 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
860 break ;
862 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
863 pop = iWGLAttr[++cur];
864 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
865 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
866 break ;
867 default:
868 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
869 break;
871 ++cur;
874 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
875 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
876 * pixmap and pbuffer formats appear as well. */
877 if (!drawattrib) drawattrib = GLX_DONT_CARE;
878 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
879 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
881 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
882 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
883 * GLX_DONT_CARE unless it is overridden. */
884 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
885 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
887 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
888 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
889 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
890 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
893 return nAttribs;
896 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
898 int render_type=0, render_type_bit;
899 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
900 switch(render_type_bit)
902 case GLX_RGBA_BIT:
903 render_type = GLX_RGBA_TYPE;
904 break;
905 case GLX_COLOR_INDEX_BIT:
906 render_type = GLX_COLOR_INDEX_TYPE;
907 break;
908 case GLX_RGBA_FLOAT_BIT:
909 render_type = GLX_RGBA_FLOAT_TYPE;
910 break;
911 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
912 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
913 break;
914 default:
915 ERR("Unknown render_type: %x\n", render_type_bit);
917 return render_type;
920 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
921 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
923 int dbuf, value;
924 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
925 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
927 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
928 * the GLX_PIXMAP_BIT set. */
929 return !dbuf && (value & GLX_PIXMAP_BIT);
932 static WineGLPixelFormat *get_formats(Display *display, int *size_ret, int *onscreen_size_ret)
934 static WineGLPixelFormat *list;
935 static int size, onscreen_size;
937 int fmt_id, nCfgs, i, run, bmp_formats;
938 GLXFBConfig* cfgs;
939 XVisualInfo *visinfo;
941 wine_tsx11_lock();
942 if (list) goto done;
944 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
945 if (NULL == cfgs || 0 == nCfgs) {
946 if(cfgs != NULL) XFree(cfgs);
947 wine_tsx11_unlock();
948 ERR("glXChooseFBConfig returns NULL\n");
949 return NULL;
952 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
953 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
954 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
955 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
957 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
959 for(i=0, bmp_formats=0; i<nCfgs; i++)
961 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
962 bmp_formats++;
964 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
966 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats)*sizeof(WineGLPixelFormat));
968 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
969 * Do this as GLX doesn't guarantee that the list is sorted */
970 for(run=0; run < 2; run++)
972 for(i=0; i<nCfgs; i++) {
973 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
974 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
976 /* The first run we only add onscreen formats (ones which have an associated X Visual).
977 * The second run we only set offscreen formats. */
978 if(!run && visinfo)
980 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
981 * The contents is copied to the destination using XCopyArea. For the copying to work
982 * the depth of the source and destination window should be the same. In general this should
983 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
984 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
985 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
986 * list formats with the same depth. */
987 if(visinfo->depth != screen_depth)
989 XFree(visinfo);
990 continue;
993 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
994 list[size].iPixelFormat = size+1; /* The index starts at 1 */
995 list[size].fbconfig = cfgs[i];
996 list[size].fmt_id = fmt_id;
997 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
998 list[size].offscreenOnly = FALSE;
999 list[size].dwFlags = 0;
1000 size++;
1001 onscreen_size++;
1003 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1004 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1006 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1007 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1008 list[size].fbconfig = cfgs[i];
1009 list[size].fmt_id = fmt_id;
1010 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1011 list[size].offscreenOnly = FALSE;
1012 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1013 size++;
1014 onscreen_size++;
1016 } else if(run && !visinfo) {
1017 int window_drawable=0;
1018 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1020 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1021 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1022 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1023 * likely make our child window opengl rendering more complicated since likely you can't use
1024 * XCopyArea on a GLX Window.
1025 * For now ignore fbconfigs which are window drawable but lack a visual. */
1026 if(window_drawable & GLX_WINDOW_BIT)
1028 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1029 continue;
1032 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1033 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1034 list[size].fbconfig = cfgs[i];
1035 list[size].fmt_id = fmt_id;
1036 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1037 list[size].offscreenOnly = TRUE;
1038 list[size].dwFlags = 0;
1039 size++;
1042 if (visinfo) XFree(visinfo);
1046 XFree(cfgs);
1048 done:
1049 if (size_ret) *size_ret = size;
1050 if (onscreen_size_ret) *onscreen_size_ret = onscreen_size;
1051 wine_tsx11_unlock();
1052 return list;
1055 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1056 * In our WGL implementation we only support a subset of these formats namely the format of
1057 * Wine's main visual and offscreen formats (if they are available).
1058 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1059 * and it returns the number of supported WGL formats in fmt_count.
1061 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
1063 WineGLPixelFormat *list, *res = NULL;
1064 int size, onscreen_size;
1066 if (!(list = get_formats(display, &size, &onscreen_size ))) return NULL;
1068 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1069 * iPixelFormat in case of probing the number of pixelformats.
1071 if((iPixelFormat > 0) && (iPixelFormat <= size) &&
1072 (!list[iPixelFormat-1].offscreenOnly || AllowOffscreen)) {
1073 res = &list[iPixelFormat-1];
1074 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res->fmt_id, iPixelFormat);
1077 if(AllowOffscreen)
1078 *fmt_count = size;
1079 else
1080 *fmt_count = onscreen_size;
1082 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
1084 return res;
1087 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1088 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id, DWORD dwFlags)
1090 WineGLPixelFormat *list;
1091 int i, size;
1093 if (!(list = get_formats(display, &size, NULL ))) return NULL;
1095 for(i=0; i<size; i++) {
1096 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1097 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1098 if( (list[i].fmt_id == fmt_id) && ((list[i].dwFlags & dwFlags) == dwFlags) ) {
1099 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list[i].iPixelFormat, fmt_id);
1100 return &list[i];
1103 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
1104 return NULL;
1107 static int pixelformat_from_fbconfig_id(XID fbconfig_id)
1109 WineGLPixelFormat *fmt;
1111 if (!fbconfig_id) return 0;
1113 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
1114 if(fmt)
1115 return fmt->iPixelFormat;
1116 /* This will happen on hwnds without a pixel format set; it's ok */
1117 return 0;
1121 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1122 void mark_drawable_dirty(Drawable old, Drawable new)
1124 struct wgl_context *ctx;
1125 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
1127 if (old == ctx->drawables[0]) {
1128 ctx->drawables[0] = new;
1129 ctx->refresh_drawables = TRUE;
1131 if (old == ctx->drawables[1]) {
1132 ctx->drawables[1] = new;
1133 ctx->refresh_drawables = TRUE;
1138 /* Given the current context, make sure its drawable is sync'd */
1139 static inline void sync_context(struct wgl_context *context)
1141 if(context && context->refresh_drawables) {
1142 if (glxRequireVersion(3))
1143 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1144 context->drawables[1], context->ctx);
1145 else
1146 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1147 context->refresh_drawables = FALSE;
1152 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1154 GLXContext ctx;
1156 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1157 BOOL indirect = (context->fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? FALSE : TRUE;
1159 if(context->gl3_context)
1161 if(context->numAttribs)
1162 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1163 else
1164 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1166 else if(context->vis)
1167 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1168 else /* Create a GLX Context for a pbuffer */
1169 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1171 return ctx;
1175 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1177 return pglXCreateGLXPixmap(display, vis, parent);
1182 * glxdrv_DescribePixelFormat
1184 * Get the pixel-format descriptor associated to the given id
1186 static int glxdrv_DescribePixelFormat(PHYSDEV dev, int iPixelFormat,
1187 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1189 /*XVisualInfo *vis;*/
1190 int value;
1191 int rb,gb,bb,ab;
1192 WineGLPixelFormat *fmt;
1193 int ret = 0;
1194 int fmt_count = 0;
1196 if (!has_opengl()) return 0;
1198 TRACE("(%p,%d,%d,%p)\n", dev->hdc, iPixelFormat, nBytes, ppfd);
1200 /* 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 */
1201 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1202 if (ppfd == NULL) {
1203 /* The application is only querying the number of pixelformats */
1204 return fmt_count;
1205 } else if(fmt == NULL) {
1206 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1207 return 0;
1210 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1211 ERR("Wrong structure size !\n");
1212 /* Should set error */
1213 return 0;
1216 ret = fmt_count;
1218 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1219 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1220 ppfd->nVersion = 1;
1222 /* These flags are always the same... */
1223 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1224 /* Now the flags extracted from the Visual */
1226 wine_tsx11_lock();
1228 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1229 if(value & GLX_WINDOW_BIT)
1230 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1232 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1233 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1234 * 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
1235 * offered the GDI bit either. */
1236 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1238 /* PFD_GENERIC_FORMAT - gdi software rendering
1239 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1240 * none set - full hardware accelerated by a ICD
1242 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1243 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1245 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1246 if (value) {
1247 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1248 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1250 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1252 /* Pixel type */
1253 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1254 if (value & GLX_RGBA_BIT)
1255 ppfd->iPixelType = PFD_TYPE_RGBA;
1256 else
1257 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1259 /* Color bits */
1260 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1261 ppfd->cColorBits = value;
1263 /* Red, green, blue and alpha bits / shifts */
1264 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1265 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1266 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1267 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1268 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1270 ppfd->cRedBits = rb;
1271 ppfd->cRedShift = gb + bb + ab;
1272 ppfd->cBlueBits = bb;
1273 ppfd->cBlueShift = ab;
1274 ppfd->cGreenBits = gb;
1275 ppfd->cGreenShift = bb + ab;
1276 ppfd->cAlphaBits = ab;
1277 ppfd->cAlphaShift = 0;
1278 } else {
1279 ppfd->cRedBits = 0;
1280 ppfd->cRedShift = 0;
1281 ppfd->cBlueBits = 0;
1282 ppfd->cBlueShift = 0;
1283 ppfd->cGreenBits = 0;
1284 ppfd->cGreenShift = 0;
1285 ppfd->cAlphaBits = 0;
1286 ppfd->cAlphaShift = 0;
1289 /* Accum RGBA bits */
1290 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1291 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1292 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1293 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1295 ppfd->cAccumBits = rb+gb+bb+ab;
1296 ppfd->cAccumRedBits = rb;
1297 ppfd->cAccumGreenBits = gb;
1298 ppfd->cAccumBlueBits = bb;
1299 ppfd->cAccumAlphaBits = ab;
1301 /* Aux bits */
1302 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1303 ppfd->cAuxBuffers = value;
1305 /* Depth bits */
1306 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1307 ppfd->cDepthBits = value;
1309 /* stencil bits */
1310 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1311 ppfd->cStencilBits = value;
1313 wine_tsx11_unlock();
1315 ppfd->iLayerType = PFD_MAIN_PLANE;
1317 if (TRACE_ON(wgl)) {
1318 dump_PIXELFORMATDESCRIPTOR(ppfd);
1321 return ret;
1324 /***********************************************************************
1325 * glxdrv_GetPixelFormat
1327 static int glxdrv_GetPixelFormat( HDC hdc )
1329 struct x11drv_escape_get_drawable escape;
1330 WineGLPixelFormat *fmt;
1331 int tmp;
1333 TRACE( "(%p)\n", hdc );
1335 escape.code = X11DRV_GET_DRAWABLE;
1336 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1337 sizeof(escape), (LPSTR)&escape ))
1338 return 0;
1340 if (!escape.pixel_format) return 0; /* not set yet */
1342 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, escape.pixel_format, TRUE, &tmp);
1343 if (!fmt)
1345 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", escape.pixel_format);
1346 return 0;
1348 if (fmt->offscreenOnly)
1350 /* Offscreen formats can't be used with traditional WGL calls.
1351 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1352 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1353 return 1;
1355 TRACE("(%p): returns %d\n", hdc, escape.pixel_format);
1356 return escape.pixel_format;
1359 /***********************************************************************
1360 * glxdrv_SetPixelFormat
1362 static BOOL glxdrv_SetPixelFormat(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
1364 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1365 WineGLPixelFormat *fmt;
1366 int value;
1367 HWND hwnd;
1369 TRACE("(%p,%d,%p)\n", dev->hdc, iPixelFormat, ppfd);
1371 if (!has_opengl()) return FALSE;
1373 if(physdev->pixel_format) /* cannot change it if already set */
1374 return (physdev->pixel_format == iPixelFormat);
1376 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1377 if(physdev->x11dev->drawable == root_window)
1379 ERR("Invalid operation on root_window\n");
1380 return FALSE;
1383 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1384 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1385 if(!fmt) {
1386 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1387 return FALSE;
1390 wine_tsx11_lock();
1391 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1392 wine_tsx11_unlock();
1394 hwnd = WindowFromDC(physdev->dev.hdc);
1395 if(hwnd) {
1396 if(!(value&GLX_WINDOW_BIT)) {
1397 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1398 return FALSE;
1401 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1402 ERR("Couldn't set format of the window, returning failure\n");
1403 return FALSE;
1405 /* physDev->current_pf will be set by the DCE update */
1407 else if (GetObjectType( physdev->dev.hdc ) == OBJ_MEMDC) {
1408 if(!(value&GLX_PIXMAP_BIT)) {
1409 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1410 return FALSE;
1413 physdev->pixel_format = iPixelFormat;
1414 physdev->type = DC_GL_BITMAP;
1416 else {
1417 FIXME("called on a non-window, non-bitmap object?\n");
1420 if (TRACE_ON(wgl)) {
1421 int gl_test = 0;
1423 wine_tsx11_lock();
1424 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1425 if (gl_test) {
1426 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1427 } else {
1428 TRACE(" FBConfig have :\n");
1429 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1430 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1431 TRACE(" - VISUAL_ID 0x%x\n", value);
1432 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1433 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1435 wine_tsx11_unlock();
1437 return TRUE;
1440 /***********************************************************************
1441 * glxdrv_wglCopyContext
1443 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1445 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1447 wine_tsx11_lock();
1448 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1449 wine_tsx11_unlock();
1451 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1452 return TRUE;
1455 /***********************************************************************
1456 * glxdrv_wglCreateContext
1458 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1460 struct x11drv_escape_get_drawable escape;
1461 struct wgl_context *ret;
1462 WineGLPixelFormat *fmt;
1463 int fmt_count = 0;
1465 TRACE( "(%p)\n", hdc );
1467 escape.code = X11DRV_GET_DRAWABLE;
1468 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1469 sizeof(escape), (LPSTR)&escape ))
1470 return 0;
1472 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, escape.pixel_format, TRUE /* Offscreen */, &fmt_count);
1473 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1474 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1475 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1476 * If this fails something is very wrong on the system. */
1477 if(!fmt) {
1478 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape.pixel_format);
1479 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1480 return NULL;
1483 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1485 ret->hdc = hdc;
1486 ret->fmt = fmt;
1487 ret->has_been_current = FALSE;
1488 ret->sharing = FALSE;
1490 wine_tsx11_lock();
1491 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1492 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1493 list_add_head( &context_list, &ret->entry );
1494 wine_tsx11_unlock();
1496 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1497 return ret;
1500 /***********************************************************************
1501 * glxdrv_wglDeleteContext
1503 static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
1505 TRACE("(%p)\n", ctx);
1507 wine_tsx11_lock();
1508 list_remove( &ctx->entry );
1509 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1510 if (ctx->glxpixmap) pglXDestroyGLXPixmap( gdi_display, ctx->glxpixmap );
1511 if (ctx->pixmap) XFreePixmap( gdi_display, ctx->pixmap );
1512 if (ctx->vis) XFree( ctx->vis );
1513 wine_tsx11_unlock();
1515 HeapFree( GetProcessHeap(), 0, ctx );
1519 * X11DRV_wglGetCurrentReadDCARB
1521 * For OpenGL32 wglGetCurrentReadDCARB.
1523 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1525 HDC ret = 0;
1526 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1528 if (ctx) ret = ctx->read_hdc;
1530 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1531 return ret;
1534 /***********************************************************************
1535 * glxdrv_wglGetProcAddress
1537 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1539 int i, j;
1540 const WineGLExtension *ext;
1542 int padding = 32 - strlen(lpszProc);
1543 if (padding < 0)
1544 padding = 0;
1546 /* Check the table of WGL extensions to see if we need to return a WGL extension
1547 * or a function pointer to a native OpenGL function. */
1548 if(strncmp(lpszProc, "wgl", 3) != 0) {
1549 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1550 } else {
1551 TRACE("('%s'):%*s", lpszProc, padding, " ");
1552 for (i = 0; i < WineGLExtensionListSize; ++i) {
1553 ext = WineGLExtensionList[i];
1554 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1555 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1556 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1557 return ext->extEntryPoints[j].funcAddress;
1563 WARN("(%s) - not found\n", lpszProc);
1564 return NULL;
1567 static GLXPixmap get_context_pixmap( HDC hdc, struct wgl_context *ctx )
1569 if (!ctx->pixmap)
1571 BITMAP bmp;
1573 GetObjectW( GetCurrentObject( hdc, OBJ_BITMAP ), sizeof(bmp), &bmp );
1575 wine_tsx11_lock();
1576 ctx->pixmap = XCreatePixmap( gdi_display, root_window,
1577 bmp.bmWidth, bmp.bmHeight, ctx->vis->depth );
1578 ctx->glxpixmap = pglXCreateGLXPixmap( gdi_display, ctx->vis, ctx->pixmap );
1579 wine_tsx11_unlock();
1580 ctx->pixmap_size.cx = bmp.bmWidth;
1581 ctx->pixmap_size.cy = bmp.bmHeight;
1583 return ctx->glxpixmap;
1586 /***********************************************************************
1587 * glxdrv_wglMakeCurrent
1589 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1591 BOOL ret;
1592 struct x11drv_escape_get_drawable escape;
1594 TRACE("(%p,%p)\n", hdc, ctx);
1596 if (!ctx)
1598 wine_tsx11_lock();
1599 ret = pglXMakeCurrent(gdi_display, None, NULL);
1600 wine_tsx11_unlock();
1601 NtCurrentTeb()->glContext = NULL;
1602 return TRUE;
1605 escape.code = X11DRV_GET_DRAWABLE;
1606 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1607 sizeof(escape), (LPSTR)&escape ))
1608 return FALSE;
1610 if (!escape.pixel_format)
1612 WARN("Trying to use an invalid drawable\n");
1613 SetLastError(ERROR_INVALID_HANDLE);
1614 return FALSE;
1616 if (ctx->fmt->iPixelFormat != escape.pixel_format)
1618 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1619 hdc, escape.pixel_format, ctx, ctx->fmt->iPixelFormat );
1620 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1621 return FALSE;
1623 else
1625 if (escape.gl_type == DC_GL_BITMAP) escape.drawable = get_context_pixmap( hdc, ctx );
1627 wine_tsx11_lock();
1629 if (TRACE_ON(wgl)) {
1630 int vis_id;
1631 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &vis_id);
1632 describeContext(ctx);
1633 TRACE("hdc %p drawable %lx fmt %u vis %x ctx %p\n", hdc,
1634 escape.drawable, escape.pixel_format, vis_id, ctx->ctx);
1637 ret = pglXMakeCurrent(gdi_display, escape.drawable, ctx->ctx);
1639 if (ret)
1641 NtCurrentTeb()->glContext = ctx;
1643 ctx->has_been_current = TRUE;
1644 ctx->hdc = hdc;
1645 ctx->read_hdc = hdc;
1646 ctx->drawables[0] = escape.drawable;
1647 ctx->drawables[1] = escape.drawable;
1648 ctx->refresh_drawables = FALSE;
1650 if (escape.gl_type == DC_GL_BITMAP) pglDrawBuffer(GL_FRONT_LEFT);
1652 else
1653 SetLastError(ERROR_INVALID_HANDLE);
1654 wine_tsx11_unlock();
1656 TRACE(" returning %s\n", (ret ? "True" : "False"));
1657 return ret;
1660 /***********************************************************************
1661 * glxdrv_wglMakeContextCurrentARB
1663 static BOOL glxdrv_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1665 struct x11drv_escape_get_drawable escape_draw, escape_read;
1666 BOOL ret;
1668 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1670 if (!ctx)
1672 wine_tsx11_lock();
1673 ret = pglXMakeCurrent(gdi_display, None, NULL);
1674 wine_tsx11_unlock();
1675 NtCurrentTeb()->glContext = NULL;
1676 return TRUE;
1679 escape_draw.code = X11DRV_GET_DRAWABLE;
1680 if (!ExtEscape( draw_hdc, X11DRV_ESCAPE, sizeof(escape_draw.code), (LPCSTR)&escape_draw.code,
1681 sizeof(escape_draw), (LPSTR)&escape_draw ))
1682 return FALSE;
1684 escape_read.code = X11DRV_GET_DRAWABLE;
1685 if (!ExtEscape( read_hdc, X11DRV_ESCAPE, sizeof(escape_read.code), (LPCSTR)&escape_read.code,
1686 sizeof(escape_read), (LPSTR)&escape_read ))
1687 return FALSE;
1689 if (!escape_draw.pixel_format)
1691 WARN("Trying to use an invalid drawable\n");
1692 SetLastError(ERROR_INVALID_HANDLE);
1693 return FALSE;
1695 else
1697 if (!pglXMakeContextCurrent) return FALSE;
1699 if (escape_draw.gl_type == DC_GL_BITMAP) escape_draw.drawable = get_context_pixmap( draw_hdc, ctx );
1700 if (escape_read.gl_type == DC_GL_BITMAP) escape_read.drawable = get_context_pixmap( read_hdc, ctx );
1702 wine_tsx11_lock();
1703 ret = pglXMakeContextCurrent(gdi_display, escape_draw.drawable, escape_read.drawable, ctx->ctx);
1704 if (ret)
1706 ctx->has_been_current = TRUE;
1707 ctx->hdc = draw_hdc;
1708 ctx->read_hdc = read_hdc;
1709 ctx->drawables[0] = escape_draw.drawable;
1710 ctx->drawables[1] = escape_read.drawable;
1711 ctx->refresh_drawables = FALSE;
1712 NtCurrentTeb()->glContext = ctx;
1714 else
1715 SetLastError(ERROR_INVALID_HANDLE);
1716 wine_tsx11_unlock();
1719 TRACE(" returning %s\n", (ret ? "True" : "False"));
1720 return ret;
1723 /***********************************************************************
1724 * glxdrv_wglShareLists
1726 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1728 TRACE("(%p, %p)\n", org, dest);
1730 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1731 * at context creation time but in case of WGL it is done using wglShareLists.
1732 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1733 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1734 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1735 * so there delaying context creation doesn't work.
1737 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1738 * and when a program requests sharing we recreate the destination context if it hasn't been made
1739 * current or when it hasn't shared display lists before.
1742 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1744 ERR("Could not share display lists, one of the contexts has been current already !\n");
1745 return FALSE;
1747 else if(dest->sharing)
1749 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1750 return FALSE;
1752 else
1754 if((GetObjectType(org->hdc) == OBJ_MEMDC) ^ (GetObjectType(dest->hdc) == OBJ_MEMDC))
1756 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1759 wine_tsx11_lock();
1760 describeContext(org);
1761 describeContext(dest);
1763 /* Re-create the GLX context and share display lists */
1764 pglXDestroyContext(gdi_display, dest->ctx);
1765 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1766 wine_tsx11_unlock();
1767 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1769 org->sharing = TRUE;
1770 dest->sharing = TRUE;
1771 return TRUE;
1773 return FALSE;
1776 /***********************************************************************
1777 * glxdrv_wglGetCurrentDC
1779 static HDC glxdrv_wglGetCurrentDC( struct wgl_context *ctx )
1781 TRACE("hdc %p\n", ctx->hdc);
1782 return ctx->hdc;
1785 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1786 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
1788 wine_tsx11_lock();
1789 switch(pname)
1791 case GL_DEPTH_BITS:
1793 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1795 pglGetIntegerv(pname, params);
1797 * if we cannot find a Wine Context
1798 * we only have the default wine desktop context,
1799 * so if we have only a 24 depth say we have 32
1801 if (!ctx && *params == 24) {
1802 *params = 32;
1804 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1805 break;
1807 case GL_ALPHA_BITS:
1809 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1811 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
1812 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
1813 break;
1815 default:
1816 pglGetIntegerv(pname, params);
1817 break;
1819 wine_tsx11_unlock();
1822 static void flush_pixmap( struct wgl_context *ctx )
1824 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1825 BITMAPINFO *info = (BITMAPINFO *)buffer;
1826 struct gdi_image_bits bits;
1828 if (!get_pixmap_image( ctx->pixmap, ctx->pixmap_size.cx, ctx->pixmap_size.cy, ctx->vis, info, &bits ))
1830 HBITMAP bitmap = GetCurrentObject( ctx->hdc, OBJ_BITMAP );
1831 SetDIBits( 0, bitmap, 0, ctx->pixmap_size.cy, bits.ptr, info, DIB_RGB_COLORS );
1832 if (bits.free) bits.free( &bits );
1836 static void flush_gl_drawable( struct glx_physdev *physdev )
1838 RECT rect;
1839 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
1840 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
1841 Drawable src = physdev->drawable;
1843 if (w <= 0 || h <= 0) return;
1845 switch (physdev->type)
1847 case DC_GL_PIXMAP_WIN:
1848 src = physdev->pixmap;
1849 /* fall through */
1850 case DC_GL_CHILD_WIN:
1851 /* The GL drawable may be lagged behind if we don't flush first, so
1852 * flush the display make sure we copy up-to-date data */
1853 wine_tsx11_lock();
1854 XFlush(gdi_display);
1855 XSetFunction(gdi_display, physdev->x11dev->gc, GXcopy);
1856 XCopyArea(gdi_display, src, physdev->x11dev->drawable, physdev->x11dev->gc, 0, 0, w, h,
1857 physdev->x11dev->dc_rect.left, physdev->x11dev->dc_rect.top);
1858 wine_tsx11_unlock();
1859 SetRect( &rect, 0, 0, w, h );
1860 add_device_bounds( physdev->x11dev, &rect );
1861 default:
1862 break;
1867 static void WINAPI X11DRV_wglFinish(void)
1869 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1870 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1872 wine_tsx11_lock();
1873 sync_context(ctx);
1874 pglFinish();
1875 wine_tsx11_unlock();
1876 if (ctx)
1878 if (ctx->pixmap) flush_pixmap( ctx );
1879 else ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1883 static void WINAPI X11DRV_wglFlush(void)
1885 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1886 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1888 wine_tsx11_lock();
1889 sync_context(ctx);
1890 pglFlush();
1891 wine_tsx11_unlock();
1892 if (ctx)
1894 if (ctx->pixmap) flush_pixmap( ctx );
1895 else ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1899 /***********************************************************************
1900 * glxdrv_wglCreateContextAttribsARB
1902 static struct wgl_context *glxdrv_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
1903 const int* attribList )
1905 struct x11drv_escape_get_drawable escape;
1906 struct wgl_context *ret;
1907 WineGLPixelFormat *fmt;
1908 int fmt_count = 0;
1910 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
1912 escape.code = X11DRV_GET_DRAWABLE;
1913 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1914 sizeof(escape), (LPSTR)&escape ))
1915 return 0;
1917 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, escape.pixel_format, TRUE /* Offscreen */, &fmt_count);
1918 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
1919 * If this fails something is very wrong on the system. */
1920 if(!fmt)
1922 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape.pixel_format);
1923 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1924 return NULL;
1927 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1929 ret->hdc = hdc;
1930 ret->fmt = fmt;
1931 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1932 ret->gl3_context = TRUE;
1934 ret->numAttribs = 0;
1935 if(attribList)
1937 int *pAttribList = (int*)attribList;
1938 int *pContextAttribList = &ret->attribList[0];
1939 /* attribList consists of pairs {token, value] terminated with 0 */
1940 while(pAttribList[0] != 0)
1942 TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]);
1943 switch(pAttribList[0])
1945 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1946 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1947 pContextAttribList[1] = pAttribList[1];
1948 break;
1949 case WGL_CONTEXT_MINOR_VERSION_ARB:
1950 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1951 pContextAttribList[1] = pAttribList[1];
1952 break;
1953 case WGL_CONTEXT_LAYER_PLANE_ARB:
1954 break;
1955 case WGL_CONTEXT_FLAGS_ARB:
1956 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1957 pContextAttribList[1] = pAttribList[1];
1958 break;
1959 case WGL_CONTEXT_PROFILE_MASK_ARB:
1960 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1961 pContextAttribList[1] = pAttribList[1];
1962 break;
1963 default:
1964 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]);
1967 ret->numAttribs++;
1968 pAttribList += 2;
1969 pContextAttribList += 2;
1973 wine_tsx11_lock();
1974 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1975 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1977 XSync(gdi_display, False);
1978 if(X11DRV_check_error() || !ret->ctx)
1980 /* In the future we should convert the GLX error to a win32 one here if needed */
1981 ERR("Context creation failed\n");
1982 HeapFree( GetProcessHeap(), 0, ret );
1983 wine_tsx11_unlock();
1984 return NULL;
1987 list_add_head( &context_list, &ret->entry );
1988 wine_tsx11_unlock();
1989 TRACE(" creating context %p\n", ret);
1990 return ret;
1994 * X11DRV_wglGetExtensionsStringARB
1996 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1998 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
1999 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2000 return WineGLInfo.wglExtensions;
2004 * X11DRV_wglCreatePbufferARB
2006 * WGL_ARB_pbuffer: wglCreatePbufferARB
2008 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2010 Wine_GLPBuffer* object = NULL;
2011 WineGLPixelFormat *fmt = NULL;
2012 int nCfgs = 0;
2013 int attribs[256];
2014 int nAttribs = 0;
2016 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2018 if (0 >= iPixelFormat) {
2019 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2020 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2021 return NULL; /* unexpected error */
2024 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2025 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2026 if(!fmt) {
2027 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2028 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2029 goto create_failed; /* unexpected error */
2032 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2033 if (NULL == object) {
2034 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2035 goto create_failed; /* unexpected error */
2037 object->hdc = hdc;
2038 object->display = gdi_display;
2039 object->width = iWidth;
2040 object->height = iHeight;
2041 object->fmt = fmt;
2043 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2044 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2045 while (piAttribList && 0 != *piAttribList) {
2046 int attr_v;
2047 switch (*piAttribList) {
2048 case WGL_PBUFFER_LARGEST_ARB: {
2049 ++piAttribList;
2050 attr_v = *piAttribList;
2051 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2052 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2053 break;
2056 case WGL_TEXTURE_FORMAT_ARB: {
2057 ++piAttribList;
2058 attr_v = *piAttribList;
2059 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2060 if (WGL_NO_TEXTURE_ARB == attr_v) {
2061 object->use_render_texture = 0;
2062 } else {
2063 if (!use_render_texture_emulation) {
2064 SetLastError(ERROR_INVALID_DATA);
2065 goto create_failed;
2067 switch (attr_v) {
2068 case WGL_TEXTURE_RGB_ARB:
2069 object->use_render_texture = GL_RGB;
2070 object->texture_bpp = 3;
2071 object->texture_format = GL_RGB;
2072 object->texture_type = GL_UNSIGNED_BYTE;
2073 break;
2074 case WGL_TEXTURE_RGBA_ARB:
2075 object->use_render_texture = GL_RGBA;
2076 object->texture_bpp = 4;
2077 object->texture_format = GL_RGBA;
2078 object->texture_type = GL_UNSIGNED_BYTE;
2079 break;
2081 /* WGL_FLOAT_COMPONENTS_NV */
2082 case WGL_TEXTURE_FLOAT_R_NV:
2083 object->use_render_texture = GL_FLOAT_R_NV;
2084 object->texture_bpp = 4;
2085 object->texture_format = GL_RED;
2086 object->texture_type = GL_FLOAT;
2087 break;
2088 case WGL_TEXTURE_FLOAT_RG_NV:
2089 object->use_render_texture = GL_FLOAT_RG_NV;
2090 object->texture_bpp = 8;
2091 object->texture_format = GL_LUMINANCE_ALPHA;
2092 object->texture_type = GL_FLOAT;
2093 break;
2094 case WGL_TEXTURE_FLOAT_RGB_NV:
2095 object->use_render_texture = GL_FLOAT_RGB_NV;
2096 object->texture_bpp = 12;
2097 object->texture_format = GL_RGB;
2098 object->texture_type = GL_FLOAT;
2099 break;
2100 case WGL_TEXTURE_FLOAT_RGBA_NV:
2101 object->use_render_texture = GL_FLOAT_RGBA_NV;
2102 object->texture_bpp = 16;
2103 object->texture_format = GL_RGBA;
2104 object->texture_type = GL_FLOAT;
2105 break;
2106 default:
2107 ERR("Unknown texture format: %x\n", attr_v);
2108 SetLastError(ERROR_INVALID_DATA);
2109 goto create_failed;
2112 break;
2115 case WGL_TEXTURE_TARGET_ARB: {
2116 ++piAttribList;
2117 attr_v = *piAttribList;
2118 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2119 if (WGL_NO_TEXTURE_ARB == attr_v) {
2120 object->texture_target = 0;
2121 } else {
2122 if (!use_render_texture_emulation) {
2123 SetLastError(ERROR_INVALID_DATA);
2124 goto create_failed;
2126 switch (attr_v) {
2127 case WGL_TEXTURE_CUBE_MAP_ARB: {
2128 if (iWidth != iHeight) {
2129 SetLastError(ERROR_INVALID_DATA);
2130 goto create_failed;
2132 object->texture_target = GL_TEXTURE_CUBE_MAP;
2133 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2134 break;
2136 case WGL_TEXTURE_1D_ARB: {
2137 if (1 != iHeight) {
2138 SetLastError(ERROR_INVALID_DATA);
2139 goto create_failed;
2141 object->texture_target = GL_TEXTURE_1D;
2142 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2143 break;
2145 case WGL_TEXTURE_2D_ARB: {
2146 object->texture_target = GL_TEXTURE_2D;
2147 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2148 break;
2150 case WGL_TEXTURE_RECTANGLE_NV: {
2151 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2152 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2153 break;
2155 default:
2156 ERR("Unknown texture target: %x\n", attr_v);
2157 SetLastError(ERROR_INVALID_DATA);
2158 goto create_failed;
2161 break;
2164 case WGL_MIPMAP_TEXTURE_ARB: {
2165 ++piAttribList;
2166 attr_v = *piAttribList;
2167 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2168 if (!use_render_texture_emulation) {
2169 SetLastError(ERROR_INVALID_DATA);
2170 goto create_failed;
2172 break;
2175 ++piAttribList;
2178 PUSH1(attribs, None);
2179 wine_tsx11_lock();
2180 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2181 wine_tsx11_unlock();
2182 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2183 if (!object->drawable) {
2184 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2185 goto create_failed; /* unexpected error */
2187 TRACE("->(%p)\n", object);
2188 return (HPBUFFERARB)object;
2190 create_failed:
2191 HeapFree(GetProcessHeap(), 0, object);
2192 TRACE("->(FAILED)\n");
2193 return NULL;
2197 * X11DRV_wglDestroyPbufferARB
2199 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2201 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2203 Wine_GLPBuffer* object = (Wine_GLPBuffer *)hPbuffer;
2204 TRACE("(%p)\n", hPbuffer);
2205 if (NULL == object) {
2206 SetLastError(ERROR_INVALID_HANDLE);
2207 return GL_FALSE;
2209 wine_tsx11_lock();
2210 pglXDestroyPbuffer(object->display, object->drawable);
2211 wine_tsx11_unlock();
2212 HeapFree(GetProcessHeap(), 0, object);
2213 return GL_TRUE;
2217 * X11DRV_wglGetPbufferDCARB
2219 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2221 static HDC WINAPI X11DRV_wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
2223 struct x11drv_escape_set_drawable escape;
2224 Wine_GLPBuffer* object = (Wine_GLPBuffer *)hPbuffer;
2225 HDC hdc;
2227 if (NULL == object) {
2228 SetLastError(ERROR_INVALID_HANDLE);
2229 return NULL;
2232 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2233 if (!hdc) return 0;
2235 escape.code = X11DRV_SET_DRAWABLE;
2236 escape.drawable = object->drawable;
2237 escape.mode = IncludeInferiors;
2238 SetRect( &escape.drawable_rect, 0, 0, object->width, object->height );
2239 escape.dc_rect = escape.drawable_rect;
2240 escape.fbconfig_id = object->fmt->fmt_id;
2241 escape.gl_drawable = object->drawable;
2242 escape.pixmap = 0;
2243 escape.gl_type = DC_GL_PBUFFER;
2244 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2246 TRACE( "(%p)->(%p)\n", hPbuffer, hdc );
2247 return hdc;
2251 * X11DRV_wglQueryPbufferARB
2253 * WGL_ARB_pbuffer: wglQueryPbufferARB
2255 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2257 Wine_GLPBuffer* object = (Wine_GLPBuffer *)hPbuffer;
2258 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2259 if (NULL == object) {
2260 SetLastError(ERROR_INVALID_HANDLE);
2261 return GL_FALSE;
2263 switch (iAttribute) {
2264 case WGL_PBUFFER_WIDTH_ARB:
2265 wine_tsx11_lock();
2266 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2267 wine_tsx11_unlock();
2268 break;
2269 case WGL_PBUFFER_HEIGHT_ARB:
2270 wine_tsx11_lock();
2271 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2272 wine_tsx11_unlock();
2273 break;
2275 case WGL_PBUFFER_LOST_ARB:
2276 /* GLX Pbuffers cannot be lost by default. We can support this by
2277 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2278 * to receive pixel buffer clobber events, however that may or may
2279 * not give any benefit */
2280 *piValue = GL_FALSE;
2281 break;
2283 case WGL_TEXTURE_FORMAT_ARB:
2284 if (!object->use_render_texture) {
2285 *piValue = WGL_NO_TEXTURE_ARB;
2286 } else {
2287 if (!use_render_texture_emulation) {
2288 SetLastError(ERROR_INVALID_HANDLE);
2289 return GL_FALSE;
2291 switch(object->use_render_texture) {
2292 case GL_RGB:
2293 *piValue = WGL_TEXTURE_RGB_ARB;
2294 break;
2295 case GL_RGBA:
2296 *piValue = WGL_TEXTURE_RGBA_ARB;
2297 break;
2298 /* WGL_FLOAT_COMPONENTS_NV */
2299 case GL_FLOAT_R_NV:
2300 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2301 break;
2302 case GL_FLOAT_RG_NV:
2303 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2304 break;
2305 case GL_FLOAT_RGB_NV:
2306 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2307 break;
2308 case GL_FLOAT_RGBA_NV:
2309 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2310 break;
2311 default:
2312 ERR("Unknown texture format: %x\n", object->use_render_texture);
2315 break;
2317 case WGL_TEXTURE_TARGET_ARB:
2318 if (!object->texture_target){
2319 *piValue = WGL_NO_TEXTURE_ARB;
2320 } else {
2321 if (!use_render_texture_emulation) {
2322 SetLastError(ERROR_INVALID_DATA);
2323 return GL_FALSE;
2325 switch (object->texture_target) {
2326 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2327 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2328 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2329 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2332 break;
2334 case WGL_MIPMAP_TEXTURE_ARB:
2335 *piValue = GL_FALSE; /** don't support that */
2336 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2337 break;
2339 default:
2340 FIXME("unexpected attribute %x\n", iAttribute);
2341 break;
2344 return GL_TRUE;
2348 * X11DRV_wglReleasePbufferDCARB
2350 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2352 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2354 TRACE("(%p, %p)\n", hPbuffer, hdc);
2355 return DeleteDC(hdc);
2359 * X11DRV_wglSetPbufferAttribARB
2361 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2363 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2365 Wine_GLPBuffer* object = (Wine_GLPBuffer *)hPbuffer;
2366 GLboolean ret = GL_FALSE;
2368 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2369 if (NULL == object) {
2370 SetLastError(ERROR_INVALID_HANDLE);
2371 return GL_FALSE;
2373 if (!object->use_render_texture) {
2374 SetLastError(ERROR_INVALID_HANDLE);
2375 return GL_FALSE;
2377 if (1 == use_render_texture_emulation) {
2378 return GL_TRUE;
2380 return ret;
2384 * X11DRV_wglChoosePixelFormatARB
2386 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2388 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2390 int gl_test = 0;
2391 int attribs[256];
2392 int nAttribs = 0;
2393 GLXFBConfig* cfgs = NULL;
2394 int nCfgs = 0;
2395 int it;
2396 int fmt_id;
2397 WineGLPixelFormat *fmt;
2398 UINT pfmt_it = 0;
2399 int run;
2400 int i;
2401 DWORD dwFlags = 0;
2403 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2404 if (NULL != pfAttribFList) {
2405 FIXME("unused pfAttribFList\n");
2408 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2409 if (-1 == nAttribs) {
2410 WARN("Cannot convert WGL to GLX attributes\n");
2411 return GL_FALSE;
2413 PUSH1(attribs, None);
2415 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2416 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2417 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2418 for(i=0; piAttribIList[i] != 0; i+=2)
2420 switch(piAttribIList[i])
2422 case WGL_DRAW_TO_BITMAP_ARB:
2423 if(piAttribIList[i+1])
2424 dwFlags |= PFD_DRAW_TO_BITMAP;
2425 break;
2426 case WGL_ACCELERATION_ARB:
2427 switch(piAttribIList[i+1])
2429 case WGL_NO_ACCELERATION_ARB:
2430 dwFlags |= PFD_GENERIC_FORMAT;
2431 break;
2432 case WGL_GENERIC_ACCELERATION_ARB:
2433 dwFlags |= PFD_GENERIC_ACCELERATED;
2434 break;
2435 case WGL_FULL_ACCELERATION_ARB:
2436 /* Nothing to do */
2437 break;
2439 break;
2440 case WGL_SUPPORT_GDI_ARB:
2441 if(piAttribIList[i+1])
2442 dwFlags |= PFD_SUPPORT_GDI;
2443 break;
2447 /* Search for FB configurations matching the requirements in attribs */
2448 wine_tsx11_lock();
2449 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2450 if (NULL == cfgs) {
2451 wine_tsx11_unlock();
2452 WARN("Compatible Pixel Format not found\n");
2453 return GL_FALSE;
2456 /* Loop through all matching formats and check if they are suitable.
2457 * Note that this function should at max return nMaxFormats different formats */
2458 for(run=0; run < 2; run++)
2460 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2462 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2463 if (gl_test) {
2464 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2465 continue;
2468 /* Search for the format in our list of compatible formats */
2469 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id, dwFlags);
2470 if(!fmt)
2471 continue;
2473 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2474 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2475 continue;
2477 piFormats[pfmt_it] = fmt->iPixelFormat;
2478 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2479 pfmt_it++;
2483 *nNumFormats = pfmt_it;
2484 /** free list */
2485 XFree(cfgs);
2486 wine_tsx11_unlock();
2487 return GL_TRUE;
2491 * X11DRV_wglGetPixelFormatAttribivARB
2493 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2495 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2497 UINT i;
2498 WineGLPixelFormat *fmt = NULL;
2499 int hTest;
2500 int tmp;
2501 int curGLXAttr = 0;
2502 int nWGLFormats = 0;
2504 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2506 if (0 < iLayerPlane) {
2507 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2508 return GL_FALSE;
2511 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2512 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2513 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2514 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2515 if(!fmt) {
2516 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2519 wine_tsx11_lock();
2520 for (i = 0; i < nAttributes; ++i) {
2521 const int curWGLAttr = piAttributes[i];
2522 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2524 switch (curWGLAttr) {
2525 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2526 piValues[i] = nWGLFormats;
2527 continue;
2529 case WGL_SUPPORT_OPENGL_ARB:
2530 piValues[i] = GL_TRUE;
2531 continue;
2533 case WGL_ACCELERATION_ARB:
2534 curGLXAttr = GLX_CONFIG_CAVEAT;
2535 if (!fmt) goto pix_error;
2536 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2537 piValues[i] = WGL_NO_ACCELERATION_ARB;
2538 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2539 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2540 else
2541 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2542 continue;
2544 case WGL_TRANSPARENT_ARB:
2545 curGLXAttr = GLX_TRANSPARENT_TYPE;
2546 if (!fmt) goto pix_error;
2547 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2548 if (hTest) goto get_error;
2549 piValues[i] = GL_FALSE;
2550 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2551 continue;
2553 case WGL_PIXEL_TYPE_ARB:
2554 curGLXAttr = GLX_RENDER_TYPE;
2555 if (!fmt) goto pix_error;
2556 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2557 if (hTest) goto get_error;
2558 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2559 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2560 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2561 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2562 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2563 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2564 else {
2565 ERR("unexpected RenderType(%x)\n", tmp);
2566 piValues[i] = WGL_TYPE_RGBA_ARB;
2568 continue;
2570 case WGL_COLOR_BITS_ARB:
2571 curGLXAttr = GLX_BUFFER_SIZE;
2572 break;
2574 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2575 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2576 if (!use_render_texture_emulation) {
2577 piValues[i] = GL_FALSE;
2578 continue;
2580 curGLXAttr = GLX_RENDER_TYPE;
2581 if (!fmt) goto pix_error;
2582 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2583 if (hTest) goto get_error;
2584 if (GLX_COLOR_INDEX_BIT == tmp) {
2585 piValues[i] = GL_FALSE;
2586 continue;
2588 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2589 if (hTest) goto get_error;
2590 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2591 continue;
2593 case WGL_BLUE_BITS_ARB:
2594 curGLXAttr = GLX_BLUE_SIZE;
2595 break;
2596 case WGL_RED_BITS_ARB:
2597 curGLXAttr = GLX_RED_SIZE;
2598 break;
2599 case WGL_GREEN_BITS_ARB:
2600 curGLXAttr = GLX_GREEN_SIZE;
2601 break;
2602 case WGL_ALPHA_BITS_ARB:
2603 curGLXAttr = GLX_ALPHA_SIZE;
2604 break;
2605 case WGL_DEPTH_BITS_ARB:
2606 curGLXAttr = GLX_DEPTH_SIZE;
2607 break;
2608 case WGL_STENCIL_BITS_ARB:
2609 curGLXAttr = GLX_STENCIL_SIZE;
2610 break;
2611 case WGL_DOUBLE_BUFFER_ARB:
2612 curGLXAttr = GLX_DOUBLEBUFFER;
2613 break;
2614 case WGL_STEREO_ARB:
2615 curGLXAttr = GLX_STEREO;
2616 break;
2617 case WGL_AUX_BUFFERS_ARB:
2618 curGLXAttr = GLX_AUX_BUFFERS;
2619 break;
2621 case WGL_SUPPORT_GDI_ARB:
2622 if (!fmt) goto pix_error;
2623 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
2624 continue;
2626 case WGL_DRAW_TO_BITMAP_ARB:
2627 if (!fmt) goto pix_error;
2628 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? TRUE : FALSE;
2629 continue;
2631 case WGL_DRAW_TO_WINDOW_ARB:
2632 case WGL_DRAW_TO_PBUFFER_ARB:
2633 if (!fmt) goto pix_error;
2634 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2635 if (hTest) goto get_error;
2636 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2637 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2638 piValues[i] = GL_TRUE;
2639 else
2640 piValues[i] = GL_FALSE;
2641 continue;
2643 case WGL_SWAP_METHOD_ARB:
2644 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2645 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2646 * point only ATI offers this.
2648 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2649 break;
2651 case WGL_PBUFFER_LARGEST_ARB:
2652 curGLXAttr = GLX_LARGEST_PBUFFER;
2653 break;
2655 case WGL_SAMPLE_BUFFERS_ARB:
2656 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2657 break;
2659 case WGL_SAMPLES_ARB:
2660 curGLXAttr = GLX_SAMPLES_ARB;
2661 break;
2663 case WGL_FLOAT_COMPONENTS_NV:
2664 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2665 break;
2667 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2668 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2669 break;
2671 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2672 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2673 break;
2675 case WGL_ACCUM_RED_BITS_ARB:
2676 curGLXAttr = GLX_ACCUM_RED_SIZE;
2677 break;
2678 case WGL_ACCUM_GREEN_BITS_ARB:
2679 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2680 break;
2681 case WGL_ACCUM_BLUE_BITS_ARB:
2682 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2683 break;
2684 case WGL_ACCUM_ALPHA_BITS_ARB:
2685 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2686 break;
2687 case WGL_ACCUM_BITS_ARB:
2688 if (!fmt) goto pix_error;
2689 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2690 if (hTest) goto get_error;
2691 piValues[i] = tmp;
2692 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2693 if (hTest) goto get_error;
2694 piValues[i] += tmp;
2695 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2696 if (hTest) goto get_error;
2697 piValues[i] += tmp;
2698 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2699 if (hTest) goto get_error;
2700 piValues[i] += tmp;
2701 continue;
2703 default:
2704 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2707 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2708 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2709 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2711 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2712 * and check which options can work using iPixelFormat=0 and which not.
2713 * A problem would be that this function is an extension. This would
2714 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2716 if (0 != curGLXAttr && iPixelFormat != 0) {
2717 if (!fmt) goto pix_error;
2718 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2719 if (hTest) goto get_error;
2720 curGLXAttr = 0;
2721 } else {
2722 piValues[i] = GL_FALSE;
2725 wine_tsx11_unlock();
2726 return GL_TRUE;
2728 get_error:
2729 wine_tsx11_unlock();
2730 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2731 return GL_FALSE;
2733 pix_error:
2734 wine_tsx11_unlock();
2735 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2736 return GL_FALSE;
2740 * X11DRV_wglGetPixelFormatAttribfvARB
2742 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2744 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2746 int *attr;
2747 int ret;
2748 UINT i;
2750 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2752 /* Allocate a temporary array to store integer values */
2753 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2754 if (!attr) {
2755 ERR("couldn't allocate %d array\n", nAttributes);
2756 return GL_FALSE;
2759 /* Piggy-back on wglGetPixelFormatAttribivARB */
2760 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2761 if (ret) {
2762 /* Convert integer values to float. Should also check for attributes
2763 that can give decimal values here */
2764 for (i=0; i<nAttributes;i++) {
2765 pfValues[i] = attr[i];
2769 HeapFree(GetProcessHeap(), 0, attr);
2770 return ret;
2774 * X11DRV_wglBindTexImageARB
2776 * WGL_ARB_render_texture: wglBindTexImageARB
2778 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2780 Wine_GLPBuffer* object = (Wine_GLPBuffer *)hPbuffer;
2781 GLboolean ret = GL_FALSE;
2783 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2784 if (NULL == object) {
2785 SetLastError(ERROR_INVALID_HANDLE);
2786 return GL_FALSE;
2788 if (!object->use_render_texture) {
2789 SetLastError(ERROR_INVALID_HANDLE);
2790 return GL_FALSE;
2793 if (1 == use_render_texture_emulation) {
2794 static int init = 0;
2795 int prev_binded_texture = 0;
2796 GLXContext prev_context;
2797 Drawable prev_drawable;
2798 GLXContext tmp_context;
2800 wine_tsx11_lock();
2801 prev_context = pglXGetCurrentContext();
2802 prev_drawable = pglXGetCurrentDrawable();
2804 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2805 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2806 isn't ideal performance wise but I wasn't able to get other ways working.
2808 if(!init) {
2809 init = 1; /* Only show the FIXME once for performance reasons */
2810 FIXME("partial stub!\n");
2813 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2814 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2816 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2818 /* Switch to our pbuffer */
2819 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2821 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2822 * After that upload the pbuffer texture data. */
2823 pglBindTexture(object->texture_target, prev_binded_texture);
2824 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2826 /* Switch back to the original drawable and upload the pbuffer-texture */
2827 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2828 pglXDestroyContext(gdi_display, tmp_context);
2829 wine_tsx11_unlock();
2830 return GL_TRUE;
2833 return ret;
2837 * X11DRV_wglReleaseTexImageARB
2839 * WGL_ARB_render_texture: wglReleaseTexImageARB
2841 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2843 Wine_GLPBuffer* object = (Wine_GLPBuffer *)hPbuffer;
2844 GLboolean ret = GL_FALSE;
2846 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2847 if (NULL == object) {
2848 SetLastError(ERROR_INVALID_HANDLE);
2849 return GL_FALSE;
2851 if (!object->use_render_texture) {
2852 SetLastError(ERROR_INVALID_HANDLE);
2853 return GL_FALSE;
2855 if (1 == use_render_texture_emulation) {
2856 return GL_TRUE;
2858 return ret;
2862 * X11DRV_wglGetExtensionsStringEXT
2864 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2866 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2867 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2868 return WineGLInfo.wglExtensions;
2872 * X11DRV_wglGetSwapIntervalEXT
2874 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2876 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2877 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2878 * interval, so the swap interval has to be tracked. */
2879 TRACE("()\n");
2880 return swap_interval;
2884 * X11DRV_wglSwapIntervalEXT
2886 * WGL_EXT_swap_control: wglSwapIntervalEXT
2888 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2889 BOOL ret = TRUE;
2891 TRACE("(%d)\n", interval);
2893 if (interval < 0)
2895 SetLastError(ERROR_INVALID_DATA);
2896 return FALSE;
2898 else if (!has_swap_control && interval == 0)
2900 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2901 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2902 * value to be an error. Just silently ignore the request for now. */
2903 WARN("Request to disable vertical sync is not handled\n");
2904 swap_interval = 0;
2906 else
2908 if (pglXSwapIntervalSGI)
2910 wine_tsx11_lock();
2911 ret = !pglXSwapIntervalSGI(interval);
2912 wine_tsx11_unlock();
2914 else
2915 WARN("GLX_SGI_swap_control extension is not available\n");
2917 if (ret)
2918 swap_interval = interval;
2919 else
2920 SetLastError(ERROR_DC_NOT_FOUND);
2923 return ret;
2927 * X11DRV_wglAllocateMemoryNV
2929 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2931 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2932 void *ret = NULL;
2933 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2935 if (pglXAllocateMemoryNV)
2937 wine_tsx11_lock();
2938 ret = pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2939 wine_tsx11_unlock();
2941 return ret;
2945 * X11DRV_wglFreeMemoryNV
2947 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2949 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2950 TRACE("(%p)\n", pointer);
2951 if (pglXFreeMemoryNV == NULL)
2952 return;
2954 wine_tsx11_lock();
2955 pglXFreeMemoryNV(pointer);
2956 wine_tsx11_unlock();
2960 * X11DRV_wglSetPixelFormatWINE
2962 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2963 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2965 static BOOL WINAPI X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2967 WineGLPixelFormat *fmt;
2968 int value;
2969 HWND hwnd;
2971 TRACE("(%p,%d)\n", hdc, format);
2973 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, format, FALSE /* Offscreen */, &value);
2974 if (!fmt)
2976 ERR( "Invalid format %d\n", format );
2977 return FALSE;
2980 hwnd = WindowFromDC( hdc );
2981 if (!hwnd || hwnd == GetDesktopWindow())
2983 ERR( "not a valid window DC %p\n", hdc );
2984 return FALSE;
2987 wine_tsx11_lock();
2988 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
2989 wine_tsx11_unlock();
2991 if (!(value & GLX_WINDOW_BIT))
2993 WARN( "Pixel format %d is not compatible for window rendering\n", format );
2994 return FALSE;
2997 return SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0);
2998 /* DC pixel format will be set by the DCE update */
3002 * glxRequireVersion (internal)
3004 * Check if the supported GLX version matches requiredVersion.
3006 static BOOL glxRequireVersion(int requiredVersion)
3008 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3009 if(requiredVersion <= WineGLInfo.glxVersion[1])
3010 return TRUE;
3012 return FALSE;
3015 static BOOL glxRequireExtension(const char *requiredExtension)
3017 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3018 return FALSE;
3021 return TRUE;
3024 static void register_extension_string(const char *ext)
3026 if (WineGLInfo.wglExtensions[0])
3027 strcat(WineGLInfo.wglExtensions, " ");
3028 strcat(WineGLInfo.wglExtensions, ext);
3030 TRACE("'%s'\n", ext);
3033 static BOOL register_extension(const WineGLExtension * ext)
3035 int i;
3037 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3038 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3040 register_extension_string(ext->extName);
3042 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3043 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3045 return TRUE;
3048 static const WineGLExtension WGL_internal_functions =
3052 { "wglFinish", X11DRV_wglFinish },
3053 { "wglFlush", X11DRV_wglFlush },
3054 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3059 static const WineGLExtension WGL_ARB_create_context =
3061 "WGL_ARB_create_context",
3063 { "wglCreateContextAttribsARB", (void *)1 /* called through the glxdrv_wgl_funcs driver */ },
3067 static const WineGLExtension WGL_ARB_extensions_string =
3069 "WGL_ARB_extensions_string",
3071 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3075 static const WineGLExtension WGL_ARB_make_current_read =
3077 "WGL_ARB_make_current_read",
3079 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3080 { "wglMakeContextCurrentARB", (void *)1 /* called through the glxdrv_wgl_funcs driver */ },
3084 static const WineGLExtension WGL_ARB_multisample =
3086 "WGL_ARB_multisample",
3089 static const WineGLExtension WGL_ARB_pbuffer =
3091 "WGL_ARB_pbuffer",
3093 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3094 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3095 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3096 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3097 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3098 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3102 static const WineGLExtension WGL_ARB_pixel_format =
3104 "WGL_ARB_pixel_format",
3106 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3107 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3108 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3112 static const WineGLExtension WGL_ARB_render_texture =
3114 "WGL_ARB_render_texture",
3116 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3117 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3121 static const WineGLExtension WGL_EXT_extensions_string =
3123 "WGL_EXT_extensions_string",
3125 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3129 static const WineGLExtension WGL_EXT_swap_control =
3131 "WGL_EXT_swap_control",
3133 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3134 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3138 static const WineGLExtension WGL_NV_vertex_array_range =
3140 "WGL_NV_vertex_array_range",
3142 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3143 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3147 static const WineGLExtension WGL_WINE_pixel_format_passthrough =
3149 "WGL_WINE_pixel_format_passthrough",
3151 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE },
3156 * X11DRV_WineGL_LoadExtensions
3158 static void X11DRV_WineGL_LoadExtensions(void)
3160 WineGLInfo.wglExtensions[0] = 0;
3162 /* Load Wine internal functions */
3163 register_extension(&WGL_internal_functions);
3165 /* ARB Extensions */
3167 if(glxRequireExtension("GLX_ARB_create_context"))
3169 register_extension(&WGL_ARB_create_context);
3171 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3172 register_extension_string("WGL_ARB_create_context_profile");
3175 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3177 register_extension_string("WGL_ARB_pixel_format_float");
3178 register_extension_string("WGL_ATI_pixel_format_float");
3181 register_extension(&WGL_ARB_extensions_string);
3183 if (glxRequireVersion(3))
3184 register_extension(&WGL_ARB_make_current_read);
3186 if (glxRequireExtension("GLX_ARB_multisample"))
3187 register_extension(&WGL_ARB_multisample);
3189 /* In general pbuffer functionality requires support in the X-server. The functionality is
3190 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3192 if ( glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") )
3193 register_extension(&WGL_ARB_pbuffer);
3195 register_extension(&WGL_ARB_pixel_format);
3197 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3198 if (glxRequireExtension("GLX_ARB_render_texture") ||
3199 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3201 register_extension(&WGL_ARB_render_texture);
3203 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3204 if(glxRequireExtension("GLX_NV_float_buffer"))
3205 register_extension_string("WGL_NV_float_buffer");
3207 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3208 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3209 register_extension_string("WGL_NV_texture_rectangle");
3212 /* EXT Extensions */
3214 register_extension(&WGL_EXT_extensions_string);
3216 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3217 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3218 register_extension(&WGL_EXT_swap_control);
3220 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3221 register_extension_string("WGL_EXT_framebuffer_sRGB");
3223 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3224 register_extension_string("WGL_EXT_pixel_format_packed_float");
3226 if (glxRequireExtension("GLX_EXT_swap_control"))
3227 has_swap_control = TRUE;
3229 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3230 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3231 register_extension(&WGL_NV_vertex_array_range);
3233 /* WINE-specific WGL Extensions */
3235 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3236 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3238 register_extension(&WGL_WINE_pixel_format_passthrough);
3242 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3244 wine_tsx11_lock();
3245 pglXDestroyGLXPixmap(display, glxpixmap);
3246 wine_tsx11_unlock();
3247 return TRUE;
3251 * glxdrv_SwapBuffers
3253 * Swap the buffers of this DC
3255 static BOOL glxdrv_SwapBuffers(PHYSDEV dev)
3257 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3258 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3260 TRACE("(%p)\n", dev->hdc);
3262 if (!ctx)
3264 WARN("Using a NULL context, skipping\n");
3265 SetLastError(ERROR_INVALID_HANDLE);
3266 return FALSE;
3269 if (!physdev->drawable)
3271 WARN("Using an invalid drawable, skipping\n");
3272 SetLastError(ERROR_INVALID_HANDLE);
3273 return FALSE;
3276 wine_tsx11_lock();
3277 sync_context(ctx);
3278 switch (physdev->type)
3280 case DC_GL_PIXMAP_WIN:
3281 if(pglXCopySubBufferMESA) {
3282 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
3283 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
3285 /* (glX)SwapBuffers has an implicit glFlush effect, however
3286 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3287 * copying */
3288 pglFlush();
3289 if(w > 0 && h > 0)
3290 pglXCopySubBufferMESA(gdi_display, physdev->drawable, 0, 0, w, h);
3291 break;
3293 /* fall through */
3294 default:
3295 pglXSwapBuffers(gdi_display, physdev->drawable);
3296 break;
3299 flush_gl_drawable( physdev );
3300 wine_tsx11_unlock();
3302 /* FPS support */
3303 if (TRACE_ON(fps))
3305 static long prev_time, start_time;
3306 static unsigned long frames, frames_total;
3308 DWORD time = GetTickCount();
3309 frames++;
3310 frames_total++;
3311 /* every 1.5 seconds */
3312 if (time - prev_time > 1500) {
3313 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3314 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3315 prev_time = time;
3316 frames = 0;
3317 if(start_time == 0) start_time = time;
3321 return TRUE;
3324 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3326 WineGLPixelFormat *fmt;
3327 XVisualInfo *ret;
3329 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
3330 if(fmt == NULL)
3331 return NULL;
3333 wine_tsx11_lock();
3334 ret = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3335 wine_tsx11_unlock();
3336 return ret;
3339 static BOOL create_glx_dc( PHYSDEV *pdev )
3341 /* assume that only the main x11 device implements GetDeviceCaps */
3342 X11DRV_PDEVICE *x11dev = get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev, pGetDeviceCaps ));
3343 struct glx_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) );
3345 if (!physdev) return FALSE;
3346 physdev->x11dev = x11dev;
3347 push_dc_driver( pdev, &physdev->dev, &glxdrv_funcs );
3348 return TRUE;
3351 /**********************************************************************
3352 * glxdrv_CreateDC
3354 static BOOL glxdrv_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
3355 LPCWSTR output, const DEVMODEW* initData )
3357 return create_glx_dc( pdev );
3360 /**********************************************************************
3361 * glxdrv_CreateCompatibleDC
3363 static BOOL glxdrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
3365 if (orig) /* chain to next driver first */
3367 orig = GET_NEXT_PHYSDEV( orig, pCreateCompatibleDC );
3368 if (!orig->funcs->pCreateCompatibleDC( orig, pdev )) return FALSE;
3370 /* otherwise we have been called by x11drv */
3371 return create_glx_dc( pdev );
3374 /**********************************************************************
3375 * glxdrv_DeleteDC
3377 static BOOL glxdrv_DeleteDC( PHYSDEV dev )
3379 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3380 HeapFree( GetProcessHeap(), 0, physdev );
3381 return TRUE;
3384 /**********************************************************************
3385 * glxdrv_ExtEscape
3387 static INT glxdrv_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
3388 INT out_count, LPVOID out_data )
3390 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3392 dev = GET_NEXT_PHYSDEV( dev, pExtEscape );
3394 if (escape == X11DRV_ESCAPE && in_data && in_count >= sizeof(enum x11drv_escape_codes))
3396 switch (*(const enum x11drv_escape_codes *)in_data)
3398 case X11DRV_SET_DRAWABLE:
3399 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
3401 const struct x11drv_escape_set_drawable *data = in_data;
3402 physdev->pixel_format = pixelformat_from_fbconfig_id( data->fbconfig_id );
3403 physdev->type = data->gl_type;
3404 physdev->drawable = data->gl_drawable;
3405 physdev->pixmap = data->pixmap;
3406 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %u type %u\n",
3407 dev->hdc, physdev->drawable, physdev->pixel_format, physdev->type );
3409 break;
3410 case X11DRV_GET_DRAWABLE:
3411 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
3413 struct x11drv_escape_get_drawable *data = out_data;
3414 data->pixel_format = physdev->pixel_format;
3415 data->gl_type = physdev->type;
3416 data->gl_drawable = physdev->drawable;
3417 data->pixmap = physdev->pixmap;
3419 break;
3420 case X11DRV_FLUSH_GL_DRAWABLE:
3421 flush_gl_drawable( physdev );
3422 return TRUE;
3423 default:
3424 break;
3427 return dev->funcs->pExtEscape( dev, escape, in_count, in_data, out_count, out_data );
3430 /**********************************************************************
3431 * glxdrv_wine_get_wgl_driver
3433 static const struct wgl_funcs * glxdrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
3435 if (version != WINE_GDI_DRIVER_VERSION)
3437 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_GDI_DRIVER_VERSION );
3438 return NULL;
3441 if (has_opengl()) return &glxdrv_wgl_funcs;
3443 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
3444 return dev->funcs->wine_get_wgl_driver( dev, version );
3447 static const struct gdi_dc_funcs glxdrv_funcs =
3449 NULL, /* pAbortDoc */
3450 NULL, /* pAbortPath */
3451 NULL, /* pAlphaBlend */
3452 NULL, /* pAngleArc */
3453 NULL, /* pArc */
3454 NULL, /* pArcTo */
3455 NULL, /* pBeginPath */
3456 NULL, /* pBlendImage */
3457 NULL, /* pChord */
3458 NULL, /* pCloseFigure */
3459 glxdrv_CreateCompatibleDC, /* pCreateCompatibleDC */
3460 glxdrv_CreateDC, /* pCreateDC */
3461 glxdrv_DeleteDC, /* pDeleteDC */
3462 NULL, /* pDeleteObject */
3463 glxdrv_DescribePixelFormat, /* pDescribePixelFormat */
3464 NULL, /* pDeviceCapabilities */
3465 NULL, /* pEllipse */
3466 NULL, /* pEndDoc */
3467 NULL, /* pEndPage */
3468 NULL, /* pEndPath */
3469 NULL, /* pEnumFonts */
3470 NULL, /* pEnumICMProfiles */
3471 NULL, /* pExcludeClipRect */
3472 NULL, /* pExtDeviceMode */
3473 glxdrv_ExtEscape, /* pExtEscape */
3474 NULL, /* pExtFloodFill */
3475 NULL, /* pExtSelectClipRgn */
3476 NULL, /* pExtTextOut */
3477 NULL, /* pFillPath */
3478 NULL, /* pFillRgn */
3479 NULL, /* pFlattenPath */
3480 NULL, /* pFontIsLinked */
3481 NULL, /* pFrameRgn */
3482 NULL, /* pGdiComment */
3483 NULL, /* pGdiRealizationInfo */
3484 NULL, /* pGetBoundsRect */
3485 NULL, /* pGetCharABCWidths */
3486 NULL, /* pGetCharABCWidthsI */
3487 NULL, /* pGetCharWidth */
3488 NULL, /* pGetDeviceCaps */
3489 NULL, /* pGetDeviceGammaRamp */
3490 NULL, /* pGetFontData */
3491 NULL, /* pGetFontUnicodeRanges */
3492 NULL, /* pGetGlyphIndices */
3493 NULL, /* pGetGlyphOutline */
3494 NULL, /* pGetICMProfile */
3495 NULL, /* pGetImage */
3496 NULL, /* pGetKerningPairs */
3497 NULL, /* pGetNearestColor */
3498 NULL, /* pGetOutlineTextMetrics */
3499 NULL, /* pGetPixel */
3500 NULL, /* pGetSystemPaletteEntries */
3501 NULL, /* pGetTextCharsetInfo */
3502 NULL, /* pGetTextExtentExPoint */
3503 NULL, /* pGetTextExtentExPointI */
3504 NULL, /* pGetTextFace */
3505 NULL, /* pGetTextMetrics */
3506 NULL, /* pGradientFill */
3507 NULL, /* pIntersectClipRect */
3508 NULL, /* pInvertRgn */
3509 NULL, /* pLineTo */
3510 NULL, /* pModifyWorldTransform */
3511 NULL, /* pMoveTo */
3512 NULL, /* pOffsetClipRgn */
3513 NULL, /* pOffsetViewportOrg */
3514 NULL, /* pOffsetWindowOrg */
3515 NULL, /* pPaintRgn */
3516 NULL, /* pPatBlt */
3517 NULL, /* pPie */
3518 NULL, /* pPolyBezier */
3519 NULL, /* pPolyBezierTo */
3520 NULL, /* pPolyDraw */
3521 NULL, /* pPolyPolygon */
3522 NULL, /* pPolyPolyline */
3523 NULL, /* pPolygon */
3524 NULL, /* pPolyline */
3525 NULL, /* pPolylineTo */
3526 NULL, /* pPutImage */
3527 NULL, /* pRealizeDefaultPalette */
3528 NULL, /* pRealizePalette */
3529 NULL, /* pRectangle */
3530 NULL, /* pResetDC */
3531 NULL, /* pRestoreDC */
3532 NULL, /* pRoundRect */
3533 NULL, /* pSaveDC */
3534 NULL, /* pScaleViewportExt */
3535 NULL, /* pScaleWindowExt */
3536 NULL, /* pSelectBitmap */
3537 NULL, /* pSelectBrush */
3538 NULL, /* pSelectClipPath */
3539 NULL, /* pSelectFont */
3540 NULL, /* pSelectPalette */
3541 NULL, /* pSelectPen */
3542 NULL, /* pSetArcDirection */
3543 NULL, /* pSetBkColor */
3544 NULL, /* pSetBkMode */
3545 NULL, /* pSetBoundsRect */
3546 NULL, /* pSetDCBrushColor */
3547 NULL, /* pSetDCPenColor */
3548 NULL, /* pSetDIBitsToDevice */
3549 NULL, /* pSetDeviceClipping */
3550 NULL, /* pSetDeviceGammaRamp */
3551 NULL, /* pSetLayout */
3552 NULL, /* pSetMapMode */
3553 NULL, /* pSetMapperFlags */
3554 NULL, /* pSetPixel */
3555 glxdrv_SetPixelFormat, /* pSetPixelFormat */
3556 NULL, /* pSetPolyFillMode */
3557 NULL, /* pSetROP2 */
3558 NULL, /* pSetRelAbs */
3559 NULL, /* pSetStretchBltMode */
3560 NULL, /* pSetTextAlign */
3561 NULL, /* pSetTextCharacterExtra */
3562 NULL, /* pSetTextColor */
3563 NULL, /* pSetTextJustification */
3564 NULL, /* pSetViewportExt */
3565 NULL, /* pSetViewportOrg */
3566 NULL, /* pSetWindowExt */
3567 NULL, /* pSetWindowOrg */
3568 NULL, /* pSetWorldTransform */
3569 NULL, /* pStartDoc */
3570 NULL, /* pStartPage */
3571 NULL, /* pStretchBlt */
3572 NULL, /* pStretchDIBits */
3573 NULL, /* pStrokeAndFillPath */
3574 NULL, /* pStrokePath */
3575 glxdrv_SwapBuffers, /* pSwapBuffers */
3576 NULL, /* pUnrealizePalette */
3577 NULL, /* pWidenPath */
3578 glxdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
3579 GDI_PRIORITY_GRAPHICS_DRV + 20 /* priority */
3582 static const struct wgl_funcs glxdrv_wgl_funcs =
3584 glxdrv_GetPixelFormat, /* p_GetPixelFormat */
3585 glxdrv_wglCopyContext, /* p_wglCopyContext */
3586 glxdrv_wglCreateContext, /* p_wglCreateContext */
3587 glxdrv_wglCreateContextAttribsARB, /* p_wglCreateContextAttribsARB */
3588 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3589 glxdrv_wglGetCurrentDC, /* p_wglGetCurrentDC */
3590 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3591 glxdrv_wglMakeContextCurrentARB, /* p_wglMakeContextCurrentARB */
3592 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3593 glxdrv_wglShareLists, /* p_wglShareLists */
3596 const struct gdi_dc_funcs *get_glx_driver(void)
3598 return &glxdrv_funcs;
3601 #else /* no OpenGL includes */
3603 const struct gdi_dc_funcs *get_glx_driver(void)
3605 return NULL;
3608 void mark_drawable_dirty(Drawable old, Drawable new)
3612 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3614 return 0;
3618 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3620 return FALSE;
3623 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3625 return NULL;
3628 #endif /* defined(SONAME_LIBGL) */