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
27 #include "wine/port.h"
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
41 #include "xcomposite.h"
43 #include "wine/library.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
50 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
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
;
66 #define GLX_BUFFER_SIZE 2
69 #define GLX_DOUBLEBUFFER 5
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
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
182 const char *glVersion
;
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
;
198 char wglExtensions
[4096];
201 struct wgl_pixel_format
203 GLXFBConfig fbconfig
;
206 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
212 BOOL has_been_current
;
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 */
220 Drawable drawables
[2];
221 BOOL refresh_drawables
;
228 const struct wgl_pixel_format
* fmt
;
232 int use_render_texture
; /* This is also the internal texture format */
233 int texture_bind_target
;
235 GLint texture_format
;
236 GLuint texture_target
;
240 GLXContext tmp_context
;
241 GLXContext prev_context
;
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 */
256 enum dc_gl_type type
; /* type of GL surface */
257 Drawable drawable
; /* drawable for rendering to the client area */
258 Pixmap pixmap
; /* base pixmap if drawable is a GLXPixmap */
259 Colormap colormap
; /* colormap used for the drawable */
260 const struct wgl_pixel_format
*format
; /* pixel format for the drawable */
261 XVisualInfo
*visual
; /* information about the GL visual */
262 RECT rect
; /* drawable rect, relative to whole window drawable */
264 BOOL refresh_swap_interval
;
267 enum glx_swap_control_method
269 GLX_SWAP_CONTROL_NONE
,
270 GLX_SWAP_CONTROL_EXT
,
271 GLX_SWAP_CONTROL_SGI
,
272 GLX_SWAP_CONTROL_MESA
275 /* X context to associate a struct gl_drawable to an hwnd */
276 static XContext gl_hwnd_context
;
277 /* X context to associate a struct gl_drawable to a pbuffer hdc */
278 static XContext gl_pbuffer_context
;
280 static struct list context_list
= LIST_INIT( context_list
);
281 static struct list pbuffer_list
= LIST_INIT( pbuffer_list
);
282 static struct WineGLInfo WineGLInfo
= { 0 };
283 static struct wgl_pixel_format
*pixel_formats
;
284 static int nb_pixel_formats
, nb_onscreen_formats
;
285 static BOOL use_render_texture_emulation
= TRUE
;
287 /* Selects the preferred GLX swap control method for use by wglSwapIntervalEXT */
288 static enum glx_swap_control_method swap_control_method
= GLX_SWAP_CONTROL_NONE
;
289 /* Set when GLX_EXT_swap_control_tear is supported, requires GLX_SWAP_CONTROL_EXT */
290 static BOOL has_swap_control_tear
= FALSE
;
291 static BOOL has_swap_method
= FALSE
;
293 static CRITICAL_SECTION context_section
;
294 static CRITICAL_SECTION_DEBUG critsect_debug
=
296 0, 0, &context_section
,
297 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
298 0, 0, { (DWORD_PTR
)(__FILE__
": context_section") }
300 static CRITICAL_SECTION context_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
302 static const BOOL is_win64
= sizeof(void *) > sizeof(int);
304 static struct opengl_funcs opengl_funcs
;
306 #define USE_GL_FUNC(name) #name,
307 static const char *opengl_func_names
[] = { ALL_WGL_FUNCS
};
310 static void X11DRV_WineGL_LoadExtensions(void);
311 static void init_pixel_formats( Display
*display
);
312 static BOOL
glxRequireVersion(int requiredVersion
);
314 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
315 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
316 TRACE(" - dwFlags : ");
317 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
318 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
319 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
320 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
321 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
322 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
323 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
324 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
325 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
326 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
327 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
328 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
329 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
330 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
331 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
332 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
333 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
334 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
335 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
336 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
340 TRACE(" - iPixelType : ");
341 switch (ppfd
->iPixelType
) {
342 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
343 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
347 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
348 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
349 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
350 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
351 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
352 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
353 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
354 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
355 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
357 TRACE(" - iLayerType : ");
358 switch (ppfd
->iLayerType
) {
359 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
360 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
361 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
366 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
367 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
370 static XVisualInfo
* (*pglXChooseVisual
)( Display
*dpy
, int screen
, int *attribList
);
371 static GLXContext (*pglXCreateContext
)( Display
*dpy
, XVisualInfo
*vis
, GLXContext shareList
, Bool direct
);
372 static void (*pglXDestroyContext
)( Display
*dpy
, GLXContext ctx
);
373 static Bool (*pglXMakeCurrent
)( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
);
374 static void (*pglXCopyContext
)( Display
*dpy
, GLXContext src
, GLXContext dst
, unsigned long mask
);
375 static void (*pglXSwapBuffers
)( Display
*dpy
, GLXDrawable drawable
);
376 static GLXPixmap (*pglXCreateGLXPixmap
)( Display
*dpy
, XVisualInfo
*visual
, Pixmap pixmap
);
377 static void (*pglXDestroyGLXPixmap
)( Display
*dpy
, GLXPixmap pixmap
);
378 static Bool (*pglXQueryExtension
)( Display
*dpy
, int *errorb
, int *event
);
379 static Bool (*pglXQueryVersion
)( Display
*dpy
, int *maj
, int *min
);
380 static Bool (*pglXIsDirect
)( Display
*dpy
, GLXContext ctx
);
381 static int (*pglXGetConfig
)( Display
*dpy
, XVisualInfo
*visual
, int attrib
, int *value
);
382 static GLXContext (*pglXGetCurrentContext
)( void );
383 static GLXDrawable (*pglXGetCurrentDrawable
)( void );
386 static const char *(*pglXQueryExtensionsString
)( Display
*dpy
, int screen
);
387 static const char *(*pglXQueryServerString
)( Display
*dpy
, int screen
, int name
);
388 static const char *(*pglXGetClientString
)( Display
*dpy
, int name
);
391 static GLXFBConfig
*(*pglXChooseFBConfig
)( Display
*dpy
, int screen
, const int *attribList
, int *nitems
);
392 static int (*pglXGetFBConfigAttrib
)( Display
*dpy
, GLXFBConfig config
, int attribute
, int *value
);
393 static GLXFBConfig
*(*pglXGetFBConfigs
)( Display
*dpy
, int screen
, int *nelements
);
394 static XVisualInfo
*(*pglXGetVisualFromFBConfig
)( Display
*dpy
, GLXFBConfig config
);
395 static GLXPbuffer (*pglXCreatePbuffer
)( Display
*dpy
, GLXFBConfig config
, const int *attribList
);
396 static void (*pglXDestroyPbuffer
)( Display
*dpy
, GLXPbuffer pbuf
);
397 static void (*pglXQueryDrawable
)( Display
*dpy
, GLXDrawable draw
, int attribute
, unsigned int *value
);
398 static GLXContext (*pglXCreateNewContext
)( Display
*dpy
, GLXFBConfig config
, int renderType
, GLXContext shareList
, Bool direct
);
399 static Bool (*pglXMakeContextCurrent
)( Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
);
402 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
403 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
404 static void (*pglXSwapIntervalEXT
)(Display
*dpy
, GLXDrawable drawable
, int interval
);
405 static int (*pglXSwapIntervalSGI
)(int);
407 /* NV GLX Extension */
408 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
409 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
411 /* MESA GLX Extensions */
412 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
413 static int (*pglXSwapIntervalMESA
)(unsigned int interval
);
414 static Bool (*pglXQueryCurrentRendererIntegerMESA
)(int attribute
, unsigned int *value
);
415 static const char *(*pglXQueryCurrentRendererStringMESA
)(int attribute
);
416 static Bool (*pglXQueryRendererIntegerMESA
)(Display
*dpy
, int screen
, int renderer
, int attribute
, unsigned int *value
);
417 static const char *(*pglXQueryRendererStringMESA
)(Display
*dpy
, int screen
, int renderer
, int attribute
);
419 /* Standard OpenGL */
420 static void (*pglFinish
)(void);
421 static void (*pglFlush
)(void);
422 static const GLubyte
*(*pglGetString
)(GLenum name
);
424 static void wglFinish(void);
425 static void wglFlush(void);
426 static const GLubyte
*wglGetString(GLenum name
);
428 /* check if the extension is present in the list */
429 static BOOL
has_extension( const char *list
, const char *ext
)
431 size_t len
= strlen( ext
);
435 while (*list
== ' ') list
++;
436 if (!strncmp( list
, ext
, len
) && (!list
[len
] || list
[len
] == ' ')) return TRUE
;
437 list
= strchr( list
, ' ' );
442 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
444 /* In the future we might want to find the exact X or GLX error to report back to the app */
448 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
450 static const char legacy_extensions
[] = " WGL_EXT_extensions_string WGL_EXT_swap_control";
452 int screen
= DefaultScreen(gdi_display
);
453 Window win
= 0, root
= 0;
454 const char *gl_renderer
;
457 GLXContext ctx
= NULL
;
458 XSetWindowAttributes attr
;
460 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
462 attr
.override_redirect
= True
;
463 attr
.colormap
= None
;
464 attr
.border_pixel
= 0;
466 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
469 WORD old_fs
= wine_get_fs();
470 /* Create a GLX Context. Without one we can't query GL information */
471 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
472 if (wine_get_fs() != old_fs
)
474 wine_set_fs( old_fs
);
475 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
476 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
480 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
485 root
= RootWindow( gdi_display
, vis
->screen
);
486 if (vis
->visual
!= DefaultVisual( gdi_display
, vis
->screen
))
487 attr
.colormap
= XCreateColormap( gdi_display
, root
, vis
->visual
, AllocNone
);
488 if ((win
= XCreateWindow( gdi_display
, root
, -1, -1, 1, 1, 0, vis
->depth
, InputOutput
,
489 vis
->visual
, CWBorderPixel
| CWOverrideRedirect
| CWColormap
, &attr
)))
490 XMapWindow( gdi_display
, win
);
494 if(pglXMakeCurrent(gdi_display
, win
, ctx
) == 0)
496 ERR_(winediag
)( "Unable to activate OpenGL context, most likely your %s OpenGL drivers haven't been "
497 "installed correctly\n", is_win64
? "64-bit" : "32-bit" );
500 gl_renderer
= (const char *)opengl_funcs
.gl
.p_glGetString(GL_RENDERER
);
501 WineGLInfo
.glVersion
= (const char *) opengl_funcs
.gl
.p_glGetString(GL_VERSION
);
502 str
= (const char *) opengl_funcs
.gl
.p_glGetString(GL_EXTENSIONS
);
503 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+sizeof(legacy_extensions
));
504 strcpy(WineGLInfo
.glExtensions
, str
);
505 strcat(WineGLInfo
.glExtensions
, legacy_extensions
);
507 /* Get the common GLX version supported by GLX client and server ( major/minor) */
508 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
510 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
511 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
512 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
514 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
515 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
516 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
518 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
519 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
521 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
522 TRACE("GL renderer : %s.\n", gl_renderer
);
523 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
524 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
525 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
526 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
527 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
528 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
530 if(!WineGLInfo
.glxDirect
)
532 int fd
= ConnectionNumber(gdi_display
);
533 struct sockaddr_un uaddr
;
534 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
536 /* In general indirect rendering on a local X11 server indicates a driver problem.
537 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
539 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
540 ERR_(winediag
)("Direct rendering is disabled, most likely your %s OpenGL drivers "
541 "haven't been installed correctly (using GL renderer %s, version %s).\n",
542 is_win64
? "64-bit" : "32-bit", debugstr_a(gl_renderer
),
543 debugstr_a(WineGLInfo
.glVersion
));
547 /* In general you would expect that if direct rendering is returned, that you receive hardware
548 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
549 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
550 * software rendering, it shows direct rendering.
552 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
553 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
554 * it shows 'Mesa X11'.
556 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
557 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your %s OpenGL "
558 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
559 is_win64
? "64-bit" : "32-bit", debugstr_a(gl_renderer
),
560 debugstr_a(WineGLInfo
.glVersion
));
567 pglXMakeCurrent(gdi_display
, None
, NULL
);
568 pglXDestroyContext(gdi_display
, ctx
);
570 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
571 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
572 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
576 static void *opengl_handle
;
578 static BOOL WINAPI
init_opengl( INIT_ONCE
*once
, void *param
, void **context
)
581 int error_base
, event_base
;
584 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
585 and include all dependencies */
586 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
587 if (opengl_handle
== NULL
)
589 ERR( "Failed to load libGL: %s\n", buffer
);
590 ERR( "OpenGL support is disabled.\n");
594 for (i
= 0; i
< sizeof(opengl_func_names
)/sizeof(opengl_func_names
[0]); i
++)
596 if (!(((void **)&opengl_funcs
.gl
)[i
] = wine_dlsym( opengl_handle
, opengl_func_names
[i
], NULL
, 0 )))
598 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names
[i
] );
603 /* redirect some standard OpenGL functions */
604 #define REDIRECT(func) \
605 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
606 REDIRECT( glFinish
);
608 REDIRECT( glGetString
);
611 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
612 if (pglXGetProcAddressARB
== NULL
) {
613 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
617 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
619 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
624 LOAD_FUNCPTR(glXChooseVisual
);
625 LOAD_FUNCPTR(glXCopyContext
);
626 LOAD_FUNCPTR(glXCreateContext
);
627 LOAD_FUNCPTR(glXCreateGLXPixmap
);
628 LOAD_FUNCPTR(glXGetCurrentContext
);
629 LOAD_FUNCPTR(glXGetCurrentDrawable
);
630 LOAD_FUNCPTR(glXDestroyContext
);
631 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
632 LOAD_FUNCPTR(glXGetConfig
);
633 LOAD_FUNCPTR(glXIsDirect
);
634 LOAD_FUNCPTR(glXMakeCurrent
);
635 LOAD_FUNCPTR(glXSwapBuffers
);
636 LOAD_FUNCPTR(glXQueryExtension
);
637 LOAD_FUNCPTR(glXQueryVersion
);
640 LOAD_FUNCPTR(glXGetClientString
);
641 LOAD_FUNCPTR(glXQueryExtensionsString
);
642 LOAD_FUNCPTR(glXQueryServerString
);
645 LOAD_FUNCPTR(glXCreatePbuffer
);
646 LOAD_FUNCPTR(glXCreateNewContext
);
647 LOAD_FUNCPTR(glXDestroyPbuffer
);
648 LOAD_FUNCPTR(glXMakeContextCurrent
);
649 LOAD_FUNCPTR(glXGetFBConfigs
);
652 /* It doesn't matter if these fail. They'll only be used if the driver reports
653 the associated extension is available (and if a driver reports the extension
654 is available but fails to provide the functions, it's quite broken) */
655 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
656 /* ARB GLX Extension */
657 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
658 /* EXT GLX Extension */
659 LOAD_FUNCPTR(glXSwapIntervalEXT
);
660 /* MESA GLX Extension */
661 LOAD_FUNCPTR(glXSwapIntervalMESA
);
662 /* SGI GLX Extension */
663 LOAD_FUNCPTR(glXSwapIntervalSGI
);
664 /* NV GLX Extension */
665 LOAD_FUNCPTR(glXAllocateMemoryNV
);
666 LOAD_FUNCPTR(glXFreeMemoryNV
);
669 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
671 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
672 TRACE("GLX is up and running error_base = %d\n", error_base
);
674 ERR( "GLX extension is missing, disabling OpenGL.\n" );
677 gl_hwnd_context
= XUniqueContext();
678 gl_pbuffer_context
= XUniqueContext();
680 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
681 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
684 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
685 * depends on the reported GLX client / server version and on the client / server extension list.
686 * Those don't have to be the same.
688 * In general the server GLX information lists the capabilities in case of indirect rendering.
689 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
690 * available and in that case the client GLX informat can be used.
691 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
692 * in the GLX version/extension list. When a program does this it works for certain for both
693 * direct and indirect rendering.
695 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
696 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
697 * extension list which causes this extension not to be listed. (Wine requires this extension).
698 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
699 * pbuffers is around.
701 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
702 * the ATI drivers and from then on use GLX client information for them.
705 if(glxRequireVersion(3)) {
706 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
707 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
708 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
709 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
710 } else if (has_extension( WineGLInfo
.glxExtensions
, "GLX_SGIX_fbconfig")) {
711 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
712 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
713 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
715 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
716 * enable this function when the Xserver understand GLX 1.3 or newer
718 pglXQueryDrawable
= NULL
;
719 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
720 TRACE("Overriding ATI GLX capabilities!\n");
721 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
722 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
723 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
724 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
726 /* Use client GLX information in case of the ATI drivers. We override the
727 * capabilities over here and not somewhere else as ATI might better their
728 * life in the future. In case they release proper drivers this block of
729 * code won't be called. */
730 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
732 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
735 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_MESA_copy_sub_buffer")) {
736 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
739 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_MESA_query_renderer" ))
741 pglXQueryCurrentRendererIntegerMESA
= pglXGetProcAddressARB(
742 (const GLubyte
*)"glXQueryCurrentRendererIntegerMESA" );
743 pglXQueryCurrentRendererStringMESA
= pglXGetProcAddressARB(
744 (const GLubyte
*)"glXQueryCurrentRendererStringMESA" );
745 pglXQueryRendererIntegerMESA
= pglXGetProcAddressARB( (const GLubyte
*)"glXQueryRendererIntegerMESA" );
746 pglXQueryRendererStringMESA
= pglXGetProcAddressARB( (const GLubyte
*)"glXQueryRendererStringMESA" );
749 X11DRV_WineGL_LoadExtensions();
750 init_pixel_formats( gdi_display
);
754 wine_dlclose(opengl_handle
, NULL
, 0);
755 opengl_handle
= NULL
;
759 static BOOL
has_opengl(void)
761 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
762 InitOnceExecuteOnce(&init_once
, init_opengl
, NULL
, NULL
);
763 return opengl_handle
!= NULL
;
766 static const char *debugstr_fbconfig( GLXFBConfig fbconfig
)
768 int id
, visual
, drawable
;
770 if (pglXGetFBConfigAttrib( gdi_display
, fbconfig
, GLX_FBCONFIG_ID
, &id
))
771 return "*** invalid fbconfig";
772 pglXGetFBConfigAttrib( gdi_display
, fbconfig
, GLX_VISUAL_ID
, &visual
);
773 pglXGetFBConfigAttrib( gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &drawable
);
774 return wine_dbg_sprintf( "fbconfig %#x visual id %#x drawable type %#x", id
, visual
, drawable
);
777 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, struct wgl_pbuffer
* pbuf
) {
782 int nvfloatattrib
= GLX_DONT_CARE
;
783 int pixelattrib
= GLX_DONT_CARE
;
785 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
786 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
787 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
788 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
790 switch (iWGLAttr
[cur
]) {
791 case WGL_AUX_BUFFERS_ARB
:
792 pop
= iWGLAttr
[++cur
];
793 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
794 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
796 case WGL_COLOR_BITS_ARB
:
797 pop
= iWGLAttr
[++cur
];
798 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
799 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
801 case WGL_BLUE_BITS_ARB
:
802 pop
= iWGLAttr
[++cur
];
803 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
804 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
806 case WGL_RED_BITS_ARB
:
807 pop
= iWGLAttr
[++cur
];
808 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
809 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
811 case WGL_GREEN_BITS_ARB
:
812 pop
= iWGLAttr
[++cur
];
813 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
814 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
816 case WGL_ALPHA_BITS_ARB
:
817 pop
= iWGLAttr
[++cur
];
818 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
819 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
821 case WGL_DEPTH_BITS_ARB
:
822 pop
= iWGLAttr
[++cur
];
823 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
824 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
826 case WGL_STENCIL_BITS_ARB
:
827 pop
= iWGLAttr
[++cur
];
828 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
829 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
831 case WGL_DOUBLE_BUFFER_ARB
:
832 pop
= iWGLAttr
[++cur
];
833 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
834 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
837 pop
= iWGLAttr
[++cur
];
838 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
839 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
842 case WGL_PIXEL_TYPE_ARB
:
843 pop
= iWGLAttr
[++cur
];
844 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
846 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
847 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
848 /* 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 */
849 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
850 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
852 ERR("unexpected PixelType(%x)\n", pop
);
857 case WGL_SUPPORT_GDI_ARB
:
858 /* This flag is set in a pixel format */
859 pop
= iWGLAttr
[++cur
];
860 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
863 case WGL_DRAW_TO_BITMAP_ARB
:
864 /* This flag is set in a pixel format */
865 pop
= iWGLAttr
[++cur
];
866 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
869 case WGL_DRAW_TO_WINDOW_ARB
:
870 pop
= iWGLAttr
[++cur
];
871 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
872 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
874 drawattrib
|= GLX_WINDOW_BIT
;
878 case WGL_DRAW_TO_PBUFFER_ARB
:
879 pop
= iWGLAttr
[++cur
];
880 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
881 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
883 drawattrib
|= GLX_PBUFFER_BIT
;
887 case WGL_ACCELERATION_ARB
:
888 /* This flag is set in a pixel format */
889 pop
= iWGLAttr
[++cur
];
890 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
893 case WGL_SUPPORT_OPENGL_ARB
:
894 pop
= iWGLAttr
[++cur
];
895 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
896 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
899 case WGL_SWAP_METHOD_ARB
:
900 pop
= iWGLAttr
[++cur
];
901 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
906 case WGL_SWAP_EXCHANGE_ARB
:
907 pop
= GLX_SWAP_EXCHANGE_OML
;
909 case WGL_SWAP_COPY_ARB
:
910 pop
= GLX_SWAP_COPY_OML
;
912 case WGL_SWAP_UNDEFINED_ARB
:
913 pop
= GLX_SWAP_UNDEFINED_OML
;
916 ERR("Unexpected swap method %#x.\n", pop
);
919 PUSH2(oGLXAttr
, GLX_SWAP_METHOD_OML
, pop
);
923 WARN("GLX_OML_swap_method not supported, ignoring attribute.\n");
927 case WGL_PBUFFER_LARGEST_ARB
:
928 pop
= iWGLAttr
[++cur
];
929 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
930 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
933 case WGL_SAMPLE_BUFFERS_ARB
:
934 pop
= iWGLAttr
[++cur
];
935 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
936 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
939 case WGL_SAMPLES_ARB
:
940 pop
= iWGLAttr
[++cur
];
941 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
942 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
945 case WGL_TEXTURE_FORMAT_ARB
:
946 case WGL_TEXTURE_TARGET_ARB
:
947 case WGL_MIPMAP_TEXTURE_ARB
:
948 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
949 pop
= iWGLAttr
[++cur
];
951 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
953 if (!use_render_texture_emulation
) {
954 if (WGL_NO_TEXTURE_ARB
!= pop
) {
955 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
956 return -1; /** error: don't support it */
958 drawattrib
|= GLX_PBUFFER_BIT
;
962 case WGL_FLOAT_COMPONENTS_NV
:
963 nvfloatattrib
= iWGLAttr
[++cur
];
964 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
966 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
967 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
968 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
969 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
970 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
971 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
972 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
973 pop
= iWGLAttr
[++cur
];
974 /** cannot be converted, see direct handling on
975 * - wglGetPixelFormatAttribivARB
976 * TODO: wglChoosePixelFormat
979 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
980 pop
= iWGLAttr
[++cur
];
981 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
982 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
985 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
986 pop
= iWGLAttr
[++cur
];
987 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
988 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
991 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
998 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
999 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
1000 * pixmap and pbuffer formats appear as well. */
1001 if (!drawattrib
) drawattrib
= GLX_DONT_CARE
;
1002 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
1003 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
1005 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
1006 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
1007 * GLX_DONT_CARE unless it is overridden. */
1008 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
1009 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
1011 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
1012 if (has_extension(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
1013 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
1014 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
1020 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
1022 int render_type
, render_type_bit
;
1023 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
1024 switch(render_type_bit
)
1027 render_type
= GLX_RGBA_TYPE
;
1029 case GLX_COLOR_INDEX_BIT
:
1030 render_type
= GLX_COLOR_INDEX_TYPE
;
1032 case GLX_RGBA_FLOAT_BIT
:
1033 render_type
= GLX_RGBA_FLOAT_TYPE
;
1035 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
1036 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
1039 ERR("Unknown render_type: %x\n", render_type_bit
);
1045 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
1046 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
1049 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
1050 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1052 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
1053 * the GLX_PIXMAP_BIT set. */
1054 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
1057 static void init_pixel_formats( Display
*display
)
1059 struct wgl_pixel_format
*list
;
1060 int size
= 0, onscreen_size
= 0;
1061 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
1063 XVisualInfo
*visinfo
;
1065 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
1066 if (NULL
== cfgs
|| 0 == nCfgs
) {
1067 if(cfgs
!= NULL
) XFree(cfgs
);
1068 ERR("glXChooseFBConfig returns NULL\n");
1072 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
1073 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
1074 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
1075 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
1077 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
1079 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
1081 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1084 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
1086 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
) * sizeof(*list
));
1088 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
1089 * Do this as GLX doesn't guarantee that the list is sorted */
1090 for(run
=0; run
< 2; run
++)
1092 for(i
=0; i
<nCfgs
; i
++) {
1093 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
1094 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
1096 /* The first run we only add onscreen formats (ones which have an associated X Visual).
1097 * The second run we only set offscreen formats. */
1100 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
1101 * The contents is copied to the destination using XCopyArea. For the copying to work
1102 * the depth of the source and destination window should be the same. In general this should
1103 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
1104 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
1105 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
1106 * list formats with the same depth. */
1107 if(visinfo
->depth
!= default_visual
.depth
)
1113 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1114 list
[size
].fbconfig
= cfgs
[i
];
1115 list
[size
].fmt_id
= fmt_id
;
1116 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1117 list
[size
].dwFlags
= 0;
1121 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1122 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1124 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1125 list
[size
].fbconfig
= cfgs
[i
];
1126 list
[size
].fmt_id
= fmt_id
;
1127 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1128 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
1132 } else if(run
&& !visinfo
) {
1133 int window_drawable
=0;
1134 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
1136 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1137 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1138 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1139 * likely make our child window opengl rendering more complicated since likely you can't use
1140 * XCopyArea on a GLX Window.
1141 * For now ignore fbconfigs which are window drawable but lack a visual. */
1142 if(window_drawable
& GLX_WINDOW_BIT
)
1144 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
1148 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1149 list
[size
].fbconfig
= cfgs
[i
];
1150 list
[size
].fmt_id
= fmt_id
;
1151 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1152 list
[size
].dwFlags
= 0;
1156 if (visinfo
) XFree(visinfo
);
1162 pixel_formats
= list
;
1163 nb_pixel_formats
= size
;
1164 nb_onscreen_formats
= onscreen_size
;
1167 static inline BOOL
is_valid_pixel_format( int format
)
1169 return format
> 0 && format
<= nb_pixel_formats
;
1172 static inline BOOL
is_onscreen_pixel_format( int format
)
1174 return format
> 0 && format
<= nb_onscreen_formats
;
1177 static inline int pixel_format_index( const struct wgl_pixel_format
*format
)
1179 return format
- pixel_formats
+ 1;
1182 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1183 * In our WGL implementation we only support a subset of these formats namely the format of
1184 * Wine's main visual and offscreen formats (if they are available).
1185 * This function converts a WGL format to its corresponding GLX one.
1187 static const struct wgl_pixel_format
*get_pixel_format(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
)
1189 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1190 * iPixelFormat in case of probing the number of pixelformats.
1192 if (is_valid_pixel_format( iPixelFormat
) &&
1193 (is_onscreen_pixel_format( iPixelFormat
) || AllowOffscreen
)) {
1194 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1195 pixel_formats
[iPixelFormat
-1].fmt_id
, iPixelFormat
);
1196 return &pixel_formats
[iPixelFormat
-1];
1201 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1202 static void mark_drawable_dirty(Drawable old
, Drawable
new)
1204 struct wgl_context
*ctx
;
1206 LIST_FOR_EACH_ENTRY( ctx
, &context_list
, struct wgl_context
, entry
)
1208 if (old
== ctx
->drawables
[0]) {
1209 ctx
->drawables
[0] = new;
1210 ctx
->refresh_drawables
= TRUE
;
1212 if (old
== ctx
->drawables
[1]) {
1213 ctx
->drawables
[1] = new;
1214 ctx
->refresh_drawables
= TRUE
;
1219 /* Given the current context, make sure its drawable is sync'd */
1220 static inline void sync_context(struct wgl_context
*context
)
1222 if (context
->refresh_drawables
) {
1223 if (glxRequireVersion(3))
1224 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1225 context
->drawables
[1], context
->ctx
);
1227 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1228 context
->refresh_drawables
= FALSE
;
1232 static BOOL
set_swap_interval(Drawable drawable
, int interval
)
1236 switch (swap_control_method
)
1238 case GLX_SWAP_CONTROL_EXT
:
1239 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
1240 pglXSwapIntervalEXT(gdi_display
, drawable
, interval
);
1241 XSync(gdi_display
, False
);
1242 ret
= !X11DRV_check_error();
1245 case GLX_SWAP_CONTROL_MESA
:
1246 ret
= !pglXSwapIntervalMESA(interval
);
1249 case GLX_SWAP_CONTROL_SGI
:
1250 /* wglSwapIntervalEXT considers an interval value of zero to mean that
1251 * vsync should be disabled, but glXSwapIntervalSGI considers such a
1252 * value to be an error. Just silently ignore the request for now.
1255 WARN("Request to disable vertical sync is not handled\n");
1257 ret
= !pglXSwapIntervalSGI(interval
);
1260 case GLX_SWAP_CONTROL_NONE
:
1261 /* Unlikely to happen on modern GLX implementations */
1262 WARN("Request to adjust swap interval is not handled\n");
1269 static struct gl_drawable
*get_gl_drawable( HWND hwnd
, HDC hdc
)
1271 struct gl_drawable
*gl
;
1273 EnterCriticalSection( &context_section
);
1274 if (hwnd
&& !XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&gl
)) return gl
;
1275 if (hdc
&& !XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&gl
)) return gl
;
1276 LeaveCriticalSection( &context_section
);
1280 static void release_gl_drawable( struct gl_drawable
*gl
)
1282 if (gl
) LeaveCriticalSection( &context_section
);
1285 static GLXContext
create_glxcontext(Display
*display
, struct wgl_context
*context
, GLXContext shareList
)
1289 if(context
->gl3_context
)
1291 if(context
->numAttribs
)
1292 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, GL_TRUE
, context
->attribList
);
1294 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, GL_TRUE
, NULL
);
1296 else if(context
->vis
)
1297 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, GL_TRUE
);
1298 else /* Create a GLX Context for a pbuffer */
1299 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1305 /***********************************************************************
1308 static void free_gl_drawable( struct gl_drawable
*gl
)
1312 case DC_GL_CHILD_WIN
:
1313 XDestroyWindow( gdi_display
, gl
->drawable
);
1314 XFreeColormap( gdi_display
, gl
->colormap
);
1316 case DC_GL_PIXMAP_WIN
:
1317 pglXDestroyGLXPixmap( gdi_display
, gl
->drawable
);
1318 XFreePixmap( gdi_display
, gl
->pixmap
);
1323 if (gl
->visual
) XFree( gl
->visual
);
1324 HeapFree( GetProcessHeap(), 0, gl
);
1328 /***********************************************************************
1329 * create_gl_drawable
1331 static BOOL
create_gl_drawable( HWND hwnd
, struct gl_drawable
*gl
)
1335 if (GetAncestor( hwnd
, GA_PARENT
) == GetDesktopWindow()) /* top-level window */
1337 struct x11drv_win_data
*data
= get_win_data( hwnd
);
1341 gl
->type
= DC_GL_WINDOW
;
1342 gl
->drawable
= create_client_window( data
, gl
->visual
);
1343 release_win_data( data
);
1346 #ifdef SONAME_LIBXCOMPOSITE
1347 else if(usexcomposite
)
1349 static Window dummy_parent
;
1350 XSetWindowAttributes attrib
;
1352 attrib
.override_redirect
= True
;
1355 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, default_visual
.depth
,
1356 InputOutput
, default_visual
.visual
, CWOverrideRedirect
, &attrib
);
1357 XMapWindow( gdi_display
, dummy_parent
);
1359 gl
->colormap
= XCreateColormap(gdi_display
, dummy_parent
, gl
->visual
->visual
,
1360 (gl
->visual
->class == PseudoColor
||
1361 gl
->visual
->class == GrayScale
||
1362 gl
->visual
->class == DirectColor
) ?
1363 AllocAll
: AllocNone
);
1364 attrib
.colormap
= gl
->colormap
;
1365 XInstallColormap(gdi_display
, attrib
.colormap
);
1367 gl
->type
= DC_GL_CHILD_WIN
;
1368 gl
->drawable
= XCreateWindow( gdi_display
, dummy_parent
, 0, 0,
1369 gl
->rect
.right
- gl
->rect
.left
, gl
->rect
.bottom
- gl
->rect
.top
,
1370 0, gl
->visual
->depth
, InputOutput
, gl
->visual
->visual
,
1371 CWColormap
| CWOverrideRedirect
, &attrib
);
1374 pXCompositeRedirectWindow(gdi_display
, gl
->drawable
, CompositeRedirectManual
);
1375 XMapWindow(gdi_display
, gl
->drawable
);
1377 else XFreeColormap( gdi_display
, gl
->colormap
);
1382 WARN("XComposite is not available, using GLXPixmap hack\n");
1384 gl
->type
= DC_GL_PIXMAP_WIN
;
1385 gl
->pixmap
= XCreatePixmap( gdi_display
, root_window
,
1386 gl
->rect
.right
- gl
->rect
.left
, gl
->rect
.bottom
- gl
->rect
.top
,
1387 gl
->visual
->depth
);
1390 gl
->drawable
= pglXCreateGLXPixmap( gdi_display
, gl
->visual
, gl
->pixmap
);
1391 if (!gl
->drawable
) XFreePixmap( gdi_display
, gl
->pixmap
);
1396 gl
->refresh_swap_interval
= TRUE
;
1397 return gl
->drawable
!= 0;
1401 /***********************************************************************
1404 static BOOL
set_win_format( HWND hwnd
, const struct wgl_pixel_format
*format
)
1406 struct gl_drawable
*gl
, *prev
;
1408 gl
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*gl
) );
1409 /* Default GLX and WGL swap interval is 1, but in case of glXSwapIntervalSGI
1410 * there is no way to query it, so we have to store it here.
1412 gl
->swap_interval
= 1;
1413 gl
->refresh_swap_interval
= TRUE
;
1414 gl
->format
= format
;
1415 gl
->visual
= pglXGetVisualFromFBConfig( gdi_display
, format
->fbconfig
);
1418 HeapFree( GetProcessHeap(), 0, gl
);
1422 GetClientRect( hwnd
, &gl
->rect
);
1423 gl
->rect
.right
= min( max( 1, gl
->rect
.right
), 65535 );
1424 gl
->rect
.bottom
= min( max( 1, gl
->rect
.bottom
), 65535 );
1426 if (!create_gl_drawable( hwnd
, gl
))
1428 XFree( gl
->visual
);
1429 HeapFree( GetProcessHeap(), 0, gl
);
1433 TRACE( "created GL drawable %lx for win %p %s\n",
1434 gl
->drawable
, hwnd
, debugstr_fbconfig( format
->fbconfig
));
1436 XFlush( gdi_display
);
1438 EnterCriticalSection( &context_section
);
1439 if (!XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&prev
))
1441 gl
->swap_interval
= prev
->swap_interval
;
1442 free_gl_drawable( prev
);
1444 XSaveContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char *)gl
);
1445 LeaveCriticalSection( &context_section
);
1447 __wine_set_pixel_format( hwnd
, pixel_format_index( format
));
1452 static BOOL
set_pixel_format(HDC hdc
, int format
, BOOL allow_change
)
1454 const struct wgl_pixel_format
*fmt
;
1456 HWND hwnd
= WindowFromDC( hdc
);
1458 TRACE("(%p,%d)\n", hdc
, format
);
1460 if (!hwnd
|| hwnd
== GetDesktopWindow())
1462 WARN( "not a valid window DC %p/%p\n", hdc
, hwnd
);
1466 fmt
= get_pixel_format(gdi_display
, format
, FALSE
/* Offscreen */);
1469 ERR( "Invalid format %d\n", format
);
1473 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1474 if (!(value
& GLX_WINDOW_BIT
))
1476 WARN( "Pixel format %d is not compatible for window rendering\n", format
);
1482 struct gl_drawable
*gl
;
1483 if ((gl
= get_gl_drawable( hwnd
, hdc
)))
1485 int prev
= pixel_format_index( gl
->format
);
1486 release_gl_drawable( gl
);
1487 return prev
== format
; /* cannot change it if already set */
1491 return set_win_format( hwnd
, fmt
);
1495 /***********************************************************************
1498 void sync_gl_drawable( HWND hwnd
, const RECT
*visible_rect
, const RECT
*client_rect
)
1500 struct gl_drawable
*gl
;
1504 XWindowChanges changes
;
1506 changes
.width
= min( max( 1, client_rect
->right
- client_rect
->left
), 65535 );
1507 changes
.height
= min( max( 1, client_rect
->bottom
- client_rect
->top
), 65535 );
1509 if (!(gl
= get_gl_drawable( hwnd
, 0 ))) return;
1511 if (changes
.width
!= gl
->rect
.right
- gl
->rect
.left
) mask
|= CWWidth
;
1512 if (changes
.height
!= gl
->rect
.bottom
- gl
->rect
.top
) mask
|= CWHeight
;
1514 TRACE( "setting drawable %lx size %dx%d\n", gl
->drawable
, changes
.width
, changes
.height
);
1518 case DC_GL_CHILD_WIN
:
1519 if (mask
) XConfigureWindow( gdi_display
, gl
->drawable
, mask
, &changes
);
1521 case DC_GL_PIXMAP_WIN
:
1523 pix
= XCreatePixmap(gdi_display
, root_window
, changes
.width
, changes
.height
, gl
->visual
->depth
);
1524 if (!pix
) goto done
;
1525 glxp
= pglXCreateGLXPixmap(gdi_display
, gl
->visual
, pix
);
1528 XFreePixmap(gdi_display
, pix
);
1531 mark_drawable_dirty(gl
->drawable
, glxp
);
1532 XFlush( gdi_display
);
1534 XFreePixmap(gdi_display
, gl
->pixmap
);
1535 pglXDestroyGLXPixmap(gdi_display
, gl
->drawable
);
1536 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, gl
->drawable
);
1539 gl
->drawable
= glxp
;
1544 SetRect( &gl
->rect
, 0, 0, changes
.width
, changes
.height
);
1546 release_gl_drawable( gl
);
1550 /***********************************************************************
1551 * set_gl_drawable_parent
1553 void set_gl_drawable_parent( HWND hwnd
, HWND parent
)
1555 struct gl_drawable
*gl
;
1556 Drawable old_drawable
;
1558 if (!(gl
= get_gl_drawable( hwnd
, 0 ))) return;
1560 TRACE( "setting drawable %lx parent %p\n", gl
->drawable
, parent
);
1562 old_drawable
= gl
->drawable
;
1567 case DC_GL_CHILD_WIN
:
1568 if (parent
!= GetDesktopWindow()) goto done
;
1569 XDestroyWindow( gdi_display
, gl
->drawable
);
1570 XFreeColormap( gdi_display
, gl
->colormap
);
1572 case DC_GL_PIXMAP_WIN
:
1573 if (parent
!= GetDesktopWindow()) goto done
;
1574 pglXDestroyGLXPixmap( gdi_display
, gl
->drawable
);
1575 XFreePixmap( gdi_display
, gl
->pixmap
);
1581 if (!create_gl_drawable( hwnd
, gl
))
1583 XDeleteContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
);
1584 release_gl_drawable( gl
);
1585 XFree( gl
->visual
);
1586 HeapFree( GetProcessHeap(), 0, gl
);
1587 __wine_set_pixel_format( hwnd
, 0 );
1590 mark_drawable_dirty( old_drawable
, gl
->drawable
);
1593 release_gl_drawable( gl
);
1598 /***********************************************************************
1599 * destroy_gl_drawable
1601 void destroy_gl_drawable( HWND hwnd
)
1603 struct gl_drawable
*gl
;
1605 EnterCriticalSection( &context_section
);
1606 if (!XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&gl
))
1608 XDeleteContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
);
1609 free_gl_drawable( gl
);
1611 LeaveCriticalSection( &context_section
);
1616 * glxdrv_DescribePixelFormat
1618 * Get the pixel-format descriptor associated to the given id
1620 static int glxdrv_wglDescribePixelFormat( HDC hdc
, int iPixelFormat
,
1621 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1623 /*XVisualInfo *vis;*/
1626 const struct wgl_pixel_format
*fmt
;
1628 if (!has_opengl()) return 0;
1630 TRACE("(%p,%d,%d,%p)\n", hdc
, iPixelFormat
, nBytes
, ppfd
);
1632 if (!ppfd
) return nb_onscreen_formats
;
1634 /* 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 */
1635 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */);
1637 WARN("unexpected format %d\n", iPixelFormat
);
1641 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1642 ERR("Wrong structure size !\n");
1643 /* Should set error */
1647 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1648 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1651 /* These flags are always the same... */
1652 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1653 /* Now the flags extracted from the Visual */
1655 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1656 if(value
& GLX_WINDOW_BIT
)
1657 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1659 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1660 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1661 * 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
1662 * offered the GDI bit either. */
1663 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1665 /* PFD_GENERIC_FORMAT - gdi software rendering
1666 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1667 * none set - full hardware accelerated by a ICD
1669 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1670 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1672 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1674 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1675 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1677 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1680 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1681 if (value
& GLX_RGBA_BIT
)
1682 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1684 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1687 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1688 ppfd
->cColorBits
= value
;
1690 /* Red, green, blue and alpha bits / shifts */
1691 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1692 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1693 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1694 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1695 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1697 ppfd
->cRedBits
= rb
;
1698 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1699 ppfd
->cBlueBits
= bb
;
1700 ppfd
->cBlueShift
= ab
;
1701 ppfd
->cGreenBits
= gb
;
1702 ppfd
->cGreenShift
= bb
+ ab
;
1703 ppfd
->cAlphaBits
= ab
;
1704 ppfd
->cAlphaShift
= 0;
1707 ppfd
->cRedShift
= 0;
1708 ppfd
->cBlueBits
= 0;
1709 ppfd
->cBlueShift
= 0;
1710 ppfd
->cGreenBits
= 0;
1711 ppfd
->cGreenShift
= 0;
1712 ppfd
->cAlphaBits
= 0;
1713 ppfd
->cAlphaShift
= 0;
1716 /* Accum RGBA bits */
1717 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1718 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1719 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1720 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1722 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1723 ppfd
->cAccumRedBits
= rb
;
1724 ppfd
->cAccumGreenBits
= gb
;
1725 ppfd
->cAccumBlueBits
= bb
;
1726 ppfd
->cAccumAlphaBits
= ab
;
1729 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1730 ppfd
->cAuxBuffers
= value
;
1733 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1734 ppfd
->cDepthBits
= value
;
1737 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1738 ppfd
->cStencilBits
= value
;
1740 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1742 if (TRACE_ON(wgl
)) {
1743 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1746 return nb_onscreen_formats
;
1749 /***********************************************************************
1750 * glxdrv_wglGetPixelFormat
1752 static int glxdrv_wglGetPixelFormat( HDC hdc
)
1754 struct gl_drawable
*gl
;
1757 if ((gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1759 ret
= pixel_format_index( gl
->format
);
1760 /* Offscreen formats can't be used with traditional WGL calls.
1761 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1762 if (!is_onscreen_pixel_format( ret
)) ret
= 1;
1763 release_gl_drawable( gl
);
1765 TRACE( "%p -> %d\n", hdc
, ret
);
1769 /***********************************************************************
1770 * glxdrv_wglSetPixelFormat
1772 static BOOL
glxdrv_wglSetPixelFormat( HDC hdc
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1774 return set_pixel_format(hdc
, iPixelFormat
, FALSE
);
1777 /***********************************************************************
1778 * glxdrv_wglCopyContext
1780 static BOOL
glxdrv_wglCopyContext(struct wgl_context
*src
, struct wgl_context
*dst
, UINT mask
)
1782 TRACE("%p -> %p mask %#x\n", src
, dst
, mask
);
1784 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1786 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1790 /***********************************************************************
1791 * glxdrv_wglCreateContext
1793 static struct wgl_context
*glxdrv_wglCreateContext( HDC hdc
)
1795 struct wgl_context
*ret
;
1796 struct gl_drawable
*gl
;
1798 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1800 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1804 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
))))
1807 ret
->fmt
= gl
->format
;
1808 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, gl
->format
->fbconfig
);
1809 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1810 list_add_head( &context_list
, &ret
->entry
);
1812 release_gl_drawable( gl
);
1813 TRACE( "%p -> %p\n", hdc
, ret
);
1817 /***********************************************************************
1818 * glxdrv_wglDeleteContext
1820 static void glxdrv_wglDeleteContext(struct wgl_context
*ctx
)
1822 struct wgl_pbuffer
*pb
;
1824 TRACE("(%p)\n", ctx
);
1826 EnterCriticalSection( &context_section
);
1827 list_remove( &ctx
->entry
);
1828 LIST_FOR_EACH_ENTRY( pb
, &pbuffer_list
, struct wgl_pbuffer
, entry
)
1830 if (pb
->prev_context
== ctx
->ctx
) {
1831 pglXDestroyContext(gdi_display
, pb
->tmp_context
);
1832 pb
->prev_context
= pb
->tmp_context
= NULL
;
1835 LeaveCriticalSection( &context_section
);
1837 if (ctx
->ctx
) pglXDestroyContext( gdi_display
, ctx
->ctx
);
1838 if (ctx
->vis
) XFree( ctx
->vis
);
1839 HeapFree( GetProcessHeap(), 0, ctx
);
1842 /***********************************************************************
1843 * glxdrv_wglGetProcAddress
1845 static PROC
glxdrv_wglGetProcAddress(LPCSTR lpszProc
)
1847 if (!strncmp(lpszProc
, "wgl", 3)) return NULL
;
1848 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1851 /***********************************************************************
1852 * glxdrv_wglMakeCurrent
1854 static BOOL
glxdrv_wglMakeCurrent(HDC hdc
, struct wgl_context
*ctx
)
1857 struct gl_drawable
*gl
;
1859 TRACE("(%p,%p)\n", hdc
, ctx
);
1863 pglXMakeCurrent(gdi_display
, None
, NULL
);
1864 NtCurrentTeb()->glContext
= NULL
;
1868 if ((gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1870 if (ctx
->fmt
!= gl
->format
)
1872 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc
, gl
->format
, ctx
, ctx
->fmt
);
1873 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1877 TRACE("hdc %p drawable %lx fmt %p ctx %p %s\n", hdc
, gl
->drawable
, gl
->format
, ctx
->ctx
,
1878 debugstr_fbconfig( gl
->format
->fbconfig
));
1880 ret
= pglXMakeCurrent(gdi_display
, gl
->drawable
, ctx
->ctx
);
1883 NtCurrentTeb()->glContext
= ctx
;
1884 ctx
->has_been_current
= TRUE
;
1886 ctx
->drawables
[0] = gl
->drawable
;
1887 ctx
->drawables
[1] = gl
->drawable
;
1888 ctx
->refresh_drawables
= FALSE
;
1892 SetLastError( ERROR_INVALID_HANDLE
);
1895 release_gl_drawable( gl
);
1896 TRACE( "%p,%p returning %d\n", hdc
, ctx
, ret
);
1900 /***********************************************************************
1901 * X11DRV_wglMakeContextCurrentARB
1903 static BOOL
X11DRV_wglMakeContextCurrentARB( HDC draw_hdc
, HDC read_hdc
, struct wgl_context
*ctx
)
1906 struct gl_drawable
*draw_gl
, *read_gl
= NULL
;
1908 TRACE("(%p,%p,%p)\n", draw_hdc
, read_hdc
, ctx
);
1912 pglXMakeCurrent(gdi_display
, None
, NULL
);
1913 NtCurrentTeb()->glContext
= NULL
;
1917 if (!pglXMakeContextCurrent
) return FALSE
;
1919 if ((draw_gl
= get_gl_drawable( WindowFromDC( draw_hdc
), draw_hdc
)))
1921 read_gl
= get_gl_drawable( WindowFromDC( read_hdc
), read_hdc
);
1922 ret
= pglXMakeContextCurrent(gdi_display
, draw_gl
->drawable
,
1923 read_gl
? read_gl
->drawable
: 0, ctx
->ctx
);
1926 ctx
->has_been_current
= TRUE
;
1927 ctx
->hdc
= draw_hdc
;
1928 ctx
->drawables
[0] = draw_gl
->drawable
;
1929 ctx
->drawables
[1] = read_gl
? read_gl
->drawable
: 0;
1930 ctx
->refresh_drawables
= FALSE
;
1931 NtCurrentTeb()->glContext
= ctx
;
1935 SetLastError( ERROR_INVALID_HANDLE
);
1937 release_gl_drawable( read_gl
);
1938 release_gl_drawable( draw_gl
);
1939 TRACE( "%p,%p,%p returning %d\n", draw_hdc
, read_hdc
, ctx
, ret
);
1943 /***********************************************************************
1944 * glxdrv_wglShareLists
1946 static BOOL
glxdrv_wglShareLists(struct wgl_context
*org
, struct wgl_context
*dest
)
1948 TRACE("(%p, %p)\n", org
, dest
);
1950 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1951 * at context creation time but in case of WGL it is done using wglShareLists.
1952 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1953 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1954 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1955 * so there delaying context creation doesn't work.
1957 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1958 * and when a program requests sharing we recreate the destination context if it hasn't been made
1959 * current or when it hasn't shared display lists before.
1962 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
1964 ERR("Could not share display lists, one of the contexts has been current already !\n");
1967 else if(dest
->sharing
)
1969 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1974 /* Re-create the GLX context and share display lists */
1975 pglXDestroyContext(gdi_display
, dest
->ctx
);
1976 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1977 TRACE(" re-created context (%p) for Wine context %p (%s) sharing lists with ctx %p (%s)\n",
1978 dest
->ctx
, dest
, debugstr_fbconfig(dest
->fmt
->fbconfig
),
1979 org
->ctx
, debugstr_fbconfig( org
->fmt
->fbconfig
));
1981 org
->sharing
= TRUE
;
1982 dest
->sharing
= TRUE
;
1988 static void wglFinish(void)
1990 struct x11drv_escape_flush_gl_drawable escape
;
1991 struct gl_drawable
*gl
;
1992 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
1994 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
1995 escape
.gl_drawable
= 0;
1997 if ((gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), 0 )))
2001 case DC_GL_PIXMAP_WIN
: escape
.gl_drawable
= gl
->pixmap
; break;
2002 case DC_GL_CHILD_WIN
: escape
.gl_drawable
= gl
->drawable
; break;
2006 release_gl_drawable( gl
);
2010 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2013 static void wglFlush(void)
2015 struct x11drv_escape_flush_gl_drawable escape
;
2016 struct gl_drawable
*gl
;
2017 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
2019 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
2020 escape
.gl_drawable
= 0;
2022 if ((gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), 0 )))
2026 case DC_GL_PIXMAP_WIN
: escape
.gl_drawable
= gl
->pixmap
; break;
2027 case DC_GL_CHILD_WIN
: escape
.gl_drawable
= gl
->drawable
; break;
2031 release_gl_drawable( gl
);
2035 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2038 static const GLubyte
*wglGetString(GLenum name
)
2040 if (name
== GL_EXTENSIONS
&& WineGLInfo
.glExtensions
)
2041 return (const GLubyte
*)WineGLInfo
.glExtensions
;
2042 return pglGetString(name
);
2045 /***********************************************************************
2046 * X11DRV_wglCreateContextAttribsARB
2048 static struct wgl_context
*X11DRV_wglCreateContextAttribsARB( HDC hdc
, struct wgl_context
*hShareContext
,
2049 const int* attribList
)
2051 struct wgl_context
*ret
;
2052 struct gl_drawable
*gl
;
2055 TRACE("(%p %p %p)\n", hdc
, hShareContext
, attribList
);
2057 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
2059 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
2063 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
))))
2066 ret
->fmt
= gl
->format
;
2067 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2068 ret
->gl3_context
= TRUE
;
2071 int *pContextAttribList
= &ret
->attribList
[0];
2072 /* attribList consists of pairs {token, value] terminated with 0 */
2073 while(attribList
[0] != 0)
2075 TRACE("%#x %#x\n", attribList
[0], attribList
[1]);
2076 switch(attribList
[0])
2078 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2079 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2080 pContextAttribList
[1] = attribList
[1];
2081 pContextAttribList
+= 2;
2084 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2085 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2086 pContextAttribList
[1] = attribList
[1];
2087 pContextAttribList
+= 2;
2090 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2092 case WGL_CONTEXT_FLAGS_ARB
:
2093 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2094 pContextAttribList
[1] = attribList
[1];
2095 pContextAttribList
+= 2;
2098 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2099 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2100 pContextAttribList
[1] = attribList
[1];
2101 pContextAttribList
+= 2;
2104 case WGL_RENDERER_ID_WINE
:
2105 pContextAttribList
[0] = GLX_RENDERER_ID_MESA
;
2106 pContextAttribList
[1] = attribList
[1];
2107 pContextAttribList
+= 2;
2111 ERR("Unhandled attribList pair: %#x %#x\n", attribList
[0], attribList
[1]);
2117 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2118 ret
->ctx
= create_glxcontext(gdi_display
, ret
, hShareContext
? hShareContext
->ctx
: NULL
);
2119 XSync(gdi_display
, False
);
2120 if ((err
= X11DRV_check_error()) || !ret
->ctx
)
2122 /* In the future we should convert the GLX error to a win32 one here if needed */
2123 ERR("Context creation failed (error %x)\n", err
);
2124 HeapFree( GetProcessHeap(), 0, ret
);
2127 else list_add_head( &context_list
, &ret
->entry
);
2130 release_gl_drawable( gl
);
2131 TRACE( "%p -> %p\n", hdc
, ret
);
2136 * X11DRV_wglGetExtensionsStringARB
2138 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2140 static const char *X11DRV_wglGetExtensionsStringARB(HDC hdc
)
2142 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2143 return WineGLInfo
.wglExtensions
;
2147 * X11DRV_wglCreatePbufferARB
2149 * WGL_ARB_pbuffer: wglCreatePbufferARB
2151 static struct wgl_pbuffer
*X11DRV_wglCreatePbufferARB( HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
,
2152 const int *piAttribList
)
2154 struct wgl_pbuffer
* object
;
2155 const struct wgl_pixel_format
*fmt
;
2159 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2161 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2162 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */);
2164 ERR("(%p): invalid pixel format %d\n", hdc
, iPixelFormat
);
2165 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2169 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2170 if (NULL
== object
) {
2171 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2174 object
->width
= iWidth
;
2175 object
->height
= iHeight
;
2178 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2179 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2180 while (piAttribList
&& 0 != *piAttribList
) {
2182 switch (*piAttribList
) {
2183 case WGL_PBUFFER_LARGEST_ARB
: {
2185 attr_v
= *piAttribList
;
2186 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2187 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2191 case WGL_TEXTURE_FORMAT_ARB
: {
2193 attr_v
= *piAttribList
;
2194 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2195 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2196 object
->use_render_texture
= 0;
2198 if (!use_render_texture_emulation
) {
2199 SetLastError(ERROR_INVALID_DATA
);
2203 case WGL_TEXTURE_RGB_ARB
:
2204 object
->use_render_texture
= GL_RGB
;
2205 object
->texture_bpp
= 3;
2206 object
->texture_format
= GL_RGB
;
2207 object
->texture_type
= GL_UNSIGNED_BYTE
;
2209 case WGL_TEXTURE_RGBA_ARB
:
2210 object
->use_render_texture
= GL_RGBA
;
2211 object
->texture_bpp
= 4;
2212 object
->texture_format
= GL_RGBA
;
2213 object
->texture_type
= GL_UNSIGNED_BYTE
;
2216 /* WGL_FLOAT_COMPONENTS_NV */
2217 case WGL_TEXTURE_FLOAT_R_NV
:
2218 object
->use_render_texture
= GL_FLOAT_R_NV
;
2219 object
->texture_bpp
= 4;
2220 object
->texture_format
= GL_RED
;
2221 object
->texture_type
= GL_FLOAT
;
2223 case WGL_TEXTURE_FLOAT_RG_NV
:
2224 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2225 object
->texture_bpp
= 8;
2226 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2227 object
->texture_type
= GL_FLOAT
;
2229 case WGL_TEXTURE_FLOAT_RGB_NV
:
2230 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2231 object
->texture_bpp
= 12;
2232 object
->texture_format
= GL_RGB
;
2233 object
->texture_type
= GL_FLOAT
;
2235 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2236 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2237 object
->texture_bpp
= 16;
2238 object
->texture_format
= GL_RGBA
;
2239 object
->texture_type
= GL_FLOAT
;
2242 ERR("Unknown texture format: %x\n", attr_v
);
2243 SetLastError(ERROR_INVALID_DATA
);
2250 case WGL_TEXTURE_TARGET_ARB
: {
2252 attr_v
= *piAttribList
;
2253 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2254 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2255 object
->texture_target
= 0;
2257 if (!use_render_texture_emulation
) {
2258 SetLastError(ERROR_INVALID_DATA
);
2262 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2263 if (iWidth
!= iHeight
) {
2264 SetLastError(ERROR_INVALID_DATA
);
2267 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2268 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2271 case WGL_TEXTURE_1D_ARB
: {
2273 SetLastError(ERROR_INVALID_DATA
);
2276 object
->texture_target
= GL_TEXTURE_1D
;
2277 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2280 case WGL_TEXTURE_2D_ARB
: {
2281 object
->texture_target
= GL_TEXTURE_2D
;
2282 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2285 case WGL_TEXTURE_RECTANGLE_NV
: {
2286 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2287 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2291 ERR("Unknown texture target: %x\n", attr_v
);
2292 SetLastError(ERROR_INVALID_DATA
);
2299 case WGL_MIPMAP_TEXTURE_ARB
: {
2301 attr_v
= *piAttribList
;
2302 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2303 if (!use_render_texture_emulation
) {
2304 SetLastError(ERROR_INVALID_DATA
);
2313 PUSH1(attribs
, None
);
2314 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2315 TRACE("new Pbuffer drawable as %lx\n", object
->drawable
);
2316 if (!object
->drawable
) {
2317 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2318 goto create_failed
; /* unexpected error */
2320 EnterCriticalSection( &context_section
);
2321 list_add_head( &pbuffer_list
, &object
->entry
);
2322 LeaveCriticalSection( &context_section
);
2323 TRACE("->(%p)\n", object
);
2327 HeapFree(GetProcessHeap(), 0, object
);
2328 TRACE("->(FAILED)\n");
2333 * X11DRV_wglDestroyPbufferARB
2335 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2337 static BOOL
X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer
*object
)
2339 TRACE("(%p)\n", object
);
2341 EnterCriticalSection( &context_section
);
2342 list_remove( &object
->entry
);
2343 LeaveCriticalSection( &context_section
);
2344 pglXDestroyPbuffer(gdi_display
, object
->drawable
);
2345 if (object
->tmp_context
)
2346 pglXDestroyContext(gdi_display
, object
->tmp_context
);
2347 HeapFree(GetProcessHeap(), 0, object
);
2352 * X11DRV_wglGetPbufferDCARB
2354 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2356 static HDC
X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer
*object
)
2358 struct x11drv_escape_set_drawable escape
;
2359 struct gl_drawable
*gl
, *prev
;
2362 hdc
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
);
2365 if (!(gl
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*gl
) )))
2370 gl
->type
= DC_GL_PBUFFER
;
2371 gl
->drawable
= object
->drawable
;
2372 gl
->format
= object
->fmt
;
2374 EnterCriticalSection( &context_section
);
2375 if (!XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&prev
))
2376 free_gl_drawable( prev
);
2377 XSaveContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char *)gl
);
2378 LeaveCriticalSection( &context_section
);
2380 escape
.code
= X11DRV_SET_DRAWABLE
;
2381 escape
.drawable
= object
->drawable
;
2382 escape
.mode
= IncludeInferiors
;
2383 SetRect( &escape
.dc_rect
, 0, 0, object
->width
, object
->height
);
2384 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2386 TRACE( "(%p)->(%p)\n", object
, hdc
);
2391 * X11DRV_wglQueryPbufferARB
2393 * WGL_ARB_pbuffer: wglQueryPbufferARB
2395 static BOOL
X11DRV_wglQueryPbufferARB( struct wgl_pbuffer
*object
, int iAttribute
, int *piValue
)
2397 TRACE("(%p, 0x%x, %p)\n", object
, iAttribute
, piValue
);
2399 switch (iAttribute
) {
2400 case WGL_PBUFFER_WIDTH_ARB
:
2401 pglXQueryDrawable(gdi_display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2403 case WGL_PBUFFER_HEIGHT_ARB
:
2404 pglXQueryDrawable(gdi_display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2407 case WGL_PBUFFER_LOST_ARB
:
2408 /* GLX Pbuffers cannot be lost by default. We can support this by
2409 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2410 * to receive pixel buffer clobber events, however that may or may
2411 * not give any benefit */
2412 *piValue
= GL_FALSE
;
2415 case WGL_TEXTURE_FORMAT_ARB
:
2416 if (!object
->use_render_texture
) {
2417 *piValue
= WGL_NO_TEXTURE_ARB
;
2419 if (!use_render_texture_emulation
) {
2420 SetLastError(ERROR_INVALID_HANDLE
);
2423 switch(object
->use_render_texture
) {
2425 *piValue
= WGL_TEXTURE_RGB_ARB
;
2428 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2430 /* WGL_FLOAT_COMPONENTS_NV */
2432 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2434 case GL_FLOAT_RG_NV
:
2435 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2437 case GL_FLOAT_RGB_NV
:
2438 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2440 case GL_FLOAT_RGBA_NV
:
2441 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2444 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2449 case WGL_TEXTURE_TARGET_ARB
:
2450 if (!object
->texture_target
){
2451 *piValue
= WGL_NO_TEXTURE_ARB
;
2453 if (!use_render_texture_emulation
) {
2454 SetLastError(ERROR_INVALID_DATA
);
2457 switch (object
->texture_target
) {
2458 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2459 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2460 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2461 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2466 case WGL_MIPMAP_TEXTURE_ARB
:
2467 *piValue
= GL_FALSE
; /** don't support that */
2468 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2472 FIXME("unexpected attribute %x\n", iAttribute
);
2480 * X11DRV_wglReleasePbufferDCARB
2482 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2484 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer
*object
, HDC hdc
)
2486 struct gl_drawable
*gl
;
2488 TRACE("(%p, %p)\n", object
, hdc
);
2490 EnterCriticalSection( &context_section
);
2492 if (!XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&gl
))
2494 XDeleteContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
);
2495 free_gl_drawable( gl
);
2499 LeaveCriticalSection( &context_section
);
2501 return hdc
&& DeleteDC(hdc
);
2505 * X11DRV_wglSetPbufferAttribARB
2507 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2509 static BOOL
X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer
*object
, const int *piAttribList
)
2511 GLboolean ret
= GL_FALSE
;
2513 WARN("(%p, %p): alpha-testing, report any problem\n", object
, piAttribList
);
2515 if (!object
->use_render_texture
) {
2516 SetLastError(ERROR_INVALID_HANDLE
);
2519 if (use_render_texture_emulation
) {
2526 * X11DRV_wglChoosePixelFormatARB
2528 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2530 static BOOL
X11DRV_wglChoosePixelFormatARB( HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
,
2531 UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2545 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2546 if (NULL
!= pfAttribFList
) {
2547 FIXME("unused pfAttribFList\n");
2550 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2551 if (-1 == nAttribs
) {
2552 WARN("Cannot convert WGL to GLX attributes\n");
2555 PUSH1(attribs
, None
);
2557 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2558 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2559 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2561 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2563 switch(piAttribIList
[i
])
2565 case WGL_DRAW_TO_BITMAP_ARB
:
2566 if(piAttribIList
[i
+1])
2567 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2569 case WGL_ACCELERATION_ARB
:
2570 switch(piAttribIList
[i
+1])
2572 case WGL_NO_ACCELERATION_ARB
:
2573 dwFlags
|= PFD_GENERIC_FORMAT
;
2575 case WGL_GENERIC_ACCELERATION_ARB
:
2576 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2578 case WGL_FULL_ACCELERATION_ARB
:
2583 case WGL_SUPPORT_GDI_ARB
:
2584 if(piAttribIList
[i
+1])
2585 dwFlags
|= PFD_SUPPORT_GDI
;
2590 /* Search for FB configurations matching the requirements in attribs */
2591 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2593 WARN("Compatible Pixel Format not found\n");
2597 /* Loop through all matching formats and check if they are suitable.
2598 * Note that this function should at max return nMaxFormats different formats */
2599 for(run
=0; run
< 2; run
++)
2601 for (it
= 0; it
< nCfgs
&& pfmt_it
< nMaxFormats
; ++it
)
2603 if (pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
))
2605 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2609 /* During the first run we only want onscreen formats and during the second only offscreen */
2610 start
= run
== 1 ? nb_onscreen_formats
: 0;
2611 end
= run
== 1 ? nb_pixel_formats
: nb_onscreen_formats
;
2613 for (i
= start
; i
< end
; i
++)
2615 if (pixel_formats
[i
].fmt_id
== fmt_id
&& (pixel_formats
[i
].dwFlags
& dwFlags
) == dwFlags
)
2617 piFormats
[pfmt_it
++] = i
+ 1;
2618 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2619 it
+ 1, nCfgs
, fmt_id
, i
+ 1);
2626 *nNumFormats
= pfmt_it
;
2633 * X11DRV_wglGetPixelFormatAttribivARB
2635 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2637 static BOOL
X11DRV_wglGetPixelFormatAttribivARB( HDC hdc
, int iPixelFormat
, int iLayerPlane
,
2638 UINT nAttributes
, const int *piAttributes
, int *piValues
)
2641 const struct wgl_pixel_format
*fmt
;
2646 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2648 if (0 < iLayerPlane
) {
2649 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2653 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2654 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2655 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2656 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */);
2658 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2661 for (i
= 0; i
< nAttributes
; ++i
) {
2662 const int curWGLAttr
= piAttributes
[i
];
2663 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2665 switch (curWGLAttr
) {
2666 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2667 piValues
[i
] = nb_pixel_formats
;
2670 case WGL_SUPPORT_OPENGL_ARB
:
2671 piValues
[i
] = GL_TRUE
;
2674 case WGL_ACCELERATION_ARB
:
2675 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2676 if (!fmt
) goto pix_error
;
2677 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2678 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2679 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2680 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2682 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2685 case WGL_TRANSPARENT_ARB
:
2686 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2687 if (!fmt
) goto pix_error
;
2688 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2689 if (hTest
) goto get_error
;
2690 piValues
[i
] = GL_FALSE
;
2691 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2694 case WGL_PIXEL_TYPE_ARB
:
2695 curGLXAttr
= GLX_RENDER_TYPE
;
2696 if (!fmt
) goto pix_error
;
2697 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2698 if (hTest
) goto get_error
;
2699 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2700 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2701 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2702 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2703 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2704 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2706 ERR("unexpected RenderType(%x)\n", tmp
);
2707 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2711 case WGL_COLOR_BITS_ARB
:
2712 curGLXAttr
= GLX_BUFFER_SIZE
;
2715 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2716 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2717 if (!use_render_texture_emulation
) {
2718 piValues
[i
] = GL_FALSE
;
2721 curGLXAttr
= GLX_RENDER_TYPE
;
2722 if (!fmt
) goto pix_error
;
2723 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2724 if (hTest
) goto get_error
;
2725 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2726 piValues
[i
] = GL_FALSE
;
2729 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2730 if (hTest
) goto get_error
;
2731 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2734 case WGL_BLUE_BITS_ARB
:
2735 curGLXAttr
= GLX_BLUE_SIZE
;
2737 case WGL_RED_BITS_ARB
:
2738 curGLXAttr
= GLX_RED_SIZE
;
2740 case WGL_GREEN_BITS_ARB
:
2741 curGLXAttr
= GLX_GREEN_SIZE
;
2743 case WGL_ALPHA_BITS_ARB
:
2744 curGLXAttr
= GLX_ALPHA_SIZE
;
2746 case WGL_DEPTH_BITS_ARB
:
2747 curGLXAttr
= GLX_DEPTH_SIZE
;
2749 case WGL_STENCIL_BITS_ARB
:
2750 curGLXAttr
= GLX_STENCIL_SIZE
;
2752 case WGL_DOUBLE_BUFFER_ARB
:
2753 curGLXAttr
= GLX_DOUBLEBUFFER
;
2755 case WGL_STEREO_ARB
:
2756 curGLXAttr
= GLX_STEREO
;
2758 case WGL_AUX_BUFFERS_ARB
:
2759 curGLXAttr
= GLX_AUX_BUFFERS
;
2762 case WGL_SUPPORT_GDI_ARB
:
2763 if (!fmt
) goto pix_error
;
2764 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) != 0;
2767 case WGL_DRAW_TO_BITMAP_ARB
:
2768 if (!fmt
) goto pix_error
;
2769 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) != 0;
2772 case WGL_DRAW_TO_WINDOW_ARB
:
2773 case WGL_DRAW_TO_PBUFFER_ARB
:
2774 if (!fmt
) goto pix_error
;
2775 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2776 if (hTest
) goto get_error
;
2777 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2778 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2779 piValues
[i
] = GL_TRUE
;
2781 piValues
[i
] = GL_FALSE
;
2784 case WGL_SWAP_METHOD_ARB
:
2785 if (has_swap_method
)
2787 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_SWAP_METHOD_OML
, &tmp
);
2788 if (hTest
) goto get_error
;
2791 case GLX_SWAP_EXCHANGE_OML
:
2792 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2794 case GLX_SWAP_COPY_OML
:
2795 piValues
[i
] = WGL_SWAP_COPY_ARB
;
2797 case GLX_SWAP_UNDEFINED_OML
:
2798 piValues
[i
] = WGL_SWAP_UNDEFINED_ARB
;
2801 ERR("Unexpected swap method %x.\n", tmp
);
2806 WARN("GLX_OML_swap_method not supported, returning WGL_SWAP_EXCHANGE_ARB.\n");
2807 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2811 case WGL_PBUFFER_LARGEST_ARB
:
2812 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2815 case WGL_SAMPLE_BUFFERS_ARB
:
2816 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2819 case WGL_SAMPLES_ARB
:
2820 curGLXAttr
= GLX_SAMPLES_ARB
;
2823 case WGL_FLOAT_COMPONENTS_NV
:
2824 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2827 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
2828 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
2831 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
2832 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
2835 case WGL_ACCUM_RED_BITS_ARB
:
2836 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2838 case WGL_ACCUM_GREEN_BITS_ARB
:
2839 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2841 case WGL_ACCUM_BLUE_BITS_ARB
:
2842 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2844 case WGL_ACCUM_ALPHA_BITS_ARB
:
2845 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2847 case WGL_ACCUM_BITS_ARB
:
2848 if (!fmt
) goto pix_error
;
2849 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2850 if (hTest
) goto get_error
;
2852 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2853 if (hTest
) goto get_error
;
2855 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2856 if (hTest
) goto get_error
;
2858 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2859 if (hTest
) goto get_error
;
2864 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2867 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2868 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2869 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2871 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2872 * and check which options can work using iPixelFormat=0 and which not.
2873 * A problem would be that this function is an extension. This would
2874 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2876 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2877 if (!fmt
) goto pix_error
;
2878 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2879 if (hTest
) goto get_error
;
2882 piValues
[i
] = GL_FALSE
;
2888 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2892 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nb_pixel_formats
);
2897 * X11DRV_wglGetPixelFormatAttribfvARB
2899 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2901 static BOOL
X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc
, int iPixelFormat
, int iLayerPlane
,
2902 UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2908 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2910 /* Allocate a temporary array to store integer values */
2911 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2913 ERR("couldn't allocate %d array\n", nAttributes
);
2917 /* Piggy-back on wglGetPixelFormatAttribivARB */
2918 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2920 /* Convert integer values to float. Should also check for attributes
2921 that can give decimal values here */
2922 for (i
=0; i
<nAttributes
;i
++) {
2923 pfValues
[i
] = attr
[i
];
2927 HeapFree(GetProcessHeap(), 0, attr
);
2932 * X11DRV_wglBindTexImageARB
2934 * WGL_ARB_render_texture: wglBindTexImageARB
2936 static BOOL
X11DRV_wglBindTexImageARB( struct wgl_pbuffer
*object
, int iBuffer
)
2938 GLboolean ret
= GL_FALSE
;
2940 TRACE("(%p, %d)\n", object
, iBuffer
);
2942 if (!object
->use_render_texture
) {
2943 SetLastError(ERROR_INVALID_HANDLE
);
2947 if (use_render_texture_emulation
) {
2948 static BOOL initialized
= FALSE
;
2949 int prev_binded_texture
= 0;
2950 GLXContext prev_context
;
2951 Drawable prev_drawable
;
2953 prev_context
= pglXGetCurrentContext();
2954 prev_drawable
= pglXGetCurrentDrawable();
2956 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2957 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2958 isn't ideal performance wise but I wasn't able to get other ways working.
2961 initialized
= TRUE
; /* Only show the FIXME once for performance reasons */
2962 FIXME("partial stub!\n");
2965 TRACE("drawable=%lx, context=%p\n", object
->drawable
, prev_context
);
2966 if (!object
->tmp_context
|| object
->prev_context
!= prev_context
) {
2967 if (object
->tmp_context
)
2968 pglXDestroyContext(gdi_display
, object
->tmp_context
);
2969 object
->tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2970 object
->prev_context
= prev_context
;
2973 opengl_funcs
.gl
.p_glGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2975 /* Switch to our pbuffer */
2976 pglXMakeCurrent(gdi_display
, object
->drawable
, object
->tmp_context
);
2978 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2979 * After that copy the pbuffer texture data. */
2980 opengl_funcs
.gl
.p_glBindTexture(object
->texture_target
, prev_binded_texture
);
2981 opengl_funcs
.gl
.p_glCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2983 /* Switch back to the original drawable and context */
2984 pglXMakeCurrent(gdi_display
, prev_drawable
, prev_context
);
2992 * X11DRV_wglReleaseTexImageARB
2994 * WGL_ARB_render_texture: wglReleaseTexImageARB
2996 static BOOL
X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer
*object
, int iBuffer
)
2998 GLboolean ret
= GL_FALSE
;
3000 TRACE("(%p, %d)\n", object
, iBuffer
);
3002 if (!object
->use_render_texture
) {
3003 SetLastError(ERROR_INVALID_HANDLE
);
3006 if (use_render_texture_emulation
) {
3013 * X11DRV_wglGetExtensionsStringEXT
3015 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3017 static const char *X11DRV_wglGetExtensionsStringEXT(void)
3019 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
3020 return WineGLInfo
.wglExtensions
;
3024 * X11DRV_wglGetSwapIntervalEXT
3026 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3028 static int X11DRV_wglGetSwapIntervalEXT(void)
3030 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
3031 struct gl_drawable
*gl
;
3036 if (!(gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), ctx
->hdc
)))
3038 /* This can't happen because a current WGL context is required to get
3039 * here. Likely the application is buggy.
3041 WARN("No GL drawable found, returning swap interval 0\n");
3045 swap_interval
= gl
->swap_interval
;
3046 release_gl_drawable(gl
);
3048 return swap_interval
;
3052 * X11DRV_wglSwapIntervalEXT
3054 * WGL_EXT_swap_control: wglSwapIntervalEXT
3056 static BOOL
X11DRV_wglSwapIntervalEXT(int interval
)
3058 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
3059 struct gl_drawable
*gl
;
3062 TRACE("(%d)\n", interval
);
3064 /* Without WGL/GLX_EXT_swap_control_tear a negative interval
3067 if (interval
< 0 && !has_swap_control_tear
)
3069 SetLastError(ERROR_INVALID_DATA
);
3073 if (!(gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), ctx
->hdc
)))
3075 SetLastError(ERROR_DC_NOT_FOUND
);
3079 ret
= set_swap_interval(gl
->drawable
, interval
);
3080 gl
->refresh_swap_interval
= FALSE
;
3082 gl
->swap_interval
= interval
;
3084 SetLastError(ERROR_DC_NOT_FOUND
);
3086 release_gl_drawable(gl
);
3092 * X11DRV_wglSetPixelFormatWINE
3094 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3095 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3097 static BOOL
X11DRV_wglSetPixelFormatWINE(HDC hdc
, int format
)
3099 return set_pixel_format(hdc
, format
, TRUE
);
3102 static BOOL
X11DRV_wglQueryCurrentRendererIntegerWINE( GLenum attribute
, GLuint
*value
)
3104 return pglXQueryCurrentRendererIntegerMESA( attribute
, value
);
3107 static const char *X11DRV_wglQueryCurrentRendererStringWINE( GLenum attribute
)
3109 return pglXQueryCurrentRendererStringMESA( attribute
);
3112 static BOOL
X11DRV_wglQueryRendererIntegerWINE( HDC dc
, GLint renderer
, GLenum attribute
, GLuint
*value
)
3114 return pglXQueryRendererIntegerMESA( gdi_display
, DefaultScreen(gdi_display
), renderer
, attribute
, value
);
3117 static const char *X11DRV_wglQueryRendererStringWINE( HDC dc
, GLint renderer
, GLenum attribute
)
3119 return pglXQueryRendererStringMESA( gdi_display
, DefaultScreen(gdi_display
), renderer
, attribute
);
3123 * glxRequireVersion (internal)
3125 * Check if the supported GLX version matches requiredVersion.
3127 static BOOL
glxRequireVersion(int requiredVersion
)
3129 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3130 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3136 static void register_extension(const char *ext
)
3138 if (WineGLInfo
.wglExtensions
[0])
3139 strcat(WineGLInfo
.wglExtensions
, " ");
3140 strcat(WineGLInfo
.wglExtensions
, ext
);
3142 TRACE("'%s'\n", ext
);
3146 * X11DRV_WineGL_LoadExtensions
3148 static void X11DRV_WineGL_LoadExtensions(void)
3150 WineGLInfo
.wglExtensions
[0] = 0;
3152 /* ARB Extensions */
3154 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_create_context"))
3156 register_extension( "WGL_ARB_create_context" );
3157 opengl_funcs
.ext
.p_wglCreateContextAttribsARB
= X11DRV_wglCreateContextAttribsARB
;
3159 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_create_context_profile"))
3160 register_extension("WGL_ARB_create_context_profile");
3163 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_fbconfig_float"))
3165 register_extension("WGL_ARB_pixel_format_float");
3166 register_extension("WGL_ATI_pixel_format_float");
3169 register_extension( "WGL_ARB_extensions_string" );
3170 opengl_funcs
.ext
.p_wglGetExtensionsStringARB
= X11DRV_wglGetExtensionsStringARB
;
3172 if (glxRequireVersion(3))
3174 register_extension( "WGL_ARB_make_current_read" );
3175 opengl_funcs
.ext
.p_wglGetCurrentReadDCARB
= (void *)1; /* never called */
3176 opengl_funcs
.ext
.p_wglMakeContextCurrentARB
= X11DRV_wglMakeContextCurrentARB
;
3179 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
3181 if (glxRequireVersion(3))
3183 register_extension( "WGL_ARB_pbuffer" );
3184 opengl_funcs
.ext
.p_wglCreatePbufferARB
= X11DRV_wglCreatePbufferARB
;
3185 opengl_funcs
.ext
.p_wglDestroyPbufferARB
= X11DRV_wglDestroyPbufferARB
;
3186 opengl_funcs
.ext
.p_wglGetPbufferDCARB
= X11DRV_wglGetPbufferDCARB
;
3187 opengl_funcs
.ext
.p_wglQueryPbufferARB
= X11DRV_wglQueryPbufferARB
;
3188 opengl_funcs
.ext
.p_wglReleasePbufferDCARB
= X11DRV_wglReleasePbufferDCARB
;
3189 opengl_funcs
.ext
.p_wglSetPbufferAttribARB
= X11DRV_wglSetPbufferAttribARB
;
3192 register_extension( "WGL_ARB_pixel_format" );
3193 opengl_funcs
.ext
.p_wglChoosePixelFormatARB
= X11DRV_wglChoosePixelFormatARB
;
3194 opengl_funcs
.ext
.p_wglGetPixelFormatAttribfvARB
= X11DRV_wglGetPixelFormatAttribfvARB
;
3195 opengl_funcs
.ext
.p_wglGetPixelFormatAttribivARB
= X11DRV_wglGetPixelFormatAttribivARB
;
3197 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3198 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_render_texture") ||
3199 (glxRequireVersion(3) && use_render_texture_emulation
))
3201 register_extension( "WGL_ARB_render_texture" );
3202 opengl_funcs
.ext
.p_wglBindTexImageARB
= X11DRV_wglBindTexImageARB
;
3203 opengl_funcs
.ext
.p_wglReleaseTexImageARB
= X11DRV_wglReleaseTexImageARB
;
3205 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3206 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer"))
3207 register_extension("WGL_NV_float_buffer");
3209 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3210 if (has_extension(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle"))
3211 register_extension("WGL_NV_render_texture_rectangle");
3214 /* EXT Extensions */
3216 register_extension( "WGL_EXT_extensions_string" );
3217 opengl_funcs
.ext
.p_wglGetExtensionsStringEXT
= X11DRV_wglGetExtensionsStringEXT
;
3219 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3220 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3221 register_extension( "WGL_EXT_swap_control" );
3222 opengl_funcs
.ext
.p_wglSwapIntervalEXT
= X11DRV_wglSwapIntervalEXT
;
3223 opengl_funcs
.ext
.p_wglGetSwapIntervalEXT
= X11DRV_wglGetSwapIntervalEXT
;
3225 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_framebuffer_sRGB"))
3226 register_extension("WGL_EXT_framebuffer_sRGB");
3228 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_fbconfig_packed_float"))
3229 register_extension("WGL_EXT_pixel_format_packed_float");
3231 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_swap_control"))
3233 swap_control_method
= GLX_SWAP_CONTROL_EXT
;
3234 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_swap_control_tear"))
3236 register_extension("WGL_EXT_swap_control_tear");
3237 has_swap_control_tear
= TRUE
;
3240 else if (has_extension( WineGLInfo
.glxExtensions
, "GLX_MESA_swap_control"))
3242 swap_control_method
= GLX_SWAP_CONTROL_MESA
;
3244 else if (has_extension( WineGLInfo
.glxExtensions
, "GLX_SGI_swap_control"))
3246 swap_control_method
= GLX_SWAP_CONTROL_SGI
;
3249 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3250 if (has_extension(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range"))
3252 register_extension( "WGL_NV_vertex_array_range" );
3253 opengl_funcs
.ext
.p_wglAllocateMemoryNV
= pglXAllocateMemoryNV
;
3254 opengl_funcs
.ext
.p_wglFreeMemoryNV
= pglXFreeMemoryNV
;
3257 if (has_extension(WineGLInfo
.glxExtensions
, "GLX_OML_swap_method"))
3258 has_swap_method
= TRUE
;
3260 /* WINE-specific WGL Extensions */
3262 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3263 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3265 register_extension( "WGL_WINE_pixel_format_passthrough" );
3266 opengl_funcs
.ext
.p_wglSetPixelFormatWINE
= X11DRV_wglSetPixelFormatWINE
;
3268 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_MESA_query_renderer" ))
3270 register_extension( "WGL_WINE_query_renderer" );
3271 opengl_funcs
.ext
.p_wglQueryCurrentRendererIntegerWINE
= X11DRV_wglQueryCurrentRendererIntegerWINE
;
3272 opengl_funcs
.ext
.p_wglQueryCurrentRendererStringWINE
= X11DRV_wglQueryCurrentRendererStringWINE
;
3273 opengl_funcs
.ext
.p_wglQueryRendererIntegerWINE
= X11DRV_wglQueryRendererIntegerWINE
;
3274 opengl_funcs
.ext
.p_wglQueryRendererStringWINE
= X11DRV_wglQueryRendererStringWINE
;
3280 * glxdrv_SwapBuffers
3282 * Swap the buffers of this DC
3284 static BOOL
glxdrv_wglSwapBuffers( HDC hdc
)
3286 struct x11drv_escape_flush_gl_drawable escape
;
3287 struct gl_drawable
*gl
;
3288 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
3290 TRACE("(%p)\n", hdc
);
3292 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
3293 escape
.gl_drawable
= 0;
3295 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
3297 SetLastError( ERROR_INVALID_HANDLE
);
3301 if (gl
->refresh_swap_interval
)
3303 set_swap_interval(gl
->drawable
, gl
->swap_interval
);
3304 gl
->refresh_swap_interval
= FALSE
;
3309 case DC_GL_PIXMAP_WIN
:
3310 if (ctx
) sync_context( ctx
);
3311 escape
.gl_drawable
= gl
->pixmap
;
3312 if (pglXCopySubBufferMESA
) {
3313 /* (glX)SwapBuffers has an implicit glFlush effect, however
3314 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3317 pglXCopySubBufferMESA( gdi_display
, gl
->drawable
, 0, 0,
3318 gl
->rect
.right
- gl
->rect
.left
, gl
->rect
.bottom
- gl
->rect
.top
);
3321 pglXSwapBuffers(gdi_display
, gl
->drawable
);
3323 case DC_GL_CHILD_WIN
:
3324 if (ctx
) sync_context( ctx
);
3325 escape
.gl_drawable
= gl
->drawable
;
3328 pglXSwapBuffers(gdi_display
, gl
->drawable
);
3332 release_gl_drawable( gl
);
3334 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
3338 static struct opengl_funcs opengl_funcs
=
3341 glxdrv_wglCopyContext
, /* p_wglCopyContext */
3342 glxdrv_wglCreateContext
, /* p_wglCreateContext */
3343 glxdrv_wglDeleteContext
, /* p_wglDeleteContext */
3344 glxdrv_wglDescribePixelFormat
, /* p_wglDescribePixelFormat */
3345 glxdrv_wglGetPixelFormat
, /* p_wglGetPixelFormat */
3346 glxdrv_wglGetProcAddress
, /* p_wglGetProcAddress */
3347 glxdrv_wglMakeCurrent
, /* p_wglMakeCurrent */
3348 glxdrv_wglSetPixelFormat
, /* p_wglSetPixelFormat */
3349 glxdrv_wglShareLists
, /* p_wglShareLists */
3350 glxdrv_wglSwapBuffers
, /* p_wglSwapBuffers */
3354 struct opengl_funcs
*get_glx_driver( UINT version
)
3356 if (version
!= WINE_WGL_DRIVER_VERSION
)
3358 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version
, WINE_WGL_DRIVER_VERSION
);
3361 if (has_opengl()) return &opengl_funcs
;
3365 #else /* no OpenGL includes */
3367 struct opengl_funcs
*get_glx_driver( UINT version
)
3372 void sync_gl_drawable( HWND hwnd
, const RECT
*visible_rect
, const RECT
*client_rect
)
3376 void set_gl_drawable_parent( HWND hwnd
, HWND parent
)
3380 void destroy_gl_drawable( HWND hwnd
)
3384 #endif /* defined(SONAME_LIBGL) */