appwiz.cpl: Add __WINE_ALLOC_SIZE attributes to heap_xxx() functions.
[wine.git] / dlls / winex11.drv / opengl.c
blobd89a19330f7884a11d4dc6337c81b97876ff26c6
1 /*
2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
9 * Copyright 2012 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
35 #endif
36 #ifdef HAVE_SYS_UN_H
37 #include <sys/un.h>
38 #endif
40 #include "x11drv.h"
41 #include "xcomposite.h"
42 #include "winternl.h"
43 #include "wine/library.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
48 #ifdef SONAME_LIBGL
50 WINE_DECLARE_DEBUG_CHANNEL(winediag);
52 #include "wine/wgl.h"
53 #include "wine/wgl_driver.h"
54 #include "wine/wglext.h"
56 typedef struct __GLXcontextRec *GLXContext;
57 typedef struct __GLXFBConfigRec *GLXFBConfig;
58 typedef XID GLXPixmap;
59 typedef XID GLXDrawable;
60 typedef XID GLXFBConfigID;
61 typedef XID GLXContextID;
62 typedef XID GLXWindow;
63 typedef XID GLXPbuffer;
65 #define GLX_USE_GL 1
66 #define GLX_BUFFER_SIZE 2
67 #define GLX_LEVEL 3
68 #define GLX_RGBA 4
69 #define GLX_DOUBLEBUFFER 5
70 #define GLX_STEREO 6
71 #define GLX_AUX_BUFFERS 7
72 #define GLX_RED_SIZE 8
73 #define GLX_GREEN_SIZE 9
74 #define GLX_BLUE_SIZE 10
75 #define GLX_ALPHA_SIZE 11
76 #define GLX_DEPTH_SIZE 12
77 #define GLX_STENCIL_SIZE 13
78 #define GLX_ACCUM_RED_SIZE 14
79 #define GLX_ACCUM_GREEN_SIZE 15
80 #define GLX_ACCUM_BLUE_SIZE 16
81 #define GLX_ACCUM_ALPHA_SIZE 17
83 #define GLX_BAD_SCREEN 1
84 #define GLX_BAD_ATTRIBUTE 2
85 #define GLX_NO_EXTENSION 3
86 #define GLX_BAD_VISUAL 4
87 #define GLX_BAD_CONTEXT 5
88 #define GLX_BAD_VALUE 6
89 #define GLX_BAD_ENUM 7
91 #define GLX_VENDOR 1
92 #define GLX_VERSION 2
93 #define GLX_EXTENSIONS 3
95 #define GLX_CONFIG_CAVEAT 0x20
96 #define GLX_DONT_CARE 0xFFFFFFFF
97 #define GLX_X_VISUAL_TYPE 0x22
98 #define GLX_TRANSPARENT_TYPE 0x23
99 #define GLX_TRANSPARENT_INDEX_VALUE 0x24
100 #define GLX_TRANSPARENT_RED_VALUE 0x25
101 #define GLX_TRANSPARENT_GREEN_VALUE 0x26
102 #define GLX_TRANSPARENT_BLUE_VALUE 0x27
103 #define GLX_TRANSPARENT_ALPHA_VALUE 0x28
104 #define GLX_WINDOW_BIT 0x00000001
105 #define GLX_PIXMAP_BIT 0x00000002
106 #define GLX_PBUFFER_BIT 0x00000004
107 #define GLX_AUX_BUFFERS_BIT 0x00000010
108 #define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
109 #define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
110 #define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
111 #define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
112 #define GLX_DEPTH_BUFFER_BIT 0x00000020
113 #define GLX_STENCIL_BUFFER_BIT 0x00000040
114 #define GLX_ACCUM_BUFFER_BIT 0x00000080
115 #define GLX_NONE 0x8000
116 #define GLX_SLOW_CONFIG 0x8001
117 #define GLX_TRUE_COLOR 0x8002
118 #define GLX_DIRECT_COLOR 0x8003
119 #define GLX_PSEUDO_COLOR 0x8004
120 #define GLX_STATIC_COLOR 0x8005
121 #define GLX_GRAY_SCALE 0x8006
122 #define GLX_STATIC_GRAY 0x8007
123 #define GLX_TRANSPARENT_RGB 0x8008
124 #define GLX_TRANSPARENT_INDEX 0x8009
125 #define GLX_VISUAL_ID 0x800B
126 #define GLX_SCREEN 0x800C
127 #define GLX_NON_CONFORMANT_CONFIG 0x800D
128 #define GLX_DRAWABLE_TYPE 0x8010
129 #define GLX_RENDER_TYPE 0x8011
130 #define GLX_X_RENDERABLE 0x8012
131 #define GLX_FBCONFIG_ID 0x8013
132 #define GLX_RGBA_TYPE 0x8014
133 #define GLX_COLOR_INDEX_TYPE 0x8015
134 #define GLX_MAX_PBUFFER_WIDTH 0x8016
135 #define GLX_MAX_PBUFFER_HEIGHT 0x8017
136 #define GLX_MAX_PBUFFER_PIXELS 0x8018
137 #define GLX_PRESERVED_CONTENTS 0x801B
138 #define GLX_LARGEST_PBUFFER 0x801C
139 #define GLX_WIDTH 0x801D
140 #define GLX_HEIGHT 0x801E
141 #define GLX_EVENT_MASK 0x801F
142 #define GLX_DAMAGED 0x8020
143 #define GLX_SAVED 0x8021
144 #define GLX_WINDOW 0x8022
145 #define GLX_PBUFFER 0x8023
146 #define GLX_PBUFFER_HEIGHT 0x8040
147 #define GLX_PBUFFER_WIDTH 0x8041
148 #define GLX_SWAP_METHOD_OML 0x8060
149 #define GLX_SWAP_EXCHANGE_OML 0x8061
150 #define GLX_SWAP_COPY_OML 0x8062
151 #define GLX_SWAP_UNDEFINED_OML 0x8063
152 #define GLX_RGBA_BIT 0x00000001
153 #define GLX_COLOR_INDEX_BIT 0x00000002
154 #define GLX_PBUFFER_CLOBBER_MASK 0x08000000
156 /** GLX_ARB_multisample */
157 #define GLX_SAMPLE_BUFFERS_ARB 100000
158 #define GLX_SAMPLES_ARB 100001
159 /** GLX_ARB_framebuffer_sRGB */
160 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
161 /** GLX_EXT_fbconfig_packed_float */
162 #define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
163 #define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
164 /** GLX_ARB_create_context */
165 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
166 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
167 #define GLX_CONTEXT_FLAGS_ARB 0x2094
168 /** GLX_ARB_create_context_profile */
169 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
170 /** GLX_ATI_pixel_format_float */
171 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
172 /** GLX_ARB_pixel_format_float */
173 #define GLX_RGBA_FLOAT_BIT 0x00000004
174 #define GLX_RGBA_FLOAT_TYPE 0x20B9
175 /** GLX_MESA_query_renderer */
176 #define GLX_RENDERER_ID_MESA 0x818E
177 /** GLX_NV_float_buffer */
178 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
181 struct WineGLInfo {
182 const char *glVersion;
183 char *glExtensions;
185 int glxVersion[2];
187 const char *glxServerVersion;
188 const char *glxServerVendor;
189 const char *glxServerExtensions;
191 const char *glxClientVersion;
192 const char *glxClientVendor;
193 const char *glxClientExtensions;
195 const char *glxExtensions;
197 BOOL glxDirect;
198 char wglExtensions[4096];
201 struct wgl_pixel_format
203 GLXFBConfig fbconfig;
204 int fmt_id;
205 int render_type;
206 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
209 struct wgl_context
211 HDC hdc;
212 BOOL has_been_current;
213 BOOL sharing;
214 BOOL gl3_context;
215 XVisualInfo *vis;
216 const struct wgl_pixel_format *fmt;
217 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
218 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
219 GLXContext ctx;
220 GLXDrawable drawables[2];
221 BOOL refresh_drawables;
222 struct list entry;
225 struct wgl_pbuffer
227 Drawable drawable;
228 const struct wgl_pixel_format* fmt;
229 int width;
230 int height;
231 int* attribList;
232 int use_render_texture; /* This is also the internal texture format */
233 int texture_bind_target;
234 int texture_bpp;
235 GLint texture_format;
236 GLuint texture_target;
237 GLenum texture_type;
238 GLuint texture;
239 int texture_level;
240 GLXContext tmp_context;
241 GLXContext prev_context;
242 struct list entry;
245 enum dc_gl_type
247 DC_GL_NONE, /* no GL support (pixel format not set yet) */
248 DC_GL_WINDOW, /* normal top-level window */
249 DC_GL_CHILD_WIN, /* child window using XComposite */
250 DC_GL_PIXMAP_WIN, /* child window using intermediate pixmap */
251 DC_GL_PBUFFER /* pseudo memory DC using a PBuffer */
254 struct gl_drawable
256 enum dc_gl_type type; /* type of GL surface */
257 GLXDrawable drawable; /* drawable for rendering with GL */
258 Window window; /* window if drawable is a GLXWindow */
259 Pixmap pixmap; /* base pixmap if drawable is a GLXPixmap */
260 Colormap colormap; /* colormap used for the drawable */
261 const struct wgl_pixel_format *format; /* pixel format for the drawable */
262 XVisualInfo *visual; /* information about the GL visual */
263 RECT rect; /* drawable rect, relative to whole window drawable */
264 int swap_interval;
265 BOOL refresh_swap_interval;
268 enum glx_swap_control_method
270 GLX_SWAP_CONTROL_NONE,
271 GLX_SWAP_CONTROL_EXT,
272 GLX_SWAP_CONTROL_SGI,
273 GLX_SWAP_CONTROL_MESA
276 /* X context to associate a struct gl_drawable to an hwnd */
277 static XContext gl_hwnd_context;
278 /* X context to associate a struct gl_drawable to a pbuffer hdc */
279 static XContext gl_pbuffer_context;
281 static struct list context_list = LIST_INIT( context_list );
282 static struct list pbuffer_list = LIST_INIT( pbuffer_list );
283 static struct WineGLInfo WineGLInfo = { 0 };
284 static struct wgl_pixel_format *pixel_formats;
285 static int nb_pixel_formats, nb_onscreen_formats;
286 static BOOL use_render_texture_emulation = TRUE;
288 /* Selects the preferred GLX swap control method for use by wglSwapIntervalEXT */
289 static enum glx_swap_control_method swap_control_method = GLX_SWAP_CONTROL_NONE;
290 /* Set when GLX_EXT_swap_control_tear is supported, requires GLX_SWAP_CONTROL_EXT */
291 static BOOL has_swap_control_tear = FALSE;
292 static BOOL has_swap_method = FALSE;
294 static CRITICAL_SECTION context_section;
295 static CRITICAL_SECTION_DEBUG critsect_debug =
297 0, 0, &context_section,
298 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
299 0, 0, { (DWORD_PTR)(__FILE__ ": context_section") }
301 static CRITICAL_SECTION context_section = { &critsect_debug, -1, 0, 0, 0, 0 };
303 static const BOOL is_win64 = sizeof(void *) > sizeof(int);
305 static struct opengl_funcs opengl_funcs;
307 #define USE_GL_FUNC(name) #name,
308 static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
309 #undef USE_GL_FUNC
311 static void X11DRV_WineGL_LoadExtensions(void);
312 static void init_pixel_formats( Display *display );
313 static BOOL glxRequireVersion(int requiredVersion);
315 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
316 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
317 TRACE(" - dwFlags : ");
318 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
319 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
320 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
321 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
322 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
323 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
324 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
325 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
326 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
327 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
328 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
329 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
330 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
331 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
332 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
333 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
334 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
335 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
336 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
337 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
338 #undef TEST_AND_DUMP
339 TRACE("\n");
341 TRACE(" - iPixelType : ");
342 switch (ppfd->iPixelType) {
343 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
344 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
346 TRACE("\n");
348 TRACE(" - Color : %d\n", ppfd->cColorBits);
349 TRACE(" - Red : %d\n", ppfd->cRedBits);
350 TRACE(" - Green : %d\n", ppfd->cGreenBits);
351 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
352 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
353 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
354 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
355 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
356 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
358 TRACE(" - iLayerType : ");
359 switch (ppfd->iLayerType) {
360 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
361 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
362 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
364 TRACE("\n");
367 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
368 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
370 /* GLX 1.0 */
371 static XVisualInfo* (*pglXChooseVisual)( Display *dpy, int screen, int *attribList );
372 static GLXContext (*pglXCreateContext)( Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct );
373 static void (*pglXDestroyContext)( Display *dpy, GLXContext ctx );
374 static Bool (*pglXMakeCurrent)( Display *dpy, GLXDrawable drawable, GLXContext ctx);
375 static void (*pglXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, unsigned long mask );
376 static void (*pglXSwapBuffers)( Display *dpy, GLXDrawable drawable );
377 static Bool (*pglXQueryExtension)( Display *dpy, int *errorb, int *event );
378 static Bool (*pglXQueryVersion)( Display *dpy, int *maj, int *min );
379 static Bool (*pglXIsDirect)( Display *dpy, GLXContext ctx );
380 static int (*pglXGetConfig)( Display *dpy, XVisualInfo *visual, int attrib, int *value );
381 static GLXContext (*pglXGetCurrentContext)( void );
382 static GLXDrawable (*pglXGetCurrentDrawable)( void );
384 /* GLX 1.1 */
385 static const char *(*pglXQueryExtensionsString)( Display *dpy, int screen );
386 static const char *(*pglXQueryServerString)( Display *dpy, int screen, int name );
387 static const char *(*pglXGetClientString)( Display *dpy, int name );
389 /* GLX 1.3 */
390 static GLXFBConfig *(*pglXChooseFBConfig)( Display *dpy, int screen, const int *attribList, int *nitems );
391 static int (*pglXGetFBConfigAttrib)( Display *dpy, GLXFBConfig config, int attribute, int *value );
392 static GLXFBConfig *(*pglXGetFBConfigs)( Display *dpy, int screen, int *nelements );
393 static XVisualInfo *(*pglXGetVisualFromFBConfig)( Display *dpy, GLXFBConfig config );
394 static GLXPbuffer (*pglXCreatePbuffer)( Display *dpy, GLXFBConfig config, const int *attribList );
395 static void (*pglXDestroyPbuffer)( Display *dpy, GLXPbuffer pbuf );
396 static void (*pglXQueryDrawable)( Display *dpy, GLXDrawable draw, int attribute, unsigned int *value );
397 static GLXContext (*pglXCreateNewContext)( Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct );
398 static Bool (*pglXMakeContextCurrent)( Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx );
399 static GLXPixmap (*pglXCreatePixmap)( Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list );
400 static void (*pglXDestroyPixmap)( Display *dpy, GLXPixmap pixmap );
401 static GLXWindow (*pglXCreateWindow)( Display *dpy, GLXFBConfig config, Window win, const int *attrib_list );
402 static void (*pglXDestroyWindow)( Display *dpy, GLXWindow win );
404 /* GLX Extensions */
405 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
406 static void* (*pglXGetProcAddressARB)(const GLubyte *);
407 static void (*pglXSwapIntervalEXT)(Display *dpy, GLXDrawable drawable, int interval);
408 static int (*pglXSwapIntervalSGI)(int);
410 /* NV GLX Extension */
411 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
412 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
414 /* MESA GLX Extensions */
415 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
416 static int (*pglXSwapIntervalMESA)(unsigned int interval);
417 static Bool (*pglXQueryCurrentRendererIntegerMESA)(int attribute, unsigned int *value);
418 static const char *(*pglXQueryCurrentRendererStringMESA)(int attribute);
419 static Bool (*pglXQueryRendererIntegerMESA)(Display *dpy, int screen, int renderer, int attribute, unsigned int *value);
420 static const char *(*pglXQueryRendererStringMESA)(Display *dpy, int screen, int renderer, int attribute);
422 /* Standard OpenGL */
423 static void (*pglFinish)(void);
424 static void (*pglFlush)(void);
425 static const GLubyte *(*pglGetString)(GLenum name);
427 static void wglFinish(void);
428 static void wglFlush(void);
429 static const GLubyte *wglGetString(GLenum name);
431 /* check if the extension is present in the list */
432 static BOOL has_extension( const char *list, const char *ext )
434 size_t len = strlen( ext );
436 while (list)
438 while (*list == ' ') list++;
439 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
440 list = strchr( list, ' ' );
442 return FALSE;
445 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
447 /* In the future we might want to find the exact X or GLX error to report back to the app */
448 return 1;
451 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
453 static const char legacy_extensions[] = " WGL_EXT_extensions_string WGL_EXT_swap_control";
455 int screen = DefaultScreen(gdi_display);
456 Window win = 0, root = 0;
457 const char *gl_renderer;
458 const char* str;
459 XVisualInfo *vis;
460 GLXContext ctx = NULL;
461 XSetWindowAttributes attr;
462 BOOL ret = FALSE;
463 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
465 attr.override_redirect = True;
466 attr.colormap = None;
467 attr.border_pixel = 0;
469 vis = pglXChooseVisual(gdi_display, screen, attribList);
470 if (vis) {
471 #ifdef __i386__
472 WORD old_fs = wine_get_fs();
473 /* Create a GLX Context. Without one we can't query GL information */
474 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
475 if (wine_get_fs() != old_fs)
477 wine_set_fs( old_fs );
478 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
479 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
480 goto done;
482 #else
483 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
484 #endif
486 if (!ctx) goto done;
488 root = RootWindow( gdi_display, vis->screen );
489 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
490 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
491 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
492 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
493 XMapWindow( gdi_display, win );
494 else
495 win = root;
497 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
499 ERR_(winediag)( "Unable to activate OpenGL context, most likely your %s OpenGL drivers haven't been "
500 "installed correctly\n", is_win64 ? "64-bit" : "32-bit" );
501 goto done;
503 gl_renderer = (const char *)opengl_funcs.gl.p_glGetString(GL_RENDERER);
504 WineGLInfo.glVersion = (const char *) opengl_funcs.gl.p_glGetString(GL_VERSION);
505 str = (const char *) opengl_funcs.gl.p_glGetString(GL_EXTENSIONS);
506 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+sizeof(legacy_extensions));
507 strcpy(WineGLInfo.glExtensions, str);
508 strcat(WineGLInfo.glExtensions, legacy_extensions);
510 /* Get the common GLX version supported by GLX client and server ( major/minor) */
511 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
513 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
514 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
515 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
517 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
518 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
519 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
521 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
522 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
524 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
525 TRACE("GL renderer : %s.\n", gl_renderer);
526 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
527 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
528 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
529 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
530 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
531 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
533 if(!WineGLInfo.glxDirect)
535 int fd = ConnectionNumber(gdi_display);
536 struct sockaddr_un uaddr;
537 unsigned int uaddrlen = sizeof(struct sockaddr_un);
539 /* In general indirect rendering on a local X11 server indicates a driver problem.
540 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
542 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
543 ERR_(winediag)("Direct rendering is disabled, most likely your %s OpenGL drivers "
544 "haven't been installed correctly (using GL renderer %s, version %s).\n",
545 is_win64 ? "64-bit" : "32-bit", debugstr_a(gl_renderer),
546 debugstr_a(WineGLInfo.glVersion));
548 else
550 /* In general you would expect that if direct rendering is returned, that you receive hardware
551 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
552 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
553 * software rendering, it shows direct rendering.
555 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
556 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
557 * it shows 'Mesa X11'.
559 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
560 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your %s OpenGL "
561 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
562 is_win64 ? "64-bit" : "32-bit", debugstr_a(gl_renderer),
563 debugstr_a(WineGLInfo.glVersion));
565 ret = TRUE;
567 done:
568 if(vis) XFree(vis);
569 if(ctx) {
570 pglXMakeCurrent(gdi_display, None, NULL);
571 pglXDestroyContext(gdi_display, ctx);
573 if (win != root) XDestroyWindow( gdi_display, win );
574 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
575 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
576 return ret;
579 static void *opengl_handle;
581 static BOOL WINAPI init_opengl( INIT_ONCE *once, void *param, void **context )
583 char buffer[200];
584 int error_base, event_base;
585 unsigned int i;
587 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
588 and include all dependencies */
589 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
590 if (opengl_handle == NULL)
592 ERR( "Failed to load libGL: %s\n", buffer );
593 ERR( "OpenGL support is disabled.\n");
594 return TRUE;
597 for (i = 0; i < sizeof(opengl_func_names)/sizeof(opengl_func_names[0]); i++)
599 if (!(((void **)&opengl_funcs.gl)[i] = wine_dlsym( opengl_handle, opengl_func_names[i], NULL, 0 )))
601 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names[i] );
602 goto failed;
606 /* redirect some standard OpenGL functions */
607 #define REDIRECT(func) \
608 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
609 REDIRECT( glFinish );
610 REDIRECT( glFlush );
611 REDIRECT( glGetString );
612 #undef REDIRECT
614 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
615 if (pglXGetProcAddressARB == NULL) {
616 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
617 goto failed;
620 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
622 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
623 goto failed; \
624 } while(0)
626 /* GLX 1.0 */
627 LOAD_FUNCPTR(glXChooseVisual);
628 LOAD_FUNCPTR(glXCopyContext);
629 LOAD_FUNCPTR(glXCreateContext);
630 LOAD_FUNCPTR(glXGetCurrentContext);
631 LOAD_FUNCPTR(glXGetCurrentDrawable);
632 LOAD_FUNCPTR(glXDestroyContext);
633 LOAD_FUNCPTR(glXGetConfig);
634 LOAD_FUNCPTR(glXIsDirect);
635 LOAD_FUNCPTR(glXMakeCurrent);
636 LOAD_FUNCPTR(glXSwapBuffers);
637 LOAD_FUNCPTR(glXQueryExtension);
638 LOAD_FUNCPTR(glXQueryVersion);
640 /* GLX 1.1 */
641 LOAD_FUNCPTR(glXGetClientString);
642 LOAD_FUNCPTR(glXQueryExtensionsString);
643 LOAD_FUNCPTR(glXQueryServerString);
645 /* GLX 1.3 */
646 LOAD_FUNCPTR(glXCreatePbuffer);
647 LOAD_FUNCPTR(glXCreateNewContext);
648 LOAD_FUNCPTR(glXDestroyPbuffer);
649 LOAD_FUNCPTR(glXMakeContextCurrent);
650 LOAD_FUNCPTR(glXGetFBConfigs);
651 LOAD_FUNCPTR(glXCreatePixmap);
652 LOAD_FUNCPTR(glXDestroyPixmap);
653 LOAD_FUNCPTR(glXCreateWindow);
654 LOAD_FUNCPTR(glXDestroyWindow);
655 #undef LOAD_FUNCPTR
657 /* It doesn't matter if these fail. They'll only be used if the driver reports
658 the associated extension is available (and if a driver reports the extension
659 is available but fails to provide the functions, it's quite broken) */
660 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
661 /* ARB GLX Extension */
662 LOAD_FUNCPTR(glXCreateContextAttribsARB);
663 /* EXT GLX Extension */
664 LOAD_FUNCPTR(glXSwapIntervalEXT);
665 /* MESA GLX Extension */
666 LOAD_FUNCPTR(glXSwapIntervalMESA);
667 /* SGI GLX Extension */
668 LOAD_FUNCPTR(glXSwapIntervalSGI);
669 /* NV GLX Extension */
670 LOAD_FUNCPTR(glXAllocateMemoryNV);
671 LOAD_FUNCPTR(glXFreeMemoryNV);
672 #undef LOAD_FUNCPTR
674 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
676 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
677 TRACE("GLX is up and running error_base = %d\n", error_base);
678 } else {
679 ERR( "GLX extension is missing, disabling OpenGL.\n" );
680 goto failed;
682 gl_hwnd_context = XUniqueContext();
683 gl_pbuffer_context = XUniqueContext();
685 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
686 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
687 * rendering is used.
689 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
690 * depends on the reported GLX client / server version and on the client / server extension list.
691 * Those don't have to be the same.
693 * In general the server GLX information lists the capabilities in case of indirect rendering.
694 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
695 * available and in that case the client GLX informat can be used.
696 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
697 * in the GLX version/extension list. When a program does this it works for certain for both
698 * direct and indirect rendering.
700 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
701 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
702 * extension list which causes this extension not to be listed. (Wine requires this extension).
703 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
704 * pbuffers is around.
706 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
707 * the ATI drivers and from then on use GLX client information for them.
710 if(glxRequireVersion(3)) {
711 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
712 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
713 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
714 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
715 } else if (has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_fbconfig")) {
716 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
717 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
718 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
720 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
721 * enable this function when the Xserver understand GLX 1.3 or newer
723 pglXQueryDrawable = NULL;
724 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
725 TRACE("Overriding ATI GLX capabilities!\n");
726 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
727 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
728 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
729 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
731 /* Use client GLX information in case of the ATI drivers. We override the
732 * capabilities over here and not somewhere else as ATI might better their
733 * life in the future. In case they release proper drivers this block of
734 * code won't be called. */
735 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
736 } else {
737 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
740 if (has_extension( WineGLInfo.glxExtensions, "GLX_MESA_copy_sub_buffer")) {
741 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
744 if (has_extension( WineGLInfo.glxExtensions, "GLX_MESA_query_renderer" ))
746 pglXQueryCurrentRendererIntegerMESA = pglXGetProcAddressARB(
747 (const GLubyte *)"glXQueryCurrentRendererIntegerMESA" );
748 pglXQueryCurrentRendererStringMESA = pglXGetProcAddressARB(
749 (const GLubyte *)"glXQueryCurrentRendererStringMESA" );
750 pglXQueryRendererIntegerMESA = pglXGetProcAddressARB( (const GLubyte *)"glXQueryRendererIntegerMESA" );
751 pglXQueryRendererStringMESA = pglXGetProcAddressARB( (const GLubyte *)"glXQueryRendererStringMESA" );
754 X11DRV_WineGL_LoadExtensions();
755 init_pixel_formats( gdi_display );
756 return TRUE;
758 failed:
759 wine_dlclose(opengl_handle, NULL, 0);
760 opengl_handle = NULL;
761 return TRUE;
764 static BOOL has_opengl(void)
766 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
767 InitOnceExecuteOnce(&init_once, init_opengl, NULL, NULL);
768 return opengl_handle != NULL;
771 static const char *debugstr_fbconfig( GLXFBConfig fbconfig )
773 int id, visual, drawable;
775 if (pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_FBCONFIG_ID, &id ))
776 return "*** invalid fbconfig";
777 pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_VISUAL_ID, &visual );
778 pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &drawable );
779 return wine_dbg_sprintf( "fbconfig %#x visual id %#x drawable type %#x", id, visual, drawable );
782 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, struct wgl_pbuffer* pbuf) {
783 int nAttribs = 0;
784 unsigned cur = 0;
785 int pop;
786 int drawattrib = 0;
787 int nvfloatattrib = GLX_DONT_CARE;
788 int pixelattrib = GLX_DONT_CARE;
790 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
791 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
792 while (iWGLAttr && 0 != iWGLAttr[cur]) {
793 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
795 switch (iWGLAttr[cur]) {
796 case WGL_AUX_BUFFERS_ARB:
797 pop = iWGLAttr[++cur];
798 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
799 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
800 break;
801 case WGL_COLOR_BITS_ARB:
802 pop = iWGLAttr[++cur];
803 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
804 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
805 break;
806 case WGL_BLUE_BITS_ARB:
807 pop = iWGLAttr[++cur];
808 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
809 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
810 break;
811 case WGL_RED_BITS_ARB:
812 pop = iWGLAttr[++cur];
813 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
814 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
815 break;
816 case WGL_GREEN_BITS_ARB:
817 pop = iWGLAttr[++cur];
818 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
819 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
820 break;
821 case WGL_ALPHA_BITS_ARB:
822 pop = iWGLAttr[++cur];
823 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
824 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
825 break;
826 case WGL_DEPTH_BITS_ARB:
827 pop = iWGLAttr[++cur];
828 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
829 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
830 break;
831 case WGL_STENCIL_BITS_ARB:
832 pop = iWGLAttr[++cur];
833 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
834 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
835 break;
836 case WGL_DOUBLE_BUFFER_ARB:
837 pop = iWGLAttr[++cur];
838 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
839 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
840 break;
841 case WGL_STEREO_ARB:
842 pop = iWGLAttr[++cur];
843 PUSH2(oGLXAttr, GLX_STEREO, pop);
844 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
845 break;
847 case WGL_PIXEL_TYPE_ARB:
848 pop = iWGLAttr[++cur];
849 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
850 switch (pop) {
851 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
852 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
853 /* 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 */
854 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
855 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
856 default:
857 ERR("unexpected PixelType(%x)\n", pop);
858 pop = 0;
860 break;
862 case WGL_SUPPORT_GDI_ARB:
863 /* This flag is set in a pixel format */
864 pop = iWGLAttr[++cur];
865 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
866 break;
868 case WGL_DRAW_TO_BITMAP_ARB:
869 /* This flag is set in a pixel format */
870 pop = iWGLAttr[++cur];
871 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
872 break;
874 case WGL_DRAW_TO_WINDOW_ARB:
875 pop = iWGLAttr[++cur];
876 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
877 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
878 if (pop) {
879 drawattrib |= GLX_WINDOW_BIT;
881 break;
883 case WGL_DRAW_TO_PBUFFER_ARB:
884 pop = iWGLAttr[++cur];
885 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
886 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
887 if (pop) {
888 drawattrib |= GLX_PBUFFER_BIT;
890 break;
892 case WGL_ACCELERATION_ARB:
893 /* This flag is set in a pixel format */
894 pop = iWGLAttr[++cur];
895 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
896 break;
898 case WGL_SUPPORT_OPENGL_ARB:
899 pop = iWGLAttr[++cur];
900 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
901 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
902 break;
904 case WGL_SWAP_METHOD_ARB:
905 pop = iWGLAttr[++cur];
906 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
907 if (has_swap_method)
909 switch (pop)
911 case WGL_SWAP_EXCHANGE_ARB:
912 pop = GLX_SWAP_EXCHANGE_OML;
913 break;
914 case WGL_SWAP_COPY_ARB:
915 pop = GLX_SWAP_COPY_OML;
916 break;
917 case WGL_SWAP_UNDEFINED_ARB:
918 pop = GLX_SWAP_UNDEFINED_OML;
919 break;
920 default:
921 ERR("Unexpected swap method %#x.\n", pop);
922 pop = GLX_DONT_CARE;
924 PUSH2(oGLXAttr, GLX_SWAP_METHOD_OML, pop);
926 else
928 WARN("GLX_OML_swap_method not supported, ignoring attribute.\n");
930 break;
932 case WGL_PBUFFER_LARGEST_ARB:
933 pop = iWGLAttr[++cur];
934 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
935 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
936 break;
938 case WGL_SAMPLE_BUFFERS_ARB:
939 pop = iWGLAttr[++cur];
940 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
941 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
942 break;
944 case WGL_SAMPLES_ARB:
945 pop = iWGLAttr[++cur];
946 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
947 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
948 break;
950 case WGL_TEXTURE_FORMAT_ARB:
951 case WGL_TEXTURE_TARGET_ARB:
952 case WGL_MIPMAP_TEXTURE_ARB:
953 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
954 pop = iWGLAttr[++cur];
955 if (NULL == pbuf) {
956 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
958 if (!use_render_texture_emulation) {
959 if (WGL_NO_TEXTURE_ARB != pop) {
960 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
961 return -1; /** error: don't support it */
962 } else {
963 drawattrib |= GLX_PBUFFER_BIT;
966 break ;
967 case WGL_FLOAT_COMPONENTS_NV:
968 nvfloatattrib = iWGLAttr[++cur];
969 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
970 break ;
971 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
972 case WGL_BIND_TO_TEXTURE_RGB_ARB:
973 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
974 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
975 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
976 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
977 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
978 pop = iWGLAttr[++cur];
979 /** cannot be converted, see direct handling on
980 * - wglGetPixelFormatAttribivARB
981 * TODO: wglChoosePixelFormat
983 break ;
984 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
985 pop = iWGLAttr[++cur];
986 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
987 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
988 break ;
990 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
991 pop = iWGLAttr[++cur];
992 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
993 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
994 break ;
995 default:
996 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
997 cur++;
998 break;
1000 ++cur;
1003 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
1004 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
1005 * pixmap and pbuffer formats appear as well. */
1006 if (!drawattrib) drawattrib = GLX_DONT_CARE;
1007 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
1008 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
1010 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
1011 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
1012 * GLX_DONT_CARE unless it is overridden. */
1013 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
1014 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
1016 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
1017 if (has_extension(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
1018 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
1019 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
1022 return nAttribs;
1025 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
1027 int render_type, render_type_bit;
1028 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
1029 switch(render_type_bit)
1031 case GLX_RGBA_BIT:
1032 render_type = GLX_RGBA_TYPE;
1033 break;
1034 case GLX_COLOR_INDEX_BIT:
1035 render_type = GLX_COLOR_INDEX_TYPE;
1036 break;
1037 case GLX_RGBA_FLOAT_BIT:
1038 render_type = GLX_RGBA_FLOAT_TYPE;
1039 break;
1040 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
1041 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
1042 break;
1043 default:
1044 ERR("Unknown render_type: %x\n", render_type_bit);
1045 render_type = 0;
1047 return render_type;
1050 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
1051 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
1053 int dbuf, value;
1054 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
1055 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
1057 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
1058 * the GLX_PIXMAP_BIT set. */
1059 return !dbuf && (value & GLX_PIXMAP_BIT);
1062 static void init_pixel_formats( Display *display )
1064 struct wgl_pixel_format *list;
1065 int size = 0, onscreen_size = 0;
1066 int fmt_id, nCfgs, i, run, bmp_formats;
1067 GLXFBConfig* cfgs;
1068 XVisualInfo *visinfo;
1070 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
1071 if (NULL == cfgs || 0 == nCfgs) {
1072 if(cfgs != NULL) XFree(cfgs);
1073 ERR("glXChooseFBConfig returns NULL\n");
1074 return;
1077 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
1078 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
1079 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
1080 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
1082 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
1084 for(i=0, bmp_formats=0; i<nCfgs; i++)
1086 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1087 bmp_formats++;
1089 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
1091 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats) * sizeof(*list));
1093 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
1094 * Do this as GLX doesn't guarantee that the list is sorted */
1095 for(run=0; run < 2; run++)
1097 for(i=0; i<nCfgs; i++) {
1098 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
1099 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
1101 /* The first run we only add onscreen formats (ones which have an associated X Visual).
1102 * The second run we only set offscreen formats. */
1103 if(!run && visinfo)
1105 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
1106 * The contents is copied to the destination using XCopyArea. For the copying to work
1107 * the depth of the source and destination window should be the same. In general this should
1108 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
1109 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
1110 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
1111 * list formats with the same depth. */
1112 if(visinfo->depth != default_visual.depth)
1114 XFree(visinfo);
1115 continue;
1118 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1119 list[size].fbconfig = cfgs[i];
1120 list[size].fmt_id = fmt_id;
1121 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1122 list[size].dwFlags = 0;
1123 size++;
1124 onscreen_size++;
1126 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1127 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1129 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1130 list[size].fbconfig = cfgs[i];
1131 list[size].fmt_id = fmt_id;
1132 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1133 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1134 size++;
1135 onscreen_size++;
1137 } else if(run && !visinfo) {
1138 int window_drawable=0;
1139 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1141 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1142 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1143 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1144 * likely make our child window opengl rendering more complicated since likely you can't use
1145 * XCopyArea on a GLX Window.
1146 * For now ignore fbconfigs which are window drawable but lack a visual. */
1147 if(window_drawable & GLX_WINDOW_BIT)
1149 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1150 continue;
1153 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1154 list[size].fbconfig = cfgs[i];
1155 list[size].fmt_id = fmt_id;
1156 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1157 list[size].dwFlags = 0;
1158 size++;
1161 if (visinfo) XFree(visinfo);
1165 XFree(cfgs);
1167 pixel_formats = list;
1168 nb_pixel_formats = size;
1169 nb_onscreen_formats = onscreen_size;
1172 static inline BOOL is_valid_pixel_format( int format )
1174 return format > 0 && format <= nb_pixel_formats;
1177 static inline BOOL is_onscreen_pixel_format( int format )
1179 return format > 0 && format <= nb_onscreen_formats;
1182 static inline int pixel_format_index( const struct wgl_pixel_format *format )
1184 return format - pixel_formats + 1;
1187 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1188 * In our WGL implementation we only support a subset of these formats namely the format of
1189 * Wine's main visual and offscreen formats (if they are available).
1190 * This function converts a WGL format to its corresponding GLX one.
1192 static const struct wgl_pixel_format *get_pixel_format(Display *display, int iPixelFormat, BOOL AllowOffscreen)
1194 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1195 * iPixelFormat in case of probing the number of pixelformats.
1197 if (is_valid_pixel_format( iPixelFormat ) &&
1198 (is_onscreen_pixel_format( iPixelFormat ) || AllowOffscreen)) {
1199 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1200 pixel_formats[iPixelFormat-1].fmt_id, iPixelFormat);
1201 return &pixel_formats[iPixelFormat-1];
1203 return NULL;
1206 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1207 static void mark_drawable_dirty(GLXDrawable old, GLXDrawable new)
1209 struct wgl_context *ctx;
1211 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
1213 if (old == ctx->drawables[0]) {
1214 ctx->drawables[0] = new;
1215 ctx->refresh_drawables = TRUE;
1217 if (old == ctx->drawables[1]) {
1218 ctx->drawables[1] = new;
1219 ctx->refresh_drawables = TRUE;
1224 /* Given the current context, make sure its drawable is sync'd */
1225 static inline void sync_context(struct wgl_context *context)
1227 if (context->refresh_drawables) {
1228 if (glxRequireVersion(3))
1229 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1230 context->drawables[1], context->ctx);
1231 else
1232 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1233 context->refresh_drawables = FALSE;
1237 static BOOL set_swap_interval(GLXDrawable drawable, int interval)
1239 BOOL ret = TRUE;
1241 switch (swap_control_method)
1243 case GLX_SWAP_CONTROL_EXT:
1244 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1245 pglXSwapIntervalEXT(gdi_display, drawable, interval);
1246 XSync(gdi_display, False);
1247 ret = !X11DRV_check_error();
1248 break;
1250 case GLX_SWAP_CONTROL_MESA:
1251 ret = !pglXSwapIntervalMESA(interval);
1252 break;
1254 case GLX_SWAP_CONTROL_SGI:
1255 /* wglSwapIntervalEXT considers an interval value of zero to mean that
1256 * vsync should be disabled, but glXSwapIntervalSGI considers such a
1257 * value to be an error. Just silently ignore the request for now.
1259 if (!interval)
1260 WARN("Request to disable vertical sync is not handled\n");
1261 else
1262 ret = !pglXSwapIntervalSGI(interval);
1263 break;
1265 case GLX_SWAP_CONTROL_NONE:
1266 /* Unlikely to happen on modern GLX implementations */
1267 WARN("Request to adjust swap interval is not handled\n");
1268 break;
1271 return ret;
1274 static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc )
1276 struct gl_drawable *gl;
1278 EnterCriticalSection( &context_section );
1279 if (hwnd && !XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl )) return gl;
1280 if (hdc && !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl )) return gl;
1281 LeaveCriticalSection( &context_section );
1282 return NULL;
1285 static void release_gl_drawable( struct gl_drawable *gl )
1287 if (gl) LeaveCriticalSection( &context_section );
1290 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1292 GLXContext ctx;
1294 if(context->gl3_context)
1296 if(context->numAttribs)
1297 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, GL_TRUE, context->attribList);
1298 else
1299 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, GL_TRUE, NULL);
1301 else if(context->vis)
1302 ctx = pglXCreateContext(gdi_display, context->vis, shareList, GL_TRUE);
1303 else /* Create a GLX Context for a pbuffer */
1304 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1306 return ctx;
1310 /***********************************************************************
1311 * free_gl_drawable
1313 static void free_gl_drawable( struct gl_drawable *gl )
1315 switch (gl->type)
1317 case DC_GL_CHILD_WIN:
1318 pglXDestroyWindow( gdi_display, gl->drawable );
1319 XDestroyWindow( gdi_display, gl->window );
1320 XFreeColormap( gdi_display, gl->colormap );
1321 break;
1322 case DC_GL_PIXMAP_WIN:
1323 pglXDestroyPixmap( gdi_display, gl->drawable );
1324 XFreePixmap( gdi_display, gl->pixmap );
1325 break;
1326 default:
1327 break;
1329 if (gl->visual) XFree( gl->visual );
1330 HeapFree( GetProcessHeap(), 0, gl );
1334 /***********************************************************************
1335 * create_gl_drawable
1337 static BOOL create_gl_drawable( HWND hwnd, struct gl_drawable *gl )
1339 gl->drawable = 0;
1341 if (GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow()) /* top-level window */
1343 struct x11drv_win_data *data = get_win_data( hwnd );
1345 if (data)
1347 gl->type = DC_GL_WINDOW;
1348 gl->window = create_client_window( data, gl->visual );
1349 if (gl->window)
1350 gl->drawable = pglXCreateWindow( gdi_display, gl->format->fbconfig, gl->window, NULL );
1351 release_win_data( data );
1354 #ifdef SONAME_LIBXCOMPOSITE
1355 else if(usexcomposite)
1357 static Window dummy_parent;
1358 XSetWindowAttributes attrib;
1360 attrib.override_redirect = True;
1361 if (!dummy_parent)
1363 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, default_visual.depth,
1364 InputOutput, default_visual.visual, CWOverrideRedirect, &attrib );
1365 XMapWindow( gdi_display, dummy_parent );
1367 gl->colormap = XCreateColormap(gdi_display, dummy_parent, gl->visual->visual,
1368 (gl->visual->class == PseudoColor ||
1369 gl->visual->class == GrayScale ||
1370 gl->visual->class == DirectColor) ?
1371 AllocAll : AllocNone);
1372 attrib.colormap = gl->colormap;
1373 XInstallColormap(gdi_display, attrib.colormap);
1375 gl->type = DC_GL_CHILD_WIN;
1376 gl->window = XCreateWindow( gdi_display, dummy_parent, 0, 0,
1377 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1378 0, gl->visual->depth, InputOutput, gl->visual->visual,
1379 CWColormap | CWOverrideRedirect, &attrib );
1380 if (gl->window)
1382 gl->drawable = pglXCreateWindow( gdi_display, gl->format->fbconfig, gl->window, NULL );
1383 if (gl->drawable)
1385 pXCompositeRedirectWindow(gdi_display, gl->window, CompositeRedirectManual);
1386 XMapWindow(gdi_display, gl->window);
1389 else XFreeColormap( gdi_display, gl->colormap );
1391 #endif
1392 else
1394 WARN("XComposite is not available, using GLXPixmap hack\n");
1396 gl->type = DC_GL_PIXMAP_WIN;
1397 gl->pixmap = XCreatePixmap( gdi_display, root_window,
1398 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1399 gl->visual->depth );
1400 if (gl->pixmap)
1402 gl->drawable = pglXCreatePixmap( gdi_display, gl->format->fbconfig, gl->pixmap, NULL );
1403 if (!gl->drawable) XFreePixmap( gdi_display, gl->pixmap );
1407 if (gl->drawable)
1408 gl->refresh_swap_interval = TRUE;
1409 return gl->drawable != 0;
1413 /***********************************************************************
1414 * set_win_format
1416 static BOOL set_win_format( HWND hwnd, const struct wgl_pixel_format *format )
1418 struct gl_drawable *gl, *prev;
1420 gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) );
1421 /* Default GLX and WGL swap interval is 1, but in case of glXSwapIntervalSGI
1422 * there is no way to query it, so we have to store it here.
1424 gl->swap_interval = 1;
1425 gl->refresh_swap_interval = TRUE;
1426 gl->format = format;
1427 gl->visual = pglXGetVisualFromFBConfig( gdi_display, format->fbconfig );
1428 if (!gl->visual)
1430 HeapFree( GetProcessHeap(), 0, gl );
1431 return FALSE;
1434 GetClientRect( hwnd, &gl->rect );
1435 gl->rect.right = min( max( 1, gl->rect.right ), 65535 );
1436 gl->rect.bottom = min( max( 1, gl->rect.bottom ), 65535 );
1438 if (!create_gl_drawable( hwnd, gl ))
1440 XFree( gl->visual );
1441 HeapFree( GetProcessHeap(), 0, gl );
1442 return FALSE;
1445 TRACE( "created GL drawable %lx for win %p %s\n",
1446 gl->drawable, hwnd, debugstr_fbconfig( format->fbconfig ));
1448 XFlush( gdi_display );
1450 EnterCriticalSection( &context_section );
1451 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&prev ))
1453 gl->swap_interval = prev->swap_interval;
1454 free_gl_drawable( prev );
1456 XSaveContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char *)gl );
1457 LeaveCriticalSection( &context_section );
1459 __wine_set_pixel_format( hwnd, pixel_format_index( format ));
1460 return TRUE;
1464 static BOOL set_pixel_format(HDC hdc, int format, BOOL allow_change)
1466 const struct wgl_pixel_format *fmt;
1467 int value;
1468 HWND hwnd = WindowFromDC( hdc );
1470 TRACE("(%p,%d)\n", hdc, format);
1472 if (!hwnd || hwnd == GetDesktopWindow())
1474 WARN( "not a valid window DC %p/%p\n", hdc, hwnd );
1475 return FALSE;
1478 fmt = get_pixel_format(gdi_display, format, FALSE /* Offscreen */);
1479 if (!fmt)
1481 ERR( "Invalid format %d\n", format );
1482 return FALSE;
1485 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1486 if (!(value & GLX_WINDOW_BIT))
1488 WARN( "Pixel format %d is not compatible for window rendering\n", format );
1489 return FALSE;
1492 if (!allow_change)
1494 struct gl_drawable *gl;
1495 if ((gl = get_gl_drawable( hwnd, hdc )))
1497 int prev = pixel_format_index( gl->format );
1498 release_gl_drawable( gl );
1499 return prev == format; /* cannot change it if already set */
1503 return set_win_format( hwnd, fmt );
1507 /***********************************************************************
1508 * sync_gl_drawable
1510 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
1512 struct gl_drawable *gl;
1513 GLXDrawable glxp;
1514 Pixmap pix;
1515 int mask = 0;
1516 XWindowChanges changes;
1518 changes.width = min( max( 1, client_rect->right - client_rect->left ), 65535 );
1519 changes.height = min( max( 1, client_rect->bottom - client_rect->top ), 65535 );
1521 if (!(gl = get_gl_drawable( hwnd, 0 ))) return;
1523 if (changes.width != gl->rect.right - gl->rect.left) mask |= CWWidth;
1524 if (changes.height != gl->rect.bottom - gl->rect.top) mask |= CWHeight;
1526 TRACE( "setting drawable %lx size %dx%d\n", gl->drawable, changes.width, changes.height );
1528 switch (gl->type)
1530 case DC_GL_CHILD_WIN:
1531 if (mask) XConfigureWindow( gdi_display, gl->window, mask, &changes );
1532 break;
1533 case DC_GL_PIXMAP_WIN:
1534 if (!mask) break;
1535 pix = XCreatePixmap(gdi_display, root_window, changes.width, changes.height, gl->visual->depth);
1536 if (!pix) goto done;
1537 glxp = pglXCreatePixmap(gdi_display, gl->format->fbconfig, pix, NULL );
1538 if (!glxp)
1540 XFreePixmap(gdi_display, pix);
1541 goto done;
1543 mark_drawable_dirty(gl->drawable, glxp);
1544 XFlush( gdi_display );
1546 XFreePixmap(gdi_display, gl->pixmap);
1547 pglXDestroyPixmap(gdi_display, gl->drawable);
1548 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, gl->drawable );
1550 gl->pixmap = pix;
1551 gl->drawable = glxp;
1552 break;
1553 default:
1554 break;
1556 SetRect( &gl->rect, 0, 0, changes.width, changes.height );
1557 done:
1558 release_gl_drawable( gl );
1562 /***********************************************************************
1563 * set_gl_drawable_parent
1565 void set_gl_drawable_parent( HWND hwnd, HWND parent )
1567 struct gl_drawable *gl;
1568 GLXDrawable old_drawable;
1570 if (!(gl = get_gl_drawable( hwnd, 0 ))) return;
1572 TRACE( "setting drawable %lx parent %p\n", gl->drawable, parent );
1574 old_drawable = gl->drawable;
1575 switch (gl->type)
1577 case DC_GL_WINDOW:
1578 break;
1579 case DC_GL_CHILD_WIN:
1580 if (parent != GetDesktopWindow()) goto done;
1581 pglXDestroyWindow( gdi_display, gl->drawable );
1582 XDestroyWindow( gdi_display, gl->window );
1583 XFreeColormap( gdi_display, gl->colormap );
1584 break;
1585 case DC_GL_PIXMAP_WIN:
1586 if (parent != GetDesktopWindow()) goto done;
1587 pglXDestroyPixmap( gdi_display, gl->drawable );
1588 XFreePixmap( gdi_display, gl->pixmap );
1589 break;
1590 default:
1591 goto done;
1594 if (!create_gl_drawable( hwnd, gl ))
1596 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1597 release_gl_drawable( gl );
1598 XFree( gl->visual );
1599 HeapFree( GetProcessHeap(), 0, gl );
1600 __wine_set_pixel_format( hwnd, 0 );
1601 return;
1603 mark_drawable_dirty( old_drawable, gl->drawable );
1605 done:
1606 release_gl_drawable( gl );
1611 /***********************************************************************
1612 * destroy_gl_drawable
1614 void destroy_gl_drawable( HWND hwnd )
1616 struct gl_drawable *gl;
1618 EnterCriticalSection( &context_section );
1619 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1621 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1622 free_gl_drawable( gl );
1624 LeaveCriticalSection( &context_section );
1629 * glxdrv_DescribePixelFormat
1631 * Get the pixel-format descriptor associated to the given id
1633 static int glxdrv_wglDescribePixelFormat( HDC hdc, int iPixelFormat,
1634 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1636 /*XVisualInfo *vis;*/
1637 int value;
1638 int rb,gb,bb,ab;
1639 const struct wgl_pixel_format *fmt;
1641 if (!has_opengl()) return 0;
1643 TRACE("(%p,%d,%d,%p)\n", hdc, iPixelFormat, nBytes, ppfd);
1645 if (!ppfd) return nb_onscreen_formats;
1647 /* 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 */
1648 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1649 if (!fmt) {
1650 WARN("unexpected format %d\n", iPixelFormat);
1651 return 0;
1654 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1655 ERR("Wrong structure size !\n");
1656 /* Should set error */
1657 return 0;
1660 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1661 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1662 ppfd->nVersion = 1;
1664 /* These flags are always the same... */
1665 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1666 /* Now the flags extracted from the Visual */
1668 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1669 if(value & GLX_WINDOW_BIT)
1670 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1672 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1673 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1674 * 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
1675 * offered the GDI bit either. */
1676 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1678 /* PFD_GENERIC_FORMAT - gdi software rendering
1679 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1680 * none set - full hardware accelerated by a ICD
1682 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1683 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1685 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1686 if (value) {
1687 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1688 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1690 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1692 /* Pixel type */
1693 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1694 if (value & GLX_RGBA_BIT)
1695 ppfd->iPixelType = PFD_TYPE_RGBA;
1696 else
1697 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1699 /* Color bits */
1700 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1701 ppfd->cColorBits = value;
1703 /* Red, green, blue and alpha bits / shifts */
1704 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1705 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1706 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1707 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1708 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1710 ppfd->cRedBits = rb;
1711 ppfd->cRedShift = gb + bb + ab;
1712 ppfd->cBlueBits = bb;
1713 ppfd->cBlueShift = ab;
1714 ppfd->cGreenBits = gb;
1715 ppfd->cGreenShift = bb + ab;
1716 ppfd->cAlphaBits = ab;
1717 ppfd->cAlphaShift = 0;
1718 } else {
1719 ppfd->cRedBits = 0;
1720 ppfd->cRedShift = 0;
1721 ppfd->cBlueBits = 0;
1722 ppfd->cBlueShift = 0;
1723 ppfd->cGreenBits = 0;
1724 ppfd->cGreenShift = 0;
1725 ppfd->cAlphaBits = 0;
1726 ppfd->cAlphaShift = 0;
1729 /* Accum RGBA bits */
1730 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1731 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1732 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1733 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1735 ppfd->cAccumBits = rb+gb+bb+ab;
1736 ppfd->cAccumRedBits = rb;
1737 ppfd->cAccumGreenBits = gb;
1738 ppfd->cAccumBlueBits = bb;
1739 ppfd->cAccumAlphaBits = ab;
1741 /* Aux bits */
1742 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1743 ppfd->cAuxBuffers = value;
1745 /* Depth bits */
1746 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1747 ppfd->cDepthBits = value;
1749 /* stencil bits */
1750 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1751 ppfd->cStencilBits = value;
1753 ppfd->iLayerType = PFD_MAIN_PLANE;
1755 if (TRACE_ON(wgl)) {
1756 dump_PIXELFORMATDESCRIPTOR(ppfd);
1759 return nb_onscreen_formats;
1762 /***********************************************************************
1763 * glxdrv_wglGetPixelFormat
1765 static int glxdrv_wglGetPixelFormat( HDC hdc )
1767 struct gl_drawable *gl;
1768 int ret = 0;
1770 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1772 ret = pixel_format_index( gl->format );
1773 /* Offscreen formats can't be used with traditional WGL calls.
1774 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1775 if (!is_onscreen_pixel_format( ret )) ret = 1;
1776 release_gl_drawable( gl );
1778 TRACE( "%p -> %d\n", hdc, ret );
1779 return ret;
1782 /***********************************************************************
1783 * glxdrv_wglSetPixelFormat
1785 static BOOL glxdrv_wglSetPixelFormat( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd )
1787 return set_pixel_format(hdc, iPixelFormat, FALSE);
1790 /***********************************************************************
1791 * glxdrv_wglCopyContext
1793 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1795 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1797 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1799 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1800 return TRUE;
1803 /***********************************************************************
1804 * glxdrv_wglCreateContext
1806 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1808 struct wgl_context *ret;
1809 struct gl_drawable *gl;
1811 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1813 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1814 return NULL;
1817 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
1819 ret->hdc = hdc;
1820 ret->fmt = gl->format;
1821 ret->vis = pglXGetVisualFromFBConfig(gdi_display, gl->format->fbconfig);
1822 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1823 list_add_head( &context_list, &ret->entry );
1825 release_gl_drawable( gl );
1826 TRACE( "%p -> %p\n", hdc, ret );
1827 return ret;
1830 /***********************************************************************
1831 * glxdrv_wglDeleteContext
1833 static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
1835 struct wgl_pbuffer *pb;
1837 TRACE("(%p)\n", ctx);
1839 EnterCriticalSection( &context_section );
1840 list_remove( &ctx->entry );
1841 LIST_FOR_EACH_ENTRY( pb, &pbuffer_list, struct wgl_pbuffer, entry )
1843 if (pb->prev_context == ctx->ctx) {
1844 pglXDestroyContext(gdi_display, pb->tmp_context);
1845 pb->prev_context = pb->tmp_context = NULL;
1848 LeaveCriticalSection( &context_section );
1850 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1851 if (ctx->vis) XFree( ctx->vis );
1852 HeapFree( GetProcessHeap(), 0, ctx );
1855 /***********************************************************************
1856 * glxdrv_wglGetProcAddress
1858 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1860 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1861 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1864 /***********************************************************************
1865 * glxdrv_wglMakeCurrent
1867 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1869 BOOL ret = FALSE;
1870 struct gl_drawable *gl;
1872 TRACE("(%p,%p)\n", hdc, ctx);
1874 if (!ctx)
1876 pglXMakeCurrent(gdi_display, None, NULL);
1877 NtCurrentTeb()->glContext = NULL;
1878 return TRUE;
1881 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1883 if (ctx->fmt != gl->format)
1885 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc, gl->format, ctx, ctx->fmt );
1886 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1887 goto done;
1890 TRACE("hdc %p drawable %lx fmt %p ctx %p %s\n", hdc, gl->drawable, gl->format, ctx->ctx,
1891 debugstr_fbconfig( gl->format->fbconfig ));
1893 ret = pglXMakeCurrent(gdi_display, gl->drawable, ctx->ctx);
1894 if (ret)
1896 NtCurrentTeb()->glContext = ctx;
1897 ctx->has_been_current = TRUE;
1898 ctx->hdc = hdc;
1899 ctx->drawables[0] = gl->drawable;
1900 ctx->drawables[1] = gl->drawable;
1901 ctx->refresh_drawables = FALSE;
1902 goto done;
1905 SetLastError( ERROR_INVALID_HANDLE );
1907 done:
1908 release_gl_drawable( gl );
1909 TRACE( "%p,%p returning %d\n", hdc, ctx, ret );
1910 return ret;
1913 /***********************************************************************
1914 * X11DRV_wglMakeContextCurrentARB
1916 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1918 BOOL ret = FALSE;
1919 struct gl_drawable *draw_gl, *read_gl = NULL;
1921 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1923 if (!ctx)
1925 pglXMakeCurrent(gdi_display, None, NULL);
1926 NtCurrentTeb()->glContext = NULL;
1927 return TRUE;
1930 if (!pglXMakeContextCurrent) return FALSE;
1932 if ((draw_gl = get_gl_drawable( WindowFromDC( draw_hdc ), draw_hdc )))
1934 read_gl = get_gl_drawable( WindowFromDC( read_hdc ), read_hdc );
1935 ret = pglXMakeContextCurrent(gdi_display, draw_gl->drawable,
1936 read_gl ? read_gl->drawable : 0, ctx->ctx);
1937 if (ret)
1939 ctx->has_been_current = TRUE;
1940 ctx->hdc = draw_hdc;
1941 ctx->drawables[0] = draw_gl->drawable;
1942 ctx->drawables[1] = read_gl ? read_gl->drawable : 0;
1943 ctx->refresh_drawables = FALSE;
1944 NtCurrentTeb()->glContext = ctx;
1945 goto done;
1948 SetLastError( ERROR_INVALID_HANDLE );
1949 done:
1950 release_gl_drawable( read_gl );
1951 release_gl_drawable( draw_gl );
1952 TRACE( "%p,%p,%p returning %d\n", draw_hdc, read_hdc, ctx, ret );
1953 return ret;
1956 /***********************************************************************
1957 * glxdrv_wglShareLists
1959 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1961 TRACE("(%p, %p)\n", org, dest);
1963 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1964 * at context creation time but in case of WGL it is done using wglShareLists.
1965 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1966 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1967 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1968 * so there delaying context creation doesn't work.
1970 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1971 * and when a program requests sharing we recreate the destination context if it hasn't been made
1972 * current or when it hasn't shared display lists before.
1975 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1977 ERR("Could not share display lists, one of the contexts has been current already !\n");
1978 return FALSE;
1980 else if(dest->sharing)
1982 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1983 return FALSE;
1985 else
1987 /* Re-create the GLX context and share display lists */
1988 pglXDestroyContext(gdi_display, dest->ctx);
1989 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1990 TRACE(" re-created context (%p) for Wine context %p (%s) sharing lists with ctx %p (%s)\n",
1991 dest->ctx, dest, debugstr_fbconfig(dest->fmt->fbconfig),
1992 org->ctx, debugstr_fbconfig( org->fmt->fbconfig));
1994 org->sharing = TRUE;
1995 dest->sharing = TRUE;
1996 return TRUE;
1998 return FALSE;
2001 static void wglFinish(void)
2003 struct x11drv_escape_flush_gl_drawable escape;
2004 struct gl_drawable *gl;
2005 struct wgl_context *ctx = NtCurrentTeb()->glContext;
2007 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
2008 escape.gl_drawable = 0;
2010 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
2012 switch (gl->type)
2014 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
2015 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->window; break;
2016 default: break;
2018 sync_context(ctx);
2019 release_gl_drawable( gl );
2022 pglFinish();
2023 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2026 static void wglFlush(void)
2028 struct x11drv_escape_flush_gl_drawable escape;
2029 struct gl_drawable *gl;
2030 struct wgl_context *ctx = NtCurrentTeb()->glContext;
2032 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
2033 escape.gl_drawable = 0;
2035 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
2037 switch (gl->type)
2039 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
2040 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->window; break;
2041 default: break;
2043 sync_context(ctx);
2044 release_gl_drawable( gl );
2047 pglFlush();
2048 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2051 static const GLubyte *wglGetString(GLenum name)
2053 if (name == GL_EXTENSIONS && WineGLInfo.glExtensions)
2054 return (const GLubyte *)WineGLInfo.glExtensions;
2055 return pglGetString(name);
2058 /***********************************************************************
2059 * X11DRV_wglCreateContextAttribsARB
2061 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
2062 const int* attribList )
2064 struct wgl_context *ret;
2065 struct gl_drawable *gl;
2066 int err = 0;
2068 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
2070 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
2072 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
2073 return NULL;
2076 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
2078 ret->hdc = hdc;
2079 ret->fmt = gl->format;
2080 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2081 ret->gl3_context = TRUE;
2082 if (attribList)
2084 int *pContextAttribList = &ret->attribList[0];
2085 /* attribList consists of pairs {token, value] terminated with 0 */
2086 while(attribList[0] != 0)
2088 TRACE("%#x %#x\n", attribList[0], attribList[1]);
2089 switch(attribList[0])
2091 case WGL_CONTEXT_MAJOR_VERSION_ARB:
2092 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
2093 pContextAttribList[1] = attribList[1];
2094 pContextAttribList += 2;
2095 ret->numAttribs++;
2096 break;
2097 case WGL_CONTEXT_MINOR_VERSION_ARB:
2098 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
2099 pContextAttribList[1] = attribList[1];
2100 pContextAttribList += 2;
2101 ret->numAttribs++;
2102 break;
2103 case WGL_CONTEXT_LAYER_PLANE_ARB:
2104 break;
2105 case WGL_CONTEXT_FLAGS_ARB:
2106 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
2107 pContextAttribList[1] = attribList[1];
2108 pContextAttribList += 2;
2109 ret->numAttribs++;
2110 break;
2111 case WGL_CONTEXT_PROFILE_MASK_ARB:
2112 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
2113 pContextAttribList[1] = attribList[1];
2114 pContextAttribList += 2;
2115 ret->numAttribs++;
2116 break;
2117 case WGL_RENDERER_ID_WINE:
2118 pContextAttribList[0] = GLX_RENDERER_ID_MESA;
2119 pContextAttribList[1] = attribList[1];
2120 pContextAttribList += 2;
2121 ret->numAttribs++;
2122 break;
2123 default:
2124 ERR("Unhandled attribList pair: %#x %#x\n", attribList[0], attribList[1]);
2126 attribList += 2;
2130 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
2131 ret->ctx = create_glxcontext(gdi_display, ret, hShareContext ? hShareContext->ctx : NULL);
2132 XSync(gdi_display, False);
2133 if ((err = X11DRV_check_error()) || !ret->ctx)
2135 /* In the future we should convert the GLX error to a win32 one here if needed */
2136 ERR("Context creation failed (error %x)\n", err);
2137 HeapFree( GetProcessHeap(), 0, ret );
2138 ret = NULL;
2140 else list_add_head( &context_list, &ret->entry );
2143 release_gl_drawable( gl );
2144 TRACE( "%p -> %p\n", hdc, ret );
2145 return ret;
2149 * X11DRV_wglGetExtensionsStringARB
2151 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2153 static const char *X11DRV_wglGetExtensionsStringARB(HDC hdc)
2155 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2156 return WineGLInfo.wglExtensions;
2160 * X11DRV_wglCreatePbufferARB
2162 * WGL_ARB_pbuffer: wglCreatePbufferARB
2164 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
2165 const int *piAttribList )
2167 struct wgl_pbuffer* object;
2168 const struct wgl_pixel_format *fmt;
2169 int attribs[256];
2170 int nAttribs = 0;
2172 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2174 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2175 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2176 if(!fmt) {
2177 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
2178 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2179 return NULL;
2182 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2183 if (NULL == object) {
2184 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2185 return NULL;
2187 object->width = iWidth;
2188 object->height = iHeight;
2189 object->fmt = fmt;
2191 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2192 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2193 while (piAttribList && 0 != *piAttribList) {
2194 int attr_v;
2195 switch (*piAttribList) {
2196 case WGL_PBUFFER_LARGEST_ARB: {
2197 ++piAttribList;
2198 attr_v = *piAttribList;
2199 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2200 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2201 break;
2204 case WGL_TEXTURE_FORMAT_ARB: {
2205 ++piAttribList;
2206 attr_v = *piAttribList;
2207 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2208 if (WGL_NO_TEXTURE_ARB == attr_v) {
2209 object->use_render_texture = 0;
2210 } else {
2211 if (!use_render_texture_emulation) {
2212 SetLastError(ERROR_INVALID_DATA);
2213 goto create_failed;
2215 switch (attr_v) {
2216 case WGL_TEXTURE_RGB_ARB:
2217 object->use_render_texture = GL_RGB;
2218 object->texture_bpp = 3;
2219 object->texture_format = GL_RGB;
2220 object->texture_type = GL_UNSIGNED_BYTE;
2221 break;
2222 case WGL_TEXTURE_RGBA_ARB:
2223 object->use_render_texture = GL_RGBA;
2224 object->texture_bpp = 4;
2225 object->texture_format = GL_RGBA;
2226 object->texture_type = GL_UNSIGNED_BYTE;
2227 break;
2229 /* WGL_FLOAT_COMPONENTS_NV */
2230 case WGL_TEXTURE_FLOAT_R_NV:
2231 object->use_render_texture = GL_FLOAT_R_NV;
2232 object->texture_bpp = 4;
2233 object->texture_format = GL_RED;
2234 object->texture_type = GL_FLOAT;
2235 break;
2236 case WGL_TEXTURE_FLOAT_RG_NV:
2237 object->use_render_texture = GL_FLOAT_RG_NV;
2238 object->texture_bpp = 8;
2239 object->texture_format = GL_LUMINANCE_ALPHA;
2240 object->texture_type = GL_FLOAT;
2241 break;
2242 case WGL_TEXTURE_FLOAT_RGB_NV:
2243 object->use_render_texture = GL_FLOAT_RGB_NV;
2244 object->texture_bpp = 12;
2245 object->texture_format = GL_RGB;
2246 object->texture_type = GL_FLOAT;
2247 break;
2248 case WGL_TEXTURE_FLOAT_RGBA_NV:
2249 object->use_render_texture = GL_FLOAT_RGBA_NV;
2250 object->texture_bpp = 16;
2251 object->texture_format = GL_RGBA;
2252 object->texture_type = GL_FLOAT;
2253 break;
2254 default:
2255 ERR("Unknown texture format: %x\n", attr_v);
2256 SetLastError(ERROR_INVALID_DATA);
2257 goto create_failed;
2260 break;
2263 case WGL_TEXTURE_TARGET_ARB: {
2264 ++piAttribList;
2265 attr_v = *piAttribList;
2266 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2267 if (WGL_NO_TEXTURE_ARB == attr_v) {
2268 object->texture_target = 0;
2269 } else {
2270 if (!use_render_texture_emulation) {
2271 SetLastError(ERROR_INVALID_DATA);
2272 goto create_failed;
2274 switch (attr_v) {
2275 case WGL_TEXTURE_CUBE_MAP_ARB: {
2276 if (iWidth != iHeight) {
2277 SetLastError(ERROR_INVALID_DATA);
2278 goto create_failed;
2280 object->texture_target = GL_TEXTURE_CUBE_MAP;
2281 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2282 break;
2284 case WGL_TEXTURE_1D_ARB: {
2285 if (1 != iHeight) {
2286 SetLastError(ERROR_INVALID_DATA);
2287 goto create_failed;
2289 object->texture_target = GL_TEXTURE_1D;
2290 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2291 break;
2293 case WGL_TEXTURE_2D_ARB: {
2294 object->texture_target = GL_TEXTURE_2D;
2295 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2296 break;
2298 case WGL_TEXTURE_RECTANGLE_NV: {
2299 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2300 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2301 break;
2303 default:
2304 ERR("Unknown texture target: %x\n", attr_v);
2305 SetLastError(ERROR_INVALID_DATA);
2306 goto create_failed;
2309 break;
2312 case WGL_MIPMAP_TEXTURE_ARB: {
2313 ++piAttribList;
2314 attr_v = *piAttribList;
2315 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2316 if (!use_render_texture_emulation) {
2317 SetLastError(ERROR_INVALID_DATA);
2318 goto create_failed;
2320 break;
2323 ++piAttribList;
2326 PUSH1(attribs, None);
2327 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2328 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2329 if (!object->drawable) {
2330 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2331 goto create_failed; /* unexpected error */
2333 EnterCriticalSection( &context_section );
2334 list_add_head( &pbuffer_list, &object->entry );
2335 LeaveCriticalSection( &context_section );
2336 TRACE("->(%p)\n", object);
2337 return object;
2339 create_failed:
2340 HeapFree(GetProcessHeap(), 0, object);
2341 TRACE("->(FAILED)\n");
2342 return NULL;
2346 * X11DRV_wglDestroyPbufferARB
2348 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2350 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
2352 TRACE("(%p)\n", object);
2354 EnterCriticalSection( &context_section );
2355 list_remove( &object->entry );
2356 LeaveCriticalSection( &context_section );
2357 pglXDestroyPbuffer(gdi_display, object->drawable);
2358 if (object->tmp_context)
2359 pglXDestroyContext(gdi_display, object->tmp_context);
2360 HeapFree(GetProcessHeap(), 0, object);
2361 return GL_TRUE;
2365 * X11DRV_wglGetPbufferDCARB
2367 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2369 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
2371 struct x11drv_escape_set_drawable escape;
2372 struct gl_drawable *gl, *prev;
2373 HDC hdc;
2375 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2376 if (!hdc) return 0;
2378 if (!(gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) )))
2380 DeleteDC( hdc );
2381 return 0;
2383 gl->type = DC_GL_PBUFFER;
2384 gl->drawable = object->drawable;
2385 gl->format = object->fmt;
2387 EnterCriticalSection( &context_section );
2388 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&prev ))
2389 free_gl_drawable( prev );
2390 XSaveContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char *)gl );
2391 LeaveCriticalSection( &context_section );
2393 escape.code = X11DRV_SET_DRAWABLE;
2394 escape.drawable = object->drawable;
2395 escape.mode = IncludeInferiors;
2396 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
2397 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2399 TRACE( "(%p)->(%p)\n", object, hdc );
2400 return hdc;
2404 * X11DRV_wglQueryPbufferARB
2406 * WGL_ARB_pbuffer: wglQueryPbufferARB
2408 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
2410 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
2412 switch (iAttribute) {
2413 case WGL_PBUFFER_WIDTH_ARB:
2414 pglXQueryDrawable(gdi_display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2415 break;
2416 case WGL_PBUFFER_HEIGHT_ARB:
2417 pglXQueryDrawable(gdi_display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2418 break;
2420 case WGL_PBUFFER_LOST_ARB:
2421 /* GLX Pbuffers cannot be lost by default. We can support this by
2422 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2423 * to receive pixel buffer clobber events, however that may or may
2424 * not give any benefit */
2425 *piValue = GL_FALSE;
2426 break;
2428 case WGL_TEXTURE_FORMAT_ARB:
2429 if (!object->use_render_texture) {
2430 *piValue = WGL_NO_TEXTURE_ARB;
2431 } else {
2432 if (!use_render_texture_emulation) {
2433 SetLastError(ERROR_INVALID_HANDLE);
2434 return GL_FALSE;
2436 switch(object->use_render_texture) {
2437 case GL_RGB:
2438 *piValue = WGL_TEXTURE_RGB_ARB;
2439 break;
2440 case GL_RGBA:
2441 *piValue = WGL_TEXTURE_RGBA_ARB;
2442 break;
2443 /* WGL_FLOAT_COMPONENTS_NV */
2444 case GL_FLOAT_R_NV:
2445 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2446 break;
2447 case GL_FLOAT_RG_NV:
2448 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2449 break;
2450 case GL_FLOAT_RGB_NV:
2451 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2452 break;
2453 case GL_FLOAT_RGBA_NV:
2454 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2455 break;
2456 default:
2457 ERR("Unknown texture format: %x\n", object->use_render_texture);
2460 break;
2462 case WGL_TEXTURE_TARGET_ARB:
2463 if (!object->texture_target){
2464 *piValue = WGL_NO_TEXTURE_ARB;
2465 } else {
2466 if (!use_render_texture_emulation) {
2467 SetLastError(ERROR_INVALID_DATA);
2468 return GL_FALSE;
2470 switch (object->texture_target) {
2471 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2472 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2473 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2474 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2477 break;
2479 case WGL_MIPMAP_TEXTURE_ARB:
2480 *piValue = GL_FALSE; /** don't support that */
2481 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2482 break;
2484 default:
2485 FIXME("unexpected attribute %x\n", iAttribute);
2486 break;
2489 return GL_TRUE;
2493 * X11DRV_wglReleasePbufferDCARB
2495 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2497 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2499 struct gl_drawable *gl;
2501 TRACE("(%p, %p)\n", object, hdc);
2503 EnterCriticalSection( &context_section );
2505 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
2507 XDeleteContext( gdi_display, (XID)hdc, gl_pbuffer_context );
2508 free_gl_drawable( gl );
2510 else hdc = 0;
2512 LeaveCriticalSection( &context_section );
2514 return hdc && DeleteDC(hdc);
2518 * X11DRV_wglSetPbufferAttribARB
2520 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2522 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2524 GLboolean ret = GL_FALSE;
2526 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2528 if (!object->use_render_texture) {
2529 SetLastError(ERROR_INVALID_HANDLE);
2530 return GL_FALSE;
2532 if (use_render_texture_emulation) {
2533 return GL_TRUE;
2535 return ret;
2539 * X11DRV_wglChoosePixelFormatARB
2541 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2543 static BOOL X11DRV_wglChoosePixelFormatARB( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
2544 UINT nMaxFormats, int *piFormats, UINT *nNumFormats )
2546 int attribs[256];
2547 int nAttribs = 0;
2548 GLXFBConfig* cfgs;
2549 int nCfgs = 0;
2550 int it;
2551 int fmt_id;
2552 int start, end;
2553 UINT pfmt_it = 0;
2554 int run;
2555 int i;
2556 DWORD dwFlags = 0;
2558 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2559 if (NULL != pfAttribFList) {
2560 FIXME("unused pfAttribFList\n");
2563 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2564 if (-1 == nAttribs) {
2565 WARN("Cannot convert WGL to GLX attributes\n");
2566 return GL_FALSE;
2568 PUSH1(attribs, None);
2570 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2571 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2572 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2574 for(i=0; piAttribIList[i] != 0; i+=2)
2576 switch(piAttribIList[i])
2578 case WGL_DRAW_TO_BITMAP_ARB:
2579 if(piAttribIList[i+1])
2580 dwFlags |= PFD_DRAW_TO_BITMAP;
2581 break;
2582 case WGL_ACCELERATION_ARB:
2583 switch(piAttribIList[i+1])
2585 case WGL_NO_ACCELERATION_ARB:
2586 dwFlags |= PFD_GENERIC_FORMAT;
2587 break;
2588 case WGL_GENERIC_ACCELERATION_ARB:
2589 dwFlags |= PFD_GENERIC_ACCELERATED;
2590 break;
2591 case WGL_FULL_ACCELERATION_ARB:
2592 /* Nothing to do */
2593 break;
2595 break;
2596 case WGL_SUPPORT_GDI_ARB:
2597 if(piAttribIList[i+1])
2598 dwFlags |= PFD_SUPPORT_GDI;
2599 break;
2603 /* Search for FB configurations matching the requirements in attribs */
2604 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2605 if (NULL == cfgs) {
2606 WARN("Compatible Pixel Format not found\n");
2607 return GL_FALSE;
2610 /* Loop through all matching formats and check if they are suitable.
2611 * Note that this function should at max return nMaxFormats different formats */
2612 for(run=0; run < 2; run++)
2614 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2616 if (pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id))
2618 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2619 continue;
2622 /* During the first run we only want onscreen formats and during the second only offscreen */
2623 start = run == 1 ? nb_onscreen_formats : 0;
2624 end = run == 1 ? nb_pixel_formats : nb_onscreen_formats;
2626 for (i = start; i < end; i++)
2628 if (pixel_formats[i].fmt_id == fmt_id && (pixel_formats[i].dwFlags & dwFlags) == dwFlags)
2630 piFormats[pfmt_it++] = i + 1;
2631 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2632 it + 1, nCfgs, fmt_id, i + 1);
2633 break;
2639 *nNumFormats = pfmt_it;
2640 /** free list */
2641 XFree(cfgs);
2642 return GL_TRUE;
2646 * X11DRV_wglGetPixelFormatAttribivARB
2648 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2650 static BOOL X11DRV_wglGetPixelFormatAttribivARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2651 UINT nAttributes, const int *piAttributes, int *piValues )
2653 UINT i;
2654 const struct wgl_pixel_format *fmt;
2655 int hTest;
2656 int tmp;
2657 int curGLXAttr = 0;
2659 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2661 if (0 < iLayerPlane) {
2662 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2663 return GL_FALSE;
2666 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2667 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2668 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2669 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2670 if(!fmt) {
2671 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2674 for (i = 0; i < nAttributes; ++i) {
2675 const int curWGLAttr = piAttributes[i];
2676 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2678 switch (curWGLAttr) {
2679 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2680 piValues[i] = nb_pixel_formats;
2681 continue;
2683 case WGL_SUPPORT_OPENGL_ARB:
2684 piValues[i] = GL_TRUE;
2685 continue;
2687 case WGL_ACCELERATION_ARB:
2688 curGLXAttr = GLX_CONFIG_CAVEAT;
2689 if (!fmt) goto pix_error;
2690 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2691 piValues[i] = WGL_NO_ACCELERATION_ARB;
2692 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2693 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2694 else
2695 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2696 continue;
2698 case WGL_TRANSPARENT_ARB:
2699 curGLXAttr = GLX_TRANSPARENT_TYPE;
2700 if (!fmt) goto pix_error;
2701 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2702 if (hTest) goto get_error;
2703 piValues[i] = GL_FALSE;
2704 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2705 continue;
2707 case WGL_PIXEL_TYPE_ARB:
2708 curGLXAttr = GLX_RENDER_TYPE;
2709 if (!fmt) goto pix_error;
2710 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2711 if (hTest) goto get_error;
2712 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2713 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2714 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2715 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2716 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2717 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2718 else {
2719 ERR("unexpected RenderType(%x)\n", tmp);
2720 piValues[i] = WGL_TYPE_RGBA_ARB;
2722 continue;
2724 case WGL_COLOR_BITS_ARB:
2725 curGLXAttr = GLX_BUFFER_SIZE;
2726 break;
2728 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2729 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2730 if (!use_render_texture_emulation) {
2731 piValues[i] = GL_FALSE;
2732 continue;
2734 curGLXAttr = GLX_RENDER_TYPE;
2735 if (!fmt) goto pix_error;
2736 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2737 if (hTest) goto get_error;
2738 if (GLX_COLOR_INDEX_BIT == tmp) {
2739 piValues[i] = GL_FALSE;
2740 continue;
2742 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2743 if (hTest) goto get_error;
2744 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2745 continue;
2747 case WGL_BLUE_BITS_ARB:
2748 curGLXAttr = GLX_BLUE_SIZE;
2749 break;
2750 case WGL_RED_BITS_ARB:
2751 curGLXAttr = GLX_RED_SIZE;
2752 break;
2753 case WGL_GREEN_BITS_ARB:
2754 curGLXAttr = GLX_GREEN_SIZE;
2755 break;
2756 case WGL_ALPHA_BITS_ARB:
2757 curGLXAttr = GLX_ALPHA_SIZE;
2758 break;
2759 case WGL_DEPTH_BITS_ARB:
2760 curGLXAttr = GLX_DEPTH_SIZE;
2761 break;
2762 case WGL_STENCIL_BITS_ARB:
2763 curGLXAttr = GLX_STENCIL_SIZE;
2764 break;
2765 case WGL_DOUBLE_BUFFER_ARB:
2766 curGLXAttr = GLX_DOUBLEBUFFER;
2767 break;
2768 case WGL_STEREO_ARB:
2769 curGLXAttr = GLX_STEREO;
2770 break;
2771 case WGL_AUX_BUFFERS_ARB:
2772 curGLXAttr = GLX_AUX_BUFFERS;
2773 break;
2775 case WGL_SUPPORT_GDI_ARB:
2776 if (!fmt) goto pix_error;
2777 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) != 0;
2778 continue;
2780 case WGL_DRAW_TO_BITMAP_ARB:
2781 if (!fmt) goto pix_error;
2782 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) != 0;
2783 continue;
2785 case WGL_DRAW_TO_WINDOW_ARB:
2786 case WGL_DRAW_TO_PBUFFER_ARB:
2787 if (!fmt) goto pix_error;
2788 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2789 if (hTest) goto get_error;
2790 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2791 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2792 piValues[i] = GL_TRUE;
2793 else
2794 piValues[i] = GL_FALSE;
2795 continue;
2797 case WGL_SWAP_METHOD_ARB:
2798 if (has_swap_method)
2800 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_SWAP_METHOD_OML, &tmp);
2801 if (hTest) goto get_error;
2802 switch (tmp)
2804 case GLX_SWAP_EXCHANGE_OML:
2805 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2806 break;
2807 case GLX_SWAP_COPY_OML:
2808 piValues[i] = WGL_SWAP_COPY_ARB;
2809 break;
2810 case GLX_SWAP_UNDEFINED_OML:
2811 piValues[i] = WGL_SWAP_UNDEFINED_ARB;
2812 break;
2813 default:
2814 ERR("Unexpected swap method %x.\n", tmp);
2817 else
2819 WARN("GLX_OML_swap_method not supported, returning WGL_SWAP_EXCHANGE_ARB.\n");
2820 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2822 continue;
2824 case WGL_PBUFFER_LARGEST_ARB:
2825 curGLXAttr = GLX_LARGEST_PBUFFER;
2826 break;
2828 case WGL_SAMPLE_BUFFERS_ARB:
2829 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2830 break;
2832 case WGL_SAMPLES_ARB:
2833 curGLXAttr = GLX_SAMPLES_ARB;
2834 break;
2836 case WGL_FLOAT_COMPONENTS_NV:
2837 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2838 break;
2840 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2841 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2842 break;
2844 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2845 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2846 break;
2848 case WGL_ACCUM_RED_BITS_ARB:
2849 curGLXAttr = GLX_ACCUM_RED_SIZE;
2850 break;
2851 case WGL_ACCUM_GREEN_BITS_ARB:
2852 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2853 break;
2854 case WGL_ACCUM_BLUE_BITS_ARB:
2855 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2856 break;
2857 case WGL_ACCUM_ALPHA_BITS_ARB:
2858 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2859 break;
2860 case WGL_ACCUM_BITS_ARB:
2861 if (!fmt) goto pix_error;
2862 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2863 if (hTest) goto get_error;
2864 piValues[i] = tmp;
2865 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2866 if (hTest) goto get_error;
2867 piValues[i] += tmp;
2868 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2869 if (hTest) goto get_error;
2870 piValues[i] += tmp;
2871 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2872 if (hTest) goto get_error;
2873 piValues[i] += tmp;
2874 continue;
2876 default:
2877 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2880 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2881 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2882 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2884 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2885 * and check which options can work using iPixelFormat=0 and which not.
2886 * A problem would be that this function is an extension. This would
2887 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2889 if (0 != curGLXAttr && iPixelFormat != 0) {
2890 if (!fmt) goto pix_error;
2891 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2892 if (hTest) goto get_error;
2893 curGLXAttr = 0;
2894 } else {
2895 piValues[i] = GL_FALSE;
2898 return GL_TRUE;
2900 get_error:
2901 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2902 return GL_FALSE;
2904 pix_error:
2905 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nb_pixel_formats);
2906 return GL_FALSE;
2910 * X11DRV_wglGetPixelFormatAttribfvARB
2912 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2914 static BOOL X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2915 UINT nAttributes, const int *piAttributes, FLOAT *pfValues )
2917 int *attr;
2918 int ret;
2919 UINT i;
2921 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2923 /* Allocate a temporary array to store integer values */
2924 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2925 if (!attr) {
2926 ERR("couldn't allocate %d array\n", nAttributes);
2927 return GL_FALSE;
2930 /* Piggy-back on wglGetPixelFormatAttribivARB */
2931 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2932 if (ret) {
2933 /* Convert integer values to float. Should also check for attributes
2934 that can give decimal values here */
2935 for (i=0; i<nAttributes;i++) {
2936 pfValues[i] = attr[i];
2940 HeapFree(GetProcessHeap(), 0, attr);
2941 return ret;
2945 * X11DRV_wglBindTexImageARB
2947 * WGL_ARB_render_texture: wglBindTexImageARB
2949 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2951 GLboolean ret = GL_FALSE;
2953 TRACE("(%p, %d)\n", object, iBuffer);
2955 if (!object->use_render_texture) {
2956 SetLastError(ERROR_INVALID_HANDLE);
2957 return GL_FALSE;
2960 if (use_render_texture_emulation) {
2961 static BOOL initialized = FALSE;
2962 int prev_binded_texture = 0;
2963 GLXContext prev_context;
2964 GLXDrawable prev_drawable;
2966 prev_context = pglXGetCurrentContext();
2967 prev_drawable = pglXGetCurrentDrawable();
2969 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2970 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2971 isn't ideal performance wise but I wasn't able to get other ways working.
2973 if(!initialized) {
2974 initialized = TRUE; /* Only show the FIXME once for performance reasons */
2975 FIXME("partial stub!\n");
2978 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2979 if (!object->tmp_context || object->prev_context != prev_context) {
2980 if (object->tmp_context)
2981 pglXDestroyContext(gdi_display, object->tmp_context);
2982 object->tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2983 object->prev_context = prev_context;
2986 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2988 /* Switch to our pbuffer */
2989 pglXMakeCurrent(gdi_display, object->drawable, object->tmp_context);
2991 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2992 * After that copy the pbuffer texture data. */
2993 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2994 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2996 /* Switch back to the original drawable and context */
2997 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2998 return GL_TRUE;
3001 return ret;
3005 * X11DRV_wglReleaseTexImageARB
3007 * WGL_ARB_render_texture: wglReleaseTexImageARB
3009 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
3011 GLboolean ret = GL_FALSE;
3013 TRACE("(%p, %d)\n", object, iBuffer);
3015 if (!object->use_render_texture) {
3016 SetLastError(ERROR_INVALID_HANDLE);
3017 return GL_FALSE;
3019 if (use_render_texture_emulation) {
3020 return GL_TRUE;
3022 return ret;
3026 * X11DRV_wglGetExtensionsStringEXT
3028 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3030 static const char *X11DRV_wglGetExtensionsStringEXT(void)
3032 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3033 return WineGLInfo.wglExtensions;
3037 * X11DRV_wglGetSwapIntervalEXT
3039 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3041 static int X11DRV_wglGetSwapIntervalEXT(void)
3043 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3044 struct gl_drawable *gl;
3045 int swap_interval;
3047 TRACE("()\n");
3049 if (!(gl = get_gl_drawable( WindowFromDC( ctx->hdc ), ctx->hdc )))
3051 /* This can't happen because a current WGL context is required to get
3052 * here. Likely the application is buggy.
3054 WARN("No GL drawable found, returning swap interval 0\n");
3055 return 0;
3058 swap_interval = gl->swap_interval;
3059 release_gl_drawable(gl);
3061 return swap_interval;
3065 * X11DRV_wglSwapIntervalEXT
3067 * WGL_EXT_swap_control: wglSwapIntervalEXT
3069 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
3071 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3072 struct gl_drawable *gl;
3073 BOOL ret;
3075 TRACE("(%d)\n", interval);
3077 /* Without WGL/GLX_EXT_swap_control_tear a negative interval
3078 * is invalid.
3080 if (interval < 0 && !has_swap_control_tear)
3082 SetLastError(ERROR_INVALID_DATA);
3083 return FALSE;
3086 if (!(gl = get_gl_drawable( WindowFromDC( ctx->hdc ), ctx->hdc )))
3088 SetLastError(ERROR_DC_NOT_FOUND);
3089 return FALSE;
3092 ret = set_swap_interval(gl->drawable, interval);
3093 gl->refresh_swap_interval = FALSE;
3094 if (ret)
3095 gl->swap_interval = interval;
3096 else
3097 SetLastError(ERROR_DC_NOT_FOUND);
3099 release_gl_drawable(gl);
3101 return ret;
3105 * X11DRV_wglSetPixelFormatWINE
3107 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3108 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3110 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
3112 return set_pixel_format(hdc, format, TRUE);
3115 static BOOL X11DRV_wglQueryCurrentRendererIntegerWINE( GLenum attribute, GLuint *value )
3117 return pglXQueryCurrentRendererIntegerMESA( attribute, value );
3120 static const char *X11DRV_wglQueryCurrentRendererStringWINE( GLenum attribute )
3122 return pglXQueryCurrentRendererStringMESA( attribute );
3125 static BOOL X11DRV_wglQueryRendererIntegerWINE( HDC dc, GLint renderer, GLenum attribute, GLuint *value )
3127 return pglXQueryRendererIntegerMESA( gdi_display, DefaultScreen(gdi_display), renderer, attribute, value );
3130 static const char *X11DRV_wglQueryRendererStringWINE( HDC dc, GLint renderer, GLenum attribute )
3132 return pglXQueryRendererStringMESA( gdi_display, DefaultScreen(gdi_display), renderer, attribute );
3136 * glxRequireVersion (internal)
3138 * Check if the supported GLX version matches requiredVersion.
3140 static BOOL glxRequireVersion(int requiredVersion)
3142 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3143 if(requiredVersion <= WineGLInfo.glxVersion[1])
3144 return TRUE;
3146 return FALSE;
3149 static void register_extension(const char *ext)
3151 if (WineGLInfo.wglExtensions[0])
3152 strcat(WineGLInfo.wglExtensions, " ");
3153 strcat(WineGLInfo.wglExtensions, ext);
3155 TRACE("'%s'\n", ext);
3159 * X11DRV_WineGL_LoadExtensions
3161 static void X11DRV_WineGL_LoadExtensions(void)
3163 WineGLInfo.wglExtensions[0] = 0;
3165 /* ARB Extensions */
3167 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context"))
3169 register_extension( "WGL_ARB_create_context" );
3170 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
3172 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context_profile"))
3173 register_extension("WGL_ARB_create_context_profile");
3176 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_fbconfig_float"))
3178 register_extension("WGL_ARB_pixel_format_float");
3179 register_extension("WGL_ATI_pixel_format_float");
3182 register_extension( "WGL_ARB_extensions_string" );
3183 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
3185 if (glxRequireVersion(3))
3187 register_extension( "WGL_ARB_make_current_read" );
3188 opengl_funcs.ext.p_wglGetCurrentReadDCARB = (void *)1; /* never called */
3189 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
3192 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
3194 if (glxRequireVersion(3))
3196 register_extension( "WGL_ARB_pbuffer" );
3197 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
3198 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
3199 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
3200 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
3201 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
3202 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
3205 register_extension( "WGL_ARB_pixel_format" );
3206 opengl_funcs.ext.p_wglChoosePixelFormatARB = X11DRV_wglChoosePixelFormatARB;
3207 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = X11DRV_wglGetPixelFormatAttribfvARB;
3208 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = X11DRV_wglGetPixelFormatAttribivARB;
3210 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3211 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_render_texture") ||
3212 (glxRequireVersion(3) && use_render_texture_emulation))
3214 register_extension( "WGL_ARB_render_texture" );
3215 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
3216 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
3218 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3219 if (has_extension( WineGLInfo.glxExtensions, "GLX_NV_float_buffer"))
3220 register_extension("WGL_NV_float_buffer");
3222 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3223 if (has_extension(WineGLInfo.glExtensions, "GL_NV_texture_rectangle"))
3224 register_extension("WGL_NV_render_texture_rectangle");
3227 /* EXT Extensions */
3229 register_extension( "WGL_EXT_extensions_string" );
3230 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
3232 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3233 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3234 register_extension( "WGL_EXT_swap_control" );
3235 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
3236 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
3238 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_framebuffer_sRGB"))
3239 register_extension("WGL_EXT_framebuffer_sRGB");
3241 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_fbconfig_packed_float"))
3242 register_extension("WGL_EXT_pixel_format_packed_float");
3244 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_swap_control"))
3246 swap_control_method = GLX_SWAP_CONTROL_EXT;
3247 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_swap_control_tear"))
3249 register_extension("WGL_EXT_swap_control_tear");
3250 has_swap_control_tear = TRUE;
3253 else if (has_extension( WineGLInfo.glxExtensions, "GLX_MESA_swap_control"))
3255 swap_control_method = GLX_SWAP_CONTROL_MESA;
3257 else if (has_extension( WineGLInfo.glxExtensions, "GLX_SGI_swap_control"))
3259 swap_control_method = GLX_SWAP_CONTROL_SGI;
3262 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3263 if (has_extension(WineGLInfo.glExtensions, "GL_NV_vertex_array_range"))
3265 register_extension( "WGL_NV_vertex_array_range" );
3266 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
3267 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
3270 if (has_extension(WineGLInfo.glxExtensions, "GLX_OML_swap_method"))
3271 has_swap_method = TRUE;
3273 /* WINE-specific WGL Extensions */
3275 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3276 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3278 register_extension( "WGL_WINE_pixel_format_passthrough" );
3279 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
3281 if (has_extension( WineGLInfo.glxExtensions, "GLX_MESA_query_renderer" ))
3283 register_extension( "WGL_WINE_query_renderer" );
3284 opengl_funcs.ext.p_wglQueryCurrentRendererIntegerWINE = X11DRV_wglQueryCurrentRendererIntegerWINE;
3285 opengl_funcs.ext.p_wglQueryCurrentRendererStringWINE = X11DRV_wglQueryCurrentRendererStringWINE;
3286 opengl_funcs.ext.p_wglQueryRendererIntegerWINE = X11DRV_wglQueryRendererIntegerWINE;
3287 opengl_funcs.ext.p_wglQueryRendererStringWINE = X11DRV_wglQueryRendererStringWINE;
3293 * glxdrv_SwapBuffers
3295 * Swap the buffers of this DC
3297 static BOOL glxdrv_wglSwapBuffers( HDC hdc )
3299 struct x11drv_escape_flush_gl_drawable escape;
3300 struct gl_drawable *gl;
3301 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3303 TRACE("(%p)\n", hdc);
3305 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
3306 escape.gl_drawable = 0;
3308 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
3310 SetLastError( ERROR_INVALID_HANDLE );
3311 return FALSE;
3314 if (gl->refresh_swap_interval)
3316 set_swap_interval(gl->drawable, gl->swap_interval);
3317 gl->refresh_swap_interval = FALSE;
3320 switch (gl->type)
3322 case DC_GL_PIXMAP_WIN:
3323 if (ctx) sync_context( ctx );
3324 escape.gl_drawable = gl->pixmap;
3325 if (pglXCopySubBufferMESA) {
3326 /* (glX)SwapBuffers has an implicit glFlush effect, however
3327 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3328 * copying */
3329 pglFlush();
3330 pglXCopySubBufferMESA( gdi_display, gl->drawable, 0, 0,
3331 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top );
3332 break;
3334 pglXSwapBuffers(gdi_display, gl->drawable);
3335 break;
3336 case DC_GL_CHILD_WIN:
3337 if (ctx) sync_context( ctx );
3338 escape.gl_drawable = gl->window;
3339 /* fall through */
3340 default:
3341 pglXSwapBuffers(gdi_display, gl->drawable);
3342 break;
3345 release_gl_drawable( gl );
3347 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
3348 return TRUE;
3351 static struct opengl_funcs opengl_funcs =
3354 glxdrv_wglCopyContext, /* p_wglCopyContext */
3355 glxdrv_wglCreateContext, /* p_wglCreateContext */
3356 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3357 glxdrv_wglDescribePixelFormat, /* p_wglDescribePixelFormat */
3358 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
3359 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3360 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3361 glxdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */
3362 glxdrv_wglShareLists, /* p_wglShareLists */
3363 glxdrv_wglSwapBuffers, /* p_wglSwapBuffers */
3367 struct opengl_funcs *get_glx_driver( UINT version )
3369 if (version != WINE_WGL_DRIVER_VERSION)
3371 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
3372 return NULL;
3374 if (has_opengl()) return &opengl_funcs;
3375 return NULL;
3378 #else /* no OpenGL includes */
3380 struct opengl_funcs *get_glx_driver( UINT version )
3382 return NULL;
3385 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
3389 void set_gl_drawable_parent( HWND hwnd, HWND parent )
3393 void destroy_gl_drawable( HWND hwnd )
3397 #endif /* defined(SONAME_LIBGL) */