push 014043c4937c940c54cd1214c96e33a3b3c8cf7d
[wine/hacks.git] / dlls / winex11.drv / opengl.c
blob0a3745d2fa1fd0d2fa7913c7d761fa33d44ea764
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_COLOR_BITS_ARB:
622 pop = iWGLAttr[++cur];
623 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
624 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
625 break;
626 case WGL_BLUE_BITS_ARB:
627 pop = iWGLAttr[++cur];
628 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
629 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
630 break;
631 case WGL_RED_BITS_ARB:
632 pop = iWGLAttr[++cur];
633 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
634 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
635 break;
636 case WGL_GREEN_BITS_ARB:
637 pop = iWGLAttr[++cur];
638 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
639 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
640 break;
641 case WGL_ALPHA_BITS_ARB:
642 pop = iWGLAttr[++cur];
643 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
644 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
645 break;
646 case WGL_DEPTH_BITS_ARB:
647 pop = iWGLAttr[++cur];
648 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
649 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
650 break;
651 case WGL_STENCIL_BITS_ARB:
652 pop = iWGLAttr[++cur];
653 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
654 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
655 break;
656 case WGL_DOUBLE_BUFFER_ARB:
657 pop = iWGLAttr[++cur];
658 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
659 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
660 doublebuf = pop;
661 break;
663 case WGL_PIXEL_TYPE_ARB:
664 pop = iWGLAttr[++cur];
665 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
666 switch (pop) {
667 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
668 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
669 /* 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 */
670 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
671 default:
672 ERR("unexpected PixelType(%x)\n", pop);
673 pop = 0;
675 break;
677 case WGL_SUPPORT_GDI_ARB:
678 pop = iWGLAttr[++cur];
679 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
680 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
681 supportgdi = pop;
682 break;
684 case WGL_DRAW_TO_BITMAP_ARB:
685 pop = iWGLAttr[++cur];
686 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
687 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
688 if (pop) {
689 drawattrib |= GLX_PIXMAP_BIT;
691 break;
693 case WGL_DRAW_TO_WINDOW_ARB:
694 pop = iWGLAttr[++cur];
695 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
696 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
697 if (pop) {
698 drawattrib |= GLX_WINDOW_BIT;
700 break;
702 case WGL_DRAW_TO_PBUFFER_ARB:
703 pop = iWGLAttr[++cur];
704 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
705 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
706 if (pop) {
707 drawattrib |= GLX_PBUFFER_BIT;
709 break;
711 case WGL_ACCELERATION_ARB:
712 case WGL_SUPPORT_OPENGL_ARB:
713 pop = iWGLAttr[++cur];
714 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
715 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
716 break;
718 case WGL_PBUFFER_LARGEST_ARB:
719 pop = iWGLAttr[++cur];
720 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
721 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
722 break;
724 case WGL_SAMPLE_BUFFERS_ARB:
725 pop = iWGLAttr[++cur];
726 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
727 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
728 break;
730 case WGL_SAMPLES_ARB:
731 pop = iWGLAttr[++cur];
732 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
733 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
734 break;
736 case WGL_TEXTURE_FORMAT_ARB:
737 case WGL_TEXTURE_TARGET_ARB:
738 case WGL_MIPMAP_TEXTURE_ARB:
739 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
740 pop = iWGLAttr[++cur];
741 if (NULL == pbuf) {
742 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
744 if (use_render_texture_ati) {
745 /** nothing to do here */
747 else if (!use_render_texture_emulation) {
748 if (WGL_NO_TEXTURE_ARB != pop) {
749 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
750 return -1; /** error: don't support it */
751 } else {
752 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
753 drawattrib |= GLX_PBUFFER_BIT;
756 break ;
757 case WGL_FLOAT_COMPONENTS_NV:
758 nvfloatattrib = iWGLAttr[++cur];
759 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
760 break ;
761 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
762 case WGL_BIND_TO_TEXTURE_RGB_ARB:
763 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
764 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
765 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
766 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
767 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
768 pop = iWGLAttr[++cur];
769 /** cannot be converted, see direct handling on
770 * - wglGetPixelFormatAttribivARB
771 * TODO: wglChoosePixelFormat
773 break ;
775 default:
776 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
777 break;
779 ++cur;
782 if(supportgdi > 0) {
783 if(doublebuf > 0) {
784 WARN("Attempting double-buffered gdi format\n");
785 return -1;
787 if(doublebuf < 0)
788 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, False);
791 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
792 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
793 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
794 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
796 /* Set GLX_RENDER_TYPE all the time */
797 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
798 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
800 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
801 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
802 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
803 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
806 return nAttribs;
809 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
811 int render_type=0, render_type_bit;
812 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
813 switch(render_type_bit)
815 case GLX_RGBA_BIT:
816 render_type = GLX_RGBA_TYPE;
817 break;
818 case GLX_COLOR_INDEX_BIT:
819 render_type = GLX_COLOR_INDEX_TYPE;
820 break;
821 case GLX_RGBA_FLOAT_BIT:
822 render_type = GLX_RGBA_FLOAT_TYPE;
823 break;
824 default:
825 ERR("Unknown render_type: %x\n", render_type);
827 return render_type;
830 static BOOL init_formats(Display *display, int screen, Visual *visual)
832 int fmt_id, nCfgs, i, run;
833 GLXFBConfig* cfgs;
834 XVisualInfo *visinfo;
836 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
837 if (NULL == cfgs || 0 == nCfgs) {
838 ERR("glXChooseFBConfig returns NULL\n");
839 if(cfgs != NULL) XFree(cfgs);
840 return FALSE;
843 WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineGLPixelFormat));
845 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
846 * Do this as GLX doesn't guarantee that the list is sorted */
847 for(run=0; run < 2; run++)
849 for(i=0; i<nCfgs; i++) {
850 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
851 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
853 /* The first run we only add onscreen formats (ones which have an associated X Visual).
854 * The second run we only set offscreen formats. */
855 if(!run && visinfo)
857 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
858 * The contents is copied to the destination using XCopyArea. For the copying to work
859 * the depth of the source and destination window should be the same. In general this should
860 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
861 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
862 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
863 * list formats with the same depth. */
864 if(visinfo->depth != screen_depth)
865 continue;
867 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, WineGLPixelFormatListSize+1, i);
868 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
869 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
870 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = fmt_id;
871 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
873 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = FALSE;
874 WineGLPixelFormatListSize++;
875 WineGLPixelFormatOnScreenSize++;
876 XFree(visinfo);
877 } else if(run && !visinfo) {
878 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, WineGLPixelFormatListSize+1, i);
879 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
880 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
881 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = fmt_id;
882 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
884 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
885 WineGLPixelFormatListSize++;
890 if(cfgs != NULL) XFree(cfgs);
892 return TRUE;
895 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
896 * In our WGL implementation we only support a subset of these formats namely the format of
897 * Wine's main visual and offscreen formats (if they are available).
898 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
899 * and it returns the number of supported WGL formats in fmt_count.
901 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
903 WineGLPixelFormat *res = NULL;
905 /* Init the list of pixel formats when we need it */
906 if(!WineGLPixelFormatListSize)
907 init_formats(display, DefaultScreen(display), visual);
909 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
910 * iPixelFormat in case of probing the number of pixelformats.
912 if((iPixelFormat > 0) && (iPixelFormat <= WineGLPixelFormatListSize) &&
913 ((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == FALSE) ||
914 AllowOffscreen)) {
915 res = &WineGLPixelFormatList[iPixelFormat-1];
916 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
919 if(AllowOffscreen)
920 *fmt_count = WineGLPixelFormatListSize;
921 else
922 *fmt_count = WineGLPixelFormatOnScreenSize;
924 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
926 return res;
929 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
930 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
932 int i;
934 /* Init the list of pixel formats when we need it */
935 if(!WineGLPixelFormatListSize)
936 init_formats(display, DefaultScreen(display), visual);
938 for(i=0; i<WineGLPixelFormatListSize; i++) {
939 if(WineGLPixelFormatList[i].fmt_id == fmt_id) {
940 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fmt_id);
941 return &WineGLPixelFormatList[i];
944 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
945 return NULL;
948 int pixelformat_from_fbconfig_id(XID fbconfig_id)
950 WineGLPixelFormat *fmt;
952 if (!fbconfig_id) return 0;
954 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
955 if(fmt)
956 return fmt->iPixelFormat;
957 /* This will happen on hwnds without a pixel format set; it's ok */
958 return 0;
962 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
963 void mark_drawable_dirty(Drawable old, Drawable new)
965 Wine_GLContext *ctx;
966 for (ctx = context_list; ctx; ctx = ctx->next) {
967 if (old == ctx->drawables[0]) {
968 ctx->drawables[0] = new;
969 ctx->refresh_drawables = TRUE;
971 if (old == ctx->drawables[1]) {
972 ctx->drawables[1] = new;
973 ctx->refresh_drawables = TRUE;
978 /* Given the current context, make sure its drawable is sync'd */
979 static inline void sync_context(Wine_GLContext *context)
981 if(context && context->refresh_drawables) {
982 if (glxRequireVersion(3))
983 pglXMakeContextCurrent(gdi_display, context->drawables[0],
984 context->drawables[1], context->ctx);
985 else
986 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
987 context->refresh_drawables = FALSE;
992 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
994 return pglXCreateGLXPixmap(display, vis, parent);
998 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev, WineGLPixelFormat *fmt)
1000 GLXPixmap ret = 0;
1001 XVisualInfo *vis;
1003 wine_tsx11_lock();
1005 vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1006 if(vis) {
1007 if(vis->depth == physDev->bitmap->pixmap_depth)
1008 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
1009 XFree(vis);
1011 wine_tsx11_unlock();
1012 TRACE("return %lx\n", ret);
1013 return ret;
1017 * X11DRV_ChoosePixelFormat
1019 * Equivalent to glXChooseVisual.
1021 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
1022 const PIXELFORMATDESCRIPTOR *ppfd) {
1023 WineGLPixelFormat *fmt = NULL;
1024 int ret = 0;
1025 int nPixelFormats;
1026 int value = 0;
1027 int i = 0;
1028 int bestFormat = -1;
1029 int bestDBuffer = -1;
1030 int bestStereo = -1;
1031 int bestColor = -1;
1032 int bestAlpha = -1;
1033 int bestDepth = -1;
1034 int bestStencil = -1;
1035 int bestAux = -1;
1036 int score;
1038 if (!has_opengl()) {
1039 ERR("No libGL on this box - disabling OpenGL support !\n");
1040 return 0;
1043 if (TRACE_ON(opengl)) {
1044 TRACE("(%p,%p)\n", physDev, ppfd);
1046 dump_PIXELFORMATDESCRIPTOR(ppfd);
1049 wine_tsx11_lock();
1050 ConvertPixelFormatWGLtoGLX(gdi_display, 0, FALSE /* offscreen */, &nPixelFormats);
1051 for(i=0; i<nPixelFormats; i++)
1053 int dwFlags = 0;
1054 int iPixelType = 0;
1055 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1057 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, i+1 /* 1-based index */, FALSE /* offscreen */, &value);
1058 score = 0;
1060 /* Pixel type */
1061 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1062 if (value & GLX_RGBA_BIT)
1063 iPixelType = PFD_TYPE_RGBA;
1064 else
1065 iPixelType = PFD_TYPE_COLORINDEX;
1067 if (ppfd->iPixelType != iPixelType)
1069 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1070 continue;
1073 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1074 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1075 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1076 if (value) dwFlags |= PFD_STEREO;
1077 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1078 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1079 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1080 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1081 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1083 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1084 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1085 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1086 * formats without the given flag set.
1087 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1088 * has indicated that a format without stereo is returned when stereo is unavailable.
1089 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1090 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1092 * To summarize the following is most likely the correct behavior:
1093 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1094 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1095 * stereo don't care -> it doesn't matter whether we get stereo or not
1097 * In Wine we will treat no-stereo the same way as don't care because it makes
1098 * format selection even more complicated and second drivers with Stereo advertise
1099 * each format twice anyway.
1102 /* Doublebuffer, see the comments above */
1103 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1104 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1105 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1107 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1108 bestStereo = dwFlags & PFD_STEREO;
1109 bestAlpha = alpha;
1110 bestColor = color;
1111 bestDepth = depth;
1112 bestStencil = stencil;
1113 bestAux = aux;
1114 bestFormat = i;
1115 continue;
1117 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1118 continue;
1121 /* Stereo, see the comments above. */
1122 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1123 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1124 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1126 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1127 bestStereo = dwFlags & PFD_STEREO;
1128 bestAlpha = alpha;
1129 bestColor = color;
1130 bestDepth = depth;
1131 bestStencil = stencil;
1132 bestAux = aux;
1133 bestFormat = i;
1134 continue;
1136 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1137 continue;
1140 /* Below we will do a number of checks to select the 'best' pixelformat.
1141 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1142 * The code works by trying to match the most important options as close as possible.
1143 * When a reasonable format is found, we will try to match more options. */
1145 /* Color bits */
1146 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1147 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1149 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1150 bestStereo = dwFlags & PFD_STEREO;
1151 bestAlpha = alpha;
1152 bestColor = color;
1153 bestDepth = depth;
1154 bestStencil = stencil;
1155 bestAux = aux;
1156 bestFormat = i;
1157 continue;
1158 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1159 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1160 continue;
1163 /* Alpha bits */
1164 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1165 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1167 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1168 bestStereo = dwFlags & PFD_STEREO;
1169 bestAlpha = alpha;
1170 bestColor = color;
1171 bestDepth = depth;
1172 bestStencil = stencil;
1173 bestAux = aux;
1174 bestFormat = i;
1175 continue;
1176 } else if(bestAlpha != alpha) {
1177 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1178 continue;
1181 /* Depth bits */
1182 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1183 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1185 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1186 bestStereo = dwFlags & PFD_STEREO;
1187 bestAlpha = alpha;
1188 bestColor = color;
1189 bestDepth = depth;
1190 bestStencil = stencil;
1191 bestAux = aux;
1192 bestFormat = i;
1193 continue;
1194 } else if(bestDepth != depth) {
1195 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1196 continue;
1199 /* Stencil bits */
1200 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1201 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1203 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1204 bestStereo = dwFlags & PFD_STEREO;
1205 bestAlpha = alpha;
1206 bestColor = color;
1207 bestDepth = depth;
1208 bestStencil = stencil;
1209 bestAux = aux;
1210 bestFormat = i;
1211 continue;
1212 } else if(bestStencil != stencil) {
1213 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1214 continue;
1217 /* Aux buffers */
1218 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1219 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1221 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1222 bestStereo = dwFlags & PFD_STEREO;
1223 bestAlpha = alpha;
1224 bestColor = color;
1225 bestDepth = depth;
1226 bestStencil = stencil;
1227 bestAux = aux;
1228 bestFormat = i;
1229 continue;
1230 } else if(bestAux != aux) {
1231 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1232 continue;
1236 if(bestFormat == -1) {
1237 TRACE("No matching mode was found returning 0\n");
1238 ret = 0;
1240 else {
1241 ret = bestFormat+1; /* the return value should be a 1-based index */
1242 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, WineGLPixelFormatList[bestFormat].fmt_id);
1245 wine_tsx11_unlock();
1247 return ret;
1250 * X11DRV_DescribePixelFormat
1252 * Get the pixel-format descriptor associated to the given id
1254 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1255 int iPixelFormat,
1256 UINT nBytes,
1257 PIXELFORMATDESCRIPTOR *ppfd) {
1258 /*XVisualInfo *vis;*/
1259 int value;
1260 int rb,gb,bb,ab;
1261 WineGLPixelFormat *fmt;
1262 int ret = 0;
1263 int fmt_count = 0;
1265 if (!has_opengl()) {
1266 ERR("No libGL on this box - disabling OpenGL support !\n");
1267 return 0;
1270 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1272 /* 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 */
1273 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1274 if (ppfd == NULL) {
1275 /* The application is only querying the number of pixelformats */
1276 return fmt_count;
1277 } else if(fmt == NULL) {
1278 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1279 return 0;
1282 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1283 ERR("Wrong structure size !\n");
1284 /* Should set error */
1285 return 0;
1288 ret = fmt_count;
1290 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1291 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1292 ppfd->nVersion = 1;
1294 /* These flags are always the same... */
1295 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1296 /* Now the flags extracted from the Visual */
1298 wine_tsx11_lock();
1300 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_X_RENDERABLE, &value);
1301 if(value)
1302 ppfd->dwFlags |= PFD_SUPPORT_GDI;
1304 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1305 if(value & GLX_WINDOW_BIT)
1306 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1307 if(value & GLX_PIXMAP_BIT)
1308 ppfd->dwFlags |= PFD_DRAW_TO_BITMAP;
1310 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1311 if(value == GLX_SLOW_CONFIG)
1312 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1314 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1315 if (value) {
1316 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1317 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1319 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1321 /* Pixel type */
1322 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1323 if (value & GLX_RGBA_BIT)
1324 ppfd->iPixelType = PFD_TYPE_RGBA;
1325 else
1326 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1328 /* Color bits */
1329 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1330 ppfd->cColorBits = value;
1332 /* Red, green, blue and alpha bits / shifts */
1333 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1334 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1335 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1336 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1337 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1339 ppfd->cRedBits = rb;
1340 ppfd->cRedShift = gb + bb + ab;
1341 ppfd->cBlueBits = bb;
1342 ppfd->cBlueShift = ab;
1343 ppfd->cGreenBits = gb;
1344 ppfd->cGreenShift = bb + ab;
1345 ppfd->cAlphaBits = ab;
1346 ppfd->cAlphaShift = 0;
1347 } else {
1348 ppfd->cRedBits = 0;
1349 ppfd->cRedShift = 0;
1350 ppfd->cBlueBits = 0;
1351 ppfd->cBlueShift = 0;
1352 ppfd->cGreenBits = 0;
1353 ppfd->cGreenShift = 0;
1354 ppfd->cAlphaBits = 0;
1355 ppfd->cAlphaShift = 0;
1358 /* Accum RGBA bits */
1359 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1360 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1361 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1362 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1364 ppfd->cAccumBits = rb+gb+bb+ab;
1365 ppfd->cAccumRedBits = rb;
1366 ppfd->cAccumGreenBits = gb;
1367 ppfd->cAccumBlueBits = bb;
1368 ppfd->cAccumAlphaBits = ab;
1370 /* Aux bits */
1371 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1372 ppfd->cAuxBuffers = value;
1374 /* Depth bits */
1375 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1376 ppfd->cDepthBits = value;
1378 /* stencil bits */
1379 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1380 ppfd->cStencilBits = value;
1382 wine_tsx11_unlock();
1384 ppfd->iLayerType = PFD_MAIN_PLANE;
1386 if (TRACE_ON(opengl)) {
1387 dump_PIXELFORMATDESCRIPTOR(ppfd);
1390 return ret;
1394 * X11DRV_GetPixelFormat
1396 * Get the pixel-format id used by this DC
1398 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1399 WineGLPixelFormat *fmt;
1400 int tmp;
1401 TRACE("(%p)\n", physDev);
1403 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1404 if(!fmt)
1406 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1407 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1408 return 0;
1410 else if(fmt->offscreenOnly)
1412 /* Offscreen formats can't be used with traditional WGL calls.
1413 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1414 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1415 return 1;
1418 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1419 return physDev->current_pf;
1423 * X11DRV_SetPixelFormat
1425 * Set the pixel-format id used by this DC
1427 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1428 int iPixelFormat,
1429 const PIXELFORMATDESCRIPTOR *ppfd) {
1430 WineGLPixelFormat *fmt;
1431 int value;
1432 HWND hwnd;
1434 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1436 if (!has_opengl()) {
1437 ERR("No libGL on this box - disabling OpenGL support !\n");
1438 return FALSE;
1441 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1442 if(get_glxdrawable(physDev) == root_window)
1444 ERR("Invalid operation on root_window\n");
1445 return FALSE;
1448 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1449 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1450 if(!fmt) {
1451 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1452 return FALSE;
1455 if(physDev->current_pf) /* cannot change it if already set */
1456 return (physDev->current_pf == iPixelFormat);
1458 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1460 hwnd = WindowFromDC(physDev->hdc);
1461 if(hwnd) {
1462 if(!(value&GLX_WINDOW_BIT)) {
1463 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1464 return FALSE;
1467 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, (WPARAM)fmt->fmt_id, 0)) {
1468 ERR("Couldn't set format of the window, returning failure\n");
1469 return FALSE;
1472 else if(physDev->bitmap) {
1473 if(!(value&GLX_PIXMAP_BIT)) {
1474 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1475 return FALSE;
1478 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev, fmt);
1479 if(!physDev->bitmap->glxpixmap) {
1480 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat);
1481 return FALSE;
1484 else {
1485 FIXME("called on a non-window, non-bitmap object?\n");
1488 physDev->current_pf = iPixelFormat;
1490 if (TRACE_ON(opengl)) {
1491 int gl_test = 0;
1493 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1494 if (gl_test) {
1495 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1496 } else {
1497 TRACE(" FBConfig have :\n");
1498 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1499 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1500 TRACE(" - VISUAL_ID 0x%x\n", value);
1501 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1502 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1505 return TRUE;
1509 * X11DRV_wglCopyContext
1511 * For OpenGL32 wglCopyContext.
1513 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
1514 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1515 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1517 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1519 /* There is a slight difference in the way GL contexts share display lists in WGL and GLX.
1520 * In case of GLX you need to specify this at context creation time but in case of WGL you
1521 * do this using wglShareLists which you can call after creating the context.
1522 * To emulate WGL we try to delay the creation of the context until wglShareLists or wglMakeCurrent.
1523 * Up to now that works fine.
1525 * The delayed GLX context creation could cause issues for wglCopyContext as it might get called
1526 * when there is no GLX context yet. The chance this will cause problems is small as at the time of
1527 * writing Wine has had OpenGL support for more than 7 years and this function has remained a stub
1528 * ever since then.
1530 if(!src->ctx || !dst->ctx) {
1531 /* NOTE: As a special case, if both GLX contexts are NULL, that means
1532 * neither WGL context was made current. In that case, both contexts
1533 * are in a default state, so any copy would no-op.
1535 if(!src->ctx && !dst->ctx) {
1536 TRACE("No source or destination contexts set. No-op.\n");
1537 return TRUE;
1540 if (!src->ctx) {
1541 DWORD type = GetObjectType(src->hdc);
1542 wine_tsx11_lock();
1543 if(src->vis)
1544 src->ctx = pglXCreateContext(gdi_display, src->vis, NULL, type == OBJ_MEMDC ? False : True);
1545 else /* Create a GLX Context for a pbuffer */
1546 src->ctx = pglXCreateNewContext(gdi_display, src->fmt->fbconfig, src->fmt->render_type, NULL, True);
1547 TRACE(" created a delayed OpenGL context (%p)\n", src->ctx);
1549 else if (!dst->ctx) {
1550 DWORD type = GetObjectType(dst->hdc);
1551 wine_tsx11_lock();
1552 if(dst->vis)
1553 dst->ctx = pglXCreateContext(gdi_display, dst->vis, NULL, type == OBJ_MEMDC ? False : True);
1554 else /* Create a GLX Context for a pbuffer */
1555 dst->ctx = pglXCreateNewContext(gdi_display, dst->fmt->fbconfig, dst->fmt->render_type, NULL, True);
1556 TRACE(" created a delayed OpenGL context (%p)\n", dst->ctx);
1559 else
1560 wine_tsx11_lock();
1562 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1563 wine_tsx11_unlock();
1565 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1566 return TRUE;
1570 * X11DRV_wglCreateContext
1572 * For OpenGL32 wglCreateContext.
1574 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1576 Wine_GLContext *ret;
1577 WineGLPixelFormat *fmt;
1578 int hdcPF = physDev->current_pf;
1579 int fmt_count = 0;
1580 HDC hdc = physDev->hdc;
1582 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1584 if (!has_opengl()) {
1585 ERR("No libGL on this box - disabling OpenGL support !\n");
1586 return 0;
1589 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1590 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1591 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1592 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1593 * If this fails something is very wrong on the system. */
1594 if(!fmt) {
1595 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1596 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1597 return NULL;
1600 /* The context will be allocated in the wglMakeCurrent call */
1601 wine_tsx11_lock();
1602 ret = alloc_context();
1603 wine_tsx11_unlock();
1604 ret->hdc = hdc;
1605 ret->fmt = fmt;
1607 /*ret->vis = vis;*/
1608 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1610 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1611 return (HGLRC) ret;
1615 * X11DRV_wglDeleteContext
1617 * For OpenGL32 wglDeleteContext.
1619 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1621 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1622 BOOL ret = TRUE;
1624 TRACE("(%p)\n", hglrc);
1626 if (!has_opengl()) {
1627 ERR("No libGL on this box - disabling OpenGL support !\n");
1628 return 0;
1631 wine_tsx11_lock();
1632 /* A game (Half Life not to name it) deletes twice the same context,
1633 * so make sure it is valid first */
1634 if (is_valid_context( ctx ))
1636 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1637 free_context(ctx);
1639 else
1641 WARN("Error deleting context !\n");
1642 SetLastError(ERROR_INVALID_HANDLE);
1643 ret = FALSE;
1645 wine_tsx11_unlock();
1647 return ret;
1651 * X11DRV_wglGetCurrentReadDCARB
1653 * For OpenGL32 wglGetCurrentReadDCARB.
1655 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1657 HDC ret = 0;
1658 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1660 if (ctx) ret = ctx->read_hdc;
1662 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1663 return ret;
1667 * X11DRV_wglGetProcAddress
1669 * For OpenGL32 wglGetProcAddress.
1671 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1673 int i, j;
1674 const WineGLExtension *ext;
1676 int padding = 32 - strlen(lpszProc);
1677 if (padding < 0)
1678 padding = 0;
1680 if (!has_opengl()) {
1681 ERR("No libGL on this box - disabling OpenGL support !\n");
1682 return 0;
1685 /* Check the table of WGL extensions to see if we need to return a WGL extension
1686 * or a function pointer to a native OpenGL function. */
1687 if(strncmp(lpszProc, "wgl", 3) != 0) {
1688 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1689 } else {
1690 TRACE("('%s'):%*s", lpszProc, padding, " ");
1691 for (i = 0; i < WineGLExtensionListSize; ++i) {
1692 ext = WineGLExtensionList[i];
1693 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1694 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1695 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1696 return ext->extEntryPoints[j].funcAddress;
1702 WARN("(%s) - not found\n", lpszProc);
1703 return NULL;
1707 * X11DRV_wglMakeCurrent
1709 * For OpenGL32 wglMakeCurrent.
1711 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1712 BOOL ret;
1713 HDC hdc = physDev->hdc;
1714 DWORD type = GetObjectType(hdc);
1716 TRACE("(%p,%p)\n", hdc, hglrc);
1718 if (!has_opengl()) {
1719 ERR("No libGL on this box - disabling OpenGL support !\n");
1720 return FALSE;
1723 wine_tsx11_lock();
1724 if (hglrc == NULL) {
1725 ret = pglXMakeCurrent(gdi_display, None, NULL);
1726 NtCurrentTeb()->glContext = NULL;
1727 } else {
1728 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1729 Drawable drawable = get_glxdrawable(physDev);
1730 if (ctx->ctx == NULL) {
1731 /* The describe lines below are for debugging purposes only */
1732 if (TRACE_ON(wgl)) {
1733 describeDrawable(ctx, drawable);
1734 describeContext(ctx);
1737 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1738 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1740 TRACE(" Creating GLX Context\n");
1741 if(ctx->vis)
1742 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1743 else /* Create a GLX Context for a pbuffer */
1744 ctx->ctx = pglXCreateNewContext(gdi_display, ctx->fmt->fbconfig, ctx->fmt->render_type, NULL, True);
1746 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1748 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1749 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1750 NtCurrentTeb()->glContext = ctx;
1751 if(ret)
1753 ctx->hdc = hdc;
1754 ctx->read_hdc = hdc;
1755 ctx->drawables[0] = drawable;
1756 ctx->drawables[1] = drawable;
1757 ctx->refresh_drawables = FALSE;
1759 if (type == OBJ_MEMDC)
1761 ctx->do_escape = TRUE;
1762 pglDrawBuffer(GL_FRONT_LEFT);
1766 wine_tsx11_unlock();
1767 TRACE(" returning %s\n", (ret ? "True" : "False"));
1768 return ret;
1772 * X11DRV_wglMakeContextCurrentARB
1774 * For OpenGL32 wglMakeContextCurrentARB
1776 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1778 BOOL ret;
1779 int indirect = (GetObjectType(pDrawDev->hdc) == OBJ_MEMDC);
1781 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1783 if (!has_opengl()) {
1784 ERR("No libGL on this box - disabling OpenGL support !\n");
1785 return 0;
1788 wine_tsx11_lock();
1789 if (hglrc == NULL) {
1790 ret = pglXMakeCurrent(gdi_display, None, NULL);
1791 NtCurrentTeb()->glContext = NULL;
1792 } else {
1793 if (NULL == pglXMakeContextCurrent) {
1794 ret = FALSE;
1795 } else {
1796 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1797 Drawable d_draw = get_glxdrawable(pDrawDev);
1798 Drawable d_read = get_glxdrawable(pReadDev);
1800 if (ctx->ctx == NULL) {
1801 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, !indirect);
1802 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1804 ctx->hdc = pDrawDev->hdc;
1805 ctx->read_hdc = pReadDev->hdc;
1806 ctx->drawables[0] = d_draw;
1807 ctx->drawables[1] = d_read;
1808 ctx->refresh_drawables = FALSE;
1809 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1810 NtCurrentTeb()->glContext = ctx;
1813 wine_tsx11_unlock();
1815 TRACE(" returning %s\n", (ret ? "True" : "False"));
1816 return ret;
1820 * X11DRV_wglShareLists
1822 * For OpenGL32 wglShaderLists.
1824 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1825 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1826 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1828 TRACE("(%p, %p)\n", org, dest);
1830 if (!has_opengl()) {
1831 ERR("No libGL on this box - disabling OpenGL support !\n");
1832 return 0;
1835 if (NULL != dest && dest->ctx != NULL) {
1836 ERR("Could not share display lists, context already created !\n");
1837 return FALSE;
1838 } else {
1839 if (org->ctx == NULL) {
1840 int indirect = (GetObjectType(org->hdc) == OBJ_MEMDC);
1841 wine_tsx11_lock();
1842 describeContext(org);
1844 if(org->vis)
1845 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, !indirect);
1846 else /* Create a GLX Context for a pbuffer */
1847 org->ctx = pglXCreateNewContext(gdi_display, org->fmt->fbconfig, org->fmt->render_type, NULL, True);
1848 wine_tsx11_unlock();
1849 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1851 if (NULL != dest) {
1852 int indirect = (GetObjectType(dest->hdc) == OBJ_MEMDC);
1853 wine_tsx11_lock();
1854 describeContext(dest);
1855 /* Create the destination context with display lists shared */
1856 if(dest->vis)
1857 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, !indirect);
1858 else /* Create a GLX Context for a pbuffer */
1859 dest->ctx = pglXCreateNewContext(gdi_display, dest->fmt->fbconfig, dest->fmt->render_type, org->ctx, True);
1860 wine_tsx11_unlock();
1861 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1862 return TRUE;
1865 return FALSE;
1868 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1870 /* We are running using client-side rendering fonts... */
1871 GLYPHMETRICS gm;
1872 unsigned int glyph;
1873 int size = 0;
1874 void *bitmap = NULL, *gl_bitmap = NULL;
1875 int org_alignment;
1877 wine_tsx11_lock();
1878 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1879 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1880 wine_tsx11_unlock();
1882 for (glyph = first; glyph < first + count; glyph++) {
1883 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1884 int height, width_int;
1886 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1887 if (needed_size == GDI_ERROR) {
1888 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1889 goto error;
1890 } else {
1891 TRACE(" - needed size : %d\n", needed_size);
1894 if (needed_size > size) {
1895 size = needed_size;
1896 HeapFree(GetProcessHeap(), 0, bitmap);
1897 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1898 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1899 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1901 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1902 if (TRACE_ON(opengl)) {
1903 unsigned int height, width, bitmask;
1904 unsigned char *bitmap_ = (unsigned char *) bitmap;
1906 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1907 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1908 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1909 if (needed_size != 0) {
1910 TRACE(" - bitmap :\n");
1911 for (height = 0; height < gm.gmBlackBoxY; height++) {
1912 TRACE(" ");
1913 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1914 if (bitmask == 0) {
1915 bitmap_ += 1;
1916 bitmask = 0x80;
1918 if (*bitmap_ & bitmask)
1919 TRACE("*");
1920 else
1921 TRACE(" ");
1923 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1924 TRACE("\n");
1929 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1930 * glyph for it to be drawn properly.
1932 if (needed_size != 0) {
1933 width_int = (gm.gmBlackBoxX + 31) / 32;
1934 for (height = 0; height < gm.gmBlackBoxY; height++) {
1935 int width;
1936 for (width = 0; width < width_int; width++) {
1937 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1938 ((int *) bitmap)[height * width_int + width];
1943 wine_tsx11_lock();
1944 pglNewList(listBase++, GL_COMPILE);
1945 if (needed_size != 0) {
1946 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1947 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
1948 gm.gmCellIncX, gm.gmCellIncY,
1949 gl_bitmap);
1950 } else {
1951 /* This is the case of 'empty' glyphs like the space character */
1952 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1954 pglEndList();
1955 wine_tsx11_unlock();
1958 wine_tsx11_lock();
1959 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1960 wine_tsx11_unlock();
1962 HeapFree(GetProcessHeap(), 0, bitmap);
1963 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1964 return TRUE;
1966 error:
1967 wine_tsx11_lock();
1968 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1969 wine_tsx11_unlock();
1971 HeapFree(GetProcessHeap(), 0, bitmap);
1972 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1973 return FALSE;
1977 * X11DRV_wglUseFontBitmapsA
1979 * For OpenGL32 wglUseFontBitmapsA.
1981 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1983 Font fid = physDev->font;
1985 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1987 if (!has_opengl()) {
1988 ERR("No libGL on this box - disabling OpenGL support !\n");
1989 return 0;
1992 if (fid == 0) {
1993 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1996 wine_tsx11_lock();
1997 /* I assume that the glyphs are at the same position for X and for Windows */
1998 pglXUseXFont(fid, first, count, listBase);
1999 wine_tsx11_unlock();
2000 return TRUE;
2004 * X11DRV_wglUseFontBitmapsW
2006 * For OpenGL32 wglUseFontBitmapsW.
2008 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2010 Font fid = physDev->font;
2012 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2014 if (!has_opengl()) {
2015 ERR("No libGL on this box - disabling OpenGL support !\n");
2016 return 0;
2019 if (fid == 0) {
2020 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
2023 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2025 wine_tsx11_lock();
2026 /* I assume that the glyphs are at the same position for X and for Windows */
2027 pglXUseXFont(fid, first, count, listBase);
2028 wine_tsx11_unlock();
2029 return TRUE;
2032 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2033 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2035 wine_tsx11_lock();
2036 switch(pname)
2038 case GL_DEPTH_BITS:
2040 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2042 pglGetIntegerv(pname, params);
2044 * if we cannot find a Wine Context
2045 * we only have the default wine desktop context,
2046 * so if we have only a 24 depth say we have 32
2048 if (!ctx && *params == 24) {
2049 *params = 32;
2051 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2052 break;
2054 case GL_ALPHA_BITS:
2056 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2058 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2059 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2060 break;
2062 default:
2063 pglGetIntegerv(pname, params);
2064 break;
2066 wine_tsx11_unlock();
2069 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
2071 int w, h;
2073 if(!physDev->gl_drawable)
2074 return;
2076 w = physDev->dc_rect.right - physDev->dc_rect.left;
2077 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
2079 if(w > 0 && h > 0) {
2080 Drawable src = physDev->pixmap;
2081 if(!src) src = physDev->gl_drawable;
2083 /* The GL drawable may be lagged behind if we don't flush first, so
2084 * flush the display make sure we copy up-to-date data */
2085 wine_tsx11_lock();
2086 XFlush(gdi_display);
2087 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
2088 physDev->dc_rect.left, physDev->dc_rect.top);
2089 wine_tsx11_unlock();
2094 static void WINAPI X11DRV_wglFinish(void)
2096 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2097 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2099 wine_tsx11_lock();
2100 sync_context(ctx);
2101 pglFinish();
2102 wine_tsx11_unlock();
2103 ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2106 static void WINAPI X11DRV_wglFlush(void)
2108 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2109 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2111 wine_tsx11_lock();
2112 sync_context(ctx);
2113 pglFlush();
2114 wine_tsx11_unlock();
2115 ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2119 * X11DRV_wglGetExtensionsStringARB
2121 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2123 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2124 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2125 return WineGLInfo.wglExtensions;
2129 * X11DRV_wglCreatePbufferARB
2131 * WGL_ARB_pbuffer: wglCreatePbufferARB
2133 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2135 Wine_GLPBuffer* object = NULL;
2136 WineGLPixelFormat *fmt = NULL;
2137 int nCfgs = 0;
2138 int attribs[256];
2139 int nAttribs = 0;
2141 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2143 if (0 >= iPixelFormat) {
2144 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2145 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2146 return NULL; /* unexpected error */
2149 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2150 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2151 if(!fmt) {
2152 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2153 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2154 goto create_failed; /* unexpected error */
2157 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2158 if (NULL == object) {
2159 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2160 goto create_failed; /* unexpected error */
2162 object->hdc = hdc;
2163 object->display = gdi_display;
2164 object->width = iWidth;
2165 object->height = iHeight;
2166 object->fmt = fmt;
2168 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2169 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2170 while (piAttribList && 0 != *piAttribList) {
2171 int attr_v;
2172 switch (*piAttribList) {
2173 case WGL_PBUFFER_LARGEST_ARB: {
2174 ++piAttribList;
2175 attr_v = *piAttribList;
2176 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2177 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2178 break;
2181 case WGL_TEXTURE_FORMAT_ARB: {
2182 ++piAttribList;
2183 attr_v = *piAttribList;
2184 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2185 if (use_render_texture_ati) {
2186 int type = 0;
2187 switch (attr_v) {
2188 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2189 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2190 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2191 default:
2192 SetLastError(ERROR_INVALID_DATA);
2193 goto create_failed;
2195 object->use_render_texture = 1;
2196 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2197 } else {
2198 if (WGL_NO_TEXTURE_ARB == attr_v) {
2199 object->use_render_texture = 0;
2200 } else {
2201 if (!use_render_texture_emulation) {
2202 SetLastError(ERROR_INVALID_DATA);
2203 goto create_failed;
2205 switch (attr_v) {
2206 case WGL_TEXTURE_RGB_ARB:
2207 object->use_render_texture = GL_RGB;
2208 object->texture_bpp = 3;
2209 object->texture_format = GL_RGB;
2210 object->texture_type = GL_UNSIGNED_BYTE;
2211 break;
2212 case WGL_TEXTURE_RGBA_ARB:
2213 object->use_render_texture = GL_RGBA;
2214 object->texture_bpp = 4;
2215 object->texture_format = GL_RGBA;
2216 object->texture_type = GL_UNSIGNED_BYTE;
2217 break;
2219 /* WGL_FLOAT_COMPONENTS_NV */
2220 case WGL_TEXTURE_FLOAT_R_NV:
2221 object->use_render_texture = GL_FLOAT_R_NV;
2222 object->texture_bpp = 4;
2223 object->texture_format = GL_RED;
2224 object->texture_type = GL_FLOAT;
2225 break;
2226 case WGL_TEXTURE_FLOAT_RG_NV:
2227 object->use_render_texture = GL_FLOAT_RG_NV;
2228 object->texture_bpp = 8;
2229 object->texture_format = GL_LUMINANCE_ALPHA;
2230 object->texture_type = GL_FLOAT;
2231 break;
2232 case WGL_TEXTURE_FLOAT_RGB_NV:
2233 object->use_render_texture = GL_FLOAT_RGB_NV;
2234 object->texture_bpp = 12;
2235 object->texture_format = GL_RGB;
2236 object->texture_type = GL_FLOAT;
2237 break;
2238 case WGL_TEXTURE_FLOAT_RGBA_NV:
2239 object->use_render_texture = GL_FLOAT_RGBA_NV;
2240 object->texture_bpp = 16;
2241 object->texture_format = GL_RGBA;
2242 object->texture_type = GL_FLOAT;
2243 break;
2244 default:
2245 ERR("Unknown texture format: %x\n", attr_v);
2246 SetLastError(ERROR_INVALID_DATA);
2247 goto create_failed;
2251 break;
2254 case WGL_TEXTURE_TARGET_ARB: {
2255 ++piAttribList;
2256 attr_v = *piAttribList;
2257 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2258 if (use_render_texture_ati) {
2259 int type = 0;
2260 switch (attr_v) {
2261 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2262 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2263 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2264 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2265 default:
2266 SetLastError(ERROR_INVALID_DATA);
2267 goto create_failed;
2269 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2270 } else {
2271 if (WGL_NO_TEXTURE_ARB == attr_v) {
2272 object->texture_target = 0;
2273 } else {
2274 if (!use_render_texture_emulation) {
2275 SetLastError(ERROR_INVALID_DATA);
2276 goto create_failed;
2278 switch (attr_v) {
2279 case WGL_TEXTURE_CUBE_MAP_ARB: {
2280 if (iWidth != iHeight) {
2281 SetLastError(ERROR_INVALID_DATA);
2282 goto create_failed;
2284 object->texture_target = GL_TEXTURE_CUBE_MAP;
2285 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2286 break;
2288 case WGL_TEXTURE_1D_ARB: {
2289 if (1 != iHeight) {
2290 SetLastError(ERROR_INVALID_DATA);
2291 goto create_failed;
2293 object->texture_target = GL_TEXTURE_1D;
2294 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2295 break;
2297 case WGL_TEXTURE_2D_ARB: {
2298 object->texture_target = GL_TEXTURE_2D;
2299 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2300 break;
2302 case WGL_TEXTURE_RECTANGLE_NV: {
2303 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2304 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2305 break;
2307 default:
2308 ERR("Unknown texture target: %x\n", attr_v);
2309 SetLastError(ERROR_INVALID_DATA);
2310 goto create_failed;
2314 break;
2317 case WGL_MIPMAP_TEXTURE_ARB: {
2318 ++piAttribList;
2319 attr_v = *piAttribList;
2320 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2321 if (use_render_texture_ati) {
2322 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2323 } else {
2324 if (!use_render_texture_emulation) {
2325 SetLastError(ERROR_INVALID_DATA);
2326 goto create_failed;
2329 break;
2332 ++piAttribList;
2335 PUSH1(attribs, None);
2336 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2337 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2338 if (!object->drawable) {
2339 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2340 goto create_failed; /* unexpected error */
2342 TRACE("->(%p)\n", object);
2343 return (HPBUFFERARB) object;
2345 create_failed:
2346 HeapFree(GetProcessHeap(), 0, object);
2347 TRACE("->(FAILED)\n");
2348 return NULL;
2352 * X11DRV_wglDestroyPbufferARB
2354 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2356 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2358 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2359 TRACE("(%p)\n", hPbuffer);
2360 if (NULL == object) {
2361 SetLastError(ERROR_INVALID_HANDLE);
2362 return GL_FALSE;
2364 pglXDestroyPbuffer(object->display, object->drawable);
2365 HeapFree(GetProcessHeap(), 0, object);
2366 return GL_TRUE;
2370 * X11DRV_wglGetPbufferDCARB
2372 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2373 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2374 * Gdi32 implements the part of this function which creates a device context.
2375 * This part associates the physDev with the X drawable of the pbuffer.
2377 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2379 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2380 if (NULL == object) {
2381 SetLastError(ERROR_INVALID_HANDLE);
2382 return NULL;
2385 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2386 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2387 physDev->current_pf = object->fmt->iPixelFormat;
2388 physDev->drawable = object->drawable;
2389 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2390 physDev->dc_rect = physDev->drawable_rect;
2392 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2393 return physDev->hdc;
2397 * X11DRV_wglQueryPbufferARB
2399 * WGL_ARB_pbuffer: wglQueryPbufferARB
2401 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2403 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2404 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2405 if (NULL == object) {
2406 SetLastError(ERROR_INVALID_HANDLE);
2407 return GL_FALSE;
2409 switch (iAttribute) {
2410 case WGL_PBUFFER_WIDTH_ARB:
2411 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2412 break;
2413 case WGL_PBUFFER_HEIGHT_ARB:
2414 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2415 break;
2417 case WGL_PBUFFER_LOST_ARB:
2418 /* GLX Pbuffers cannot be lost by default. We can support this by
2419 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2420 * to receive pixel buffer clobber events, however that may or may
2421 * not give any benefit */
2422 *piValue = GL_FALSE;
2423 break;
2425 case WGL_TEXTURE_FORMAT_ARB:
2426 if (use_render_texture_ati) {
2427 unsigned int tmp;
2428 int type = WGL_NO_TEXTURE_ARB;
2429 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2430 switch (tmp) {
2431 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2432 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2433 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2435 *piValue = type;
2436 } else {
2437 if (!object->use_render_texture) {
2438 *piValue = WGL_NO_TEXTURE_ARB;
2439 } else {
2440 if (!use_render_texture_emulation) {
2441 SetLastError(ERROR_INVALID_HANDLE);
2442 return GL_FALSE;
2444 switch(object->use_render_texture) {
2445 case GL_RGB:
2446 *piValue = WGL_TEXTURE_RGB_ARB;
2447 break;
2448 case GL_RGBA:
2449 *piValue = WGL_TEXTURE_RGBA_ARB;
2450 break;
2451 /* WGL_FLOAT_COMPONENTS_NV */
2452 case GL_FLOAT_R_NV:
2453 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2454 break;
2455 case GL_FLOAT_RG_NV:
2456 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2457 break;
2458 case GL_FLOAT_RGB_NV:
2459 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2460 break;
2461 case GL_FLOAT_RGBA_NV:
2462 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2463 break;
2464 default:
2465 ERR("Unknown texture format: %x\n", object->use_render_texture);
2469 break;
2471 case WGL_TEXTURE_TARGET_ARB:
2472 if (use_render_texture_ati) {
2473 unsigned int tmp;
2474 int type = WGL_NO_TEXTURE_ARB;
2475 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2476 switch (tmp) {
2477 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2478 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2479 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2480 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2482 *piValue = type;
2483 } else {
2484 if (!object->texture_target) {
2485 *piValue = WGL_NO_TEXTURE_ARB;
2486 } else {
2487 if (!use_render_texture_emulation) {
2488 SetLastError(ERROR_INVALID_DATA);
2489 return GL_FALSE;
2491 switch (object->texture_target) {
2492 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2493 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2494 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2495 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2499 break;
2501 case WGL_MIPMAP_TEXTURE_ARB:
2502 if (use_render_texture_ati) {
2503 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2504 } else {
2505 *piValue = GL_FALSE; /** don't support that */
2506 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2508 break;
2510 default:
2511 FIXME("unexpected attribute %x\n", iAttribute);
2512 break;
2515 return GL_TRUE;
2519 * X11DRV_wglReleasePbufferDCARB
2521 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2523 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2525 TRACE("(%p, %p)\n", hPbuffer, hdc);
2526 DeleteDC(hdc);
2527 return 0;
2531 * X11DRV_wglSetPbufferAttribARB
2533 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2535 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2537 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2538 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2539 if (NULL == object) {
2540 SetLastError(ERROR_INVALID_HANDLE);
2541 return GL_FALSE;
2543 if (!object->use_render_texture) {
2544 SetLastError(ERROR_INVALID_HANDLE);
2545 return GL_FALSE;
2547 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2548 return GL_TRUE;
2550 if (NULL != pglXDrawableAttribATI) {
2551 if (use_render_texture_ati) {
2552 FIXME("Need conversion for GLX_ATI_render_texture\n");
2554 return pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2556 return GL_FALSE;
2560 * X11DRV_wglChoosePixelFormatARB
2562 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2564 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2566 int gl_test = 0;
2567 int attribs[256];
2568 int nAttribs = 0;
2569 GLXFBConfig* cfgs = NULL;
2570 int nCfgs = 0;
2571 UINT it;
2572 int fmt_id;
2573 WineGLPixelFormat *fmt;
2574 int pfmt_it = 0;
2575 int run;
2577 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2578 if (NULL != pfAttribFList) {
2579 FIXME("unused pfAttribFList\n");
2582 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2583 if (-1 == nAttribs) {
2584 WARN("Cannot convert WGL to GLX attributes\n");
2585 return GL_FALSE;
2587 PUSH1(attribs, None);
2589 /* Search for FB configurations matching the requirements in attribs */
2590 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2591 if (NULL == cfgs) {
2592 WARN("Compatible Pixel Format not found\n");
2593 return GL_FALSE;
2596 /* Loop through all matching formats and check if they are suitable.
2597 * Note that this function should at max return nMaxFormats different formats */
2598 for(run=0; run < 2; run++)
2600 for (it = 0; it < nCfgs; ++it) {
2601 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2602 if (gl_test) {
2603 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2604 continue;
2607 /* Search for the format in our list of compatible formats */
2608 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2609 if(!fmt)
2610 continue;
2612 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2613 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2614 continue;
2616 if(pfmt_it < nMaxFormats) {
2617 piFormats[pfmt_it] = fmt->iPixelFormat;
2618 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2620 pfmt_it++;
2624 *nNumFormats = pfmt_it;
2625 /** free list */
2626 XFree(cfgs);
2627 return GL_TRUE;
2631 * X11DRV_wglGetPixelFormatAttribivARB
2633 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2635 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2637 UINT i;
2638 WineGLPixelFormat *fmt = NULL;
2639 int hTest;
2640 int tmp;
2641 int curGLXAttr = 0;
2642 int nWGLFormats = 0;
2644 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2646 if (0 < iLayerPlane) {
2647 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2648 return GL_FALSE;
2651 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2652 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2653 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2654 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2655 if(!fmt) {
2656 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2659 for (i = 0; i < nAttributes; ++i) {
2660 const int curWGLAttr = piAttributes[i];
2661 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2663 switch (curWGLAttr) {
2664 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2665 piValues[i] = nWGLFormats;
2666 continue;
2668 case WGL_SUPPORT_OPENGL_ARB:
2669 piValues[i] = GL_TRUE;
2670 continue;
2672 case WGL_ACCELERATION_ARB:
2673 curGLXAttr = GLX_CONFIG_CAVEAT;
2674 if (!fmt) goto pix_error;
2675 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2676 if (hTest) goto get_error;
2677 switch (tmp) {
2678 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2679 case GLX_SLOW_CONFIG: piValues[i] = WGL_GENERIC_ACCELERATION_ARB; break;
2680 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2681 default:
2682 ERR("unexpected Config Caveat(%x)\n", tmp);
2683 piValues[i] = WGL_NO_ACCELERATION_ARB;
2685 continue;
2687 case WGL_TRANSPARENT_ARB:
2688 curGLXAttr = GLX_TRANSPARENT_TYPE;
2689 if (!fmt) goto pix_error;
2690 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2691 if (hTest) goto get_error;
2692 piValues[i] = GL_FALSE;
2693 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2694 continue;
2696 case WGL_PIXEL_TYPE_ARB:
2697 curGLXAttr = GLX_RENDER_TYPE;
2698 if (!fmt) goto pix_error;
2699 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2700 if (hTest) goto get_error;
2701 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2702 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2703 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2704 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2705 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2706 else {
2707 ERR("unexpected RenderType(%x)\n", tmp);
2708 piValues[i] = WGL_TYPE_RGBA_ARB;
2710 continue;
2712 case WGL_COLOR_BITS_ARB:
2713 curGLXAttr = GLX_BUFFER_SIZE;
2714 break;
2716 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2717 if (use_render_texture_ati) {
2718 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2719 break;
2721 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2722 if (use_render_texture_ati) {
2723 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2724 break;
2726 if (!use_render_texture_emulation) {
2727 piValues[i] = GL_FALSE;
2728 continue;
2730 curGLXAttr = GLX_RENDER_TYPE;
2731 if (!fmt) goto pix_error;
2732 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2733 if (hTest) goto get_error;
2734 if (GLX_COLOR_INDEX_BIT == tmp) {
2735 piValues[i] = GL_FALSE;
2736 continue;
2738 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2739 if (hTest) goto get_error;
2740 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2741 continue;
2743 case WGL_BLUE_BITS_ARB:
2744 curGLXAttr = GLX_BLUE_SIZE;
2745 break;
2746 case WGL_RED_BITS_ARB:
2747 curGLXAttr = GLX_RED_SIZE;
2748 break;
2749 case WGL_GREEN_BITS_ARB:
2750 curGLXAttr = GLX_GREEN_SIZE;
2751 break;
2752 case WGL_ALPHA_BITS_ARB:
2753 curGLXAttr = GLX_ALPHA_SIZE;
2754 break;
2755 case WGL_DEPTH_BITS_ARB:
2756 curGLXAttr = GLX_DEPTH_SIZE;
2757 break;
2758 case WGL_STENCIL_BITS_ARB:
2759 curGLXAttr = GLX_STENCIL_SIZE;
2760 break;
2761 case WGL_DOUBLE_BUFFER_ARB:
2762 curGLXAttr = GLX_DOUBLEBUFFER;
2763 break;
2764 case WGL_STEREO_ARB:
2765 curGLXAttr = GLX_STEREO;
2766 break;
2767 case WGL_AUX_BUFFERS_ARB:
2768 curGLXAttr = GLX_AUX_BUFFERS;
2769 break;
2771 case WGL_SUPPORT_GDI_ARB:
2772 if (!fmt) goto pix_error;
2773 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &tmp);
2774 if (hTest) goto get_error;
2775 if(tmp) {
2776 piValues[i] = GL_FALSE;
2777 continue;
2779 curGLXAttr = GLX_X_RENDERABLE;
2780 break;
2782 case WGL_DRAW_TO_WINDOW_ARB:
2783 case WGL_DRAW_TO_BITMAP_ARB:
2784 case WGL_DRAW_TO_PBUFFER_ARB:
2785 if (!fmt) goto pix_error;
2786 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2787 if (hTest) goto get_error;
2788 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2789 (curWGLAttr == WGL_DRAW_TO_BITMAP_ARB && (tmp&GLX_PIXMAP_BIT)) ||
2790 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2791 piValues[i] = GL_TRUE;
2792 else
2793 piValues[i] = GL_FALSE;
2794 continue;
2796 case WGL_PBUFFER_LARGEST_ARB:
2797 curGLXAttr = GLX_LARGEST_PBUFFER;
2798 break;
2800 case WGL_SAMPLE_BUFFERS_ARB:
2801 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2802 break;
2804 case WGL_SAMPLES_ARB:
2805 curGLXAttr = GLX_SAMPLES_ARB;
2806 break;
2808 case WGL_FLOAT_COMPONENTS_NV:
2809 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2810 break;
2812 case WGL_ACCUM_RED_BITS_ARB:
2813 curGLXAttr = GLX_ACCUM_RED_SIZE;
2814 break;
2815 case WGL_ACCUM_GREEN_BITS_ARB:
2816 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2817 break;
2818 case WGL_ACCUM_BLUE_BITS_ARB:
2819 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2820 break;
2821 case WGL_ACCUM_ALPHA_BITS_ARB:
2822 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2823 break;
2824 case WGL_ACCUM_BITS_ARB:
2825 if (!fmt) goto pix_error;
2826 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2827 if (hTest) goto get_error;
2828 piValues[i] = tmp;
2829 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2830 if (hTest) goto get_error;
2831 piValues[i] += tmp;
2832 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2833 if (hTest) goto get_error;
2834 piValues[i] += tmp;
2835 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2836 if (hTest) goto get_error;
2837 piValues[i] += tmp;
2838 continue;
2840 default:
2841 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2844 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2845 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2846 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2848 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2849 * and check which options can work using iPixelFormat=0 and which not.
2850 * A problem would be that this function is an extension. This would
2851 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2853 if (0 != curGLXAttr && iPixelFormat != 0) {
2854 if (!fmt) goto pix_error;
2855 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2856 if (hTest) goto get_error;
2857 curGLXAttr = 0;
2858 } else {
2859 piValues[i] = GL_FALSE;
2862 return GL_TRUE;
2864 get_error:
2865 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2866 return GL_FALSE;
2868 pix_error:
2869 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2870 return GL_FALSE;
2874 * X11DRV_wglGetPixelFormatAttribfvARB
2876 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2878 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2880 int *attr;
2881 int ret;
2882 int i;
2884 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2886 /* Allocate a temporary array to store integer values */
2887 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2888 if (!attr) {
2889 ERR("couldn't allocate %d array\n", nAttributes);
2890 return GL_FALSE;
2893 /* Piggy-back on wglGetPixelFormatAttribivARB */
2894 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2895 if (ret) {
2896 /* Convert integer values to float. Should also check for attributes
2897 that can give decimal values here */
2898 for (i=0; i<nAttributes;i++) {
2899 pfValues[i] = attr[i];
2903 HeapFree(GetProcessHeap(), 0, attr);
2904 return ret;
2908 * X11DRV_wglBindTexImageARB
2910 * WGL_ARB_render_texture: wglBindTexImageARB
2912 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2914 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2915 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2916 if (NULL == object) {
2917 SetLastError(ERROR_INVALID_HANDLE);
2918 return GL_FALSE;
2920 if (!object->use_render_texture) {
2921 SetLastError(ERROR_INVALID_HANDLE);
2922 return GL_FALSE;
2925 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2926 static int init = 0;
2927 int prev_binded_texture = 0;
2928 GLXContext prev_context = pglXGetCurrentContext();
2929 Drawable prev_drawable = pglXGetCurrentDrawable();
2930 GLXContext tmp_context;
2932 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2933 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2934 isn't ideal performance wise but I wasn't able to get other ways working.
2936 if(!init) {
2937 init = 1; /* Only show the FIXME once for performance reasons */
2938 FIXME("partial stub!\n");
2941 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
2942 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2944 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2946 /* Switch to our pbuffer */
2947 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2949 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2950 * After that upload the pbuffer texture data. */
2951 pglBindTexture(object->texture_target, prev_binded_texture);
2952 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2954 /* Switch back to the original drawable and upload the pbuffer-texture */
2955 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2956 pglXDestroyContext(gdi_display, tmp_context);
2957 return GL_TRUE;
2960 if (NULL != pglXBindTexImageATI) {
2961 int buffer;
2963 switch(iBuffer)
2965 case WGL_FRONT_LEFT_ARB:
2966 buffer = GLX_FRONT_LEFT_ATI;
2967 break;
2968 case WGL_FRONT_RIGHT_ARB:
2969 buffer = GLX_FRONT_RIGHT_ATI;
2970 break;
2971 case WGL_BACK_LEFT_ARB:
2972 buffer = GLX_BACK_LEFT_ATI;
2973 break;
2974 case WGL_BACK_RIGHT_ARB:
2975 buffer = GLX_BACK_RIGHT_ATI;
2976 break;
2977 default:
2978 ERR("Unknown iBuffer=%#x\n", iBuffer);
2979 return FALSE;
2982 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
2983 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
2984 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
2985 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
2986 * works fine using our pbuffer emulation path.
2988 return pglXBindTexImageATI(object->display, object->drawable, buffer);
2990 return GL_FALSE;
2994 * X11DRV_wglReleaseTexImageARB
2996 * WGL_ARB_render_texture: wglReleaseTexImageARB
2998 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3000 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
3001 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3002 if (NULL == object) {
3003 SetLastError(ERROR_INVALID_HANDLE);
3004 return GL_FALSE;
3006 if (!object->use_render_texture) {
3007 SetLastError(ERROR_INVALID_HANDLE);
3008 return GL_FALSE;
3010 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3011 return GL_TRUE;
3013 if (NULL != pglXReleaseTexImageATI) {
3014 int buffer;
3016 switch(iBuffer)
3018 case WGL_FRONT_LEFT_ARB:
3019 buffer = GLX_FRONT_LEFT_ATI;
3020 break;
3021 case WGL_FRONT_RIGHT_ARB:
3022 buffer = GLX_FRONT_RIGHT_ATI;
3023 break;
3024 case WGL_BACK_LEFT_ARB:
3025 buffer = GLX_BACK_LEFT_ATI;
3026 break;
3027 case WGL_BACK_RIGHT_ARB:
3028 buffer = GLX_BACK_RIGHT_ATI;
3029 break;
3030 default:
3031 ERR("Unknown iBuffer=%#x\n", iBuffer);
3032 return FALSE;
3034 return pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3036 return GL_FALSE;
3040 * X11DRV_wglGetExtensionsStringEXT
3042 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3044 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3045 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3046 return WineGLInfo.wglExtensions;
3050 * X11DRV_wglGetSwapIntervalEXT
3052 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3054 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3055 FIXME("(),stub!\n");
3056 return swap_interval;
3060 * X11DRV_wglSwapIntervalEXT
3062 * WGL_EXT_swap_control: wglSwapIntervalEXT
3064 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3065 TRACE("(%d)\n", interval);
3066 swap_interval = interval;
3067 if (NULL != pglXSwapIntervalSGI) {
3068 return 0 == pglXSwapIntervalSGI(interval);
3070 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3071 return TRUE;
3075 * X11DRV_wglAllocateMemoryNV
3077 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3079 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3080 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3081 if (pglXAllocateMemoryNV == NULL)
3082 return NULL;
3084 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3088 * X11DRV_wglFreeMemoryNV
3090 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3092 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3093 TRACE("(%p)\n", pointer);
3094 if (pglXFreeMemoryNV == NULL)
3095 return;
3097 pglXFreeMemoryNV(pointer);
3101 * glxRequireVersion (internal)
3103 * Check if the supported GLX version matches requiredVersion.
3105 static BOOL glxRequireVersion(int requiredVersion)
3107 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3108 if(requiredVersion <= WineGLInfo.glxVersion[1])
3109 return TRUE;
3111 return FALSE;
3114 static BOOL glxRequireExtension(const char *requiredExtension)
3116 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3117 return FALSE;
3120 return TRUE;
3123 static void register_extension_string(const char *ext)
3125 if (WineGLInfo.wglExtensions[0])
3126 strcat(WineGLInfo.wglExtensions, " ");
3127 strcat(WineGLInfo.wglExtensions, ext);
3129 TRACE("'%s'\n", ext);
3132 static BOOL register_extension(const WineGLExtension * ext)
3134 int i;
3136 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3137 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3139 register_extension_string(ext->extName);
3141 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3142 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3144 return TRUE;
3147 static const WineGLExtension WGL_internal_functions =
3151 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3152 { "wglFinish", X11DRV_wglFinish },
3153 { "wglFlush", X11DRV_wglFlush },
3158 static const WineGLExtension WGL_ARB_extensions_string =
3160 "WGL_ARB_extensions_string",
3162 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3166 static const WineGLExtension WGL_ARB_make_current_read =
3168 "WGL_ARB_make_current_read",
3170 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3171 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3175 static const WineGLExtension WGL_ARB_multisample =
3177 "WGL_ARB_multisample",
3180 static const WineGLExtension WGL_ARB_pbuffer =
3182 "WGL_ARB_pbuffer",
3184 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3185 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3186 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3187 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3188 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3189 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3193 static const WineGLExtension WGL_ARB_pixel_format =
3195 "WGL_ARB_pixel_format",
3197 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3198 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3199 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3203 static const WineGLExtension WGL_ARB_render_texture =
3205 "WGL_ARB_render_texture",
3207 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3208 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3212 static const WineGLExtension WGL_EXT_extensions_string =
3214 "WGL_EXT_extensions_string",
3216 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3220 static const WineGLExtension WGL_EXT_swap_control =
3222 "WGL_EXT_swap_control",
3224 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3225 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3229 static const WineGLExtension WGL_NV_vertex_array_range =
3231 "WGL_NV_vertex_array_range",
3233 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3234 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3239 * X11DRV_WineGL_LoadExtensions
3241 static void X11DRV_WineGL_LoadExtensions(void)
3243 WineGLInfo.wglExtensions[0] = 0;
3245 /* Load Wine internal functions */
3246 register_extension(&WGL_internal_functions);
3248 /* ARB Extensions */
3250 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3252 register_extension_string("WGL_ARB_pixel_format_float");
3253 register_extension_string("WGL_ATI_pixel_format_float");
3256 register_extension(&WGL_ARB_extensions_string);
3258 if (glxRequireVersion(3))
3259 register_extension(&WGL_ARB_make_current_read);
3261 if (glxRequireExtension("GLX_ARB_multisample"))
3262 register_extension(&WGL_ARB_multisample);
3264 /* In general pbuffer functionality requires support in the X-server. The functionality is
3265 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3266 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3267 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3269 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3270 * without support in the X-server (which other Mesa based drivers require).
3272 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3273 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3274 * is available pbuffers must be available too. */
3275 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3276 register_extension(&WGL_ARB_pbuffer);
3278 register_extension(&WGL_ARB_pixel_format);
3280 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3281 if (glxRequireExtension("GLX_ATI_render_texture") ||
3282 glxRequireExtension("GLX_ARB_render_texture") ||
3283 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3285 register_extension(&WGL_ARB_render_texture);
3287 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3288 if(glxRequireExtension("GLX_NV_float_buffer"))
3289 register_extension_string("WGL_NV_float_buffer");
3291 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3292 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3293 register_extension_string("WGL_NV_texture_rectangle");
3296 /* EXT Extensions */
3298 register_extension(&WGL_EXT_extensions_string);
3300 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3301 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3302 register_extension(&WGL_EXT_swap_control);
3304 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3305 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3306 register_extension(&WGL_NV_vertex_array_range);
3310 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3312 Drawable ret;
3314 if(physDev->bitmap)
3316 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3317 ret = physDev->drawable; /* PBuffer */
3318 else
3319 ret = physDev->bitmap->glxpixmap;
3321 else if(physDev->gl_drawable)
3322 ret = physDev->gl_drawable;
3323 else
3324 ret = physDev->drawable;
3325 return ret;
3328 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3330 wine_tsx11_lock();
3331 pglXDestroyGLXPixmap(display, glxpixmap);
3332 wine_tsx11_unlock();
3333 return TRUE;
3337 * X11DRV_SwapBuffers
3339 * Swap the buffers of this DC
3341 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3343 GLXDrawable drawable;
3344 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3346 if (!has_opengl()) {
3347 ERR("No libGL on this box - disabling OpenGL support !\n");
3348 return 0;
3351 TRACE_(opengl)("(%p)\n", physDev);
3353 drawable = get_glxdrawable(physDev);
3355 wine_tsx11_lock();
3356 sync_context(ctx);
3357 if(physDev->pixmap) {
3358 if(pglXCopySubBufferMESA) {
3359 int w = physDev->dc_rect.right - physDev->dc_rect.left;
3360 int h = physDev->dc_rect.bottom - physDev->dc_rect.top;
3362 /* (glX)SwapBuffers has an implicit glFlush effect, however
3363 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3364 * copying */
3365 pglFlush();
3366 if(w > 0 && h > 0)
3367 pglXCopySubBufferMESA(gdi_display, drawable, 0, 0, w, h);
3369 else
3370 pglXSwapBuffers(gdi_display, drawable);
3372 else
3373 pglXSwapBuffers(gdi_display, drawable);
3375 flush_gl_drawable(physDev);
3376 wine_tsx11_unlock();
3378 /* FPS support */
3379 if (TRACE_ON(fps))
3381 static long prev_time, frames;
3383 DWORD time = GetTickCount();
3384 frames++;
3385 /* every 1.5 seconds */
3386 if (time - prev_time > 1500) {
3387 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3388 prev_time = time;
3389 frames = 0;
3393 return TRUE;
3396 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3398 WineGLPixelFormat *fmt;
3400 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
3401 if(fmt == NULL)
3402 return NULL;
3403 return pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3406 #else /* no OpenGL includes */
3408 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3410 return 0;
3413 void mark_drawable_dirty(Drawable old, Drawable new)
3417 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
3421 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3423 return 0;
3426 /***********************************************************************
3427 * ChoosePixelFormat (X11DRV.@)
3429 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3430 const PIXELFORMATDESCRIPTOR *ppfd) {
3431 ERR("No OpenGL support compiled in.\n");
3433 return 0;
3436 /***********************************************************************
3437 * DescribePixelFormat (X11DRV.@)
3439 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3440 int iPixelFormat,
3441 UINT nBytes,
3442 PIXELFORMATDESCRIPTOR *ppfd) {
3443 ERR("No OpenGL support compiled in.\n");
3445 return 0;
3448 /***********************************************************************
3449 * GetPixelFormat (X11DRV.@)
3451 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3452 ERR("No OpenGL support compiled in.\n");
3454 return 0;
3457 /***********************************************************************
3458 * SetPixelFormat (X11DRV.@)
3460 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3461 int iPixelFormat,
3462 const PIXELFORMATDESCRIPTOR *ppfd) {
3463 ERR("No OpenGL support compiled in.\n");
3465 return FALSE;
3468 /***********************************************************************
3469 * SwapBuffers (X11DRV.@)
3471 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3472 ERR_(opengl)("No OpenGL support compiled in.\n");
3474 return FALSE;
3478 * X11DRV_wglCopyContext
3480 * For OpenGL32 wglCopyContext.
3482 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
3483 ERR_(opengl)("No OpenGL support compiled in.\n");
3484 return FALSE;
3488 * X11DRV_wglCreateContext
3490 * For OpenGL32 wglCreateContext.
3492 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3493 ERR_(opengl)("No OpenGL support compiled in.\n");
3494 return NULL;
3498 * X11DRV_wglDeleteContext
3500 * For OpenGL32 wglDeleteContext.
3502 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3503 ERR_(opengl)("No OpenGL support compiled in.\n");
3504 return FALSE;
3508 * X11DRV_wglGetProcAddress
3510 * For OpenGL32 wglGetProcAddress.
3512 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3513 ERR_(opengl)("No OpenGL support compiled in.\n");
3514 return NULL;
3517 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3519 ERR_(opengl)("No OpenGL support compiled in.\n");
3520 return NULL;
3523 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3524 ERR_(opengl)("No OpenGL support compiled in.\n");
3525 return FALSE;
3529 * X11DRV_wglMakeCurrent
3531 * For OpenGL32 wglMakeCurrent.
3533 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3534 ERR_(opengl)("No OpenGL support compiled in.\n");
3535 return FALSE;
3539 * X11DRV_wglShareLists
3541 * For OpenGL32 wglShaderLists.
3543 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3544 ERR_(opengl)("No OpenGL support compiled in.\n");
3545 return FALSE;
3549 * X11DRV_wglUseFontBitmapsA
3551 * For OpenGL32 wglUseFontBitmapsA.
3553 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3555 ERR_(opengl)("No OpenGL support compiled in.\n");
3556 return FALSE;
3560 * X11DRV_wglUseFontBitmapsW
3562 * For OpenGL32 wglUseFontBitmapsW.
3564 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3566 ERR_(opengl)("No OpenGL support compiled in.\n");
3567 return FALSE;
3570 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3572 return 0;
3575 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3577 return FALSE;
3580 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3582 return NULL;
3585 #endif /* defined(HAVE_OPENGL) */