wgl: Fix ChoosePixelFormat behavior.
[wine/wine-kai.git] / dlls / winex11.drv / opengl.c
blob5a0469c994b150aa9c173042974dc06d5f7d4701
1 /*
2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
26 #include "wine/port.h"
28 #include <assert.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include "x11drv.h"
33 #include "winternl.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
38 WINE_DECLARE_DEBUG_CHANNEL(opengl);
40 #ifdef SONAME_LIBGL
42 #undef APIENTRY
43 #undef CALLBACK
44 #undef WINAPI
46 #ifdef HAVE_GL_GL_H
47 # include <GL/gl.h>
48 #endif
49 #ifdef HAVE_GL_GLX_H
50 # include <GL/glx.h>
51 #endif
52 #ifdef HAVE_GL_GLEXT_H
53 # include <GL/glext.h>
54 #endif
56 #include "wine/wgl.h"
58 #undef APIENTRY
59 #undef CALLBACK
60 #undef WINAPI
62 /* Redefines the constants */
63 #define CALLBACK __stdcall
64 #define WINAPI __stdcall
65 #define APIENTRY WINAPI
68 WINE_DECLARE_DEBUG_CHANNEL(fps);
70 typedef struct wine_glextension {
71 const char *extName;
72 struct {
73 const char *funcName;
74 void *funcAddress;
75 } extEntryPoints[9];
76 } WineGLExtension;
78 struct WineGLInfo {
79 const char *glVersion;
80 const char *glExtensions;
82 int glxVersion[2];
84 const char *glxServerVersion;
85 const char *glxServerVendor;
86 const char *glxServerExtensions;
88 const char *glxClientVersion;
89 const char *glxClientVendor;
90 const char *glxClientExtensions;
92 const char *glxExtensions;
94 BOOL glxDirect;
95 char wglExtensions[4096];
98 typedef struct wine_glpixelformat {
99 int iPixelFormat;
100 GLXFBConfig fbconfig;
101 int fmt_id;
102 int render_type;
103 BOOL offscreenOnly;
104 } WineGLPixelFormat;
106 typedef struct wine_glcontext {
107 HDC hdc;
108 XVisualInfo *vis;
109 WineGLPixelFormat *fmt;
110 GLXContext ctx;
111 BOOL do_escape;
112 HDC read_hdc;
113 Drawable drawables[2];
114 BOOL refresh_drawables;
115 struct wine_glcontext *next;
116 struct wine_glcontext *prev;
117 } Wine_GLContext;
119 typedef struct wine_glpbuffer {
120 Drawable drawable;
121 Display* display;
122 WineGLPixelFormat* fmt;
123 int width;
124 int height;
125 int* attribList;
126 HDC hdc;
128 int use_render_texture; /* This is also the internal texture format */
129 int texture_bind_target;
130 int texture_bpp;
131 GLint texture_format;
132 GLuint texture_target;
133 GLenum texture_type;
134 GLuint texture;
135 int texture_level;
136 } Wine_GLPBuffer;
138 static Wine_GLContext *context_list;
139 static struct WineGLInfo WineGLInfo = { 0 };
140 static int use_render_texture_emulation = 1;
141 static int use_render_texture_ati = 0;
142 static int swap_interval = 1;
144 #define MAX_EXTENSIONS 16
145 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
146 static int WineGLExtensionListSize;
148 static WineGLPixelFormat *WineGLPixelFormatList;
149 static int WineGLPixelFormatListSize = 0;
150 static int WineGLPixelFormatOnScreenSize = 0;
152 static void X11DRV_WineGL_LoadExtensions(void);
153 static BOOL glxRequireVersion(int requiredVersion);
154 static BOOL glxRequireExtension(const char *requiredExtension);
156 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
157 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
158 TRACE(" - dwFlags : ");
159 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
174 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
175 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
176 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
177 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
178 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
179 #undef TEST_AND_DUMP
180 TRACE("\n");
182 TRACE(" - iPixelType : ");
183 switch (ppfd->iPixelType) {
184 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
185 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
187 TRACE("\n");
189 TRACE(" - Color : %d\n", ppfd->cColorBits);
190 TRACE(" - Red : %d\n", ppfd->cRedBits);
191 TRACE(" - Green : %d\n", ppfd->cGreenBits);
192 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
193 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
194 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
195 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
196 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
197 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
199 TRACE(" - iLayerType : ");
200 switch (ppfd->iLayerType) {
201 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
202 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
203 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
205 TRACE("\n");
208 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
209 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
211 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
212 /* GLX 1.0 */
213 MAKE_FUNCPTR(glXChooseVisual)
214 MAKE_FUNCPTR(glXCopyContext)
215 MAKE_FUNCPTR(glXCreateContext)
216 MAKE_FUNCPTR(glXCreateGLXPixmap)
217 MAKE_FUNCPTR(glXGetCurrentContext)
218 MAKE_FUNCPTR(glXGetCurrentDrawable)
219 MAKE_FUNCPTR(glXDestroyContext)
220 MAKE_FUNCPTR(glXDestroyGLXPixmap)
221 MAKE_FUNCPTR(glXGetConfig)
222 MAKE_FUNCPTR(glXIsDirect)
223 MAKE_FUNCPTR(glXMakeCurrent)
224 MAKE_FUNCPTR(glXSwapBuffers)
225 MAKE_FUNCPTR(glXQueryExtension)
226 MAKE_FUNCPTR(glXQueryVersion)
227 MAKE_FUNCPTR(glXUseXFont)
229 /* GLX 1.1 */
230 MAKE_FUNCPTR(glXGetClientString)
231 MAKE_FUNCPTR(glXQueryExtensionsString)
232 MAKE_FUNCPTR(glXQueryServerString)
234 /* GLX 1.3 */
235 MAKE_FUNCPTR(glXGetFBConfigs)
236 MAKE_FUNCPTR(glXChooseFBConfig)
237 MAKE_FUNCPTR(glXCreatePbuffer)
238 MAKE_FUNCPTR(glXCreateNewContext)
239 MAKE_FUNCPTR(glXDestroyPbuffer)
240 MAKE_FUNCPTR(glXGetFBConfigAttrib)
241 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
242 MAKE_FUNCPTR(glXMakeContextCurrent)
243 MAKE_FUNCPTR(glXQueryDrawable)
244 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
246 /* GLX Extensions */
247 static void* (*pglXGetProcAddressARB)(const GLubyte *);
248 static int (*pglXSwapIntervalSGI)(int);
250 /* ATI GLX Extensions */
251 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
252 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
253 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
255 /* NV GLX Extension */
256 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
257 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
259 /* MESA GLX Extensions */
260 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
262 /* Standard OpenGL */
263 MAKE_FUNCPTR(glBindTexture)
264 MAKE_FUNCPTR(glBitmap)
265 MAKE_FUNCPTR(glCopyTexSubImage1D)
266 MAKE_FUNCPTR(glCopyTexImage2D)
267 MAKE_FUNCPTR(glCopyTexSubImage2D)
268 MAKE_FUNCPTR(glDrawBuffer)
269 MAKE_FUNCPTR(glEndList)
270 MAKE_FUNCPTR(glGetError)
271 MAKE_FUNCPTR(glGetIntegerv)
272 MAKE_FUNCPTR(glGetString)
273 MAKE_FUNCPTR(glNewList)
274 MAKE_FUNCPTR(glPixelStorei)
275 MAKE_FUNCPTR(glReadPixels)
276 MAKE_FUNCPTR(glTexImage2D)
277 MAKE_FUNCPTR(glFinish)
278 MAKE_FUNCPTR(glFlush)
279 #undef MAKE_FUNCPTR
281 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
283 static BOOL infoInitialized = FALSE;
285 int screen = DefaultScreen(gdi_display);
286 Window win = RootWindow(gdi_display, screen);
287 Visual *visual;
288 XVisualInfo template;
289 XVisualInfo *vis;
290 int num;
291 GLXContext ctx = NULL;
293 if (infoInitialized)
294 return TRUE;
295 infoInitialized = TRUE;
297 wine_tsx11_lock();
299 visual = DefaultVisual(gdi_display, screen);
300 template.visualid = XVisualIDFromVisual(visual);
301 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
302 if (vis) {
303 WORD old_fs = wine_get_fs();
304 /* Create a GLX Context. Without one we can't query GL information */
305 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
306 if (wine_get_fs() != old_fs)
308 wine_set_fs( old_fs );
309 wine_tsx11_unlock();
310 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
311 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
312 return FALSE;
316 if (ctx) {
317 pglXMakeCurrent(gdi_display, win, ctx);
318 } else {
319 ERR(" couldn't initialize OpenGL, expect problems\n");
320 wine_tsx11_unlock();
321 return FALSE;
324 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
325 WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
327 /* Get the common GLX version supported by GLX client and server ( major/minor) */
328 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
330 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
331 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
332 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
334 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
335 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
336 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
338 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
339 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
341 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
342 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER));
343 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
344 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
345 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
346 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
347 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
348 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
350 if(vis) XFree(vis);
351 if(ctx) {
352 pglXMakeCurrent(gdi_display, None, NULL);
353 pglXDestroyContext(gdi_display, ctx);
355 wine_tsx11_unlock();
356 return TRUE;
359 static BOOL has_opengl(void)
361 static int init_done;
362 static void *opengl_handle;
364 int error_base, event_base;
366 if (init_done) return (opengl_handle != NULL);
367 init_done = 1;
369 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
370 and include all dependencies */
371 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
372 if (opengl_handle == NULL) return FALSE;
374 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
375 if (pglXGetProcAddressARB == NULL) {
376 ERR("could not find glXGetProcAddressARB in libGL.\n");
377 return FALSE;
380 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
381 /* GLX 1.0 */
382 LOAD_FUNCPTR(glXChooseVisual)
383 LOAD_FUNCPTR(glXCopyContext)
384 LOAD_FUNCPTR(glXCreateContext)
385 LOAD_FUNCPTR(glXCreateGLXPixmap)
386 LOAD_FUNCPTR(glXGetCurrentContext)
387 LOAD_FUNCPTR(glXGetCurrentDrawable)
388 LOAD_FUNCPTR(glXDestroyContext)
389 LOAD_FUNCPTR(glXDestroyGLXPixmap)
390 LOAD_FUNCPTR(glXGetConfig)
391 LOAD_FUNCPTR(glXIsDirect)
392 LOAD_FUNCPTR(glXMakeCurrent)
393 LOAD_FUNCPTR(glXSwapBuffers)
394 LOAD_FUNCPTR(glXQueryExtension)
395 LOAD_FUNCPTR(glXQueryVersion)
396 LOAD_FUNCPTR(glXUseXFont)
398 /* GLX 1.1 */
399 LOAD_FUNCPTR(glXGetClientString)
400 LOAD_FUNCPTR(glXQueryExtensionsString)
401 LOAD_FUNCPTR(glXQueryServerString)
403 /* GLX 1.3 */
404 LOAD_FUNCPTR(glXCreatePbuffer)
405 LOAD_FUNCPTR(glXCreateNewContext)
406 LOAD_FUNCPTR(glXDestroyPbuffer)
407 LOAD_FUNCPTR(glXMakeContextCurrent)
408 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
409 LOAD_FUNCPTR(glXGetFBConfigs)
411 /* Standard OpenGL calls */
412 LOAD_FUNCPTR(glBindTexture)
413 LOAD_FUNCPTR(glBitmap)
414 LOAD_FUNCPTR(glCopyTexSubImage1D)
415 LOAD_FUNCPTR(glCopyTexImage2D)
416 LOAD_FUNCPTR(glCopyTexSubImage2D)
417 LOAD_FUNCPTR(glDrawBuffer)
418 LOAD_FUNCPTR(glEndList)
419 LOAD_FUNCPTR(glGetError)
420 LOAD_FUNCPTR(glGetIntegerv)
421 LOAD_FUNCPTR(glGetString)
422 LOAD_FUNCPTR(glNewList)
423 LOAD_FUNCPTR(glPixelStorei)
424 LOAD_FUNCPTR(glReadPixels)
425 LOAD_FUNCPTR(glTexImage2D)
426 LOAD_FUNCPTR(glFinish)
427 LOAD_FUNCPTR(glFlush)
428 #undef LOAD_FUNCPTR
430 /* It doesn't matter if these fail. They'll only be used if the driver reports
431 the associated extension is available (and if a driver reports the extension
432 is available but fails to provide the functions, it's quite broken) */
433 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
434 /* NV GLX Extension */
435 LOAD_FUNCPTR(glXAllocateMemoryNV)
436 LOAD_FUNCPTR(glXFreeMemoryNV)
437 #undef LOAD_FUNCPTR
439 if(!X11DRV_WineGL_InitOpenglInfo()) {
440 wine_dlclose(opengl_handle, NULL, 0);
441 opengl_handle = NULL;
442 return FALSE;
445 wine_tsx11_lock();
446 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
447 TRACE("GLX is up and running error_base = %d\n", error_base);
448 } else {
449 wine_dlclose(opengl_handle, NULL, 0);
450 opengl_handle = NULL;
453 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
454 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
455 * rendering is used.
457 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
458 * depends on the reported GLX client / server version and on the client / server extension list.
459 * Those don't have to be the same.
461 * In general the server GLX information lists the capabilities in case of indirect rendering.
462 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
463 * available and in that case the client GLX informat can be used.
464 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
465 * in the GLX version/extension list. When a program does this it works for certain for both
466 * direct and indirect rendering.
468 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
469 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
470 * extension list which causes this extension not to be listed. (Wine requires this extension).
471 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
472 * pbuffers is around.
474 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
475 * the ATI drivers and from then on use GLX client information for them.
478 if(glxRequireVersion(3)) {
479 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
480 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
481 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
482 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
483 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
484 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
485 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
486 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
488 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
489 * enable this function when the Xserver understand GLX 1.3 or newer
491 pglXQueryDrawable = NULL;
492 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
493 TRACE("Overriding ATI GLX capabilities!\n");
494 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
495 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
496 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
497 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
499 /* Use client GLX information in case of the ATI drivers. We override the
500 * capabilities over here and not somewhere else as ATI might better their
501 * life in the future. In case they release proper drivers this block of
502 * code won't be called. */
503 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
504 } else {
505 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
508 if(glxRequireExtension("GLX_ATI_render_texture")) {
509 use_render_texture_ati = 1;
510 pglXBindTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
511 pglXReleaseTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
512 pglXDrawableAttribATI = pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
515 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
516 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
519 X11DRV_WineGL_LoadExtensions();
521 wine_tsx11_unlock();
522 return (opengl_handle != NULL);
524 sym_not_found:
525 wine_dlclose(opengl_handle, NULL, 0);
526 opengl_handle = NULL;
527 return FALSE;
530 static inline Wine_GLContext *alloc_context(void)
532 Wine_GLContext *ret;
534 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
536 ret->next = context_list;
537 if (context_list) context_list->prev = ret;
538 context_list = ret;
540 return ret;
543 static inline void free_context(Wine_GLContext *context)
545 if (context->next != NULL) context->next->prev = context->prev;
546 if (context->prev != NULL) context->prev->next = context->next;
547 else context_list = context->next;
549 if (context->vis) XFree(context->vis);
550 HeapFree(GetProcessHeap(), 0, context);
553 static inline BOOL is_valid_context( Wine_GLContext *ctx )
555 Wine_GLContext *ptr;
556 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
557 return (ptr != NULL);
560 static int describeContext(Wine_GLContext* ctx) {
561 int tmp;
562 int ctx_vis_id;
563 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
564 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
565 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
566 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
567 TRACE(" - VISUAL_ID 0x%x\n", tmp);
568 ctx_vis_id = tmp;
569 return ctx_vis_id;
572 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
573 int tmp;
574 int nElements;
575 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
576 GLXFBConfig *fbCfgs;
578 if (pglXQueryDrawable == NULL) {
579 /** glXQueryDrawable not available so returns not supported */
580 return -1;
583 TRACE(" Drawable %p have :\n", (void*) drawable);
584 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
585 TRACE(" - WIDTH as %d\n", tmp);
586 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
587 TRACE(" - HEIGHT as %d\n", tmp);
588 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
589 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
591 attribList[1] = tmp;
592 fbCfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribList, &nElements);
593 if (fbCfgs == NULL) {
594 return -1;
597 pglXGetFBConfigAttrib(gdi_display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
598 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
600 XFree(fbCfgs);
602 return tmp;
605 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
606 int nAttribs = 0;
607 unsigned cur = 0;
608 int pop;
609 int drawattrib = 0;
610 int nvfloatattrib = GLX_DONT_CARE;
611 int pixelattrib = 0;
612 int supportgdi = -1;
613 int doublebuf = -1;
615 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
616 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
617 while (iWGLAttr && 0 != iWGLAttr[cur]) {
618 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
620 switch (iWGLAttr[cur]) {
621 case WGL_AUX_BUFFERS_ARB:
622 pop = iWGLAttr[++cur];
623 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
624 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
625 break;
626 case WGL_COLOR_BITS_ARB:
627 pop = iWGLAttr[++cur];
628 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
629 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
630 break;
631 case WGL_BLUE_BITS_ARB:
632 pop = iWGLAttr[++cur];
633 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
634 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
635 break;
636 case WGL_RED_BITS_ARB:
637 pop = iWGLAttr[++cur];
638 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
639 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
640 break;
641 case WGL_GREEN_BITS_ARB:
642 pop = iWGLAttr[++cur];
643 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
644 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
645 break;
646 case WGL_ALPHA_BITS_ARB:
647 pop = iWGLAttr[++cur];
648 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
649 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
650 break;
651 case WGL_DEPTH_BITS_ARB:
652 pop = iWGLAttr[++cur];
653 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
654 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
655 break;
656 case WGL_STENCIL_BITS_ARB:
657 pop = iWGLAttr[++cur];
658 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
659 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
660 break;
661 case WGL_DOUBLE_BUFFER_ARB:
662 pop = iWGLAttr[++cur];
663 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
664 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
665 doublebuf = pop;
666 break;
668 case WGL_PIXEL_TYPE_ARB:
669 pop = iWGLAttr[++cur];
670 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
671 switch (pop) {
672 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
673 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
674 /* 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 */
675 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
676 default:
677 ERR("unexpected PixelType(%x)\n", pop);
678 pop = 0;
680 break;
682 case WGL_SUPPORT_GDI_ARB:
683 pop = iWGLAttr[++cur];
684 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
685 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
686 supportgdi = pop;
687 break;
689 case WGL_DRAW_TO_BITMAP_ARB:
690 pop = iWGLAttr[++cur];
691 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
692 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
693 if (pop) {
694 drawattrib |= GLX_PIXMAP_BIT;
696 break;
698 case WGL_DRAW_TO_WINDOW_ARB:
699 pop = iWGLAttr[++cur];
700 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
701 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
702 if (pop) {
703 drawattrib |= GLX_WINDOW_BIT;
705 break;
707 case WGL_DRAW_TO_PBUFFER_ARB:
708 pop = iWGLAttr[++cur];
709 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
710 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
711 if (pop) {
712 drawattrib |= GLX_PBUFFER_BIT;
714 break;
716 case WGL_ACCELERATION_ARB:
717 case WGL_SUPPORT_OPENGL_ARB:
718 pop = iWGLAttr[++cur];
719 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
720 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
721 break;
723 case WGL_PBUFFER_LARGEST_ARB:
724 pop = iWGLAttr[++cur];
725 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
726 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
727 break;
729 case WGL_SAMPLE_BUFFERS_ARB:
730 pop = iWGLAttr[++cur];
731 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
732 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
733 break;
735 case WGL_SAMPLES_ARB:
736 pop = iWGLAttr[++cur];
737 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
738 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
739 break;
741 case WGL_TEXTURE_FORMAT_ARB:
742 case WGL_TEXTURE_TARGET_ARB:
743 case WGL_MIPMAP_TEXTURE_ARB:
744 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
745 pop = iWGLAttr[++cur];
746 if (NULL == pbuf) {
747 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
749 if (use_render_texture_ati) {
750 /** nothing to do here */
752 else if (!use_render_texture_emulation) {
753 if (WGL_NO_TEXTURE_ARB != pop) {
754 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
755 return -1; /** error: don't support it */
756 } else {
757 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
758 drawattrib |= GLX_PBUFFER_BIT;
761 break ;
762 case WGL_FLOAT_COMPONENTS_NV:
763 nvfloatattrib = iWGLAttr[++cur];
764 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
765 break ;
766 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
767 case WGL_BIND_TO_TEXTURE_RGB_ARB:
768 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
769 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
770 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
771 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
772 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
773 pop = iWGLAttr[++cur];
774 /** cannot be converted, see direct handling on
775 * - wglGetPixelFormatAttribivARB
776 * TODO: wglChoosePixelFormat
778 break ;
780 default:
781 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
782 break;
784 ++cur;
787 if(supportgdi > 0) {
788 if(doublebuf > 0) {
789 WARN("Attempting double-buffered gdi format\n");
790 return -1;
792 if(doublebuf < 0)
793 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, False);
796 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
797 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
798 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
799 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
801 /* Set GLX_RENDER_TYPE all the time */
802 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
803 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
805 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
806 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
807 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
808 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
811 return nAttribs;
814 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
816 int render_type=0, render_type_bit;
817 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
818 switch(render_type_bit)
820 case GLX_RGBA_BIT:
821 render_type = GLX_RGBA_TYPE;
822 break;
823 case GLX_COLOR_INDEX_BIT:
824 render_type = GLX_COLOR_INDEX_TYPE;
825 break;
826 case GLX_RGBA_FLOAT_BIT:
827 render_type = GLX_RGBA_FLOAT_TYPE;
828 break;
829 default:
830 ERR("Unknown render_type: %x\n", render_type);
832 return render_type;
835 static BOOL init_formats(Display *display, int screen, Visual *visual)
837 int fmt_id, nCfgs, i, run;
838 GLXFBConfig* cfgs;
839 XVisualInfo *visinfo;
841 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
842 if (NULL == cfgs || 0 == nCfgs) {
843 ERR("glXChooseFBConfig returns NULL\n");
844 if(cfgs != NULL) XFree(cfgs);
845 return FALSE;
848 WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineGLPixelFormat));
850 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
851 * Do this as GLX doesn't guarantee that the list is sorted */
852 for(run=0; run < 2; run++)
854 for(i=0; i<nCfgs; i++) {
855 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
856 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
858 /* The first run we only add onscreen formats (ones which have an associated X Visual).
859 * The second run we only set offscreen formats. */
860 if(!run && visinfo)
862 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
863 * The contents is copied to the destination using XCopyArea. For the copying to work
864 * the depth of the source and destination window should be the same. In general this should
865 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
866 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
867 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
868 * list formats with the same depth. */
869 if(visinfo->depth != screen_depth)
870 continue;
872 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, WineGLPixelFormatListSize+1, i);
873 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
874 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
875 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = fmt_id;
876 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
878 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = FALSE;
879 WineGLPixelFormatListSize++;
880 WineGLPixelFormatOnScreenSize++;
881 XFree(visinfo);
882 } else if(run && !visinfo) {
883 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, WineGLPixelFormatListSize+1, i);
884 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
885 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
886 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = fmt_id;
887 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
889 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
890 WineGLPixelFormatListSize++;
895 if(cfgs != NULL) XFree(cfgs);
897 return TRUE;
900 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
901 * In our WGL implementation we only support a subset of these formats namely the format of
902 * Wine's main visual and offscreen formats (if they are available).
903 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
904 * and it returns the number of supported WGL formats in fmt_count.
906 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
908 WineGLPixelFormat *res = NULL;
910 /* Init the list of pixel formats when we need it */
911 if(!WineGLPixelFormatListSize)
912 init_formats(display, DefaultScreen(display), visual);
914 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
915 * iPixelFormat in case of probing the number of pixelformats.
917 if((iPixelFormat > 0) && (iPixelFormat <= WineGLPixelFormatListSize) &&
918 ((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == FALSE) ||
919 AllowOffscreen)) {
920 res = &WineGLPixelFormatList[iPixelFormat-1];
921 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
924 if(AllowOffscreen)
925 *fmt_count = WineGLPixelFormatListSize;
926 else
927 *fmt_count = WineGLPixelFormatOnScreenSize;
929 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
931 return res;
934 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
935 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
937 int i;
939 /* Init the list of pixel formats when we need it */
940 if(!WineGLPixelFormatListSize)
941 init_formats(display, DefaultScreen(display), visual);
943 for(i=0; i<WineGLPixelFormatListSize; i++) {
944 if(WineGLPixelFormatList[i].fmt_id == fmt_id) {
945 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fmt_id);
946 return &WineGLPixelFormatList[i];
949 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
950 return NULL;
953 int pixelformat_from_fbconfig_id(XID fbconfig_id)
955 WineGLPixelFormat *fmt;
957 if (!fbconfig_id) return 0;
959 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
960 if(fmt)
961 return fmt->iPixelFormat;
962 /* This will happen on hwnds without a pixel format set; it's ok */
963 return 0;
967 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
968 void mark_drawable_dirty(Drawable old, Drawable new)
970 Wine_GLContext *ctx;
971 for (ctx = context_list; ctx; ctx = ctx->next) {
972 if (old == ctx->drawables[0]) {
973 ctx->drawables[0] = new;
974 ctx->refresh_drawables = TRUE;
976 if (old == ctx->drawables[1]) {
977 ctx->drawables[1] = new;
978 ctx->refresh_drawables = TRUE;
983 /* Given the current context, make sure its drawable is sync'd */
984 static inline void sync_context(Wine_GLContext *context)
986 if(context && context->refresh_drawables) {
987 if (glxRequireVersion(3))
988 pglXMakeContextCurrent(gdi_display, context->drawables[0],
989 context->drawables[1], context->ctx);
990 else
991 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
992 context->refresh_drawables = FALSE;
997 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
999 return pglXCreateGLXPixmap(display, vis, parent);
1003 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev, WineGLPixelFormat *fmt)
1005 GLXPixmap ret = 0;
1006 XVisualInfo *vis;
1008 wine_tsx11_lock();
1010 vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1011 if(vis) {
1012 if(vis->depth == physDev->bitmap->pixmap_depth)
1013 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
1014 XFree(vis);
1016 wine_tsx11_unlock();
1017 TRACE("return %lx\n", ret);
1018 return ret;
1022 * X11DRV_ChoosePixelFormat
1024 * Equivalent to glXChooseVisual.
1026 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
1027 const PIXELFORMATDESCRIPTOR *ppfd) {
1028 WineGLPixelFormat *fmt = NULL;
1029 int ret = 0;
1030 int nPixelFormats;
1031 int value = 0;
1032 int i = 0;
1033 int bestFormat = -1;
1034 int bestDBuffer = -1;
1035 int bestStereo = -1;
1036 int bestColor = -1;
1037 int bestAlpha = -1;
1038 int bestDepth = -1;
1039 int bestStencil = -1;
1040 int bestAux = -1;
1041 int score;
1043 if (!has_opengl()) {
1044 ERR("No libGL on this box - disabling OpenGL support !\n");
1045 return 0;
1048 if (TRACE_ON(wgl)) {
1049 TRACE("(%p,%p)\n", physDev, ppfd);
1051 dump_PIXELFORMATDESCRIPTOR(ppfd);
1054 wine_tsx11_lock();
1055 ConvertPixelFormatWGLtoGLX(gdi_display, 0, FALSE /* offscreen */, &nPixelFormats);
1056 for(i=0; i<nPixelFormats; i++)
1058 int dwFlags = 0;
1059 int iPixelType = 0;
1060 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1062 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, i+1 /* 1-based index */, FALSE /* offscreen */, &value);
1063 score = 0;
1065 /* Pixel type */
1066 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1067 if (value & GLX_RGBA_BIT)
1068 iPixelType = PFD_TYPE_RGBA;
1069 else
1070 iPixelType = PFD_TYPE_COLORINDEX;
1072 if (ppfd->iPixelType != iPixelType)
1074 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1075 continue;
1078 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1079 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1080 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1081 if (value) dwFlags |= PFD_STEREO;
1082 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1083 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1084 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1085 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1086 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1088 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1089 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1090 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1091 * formats without the given flag set.
1092 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1093 * has indicated that a format without stereo is returned when stereo is unavailable.
1094 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1095 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1097 * To summarize the following is most likely the correct behavior:
1098 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1099 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1100 * stereo don't care -> it doesn't matter whether we get stereo or not
1102 * In Wine we will treat no-stereo the same way as don't care because it makes
1103 * format selection even more complicated and second drivers with Stereo advertise
1104 * each format twice anyway.
1107 /* Doublebuffer, see the comments above */
1108 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1109 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1110 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1112 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1113 bestStereo = dwFlags & PFD_STEREO;
1114 bestAlpha = alpha;
1115 bestColor = color;
1116 bestDepth = depth;
1117 bestStencil = stencil;
1118 bestAux = aux;
1119 bestFormat = i;
1120 continue;
1122 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1123 continue;
1126 /* Stereo, see the comments above. */
1127 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1128 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1129 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1131 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1132 bestStereo = dwFlags & PFD_STEREO;
1133 bestAlpha = alpha;
1134 bestColor = color;
1135 bestDepth = depth;
1136 bestStencil = stencil;
1137 bestAux = aux;
1138 bestFormat = i;
1139 continue;
1141 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1142 continue;
1145 /* Below we will do a number of checks to select the 'best' pixelformat.
1146 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1147 * The code works by trying to match the most important options as close as possible.
1148 * When a reasonable format is found, we will try to match more options.
1149 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1150 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1151 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1153 /* Color bits */
1154 if(ppfd->cColorBits) {
1155 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1156 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1158 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1159 bestStereo = dwFlags & PFD_STEREO;
1160 bestAlpha = alpha;
1161 bestColor = color;
1162 bestDepth = depth;
1163 bestStencil = stencil;
1164 bestAux = aux;
1165 bestFormat = i;
1166 continue;
1167 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1168 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1169 continue;
1173 /* Alpha bits */
1174 if(ppfd->cAlphaBits) {
1175 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1176 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1178 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1179 bestStereo = dwFlags & PFD_STEREO;
1180 bestAlpha = alpha;
1181 bestColor = color;
1182 bestDepth = depth;
1183 bestStencil = stencil;
1184 bestAux = aux;
1185 bestFormat = i;
1186 continue;
1187 } else if(bestAlpha != alpha) {
1188 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1189 continue;
1193 /* Depth bits */
1194 if(ppfd->cDepthBits) {
1195 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1196 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1198 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1199 bestStereo = dwFlags & PFD_STEREO;
1200 bestAlpha = alpha;
1201 bestColor = color;
1202 bestDepth = depth;
1203 bestStencil = stencil;
1204 bestAux = aux;
1205 bestFormat = i;
1206 continue;
1207 } else if(bestDepth != depth) {
1208 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1209 continue;
1213 /* Stencil bits */
1214 if(ppfd->cStencilBits) {
1215 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1216 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1218 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1219 bestStereo = dwFlags & PFD_STEREO;
1220 bestAlpha = alpha;
1221 bestColor = color;
1222 bestDepth = depth;
1223 bestStencil = stencil;
1224 bestAux = aux;
1225 bestFormat = i;
1226 continue;
1227 } else if(bestStencil != stencil) {
1228 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1229 continue;
1233 /* Aux buffers */
1234 if(ppfd->cAuxBuffers) {
1235 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1236 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1238 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1239 bestStereo = dwFlags & PFD_STEREO;
1240 bestAlpha = alpha;
1241 bestColor = color;
1242 bestDepth = depth;
1243 bestStencil = stencil;
1244 bestAux = aux;
1245 bestFormat = i;
1246 continue;
1247 } else if(bestAux != aux) {
1248 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1249 continue;
1254 if(bestFormat == -1) {
1255 TRACE("No matching mode was found returning 0\n");
1256 ret = 0;
1258 else {
1259 ret = bestFormat+1; /* the return value should be a 1-based index */
1260 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, WineGLPixelFormatList[bestFormat].fmt_id);
1263 wine_tsx11_unlock();
1265 return ret;
1268 * X11DRV_DescribePixelFormat
1270 * Get the pixel-format descriptor associated to the given id
1272 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1273 int iPixelFormat,
1274 UINT nBytes,
1275 PIXELFORMATDESCRIPTOR *ppfd) {
1276 /*XVisualInfo *vis;*/
1277 int value;
1278 int rb,gb,bb,ab;
1279 WineGLPixelFormat *fmt;
1280 int ret = 0;
1281 int fmt_count = 0;
1283 if (!has_opengl()) {
1284 ERR("No libGL on this box - disabling OpenGL support !\n");
1285 return 0;
1288 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1290 /* 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 */
1291 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1292 if (ppfd == NULL) {
1293 /* The application is only querying the number of pixelformats */
1294 return fmt_count;
1295 } else if(fmt == NULL) {
1296 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1297 return 0;
1300 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1301 ERR("Wrong structure size !\n");
1302 /* Should set error */
1303 return 0;
1306 ret = fmt_count;
1308 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1309 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1310 ppfd->nVersion = 1;
1312 /* These flags are always the same... */
1313 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1314 /* Now the flags extracted from the Visual */
1316 wine_tsx11_lock();
1318 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_X_RENDERABLE, &value);
1319 if(value)
1320 ppfd->dwFlags |= PFD_SUPPORT_GDI;
1322 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1323 if(value & GLX_WINDOW_BIT)
1324 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1325 if(value & GLX_PIXMAP_BIT)
1326 ppfd->dwFlags |= PFD_DRAW_TO_BITMAP;
1328 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1329 if(value == GLX_SLOW_CONFIG)
1330 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1332 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1333 if (value) {
1334 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1335 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1337 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1339 /* Pixel type */
1340 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1341 if (value & GLX_RGBA_BIT)
1342 ppfd->iPixelType = PFD_TYPE_RGBA;
1343 else
1344 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1346 /* Color bits */
1347 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1348 ppfd->cColorBits = value;
1350 /* Red, green, blue and alpha bits / shifts */
1351 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1352 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1353 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1354 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1355 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1357 ppfd->cRedBits = rb;
1358 ppfd->cRedShift = gb + bb + ab;
1359 ppfd->cBlueBits = bb;
1360 ppfd->cBlueShift = ab;
1361 ppfd->cGreenBits = gb;
1362 ppfd->cGreenShift = bb + ab;
1363 ppfd->cAlphaBits = ab;
1364 ppfd->cAlphaShift = 0;
1365 } else {
1366 ppfd->cRedBits = 0;
1367 ppfd->cRedShift = 0;
1368 ppfd->cBlueBits = 0;
1369 ppfd->cBlueShift = 0;
1370 ppfd->cGreenBits = 0;
1371 ppfd->cGreenShift = 0;
1372 ppfd->cAlphaBits = 0;
1373 ppfd->cAlphaShift = 0;
1376 /* Accum RGBA bits */
1377 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1378 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1379 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1380 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1382 ppfd->cAccumBits = rb+gb+bb+ab;
1383 ppfd->cAccumRedBits = rb;
1384 ppfd->cAccumGreenBits = gb;
1385 ppfd->cAccumBlueBits = bb;
1386 ppfd->cAccumAlphaBits = ab;
1388 /* Aux bits */
1389 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1390 ppfd->cAuxBuffers = value;
1392 /* Depth bits */
1393 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1394 ppfd->cDepthBits = value;
1396 /* stencil bits */
1397 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1398 ppfd->cStencilBits = value;
1400 wine_tsx11_unlock();
1402 ppfd->iLayerType = PFD_MAIN_PLANE;
1404 if (TRACE_ON(wgl)) {
1405 dump_PIXELFORMATDESCRIPTOR(ppfd);
1408 return ret;
1412 * X11DRV_GetPixelFormat
1414 * Get the pixel-format id used by this DC
1416 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1417 WineGLPixelFormat *fmt;
1418 int tmp;
1419 TRACE("(%p)\n", physDev);
1421 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1422 if(!fmt)
1424 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1425 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1426 return 0;
1428 else if(fmt->offscreenOnly)
1430 /* Offscreen formats can't be used with traditional WGL calls.
1431 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1432 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1433 return 1;
1436 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1437 return physDev->current_pf;
1441 * X11DRV_SetPixelFormat
1443 * Set the pixel-format id used by this DC
1445 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1446 int iPixelFormat,
1447 const PIXELFORMATDESCRIPTOR *ppfd) {
1448 WineGLPixelFormat *fmt;
1449 int value;
1450 HWND hwnd;
1452 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1454 if (!has_opengl()) {
1455 ERR("No libGL on this box - disabling OpenGL support !\n");
1456 return FALSE;
1459 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1460 if(get_glxdrawable(physDev) == root_window)
1462 ERR("Invalid operation on root_window\n");
1463 return FALSE;
1466 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1467 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1468 if(!fmt) {
1469 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1470 return FALSE;
1473 if(physDev->current_pf) /* cannot change it if already set */
1474 return (physDev->current_pf == iPixelFormat);
1476 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1478 hwnd = WindowFromDC(physDev->hdc);
1479 if(hwnd) {
1480 if(!(value&GLX_WINDOW_BIT)) {
1481 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1482 return FALSE;
1485 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, (WPARAM)fmt->fmt_id, 0)) {
1486 ERR("Couldn't set format of the window, returning failure\n");
1487 return FALSE;
1490 else if(physDev->bitmap) {
1491 if(!(value&GLX_PIXMAP_BIT)) {
1492 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1493 return FALSE;
1496 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev, fmt);
1497 if(!physDev->bitmap->glxpixmap) {
1498 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat);
1499 return FALSE;
1502 else {
1503 FIXME("called on a non-window, non-bitmap object?\n");
1506 physDev->current_pf = iPixelFormat;
1508 if (TRACE_ON(wgl)) {
1509 int gl_test = 0;
1511 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1512 if (gl_test) {
1513 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1514 } else {
1515 TRACE(" FBConfig have :\n");
1516 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1517 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1518 TRACE(" - VISUAL_ID 0x%x\n", value);
1519 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1520 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1523 return TRUE;
1527 * X11DRV_wglCopyContext
1529 * For OpenGL32 wglCopyContext.
1531 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
1532 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1533 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1535 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1537 /* There is a slight difference in the way GL contexts share display lists in WGL and GLX.
1538 * In case of GLX you need to specify this at context creation time but in case of WGL you
1539 * do this using wglShareLists which you can call after creating the context.
1540 * To emulate WGL we try to delay the creation of the context until wglShareLists or wglMakeCurrent.
1541 * Up to now that works fine.
1543 * The delayed GLX context creation could cause issues for wglCopyContext as it might get called
1544 * when there is no GLX context yet. The chance this will cause problems is small as at the time of
1545 * writing Wine has had OpenGL support for more than 7 years and this function has remained a stub
1546 * ever since then.
1548 if(!src->ctx || !dst->ctx) {
1549 /* NOTE: As a special case, if both GLX contexts are NULL, that means
1550 * neither WGL context was made current. In that case, both contexts
1551 * are in a default state, so any copy would no-op.
1553 if(!src->ctx && !dst->ctx) {
1554 TRACE("No source or destination contexts set. No-op.\n");
1555 return TRUE;
1558 if (!src->ctx) {
1559 DWORD type = GetObjectType(src->hdc);
1560 wine_tsx11_lock();
1561 if(src->vis)
1562 src->ctx = pglXCreateContext(gdi_display, src->vis, NULL, type == OBJ_MEMDC ? False : True);
1563 else /* Create a GLX Context for a pbuffer */
1564 src->ctx = pglXCreateNewContext(gdi_display, src->fmt->fbconfig, src->fmt->render_type, NULL, True);
1565 TRACE(" created a delayed OpenGL context (%p)\n", src->ctx);
1567 else if (!dst->ctx) {
1568 DWORD type = GetObjectType(dst->hdc);
1569 wine_tsx11_lock();
1570 if(dst->vis)
1571 dst->ctx = pglXCreateContext(gdi_display, dst->vis, NULL, type == OBJ_MEMDC ? False : True);
1572 else /* Create a GLX Context for a pbuffer */
1573 dst->ctx = pglXCreateNewContext(gdi_display, dst->fmt->fbconfig, dst->fmt->render_type, NULL, True);
1574 TRACE(" created a delayed OpenGL context (%p)\n", dst->ctx);
1577 else
1578 wine_tsx11_lock();
1580 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1581 wine_tsx11_unlock();
1583 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1584 return TRUE;
1588 * X11DRV_wglCreateContext
1590 * For OpenGL32 wglCreateContext.
1592 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1594 Wine_GLContext *ret;
1595 WineGLPixelFormat *fmt;
1596 int hdcPF = physDev->current_pf;
1597 int fmt_count = 0;
1598 HDC hdc = physDev->hdc;
1600 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1602 if (!has_opengl()) {
1603 ERR("No libGL on this box - disabling OpenGL support !\n");
1604 return 0;
1607 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1608 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1609 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1610 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1611 * If this fails something is very wrong on the system. */
1612 if(!fmt) {
1613 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1614 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1615 return NULL;
1618 /* The context will be allocated in the wglMakeCurrent call */
1619 wine_tsx11_lock();
1620 ret = alloc_context();
1621 wine_tsx11_unlock();
1622 ret->hdc = hdc;
1623 ret->fmt = fmt;
1625 /*ret->vis = vis;*/
1626 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1628 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1629 return (HGLRC) ret;
1633 * X11DRV_wglDeleteContext
1635 * For OpenGL32 wglDeleteContext.
1637 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1639 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1640 BOOL ret = TRUE;
1642 TRACE("(%p)\n", hglrc);
1644 if (!has_opengl()) {
1645 ERR("No libGL on this box - disabling OpenGL support !\n");
1646 return 0;
1649 wine_tsx11_lock();
1650 /* A game (Half Life not to name it) deletes twice the same context,
1651 * so make sure it is valid first */
1652 if (is_valid_context( ctx ))
1654 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1655 free_context(ctx);
1657 else
1659 WARN("Error deleting context !\n");
1660 SetLastError(ERROR_INVALID_HANDLE);
1661 ret = FALSE;
1663 wine_tsx11_unlock();
1665 return ret;
1669 * X11DRV_wglGetCurrentReadDCARB
1671 * For OpenGL32 wglGetCurrentReadDCARB.
1673 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1675 HDC ret = 0;
1676 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1678 if (ctx) ret = ctx->read_hdc;
1680 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1681 return ret;
1685 * X11DRV_wglGetProcAddress
1687 * For OpenGL32 wglGetProcAddress.
1689 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1691 int i, j;
1692 const WineGLExtension *ext;
1694 int padding = 32 - strlen(lpszProc);
1695 if (padding < 0)
1696 padding = 0;
1698 if (!has_opengl()) {
1699 ERR("No libGL on this box - disabling OpenGL support !\n");
1700 return 0;
1703 /* Check the table of WGL extensions to see if we need to return a WGL extension
1704 * or a function pointer to a native OpenGL function. */
1705 if(strncmp(lpszProc, "wgl", 3) != 0) {
1706 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1707 } else {
1708 TRACE("('%s'):%*s", lpszProc, padding, " ");
1709 for (i = 0; i < WineGLExtensionListSize; ++i) {
1710 ext = WineGLExtensionList[i];
1711 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1712 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1713 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1714 return ext->extEntryPoints[j].funcAddress;
1720 WARN("(%s) - not found\n", lpszProc);
1721 return NULL;
1725 * X11DRV_wglMakeCurrent
1727 * For OpenGL32 wglMakeCurrent.
1729 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1730 BOOL ret;
1731 HDC hdc = physDev->hdc;
1732 DWORD type = GetObjectType(hdc);
1734 TRACE("(%p,%p)\n", hdc, hglrc);
1736 if (!has_opengl()) {
1737 ERR("No libGL on this box - disabling OpenGL support !\n");
1738 return FALSE;
1741 wine_tsx11_lock();
1742 if (hglrc == NULL) {
1743 ret = pglXMakeCurrent(gdi_display, None, NULL);
1744 NtCurrentTeb()->glContext = NULL;
1745 } else {
1746 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1747 Drawable drawable = get_glxdrawable(physDev);
1748 if (ctx->ctx == NULL) {
1749 /* The describe lines below are for debugging purposes only */
1750 if (TRACE_ON(wgl)) {
1751 describeDrawable(ctx, drawable);
1752 describeContext(ctx);
1755 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1756 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1758 TRACE(" Creating GLX Context\n");
1759 if(ctx->vis)
1760 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1761 else /* Create a GLX Context for a pbuffer */
1762 ctx->ctx = pglXCreateNewContext(gdi_display, ctx->fmt->fbconfig, ctx->fmt->render_type, NULL, True);
1764 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1766 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1767 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1768 NtCurrentTeb()->glContext = ctx;
1769 if(ret)
1771 ctx->hdc = hdc;
1772 ctx->read_hdc = hdc;
1773 ctx->drawables[0] = drawable;
1774 ctx->drawables[1] = drawable;
1775 ctx->refresh_drawables = FALSE;
1777 if (type == OBJ_MEMDC)
1779 ctx->do_escape = TRUE;
1780 pglDrawBuffer(GL_FRONT_LEFT);
1784 wine_tsx11_unlock();
1785 TRACE(" returning %s\n", (ret ? "True" : "False"));
1786 return ret;
1790 * X11DRV_wglMakeContextCurrentARB
1792 * For OpenGL32 wglMakeContextCurrentARB
1794 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1796 BOOL ret;
1797 int indirect = (GetObjectType(pDrawDev->hdc) == OBJ_MEMDC);
1799 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1801 if (!has_opengl()) {
1802 ERR("No libGL on this box - disabling OpenGL support !\n");
1803 return 0;
1806 wine_tsx11_lock();
1807 if (hglrc == NULL) {
1808 ret = pglXMakeCurrent(gdi_display, None, NULL);
1809 NtCurrentTeb()->glContext = NULL;
1810 } else {
1811 if (NULL == pglXMakeContextCurrent) {
1812 ret = FALSE;
1813 } else {
1814 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1815 Drawable d_draw = get_glxdrawable(pDrawDev);
1816 Drawable d_read = get_glxdrawable(pReadDev);
1818 if (ctx->ctx == NULL) {
1819 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, !indirect);
1820 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1822 ctx->hdc = pDrawDev->hdc;
1823 ctx->read_hdc = pReadDev->hdc;
1824 ctx->drawables[0] = d_draw;
1825 ctx->drawables[1] = d_read;
1826 ctx->refresh_drawables = FALSE;
1827 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1828 NtCurrentTeb()->glContext = ctx;
1831 wine_tsx11_unlock();
1833 TRACE(" returning %s\n", (ret ? "True" : "False"));
1834 return ret;
1838 * X11DRV_wglShareLists
1840 * For OpenGL32 wglShaderLists.
1842 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1843 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1844 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1846 TRACE("(%p, %p)\n", org, dest);
1848 if (!has_opengl()) {
1849 ERR("No libGL on this box - disabling OpenGL support !\n");
1850 return 0;
1853 if (NULL != dest && dest->ctx != NULL) {
1854 ERR("Could not share display lists, context already created !\n");
1855 return FALSE;
1856 } else {
1857 if (org->ctx == NULL) {
1858 int indirect = (GetObjectType(org->hdc) == OBJ_MEMDC);
1859 wine_tsx11_lock();
1860 describeContext(org);
1862 if(org->vis)
1863 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, !indirect);
1864 else /* Create a GLX Context for a pbuffer */
1865 org->ctx = pglXCreateNewContext(gdi_display, org->fmt->fbconfig, org->fmt->render_type, NULL, True);
1866 wine_tsx11_unlock();
1867 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1869 if (NULL != dest) {
1870 int indirect = (GetObjectType(dest->hdc) == OBJ_MEMDC);
1871 wine_tsx11_lock();
1872 describeContext(dest);
1873 /* Create the destination context with display lists shared */
1874 if(dest->vis)
1875 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, !indirect);
1876 else /* Create a GLX Context for a pbuffer */
1877 dest->ctx = pglXCreateNewContext(gdi_display, dest->fmt->fbconfig, dest->fmt->render_type, org->ctx, True);
1878 wine_tsx11_unlock();
1879 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1880 return TRUE;
1883 return FALSE;
1886 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1888 /* We are running using client-side rendering fonts... */
1889 GLYPHMETRICS gm;
1890 unsigned int glyph;
1891 int size = 0;
1892 void *bitmap = NULL, *gl_bitmap = NULL;
1893 int org_alignment;
1895 wine_tsx11_lock();
1896 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1897 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1898 wine_tsx11_unlock();
1900 for (glyph = first; glyph < first + count; glyph++) {
1901 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1902 int height, width_int;
1904 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1905 if (needed_size == GDI_ERROR) {
1906 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1907 goto error;
1908 } else {
1909 TRACE(" - needed size : %d\n", needed_size);
1912 if (needed_size > size) {
1913 size = needed_size;
1914 HeapFree(GetProcessHeap(), 0, bitmap);
1915 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1916 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1917 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1919 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1920 if (TRACE_ON(wgl)) {
1921 unsigned int height, width, bitmask;
1922 unsigned char *bitmap_ = (unsigned char *) bitmap;
1924 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1925 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1926 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1927 if (needed_size != 0) {
1928 TRACE(" - bitmap :\n");
1929 for (height = 0; height < gm.gmBlackBoxY; height++) {
1930 TRACE(" ");
1931 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1932 if (bitmask == 0) {
1933 bitmap_ += 1;
1934 bitmask = 0x80;
1936 if (*bitmap_ & bitmask)
1937 TRACE("*");
1938 else
1939 TRACE(" ");
1941 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1942 TRACE("\n");
1947 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1948 * glyph for it to be drawn properly.
1950 if (needed_size != 0) {
1951 width_int = (gm.gmBlackBoxX + 31) / 32;
1952 for (height = 0; height < gm.gmBlackBoxY; height++) {
1953 int width;
1954 for (width = 0; width < width_int; width++) {
1955 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1956 ((int *) bitmap)[height * width_int + width];
1961 wine_tsx11_lock();
1962 pglNewList(listBase++, GL_COMPILE);
1963 if (needed_size != 0) {
1964 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1965 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
1966 gm.gmCellIncX, gm.gmCellIncY,
1967 gl_bitmap);
1968 } else {
1969 /* This is the case of 'empty' glyphs like the space character */
1970 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1972 pglEndList();
1973 wine_tsx11_unlock();
1976 wine_tsx11_lock();
1977 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1978 wine_tsx11_unlock();
1980 HeapFree(GetProcessHeap(), 0, bitmap);
1981 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1982 return TRUE;
1984 error:
1985 wine_tsx11_lock();
1986 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1987 wine_tsx11_unlock();
1989 HeapFree(GetProcessHeap(), 0, bitmap);
1990 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1991 return FALSE;
1995 * X11DRV_wglUseFontBitmapsA
1997 * For OpenGL32 wglUseFontBitmapsA.
1999 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2001 Font fid = physDev->font;
2003 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2005 if (!has_opengl()) {
2006 ERR("No libGL on this box - disabling OpenGL support !\n");
2007 return 0;
2010 if (fid == 0) {
2011 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
2014 wine_tsx11_lock();
2015 /* I assume that the glyphs are at the same position for X and for Windows */
2016 pglXUseXFont(fid, first, count, listBase);
2017 wine_tsx11_unlock();
2018 return TRUE;
2022 * X11DRV_wglUseFontBitmapsW
2024 * For OpenGL32 wglUseFontBitmapsW.
2026 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2028 Font fid = physDev->font;
2030 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2032 if (!has_opengl()) {
2033 ERR("No libGL on this box - disabling OpenGL support !\n");
2034 return 0;
2037 if (fid == 0) {
2038 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
2041 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2043 wine_tsx11_lock();
2044 /* I assume that the glyphs are at the same position for X and for Windows */
2045 pglXUseXFont(fid, first, count, listBase);
2046 wine_tsx11_unlock();
2047 return TRUE;
2050 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2051 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2053 wine_tsx11_lock();
2054 switch(pname)
2056 case GL_DEPTH_BITS:
2058 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2060 pglGetIntegerv(pname, params);
2062 * if we cannot find a Wine Context
2063 * we only have the default wine desktop context,
2064 * so if we have only a 24 depth say we have 32
2066 if (!ctx && *params == 24) {
2067 *params = 32;
2069 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2070 break;
2072 case GL_ALPHA_BITS:
2074 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2076 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2077 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2078 break;
2080 default:
2081 pglGetIntegerv(pname, params);
2082 break;
2084 wine_tsx11_unlock();
2087 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
2089 int w, h;
2091 if(!physDev->gl_drawable)
2092 return;
2094 w = physDev->dc_rect.right - physDev->dc_rect.left;
2095 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
2097 if(w > 0 && h > 0) {
2098 Drawable src = physDev->pixmap;
2099 if(!src) src = physDev->gl_drawable;
2101 /* The GL drawable may be lagged behind if we don't flush first, so
2102 * flush the display make sure we copy up-to-date data */
2103 wine_tsx11_lock();
2104 XFlush(gdi_display);
2105 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
2106 physDev->dc_rect.left, physDev->dc_rect.top);
2107 wine_tsx11_unlock();
2112 static void WINAPI X11DRV_wglFinish(void)
2114 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2115 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2117 wine_tsx11_lock();
2118 sync_context(ctx);
2119 pglFinish();
2120 wine_tsx11_unlock();
2121 ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2124 static void WINAPI X11DRV_wglFlush(void)
2126 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2127 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2129 wine_tsx11_lock();
2130 sync_context(ctx);
2131 pglFlush();
2132 wine_tsx11_unlock();
2133 ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2137 * X11DRV_wglGetExtensionsStringARB
2139 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2141 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2142 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2143 return WineGLInfo.wglExtensions;
2147 * X11DRV_wglCreatePbufferARB
2149 * WGL_ARB_pbuffer: wglCreatePbufferARB
2151 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2153 Wine_GLPBuffer* object = NULL;
2154 WineGLPixelFormat *fmt = NULL;
2155 int nCfgs = 0;
2156 int attribs[256];
2157 int nAttribs = 0;
2159 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2161 if (0 >= iPixelFormat) {
2162 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2163 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2164 return NULL; /* unexpected error */
2167 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2168 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2169 if(!fmt) {
2170 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2171 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2172 goto create_failed; /* unexpected error */
2175 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2176 if (NULL == object) {
2177 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2178 goto create_failed; /* unexpected error */
2180 object->hdc = hdc;
2181 object->display = gdi_display;
2182 object->width = iWidth;
2183 object->height = iHeight;
2184 object->fmt = fmt;
2186 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2187 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2188 while (piAttribList && 0 != *piAttribList) {
2189 int attr_v;
2190 switch (*piAttribList) {
2191 case WGL_PBUFFER_LARGEST_ARB: {
2192 ++piAttribList;
2193 attr_v = *piAttribList;
2194 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2195 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2196 break;
2199 case WGL_TEXTURE_FORMAT_ARB: {
2200 ++piAttribList;
2201 attr_v = *piAttribList;
2202 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2203 if (use_render_texture_ati) {
2204 int type = 0;
2205 switch (attr_v) {
2206 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2207 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2208 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2209 default:
2210 SetLastError(ERROR_INVALID_DATA);
2211 goto create_failed;
2213 object->use_render_texture = 1;
2214 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2215 } else {
2216 if (WGL_NO_TEXTURE_ARB == attr_v) {
2217 object->use_render_texture = 0;
2218 } else {
2219 if (!use_render_texture_emulation) {
2220 SetLastError(ERROR_INVALID_DATA);
2221 goto create_failed;
2223 switch (attr_v) {
2224 case WGL_TEXTURE_RGB_ARB:
2225 object->use_render_texture = GL_RGB;
2226 object->texture_bpp = 3;
2227 object->texture_format = GL_RGB;
2228 object->texture_type = GL_UNSIGNED_BYTE;
2229 break;
2230 case WGL_TEXTURE_RGBA_ARB:
2231 object->use_render_texture = GL_RGBA;
2232 object->texture_bpp = 4;
2233 object->texture_format = GL_RGBA;
2234 object->texture_type = GL_UNSIGNED_BYTE;
2235 break;
2237 /* WGL_FLOAT_COMPONENTS_NV */
2238 case WGL_TEXTURE_FLOAT_R_NV:
2239 object->use_render_texture = GL_FLOAT_R_NV;
2240 object->texture_bpp = 4;
2241 object->texture_format = GL_RED;
2242 object->texture_type = GL_FLOAT;
2243 break;
2244 case WGL_TEXTURE_FLOAT_RG_NV:
2245 object->use_render_texture = GL_FLOAT_RG_NV;
2246 object->texture_bpp = 8;
2247 object->texture_format = GL_LUMINANCE_ALPHA;
2248 object->texture_type = GL_FLOAT;
2249 break;
2250 case WGL_TEXTURE_FLOAT_RGB_NV:
2251 object->use_render_texture = GL_FLOAT_RGB_NV;
2252 object->texture_bpp = 12;
2253 object->texture_format = GL_RGB;
2254 object->texture_type = GL_FLOAT;
2255 break;
2256 case WGL_TEXTURE_FLOAT_RGBA_NV:
2257 object->use_render_texture = GL_FLOAT_RGBA_NV;
2258 object->texture_bpp = 16;
2259 object->texture_format = GL_RGBA;
2260 object->texture_type = GL_FLOAT;
2261 break;
2262 default:
2263 ERR("Unknown texture format: %x\n", attr_v);
2264 SetLastError(ERROR_INVALID_DATA);
2265 goto create_failed;
2269 break;
2272 case WGL_TEXTURE_TARGET_ARB: {
2273 ++piAttribList;
2274 attr_v = *piAttribList;
2275 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2276 if (use_render_texture_ati) {
2277 int type = 0;
2278 switch (attr_v) {
2279 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2280 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2281 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2282 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2283 default:
2284 SetLastError(ERROR_INVALID_DATA);
2285 goto create_failed;
2287 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2288 } else {
2289 if (WGL_NO_TEXTURE_ARB == attr_v) {
2290 object->texture_target = 0;
2291 } else {
2292 if (!use_render_texture_emulation) {
2293 SetLastError(ERROR_INVALID_DATA);
2294 goto create_failed;
2296 switch (attr_v) {
2297 case WGL_TEXTURE_CUBE_MAP_ARB: {
2298 if (iWidth != iHeight) {
2299 SetLastError(ERROR_INVALID_DATA);
2300 goto create_failed;
2302 object->texture_target = GL_TEXTURE_CUBE_MAP;
2303 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2304 break;
2306 case WGL_TEXTURE_1D_ARB: {
2307 if (1 != iHeight) {
2308 SetLastError(ERROR_INVALID_DATA);
2309 goto create_failed;
2311 object->texture_target = GL_TEXTURE_1D;
2312 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2313 break;
2315 case WGL_TEXTURE_2D_ARB: {
2316 object->texture_target = GL_TEXTURE_2D;
2317 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2318 break;
2320 case WGL_TEXTURE_RECTANGLE_NV: {
2321 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2322 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2323 break;
2325 default:
2326 ERR("Unknown texture target: %x\n", attr_v);
2327 SetLastError(ERROR_INVALID_DATA);
2328 goto create_failed;
2332 break;
2335 case WGL_MIPMAP_TEXTURE_ARB: {
2336 ++piAttribList;
2337 attr_v = *piAttribList;
2338 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2339 if (use_render_texture_ati) {
2340 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2341 } else {
2342 if (!use_render_texture_emulation) {
2343 SetLastError(ERROR_INVALID_DATA);
2344 goto create_failed;
2347 break;
2350 ++piAttribList;
2353 PUSH1(attribs, None);
2354 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2355 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2356 if (!object->drawable) {
2357 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2358 goto create_failed; /* unexpected error */
2360 TRACE("->(%p)\n", object);
2361 return (HPBUFFERARB) object;
2363 create_failed:
2364 HeapFree(GetProcessHeap(), 0, object);
2365 TRACE("->(FAILED)\n");
2366 return NULL;
2370 * X11DRV_wglDestroyPbufferARB
2372 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2374 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2376 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2377 TRACE("(%p)\n", hPbuffer);
2378 if (NULL == object) {
2379 SetLastError(ERROR_INVALID_HANDLE);
2380 return GL_FALSE;
2382 pglXDestroyPbuffer(object->display, object->drawable);
2383 HeapFree(GetProcessHeap(), 0, object);
2384 return GL_TRUE;
2388 * X11DRV_wglGetPbufferDCARB
2390 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2391 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2392 * Gdi32 implements the part of this function which creates a device context.
2393 * This part associates the physDev with the X drawable of the pbuffer.
2395 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2397 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2398 if (NULL == object) {
2399 SetLastError(ERROR_INVALID_HANDLE);
2400 return NULL;
2403 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2404 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2405 physDev->current_pf = object->fmt->iPixelFormat;
2406 physDev->drawable = object->drawable;
2407 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2408 physDev->dc_rect = physDev->drawable_rect;
2410 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2411 return physDev->hdc;
2415 * X11DRV_wglQueryPbufferARB
2417 * WGL_ARB_pbuffer: wglQueryPbufferARB
2419 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2421 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2422 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2423 if (NULL == object) {
2424 SetLastError(ERROR_INVALID_HANDLE);
2425 return GL_FALSE;
2427 switch (iAttribute) {
2428 case WGL_PBUFFER_WIDTH_ARB:
2429 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2430 break;
2431 case WGL_PBUFFER_HEIGHT_ARB:
2432 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2433 break;
2435 case WGL_PBUFFER_LOST_ARB:
2436 /* GLX Pbuffers cannot be lost by default. We can support this by
2437 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2438 * to receive pixel buffer clobber events, however that may or may
2439 * not give any benefit */
2440 *piValue = GL_FALSE;
2441 break;
2443 case WGL_TEXTURE_FORMAT_ARB:
2444 if (use_render_texture_ati) {
2445 unsigned int tmp;
2446 int type = WGL_NO_TEXTURE_ARB;
2447 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2448 switch (tmp) {
2449 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2450 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2451 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2453 *piValue = type;
2454 } else {
2455 if (!object->use_render_texture) {
2456 *piValue = WGL_NO_TEXTURE_ARB;
2457 } else {
2458 if (!use_render_texture_emulation) {
2459 SetLastError(ERROR_INVALID_HANDLE);
2460 return GL_FALSE;
2462 switch(object->use_render_texture) {
2463 case GL_RGB:
2464 *piValue = WGL_TEXTURE_RGB_ARB;
2465 break;
2466 case GL_RGBA:
2467 *piValue = WGL_TEXTURE_RGBA_ARB;
2468 break;
2469 /* WGL_FLOAT_COMPONENTS_NV */
2470 case GL_FLOAT_R_NV:
2471 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2472 break;
2473 case GL_FLOAT_RG_NV:
2474 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2475 break;
2476 case GL_FLOAT_RGB_NV:
2477 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2478 break;
2479 case GL_FLOAT_RGBA_NV:
2480 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2481 break;
2482 default:
2483 ERR("Unknown texture format: %x\n", object->use_render_texture);
2487 break;
2489 case WGL_TEXTURE_TARGET_ARB:
2490 if (use_render_texture_ati) {
2491 unsigned int tmp;
2492 int type = WGL_NO_TEXTURE_ARB;
2493 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2494 switch (tmp) {
2495 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2496 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2497 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2498 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2500 *piValue = type;
2501 } else {
2502 if (!object->texture_target) {
2503 *piValue = WGL_NO_TEXTURE_ARB;
2504 } else {
2505 if (!use_render_texture_emulation) {
2506 SetLastError(ERROR_INVALID_DATA);
2507 return GL_FALSE;
2509 switch (object->texture_target) {
2510 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2511 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2512 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2513 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2517 break;
2519 case WGL_MIPMAP_TEXTURE_ARB:
2520 if (use_render_texture_ati) {
2521 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2522 } else {
2523 *piValue = GL_FALSE; /** don't support that */
2524 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2526 break;
2528 default:
2529 FIXME("unexpected attribute %x\n", iAttribute);
2530 break;
2533 return GL_TRUE;
2537 * X11DRV_wglReleasePbufferDCARB
2539 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2541 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2543 TRACE("(%p, %p)\n", hPbuffer, hdc);
2544 return DeleteDC(hdc);
2548 * X11DRV_wglSetPbufferAttribARB
2550 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2552 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2554 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2555 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2556 if (NULL == object) {
2557 SetLastError(ERROR_INVALID_HANDLE);
2558 return GL_FALSE;
2560 if (!object->use_render_texture) {
2561 SetLastError(ERROR_INVALID_HANDLE);
2562 return GL_FALSE;
2564 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2565 return GL_TRUE;
2567 if (NULL != pglXDrawableAttribATI) {
2568 if (use_render_texture_ati) {
2569 FIXME("Need conversion for GLX_ATI_render_texture\n");
2571 return pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2573 return GL_FALSE;
2577 * X11DRV_wglChoosePixelFormatARB
2579 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2581 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2583 int gl_test = 0;
2584 int attribs[256];
2585 int nAttribs = 0;
2586 GLXFBConfig* cfgs = NULL;
2587 int nCfgs = 0;
2588 UINT it;
2589 int fmt_id;
2590 WineGLPixelFormat *fmt;
2591 int pfmt_it = 0;
2592 int run;
2594 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2595 if (NULL != pfAttribFList) {
2596 FIXME("unused pfAttribFList\n");
2599 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2600 if (-1 == nAttribs) {
2601 WARN("Cannot convert WGL to GLX attributes\n");
2602 return GL_FALSE;
2604 PUSH1(attribs, None);
2606 /* Search for FB configurations matching the requirements in attribs */
2607 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2608 if (NULL == cfgs) {
2609 WARN("Compatible Pixel Format not found\n");
2610 return GL_FALSE;
2613 /* Loop through all matching formats and check if they are suitable.
2614 * Note that this function should at max return nMaxFormats different formats */
2615 for(run=0; run < 2; run++)
2617 for (it = 0; it < nCfgs; ++it) {
2618 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2619 if (gl_test) {
2620 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2621 continue;
2624 /* Search for the format in our list of compatible formats */
2625 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2626 if(!fmt)
2627 continue;
2629 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2630 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2631 continue;
2633 if(pfmt_it < nMaxFormats) {
2634 piFormats[pfmt_it] = fmt->iPixelFormat;
2635 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2637 pfmt_it++;
2641 *nNumFormats = pfmt_it;
2642 /** free list */
2643 XFree(cfgs);
2644 return GL_TRUE;
2648 * X11DRV_wglGetPixelFormatAttribivARB
2650 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2652 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2654 UINT i;
2655 WineGLPixelFormat *fmt = NULL;
2656 int hTest;
2657 int tmp;
2658 int curGLXAttr = 0;
2659 int nWGLFormats = 0;
2661 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2663 if (0 < iLayerPlane) {
2664 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2665 return GL_FALSE;
2668 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2669 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2670 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2671 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2672 if(!fmt) {
2673 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2676 for (i = 0; i < nAttributes; ++i) {
2677 const int curWGLAttr = piAttributes[i];
2678 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2680 switch (curWGLAttr) {
2681 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2682 piValues[i] = nWGLFormats;
2683 continue;
2685 case WGL_SUPPORT_OPENGL_ARB:
2686 piValues[i] = GL_TRUE;
2687 continue;
2689 case WGL_ACCELERATION_ARB:
2690 curGLXAttr = GLX_CONFIG_CAVEAT;
2691 if (!fmt) goto pix_error;
2692 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2693 if (hTest) goto get_error;
2694 switch (tmp) {
2695 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2696 case GLX_SLOW_CONFIG: piValues[i] = WGL_GENERIC_ACCELERATION_ARB; break;
2697 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2698 default:
2699 ERR("unexpected Config Caveat(%x)\n", tmp);
2700 piValues[i] = WGL_NO_ACCELERATION_ARB;
2702 continue;
2704 case WGL_TRANSPARENT_ARB:
2705 curGLXAttr = GLX_TRANSPARENT_TYPE;
2706 if (!fmt) goto pix_error;
2707 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2708 if (hTest) goto get_error;
2709 piValues[i] = GL_FALSE;
2710 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2711 continue;
2713 case WGL_PIXEL_TYPE_ARB:
2714 curGLXAttr = GLX_RENDER_TYPE;
2715 if (!fmt) goto pix_error;
2716 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2717 if (hTest) goto get_error;
2718 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2719 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2720 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2721 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2722 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2723 else {
2724 ERR("unexpected RenderType(%x)\n", tmp);
2725 piValues[i] = WGL_TYPE_RGBA_ARB;
2727 continue;
2729 case WGL_COLOR_BITS_ARB:
2730 curGLXAttr = GLX_BUFFER_SIZE;
2731 break;
2733 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2734 if (use_render_texture_ati) {
2735 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2736 break;
2738 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2739 if (use_render_texture_ati) {
2740 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2741 break;
2743 if (!use_render_texture_emulation) {
2744 piValues[i] = GL_FALSE;
2745 continue;
2747 curGLXAttr = GLX_RENDER_TYPE;
2748 if (!fmt) goto pix_error;
2749 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2750 if (hTest) goto get_error;
2751 if (GLX_COLOR_INDEX_BIT == tmp) {
2752 piValues[i] = GL_FALSE;
2753 continue;
2755 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2756 if (hTest) goto get_error;
2757 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2758 continue;
2760 case WGL_BLUE_BITS_ARB:
2761 curGLXAttr = GLX_BLUE_SIZE;
2762 break;
2763 case WGL_RED_BITS_ARB:
2764 curGLXAttr = GLX_RED_SIZE;
2765 break;
2766 case WGL_GREEN_BITS_ARB:
2767 curGLXAttr = GLX_GREEN_SIZE;
2768 break;
2769 case WGL_ALPHA_BITS_ARB:
2770 curGLXAttr = GLX_ALPHA_SIZE;
2771 break;
2772 case WGL_DEPTH_BITS_ARB:
2773 curGLXAttr = GLX_DEPTH_SIZE;
2774 break;
2775 case WGL_STENCIL_BITS_ARB:
2776 curGLXAttr = GLX_STENCIL_SIZE;
2777 break;
2778 case WGL_DOUBLE_BUFFER_ARB:
2779 curGLXAttr = GLX_DOUBLEBUFFER;
2780 break;
2781 case WGL_STEREO_ARB:
2782 curGLXAttr = GLX_STEREO;
2783 break;
2784 case WGL_AUX_BUFFERS_ARB:
2785 curGLXAttr = GLX_AUX_BUFFERS;
2786 break;
2788 case WGL_SUPPORT_GDI_ARB:
2789 if (!fmt) goto pix_error;
2790 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &tmp);
2791 if (hTest) goto get_error;
2792 if(tmp) {
2793 piValues[i] = GL_FALSE;
2794 continue;
2796 curGLXAttr = GLX_X_RENDERABLE;
2797 break;
2799 case WGL_DRAW_TO_WINDOW_ARB:
2800 case WGL_DRAW_TO_BITMAP_ARB:
2801 case WGL_DRAW_TO_PBUFFER_ARB:
2802 if (!fmt) goto pix_error;
2803 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2804 if (hTest) goto get_error;
2805 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2806 (curWGLAttr == WGL_DRAW_TO_BITMAP_ARB && (tmp&GLX_PIXMAP_BIT)) ||
2807 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2808 piValues[i] = GL_TRUE;
2809 else
2810 piValues[i] = GL_FALSE;
2811 continue;
2813 case WGL_PBUFFER_LARGEST_ARB:
2814 curGLXAttr = GLX_LARGEST_PBUFFER;
2815 break;
2817 case WGL_SAMPLE_BUFFERS_ARB:
2818 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2819 break;
2821 case WGL_SAMPLES_ARB:
2822 curGLXAttr = GLX_SAMPLES_ARB;
2823 break;
2825 case WGL_FLOAT_COMPONENTS_NV:
2826 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2827 break;
2829 case WGL_ACCUM_RED_BITS_ARB:
2830 curGLXAttr = GLX_ACCUM_RED_SIZE;
2831 break;
2832 case WGL_ACCUM_GREEN_BITS_ARB:
2833 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2834 break;
2835 case WGL_ACCUM_BLUE_BITS_ARB:
2836 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2837 break;
2838 case WGL_ACCUM_ALPHA_BITS_ARB:
2839 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2840 break;
2841 case WGL_ACCUM_BITS_ARB:
2842 if (!fmt) goto pix_error;
2843 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2844 if (hTest) goto get_error;
2845 piValues[i] = tmp;
2846 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2847 if (hTest) goto get_error;
2848 piValues[i] += tmp;
2849 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2850 if (hTest) goto get_error;
2851 piValues[i] += tmp;
2852 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2853 if (hTest) goto get_error;
2854 piValues[i] += tmp;
2855 continue;
2857 default:
2858 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2861 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2862 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2863 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2865 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2866 * and check which options can work using iPixelFormat=0 and which not.
2867 * A problem would be that this function is an extension. This would
2868 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2870 if (0 != curGLXAttr && iPixelFormat != 0) {
2871 if (!fmt) goto pix_error;
2872 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2873 if (hTest) goto get_error;
2874 curGLXAttr = 0;
2875 } else {
2876 piValues[i] = GL_FALSE;
2879 return GL_TRUE;
2881 get_error:
2882 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2883 return GL_FALSE;
2885 pix_error:
2886 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2887 return GL_FALSE;
2891 * X11DRV_wglGetPixelFormatAttribfvARB
2893 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2895 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2897 int *attr;
2898 int ret;
2899 int i;
2901 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2903 /* Allocate a temporary array to store integer values */
2904 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2905 if (!attr) {
2906 ERR("couldn't allocate %d array\n", nAttributes);
2907 return GL_FALSE;
2910 /* Piggy-back on wglGetPixelFormatAttribivARB */
2911 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2912 if (ret) {
2913 /* Convert integer values to float. Should also check for attributes
2914 that can give decimal values here */
2915 for (i=0; i<nAttributes;i++) {
2916 pfValues[i] = attr[i];
2920 HeapFree(GetProcessHeap(), 0, attr);
2921 return ret;
2925 * X11DRV_wglBindTexImageARB
2927 * WGL_ARB_render_texture: wglBindTexImageARB
2929 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2931 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2932 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2933 if (NULL == object) {
2934 SetLastError(ERROR_INVALID_HANDLE);
2935 return GL_FALSE;
2937 if (!object->use_render_texture) {
2938 SetLastError(ERROR_INVALID_HANDLE);
2939 return GL_FALSE;
2942 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2943 static int init = 0;
2944 int prev_binded_texture = 0;
2945 GLXContext prev_context = pglXGetCurrentContext();
2946 Drawable prev_drawable = pglXGetCurrentDrawable();
2947 GLXContext tmp_context;
2949 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2950 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2951 isn't ideal performance wise but I wasn't able to get other ways working.
2953 if(!init) {
2954 init = 1; /* Only show the FIXME once for performance reasons */
2955 FIXME("partial stub!\n");
2958 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
2959 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2961 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2963 /* Switch to our pbuffer */
2964 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2966 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2967 * After that upload the pbuffer texture data. */
2968 pglBindTexture(object->texture_target, prev_binded_texture);
2969 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2971 /* Switch back to the original drawable and upload the pbuffer-texture */
2972 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2973 pglXDestroyContext(gdi_display, tmp_context);
2974 return GL_TRUE;
2977 if (NULL != pglXBindTexImageATI) {
2978 int buffer;
2980 switch(iBuffer)
2982 case WGL_FRONT_LEFT_ARB:
2983 buffer = GLX_FRONT_LEFT_ATI;
2984 break;
2985 case WGL_FRONT_RIGHT_ARB:
2986 buffer = GLX_FRONT_RIGHT_ATI;
2987 break;
2988 case WGL_BACK_LEFT_ARB:
2989 buffer = GLX_BACK_LEFT_ATI;
2990 break;
2991 case WGL_BACK_RIGHT_ARB:
2992 buffer = GLX_BACK_RIGHT_ATI;
2993 break;
2994 default:
2995 ERR("Unknown iBuffer=%#x\n", iBuffer);
2996 return FALSE;
2999 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3000 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3001 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3002 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3003 * works fine using our pbuffer emulation path.
3005 return pglXBindTexImageATI(object->display, object->drawable, buffer);
3007 return GL_FALSE;
3011 * X11DRV_wglReleaseTexImageARB
3013 * WGL_ARB_render_texture: wglReleaseTexImageARB
3015 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3017 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
3018 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3019 if (NULL == object) {
3020 SetLastError(ERROR_INVALID_HANDLE);
3021 return GL_FALSE;
3023 if (!object->use_render_texture) {
3024 SetLastError(ERROR_INVALID_HANDLE);
3025 return GL_FALSE;
3027 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3028 return GL_TRUE;
3030 if (NULL != pglXReleaseTexImageATI) {
3031 int buffer;
3033 switch(iBuffer)
3035 case WGL_FRONT_LEFT_ARB:
3036 buffer = GLX_FRONT_LEFT_ATI;
3037 break;
3038 case WGL_FRONT_RIGHT_ARB:
3039 buffer = GLX_FRONT_RIGHT_ATI;
3040 break;
3041 case WGL_BACK_LEFT_ARB:
3042 buffer = GLX_BACK_LEFT_ATI;
3043 break;
3044 case WGL_BACK_RIGHT_ARB:
3045 buffer = GLX_BACK_RIGHT_ATI;
3046 break;
3047 default:
3048 ERR("Unknown iBuffer=%#x\n", iBuffer);
3049 return FALSE;
3051 return pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3053 return GL_FALSE;
3057 * X11DRV_wglGetExtensionsStringEXT
3059 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3061 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3062 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3063 return WineGLInfo.wglExtensions;
3067 * X11DRV_wglGetSwapIntervalEXT
3069 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3071 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3072 FIXME("(),stub!\n");
3073 return swap_interval;
3077 * X11DRV_wglSwapIntervalEXT
3079 * WGL_EXT_swap_control: wglSwapIntervalEXT
3081 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3082 TRACE("(%d)\n", interval);
3083 swap_interval = interval;
3084 if (NULL != pglXSwapIntervalSGI) {
3085 return 0 == pglXSwapIntervalSGI(interval);
3087 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3088 return TRUE;
3092 * X11DRV_wglAllocateMemoryNV
3094 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3096 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3097 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3098 if (pglXAllocateMemoryNV == NULL)
3099 return NULL;
3101 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3105 * X11DRV_wglFreeMemoryNV
3107 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3109 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3110 TRACE("(%p)\n", pointer);
3111 if (pglXFreeMemoryNV == NULL)
3112 return;
3114 pglXFreeMemoryNV(pointer);
3118 * glxRequireVersion (internal)
3120 * Check if the supported GLX version matches requiredVersion.
3122 static BOOL glxRequireVersion(int requiredVersion)
3124 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3125 if(requiredVersion <= WineGLInfo.glxVersion[1])
3126 return TRUE;
3128 return FALSE;
3131 static BOOL glxRequireExtension(const char *requiredExtension)
3133 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3134 return FALSE;
3137 return TRUE;
3140 static void register_extension_string(const char *ext)
3142 if (WineGLInfo.wglExtensions[0])
3143 strcat(WineGLInfo.wglExtensions, " ");
3144 strcat(WineGLInfo.wglExtensions, ext);
3146 TRACE("'%s'\n", ext);
3149 static BOOL register_extension(const WineGLExtension * ext)
3151 int i;
3153 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3154 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3156 register_extension_string(ext->extName);
3158 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3159 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3161 return TRUE;
3164 static const WineGLExtension WGL_internal_functions =
3168 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3169 { "wglFinish", X11DRV_wglFinish },
3170 { "wglFlush", X11DRV_wglFlush },
3175 static const WineGLExtension WGL_ARB_extensions_string =
3177 "WGL_ARB_extensions_string",
3179 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3183 static const WineGLExtension WGL_ARB_make_current_read =
3185 "WGL_ARB_make_current_read",
3187 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3188 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3192 static const WineGLExtension WGL_ARB_multisample =
3194 "WGL_ARB_multisample",
3197 static const WineGLExtension WGL_ARB_pbuffer =
3199 "WGL_ARB_pbuffer",
3201 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3202 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3203 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3204 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3205 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3206 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3210 static const WineGLExtension WGL_ARB_pixel_format =
3212 "WGL_ARB_pixel_format",
3214 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3215 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3216 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3220 static const WineGLExtension WGL_ARB_render_texture =
3222 "WGL_ARB_render_texture",
3224 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3225 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3229 static const WineGLExtension WGL_EXT_extensions_string =
3231 "WGL_EXT_extensions_string",
3233 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3237 static const WineGLExtension WGL_EXT_swap_control =
3239 "WGL_EXT_swap_control",
3241 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3242 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3246 static const WineGLExtension WGL_NV_vertex_array_range =
3248 "WGL_NV_vertex_array_range",
3250 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3251 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3256 * X11DRV_WineGL_LoadExtensions
3258 static void X11DRV_WineGL_LoadExtensions(void)
3260 WineGLInfo.wglExtensions[0] = 0;
3262 /* Load Wine internal functions */
3263 register_extension(&WGL_internal_functions);
3265 /* ARB Extensions */
3267 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3269 register_extension_string("WGL_ARB_pixel_format_float");
3270 register_extension_string("WGL_ATI_pixel_format_float");
3273 register_extension(&WGL_ARB_extensions_string);
3275 if (glxRequireVersion(3))
3276 register_extension(&WGL_ARB_make_current_read);
3278 if (glxRequireExtension("GLX_ARB_multisample"))
3279 register_extension(&WGL_ARB_multisample);
3281 /* In general pbuffer functionality requires support in the X-server. The functionality is
3282 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3283 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3284 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3286 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3287 * without support in the X-server (which other Mesa based drivers require).
3289 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3290 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3291 * is available pbuffers must be available too. */
3292 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3293 register_extension(&WGL_ARB_pbuffer);
3295 register_extension(&WGL_ARB_pixel_format);
3297 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3298 if (glxRequireExtension("GLX_ATI_render_texture") ||
3299 glxRequireExtension("GLX_ARB_render_texture") ||
3300 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3302 register_extension(&WGL_ARB_render_texture);
3304 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3305 if(glxRequireExtension("GLX_NV_float_buffer"))
3306 register_extension_string("WGL_NV_float_buffer");
3308 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3309 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3310 register_extension_string("WGL_NV_texture_rectangle");
3313 /* EXT Extensions */
3315 register_extension(&WGL_EXT_extensions_string);
3317 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3318 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3319 register_extension(&WGL_EXT_swap_control);
3321 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3322 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3323 register_extension(&WGL_NV_vertex_array_range);
3327 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3329 Drawable ret;
3331 if(physDev->bitmap)
3333 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3334 ret = physDev->drawable; /* PBuffer */
3335 else
3336 ret = physDev->bitmap->glxpixmap;
3338 else if(physDev->gl_drawable)
3339 ret = physDev->gl_drawable;
3340 else
3341 ret = physDev->drawable;
3342 return ret;
3345 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3347 wine_tsx11_lock();
3348 pglXDestroyGLXPixmap(display, glxpixmap);
3349 wine_tsx11_unlock();
3350 return TRUE;
3354 * X11DRV_SwapBuffers
3356 * Swap the buffers of this DC
3358 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3360 GLXDrawable drawable;
3361 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3363 if (!has_opengl()) {
3364 ERR("No libGL on this box - disabling OpenGL support !\n");
3365 return 0;
3368 TRACE_(opengl)("(%p)\n", physDev);
3370 drawable = get_glxdrawable(physDev);
3372 wine_tsx11_lock();
3373 sync_context(ctx);
3374 if(physDev->pixmap) {
3375 if(pglXCopySubBufferMESA) {
3376 int w = physDev->dc_rect.right - physDev->dc_rect.left;
3377 int h = physDev->dc_rect.bottom - physDev->dc_rect.top;
3379 /* (glX)SwapBuffers has an implicit glFlush effect, however
3380 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3381 * copying */
3382 pglFlush();
3383 if(w > 0 && h > 0)
3384 pglXCopySubBufferMESA(gdi_display, drawable, 0, 0, w, h);
3386 else
3387 pglXSwapBuffers(gdi_display, drawable);
3389 else
3390 pglXSwapBuffers(gdi_display, drawable);
3392 flush_gl_drawable(physDev);
3393 wine_tsx11_unlock();
3395 /* FPS support */
3396 if (TRACE_ON(fps))
3398 static long prev_time, frames;
3400 DWORD time = GetTickCount();
3401 frames++;
3402 /* every 1.5 seconds */
3403 if (time - prev_time > 1500) {
3404 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3405 prev_time = time;
3406 frames = 0;
3410 return TRUE;
3413 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3415 WineGLPixelFormat *fmt;
3417 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
3418 if(fmt == NULL)
3419 return NULL;
3420 return pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3423 #else /* no OpenGL includes */
3425 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3427 return 0;
3430 void mark_drawable_dirty(Drawable old, Drawable new)
3434 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
3438 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3440 return 0;
3443 /***********************************************************************
3444 * ChoosePixelFormat (X11DRV.@)
3446 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3447 const PIXELFORMATDESCRIPTOR *ppfd) {
3448 ERR("No OpenGL support compiled in.\n");
3450 return 0;
3453 /***********************************************************************
3454 * DescribePixelFormat (X11DRV.@)
3456 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3457 int iPixelFormat,
3458 UINT nBytes,
3459 PIXELFORMATDESCRIPTOR *ppfd) {
3460 ERR("No OpenGL support compiled in.\n");
3462 return 0;
3465 /***********************************************************************
3466 * GetPixelFormat (X11DRV.@)
3468 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3469 ERR("No OpenGL support compiled in.\n");
3471 return 0;
3474 /***********************************************************************
3475 * SetPixelFormat (X11DRV.@)
3477 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3478 int iPixelFormat,
3479 const PIXELFORMATDESCRIPTOR *ppfd) {
3480 ERR("No OpenGL support compiled in.\n");
3482 return FALSE;
3485 /***********************************************************************
3486 * SwapBuffers (X11DRV.@)
3488 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3489 ERR_(opengl)("No OpenGL support compiled in.\n");
3491 return FALSE;
3495 * X11DRV_wglCopyContext
3497 * For OpenGL32 wglCopyContext.
3499 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
3500 ERR_(opengl)("No OpenGL support compiled in.\n");
3501 return FALSE;
3505 * X11DRV_wglCreateContext
3507 * For OpenGL32 wglCreateContext.
3509 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3510 ERR_(opengl)("No OpenGL support compiled in.\n");
3511 return NULL;
3515 * X11DRV_wglDeleteContext
3517 * For OpenGL32 wglDeleteContext.
3519 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3520 ERR_(opengl)("No OpenGL support compiled in.\n");
3521 return FALSE;
3525 * X11DRV_wglGetProcAddress
3527 * For OpenGL32 wglGetProcAddress.
3529 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3530 ERR_(opengl)("No OpenGL support compiled in.\n");
3531 return NULL;
3534 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3536 ERR_(opengl)("No OpenGL support compiled in.\n");
3537 return NULL;
3540 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3541 ERR_(opengl)("No OpenGL support compiled in.\n");
3542 return FALSE;
3546 * X11DRV_wglMakeCurrent
3548 * For OpenGL32 wglMakeCurrent.
3550 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3551 ERR_(opengl)("No OpenGL support compiled in.\n");
3552 return FALSE;
3556 * X11DRV_wglShareLists
3558 * For OpenGL32 wglShaderLists.
3560 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3561 ERR_(opengl)("No OpenGL support compiled in.\n");
3562 return FALSE;
3566 * X11DRV_wglUseFontBitmapsA
3568 * For OpenGL32 wglUseFontBitmapsA.
3570 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3572 ERR_(opengl)("No OpenGL support compiled in.\n");
3573 return FALSE;
3577 * X11DRV_wglUseFontBitmapsW
3579 * For OpenGL32 wglUseFontBitmapsW.
3581 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3583 ERR_(opengl)("No OpenGL support compiled in.\n");
3584 return FALSE;
3587 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3589 return 0;
3592 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3594 return FALSE;
3597 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3599 return NULL;
3602 #endif /* defined(HAVE_OPENGL) */