wine.inf: Avoid creating empty registry values.
[wine/multimedia.git] / dlls / winex11.drv / opengl.c
blobe8d0f892fb38ec78e385e378077d40ff7adad724
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
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
26 #include "wine/port.h"
28 #include <assert.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
34 #endif
35 #ifdef HAVE_SYS_UN_H
36 #include <sys/un.h>
37 #endif
39 #include "x11drv.h"
40 #include "winternl.h"
41 #include "wine/library.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
46 #ifdef SONAME_LIBGL
48 WINE_DECLARE_DEBUG_CHANNEL(winediag);
50 #undef APIENTRY
51 #undef CALLBACK
52 #undef WINAPI
54 #ifdef HAVE_GL_GL_H
55 # include <GL/gl.h>
56 #endif
57 #ifdef HAVE_GL_GLX_H
58 # include <GL/glx.h>
59 #endif
61 #include "wine/wgl.h"
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
73 WINE_DECLARE_DEBUG_CHANNEL(fps);
75 typedef struct wine_glextension {
76 const char *extName;
77 struct {
78 const char *funcName;
79 void *funcAddress;
80 } extEntryPoints[9];
81 } WineGLExtension;
83 struct WineGLInfo {
84 const char *glVersion;
85 char *glExtensions;
87 int glxVersion[2];
89 const char *glxServerVersion;
90 const char *glxServerVendor;
91 const char *glxServerExtensions;
93 const char *glxClientVersion;
94 const char *glxClientVendor;
95 const char *glxClientExtensions;
97 const char *glxExtensions;
99 BOOL glxDirect;
100 char wglExtensions[4096];
103 typedef struct wine_glpixelformat {
104 int iPixelFormat;
105 GLXFBConfig fbconfig;
106 int fmt_id;
107 int render_type;
108 BOOL offscreenOnly;
109 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
110 } WineGLPixelFormat;
112 typedef struct wine_glcontext {
113 HDC hdc;
114 BOOL has_been_current;
115 BOOL sharing;
116 DWORD tid;
117 BOOL gl3_context;
118 XVisualInfo *vis;
119 WineGLPixelFormat *fmt;
120 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
121 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
122 GLXContext ctx;
123 HDC read_hdc;
124 Drawable drawables[2];
125 BOOL refresh_drawables;
126 struct wine_glcontext *next;
127 struct wine_glcontext *prev;
128 } Wine_GLContext;
130 typedef struct wine_glpbuffer {
131 Drawable drawable;
132 Display* display;
133 WineGLPixelFormat* fmt;
134 int width;
135 int height;
136 int* attribList;
137 HDC hdc;
139 int use_render_texture; /* This is also the internal texture format */
140 int texture_bind_target;
141 int texture_bpp;
142 GLint texture_format;
143 GLuint texture_target;
144 GLenum texture_type;
145 GLuint texture;
146 int texture_level;
147 } Wine_GLPBuffer;
149 static Wine_GLContext *context_list;
150 static struct WineGLInfo WineGLInfo = { 0 };
151 static int use_render_texture_emulation = 1;
152 static int use_render_texture_ati = 0;
153 static BOOL has_swap_control;
154 static int swap_interval = 1;
156 #define MAX_EXTENSIONS 16
157 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
158 static int WineGLExtensionListSize;
160 static void X11DRV_WineGL_LoadExtensions(void);
161 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count);
162 static BOOL glxRequireVersion(int requiredVersion);
163 static BOOL glxRequireExtension(const char *requiredExtension);
165 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
166 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
167 TRACE(" - dwFlags : ");
168 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
174 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
175 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
176 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
177 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
178 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
179 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
180 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
181 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
182 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
183 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
184 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
185 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
186 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
187 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
188 #undef TEST_AND_DUMP
189 TRACE("\n");
191 TRACE(" - iPixelType : ");
192 switch (ppfd->iPixelType) {
193 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
194 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
196 TRACE("\n");
198 TRACE(" - Color : %d\n", ppfd->cColorBits);
199 TRACE(" - Red : %d\n", ppfd->cRedBits);
200 TRACE(" - Green : %d\n", ppfd->cGreenBits);
201 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
202 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
203 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
204 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
205 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
206 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
208 TRACE(" - iLayerType : ");
209 switch (ppfd->iLayerType) {
210 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
211 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
212 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
214 TRACE("\n");
217 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
218 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
220 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
221 /* GLX 1.0 */
222 MAKE_FUNCPTR(glXChooseVisual)
223 MAKE_FUNCPTR(glXCopyContext)
224 MAKE_FUNCPTR(glXCreateContext)
225 MAKE_FUNCPTR(glXCreateGLXPixmap)
226 MAKE_FUNCPTR(glXGetCurrentContext)
227 MAKE_FUNCPTR(glXGetCurrentDrawable)
228 MAKE_FUNCPTR(glXDestroyContext)
229 MAKE_FUNCPTR(glXDestroyGLXPixmap)
230 MAKE_FUNCPTR(glXGetConfig)
231 MAKE_FUNCPTR(glXIsDirect)
232 MAKE_FUNCPTR(glXMakeCurrent)
233 MAKE_FUNCPTR(glXSwapBuffers)
234 MAKE_FUNCPTR(glXQueryExtension)
235 MAKE_FUNCPTR(glXQueryVersion)
236 MAKE_FUNCPTR(glXUseXFont)
238 /* GLX 1.1 */
239 MAKE_FUNCPTR(glXGetClientString)
240 MAKE_FUNCPTR(glXQueryExtensionsString)
241 MAKE_FUNCPTR(glXQueryServerString)
243 /* GLX 1.3 */
244 MAKE_FUNCPTR(glXGetFBConfigs)
245 MAKE_FUNCPTR(glXChooseFBConfig)
246 MAKE_FUNCPTR(glXCreatePbuffer)
247 MAKE_FUNCPTR(glXCreateNewContext)
248 MAKE_FUNCPTR(glXDestroyPbuffer)
249 MAKE_FUNCPTR(glXGetFBConfigAttrib)
250 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
251 MAKE_FUNCPTR(glXMakeContextCurrent)
252 MAKE_FUNCPTR(glXQueryDrawable)
253 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
255 /* GLX Extensions */
256 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
257 static void* (*pglXGetProcAddressARB)(const GLubyte *);
258 static int (*pglXSwapIntervalSGI)(int);
260 /* ATI GLX Extensions */
261 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
262 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
263 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
265 /* NV GLX Extension */
266 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
267 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
269 /* MESA GLX Extensions */
270 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
272 /* Standard OpenGL */
273 MAKE_FUNCPTR(glBindTexture)
274 MAKE_FUNCPTR(glBitmap)
275 MAKE_FUNCPTR(glCopyTexSubImage1D)
276 MAKE_FUNCPTR(glCopyTexImage2D)
277 MAKE_FUNCPTR(glCopyTexSubImage2D)
278 MAKE_FUNCPTR(glDrawBuffer)
279 MAKE_FUNCPTR(glEndList)
280 MAKE_FUNCPTR(glGetError)
281 MAKE_FUNCPTR(glGetIntegerv)
282 MAKE_FUNCPTR(glGetString)
283 MAKE_FUNCPTR(glNewList)
284 MAKE_FUNCPTR(glPixelStorei)
285 MAKE_FUNCPTR(glReadPixels)
286 MAKE_FUNCPTR(glTexImage2D)
287 MAKE_FUNCPTR(glFinish)
288 MAKE_FUNCPTR(glFlush)
289 #undef MAKE_FUNCPTR
291 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
293 /* In the future we might want to find the exact X or GLX error to report back to the app */
294 return 1;
297 static BOOL infoInitialized = FALSE;
298 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
300 int screen = DefaultScreen(gdi_display);
301 Window win = 0, root = 0;
302 const char *gl_renderer;
303 const char* str;
304 XVisualInfo *vis;
305 GLXContext ctx = NULL;
306 XSetWindowAttributes attr;
307 BOOL ret = FALSE;
308 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
310 if (infoInitialized)
311 return TRUE;
312 infoInitialized = TRUE;
314 attr.override_redirect = True;
315 attr.colormap = None;
316 attr.border_pixel = 0;
318 wine_tsx11_lock();
320 vis = pglXChooseVisual(gdi_display, screen, attribList);
321 if (vis) {
322 #ifdef __i386__
323 WORD old_fs = wine_get_fs();
324 /* Create a GLX Context. Without one we can't query GL information */
325 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
326 if (wine_get_fs() != old_fs)
328 wine_set_fs( old_fs );
329 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
330 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
331 goto done;
333 #else
334 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
335 #endif
337 if (!ctx) goto done;
339 root = RootWindow( gdi_display, vis->screen );
340 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
341 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
342 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
343 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
344 XMapWindow( gdi_display, win );
345 else
346 win = root;
348 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
350 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
351 goto done;
353 gl_renderer = (const char *)pglGetString(GL_RENDERER);
354 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
355 str = (const char *) pglGetString(GL_EXTENSIONS);
356 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
357 strcpy(WineGLInfo.glExtensions, str);
359 /* Get the common GLX version supported by GLX client and server ( major/minor) */
360 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
362 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
363 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
364 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
366 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
367 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
368 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
370 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
371 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
373 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
374 TRACE("GL renderer : %s.\n", gl_renderer);
375 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
376 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
377 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
378 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
379 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
380 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
382 if(!WineGLInfo.glxDirect)
384 int fd = ConnectionNumber(gdi_display);
385 struct sockaddr_un uaddr;
386 unsigned int uaddrlen = sizeof(struct sockaddr_un);
388 /* In general indirect rendering on a local X11 server indicates a driver problem.
389 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
391 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
392 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
393 "haven't been installed correctly (using GL renderer %s, version %s).\n",
394 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
396 else
398 /* In general you would expect that if direct rendering is returned, that you receive hardware
399 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
400 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
401 * software rendering, it shows direct rendering.
403 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
404 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
405 * it shows 'Mesa X11'.
407 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
408 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
409 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
410 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
412 ret = TRUE;
414 done:
415 if(vis) XFree(vis);
416 if(ctx) {
417 pglXMakeCurrent(gdi_display, None, NULL);
418 pglXDestroyContext(gdi_display, ctx);
420 if (win != root) XDestroyWindow( gdi_display, win );
421 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
422 wine_tsx11_unlock();
423 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
424 return ret;
427 void X11DRV_OpenGL_Cleanup(void)
429 HeapFree(GetProcessHeap(), 0, WineGLInfo.glExtensions);
430 infoInitialized = FALSE;
433 static BOOL has_opengl(void)
435 static int init_done;
436 static void *opengl_handle;
438 char buffer[200];
439 int error_base, event_base;
441 if (init_done) return (opengl_handle != NULL);
442 init_done = 1;
444 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
445 and include all dependencies */
446 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
447 if (opengl_handle == NULL)
449 ERR( "Failed to load libGL: %s\n", buffer );
450 ERR( "OpenGL support is disabled.\n");
451 return FALSE;
454 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
455 if (pglXGetProcAddressARB == NULL) {
456 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
457 goto failed;
460 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
462 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
463 goto failed; \
464 } while(0)
466 /* GLX 1.0 */
467 LOAD_FUNCPTR(glXChooseVisual);
468 LOAD_FUNCPTR(glXCopyContext);
469 LOAD_FUNCPTR(glXCreateContext);
470 LOAD_FUNCPTR(glXCreateGLXPixmap);
471 LOAD_FUNCPTR(glXGetCurrentContext);
472 LOAD_FUNCPTR(glXGetCurrentDrawable);
473 LOAD_FUNCPTR(glXDestroyContext);
474 LOAD_FUNCPTR(glXDestroyGLXPixmap);
475 LOAD_FUNCPTR(glXGetConfig);
476 LOAD_FUNCPTR(glXIsDirect);
477 LOAD_FUNCPTR(glXMakeCurrent);
478 LOAD_FUNCPTR(glXSwapBuffers);
479 LOAD_FUNCPTR(glXQueryExtension);
480 LOAD_FUNCPTR(glXQueryVersion);
481 LOAD_FUNCPTR(glXUseXFont);
483 /* GLX 1.1 */
484 LOAD_FUNCPTR(glXGetClientString);
485 LOAD_FUNCPTR(glXQueryExtensionsString);
486 LOAD_FUNCPTR(glXQueryServerString);
488 /* GLX 1.3 */
489 LOAD_FUNCPTR(glXCreatePbuffer);
490 LOAD_FUNCPTR(glXCreateNewContext);
491 LOAD_FUNCPTR(glXDestroyPbuffer);
492 LOAD_FUNCPTR(glXMakeContextCurrent);
493 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
494 LOAD_FUNCPTR(glXGetFBConfigs);
496 /* Standard OpenGL calls */
497 LOAD_FUNCPTR(glBindTexture);
498 LOAD_FUNCPTR(glBitmap);
499 LOAD_FUNCPTR(glCopyTexSubImage1D);
500 LOAD_FUNCPTR(glCopyTexImage2D);
501 LOAD_FUNCPTR(glCopyTexSubImage2D);
502 LOAD_FUNCPTR(glDrawBuffer);
503 LOAD_FUNCPTR(glEndList);
504 LOAD_FUNCPTR(glGetError);
505 LOAD_FUNCPTR(glGetIntegerv);
506 LOAD_FUNCPTR(glGetString);
507 LOAD_FUNCPTR(glNewList);
508 LOAD_FUNCPTR(glPixelStorei);
509 LOAD_FUNCPTR(glReadPixels);
510 LOAD_FUNCPTR(glTexImage2D);
511 LOAD_FUNCPTR(glFinish);
512 LOAD_FUNCPTR(glFlush);
513 #undef LOAD_FUNCPTR
515 /* It doesn't matter if these fail. They'll only be used if the driver reports
516 the associated extension is available (and if a driver reports the extension
517 is available but fails to provide the functions, it's quite broken) */
518 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
519 /* ARB GLX Extension */
520 LOAD_FUNCPTR(glXCreateContextAttribsARB);
521 /* SGI GLX Extension */
522 LOAD_FUNCPTR(glXSwapIntervalSGI);
523 /* NV GLX Extension */
524 LOAD_FUNCPTR(glXAllocateMemoryNV);
525 LOAD_FUNCPTR(glXFreeMemoryNV);
526 #undef LOAD_FUNCPTR
528 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
530 wine_tsx11_lock();
531 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
532 TRACE("GLX is up and running error_base = %d\n", error_base);
533 } else {
534 wine_tsx11_unlock();
535 ERR( "GLX extension is missing, disabling OpenGL.\n" );
536 goto failed;
539 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
540 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
541 * rendering is used.
543 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
544 * depends on the reported GLX client / server version and on the client / server extension list.
545 * Those don't have to be the same.
547 * In general the server GLX information lists the capabilities in case of indirect rendering.
548 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
549 * available and in that case the client GLX informat can be used.
550 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
551 * in the GLX version/extension list. When a program does this it works for certain for both
552 * direct and indirect rendering.
554 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
555 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
556 * extension list which causes this extension not to be listed. (Wine requires this extension).
557 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
558 * pbuffers is around.
560 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
561 * the ATI drivers and from then on use GLX client information for them.
564 if(glxRequireVersion(3)) {
565 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
566 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
567 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
568 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
569 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
570 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
571 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
572 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
574 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
575 * enable this function when the Xserver understand GLX 1.3 or newer
577 pglXQueryDrawable = NULL;
578 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
579 TRACE("Overriding ATI GLX capabilities!\n");
580 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
581 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
582 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
583 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
585 /* Use client GLX information in case of the ATI drivers. We override the
586 * capabilities over here and not somewhere else as ATI might better their
587 * life in the future. In case they release proper drivers this block of
588 * code won't be called. */
589 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
590 } else {
591 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
594 if(glxRequireExtension("GLX_ATI_render_texture")) {
595 use_render_texture_ati = 1;
596 pglXBindTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
597 pglXReleaseTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
598 pglXDrawableAttribATI = pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
601 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
602 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
605 X11DRV_WineGL_LoadExtensions();
607 wine_tsx11_unlock();
608 return TRUE;
610 failed:
611 wine_dlclose(opengl_handle, NULL, 0);
612 opengl_handle = NULL;
613 return FALSE;
616 static inline Wine_GLContext *alloc_context(void)
618 Wine_GLContext *ret;
620 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
622 ret->next = context_list;
623 if (context_list) context_list->prev = ret;
624 context_list = ret;
626 return ret;
629 static inline void free_context(Wine_GLContext *context)
631 if (context->next != NULL) context->next->prev = context->prev;
632 if (context->prev != NULL) context->prev->next = context->next;
633 else context_list = context->next;
635 if (context->vis) XFree(context->vis);
636 HeapFree(GetProcessHeap(), 0, context);
639 static inline BOOL is_valid_context( Wine_GLContext *ctx )
641 Wine_GLContext *ptr;
642 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
643 return (ptr != NULL);
646 static int describeContext(Wine_GLContext* ctx) {
647 int tmp;
648 int ctx_vis_id;
649 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
650 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
651 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
652 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
653 TRACE(" - VISUAL_ID 0x%x\n", tmp);
654 ctx_vis_id = tmp;
655 return ctx_vis_id;
658 static BOOL describeDrawable(X11DRV_PDEVICE *physDev) {
659 int tmp;
660 WineGLPixelFormat *fmt;
661 int fmt_count = 0;
663 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE /* Offscreen */, &fmt_count);
664 if(!fmt) return FALSE;
666 TRACE(" HDC %p has:\n", physDev->dev.hdc);
667 TRACE(" - iPixelFormat %d\n", fmt->iPixelFormat);
668 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev));
669 TRACE(" - FBCONFIG_ID 0x%x\n", fmt->fmt_id);
671 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &tmp);
672 TRACE(" - VISUAL_ID 0x%x\n", tmp);
674 return TRUE;
677 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
678 int nAttribs = 0;
679 unsigned cur = 0;
680 int pop;
681 int drawattrib = 0;
682 int nvfloatattrib = GLX_DONT_CARE;
683 int pixelattrib = ~0;
685 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
686 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
687 while (iWGLAttr && 0 != iWGLAttr[cur]) {
688 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
690 switch (iWGLAttr[cur]) {
691 case WGL_AUX_BUFFERS_ARB:
692 pop = iWGLAttr[++cur];
693 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
694 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
695 break;
696 case WGL_COLOR_BITS_ARB:
697 pop = iWGLAttr[++cur];
698 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
699 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
700 break;
701 case WGL_BLUE_BITS_ARB:
702 pop = iWGLAttr[++cur];
703 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
704 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
705 break;
706 case WGL_RED_BITS_ARB:
707 pop = iWGLAttr[++cur];
708 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
709 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
710 break;
711 case WGL_GREEN_BITS_ARB:
712 pop = iWGLAttr[++cur];
713 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
714 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
715 break;
716 case WGL_ALPHA_BITS_ARB:
717 pop = iWGLAttr[++cur];
718 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
719 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
720 break;
721 case WGL_DEPTH_BITS_ARB:
722 pop = iWGLAttr[++cur];
723 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
724 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
725 break;
726 case WGL_STENCIL_BITS_ARB:
727 pop = iWGLAttr[++cur];
728 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
729 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
730 break;
731 case WGL_DOUBLE_BUFFER_ARB:
732 pop = iWGLAttr[++cur];
733 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
734 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
735 break;
736 case WGL_STEREO_ARB:
737 pop = iWGLAttr[++cur];
738 PUSH2(oGLXAttr, GLX_STEREO, pop);
739 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
740 break;
742 case WGL_PIXEL_TYPE_ARB:
743 pop = iWGLAttr[++cur];
744 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
745 switch (pop) {
746 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
747 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
748 /* 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 */
749 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
750 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
751 default:
752 ERR("unexpected PixelType(%x)\n", pop);
753 pop = 0;
755 break;
757 case WGL_SUPPORT_GDI_ARB:
758 /* This flag is set in a WineGLPixelFormat */
759 pop = iWGLAttr[++cur];
760 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
761 break;
763 case WGL_DRAW_TO_BITMAP_ARB:
764 /* This flag is set in a WineGLPixelFormat */
765 pop = iWGLAttr[++cur];
766 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
767 break;
769 case WGL_DRAW_TO_WINDOW_ARB:
770 pop = iWGLAttr[++cur];
771 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
772 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
773 if (pop) {
774 drawattrib |= GLX_WINDOW_BIT;
776 break;
778 case WGL_DRAW_TO_PBUFFER_ARB:
779 pop = iWGLAttr[++cur];
780 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
781 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
782 if (pop) {
783 drawattrib |= GLX_PBUFFER_BIT;
785 break;
787 case WGL_ACCELERATION_ARB:
788 /* This flag is set in a WineGLPixelFormat */
789 pop = iWGLAttr[++cur];
790 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
791 break;
793 case WGL_SUPPORT_OPENGL_ARB:
794 pop = iWGLAttr[++cur];
795 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
796 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
797 break;
799 case WGL_SWAP_METHOD_ARB:
800 pop = iWGLAttr[++cur];
801 /* For now we ignore this and just return SWAP_EXCHANGE */
802 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
803 break;
805 case WGL_PBUFFER_LARGEST_ARB:
806 pop = iWGLAttr[++cur];
807 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
808 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
809 break;
811 case WGL_SAMPLE_BUFFERS_ARB:
812 pop = iWGLAttr[++cur];
813 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
814 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
815 break;
817 case WGL_SAMPLES_ARB:
818 pop = iWGLAttr[++cur];
819 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
820 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
821 break;
823 case WGL_TEXTURE_FORMAT_ARB:
824 case WGL_TEXTURE_TARGET_ARB:
825 case WGL_MIPMAP_TEXTURE_ARB:
826 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
827 pop = iWGLAttr[++cur];
828 if (NULL == pbuf) {
829 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
831 if (use_render_texture_ati) {
832 /** nothing to do here */
834 else if (!use_render_texture_emulation) {
835 if (WGL_NO_TEXTURE_ARB != pop) {
836 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
837 return -1; /** error: don't support it */
838 } else {
839 drawattrib |= GLX_PBUFFER_BIT;
842 break ;
843 case WGL_FLOAT_COMPONENTS_NV:
844 nvfloatattrib = iWGLAttr[++cur];
845 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
846 break ;
847 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
848 case WGL_BIND_TO_TEXTURE_RGB_ARB:
849 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
850 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
851 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
852 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
853 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
854 pop = iWGLAttr[++cur];
855 /** cannot be converted, see direct handling on
856 * - wglGetPixelFormatAttribivARB
857 * TODO: wglChoosePixelFormat
859 break ;
860 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
861 pop = iWGLAttr[++cur];
862 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
863 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
864 break ;
866 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
867 pop = iWGLAttr[++cur];
868 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
869 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
870 break ;
871 default:
872 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
873 break;
875 ++cur;
878 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
879 * all formats. Unless drawattrib is set to a non-zero value override it with ~0, so that pixmap and pbuffer
880 * formats appear as well. */
881 if(!drawattrib) drawattrib = ~0;
882 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
883 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
885 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
886 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to ~0 unless
887 * it is overridden. */
888 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
889 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
891 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
892 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
893 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
894 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
897 return nAttribs;
900 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
902 int render_type=0, render_type_bit;
903 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
904 switch(render_type_bit)
906 case GLX_RGBA_BIT:
907 render_type = GLX_RGBA_TYPE;
908 break;
909 case GLX_COLOR_INDEX_BIT:
910 render_type = GLX_COLOR_INDEX_TYPE;
911 break;
912 case GLX_RGBA_FLOAT_BIT:
913 render_type = GLX_RGBA_FLOAT_TYPE;
914 break;
915 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
916 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
917 break;
918 default:
919 ERR("Unknown render_type: %x\n", render_type_bit);
921 return render_type;
924 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
925 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
927 int dbuf, value;
928 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
929 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
931 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
932 * the GLX_PIXMAP_BIT set. */
933 return !dbuf && (value & GLX_PIXMAP_BIT);
936 static WineGLPixelFormat *get_formats(Display *display, int *size_ret, int *onscreen_size_ret)
938 static WineGLPixelFormat *list;
939 static int size, onscreen_size;
941 int fmt_id, nCfgs, i, run, bmp_formats;
942 GLXFBConfig* cfgs;
943 XVisualInfo *visinfo;
945 wine_tsx11_lock();
946 if (list) goto done;
948 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
949 if (NULL == cfgs || 0 == nCfgs) {
950 if(cfgs != NULL) XFree(cfgs);
951 wine_tsx11_unlock();
952 ERR("glXChooseFBConfig returns NULL\n");
953 return NULL;
956 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
957 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
958 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
959 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
961 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
963 for(i=0, bmp_formats=0; i<nCfgs; i++)
965 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
966 bmp_formats++;
968 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
970 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats)*sizeof(WineGLPixelFormat));
972 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
973 * Do this as GLX doesn't guarantee that the list is sorted */
974 for(run=0; run < 2; run++)
976 for(i=0; i<nCfgs; i++) {
977 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
978 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
980 /* The first run we only add onscreen formats (ones which have an associated X Visual).
981 * The second run we only set offscreen formats. */
982 if(!run && visinfo)
984 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
985 * The contents is copied to the destination using XCopyArea. For the copying to work
986 * the depth of the source and destination window should be the same. In general this should
987 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
988 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
989 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
990 * list formats with the same depth. */
991 if(visinfo->depth != screen_depth)
993 XFree(visinfo);
994 continue;
997 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
998 list[size].iPixelFormat = size+1; /* The index starts at 1 */
999 list[size].fbconfig = cfgs[i];
1000 list[size].fmt_id = fmt_id;
1001 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1002 list[size].offscreenOnly = FALSE;
1003 list[size].dwFlags = 0;
1004 size++;
1005 onscreen_size++;
1007 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1008 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1010 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1011 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1012 list[size].fbconfig = cfgs[i];
1013 list[size].fmt_id = fmt_id;
1014 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1015 list[size].offscreenOnly = FALSE;
1016 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1017 size++;
1018 onscreen_size++;
1020 } else if(run && !visinfo) {
1021 int window_drawable=0;
1022 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1024 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1025 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1026 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1027 * likely make our child window opengl rendering more complicated since likely you can't use
1028 * XCopyArea on a GLX Window.
1029 * For now ignore fbconfigs which are window drawable but lack a visual. */
1030 if(window_drawable & GLX_WINDOW_BIT)
1032 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1033 continue;
1036 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1037 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1038 list[size].fbconfig = cfgs[i];
1039 list[size].fmt_id = fmt_id;
1040 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1041 list[size].offscreenOnly = TRUE;
1042 list[size].dwFlags = 0;
1043 size++;
1046 if (visinfo) XFree(visinfo);
1050 XFree(cfgs);
1052 done:
1053 if (size_ret) *size_ret = size;
1054 if (onscreen_size_ret) *onscreen_size_ret = onscreen_size;
1055 wine_tsx11_unlock();
1056 return list;
1059 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1060 * In our WGL implementation we only support a subset of these formats namely the format of
1061 * Wine's main visual and offscreen formats (if they are available).
1062 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1063 * and it returns the number of supported WGL formats in fmt_count.
1065 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
1067 WineGLPixelFormat *list, *res = NULL;
1068 int size, onscreen_size;
1070 if (!(list = get_formats(display, &size, &onscreen_size ))) return NULL;
1072 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1073 * iPixelFormat in case of probing the number of pixelformats.
1075 if((iPixelFormat > 0) && (iPixelFormat <= size) &&
1076 (!list[iPixelFormat-1].offscreenOnly || AllowOffscreen)) {
1077 res = &list[iPixelFormat-1];
1078 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res->fmt_id, iPixelFormat);
1081 if(AllowOffscreen)
1082 *fmt_count = size;
1083 else
1084 *fmt_count = onscreen_size;
1086 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
1088 return res;
1091 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1092 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id, DWORD dwFlags)
1094 WineGLPixelFormat *list;
1095 int i, size;
1097 if (!(list = get_formats(display, &size, NULL ))) return NULL;
1099 for(i=0; i<size; i++) {
1100 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1101 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1102 if( (list[i].fmt_id == fmt_id) && ((list[i].dwFlags & dwFlags) == dwFlags) ) {
1103 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list[i].iPixelFormat, fmt_id);
1104 return &list[i];
1107 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
1108 return NULL;
1111 int pixelformat_from_fbconfig_id(XID fbconfig_id)
1113 WineGLPixelFormat *fmt;
1115 if (!fbconfig_id) return 0;
1117 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
1118 if(fmt)
1119 return fmt->iPixelFormat;
1120 /* This will happen on hwnds without a pixel format set; it's ok */
1121 return 0;
1125 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1126 void mark_drawable_dirty(Drawable old, Drawable new)
1128 Wine_GLContext *ctx;
1129 for (ctx = context_list; ctx; ctx = ctx->next) {
1130 if (old == ctx->drawables[0]) {
1131 ctx->drawables[0] = new;
1132 ctx->refresh_drawables = TRUE;
1134 if (old == ctx->drawables[1]) {
1135 ctx->drawables[1] = new;
1136 ctx->refresh_drawables = TRUE;
1141 /* Given the current context, make sure its drawable is sync'd */
1142 static inline void sync_context(Wine_GLContext *context)
1144 if(context && context->refresh_drawables) {
1145 if (glxRequireVersion(3))
1146 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1147 context->drawables[1], context->ctx);
1148 else
1149 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1150 context->refresh_drawables = FALSE;
1155 static GLXContext create_glxcontext(Display *display, Wine_GLContext *context, GLXContext shareList)
1157 GLXContext ctx;
1159 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1160 BOOL indirect = (context->fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? FALSE : TRUE;
1162 if(context->gl3_context)
1164 if(context->numAttribs)
1165 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1166 else
1167 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1169 else if(context->vis)
1170 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1171 else /* Create a GLX Context for a pbuffer */
1172 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1174 return ctx;
1178 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1180 return pglXCreateGLXPixmap(display, vis, parent);
1184 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev, WineGLPixelFormat *fmt)
1186 GLXPixmap ret = 0;
1187 XVisualInfo *vis;
1189 wine_tsx11_lock();
1191 vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1192 if(vis) {
1193 if(vis->depth == physDev->bitmap->depth)
1194 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
1195 XFree(vis);
1197 wine_tsx11_unlock();
1198 TRACE("return %lx\n", ret);
1199 return ret;
1203 * X11DRV_ChoosePixelFormat
1205 * Equivalent to glXChooseVisual.
1207 int X11DRV_ChoosePixelFormat(PHYSDEV dev, const PIXELFORMATDESCRIPTOR *ppfd)
1209 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
1210 WineGLPixelFormat *list;
1211 int onscreen_size;
1212 int ret = 0;
1213 int value = 0;
1214 int i = 0;
1215 int bestFormat = -1;
1216 int bestDBuffer = -1;
1217 int bestStereo = -1;
1218 int bestColor = -1;
1219 int bestAlpha = -1;
1220 int bestDepth = -1;
1221 int bestStencil = -1;
1222 int bestAux = -1;
1224 if (!has_opengl()) return 0;
1226 if (TRACE_ON(wgl)) {
1227 TRACE("(%p,%p)\n", physDev, ppfd);
1229 dump_PIXELFORMATDESCRIPTOR(ppfd);
1232 if (!(list = get_formats(gdi_display, NULL, &onscreen_size ))) return 0;
1234 wine_tsx11_lock();
1235 for(i=0; i<onscreen_size; i++)
1237 int dwFlags = 0;
1238 int iPixelType = 0;
1239 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1240 WineGLPixelFormat *fmt = &list[i];
1242 /* Pixel type */
1243 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1244 if (value & GLX_RGBA_BIT)
1245 iPixelType = PFD_TYPE_RGBA;
1246 else
1247 iPixelType = PFD_TYPE_COLORINDEX;
1249 if (ppfd->iPixelType != iPixelType)
1251 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1252 continue;
1255 /* Only use bitmap capable for formats for bitmap rendering.
1256 * See get_formats for more info. */
1257 if( (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) != (fmt->dwFlags & PFD_DRAW_TO_BITMAP))
1259 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i+1);
1260 continue;
1263 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1264 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1265 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1266 if (value) dwFlags |= PFD_STEREO;
1267 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1268 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1269 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1270 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1271 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1273 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1274 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1275 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1276 * formats without the given flag set.
1277 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1278 * has indicated that a format without stereo is returned when stereo is unavailable.
1279 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1280 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1282 * To summarize the following is most likely the correct behavior:
1283 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1284 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1285 * stereo don't care -> it doesn't matter whether we get stereo or not
1287 * In Wine we will treat no-stereo the same way as don't care because it makes
1288 * format selection even more complicated and second drivers with Stereo advertise
1289 * each format twice anyway.
1292 /* Doublebuffer, see the comments above */
1293 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1294 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1295 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1297 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1298 bestStereo = dwFlags & PFD_STEREO;
1299 bestAlpha = alpha;
1300 bestColor = color;
1301 bestDepth = depth;
1302 bestStencil = stencil;
1303 bestAux = aux;
1304 bestFormat = i;
1305 continue;
1307 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1308 continue;
1311 /* Stereo, see the comments above. */
1312 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1313 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1314 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1316 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1317 bestStereo = dwFlags & PFD_STEREO;
1318 bestAlpha = alpha;
1319 bestColor = color;
1320 bestDepth = depth;
1321 bestStencil = stencil;
1322 bestAux = aux;
1323 bestFormat = i;
1324 continue;
1326 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1327 continue;
1330 /* Below we will do a number of checks to select the 'best' pixelformat.
1331 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1332 * The code works by trying to match the most important options as close as possible.
1333 * When a reasonable format is found, we will try to match more options.
1334 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1335 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1336 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1338 /* Color bits */
1339 if(ppfd->cColorBits) {
1340 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1341 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1343 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1344 bestStereo = dwFlags & PFD_STEREO;
1345 bestAlpha = alpha;
1346 bestColor = color;
1347 bestDepth = depth;
1348 bestStencil = stencil;
1349 bestAux = aux;
1350 bestFormat = i;
1351 continue;
1352 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1353 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1354 continue;
1358 /* Alpha bits */
1359 if(ppfd->cAlphaBits) {
1360 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1361 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1363 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1364 bestStereo = dwFlags & PFD_STEREO;
1365 bestAlpha = alpha;
1366 bestColor = color;
1367 bestDepth = depth;
1368 bestStencil = stencil;
1369 bestAux = aux;
1370 bestFormat = i;
1371 continue;
1372 } else if(bestAlpha != alpha) {
1373 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1374 continue;
1378 /* Depth bits */
1379 if(ppfd->cDepthBits) {
1380 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1381 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1383 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1384 bestStereo = dwFlags & PFD_STEREO;
1385 bestAlpha = alpha;
1386 bestColor = color;
1387 bestDepth = depth;
1388 bestStencil = stencil;
1389 bestAux = aux;
1390 bestFormat = i;
1391 continue;
1392 } else if(bestDepth != depth) {
1393 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1394 continue;
1398 /* Stencil bits */
1399 if(ppfd->cStencilBits) {
1400 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1401 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1403 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1404 bestStereo = dwFlags & PFD_STEREO;
1405 bestAlpha = alpha;
1406 bestColor = color;
1407 bestDepth = depth;
1408 bestStencil = stencil;
1409 bestAux = aux;
1410 bestFormat = i;
1411 continue;
1412 } else if(bestStencil != stencil) {
1413 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1414 continue;
1418 /* Aux buffers */
1419 if(ppfd->cAuxBuffers) {
1420 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1421 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1423 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1424 bestStereo = dwFlags & PFD_STEREO;
1425 bestAlpha = alpha;
1426 bestColor = color;
1427 bestDepth = depth;
1428 bestStencil = stencil;
1429 bestAux = aux;
1430 bestFormat = i;
1431 continue;
1432 } else if(bestAux != aux) {
1433 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1434 continue;
1439 if(bestFormat == -1) {
1440 TRACE("No matching mode was found returning 0\n");
1441 ret = 0;
1443 else {
1444 ret = bestFormat+1; /* the return value should be a 1-based index */
1445 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, list[bestFormat].fmt_id);
1448 wine_tsx11_unlock();
1450 return ret;
1453 * X11DRV_DescribePixelFormat
1455 * Get the pixel-format descriptor associated to the given id
1457 int X11DRV_DescribePixelFormat(PHYSDEV dev, int iPixelFormat,
1458 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1460 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
1461 /*XVisualInfo *vis;*/
1462 int value;
1463 int rb,gb,bb,ab;
1464 WineGLPixelFormat *fmt;
1465 int ret = 0;
1466 int fmt_count = 0;
1468 if (!has_opengl()) return 0;
1470 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1472 /* 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 */
1473 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1474 if (ppfd == NULL) {
1475 /* The application is only querying the number of pixelformats */
1476 return fmt_count;
1477 } else if(fmt == NULL) {
1478 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1479 return 0;
1482 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1483 ERR("Wrong structure size !\n");
1484 /* Should set error */
1485 return 0;
1488 ret = fmt_count;
1490 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1491 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1492 ppfd->nVersion = 1;
1494 /* These flags are always the same... */
1495 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1496 /* Now the flags extracted from the Visual */
1498 wine_tsx11_lock();
1500 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1501 if(value & GLX_WINDOW_BIT)
1502 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1504 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1505 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1506 * 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
1507 * offered the GDI bit either. */
1508 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1510 /* PFD_GENERIC_FORMAT - gdi software rendering
1511 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1512 * none set - full hardware accelerated by a ICD
1514 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1515 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1517 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1518 if (value) {
1519 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1520 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1522 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1524 /* Pixel type */
1525 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1526 if (value & GLX_RGBA_BIT)
1527 ppfd->iPixelType = PFD_TYPE_RGBA;
1528 else
1529 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1531 /* Color bits */
1532 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1533 ppfd->cColorBits = value;
1535 /* Red, green, blue and alpha bits / shifts */
1536 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1537 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1538 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1539 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1540 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1542 ppfd->cRedBits = rb;
1543 ppfd->cRedShift = gb + bb + ab;
1544 ppfd->cBlueBits = bb;
1545 ppfd->cBlueShift = ab;
1546 ppfd->cGreenBits = gb;
1547 ppfd->cGreenShift = bb + ab;
1548 ppfd->cAlphaBits = ab;
1549 ppfd->cAlphaShift = 0;
1550 } else {
1551 ppfd->cRedBits = 0;
1552 ppfd->cRedShift = 0;
1553 ppfd->cBlueBits = 0;
1554 ppfd->cBlueShift = 0;
1555 ppfd->cGreenBits = 0;
1556 ppfd->cGreenShift = 0;
1557 ppfd->cAlphaBits = 0;
1558 ppfd->cAlphaShift = 0;
1561 /* Accum RGBA bits */
1562 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1563 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1564 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1565 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1567 ppfd->cAccumBits = rb+gb+bb+ab;
1568 ppfd->cAccumRedBits = rb;
1569 ppfd->cAccumGreenBits = gb;
1570 ppfd->cAccumBlueBits = bb;
1571 ppfd->cAccumAlphaBits = ab;
1573 /* Aux bits */
1574 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1575 ppfd->cAuxBuffers = value;
1577 /* Depth bits */
1578 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1579 ppfd->cDepthBits = value;
1581 /* stencil bits */
1582 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1583 ppfd->cStencilBits = value;
1585 wine_tsx11_unlock();
1587 ppfd->iLayerType = PFD_MAIN_PLANE;
1589 if (TRACE_ON(wgl)) {
1590 dump_PIXELFORMATDESCRIPTOR(ppfd);
1593 return ret;
1597 * X11DRV_GetPixelFormat
1599 * Get the pixel-format id used by this DC
1601 int X11DRV_GetPixelFormat(PHYSDEV dev)
1603 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
1604 WineGLPixelFormat *fmt;
1605 int tmp;
1606 TRACE("(%p)\n", physDev);
1608 if (!physDev->current_pf) return 0; /* not set yet */
1610 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1611 if(!fmt)
1613 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1614 return 0;
1616 else if(fmt->offscreenOnly)
1618 /* Offscreen formats can't be used with traditional WGL calls.
1619 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1620 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1621 return 1;
1624 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1625 return physDev->current_pf;
1628 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1629 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1630 * set the pixel format multiple times. */
1631 static BOOL internal_SetPixelFormat(X11DRV_PDEVICE *physDev,
1632 int iPixelFormat,
1633 const PIXELFORMATDESCRIPTOR *ppfd) {
1634 WineGLPixelFormat *fmt;
1635 int value;
1636 HWND hwnd;
1638 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1639 if(get_glxdrawable(physDev) == root_window)
1641 ERR("Invalid operation on root_window\n");
1642 return FALSE;
1645 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1646 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1647 if(!fmt) {
1648 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1649 return FALSE;
1652 wine_tsx11_lock();
1653 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1654 wine_tsx11_unlock();
1656 hwnd = WindowFromDC(physDev->dev.hdc);
1657 if(hwnd) {
1658 if(!(value&GLX_WINDOW_BIT)) {
1659 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1660 return FALSE;
1663 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1664 ERR("Couldn't set format of the window, returning failure\n");
1665 return FALSE;
1668 else if(physDev->bitmap) {
1669 if(!(value&GLX_PIXMAP_BIT)) {
1670 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1671 return FALSE;
1674 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev, fmt);
1675 if(!physDev->bitmap->glxpixmap) {
1676 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat);
1677 return FALSE;
1680 else {
1681 FIXME("called on a non-window, non-bitmap object?\n");
1684 physDev->current_pf = iPixelFormat;
1686 if (TRACE_ON(wgl)) {
1687 int gl_test = 0;
1689 wine_tsx11_lock();
1690 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1691 if (gl_test) {
1692 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1693 } else {
1694 TRACE(" FBConfig have :\n");
1695 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1696 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1697 TRACE(" - VISUAL_ID 0x%x\n", value);
1698 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1699 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1701 wine_tsx11_unlock();
1703 return TRUE;
1708 * X11DRV_SetPixelFormat
1710 * Set the pixel-format id used by this DC
1712 BOOL X11DRV_SetPixelFormat(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
1714 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
1716 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1718 if (!has_opengl()) return FALSE;
1720 if(physDev->current_pf) /* cannot change it if already set */
1721 return (physDev->current_pf == iPixelFormat);
1723 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
1727 * X11DRV_wglCopyContext
1729 * For OpenGL32 wglCopyContext.
1731 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
1733 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1734 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1736 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1738 wine_tsx11_lock();
1739 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1740 wine_tsx11_unlock();
1742 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1743 return TRUE;
1747 * X11DRV_wglCreateContext
1749 * For OpenGL32 wglCreateContext.
1751 HGLRC X11DRV_wglCreateContext(PHYSDEV dev)
1753 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
1754 Wine_GLContext *ret;
1755 WineGLPixelFormat *fmt;
1756 int hdcPF = physDev->current_pf;
1757 int fmt_count = 0;
1758 HDC hdc = dev->hdc;
1760 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1762 if (!has_opengl()) return 0;
1764 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1765 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1766 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1767 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1768 * If this fails something is very wrong on the system. */
1769 if(!fmt) {
1770 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1771 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1772 return NULL;
1775 wine_tsx11_lock();
1776 ret = alloc_context();
1777 ret->hdc = hdc;
1778 ret->fmt = fmt;
1779 ret->has_been_current = FALSE;
1780 ret->sharing = FALSE;
1782 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1783 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1784 wine_tsx11_unlock();
1786 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1787 return (HGLRC) ret;
1791 * X11DRV_wglDeleteContext
1793 * For OpenGL32 wglDeleteContext.
1795 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1797 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1799 TRACE("(%p)\n", hglrc);
1801 if (!has_opengl()) return 0;
1803 if (!is_valid_context(ctx))
1805 WARN("Error deleting context !\n");
1806 SetLastError(ERROR_INVALID_HANDLE);
1807 return FALSE;
1810 /* WGL doesn't allow deletion of a context which is current in another thread */
1811 if (ctx->tid != 0 && ctx->tid != GetCurrentThreadId())
1813 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx);
1814 SetLastError(ERROR_BUSY);
1815 return FALSE;
1818 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1819 if (ctx == NtCurrentTeb()->glContext)
1820 wglMakeCurrent(ctx->hdc, NULL);
1822 if (ctx->ctx)
1824 wine_tsx11_lock();
1825 pglXDestroyContext(gdi_display, ctx->ctx);
1826 wine_tsx11_unlock();
1829 free_context(ctx);
1830 return TRUE;
1834 * X11DRV_wglGetCurrentReadDCARB
1836 * For OpenGL32 wglGetCurrentReadDCARB.
1838 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1840 HDC ret = 0;
1841 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1843 if (ctx) ret = ctx->read_hdc;
1845 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1846 return ret;
1850 * X11DRV_wglGetProcAddress
1852 * For OpenGL32 wglGetProcAddress.
1854 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1856 int i, j;
1857 const WineGLExtension *ext;
1859 int padding = 32 - strlen(lpszProc);
1860 if (padding < 0)
1861 padding = 0;
1863 if (!has_opengl()) return NULL;
1865 /* Check the table of WGL extensions to see if we need to return a WGL extension
1866 * or a function pointer to a native OpenGL function. */
1867 if(strncmp(lpszProc, "wgl", 3) != 0) {
1868 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1869 } else {
1870 TRACE("('%s'):%*s", lpszProc, padding, " ");
1871 for (i = 0; i < WineGLExtensionListSize; ++i) {
1872 ext = WineGLExtensionList[i];
1873 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1874 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1875 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1876 return ext->extEntryPoints[j].funcAddress;
1882 WARN("(%s) - not found\n", lpszProc);
1883 return NULL;
1887 * X11DRV_wglMakeCurrent
1889 * For OpenGL32 wglMakeCurrent.
1891 BOOL X11DRV_wglMakeCurrent(PHYSDEV dev, HGLRC hglrc)
1893 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
1894 BOOL ret;
1895 HDC hdc = dev->hdc;
1896 DWORD type = GetObjectType(hdc);
1897 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1899 TRACE("(%p,%p)\n", hdc, hglrc);
1901 if (!has_opengl()) return FALSE;
1903 wine_tsx11_lock();
1904 if (hglrc == NULL)
1906 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1907 if (prev_ctx) prev_ctx->tid = 0;
1909 ret = pglXMakeCurrent(gdi_display, None, NULL);
1910 NtCurrentTeb()->glContext = NULL;
1912 else if (!physDev->current_pf)
1914 WARN("Trying to use an invalid drawable\n");
1915 SetLastError(ERROR_INVALID_HANDLE);
1916 ret = FALSE;
1918 else if (ctx->fmt->iPixelFormat != physDev->current_pf)
1920 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1921 hdc, physDev->current_pf, ctx, ctx->fmt->iPixelFormat );
1922 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1923 ret = FALSE;
1925 else
1927 Drawable drawable = get_glxdrawable(physDev);
1928 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1930 /* The describe lines below are for debugging purposes only */
1931 if (TRACE_ON(wgl)) {
1932 describeDrawable(physDev);
1933 describeContext(ctx);
1936 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1937 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1939 if (ret)
1941 if (prev_ctx) prev_ctx->tid = 0;
1942 NtCurrentTeb()->glContext = ctx;
1944 ctx->has_been_current = TRUE;
1945 ctx->tid = GetCurrentThreadId();
1946 ctx->hdc = hdc;
1947 ctx->read_hdc = hdc;
1948 ctx->drawables[0] = drawable;
1949 ctx->drawables[1] = drawable;
1950 ctx->refresh_drawables = FALSE;
1952 if (type == OBJ_MEMDC) pglDrawBuffer(GL_FRONT_LEFT);
1954 else
1955 SetLastError(ERROR_INVALID_HANDLE);
1957 wine_tsx11_unlock();
1958 TRACE(" returning %s\n", (ret ? "True" : "False"));
1959 return ret;
1963 * X11DRV_wglMakeContextCurrentARB
1965 * For OpenGL32 wglMakeContextCurrentARB
1967 BOOL X11DRV_wglMakeContextCurrentARB( PHYSDEV draw_dev, PHYSDEV read_dev, HGLRC hglrc )
1969 X11DRV_PDEVICE *pDrawDev = get_x11drv_dev( draw_dev );
1970 X11DRV_PDEVICE *pReadDev = get_x11drv_dev( read_dev );
1971 BOOL ret;
1973 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1975 if (!has_opengl()) return 0;
1977 wine_tsx11_lock();
1978 if (hglrc == NULL)
1980 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1981 if (prev_ctx) prev_ctx->tid = 0;
1983 ret = pglXMakeCurrent(gdi_display, None, NULL);
1984 NtCurrentTeb()->glContext = NULL;
1986 else if (!pDrawDev->current_pf)
1988 WARN("Trying to use an invalid drawable\n");
1989 SetLastError(ERROR_INVALID_HANDLE);
1990 ret = FALSE;
1992 else
1994 if (NULL == pglXMakeContextCurrent) {
1995 ret = FALSE;
1996 } else {
1997 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1998 Drawable d_draw = get_glxdrawable(pDrawDev);
1999 Drawable d_read = get_glxdrawable(pReadDev);
2001 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
2002 if (ret)
2004 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
2005 if (prev_ctx) prev_ctx->tid = 0;
2007 ctx->has_been_current = TRUE;
2008 ctx->tid = GetCurrentThreadId();
2009 ctx->hdc = draw_dev->hdc;
2010 ctx->read_hdc = read_dev->hdc;
2011 ctx->drawables[0] = d_draw;
2012 ctx->drawables[1] = d_read;
2013 ctx->refresh_drawables = FALSE;
2014 NtCurrentTeb()->glContext = ctx;
2016 else
2017 SetLastError(ERROR_INVALID_HANDLE);
2020 wine_tsx11_unlock();
2022 TRACE(" returning %s\n", (ret ? "True" : "False"));
2023 return ret;
2027 * X11DRV_wglShareLists
2029 * For OpenGL32 wglShareLists.
2031 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
2033 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
2034 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
2036 TRACE("(%p, %p)\n", org, dest);
2038 if (!has_opengl()) return FALSE;
2040 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
2041 * at context creation time but in case of WGL it is done using wglShareLists.
2042 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
2043 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
2044 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
2045 * so there delaying context creation doesn't work.
2047 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
2048 * and when a program requests sharing we recreate the destination context if it hasn't been made
2049 * current or when it hasn't shared display lists before.
2052 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
2054 ERR("Could not share display lists, one of the contexts has been current already !\n");
2055 return FALSE;
2057 else if(dest->sharing)
2059 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
2060 return FALSE;
2062 else
2064 if((GetObjectType(org->hdc) == OBJ_MEMDC) ^ (GetObjectType(dest->hdc) == OBJ_MEMDC))
2066 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
2069 wine_tsx11_lock();
2070 describeContext(org);
2071 describeContext(dest);
2073 /* Re-create the GLX context and share display lists */
2074 pglXDestroyContext(gdi_display, dest->ctx);
2075 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
2076 wine_tsx11_unlock();
2077 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
2079 org->sharing = TRUE;
2080 dest->sharing = TRUE;
2081 return TRUE;
2083 return FALSE;
2086 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
2088 /* We are running using client-side rendering fonts... */
2089 GLYPHMETRICS gm;
2090 unsigned int glyph, size = 0;
2091 void *bitmap = NULL, *gl_bitmap = NULL;
2092 int org_alignment;
2094 wine_tsx11_lock();
2095 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
2096 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
2097 wine_tsx11_unlock();
2099 for (glyph = first; glyph < first + count; glyph++) {
2100 static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
2101 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
2102 unsigned int height, width_int;
2104 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
2105 if (needed_size == GDI_ERROR) {
2106 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
2107 goto error;
2108 } else {
2109 TRACE(" - needed size : %d\n", needed_size);
2112 if (needed_size > size) {
2113 size = needed_size;
2114 HeapFree(GetProcessHeap(), 0, bitmap);
2115 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2116 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2117 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2119 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) == GDI_ERROR)
2120 goto error;
2121 if (TRACE_ON(wgl)) {
2122 unsigned int height, width, bitmask;
2123 unsigned char *bitmap_ = bitmap;
2125 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
2126 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
2127 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
2128 if (needed_size != 0) {
2129 TRACE(" - bitmap :\n");
2130 for (height = 0; height < gm.gmBlackBoxY; height++) {
2131 TRACE(" ");
2132 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
2133 if (bitmask == 0) {
2134 bitmap_ += 1;
2135 bitmask = 0x80;
2137 if (*bitmap_ & bitmask)
2138 TRACE("*");
2139 else
2140 TRACE(" ");
2142 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
2143 TRACE("\n");
2148 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2149 * glyph for it to be drawn properly.
2151 if (needed_size != 0) {
2152 width_int = (gm.gmBlackBoxX + 31) / 32;
2153 for (height = 0; height < gm.gmBlackBoxY; height++) {
2154 unsigned int width;
2155 for (width = 0; width < width_int; width++) {
2156 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
2157 ((int *) bitmap)[height * width_int + width];
2162 wine_tsx11_lock();
2163 pglNewList(listBase++, GL_COMPILE);
2164 if (needed_size != 0) {
2165 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
2166 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
2167 gm.gmCellIncX, gm.gmCellIncY,
2168 gl_bitmap);
2169 } else {
2170 /* This is the case of 'empty' glyphs like the space character */
2171 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
2173 pglEndList();
2174 wine_tsx11_unlock();
2177 wine_tsx11_lock();
2178 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2179 wine_tsx11_unlock();
2181 HeapFree(GetProcessHeap(), 0, bitmap);
2182 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2183 return TRUE;
2185 error:
2186 wine_tsx11_lock();
2187 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2188 wine_tsx11_unlock();
2190 HeapFree(GetProcessHeap(), 0, bitmap);
2191 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2192 return FALSE;
2196 * X11DRV_wglUseFontBitmapsA
2198 * For OpenGL32 wglUseFontBitmapsA.
2200 BOOL X11DRV_wglUseFontBitmapsA(PHYSDEV dev, DWORD first, DWORD count, DWORD listBase)
2202 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
2203 Font fid = physDev->font;
2205 TRACE("(%p, %d, %d, %d) using font %ld\n", dev->hdc, first, count, listBase, fid);
2207 if (!has_opengl()) return FALSE;
2209 if (fid == 0) {
2210 return internal_wglUseFontBitmaps(dev->hdc, first, count, listBase, GetGlyphOutlineA);
2213 wine_tsx11_lock();
2214 /* I assume that the glyphs are at the same position for X and for Windows */
2215 pglXUseXFont(fid, first, count, listBase);
2216 wine_tsx11_unlock();
2217 return TRUE;
2221 * X11DRV_wglUseFontBitmapsW
2223 * For OpenGL32 wglUseFontBitmapsW.
2225 BOOL X11DRV_wglUseFontBitmapsW(PHYSDEV dev, DWORD first, DWORD count, DWORD listBase)
2227 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
2228 Font fid = physDev->font;
2230 TRACE("(%p, %d, %d, %d) using font %ld\n", dev->hdc, first, count, listBase, fid);
2232 if (!has_opengl()) return FALSE;
2234 if (fid == 0) {
2235 return internal_wglUseFontBitmaps(dev->hdc, first, count, listBase, GetGlyphOutlineW);
2238 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2240 wine_tsx11_lock();
2241 /* I assume that the glyphs are at the same position for X and for Windows */
2242 pglXUseXFont(fid, first, count, listBase);
2243 wine_tsx11_unlock();
2244 return TRUE;
2247 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2248 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2250 wine_tsx11_lock();
2251 switch(pname)
2253 case GL_DEPTH_BITS:
2255 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2257 pglGetIntegerv(pname, params);
2259 * if we cannot find a Wine Context
2260 * we only have the default wine desktop context,
2261 * so if we have only a 24 depth say we have 32
2263 if (!ctx && *params == 24) {
2264 *params = 32;
2266 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2267 break;
2269 case GL_ALPHA_BITS:
2271 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2273 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2274 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2275 break;
2277 default:
2278 pglGetIntegerv(pname, params);
2279 break;
2281 wine_tsx11_unlock();
2284 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
2286 int w, h;
2288 if (!physDev->gl_copy || !physDev->current_pf)
2289 return;
2291 w = physDev->dc_rect.right - physDev->dc_rect.left;
2292 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
2294 if(w > 0 && h > 0) {
2295 Drawable src = physDev->pixmap;
2296 if(!src) src = physDev->gl_drawable;
2298 /* The GL drawable may be lagged behind if we don't flush first, so
2299 * flush the display make sure we copy up-to-date data */
2300 wine_tsx11_lock();
2301 XFlush(gdi_display);
2302 XSetFunction(gdi_display, physDev->gc, GXcopy);
2303 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
2304 physDev->dc_rect.left, physDev->dc_rect.top);
2305 wine_tsx11_unlock();
2310 static void WINAPI X11DRV_wglFinish(void)
2312 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2313 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2315 wine_tsx11_lock();
2316 sync_context(ctx);
2317 pglFinish();
2318 wine_tsx11_unlock();
2319 if (ctx) ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2322 static void WINAPI X11DRV_wglFlush(void)
2324 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2325 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2327 wine_tsx11_lock();
2328 sync_context(ctx);
2329 pglFlush();
2330 wine_tsx11_unlock();
2331 if (ctx) ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2335 * X11DRV_wglCreateContextAttribsARB
2337 * WGL_ARB_create_context: wglCreateContextAttribsARB
2339 HGLRC X11DRV_wglCreateContextAttribsARB(PHYSDEV dev, HGLRC hShareContext, const int* attribList)
2341 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
2342 Wine_GLContext *ret;
2343 WineGLPixelFormat *fmt;
2344 int hdcPF = physDev->current_pf;
2345 int fmt_count = 0;
2347 TRACE("(%p %p %p)\n", physDev, hShareContext, attribList);
2349 if (!has_opengl()) return 0;
2351 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
2352 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2353 * If this fails something is very wrong on the system. */
2354 if(!fmt)
2356 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
2357 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2358 return NULL;
2361 wine_tsx11_lock();
2362 ret = alloc_context();
2363 wine_tsx11_unlock();
2364 ret->hdc = dev->hdc;
2365 ret->fmt = fmt;
2366 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2367 ret->gl3_context = TRUE;
2369 ret->numAttribs = 0;
2370 if(attribList)
2372 int *pAttribList = (int*)attribList;
2373 int *pContextAttribList = &ret->attribList[0];
2374 /* attribList consists of pairs {token, value] terminated with 0 */
2375 while(pAttribList[0] != 0)
2377 TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]);
2378 switch(pAttribList[0])
2380 case WGL_CONTEXT_MAJOR_VERSION_ARB:
2381 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
2382 pContextAttribList[1] = pAttribList[1];
2383 break;
2384 case WGL_CONTEXT_MINOR_VERSION_ARB:
2385 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
2386 pContextAttribList[1] = pAttribList[1];
2387 break;
2388 case WGL_CONTEXT_LAYER_PLANE_ARB:
2389 break;
2390 case WGL_CONTEXT_FLAGS_ARB:
2391 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
2392 pContextAttribList[1] = pAttribList[1];
2393 break;
2394 case WGL_CONTEXT_PROFILE_MASK_ARB:
2395 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
2396 pContextAttribList[1] = pAttribList[1];
2397 break;
2398 default:
2399 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]);
2402 ret->numAttribs++;
2403 pAttribList += 2;
2404 pContextAttribList += 2;
2408 wine_tsx11_lock();
2409 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
2410 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
2412 XSync(gdi_display, False);
2413 if(X11DRV_check_error() || !ret->ctx)
2415 /* In the future we should convert the GLX error to a win32 one here if needed */
2416 ERR("Context creation failed\n");
2417 free_context(ret);
2418 wine_tsx11_unlock();
2419 return NULL;
2422 wine_tsx11_unlock();
2423 TRACE(" creating context %p\n", ret);
2424 return (HGLRC) ret;
2428 * X11DRV_wglGetExtensionsStringARB
2430 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2432 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2433 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2434 return WineGLInfo.wglExtensions;
2438 * X11DRV_wglCreatePbufferARB
2440 * WGL_ARB_pbuffer: wglCreatePbufferARB
2442 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2444 Wine_GLPBuffer* object = NULL;
2445 WineGLPixelFormat *fmt = NULL;
2446 int nCfgs = 0;
2447 int attribs[256];
2448 int nAttribs = 0;
2450 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2452 if (0 >= iPixelFormat) {
2453 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2454 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2455 return NULL; /* unexpected error */
2458 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2459 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2460 if(!fmt) {
2461 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2462 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2463 goto create_failed; /* unexpected error */
2466 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2467 if (NULL == object) {
2468 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2469 goto create_failed; /* unexpected error */
2471 object->hdc = hdc;
2472 object->display = gdi_display;
2473 object->width = iWidth;
2474 object->height = iHeight;
2475 object->fmt = fmt;
2477 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2478 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2479 while (piAttribList && 0 != *piAttribList) {
2480 int attr_v;
2481 switch (*piAttribList) {
2482 case WGL_PBUFFER_LARGEST_ARB: {
2483 ++piAttribList;
2484 attr_v = *piAttribList;
2485 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2486 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2487 break;
2490 case WGL_TEXTURE_FORMAT_ARB: {
2491 ++piAttribList;
2492 attr_v = *piAttribList;
2493 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2494 if (use_render_texture_ati) {
2495 int type = 0;
2496 switch (attr_v) {
2497 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2498 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2499 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2500 default:
2501 SetLastError(ERROR_INVALID_DATA);
2502 goto create_failed;
2504 object->use_render_texture = 1;
2505 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2506 } else {
2507 if (WGL_NO_TEXTURE_ARB == attr_v) {
2508 object->use_render_texture = 0;
2509 } else {
2510 if (!use_render_texture_emulation) {
2511 SetLastError(ERROR_INVALID_DATA);
2512 goto create_failed;
2514 switch (attr_v) {
2515 case WGL_TEXTURE_RGB_ARB:
2516 object->use_render_texture = GL_RGB;
2517 object->texture_bpp = 3;
2518 object->texture_format = GL_RGB;
2519 object->texture_type = GL_UNSIGNED_BYTE;
2520 break;
2521 case WGL_TEXTURE_RGBA_ARB:
2522 object->use_render_texture = GL_RGBA;
2523 object->texture_bpp = 4;
2524 object->texture_format = GL_RGBA;
2525 object->texture_type = GL_UNSIGNED_BYTE;
2526 break;
2528 /* WGL_FLOAT_COMPONENTS_NV */
2529 case WGL_TEXTURE_FLOAT_R_NV:
2530 object->use_render_texture = GL_FLOAT_R_NV;
2531 object->texture_bpp = 4;
2532 object->texture_format = GL_RED;
2533 object->texture_type = GL_FLOAT;
2534 break;
2535 case WGL_TEXTURE_FLOAT_RG_NV:
2536 object->use_render_texture = GL_FLOAT_RG_NV;
2537 object->texture_bpp = 8;
2538 object->texture_format = GL_LUMINANCE_ALPHA;
2539 object->texture_type = GL_FLOAT;
2540 break;
2541 case WGL_TEXTURE_FLOAT_RGB_NV:
2542 object->use_render_texture = GL_FLOAT_RGB_NV;
2543 object->texture_bpp = 12;
2544 object->texture_format = GL_RGB;
2545 object->texture_type = GL_FLOAT;
2546 break;
2547 case WGL_TEXTURE_FLOAT_RGBA_NV:
2548 object->use_render_texture = GL_FLOAT_RGBA_NV;
2549 object->texture_bpp = 16;
2550 object->texture_format = GL_RGBA;
2551 object->texture_type = GL_FLOAT;
2552 break;
2553 default:
2554 ERR("Unknown texture format: %x\n", attr_v);
2555 SetLastError(ERROR_INVALID_DATA);
2556 goto create_failed;
2560 break;
2563 case WGL_TEXTURE_TARGET_ARB: {
2564 ++piAttribList;
2565 attr_v = *piAttribList;
2566 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2567 if (use_render_texture_ati) {
2568 int type = 0;
2569 switch (attr_v) {
2570 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2571 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2572 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2573 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2574 default:
2575 SetLastError(ERROR_INVALID_DATA);
2576 goto create_failed;
2578 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2579 } else {
2580 if (WGL_NO_TEXTURE_ARB == attr_v) {
2581 object->texture_target = 0;
2582 } else {
2583 if (!use_render_texture_emulation) {
2584 SetLastError(ERROR_INVALID_DATA);
2585 goto create_failed;
2587 switch (attr_v) {
2588 case WGL_TEXTURE_CUBE_MAP_ARB: {
2589 if (iWidth != iHeight) {
2590 SetLastError(ERROR_INVALID_DATA);
2591 goto create_failed;
2593 object->texture_target = GL_TEXTURE_CUBE_MAP;
2594 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2595 break;
2597 case WGL_TEXTURE_1D_ARB: {
2598 if (1 != iHeight) {
2599 SetLastError(ERROR_INVALID_DATA);
2600 goto create_failed;
2602 object->texture_target = GL_TEXTURE_1D;
2603 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2604 break;
2606 case WGL_TEXTURE_2D_ARB: {
2607 object->texture_target = GL_TEXTURE_2D;
2608 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2609 break;
2611 case WGL_TEXTURE_RECTANGLE_NV: {
2612 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2613 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2614 break;
2616 default:
2617 ERR("Unknown texture target: %x\n", attr_v);
2618 SetLastError(ERROR_INVALID_DATA);
2619 goto create_failed;
2623 break;
2626 case WGL_MIPMAP_TEXTURE_ARB: {
2627 ++piAttribList;
2628 attr_v = *piAttribList;
2629 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2630 if (use_render_texture_ati) {
2631 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2632 } else {
2633 if (!use_render_texture_emulation) {
2634 SetLastError(ERROR_INVALID_DATA);
2635 goto create_failed;
2638 break;
2641 ++piAttribList;
2644 PUSH1(attribs, None);
2645 wine_tsx11_lock();
2646 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2647 wine_tsx11_unlock();
2648 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2649 if (!object->drawable) {
2650 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2651 goto create_failed; /* unexpected error */
2653 TRACE("->(%p)\n", object);
2654 return object;
2656 create_failed:
2657 HeapFree(GetProcessHeap(), 0, object);
2658 TRACE("->(FAILED)\n");
2659 return NULL;
2663 * X11DRV_wglDestroyPbufferARB
2665 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2667 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2669 Wine_GLPBuffer* object = hPbuffer;
2670 TRACE("(%p)\n", hPbuffer);
2671 if (NULL == object) {
2672 SetLastError(ERROR_INVALID_HANDLE);
2673 return GL_FALSE;
2675 wine_tsx11_lock();
2676 pglXDestroyPbuffer(object->display, object->drawable);
2677 wine_tsx11_unlock();
2678 HeapFree(GetProcessHeap(), 0, object);
2679 return GL_TRUE;
2683 * X11DRV_wglGetPbufferDCARB
2685 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2686 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2687 * Gdi32 implements the part of this function which creates a device context.
2688 * This part associates the physDev with the X drawable of the pbuffer.
2690 HDC X11DRV_wglGetPbufferDCARB(PHYSDEV dev, HPBUFFERARB hPbuffer)
2692 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
2693 Wine_GLPBuffer* object = hPbuffer;
2695 if (NULL == object) {
2696 SetLastError(ERROR_INVALID_HANDLE);
2697 return NULL;
2700 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2701 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2702 physDev->current_pf = object->fmt->iPixelFormat;
2703 physDev->drawable = object->drawable;
2704 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2705 physDev->dc_rect = physDev->drawable_rect;
2707 TRACE("(%p)->(%p)\n", hPbuffer, dev->hdc);
2708 return dev->hdc;
2712 * X11DRV_wglQueryPbufferARB
2714 * WGL_ARB_pbuffer: wglQueryPbufferARB
2716 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2718 Wine_GLPBuffer* object = hPbuffer;
2719 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2720 if (NULL == object) {
2721 SetLastError(ERROR_INVALID_HANDLE);
2722 return GL_FALSE;
2724 switch (iAttribute) {
2725 case WGL_PBUFFER_WIDTH_ARB:
2726 wine_tsx11_lock();
2727 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2728 wine_tsx11_unlock();
2729 break;
2730 case WGL_PBUFFER_HEIGHT_ARB:
2731 wine_tsx11_lock();
2732 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2733 wine_tsx11_unlock();
2734 break;
2736 case WGL_PBUFFER_LOST_ARB:
2737 /* GLX Pbuffers cannot be lost by default. We can support this by
2738 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2739 * to receive pixel buffer clobber events, however that may or may
2740 * not give any benefit */
2741 *piValue = GL_FALSE;
2742 break;
2744 case WGL_TEXTURE_FORMAT_ARB:
2745 if (use_render_texture_ati) {
2746 unsigned int tmp;
2747 int type = WGL_NO_TEXTURE_ARB;
2748 wine_tsx11_lock();
2749 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2750 wine_tsx11_unlock();
2751 switch (tmp) {
2752 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2753 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2754 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2756 *piValue = type;
2757 } else {
2758 if (!object->use_render_texture) {
2759 *piValue = WGL_NO_TEXTURE_ARB;
2760 } else {
2761 if (!use_render_texture_emulation) {
2762 SetLastError(ERROR_INVALID_HANDLE);
2763 return GL_FALSE;
2765 switch(object->use_render_texture) {
2766 case GL_RGB:
2767 *piValue = WGL_TEXTURE_RGB_ARB;
2768 break;
2769 case GL_RGBA:
2770 *piValue = WGL_TEXTURE_RGBA_ARB;
2771 break;
2772 /* WGL_FLOAT_COMPONENTS_NV */
2773 case GL_FLOAT_R_NV:
2774 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2775 break;
2776 case GL_FLOAT_RG_NV:
2777 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2778 break;
2779 case GL_FLOAT_RGB_NV:
2780 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2781 break;
2782 case GL_FLOAT_RGBA_NV:
2783 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2784 break;
2785 default:
2786 ERR("Unknown texture format: %x\n", object->use_render_texture);
2790 break;
2792 case WGL_TEXTURE_TARGET_ARB:
2793 if (use_render_texture_ati) {
2794 unsigned int tmp;
2795 int type = WGL_NO_TEXTURE_ARB;
2796 wine_tsx11_lock();
2797 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2798 wine_tsx11_unlock();
2799 switch (tmp) {
2800 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2801 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2802 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2803 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2805 *piValue = type;
2806 } else {
2807 if (!object->texture_target) {
2808 *piValue = WGL_NO_TEXTURE_ARB;
2809 } else {
2810 if (!use_render_texture_emulation) {
2811 SetLastError(ERROR_INVALID_DATA);
2812 return GL_FALSE;
2814 switch (object->texture_target) {
2815 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2816 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2817 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2818 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2822 break;
2824 case WGL_MIPMAP_TEXTURE_ARB:
2825 if (use_render_texture_ati) {
2826 wine_tsx11_lock();
2827 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2828 wine_tsx11_unlock();
2829 } else {
2830 *piValue = GL_FALSE; /** don't support that */
2831 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2833 break;
2835 default:
2836 FIXME("unexpected attribute %x\n", iAttribute);
2837 break;
2840 return GL_TRUE;
2844 * X11DRV_wglReleasePbufferDCARB
2846 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2848 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2850 TRACE("(%p, %p)\n", hPbuffer, hdc);
2851 return DeleteDC(hdc);
2855 * X11DRV_wglSetPbufferAttribARB
2857 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2859 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2861 Wine_GLPBuffer* object = hPbuffer;
2862 GLboolean ret = GL_FALSE;
2864 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2865 if (NULL == object) {
2866 SetLastError(ERROR_INVALID_HANDLE);
2867 return GL_FALSE;
2869 if (!object->use_render_texture) {
2870 SetLastError(ERROR_INVALID_HANDLE);
2871 return GL_FALSE;
2873 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2874 return GL_TRUE;
2876 if (NULL != pglXDrawableAttribATI) {
2877 if (use_render_texture_ati) {
2878 FIXME("Need conversion for GLX_ATI_render_texture\n");
2880 wine_tsx11_lock();
2881 ret = pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2882 wine_tsx11_unlock();
2884 return ret;
2888 * X11DRV_wglChoosePixelFormatARB
2890 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2892 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2894 int gl_test = 0;
2895 int attribs[256];
2896 int nAttribs = 0;
2897 GLXFBConfig* cfgs = NULL;
2898 int nCfgs = 0;
2899 int it;
2900 int fmt_id;
2901 WineGLPixelFormat *fmt;
2902 UINT pfmt_it = 0;
2903 int run;
2904 int i;
2905 DWORD dwFlags = 0;
2907 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2908 if (NULL != pfAttribFList) {
2909 FIXME("unused pfAttribFList\n");
2912 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2913 if (-1 == nAttribs) {
2914 WARN("Cannot convert WGL to GLX attributes\n");
2915 return GL_FALSE;
2917 PUSH1(attribs, None);
2919 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2920 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2921 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2922 for(i=0; piAttribIList[i] != 0; i+=2)
2924 switch(piAttribIList[i])
2926 case WGL_DRAW_TO_BITMAP_ARB:
2927 if(piAttribIList[i+1])
2928 dwFlags |= PFD_DRAW_TO_BITMAP;
2929 break;
2930 case WGL_ACCELERATION_ARB:
2931 switch(piAttribIList[i+1])
2933 case WGL_NO_ACCELERATION_ARB:
2934 dwFlags |= PFD_GENERIC_FORMAT;
2935 break;
2936 case WGL_GENERIC_ACCELERATION_ARB:
2937 dwFlags |= PFD_GENERIC_ACCELERATED;
2938 break;
2939 case WGL_FULL_ACCELERATION_ARB:
2940 /* Nothing to do */
2941 break;
2943 break;
2944 case WGL_SUPPORT_GDI_ARB:
2945 if(piAttribIList[i+1])
2946 dwFlags |= PFD_SUPPORT_GDI;
2947 break;
2951 /* Search for FB configurations matching the requirements in attribs */
2952 wine_tsx11_lock();
2953 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2954 if (NULL == cfgs) {
2955 wine_tsx11_unlock();
2956 WARN("Compatible Pixel Format not found\n");
2957 return GL_FALSE;
2960 /* Loop through all matching formats and check if they are suitable.
2961 * Note that this function should at max return nMaxFormats different formats */
2962 for(run=0; run < 2; run++)
2964 for (it = 0; it < nCfgs; ++it) {
2965 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2966 if (gl_test) {
2967 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2968 continue;
2971 /* Search for the format in our list of compatible formats */
2972 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id, dwFlags);
2973 if(!fmt)
2974 continue;
2976 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2977 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2978 continue;
2980 if(pfmt_it < nMaxFormats) {
2981 piFormats[pfmt_it] = fmt->iPixelFormat;
2982 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2984 pfmt_it++;
2988 *nNumFormats = pfmt_it;
2989 /** free list */
2990 XFree(cfgs);
2991 wine_tsx11_unlock();
2992 return GL_TRUE;
2996 * X11DRV_wglGetPixelFormatAttribivARB
2998 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
3000 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
3002 UINT i;
3003 WineGLPixelFormat *fmt = NULL;
3004 int hTest;
3005 int tmp;
3006 int curGLXAttr = 0;
3007 int nWGLFormats = 0;
3009 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
3011 if (0 < iLayerPlane) {
3012 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
3013 return GL_FALSE;
3016 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
3017 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
3018 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
3019 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
3020 if(!fmt) {
3021 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
3024 wine_tsx11_lock();
3025 for (i = 0; i < nAttributes; ++i) {
3026 const int curWGLAttr = piAttributes[i];
3027 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
3029 switch (curWGLAttr) {
3030 case WGL_NUMBER_PIXEL_FORMATS_ARB:
3031 piValues[i] = nWGLFormats;
3032 continue;
3034 case WGL_SUPPORT_OPENGL_ARB:
3035 piValues[i] = GL_TRUE;
3036 continue;
3038 case WGL_ACCELERATION_ARB:
3039 curGLXAttr = GLX_CONFIG_CAVEAT;
3040 if (!fmt) goto pix_error;
3041 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
3042 piValues[i] = WGL_NO_ACCELERATION_ARB;
3043 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
3044 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
3045 else
3046 piValues[i] = WGL_FULL_ACCELERATION_ARB;
3047 continue;
3049 case WGL_TRANSPARENT_ARB:
3050 curGLXAttr = GLX_TRANSPARENT_TYPE;
3051 if (!fmt) goto pix_error;
3052 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
3053 if (hTest) goto get_error;
3054 piValues[i] = GL_FALSE;
3055 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
3056 continue;
3058 case WGL_PIXEL_TYPE_ARB:
3059 curGLXAttr = GLX_RENDER_TYPE;
3060 if (!fmt) goto pix_error;
3061 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
3062 if (hTest) goto get_error;
3063 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
3064 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
3065 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
3066 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
3067 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
3068 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
3069 else {
3070 ERR("unexpected RenderType(%x)\n", tmp);
3071 piValues[i] = WGL_TYPE_RGBA_ARB;
3073 continue;
3075 case WGL_COLOR_BITS_ARB:
3076 curGLXAttr = GLX_BUFFER_SIZE;
3077 break;
3079 case WGL_BIND_TO_TEXTURE_RGB_ARB:
3080 if (use_render_texture_ati) {
3081 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
3082 break;
3084 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
3085 if (use_render_texture_ati) {
3086 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
3087 break;
3089 if (!use_render_texture_emulation) {
3090 piValues[i] = GL_FALSE;
3091 continue;
3093 curGLXAttr = GLX_RENDER_TYPE;
3094 if (!fmt) goto pix_error;
3095 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
3096 if (hTest) goto get_error;
3097 if (GLX_COLOR_INDEX_BIT == tmp) {
3098 piValues[i] = GL_FALSE;
3099 continue;
3101 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
3102 if (hTest) goto get_error;
3103 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
3104 continue;
3106 case WGL_BLUE_BITS_ARB:
3107 curGLXAttr = GLX_BLUE_SIZE;
3108 break;
3109 case WGL_RED_BITS_ARB:
3110 curGLXAttr = GLX_RED_SIZE;
3111 break;
3112 case WGL_GREEN_BITS_ARB:
3113 curGLXAttr = GLX_GREEN_SIZE;
3114 break;
3115 case WGL_ALPHA_BITS_ARB:
3116 curGLXAttr = GLX_ALPHA_SIZE;
3117 break;
3118 case WGL_DEPTH_BITS_ARB:
3119 curGLXAttr = GLX_DEPTH_SIZE;
3120 break;
3121 case WGL_STENCIL_BITS_ARB:
3122 curGLXAttr = GLX_STENCIL_SIZE;
3123 break;
3124 case WGL_DOUBLE_BUFFER_ARB:
3125 curGLXAttr = GLX_DOUBLEBUFFER;
3126 break;
3127 case WGL_STEREO_ARB:
3128 curGLXAttr = GLX_STEREO;
3129 break;
3130 case WGL_AUX_BUFFERS_ARB:
3131 curGLXAttr = GLX_AUX_BUFFERS;
3132 break;
3134 case WGL_SUPPORT_GDI_ARB:
3135 if (!fmt) goto pix_error;
3136 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
3137 continue;
3139 case WGL_DRAW_TO_BITMAP_ARB:
3140 if (!fmt) goto pix_error;
3141 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? TRUE : FALSE;
3142 continue;
3144 case WGL_DRAW_TO_WINDOW_ARB:
3145 case WGL_DRAW_TO_PBUFFER_ARB:
3146 if (!fmt) goto pix_error;
3147 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
3148 if (hTest) goto get_error;
3149 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
3150 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
3151 piValues[i] = GL_TRUE;
3152 else
3153 piValues[i] = GL_FALSE;
3154 continue;
3156 case WGL_SWAP_METHOD_ARB:
3157 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3158 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3159 * point only ATI offers this.
3161 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
3162 break;
3164 case WGL_PBUFFER_LARGEST_ARB:
3165 curGLXAttr = GLX_LARGEST_PBUFFER;
3166 break;
3168 case WGL_SAMPLE_BUFFERS_ARB:
3169 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
3170 break;
3172 case WGL_SAMPLES_ARB:
3173 curGLXAttr = GLX_SAMPLES_ARB;
3174 break;
3176 case WGL_FLOAT_COMPONENTS_NV:
3177 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
3178 break;
3180 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
3181 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
3182 break;
3184 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
3185 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
3186 break;
3188 case WGL_ACCUM_RED_BITS_ARB:
3189 curGLXAttr = GLX_ACCUM_RED_SIZE;
3190 break;
3191 case WGL_ACCUM_GREEN_BITS_ARB:
3192 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
3193 break;
3194 case WGL_ACCUM_BLUE_BITS_ARB:
3195 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
3196 break;
3197 case WGL_ACCUM_ALPHA_BITS_ARB:
3198 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
3199 break;
3200 case WGL_ACCUM_BITS_ARB:
3201 if (!fmt) goto pix_error;
3202 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
3203 if (hTest) goto get_error;
3204 piValues[i] = tmp;
3205 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
3206 if (hTest) goto get_error;
3207 piValues[i] += tmp;
3208 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
3209 if (hTest) goto get_error;
3210 piValues[i] += tmp;
3211 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
3212 if (hTest) goto get_error;
3213 piValues[i] += tmp;
3214 continue;
3216 default:
3217 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
3220 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3221 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3222 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3224 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3225 * and check which options can work using iPixelFormat=0 and which not.
3226 * A problem would be that this function is an extension. This would
3227 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3229 if (0 != curGLXAttr && iPixelFormat != 0) {
3230 if (!fmt) goto pix_error;
3231 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
3232 if (hTest) goto get_error;
3233 curGLXAttr = 0;
3234 } else {
3235 piValues[i] = GL_FALSE;
3238 wine_tsx11_unlock();
3239 return GL_TRUE;
3241 get_error:
3242 wine_tsx11_unlock();
3243 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
3244 return GL_FALSE;
3246 pix_error:
3247 wine_tsx11_unlock();
3248 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
3249 return GL_FALSE;
3253 * X11DRV_wglGetPixelFormatAttribfvARB
3255 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3257 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
3259 int *attr;
3260 int ret;
3261 UINT i;
3263 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
3265 /* Allocate a temporary array to store integer values */
3266 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
3267 if (!attr) {
3268 ERR("couldn't allocate %d array\n", nAttributes);
3269 return GL_FALSE;
3272 /* Piggy-back on wglGetPixelFormatAttribivARB */
3273 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
3274 if (ret) {
3275 /* Convert integer values to float. Should also check for attributes
3276 that can give decimal values here */
3277 for (i=0; i<nAttributes;i++) {
3278 pfValues[i] = attr[i];
3282 HeapFree(GetProcessHeap(), 0, attr);
3283 return ret;
3287 * X11DRV_wglBindTexImageARB
3289 * WGL_ARB_render_texture: wglBindTexImageARB
3291 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3293 Wine_GLPBuffer* object = hPbuffer;
3294 GLboolean ret = GL_FALSE;
3296 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3297 if (NULL == object) {
3298 SetLastError(ERROR_INVALID_HANDLE);
3299 return GL_FALSE;
3301 if (!object->use_render_texture) {
3302 SetLastError(ERROR_INVALID_HANDLE);
3303 return GL_FALSE;
3306 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3307 static int init = 0;
3308 int prev_binded_texture = 0;
3309 GLXContext prev_context;
3310 Drawable prev_drawable;
3311 GLXContext tmp_context;
3313 wine_tsx11_lock();
3314 prev_context = pglXGetCurrentContext();
3315 prev_drawable = pglXGetCurrentDrawable();
3317 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3318 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3319 isn't ideal performance wise but I wasn't able to get other ways working.
3321 if(!init) {
3322 init = 1; /* Only show the FIXME once for performance reasons */
3323 FIXME("partial stub!\n");
3326 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
3327 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
3329 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
3331 /* Switch to our pbuffer */
3332 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
3334 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3335 * After that upload the pbuffer texture data. */
3336 pglBindTexture(object->texture_target, prev_binded_texture);
3337 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
3339 /* Switch back to the original drawable and upload the pbuffer-texture */
3340 pglXMakeCurrent(object->display, prev_drawable, prev_context);
3341 pglXDestroyContext(gdi_display, tmp_context);
3342 wine_tsx11_unlock();
3343 return GL_TRUE;
3346 if (NULL != pglXBindTexImageATI) {
3347 int buffer;
3349 switch(iBuffer)
3351 case WGL_FRONT_LEFT_ARB:
3352 buffer = GLX_FRONT_LEFT_ATI;
3353 break;
3354 case WGL_FRONT_RIGHT_ARB:
3355 buffer = GLX_FRONT_RIGHT_ATI;
3356 break;
3357 case WGL_BACK_LEFT_ARB:
3358 buffer = GLX_BACK_LEFT_ATI;
3359 break;
3360 case WGL_BACK_RIGHT_ARB:
3361 buffer = GLX_BACK_RIGHT_ATI;
3362 break;
3363 default:
3364 ERR("Unknown iBuffer=%#x\n", iBuffer);
3365 return FALSE;
3368 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3369 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3370 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3371 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3372 * works fine using our pbuffer emulation path.
3374 wine_tsx11_lock();
3375 ret = pglXBindTexImageATI(object->display, object->drawable, buffer);
3376 wine_tsx11_unlock();
3378 return ret;
3382 * X11DRV_wglReleaseTexImageARB
3384 * WGL_ARB_render_texture: wglReleaseTexImageARB
3386 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3388 Wine_GLPBuffer* object = hPbuffer;
3389 GLboolean ret = GL_FALSE;
3391 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3392 if (NULL == object) {
3393 SetLastError(ERROR_INVALID_HANDLE);
3394 return GL_FALSE;
3396 if (!object->use_render_texture) {
3397 SetLastError(ERROR_INVALID_HANDLE);
3398 return GL_FALSE;
3400 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3401 return GL_TRUE;
3403 if (NULL != pglXReleaseTexImageATI) {
3404 int buffer;
3406 switch(iBuffer)
3408 case WGL_FRONT_LEFT_ARB:
3409 buffer = GLX_FRONT_LEFT_ATI;
3410 break;
3411 case WGL_FRONT_RIGHT_ARB:
3412 buffer = GLX_FRONT_RIGHT_ATI;
3413 break;
3414 case WGL_BACK_LEFT_ARB:
3415 buffer = GLX_BACK_LEFT_ATI;
3416 break;
3417 case WGL_BACK_RIGHT_ARB:
3418 buffer = GLX_BACK_RIGHT_ATI;
3419 break;
3420 default:
3421 ERR("Unknown iBuffer=%#x\n", iBuffer);
3422 return FALSE;
3424 wine_tsx11_lock();
3425 ret = pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3426 wine_tsx11_unlock();
3428 return ret;
3432 * X11DRV_wglGetExtensionsStringEXT
3434 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3436 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3437 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3438 return WineGLInfo.wglExtensions;
3442 * X11DRV_wglGetSwapIntervalEXT
3444 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3446 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3447 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
3448 * interval, so the swap interval has to be tracked. */
3449 TRACE("()\n");
3450 return swap_interval;
3454 * X11DRV_wglSwapIntervalEXT
3456 * WGL_EXT_swap_control: wglSwapIntervalEXT
3458 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3459 BOOL ret = TRUE;
3461 TRACE("(%d)\n", interval);
3463 if (interval < 0)
3465 SetLastError(ERROR_INVALID_DATA);
3466 return FALSE;
3468 else if (!has_swap_control && interval == 0)
3470 /* wglSwapIntervalEXT considers an interval value of zero to mean that
3471 * vsync should be disabled, but glXSwapIntervalSGI considers such a
3472 * value to be an error. Just silently ignore the request for now. */
3473 WARN("Request to disable vertical sync is not handled\n");
3474 swap_interval = 0;
3476 else
3478 if (pglXSwapIntervalSGI)
3480 wine_tsx11_lock();
3481 ret = !pglXSwapIntervalSGI(interval);
3482 wine_tsx11_unlock();
3484 else
3485 WARN("GLX_SGI_swap_control extension is not available\n");
3487 if (ret)
3488 swap_interval = interval;
3489 else
3490 SetLastError(ERROR_DC_NOT_FOUND);
3493 return ret;
3497 * X11DRV_wglAllocateMemoryNV
3499 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3501 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3502 void *ret = NULL;
3503 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3505 if (pglXAllocateMemoryNV)
3507 wine_tsx11_lock();
3508 ret = pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3509 wine_tsx11_unlock();
3511 return ret;
3515 * X11DRV_wglFreeMemoryNV
3517 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3519 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3520 TRACE("(%p)\n", pointer);
3521 if (pglXFreeMemoryNV == NULL)
3522 return;
3524 wine_tsx11_lock();
3525 pglXFreeMemoryNV(pointer);
3526 wine_tsx11_unlock();
3530 * X11DRV_wglSetPixelFormatWINE
3532 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3533 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3535 BOOL X11DRV_wglSetPixelFormatWINE(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3537 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
3539 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
3541 if (!has_opengl()) return FALSE;
3543 if (physDev->current_pf == iPixelFormat) return TRUE;
3545 /* Relay to the core SetPixelFormat */
3546 TRACE("Changing iPixelFormat from %d to %d\n", physDev->current_pf, iPixelFormat);
3547 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
3551 * glxRequireVersion (internal)
3553 * Check if the supported GLX version matches requiredVersion.
3555 static BOOL glxRequireVersion(int requiredVersion)
3557 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3558 if(requiredVersion <= WineGLInfo.glxVersion[1])
3559 return TRUE;
3561 return FALSE;
3564 static BOOL glxRequireExtension(const char *requiredExtension)
3566 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3567 return FALSE;
3570 return TRUE;
3573 static void register_extension_string(const char *ext)
3575 if (WineGLInfo.wglExtensions[0])
3576 strcat(WineGLInfo.wglExtensions, " ");
3577 strcat(WineGLInfo.wglExtensions, ext);
3579 TRACE("'%s'\n", ext);
3582 static BOOL register_extension(const WineGLExtension * ext)
3584 int i;
3586 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3587 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3589 register_extension_string(ext->extName);
3591 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3592 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3594 return TRUE;
3597 static const WineGLExtension WGL_internal_functions =
3601 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3602 { "wglFinish", X11DRV_wglFinish },
3603 { "wglFlush", X11DRV_wglFlush },
3608 static const WineGLExtension WGL_ARB_create_context =
3610 "WGL_ARB_create_context",
3612 { "wglCreateContextAttribsARB", X11DRV_wglCreateContextAttribsARB },
3616 static const WineGLExtension WGL_ARB_extensions_string =
3618 "WGL_ARB_extensions_string",
3620 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3624 static const WineGLExtension WGL_ARB_make_current_read =
3626 "WGL_ARB_make_current_read",
3628 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3629 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3633 static const WineGLExtension WGL_ARB_multisample =
3635 "WGL_ARB_multisample",
3638 static const WineGLExtension WGL_ARB_pbuffer =
3640 "WGL_ARB_pbuffer",
3642 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3643 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3644 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3645 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3646 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3647 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3651 static const WineGLExtension WGL_ARB_pixel_format =
3653 "WGL_ARB_pixel_format",
3655 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3656 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3657 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3661 static const WineGLExtension WGL_ARB_render_texture =
3663 "WGL_ARB_render_texture",
3665 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3666 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3670 static const WineGLExtension WGL_EXT_extensions_string =
3672 "WGL_EXT_extensions_string",
3674 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3678 static const WineGLExtension WGL_EXT_swap_control =
3680 "WGL_EXT_swap_control",
3682 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3683 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3687 static const WineGLExtension WGL_NV_vertex_array_range =
3689 "WGL_NV_vertex_array_range",
3691 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3692 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3696 static const WineGLExtension WGL_WINE_pixel_format_passthrough =
3698 "WGL_WINE_pixel_format_passthrough",
3700 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE },
3705 * X11DRV_WineGL_LoadExtensions
3707 static void X11DRV_WineGL_LoadExtensions(void)
3709 WineGLInfo.wglExtensions[0] = 0;
3711 /* Load Wine internal functions */
3712 register_extension(&WGL_internal_functions);
3714 /* ARB Extensions */
3716 if(glxRequireExtension("GLX_ARB_create_context"))
3718 register_extension(&WGL_ARB_create_context);
3720 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3721 register_extension_string("WGL_ARB_create_context_profile");
3724 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3726 register_extension_string("WGL_ARB_pixel_format_float");
3727 register_extension_string("WGL_ATI_pixel_format_float");
3730 register_extension(&WGL_ARB_extensions_string);
3732 if (glxRequireVersion(3))
3733 register_extension(&WGL_ARB_make_current_read);
3735 if (glxRequireExtension("GLX_ARB_multisample"))
3736 register_extension(&WGL_ARB_multisample);
3738 /* In general pbuffer functionality requires support in the X-server. The functionality is
3739 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3740 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3741 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3743 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3744 * without support in the X-server (which other Mesa based drivers require).
3746 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3747 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3748 * is available pbuffers must be available too. */
3749 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3750 register_extension(&WGL_ARB_pbuffer);
3752 register_extension(&WGL_ARB_pixel_format);
3754 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3755 if (glxRequireExtension("GLX_ATI_render_texture") ||
3756 glxRequireExtension("GLX_ARB_render_texture") ||
3757 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3759 register_extension(&WGL_ARB_render_texture);
3761 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3762 if(glxRequireExtension("GLX_NV_float_buffer"))
3763 register_extension_string("WGL_NV_float_buffer");
3765 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3766 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3767 register_extension_string("WGL_NV_texture_rectangle");
3770 /* EXT Extensions */
3772 register_extension(&WGL_EXT_extensions_string);
3774 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3775 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3776 register_extension(&WGL_EXT_swap_control);
3778 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3779 register_extension_string("WGL_EXT_framebuffer_sRGB");
3781 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3782 register_extension_string("WGL_EXT_pixel_format_packed_float");
3784 if (glxRequireExtension("GLX_EXT_swap_control"))
3785 has_swap_control = TRUE;
3787 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3788 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3789 register_extension(&WGL_NV_vertex_array_range);
3791 /* WINE-specific WGL Extensions */
3793 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3794 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3796 register_extension(&WGL_WINE_pixel_format_passthrough);
3800 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3802 Drawable ret;
3804 if(physDev->bitmap)
3806 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3807 ret = physDev->drawable; /* PBuffer */
3808 else
3809 ret = physDev->bitmap->glxpixmap;
3811 else if(physDev->gl_drawable)
3812 ret = physDev->gl_drawable;
3813 else
3814 ret = physDev->drawable;
3815 return ret;
3818 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3820 wine_tsx11_lock();
3821 pglXDestroyGLXPixmap(display, glxpixmap);
3822 wine_tsx11_unlock();
3823 return TRUE;
3827 * X11DRV_SwapBuffers
3829 * Swap the buffers of this DC
3831 BOOL X11DRV_SwapBuffers(PHYSDEV dev)
3833 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
3834 GLXDrawable drawable;
3835 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3837 if (!has_opengl()) return FALSE;
3839 TRACE("(%p)\n", physDev);
3841 if (!ctx)
3843 WARN("Using a NULL context, skipping\n");
3844 SetLastError(ERROR_INVALID_HANDLE);
3845 return FALSE;
3848 if (!physDev->current_pf)
3850 WARN("Using an invalid drawable, skipping\n");
3851 SetLastError(ERROR_INVALID_HANDLE);
3852 return FALSE;
3855 drawable = get_glxdrawable(physDev);
3857 wine_tsx11_lock();
3858 sync_context(ctx);
3859 if(physDev->pixmap) {
3860 if(pglXCopySubBufferMESA) {
3861 int w = physDev->dc_rect.right - physDev->dc_rect.left;
3862 int h = physDev->dc_rect.bottom - physDev->dc_rect.top;
3864 /* (glX)SwapBuffers has an implicit glFlush effect, however
3865 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3866 * copying */
3867 pglFlush();
3868 if(w > 0 && h > 0)
3869 pglXCopySubBufferMESA(gdi_display, drawable, 0, 0, w, h);
3871 else
3872 pglXSwapBuffers(gdi_display, drawable);
3874 else
3875 pglXSwapBuffers(gdi_display, drawable);
3877 flush_gl_drawable(physDev);
3878 wine_tsx11_unlock();
3880 /* FPS support */
3881 if (TRACE_ON(fps))
3883 static long prev_time, start_time;
3884 static unsigned long frames, frames_total;
3886 DWORD time = GetTickCount();
3887 frames++;
3888 frames_total++;
3889 /* every 1.5 seconds */
3890 if (time - prev_time > 1500) {
3891 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3892 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3893 prev_time = time;
3894 frames = 0;
3895 if(start_time == 0) start_time = time;
3899 return TRUE;
3902 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3904 WineGLPixelFormat *fmt;
3905 XVisualInfo *ret;
3907 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
3908 if(fmt == NULL)
3909 return NULL;
3911 wine_tsx11_lock();
3912 ret = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3913 wine_tsx11_unlock();
3914 return ret;
3917 #else /* no OpenGL includes */
3919 void X11DRV_OpenGL_Cleanup(void)
3923 static inline void opengl_error(void)
3925 static int warned;
3926 if (!warned++) ERR("No OpenGL support compiled in.\n");
3929 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3931 return 0;
3934 void mark_drawable_dirty(Drawable old, Drawable new)
3938 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
3942 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3944 return 0;
3947 /***********************************************************************
3948 * ChoosePixelFormat (X11DRV.@)
3950 int X11DRV_ChoosePixelFormat(PHYSDEV dev, const PIXELFORMATDESCRIPTOR *ppfd)
3952 opengl_error();
3953 return 0;
3956 /***********************************************************************
3957 * DescribePixelFormat (X11DRV.@)
3959 int X11DRV_DescribePixelFormat(PHYSDEV dev, int iPixelFormat, UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
3961 opengl_error();
3962 return 0;
3965 /***********************************************************************
3966 * GetPixelFormat (X11DRV.@)
3968 int X11DRV_GetPixelFormat(PHYSDEV dev)
3970 opengl_error();
3971 return 0;
3974 /***********************************************************************
3975 * SetPixelFormat (X11DRV.@)
3977 BOOL X11DRV_SetPixelFormat(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3979 opengl_error();
3980 return FALSE;
3983 /***********************************************************************
3984 * SwapBuffers (X11DRV.@)
3986 BOOL X11DRV_SwapBuffers(PHYSDEV dev)
3988 opengl_error();
3989 return FALSE;
3993 * X11DRV_wglCopyContext
3995 * For OpenGL32 wglCopyContext.
3997 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
3999 opengl_error();
4000 return FALSE;
4004 * X11DRV_wglCreateContext
4006 * For OpenGL32 wglCreateContext.
4008 HGLRC X11DRV_wglCreateContext(PHYSDEV dev)
4010 opengl_error();
4011 return NULL;
4015 * X11DRV_wglCreateContextAttribsARB
4017 * WGL_ARB_create_context: wglCreateContextAttribsARB
4019 HGLRC X11DRV_wglCreateContextAttribsARB(PHYSDEV dev, HGLRC hShareContext, const int* attribList)
4021 opengl_error();
4022 return NULL;
4026 * X11DRV_wglDeleteContext
4028 * For OpenGL32 wglDeleteContext.
4030 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
4032 opengl_error();
4033 return FALSE;
4037 * X11DRV_wglGetProcAddress
4039 * For OpenGL32 wglGetProcAddress.
4041 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
4043 opengl_error();
4044 return NULL;
4047 HDC X11DRV_wglGetPbufferDCARB(PHYSDEV dev, void *hPbuffer)
4049 opengl_error();
4050 return NULL;
4053 BOOL X11DRV_wglMakeContextCurrentARB(PHYSDEV draw_dev, PHYSDEV read_dev, HGLRC hglrc)
4055 opengl_error();
4056 return FALSE;
4060 * X11DRV_wglMakeCurrent
4062 * For OpenGL32 wglMakeCurrent.
4064 BOOL X11DRV_wglMakeCurrent(PHYSDEV dev, HGLRC hglrc)
4066 opengl_error();
4067 return FALSE;
4071 * X11DRV_wglShareLists
4073 * For OpenGL32 wglShareLists.
4075 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
4077 opengl_error();
4078 return FALSE;
4082 * X11DRV_wglUseFontBitmapsA
4084 * For OpenGL32 wglUseFontBitmapsA.
4086 BOOL X11DRV_wglUseFontBitmapsA(PHYSDEV dev, DWORD first, DWORD count, DWORD listBase)
4088 opengl_error();
4089 return FALSE;
4093 * X11DRV_wglUseFontBitmapsW
4095 * For OpenGL32 wglUseFontBitmapsW.
4097 BOOL X11DRV_wglUseFontBitmapsW(PHYSDEV dev, DWORD first, DWORD count, DWORD listBase)
4099 opengl_error();
4100 return FALSE;
4104 * X11DRV_wglSetPixelFormatWINE
4106 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
4107 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
4109 BOOL X11DRV_wglSetPixelFormatWINE(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
4111 opengl_error();
4112 return FALSE;
4115 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
4117 return 0;
4120 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
4122 return FALSE;
4125 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
4127 return NULL;
4130 #endif /* defined(SONAME_LIBGL) */