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"
48 WINE_DEFAULT_DEBUG_CHANNEL(wgl
);
49 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
52 #include "wine/wgl_driver.h"
54 typedef struct __GLXcontextRec
*GLXContext
;
55 typedef struct __GLXFBConfigRec
*GLXFBConfig
;
56 typedef XID GLXPixmap
;
57 typedef XID GLXDrawable
;
58 typedef XID GLXFBConfigID
;
59 typedef XID GLXContextID
;
60 typedef XID GLXWindow
;
61 typedef XID GLXPbuffer
;
64 #define GLX_BUFFER_SIZE 2
67 #define GLX_DOUBLEBUFFER 5
69 #define GLX_AUX_BUFFERS 7
70 #define GLX_RED_SIZE 8
71 #define GLX_GREEN_SIZE 9
72 #define GLX_BLUE_SIZE 10
73 #define GLX_ALPHA_SIZE 11
74 #define GLX_DEPTH_SIZE 12
75 #define GLX_STENCIL_SIZE 13
76 #define GLX_ACCUM_RED_SIZE 14
77 #define GLX_ACCUM_GREEN_SIZE 15
78 #define GLX_ACCUM_BLUE_SIZE 16
79 #define GLX_ACCUM_ALPHA_SIZE 17
81 #define GLX_BAD_SCREEN 1
82 #define GLX_BAD_ATTRIBUTE 2
83 #define GLX_NO_EXTENSION 3
84 #define GLX_BAD_VISUAL 4
85 #define GLX_BAD_CONTEXT 5
86 #define GLX_BAD_VALUE 6
87 #define GLX_BAD_ENUM 7
91 #define GLX_EXTENSIONS 3
93 #define GLX_CONFIG_CAVEAT 0x20
94 #define GLX_DONT_CARE 0xFFFFFFFF
95 #define GLX_X_VISUAL_TYPE 0x22
96 #define GLX_TRANSPARENT_TYPE 0x23
97 #define GLX_TRANSPARENT_INDEX_VALUE 0x24
98 #define GLX_TRANSPARENT_RED_VALUE 0x25
99 #define GLX_TRANSPARENT_GREEN_VALUE 0x26
100 #define GLX_TRANSPARENT_BLUE_VALUE 0x27
101 #define GLX_TRANSPARENT_ALPHA_VALUE 0x28
102 #define GLX_WINDOW_BIT 0x00000001
103 #define GLX_PIXMAP_BIT 0x00000002
104 #define GLX_PBUFFER_BIT 0x00000004
105 #define GLX_AUX_BUFFERS_BIT 0x00000010
106 #define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
107 #define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
108 #define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
109 #define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
110 #define GLX_DEPTH_BUFFER_BIT 0x00000020
111 #define GLX_STENCIL_BUFFER_BIT 0x00000040
112 #define GLX_ACCUM_BUFFER_BIT 0x00000080
113 #define GLX_NONE 0x8000
114 #define GLX_SLOW_CONFIG 0x8001
115 #define GLX_TRUE_COLOR 0x8002
116 #define GLX_DIRECT_COLOR 0x8003
117 #define GLX_PSEUDO_COLOR 0x8004
118 #define GLX_STATIC_COLOR 0x8005
119 #define GLX_GRAY_SCALE 0x8006
120 #define GLX_STATIC_GRAY 0x8007
121 #define GLX_TRANSPARENT_RGB 0x8008
122 #define GLX_TRANSPARENT_INDEX 0x8009
123 #define GLX_VISUAL_ID 0x800B
124 #define GLX_SCREEN 0x800C
125 #define GLX_NON_CONFORMANT_CONFIG 0x800D
126 #define GLX_DRAWABLE_TYPE 0x8010
127 #define GLX_RENDER_TYPE 0x8011
128 #define GLX_X_RENDERABLE 0x8012
129 #define GLX_FBCONFIG_ID 0x8013
130 #define GLX_RGBA_TYPE 0x8014
131 #define GLX_COLOR_INDEX_TYPE 0x8015
132 #define GLX_MAX_PBUFFER_WIDTH 0x8016
133 #define GLX_MAX_PBUFFER_HEIGHT 0x8017
134 #define GLX_MAX_PBUFFER_PIXELS 0x8018
135 #define GLX_PRESERVED_CONTENTS 0x801B
136 #define GLX_LARGEST_PBUFFER 0x801C
137 #define GLX_WIDTH 0x801D
138 #define GLX_HEIGHT 0x801E
139 #define GLX_EVENT_MASK 0x801F
140 #define GLX_DAMAGED 0x8020
141 #define GLX_SAVED 0x8021
142 #define GLX_WINDOW 0x8022
143 #define GLX_PBUFFER 0x8023
144 #define GLX_PBUFFER_HEIGHT 0x8040
145 #define GLX_PBUFFER_WIDTH 0x8041
146 #define GLX_SWAP_METHOD_OML 0x8060
147 #define GLX_SWAP_EXCHANGE_OML 0x8061
148 #define GLX_SWAP_COPY_OML 0x8062
149 #define GLX_SWAP_UNDEFINED_OML 0x8063
150 #define GLX_RGBA_BIT 0x00000001
151 #define GLX_COLOR_INDEX_BIT 0x00000002
152 #define GLX_PBUFFER_CLOBBER_MASK 0x08000000
154 /** GLX_ARB_multisample */
155 #define GLX_SAMPLE_BUFFERS_ARB 100000
156 #define GLX_SAMPLES_ARB 100001
157 /** GLX_ARB_framebuffer_sRGB */
158 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
159 /** GLX_EXT_fbconfig_packed_float */
160 #define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
161 #define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
162 /** GLX_ARB_create_context */
163 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
164 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
165 #define GLX_CONTEXT_FLAGS_ARB 0x2094
166 /** GLX_ARB_create_context_no_error */
167 #define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31B3
168 /** GLX_ARB_create_context_profile */
169 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
170 /** GLX_ATI_pixel_format_float */
171 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
172 /** GLX_ARB_pixel_format_float */
173 #define GLX_RGBA_FLOAT_BIT 0x00000004
174 #define GLX_RGBA_FLOAT_TYPE 0x20B9
175 /** GLX_MESA_query_renderer */
176 #define GLX_RENDERER_ID_MESA 0x818E
177 /** GLX_NV_float_buffer */
178 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
181 static char *glExtensions
;
182 static const char *glxExtensions
;
183 static char wglExtensions
[4096];
184 static int glxVersion
[2];
186 struct wgl_pixel_format
188 GLXFBConfig fbconfig
;
192 DWORD dwFlags
; /* We store some PFD_* flags in here for emulated bitmap formats */
198 BOOL has_been_current
;
201 const struct wgl_pixel_format
*fmt
;
202 int numAttribs
; /* This is needed for delaying wglCreateContextAttribsARB */
203 int attribList
[16]; /* This is needed for delaying wglCreateContextAttribsARB */
205 struct gl_drawable
*drawables
[2];
206 struct gl_drawable
*new_drawables
[2];
207 BOOL refresh_drawables
;
214 const struct wgl_pixel_format
* fmt
;
218 int use_render_texture
; /* This is also the internal texture format */
219 int texture_bind_target
;
221 GLint texture_format
;
222 GLuint texture_target
;
226 GLXContext tmp_context
;
227 GLXContext prev_context
;
233 DC_GL_NONE
, /* no GL support (pixel format not set yet) */
234 DC_GL_WINDOW
, /* normal top-level window */
235 DC_GL_CHILD_WIN
, /* child window using XComposite */
236 DC_GL_PIXMAP_WIN
, /* child window using intermediate pixmap */
237 DC_GL_PBUFFER
/* pseudo memory DC using a PBuffer */
242 LONG ref
; /* reference count */
243 enum dc_gl_type type
; /* type of GL surface */
244 GLXDrawable drawable
; /* drawable for rendering with GL */
245 Window window
; /* window if drawable is a GLXWindow */
246 Pixmap pixmap
; /* base pixmap if drawable is a GLXPixmap */
247 const struct wgl_pixel_format
*format
; /* pixel format for the drawable */
248 SIZE pixmap_size
; /* pixmap size for GLXPixmap drawables */
250 BOOL refresh_swap_interval
;
253 enum glx_swap_control_method
255 GLX_SWAP_CONTROL_NONE
,
256 GLX_SWAP_CONTROL_EXT
,
257 GLX_SWAP_CONTROL_SGI
,
258 GLX_SWAP_CONTROL_MESA
261 /* X context to associate a struct gl_drawable to an hwnd */
262 static XContext gl_hwnd_context
;
263 /* X context to associate a struct gl_drawable to a pbuffer hdc */
264 static XContext gl_pbuffer_context
;
266 static struct list context_list
= LIST_INIT( context_list
);
267 static struct list pbuffer_list
= LIST_INIT( pbuffer_list
);
268 static struct wgl_pixel_format
*pixel_formats
;
269 static int nb_pixel_formats
, nb_onscreen_formats
;
270 static BOOL use_render_texture_emulation
= TRUE
;
272 /* Selects the preferred GLX swap control method for use by wglSwapIntervalEXT */
273 static enum glx_swap_control_method swap_control_method
= GLX_SWAP_CONTROL_NONE
;
274 /* Set when GLX_EXT_swap_control_tear is supported, requires GLX_SWAP_CONTROL_EXT */
275 static BOOL has_swap_control_tear
= FALSE
;
276 static BOOL has_swap_method
= FALSE
;
278 static CRITICAL_SECTION context_section
;
279 static CRITICAL_SECTION_DEBUG critsect_debug
=
281 0, 0, &context_section
,
282 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
283 0, 0, { (DWORD_PTR
)(__FILE__
": context_section") }
285 static CRITICAL_SECTION context_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
287 static const BOOL is_win64
= sizeof(void *) > sizeof(int);
289 static struct opengl_funcs opengl_funcs
;
291 #define USE_GL_FUNC(name) #name,
292 static const char *opengl_func_names
[] = { ALL_WGL_FUNCS
};
295 static void X11DRV_WineGL_LoadExtensions(void);
296 static void init_pixel_formats( Display
*display
);
297 static BOOL
glxRequireVersion(int requiredVersion
);
299 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR
*ppfd
) {
300 TRACE(" - size / version : %d / %d\n", ppfd
->nSize
, ppfd
->nVersion
);
301 TRACE(" - dwFlags : ");
302 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
303 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DEPTH_DONTCARE
);
304 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER
);
305 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DOUBLEBUFFER_DONTCARE
);
306 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_WINDOW
);
307 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_DRAW_TO_BITMAP
);
308 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_ACCELERATED
);
309 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_GENERIC_FORMAT
);
310 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_PALETTE
);
311 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_NEED_SYSTEM_PALETTE
);
312 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO
);
313 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_STEREO_DONTCARE
);
314 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_GDI
);
315 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_OPENGL
);
316 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_COPY
);
317 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_EXCHANGE
);
318 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SWAP_LAYER_BUFFERS
);
319 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
320 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
321 TEST_AND_DUMP(ppfd
->dwFlags
, PFD_SUPPORT_COMPOSITION
);
325 TRACE(" - iPixelType : ");
326 switch (ppfd
->iPixelType
) {
327 case PFD_TYPE_RGBA
: TRACE("PFD_TYPE_RGBA"); break;
328 case PFD_TYPE_COLORINDEX
: TRACE("PFD_TYPE_COLORINDEX"); break;
332 TRACE(" - Color : %d\n", ppfd
->cColorBits
);
333 TRACE(" - Red : %d\n", ppfd
->cRedBits
);
334 TRACE(" - Green : %d\n", ppfd
->cGreenBits
);
335 TRACE(" - Blue : %d\n", ppfd
->cBlueBits
);
336 TRACE(" - Alpha : %d\n", ppfd
->cAlphaBits
);
337 TRACE(" - Accum : %d\n", ppfd
->cAccumBits
);
338 TRACE(" - Depth : %d\n", ppfd
->cDepthBits
);
339 TRACE(" - Stencil : %d\n", ppfd
->cStencilBits
);
340 TRACE(" - Aux : %d\n", ppfd
->cAuxBuffers
);
342 TRACE(" - iLayerType : ");
343 switch (ppfd
->iLayerType
) {
344 case PFD_MAIN_PLANE
: TRACE("PFD_MAIN_PLANE"); break;
345 case PFD_OVERLAY_PLANE
: TRACE("PFD_OVERLAY_PLANE"); break;
346 case (BYTE
)PFD_UNDERLAY_PLANE
: TRACE("PFD_UNDERLAY_PLANE"); break;
351 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
352 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
355 static XVisualInfo
* (*pglXChooseVisual
)( Display
*dpy
, int screen
, int *attribList
);
356 static GLXContext (*pglXCreateContext
)( Display
*dpy
, XVisualInfo
*vis
, GLXContext shareList
, Bool direct
);
357 static void (*pglXDestroyContext
)( Display
*dpy
, GLXContext ctx
);
358 static Bool (*pglXMakeCurrent
)( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
);
359 static void (*pglXCopyContext
)( Display
*dpy
, GLXContext src
, GLXContext dst
, unsigned long mask
);
360 static void (*pglXSwapBuffers
)( Display
*dpy
, GLXDrawable drawable
);
361 static Bool (*pglXQueryExtension
)( Display
*dpy
, int *errorb
, int *event
);
362 static Bool (*pglXQueryVersion
)( Display
*dpy
, int *maj
, int *min
);
363 static Bool (*pglXIsDirect
)( Display
*dpy
, GLXContext ctx
);
364 static GLXContext (*pglXGetCurrentContext
)( void );
365 static GLXDrawable (*pglXGetCurrentDrawable
)( void );
368 static const char *(*pglXQueryExtensionsString
)( Display
*dpy
, int screen
);
369 static const char *(*pglXQueryServerString
)( Display
*dpy
, int screen
, int name
);
370 static const char *(*pglXGetClientString
)( Display
*dpy
, int name
);
373 static GLXFBConfig
*(*pglXChooseFBConfig
)( Display
*dpy
, int screen
, const int *attribList
, int *nitems
);
374 static int (*pglXGetFBConfigAttrib
)( Display
*dpy
, GLXFBConfig config
, int attribute
, int *value
);
375 static GLXFBConfig
*(*pglXGetFBConfigs
)( Display
*dpy
, int screen
, int *nelements
);
376 static XVisualInfo
*(*pglXGetVisualFromFBConfig
)( Display
*dpy
, GLXFBConfig config
);
377 static GLXPbuffer (*pglXCreatePbuffer
)( Display
*dpy
, GLXFBConfig config
, const int *attribList
);
378 static void (*pglXDestroyPbuffer
)( Display
*dpy
, GLXPbuffer pbuf
);
379 static void (*pglXQueryDrawable
)( Display
*dpy
, GLXDrawable draw
, int attribute
, unsigned int *value
);
380 static GLXContext (*pglXCreateNewContext
)( Display
*dpy
, GLXFBConfig config
, int renderType
, GLXContext shareList
, Bool direct
);
381 static Bool (*pglXMakeContextCurrent
)( Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
);
382 static GLXPixmap (*pglXCreatePixmap
)( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
, const int *attrib_list
);
383 static void (*pglXDestroyPixmap
)( Display
*dpy
, GLXPixmap pixmap
);
384 static GLXWindow (*pglXCreateWindow
)( Display
*dpy
, GLXFBConfig config
, Window win
, const int *attrib_list
);
385 static void (*pglXDestroyWindow
)( Display
*dpy
, GLXWindow win
);
388 static GLXContext (*pglXCreateContextAttribsARB
)(Display
*dpy
, GLXFBConfig config
, GLXContext share_context
, Bool direct
, const int *attrib_list
);
389 static void* (*pglXGetProcAddressARB
)(const GLubyte
*);
390 static void (*pglXSwapIntervalEXT
)(Display
*dpy
, GLXDrawable drawable
, int interval
);
391 static int (*pglXSwapIntervalSGI
)(int);
393 /* NV GLX Extension */
394 static void* (*pglXAllocateMemoryNV
)(GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
);
395 static void (*pglXFreeMemoryNV
)(GLvoid
*pointer
);
397 /* MESA GLX Extensions */
398 static void (*pglXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
);
399 static int (*pglXSwapIntervalMESA
)(unsigned int interval
);
400 static Bool (*pglXQueryCurrentRendererIntegerMESA
)(int attribute
, unsigned int *value
);
401 static const char *(*pglXQueryCurrentRendererStringMESA
)(int attribute
);
402 static Bool (*pglXQueryRendererIntegerMESA
)(Display
*dpy
, int screen
, int renderer
, int attribute
, unsigned int *value
);
403 static const char *(*pglXQueryRendererStringMESA
)(Display
*dpy
, int screen
, int renderer
, int attribute
);
405 /* OpenML GLX Extensions */
406 static Bool (*pglXWaitForSbcOML
)( Display
*dpy
, GLXDrawable drawable
,
407 INT64 target_sbc
, INT64
*ust
, INT64
*msc
, INT64
*sbc
);
408 static INT64 (*pglXSwapBuffersMscOML
)( Display
*dpy
, GLXDrawable drawable
,
409 INT64 target_msc
, INT64 divisor
, INT64 remainder
);
411 /* Standard OpenGL */
412 static void (*pglFinish
)(void);
413 static void (*pglFlush
)(void);
414 static const GLubyte
*(*pglGetString
)(GLenum name
);
416 static void wglFinish(void);
417 static void wglFlush(void);
418 static const GLubyte
*wglGetString(GLenum name
);
420 /* check if the extension is present in the list */
421 static BOOL
has_extension( const char *list
, const char *ext
)
423 size_t len
= strlen( ext
);
427 while (*list
== ' ') list
++;
428 if (!strncmp( list
, ext
, len
) && (!list
[len
] || list
[len
] == ' ')) return TRUE
;
429 list
= strchr( list
, ' ' );
434 static int GLXErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
436 /* In the future we might want to find the exact X or GLX error to report back to the app */
440 static BOOL
X11DRV_WineGL_InitOpenglInfo(void)
442 static const char legacy_extensions
[] = " WGL_EXT_extensions_string WGL_EXT_swap_control";
444 int screen
= DefaultScreen(gdi_display
);
445 Window win
= 0, root
= 0;
446 const char *gl_version
;
447 const char *gl_renderer
;
451 GLXContext ctx
= NULL
;
452 XSetWindowAttributes attr
;
454 int attribList
[] = {GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
456 attr
.override_redirect
= True
;
457 attr
.colormap
= None
;
458 attr
.border_pixel
= 0;
460 vis
= pglXChooseVisual(gdi_display
, screen
, attribList
);
463 WORD old_fs
= wine_get_fs();
464 /* Create a GLX Context. Without one we can't query GL information */
465 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
466 if (wine_get_fs() != old_fs
)
468 wine_set_fs( old_fs
);
469 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
470 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
474 ctx
= pglXCreateContext(gdi_display
, vis
, None
, GL_TRUE
);
479 root
= RootWindow( gdi_display
, vis
->screen
);
480 if (vis
->visual
!= DefaultVisual( gdi_display
, vis
->screen
))
481 attr
.colormap
= XCreateColormap( gdi_display
, root
, vis
->visual
, AllocNone
);
482 if ((win
= XCreateWindow( gdi_display
, root
, -1, -1, 1, 1, 0, vis
->depth
, InputOutput
,
483 vis
->visual
, CWBorderPixel
| CWOverrideRedirect
| CWColormap
, &attr
)))
484 XMapWindow( gdi_display
, win
);
488 if(pglXMakeCurrent(gdi_display
, win
, ctx
) == 0)
490 ERR_(winediag
)( "Unable to activate OpenGL context, most likely your %s OpenGL drivers haven't been "
491 "installed correctly\n", is_win64
? "64-bit" : "32-bit" );
494 gl_renderer
= (const char *)opengl_funcs
.gl
.p_glGetString(GL_RENDERER
);
495 gl_version
= (const char *)opengl_funcs
.gl
.p_glGetString(GL_VERSION
);
496 str
= (const char *) opengl_funcs
.gl
.p_glGetString(GL_EXTENSIONS
);
497 glExtensions
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+sizeof(legacy_extensions
));
498 strcpy(glExtensions
, str
);
499 strcat(glExtensions
, legacy_extensions
);
501 /* Get the common GLX version supported by GLX client and server ( major/minor) */
502 pglXQueryVersion(gdi_display
, &glxVersion
[0], &glxVersion
[1]);
504 glxExtensions
= pglXQueryExtensionsString(gdi_display
, screen
);
505 glx_direct
= pglXIsDirect(gdi_display
, ctx
);
507 TRACE("GL version : %s.\n", gl_version
);
508 TRACE("GL renderer : %s.\n", gl_renderer
);
509 TRACE("GLX version : %d.%d.\n", glxVersion
[0], glxVersion
[1]);
510 TRACE("Server GLX version : %s.\n", pglXQueryServerString(gdi_display
, screen
, GLX_VERSION
));
511 TRACE("Server GLX vendor: : %s.\n", pglXQueryServerString(gdi_display
, screen
, GLX_VENDOR
));
512 TRACE("Client GLX version : %s.\n", pglXGetClientString(gdi_display
, GLX_VERSION
));
513 TRACE("Client GLX vendor: : %s.\n", pglXGetClientString(gdi_display
, GLX_VENDOR
));
514 TRACE("Direct rendering enabled: %s\n", glx_direct
? "True" : "False");
518 int fd
= ConnectionNumber(gdi_display
);
519 struct sockaddr_un uaddr
;
520 unsigned int uaddrlen
= sizeof(struct sockaddr_un
);
522 /* In general indirect rendering on a local X11 server indicates a driver problem.
523 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
525 if(!getsockname(fd
, (struct sockaddr
*)&uaddr
, &uaddrlen
) && uaddr
.sun_family
== AF_UNIX
)
526 ERR_(winediag
)("Direct rendering is disabled, most likely your %s OpenGL drivers "
527 "haven't been installed correctly (using GL renderer %s, version %s).\n",
528 is_win64
? "64-bit" : "32-bit", debugstr_a(gl_renderer
),
529 debugstr_a(gl_version
));
533 /* In general you would expect that if direct rendering is returned, that you receive hardware
534 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
535 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
536 * software rendering, it shows direct rendering.
538 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
539 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
540 * it shows 'Mesa X11'.
542 if(!strcmp(gl_renderer
, "Software Rasterizer") || !strcmp(gl_renderer
, "Mesa X11"))
543 ERR_(winediag
)("The Mesa OpenGL driver is using software rendering, most likely your %s OpenGL "
544 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
545 is_win64
? "64-bit" : "32-bit", debugstr_a(gl_renderer
),
546 debugstr_a(gl_version
));
553 pglXMakeCurrent(gdi_display
, None
, NULL
);
554 pglXDestroyContext(gdi_display
, ctx
);
556 if (win
!= root
) XDestroyWindow( gdi_display
, win
);
557 if (attr
.colormap
) XFreeColormap( gdi_display
, attr
.colormap
);
558 if (!ret
) ERR(" couldn't initialize OpenGL, expect problems\n");
562 static void *opengl_handle
;
564 static BOOL WINAPI
init_opengl( INIT_ONCE
*once
, void *param
, void **context
)
567 int error_base
, event_base
;
570 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
571 and include all dependencies */
572 opengl_handle
= wine_dlopen(SONAME_LIBGL
, RTLD_NOW
|RTLD_GLOBAL
, buffer
, sizeof(buffer
));
573 if (opengl_handle
== NULL
)
575 ERR( "Failed to load libGL: %s\n", buffer
);
576 ERR( "OpenGL support is disabled.\n");
580 for (i
= 0; i
< sizeof(opengl_func_names
)/sizeof(opengl_func_names
[0]); i
++)
582 if (!(((void **)&opengl_funcs
.gl
)[i
] = wine_dlsym( opengl_handle
, opengl_func_names
[i
], NULL
, 0 )))
584 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names
[i
] );
589 /* redirect some standard OpenGL functions */
590 #define REDIRECT(func) \
591 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
592 REDIRECT( glFinish
);
594 REDIRECT( glGetString
);
597 pglXGetProcAddressARB
= wine_dlsym(opengl_handle
, "glXGetProcAddressARB", NULL
, 0);
598 if (pglXGetProcAddressARB
== NULL
) {
599 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
603 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
605 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
610 LOAD_FUNCPTR(glXChooseVisual
);
611 LOAD_FUNCPTR(glXCopyContext
);
612 LOAD_FUNCPTR(glXCreateContext
);
613 LOAD_FUNCPTR(glXGetCurrentContext
);
614 LOAD_FUNCPTR(glXGetCurrentDrawable
);
615 LOAD_FUNCPTR(glXDestroyContext
);
616 LOAD_FUNCPTR(glXIsDirect
);
617 LOAD_FUNCPTR(glXMakeCurrent
);
618 LOAD_FUNCPTR(glXSwapBuffers
);
619 LOAD_FUNCPTR(glXQueryExtension
);
620 LOAD_FUNCPTR(glXQueryVersion
);
623 LOAD_FUNCPTR(glXGetClientString
);
624 LOAD_FUNCPTR(glXQueryExtensionsString
);
625 LOAD_FUNCPTR(glXQueryServerString
);
628 LOAD_FUNCPTR(glXCreatePbuffer
);
629 LOAD_FUNCPTR(glXCreateNewContext
);
630 LOAD_FUNCPTR(glXDestroyPbuffer
);
631 LOAD_FUNCPTR(glXMakeContextCurrent
);
632 LOAD_FUNCPTR(glXGetFBConfigs
);
633 LOAD_FUNCPTR(glXCreatePixmap
);
634 LOAD_FUNCPTR(glXDestroyPixmap
);
635 LOAD_FUNCPTR(glXCreateWindow
);
636 LOAD_FUNCPTR(glXDestroyWindow
);
639 /* It doesn't matter if these fail. They'll only be used if the driver reports
640 the associated extension is available (and if a driver reports the extension
641 is available but fails to provide the functions, it's quite broken) */
642 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
643 /* ARB GLX Extension */
644 LOAD_FUNCPTR(glXCreateContextAttribsARB
);
645 /* EXT GLX Extension */
646 LOAD_FUNCPTR(glXSwapIntervalEXT
);
647 /* MESA GLX Extension */
648 LOAD_FUNCPTR(glXSwapIntervalMESA
);
649 /* SGI GLX Extension */
650 LOAD_FUNCPTR(glXSwapIntervalSGI
);
651 /* NV GLX Extension */
652 LOAD_FUNCPTR(glXAllocateMemoryNV
);
653 LOAD_FUNCPTR(glXFreeMemoryNV
);
656 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed
;
658 if (pglXQueryExtension(gdi_display
, &error_base
, &event_base
)) {
659 TRACE("GLX is up and running error_base = %d\n", error_base
);
661 ERR( "GLX extension is missing, disabling OpenGL.\n" );
664 gl_hwnd_context
= XUniqueContext();
665 gl_pbuffer_context
= XUniqueContext();
667 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
668 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
671 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
672 * depends on the reported GLX client / server version and on the client / server extension list.
673 * Those don't have to be the same.
675 * In general the server GLX information lists the capabilities in case of indirect rendering.
676 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
677 * available and in that case the client GLX informat can be used.
678 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
679 * in the GLX version/extension list. When a program does this it works for certain for both
680 * direct and indirect rendering.
682 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
683 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
684 * extension list which causes this extension not to be listed. (Wine requires this extension).
685 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
686 * pbuffers is around.
688 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
689 * the ATI drivers and from then on use GLX client information for them.
692 if(glxRequireVersion(3)) {
693 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
694 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
695 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
696 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
697 } else if (has_extension( glxExtensions
, "GLX_SGIX_fbconfig")) {
698 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfigSGIX");
699 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttribSGIX");
700 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfigSGIX");
702 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
703 * enable this function when the Xserver understand GLX 1.3 or newer
705 pglXQueryDrawable
= NULL
;
706 } else if(strcmp("ATI", pglXGetClientString(gdi_display
, GLX_VENDOR
)) == 0) {
707 TRACE("Overriding ATI GLX capabilities!\n");
708 pglXChooseFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXChooseFBConfig");
709 pglXGetFBConfigAttrib
= pglXGetProcAddressARB((const GLubyte
*) "glXGetFBConfigAttrib");
710 pglXGetVisualFromFBConfig
= pglXGetProcAddressARB((const GLubyte
*) "glXGetVisualFromFBConfig");
711 pglXQueryDrawable
= pglXGetProcAddressARB((const GLubyte
*) "glXQueryDrawable");
713 /* Use client GLX information in case of the ATI drivers. We override the
714 * capabilities over here and not somewhere else as ATI might better their
715 * life in the future. In case they release proper drivers this block of
716 * code won't be called. */
717 glxExtensions
= pglXGetClientString(gdi_display
, GLX_EXTENSIONS
);
719 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n",
720 pglXQueryServerString(gdi_display
, DefaultScreen(gdi_display
), GLX_VERSION
));
723 if (has_extension( glxExtensions
, "GLX_MESA_copy_sub_buffer")) {
724 pglXCopySubBufferMESA
= pglXGetProcAddressARB((const GLubyte
*) "glXCopySubBufferMESA");
727 if (has_extension( glxExtensions
, "GLX_MESA_query_renderer" ))
729 pglXQueryCurrentRendererIntegerMESA
= pglXGetProcAddressARB(
730 (const GLubyte
*)"glXQueryCurrentRendererIntegerMESA" );
731 pglXQueryCurrentRendererStringMESA
= pglXGetProcAddressARB(
732 (const GLubyte
*)"glXQueryCurrentRendererStringMESA" );
733 pglXQueryRendererIntegerMESA
= pglXGetProcAddressARB( (const GLubyte
*)"glXQueryRendererIntegerMESA" );
734 pglXQueryRendererStringMESA
= pglXGetProcAddressARB( (const GLubyte
*)"glXQueryRendererStringMESA" );
737 if (has_extension( glxExtensions
, "GLX_OML_sync_control" ))
739 pglXWaitForSbcOML
= pglXGetProcAddressARB( (const GLubyte
*)"glXWaitForSbcOML" );
740 pglXSwapBuffersMscOML
= pglXGetProcAddressARB( (const GLubyte
*)"glXSwapBuffersMscOML" );
743 X11DRV_WineGL_LoadExtensions();
744 init_pixel_formats( gdi_display
);
748 wine_dlclose(opengl_handle
, NULL
, 0);
749 opengl_handle
= NULL
;
753 static BOOL
has_opengl(void)
755 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
756 InitOnceExecuteOnce(&init_once
, init_opengl
, NULL
, NULL
);
757 return opengl_handle
!= NULL
;
760 static const char *debugstr_fbconfig( GLXFBConfig fbconfig
)
762 int id
, visual
, drawable
;
764 if (pglXGetFBConfigAttrib( gdi_display
, fbconfig
, GLX_FBCONFIG_ID
, &id
))
765 return "*** invalid fbconfig";
766 pglXGetFBConfigAttrib( gdi_display
, fbconfig
, GLX_VISUAL_ID
, &visual
);
767 pglXGetFBConfigAttrib( gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &drawable
);
768 return wine_dbg_sprintf( "fbconfig %#x visual id %#x drawable type %#x", id
, visual
, drawable
);
771 static int ConvertAttribWGLtoGLX(const int* iWGLAttr
, int* oGLXAttr
, struct wgl_pbuffer
* pbuf
) {
776 int nvfloatattrib
= GLX_DONT_CARE
;
777 int pixelattrib
= GLX_DONT_CARE
;
779 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
780 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
781 while (iWGLAttr
&& 0 != iWGLAttr
[cur
]) {
782 TRACE("pAttr[%d] = %x\n", cur
, iWGLAttr
[cur
]);
784 switch (iWGLAttr
[cur
]) {
785 case WGL_AUX_BUFFERS_ARB
:
786 pop
= iWGLAttr
[++cur
];
787 PUSH2(oGLXAttr
, GLX_AUX_BUFFERS
, pop
);
788 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur
, pop
);
790 case WGL_COLOR_BITS_ARB
:
791 pop
= iWGLAttr
[++cur
];
792 PUSH2(oGLXAttr
, GLX_BUFFER_SIZE
, pop
);
793 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur
, pop
);
795 case WGL_BLUE_BITS_ARB
:
796 pop
= iWGLAttr
[++cur
];
797 PUSH2(oGLXAttr
, GLX_BLUE_SIZE
, pop
);
798 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur
, pop
);
800 case WGL_RED_BITS_ARB
:
801 pop
= iWGLAttr
[++cur
];
802 PUSH2(oGLXAttr
, GLX_RED_SIZE
, pop
);
803 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur
, pop
);
805 case WGL_GREEN_BITS_ARB
:
806 pop
= iWGLAttr
[++cur
];
807 PUSH2(oGLXAttr
, GLX_GREEN_SIZE
, pop
);
808 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur
, pop
);
810 case WGL_ALPHA_BITS_ARB
:
811 pop
= iWGLAttr
[++cur
];
812 PUSH2(oGLXAttr
, GLX_ALPHA_SIZE
, pop
);
813 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur
, pop
);
815 case WGL_DEPTH_BITS_ARB
:
816 pop
= iWGLAttr
[++cur
];
817 PUSH2(oGLXAttr
, GLX_DEPTH_SIZE
, pop
);
818 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur
, pop
);
820 case WGL_STENCIL_BITS_ARB
:
821 pop
= iWGLAttr
[++cur
];
822 PUSH2(oGLXAttr
, GLX_STENCIL_SIZE
, pop
);
823 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur
, pop
);
825 case WGL_DOUBLE_BUFFER_ARB
:
826 pop
= iWGLAttr
[++cur
];
827 PUSH2(oGLXAttr
, GLX_DOUBLEBUFFER
, pop
);
828 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur
, pop
);
831 pop
= iWGLAttr
[++cur
];
832 PUSH2(oGLXAttr
, GLX_STEREO
, pop
);
833 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur
, pop
);
836 case WGL_PIXEL_TYPE_ARB
:
837 pop
= iWGLAttr
[++cur
];
838 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur
, pop
);
840 case WGL_TYPE_COLORINDEX_ARB
: pixelattrib
= GLX_COLOR_INDEX_BIT
; break ;
841 case WGL_TYPE_RGBA_ARB
: pixelattrib
= GLX_RGBA_BIT
; break ;
842 /* 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 */
843 case WGL_TYPE_RGBA_FLOAT_ATI
: pixelattrib
= GLX_RGBA_FLOAT_BIT
; break ;
844 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
: pixelattrib
= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
; break ;
846 ERR("unexpected PixelType(%x)\n", pop
);
851 case WGL_SUPPORT_GDI_ARB
:
852 /* This flag is set in a pixel format */
853 pop
= iWGLAttr
[++cur
];
854 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur
, pop
);
857 case WGL_DRAW_TO_BITMAP_ARB
:
858 /* This flag is set in a pixel format */
859 pop
= iWGLAttr
[++cur
];
860 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur
, pop
);
863 case WGL_DRAW_TO_WINDOW_ARB
:
864 pop
= iWGLAttr
[++cur
];
865 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur
, pop
);
866 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
868 drawattrib
|= GLX_WINDOW_BIT
;
872 case WGL_DRAW_TO_PBUFFER_ARB
:
873 pop
= iWGLAttr
[++cur
];
874 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur
, pop
);
875 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
877 drawattrib
|= GLX_PBUFFER_BIT
;
881 case WGL_ACCELERATION_ARB
:
882 /* This flag is set in a pixel format */
883 pop
= iWGLAttr
[++cur
];
884 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur
, pop
);
887 case WGL_SUPPORT_OPENGL_ARB
:
888 pop
= iWGLAttr
[++cur
];
889 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
890 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur
, pop
);
893 case WGL_SWAP_METHOD_ARB
:
894 pop
= iWGLAttr
[++cur
];
895 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur
, pop
);
900 case WGL_SWAP_EXCHANGE_ARB
:
901 pop
= GLX_SWAP_EXCHANGE_OML
;
903 case WGL_SWAP_COPY_ARB
:
904 pop
= GLX_SWAP_COPY_OML
;
906 case WGL_SWAP_UNDEFINED_ARB
:
907 pop
= GLX_SWAP_UNDEFINED_OML
;
910 ERR("Unexpected swap method %#x.\n", pop
);
913 PUSH2(oGLXAttr
, GLX_SWAP_METHOD_OML
, pop
);
917 WARN("GLX_OML_swap_method not supported, ignoring attribute.\n");
921 case WGL_PBUFFER_LARGEST_ARB
:
922 pop
= iWGLAttr
[++cur
];
923 PUSH2(oGLXAttr
, GLX_LARGEST_PBUFFER
, pop
);
924 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur
, pop
);
927 case WGL_SAMPLE_BUFFERS_ARB
:
928 pop
= iWGLAttr
[++cur
];
929 PUSH2(oGLXAttr
, GLX_SAMPLE_BUFFERS_ARB
, pop
);
930 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur
, pop
);
933 case WGL_SAMPLES_ARB
:
934 pop
= iWGLAttr
[++cur
];
935 PUSH2(oGLXAttr
, GLX_SAMPLES_ARB
, pop
);
936 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur
, pop
);
939 case WGL_TEXTURE_FORMAT_ARB
:
940 case WGL_TEXTURE_TARGET_ARB
:
941 case WGL_MIPMAP_TEXTURE_ARB
:
942 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr
[cur
], iWGLAttr
[cur
+ 1]);
943 pop
= iWGLAttr
[++cur
];
945 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr
[cur
]);
947 if (!use_render_texture_emulation
) {
948 if (WGL_NO_TEXTURE_ARB
!= pop
) {
949 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr
[cur
]);
950 return -1; /** error: don't support it */
952 drawattrib
|= GLX_PBUFFER_BIT
;
956 case WGL_FLOAT_COMPONENTS_NV
:
957 nvfloatattrib
= iWGLAttr
[++cur
];
958 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur
, nvfloatattrib
);
960 case WGL_BIND_TO_TEXTURE_DEPTH_NV
:
961 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
962 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
963 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
:
964 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
:
965 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
:
966 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
:
967 pop
= iWGLAttr
[++cur
];
968 /** cannot be converted, see direct handling on
969 * - wglGetPixelFormatAttribivARB
970 * TODO: wglChoosePixelFormat
973 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
974 pop
= iWGLAttr
[++cur
];
975 PUSH2(oGLXAttr
, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
, pop
);
976 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur
, pop
);
979 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
980 pop
= iWGLAttr
[++cur
];
981 PUSH2(oGLXAttr
, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
, pop
);
982 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur
, pop
);
985 FIXME("unsupported %x WGL Attribute\n", iWGLAttr
[cur
]);
992 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
993 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
994 * pixmap and pbuffer formats appear as well. */
995 if (!drawattrib
) drawattrib
= GLX_DONT_CARE
;
996 PUSH2(oGLXAttr
, GLX_DRAWABLE_TYPE
, drawattrib
);
997 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib
);
999 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
1000 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
1001 * GLX_DONT_CARE unless it is overridden. */
1002 PUSH2(oGLXAttr
, GLX_RENDER_TYPE
, pixelattrib
);
1003 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib
);
1005 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
1006 if (has_extension(glxExtensions
, "GLX_NV_float_buffer")) {
1007 PUSH2(oGLXAttr
, GLX_FLOAT_COMPONENTS_NV
, nvfloatattrib
);
1008 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib
);
1014 static int get_render_type_from_fbconfig(Display
*display
, GLXFBConfig fbconfig
)
1016 int render_type
, render_type_bit
;
1017 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_RENDER_TYPE
, &render_type_bit
);
1018 switch(render_type_bit
)
1021 render_type
= GLX_RGBA_TYPE
;
1023 case GLX_COLOR_INDEX_BIT
:
1024 render_type
= GLX_COLOR_INDEX_TYPE
;
1026 case GLX_RGBA_FLOAT_BIT
:
1027 render_type
= GLX_RGBA_FLOAT_TYPE
;
1029 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
:
1030 render_type
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
1033 ERR("Unknown render_type: %x\n", render_type_bit
);
1039 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
1040 static BOOL
check_fbconfig_bitmap_capability(Display
*display
, GLXFBConfig fbconfig
)
1043 pglXGetFBConfigAttrib(display
, fbconfig
, GLX_DOUBLEBUFFER
, &dbuf
);
1044 pglXGetFBConfigAttrib(gdi_display
, fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1046 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
1047 * the GLX_PIXMAP_BIT set. */
1048 return !dbuf
&& (value
& GLX_PIXMAP_BIT
);
1051 static void init_pixel_formats( Display
*display
)
1053 struct wgl_pixel_format
*list
;
1054 int size
= 0, onscreen_size
= 0;
1055 int fmt_id
, nCfgs
, i
, run
, bmp_formats
;
1057 XVisualInfo
*visinfo
;
1059 cfgs
= pglXGetFBConfigs(display
, DefaultScreen(display
), &nCfgs
);
1060 if (NULL
== cfgs
|| 0 == nCfgs
) {
1061 if(cfgs
!= NULL
) XFree(cfgs
);
1062 ERR("glXChooseFBConfig returns NULL\n");
1066 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
1067 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
1068 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
1069 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
1071 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
1073 for(i
=0, bmp_formats
=0; i
<nCfgs
; i
++)
1075 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1078 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats
);
1080 list
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nCfgs
+ bmp_formats
) * sizeof(*list
));
1082 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
1083 * Do this as GLX doesn't guarantee that the list is sorted */
1084 for(run
=0; run
< 2; run
++)
1086 for(i
=0; i
<nCfgs
; i
++) {
1087 pglXGetFBConfigAttrib(display
, cfgs
[i
], GLX_FBCONFIG_ID
, &fmt_id
);
1088 visinfo
= pglXGetVisualFromFBConfig(display
, cfgs
[i
]);
1090 /* The first run we only add onscreen formats (ones which have an associated X Visual).
1091 * The second run we only set offscreen formats. */
1094 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
1095 * The contents is copied to the destination using XCopyArea. For the copying to work
1096 * the depth of the source and destination window should be the same. In general this should
1097 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
1098 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
1099 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
1100 * list formats with the same depth. */
1101 if(visinfo
->depth
!= default_visual
.depth
)
1107 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1108 list
[size
].fbconfig
= cfgs
[i
];
1109 list
[size
].visual
= visinfo
;
1110 list
[size
].fmt_id
= fmt_id
;
1111 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1112 list
[size
].dwFlags
= 0;
1116 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1117 if(check_fbconfig_bitmap_capability(display
, cfgs
[i
]))
1119 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1120 list
[size
].fbconfig
= cfgs
[i
];
1121 list
[size
].visual
= visinfo
;
1122 list
[size
].fmt_id
= fmt_id
;
1123 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1124 list
[size
].dwFlags
= PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
| PFD_GENERIC_FORMAT
;
1128 } else if(run
&& !visinfo
) {
1129 int window_drawable
=0;
1130 pglXGetFBConfigAttrib(gdi_display
, cfgs
[i
], GLX_DRAWABLE_TYPE
, &window_drawable
);
1132 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1133 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1134 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1135 * likely make our child window opengl rendering more complicated since likely you can't use
1136 * XCopyArea on a GLX Window.
1137 * For now ignore fbconfigs which are window drawable but lack a visual. */
1138 if(window_drawable
& GLX_WINDOW_BIT
)
1140 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id
);
1144 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id
, size
+1, i
);
1145 list
[size
].fbconfig
= cfgs
[i
];
1146 list
[size
].fmt_id
= fmt_id
;
1147 list
[size
].render_type
= get_render_type_from_fbconfig(display
, cfgs
[i
]);
1148 list
[size
].dwFlags
= 0;
1151 else if (visinfo
) XFree(visinfo
);
1157 pixel_formats
= list
;
1158 nb_pixel_formats
= size
;
1159 nb_onscreen_formats
= onscreen_size
;
1162 static inline BOOL
is_valid_pixel_format( int format
)
1164 return format
> 0 && format
<= nb_pixel_formats
;
1167 static inline BOOL
is_onscreen_pixel_format( int format
)
1169 return format
> 0 && format
<= nb_onscreen_formats
;
1172 static inline int pixel_format_index( const struct wgl_pixel_format
*format
)
1174 return format
- pixel_formats
+ 1;
1177 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1178 * In our WGL implementation we only support a subset of these formats namely the format of
1179 * Wine's main visual and offscreen formats (if they are available).
1180 * This function converts a WGL format to its corresponding GLX one.
1182 static const struct wgl_pixel_format
*get_pixel_format(Display
*display
, int iPixelFormat
, BOOL AllowOffscreen
)
1184 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1185 * iPixelFormat in case of probing the number of pixelformats.
1187 if (is_valid_pixel_format( iPixelFormat
) &&
1188 (is_onscreen_pixel_format( iPixelFormat
) || AllowOffscreen
)) {
1189 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1190 pixel_formats
[iPixelFormat
-1].fmt_id
, iPixelFormat
);
1191 return &pixel_formats
[iPixelFormat
-1];
1196 static struct gl_drawable
*grab_gl_drawable( struct gl_drawable
*gl
)
1198 InterlockedIncrement( &gl
->ref
);
1202 static void release_gl_drawable( struct gl_drawable
*gl
)
1205 if (InterlockedDecrement( &gl
->ref
)) return;
1209 case DC_GL_CHILD_WIN
:
1210 TRACE( "destroying %lx drawable %lx\n", gl
->window
, gl
->drawable
);
1211 pglXDestroyWindow( gdi_display
, gl
->drawable
);
1212 XDestroyWindow( gdi_display
, gl
->window
);
1214 case DC_GL_PIXMAP_WIN
:
1215 TRACE( "destroying pixmap %lx drawable %lx\n", gl
->pixmap
, gl
->drawable
);
1216 pglXDestroyPixmap( gdi_display
, gl
->drawable
);
1217 XFreePixmap( gdi_display
, gl
->pixmap
);
1222 HeapFree( GetProcessHeap(), 0, gl
);
1225 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1226 static void mark_drawable_dirty( struct gl_drawable
*old
, struct gl_drawable
*new )
1228 struct wgl_context
*ctx
;
1230 EnterCriticalSection( &context_section
);
1231 LIST_FOR_EACH_ENTRY( ctx
, &context_list
, struct wgl_context
, entry
)
1233 if (old
== ctx
->drawables
[0] || old
== ctx
->new_drawables
[0])
1235 release_gl_drawable( ctx
->new_drawables
[0] );
1236 ctx
->new_drawables
[0] = grab_gl_drawable( new );
1238 if (old
== ctx
->drawables
[1] || old
== ctx
->new_drawables
[1])
1240 release_gl_drawable( ctx
->new_drawables
[1] );
1241 ctx
->new_drawables
[1] = grab_gl_drawable( new );
1244 LeaveCriticalSection( &context_section
);
1247 /* Given the current context, make sure its drawable is sync'd */
1248 static inline void sync_context(struct wgl_context
*context
)
1250 BOOL refresh
= FALSE
;
1252 EnterCriticalSection( &context_section
);
1253 if (context
->new_drawables
[0])
1255 release_gl_drawable( context
->drawables
[0] );
1256 context
->drawables
[0] = context
->new_drawables
[0];
1257 context
->new_drawables
[0] = NULL
;
1260 if (context
->new_drawables
[1])
1262 release_gl_drawable( context
->drawables
[1] );
1263 context
->drawables
[1] = context
->new_drawables
[1];
1264 context
->new_drawables
[1] = NULL
;
1269 if (glxRequireVersion(3))
1270 pglXMakeContextCurrent(gdi_display
, context
->drawables
[0]->drawable
,
1271 context
->drawables
[1]->drawable
, context
->ctx
);
1273 pglXMakeCurrent(gdi_display
, context
->drawables
[0]->drawable
, context
->ctx
);
1275 LeaveCriticalSection( &context_section
);
1278 static BOOL
set_swap_interval(GLXDrawable drawable
, int interval
)
1282 switch (swap_control_method
)
1284 case GLX_SWAP_CONTROL_EXT
:
1285 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
1286 pglXSwapIntervalEXT(gdi_display
, drawable
, interval
);
1287 XSync(gdi_display
, False
);
1288 ret
= !X11DRV_check_error();
1291 case GLX_SWAP_CONTROL_MESA
:
1292 ret
= !pglXSwapIntervalMESA(interval
);
1295 case GLX_SWAP_CONTROL_SGI
:
1296 /* wglSwapIntervalEXT considers an interval value of zero to mean that
1297 * vsync should be disabled, but glXSwapIntervalSGI considers such a
1298 * value to be an error. Just silently ignore the request for now.
1301 WARN("Request to disable vertical sync is not handled\n");
1303 ret
= !pglXSwapIntervalSGI(interval
);
1306 case GLX_SWAP_CONTROL_NONE
:
1307 /* Unlikely to happen on modern GLX implementations */
1308 WARN("Request to adjust swap interval is not handled\n");
1315 static struct gl_drawable
*get_gl_drawable( HWND hwnd
, HDC hdc
)
1317 struct gl_drawable
*gl
;
1319 EnterCriticalSection( &context_section
);
1320 if (hwnd
&& !XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&gl
))
1321 gl
= grab_gl_drawable( gl
);
1322 else if (hdc
&& !XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&gl
))
1323 gl
= grab_gl_drawable( gl
);
1326 LeaveCriticalSection( &context_section
);
1330 static GLXContext
create_glxcontext(Display
*display
, struct wgl_context
*context
, GLXContext shareList
)
1334 if(context
->gl3_context
)
1336 if(context
->numAttribs
)
1337 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, GL_TRUE
, context
->attribList
);
1339 ctx
= pglXCreateContextAttribsARB(gdi_display
, context
->fmt
->fbconfig
, shareList
, GL_TRUE
, NULL
);
1341 else if(context
->fmt
->visual
)
1342 ctx
= pglXCreateContext(gdi_display
, context
->fmt
->visual
, shareList
, GL_TRUE
);
1343 else /* Create a GLX Context for a pbuffer */
1344 ctx
= pglXCreateNewContext(gdi_display
, context
->fmt
->fbconfig
, context
->fmt
->render_type
, shareList
, TRUE
);
1350 /***********************************************************************
1351 * create_gl_drawable
1353 static struct gl_drawable
*create_gl_drawable( HWND hwnd
, const struct wgl_pixel_format
*format
)
1355 struct gl_drawable
*gl
, *prev
;
1356 XVisualInfo
*visual
= format
->visual
;
1360 GetClientRect( hwnd
, &rect
);
1361 width
= min( max( 1, rect
.right
), 65535 );
1362 height
= min( max( 1, rect
.bottom
), 65535 );
1364 if (!(gl
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*gl
) ))) return NULL
;
1366 /* Default GLX and WGL swap interval is 1, but in case of glXSwapIntervalSGI
1367 * there is no way to query it, so we have to store it here.
1369 gl
->swap_interval
= 1;
1370 gl
->refresh_swap_interval
= TRUE
;
1371 gl
->format
= format
;
1374 if (GetAncestor( hwnd
, GA_PARENT
) == GetDesktopWindow()) /* top-level window */
1376 gl
->type
= DC_GL_WINDOW
;
1377 gl
->window
= create_client_window( hwnd
, visual
);
1379 gl
->drawable
= pglXCreateWindow( gdi_display
, gl
->format
->fbconfig
, gl
->window
, NULL
);
1380 TRACE( "%p created client %lx drawable %lx\n", hwnd
, gl
->window
, gl
->drawable
);
1382 #ifdef SONAME_LIBXCOMPOSITE
1383 else if(usexcomposite
)
1385 gl
->type
= DC_GL_CHILD_WIN
;
1386 gl
->window
= create_client_window( hwnd
, visual
);
1389 gl
->drawable
= pglXCreateWindow( gdi_display
, gl
->format
->fbconfig
, gl
->window
, NULL
);
1390 pXCompositeRedirectWindow( gdi_display
, gl
->window
, CompositeRedirectManual
);
1392 TRACE( "%p created child %lx drawable %lx\n", hwnd
, gl
->window
, gl
->drawable
);
1397 WARN("XComposite is not available, using GLXPixmap hack\n");
1399 gl
->type
= DC_GL_PIXMAP_WIN
;
1400 gl
->pixmap
= XCreatePixmap( gdi_display
, root_window
, width
, height
, visual
->depth
);
1403 gl
->drawable
= pglXCreatePixmap( gdi_display
, gl
->format
->fbconfig
, gl
->pixmap
, NULL
);
1404 if (!gl
->drawable
) XFreePixmap( gdi_display
, gl
->pixmap
);
1405 gl
->pixmap_size
.cx
= width
;
1406 gl
->pixmap_size
.cy
= height
;
1412 HeapFree( GetProcessHeap(), 0, gl
);
1416 EnterCriticalSection( &context_section
);
1417 if (!XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&prev
))
1419 gl
->swap_interval
= prev
->swap_interval
;
1420 release_gl_drawable( prev
);
1422 XSaveContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char *)grab_gl_drawable(gl
) );
1423 LeaveCriticalSection( &context_section
);
1428 /***********************************************************************
1431 static BOOL
set_win_format( HWND hwnd
, const struct wgl_pixel_format
*format
)
1433 struct gl_drawable
*gl
;
1435 if (!format
->visual
) return FALSE
;
1437 if (!(gl
= create_gl_drawable( hwnd
, format
))) return FALSE
;
1439 TRACE( "created GL drawable %lx for win %p %s\n",
1440 gl
->drawable
, hwnd
, debugstr_fbconfig( format
->fbconfig
));
1442 XFlush( gdi_display
);
1443 release_gl_drawable( gl
);
1445 __wine_set_pixel_format( hwnd
, pixel_format_index( format
));
1450 static BOOL
set_pixel_format(HDC hdc
, int format
, BOOL allow_change
)
1452 const struct wgl_pixel_format
*fmt
;
1454 HWND hwnd
= WindowFromDC( hdc
);
1456 TRACE("(%p,%d)\n", hdc
, format
);
1458 if (!hwnd
|| hwnd
== GetDesktopWindow())
1460 WARN( "not a valid window DC %p/%p\n", hdc
, hwnd
);
1464 fmt
= get_pixel_format(gdi_display
, format
, FALSE
/* Offscreen */);
1467 ERR( "Invalid format %d\n", format
);
1471 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1472 if (!(value
& GLX_WINDOW_BIT
))
1474 WARN( "Pixel format %d is not compatible for window rendering\n", format
);
1480 struct gl_drawable
*gl
;
1481 if ((gl
= get_gl_drawable( hwnd
, hdc
)))
1483 int prev
= pixel_format_index( gl
->format
);
1484 release_gl_drawable( gl
);
1485 return prev
== format
; /* cannot change it if already set */
1489 return set_win_format( hwnd
, fmt
);
1493 /***********************************************************************
1496 void sync_gl_drawable( HWND hwnd
)
1498 struct gl_drawable
*old
, *new;
1500 if (!(old
= get_gl_drawable( hwnd
, 0 ))) return;
1504 case DC_GL_PIXMAP_WIN
:
1505 if (!(new = create_gl_drawable( hwnd
, old
->format
))) break;
1506 mark_drawable_dirty( old
, new );
1507 XFlush( gdi_display
);
1508 TRACE( "Recreated GL drawable %lx to replace %lx\n", new->drawable
, old
->drawable
);
1509 release_gl_drawable( new );
1514 release_gl_drawable( old
);
1518 /***********************************************************************
1519 * set_gl_drawable_parent
1521 void set_gl_drawable_parent( HWND hwnd
, HWND parent
)
1523 struct gl_drawable
*old
, *new;
1525 if (!(old
= get_gl_drawable( hwnd
, 0 ))) return;
1527 TRACE( "setting drawable %lx parent %p\n", old
->drawable
, parent
);
1533 case DC_GL_CHILD_WIN
:
1534 case DC_GL_PIXMAP_WIN
:
1535 if (parent
== GetDesktopWindow()) break;
1538 release_gl_drawable( old
);
1542 if ((new = create_gl_drawable( hwnd
, old
->format
)))
1544 mark_drawable_dirty( old
, new );
1545 release_gl_drawable( new );
1549 destroy_gl_drawable( hwnd
);
1550 __wine_set_pixel_format( hwnd
, 0 );
1552 release_gl_drawable( old
);
1556 /***********************************************************************
1557 * destroy_gl_drawable
1559 void destroy_gl_drawable( HWND hwnd
)
1561 struct gl_drawable
*gl
;
1563 EnterCriticalSection( &context_section
);
1564 if (!XFindContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
, (char **)&gl
))
1566 XDeleteContext( gdi_display
, (XID
)hwnd
, gl_hwnd_context
);
1567 release_gl_drawable( gl
);
1569 LeaveCriticalSection( &context_section
);
1574 * glxdrv_DescribePixelFormat
1576 * Get the pixel-format descriptor associated to the given id
1578 static int glxdrv_wglDescribePixelFormat( HDC hdc
, int iPixelFormat
,
1579 UINT nBytes
, PIXELFORMATDESCRIPTOR
*ppfd
)
1581 /*XVisualInfo *vis;*/
1584 const struct wgl_pixel_format
*fmt
;
1586 if (!has_opengl()) return 0;
1588 TRACE("(%p,%d,%d,%p)\n", hdc
, iPixelFormat
, nBytes
, ppfd
);
1590 if (!ppfd
) return nb_onscreen_formats
;
1592 /* 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 */
1593 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, FALSE
/* Offscreen */);
1595 WARN("unexpected format %d\n", iPixelFormat
);
1599 if (nBytes
< sizeof(PIXELFORMATDESCRIPTOR
)) {
1600 ERR("Wrong structure size !\n");
1601 /* Should set error */
1605 memset(ppfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
1606 ppfd
->nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1609 /* These flags are always the same... */
1610 ppfd
->dwFlags
= PFD_SUPPORT_OPENGL
;
1611 /* Now the flags extracted from the Visual */
1613 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &value
);
1614 if(value
& GLX_WINDOW_BIT
)
1615 ppfd
->dwFlags
|= PFD_DRAW_TO_WINDOW
;
1617 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1618 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1619 * 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
1620 * offered the GDI bit either. */
1621 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_DRAW_TO_BITMAP
| PFD_SUPPORT_GDI
);
1623 /* PFD_GENERIC_FORMAT - gdi software rendering
1624 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1625 * none set - full hardware accelerated by a ICD
1627 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1628 ppfd
->dwFlags
|= fmt
->dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
);
1630 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DOUBLEBUFFER
, &value
);
1632 ppfd
->dwFlags
|= PFD_DOUBLEBUFFER
;
1633 ppfd
->dwFlags
&= ~PFD_SUPPORT_GDI
;
1635 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STEREO
, &value
); if (value
) ppfd
->dwFlags
|= PFD_STEREO
;
1638 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RENDER_TYPE
, &value
);
1639 if (value
& GLX_RGBA_BIT
)
1640 ppfd
->iPixelType
= PFD_TYPE_RGBA
;
1642 ppfd
->iPixelType
= PFD_TYPE_COLORINDEX
;
1645 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BUFFER_SIZE
, &value
);
1646 ppfd
->cColorBits
= value
;
1648 /* Red, green, blue and alpha bits / shifts */
1649 if (ppfd
->iPixelType
== PFD_TYPE_RGBA
) {
1650 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_RED_SIZE
, &rb
);
1651 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_GREEN_SIZE
, &gb
);
1652 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_BLUE_SIZE
, &bb
);
1653 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ALPHA_SIZE
, &ab
);
1655 ppfd
->cRedBits
= rb
;
1656 ppfd
->cRedShift
= gb
+ bb
+ ab
;
1657 ppfd
->cBlueBits
= bb
;
1658 ppfd
->cBlueShift
= ab
;
1659 ppfd
->cGreenBits
= gb
;
1660 ppfd
->cGreenShift
= bb
+ ab
;
1661 ppfd
->cAlphaBits
= ab
;
1662 ppfd
->cAlphaShift
= 0;
1665 ppfd
->cRedShift
= 0;
1666 ppfd
->cBlueBits
= 0;
1667 ppfd
->cBlueShift
= 0;
1668 ppfd
->cGreenBits
= 0;
1669 ppfd
->cGreenShift
= 0;
1670 ppfd
->cAlphaBits
= 0;
1671 ppfd
->cAlphaShift
= 0;
1674 /* Accum RGBA bits */
1675 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &rb
);
1676 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &gb
);
1677 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &bb
);
1678 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &ab
);
1680 ppfd
->cAccumBits
= rb
+gb
+bb
+ab
;
1681 ppfd
->cAccumRedBits
= rb
;
1682 ppfd
->cAccumGreenBits
= gb
;
1683 ppfd
->cAccumBlueBits
= bb
;
1684 ppfd
->cAccumAlphaBits
= ab
;
1687 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_AUX_BUFFERS
, &value
);
1688 ppfd
->cAuxBuffers
= value
;
1691 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DEPTH_SIZE
, &value
);
1692 ppfd
->cDepthBits
= value
;
1695 pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_STENCIL_SIZE
, &value
);
1696 ppfd
->cStencilBits
= value
;
1698 ppfd
->iLayerType
= PFD_MAIN_PLANE
;
1700 if (TRACE_ON(wgl
)) {
1701 dump_PIXELFORMATDESCRIPTOR(ppfd
);
1704 return nb_onscreen_formats
;
1707 /***********************************************************************
1708 * glxdrv_wglGetPixelFormat
1710 static int glxdrv_wglGetPixelFormat( HDC hdc
)
1712 struct gl_drawable
*gl
;
1715 if ((gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1717 ret
= pixel_format_index( gl
->format
);
1718 /* Offscreen formats can't be used with traditional WGL calls.
1719 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1720 if (!is_onscreen_pixel_format( ret
)) ret
= 1;
1721 release_gl_drawable( gl
);
1723 TRACE( "%p -> %d\n", hdc
, ret
);
1727 /***********************************************************************
1728 * glxdrv_wglSetPixelFormat
1730 static BOOL
glxdrv_wglSetPixelFormat( HDC hdc
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1732 return set_pixel_format(hdc
, iPixelFormat
, FALSE
);
1735 /***********************************************************************
1736 * glxdrv_wglCopyContext
1738 static BOOL
glxdrv_wglCopyContext(struct wgl_context
*src
, struct wgl_context
*dst
, UINT mask
)
1740 TRACE("%p -> %p mask %#x\n", src
, dst
, mask
);
1742 pglXCopyContext(gdi_display
, src
->ctx
, dst
->ctx
, mask
);
1744 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1748 /***********************************************************************
1749 * glxdrv_wglCreateContext
1751 static struct wgl_context
*glxdrv_wglCreateContext( HDC hdc
)
1753 struct wgl_context
*ret
;
1754 struct gl_drawable
*gl
;
1756 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1758 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1762 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
))))
1765 ret
->fmt
= gl
->format
;
1766 ret
->ctx
= create_glxcontext(gdi_display
, ret
, NULL
);
1767 EnterCriticalSection( &context_section
);
1768 list_add_head( &context_list
, &ret
->entry
);
1769 LeaveCriticalSection( &context_section
);
1771 release_gl_drawable( gl
);
1772 TRACE( "%p -> %p\n", hdc
, ret
);
1776 /***********************************************************************
1777 * glxdrv_wglDeleteContext
1779 static BOOL
glxdrv_wglDeleteContext(struct wgl_context
*ctx
)
1781 struct wgl_pbuffer
*pb
;
1783 TRACE("(%p)\n", ctx
);
1785 EnterCriticalSection( &context_section
);
1786 list_remove( &ctx
->entry
);
1787 LIST_FOR_EACH_ENTRY( pb
, &pbuffer_list
, struct wgl_pbuffer
, entry
)
1789 if (pb
->prev_context
== ctx
->ctx
) {
1790 pglXDestroyContext(gdi_display
, pb
->tmp_context
);
1791 pb
->prev_context
= pb
->tmp_context
= NULL
;
1794 LeaveCriticalSection( &context_section
);
1796 if (ctx
->ctx
) pglXDestroyContext( gdi_display
, ctx
->ctx
);
1797 release_gl_drawable( ctx
->drawables
[0] );
1798 release_gl_drawable( ctx
->drawables
[1] );
1799 release_gl_drawable( ctx
->new_drawables
[0] );
1800 release_gl_drawable( ctx
->new_drawables
[1] );
1801 return HeapFree( GetProcessHeap(), 0, ctx
);
1804 /***********************************************************************
1805 * glxdrv_wglGetProcAddress
1807 static PROC
glxdrv_wglGetProcAddress(LPCSTR lpszProc
)
1809 if (!strncmp(lpszProc
, "wgl", 3)) return NULL
;
1810 return pglXGetProcAddressARB((const GLubyte
*)lpszProc
);
1813 static void set_context_drawables( struct wgl_context
*ctx
, struct gl_drawable
*draw
,
1814 struct gl_drawable
*read
)
1816 struct gl_drawable
*prev
[4];
1819 prev
[0] = ctx
->drawables
[0];
1820 prev
[1] = ctx
->drawables
[1];
1821 prev
[2] = ctx
->new_drawables
[0];
1822 prev
[3] = ctx
->new_drawables
[1];
1823 ctx
->drawables
[0] = grab_gl_drawable( draw
);
1824 ctx
->drawables
[1] = read
? grab_gl_drawable( read
) : NULL
;
1825 ctx
->new_drawables
[0] = ctx
->new_drawables
[1] = NULL
;
1826 for (i
= 0; i
< 4; i
++) release_gl_drawable( prev
[i
] );
1829 /***********************************************************************
1830 * glxdrv_wglMakeCurrent
1832 static BOOL
glxdrv_wglMakeCurrent(HDC hdc
, struct wgl_context
*ctx
)
1835 struct gl_drawable
*gl
;
1837 TRACE("(%p,%p)\n", hdc
, ctx
);
1841 pglXMakeCurrent(gdi_display
, None
, NULL
);
1842 NtCurrentTeb()->glContext
= NULL
;
1846 if ((gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
1848 if (ctx
->fmt
!= gl
->format
)
1850 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc
, gl
->format
, ctx
, ctx
->fmt
);
1851 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
1855 TRACE("hdc %p drawable %lx fmt %p ctx %p %s\n", hdc
, gl
->drawable
, gl
->format
, ctx
->ctx
,
1856 debugstr_fbconfig( gl
->format
->fbconfig
));
1858 EnterCriticalSection( &context_section
);
1859 ret
= pglXMakeCurrent(gdi_display
, gl
->drawable
, ctx
->ctx
);
1862 NtCurrentTeb()->glContext
= ctx
;
1863 ctx
->has_been_current
= TRUE
;
1865 set_context_drawables( ctx
, gl
, gl
);
1866 ctx
->refresh_drawables
= FALSE
;
1867 LeaveCriticalSection( &context_section
);
1870 LeaveCriticalSection( &context_section
);
1872 SetLastError( ERROR_INVALID_HANDLE
);
1875 release_gl_drawable( gl
);
1876 TRACE( "%p,%p returning %d\n", hdc
, ctx
, ret
);
1880 /***********************************************************************
1881 * X11DRV_wglMakeContextCurrentARB
1883 static BOOL
X11DRV_wglMakeContextCurrentARB( HDC draw_hdc
, HDC read_hdc
, struct wgl_context
*ctx
)
1886 struct gl_drawable
*draw_gl
, *read_gl
= NULL
;
1888 TRACE("(%p,%p,%p)\n", draw_hdc
, read_hdc
, ctx
);
1892 pglXMakeCurrent(gdi_display
, None
, NULL
);
1893 NtCurrentTeb()->glContext
= NULL
;
1897 if (!pglXMakeContextCurrent
) return FALSE
;
1899 if ((draw_gl
= get_gl_drawable( WindowFromDC( draw_hdc
), draw_hdc
)))
1901 read_gl
= get_gl_drawable( WindowFromDC( read_hdc
), read_hdc
);
1903 EnterCriticalSection( &context_section
);
1904 ret
= pglXMakeContextCurrent(gdi_display
, draw_gl
->drawable
,
1905 read_gl
? read_gl
->drawable
: 0, ctx
->ctx
);
1908 ctx
->has_been_current
= TRUE
;
1909 ctx
->hdc
= draw_hdc
;
1910 set_context_drawables( ctx
, draw_gl
, read_gl
);
1911 ctx
->refresh_drawables
= FALSE
;
1912 NtCurrentTeb()->glContext
= ctx
;
1913 LeaveCriticalSection( &context_section
);
1916 LeaveCriticalSection( &context_section
);
1918 SetLastError( ERROR_INVALID_HANDLE
);
1920 release_gl_drawable( read_gl
);
1921 release_gl_drawable( draw_gl
);
1922 TRACE( "%p,%p,%p returning %d\n", draw_hdc
, read_hdc
, ctx
, ret
);
1926 /***********************************************************************
1927 * glxdrv_wglShareLists
1929 static BOOL
glxdrv_wglShareLists(struct wgl_context
*org
, struct wgl_context
*dest
)
1931 TRACE("(%p, %p)\n", org
, dest
);
1933 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1934 * at context creation time but in case of WGL it is done using wglShareLists.
1935 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1936 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1937 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1938 * so there delaying context creation doesn't work.
1940 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1941 * and when a program requests sharing we recreate the destination context if it hasn't been made
1942 * current or when it hasn't shared display lists before.
1945 if((org
->has_been_current
&& dest
->has_been_current
) || dest
->has_been_current
)
1947 ERR("Could not share display lists, one of the contexts has been current already !\n");
1950 else if(dest
->sharing
)
1952 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1957 /* Re-create the GLX context and share display lists */
1958 pglXDestroyContext(gdi_display
, dest
->ctx
);
1959 dest
->ctx
= create_glxcontext(gdi_display
, dest
, org
->ctx
);
1960 TRACE(" re-created context (%p) for Wine context %p (%s) sharing lists with ctx %p (%s)\n",
1961 dest
->ctx
, dest
, debugstr_fbconfig(dest
->fmt
->fbconfig
),
1962 org
->ctx
, debugstr_fbconfig( org
->fmt
->fbconfig
));
1964 org
->sharing
= TRUE
;
1965 dest
->sharing
= TRUE
;
1971 static void wglFinish(void)
1973 struct x11drv_escape_flush_gl_drawable escape
;
1974 struct gl_drawable
*gl
;
1975 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
1977 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
1978 escape
.gl_drawable
= 0;
1979 escape
.flush
= FALSE
;
1981 if ((gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), 0 )))
1985 case DC_GL_PIXMAP_WIN
: escape
.gl_drawable
= gl
->pixmap
; break;
1986 case DC_GL_CHILD_WIN
: escape
.gl_drawable
= gl
->window
; break;
1990 release_gl_drawable( gl
);
1994 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1997 static void wglFlush(void)
1999 struct x11drv_escape_flush_gl_drawable escape
;
2000 struct gl_drawable
*gl
;
2001 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
2003 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
2004 escape
.gl_drawable
= 0;
2005 escape
.flush
= FALSE
;
2007 if ((gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), 0 )))
2011 case DC_GL_PIXMAP_WIN
: escape
.gl_drawable
= gl
->pixmap
; break;
2012 case DC_GL_CHILD_WIN
: escape
.gl_drawable
= gl
->window
; break;
2016 release_gl_drawable( gl
);
2020 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2023 static const GLubyte
*wglGetString(GLenum name
)
2025 if (name
== GL_EXTENSIONS
&& glExtensions
) return (const GLubyte
*)glExtensions
;
2026 return pglGetString(name
);
2029 /***********************************************************************
2030 * X11DRV_wglCreateContextAttribsARB
2032 static struct wgl_context
*X11DRV_wglCreateContextAttribsARB( HDC hdc
, struct wgl_context
*hShareContext
,
2033 const int* attribList
)
2035 struct wgl_context
*ret
;
2036 struct gl_drawable
*gl
;
2039 TRACE("(%p %p %p)\n", hdc
, hShareContext
, attribList
);
2041 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
2043 SetLastError( ERROR_INVALID_PIXEL_FORMAT
);
2047 if ((ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
))))
2050 ret
->fmt
= gl
->format
;
2051 ret
->gl3_context
= TRUE
;
2054 int *pContextAttribList
= &ret
->attribList
[0];
2055 /* attribList consists of pairs {token, value] terminated with 0 */
2056 while(attribList
[0] != 0)
2058 TRACE("%#x %#x\n", attribList
[0], attribList
[1]);
2059 switch(attribList
[0])
2061 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
2062 pContextAttribList
[0] = GLX_CONTEXT_MAJOR_VERSION_ARB
;
2063 pContextAttribList
[1] = attribList
[1];
2064 pContextAttribList
+= 2;
2067 case WGL_CONTEXT_MINOR_VERSION_ARB
:
2068 pContextAttribList
[0] = GLX_CONTEXT_MINOR_VERSION_ARB
;
2069 pContextAttribList
[1] = attribList
[1];
2070 pContextAttribList
+= 2;
2073 case WGL_CONTEXT_LAYER_PLANE_ARB
:
2075 case WGL_CONTEXT_FLAGS_ARB
:
2076 pContextAttribList
[0] = GLX_CONTEXT_FLAGS_ARB
;
2077 pContextAttribList
[1] = attribList
[1];
2078 pContextAttribList
+= 2;
2081 case WGL_CONTEXT_OPENGL_NO_ERROR_ARB
:
2082 pContextAttribList
[0] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB
;
2083 pContextAttribList
[1] = attribList
[1];
2084 pContextAttribList
+= 2;
2087 case WGL_CONTEXT_PROFILE_MASK_ARB
:
2088 pContextAttribList
[0] = GLX_CONTEXT_PROFILE_MASK_ARB
;
2089 pContextAttribList
[1] = attribList
[1];
2090 pContextAttribList
+= 2;
2093 case WGL_RENDERER_ID_WINE
:
2094 pContextAttribList
[0] = GLX_RENDERER_ID_MESA
;
2095 pContextAttribList
[1] = attribList
[1];
2096 pContextAttribList
+= 2;
2100 ERR("Unhandled attribList pair: %#x %#x\n", attribList
[0], attribList
[1]);
2106 X11DRV_expect_error(gdi_display
, GLXErrorHandler
, NULL
);
2107 ret
->ctx
= create_glxcontext(gdi_display
, ret
, hShareContext
? hShareContext
->ctx
: NULL
);
2108 XSync(gdi_display
, False
);
2109 if ((err
= X11DRV_check_error()) || !ret
->ctx
)
2111 /* In the future we should convert the GLX error to a win32 one here if needed */
2112 WARN("Context creation failed (error %#x).\n", err
);
2113 HeapFree( GetProcessHeap(), 0, ret
);
2118 EnterCriticalSection( &context_section
);
2119 list_add_head( &context_list
, &ret
->entry
);
2120 LeaveCriticalSection( &context_section
);
2124 release_gl_drawable( gl
);
2125 TRACE( "%p -> %p\n", hdc
, ret
);
2130 * X11DRV_wglGetExtensionsStringARB
2132 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2134 static const char *X11DRV_wglGetExtensionsStringARB(HDC hdc
)
2136 TRACE("() returning \"%s\"\n", wglExtensions
);
2137 return wglExtensions
;
2141 * X11DRV_wglCreatePbufferARB
2143 * WGL_ARB_pbuffer: wglCreatePbufferARB
2145 static struct wgl_pbuffer
*X11DRV_wglCreatePbufferARB( HDC hdc
, int iPixelFormat
, int iWidth
, int iHeight
,
2146 const int *piAttribList
)
2148 struct wgl_pbuffer
* object
;
2149 const struct wgl_pixel_format
*fmt
;
2153 TRACE("(%p, %d, %d, %d, %p)\n", hdc
, iPixelFormat
, iWidth
, iHeight
, piAttribList
);
2155 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2156 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */);
2158 ERR("(%p): invalid pixel format %d\n", hdc
, iPixelFormat
);
2159 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
2163 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2164 if (NULL
== object
) {
2165 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2168 object
->width
= iWidth
;
2169 object
->height
= iHeight
;
2172 PUSH2(attribs
, GLX_PBUFFER_WIDTH
, iWidth
);
2173 PUSH2(attribs
, GLX_PBUFFER_HEIGHT
, iHeight
);
2174 while (piAttribList
&& 0 != *piAttribList
) {
2176 switch (*piAttribList
) {
2177 case WGL_PBUFFER_LARGEST_ARB
: {
2179 attr_v
= *piAttribList
;
2180 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v
);
2181 PUSH2(attribs
, GLX_LARGEST_PBUFFER
, attr_v
);
2185 case WGL_TEXTURE_FORMAT_ARB
: {
2187 attr_v
= *piAttribList
;
2188 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v
);
2189 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2190 object
->use_render_texture
= 0;
2192 if (!use_render_texture_emulation
) {
2193 SetLastError(ERROR_INVALID_DATA
);
2197 case WGL_TEXTURE_RGB_ARB
:
2198 object
->use_render_texture
= GL_RGB
;
2199 object
->texture_bpp
= 3;
2200 object
->texture_format
= GL_RGB
;
2201 object
->texture_type
= GL_UNSIGNED_BYTE
;
2203 case WGL_TEXTURE_RGBA_ARB
:
2204 object
->use_render_texture
= GL_RGBA
;
2205 object
->texture_bpp
= 4;
2206 object
->texture_format
= GL_RGBA
;
2207 object
->texture_type
= GL_UNSIGNED_BYTE
;
2210 /* WGL_FLOAT_COMPONENTS_NV */
2211 case WGL_TEXTURE_FLOAT_R_NV
:
2212 object
->use_render_texture
= GL_FLOAT_R_NV
;
2213 object
->texture_bpp
= 4;
2214 object
->texture_format
= GL_RED
;
2215 object
->texture_type
= GL_FLOAT
;
2217 case WGL_TEXTURE_FLOAT_RG_NV
:
2218 object
->use_render_texture
= GL_FLOAT_RG_NV
;
2219 object
->texture_bpp
= 8;
2220 object
->texture_format
= GL_LUMINANCE_ALPHA
;
2221 object
->texture_type
= GL_FLOAT
;
2223 case WGL_TEXTURE_FLOAT_RGB_NV
:
2224 object
->use_render_texture
= GL_FLOAT_RGB_NV
;
2225 object
->texture_bpp
= 12;
2226 object
->texture_format
= GL_RGB
;
2227 object
->texture_type
= GL_FLOAT
;
2229 case WGL_TEXTURE_FLOAT_RGBA_NV
:
2230 object
->use_render_texture
= GL_FLOAT_RGBA_NV
;
2231 object
->texture_bpp
= 16;
2232 object
->texture_format
= GL_RGBA
;
2233 object
->texture_type
= GL_FLOAT
;
2236 ERR("Unknown texture format: %x\n", attr_v
);
2237 SetLastError(ERROR_INVALID_DATA
);
2244 case WGL_TEXTURE_TARGET_ARB
: {
2246 attr_v
= *piAttribList
;
2247 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v
);
2248 if (WGL_NO_TEXTURE_ARB
== attr_v
) {
2249 object
->texture_target
= 0;
2251 if (!use_render_texture_emulation
) {
2252 SetLastError(ERROR_INVALID_DATA
);
2256 case WGL_TEXTURE_CUBE_MAP_ARB
: {
2257 if (iWidth
!= iHeight
) {
2258 SetLastError(ERROR_INVALID_DATA
);
2261 object
->texture_target
= GL_TEXTURE_CUBE_MAP
;
2262 object
->texture_bind_target
= GL_TEXTURE_BINDING_CUBE_MAP
;
2265 case WGL_TEXTURE_1D_ARB
: {
2267 SetLastError(ERROR_INVALID_DATA
);
2270 object
->texture_target
= GL_TEXTURE_1D
;
2271 object
->texture_bind_target
= GL_TEXTURE_BINDING_1D
;
2274 case WGL_TEXTURE_2D_ARB
: {
2275 object
->texture_target
= GL_TEXTURE_2D
;
2276 object
->texture_bind_target
= GL_TEXTURE_BINDING_2D
;
2279 case WGL_TEXTURE_RECTANGLE_NV
: {
2280 object
->texture_target
= GL_TEXTURE_RECTANGLE_NV
;
2281 object
->texture_bind_target
= GL_TEXTURE_BINDING_RECTANGLE_NV
;
2285 ERR("Unknown texture target: %x\n", attr_v
);
2286 SetLastError(ERROR_INVALID_DATA
);
2293 case WGL_MIPMAP_TEXTURE_ARB
: {
2295 attr_v
= *piAttribList
;
2296 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v
);
2297 if (!use_render_texture_emulation
) {
2298 SetLastError(ERROR_INVALID_DATA
);
2307 PUSH1(attribs
, None
);
2308 object
->drawable
= pglXCreatePbuffer(gdi_display
, fmt
->fbconfig
, attribs
);
2309 TRACE("new Pbuffer drawable as %lx\n", object
->drawable
);
2310 if (!object
->drawable
) {
2311 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
2312 goto create_failed
; /* unexpected error */
2314 EnterCriticalSection( &context_section
);
2315 list_add_head( &pbuffer_list
, &object
->entry
);
2316 LeaveCriticalSection( &context_section
);
2317 TRACE("->(%p)\n", object
);
2321 HeapFree(GetProcessHeap(), 0, object
);
2322 TRACE("->(FAILED)\n");
2327 * X11DRV_wglDestroyPbufferARB
2329 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2331 static BOOL
X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer
*object
)
2333 TRACE("(%p)\n", object
);
2335 EnterCriticalSection( &context_section
);
2336 list_remove( &object
->entry
);
2337 LeaveCriticalSection( &context_section
);
2338 pglXDestroyPbuffer(gdi_display
, object
->drawable
);
2339 if (object
->tmp_context
)
2340 pglXDestroyContext(gdi_display
, object
->tmp_context
);
2341 HeapFree(GetProcessHeap(), 0, object
);
2346 * X11DRV_wglGetPbufferDCARB
2348 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2350 static HDC
X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer
*object
)
2352 struct x11drv_escape_set_drawable escape
;
2353 struct gl_drawable
*gl
, *prev
;
2356 hdc
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
);
2359 if (!(gl
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*gl
) )))
2364 gl
->type
= DC_GL_PBUFFER
;
2365 gl
->drawable
= object
->drawable
;
2366 gl
->format
= object
->fmt
;
2369 EnterCriticalSection( &context_section
);
2370 if (!XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&prev
))
2371 release_gl_drawable( prev
);
2372 XSaveContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char *)gl
);
2373 LeaveCriticalSection( &context_section
);
2375 escape
.code
= X11DRV_SET_DRAWABLE
;
2376 escape
.drawable
= object
->drawable
;
2377 escape
.mode
= IncludeInferiors
;
2378 SetRect( &escape
.dc_rect
, 0, 0, object
->width
, object
->height
);
2379 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2381 TRACE( "(%p)->(%p)\n", object
, hdc
);
2386 * X11DRV_wglQueryPbufferARB
2388 * WGL_ARB_pbuffer: wglQueryPbufferARB
2390 static BOOL
X11DRV_wglQueryPbufferARB( struct wgl_pbuffer
*object
, int iAttribute
, int *piValue
)
2392 TRACE("(%p, 0x%x, %p)\n", object
, iAttribute
, piValue
);
2394 switch (iAttribute
) {
2395 case WGL_PBUFFER_WIDTH_ARB
:
2396 pglXQueryDrawable(gdi_display
, object
->drawable
, GLX_WIDTH
, (unsigned int*) piValue
);
2398 case WGL_PBUFFER_HEIGHT_ARB
:
2399 pglXQueryDrawable(gdi_display
, object
->drawable
, GLX_HEIGHT
, (unsigned int*) piValue
);
2402 case WGL_PBUFFER_LOST_ARB
:
2403 /* GLX Pbuffers cannot be lost by default. We can support this by
2404 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2405 * to receive pixel buffer clobber events, however that may or may
2406 * not give any benefit */
2407 *piValue
= GL_FALSE
;
2410 case WGL_TEXTURE_FORMAT_ARB
:
2411 if (!object
->use_render_texture
) {
2412 *piValue
= WGL_NO_TEXTURE_ARB
;
2414 if (!use_render_texture_emulation
) {
2415 SetLastError(ERROR_INVALID_HANDLE
);
2418 switch(object
->use_render_texture
) {
2420 *piValue
= WGL_TEXTURE_RGB_ARB
;
2423 *piValue
= WGL_TEXTURE_RGBA_ARB
;
2425 /* WGL_FLOAT_COMPONENTS_NV */
2427 *piValue
= WGL_TEXTURE_FLOAT_R_NV
;
2429 case GL_FLOAT_RG_NV
:
2430 *piValue
= WGL_TEXTURE_FLOAT_RG_NV
;
2432 case GL_FLOAT_RGB_NV
:
2433 *piValue
= WGL_TEXTURE_FLOAT_RGB_NV
;
2435 case GL_FLOAT_RGBA_NV
:
2436 *piValue
= WGL_TEXTURE_FLOAT_RGBA_NV
;
2439 ERR("Unknown texture format: %x\n", object
->use_render_texture
);
2444 case WGL_TEXTURE_TARGET_ARB
:
2445 if (!object
->texture_target
){
2446 *piValue
= WGL_NO_TEXTURE_ARB
;
2448 if (!use_render_texture_emulation
) {
2449 SetLastError(ERROR_INVALID_DATA
);
2452 switch (object
->texture_target
) {
2453 case GL_TEXTURE_1D
: *piValue
= WGL_TEXTURE_1D_ARB
; break;
2454 case GL_TEXTURE_2D
: *piValue
= WGL_TEXTURE_2D_ARB
; break;
2455 case GL_TEXTURE_CUBE_MAP
: *piValue
= WGL_TEXTURE_CUBE_MAP_ARB
; break;
2456 case GL_TEXTURE_RECTANGLE_NV
: *piValue
= WGL_TEXTURE_RECTANGLE_NV
; break;
2461 case WGL_MIPMAP_TEXTURE_ARB
:
2462 *piValue
= GL_FALSE
; /** don't support that */
2463 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute
);
2467 FIXME("unexpected attribute %x\n", iAttribute
);
2475 * X11DRV_wglReleasePbufferDCARB
2477 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2479 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer
*object
, HDC hdc
)
2481 struct gl_drawable
*gl
;
2483 TRACE("(%p, %p)\n", object
, hdc
);
2485 EnterCriticalSection( &context_section
);
2487 if (!XFindContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
, (char **)&gl
))
2489 XDeleteContext( gdi_display
, (XID
)hdc
, gl_pbuffer_context
);
2490 release_gl_drawable( gl
);
2494 LeaveCriticalSection( &context_section
);
2496 return hdc
&& DeleteDC(hdc
);
2500 * X11DRV_wglSetPbufferAttribARB
2502 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2504 static BOOL
X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer
*object
, const int *piAttribList
)
2506 GLboolean ret
= GL_FALSE
;
2508 WARN("(%p, %p): alpha-testing, report any problem\n", object
, piAttribList
);
2510 if (!object
->use_render_texture
) {
2511 SetLastError(ERROR_INVALID_HANDLE
);
2514 if (use_render_texture_emulation
) {
2521 * X11DRV_wglChoosePixelFormatARB
2523 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2525 static BOOL
X11DRV_wglChoosePixelFormatARB( HDC hdc
, const int *piAttribIList
, const FLOAT
*pfAttribFList
,
2526 UINT nMaxFormats
, int *piFormats
, UINT
*nNumFormats
)
2540 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc
, piAttribIList
, pfAttribFList
, nMaxFormats
, piFormats
, nNumFormats
);
2541 if (NULL
!= pfAttribFList
) {
2542 FIXME("unused pfAttribFList\n");
2545 nAttribs
= ConvertAttribWGLtoGLX(piAttribIList
, attribs
, NULL
);
2546 if (-1 == nAttribs
) {
2547 WARN("Cannot convert WGL to GLX attributes\n");
2550 PUSH1(attribs
, None
);
2552 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2553 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2554 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2556 for(i
=0; piAttribIList
[i
] != 0; i
+=2)
2558 switch(piAttribIList
[i
])
2560 case WGL_DRAW_TO_BITMAP_ARB
:
2561 if(piAttribIList
[i
+1])
2562 dwFlags
|= PFD_DRAW_TO_BITMAP
;
2564 case WGL_ACCELERATION_ARB
:
2565 switch(piAttribIList
[i
+1])
2567 case WGL_NO_ACCELERATION_ARB
:
2568 dwFlags
|= PFD_GENERIC_FORMAT
;
2570 case WGL_GENERIC_ACCELERATION_ARB
:
2571 dwFlags
|= PFD_GENERIC_ACCELERATED
;
2573 case WGL_FULL_ACCELERATION_ARB
:
2578 case WGL_SUPPORT_GDI_ARB
:
2579 if(piAttribIList
[i
+1])
2580 dwFlags
|= PFD_SUPPORT_GDI
;
2585 /* Search for FB configurations matching the requirements in attribs */
2586 cfgs
= pglXChooseFBConfig(gdi_display
, DefaultScreen(gdi_display
), attribs
, &nCfgs
);
2588 WARN("Compatible Pixel Format not found\n");
2592 /* Loop through all matching formats and check if they are suitable.
2593 * Note that this function should at max return nMaxFormats different formats */
2594 for(run
=0; run
< 2; run
++)
2596 for (it
= 0; it
< nCfgs
&& pfmt_it
< nMaxFormats
; ++it
)
2598 if (pglXGetFBConfigAttrib(gdi_display
, cfgs
[it
], GLX_FBCONFIG_ID
, &fmt_id
))
2600 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2604 /* During the first run we only want onscreen formats and during the second only offscreen */
2605 start
= run
== 1 ? nb_onscreen_formats
: 0;
2606 end
= run
== 1 ? nb_pixel_formats
: nb_onscreen_formats
;
2608 for (i
= start
; i
< end
; i
++)
2610 if (pixel_formats
[i
].fmt_id
== fmt_id
&& (pixel_formats
[i
].dwFlags
& dwFlags
) == dwFlags
)
2612 piFormats
[pfmt_it
++] = i
+ 1;
2613 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2614 it
+ 1, nCfgs
, fmt_id
, i
+ 1);
2621 *nNumFormats
= pfmt_it
;
2628 * X11DRV_wglGetPixelFormatAttribivARB
2630 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2632 static BOOL
X11DRV_wglGetPixelFormatAttribivARB( HDC hdc
, int iPixelFormat
, int iLayerPlane
,
2633 UINT nAttributes
, const int *piAttributes
, int *piValues
)
2636 const struct wgl_pixel_format
*fmt
;
2641 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, piValues
);
2643 if (0 < iLayerPlane
) {
2644 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane
);
2648 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2649 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2650 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2651 fmt
= get_pixel_format(gdi_display
, iPixelFormat
, TRUE
/* Offscreen */);
2653 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat
);
2656 for (i
= 0; i
< nAttributes
; ++i
) {
2657 const int curWGLAttr
= piAttributes
[i
];
2658 TRACE("pAttr[%d] = %x\n", i
, curWGLAttr
);
2660 switch (curWGLAttr
) {
2661 case WGL_NUMBER_PIXEL_FORMATS_ARB
:
2662 piValues
[i
] = nb_pixel_formats
;
2665 case WGL_SUPPORT_OPENGL_ARB
:
2666 piValues
[i
] = GL_TRUE
;
2669 case WGL_ACCELERATION_ARB
:
2670 curGLXAttr
= GLX_CONFIG_CAVEAT
;
2671 if (!fmt
) goto pix_error
;
2672 if(fmt
->dwFlags
& PFD_GENERIC_FORMAT
)
2673 piValues
[i
] = WGL_NO_ACCELERATION_ARB
;
2674 else if(fmt
->dwFlags
& PFD_GENERIC_ACCELERATED
)
2675 piValues
[i
] = WGL_GENERIC_ACCELERATION_ARB
;
2677 piValues
[i
] = WGL_FULL_ACCELERATION_ARB
;
2680 case WGL_TRANSPARENT_ARB
:
2681 curGLXAttr
= GLX_TRANSPARENT_TYPE
;
2682 if (!fmt
) goto pix_error
;
2683 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2684 if (hTest
) goto get_error
;
2685 piValues
[i
] = GL_FALSE
;
2686 if (GLX_NONE
!= tmp
) piValues
[i
] = GL_TRUE
;
2689 case WGL_PIXEL_TYPE_ARB
:
2690 curGLXAttr
= GLX_RENDER_TYPE
;
2691 if (!fmt
) goto pix_error
;
2692 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2693 if (hTest
) goto get_error
;
2694 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp
);
2695 if (tmp
& GLX_RGBA_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_ARB
; }
2696 else if (tmp
& GLX_COLOR_INDEX_BIT
) { piValues
[i
] = WGL_TYPE_COLORINDEX_ARB
; }
2697 else if (tmp
& GLX_RGBA_FLOAT_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2698 else if (tmp
& GLX_RGBA_FLOAT_ATI_BIT
) { piValues
[i
] = WGL_TYPE_RGBA_FLOAT_ATI
; }
2699 else if (tmp
& GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
) { piValues
[i
] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
; }
2701 ERR("unexpected RenderType(%x)\n", tmp
);
2702 piValues
[i
] = WGL_TYPE_RGBA_ARB
;
2706 case WGL_COLOR_BITS_ARB
:
2707 curGLXAttr
= GLX_BUFFER_SIZE
;
2710 case WGL_BIND_TO_TEXTURE_RGB_ARB
:
2711 case WGL_BIND_TO_TEXTURE_RGBA_ARB
:
2712 if (!use_render_texture_emulation
) {
2713 piValues
[i
] = GL_FALSE
;
2716 curGLXAttr
= GLX_RENDER_TYPE
;
2717 if (!fmt
) goto pix_error
;
2718 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, &tmp
);
2719 if (hTest
) goto get_error
;
2720 if (GLX_COLOR_INDEX_BIT
== tmp
) {
2721 piValues
[i
] = GL_FALSE
;
2724 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2725 if (hTest
) goto get_error
;
2726 piValues
[i
] = (tmp
& GLX_PBUFFER_BIT
) ? GL_TRUE
: GL_FALSE
;
2729 case WGL_BLUE_BITS_ARB
:
2730 curGLXAttr
= GLX_BLUE_SIZE
;
2732 case WGL_RED_BITS_ARB
:
2733 curGLXAttr
= GLX_RED_SIZE
;
2735 case WGL_GREEN_BITS_ARB
:
2736 curGLXAttr
= GLX_GREEN_SIZE
;
2738 case WGL_ALPHA_BITS_ARB
:
2739 curGLXAttr
= GLX_ALPHA_SIZE
;
2741 case WGL_DEPTH_BITS_ARB
:
2742 curGLXAttr
= GLX_DEPTH_SIZE
;
2744 case WGL_STENCIL_BITS_ARB
:
2745 curGLXAttr
= GLX_STENCIL_SIZE
;
2747 case WGL_DOUBLE_BUFFER_ARB
:
2748 curGLXAttr
= GLX_DOUBLEBUFFER
;
2750 case WGL_STEREO_ARB
:
2751 curGLXAttr
= GLX_STEREO
;
2753 case WGL_AUX_BUFFERS_ARB
:
2754 curGLXAttr
= GLX_AUX_BUFFERS
;
2757 case WGL_SUPPORT_GDI_ARB
:
2758 if (!fmt
) goto pix_error
;
2759 piValues
[i
] = (fmt
->dwFlags
& PFD_SUPPORT_GDI
) != 0;
2762 case WGL_DRAW_TO_BITMAP_ARB
:
2763 if (!fmt
) goto pix_error
;
2764 piValues
[i
] = (fmt
->dwFlags
& PFD_DRAW_TO_BITMAP
) != 0;
2767 case WGL_DRAW_TO_WINDOW_ARB
:
2768 case WGL_DRAW_TO_PBUFFER_ARB
:
2769 if (!fmt
) goto pix_error
;
2770 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_DRAWABLE_TYPE
, &tmp
);
2771 if (hTest
) goto get_error
;
2772 if((curWGLAttr
== WGL_DRAW_TO_WINDOW_ARB
&& (tmp
&GLX_WINDOW_BIT
)) ||
2773 (curWGLAttr
== WGL_DRAW_TO_PBUFFER_ARB
&& (tmp
&GLX_PBUFFER_BIT
)))
2774 piValues
[i
] = GL_TRUE
;
2776 piValues
[i
] = GL_FALSE
;
2779 case WGL_SWAP_METHOD_ARB
:
2780 if (has_swap_method
)
2782 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_SWAP_METHOD_OML
, &tmp
);
2783 if (hTest
) goto get_error
;
2786 case GLX_SWAP_EXCHANGE_OML
:
2787 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2789 case GLX_SWAP_COPY_OML
:
2790 piValues
[i
] = WGL_SWAP_COPY_ARB
;
2792 case GLX_SWAP_UNDEFINED_OML
:
2793 piValues
[i
] = WGL_SWAP_UNDEFINED_ARB
;
2796 ERR("Unexpected swap method %x.\n", tmp
);
2801 WARN("GLX_OML_swap_method not supported, returning WGL_SWAP_EXCHANGE_ARB.\n");
2802 piValues
[i
] = WGL_SWAP_EXCHANGE_ARB
;
2806 case WGL_PBUFFER_LARGEST_ARB
:
2807 curGLXAttr
= GLX_LARGEST_PBUFFER
;
2810 case WGL_SAMPLE_BUFFERS_ARB
:
2811 curGLXAttr
= GLX_SAMPLE_BUFFERS_ARB
;
2814 case WGL_SAMPLES_ARB
:
2815 curGLXAttr
= GLX_SAMPLES_ARB
;
2818 case WGL_FLOAT_COMPONENTS_NV
:
2819 curGLXAttr
= GLX_FLOAT_COMPONENTS_NV
;
2822 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
2823 curGLXAttr
= GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
;
2826 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
:
2827 curGLXAttr
= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
;
2830 case WGL_ACCUM_RED_BITS_ARB
:
2831 curGLXAttr
= GLX_ACCUM_RED_SIZE
;
2833 case WGL_ACCUM_GREEN_BITS_ARB
:
2834 curGLXAttr
= GLX_ACCUM_GREEN_SIZE
;
2836 case WGL_ACCUM_BLUE_BITS_ARB
:
2837 curGLXAttr
= GLX_ACCUM_BLUE_SIZE
;
2839 case WGL_ACCUM_ALPHA_BITS_ARB
:
2840 curGLXAttr
= GLX_ACCUM_ALPHA_SIZE
;
2842 case WGL_ACCUM_BITS_ARB
:
2843 if (!fmt
) goto pix_error
;
2844 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_RED_SIZE
, &tmp
);
2845 if (hTest
) goto get_error
;
2847 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_GREEN_SIZE
, &tmp
);
2848 if (hTest
) goto get_error
;
2850 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_BLUE_SIZE
, &tmp
);
2851 if (hTest
) goto get_error
;
2853 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &tmp
);
2854 if (hTest
) goto get_error
;
2859 FIXME("unsupported %x WGL Attribute\n", curWGLAttr
);
2862 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2863 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2864 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2866 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2867 * and check which options can work using iPixelFormat=0 and which not.
2868 * A problem would be that this function is an extension. This would
2869 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2871 if (0 != curGLXAttr
&& iPixelFormat
!= 0) {
2872 if (!fmt
) goto pix_error
;
2873 hTest
= pglXGetFBConfigAttrib(gdi_display
, fmt
->fbconfig
, curGLXAttr
, piValues
+ i
);
2874 if (hTest
) goto get_error
;
2877 piValues
[i
] = GL_FALSE
;
2883 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc
, curGLXAttr
);
2887 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc
, iPixelFormat
, nb_pixel_formats
);
2892 * X11DRV_wglGetPixelFormatAttribfvARB
2894 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2896 static BOOL
X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc
, int iPixelFormat
, int iLayerPlane
,
2897 UINT nAttributes
, const int *piAttributes
, FLOAT
*pfValues
)
2903 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, pfValues
);
2905 /* Allocate a temporary array to store integer values */
2906 attr
= HeapAlloc(GetProcessHeap(), 0, nAttributes
* sizeof(int));
2908 ERR("couldn't allocate %d array\n", nAttributes
);
2912 /* Piggy-back on wglGetPixelFormatAttribivARB */
2913 ret
= X11DRV_wglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, iLayerPlane
, nAttributes
, piAttributes
, attr
);
2915 /* Convert integer values to float. Should also check for attributes
2916 that can give decimal values here */
2917 for (i
=0; i
<nAttributes
;i
++) {
2918 pfValues
[i
] = attr
[i
];
2922 HeapFree(GetProcessHeap(), 0, attr
);
2927 * X11DRV_wglBindTexImageARB
2929 * WGL_ARB_render_texture: wglBindTexImageARB
2931 static BOOL
X11DRV_wglBindTexImageARB( struct wgl_pbuffer
*object
, int iBuffer
)
2933 GLboolean ret
= GL_FALSE
;
2935 TRACE("(%p, %d)\n", object
, iBuffer
);
2937 if (!object
->use_render_texture
) {
2938 SetLastError(ERROR_INVALID_HANDLE
);
2942 if (use_render_texture_emulation
) {
2943 static BOOL initialized
= FALSE
;
2944 int prev_binded_texture
= 0;
2945 GLXContext prev_context
;
2946 GLXDrawable prev_drawable
;
2948 prev_context
= pglXGetCurrentContext();
2949 prev_drawable
= pglXGetCurrentDrawable();
2951 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2952 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2953 isn't ideal performance wise but I wasn't able to get other ways working.
2956 initialized
= TRUE
; /* Only show the FIXME once for performance reasons */
2957 FIXME("partial stub!\n");
2960 TRACE("drawable=%lx, context=%p\n", object
->drawable
, prev_context
);
2961 if (!object
->tmp_context
|| object
->prev_context
!= prev_context
) {
2962 if (object
->tmp_context
)
2963 pglXDestroyContext(gdi_display
, object
->tmp_context
);
2964 object
->tmp_context
= pglXCreateNewContext(gdi_display
, object
->fmt
->fbconfig
, object
->fmt
->render_type
, prev_context
, True
);
2965 object
->prev_context
= prev_context
;
2968 opengl_funcs
.gl
.p_glGetIntegerv(object
->texture_bind_target
, &prev_binded_texture
);
2970 /* Switch to our pbuffer */
2971 pglXMakeCurrent(gdi_display
, object
->drawable
, object
->tmp_context
);
2973 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2974 * After that copy the pbuffer texture data. */
2975 opengl_funcs
.gl
.p_glBindTexture(object
->texture_target
, prev_binded_texture
);
2976 opengl_funcs
.gl
.p_glCopyTexImage2D(object
->texture_target
, 0, object
->use_render_texture
, 0, 0, object
->width
, object
->height
, 0);
2978 /* Switch back to the original drawable and context */
2979 pglXMakeCurrent(gdi_display
, prev_drawable
, prev_context
);
2987 * X11DRV_wglReleaseTexImageARB
2989 * WGL_ARB_render_texture: wglReleaseTexImageARB
2991 static BOOL
X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer
*object
, int iBuffer
)
2993 GLboolean ret
= GL_FALSE
;
2995 TRACE("(%p, %d)\n", object
, iBuffer
);
2997 if (!object
->use_render_texture
) {
2998 SetLastError(ERROR_INVALID_HANDLE
);
3001 if (use_render_texture_emulation
) {
3008 * X11DRV_wglGetExtensionsStringEXT
3010 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3012 static const char *X11DRV_wglGetExtensionsStringEXT(void)
3014 TRACE("() returning \"%s\"\n", wglExtensions
);
3015 return wglExtensions
;
3019 * X11DRV_wglGetSwapIntervalEXT
3021 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3023 static int X11DRV_wglGetSwapIntervalEXT(void)
3025 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
3026 struct gl_drawable
*gl
;
3031 if (!(gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), ctx
->hdc
)))
3033 /* This can't happen because a current WGL context is required to get
3034 * here. Likely the application is buggy.
3036 WARN("No GL drawable found, returning swap interval 0\n");
3040 swap_interval
= gl
->swap_interval
;
3041 release_gl_drawable(gl
);
3043 return swap_interval
;
3047 * X11DRV_wglSwapIntervalEXT
3049 * WGL_EXT_swap_control: wglSwapIntervalEXT
3051 static BOOL
X11DRV_wglSwapIntervalEXT(int interval
)
3053 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
3054 struct gl_drawable
*gl
;
3057 TRACE("(%d)\n", interval
);
3059 /* Without WGL/GLX_EXT_swap_control_tear a negative interval
3062 if (interval
< 0 && !has_swap_control_tear
)
3064 SetLastError(ERROR_INVALID_DATA
);
3068 if (!(gl
= get_gl_drawable( WindowFromDC( ctx
->hdc
), ctx
->hdc
)))
3070 SetLastError(ERROR_DC_NOT_FOUND
);
3074 EnterCriticalSection( &context_section
);
3075 ret
= set_swap_interval(gl
->drawable
, interval
);
3076 gl
->refresh_swap_interval
= FALSE
;
3078 gl
->swap_interval
= interval
;
3080 SetLastError(ERROR_DC_NOT_FOUND
);
3082 LeaveCriticalSection( &context_section
);
3083 release_gl_drawable(gl
);
3089 * X11DRV_wglSetPixelFormatWINE
3091 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3092 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3094 static BOOL
X11DRV_wglSetPixelFormatWINE(HDC hdc
, int format
)
3096 return set_pixel_format(hdc
, format
, TRUE
);
3099 static BOOL
X11DRV_wglQueryCurrentRendererIntegerWINE( GLenum attribute
, GLuint
*value
)
3101 return pglXQueryCurrentRendererIntegerMESA( attribute
, value
);
3104 static const char *X11DRV_wglQueryCurrentRendererStringWINE( GLenum attribute
)
3106 return pglXQueryCurrentRendererStringMESA( attribute
);
3109 static BOOL
X11DRV_wglQueryRendererIntegerWINE( HDC dc
, GLint renderer
, GLenum attribute
, GLuint
*value
)
3111 return pglXQueryRendererIntegerMESA( gdi_display
, DefaultScreen(gdi_display
), renderer
, attribute
, value
);
3114 static const char *X11DRV_wglQueryRendererStringWINE( HDC dc
, GLint renderer
, GLenum attribute
)
3116 return pglXQueryRendererStringMESA( gdi_display
, DefaultScreen(gdi_display
), renderer
, attribute
);
3120 * glxRequireVersion (internal)
3122 * Check if the supported GLX version matches requiredVersion.
3124 static BOOL
glxRequireVersion(int requiredVersion
)
3126 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3127 return (requiredVersion
<= glxVersion
[1]);
3130 static void register_extension(const char *ext
)
3132 if (wglExtensions
[0])
3133 strcat(wglExtensions
, " ");
3134 strcat(wglExtensions
, ext
);
3136 TRACE("'%s'\n", ext
);
3140 * X11DRV_WineGL_LoadExtensions
3142 static void X11DRV_WineGL_LoadExtensions(void)
3144 wglExtensions
[0] = 0;
3146 /* ARB Extensions */
3148 if (has_extension( glxExtensions
, "GLX_ARB_create_context"))
3150 register_extension( "WGL_ARB_create_context" );
3151 opengl_funcs
.ext
.p_wglCreateContextAttribsARB
= X11DRV_wglCreateContextAttribsARB
;
3153 if (has_extension( glxExtensions
, "GLX_ARB_create_context_no_error" ))
3154 register_extension( "WGL_ARB_create_context_no_error" );
3155 if (has_extension( glxExtensions
, "GLX_ARB_create_context_profile"))
3156 register_extension("WGL_ARB_create_context_profile");
3159 if (has_extension( glxExtensions
, "GLX_ARB_fbconfig_float"))
3161 register_extension("WGL_ARB_pixel_format_float");
3162 register_extension("WGL_ATI_pixel_format_float");
3165 register_extension( "WGL_ARB_extensions_string" );
3166 opengl_funcs
.ext
.p_wglGetExtensionsStringARB
= X11DRV_wglGetExtensionsStringARB
;
3168 if (glxRequireVersion(3))
3170 register_extension( "WGL_ARB_make_current_read" );
3171 opengl_funcs
.ext
.p_wglGetCurrentReadDCARB
= (void *)1; /* never called */
3172 opengl_funcs
.ext
.p_wglMakeContextCurrentARB
= X11DRV_wglMakeContextCurrentARB
;
3175 if (has_extension( glxExtensions
, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
3177 if (glxRequireVersion(3))
3179 register_extension( "WGL_ARB_pbuffer" );
3180 opengl_funcs
.ext
.p_wglCreatePbufferARB
= X11DRV_wglCreatePbufferARB
;
3181 opengl_funcs
.ext
.p_wglDestroyPbufferARB
= X11DRV_wglDestroyPbufferARB
;
3182 opengl_funcs
.ext
.p_wglGetPbufferDCARB
= X11DRV_wglGetPbufferDCARB
;
3183 opengl_funcs
.ext
.p_wglQueryPbufferARB
= X11DRV_wglQueryPbufferARB
;
3184 opengl_funcs
.ext
.p_wglReleasePbufferDCARB
= X11DRV_wglReleasePbufferDCARB
;
3185 opengl_funcs
.ext
.p_wglSetPbufferAttribARB
= X11DRV_wglSetPbufferAttribARB
;
3188 register_extension( "WGL_ARB_pixel_format" );
3189 opengl_funcs
.ext
.p_wglChoosePixelFormatARB
= X11DRV_wglChoosePixelFormatARB
;
3190 opengl_funcs
.ext
.p_wglGetPixelFormatAttribfvARB
= X11DRV_wglGetPixelFormatAttribfvARB
;
3191 opengl_funcs
.ext
.p_wglGetPixelFormatAttribivARB
= X11DRV_wglGetPixelFormatAttribivARB
;
3193 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3194 if (has_extension( glxExtensions
, "GLX_ARB_render_texture") ||
3195 (glxRequireVersion(3) && use_render_texture_emulation
))
3197 register_extension( "WGL_ARB_render_texture" );
3198 opengl_funcs
.ext
.p_wglBindTexImageARB
= X11DRV_wglBindTexImageARB
;
3199 opengl_funcs
.ext
.p_wglReleaseTexImageARB
= X11DRV_wglReleaseTexImageARB
;
3201 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3202 if (has_extension( glxExtensions
, "GLX_NV_float_buffer"))
3203 register_extension("WGL_NV_float_buffer");
3205 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3206 if (has_extension(glExtensions
, "GL_NV_texture_rectangle"))
3207 register_extension("WGL_NV_render_texture_rectangle");
3210 /* EXT Extensions */
3212 register_extension( "WGL_EXT_extensions_string" );
3213 opengl_funcs
.ext
.p_wglGetExtensionsStringEXT
= X11DRV_wglGetExtensionsStringEXT
;
3215 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3216 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3217 register_extension( "WGL_EXT_swap_control" );
3218 opengl_funcs
.ext
.p_wglSwapIntervalEXT
= X11DRV_wglSwapIntervalEXT
;
3219 opengl_funcs
.ext
.p_wglGetSwapIntervalEXT
= X11DRV_wglGetSwapIntervalEXT
;
3221 if (has_extension( glxExtensions
, "GLX_EXT_framebuffer_sRGB"))
3222 register_extension("WGL_EXT_framebuffer_sRGB");
3224 if (has_extension( glxExtensions
, "GLX_EXT_fbconfig_packed_float"))
3225 register_extension("WGL_EXT_pixel_format_packed_float");
3227 if (has_extension( glxExtensions
, "GLX_EXT_swap_control"))
3229 swap_control_method
= GLX_SWAP_CONTROL_EXT
;
3230 if (has_extension( glxExtensions
, "GLX_EXT_swap_control_tear"))
3232 register_extension("WGL_EXT_swap_control_tear");
3233 has_swap_control_tear
= TRUE
;
3236 else if (has_extension( glxExtensions
, "GLX_MESA_swap_control"))
3238 swap_control_method
= GLX_SWAP_CONTROL_MESA
;
3240 else if (has_extension( glxExtensions
, "GLX_SGI_swap_control"))
3242 swap_control_method
= GLX_SWAP_CONTROL_SGI
;
3245 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3246 if (has_extension(glExtensions
, "GL_NV_vertex_array_range"))
3248 register_extension( "WGL_NV_vertex_array_range" );
3249 opengl_funcs
.ext
.p_wglAllocateMemoryNV
= pglXAllocateMemoryNV
;
3250 opengl_funcs
.ext
.p_wglFreeMemoryNV
= pglXFreeMemoryNV
;
3253 if (has_extension(glxExtensions
, "GLX_OML_swap_method"))
3254 has_swap_method
= TRUE
;
3256 /* WINE-specific WGL Extensions */
3258 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3259 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3261 register_extension( "WGL_WINE_pixel_format_passthrough" );
3262 opengl_funcs
.ext
.p_wglSetPixelFormatWINE
= X11DRV_wglSetPixelFormatWINE
;
3264 if (has_extension( glxExtensions
, "GLX_MESA_query_renderer" ))
3266 register_extension( "WGL_WINE_query_renderer" );
3267 opengl_funcs
.ext
.p_wglQueryCurrentRendererIntegerWINE
= X11DRV_wglQueryCurrentRendererIntegerWINE
;
3268 opengl_funcs
.ext
.p_wglQueryCurrentRendererStringWINE
= X11DRV_wglQueryCurrentRendererStringWINE
;
3269 opengl_funcs
.ext
.p_wglQueryRendererIntegerWINE
= X11DRV_wglQueryRendererIntegerWINE
;
3270 opengl_funcs
.ext
.p_wglQueryRendererStringWINE
= X11DRV_wglQueryRendererStringWINE
;
3276 * glxdrv_SwapBuffers
3278 * Swap the buffers of this DC
3280 static BOOL
glxdrv_wglSwapBuffers( HDC hdc
)
3282 struct x11drv_escape_flush_gl_drawable escape
;
3283 struct gl_drawable
*gl
;
3284 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
3285 INT64 ust
, msc
, sbc
, target_sbc
= 0;
3287 TRACE("(%p)\n", hdc
);
3289 escape
.code
= X11DRV_FLUSH_GL_DRAWABLE
;
3290 escape
.gl_drawable
= 0;
3291 escape
.flush
= !pglXWaitForSbcOML
;
3293 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
3295 SetLastError( ERROR_INVALID_HANDLE
);
3299 EnterCriticalSection( &context_section
);
3300 if (gl
->refresh_swap_interval
)
3302 set_swap_interval(gl
->drawable
, gl
->swap_interval
);
3303 gl
->refresh_swap_interval
= FALSE
;
3305 LeaveCriticalSection( &context_section
);
3309 case DC_GL_PIXMAP_WIN
:
3310 if (ctx
) sync_context( ctx
);
3311 escape
.gl_drawable
= gl
->pixmap
;
3312 if (pglXCopySubBufferMESA
) {
3313 /* (glX)SwapBuffers has an implicit glFlush effect, however
3314 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3317 pglXCopySubBufferMESA( gdi_display
, gl
->drawable
, 0, 0,
3318 gl
->pixmap_size
.cx
, gl
->pixmap_size
.cy
);
3321 if (pglXSwapBuffersMscOML
)
3324 target_sbc
= pglXSwapBuffersMscOML( gdi_display
, gl
->drawable
, 0, 0, 0 );
3327 pglXSwapBuffers(gdi_display
, gl
->drawable
);
3329 case DC_GL_CHILD_WIN
:
3330 if (ctx
) sync_context( ctx
);
3331 escape
.gl_drawable
= gl
->window
;
3334 if (escape
.gl_drawable
&& pglXSwapBuffersMscOML
)
3337 target_sbc
= pglXSwapBuffersMscOML( gdi_display
, gl
->drawable
, 0, 0, 0 );
3340 pglXSwapBuffers(gdi_display
, gl
->drawable
);
3344 if (escape
.gl_drawable
&& pglXWaitForSbcOML
)
3345 pglXWaitForSbcOML( gdi_display
, gl
->drawable
, target_sbc
, &ust
, &msc
, &sbc
);
3347 release_gl_drawable( gl
);
3349 if (escape
.gl_drawable
) ExtEscape( ctx
->hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
3353 static struct opengl_funcs opengl_funcs
=
3356 glxdrv_wglCopyContext
, /* p_wglCopyContext */
3357 glxdrv_wglCreateContext
, /* p_wglCreateContext */
3358 glxdrv_wglDeleteContext
, /* p_wglDeleteContext */
3359 glxdrv_wglDescribePixelFormat
, /* p_wglDescribePixelFormat */
3360 glxdrv_wglGetPixelFormat
, /* p_wglGetPixelFormat */
3361 glxdrv_wglGetProcAddress
, /* p_wglGetProcAddress */
3362 glxdrv_wglMakeCurrent
, /* p_wglMakeCurrent */
3363 glxdrv_wglSetPixelFormat
, /* p_wglSetPixelFormat */
3364 glxdrv_wglShareLists
, /* p_wglShareLists */
3365 glxdrv_wglSwapBuffers
, /* p_wglSwapBuffers */
3369 struct opengl_funcs
*get_glx_driver( UINT version
)
3371 if (version
!= WINE_WGL_DRIVER_VERSION
)
3373 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version
, WINE_WGL_DRIVER_VERSION
);
3376 if (has_opengl()) return &opengl_funcs
;
3380 #else /* no OpenGL includes */
3382 struct opengl_funcs
*get_glx_driver( UINT version
)
3387 void sync_gl_drawable( HWND hwnd
)
3391 void set_gl_drawable_parent( HWND hwnd
, HWND parent
)
3395 void destroy_gl_drawable( HWND hwnd
)
3399 #endif /* defined(SONAME_LIBGL) */