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_RGBA_BIT 0x00000001
149 #define GLX_COLOR_INDEX_BIT 0x00000002
150 #define GLX_PBUFFER_CLOBBER_MASK 0x08000000
152 /** GLX_ARB_multisample */
153 #define GLX_SAMPLE_BUFFERS_ARB 100000
154 #define GLX_SAMPLES_ARB 100001
155 /** GLX_ARB_framebuffer_sRGB */
156 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
157 /** GLX_EXT_fbconfig_packed_float */
158 #define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
159 #define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
160 /** GLX_ARB_create_context */
161 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
162 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
163 #define GLX_CONTEXT_FLAGS_ARB 0x2094
164 /** GLX_ARB_create_context_profile */
165 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
166 /** GLX_ATI_pixel_format_float */
167 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
168 /** GLX_ARB_pixel_format_float */
169 #define GLX_RGBA_FLOAT_BIT 0x00000004
170 #define GLX_RGBA_FLOAT_TYPE 0x20B9
171 /** GLX_NV_float_buffer */
172 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
176 const char *glVersion
;
181 const char *glxServerVersion
;
182 const char *glxServerVendor
;
183 const char *glxServerExtensions
;
185 const char *glxClientVersion
;
186 const char *glxClientVendor
;
187 const char *glxClientExtensions
;
189 const char *glxExtensions
;
192 char wglExtensions
[4096];
195 struct wgl_pixel_format
197 GLXFBConfig fbconfig
;
200 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
206 BOOL has_been_current
;
210 const struct wgl_pixel_format
*fmt
;
211 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
212 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
214 Drawable drawables
[2];
215 BOOL refresh_drawables
;
222 const struct wgl_pixel_format
* fmt
;
226 int use_render_texture
; /* This is also the internal texture format */
227 int texture_bind_target
;
229 GLint texture_format
;
230 GLuint texture_target
;
238 DC_GL_NONE
, /* no GL support (pixel format not set yet) */
239 DC_GL_WINDOW
, /* normal top-level window */
240 DC_GL_CHILD_WIN
, /* child window using XComposite */
241 DC_GL_PIXMAP_WIN
, /* child window using intermediate pixmap */
242 DC_GL_PBUFFER
/* pseudo memory DC using a PBuffer */
247 enum dc_gl_type type
; /* type of GL surface */
248 Drawable drawable
; /* drawable for rendering to the client area */
249 Pixmap pixmap
; /* base pixmap if drawable is a GLXPixmap */
250 Colormap colormap
; /* colormap used for the drawable */
251 const struct wgl_pixel_format
*format
; /* pixel format for the drawable */
252 XVisualInfo
*visual
; /* information about the GL visual */
253 RECT rect
; /* drawable rect, relative to whole window drawable */
257 enum glx_swap_control_method
259 GLX_SWAP_CONTROL_NONE
,
260 GLX_SWAP_CONTROL_EXT
,
261 GLX_SWAP_CONTROL_SGI
,
262 GLX_SWAP_CONTROL_MESA
265 /* X context to associate a struct gl_drawable to an hwnd */
266 static XContext gl_hwnd_context
;
267 /* X context to associate a struct gl_drawable to a pbuffer hdc */
268 static XContext gl_pbuffer_context
;
270 static const struct gdi_dc_funcs glxdrv_funcs
;
272 static inline struct glx_physdev
*get_glxdrv_dev( PHYSDEV dev
)
274 return (struct glx_physdev
*)dev
;
277 static struct list context_list
= LIST_INIT( context_list
);
278 static struct WineGLInfo WineGLInfo
= { 0 };
279 static struct wgl_pixel_format
*pixel_formats
;
280 static int nb_pixel_formats
, nb_onscreen_formats
;
281 static BOOL use_render_texture_emulation
= TRUE
;
283 /* Selects the preferred GLX swap control method for use by wglSwapIntervalEXT */
284 static enum glx_swap_control_method swap_control_method
= GLX_SWAP_CONTROL_NONE
;
285 /* Set when GLX_EXT_swap_control_tear is supported, requires GLX_SWAP_CONTROL_EXT */
286 static BOOL has_swap_control_tear
= FALSE
;
288 static CRITICAL_SECTION context_section
;
289 static CRITICAL_SECTION_DEBUG critsect_debug
=
291 0, 0, &context_section
,
292 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
293 0, 0, { (DWORD_PTR
)(__FILE__
": context_section") }
295 static CRITICAL_SECTION context_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
297 static const BOOL is_win64
= sizeof(void *) > sizeof(int);
299 static struct opengl_funcs opengl_funcs
;
301 #define USE_GL_FUNC(name) #name,
302 static const char *opengl_func_names
[] = { ALL_WGL_FUNCS
};
305 static void X11DRV_WineGL_LoadExtensions(void);
306 static void init_pixel_formats( Display
*display
);
307 static BOOL
glxRequireVersion(int requiredVersion
);
309 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
310 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
311 TRACE(" - dwFlags : ");
312 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
313 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
314 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
315 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
316 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
317 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
318 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
319 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
320 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
321 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
322 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
323 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
324 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
325 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
326 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
327 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
328 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
329 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
330 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
331 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
335 TRACE(" - iPixelType : ");
336 switch (ppfd
->iPixelType
) {
337 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
338 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
342 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
343 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
344 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
345 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
346 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
347 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
348 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
349 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
350 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
352 TRACE(" - iLayerType : ");
353 switch (ppfd
->iLayerType
) {
354 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
355 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
356 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
361 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
362 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
365 static XVisualInfo
* (*pglXChooseVisual
)( Display
*dpy
, int screen
, int *attribList
);
366 static GLXContext (*pglXCreateContext
)( Display
*dpy
, XVisualInfo
*vis
, GLXContext shareList
, Bool direct
);
367 static void (*pglXDestroyContext
)( Display
*dpy
, GLXContext ctx
);
368 static Bool (*pglXMakeCurrent
)( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
);
369 static void (*pglXCopyContext
)( Display
*dpy
, GLXContext src
, GLXContext dst
, unsigned long mask
);
370 static void (*pglXSwapBuffers
)( Display
*dpy
, GLXDrawable drawable
);
371 static GLXPixmap (*pglXCreateGLXPixmap
)( Display
*dpy
, XVisualInfo
*visual
, Pixmap pixmap
);
372 static void (*pglXDestroyGLXPixmap
)( Display
*dpy
, GLXPixmap pixmap
);
373 static Bool (*pglXQueryExtension
)( Display
*dpy
, int *errorb
, int *event
);
374 static Bool (*pglXQueryVersion
)( Display
*dpy
, int *maj
, int *min
);
375 static Bool (*pglXIsDirect
)( Display
*dpy
, GLXContext ctx
);
376 static int (*pglXGetConfig
)( Display
*dpy
, XVisualInfo
*visual
, int attrib
, int *value
);
377 static GLXContext (*pglXGetCurrentContext
)( void );
378 static GLXDrawable (*pglXGetCurrentDrawable
)( void );
381 static const char *(*pglXQueryExtensionsString
)( Display
*dpy
, int screen
);
382 static const char *(*pglXQueryServerString
)( Display
*dpy
, int screen
, int name
);
383 static const char *(*pglXGetClientString
)( Display
*dpy
, int name
);
386 static GLXFBConfig
*(*pglXChooseFBConfig
)( Display
*dpy
, int screen
, const int *attribList
, int *nitems
);
387 static int (*pglXGetFBConfigAttrib
)( Display
*dpy
, GLXFBConfig config
, int attribute
, int *value
);
388 static GLXFBConfig
*(*pglXGetFBConfigs
)( Display
*dpy
, int screen
, int *nelements
);
389 static XVisualInfo
*(*pglXGetVisualFromFBConfig
)( Display
*dpy
, GLXFBConfig config
);
390 static GLXPbuffer (*pglXCreatePbuffer
)( Display
*dpy
, GLXFBConfig config
, const int *attribList
);
391 static void (*pglXDestroyPbuffer
)( Display
*dpy
, GLXPbuffer pbuf
);
392 static void (*pglXQueryDrawable
)( Display
*dpy
, GLXDrawable draw
, int attribute
, unsigned int *value
);
393 static GLXContext (*pglXCreateNewContext
)( Display
*dpy
, GLXFBConfig config
, int renderType
, GLXContext shareList
, Bool direct
);
394 static Bool (*pglXMakeContextCurrent
)( Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
);
397 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
398 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
399 static void (*pglXSwapIntervalEXT
)(Display
*dpy
, GLXDrawable drawable
, int interval
);
400 static int (*pglXSwapIntervalSGI
)(int);
402 /* NV GLX Extension */
403 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
404 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
406 /* MESA GLX Extensions */
407 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
408 static int (*pglXSwapIntervalMESA
)(unsigned int interval
);
410 /* Standard OpenGL */
411 static void (*pglFinish
)(void);
412 static void (*pglFlush
)(void);
413 static const GLubyte
*(*pglGetString
)(GLenum name
);
415 static void wglFinish(void);
416 static void wglFlush(void);
417 static const GLubyte
*wglGetString(GLenum name
);
419 /* check if the extension is present in the list */
420 static BOOL
has_extension( const char *list
, const char *ext
)
422 size_t len
= strlen( ext
);
426 while (*list
== ' ') list
++;
427 if (!strncmp( list
, ext
, len
) && (!list
[len
] || list
[len
] == ' ')) return TRUE
;
428 list
= strchr( list
, ' ' );
433 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
435 /* In the future we might want to find the exact X or GLX error to report back to the app */
439 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
441 static const char legacy_extensions
[] = " WGL_EXT_extensions_string WGL_EXT_swap_control";
443 int screen
= DefaultScreen(gdi_display
);
444 Window win
= 0, root
= 0;
445 const char *gl_renderer
;
448 GLXContext ctx
= NULL
;
449 XSetWindowAttributes attr
;
451 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
453 attr
.override_redirect
= True
;
454 attr
.colormap
= None
;
455 attr
.border_pixel
= 0;
457 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
460 WORD old_fs
= wine_get_fs();
461 /* Create a GLX Context. Without one we can't query GL information */
462 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
463 if (wine_get_fs() != old_fs
)
465 wine_set_fs( old_fs
);
466 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
467 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
471 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
476 root
= RootWindow( gdi_display
, vis
->screen
);
477 if (vis
->visual
!= DefaultVisual( gdi_display
, vis
->screen
))
478 attr
.colormap
= XCreateColormap( gdi_display
, root
, vis
->visual
, AllocNone
);
479 if ((win
= XCreateWindow( gdi_display
, root
, -1, -1, 1, 1, 0, vis
->depth
, InputOutput
,
480 vis
->visual
, CWBorderPixel
| CWOverrideRedirect
| CWColormap
, &attr
)))
481 XMapWindow( gdi_display
, win
);
485 if(pglXMakeCurrent(gdi_display
, win
, ctx
) == 0)
487 ERR_(winediag
)( "Unable to activate OpenGL context, most likely your %s OpenGL drivers haven't been "
488 "installed correctly\n", is_win64
? "64-bit" : "32-bit" );
491 gl_renderer
= (const char *)opengl_funcs
.gl
.p_glGetString(GL_RENDERER
);
492 WineGLInfo
.glVersion
= (const char *) opengl_funcs
.gl
.p_glGetString(GL_VERSION
);
493 str
= (const char *) opengl_funcs
.gl
.p_glGetString(GL_EXTENSIONS
);
494 WineGLInfo
.glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+sizeof(legacy_extensions
));
495 strcpy(WineGLInfo
.glExtensions
, str
);
496 strcat(WineGLInfo
.glExtensions
, legacy_extensions
);
498 /* Get the common GLX version supported by GLX client and server ( major/minor) */
499 pglXQueryVersion(gdi_display
, &WineGLInfo
.glxVersion
[0], &WineGLInfo
.glxVersion
[1]);
501 WineGLInfo
.glxServerVersion
= pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
);
502 WineGLInfo
.glxServerVendor
= pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
);
503 WineGLInfo
.glxServerExtensions
= pglXQueryServerString(gdi_display
, screen
, GLX_EXTENSIONS
);
505 WineGLInfo
.glxClientVersion
= pglXGetClientString(gdi_display
, GLX_VERSION
);
506 WineGLInfo
.glxClientVendor
= pglXGetClientString(gdi_display
, GLX_VENDOR
);
507 WineGLInfo
.glxClientExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
509 WineGLInfo
.glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
510 WineGLInfo
.glxDirect
= pglXIsDirect(gdi_display
, ctx
);
512 TRACE("GL version : %s.\n", WineGLInfo
.glVersion
);
513 TRACE("GL renderer : %s.\n", gl_renderer
);
514 TRACE("GLX version : %d.%d.\n", WineGLInfo
.glxVersion
[0], WineGLInfo
.glxVersion
[1]);
515 TRACE("Server GLX version : %s.\n", WineGLInfo
.glxServerVersion
);
516 TRACE("Server GLX vendor: : %s.\n", WineGLInfo
.glxServerVendor
);
517 TRACE("Client GLX version : %s.\n", WineGLInfo
.glxClientVersion
);
518 TRACE("Client GLX vendor: : %s.\n", WineGLInfo
.glxClientVendor
);
519 TRACE("Direct rendering enabled: %s\n", WineGLInfo
.glxDirect
? "True" : "False");
521 if(!WineGLInfo
.glxDirect
)
523 int fd
= ConnectionNumber(gdi_display
);
524 struct sockaddr_un uaddr
;
525 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
527 /* In general indirect rendering on a local X11 server indicates a driver problem.
528 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
530 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
531 ERR_(winediag
)("Direct rendering is disabled, most likely your %s OpenGL drivers "
532 "haven't been installed correctly (using GL renderer %s, version %s).\n",
533 is_win64
? "64-bit" : "32-bit", debugstr_a(gl_renderer
),
534 debugstr_a(WineGLInfo
.glVersion
));
538 /* In general you would expect that if direct rendering is returned, that you receive hardware
539 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
540 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
541 * software rendering, it shows direct rendering.
543 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
544 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
545 * it shows 'Mesa X11'.
547 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
548 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your %s OpenGL "
549 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
550 is_win64
? "64-bit" : "32-bit", debugstr_a(gl_renderer
),
551 debugstr_a(WineGLInfo
.glVersion
));
558 pglXMakeCurrent(gdi_display
, None
, NULL
);
559 pglXDestroyContext(gdi_display
, ctx
);
561 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
562 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
563 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
567 static BOOL
has_opengl(void)
569 static BOOL init_done
= FALSE
;
570 static void *opengl_handle
;
573 int error_base
, event_base
;
576 if (init_done
) return (opengl_handle
!= NULL
);
579 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
580 and include all dependencies */
581 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
582 if (opengl_handle
== NULL
)
584 ERR( "Failed to load libGL: %s\n", buffer
);
585 ERR( "OpenGL support is disabled.\n");
589 for (i
= 0; i
< sizeof(opengl_func_names
)/sizeof(opengl_func_names
[0]); i
++)
591 if (!(((void **)&opengl_funcs
.gl
)[i
] = wine_dlsym( opengl_handle
, opengl_func_names
[i
], NULL
, 0 )))
593 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names
[i
] );
598 /* redirect some standard OpenGL functions */
599 #define REDIRECT(func) \
600 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
601 REDIRECT( glFinish
);
603 REDIRECT( glGetString
);
606 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
607 if (pglXGetProcAddressARB
== NULL
) {
608 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
612 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
614 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
619 LOAD_FUNCPTR(glXChooseVisual
);
620 LOAD_FUNCPTR(glXCopyContext
);
621 LOAD_FUNCPTR(glXCreateContext
);
622 LOAD_FUNCPTR(glXCreateGLXPixmap
);
623 LOAD_FUNCPTR(glXGetCurrentContext
);
624 LOAD_FUNCPTR(glXGetCurrentDrawable
);
625 LOAD_FUNCPTR(glXDestroyContext
);
626 LOAD_FUNCPTR(glXDestroyGLXPixmap
);
627 LOAD_FUNCPTR(glXGetConfig
);
628 LOAD_FUNCPTR(glXIsDirect
);
629 LOAD_FUNCPTR(glXMakeCurrent
);
630 LOAD_FUNCPTR(glXSwapBuffers
);
631 LOAD_FUNCPTR(glXQueryExtension
);
632 LOAD_FUNCPTR(glXQueryVersion
);
635 LOAD_FUNCPTR(glXGetClientString
);
636 LOAD_FUNCPTR(glXQueryExtensionsString
);
637 LOAD_FUNCPTR(glXQueryServerString
);
640 LOAD_FUNCPTR(glXCreatePbuffer
);
641 LOAD_FUNCPTR(glXCreateNewContext
);
642 LOAD_FUNCPTR(glXDestroyPbuffer
);
643 LOAD_FUNCPTR(glXMakeContextCurrent
);
644 LOAD_FUNCPTR(glXGetFBConfigs
);
647 /* It doesn't matter if these fail. They'll only be used if the driver reports
648 the associated extension is available (and if a driver reports the extension
649 is available but fails to provide the functions, it's quite broken) */
650 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
651 /* ARB GLX Extension */
652 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
653 /* EXT GLX Extension */
654 LOAD_FUNCPTR(glXSwapIntervalEXT
);
655 /* MESA GLX Extension */
656 LOAD_FUNCPTR(glXSwapIntervalMESA
);
657 /* SGI GLX Extension */
658 LOAD_FUNCPTR(glXSwapIntervalSGI
);
659 /* NV GLX Extension */
660 LOAD_FUNCPTR(glXAllocateMemoryNV
);
661 LOAD_FUNCPTR(glXFreeMemoryNV
);
664 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
666 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
667 TRACE("GLX is up and running error_base = %d\n", error_base
);
669 ERR( "GLX extension is missing, disabling OpenGL.\n" );
672 gl_hwnd_context
= XUniqueContext();
673 gl_pbuffer_context
= XUniqueContext();
675 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
676 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
679 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
680 * depends on the reported GLX client / server version and on the client / server extension list.
681 * Those don't have to be the same.
683 * In general the server GLX information lists the capabilities in case of indirect rendering.
684 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
685 * available and in that case the client GLX informat can be used.
686 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
687 * in the GLX version/extension list. When a program does this it works for certain for both
688 * direct and indirect rendering.
690 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
691 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
692 * extension list which causes this extension not to be listed. (Wine requires this extension).
693 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
694 * pbuffers is around.
696 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
697 * the ATI drivers and from then on use GLX client information for them.
700 if(glxRequireVersion(3)) {
701 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
702 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
703 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
704 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
705 } else if (has_extension( WineGLInfo
.glxExtensions
, "GLX_SGIX_fbconfig")) {
706 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
707 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
708 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
710 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
711 * enable this function when the Xserver understand GLX 1.3 or newer
713 pglXQueryDrawable
= NULL
;
714 } else if(strcmp("ATI", WineGLInfo
.glxClientVendor
) == 0) {
715 TRACE("Overriding ATI GLX capabilities!\n");
716 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
717 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
718 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
719 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
721 /* Use client GLX information in case of the ATI drivers. We override the
722 * capabilities over here and not somewhere else as ATI might better their
723 * life in the future. In case they release proper drivers this block of
724 * code won't be called. */
725 WineGLInfo
.glxExtensions
= WineGLInfo
.glxClientExtensions
;
727 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo
.glxServerVersion
);
730 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_MESA_copy_sub_buffer")) {
731 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
734 X11DRV_WineGL_LoadExtensions();
735 init_pixel_formats( gdi_display
);
739 wine_dlclose(opengl_handle
, NULL
, 0);
740 opengl_handle
= NULL
;
744 static int describeContext( struct wgl_context
*ctx
) {
747 TRACE(" Context %p have (vis:%p):\n", ctx
, ctx
->vis
);
748 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_FBCONFIG_ID
, &tmp
);
749 TRACE(" - FBCONFIG_ID 0x%x\n", tmp
);
750 pglXGetFBConfigAttrib(gdi_display
, ctx
->fmt
->fbconfig
, GLX_VISUAL_ID
, &tmp
);
751 TRACE(" - VISUAL_ID 0x%x\n", tmp
);
756 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, struct wgl_pbuffer
* pbuf
) {
761 int nvfloatattrib
= GLX_DONT_CARE
;
762 int pixelattrib
= GLX_DONT_CARE
;
764 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
765 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
766 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
767 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
769 switch (iWGLAttr
[cur
]) {
770 case WGL_AUX_BUFFERS_ARB
:
771 pop
= iWGLAttr
[++cur
];
772 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
773 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
775 case WGL_COLOR_BITS_ARB
:
776 pop
= iWGLAttr
[++cur
];
777 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
778 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
780 case WGL_BLUE_BITS_ARB
:
781 pop
= iWGLAttr
[++cur
];
782 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
783 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
785 case WGL_RED_BITS_ARB
:
786 pop
= iWGLAttr
[++cur
];
787 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
788 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
790 case WGL_GREEN_BITS_ARB
:
791 pop
= iWGLAttr
[++cur
];
792 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
793 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
795 case WGL_ALPHA_BITS_ARB
:
796 pop
= iWGLAttr
[++cur
];
797 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
798 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
800 case WGL_DEPTH_BITS_ARB
:
801 pop
= iWGLAttr
[++cur
];
802 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
803 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
805 case WGL_STENCIL_BITS_ARB
:
806 pop
= iWGLAttr
[++cur
];
807 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
808 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
810 case WGL_DOUBLE_BUFFER_ARB
:
811 pop
= iWGLAttr
[++cur
];
812 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
813 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
816 pop
= iWGLAttr
[++cur
];
817 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
818 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
821 case WGL_PIXEL_TYPE_ARB
:
822 pop
= iWGLAttr
[++cur
];
823 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
825 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
826 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
827 /* 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 */
828 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
829 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
831 ERR("unexpected PixelType(%x)\n", pop
);
836 case WGL_SUPPORT_GDI_ARB
:
837 /* This flag is set in a pixel format */
838 pop
= iWGLAttr
[++cur
];
839 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
842 case WGL_DRAW_TO_BITMAP_ARB
:
843 /* This flag is set in a pixel format */
844 pop
= iWGLAttr
[++cur
];
845 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
848 case WGL_DRAW_TO_WINDOW_ARB
:
849 pop
= iWGLAttr
[++cur
];
850 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
851 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
853 drawattrib
|= GLX_WINDOW_BIT
;
857 case WGL_DRAW_TO_PBUFFER_ARB
:
858 pop
= iWGLAttr
[++cur
];
859 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
860 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
862 drawattrib
|= GLX_PBUFFER_BIT
;
866 case WGL_ACCELERATION_ARB
:
867 /* This flag is set in a pixel format */
868 pop
= iWGLAttr
[++cur
];
869 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
872 case WGL_SUPPORT_OPENGL_ARB
:
873 pop
= iWGLAttr
[++cur
];
874 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
875 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
878 case WGL_SWAP_METHOD_ARB
:
879 pop
= iWGLAttr
[++cur
];
880 /* For now we ignore this and just return SWAP_EXCHANGE */
881 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
884 case WGL_PBUFFER_LARGEST_ARB
:
885 pop
= iWGLAttr
[++cur
];
886 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
887 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
890 case WGL_SAMPLE_BUFFERS_ARB
:
891 pop
= iWGLAttr
[++cur
];
892 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
893 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
896 case WGL_SAMPLES_ARB
:
897 pop
= iWGLAttr
[++cur
];
898 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
899 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
902 case WGL_TEXTURE_FORMAT_ARB
:
903 case WGL_TEXTURE_TARGET_ARB
:
904 case WGL_MIPMAP_TEXTURE_ARB
:
905 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
906 pop
= iWGLAttr
[++cur
];
908 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
910 if (!use_render_texture_emulation
) {
911 if (WGL_NO_TEXTURE_ARB
!= pop
) {
912 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
913 return -1; /** error: don't support it */
915 drawattrib
|= GLX_PBUFFER_BIT
;
919 case WGL_FLOAT_COMPONENTS_NV
:
920 nvfloatattrib
= iWGLAttr
[++cur
];
921 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
923 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
924 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
925 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
926 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
927 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
928 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
929 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
930 pop
= iWGLAttr
[++cur
];
931 /** cannot be converted, see direct handling on
932 * - wglGetPixelFormatAttribivARB
933 * TODO: wglChoosePixelFormat
936 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
937 pop
= iWGLAttr
[++cur
];
938 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
939 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
942 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
943 pop
= iWGLAttr
[++cur
];
944 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
945 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
948 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
955 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
956 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
957 * pixmap and pbuffer formats appear as well. */
958 if (!drawattrib
) drawattrib
= GLX_DONT_CARE
;
959 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
960 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
962 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
963 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
964 * GLX_DONT_CARE unless it is overridden. */
965 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
966 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
968 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
969 if (has_extension(WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer")) {
970 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
971 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
977 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
979 int render_type
=0, render_type_bit
;
980 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
981 switch(render_type_bit
)
984 render_type
= GLX_RGBA_TYPE
;
986 case GLX_COLOR_INDEX_BIT
:
987 render_type
= GLX_COLOR_INDEX_TYPE
;
989 case GLX_RGBA_FLOAT_BIT
:
990 render_type
= GLX_RGBA_FLOAT_TYPE
;
992 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
993 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
996 ERR("Unknown render_type: %x\n", render_type_bit
);
1001 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
1002 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
1005 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
1006 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1008 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
1009 * the GLX_PIXMAP_BIT set. */
1010 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
1013 static void init_pixel_formats( Display
*display
)
1015 struct wgl_pixel_format
*list
;
1016 int size
= 0, onscreen_size
= 0;
1017 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
1019 XVisualInfo
*visinfo
;
1021 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
1022 if (NULL
== cfgs
|| 0 == nCfgs
) {
1023 if(cfgs
!= NULL
) XFree(cfgs
);
1024 ERR("glXChooseFBConfig returns NULL\n");
1028 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
1029 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
1030 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
1031 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
1033 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
1035 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
1037 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1040 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
1042 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
) * sizeof(*list
));
1044 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
1045 * Do this as GLX doesn't guarantee that the list is sorted */
1046 for(run
=0; run
< 2; run
++)
1048 for(i
=0; i
<nCfgs
; i
++) {
1049 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
1050 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
1052 /* The first run we only add onscreen formats (ones which have an associated X Visual).
1053 * The second run we only set offscreen formats. */
1056 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
1057 * The contents is copied to the destination using XCopyArea. For the copying to work
1058 * the depth of the source and destination window should be the same. In general this should
1059 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
1060 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
1061 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
1062 * list formats with the same depth. */
1063 if(visinfo
->depth
!= default_visual
.depth
)
1069 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1070 list
[size
].fbconfig
= cfgs
[i
];
1071 list
[size
].fmt_id
= fmt_id
;
1072 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1073 list
[size
].dwFlags
= 0;
1077 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1078 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1080 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1081 list
[size
].fbconfig
= cfgs
[i
];
1082 list
[size
].fmt_id
= fmt_id
;
1083 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1084 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
1088 } else if(run
&& !visinfo
) {
1089 int window_drawable
=0;
1090 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
1092 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1093 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1094 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1095 * likely make our child window opengl rendering more complicated since likely you can't use
1096 * XCopyArea on a GLX Window.
1097 * For now ignore fbconfigs which are window drawable but lack a visual. */
1098 if(window_drawable
& GLX_WINDOW_BIT
)
1100 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
1104 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1105 list
[size
].fbconfig
= cfgs
[i
];
1106 list
[size
].fmt_id
= fmt_id
;
1107 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1108 list
[size
].dwFlags
= 0;
1112 if (visinfo
) XFree(visinfo
);
1118 pixel_formats
= list
;
1119 nb_pixel_formats
= size
;
1120 nb_onscreen_formats
= onscreen_size
;
1123 static inline BOOL
is_valid_pixel_format( int format
)
1125 return format
> 0 && format
<= nb_pixel_formats
;
1128 static inline BOOL
is_onscreen_pixel_format( int format
)
1130 return format
> 0 && format
<= nb_onscreen_formats
;
1133 static inline int pixel_format_index( const struct wgl_pixel_format
*format
)
1135 return format
- pixel_formats
+ 1;
1138 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1139 * In our WGL implementation we only support a subset of these formats namely the format of
1140 * Wine's main visual and offscreen formats (if they are available).
1141 * This function converts a WGL format to its corresponding GLX one.
1143 static const struct wgl_pixel_format
*get_pixel_format(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
)
1145 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1146 * iPixelFormat in case of probing the number of pixelformats.
1148 if (is_valid_pixel_format( iPixelFormat
) &&
1149 (is_onscreen_pixel_format( iPixelFormat
) || AllowOffscreen
)) {
1150 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1151 pixel_formats
[iPixelFormat
-1].fmt_id
, iPixelFormat
);
1152 return &pixel_formats
[iPixelFormat
-1];
1157 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1158 static void mark_drawable_dirty(Drawable old
, Drawable
new)
1160 struct wgl_context
*ctx
;
1162 LIST_FOR_EACH_ENTRY( ctx
, &context_list
, struct wgl_context
, entry
)
1164 if (old
== ctx
->drawables
[0]) {
1165 ctx
->drawables
[0] = new;
1166 ctx
->refresh_drawables
= TRUE
;
1168 if (old
== ctx
->drawables
[1]) {
1169 ctx
->drawables
[1] = new;
1170 ctx
->refresh_drawables
= TRUE
;
1175 /* Given the current context, make sure its drawable is sync'd */
1176 static inline void sync_context(struct wgl_context
*context
)
1178 if (context
->refresh_drawables
) {
1179 if (glxRequireVersion(3))
1180 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0],
1181 context
->drawables
[1], context
->ctx
);
1183 pglXMakeCurrent(gdi_display
, context
->drawables
[0], context
->ctx
);
1184 context
->refresh_drawables
= FALSE
;
1188 static struct gl_drawable
*get_gl_drawable( HWND hwnd
, HDC hdc
)
1190 struct gl_drawable
*gl
;
1192 EnterCriticalSection( &context_section
);
1193 if (hwnd
&& !XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&gl
)) return gl
;
1194 if (hdc
&& !XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&gl
)) return gl
;
1195 LeaveCriticalSection( &context_section
);
1199 static void release_gl_drawable( struct gl_drawable
*gl
)
1201 if (gl
) LeaveCriticalSection( &context_section
);
1204 static GLXContext
create_glxcontext(Display
*display
, struct wgl_context
*context
, GLXContext shareList
)
1208 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1209 BOOL indirect
= !(context
->fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
);
1211 if(context
->gl3_context
)
1213 if(context
->numAttribs
)
1214 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, context
->attribList
);
1216 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, indirect
, NULL
);
1218 else if(context
->vis
)
1219 ctx
= pglXCreateContext(gdi_display
, context
->vis
, shareList
, indirect
);
1220 else /* Create a GLX Context for a pbuffer */
1221 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1227 /***********************************************************************
1230 static void free_gl_drawable( struct gl_drawable
*gl
)
1234 case DC_GL_CHILD_WIN
:
1235 XDestroyWindow( gdi_display
, gl
->drawable
);
1236 XFreeColormap( gdi_display
, gl
->colormap
);
1238 case DC_GL_PIXMAP_WIN
:
1239 pglXDestroyGLXPixmap( gdi_display
, gl
->drawable
);
1240 XFreePixmap( gdi_display
, gl
->pixmap
);
1245 if (gl
->visual
) XFree( gl
->visual
);
1246 HeapFree( GetProcessHeap(), 0, gl
);
1250 /***********************************************************************
1251 * create_gl_drawable
1253 static BOOL
create_gl_drawable( HWND hwnd
, HWND parent
, struct gl_drawable
*gl
)
1256 /* Default GLX and WGL swap interval is 1, but in case of glXSwapIntervalSGI
1257 * there is no way to query it, so we have to store it here.
1259 gl
->swap_interval
= 1;
1261 if (GetAncestor( hwnd
, GA_PARENT
) == GetDesktopWindow()) /* top-level window */
1263 struct x11drv_win_data
*data
= get_win_data( hwnd
);
1267 gl
->type
= DC_GL_WINDOW
;
1268 gl
->drawable
= create_client_window( data
, gl
->visual
);
1269 release_win_data( data
);
1272 #ifdef SONAME_LIBXCOMPOSITE
1273 else if(usexcomposite
)
1275 static Window dummy_parent
;
1276 XSetWindowAttributes attrib
;
1278 attrib
.override_redirect
= True
;
1281 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, default_visual
.depth
,
1282 InputOutput
, default_visual
.visual
, CWOverrideRedirect
, &attrib
);
1283 XMapWindow( gdi_display
, dummy_parent
);
1285 gl
->colormap
= XCreateColormap(gdi_display
, dummy_parent
, gl
->visual
->visual
,
1286 (gl
->visual
->class == PseudoColor
||
1287 gl
->visual
->class == GrayScale
||
1288 gl
->visual
->class == DirectColor
) ?
1289 AllocAll
: AllocNone
);
1290 attrib
.colormap
= gl
->colormap
;
1291 XInstallColormap(gdi_display
, attrib
.colormap
);
1293 gl
->type
= DC_GL_CHILD_WIN
;
1294 gl
->drawable
= XCreateWindow( gdi_display
, dummy_parent
, 0, 0,
1295 gl
->rect
.right
- gl
->rect
.left
, gl
->rect
.bottom
- gl
->rect
.top
,
1296 0, gl
->visual
->depth
, InputOutput
, gl
->visual
->visual
,
1297 CWColormap
| CWOverrideRedirect
, &attrib
);
1300 pXCompositeRedirectWindow(gdi_display
, gl
->drawable
, CompositeRedirectManual
);
1301 XMapWindow(gdi_display
, gl
->drawable
);
1303 else XFreeColormap( gdi_display
, gl
->colormap
);
1308 WARN("XComposite is not available, using GLXPixmap hack\n");
1310 gl
->type
= DC_GL_PIXMAP_WIN
;
1311 gl
->pixmap
= XCreatePixmap( gdi_display
, root_window
,
1312 gl
->rect
.right
- gl
->rect
.left
, gl
->rect
.bottom
- gl
->rect
.top
,
1313 gl
->visual
->depth
);
1316 gl
->drawable
= pglXCreateGLXPixmap( gdi_display
, gl
->visual
, gl
->pixmap
);
1317 if (!gl
->drawable
) XFreePixmap( gdi_display
, gl
->pixmap
);
1321 return gl
->drawable
!= 0;
1325 /***********************************************************************
1328 static BOOL
set_win_format( HWND hwnd
, const struct wgl_pixel_format
*format
)
1330 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
1331 struct gl_drawable
*gl
, *prev
;
1333 gl
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*gl
) );
1334 gl
->format
= format
;
1335 gl
->visual
= pglXGetVisualFromFBConfig( gdi_display
, format
->fbconfig
);
1338 HeapFree( GetProcessHeap(), 0, gl
);
1342 GetClientRect( hwnd
, &gl
->rect
);
1343 gl
->rect
.right
= min( max( 1, gl
->rect
.right
), 65535 );
1344 gl
->rect
.bottom
= min( max( 1, gl
->rect
.bottom
), 65535 );
1346 if (!create_gl_drawable( hwnd
, parent
, gl
))
1348 XFree( gl
->visual
);
1349 HeapFree( GetProcessHeap(), 0, gl
);
1353 TRACE("created GL drawable %lx for win %p format %x\n", gl
->drawable
, hwnd
, format
->fmt_id
);
1355 XFlush( gdi_display
);
1357 EnterCriticalSection( &context_section
);
1358 if (!XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&prev
))
1359 free_gl_drawable( prev
);
1360 XSaveContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char *)gl
);
1361 LeaveCriticalSection( &context_section
);
1363 __wine_set_pixel_format( hwnd
, pixel_format_index( format
));
1367 /***********************************************************************
1370 void sync_gl_drawable( HWND hwnd
, const RECT
*visible_rect
, const RECT
*client_rect
)
1372 struct gl_drawable
*gl
;
1376 XWindowChanges changes
;
1378 changes
.width
= min( max( 1, client_rect
->right
- client_rect
->left
), 65535 );
1379 changes
.height
= min( max( 1, client_rect
->bottom
- client_rect
->top
), 65535 );
1381 if (!(gl
= get_gl_drawable( hwnd
, 0 ))) return;
1383 if (changes
.width
!= gl
->rect
.right
- gl
->rect
.left
) mask
|= CWWidth
;
1384 if (changes
.height
!= gl
->rect
.bottom
- gl
->rect
.top
) mask
|= CWHeight
;
1386 TRACE( "setting drawable %lx size %dx%d\n", gl
->drawable
, changes
.width
, changes
.height
);
1390 case DC_GL_CHILD_WIN
:
1391 if (mask
) XConfigureWindow( gdi_display
, gl
->drawable
, mask
, &changes
);
1393 case DC_GL_PIXMAP_WIN
:
1395 pix
= XCreatePixmap(gdi_display
, root_window
, changes
.width
, changes
.height
, gl
->visual
->depth
);
1396 if (!pix
) goto done
;
1397 glxp
= pglXCreateGLXPixmap(gdi_display
, gl
->visual
, pix
);
1400 XFreePixmap(gdi_display
, pix
);
1403 mark_drawable_dirty(gl
->drawable
, glxp
);
1404 XFlush( gdi_display
);
1406 XFreePixmap(gdi_display
, gl
->pixmap
);
1407 pglXDestroyGLXPixmap(gdi_display
, gl
->drawable
);
1408 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, gl
->drawable
);
1411 gl
->drawable
= glxp
;
1416 SetRect( &gl
->rect
, 0, 0, changes
.width
, changes
.height
);
1418 release_gl_drawable( gl
);
1422 /***********************************************************************
1423 * set_gl_drawable_parent
1425 void set_gl_drawable_parent( HWND hwnd
, HWND parent
)
1427 struct gl_drawable
*gl
;
1428 Drawable old_drawable
;
1430 if (!(gl
= get_gl_drawable( hwnd
, 0 ))) return;
1432 TRACE( "setting drawable %lx parent %p\n", gl
->drawable
, parent
);
1434 old_drawable
= gl
->drawable
;
1439 case DC_GL_CHILD_WIN
:
1440 if (parent
!= GetDesktopWindow()) goto done
;
1441 XDestroyWindow( gdi_display
, gl
->drawable
);
1442 XFreeColormap( gdi_display
, gl
->colormap
);
1444 case DC_GL_PIXMAP_WIN
:
1445 if (parent
!= GetDesktopWindow()) goto done
;
1446 pglXDestroyGLXPixmap( gdi_display
, gl
->drawable
);
1447 XFreePixmap( gdi_display
, gl
->pixmap
);
1453 if (!create_gl_drawable( hwnd
, parent
, gl
))
1455 XDeleteContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
);
1456 release_gl_drawable( gl
);
1457 XFree( gl
->visual
);
1458 HeapFree( GetProcessHeap(), 0, gl
);
1459 __wine_set_pixel_format( hwnd
, 0 );
1462 mark_drawable_dirty( old_drawable
, gl
->drawable
);
1465 release_gl_drawable( gl
);
1470 /***********************************************************************
1471 * destroy_gl_drawable
1473 void destroy_gl_drawable( HWND hwnd
)
1475 struct gl_drawable
*gl
;
1477 EnterCriticalSection( &context_section
);
1478 if (!XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&gl
))
1480 XDeleteContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
);
1481 free_gl_drawable( gl
);
1483 LeaveCriticalSection( &context_section
);
1488 * glxdrv_DescribePixelFormat
1490 * Get the pixel-format descriptor associated to the given id
1492 static int glxdrv_wglDescribePixelFormat( HDC hdc
, int iPixelFormat
,
1493 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1495 /*XVisualInfo *vis;*/
1498 const struct wgl_pixel_format
*fmt
;
1500 if (!has_opengl()) return 0;
1502 TRACE("(%p,%d,%d,%p)\n", hdc
, iPixelFormat
, nBytes
, ppfd
);
1504 if (!ppfd
) return nb_onscreen_formats
;
1506 /* 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 */
1507 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */);
1509 WARN("unexpected format %d\n", iPixelFormat
);
1513 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1514 ERR("Wrong structure size !\n");
1515 /* Should set error */
1519 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1520 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1523 /* These flags are always the same... */
1524 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1525 /* Now the flags extracted from the Visual */
1527 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1528 if(value
& GLX_WINDOW_BIT
)
1529 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1531 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1532 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1533 * 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
1534 * offered the GDI bit either. */
1535 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1537 /* PFD_GENERIC_FORMAT - gdi software rendering
1538 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1539 * none set - full hardware accelerated by a ICD
1541 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1542 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1544 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1546 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1547 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1549 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1552 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1553 if (value
& GLX_RGBA_BIT
)
1554 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1556 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1559 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1560 ppfd
->cColorBits
= value
;
1562 /* Red, green, blue and alpha bits / shifts */
1563 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1564 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1565 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1566 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1567 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1569 ppfd
->cRedBits
= rb
;
1570 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1571 ppfd
->cBlueBits
= bb
;
1572 ppfd
->cBlueShift
= ab
;
1573 ppfd
->cGreenBits
= gb
;
1574 ppfd
->cGreenShift
= bb
+ ab
;
1575 ppfd
->cAlphaBits
= ab
;
1576 ppfd
->cAlphaShift
= 0;
1579 ppfd
->cRedShift
= 0;
1580 ppfd
->cBlueBits
= 0;
1581 ppfd
->cBlueShift
= 0;
1582 ppfd
->cGreenBits
= 0;
1583 ppfd
->cGreenShift
= 0;
1584 ppfd
->cAlphaBits
= 0;
1585 ppfd
->cAlphaShift
= 0;
1588 /* Accum RGBA bits */
1589 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1590 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1591 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1592 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1594 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1595 ppfd
->cAccumRedBits
= rb
;
1596 ppfd
->cAccumGreenBits
= gb
;
1597 ppfd
->cAccumBlueBits
= bb
;
1598 ppfd
->cAccumAlphaBits
= ab
;
1601 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1602 ppfd
->cAuxBuffers
= value
;
1605 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1606 ppfd
->cDepthBits
= value
;
1609 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1610 ppfd
->cStencilBits
= value
;
1612 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1614 if (TRACE_ON(wgl
)) {
1615 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1618 return nb_onscreen_formats
;
1621 /***********************************************************************
1622 * glxdrv_wglGetPixelFormat
1624 static int glxdrv_wglGetPixelFormat( HDC hdc
)
1626 struct gl_drawable
*gl
;
1629 if ((gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1631 ret
= pixel_format_index( gl
->format
);
1632 /* Offscreen formats can't be used with traditional WGL calls.
1633 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1634 if (!is_onscreen_pixel_format( ret
)) ret
= 1;
1635 release_gl_drawable( gl
);
1637 TRACE( "%p -> %d\n", hdc
, ret
);
1641 /***********************************************************************
1642 * glxdrv_wglSetPixelFormat
1644 static BOOL
glxdrv_wglSetPixelFormat( HDC hdc
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1646 const struct wgl_pixel_format
*fmt
;
1648 struct gl_drawable
*gl
;
1649 HWND hwnd
= WindowFromDC( hdc
);
1651 TRACE("(%p,%d,%p)\n", hdc
, iPixelFormat
, ppfd
);
1653 if (!hwnd
|| hwnd
== GetDesktopWindow())
1655 WARN( "not a proper window DC %p/%p\n", hdc
, hwnd
);
1659 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1660 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */);
1662 ERR("Invalid iPixelFormat: %d\n", iPixelFormat
);
1666 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1667 if (!(value
& GLX_WINDOW_BIT
))
1669 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat
);
1673 if ((gl
= get_gl_drawable( hwnd
, hdc
)))
1675 int prev
= pixel_format_index( gl
->format
);
1676 release_gl_drawable( gl
);
1677 return prev
== iPixelFormat
; /* cannot change it if already set */
1680 if (TRACE_ON(wgl
)) {
1683 gl_test
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_FBCONFIG_ID
, &value
);
1685 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1687 TRACE(" FBConfig have :\n");
1688 TRACE(" - FBCONFIG_ID 0x%x\n", value
);
1689 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_VISUAL_ID
, &value
);
1690 TRACE(" - VISUAL_ID 0x%x\n", value
);
1691 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1692 TRACE(" - DRAWABLE_TYPE 0x%x\n", value
);
1696 return set_win_format( hwnd
, fmt
);
1699 /***********************************************************************
1700 * glxdrv_wglCopyContext
1702 static BOOL
glxdrv_wglCopyContext(struct wgl_context
*src
, struct wgl_context
*dst
, UINT mask
)
1704 TRACE("%p -> %p mask %#x\n", src
, dst
, mask
);
1706 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1708 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1712 /***********************************************************************
1713 * glxdrv_wglCreateContext
1715 static struct wgl_context
*glxdrv_wglCreateContext( HDC hdc
)
1717 struct wgl_context
*ret
= NULL
;
1718 struct gl_drawable
*gl
;
1720 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1722 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1726 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
))))
1729 ret
->fmt
= gl
->format
;
1730 ret
->vis
= pglXGetVisualFromFBConfig(gdi_display
, gl
->format
->fbconfig
);
1731 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1732 list_add_head( &context_list
, &ret
->entry
);
1734 release_gl_drawable( gl
);
1735 TRACE( "%p -> %p\n", hdc
, ret
);
1739 /***********************************************************************
1740 * glxdrv_wglDeleteContext
1742 static void glxdrv_wglDeleteContext(struct wgl_context
*ctx
)
1744 TRACE("(%p)\n", ctx
);
1746 EnterCriticalSection( &context_section
);
1747 list_remove( &ctx
->entry
);
1748 LeaveCriticalSection( &context_section
);
1750 if (ctx
->ctx
) pglXDestroyContext( gdi_display
, ctx
->ctx
);
1751 if (ctx
->vis
) XFree( ctx
->vis
);
1752 HeapFree( GetProcessHeap(), 0, ctx
);
1755 /***********************************************************************
1756 * glxdrv_wglGetProcAddress
1758 static PROC
glxdrv_wglGetProcAddress(LPCSTR lpszProc
)
1760 if (!strncmp(lpszProc
, "wgl", 3)) return NULL
;
1761 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1764 /***********************************************************************
1765 * glxdrv_wglMakeCurrent
1767 static BOOL
glxdrv_wglMakeCurrent(HDC hdc
, struct wgl_context
*ctx
)
1770 struct gl_drawable
*gl
;
1772 TRACE("(%p,%p)\n", hdc
, ctx
);
1776 pglXMakeCurrent(gdi_display
, None
, NULL
);
1777 NtCurrentTeb()->glContext
= NULL
;
1781 if ((gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1783 if (ctx
->fmt
!= gl
->format
)
1785 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc
, gl
->format
, ctx
, ctx
->fmt
);
1786 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1790 if (TRACE_ON(wgl
)) {
1791 describeContext(ctx
);
1792 TRACE("hdc %p drawable %lx fmt %p ctx %p\n", hdc
, gl
->drawable
, gl
->format
, ctx
->ctx
);
1795 ret
= pglXMakeCurrent(gdi_display
, gl
->drawable
, ctx
->ctx
);
1798 NtCurrentTeb()->glContext
= ctx
;
1799 ctx
->has_been_current
= TRUE
;
1801 ctx
->drawables
[0] = gl
->drawable
;
1802 ctx
->drawables
[1] = gl
->drawable
;
1803 ctx
->refresh_drawables
= FALSE
;
1807 SetLastError( ERROR_INVALID_HANDLE
);
1810 release_gl_drawable( gl
);
1811 TRACE( "%p,%p returning %d\n", hdc
, ctx
, ret
);
1815 /***********************************************************************
1816 * X11DRV_wglMakeContextCurrentARB
1818 static BOOL
X11DRV_wglMakeContextCurrentARB( HDC draw_hdc
, HDC read_hdc
, struct wgl_context
*ctx
)
1821 struct gl_drawable
*draw_gl
, *read_gl
= NULL
;
1823 TRACE("(%p,%p,%p)\n", draw_hdc
, read_hdc
, ctx
);
1827 pglXMakeCurrent(gdi_display
, None
, NULL
);
1828 NtCurrentTeb()->glContext
= NULL
;
1832 if (!pglXMakeContextCurrent
) return FALSE
;
1834 if ((draw_gl
= get_gl_drawable( WindowFromDC( draw_hdc
), draw_hdc
)))
1836 read_gl
= get_gl_drawable( WindowFromDC( read_hdc
), read_hdc
);
1837 ret
= pglXMakeContextCurrent(gdi_display
, draw_gl
->drawable
,
1838 read_gl
? read_gl
->drawable
: 0, ctx
->ctx
);
1841 ctx
->has_been_current
= TRUE
;
1842 ctx
->hdc
= draw_hdc
;
1843 ctx
->drawables
[0] = draw_gl
->drawable
;
1844 ctx
->drawables
[1] = read_gl
? read_gl
->drawable
: 0;
1845 ctx
->refresh_drawables
= FALSE
;
1846 NtCurrentTeb()->glContext
= ctx
;
1850 SetLastError( ERROR_INVALID_HANDLE
);
1852 release_gl_drawable( read_gl
);
1853 release_gl_drawable( draw_gl
);
1854 TRACE( "%p,%p,%p returning %d\n", draw_hdc
, read_hdc
, ctx
, ret
);
1858 /***********************************************************************
1859 * glxdrv_wglShareLists
1861 static BOOL
glxdrv_wglShareLists(struct wgl_context
*org
, struct wgl_context
*dest
)
1863 TRACE("(%p, %p)\n", org
, dest
);
1865 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1866 * at context creation time but in case of WGL it is done using wglShareLists.
1867 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1868 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1869 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1870 * so there delaying context creation doesn't work.
1872 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1873 * and when a program requests sharing we recreate the destination context if it hasn't been made
1874 * current or when it hasn't shared display lists before.
1877 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
1879 ERR("Could not share display lists, one of the contexts has been current already !\n");
1882 else if(dest
->sharing
)
1884 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1889 describeContext(org
);
1890 describeContext(dest
);
1892 /* Re-create the GLX context and share display lists */
1893 pglXDestroyContext(gdi_display
, dest
->ctx
);
1894 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1895 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest
->ctx
, dest
, org
->ctx
);
1897 org
->sharing
= TRUE
;
1898 dest
->sharing
= TRUE
;
1904 static void wglFinish(void)
1906 struct x11drv_escape_flush_gl_drawable escape
;
1907 struct gl_drawable
*gl
;
1908 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
1910 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
1911 escape
.gl_drawable
= 0;
1913 if ((gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), 0 )))
1917 case DC_GL_PIXMAP_WIN
: escape
.gl_drawable
= gl
->pixmap
; break;
1918 case DC_GL_CHILD_WIN
: escape
.gl_drawable
= gl
->drawable
; break;
1922 release_gl_drawable( gl
);
1926 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1929 static void wglFlush(void)
1931 struct x11drv_escape_flush_gl_drawable escape
;
1932 struct gl_drawable
*gl
;
1933 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
1935 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
1936 escape
.gl_drawable
= 0;
1938 if ((gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), 0 )))
1942 case DC_GL_PIXMAP_WIN
: escape
.gl_drawable
= gl
->pixmap
; break;
1943 case DC_GL_CHILD_WIN
: escape
.gl_drawable
= gl
->drawable
; break;
1947 release_gl_drawable( gl
);
1951 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1954 static const GLubyte
*wglGetString(GLenum name
)
1956 if (name
== GL_EXTENSIONS
&& WineGLInfo
.glExtensions
)
1957 return (const GLubyte
*)WineGLInfo
.glExtensions
;
1958 return pglGetString(name
);
1961 /***********************************************************************
1962 * X11DRV_wglCreateContextAttribsARB
1964 static struct wgl_context
*X11DRV_wglCreateContextAttribsARB( HDC hdc
, struct wgl_context
*hShareContext
,
1965 const int* attribList
)
1967 struct wgl_context
*ret
= NULL
;
1968 struct gl_drawable
*gl
;
1971 TRACE("(%p %p %p)\n", hdc
, hShareContext
, attribList
);
1973 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1975 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1979 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
))))
1982 ret
->fmt
= gl
->format
;
1983 ret
->vis
= NULL
; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1984 ret
->gl3_context
= TRUE
;
1987 int *pContextAttribList
= &ret
->attribList
[0];
1988 /* attribList consists of pairs {token, value] terminated with 0 */
1989 while(attribList
[0] != 0)
1991 TRACE("%#x %#x\n", attribList
[0], attribList
[1]);
1992 switch(attribList
[0])
1994 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
1995 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
1996 pContextAttribList
[1] = attribList
[1];
1997 pContextAttribList
+= 2;
2000 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2001 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2002 pContextAttribList
[1] = attribList
[1];
2003 pContextAttribList
+= 2;
2006 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2008 case WGL_CONTEXT_FLAGS_ARB
:
2009 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2010 pContextAttribList
[1] = attribList
[1];
2011 pContextAttribList
+= 2;
2014 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2015 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2016 pContextAttribList
[1] = attribList
[1];
2017 pContextAttribList
+= 2;
2021 ERR("Unhandled attribList pair: %#x %#x\n", attribList
[0], attribList
[1]);
2027 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2028 ret
->ctx
= create_glxcontext(gdi_display
, ret
, hShareContext
? hShareContext
->ctx
: NULL
);
2029 XSync(gdi_display
, False
);
2030 if ((err
= X11DRV_check_error()) || !ret
->ctx
)
2032 /* In the future we should convert the GLX error to a win32 one here if needed */
2033 ERR("Context creation failed (error %x)\n", err
);
2034 HeapFree( GetProcessHeap(), 0, ret
);
2037 else list_add_head( &context_list
, &ret
->entry
);
2040 release_gl_drawable( gl
);
2041 TRACE( "%p -> %p\n", hdc
, ret
);
2046 * X11DRV_wglGetExtensionsStringARB
2048 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2050 static const char *X11DRV_wglGetExtensionsStringARB(HDC hdc
)
2052 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2053 return WineGLInfo
.wglExtensions
;
2057 * X11DRV_wglCreatePbufferARB
2059 * WGL_ARB_pbuffer: wglCreatePbufferARB
2061 static struct wgl_pbuffer
*X11DRV_wglCreatePbufferARB( HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
,
2062 const int *piAttribList
)
2064 struct wgl_pbuffer
* object
= NULL
;
2065 const struct wgl_pixel_format
*fmt
= NULL
;
2069 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2071 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2072 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */);
2074 ERR("(%p): invalid pixel format %d\n", hdc
, iPixelFormat
);
2075 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2079 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2080 if (NULL
== object
) {
2081 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2084 object
->width
= iWidth
;
2085 object
->height
= iHeight
;
2088 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2089 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2090 while (piAttribList
&& 0 != *piAttribList
) {
2092 switch (*piAttribList
) {
2093 case WGL_PBUFFER_LARGEST_ARB
: {
2095 attr_v
= *piAttribList
;
2096 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2097 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2101 case WGL_TEXTURE_FORMAT_ARB
: {
2103 attr_v
= *piAttribList
;
2104 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2105 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2106 object
->use_render_texture
= 0;
2108 if (!use_render_texture_emulation
) {
2109 SetLastError(ERROR_INVALID_DATA
);
2113 case WGL_TEXTURE_RGB_ARB
:
2114 object
->use_render_texture
= GL_RGB
;
2115 object
->texture_bpp
= 3;
2116 object
->texture_format
= GL_RGB
;
2117 object
->texture_type
= GL_UNSIGNED_BYTE
;
2119 case WGL_TEXTURE_RGBA_ARB
:
2120 object
->use_render_texture
= GL_RGBA
;
2121 object
->texture_bpp
= 4;
2122 object
->texture_format
= GL_RGBA
;
2123 object
->texture_type
= GL_UNSIGNED_BYTE
;
2126 /* WGL_FLOAT_COMPONENTS_NV */
2127 case WGL_TEXTURE_FLOAT_R_NV
:
2128 object
->use_render_texture
= GL_FLOAT_R_NV
;
2129 object
->texture_bpp
= 4;
2130 object
->texture_format
= GL_RED
;
2131 object
->texture_type
= GL_FLOAT
;
2133 case WGL_TEXTURE_FLOAT_RG_NV
:
2134 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2135 object
->texture_bpp
= 8;
2136 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2137 object
->texture_type
= GL_FLOAT
;
2139 case WGL_TEXTURE_FLOAT_RGB_NV
:
2140 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2141 object
->texture_bpp
= 12;
2142 object
->texture_format
= GL_RGB
;
2143 object
->texture_type
= GL_FLOAT
;
2145 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2146 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2147 object
->texture_bpp
= 16;
2148 object
->texture_format
= GL_RGBA
;
2149 object
->texture_type
= GL_FLOAT
;
2152 ERR("Unknown texture format: %x\n", attr_v
);
2153 SetLastError(ERROR_INVALID_DATA
);
2160 case WGL_TEXTURE_TARGET_ARB
: {
2162 attr_v
= *piAttribList
;
2163 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2164 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2165 object
->texture_target
= 0;
2167 if (!use_render_texture_emulation
) {
2168 SetLastError(ERROR_INVALID_DATA
);
2172 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2173 if (iWidth
!= iHeight
) {
2174 SetLastError(ERROR_INVALID_DATA
);
2177 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2178 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2181 case WGL_TEXTURE_1D_ARB
: {
2183 SetLastError(ERROR_INVALID_DATA
);
2186 object
->texture_target
= GL_TEXTURE_1D
;
2187 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2190 case WGL_TEXTURE_2D_ARB
: {
2191 object
->texture_target
= GL_TEXTURE_2D
;
2192 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2195 case WGL_TEXTURE_RECTANGLE_NV
: {
2196 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2197 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2201 ERR("Unknown texture target: %x\n", attr_v
);
2202 SetLastError(ERROR_INVALID_DATA
);
2209 case WGL_MIPMAP_TEXTURE_ARB
: {
2211 attr_v
= *piAttribList
;
2212 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2213 if (!use_render_texture_emulation
) {
2214 SetLastError(ERROR_INVALID_DATA
);
2223 PUSH1(attribs
, None
);
2224 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2225 TRACE("new Pbuffer drawable as %lx\n", object
->drawable
);
2226 if (!object
->drawable
) {
2227 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2228 goto create_failed
; /* unexpected error */
2230 TRACE("->(%p)\n", object
);
2234 HeapFree(GetProcessHeap(), 0, object
);
2235 TRACE("->(FAILED)\n");
2240 * X11DRV_wglDestroyPbufferARB
2242 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2244 static BOOL
X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer
*object
)
2246 TRACE("(%p)\n", object
);
2248 pglXDestroyPbuffer(gdi_display
, object
->drawable
);
2249 HeapFree(GetProcessHeap(), 0, object
);
2254 * X11DRV_wglGetPbufferDCARB
2256 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2258 static HDC
X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer
*object
)
2260 struct x11drv_escape_set_drawable escape
;
2261 struct gl_drawable
*gl
, *prev
;
2264 hdc
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
);
2267 if (!(gl
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*gl
) )))
2272 gl
->type
= DC_GL_PBUFFER
;
2273 gl
->drawable
= object
->drawable
;
2274 gl
->format
= object
->fmt
;
2276 EnterCriticalSection( &context_section
);
2277 if (!XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&prev
))
2278 free_gl_drawable( prev
);
2279 XSaveContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char *)gl
);
2280 LeaveCriticalSection( &context_section
);
2282 escape
.code
= X11DRV_SET_DRAWABLE
;
2284 escape
.drawable
= object
->drawable
;
2285 escape
.mode
= IncludeInferiors
;
2286 SetRect( &escape
.dc_rect
, 0, 0, object
->width
, object
->height
);
2287 escape
.fbconfig_id
= object
->fmt
->fmt_id
;
2288 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2290 TRACE( "(%p)->(%p)\n", object
, hdc
);
2295 * X11DRV_wglQueryPbufferARB
2297 * WGL_ARB_pbuffer: wglQueryPbufferARB
2299 static BOOL
X11DRV_wglQueryPbufferARB( struct wgl_pbuffer
*object
, int iAttribute
, int *piValue
)
2301 TRACE("(%p, 0x%x, %p)\n", object
, iAttribute
, piValue
);
2303 switch (iAttribute
) {
2304 case WGL_PBUFFER_WIDTH_ARB
:
2305 pglXQueryDrawable(gdi_display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2307 case WGL_PBUFFER_HEIGHT_ARB
:
2308 pglXQueryDrawable(gdi_display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2311 case WGL_PBUFFER_LOST_ARB
:
2312 /* GLX Pbuffers cannot be lost by default. We can support this by
2313 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2314 * to receive pixel buffer clobber events, however that may or may
2315 * not give any benefit */
2316 *piValue
= GL_FALSE
;
2319 case WGL_TEXTURE_FORMAT_ARB
:
2320 if (!object
->use_render_texture
) {
2321 *piValue
= WGL_NO_TEXTURE_ARB
;
2323 if (!use_render_texture_emulation
) {
2324 SetLastError(ERROR_INVALID_HANDLE
);
2327 switch(object
->use_render_texture
) {
2329 *piValue
= WGL_TEXTURE_RGB_ARB
;
2332 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2334 /* WGL_FLOAT_COMPONENTS_NV */
2336 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2338 case GL_FLOAT_RG_NV
:
2339 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2341 case GL_FLOAT_RGB_NV
:
2342 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2344 case GL_FLOAT_RGBA_NV
:
2345 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2348 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2353 case WGL_TEXTURE_TARGET_ARB
:
2354 if (!object
->texture_target
){
2355 *piValue
= WGL_NO_TEXTURE_ARB
;
2357 if (!use_render_texture_emulation
) {
2358 SetLastError(ERROR_INVALID_DATA
);
2361 switch (object
->texture_target
) {
2362 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2363 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2364 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2365 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2370 case WGL_MIPMAP_TEXTURE_ARB
:
2371 *piValue
= GL_FALSE
; /** don't support that */
2372 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2376 FIXME("unexpected attribute %x\n", iAttribute
);
2384 * X11DRV_wglReleasePbufferDCARB
2386 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2388 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer
*object
, HDC hdc
)
2390 struct gl_drawable
*gl
;
2392 TRACE("(%p, %p)\n", object
, hdc
);
2394 EnterCriticalSection( &context_section
);
2396 if (!XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&gl
))
2398 XDeleteContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
);
2399 free_gl_drawable( gl
);
2403 LeaveCriticalSection( &context_section
);
2405 return hdc
&& DeleteDC(hdc
);
2409 * X11DRV_wglSetPbufferAttribARB
2411 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2413 static BOOL
X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer
*object
, const int *piAttribList
)
2415 GLboolean ret
= GL_FALSE
;
2417 WARN("(%p, %p): alpha-testing, report any problem\n", object
, piAttribList
);
2419 if (!object
->use_render_texture
) {
2420 SetLastError(ERROR_INVALID_HANDLE
);
2423 if (use_render_texture_emulation
) {
2430 * X11DRV_wglChoosePixelFormatARB
2432 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2434 static BOOL
X11DRV_wglChoosePixelFormatARB( HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
,
2435 UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2439 GLXFBConfig
* cfgs
= NULL
;
2449 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2450 if (NULL
!= pfAttribFList
) {
2451 FIXME("unused pfAttribFList\n");
2454 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2455 if (-1 == nAttribs
) {
2456 WARN("Cannot convert WGL to GLX attributes\n");
2459 PUSH1(attribs
, None
);
2461 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2462 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2463 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2465 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2467 switch(piAttribIList
[i
])
2469 case WGL_DRAW_TO_BITMAP_ARB
:
2470 if(piAttribIList
[i
+1])
2471 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2473 case WGL_ACCELERATION_ARB
:
2474 switch(piAttribIList
[i
+1])
2476 case WGL_NO_ACCELERATION_ARB
:
2477 dwFlags
|= PFD_GENERIC_FORMAT
;
2479 case WGL_GENERIC_ACCELERATION_ARB
:
2480 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2482 case WGL_FULL_ACCELERATION_ARB
:
2487 case WGL_SUPPORT_GDI_ARB
:
2488 if(piAttribIList
[i
+1])
2489 dwFlags
|= PFD_SUPPORT_GDI
;
2494 /* Search for FB configurations matching the requirements in attribs */
2495 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2497 WARN("Compatible Pixel Format not found\n");
2501 /* Loop through all matching formats and check if they are suitable.
2502 * Note that this function should at max return nMaxFormats different formats */
2503 for(run
=0; run
< 2; run
++)
2505 for (it
= 0; it
< nCfgs
&& pfmt_it
< nMaxFormats
; ++it
)
2507 if (pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
))
2509 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2513 /* During the first run we only want onscreen formats and during the second only offscreen */
2514 start
= run
== 1 ? nb_onscreen_formats
: 0;
2515 end
= run
== 1 ? nb_pixel_formats
: nb_onscreen_formats
;
2517 for (i
= start
; i
< end
; i
++)
2519 if (pixel_formats
[i
].fmt_id
== fmt_id
&& (pixel_formats
[i
].dwFlags
& dwFlags
) == dwFlags
)
2521 piFormats
[pfmt_it
++] = i
+ 1;
2522 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2523 it
+ 1, nCfgs
, fmt_id
, i
+ 1);
2530 *nNumFormats
= pfmt_it
;
2537 * X11DRV_wglGetPixelFormatAttribivARB
2539 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2541 static BOOL
X11DRV_wglGetPixelFormatAttribivARB( HDC hdc
, int iPixelFormat
, int iLayerPlane
,
2542 UINT nAttributes
, const int *piAttributes
, int *piValues
)
2545 const struct wgl_pixel_format
*fmt
= NULL
;
2550 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2552 if (0 < iLayerPlane
) {
2553 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2557 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2558 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2559 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2560 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */);
2562 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2565 for (i
= 0; i
< nAttributes
; ++i
) {
2566 const int curWGLAttr
= piAttributes
[i
];
2567 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2569 switch (curWGLAttr
) {
2570 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2571 piValues
[i
] = nb_pixel_formats
;
2574 case WGL_SUPPORT_OPENGL_ARB
:
2575 piValues
[i
] = GL_TRUE
;
2578 case WGL_ACCELERATION_ARB
:
2579 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2580 if (!fmt
) goto pix_error
;
2581 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2582 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2583 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2584 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2586 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2589 case WGL_TRANSPARENT_ARB
:
2590 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2591 if (!fmt
) goto pix_error
;
2592 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2593 if (hTest
) goto get_error
;
2594 piValues
[i
] = GL_FALSE
;
2595 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2598 case WGL_PIXEL_TYPE_ARB
:
2599 curGLXAttr
= GLX_RENDER_TYPE
;
2600 if (!fmt
) goto pix_error
;
2601 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2602 if (hTest
) goto get_error
;
2603 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2604 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2605 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2606 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2607 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2608 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2610 ERR("unexpected RenderType(%x)\n", tmp
);
2611 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2615 case WGL_COLOR_BITS_ARB
:
2616 curGLXAttr
= GLX_BUFFER_SIZE
;
2619 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2620 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2621 if (!use_render_texture_emulation
) {
2622 piValues
[i
] = GL_FALSE
;
2625 curGLXAttr
= GLX_RENDER_TYPE
;
2626 if (!fmt
) goto pix_error
;
2627 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2628 if (hTest
) goto get_error
;
2629 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2630 piValues
[i
] = GL_FALSE
;
2633 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2634 if (hTest
) goto get_error
;
2635 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2638 case WGL_BLUE_BITS_ARB
:
2639 curGLXAttr
= GLX_BLUE_SIZE
;
2641 case WGL_RED_BITS_ARB
:
2642 curGLXAttr
= GLX_RED_SIZE
;
2644 case WGL_GREEN_BITS_ARB
:
2645 curGLXAttr
= GLX_GREEN_SIZE
;
2647 case WGL_ALPHA_BITS_ARB
:
2648 curGLXAttr
= GLX_ALPHA_SIZE
;
2650 case WGL_DEPTH_BITS_ARB
:
2651 curGLXAttr
= GLX_DEPTH_SIZE
;
2653 case WGL_STENCIL_BITS_ARB
:
2654 curGLXAttr
= GLX_STENCIL_SIZE
;
2656 case WGL_DOUBLE_BUFFER_ARB
:
2657 curGLXAttr
= GLX_DOUBLEBUFFER
;
2659 case WGL_STEREO_ARB
:
2660 curGLXAttr
= GLX_STEREO
;
2662 case WGL_AUX_BUFFERS_ARB
:
2663 curGLXAttr
= GLX_AUX_BUFFERS
;
2666 case WGL_SUPPORT_GDI_ARB
:
2667 if (!fmt
) goto pix_error
;
2668 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) != 0;
2671 case WGL_DRAW_TO_BITMAP_ARB
:
2672 if (!fmt
) goto pix_error
;
2673 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) != 0;
2676 case WGL_DRAW_TO_WINDOW_ARB
:
2677 case WGL_DRAW_TO_PBUFFER_ARB
:
2678 if (!fmt
) goto pix_error
;
2679 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2680 if (hTest
) goto get_error
;
2681 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2682 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2683 piValues
[i
] = GL_TRUE
;
2685 piValues
[i
] = GL_FALSE
;
2688 case WGL_SWAP_METHOD_ARB
:
2689 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2690 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2691 * point only ATI offers this.
2693 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2696 case WGL_PBUFFER_LARGEST_ARB
:
2697 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2700 case WGL_SAMPLE_BUFFERS_ARB
:
2701 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2704 case WGL_SAMPLES_ARB
:
2705 curGLXAttr
= GLX_SAMPLES_ARB
;
2708 case WGL_FLOAT_COMPONENTS_NV
:
2709 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2712 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
2713 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
2716 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
2717 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
2720 case WGL_ACCUM_RED_BITS_ARB
:
2721 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2723 case WGL_ACCUM_GREEN_BITS_ARB
:
2724 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2726 case WGL_ACCUM_BLUE_BITS_ARB
:
2727 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2729 case WGL_ACCUM_ALPHA_BITS_ARB
:
2730 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2732 case WGL_ACCUM_BITS_ARB
:
2733 if (!fmt
) goto pix_error
;
2734 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2735 if (hTest
) goto get_error
;
2737 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2738 if (hTest
) goto get_error
;
2740 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2741 if (hTest
) goto get_error
;
2743 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2744 if (hTest
) goto get_error
;
2749 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2752 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2753 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2754 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2756 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2757 * and check which options can work using iPixelFormat=0 and which not.
2758 * A problem would be that this function is an extension. This would
2759 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2761 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2762 if (!fmt
) goto pix_error
;
2763 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2764 if (hTest
) goto get_error
;
2767 piValues
[i
] = GL_FALSE
;
2773 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2777 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nb_pixel_formats
);
2782 * X11DRV_wglGetPixelFormatAttribfvARB
2784 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2786 static BOOL
X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc
, int iPixelFormat
, int iLayerPlane
,
2787 UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2793 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2795 /* Allocate a temporary array to store integer values */
2796 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2798 ERR("couldn't allocate %d array\n", nAttributes
);
2802 /* Piggy-back on wglGetPixelFormatAttribivARB */
2803 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2805 /* Convert integer values to float. Should also check for attributes
2806 that can give decimal values here */
2807 for (i
=0; i
<nAttributes
;i
++) {
2808 pfValues
[i
] = attr
[i
];
2812 HeapFree(GetProcessHeap(), 0, attr
);
2817 * X11DRV_wglBindTexImageARB
2819 * WGL_ARB_render_texture: wglBindTexImageARB
2821 static BOOL
X11DRV_wglBindTexImageARB( struct wgl_pbuffer
*object
, int iBuffer
)
2823 GLboolean ret
= GL_FALSE
;
2825 TRACE("(%p, %d)\n", object
, iBuffer
);
2827 if (!object
->use_render_texture
) {
2828 SetLastError(ERROR_INVALID_HANDLE
);
2832 if (use_render_texture_emulation
) {
2833 static BOOL initialized
= FALSE
;
2834 int prev_binded_texture
= 0;
2835 GLXContext prev_context
;
2836 Drawable prev_drawable
;
2837 GLXContext tmp_context
;
2839 prev_context
= pglXGetCurrentContext();
2840 prev_drawable
= pglXGetCurrentDrawable();
2842 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2843 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2844 isn't ideal performance wise but I wasn't able to get other ways working.
2847 initialized
= TRUE
; /* Only show the FIXME once for performance reasons */
2848 FIXME("partial stub!\n");
2851 TRACE("drawable=%lx, context=%p\n", object
->drawable
, prev_context
);
2852 tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2854 opengl_funcs
.gl
.p_glGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2856 /* Switch to our pbuffer */
2857 pglXMakeCurrent(gdi_display
, object
->drawable
, tmp_context
);
2859 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2860 * After that upload the pbuffer texture data. */
2861 opengl_funcs
.gl
.p_glBindTexture(object
->texture_target
, prev_binded_texture
);
2862 opengl_funcs
.gl
.p_glCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2864 /* Switch back to the original drawable and upload the pbuffer-texture */
2865 pglXMakeCurrent(gdi_display
, prev_drawable
, prev_context
);
2866 pglXDestroyContext(gdi_display
, tmp_context
);
2874 * X11DRV_wglReleaseTexImageARB
2876 * WGL_ARB_render_texture: wglReleaseTexImageARB
2878 static BOOL
X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer
*object
, int iBuffer
)
2880 GLboolean ret
= GL_FALSE
;
2882 TRACE("(%p, %d)\n", object
, iBuffer
);
2884 if (!object
->use_render_texture
) {
2885 SetLastError(ERROR_INVALID_HANDLE
);
2888 if (use_render_texture_emulation
) {
2895 * X11DRV_wglGetExtensionsStringEXT
2897 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2899 static const char *X11DRV_wglGetExtensionsStringEXT(void)
2901 TRACE("() returning \"%s\"\n", WineGLInfo
.wglExtensions
);
2902 return WineGLInfo
.wglExtensions
;
2906 * X11DRV_wglGetSwapIntervalEXT
2908 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2910 static int X11DRV_wglGetSwapIntervalEXT(void)
2912 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
2913 struct gl_drawable
*gl
;
2918 if (!(gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), ctx
->hdc
)))
2920 /* This can't happen because a current WGL context is required to get
2921 * here. Likely the application is buggy.
2923 WARN("No GL drawable found, returning swap interval 0\n");
2927 swap_interval
= gl
->swap_interval
;
2928 release_gl_drawable(gl
);
2930 return swap_interval
;
2934 * X11DRV_wglSwapIntervalEXT
2936 * WGL_EXT_swap_control: wglSwapIntervalEXT
2938 static BOOL
X11DRV_wglSwapIntervalEXT(int interval
)
2940 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
2941 struct gl_drawable
*gl
;
2944 TRACE("(%d)\n", interval
);
2946 /* Without WGL/GLX_EXT_swap_control_tear a negative interval
2949 if (interval
< 0 && !has_swap_control_tear
)
2951 SetLastError(ERROR_INVALID_DATA
);
2955 if (!(gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), ctx
->hdc
)))
2957 SetLastError(ERROR_DC_NOT_FOUND
);
2961 switch (swap_control_method
)
2963 case GLX_SWAP_CONTROL_EXT
:
2964 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2965 pglXSwapIntervalEXT(gdi_display
, gl
->drawable
, interval
);
2966 XSync(gdi_display
, False
);
2967 ret
= !X11DRV_check_error();
2970 case GLX_SWAP_CONTROL_MESA
:
2971 ret
= !pglXSwapIntervalMESA(interval
);
2974 case GLX_SWAP_CONTROL_SGI
:
2975 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2976 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2977 * value to be an error. Just silently ignore the request for now.
2980 WARN("Request to disable vertical sync is not handled\n");
2982 ret
= !pglXSwapIntervalSGI(interval
);
2985 case GLX_SWAP_CONTROL_NONE
:
2986 /* Unlikely to happen on modern GLX implementations */
2987 WARN("Request to adjust swap interval is not handled\n");
2992 gl
->swap_interval
= interval
;
2994 SetLastError(ERROR_DC_NOT_FOUND
);
2996 release_gl_drawable(gl
);
3002 * X11DRV_wglSetPixelFormatWINE
3004 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3005 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3007 static BOOL
X11DRV_wglSetPixelFormatWINE(HDC hdc
, int format
)
3009 const struct wgl_pixel_format
*fmt
;
3013 TRACE("(%p,%d)\n", hdc
, format
);
3015 fmt
= get_pixel_format(gdi_display
, format
, FALSE
/* Offscreen */);
3018 ERR( "Invalid format %d\n", format
);
3022 hwnd
= WindowFromDC( hdc
);
3023 if (!hwnd
|| hwnd
== GetDesktopWindow())
3025 ERR( "not a valid window DC %p\n", hdc
);
3029 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
3030 if (!(value
& GLX_WINDOW_BIT
))
3032 WARN( "Pixel format %d is not compatible for window rendering\n", format
);
3036 return set_win_format( hwnd
, fmt
);
3040 * glxRequireVersion (internal)
3042 * Check if the supported GLX version matches requiredVersion.
3044 static BOOL
glxRequireVersion(int requiredVersion
)
3046 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3047 if(requiredVersion
<= WineGLInfo
.glxVersion
[1])
3053 static void register_extension(const char *ext
)
3055 if (WineGLInfo
.wglExtensions
[0])
3056 strcat(WineGLInfo
.wglExtensions
, " ");
3057 strcat(WineGLInfo
.wglExtensions
, ext
);
3059 TRACE("'%s'\n", ext
);
3063 * X11DRV_WineGL_LoadExtensions
3065 static void X11DRV_WineGL_LoadExtensions(void)
3067 WineGLInfo
.wglExtensions
[0] = 0;
3069 /* ARB Extensions */
3071 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_create_context"))
3073 register_extension( "WGL_ARB_create_context" );
3074 opengl_funcs
.ext
.p_wglCreateContextAttribsARB
= X11DRV_wglCreateContextAttribsARB
;
3076 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_create_context_profile"))
3077 register_extension("WGL_ARB_create_context_profile");
3080 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_fbconfig_float"))
3082 register_extension("WGL_ARB_pixel_format_float");
3083 register_extension("WGL_ATI_pixel_format_float");
3086 register_extension( "WGL_ARB_extensions_string" );
3087 opengl_funcs
.ext
.p_wglGetExtensionsStringARB
= X11DRV_wglGetExtensionsStringARB
;
3089 if (glxRequireVersion(3))
3091 register_extension( "WGL_ARB_make_current_read" );
3092 opengl_funcs
.ext
.p_wglGetCurrentReadDCARB
= (void *)1; /* never called */
3093 opengl_funcs
.ext
.p_wglMakeContextCurrentARB
= X11DRV_wglMakeContextCurrentARB
;
3096 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
3098 if (glxRequireVersion(3))
3100 register_extension( "WGL_ARB_pbuffer" );
3101 opengl_funcs
.ext
.p_wglCreatePbufferARB
= X11DRV_wglCreatePbufferARB
;
3102 opengl_funcs
.ext
.p_wglDestroyPbufferARB
= X11DRV_wglDestroyPbufferARB
;
3103 opengl_funcs
.ext
.p_wglGetPbufferDCARB
= X11DRV_wglGetPbufferDCARB
;
3104 opengl_funcs
.ext
.p_wglQueryPbufferARB
= X11DRV_wglQueryPbufferARB
;
3105 opengl_funcs
.ext
.p_wglReleasePbufferDCARB
= X11DRV_wglReleasePbufferDCARB
;
3106 opengl_funcs
.ext
.p_wglSetPbufferAttribARB
= X11DRV_wglSetPbufferAttribARB
;
3109 register_extension( "WGL_ARB_pixel_format" );
3110 opengl_funcs
.ext
.p_wglChoosePixelFormatARB
= X11DRV_wglChoosePixelFormatARB
;
3111 opengl_funcs
.ext
.p_wglGetPixelFormatAttribfvARB
= X11DRV_wglGetPixelFormatAttribfvARB
;
3112 opengl_funcs
.ext
.p_wglGetPixelFormatAttribivARB
= X11DRV_wglGetPixelFormatAttribivARB
;
3114 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3115 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_ARB_render_texture") ||
3116 (glxRequireVersion(3) && use_render_texture_emulation
))
3118 register_extension( "WGL_ARB_render_texture" );
3119 opengl_funcs
.ext
.p_wglBindTexImageARB
= X11DRV_wglBindTexImageARB
;
3120 opengl_funcs
.ext
.p_wglReleaseTexImageARB
= X11DRV_wglReleaseTexImageARB
;
3122 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3123 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_NV_float_buffer"))
3124 register_extension("WGL_NV_float_buffer");
3126 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3127 if (has_extension(WineGLInfo
.glExtensions
, "GL_NV_texture_rectangle"))
3128 register_extension("WGL_NV_render_texture_rectangle");
3131 /* EXT Extensions */
3133 register_extension( "WGL_EXT_extensions_string" );
3134 opengl_funcs
.ext
.p_wglGetExtensionsStringEXT
= X11DRV_wglGetExtensionsStringEXT
;
3136 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3137 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3138 register_extension( "WGL_EXT_swap_control" );
3139 opengl_funcs
.ext
.p_wglSwapIntervalEXT
= X11DRV_wglSwapIntervalEXT
;
3140 opengl_funcs
.ext
.p_wglGetSwapIntervalEXT
= X11DRV_wglGetSwapIntervalEXT
;
3142 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_framebuffer_sRGB"))
3143 register_extension("WGL_EXT_framebuffer_sRGB");
3145 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_fbconfig_packed_float"))
3146 register_extension("WGL_EXT_pixel_format_packed_float");
3148 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_swap_control"))
3150 swap_control_method
= GLX_SWAP_CONTROL_EXT
;
3151 if (has_extension( WineGLInfo
.glxExtensions
, "GLX_EXT_swap_control_tear"))
3153 register_extension("WGL_EXT_swap_control_tear");
3154 has_swap_control_tear
= TRUE
;
3157 else if (has_extension( WineGLInfo
.glxExtensions
, "GLX_MESA_swap_control"))
3159 swap_control_method
= GLX_SWAP_CONTROL_MESA
;
3161 else if (has_extension( WineGLInfo
.glxExtensions
, "GLX_SGI_swap_control"))
3163 swap_control_method
= GLX_SWAP_CONTROL_SGI
;
3166 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3167 if (has_extension(WineGLInfo
.glExtensions
, "GL_NV_vertex_array_range"))
3169 register_extension( "WGL_NV_vertex_array_range" );
3170 opengl_funcs
.ext
.p_wglAllocateMemoryNV
= pglXAllocateMemoryNV
;
3171 opengl_funcs
.ext
.p_wglFreeMemoryNV
= pglXFreeMemoryNV
;
3174 /* WINE-specific WGL Extensions */
3176 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3177 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3179 register_extension( "WGL_WINE_pixel_format_passthrough" );
3180 opengl_funcs
.ext
.p_wglSetPixelFormatWINE
= X11DRV_wglSetPixelFormatWINE
;
3185 * glxdrv_SwapBuffers
3187 * Swap the buffers of this DC
3189 static BOOL
glxdrv_wglSwapBuffers( HDC hdc
)
3191 struct x11drv_escape_flush_gl_drawable escape
;
3192 struct gl_drawable
*gl
;
3193 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
3195 TRACE("(%p)\n", hdc
);
3197 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
3198 escape
.gl_drawable
= 0;
3200 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
3202 SetLastError( ERROR_INVALID_HANDLE
);
3208 case DC_GL_PIXMAP_WIN
:
3209 if (ctx
) sync_context( ctx
);
3210 escape
.gl_drawable
= gl
->pixmap
;
3211 if (pglXCopySubBufferMESA
) {
3212 /* (glX)SwapBuffers has an implicit glFlush effect, however
3213 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3216 pglXCopySubBufferMESA( gdi_display
, gl
->drawable
, 0, 0,
3217 gl
->rect
.right
- gl
->rect
.left
, gl
->rect
.bottom
- gl
->rect
.top
);
3220 pglXSwapBuffers(gdi_display
, gl
->drawable
);
3222 case DC_GL_CHILD_WIN
:
3223 if (ctx
) sync_context( ctx
);
3224 escape
.gl_drawable
= gl
->drawable
;
3227 pglXSwapBuffers(gdi_display
, gl
->drawable
);
3231 release_gl_drawable( gl
);
3233 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
3237 static struct opengl_funcs opengl_funcs
=
3240 glxdrv_wglCopyContext
, /* p_wglCopyContext */
3241 glxdrv_wglCreateContext
, /* p_wglCreateContext */
3242 glxdrv_wglDeleteContext
, /* p_wglDeleteContext */
3243 glxdrv_wglDescribePixelFormat
, /* p_wglDescribePixelFormat */
3244 glxdrv_wglGetPixelFormat
, /* p_wglGetPixelFormat */
3245 glxdrv_wglGetProcAddress
, /* p_wglGetProcAddress */
3246 glxdrv_wglMakeCurrent
, /* p_wglMakeCurrent */
3247 glxdrv_wglSetPixelFormat
, /* p_wglSetPixelFormat */
3248 glxdrv_wglShareLists
, /* p_wglShareLists */
3249 glxdrv_wglSwapBuffers
, /* p_wglSwapBuffers */
3253 struct opengl_funcs
*get_glx_driver( UINT version
)
3255 if (version
!= WINE_WGL_DRIVER_VERSION
)
3257 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version
, WINE_WGL_DRIVER_VERSION
);
3260 if (has_opengl()) return &opengl_funcs
;
3264 #else /* no OpenGL includes */
3266 struct opengl_funcs
*get_glx_driver( UINT version
)
3271 void sync_gl_drawable( HWND hwnd
, const RECT
*visible_rect
, const RECT
*client_rect
)
3275 void set_gl_drawable_parent( HWND hwnd
, HWND parent
)
3279 void destroy_gl_drawable( HWND hwnd
)
3283 #endif /* defined(SONAME_LIBGL) */