winex11.drv: Remove unused variables.
[wine/gsoc-2012-control.git] / dlls / winex11.drv / opengl.c
blobf92f94376fe705e1d06f75bbaf39f3acc68f42a6
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);
39 #ifdef SONAME_LIBGL
41 #undef APIENTRY
42 #undef CALLBACK
43 #undef WINAPI
45 #ifdef HAVE_GL_GL_H
46 # include <GL/gl.h>
47 #endif
48 #ifdef HAVE_GL_GLX_H
49 # include <GL/glx.h>
50 #endif
51 #ifdef HAVE_GL_GLEXT_H
52 # include <GL/glext.h>
53 #endif
55 #include "wine/wgl.h"
57 #undef APIENTRY
58 #undef CALLBACK
59 #undef WINAPI
61 /* Redefines the constants */
62 #define CALLBACK __stdcall
63 #define WINAPI __stdcall
64 #define APIENTRY WINAPI
67 WINE_DECLARE_DEBUG_CHANNEL(fps);
69 typedef struct wine_glextension {
70 const char *extName;
71 struct {
72 const char *funcName;
73 void *funcAddress;
74 } extEntryPoints[9];
75 } WineGLExtension;
77 struct WineGLInfo {
78 const char *glVersion;
79 const char *glExtensions;
81 int glxVersion[2];
83 const char *glxServerVersion;
84 const char *glxServerVendor;
85 const char *glxServerExtensions;
87 const char *glxClientVersion;
88 const char *glxClientVendor;
89 const char *glxClientExtensions;
91 const char *glxExtensions;
93 BOOL glxDirect;
94 char wglExtensions[4096];
97 typedef struct wine_glpixelformat {
98 int iPixelFormat;
99 GLXFBConfig fbconfig;
100 int fmt_id;
101 int render_type;
102 BOOL offscreenOnly;
103 } WineGLPixelFormat;
105 typedef struct wine_glcontext {
106 HDC hdc;
107 BOOL do_escape;
108 XVisualInfo *vis;
109 WineGLPixelFormat *fmt;
110 GLXContext ctx;
111 HDC read_hdc;
112 Drawable drawables[2];
113 BOOL refresh_drawables;
114 struct wine_glcontext *next;
115 struct wine_glcontext *prev;
116 } Wine_GLContext;
118 typedef struct wine_glpbuffer {
119 Drawable drawable;
120 Display* display;
121 WineGLPixelFormat* fmt;
122 int width;
123 int height;
124 int* attribList;
125 HDC hdc;
127 int use_render_texture; /* This is also the internal texture format */
128 int texture_bind_target;
129 int texture_bpp;
130 GLint texture_format;
131 GLuint texture_target;
132 GLenum texture_type;
133 GLuint texture;
134 int texture_level;
135 } Wine_GLPBuffer;
137 static Wine_GLContext *context_list;
138 static struct WineGLInfo WineGLInfo = { 0 };
139 static int use_render_texture_emulation = 1;
140 static int use_render_texture_ati = 0;
141 static int swap_interval = 1;
143 #define MAX_EXTENSIONS 16
144 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
145 static int WineGLExtensionListSize;
147 static WineGLPixelFormat *WineGLPixelFormatList;
148 static int WineGLPixelFormatListSize = 0;
149 static int WineGLPixelFormatOnScreenSize = 0;
151 static void X11DRV_WineGL_LoadExtensions(void);
152 static BOOL glxRequireVersion(int requiredVersion);
153 static BOOL glxRequireExtension(const char *requiredExtension);
155 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
156 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
157 TRACE(" - dwFlags : ");
158 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
159 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
174 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
175 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
176 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
177 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
178 #undef TEST_AND_DUMP
179 TRACE("\n");
181 TRACE(" - iPixelType : ");
182 switch (ppfd->iPixelType) {
183 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
184 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
186 TRACE("\n");
188 TRACE(" - Color : %d\n", ppfd->cColorBits);
189 TRACE(" - Red : %d\n", ppfd->cRedBits);
190 TRACE(" - Green : %d\n", ppfd->cGreenBits);
191 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
192 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
193 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
194 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
195 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
196 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
198 TRACE(" - iLayerType : ");
199 switch (ppfd->iLayerType) {
200 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
201 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
202 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
204 TRACE("\n");
207 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
208 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
210 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
211 /* GLX 1.0 */
212 MAKE_FUNCPTR(glXChooseVisual)
213 MAKE_FUNCPTR(glXCopyContext)
214 MAKE_FUNCPTR(glXCreateContext)
215 MAKE_FUNCPTR(glXCreateGLXPixmap)
216 MAKE_FUNCPTR(glXGetCurrentContext)
217 MAKE_FUNCPTR(glXGetCurrentDrawable)
218 MAKE_FUNCPTR(glXDestroyContext)
219 MAKE_FUNCPTR(glXDestroyGLXPixmap)
220 MAKE_FUNCPTR(glXGetConfig)
221 MAKE_FUNCPTR(glXIsDirect)
222 MAKE_FUNCPTR(glXMakeCurrent)
223 MAKE_FUNCPTR(glXSwapBuffers)
224 MAKE_FUNCPTR(glXQueryExtension)
225 MAKE_FUNCPTR(glXQueryVersion)
226 MAKE_FUNCPTR(glXUseXFont)
228 /* GLX 1.1 */
229 MAKE_FUNCPTR(glXGetClientString)
230 MAKE_FUNCPTR(glXQueryExtensionsString)
231 MAKE_FUNCPTR(glXQueryServerString)
233 /* GLX 1.3 */
234 MAKE_FUNCPTR(glXGetFBConfigs)
235 MAKE_FUNCPTR(glXChooseFBConfig)
236 MAKE_FUNCPTR(glXCreatePbuffer)
237 MAKE_FUNCPTR(glXCreateNewContext)
238 MAKE_FUNCPTR(glXDestroyPbuffer)
239 MAKE_FUNCPTR(glXGetFBConfigAttrib)
240 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
241 MAKE_FUNCPTR(glXMakeContextCurrent)
242 MAKE_FUNCPTR(glXQueryDrawable)
243 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
245 /* GLX Extensions */
246 static void* (*pglXGetProcAddressARB)(const GLubyte *);
247 static int (*pglXSwapIntervalSGI)(int);
249 /* ATI GLX Extensions */
250 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
251 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
252 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
254 /* NV GLX Extension */
255 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
256 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
258 /* MESA GLX Extensions */
259 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
261 /* Standard OpenGL */
262 MAKE_FUNCPTR(glBindTexture)
263 MAKE_FUNCPTR(glBitmap)
264 MAKE_FUNCPTR(glCopyTexSubImage1D)
265 MAKE_FUNCPTR(glCopyTexImage2D)
266 MAKE_FUNCPTR(glCopyTexSubImage2D)
267 MAKE_FUNCPTR(glDrawBuffer)
268 MAKE_FUNCPTR(glEndList)
269 MAKE_FUNCPTR(glGetError)
270 MAKE_FUNCPTR(glGetIntegerv)
271 MAKE_FUNCPTR(glGetString)
272 MAKE_FUNCPTR(glNewList)
273 MAKE_FUNCPTR(glPixelStorei)
274 MAKE_FUNCPTR(glReadPixels)
275 MAKE_FUNCPTR(glTexImage2D)
276 MAKE_FUNCPTR(glFinish)
277 MAKE_FUNCPTR(glFlush)
278 #undef MAKE_FUNCPTR
280 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
282 static BOOL infoInitialized = FALSE;
284 int screen = DefaultScreen(gdi_display);
285 Window win = RootWindow(gdi_display, screen);
286 Visual *visual;
287 XVisualInfo template;
288 XVisualInfo *vis;
289 int num;
290 GLXContext ctx = NULL;
292 if (infoInitialized)
293 return TRUE;
294 infoInitialized = TRUE;
296 wine_tsx11_lock();
298 visual = DefaultVisual(gdi_display, screen);
299 template.visualid = XVisualIDFromVisual(visual);
300 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
301 if (vis) {
302 WORD old_fs = wine_get_fs();
303 /* Create a GLX Context. Without one we can't query GL information */
304 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
305 if (wine_get_fs() != old_fs)
307 wine_set_fs( old_fs );
308 wine_tsx11_unlock();
309 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
310 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
311 return FALSE;
315 if (ctx) {
316 pglXMakeCurrent(gdi_display, win, ctx);
317 } else {
318 ERR(" couldn't initialize OpenGL, expect problems\n");
319 wine_tsx11_unlock();
320 return FALSE;
323 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
324 WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
326 /* Get the common GLX version supported by GLX client and server ( major/minor) */
327 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
329 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
330 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
331 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
333 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
334 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
335 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
337 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
338 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
340 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
341 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER));
342 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
343 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
344 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
345 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
346 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
347 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
349 if(vis) XFree(vis);
350 if(ctx) {
351 pglXMakeCurrent(gdi_display, None, NULL);
352 pglXDestroyContext(gdi_display, ctx);
354 wine_tsx11_unlock();
355 return TRUE;
358 static BOOL has_opengl(void)
360 static int init_done;
361 static void *opengl_handle;
363 int error_base, event_base;
365 if (init_done) return (opengl_handle != NULL);
366 init_done = 1;
368 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
369 and include all dependencies */
370 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
371 if (opengl_handle == NULL) return FALSE;
373 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
374 if (pglXGetProcAddressARB == NULL) {
375 ERR("could not find glXGetProcAddressARB in libGL.\n");
376 return FALSE;
379 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
380 /* GLX 1.0 */
381 LOAD_FUNCPTR(glXChooseVisual)
382 LOAD_FUNCPTR(glXCopyContext)
383 LOAD_FUNCPTR(glXCreateContext)
384 LOAD_FUNCPTR(glXCreateGLXPixmap)
385 LOAD_FUNCPTR(glXGetCurrentContext)
386 LOAD_FUNCPTR(glXGetCurrentDrawable)
387 LOAD_FUNCPTR(glXDestroyContext)
388 LOAD_FUNCPTR(glXDestroyGLXPixmap)
389 LOAD_FUNCPTR(glXGetConfig)
390 LOAD_FUNCPTR(glXIsDirect)
391 LOAD_FUNCPTR(glXMakeCurrent)
392 LOAD_FUNCPTR(glXSwapBuffers)
393 LOAD_FUNCPTR(glXQueryExtension)
394 LOAD_FUNCPTR(glXQueryVersion)
395 LOAD_FUNCPTR(glXUseXFont)
397 /* GLX 1.1 */
398 LOAD_FUNCPTR(glXGetClientString)
399 LOAD_FUNCPTR(glXQueryExtensionsString)
400 LOAD_FUNCPTR(glXQueryServerString)
402 /* GLX 1.3 */
403 LOAD_FUNCPTR(glXCreatePbuffer)
404 LOAD_FUNCPTR(glXCreateNewContext)
405 LOAD_FUNCPTR(glXDestroyPbuffer)
406 LOAD_FUNCPTR(glXMakeContextCurrent)
407 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
408 LOAD_FUNCPTR(glXGetFBConfigs)
410 /* Standard OpenGL calls */
411 LOAD_FUNCPTR(glBindTexture)
412 LOAD_FUNCPTR(glBitmap)
413 LOAD_FUNCPTR(glCopyTexSubImage1D)
414 LOAD_FUNCPTR(glCopyTexImage2D)
415 LOAD_FUNCPTR(glCopyTexSubImage2D)
416 LOAD_FUNCPTR(glDrawBuffer)
417 LOAD_FUNCPTR(glEndList)
418 LOAD_FUNCPTR(glGetError)
419 LOAD_FUNCPTR(glGetIntegerv)
420 LOAD_FUNCPTR(glGetString)
421 LOAD_FUNCPTR(glNewList)
422 LOAD_FUNCPTR(glPixelStorei)
423 LOAD_FUNCPTR(glReadPixels)
424 LOAD_FUNCPTR(glTexImage2D)
425 LOAD_FUNCPTR(glFinish)
426 LOAD_FUNCPTR(glFlush)
427 #undef LOAD_FUNCPTR
429 /* It doesn't matter if these fail. They'll only be used if the driver reports
430 the associated extension is available (and if a driver reports the extension
431 is available but fails to provide the functions, it's quite broken) */
432 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
433 /* NV GLX Extension */
434 LOAD_FUNCPTR(glXAllocateMemoryNV)
435 LOAD_FUNCPTR(glXFreeMemoryNV)
436 #undef LOAD_FUNCPTR
438 if(!X11DRV_WineGL_InitOpenglInfo()) {
439 wine_dlclose(opengl_handle, NULL, 0);
440 opengl_handle = NULL;
441 return FALSE;
444 wine_tsx11_lock();
445 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
446 TRACE("GLX is up and running error_base = %d\n", error_base);
447 } else {
448 wine_dlclose(opengl_handle, NULL, 0);
449 opengl_handle = NULL;
452 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
453 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
454 * rendering is used.
456 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
457 * depends on the reported GLX client / server version and on the client / server extension list.
458 * Those don't have to be the same.
460 * In general the server GLX information lists the capabilities in case of indirect rendering.
461 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
462 * available and in that case the client GLX informat can be used.
463 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
464 * in the GLX version/extension list. When a program does this it works for certain for both
465 * direct and indirect rendering.
467 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
468 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
469 * extension list which causes this extension not to be listed. (Wine requires this extension).
470 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
471 * pbuffers is around.
473 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
474 * the ATI drivers and from then on use GLX client information for them.
477 if(glxRequireVersion(3)) {
478 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
479 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
480 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
481 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
482 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
483 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
484 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
485 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
487 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
488 * enable this function when the Xserver understand GLX 1.3 or newer
490 pglXQueryDrawable = NULL;
491 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
492 TRACE("Overriding ATI GLX capabilities!\n");
493 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
494 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
495 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
496 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
498 /* Use client GLX information in case of the ATI drivers. We override the
499 * capabilities over here and not somewhere else as ATI might better their
500 * life in the future. In case they release proper drivers this block of
501 * code won't be called. */
502 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
503 } else {
504 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
507 if(glxRequireExtension("GLX_ATI_render_texture")) {
508 use_render_texture_ati = 1;
509 pglXBindTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
510 pglXReleaseTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
511 pglXDrawableAttribATI = pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
514 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
515 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
518 X11DRV_WineGL_LoadExtensions();
520 wine_tsx11_unlock();
521 return (opengl_handle != NULL);
523 sym_not_found:
524 wine_dlclose(opengl_handle, NULL, 0);
525 opengl_handle = NULL;
526 return FALSE;
529 static inline Wine_GLContext *alloc_context(void)
531 Wine_GLContext *ret;
533 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
535 ret->next = context_list;
536 if (context_list) context_list->prev = ret;
537 context_list = ret;
539 return ret;
542 static inline void free_context(Wine_GLContext *context)
544 if (context->next != NULL) context->next->prev = context->prev;
545 if (context->prev != NULL) context->prev->next = context->next;
546 else context_list = context->next;
548 if (context->vis) XFree(context->vis);
549 HeapFree(GetProcessHeap(), 0, context);
552 static inline BOOL is_valid_context( Wine_GLContext *ctx )
554 Wine_GLContext *ptr;
555 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
556 return (ptr != NULL);
559 static int describeContext(Wine_GLContext* ctx) {
560 int tmp;
561 int ctx_vis_id;
562 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
563 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
564 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
565 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
566 TRACE(" - VISUAL_ID 0x%x\n", tmp);
567 ctx_vis_id = tmp;
568 return ctx_vis_id;
571 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
572 int tmp;
573 int nElements;
574 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
575 GLXFBConfig *fbCfgs;
577 if (pglXQueryDrawable == NULL) {
578 /** glXQueryDrawable not available so returns not supported */
579 return -1;
582 TRACE(" Drawable %p have :\n", (void*) drawable);
583 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
584 TRACE(" - WIDTH as %d\n", tmp);
585 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
586 TRACE(" - HEIGHT as %d\n", tmp);
587 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
588 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
590 attribList[1] = tmp;
591 fbCfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribList, &nElements);
592 if (fbCfgs == NULL) {
593 return -1;
596 pglXGetFBConfigAttrib(gdi_display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
597 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
599 XFree(fbCfgs);
601 return tmp;
604 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
605 int nAttribs = 0;
606 unsigned cur = 0;
607 int pop;
608 int drawattrib = 0;
609 int nvfloatattrib = GLX_DONT_CARE;
610 int pixelattrib = 0;
611 int supportgdi = -1;
612 int doublebuf = -1;
614 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
615 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
616 while (iWGLAttr && 0 != iWGLAttr[cur]) {
617 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
619 switch (iWGLAttr[cur]) {
620 case WGL_AUX_BUFFERS_ARB:
621 pop = iWGLAttr[++cur];
622 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
623 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
624 break;
625 case WGL_COLOR_BITS_ARB:
626 pop = iWGLAttr[++cur];
627 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
628 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
629 break;
630 case WGL_BLUE_BITS_ARB:
631 pop = iWGLAttr[++cur];
632 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
633 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
634 break;
635 case WGL_RED_BITS_ARB:
636 pop = iWGLAttr[++cur];
637 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
638 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
639 break;
640 case WGL_GREEN_BITS_ARB:
641 pop = iWGLAttr[++cur];
642 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
643 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
644 break;
645 case WGL_ALPHA_BITS_ARB:
646 pop = iWGLAttr[++cur];
647 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
648 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
649 break;
650 case WGL_DEPTH_BITS_ARB:
651 pop = iWGLAttr[++cur];
652 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
653 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
654 break;
655 case WGL_STENCIL_BITS_ARB:
656 pop = iWGLAttr[++cur];
657 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
658 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
659 break;
660 case WGL_DOUBLE_BUFFER_ARB:
661 pop = iWGLAttr[++cur];
662 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
663 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
664 doublebuf = pop;
665 break;
666 case WGL_STEREO_ARB:
667 pop = iWGLAttr[++cur];
668 PUSH2(oGLXAttr, GLX_STEREO, pop);
669 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
670 break;
672 case WGL_PIXEL_TYPE_ARB:
673 pop = iWGLAttr[++cur];
674 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
675 switch (pop) {
676 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
677 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
678 /* 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 */
679 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
680 default:
681 ERR("unexpected PixelType(%x)\n", pop);
682 pop = 0;
684 break;
686 case WGL_SUPPORT_GDI_ARB:
687 pop = iWGLAttr[++cur];
688 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
689 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
690 supportgdi = pop;
691 break;
693 case WGL_DRAW_TO_BITMAP_ARB:
694 pop = iWGLAttr[++cur];
695 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
696 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
697 if (pop) {
698 drawattrib |= GLX_PIXMAP_BIT;
700 break;
702 case WGL_DRAW_TO_WINDOW_ARB:
703 pop = iWGLAttr[++cur];
704 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
705 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
706 if (pop) {
707 drawattrib |= GLX_WINDOW_BIT;
709 break;
711 case WGL_DRAW_TO_PBUFFER_ARB:
712 pop = iWGLAttr[++cur];
713 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
714 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
715 if (pop) {
716 drawattrib |= GLX_PBUFFER_BIT;
718 break;
720 case WGL_ACCELERATION_ARB:
721 case WGL_SUPPORT_OPENGL_ARB:
722 pop = iWGLAttr[++cur];
723 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
724 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
725 break;
727 case WGL_PBUFFER_LARGEST_ARB:
728 pop = iWGLAttr[++cur];
729 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
730 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
731 break;
733 case WGL_SAMPLE_BUFFERS_ARB:
734 pop = iWGLAttr[++cur];
735 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
736 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
737 break;
739 case WGL_SAMPLES_ARB:
740 pop = iWGLAttr[++cur];
741 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
742 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
743 break;
745 case WGL_TEXTURE_FORMAT_ARB:
746 case WGL_TEXTURE_TARGET_ARB:
747 case WGL_MIPMAP_TEXTURE_ARB:
748 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
749 pop = iWGLAttr[++cur];
750 if (NULL == pbuf) {
751 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
753 if (use_render_texture_ati) {
754 /** nothing to do here */
756 else if (!use_render_texture_emulation) {
757 if (WGL_NO_TEXTURE_ARB != pop) {
758 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
759 return -1; /** error: don't support it */
760 } else {
761 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
762 drawattrib |= GLX_PBUFFER_BIT;
765 break ;
766 case WGL_FLOAT_COMPONENTS_NV:
767 nvfloatattrib = iWGLAttr[++cur];
768 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
769 break ;
770 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
771 case WGL_BIND_TO_TEXTURE_RGB_ARB:
772 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
773 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
774 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
775 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
776 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
777 pop = iWGLAttr[++cur];
778 /** cannot be converted, see direct handling on
779 * - wglGetPixelFormatAttribivARB
780 * TODO: wglChoosePixelFormat
782 break ;
783 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
784 pop = iWGLAttr[++cur];
785 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
786 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
787 break ;
789 default:
790 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
791 break;
793 ++cur;
796 if(supportgdi > 0) {
797 if(doublebuf > 0) {
798 WARN("Attempting double-buffered gdi format\n");
799 return -1;
801 if(doublebuf < 0)
802 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, False);
805 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
806 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
807 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
808 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
810 /* Set GLX_RENDER_TYPE all the time */
811 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
812 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
814 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
815 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
816 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
817 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
820 return nAttribs;
823 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
825 int render_type=0, render_type_bit;
826 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
827 switch(render_type_bit)
829 case GLX_RGBA_BIT:
830 render_type = GLX_RGBA_TYPE;
831 break;
832 case GLX_COLOR_INDEX_BIT:
833 render_type = GLX_COLOR_INDEX_TYPE;
834 break;
835 case GLX_RGBA_FLOAT_BIT:
836 render_type = GLX_RGBA_FLOAT_TYPE;
837 break;
838 default:
839 ERR("Unknown render_type: %x\n", render_type);
841 return render_type;
844 static BOOL init_formats(Display *display, int screen, Visual *visual)
846 int fmt_id, nCfgs, i, run;
847 GLXFBConfig* cfgs;
848 XVisualInfo *visinfo;
850 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
851 if (NULL == cfgs || 0 == nCfgs) {
852 ERR("glXChooseFBConfig returns NULL\n");
853 if(cfgs != NULL) XFree(cfgs);
854 return FALSE;
857 WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineGLPixelFormat));
859 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
860 * Do this as GLX doesn't guarantee that the list is sorted */
861 for(run=0; run < 2; run++)
863 for(i=0; i<nCfgs; i++) {
864 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
865 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
867 /* The first run we only add onscreen formats (ones which have an associated X Visual).
868 * The second run we only set offscreen formats. */
869 if(!run && visinfo)
871 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
872 * The contents is copied to the destination using XCopyArea. For the copying to work
873 * the depth of the source and destination window should be the same. In general this should
874 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
875 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
876 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
877 * list formats with the same depth. */
878 if(visinfo->depth != screen_depth)
879 continue;
881 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, WineGLPixelFormatListSize+1, i);
882 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
883 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
884 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = fmt_id;
885 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
887 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = FALSE;
888 WineGLPixelFormatListSize++;
889 WineGLPixelFormatOnScreenSize++;
890 XFree(visinfo);
891 } else if(run && !visinfo) {
892 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, WineGLPixelFormatListSize+1, i);
893 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
894 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
895 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = fmt_id;
896 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
898 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
899 WineGLPixelFormatListSize++;
904 if(cfgs != NULL) XFree(cfgs);
906 return TRUE;
909 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
910 * In our WGL implementation we only support a subset of these formats namely the format of
911 * Wine's main visual and offscreen formats (if they are available).
912 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
913 * and it returns the number of supported WGL formats in fmt_count.
915 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
917 WineGLPixelFormat *res = NULL;
919 /* Init the list of pixel formats when we need it */
920 if(!WineGLPixelFormatListSize)
921 init_formats(display, DefaultScreen(display), visual);
923 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
924 * iPixelFormat in case of probing the number of pixelformats.
926 if((iPixelFormat > 0) && (iPixelFormat <= WineGLPixelFormatListSize) &&
927 ((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == FALSE) ||
928 AllowOffscreen)) {
929 res = &WineGLPixelFormatList[iPixelFormat-1];
930 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
933 if(AllowOffscreen)
934 *fmt_count = WineGLPixelFormatListSize;
935 else
936 *fmt_count = WineGLPixelFormatOnScreenSize;
938 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
940 return res;
943 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
944 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
946 int i;
948 /* Init the list of pixel formats when we need it */
949 if(!WineGLPixelFormatListSize)
950 init_formats(display, DefaultScreen(display), visual);
952 for(i=0; i<WineGLPixelFormatListSize; i++) {
953 if(WineGLPixelFormatList[i].fmt_id == fmt_id) {
954 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fmt_id);
955 return &WineGLPixelFormatList[i];
958 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
959 return NULL;
962 int pixelformat_from_fbconfig_id(XID fbconfig_id)
964 WineGLPixelFormat *fmt;
966 if (!fbconfig_id) return 0;
968 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
969 if(fmt)
970 return fmt->iPixelFormat;
971 /* This will happen on hwnds without a pixel format set; it's ok */
972 return 0;
976 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
977 void mark_drawable_dirty(Drawable old, Drawable new)
979 Wine_GLContext *ctx;
980 for (ctx = context_list; ctx; ctx = ctx->next) {
981 if (old == ctx->drawables[0]) {
982 ctx->drawables[0] = new;
983 ctx->refresh_drawables = TRUE;
985 if (old == ctx->drawables[1]) {
986 ctx->drawables[1] = new;
987 ctx->refresh_drawables = TRUE;
992 /* Given the current context, make sure its drawable is sync'd */
993 static inline void sync_context(Wine_GLContext *context)
995 if(context && context->refresh_drawables) {
996 if (glxRequireVersion(3))
997 pglXMakeContextCurrent(gdi_display, context->drawables[0],
998 context->drawables[1], context->ctx);
999 else
1000 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1001 context->refresh_drawables = FALSE;
1006 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1008 return pglXCreateGLXPixmap(display, vis, parent);
1012 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev, WineGLPixelFormat *fmt)
1014 GLXPixmap ret = 0;
1015 XVisualInfo *vis;
1017 wine_tsx11_lock();
1019 vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1020 if(vis) {
1021 if(vis->depth == physDev->bitmap->pixmap_depth)
1022 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
1023 XFree(vis);
1025 wine_tsx11_unlock();
1026 TRACE("return %lx\n", ret);
1027 return ret;
1031 * X11DRV_ChoosePixelFormat
1033 * Equivalent to glXChooseVisual.
1035 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
1036 const PIXELFORMATDESCRIPTOR *ppfd) {
1037 WineGLPixelFormat *fmt = NULL;
1038 int ret = 0;
1039 int nPixelFormats;
1040 int value = 0;
1041 int i = 0;
1042 int bestFormat = -1;
1043 int bestDBuffer = -1;
1044 int bestStereo = -1;
1045 int bestColor = -1;
1046 int bestAlpha = -1;
1047 int bestDepth = -1;
1048 int bestStencil = -1;
1049 int bestAux = -1;
1051 if (!has_opengl()) {
1052 ERR("No libGL on this box - disabling OpenGL support !\n");
1053 return 0;
1056 if (TRACE_ON(wgl)) {
1057 TRACE("(%p,%p)\n", physDev, ppfd);
1059 dump_PIXELFORMATDESCRIPTOR(ppfd);
1062 wine_tsx11_lock();
1063 ConvertPixelFormatWGLtoGLX(gdi_display, 0, FALSE /* offscreen */, &nPixelFormats);
1064 for(i=0; i<nPixelFormats; i++)
1066 int dwFlags = 0;
1067 int iPixelType = 0;
1068 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1070 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, i+1 /* 1-based index */, FALSE /* offscreen */, &value);
1072 /* Pixel type */
1073 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1074 if (value & GLX_RGBA_BIT)
1075 iPixelType = PFD_TYPE_RGBA;
1076 else
1077 iPixelType = PFD_TYPE_COLORINDEX;
1079 if (ppfd->iPixelType != iPixelType)
1081 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1082 continue;
1085 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1086 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1087 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1088 if (value) dwFlags |= PFD_STEREO;
1089 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1090 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1091 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1092 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1093 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1095 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1096 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1097 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1098 * formats without the given flag set.
1099 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1100 * has indicated that a format without stereo is returned when stereo is unavailable.
1101 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1102 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1104 * To summarize the following is most likely the correct behavior:
1105 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1106 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1107 * stereo don't care -> it doesn't matter whether we get stereo or not
1109 * In Wine we will treat no-stereo the same way as don't care because it makes
1110 * format selection even more complicated and second drivers with Stereo advertise
1111 * each format twice anyway.
1114 /* Doublebuffer, see the comments above */
1115 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1116 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1117 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1119 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1120 bestStereo = dwFlags & PFD_STEREO;
1121 bestAlpha = alpha;
1122 bestColor = color;
1123 bestDepth = depth;
1124 bestStencil = stencil;
1125 bestAux = aux;
1126 bestFormat = i;
1127 continue;
1129 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1130 continue;
1133 /* Stereo, see the comments above. */
1134 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1135 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1136 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1138 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1139 bestStereo = dwFlags & PFD_STEREO;
1140 bestAlpha = alpha;
1141 bestColor = color;
1142 bestDepth = depth;
1143 bestStencil = stencil;
1144 bestAux = aux;
1145 bestFormat = i;
1146 continue;
1148 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1149 continue;
1152 /* Below we will do a number of checks to select the 'best' pixelformat.
1153 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1154 * The code works by trying to match the most important options as close as possible.
1155 * When a reasonable format is found, we will try to match more options.
1156 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1157 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1158 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1160 /* Color bits */
1161 if(ppfd->cColorBits) {
1162 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1163 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1165 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1166 bestStereo = dwFlags & PFD_STEREO;
1167 bestAlpha = alpha;
1168 bestColor = color;
1169 bestDepth = depth;
1170 bestStencil = stencil;
1171 bestAux = aux;
1172 bestFormat = i;
1173 continue;
1174 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1175 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1176 continue;
1180 /* Alpha bits */
1181 if(ppfd->cAlphaBits) {
1182 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1183 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1185 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1186 bestStereo = dwFlags & PFD_STEREO;
1187 bestAlpha = alpha;
1188 bestColor = color;
1189 bestDepth = depth;
1190 bestStencil = stencil;
1191 bestAux = aux;
1192 bestFormat = i;
1193 continue;
1194 } else if(bestAlpha != alpha) {
1195 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1196 continue;
1200 /* Depth bits */
1201 if(ppfd->cDepthBits) {
1202 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1203 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1205 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1206 bestStereo = dwFlags & PFD_STEREO;
1207 bestAlpha = alpha;
1208 bestColor = color;
1209 bestDepth = depth;
1210 bestStencil = stencil;
1211 bestAux = aux;
1212 bestFormat = i;
1213 continue;
1214 } else if(bestDepth != depth) {
1215 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1216 continue;
1220 /* Stencil bits */
1221 if(ppfd->cStencilBits) {
1222 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1223 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1225 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1226 bestStereo = dwFlags & PFD_STEREO;
1227 bestAlpha = alpha;
1228 bestColor = color;
1229 bestDepth = depth;
1230 bestStencil = stencil;
1231 bestAux = aux;
1232 bestFormat = i;
1233 continue;
1234 } else if(bestStencil != stencil) {
1235 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1236 continue;
1240 /* Aux buffers */
1241 if(ppfd->cAuxBuffers) {
1242 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1243 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1245 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1246 bestStereo = dwFlags & PFD_STEREO;
1247 bestAlpha = alpha;
1248 bestColor = color;
1249 bestDepth = depth;
1250 bestStencil = stencil;
1251 bestAux = aux;
1252 bestFormat = i;
1253 continue;
1254 } else if(bestAux != aux) {
1255 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1256 continue;
1261 if(bestFormat == -1) {
1262 TRACE("No matching mode was found returning 0\n");
1263 ret = 0;
1265 else {
1266 ret = bestFormat+1; /* the return value should be a 1-based index */
1267 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, WineGLPixelFormatList[bestFormat].fmt_id);
1270 wine_tsx11_unlock();
1272 return ret;
1275 * X11DRV_DescribePixelFormat
1277 * Get the pixel-format descriptor associated to the given id
1279 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1280 int iPixelFormat,
1281 UINT nBytes,
1282 PIXELFORMATDESCRIPTOR *ppfd) {
1283 /*XVisualInfo *vis;*/
1284 int value;
1285 int rb,gb,bb,ab;
1286 WineGLPixelFormat *fmt;
1287 int ret = 0;
1288 int fmt_count = 0;
1290 if (!has_opengl()) {
1291 ERR("No libGL on this box - disabling OpenGL support !\n");
1292 return 0;
1295 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1297 /* 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 */
1298 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1299 if (ppfd == NULL) {
1300 /* The application is only querying the number of pixelformats */
1301 return fmt_count;
1302 } else if(fmt == NULL) {
1303 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1304 return 0;
1307 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1308 ERR("Wrong structure size !\n");
1309 /* Should set error */
1310 return 0;
1313 ret = fmt_count;
1315 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1316 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1317 ppfd->nVersion = 1;
1319 /* These flags are always the same... */
1320 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1321 /* Now the flags extracted from the Visual */
1323 wine_tsx11_lock();
1325 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_X_RENDERABLE, &value);
1326 if(value)
1327 ppfd->dwFlags |= PFD_SUPPORT_GDI;
1329 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1330 if(value & GLX_WINDOW_BIT)
1331 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1332 if(value & GLX_PIXMAP_BIT)
1333 ppfd->dwFlags |= PFD_DRAW_TO_BITMAP;
1335 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1336 if(value == GLX_SLOW_CONFIG)
1337 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1339 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1340 if (value) {
1341 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1342 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1344 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1346 /* Pixel type */
1347 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1348 if (value & GLX_RGBA_BIT)
1349 ppfd->iPixelType = PFD_TYPE_RGBA;
1350 else
1351 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1353 /* Color bits */
1354 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1355 ppfd->cColorBits = value;
1357 /* Red, green, blue and alpha bits / shifts */
1358 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1359 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1360 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1361 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1362 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1364 ppfd->cRedBits = rb;
1365 ppfd->cRedShift = gb + bb + ab;
1366 ppfd->cBlueBits = bb;
1367 ppfd->cBlueShift = ab;
1368 ppfd->cGreenBits = gb;
1369 ppfd->cGreenShift = bb + ab;
1370 ppfd->cAlphaBits = ab;
1371 ppfd->cAlphaShift = 0;
1372 } else {
1373 ppfd->cRedBits = 0;
1374 ppfd->cRedShift = 0;
1375 ppfd->cBlueBits = 0;
1376 ppfd->cBlueShift = 0;
1377 ppfd->cGreenBits = 0;
1378 ppfd->cGreenShift = 0;
1379 ppfd->cAlphaBits = 0;
1380 ppfd->cAlphaShift = 0;
1383 /* Accum RGBA bits */
1384 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1385 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1386 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1387 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1389 ppfd->cAccumBits = rb+gb+bb+ab;
1390 ppfd->cAccumRedBits = rb;
1391 ppfd->cAccumGreenBits = gb;
1392 ppfd->cAccumBlueBits = bb;
1393 ppfd->cAccumAlphaBits = ab;
1395 /* Aux bits */
1396 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1397 ppfd->cAuxBuffers = value;
1399 /* Depth bits */
1400 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1401 ppfd->cDepthBits = value;
1403 /* stencil bits */
1404 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1405 ppfd->cStencilBits = value;
1407 wine_tsx11_unlock();
1409 ppfd->iLayerType = PFD_MAIN_PLANE;
1411 if (TRACE_ON(wgl)) {
1412 dump_PIXELFORMATDESCRIPTOR(ppfd);
1415 return ret;
1419 * X11DRV_GetPixelFormat
1421 * Get the pixel-format id used by this DC
1423 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1424 WineGLPixelFormat *fmt;
1425 int tmp;
1426 TRACE("(%p)\n", physDev);
1428 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1429 if(!fmt)
1431 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1432 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1433 return 0;
1435 else if(fmt->offscreenOnly)
1437 /* Offscreen formats can't be used with traditional WGL calls.
1438 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1439 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1440 return 1;
1443 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1444 return physDev->current_pf;
1447 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1448 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1449 * set the pixel format multiple times. */
1450 static BOOL internal_SetPixelFormat(X11DRV_PDEVICE *physDev,
1451 int iPixelFormat,
1452 const PIXELFORMATDESCRIPTOR *ppfd) {
1453 WineGLPixelFormat *fmt;
1454 int value;
1455 HWND hwnd;
1457 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1458 if(get_glxdrawable(physDev) == root_window)
1460 ERR("Invalid operation on root_window\n");
1461 return FALSE;
1464 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1465 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1466 if(!fmt) {
1467 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1468 return FALSE;
1471 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1473 hwnd = WindowFromDC(physDev->hdc);
1474 if(hwnd) {
1475 if(!(value&GLX_WINDOW_BIT)) {
1476 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1477 return FALSE;
1480 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, (WPARAM)fmt->fmt_id, 0)) {
1481 ERR("Couldn't set format of the window, returning failure\n");
1482 return FALSE;
1485 else if(physDev->bitmap) {
1486 if(!(value&GLX_PIXMAP_BIT)) {
1487 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1488 return FALSE;
1491 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev, fmt);
1492 if(!physDev->bitmap->glxpixmap) {
1493 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat);
1494 return FALSE;
1497 else {
1498 FIXME("called on a non-window, non-bitmap object?\n");
1501 physDev->current_pf = iPixelFormat;
1503 if (TRACE_ON(wgl)) {
1504 int gl_test = 0;
1506 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1507 if (gl_test) {
1508 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1509 } else {
1510 TRACE(" FBConfig have :\n");
1511 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1512 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1513 TRACE(" - VISUAL_ID 0x%x\n", value);
1514 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1515 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1518 return TRUE;
1523 * X11DRV_SetPixelFormat
1525 * Set the pixel-format id used by this DC
1527 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1528 int iPixelFormat,
1529 const PIXELFORMATDESCRIPTOR *ppfd) {
1530 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1532 if (!has_opengl()) {
1533 ERR("No libGL on this box - disabling OpenGL support !\n");
1534 return FALSE;
1537 if(physDev->current_pf) /* cannot change it if already set */
1538 return (physDev->current_pf == iPixelFormat);
1540 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
1544 * X11DRV_wglCopyContext
1546 * For OpenGL32 wglCopyContext.
1548 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
1549 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1550 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1552 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1554 /* There is a slight difference in the way GL contexts share display lists in WGL and GLX.
1555 * In case of GLX you need to specify this at context creation time but in case of WGL you
1556 * do this using wglShareLists which you can call after creating the context.
1557 * To emulate WGL we try to delay the creation of the context until wglShareLists or wglMakeCurrent.
1558 * Up to now that works fine.
1560 * The delayed GLX context creation could cause issues for wglCopyContext as it might get called
1561 * when there is no GLX context yet. The chance this will cause problems is small as at the time of
1562 * writing Wine has had OpenGL support for more than 7 years and this function has remained a stub
1563 * ever since then.
1565 if(!src->ctx || !dst->ctx) {
1566 /* NOTE: As a special case, if both GLX contexts are NULL, that means
1567 * neither WGL context was made current. In that case, both contexts
1568 * are in a default state, so any copy would no-op.
1570 if(!src->ctx && !dst->ctx) {
1571 TRACE("No source or destination contexts set. No-op.\n");
1572 return TRUE;
1575 if (!src->ctx) {
1576 DWORD type = GetObjectType(src->hdc);
1577 wine_tsx11_lock();
1578 if(src->vis)
1579 src->ctx = pglXCreateContext(gdi_display, src->vis, NULL, type == OBJ_MEMDC ? False : True);
1580 else /* Create a GLX Context for a pbuffer */
1581 src->ctx = pglXCreateNewContext(gdi_display, src->fmt->fbconfig, src->fmt->render_type, NULL, True);
1582 TRACE(" created a delayed OpenGL context (%p)\n", src->ctx);
1584 else if (!dst->ctx) {
1585 DWORD type = GetObjectType(dst->hdc);
1586 wine_tsx11_lock();
1587 if(dst->vis)
1588 dst->ctx = pglXCreateContext(gdi_display, dst->vis, NULL, type == OBJ_MEMDC ? False : True);
1589 else /* Create a GLX Context for a pbuffer */
1590 dst->ctx = pglXCreateNewContext(gdi_display, dst->fmt->fbconfig, dst->fmt->render_type, NULL, True);
1591 TRACE(" created a delayed OpenGL context (%p)\n", dst->ctx);
1594 else
1595 wine_tsx11_lock();
1597 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1598 wine_tsx11_unlock();
1600 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1601 return TRUE;
1605 * X11DRV_wglCreateContext
1607 * For OpenGL32 wglCreateContext.
1609 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1611 Wine_GLContext *ret;
1612 WineGLPixelFormat *fmt;
1613 int hdcPF = physDev->current_pf;
1614 int fmt_count = 0;
1615 HDC hdc = physDev->hdc;
1617 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1619 if (!has_opengl()) {
1620 ERR("No libGL on this box - disabling OpenGL support !\n");
1621 return 0;
1624 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1625 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1626 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1627 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1628 * If this fails something is very wrong on the system. */
1629 if(!fmt) {
1630 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1631 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1632 return NULL;
1635 /* The context will be allocated in the wglMakeCurrent call */
1636 wine_tsx11_lock();
1637 ret = alloc_context();
1638 wine_tsx11_unlock();
1639 ret->hdc = hdc;
1640 ret->fmt = fmt;
1642 /*ret->vis = vis;*/
1643 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1645 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1646 return (HGLRC) ret;
1650 * X11DRV_wglDeleteContext
1652 * For OpenGL32 wglDeleteContext.
1654 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1656 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1657 BOOL ret = TRUE;
1659 TRACE("(%p)\n", hglrc);
1661 if (!has_opengl()) {
1662 ERR("No libGL on this box - disabling OpenGL support !\n");
1663 return 0;
1666 wine_tsx11_lock();
1667 /* A game (Half Life not to name it) deletes twice the same context,
1668 * so make sure it is valid first */
1669 if (is_valid_context( ctx ))
1671 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1672 free_context(ctx);
1674 else
1676 WARN("Error deleting context !\n");
1677 SetLastError(ERROR_INVALID_HANDLE);
1678 ret = FALSE;
1680 wine_tsx11_unlock();
1682 return ret;
1686 * X11DRV_wglGetCurrentReadDCARB
1688 * For OpenGL32 wglGetCurrentReadDCARB.
1690 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1692 HDC ret = 0;
1693 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1695 if (ctx) ret = ctx->read_hdc;
1697 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1698 return ret;
1702 * X11DRV_wglGetProcAddress
1704 * For OpenGL32 wglGetProcAddress.
1706 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1708 int i, j;
1709 const WineGLExtension *ext;
1711 int padding = 32 - strlen(lpszProc);
1712 if (padding < 0)
1713 padding = 0;
1715 if (!has_opengl()) {
1716 ERR("No libGL on this box - disabling OpenGL support !\n");
1717 return 0;
1720 /* Check the table of WGL extensions to see if we need to return a WGL extension
1721 * or a function pointer to a native OpenGL function. */
1722 if(strncmp(lpszProc, "wgl", 3) != 0) {
1723 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1724 } else {
1725 TRACE("('%s'):%*s", lpszProc, padding, " ");
1726 for (i = 0; i < WineGLExtensionListSize; ++i) {
1727 ext = WineGLExtensionList[i];
1728 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1729 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1730 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1731 return ext->extEntryPoints[j].funcAddress;
1737 WARN("(%s) - not found\n", lpszProc);
1738 return NULL;
1742 * X11DRV_wglMakeCurrent
1744 * For OpenGL32 wglMakeCurrent.
1746 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1747 BOOL ret;
1748 HDC hdc = physDev->hdc;
1749 DWORD type = GetObjectType(hdc);
1751 TRACE("(%p,%p)\n", hdc, hglrc);
1753 if (!has_opengl()) {
1754 ERR("No libGL on this box - disabling OpenGL support !\n");
1755 return FALSE;
1758 wine_tsx11_lock();
1759 if (hglrc == NULL) {
1760 ret = pglXMakeCurrent(gdi_display, None, NULL);
1761 NtCurrentTeb()->glContext = NULL;
1762 } else {
1763 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1764 Drawable drawable = get_glxdrawable(physDev);
1765 if (ctx->ctx == NULL) {
1766 /* The describe lines below are for debugging purposes only */
1767 if (TRACE_ON(wgl)) {
1768 describeDrawable(ctx, drawable);
1769 describeContext(ctx);
1772 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1773 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1775 TRACE(" Creating GLX Context\n");
1776 if(ctx->vis)
1777 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1778 else /* Create a GLX Context for a pbuffer */
1779 ctx->ctx = pglXCreateNewContext(gdi_display, ctx->fmt->fbconfig, ctx->fmt->render_type, NULL, True);
1781 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1783 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1784 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1785 NtCurrentTeb()->glContext = ctx;
1786 if(ret)
1788 ctx->hdc = hdc;
1789 ctx->read_hdc = hdc;
1790 ctx->drawables[0] = drawable;
1791 ctx->drawables[1] = drawable;
1792 ctx->refresh_drawables = FALSE;
1794 if (type == OBJ_MEMDC)
1796 ctx->do_escape = TRUE;
1797 pglDrawBuffer(GL_FRONT_LEFT);
1801 wine_tsx11_unlock();
1802 TRACE(" returning %s\n", (ret ? "True" : "False"));
1803 return ret;
1807 * X11DRV_wglMakeContextCurrentARB
1809 * For OpenGL32 wglMakeContextCurrentARB
1811 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1813 BOOL ret;
1814 int indirect = (GetObjectType(pDrawDev->hdc) == OBJ_MEMDC);
1816 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1818 if (!has_opengl()) {
1819 ERR("No libGL on this box - disabling OpenGL support !\n");
1820 return 0;
1823 wine_tsx11_lock();
1824 if (hglrc == NULL) {
1825 ret = pglXMakeCurrent(gdi_display, None, NULL);
1826 NtCurrentTeb()->glContext = NULL;
1827 } else {
1828 if (NULL == pglXMakeContextCurrent) {
1829 ret = FALSE;
1830 } else {
1831 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1832 Drawable d_draw = get_glxdrawable(pDrawDev);
1833 Drawable d_read = get_glxdrawable(pReadDev);
1835 if (ctx->ctx == NULL) {
1836 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, !indirect);
1837 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1839 ctx->hdc = pDrawDev->hdc;
1840 ctx->read_hdc = pReadDev->hdc;
1841 ctx->drawables[0] = d_draw;
1842 ctx->drawables[1] = d_read;
1843 ctx->refresh_drawables = FALSE;
1844 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1845 NtCurrentTeb()->glContext = ctx;
1848 wine_tsx11_unlock();
1850 TRACE(" returning %s\n", (ret ? "True" : "False"));
1851 return ret;
1855 * X11DRV_wglShareLists
1857 * For OpenGL32 wglShaderLists.
1859 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1860 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1861 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1863 TRACE("(%p, %p)\n", org, dest);
1865 if (!has_opengl()) {
1866 ERR("No libGL on this box - disabling OpenGL support !\n");
1867 return 0;
1870 if (NULL != dest && dest->ctx != NULL) {
1871 ERR("Could not share display lists, context already created !\n");
1872 return FALSE;
1873 } else {
1874 if (org->ctx == NULL) {
1875 int indirect = (GetObjectType(org->hdc) == OBJ_MEMDC);
1876 wine_tsx11_lock();
1877 describeContext(org);
1879 if(org->vis)
1880 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, !indirect);
1881 else /* Create a GLX Context for a pbuffer */
1882 org->ctx = pglXCreateNewContext(gdi_display, org->fmt->fbconfig, org->fmt->render_type, NULL, True);
1883 wine_tsx11_unlock();
1884 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1886 if (NULL != dest) {
1887 int indirect = (GetObjectType(dest->hdc) == OBJ_MEMDC);
1888 wine_tsx11_lock();
1889 describeContext(dest);
1890 /* Create the destination context with display lists shared */
1891 if(dest->vis)
1892 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, !indirect);
1893 else /* Create a GLX Context for a pbuffer */
1894 dest->ctx = pglXCreateNewContext(gdi_display, dest->fmt->fbconfig, dest->fmt->render_type, org->ctx, True);
1895 wine_tsx11_unlock();
1896 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1897 return TRUE;
1900 return FALSE;
1903 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1905 /* We are running using client-side rendering fonts... */
1906 GLYPHMETRICS gm;
1907 unsigned int glyph;
1908 int size = 0;
1909 void *bitmap = NULL, *gl_bitmap = NULL;
1910 int org_alignment;
1912 wine_tsx11_lock();
1913 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1914 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1915 wine_tsx11_unlock();
1917 for (glyph = first; glyph < first + count; glyph++) {
1918 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1919 int height, width_int;
1921 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1922 if (needed_size == GDI_ERROR) {
1923 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1924 goto error;
1925 } else {
1926 TRACE(" - needed size : %d\n", needed_size);
1929 if (needed_size > size) {
1930 size = needed_size;
1931 HeapFree(GetProcessHeap(), 0, bitmap);
1932 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1933 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1934 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1936 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1937 if (TRACE_ON(wgl)) {
1938 unsigned int height, width, bitmask;
1939 unsigned char *bitmap_ = (unsigned char *) bitmap;
1941 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1942 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1943 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1944 if (needed_size != 0) {
1945 TRACE(" - bitmap :\n");
1946 for (height = 0; height < gm.gmBlackBoxY; height++) {
1947 TRACE(" ");
1948 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1949 if (bitmask == 0) {
1950 bitmap_ += 1;
1951 bitmask = 0x80;
1953 if (*bitmap_ & bitmask)
1954 TRACE("*");
1955 else
1956 TRACE(" ");
1958 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1959 TRACE("\n");
1964 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1965 * glyph for it to be drawn properly.
1967 if (needed_size != 0) {
1968 width_int = (gm.gmBlackBoxX + 31) / 32;
1969 for (height = 0; height < gm.gmBlackBoxY; height++) {
1970 int width;
1971 for (width = 0; width < width_int; width++) {
1972 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1973 ((int *) bitmap)[height * width_int + width];
1978 wine_tsx11_lock();
1979 pglNewList(listBase++, GL_COMPILE);
1980 if (needed_size != 0) {
1981 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1982 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
1983 gm.gmCellIncX, gm.gmCellIncY,
1984 gl_bitmap);
1985 } else {
1986 /* This is the case of 'empty' glyphs like the space character */
1987 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1989 pglEndList();
1990 wine_tsx11_unlock();
1993 wine_tsx11_lock();
1994 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1995 wine_tsx11_unlock();
1997 HeapFree(GetProcessHeap(), 0, bitmap);
1998 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1999 return TRUE;
2001 error:
2002 wine_tsx11_lock();
2003 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2004 wine_tsx11_unlock();
2006 HeapFree(GetProcessHeap(), 0, bitmap);
2007 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2008 return FALSE;
2012 * X11DRV_wglUseFontBitmapsA
2014 * For OpenGL32 wglUseFontBitmapsA.
2016 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2018 Font fid = physDev->font;
2020 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2022 if (!has_opengl()) {
2023 ERR("No libGL on this box - disabling OpenGL support !\n");
2024 return 0;
2027 if (fid == 0) {
2028 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
2031 wine_tsx11_lock();
2032 /* I assume that the glyphs are at the same position for X and for Windows */
2033 pglXUseXFont(fid, first, count, listBase);
2034 wine_tsx11_unlock();
2035 return TRUE;
2039 * X11DRV_wglUseFontBitmapsW
2041 * For OpenGL32 wglUseFontBitmapsW.
2043 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2045 Font fid = physDev->font;
2047 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2049 if (!has_opengl()) {
2050 ERR("No libGL on this box - disabling OpenGL support !\n");
2051 return 0;
2054 if (fid == 0) {
2055 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
2058 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2060 wine_tsx11_lock();
2061 /* I assume that the glyphs are at the same position for X and for Windows */
2062 pglXUseXFont(fid, first, count, listBase);
2063 wine_tsx11_unlock();
2064 return TRUE;
2067 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2068 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2070 wine_tsx11_lock();
2071 switch(pname)
2073 case GL_DEPTH_BITS:
2075 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2077 pglGetIntegerv(pname, params);
2079 * if we cannot find a Wine Context
2080 * we only have the default wine desktop context,
2081 * so if we have only a 24 depth say we have 32
2083 if (!ctx && *params == 24) {
2084 *params = 32;
2086 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2087 break;
2089 case GL_ALPHA_BITS:
2091 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2093 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2094 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2095 break;
2097 default:
2098 pglGetIntegerv(pname, params);
2099 break;
2101 wine_tsx11_unlock();
2104 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
2106 int w, h;
2108 if(!physDev->gl_drawable)
2109 return;
2111 w = physDev->dc_rect.right - physDev->dc_rect.left;
2112 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
2114 if(w > 0 && h > 0) {
2115 Drawable src = physDev->pixmap;
2116 if(!src) src = physDev->gl_drawable;
2118 /* The GL drawable may be lagged behind if we don't flush first, so
2119 * flush the display make sure we copy up-to-date data */
2120 wine_tsx11_lock();
2121 XFlush(gdi_display);
2122 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
2123 physDev->dc_rect.left, physDev->dc_rect.top);
2124 wine_tsx11_unlock();
2129 static void WINAPI X11DRV_wglFinish(void)
2131 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2132 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2134 wine_tsx11_lock();
2135 sync_context(ctx);
2136 pglFinish();
2137 wine_tsx11_unlock();
2138 ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2141 static void WINAPI X11DRV_wglFlush(void)
2143 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2144 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2146 wine_tsx11_lock();
2147 sync_context(ctx);
2148 pglFlush();
2149 wine_tsx11_unlock();
2150 ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2154 * X11DRV_wglGetExtensionsStringARB
2156 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2158 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2159 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2160 return WineGLInfo.wglExtensions;
2164 * X11DRV_wglCreatePbufferARB
2166 * WGL_ARB_pbuffer: wglCreatePbufferARB
2168 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2170 Wine_GLPBuffer* object = NULL;
2171 WineGLPixelFormat *fmt = NULL;
2172 int nCfgs = 0;
2173 int attribs[256];
2174 int nAttribs = 0;
2176 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2178 if (0 >= iPixelFormat) {
2179 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2180 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2181 return NULL; /* unexpected error */
2184 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2185 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2186 if(!fmt) {
2187 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2188 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2189 goto create_failed; /* unexpected error */
2192 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2193 if (NULL == object) {
2194 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2195 goto create_failed; /* unexpected error */
2197 object->hdc = hdc;
2198 object->display = gdi_display;
2199 object->width = iWidth;
2200 object->height = iHeight;
2201 object->fmt = fmt;
2203 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2204 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2205 while (piAttribList && 0 != *piAttribList) {
2206 int attr_v;
2207 switch (*piAttribList) {
2208 case WGL_PBUFFER_LARGEST_ARB: {
2209 ++piAttribList;
2210 attr_v = *piAttribList;
2211 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2212 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2213 break;
2216 case WGL_TEXTURE_FORMAT_ARB: {
2217 ++piAttribList;
2218 attr_v = *piAttribList;
2219 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2220 if (use_render_texture_ati) {
2221 int type = 0;
2222 switch (attr_v) {
2223 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2224 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2225 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2226 default:
2227 SetLastError(ERROR_INVALID_DATA);
2228 goto create_failed;
2230 object->use_render_texture = 1;
2231 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2232 } else {
2233 if (WGL_NO_TEXTURE_ARB == attr_v) {
2234 object->use_render_texture = 0;
2235 } else {
2236 if (!use_render_texture_emulation) {
2237 SetLastError(ERROR_INVALID_DATA);
2238 goto create_failed;
2240 switch (attr_v) {
2241 case WGL_TEXTURE_RGB_ARB:
2242 object->use_render_texture = GL_RGB;
2243 object->texture_bpp = 3;
2244 object->texture_format = GL_RGB;
2245 object->texture_type = GL_UNSIGNED_BYTE;
2246 break;
2247 case WGL_TEXTURE_RGBA_ARB:
2248 object->use_render_texture = GL_RGBA;
2249 object->texture_bpp = 4;
2250 object->texture_format = GL_RGBA;
2251 object->texture_type = GL_UNSIGNED_BYTE;
2252 break;
2254 /* WGL_FLOAT_COMPONENTS_NV */
2255 case WGL_TEXTURE_FLOAT_R_NV:
2256 object->use_render_texture = GL_FLOAT_R_NV;
2257 object->texture_bpp = 4;
2258 object->texture_format = GL_RED;
2259 object->texture_type = GL_FLOAT;
2260 break;
2261 case WGL_TEXTURE_FLOAT_RG_NV:
2262 object->use_render_texture = GL_FLOAT_RG_NV;
2263 object->texture_bpp = 8;
2264 object->texture_format = GL_LUMINANCE_ALPHA;
2265 object->texture_type = GL_FLOAT;
2266 break;
2267 case WGL_TEXTURE_FLOAT_RGB_NV:
2268 object->use_render_texture = GL_FLOAT_RGB_NV;
2269 object->texture_bpp = 12;
2270 object->texture_format = GL_RGB;
2271 object->texture_type = GL_FLOAT;
2272 break;
2273 case WGL_TEXTURE_FLOAT_RGBA_NV:
2274 object->use_render_texture = GL_FLOAT_RGBA_NV;
2275 object->texture_bpp = 16;
2276 object->texture_format = GL_RGBA;
2277 object->texture_type = GL_FLOAT;
2278 break;
2279 default:
2280 ERR("Unknown texture format: %x\n", attr_v);
2281 SetLastError(ERROR_INVALID_DATA);
2282 goto create_failed;
2286 break;
2289 case WGL_TEXTURE_TARGET_ARB: {
2290 ++piAttribList;
2291 attr_v = *piAttribList;
2292 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2293 if (use_render_texture_ati) {
2294 int type = 0;
2295 switch (attr_v) {
2296 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2297 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2298 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2299 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2300 default:
2301 SetLastError(ERROR_INVALID_DATA);
2302 goto create_failed;
2304 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2305 } else {
2306 if (WGL_NO_TEXTURE_ARB == attr_v) {
2307 object->texture_target = 0;
2308 } else {
2309 if (!use_render_texture_emulation) {
2310 SetLastError(ERROR_INVALID_DATA);
2311 goto create_failed;
2313 switch (attr_v) {
2314 case WGL_TEXTURE_CUBE_MAP_ARB: {
2315 if (iWidth != iHeight) {
2316 SetLastError(ERROR_INVALID_DATA);
2317 goto create_failed;
2319 object->texture_target = GL_TEXTURE_CUBE_MAP;
2320 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2321 break;
2323 case WGL_TEXTURE_1D_ARB: {
2324 if (1 != iHeight) {
2325 SetLastError(ERROR_INVALID_DATA);
2326 goto create_failed;
2328 object->texture_target = GL_TEXTURE_1D;
2329 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2330 break;
2332 case WGL_TEXTURE_2D_ARB: {
2333 object->texture_target = GL_TEXTURE_2D;
2334 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2335 break;
2337 case WGL_TEXTURE_RECTANGLE_NV: {
2338 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2339 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2340 break;
2342 default:
2343 ERR("Unknown texture target: %x\n", attr_v);
2344 SetLastError(ERROR_INVALID_DATA);
2345 goto create_failed;
2349 break;
2352 case WGL_MIPMAP_TEXTURE_ARB: {
2353 ++piAttribList;
2354 attr_v = *piAttribList;
2355 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2356 if (use_render_texture_ati) {
2357 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2358 } else {
2359 if (!use_render_texture_emulation) {
2360 SetLastError(ERROR_INVALID_DATA);
2361 goto create_failed;
2364 break;
2367 ++piAttribList;
2370 PUSH1(attribs, None);
2371 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2372 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2373 if (!object->drawable) {
2374 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2375 goto create_failed; /* unexpected error */
2377 TRACE("->(%p)\n", object);
2378 return (HPBUFFERARB) object;
2380 create_failed:
2381 HeapFree(GetProcessHeap(), 0, object);
2382 TRACE("->(FAILED)\n");
2383 return NULL;
2387 * X11DRV_wglDestroyPbufferARB
2389 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2391 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2393 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2394 TRACE("(%p)\n", hPbuffer);
2395 if (NULL == object) {
2396 SetLastError(ERROR_INVALID_HANDLE);
2397 return GL_FALSE;
2399 pglXDestroyPbuffer(object->display, object->drawable);
2400 HeapFree(GetProcessHeap(), 0, object);
2401 return GL_TRUE;
2405 * X11DRV_wglGetPbufferDCARB
2407 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2408 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2409 * Gdi32 implements the part of this function which creates a device context.
2410 * This part associates the physDev with the X drawable of the pbuffer.
2412 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2414 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2415 if (NULL == object) {
2416 SetLastError(ERROR_INVALID_HANDLE);
2417 return NULL;
2420 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2421 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2422 physDev->current_pf = object->fmt->iPixelFormat;
2423 physDev->drawable = object->drawable;
2424 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2425 physDev->dc_rect = physDev->drawable_rect;
2427 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2428 return physDev->hdc;
2432 * X11DRV_wglQueryPbufferARB
2434 * WGL_ARB_pbuffer: wglQueryPbufferARB
2436 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2438 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2439 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2440 if (NULL == object) {
2441 SetLastError(ERROR_INVALID_HANDLE);
2442 return GL_FALSE;
2444 switch (iAttribute) {
2445 case WGL_PBUFFER_WIDTH_ARB:
2446 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2447 break;
2448 case WGL_PBUFFER_HEIGHT_ARB:
2449 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2450 break;
2452 case WGL_PBUFFER_LOST_ARB:
2453 /* GLX Pbuffers cannot be lost by default. We can support this by
2454 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2455 * to receive pixel buffer clobber events, however that may or may
2456 * not give any benefit */
2457 *piValue = GL_FALSE;
2458 break;
2460 case WGL_TEXTURE_FORMAT_ARB:
2461 if (use_render_texture_ati) {
2462 unsigned int tmp;
2463 int type = WGL_NO_TEXTURE_ARB;
2464 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2465 switch (tmp) {
2466 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2467 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2468 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2470 *piValue = type;
2471 } else {
2472 if (!object->use_render_texture) {
2473 *piValue = WGL_NO_TEXTURE_ARB;
2474 } else {
2475 if (!use_render_texture_emulation) {
2476 SetLastError(ERROR_INVALID_HANDLE);
2477 return GL_FALSE;
2479 switch(object->use_render_texture) {
2480 case GL_RGB:
2481 *piValue = WGL_TEXTURE_RGB_ARB;
2482 break;
2483 case GL_RGBA:
2484 *piValue = WGL_TEXTURE_RGBA_ARB;
2485 break;
2486 /* WGL_FLOAT_COMPONENTS_NV */
2487 case GL_FLOAT_R_NV:
2488 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2489 break;
2490 case GL_FLOAT_RG_NV:
2491 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2492 break;
2493 case GL_FLOAT_RGB_NV:
2494 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2495 break;
2496 case GL_FLOAT_RGBA_NV:
2497 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2498 break;
2499 default:
2500 ERR("Unknown texture format: %x\n", object->use_render_texture);
2504 break;
2506 case WGL_TEXTURE_TARGET_ARB:
2507 if (use_render_texture_ati) {
2508 unsigned int tmp;
2509 int type = WGL_NO_TEXTURE_ARB;
2510 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2511 switch (tmp) {
2512 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2513 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2514 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2515 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2517 *piValue = type;
2518 } else {
2519 if (!object->texture_target) {
2520 *piValue = WGL_NO_TEXTURE_ARB;
2521 } else {
2522 if (!use_render_texture_emulation) {
2523 SetLastError(ERROR_INVALID_DATA);
2524 return GL_FALSE;
2526 switch (object->texture_target) {
2527 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2528 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2529 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2530 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2534 break;
2536 case WGL_MIPMAP_TEXTURE_ARB:
2537 if (use_render_texture_ati) {
2538 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2539 } else {
2540 *piValue = GL_FALSE; /** don't support that */
2541 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2543 break;
2545 default:
2546 FIXME("unexpected attribute %x\n", iAttribute);
2547 break;
2550 return GL_TRUE;
2554 * X11DRV_wglReleasePbufferDCARB
2556 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2558 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2560 TRACE("(%p, %p)\n", hPbuffer, hdc);
2561 return DeleteDC(hdc);
2565 * X11DRV_wglSetPbufferAttribARB
2567 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2569 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2571 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2572 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2573 if (NULL == object) {
2574 SetLastError(ERROR_INVALID_HANDLE);
2575 return GL_FALSE;
2577 if (!object->use_render_texture) {
2578 SetLastError(ERROR_INVALID_HANDLE);
2579 return GL_FALSE;
2581 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2582 return GL_TRUE;
2584 if (NULL != pglXDrawableAttribATI) {
2585 if (use_render_texture_ati) {
2586 FIXME("Need conversion for GLX_ATI_render_texture\n");
2588 return pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2590 return GL_FALSE;
2594 * X11DRV_wglChoosePixelFormatARB
2596 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2598 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2600 int gl_test = 0;
2601 int attribs[256];
2602 int nAttribs = 0;
2603 GLXFBConfig* cfgs = NULL;
2604 int nCfgs = 0;
2605 UINT it;
2606 int fmt_id;
2607 WineGLPixelFormat *fmt;
2608 int pfmt_it = 0;
2609 int run;
2611 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2612 if (NULL != pfAttribFList) {
2613 FIXME("unused pfAttribFList\n");
2616 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2617 if (-1 == nAttribs) {
2618 WARN("Cannot convert WGL to GLX attributes\n");
2619 return GL_FALSE;
2621 PUSH1(attribs, None);
2623 /* Search for FB configurations matching the requirements in attribs */
2624 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2625 if (NULL == cfgs) {
2626 WARN("Compatible Pixel Format not found\n");
2627 return GL_FALSE;
2630 /* Loop through all matching formats and check if they are suitable.
2631 * Note that this function should at max return nMaxFormats different formats */
2632 for(run=0; run < 2; run++)
2634 for (it = 0; it < nCfgs; ++it) {
2635 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2636 if (gl_test) {
2637 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2638 continue;
2641 /* Search for the format in our list of compatible formats */
2642 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2643 if(!fmt)
2644 continue;
2646 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2647 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2648 continue;
2650 if(pfmt_it < nMaxFormats) {
2651 piFormats[pfmt_it] = fmt->iPixelFormat;
2652 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2654 pfmt_it++;
2658 *nNumFormats = pfmt_it;
2659 /** free list */
2660 XFree(cfgs);
2661 return GL_TRUE;
2665 * X11DRV_wglGetPixelFormatAttribivARB
2667 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2669 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2671 UINT i;
2672 WineGLPixelFormat *fmt = NULL;
2673 int hTest;
2674 int tmp;
2675 int curGLXAttr = 0;
2676 int nWGLFormats = 0;
2678 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2680 if (0 < iLayerPlane) {
2681 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2682 return GL_FALSE;
2685 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2686 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2687 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2688 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2689 if(!fmt) {
2690 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2693 for (i = 0; i < nAttributes; ++i) {
2694 const int curWGLAttr = piAttributes[i];
2695 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2697 switch (curWGLAttr) {
2698 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2699 piValues[i] = nWGLFormats;
2700 continue;
2702 case WGL_SUPPORT_OPENGL_ARB:
2703 piValues[i] = GL_TRUE;
2704 continue;
2706 case WGL_ACCELERATION_ARB:
2707 curGLXAttr = GLX_CONFIG_CAVEAT;
2708 if (!fmt) goto pix_error;
2709 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2710 if (hTest) goto get_error;
2711 switch (tmp) {
2712 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2713 case GLX_SLOW_CONFIG: piValues[i] = WGL_GENERIC_ACCELERATION_ARB; break;
2714 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2715 default:
2716 ERR("unexpected Config Caveat(%x)\n", tmp);
2717 piValues[i] = WGL_NO_ACCELERATION_ARB;
2719 continue;
2721 case WGL_TRANSPARENT_ARB:
2722 curGLXAttr = GLX_TRANSPARENT_TYPE;
2723 if (!fmt) goto pix_error;
2724 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2725 if (hTest) goto get_error;
2726 piValues[i] = GL_FALSE;
2727 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2728 continue;
2730 case WGL_PIXEL_TYPE_ARB:
2731 curGLXAttr = GLX_RENDER_TYPE;
2732 if (!fmt) goto pix_error;
2733 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2734 if (hTest) goto get_error;
2735 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2736 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2737 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2738 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2739 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2740 else {
2741 ERR("unexpected RenderType(%x)\n", tmp);
2742 piValues[i] = WGL_TYPE_RGBA_ARB;
2744 continue;
2746 case WGL_COLOR_BITS_ARB:
2747 curGLXAttr = GLX_BUFFER_SIZE;
2748 break;
2750 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2751 if (use_render_texture_ati) {
2752 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2753 break;
2755 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2756 if (use_render_texture_ati) {
2757 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2758 break;
2760 if (!use_render_texture_emulation) {
2761 piValues[i] = GL_FALSE;
2762 continue;
2764 curGLXAttr = GLX_RENDER_TYPE;
2765 if (!fmt) goto pix_error;
2766 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2767 if (hTest) goto get_error;
2768 if (GLX_COLOR_INDEX_BIT == tmp) {
2769 piValues[i] = GL_FALSE;
2770 continue;
2772 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2773 if (hTest) goto get_error;
2774 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2775 continue;
2777 case WGL_BLUE_BITS_ARB:
2778 curGLXAttr = GLX_BLUE_SIZE;
2779 break;
2780 case WGL_RED_BITS_ARB:
2781 curGLXAttr = GLX_RED_SIZE;
2782 break;
2783 case WGL_GREEN_BITS_ARB:
2784 curGLXAttr = GLX_GREEN_SIZE;
2785 break;
2786 case WGL_ALPHA_BITS_ARB:
2787 curGLXAttr = GLX_ALPHA_SIZE;
2788 break;
2789 case WGL_DEPTH_BITS_ARB:
2790 curGLXAttr = GLX_DEPTH_SIZE;
2791 break;
2792 case WGL_STENCIL_BITS_ARB:
2793 curGLXAttr = GLX_STENCIL_SIZE;
2794 break;
2795 case WGL_DOUBLE_BUFFER_ARB:
2796 curGLXAttr = GLX_DOUBLEBUFFER;
2797 break;
2798 case WGL_STEREO_ARB:
2799 curGLXAttr = GLX_STEREO;
2800 break;
2801 case WGL_AUX_BUFFERS_ARB:
2802 curGLXAttr = GLX_AUX_BUFFERS;
2803 break;
2805 case WGL_SUPPORT_GDI_ARB:
2806 if (!fmt) goto pix_error;
2807 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &tmp);
2808 if (hTest) goto get_error;
2809 if(tmp) {
2810 piValues[i] = GL_FALSE;
2811 continue;
2813 curGLXAttr = GLX_X_RENDERABLE;
2814 break;
2816 case WGL_DRAW_TO_WINDOW_ARB:
2817 case WGL_DRAW_TO_BITMAP_ARB:
2818 case WGL_DRAW_TO_PBUFFER_ARB:
2819 if (!fmt) goto pix_error;
2820 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2821 if (hTest) goto get_error;
2822 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2823 (curWGLAttr == WGL_DRAW_TO_BITMAP_ARB && (tmp&GLX_PIXMAP_BIT)) ||
2824 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2825 piValues[i] = GL_TRUE;
2826 else
2827 piValues[i] = GL_FALSE;
2828 continue;
2830 case WGL_PBUFFER_LARGEST_ARB:
2831 curGLXAttr = GLX_LARGEST_PBUFFER;
2832 break;
2834 case WGL_SAMPLE_BUFFERS_ARB:
2835 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2836 break;
2838 case WGL_SAMPLES_ARB:
2839 curGLXAttr = GLX_SAMPLES_ARB;
2840 break;
2842 case WGL_FLOAT_COMPONENTS_NV:
2843 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2844 break;
2846 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2847 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2848 break;
2850 case WGL_ACCUM_RED_BITS_ARB:
2851 curGLXAttr = GLX_ACCUM_RED_SIZE;
2852 break;
2853 case WGL_ACCUM_GREEN_BITS_ARB:
2854 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2855 break;
2856 case WGL_ACCUM_BLUE_BITS_ARB:
2857 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2858 break;
2859 case WGL_ACCUM_ALPHA_BITS_ARB:
2860 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2861 break;
2862 case WGL_ACCUM_BITS_ARB:
2863 if (!fmt) goto pix_error;
2864 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2865 if (hTest) goto get_error;
2866 piValues[i] = tmp;
2867 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2868 if (hTest) goto get_error;
2869 piValues[i] += tmp;
2870 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2871 if (hTest) goto get_error;
2872 piValues[i] += tmp;
2873 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2874 if (hTest) goto get_error;
2875 piValues[i] += tmp;
2876 continue;
2878 default:
2879 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2882 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2883 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2884 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2886 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2887 * and check which options can work using iPixelFormat=0 and which not.
2888 * A problem would be that this function is an extension. This would
2889 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2891 if (0 != curGLXAttr && iPixelFormat != 0) {
2892 if (!fmt) goto pix_error;
2893 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2894 if (hTest) goto get_error;
2895 curGLXAttr = 0;
2896 } else {
2897 piValues[i] = GL_FALSE;
2900 return GL_TRUE;
2902 get_error:
2903 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2904 return GL_FALSE;
2906 pix_error:
2907 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2908 return GL_FALSE;
2912 * X11DRV_wglGetPixelFormatAttribfvARB
2914 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2916 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2918 int *attr;
2919 int ret;
2920 int i;
2922 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2924 /* Allocate a temporary array to store integer values */
2925 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2926 if (!attr) {
2927 ERR("couldn't allocate %d array\n", nAttributes);
2928 return GL_FALSE;
2931 /* Piggy-back on wglGetPixelFormatAttribivARB */
2932 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2933 if (ret) {
2934 /* Convert integer values to float. Should also check for attributes
2935 that can give decimal values here */
2936 for (i=0; i<nAttributes;i++) {
2937 pfValues[i] = attr[i];
2941 HeapFree(GetProcessHeap(), 0, attr);
2942 return ret;
2946 * X11DRV_wglBindTexImageARB
2948 * WGL_ARB_render_texture: wglBindTexImageARB
2950 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2952 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2953 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2954 if (NULL == object) {
2955 SetLastError(ERROR_INVALID_HANDLE);
2956 return GL_FALSE;
2958 if (!object->use_render_texture) {
2959 SetLastError(ERROR_INVALID_HANDLE);
2960 return GL_FALSE;
2963 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2964 static int init = 0;
2965 int prev_binded_texture = 0;
2966 GLXContext prev_context = pglXGetCurrentContext();
2967 Drawable prev_drawable = pglXGetCurrentDrawable();
2968 GLXContext tmp_context;
2970 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2971 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2972 isn't ideal performance wise but I wasn't able to get other ways working.
2974 if(!init) {
2975 init = 1; /* Only show the FIXME once for performance reasons */
2976 FIXME("partial stub!\n");
2979 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
2980 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2982 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2984 /* Switch to our pbuffer */
2985 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2987 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2988 * After that upload the pbuffer texture data. */
2989 pglBindTexture(object->texture_target, prev_binded_texture);
2990 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2992 /* Switch back to the original drawable and upload the pbuffer-texture */
2993 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2994 pglXDestroyContext(gdi_display, tmp_context);
2995 return GL_TRUE;
2998 if (NULL != pglXBindTexImageATI) {
2999 int buffer;
3001 switch(iBuffer)
3003 case WGL_FRONT_LEFT_ARB:
3004 buffer = GLX_FRONT_LEFT_ATI;
3005 break;
3006 case WGL_FRONT_RIGHT_ARB:
3007 buffer = GLX_FRONT_RIGHT_ATI;
3008 break;
3009 case WGL_BACK_LEFT_ARB:
3010 buffer = GLX_BACK_LEFT_ATI;
3011 break;
3012 case WGL_BACK_RIGHT_ARB:
3013 buffer = GLX_BACK_RIGHT_ATI;
3014 break;
3015 default:
3016 ERR("Unknown iBuffer=%#x\n", iBuffer);
3017 return FALSE;
3020 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3021 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3022 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3023 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3024 * works fine using our pbuffer emulation path.
3026 return pglXBindTexImageATI(object->display, object->drawable, buffer);
3028 return GL_FALSE;
3032 * X11DRV_wglReleaseTexImageARB
3034 * WGL_ARB_render_texture: wglReleaseTexImageARB
3036 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3038 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
3039 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3040 if (NULL == object) {
3041 SetLastError(ERROR_INVALID_HANDLE);
3042 return GL_FALSE;
3044 if (!object->use_render_texture) {
3045 SetLastError(ERROR_INVALID_HANDLE);
3046 return GL_FALSE;
3048 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3049 return GL_TRUE;
3051 if (NULL != pglXReleaseTexImageATI) {
3052 int buffer;
3054 switch(iBuffer)
3056 case WGL_FRONT_LEFT_ARB:
3057 buffer = GLX_FRONT_LEFT_ATI;
3058 break;
3059 case WGL_FRONT_RIGHT_ARB:
3060 buffer = GLX_FRONT_RIGHT_ATI;
3061 break;
3062 case WGL_BACK_LEFT_ARB:
3063 buffer = GLX_BACK_LEFT_ATI;
3064 break;
3065 case WGL_BACK_RIGHT_ARB:
3066 buffer = GLX_BACK_RIGHT_ATI;
3067 break;
3068 default:
3069 ERR("Unknown iBuffer=%#x\n", iBuffer);
3070 return FALSE;
3072 return pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3074 return GL_FALSE;
3078 * X11DRV_wglGetExtensionsStringEXT
3080 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3082 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3083 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3084 return WineGLInfo.wglExtensions;
3088 * X11DRV_wglGetSwapIntervalEXT
3090 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3092 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3093 FIXME("(),stub!\n");
3094 return swap_interval;
3098 * X11DRV_wglSwapIntervalEXT
3100 * WGL_EXT_swap_control: wglSwapIntervalEXT
3102 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3103 TRACE("(%d)\n", interval);
3104 swap_interval = interval;
3105 if (NULL != pglXSwapIntervalSGI) {
3106 return 0 == pglXSwapIntervalSGI(interval);
3108 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3109 return TRUE;
3113 * X11DRV_wglAllocateMemoryNV
3115 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3117 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3118 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3119 if (pglXAllocateMemoryNV == NULL)
3120 return NULL;
3122 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3126 * X11DRV_wglFreeMemoryNV
3128 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3130 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3131 TRACE("(%p)\n", pointer);
3132 if (pglXFreeMemoryNV == NULL)
3133 return;
3135 pglXFreeMemoryNV(pointer);
3139 * X11DRV_wglSetPixelFormatWINE
3141 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3142 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3144 BOOL X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3146 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
3148 if (!has_opengl()) {
3149 ERR("No libGL on this box - disabling OpenGL support !\n");
3150 return FALSE;
3153 if (physDev->current_pf == iPixelFormat) return TRUE;
3155 /* Relay to the core SetPixelFormat */
3156 TRACE("Changing iPixelFormat from %d to %d\n", physDev->current_pf, iPixelFormat);
3157 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
3161 * glxRequireVersion (internal)
3163 * Check if the supported GLX version matches requiredVersion.
3165 static BOOL glxRequireVersion(int requiredVersion)
3167 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3168 if(requiredVersion <= WineGLInfo.glxVersion[1])
3169 return TRUE;
3171 return FALSE;
3174 static BOOL glxRequireExtension(const char *requiredExtension)
3176 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3177 return FALSE;
3180 return TRUE;
3183 static void register_extension_string(const char *ext)
3185 if (WineGLInfo.wglExtensions[0])
3186 strcat(WineGLInfo.wglExtensions, " ");
3187 strcat(WineGLInfo.wglExtensions, ext);
3189 TRACE("'%s'\n", ext);
3192 static BOOL register_extension(const WineGLExtension * ext)
3194 int i;
3196 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3197 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3199 register_extension_string(ext->extName);
3201 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3202 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3204 return TRUE;
3207 static const WineGLExtension WGL_internal_functions =
3211 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3212 { "wglFinish", X11DRV_wglFinish },
3213 { "wglFlush", X11DRV_wglFlush },
3218 static const WineGLExtension WGL_ARB_extensions_string =
3220 "WGL_ARB_extensions_string",
3222 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3226 static const WineGLExtension WGL_ARB_make_current_read =
3228 "WGL_ARB_make_current_read",
3230 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3231 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3235 static const WineGLExtension WGL_ARB_multisample =
3237 "WGL_ARB_multisample",
3240 static const WineGLExtension WGL_ARB_pbuffer =
3242 "WGL_ARB_pbuffer",
3244 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3245 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3246 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3247 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3248 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3249 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3253 static const WineGLExtension WGL_ARB_pixel_format =
3255 "WGL_ARB_pixel_format",
3257 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3258 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3259 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3263 static const WineGLExtension WGL_ARB_render_texture =
3265 "WGL_ARB_render_texture",
3267 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3268 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3272 static const WineGLExtension WGL_EXT_extensions_string =
3274 "WGL_EXT_extensions_string",
3276 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3280 static const WineGLExtension WGL_EXT_swap_control =
3282 "WGL_EXT_swap_control",
3284 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3285 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3289 static const WineGLExtension WGL_NV_vertex_array_range =
3291 "WGL_NV_vertex_array_range",
3293 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3294 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3298 static const WineGLExtension WGL_WINE_pixel_format_passthrough =
3300 "WGL_WINE_pixel_format_passthrough",
3302 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE },
3307 * X11DRV_WineGL_LoadExtensions
3309 static void X11DRV_WineGL_LoadExtensions(void)
3311 WineGLInfo.wglExtensions[0] = 0;
3313 /* Load Wine internal functions */
3314 register_extension(&WGL_internal_functions);
3316 /* ARB Extensions */
3318 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3320 register_extension_string("WGL_ARB_pixel_format_float");
3321 register_extension_string("WGL_ATI_pixel_format_float");
3324 register_extension(&WGL_ARB_extensions_string);
3326 if (glxRequireVersion(3))
3327 register_extension(&WGL_ARB_make_current_read);
3329 if (glxRequireExtension("GLX_ARB_multisample"))
3330 register_extension(&WGL_ARB_multisample);
3332 /* In general pbuffer functionality requires support in the X-server. The functionality is
3333 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3334 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3335 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3337 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3338 * without support in the X-server (which other Mesa based drivers require).
3340 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3341 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3342 * is available pbuffers must be available too. */
3343 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3344 register_extension(&WGL_ARB_pbuffer);
3346 register_extension(&WGL_ARB_pixel_format);
3348 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3349 if (glxRequireExtension("GLX_ATI_render_texture") ||
3350 glxRequireExtension("GLX_ARB_render_texture") ||
3351 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3353 register_extension(&WGL_ARB_render_texture);
3355 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3356 if(glxRequireExtension("GLX_NV_float_buffer"))
3357 register_extension_string("WGL_NV_float_buffer");
3359 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3360 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3361 register_extension_string("WGL_NV_texture_rectangle");
3364 /* EXT Extensions */
3366 register_extension(&WGL_EXT_extensions_string);
3368 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3369 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3370 register_extension(&WGL_EXT_swap_control);
3372 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3373 register_extension_string("WGL_EXT_framebuffer_sRGB");
3375 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3376 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3377 register_extension(&WGL_NV_vertex_array_range);
3379 /* WINE-specific WGL Extensions */
3381 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3382 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3384 register_extension(&WGL_WINE_pixel_format_passthrough);
3388 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3390 Drawable ret;
3392 if(physDev->bitmap)
3394 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3395 ret = physDev->drawable; /* PBuffer */
3396 else
3397 ret = physDev->bitmap->glxpixmap;
3399 else if(physDev->gl_drawable)
3400 ret = physDev->gl_drawable;
3401 else
3402 ret = physDev->drawable;
3403 return ret;
3406 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3408 wine_tsx11_lock();
3409 pglXDestroyGLXPixmap(display, glxpixmap);
3410 wine_tsx11_unlock();
3411 return TRUE;
3415 * X11DRV_SwapBuffers
3417 * Swap the buffers of this DC
3419 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3421 GLXDrawable drawable;
3422 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3424 if (!has_opengl()) {
3425 ERR("No libGL on this box - disabling OpenGL support !\n");
3426 return 0;
3429 TRACE("(%p)\n", physDev);
3431 drawable = get_glxdrawable(physDev);
3433 wine_tsx11_lock();
3434 sync_context(ctx);
3435 if(physDev->pixmap) {
3436 if(pglXCopySubBufferMESA) {
3437 int w = physDev->dc_rect.right - physDev->dc_rect.left;
3438 int h = physDev->dc_rect.bottom - physDev->dc_rect.top;
3440 /* (glX)SwapBuffers has an implicit glFlush effect, however
3441 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3442 * copying */
3443 pglFlush();
3444 if(w > 0 && h > 0)
3445 pglXCopySubBufferMESA(gdi_display, drawable, 0, 0, w, h);
3447 else
3448 pglXSwapBuffers(gdi_display, drawable);
3450 else
3451 pglXSwapBuffers(gdi_display, drawable);
3453 flush_gl_drawable(physDev);
3454 wine_tsx11_unlock();
3456 /* FPS support */
3457 if (TRACE_ON(fps))
3459 static long prev_time, frames;
3461 DWORD time = GetTickCount();
3462 frames++;
3463 /* every 1.5 seconds */
3464 if (time - prev_time > 1500) {
3465 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3466 prev_time = time;
3467 frames = 0;
3471 return TRUE;
3474 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3476 WineGLPixelFormat *fmt;
3478 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
3479 if(fmt == NULL)
3480 return NULL;
3481 return pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3484 #else /* no OpenGL includes */
3486 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3488 return 0;
3491 void mark_drawable_dirty(Drawable old, Drawable new)
3495 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
3499 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3501 return 0;
3504 /***********************************************************************
3505 * ChoosePixelFormat (X11DRV.@)
3507 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3508 const PIXELFORMATDESCRIPTOR *ppfd) {
3509 ERR("No OpenGL support compiled in.\n");
3511 return 0;
3514 /***********************************************************************
3515 * DescribePixelFormat (X11DRV.@)
3517 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3518 int iPixelFormat,
3519 UINT nBytes,
3520 PIXELFORMATDESCRIPTOR *ppfd) {
3521 ERR("No OpenGL support compiled in.\n");
3523 return 0;
3526 /***********************************************************************
3527 * GetPixelFormat (X11DRV.@)
3529 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3530 ERR("No OpenGL support compiled in.\n");
3532 return 0;
3535 /***********************************************************************
3536 * SetPixelFormat (X11DRV.@)
3538 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3539 int iPixelFormat,
3540 const PIXELFORMATDESCRIPTOR *ppfd) {
3541 ERR("No OpenGL support compiled in.\n");
3543 return FALSE;
3546 /***********************************************************************
3547 * SwapBuffers (X11DRV.@)
3549 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3550 ERR("No OpenGL support compiled in.\n");
3552 return FALSE;
3556 * X11DRV_wglCopyContext
3558 * For OpenGL32 wglCopyContext.
3560 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
3561 ERR("No OpenGL support compiled in.\n");
3562 return FALSE;
3566 * X11DRV_wglCreateContext
3568 * For OpenGL32 wglCreateContext.
3570 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3571 ERR("No OpenGL support compiled in.\n");
3572 return NULL;
3576 * X11DRV_wglDeleteContext
3578 * For OpenGL32 wglDeleteContext.
3580 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3581 ERR("No OpenGL support compiled in.\n");
3582 return FALSE;
3586 * X11DRV_wglGetProcAddress
3588 * For OpenGL32 wglGetProcAddress.
3590 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3591 ERR("No OpenGL support compiled in.\n");
3592 return NULL;
3595 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3597 ERR("No OpenGL support compiled in.\n");
3598 return NULL;
3601 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3602 ERR("No OpenGL support compiled in.\n");
3603 return FALSE;
3607 * X11DRV_wglMakeCurrent
3609 * For OpenGL32 wglMakeCurrent.
3611 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3612 ERR("No OpenGL support compiled in.\n");
3613 return FALSE;
3617 * X11DRV_wglShareLists
3619 * For OpenGL32 wglShaderLists.
3621 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3622 ERR("No OpenGL support compiled in.\n");
3623 return FALSE;
3627 * X11DRV_wglUseFontBitmapsA
3629 * For OpenGL32 wglUseFontBitmapsA.
3631 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3633 ERR("No OpenGL support compiled in.\n");
3634 return FALSE;
3638 * X11DRV_wglUseFontBitmapsW
3640 * For OpenGL32 wglUseFontBitmapsW.
3642 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3644 ERR("No OpenGL support compiled in.\n");
3645 return FALSE;
3649 * X11DRV_wglSetPixelFormatWINE
3651 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3652 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3654 BOOL X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3656 ERR("No OpenGL support compiled in.\n");
3657 return FALSE;
3660 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3662 return 0;
3665 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3667 return FALSE;
3670 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3672 return NULL;
3675 #endif /* defined(HAVE_OPENGL) */