winex11: Use a GLXPixmap for offscreen OpenGL rendering when XComposite isn't available.
[wine/hacks.git] / dlls / winex11.drv / opengl.c
blob74ab94016c15b303f20e3c79258e5624e31db1a8
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 X11DRV_PDEVICE *physDev;
113 X11DRV_PDEVICE *pReadDev;
114 Drawable drawables[2];
115 BOOL refresh_drawables;
116 struct wine_glcontext *next;
117 struct wine_glcontext *prev;
118 } Wine_GLContext;
120 typedef struct wine_glpbuffer {
121 Drawable drawable;
122 Display* display;
123 WineGLPixelFormat* fmt;
124 int width;
125 int height;
126 int* attribList;
127 HDC hdc;
129 int use_render_texture; /* This is also the internal texture format */
130 int texture_bind_target;
131 int texture_bpp;
132 GLint texture_format;
133 GLuint texture_target;
134 GLenum texture_type;
135 GLuint texture;
136 int texture_level;
137 } Wine_GLPBuffer;
139 static Wine_GLContext *context_list;
140 static struct WineGLInfo WineGLInfo = { 0 };
141 static int use_render_texture_emulation = 1;
142 static int use_render_texture_ati = 0;
143 static int swap_interval = 1;
145 #define MAX_EXTENSIONS 16
146 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
147 static int WineGLExtensionListSize;
149 static WineGLPixelFormat *WineGLPixelFormatList;
150 static int WineGLPixelFormatListSize = 0;
151 static int WineGLPixelFormatOnScreenSize = 0;
153 static void X11DRV_WineGL_LoadExtensions(void);
154 static BOOL glxRequireVersion(int requiredVersion);
155 static BOOL glxRequireExtension(const char *requiredExtension);
157 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
158 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
159 TRACE(" - dwFlags : ");
160 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
174 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
175 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
176 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
177 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
178 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
179 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
180 #undef TEST_AND_DUMP
181 TRACE("\n");
183 TRACE(" - iPixelType : ");
184 switch (ppfd->iPixelType) {
185 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
186 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
188 TRACE("\n");
190 TRACE(" - Color : %d\n", ppfd->cColorBits);
191 TRACE(" - Red : %d\n", ppfd->cRedBits);
192 TRACE(" - Green : %d\n", ppfd->cGreenBits);
193 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
194 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
195 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
196 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
197 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
198 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
200 TRACE(" - iLayerType : ");
201 switch (ppfd->iLayerType) {
202 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
203 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
204 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
206 TRACE("\n");
209 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
210 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
212 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
213 /* GLX 1.0 */
214 MAKE_FUNCPTR(glXChooseVisual)
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 /* Standard OpenGL */
260 MAKE_FUNCPTR(glBindTexture)
261 MAKE_FUNCPTR(glBitmap)
262 MAKE_FUNCPTR(glCopyTexSubImage1D)
263 MAKE_FUNCPTR(glCopyTexImage2D)
264 MAKE_FUNCPTR(glCopyTexSubImage2D)
265 MAKE_FUNCPTR(glDrawBuffer)
266 MAKE_FUNCPTR(glEndList)
267 MAKE_FUNCPTR(glGetError)
268 MAKE_FUNCPTR(glGetIntegerv)
269 MAKE_FUNCPTR(glGetString)
270 MAKE_FUNCPTR(glNewList)
271 MAKE_FUNCPTR(glPixelStorei)
272 MAKE_FUNCPTR(glReadPixels)
273 MAKE_FUNCPTR(glTexImage2D)
274 MAKE_FUNCPTR(glFinish)
275 MAKE_FUNCPTR(glFlush)
276 #undef MAKE_FUNCPTR
278 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
280 static BOOL infoInitialized = FALSE;
282 int screen = DefaultScreen(gdi_display);
283 Window win = RootWindow(gdi_display, screen);
284 Visual *visual;
285 XVisualInfo template;
286 XVisualInfo *vis;
287 int num;
288 GLXContext ctx = NULL;
290 if (infoInitialized)
291 return TRUE;
292 infoInitialized = TRUE;
294 wine_tsx11_lock();
296 visual = DefaultVisual(gdi_display, screen);
297 template.visualid = XVisualIDFromVisual(visual);
298 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
299 if (vis) {
300 WORD old_fs = wine_get_fs();
301 /* Create a GLX Context. Without one we can't query GL information */
302 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
303 if (wine_get_fs() != old_fs)
305 wine_set_fs( old_fs );
306 wine_tsx11_unlock();
307 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
308 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
309 return FALSE;
313 if (ctx) {
314 pglXMakeCurrent(gdi_display, win, ctx);
315 } else {
316 ERR(" couldn't initialize OpenGL, expect problems\n");
317 wine_tsx11_unlock();
318 return FALSE;
321 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
322 WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
324 /* Get the common GLX version supported by GLX client and server ( major/minor) */
325 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
327 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
328 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
329 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
331 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
332 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
333 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
335 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
336 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
338 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
339 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER));
340 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
341 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
342 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
343 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
344 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
345 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
347 if(vis) XFree(vis);
348 if(ctx) {
349 pglXMakeCurrent(gdi_display, None, NULL);
350 pglXDestroyContext(gdi_display, ctx);
352 wine_tsx11_unlock();
353 return TRUE;
356 static BOOL has_opengl(void)
358 static int init_done;
359 static void *opengl_handle;
361 int error_base, event_base;
363 if (init_done) return (opengl_handle != NULL);
364 init_done = 1;
366 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
367 and include all dependencies */
368 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
369 if (opengl_handle == NULL) return FALSE;
371 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
372 if (pglXGetProcAddressARB == NULL) {
373 ERR("could not find glXGetProcAddressARB in libGL.\n");
374 return FALSE;
377 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
378 /* GLX 1.0 */
379 LOAD_FUNCPTR(glXChooseVisual)
380 LOAD_FUNCPTR(glXCreateContext)
381 LOAD_FUNCPTR(glXCreateGLXPixmap)
382 LOAD_FUNCPTR(glXGetCurrentContext)
383 LOAD_FUNCPTR(glXGetCurrentDrawable)
384 LOAD_FUNCPTR(glXDestroyContext)
385 LOAD_FUNCPTR(glXDestroyGLXPixmap)
386 LOAD_FUNCPTR(glXGetConfig)
387 LOAD_FUNCPTR(glXIsDirect)
388 LOAD_FUNCPTR(glXMakeCurrent)
389 LOAD_FUNCPTR(glXSwapBuffers)
390 LOAD_FUNCPTR(glXQueryExtension)
391 LOAD_FUNCPTR(glXQueryVersion)
392 LOAD_FUNCPTR(glXUseXFont)
394 /* GLX 1.1 */
395 LOAD_FUNCPTR(glXGetClientString)
396 LOAD_FUNCPTR(glXQueryExtensionsString)
397 LOAD_FUNCPTR(glXQueryServerString)
399 /* GLX 1.3 */
400 LOAD_FUNCPTR(glXCreatePbuffer)
401 LOAD_FUNCPTR(glXCreateNewContext)
402 LOAD_FUNCPTR(glXDestroyPbuffer)
403 LOAD_FUNCPTR(glXMakeContextCurrent)
404 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
405 LOAD_FUNCPTR(glXGetFBConfigs)
407 /* Standard OpenGL calls */
408 LOAD_FUNCPTR(glBindTexture)
409 LOAD_FUNCPTR(glBitmap)
410 LOAD_FUNCPTR(glCopyTexSubImage1D)
411 LOAD_FUNCPTR(glCopyTexImage2D)
412 LOAD_FUNCPTR(glCopyTexSubImage2D)
413 LOAD_FUNCPTR(glDrawBuffer)
414 LOAD_FUNCPTR(glEndList)
415 LOAD_FUNCPTR(glGetError)
416 LOAD_FUNCPTR(glGetIntegerv)
417 LOAD_FUNCPTR(glGetString)
418 LOAD_FUNCPTR(glNewList)
419 LOAD_FUNCPTR(glPixelStorei)
420 LOAD_FUNCPTR(glReadPixels)
421 LOAD_FUNCPTR(glTexImage2D)
422 LOAD_FUNCPTR(glFinish)
423 LOAD_FUNCPTR(glFlush)
424 #undef LOAD_FUNCPTR
426 /* It doesn't matter if these fail. They'll only be used if the driver reports
427 the associated extension is available (and if a driver reports the extension
428 is available but fails to provide the functions, it's quite broken) */
429 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
430 /* NV GLX Extension */
431 LOAD_FUNCPTR(glXAllocateMemoryNV)
432 LOAD_FUNCPTR(glXFreeMemoryNV)
433 #undef LOAD_FUNCPTR
435 if(!X11DRV_WineGL_InitOpenglInfo()) {
436 wine_dlclose(opengl_handle, NULL, 0);
437 opengl_handle = NULL;
438 return FALSE;
441 wine_tsx11_lock();
442 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
443 TRACE("GLX is up and running error_base = %d\n", error_base);
444 } else {
445 wine_dlclose(opengl_handle, NULL, 0);
446 opengl_handle = NULL;
449 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
450 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
451 * rendering is used.
453 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
454 * depends on the reported GLX client / server version and on the client / server extension list.
455 * Those don't have to be the same.
457 * In general the server GLX information lists the capabilities in case of indirect rendering.
458 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
459 * available and in that case the client GLX informat can be used.
460 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
461 * in the GLX version/extension list. When a program does this it works for certain for both
462 * direct and indirect rendering.
464 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
465 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
466 * extension list which causes this extension not to be listed. (Wine requires this extension).
467 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
468 * pbuffers is around.
470 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
471 * the ATI drivers and from then on use GLX client information for them.
474 if(glxRequireVersion(3)) {
475 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
476 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
477 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
478 pglXQueryDrawable = (void*)pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
479 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
480 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
481 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
482 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
484 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
485 * enable this function when the Xserver understand GLX 1.3 or newer
487 pglXQueryDrawable = NULL;
488 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
489 TRACE("Overriding ATI GLX capabilities!\n");
490 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
491 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
492 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
493 pglXQueryDrawable = (void*)pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
495 /* Use client GLX information in case of the ATI drivers. We override the
496 * capabilities over here and not somewhere else as ATI might better their
497 * life in the future. In case they release proper drivers this block of
498 * code won't be called. */
499 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
500 } else {
501 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
504 if(glxRequireExtension("GLX_ATI_render_texture")) {
505 use_render_texture_ati = 1;
506 pglXBindTexImageATI = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
507 pglXReleaseTexImageATI = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
508 pglXDrawableAttribATI = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
511 X11DRV_WineGL_LoadExtensions();
513 wine_tsx11_unlock();
514 return (opengl_handle != NULL);
516 sym_not_found:
517 wine_dlclose(opengl_handle, NULL, 0);
518 opengl_handle = NULL;
519 return FALSE;
522 static inline Wine_GLContext *alloc_context(void)
524 Wine_GLContext *ret;
526 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
528 ret->next = context_list;
529 if (context_list) context_list->prev = ret;
530 context_list = ret;
532 return ret;
535 static inline void free_context(Wine_GLContext *context)
537 if (context->next != NULL) context->next->prev = context->prev;
538 if (context->prev != NULL) context->prev->next = context->next;
539 else context_list = context->next;
541 if (context->vis) XFree(context->vis);
542 HeapFree(GetProcessHeap(), 0, context);
545 static inline BOOL is_valid_context( Wine_GLContext *ctx )
547 Wine_GLContext *ptr;
548 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
549 return (ptr != NULL);
552 static int describeContext(Wine_GLContext* ctx) {
553 int tmp;
554 int ctx_vis_id;
555 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
556 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
557 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
558 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
559 TRACE(" - VISUAL_ID 0x%x\n", tmp);
560 ctx_vis_id = tmp;
561 return ctx_vis_id;
564 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
565 int tmp;
566 int nElements;
567 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
568 GLXFBConfig *fbCfgs;
570 if (pglXQueryDrawable == NULL) {
571 /** glXQueryDrawable not available so returns not supported */
572 return -1;
575 TRACE(" Drawable %p have :\n", (void*) drawable);
576 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
577 TRACE(" - WIDTH as %d\n", tmp);
578 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
579 TRACE(" - HEIGHT as %d\n", tmp);
580 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
581 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
583 attribList[1] = tmp;
584 fbCfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribList, &nElements);
585 if (fbCfgs == NULL) {
586 return -1;
589 pglXGetFBConfigAttrib(gdi_display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
590 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
592 XFree(fbCfgs);
594 return tmp;
597 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
598 int nAttribs = 0;
599 unsigned cur = 0;
600 int pop;
601 int drawattrib = 0;
602 int nvfloatattrib = GLX_DONT_CARE;
603 int pixelattrib = 0;
605 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
606 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
607 while (iWGLAttr && 0 != iWGLAttr[cur]) {
608 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
610 switch (iWGLAttr[cur]) {
611 case WGL_COLOR_BITS_ARB:
612 pop = iWGLAttr[++cur];
613 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
614 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
615 break;
616 case WGL_BLUE_BITS_ARB:
617 pop = iWGLAttr[++cur];
618 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
619 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
620 break;
621 case WGL_RED_BITS_ARB:
622 pop = iWGLAttr[++cur];
623 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
624 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
625 break;
626 case WGL_GREEN_BITS_ARB:
627 pop = iWGLAttr[++cur];
628 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
629 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
630 break;
631 case WGL_ALPHA_BITS_ARB:
632 pop = iWGLAttr[++cur];
633 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
634 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
635 break;
636 case WGL_DEPTH_BITS_ARB:
637 pop = iWGLAttr[++cur];
638 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
639 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
640 break;
641 case WGL_STENCIL_BITS_ARB:
642 pop = iWGLAttr[++cur];
643 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
644 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
645 break;
646 case WGL_DOUBLE_BUFFER_ARB:
647 pop = iWGLAttr[++cur];
648 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
649 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
650 break;
652 case WGL_PIXEL_TYPE_ARB:
653 pop = iWGLAttr[++cur];
654 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
655 switch (pop) {
656 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
657 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
658 /* 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 */
659 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
660 default:
661 ERR("unexpected PixelType(%x)\n", pop);
662 pop = 0;
664 break;
666 case WGL_SUPPORT_GDI_ARB:
667 pop = iWGLAttr[++cur];
668 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
669 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
670 break;
672 case WGL_DRAW_TO_BITMAP_ARB:
673 pop = iWGLAttr[++cur];
674 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
675 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
676 if (pop) {
677 drawattrib |= GLX_PIXMAP_BIT;
679 break;
681 case WGL_DRAW_TO_WINDOW_ARB:
682 pop = iWGLAttr[++cur];
683 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
684 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
685 if (pop) {
686 drawattrib |= GLX_WINDOW_BIT;
688 break;
690 case WGL_DRAW_TO_PBUFFER_ARB:
691 pop = iWGLAttr[++cur];
692 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
693 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
694 if (pop) {
695 drawattrib |= GLX_PBUFFER_BIT;
697 break;
699 case WGL_ACCELERATION_ARB:
700 case WGL_SUPPORT_OPENGL_ARB:
701 pop = iWGLAttr[++cur];
702 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
703 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
704 break;
706 case WGL_PBUFFER_LARGEST_ARB:
707 pop = iWGLAttr[++cur];
708 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
709 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
710 break;
712 case WGL_SAMPLE_BUFFERS_ARB:
713 pop = iWGLAttr[++cur];
714 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
715 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
716 break;
718 case WGL_SAMPLES_ARB:
719 pop = iWGLAttr[++cur];
720 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
721 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
722 break;
724 case WGL_TEXTURE_FORMAT_ARB:
725 case WGL_TEXTURE_TARGET_ARB:
726 case WGL_MIPMAP_TEXTURE_ARB:
727 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
728 pop = iWGLAttr[++cur];
729 if (NULL == pbuf) {
730 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
732 if (use_render_texture_ati) {
733 /** nothing to do here */
735 else if (!use_render_texture_emulation) {
736 if (WGL_NO_TEXTURE_ARB != pop) {
737 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
738 return -1; /** error: don't support it */
739 } else {
740 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
741 drawattrib |= GLX_PBUFFER_BIT;
744 break ;
745 case WGL_FLOAT_COMPONENTS_NV:
746 nvfloatattrib = iWGLAttr[++cur];
747 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
748 break ;
749 case WGL_BIND_TO_TEXTURE_RGB_ARB:
750 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
751 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
752 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
753 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
754 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
755 pop = iWGLAttr[++cur];
756 /** cannot be converted, see direct handling on
757 * - wglGetPixelFormatAttribivARB
758 * TODO: wglChoosePixelFormat
760 break ;
762 default:
763 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
764 break;
766 ++cur;
769 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
770 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
771 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
772 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
774 /* Set GLX_RENDER_TYPE all the time */
775 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
776 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
778 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
779 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
780 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
781 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
784 return nAttribs;
787 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
789 int render_type=0, render_type_bit;
790 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
791 switch(render_type_bit)
793 case GLX_RGBA_BIT:
794 render_type = GLX_RGBA_TYPE;
795 break;
796 case GLX_COLOR_INDEX_BIT:
797 render_type = GLX_COLOR_INDEX_TYPE;
798 break;
799 case GLX_RGBA_FLOAT_BIT:
800 render_type = GLX_RGBA_FLOAT_TYPE;
801 break;
802 default:
803 ERR("Unknown render_type: %x\n", render_type);
805 return render_type;
808 static BOOL init_formats(Display *display, int screen, Visual *visual)
810 int fmt_id, tmp_fmt_id, nCfgs, i;
811 GLXFBConfig* cfgs;
812 GLXFBConfig fbconfig = NULL;
813 XVisualInfo *visinfo;
814 VisualID visualid = XVisualIDFromVisual(visual);
815 int nOffscreenFormats = 0;
817 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
818 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
819 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
820 * because this call lists both types of formats instead of only onscreen ones. */
821 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
822 if (NULL == cfgs || 0 == nCfgs) {
823 ERR("glXChooseFBConfig returns NULL\n");
824 if(cfgs != NULL) XFree(cfgs);
825 return FALSE;
828 /* Count the number of offscreen formats to determine the size for our pixelformat list */
829 for(i=0; i<nCfgs; i++) {
830 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
832 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
833 /* Onscreen formats have a corresponding XVisual, offscreen ones don't */
834 if(!visinfo) {
835 nOffscreenFormats++;
836 } else if(visinfo && visinfo->visualid == visualid) {
837 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
838 fbconfig = cfgs[i];
839 XFree(visinfo);
842 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats);
844 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
845 WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (1+nOffscreenFormats)*sizeof(WineGLPixelFormat));
846 WineGLPixelFormatList[0].iPixelFormat = 1;
847 WineGLPixelFormatList[0].fbconfig = fbconfig;
848 WineGLPixelFormatList[0].fmt_id = fmt_id;
849 WineGLPixelFormatList[0].render_type = get_render_type_from_fbconfig(display, fbconfig);
850 WineGLPixelFormatList[0].offscreenOnly = FALSE;
851 WineGLPixelFormatListSize = 1;
852 WineGLPixelFormatOnScreenSize = 1;
854 /* Fill the list with offscreen formats */
855 for(i=0; i<nCfgs; i++) {
856 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
858 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
859 /* We have found an offscreen rendering format when there is no visualinfo :) */
860 if(!visinfo) {
861 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id, WineGLPixelFormatListSize+1, i);
862 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
863 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
864 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = tmp_fmt_id;
865 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
866 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
867 WineGLPixelFormatListSize++;
868 } else {
869 XFree(visinfo);
873 if(cfgs != NULL) XFree(cfgs);
875 return TRUE;
878 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
879 * In our WGL implementation we only support a subset of these formats namely the format of
880 * Wine's main visual and offscreen formats (if they are available).
881 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
882 * and it returns the number of supported WGL formats in fmt_count.
884 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
886 WineGLPixelFormat *res = NULL;
888 /* Init the list of pixel formats when we need it */
889 if(!WineGLPixelFormatListSize)
890 init_formats(display, DefaultScreen(display), visual);
892 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
893 * iPixelFormat in case of probing the number of pixelformats.
895 if((iPixelFormat > 0) && (iPixelFormat <= WineGLPixelFormatListSize) &&
896 ((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == FALSE) ||
897 AllowOffscreen)) {
898 res = &WineGLPixelFormatList[iPixelFormat-1];
899 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
902 if(AllowOffscreen)
903 *fmt_count = WineGLPixelFormatListSize;
904 else
905 *fmt_count = WineGLPixelFormatOnScreenSize;
907 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
909 return res;
912 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
913 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
915 int i;
917 /* Init the list of pixel formats when we need it */
918 if(!WineGLPixelFormatListSize)
919 init_formats(display, DefaultScreen(display), visual);
921 for(i=0; i<WineGLPixelFormatListSize; i++) {
922 if(WineGLPixelFormatList[i].fmt_id == fmt_id) {
923 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fmt_id);
924 return &WineGLPixelFormatList[i];
927 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
928 return NULL;
931 int pixelformat_from_fbconfig_id(XID fbconfig_id)
933 WineGLPixelFormat *fmt;
935 if (!fbconfig_id) return 0;
937 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
938 if(fmt)
939 return fmt->iPixelFormat;
940 /* This will happen on hwnds without a pixel format set; it's ok */
941 return 0;
945 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
946 void mark_drawable_dirty(Drawable old, Drawable new)
948 Wine_GLContext *ctx;
949 for (ctx = context_list; ctx; ctx = ctx->next) {
950 if (old == ctx->drawables[0]) {
951 ctx->drawables[0] = new;
952 ctx->refresh_drawables = TRUE;
954 if (old == ctx->drawables[1]) {
955 ctx->drawables[1] = new;
956 ctx->refresh_drawables = TRUE;
961 /* Given the current context, make sure its drawable is sync'd */
962 static inline void sync_context(Wine_GLContext *context)
964 if(context && context->refresh_drawables) {
965 if (glxRequireVersion(3))
966 pglXMakeContextCurrent(gdi_display, context->drawables[0],
967 context->drawables[1], context->ctx);
968 else
969 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
970 context->refresh_drawables = FALSE;
975 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
977 return pglXCreateGLXPixmap(display, vis, parent);
982 * X11DRV_ChoosePixelFormat
984 * Equivalent to glXChooseVisual.
986 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
987 const PIXELFORMATDESCRIPTOR *ppfd) {
988 WineGLPixelFormat *fmt = NULL;
989 int ret = 0;
990 int nPixelFormats;
991 int value = 0;
992 int i = 0;
993 int bestFormat = -1;
994 int bestDBuffer = -1;
995 int bestStereo = -1;
996 int bestColor = -1;
997 int bestAlpha = -1;
998 int bestDepth = -1;
999 int bestStencil = -1;
1000 int bestAux = -1;
1001 int score;
1003 if (!has_opengl()) {
1004 ERR("No libGL on this box - disabling OpenGL support !\n");
1005 return 0;
1008 if (TRACE_ON(opengl)) {
1009 TRACE("(%p,%p)\n", physDev, ppfd);
1011 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
1014 wine_tsx11_lock();
1015 ConvertPixelFormatWGLtoGLX(gdi_display, 0, FALSE /* offscreen */, &nPixelFormats);
1016 for(i=0; i<nPixelFormats; i++)
1018 int dwFlags = 0;
1019 int iPixelType = 0;
1020 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1022 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, i+1 /* 1-based index */, FALSE /* offscreen */, &value);
1023 score = 0;
1025 /* Pixel type */
1026 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1027 if (value & GLX_RGBA_BIT)
1028 iPixelType = PFD_TYPE_RGBA;
1029 else
1030 iPixelType = PFD_TYPE_COLORINDEX;
1032 if (ppfd->iPixelType != iPixelType)
1034 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1035 continue;
1038 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1039 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1040 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1041 if (value) dwFlags |= PFD_STEREO;
1042 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1043 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1044 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1045 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1046 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1048 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1049 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1050 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1051 * formats without the given flag set.
1052 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1053 * has indicated that a format without stereo is returned when stereo is unavailable.
1054 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1055 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1057 * To summarize the following is most likely the correct behavior:
1058 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1059 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1060 * stereo don't care -> it doesn't matter whether we get stereo or not
1062 * In Wine we will treat no-stereo the same way as don't care because it makes
1063 * format selection even more complicated and second drivers with Stereo advertise
1064 * each format twice anyway.
1067 /* Doublebuffer, see the comments above */
1068 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1069 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1070 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1072 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1073 bestStereo = dwFlags & PFD_STEREO;
1074 bestAlpha = alpha;
1075 bestColor = color;
1076 bestDepth = depth;
1077 bestStencil = stencil;
1078 bestAux = aux;
1079 bestFormat = i;
1080 continue;
1082 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1083 continue;
1086 /* Stereo, see the comments above. */
1087 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1088 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1089 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1091 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1092 bestStereo = dwFlags & PFD_STEREO;
1093 bestAlpha = alpha;
1094 bestColor = color;
1095 bestDepth = depth;
1096 bestStencil = stencil;
1097 bestAux = aux;
1098 bestFormat = i;
1099 continue;
1101 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1102 continue;
1105 /* Below we will do a number of checks to select the 'best' pixelformat.
1106 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1107 * The code works by trying to match the most important options as close as possible.
1108 * When a reasonable format is found, we will try to match more options. */
1110 /* Color bits */
1111 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1112 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1114 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1115 bestStereo = dwFlags & PFD_STEREO;
1116 bestAlpha = alpha;
1117 bestColor = color;
1118 bestDepth = depth;
1119 bestStencil = stencil;
1120 bestAux = aux;
1121 bestFormat = i;
1122 continue;
1123 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1124 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1125 continue;
1128 /* Alpha bits */
1129 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1130 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1132 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1133 bestStereo = dwFlags & PFD_STEREO;
1134 bestAlpha = alpha;
1135 bestColor = color;
1136 bestDepth = depth;
1137 bestStencil = stencil;
1138 bestAux = aux;
1139 bestFormat = i;
1140 continue;
1141 } else if(bestAlpha != alpha) {
1142 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1143 continue;
1146 /* Depth bits */
1147 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1148 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1150 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1151 bestStereo = dwFlags & PFD_STEREO;
1152 bestAlpha = alpha;
1153 bestColor = color;
1154 bestDepth = depth;
1155 bestStencil = stencil;
1156 bestAux = aux;
1157 bestFormat = i;
1158 continue;
1159 } else if(bestDepth != depth) {
1160 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1161 continue;
1164 /* Stencil bits */
1165 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1166 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1168 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1169 bestStereo = dwFlags & PFD_STEREO;
1170 bestAlpha = alpha;
1171 bestColor = color;
1172 bestDepth = depth;
1173 bestStencil = stencil;
1174 bestAux = aux;
1175 bestFormat = i;
1176 continue;
1177 } else if(bestStencil != stencil) {
1178 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1179 continue;
1182 /* Aux buffers */
1183 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1184 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1186 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1187 bestStereo = dwFlags & PFD_STEREO;
1188 bestAlpha = alpha;
1189 bestColor = color;
1190 bestDepth = depth;
1191 bestStencil = stencil;
1192 bestAux = aux;
1193 bestFormat = i;
1194 continue;
1195 } else if(bestAux != aux) {
1196 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1197 continue;
1201 if(bestFormat == -1) {
1202 TRACE("No matching mode was found returning 0\n");
1203 ret = 0;
1205 else {
1206 ret = bestFormat+1; /* the return value should be a 1-based index */
1207 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, WineGLPixelFormatList[bestFormat].fmt_id);
1210 wine_tsx11_unlock();
1212 return ret;
1215 * X11DRV_DescribePixelFormat
1217 * Get the pixel-format descriptor associated to the given id
1219 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1220 int iPixelFormat,
1221 UINT nBytes,
1222 PIXELFORMATDESCRIPTOR *ppfd) {
1223 /*XVisualInfo *vis;*/
1224 int value;
1225 int rb,gb,bb,ab;
1226 WineGLPixelFormat *fmt;
1227 int ret = 0;
1228 int fmt_count = 0;
1230 if (!has_opengl()) {
1231 ERR("No libGL on this box - disabling OpenGL support !\n");
1232 return 0;
1235 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1237 /* 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 */
1238 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1239 if (ppfd == NULL) {
1240 /* The application is only querying the number of pixelformats */
1241 return fmt_count;
1242 } else if(fmt == NULL) {
1243 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1244 return 0;
1247 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1248 ERR("Wrong structure size !\n");
1249 /* Should set error */
1250 return 0;
1253 ret = fmt_count;
1255 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1256 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1257 ppfd->nVersion = 1;
1259 /* These flags are always the same... */
1260 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1261 /* Now the flags extracted from the Visual */
1263 wine_tsx11_lock();
1265 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_X_RENDERABLE, &value);
1266 if(value)
1267 ppfd->dwFlags |= PFD_SUPPORT_GDI;
1269 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1270 if(value & GLX_WINDOW_BIT)
1271 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1272 if(value & GLX_PIXMAP_BIT)
1273 ppfd->dwFlags |= PFD_DRAW_TO_BITMAP;
1275 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1276 if(value == GLX_SLOW_CONFIG)
1277 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1279 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1280 if (value) {
1281 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1282 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1284 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1286 /* Pixel type */
1287 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1288 if (value & GLX_RGBA_BIT)
1289 ppfd->iPixelType = PFD_TYPE_RGBA;
1290 else
1291 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1293 /* Color bits */
1294 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1295 ppfd->cColorBits = value;
1297 /* Red, green, blue and alpha bits / shifts */
1298 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1299 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1300 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1301 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1302 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1304 ppfd->cRedBits = rb;
1305 ppfd->cRedShift = gb + bb + ab;
1306 ppfd->cBlueBits = bb;
1307 ppfd->cBlueShift = ab;
1308 ppfd->cGreenBits = gb;
1309 ppfd->cGreenShift = bb + ab;
1310 ppfd->cAlphaBits = ab;
1311 ppfd->cAlphaShift = 0;
1312 } else {
1313 ppfd->cRedBits = 0;
1314 ppfd->cRedShift = 0;
1315 ppfd->cBlueBits = 0;
1316 ppfd->cBlueShift = 0;
1317 ppfd->cGreenBits = 0;
1318 ppfd->cGreenShift = 0;
1319 ppfd->cAlphaBits = 0;
1320 ppfd->cAlphaShift = 0;
1323 /* Accum RGBA bits */
1324 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1325 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1326 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1327 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1329 ppfd->cAccumBits = rb+gb+bb+ab;
1330 ppfd->cAccumRedBits = rb;
1331 ppfd->cAccumGreenBits = gb;
1332 ppfd->cAccumBlueBits = bb;
1333 ppfd->cAccumAlphaBits = ab;
1335 /* Depth bits */
1336 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1337 ppfd->cDepthBits = value;
1339 /* stencil bits */
1340 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1341 ppfd->cStencilBits = value;
1343 wine_tsx11_unlock();
1345 /* Aux : to do ... */
1347 ppfd->iLayerType = PFD_MAIN_PLANE;
1349 if (TRACE_ON(opengl)) {
1350 dump_PIXELFORMATDESCRIPTOR(ppfd);
1353 return ret;
1357 * X11DRV_GetPixelFormat
1359 * Get the pixel-format id used by this DC
1361 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1362 WineGLPixelFormat *fmt;
1363 int tmp;
1364 TRACE("(%p)\n", physDev);
1366 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1367 if(!fmt)
1369 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1370 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1371 return 0;
1373 else if(fmt->offscreenOnly)
1375 /* Offscreen formats can't be used with traditional WGL calls.
1376 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1377 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1378 return 1;
1381 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1382 return physDev->current_pf;
1386 * X11DRV_SetPixelFormat
1388 * Set the pixel-format id used by this DC
1390 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1391 int iPixelFormat,
1392 const PIXELFORMATDESCRIPTOR *ppfd) {
1393 WineGLPixelFormat *fmt;
1394 int value;
1395 HWND hwnd;
1397 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1399 if (!has_opengl()) {
1400 ERR("No libGL on this box - disabling OpenGL support !\n");
1401 return FALSE;
1404 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1405 if(get_glxdrawable(physDev) == root_window)
1407 ERR("Invalid operation on root_window\n");
1408 return FALSE;
1411 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1412 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1413 if(!fmt) {
1414 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1415 return FALSE;
1418 if(physDev->current_pf) /* cannot change it if already set */
1419 return (physDev->current_pf == iPixelFormat);
1421 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1423 hwnd = WindowFromDC(physDev->hdc);
1424 if(hwnd) {
1425 if(!(value&GLX_WINDOW_BIT)) {
1426 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1427 return FALSE;
1430 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, (WPARAM)fmt->fmt_id, 0)) {
1431 ERR("Couldn't set format of the window, returning failure\n");
1432 return FALSE;
1435 physDev->gl_drawable = X11DRV_get_gl_drawable(hwnd);
1438 physDev->current_pf = iPixelFormat;
1440 if (TRACE_ON(opengl)) {
1441 int gl_test = 0;
1443 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1444 if (gl_test) {
1445 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1446 } else {
1447 TRACE(" FBConfig have :\n");
1448 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1449 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1450 TRACE(" - VISUAL_ID 0x%x\n", value);
1451 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1452 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1455 return TRUE;
1459 * X11DRV_wglCreateContext
1461 * For OpenGL32 wglCreateContext.
1463 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1465 Wine_GLContext *ret;
1466 WineGLPixelFormat *fmt;
1467 int hdcPF = physDev->current_pf;
1468 int fmt_count = 0;
1469 HDC hdc = physDev->hdc;
1471 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1473 if (!has_opengl()) {
1474 ERR("No libGL on this box - disabling OpenGL support !\n");
1475 return 0;
1478 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1479 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1480 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1481 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1482 * If this fails something is very wrong on the system. */
1483 if(!fmt) {
1484 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1485 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1486 return NULL;
1489 /* The context will be allocated in the wglMakeCurrent call */
1490 wine_tsx11_lock();
1491 ret = alloc_context();
1492 wine_tsx11_unlock();
1493 ret->hdc = hdc;
1494 ret->physDev = physDev;
1495 ret->fmt = fmt;
1497 /*ret->vis = vis;*/
1498 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1500 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1501 return (HGLRC) ret;
1505 * X11DRV_wglDeleteContext
1507 * For OpenGL32 wglDeleteContext.
1509 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1511 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1512 BOOL ret = TRUE;
1514 TRACE("(%p)\n", hglrc);
1516 if (!has_opengl()) {
1517 ERR("No libGL on this box - disabling OpenGL support !\n");
1518 return 0;
1521 wine_tsx11_lock();
1522 /* A game (Half Life not to name it) deletes twice the same context,
1523 * so make sure it is valid first */
1524 if (is_valid_context( ctx ))
1526 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1527 free_context(ctx);
1529 else
1531 WARN("Error deleting context !\n");
1532 SetLastError(ERROR_INVALID_HANDLE);
1533 ret = FALSE;
1535 wine_tsx11_unlock();
1537 return ret;
1541 * X11DRV_wglGetCurrentReadDCARB
1543 * For OpenGL32 wglGetCurrentReadDCARB.
1545 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1547 HDC ret = 0;
1548 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1549 X11DRV_PDEVICE *physDev = ctx ? ctx->pReadDev : NULL;
1551 if(physDev)
1552 ret = physDev->hdc;
1554 TRACE(" returning %p (GL drawable %lu)\n", ret, physDev ? physDev->drawable : 0);
1555 return ret;
1559 * X11DRV_wglGetProcAddress
1561 * For OpenGL32 wglGetProcAddress.
1563 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1565 int i, j;
1566 const WineGLExtension *ext;
1568 int padding = 32 - strlen(lpszProc);
1569 if (padding < 0)
1570 padding = 0;
1572 if (!has_opengl()) {
1573 ERR("No libGL on this box - disabling OpenGL support !\n");
1574 return 0;
1577 /* Check the table of WGL extensions to see if we need to return a WGL extension
1578 * or a function pointer to a native OpenGL function. */
1579 if(strncmp(lpszProc, "wgl", 3) != 0) {
1580 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1581 } else {
1582 TRACE("('%s'):%*s", lpszProc, padding, " ");
1583 for (i = 0; i < WineGLExtensionListSize; ++i) {
1584 ext = WineGLExtensionList[i];
1585 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1586 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1587 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1588 return ext->extEntryPoints[j].funcAddress;
1594 WARN("(%s) - not found\n", lpszProc);
1595 return NULL;
1599 * X11DRV_wglMakeCurrent
1601 * For OpenGL32 wglMakeCurrent.
1603 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1604 BOOL ret;
1605 HDC hdc = physDev->hdc;
1606 DWORD type = GetObjectType(hdc);
1608 TRACE("(%p,%p)\n", hdc, hglrc);
1610 if (!has_opengl()) {
1611 ERR("No libGL on this box - disabling OpenGL support !\n");
1612 return 0;
1615 wine_tsx11_lock();
1616 if (hglrc == NULL) {
1617 ret = pglXMakeCurrent(gdi_display, None, NULL);
1618 NtCurrentTeb()->glContext = NULL;
1619 } else {
1620 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1621 Drawable drawable = get_glxdrawable(physDev);
1622 if (ctx->ctx == NULL) {
1623 /* The describe lines below are for debugging purposes only */
1624 if (TRACE_ON(wgl)) {
1625 describeDrawable(ctx, drawable);
1626 describeContext(ctx);
1629 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1630 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1632 TRACE(" Creating GLX Context\n");
1633 if(ctx->vis)
1634 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1635 else /* Create a GLX Context for a pbuffer */
1636 ctx->ctx = pglXCreateNewContext(gdi_display, ctx->fmt->fbconfig, ctx->fmt->render_type, NULL, True);
1638 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1640 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1641 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1642 NtCurrentTeb()->glContext = ctx;
1643 if(ret)
1645 ctx->hdc = hdc;
1646 ctx->physDev = physDev;
1647 ctx->pReadDev = physDev;
1648 ctx->drawables[0] = drawable;
1649 ctx->drawables[1] = drawable;
1650 ctx->refresh_drawables = FALSE;
1652 if (type == OBJ_MEMDC)
1654 ctx->do_escape = TRUE;
1655 pglDrawBuffer(GL_FRONT_LEFT);
1659 wine_tsx11_unlock();
1660 TRACE(" returning %s\n", (ret ? "True" : "False"));
1661 return ret;
1665 * X11DRV_wglMakeContextCurrentARB
1667 * For OpenGL32 wglMakeContextCurrentARB
1669 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1671 BOOL ret;
1672 int indirect = (GetObjectType(pDrawDev->hdc) == OBJ_MEMDC);
1674 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1676 if (!has_opengl()) {
1677 ERR("No libGL on this box - disabling OpenGL support !\n");
1678 return 0;
1681 wine_tsx11_lock();
1682 if (hglrc == NULL) {
1683 ret = pglXMakeCurrent(gdi_display, None, NULL);
1684 NtCurrentTeb()->glContext = NULL;
1685 } else {
1686 if (NULL == pglXMakeContextCurrent) {
1687 ret = FALSE;
1688 } else {
1689 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1690 Drawable d_draw = get_glxdrawable(pDrawDev);
1691 Drawable d_read = get_glxdrawable(pReadDev);
1693 if (ctx->ctx == NULL) {
1694 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, !indirect);
1695 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1697 ctx->hdc = pDrawDev->hdc;
1698 ctx->physDev = pDrawDev;
1699 ctx->pReadDev = pReadDev;
1700 ctx->drawables[0] = d_draw;
1701 ctx->drawables[1] = d_read;
1702 ctx->refresh_drawables = FALSE;
1703 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1704 NtCurrentTeb()->glContext = ctx;
1707 wine_tsx11_unlock();
1709 TRACE(" returning %s\n", (ret ? "True" : "False"));
1710 return ret;
1714 * X11DRV_wglShareLists
1716 * For OpenGL32 wglShaderLists.
1718 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1719 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1720 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1722 TRACE("(%p, %p)\n", org, dest);
1724 if (!has_opengl()) {
1725 ERR("No libGL on this box - disabling OpenGL support !\n");
1726 return 0;
1729 if (NULL != dest && dest->ctx != NULL) {
1730 ERR("Could not share display lists, context already created !\n");
1731 return FALSE;
1732 } else {
1733 if (org->ctx == NULL) {
1734 int indirect = (GetObjectType(org->hdc) == OBJ_MEMDC);
1735 wine_tsx11_lock();
1736 describeContext(org);
1738 if(org->vis)
1739 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, !indirect);
1740 else /* Create a GLX Context for a pbuffer */
1741 org->ctx = pglXCreateNewContext(gdi_display, org->fmt->fbconfig, org->fmt->render_type, NULL, True);
1742 wine_tsx11_unlock();
1743 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1745 if (NULL != dest) {
1746 int indirect = (GetObjectType(dest->hdc) == OBJ_MEMDC);
1747 wine_tsx11_lock();
1748 describeContext(dest);
1749 /* Create the destination context with display lists shared */
1750 if(dest->vis)
1751 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, !indirect);
1752 else /* Create a GLX Context for a pbuffer */
1753 dest->ctx = pglXCreateNewContext(gdi_display, dest->fmt->fbconfig, dest->fmt->render_type, org->ctx, True);
1754 wine_tsx11_unlock();
1755 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1756 return TRUE;
1759 return FALSE;
1762 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1764 /* We are running using client-side rendering fonts... */
1765 GLYPHMETRICS gm;
1766 unsigned int glyph;
1767 int size = 0;
1768 void *bitmap = NULL, *gl_bitmap = NULL;
1769 int org_alignment;
1771 wine_tsx11_lock();
1772 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1773 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1774 wine_tsx11_unlock();
1776 for (glyph = first; glyph < first + count; glyph++) {
1777 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1778 int height, width_int;
1780 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1781 if (needed_size == GDI_ERROR) {
1782 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1783 goto error;
1784 } else {
1785 TRACE(" - needed size : %d\n", needed_size);
1788 if (needed_size > size) {
1789 size = needed_size;
1790 HeapFree(GetProcessHeap(), 0, bitmap);
1791 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1792 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1793 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1795 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1796 if (TRACE_ON(opengl)) {
1797 unsigned int height, width, bitmask;
1798 unsigned char *bitmap_ = (unsigned char *) bitmap;
1800 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1801 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1802 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1803 if (needed_size != 0) {
1804 TRACE(" - bitmap :\n");
1805 for (height = 0; height < gm.gmBlackBoxY; height++) {
1806 TRACE(" ");
1807 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1808 if (bitmask == 0) {
1809 bitmap_ += 1;
1810 bitmask = 0x80;
1812 if (*bitmap_ & bitmask)
1813 TRACE("*");
1814 else
1815 TRACE(" ");
1817 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1818 TRACE("\n");
1823 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1824 * glyph for it to be drawn properly.
1826 if (needed_size != 0) {
1827 width_int = (gm.gmBlackBoxX + 31) / 32;
1828 for (height = 0; height < gm.gmBlackBoxY; height++) {
1829 int width;
1830 for (width = 0; width < width_int; width++) {
1831 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1832 ((int *) bitmap)[height * width_int + width];
1837 wine_tsx11_lock();
1838 pglNewList(listBase++, GL_COMPILE);
1839 if (needed_size != 0) {
1840 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1841 0 - (int) gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - (int) gm.gmptGlyphOrigin.y,
1842 gm.gmCellIncX, gm.gmCellIncY,
1843 gl_bitmap);
1844 } else {
1845 /* This is the case of 'empty' glyphs like the space character */
1846 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1848 pglEndList();
1849 wine_tsx11_unlock();
1852 wine_tsx11_lock();
1853 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1854 wine_tsx11_unlock();
1856 HeapFree(GetProcessHeap(), 0, bitmap);
1857 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1858 return TRUE;
1860 error:
1861 wine_tsx11_lock();
1862 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1863 wine_tsx11_unlock();
1865 HeapFree(GetProcessHeap(), 0, bitmap);
1866 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1867 return FALSE;
1871 * X11DRV_wglUseFontBitmapsA
1873 * For OpenGL32 wglUseFontBitmapsA.
1875 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1877 Font fid = physDev->font;
1879 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1881 if (!has_opengl()) {
1882 ERR("No libGL on this box - disabling OpenGL support !\n");
1883 return 0;
1886 if (fid == 0) {
1887 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1890 wine_tsx11_lock();
1891 /* I assume that the glyphs are at the same position for X and for Windows */
1892 pglXUseXFont(fid, first, count, listBase);
1893 wine_tsx11_unlock();
1894 return TRUE;
1898 * X11DRV_wglUseFontBitmapsW
1900 * For OpenGL32 wglUseFontBitmapsW.
1902 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1904 Font fid = physDev->font;
1906 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1908 if (!has_opengl()) {
1909 ERR("No libGL on this box - disabling OpenGL support !\n");
1910 return 0;
1913 if (fid == 0) {
1914 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
1917 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1919 wine_tsx11_lock();
1920 /* I assume that the glyphs are at the same position for X and for Windows */
1921 pglXUseXFont(fid, first, count, listBase);
1922 wine_tsx11_unlock();
1923 return TRUE;
1926 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1927 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
1929 wine_tsx11_lock();
1930 switch(pname)
1932 case GL_DEPTH_BITS:
1934 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1936 pglGetIntegerv(pname, params);
1938 * if we cannot find a Wine Context
1939 * we only have the default wine desktop context,
1940 * so if we have only a 24 depth say we have 32
1942 if (!ctx && *params == 24) {
1943 *params = 32;
1945 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1946 break;
1948 case GL_ALPHA_BITS:
1950 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1952 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
1953 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
1954 break;
1956 default:
1957 pglGetIntegerv(pname, params);
1958 break;
1960 wine_tsx11_unlock();
1963 static inline void update_drawable(X11DRV_PDEVICE *physDev)
1965 int w, h;
1967 if(!physDev->gl_drawable)
1968 return;
1970 w = physDev->dc_rect.right - physDev->dc_rect.left;
1971 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
1973 if(w > 0 && h > 0) {
1974 Drawable src = physDev->pixmap;
1975 if(!src) src = physDev->gl_drawable;
1977 /* The GL drawable may be lagged behind if we don't flush first, so
1978 * flush the display make sure we copy up-to-date data */
1979 XFlush(gdi_display);
1980 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
1981 physDev->dc_rect.left, physDev->dc_rect.top);
1986 static void WINAPI X11DRV_wglFinish(void)
1988 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1990 wine_tsx11_lock();
1991 sync_context(ctx);
1992 pglFinish();
1993 update_drawable(ctx->physDev);
1994 wine_tsx11_unlock();
1997 static void WINAPI X11DRV_wglFlush(void)
1999 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2001 wine_tsx11_lock();
2002 sync_context(ctx);
2003 pglFlush();
2004 update_drawable(ctx->physDev);
2005 wine_tsx11_unlock();
2009 * X11DRV_wglGetExtensionsStringARB
2011 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2013 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2014 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2015 return WineGLInfo.wglExtensions;
2019 * X11DRV_wglCreatePbufferARB
2021 * WGL_ARB_pbuffer: wglCreatePbufferARB
2023 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2025 Wine_GLPBuffer* object = NULL;
2026 WineGLPixelFormat *fmt = NULL;
2027 int nCfgs = 0;
2028 int attribs[256];
2029 int nAttribs = 0;
2031 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2033 if (0 >= iPixelFormat) {
2034 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2035 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2036 return NULL; /* unexpected error */
2039 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2040 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2041 if(!fmt) {
2042 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2043 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2044 goto create_failed; /* unexpected error */
2047 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2048 if (NULL == object) {
2049 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2050 goto create_failed; /* unexpected error */
2052 object->hdc = hdc;
2053 object->display = gdi_display;
2054 object->width = iWidth;
2055 object->height = iHeight;
2056 object->fmt = fmt;
2058 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2059 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2060 while (piAttribList && 0 != *piAttribList) {
2061 int attr_v;
2062 switch (*piAttribList) {
2063 case WGL_PBUFFER_LARGEST_ARB: {
2064 ++piAttribList;
2065 attr_v = *piAttribList;
2066 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2067 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2068 break;
2071 case WGL_TEXTURE_FORMAT_ARB: {
2072 ++piAttribList;
2073 attr_v = *piAttribList;
2074 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2075 if (use_render_texture_ati) {
2076 int type = 0;
2077 switch (attr_v) {
2078 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2079 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2080 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2081 default:
2082 SetLastError(ERROR_INVALID_DATA);
2083 goto create_failed;
2085 object->use_render_texture = 1;
2086 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2087 } else {
2088 if (WGL_NO_TEXTURE_ARB == attr_v) {
2089 object->use_render_texture = 0;
2090 } else {
2091 if (!use_render_texture_emulation) {
2092 SetLastError(ERROR_INVALID_DATA);
2093 goto create_failed;
2095 switch (attr_v) {
2096 case WGL_TEXTURE_RGB_ARB:
2097 object->use_render_texture = GL_RGB;
2098 object->texture_bpp = 3;
2099 object->texture_format = GL_RGB;
2100 object->texture_type = GL_UNSIGNED_BYTE;
2101 break;
2102 case WGL_TEXTURE_RGBA_ARB:
2103 object->use_render_texture = GL_RGBA;
2104 object->texture_bpp = 4;
2105 object->texture_format = GL_RGBA;
2106 object->texture_type = GL_UNSIGNED_BYTE;
2107 break;
2109 /* WGL_FLOAT_COMPONENTS_NV */
2110 case WGL_TEXTURE_FLOAT_R_NV:
2111 object->use_render_texture = GL_FLOAT_R_NV;
2112 object->texture_bpp = 4;
2113 object->texture_format = GL_RED;
2114 object->texture_type = GL_FLOAT;
2115 break;
2116 case WGL_TEXTURE_FLOAT_RG_NV:
2117 object->use_render_texture = GL_FLOAT_RG_NV;
2118 object->texture_bpp = 8;
2119 object->texture_format = GL_LUMINANCE_ALPHA;
2120 object->texture_type = GL_FLOAT;
2121 break;
2122 case WGL_TEXTURE_FLOAT_RGB_NV:
2123 object->use_render_texture = GL_FLOAT_RGB_NV;
2124 object->texture_bpp = 12;
2125 object->texture_format = GL_RGB;
2126 object->texture_type = GL_FLOAT;
2127 break;
2128 case WGL_TEXTURE_FLOAT_RGBA_NV:
2129 object->use_render_texture = GL_FLOAT_RGBA_NV;
2130 object->texture_bpp = 16;
2131 object->texture_format = GL_RGBA;
2132 object->texture_type = GL_FLOAT;
2133 break;
2134 default:
2135 ERR("Unknown texture format: %x\n", attr_v);
2136 SetLastError(ERROR_INVALID_DATA);
2137 goto create_failed;
2141 break;
2144 case WGL_TEXTURE_TARGET_ARB: {
2145 ++piAttribList;
2146 attr_v = *piAttribList;
2147 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2148 if (use_render_texture_ati) {
2149 int type = 0;
2150 switch (attr_v) {
2151 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2152 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2153 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2154 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2155 default:
2156 SetLastError(ERROR_INVALID_DATA);
2157 goto create_failed;
2159 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2160 } else {
2161 if (WGL_NO_TEXTURE_ARB == attr_v) {
2162 object->texture_target = 0;
2163 } else {
2164 if (!use_render_texture_emulation) {
2165 SetLastError(ERROR_INVALID_DATA);
2166 goto create_failed;
2168 switch (attr_v) {
2169 case WGL_TEXTURE_CUBE_MAP_ARB: {
2170 if (iWidth != iHeight) {
2171 SetLastError(ERROR_INVALID_DATA);
2172 goto create_failed;
2174 object->texture_target = GL_TEXTURE_CUBE_MAP;
2175 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2176 break;
2178 case WGL_TEXTURE_1D_ARB: {
2179 if (1 != iHeight) {
2180 SetLastError(ERROR_INVALID_DATA);
2181 goto create_failed;
2183 object->texture_target = GL_TEXTURE_1D;
2184 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2185 break;
2187 case WGL_TEXTURE_2D_ARB: {
2188 object->texture_target = GL_TEXTURE_2D;
2189 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2190 break;
2192 case WGL_TEXTURE_RECTANGLE_NV: {
2193 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2194 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2195 break;
2197 default:
2198 ERR("Unknown texture target: %x\n", attr_v);
2199 SetLastError(ERROR_INVALID_DATA);
2200 goto create_failed;
2204 break;
2207 case WGL_MIPMAP_TEXTURE_ARB: {
2208 ++piAttribList;
2209 attr_v = *piAttribList;
2210 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2211 if (use_render_texture_ati) {
2212 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2213 } else {
2214 if (!use_render_texture_emulation) {
2215 SetLastError(ERROR_INVALID_DATA);
2216 goto create_failed;
2219 break;
2222 ++piAttribList;
2225 PUSH1(attribs, None);
2226 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2227 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2228 if (!object->drawable) {
2229 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2230 goto create_failed; /* unexpected error */
2232 TRACE("->(%p)\n", object);
2233 return (HPBUFFERARB) object;
2235 create_failed:
2236 HeapFree(GetProcessHeap(), 0, object);
2237 TRACE("->(FAILED)\n");
2238 return (HPBUFFERARB) NULL;
2242 * X11DRV_wglDestroyPbufferARB
2244 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2246 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2248 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2249 TRACE("(%p)\n", hPbuffer);
2250 if (NULL == object) {
2251 SetLastError(ERROR_INVALID_HANDLE);
2252 return GL_FALSE;
2254 pglXDestroyPbuffer(object->display, object->drawable);
2255 HeapFree(GetProcessHeap(), 0, object);
2256 return GL_TRUE;
2260 * X11DRV_wglGetPbufferDCARB
2262 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2263 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2264 * Gdi32 implements the part of this function which creates a device context.
2265 * This part associates the physDev with the X drawable of the pbuffer.
2267 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2269 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2270 if (NULL == object) {
2271 SetLastError(ERROR_INVALID_HANDLE);
2272 return NULL;
2275 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2276 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2277 physDev->current_pf = object->fmt->iPixelFormat;
2278 physDev->drawable = object->drawable;
2279 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2280 physDev->dc_rect = physDev->drawable_rect;
2282 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2283 return physDev->hdc;
2287 * X11DRV_wglQueryPbufferARB
2289 * WGL_ARB_pbuffer: wglQueryPbufferARB
2291 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2293 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2294 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2295 if (NULL == object) {
2296 SetLastError(ERROR_INVALID_HANDLE);
2297 return GL_FALSE;
2299 switch (iAttribute) {
2300 case WGL_PBUFFER_WIDTH_ARB:
2301 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2302 break;
2303 case WGL_PBUFFER_HEIGHT_ARB:
2304 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2305 break;
2307 case WGL_PBUFFER_LOST_ARB:
2308 /* GLX Pbuffers cannot be lost by default. We can support this by
2309 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2310 * to receive pixel buffer clobber events, however that may or may
2311 * not give any benefit */
2312 *piValue = GL_FALSE;
2313 break;
2315 case WGL_TEXTURE_FORMAT_ARB:
2316 if (use_render_texture_ati) {
2317 unsigned int tmp;
2318 int type = WGL_NO_TEXTURE_ARB;
2319 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2320 switch (tmp) {
2321 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2322 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2323 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2325 *piValue = type;
2326 } else {
2327 if (!object->use_render_texture) {
2328 *piValue = WGL_NO_TEXTURE_ARB;
2329 } else {
2330 if (!use_render_texture_emulation) {
2331 SetLastError(ERROR_INVALID_HANDLE);
2332 return GL_FALSE;
2334 switch(object->use_render_texture) {
2335 case GL_RGB:
2336 *piValue = WGL_TEXTURE_RGB_ARB;
2337 break;
2338 case GL_RGBA:
2339 *piValue = WGL_TEXTURE_RGBA_ARB;
2340 break;
2341 /* WGL_FLOAT_COMPONENTS_NV */
2342 case GL_FLOAT_R_NV:
2343 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2344 break;
2345 case GL_FLOAT_RG_NV:
2346 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2347 break;
2348 case GL_FLOAT_RGB_NV:
2349 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2350 break;
2351 case GL_FLOAT_RGBA_NV:
2352 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2353 break;
2354 default:
2355 ERR("Unknown texture format: %x\n", object->use_render_texture);
2359 break;
2361 case WGL_TEXTURE_TARGET_ARB:
2362 if (use_render_texture_ati) {
2363 unsigned int tmp;
2364 int type = WGL_NO_TEXTURE_ARB;
2365 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2366 switch (tmp) {
2367 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2368 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2369 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2370 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2372 *piValue = type;
2373 } else {
2374 if (!object->texture_target) {
2375 *piValue = WGL_NO_TEXTURE_ARB;
2376 } else {
2377 if (!use_render_texture_emulation) {
2378 SetLastError(ERROR_INVALID_DATA);
2379 return GL_FALSE;
2381 switch (object->texture_target) {
2382 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2383 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2384 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2385 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2389 break;
2391 case WGL_MIPMAP_TEXTURE_ARB:
2392 if (use_render_texture_ati) {
2393 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2394 } else {
2395 *piValue = GL_FALSE; /** don't support that */
2396 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2398 break;
2400 default:
2401 FIXME("unexpected attribute %x\n", iAttribute);
2402 break;
2405 return GL_TRUE;
2409 * X11DRV_wglReleasePbufferDCARB
2411 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2413 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2415 TRACE("(%p, %p)\n", hPbuffer, hdc);
2416 DeleteDC(hdc);
2417 return 0;
2421 * X11DRV_wglSetPbufferAttribARB
2423 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2425 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2427 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2428 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2429 if (NULL == object) {
2430 SetLastError(ERROR_INVALID_HANDLE);
2431 return GL_FALSE;
2433 if (!object->use_render_texture) {
2434 SetLastError(ERROR_INVALID_HANDLE);
2435 return GL_FALSE;
2437 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2438 return GL_TRUE;
2440 if (NULL != pglXDrawableAttribATI) {
2441 if (use_render_texture_ati) {
2442 FIXME("Need conversion for GLX_ATI_render_texture\n");
2444 return pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2446 return GL_FALSE;
2450 * X11DRV_wglChoosePixelFormatARB
2452 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2454 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2456 int gl_test = 0;
2457 int attribs[256];
2458 int nAttribs = 0;
2459 GLXFBConfig* cfgs = NULL;
2460 int nCfgs = 0;
2461 UINT it;
2462 int fmt_id;
2463 WineGLPixelFormat *fmt;
2464 int pfmt_it = 0;
2465 int run;
2467 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2468 if (NULL != pfAttribFList) {
2469 FIXME("unused pfAttribFList\n");
2472 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2473 if (-1 == nAttribs) {
2474 WARN("Cannot convert WGL to GLX attributes\n");
2475 return GL_FALSE;
2477 PUSH1(attribs, None);
2479 /* Search for FB configurations matching the requirements in attribs */
2480 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2481 if (NULL == cfgs) {
2482 WARN("Compatible Pixel Format not found\n");
2483 return GL_FALSE;
2486 /* Loop through all matching formats and check if they are suitable.
2487 * Note that this function should at max return nMaxFormats different formats */
2488 for(run=0; run < 2; run++)
2490 for (it = 0; it < nCfgs; ++it) {
2491 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2492 if (gl_test) {
2493 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2494 continue;
2497 /* Search for the format in our list of compatible formats */
2498 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2499 if(!fmt)
2500 continue;
2502 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2503 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2504 continue;
2506 if(pfmt_it < nMaxFormats) {
2507 piFormats[pfmt_it] = fmt->iPixelFormat;
2508 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2510 pfmt_it++;
2514 *nNumFormats = pfmt_it;
2515 /** free list */
2516 XFree(cfgs);
2517 return GL_TRUE;
2521 * X11DRV_wglGetPixelFormatAttribivARB
2523 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2525 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2527 UINT i;
2528 WineGLPixelFormat *fmt = NULL;
2529 int hTest;
2530 int tmp;
2531 int curGLXAttr = 0;
2532 int nWGLFormats = 0;
2534 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2536 if (0 < iLayerPlane) {
2537 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2538 return GL_FALSE;
2541 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2542 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2543 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2544 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2545 if(!fmt) {
2546 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2549 for (i = 0; i < nAttributes; ++i) {
2550 const int curWGLAttr = piAttributes[i];
2551 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2553 switch (curWGLAttr) {
2554 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2555 piValues[i] = nWGLFormats;
2556 continue;
2558 case WGL_SUPPORT_OPENGL_ARB:
2559 piValues[i] = GL_TRUE;
2560 continue;
2562 case WGL_ACCELERATION_ARB:
2563 curGLXAttr = GLX_CONFIG_CAVEAT;
2564 if (!fmt) goto pix_error;
2565 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2566 if (hTest) goto get_error;
2567 switch (tmp) {
2568 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2569 case GLX_SLOW_CONFIG: piValues[i] = WGL_GENERIC_ACCELERATION_ARB; break;
2570 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2571 default:
2572 ERR("unexpected Config Caveat(%x)\n", tmp);
2573 piValues[i] = WGL_NO_ACCELERATION_ARB;
2575 continue;
2577 case WGL_TRANSPARENT_ARB:
2578 curGLXAttr = GLX_TRANSPARENT_TYPE;
2579 if (!fmt) goto pix_error;
2580 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2581 if (hTest) goto get_error;
2582 piValues[i] = GL_FALSE;
2583 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2584 continue;
2586 case WGL_PIXEL_TYPE_ARB:
2587 curGLXAttr = GLX_RENDER_TYPE;
2588 if (!fmt) goto pix_error;
2589 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2590 if (hTest) goto get_error;
2591 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2592 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2593 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2594 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2595 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2596 else {
2597 ERR("unexpected RenderType(%x)\n", tmp);
2598 piValues[i] = WGL_TYPE_RGBA_ARB;
2600 continue;
2602 case WGL_COLOR_BITS_ARB:
2603 curGLXAttr = GLX_BUFFER_SIZE;
2604 break;
2606 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2607 if (use_render_texture_ati) {
2608 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2609 break;
2611 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2612 if (use_render_texture_ati) {
2613 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2614 break;
2616 if (!use_render_texture_emulation) {
2617 piValues[i] = GL_FALSE;
2618 continue;
2620 curGLXAttr = GLX_RENDER_TYPE;
2621 if (!fmt) goto pix_error;
2622 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2623 if (hTest) goto get_error;
2624 if (GLX_COLOR_INDEX_BIT == tmp) {
2625 piValues[i] = GL_FALSE;
2626 continue;
2628 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2629 if (hTest) goto get_error;
2630 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2631 continue;
2633 case WGL_BLUE_BITS_ARB:
2634 curGLXAttr = GLX_BLUE_SIZE;
2635 break;
2636 case WGL_RED_BITS_ARB:
2637 curGLXAttr = GLX_RED_SIZE;
2638 break;
2639 case WGL_GREEN_BITS_ARB:
2640 curGLXAttr = GLX_GREEN_SIZE;
2641 break;
2642 case WGL_ALPHA_BITS_ARB:
2643 curGLXAttr = GLX_ALPHA_SIZE;
2644 break;
2645 case WGL_DEPTH_BITS_ARB:
2646 curGLXAttr = GLX_DEPTH_SIZE;
2647 break;
2648 case WGL_STENCIL_BITS_ARB:
2649 curGLXAttr = GLX_STENCIL_SIZE;
2650 break;
2651 case WGL_DOUBLE_BUFFER_ARB:
2652 curGLXAttr = GLX_DOUBLEBUFFER;
2653 break;
2654 case WGL_STEREO_ARB:
2655 curGLXAttr = GLX_STEREO;
2656 break;
2657 case WGL_AUX_BUFFERS_ARB:
2658 curGLXAttr = GLX_AUX_BUFFERS;
2659 break;
2661 case WGL_SUPPORT_GDI_ARB:
2662 if (!fmt) goto pix_error;
2663 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &tmp);
2664 if (hTest) goto get_error;
2665 if(tmp) {
2666 piValues[i] = GL_FALSE;
2667 continue;
2669 curGLXAttr = GLX_X_RENDERABLE;
2670 break;
2672 case WGL_DRAW_TO_WINDOW_ARB:
2673 case WGL_DRAW_TO_BITMAP_ARB:
2674 case WGL_DRAW_TO_PBUFFER_ARB:
2675 if (!fmt) goto pix_error;
2676 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2677 if (hTest) goto get_error;
2678 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2679 (curWGLAttr == WGL_DRAW_TO_BITMAP_ARB && (tmp&GLX_PIXMAP_BIT)) ||
2680 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2681 piValues[i] = GL_TRUE;
2682 else
2683 piValues[i] = GL_FALSE;
2684 continue;
2686 case WGL_PBUFFER_LARGEST_ARB:
2687 curGLXAttr = GLX_LARGEST_PBUFFER;
2688 break;
2690 case WGL_SAMPLE_BUFFERS_ARB:
2691 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2692 break;
2694 case WGL_SAMPLES_ARB:
2695 curGLXAttr = GLX_SAMPLES_ARB;
2696 break;
2698 case WGL_FLOAT_COMPONENTS_NV:
2699 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2700 break;
2702 case WGL_ACCUM_RED_BITS_ARB:
2703 curGLXAttr = GLX_ACCUM_RED_SIZE;
2704 break;
2705 case WGL_ACCUM_GREEN_BITS_ARB:
2706 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2707 break;
2708 case WGL_ACCUM_BLUE_BITS_ARB:
2709 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2710 break;
2711 case WGL_ACCUM_ALPHA_BITS_ARB:
2712 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2713 break;
2714 case WGL_ACCUM_BITS_ARB:
2715 if (!fmt) goto pix_error;
2716 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2717 if (hTest) goto get_error;
2718 piValues[i] = tmp;
2719 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2720 if (hTest) goto get_error;
2721 piValues[i] += tmp;
2722 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2723 if (hTest) goto get_error;
2724 piValues[i] += tmp;
2725 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2726 if (hTest) goto get_error;
2727 piValues[i] += tmp;
2728 continue;
2730 default:
2731 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2734 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2735 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2736 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2738 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2739 * and check which options can work using iPixelFormat=0 and which not.
2740 * A problem would be that this function is an extension. This would
2741 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2743 if (0 != curGLXAttr && iPixelFormat != 0) {
2744 if (!fmt) goto pix_error;
2745 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2746 if (hTest) goto get_error;
2747 curGLXAttr = 0;
2748 } else {
2749 piValues[i] = GL_FALSE;
2752 return GL_TRUE;
2754 get_error:
2755 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2756 return GL_FALSE;
2758 pix_error:
2759 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2760 return GL_FALSE;
2764 * X11DRV_wglGetPixelFormatAttribfvARB
2766 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2768 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2770 int *attr;
2771 int ret;
2772 int i;
2774 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2776 /* Allocate a temporary array to store integer values */
2777 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2778 if (!attr) {
2779 ERR("couldn't allocate %d array\n", nAttributes);
2780 return GL_FALSE;
2783 /* Piggy-back on wglGetPixelFormatAttribivARB */
2784 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2785 if (ret) {
2786 /* Convert integer values to float. Should also check for attributes
2787 that can give decimal values here */
2788 for (i=0; i<nAttributes;i++) {
2789 pfValues[i] = attr[i];
2793 HeapFree(GetProcessHeap(), 0, attr);
2794 return ret;
2798 * X11DRV_wglBindTexImageARB
2800 * WGL_ARB_render_texture: wglBindTexImageARB
2802 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2804 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2805 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2806 if (NULL == object) {
2807 SetLastError(ERROR_INVALID_HANDLE);
2808 return GL_FALSE;
2810 if (!object->use_render_texture) {
2811 SetLastError(ERROR_INVALID_HANDLE);
2812 return GL_FALSE;
2815 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2816 static int init = 0;
2817 int prev_binded_texture = 0;
2818 GLXContext prev_context = pglXGetCurrentContext();
2819 Drawable prev_drawable = pglXGetCurrentDrawable();
2820 GLXContext tmp_context;
2822 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2823 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2824 isn't ideal performance wise but I wasn't able to get other ways working.
2826 if(!init) {
2827 init = 1; /* Only show the FIXME once for performance reasons */
2828 FIXME("partial stub!\n");
2831 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
2832 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2834 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2836 /* Switch to our pbuffer */
2837 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2839 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2840 * After that upload the pbuffer texture data. */
2841 pglBindTexture(object->texture_target, prev_binded_texture);
2842 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2844 /* Switch back to the original drawable and upload the pbuffer-texture */
2845 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2846 pglXDestroyContext(gdi_display, tmp_context);
2847 return GL_TRUE;
2850 if (NULL != pglXBindTexImageATI) {
2851 int buffer;
2853 switch(iBuffer)
2855 case WGL_FRONT_LEFT_ARB:
2856 buffer = GLX_FRONT_LEFT_ATI;
2857 break;
2858 case WGL_FRONT_RIGHT_ARB:
2859 buffer = GLX_FRONT_RIGHT_ATI;
2860 break;
2861 case WGL_BACK_LEFT_ARB:
2862 buffer = GLX_BACK_LEFT_ATI;
2863 break;
2864 case WGL_BACK_RIGHT_ARB:
2865 buffer = GLX_BACK_RIGHT_ATI;
2866 break;
2867 default:
2868 ERR("Unknown iBuffer=%#x\n", iBuffer);
2869 return FALSE;
2872 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
2873 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
2874 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
2875 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
2876 * works fine using our pbuffer emulation path.
2878 return pglXBindTexImageATI(object->display, object->drawable, buffer);
2880 return GL_FALSE;
2884 * X11DRV_wglReleaseTexImageARB
2886 * WGL_ARB_render_texture: wglReleaseTexImageARB
2888 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2890 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2891 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2892 if (NULL == object) {
2893 SetLastError(ERROR_INVALID_HANDLE);
2894 return GL_FALSE;
2896 if (!object->use_render_texture) {
2897 SetLastError(ERROR_INVALID_HANDLE);
2898 return GL_FALSE;
2900 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2901 return GL_TRUE;
2903 if (NULL != pglXReleaseTexImageATI) {
2904 int buffer;
2906 switch(iBuffer)
2908 case WGL_FRONT_LEFT_ARB:
2909 buffer = GLX_FRONT_LEFT_ATI;
2910 break;
2911 case WGL_FRONT_RIGHT_ARB:
2912 buffer = GLX_FRONT_RIGHT_ATI;
2913 break;
2914 case WGL_BACK_LEFT_ARB:
2915 buffer = GLX_BACK_LEFT_ATI;
2916 break;
2917 case WGL_BACK_RIGHT_ARB:
2918 buffer = GLX_BACK_RIGHT_ATI;
2919 break;
2920 default:
2921 ERR("Unknown iBuffer=%#x\n", iBuffer);
2922 return FALSE;
2924 return pglXReleaseTexImageATI(object->display, object->drawable, buffer);
2926 return GL_FALSE;
2930 * X11DRV_wglGetExtensionsStringEXT
2932 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2934 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2935 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2936 return WineGLInfo.wglExtensions;
2940 * X11DRV_wglGetSwapIntervalEXT
2942 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2944 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2945 FIXME("(),stub!\n");
2946 return swap_interval;
2950 * X11DRV_wglSwapIntervalEXT
2952 * WGL_EXT_swap_control: wglSwapIntervalEXT
2954 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2955 TRACE("(%d)\n", interval);
2956 swap_interval = interval;
2957 if (NULL != pglXSwapIntervalSGI) {
2958 return 0 == pglXSwapIntervalSGI(interval);
2960 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2961 return TRUE;
2965 * X11DRV_wglAllocateMemoryNV
2967 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2969 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2970 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2971 if (pglXAllocateMemoryNV == NULL)
2972 return NULL;
2974 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2978 * X11DRV_wglFreeMemoryNV
2980 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2982 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2983 TRACE("(%p)\n", pointer);
2984 if (pglXFreeMemoryNV == NULL)
2985 return;
2987 pglXFreeMemoryNV(pointer);
2991 * glxRequireVersion (internal)
2993 * Check if the supported GLX version matches requiredVersion.
2995 static BOOL glxRequireVersion(int requiredVersion)
2997 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2998 if(requiredVersion <= WineGLInfo.glxVersion[1])
2999 return TRUE;
3001 return FALSE;
3004 static BOOL glxRequireExtension(const char *requiredExtension)
3006 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3007 return FALSE;
3010 return TRUE;
3013 static void register_extension_string(const char *ext)
3015 if (WineGLInfo.wglExtensions[0])
3016 strcat(WineGLInfo.wglExtensions, " ");
3017 strcat(WineGLInfo.wglExtensions, ext);
3019 TRACE("'%s'\n", ext);
3022 static BOOL register_extension(const WineGLExtension * ext)
3024 int i;
3026 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3027 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3029 register_extension_string(ext->extName);
3031 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3032 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3034 return TRUE;
3037 static const WineGLExtension WGL_internal_functions =
3041 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3042 { "wglFinish", X11DRV_wglFinish },
3043 { "wglFlush", X11DRV_wglFlush },
3048 static const WineGLExtension WGL_ARB_extensions_string =
3050 "WGL_ARB_extensions_string",
3052 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3056 static const WineGLExtension WGL_ARB_make_current_read =
3058 "WGL_ARB_make_current_read",
3060 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3061 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3065 static const WineGLExtension WGL_ARB_multisample =
3067 "WGL_ARB_multisample",
3070 static const WineGLExtension WGL_ARB_pbuffer =
3072 "WGL_ARB_pbuffer",
3074 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3075 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3076 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3077 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3078 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3079 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3083 static const WineGLExtension WGL_ARB_pixel_format =
3085 "WGL_ARB_pixel_format",
3087 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3088 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3089 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3093 static const WineGLExtension WGL_ARB_render_texture =
3095 "WGL_ARB_render_texture",
3097 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3098 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3102 static const WineGLExtension WGL_EXT_extensions_string =
3104 "WGL_EXT_extensions_string",
3106 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3110 static const WineGLExtension WGL_EXT_swap_control =
3112 "WGL_EXT_swap_control",
3114 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3115 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3119 static const WineGLExtension WGL_NV_vertex_array_range =
3121 "WGL_NV_vertex_array_range",
3123 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3124 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3129 * X11DRV_WineGL_LoadExtensions
3131 static void X11DRV_WineGL_LoadExtensions(void)
3133 WineGLInfo.wglExtensions[0] = 0;
3135 /* Load Wine internal functions */
3136 register_extension(&WGL_internal_functions);
3138 /* ARB Extensions */
3140 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3142 register_extension_string("WGL_ARB_pixel_format_float");
3143 register_extension_string("WGL_ATI_pixel_format_float");
3146 register_extension(&WGL_ARB_extensions_string);
3148 if (glxRequireVersion(3))
3149 register_extension(&WGL_ARB_make_current_read);
3151 if (glxRequireExtension("GLX_ARB_multisample"))
3152 register_extension(&WGL_ARB_multisample);
3154 /* In general pbuffer functionality requires support in the X-server. The functionality is
3155 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3156 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3157 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3159 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3160 * without support in the X-server (which other Mesa based drivers require).
3162 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3163 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3164 * is available pbuffers must be available too. */
3165 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3166 register_extension(&WGL_ARB_pbuffer);
3168 register_extension(&WGL_ARB_pixel_format);
3170 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3171 if (glxRequireExtension("GLX_ATI_render_texture") ||
3172 glxRequireExtension("GLX_ARB_render_texture") ||
3173 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3175 register_extension(&WGL_ARB_render_texture);
3177 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3178 if(glxRequireExtension("GLX_NV_float_buffer"))
3179 register_extension_string("WGL_NV_float_buffer");
3181 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3182 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3183 register_extension_string("WGL_NV_texture_rectangle");
3186 /* EXT Extensions */
3188 register_extension(&WGL_EXT_extensions_string);
3190 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3191 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3192 register_extension(&WGL_EXT_swap_control);
3194 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3195 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3196 register_extension(&WGL_NV_vertex_array_range);
3200 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev)
3202 GLXPixmap ret;
3203 XVisualInfo *vis;
3204 XVisualInfo template;
3205 int num;
3207 wine_tsx11_lock();
3209 /* Retrieve the visualid from our main visual which is the only visual we can use */
3210 template.visualid = XVisualIDFromVisual(visual);
3211 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
3213 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
3214 XFree(vis);
3215 wine_tsx11_unlock();
3216 TRACE("return %lx\n", ret);
3217 return ret;
3220 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3222 Drawable ret;
3224 if(physDev->bitmap)
3226 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3227 ret = physDev->drawable; /* PBuffer */
3228 else
3230 if(!physDev->bitmap->glxpixmap)
3231 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev);
3232 ret = physDev->bitmap->glxpixmap;
3235 else if(physDev->gl_drawable)
3236 ret = physDev->gl_drawable;
3237 else
3238 ret = physDev->drawable;
3239 return ret;
3242 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3244 wine_tsx11_lock();
3245 pglXDestroyGLXPixmap(display, glxpixmap);
3246 wine_tsx11_unlock();
3247 return TRUE;
3251 * X11DRV_SwapBuffers
3253 * Swap the buffers of this DC
3255 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3257 GLXDrawable drawable;
3258 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3260 if (!has_opengl()) {
3261 ERR("No libGL on this box - disabling OpenGL support !\n");
3262 return 0;
3265 TRACE_(opengl)("(%p)\n", physDev);
3267 drawable = get_glxdrawable(physDev);
3269 wine_tsx11_lock();
3270 sync_context(ctx);
3271 pglXSwapBuffers(gdi_display, drawable);
3272 update_drawable(physDev);
3273 wine_tsx11_unlock();
3275 /* FPS support */
3276 if (TRACE_ON(fps))
3278 static long prev_time, frames;
3280 DWORD time = GetTickCount();
3281 frames++;
3282 /* every 1.5 seconds */
3283 if (time - prev_time > 1500) {
3284 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3285 prev_time = time;
3286 frames = 0;
3290 return TRUE;
3293 /***********************************************************************
3294 * X11DRV_setup_opengl_visual
3296 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3297 * window (if it exists). If OpenGL isn't available, the visual is simply
3298 * set to the default visual for the display
3300 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3302 XVisualInfo *visual = NULL;
3303 int i;
3305 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3306 * D3D and some applications can make use of aux buffers.
3308 int visualProperties[][11] = {
3309 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_AUX_BUFFERS, 1, None },
3310 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, None },
3311 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, None },
3312 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, None },
3315 if (!has_opengl())
3316 return NULL;
3318 wine_tsx11_lock();
3319 for (i = 0; i < sizeof(visualProperties)/sizeof(visualProperties[0]); ++i) {
3320 visual = pglXChooseVisual(display, DefaultScreen(display), visualProperties[i]);
3321 if (visual)
3322 break;
3324 wine_tsx11_unlock();
3326 if (visual)
3327 TRACE("Visual ID %lx Chosen\n", visual->visualid);
3328 else
3329 WARN("No suitable visual found\n");
3331 return visual;
3334 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3336 WineGLPixelFormat *fmt;
3338 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
3339 if(fmt == NULL)
3340 return NULL;
3341 return pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3344 #else /* no OpenGL includes */
3346 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3348 return 0;
3351 void mark_drawable_dirty(Drawable old, Drawable new)
3355 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3357 return 0;
3360 /***********************************************************************
3361 * ChoosePixelFormat (X11DRV.@)
3363 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3364 const PIXELFORMATDESCRIPTOR *ppfd) {
3365 ERR("No OpenGL support compiled in.\n");
3367 return 0;
3370 /***********************************************************************
3371 * DescribePixelFormat (X11DRV.@)
3373 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3374 int iPixelFormat,
3375 UINT nBytes,
3376 PIXELFORMATDESCRIPTOR *ppfd) {
3377 ERR("No OpenGL support compiled in.\n");
3379 return 0;
3382 /***********************************************************************
3383 * GetPixelFormat (X11DRV.@)
3385 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3386 ERR("No OpenGL support compiled in.\n");
3388 return 0;
3391 /***********************************************************************
3392 * SetPixelFormat (X11DRV.@)
3394 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3395 int iPixelFormat,
3396 const PIXELFORMATDESCRIPTOR *ppfd) {
3397 ERR("No OpenGL support compiled in.\n");
3399 return FALSE;
3402 /***********************************************************************
3403 * SwapBuffers (X11DRV.@)
3405 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3406 ERR_(opengl)("No OpenGL support compiled in.\n");
3408 return FALSE;
3412 * X11DRV_wglCreateContext
3414 * For OpenGL32 wglCreateContext.
3416 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3417 ERR_(opengl)("No OpenGL support compiled in.\n");
3418 return NULL;
3422 * X11DRV_wglDeleteContext
3424 * For OpenGL32 wglDeleteContext.
3426 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3427 ERR_(opengl)("No OpenGL support compiled in.\n");
3428 return FALSE;
3432 * X11DRV_wglGetProcAddress
3434 * For OpenGL32 wglGetProcAddress.
3436 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3437 ERR_(opengl)("No OpenGL support compiled in.\n");
3438 return NULL;
3441 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3443 ERR_(opengl)("No OpenGL support compiled in.\n");
3444 return NULL;
3447 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3448 ERR_(opengl)("No OpenGL support compiled in.\n");
3449 return FALSE;
3453 * X11DRV_wglMakeCurrent
3455 * For OpenGL32 wglMakeCurrent.
3457 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3458 ERR_(opengl)("No OpenGL support compiled in.\n");
3459 return FALSE;
3463 * X11DRV_wglShareLists
3465 * For OpenGL32 wglShaderLists.
3467 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3468 ERR_(opengl)("No OpenGL support compiled in.\n");
3469 return FALSE;
3473 * X11DRV_wglUseFontBitmapsA
3475 * For OpenGL32 wglUseFontBitmapsA.
3477 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3479 ERR_(opengl)("No OpenGL support compiled in.\n");
3480 return FALSE;
3484 * X11DRV_wglUseFontBitmapsW
3486 * For OpenGL32 wglUseFontBitmapsW.
3488 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3490 ERR_(opengl)("No OpenGL support compiled in.\n");
3491 return FALSE;
3494 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3496 return NULL;
3499 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3501 return 0;
3504 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3506 return FALSE;
3509 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3511 return NULL;
3514 #endif /* defined(HAVE_OPENGL) */