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
26 #include "wine/port.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
38 WINE_DECLARE_DEBUG_CHANNEL(opengl);
40 #if defined(HAVE_GL_GL_H) && defined(HAVE_GL_GLX_H)
52 #ifdef HAVE_GL_GLEXT_H
53 # include <GL/glext.h>
62 /* Redefines the constants */
63 #define CALLBACK __stdcall
64 #define WINAPI __stdcall
65 #define APIENTRY WINAPI
68 WINE_DECLARE_DEBUG_CHANNEL(fps);
70 typedef struct wine_glcontext {
77 X11DRV_PDEVICE *physDev;
81 struct wine_glcontext *next;
82 struct wine_glcontext *prev;
85 typedef struct wine_glpbuffer {
94 int use_render_texture;
95 GLuint texture_target;
96 GLuint texture_bind_target;
105 typedef struct wine_glextension {
108 const char *funcName;
114 const char *glVersion;
115 const char *glExtensions;
119 const char *glxServerVersion;
120 const char *glxServerExtensions;
122 const char *glxClientVersion;
123 const char *glxClientExtensions;
125 const char *glxExtensions;
128 char wglExtensions[4096];
131 typedef struct wine_glpixelformat {
137 static Wine_GLContext *context_list;
138 static struct WineGLInfo WineGLInfo = { 0 };
139 static int use_render_texture_emulation = 0;
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 #define MAX_GLPIXELFORMATS 32
148 static WineGLPixelFormat WineGLPixelFormatList[MAX_GLPIXELFORMATS];
149 static int WineGLPixelFormatListSize = 0;
151 static void X11DRV_WineGL_LoadExtensions(void);
153 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
154 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
155 TRACE(" - dwFlags : ");
156 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
157 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
158 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
159 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
176 TRACE(" - iPixelType : ");
177 switch (ppfd->iPixelType) {
178 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
179 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
183 TRACE(" - Color : %d\n", ppfd->cColorBits);
184 TRACE(" - Red : %d\n", ppfd->cRedBits);
185 TRACE(" - Green : %d\n", ppfd->cGreenBits);
186 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
187 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
188 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
189 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
190 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
191 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
193 TRACE(" - iLayerType : ");
194 switch (ppfd->iLayerType) {
195 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
196 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
197 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
202 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and
203 include all dependencies
206 #define SONAME_LIBGL "libGL.so"
209 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
210 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
212 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
214 MAKE_FUNCPTR(glXChooseVisual)
215 MAKE_FUNCPTR(glXCreateContext)
216 MAKE_FUNCPTR(glXCreateGLXPixmap)
217 MAKE_FUNCPTR(glXGetCurrentContext)
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)
229 MAKE_FUNCPTR(glXGetClientString)
230 MAKE_FUNCPTR(glXQueryExtensionsString)
231 MAKE_FUNCPTR(glXQueryServerString)
234 MAKE_FUNCPTR(glXGetFBConfigs)
235 MAKE_FUNCPTR(glXChooseFBConfig)
236 MAKE_FUNCPTR(glXCreatePbuffer)
237 MAKE_FUNCPTR(glXDestroyPbuffer)
238 MAKE_FUNCPTR(glXGetFBConfigAttrib)
239 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
240 MAKE_FUNCPTR(glXMakeContextCurrent)
241 MAKE_FUNCPTR(glXQueryDrawable)
242 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
245 static void* (*pglXGetProcAddressARB)(const GLubyte *);
246 static BOOL (*pglXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
247 static BOOL (*pglXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
248 static BOOL (*pglXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
249 static int (*pglXSwapIntervalSGI)(int);
251 /* NV GLX Extension */
252 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
253 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
255 /* Standard OpenGL */
256 MAKE_FUNCPTR(glBindTexture)
257 MAKE_FUNCPTR(glBitmap)
258 MAKE_FUNCPTR(glCopyTexSubImage1D)
259 MAKE_FUNCPTR(glCopyTexSubImage2D)
260 MAKE_FUNCPTR(glDisable)
261 MAKE_FUNCPTR(glDrawBuffer)
262 MAKE_FUNCPTR(glEnable)
263 MAKE_FUNCPTR(glEndList)
264 MAKE_FUNCPTR(glGetError)
265 MAKE_FUNCPTR(glGetIntegerv)
266 MAKE_FUNCPTR(glGetString)
267 MAKE_FUNCPTR(glIsEnabled)
268 MAKE_FUNCPTR(glNewList)
269 MAKE_FUNCPTR(glPixelStorei)
270 MAKE_FUNCPTR(glScissor)
271 MAKE_FUNCPTR(glViewport)
274 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
276 static BOOL infoInitialized = FALSE;
278 int screen = DefaultScreen(gdi_display);
279 Window win = RootWindow(gdi_display, screen);
281 XVisualInfo template;
284 GLXContext ctx = NULL;
288 infoInitialized = TRUE;
292 visual = DefaultVisual(gdi_display, screen);
293 template.visualid = XVisualIDFromVisual(visual);
294 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
296 /* Create a GLX Context. Without one we can't query GL information */
297 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
301 pglXMakeCurrent(gdi_display, win, ctx);
303 ERR(" couldn't initialize OpenGL, expect problems\n");
308 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
309 WineGLInfo.glExtensions = (const char *) pglGetString(GL_EXTENSIONS);
311 /* Get the common GLX version supported by GLX client and server ( major/minor) */
312 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
314 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
315 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
317 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
318 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
320 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
321 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
323 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
324 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
325 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
326 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
327 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
331 pglXMakeCurrent(gdi_display, None, NULL);
332 pglXDestroyContext(gdi_display, ctx);
338 static BOOL has_opengl(void)
340 static int init_done;
341 static void *opengl_handle;
342 const char *glx_extensions;
344 int error_base, event_base;
346 if (init_done) return (opengl_handle != NULL);
349 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
350 if (opengl_handle == NULL) return FALSE;
352 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
353 if (pglXGetProcAddressARB == NULL) {
354 ERR("could not find glXGetProcAddressARB in libGL.\n");
358 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
360 LOAD_FUNCPTR(glXChooseVisual)
361 LOAD_FUNCPTR(glXCreateContext)
362 LOAD_FUNCPTR(glXCreateGLXPixmap)
363 LOAD_FUNCPTR(glXGetCurrentContext)
364 LOAD_FUNCPTR(glXDestroyContext)
365 LOAD_FUNCPTR(glXDestroyGLXPixmap)
366 LOAD_FUNCPTR(glXGetConfig)
367 LOAD_FUNCPTR(glXIsDirect)
368 LOAD_FUNCPTR(glXMakeCurrent)
369 LOAD_FUNCPTR(glXSwapBuffers)
370 LOAD_FUNCPTR(glXQueryExtension)
371 LOAD_FUNCPTR(glXQueryVersion)
372 LOAD_FUNCPTR(glXUseXFont)
375 LOAD_FUNCPTR(glXGetClientString)
376 LOAD_FUNCPTR(glXQueryExtensionsString)
377 LOAD_FUNCPTR(glXQueryServerString)
380 LOAD_FUNCPTR(glXCreatePbuffer)
381 LOAD_FUNCPTR(glXDestroyPbuffer)
382 LOAD_FUNCPTR(glXMakeContextCurrent)
383 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
384 LOAD_FUNCPTR(glXGetFBConfigs)
386 /* Standard OpenGL calls */
387 LOAD_FUNCPTR(glBindTexture)
388 LOAD_FUNCPTR(glBitmap)
389 LOAD_FUNCPTR(glCopyTexSubImage1D)
390 LOAD_FUNCPTR(glCopyTexSubImage2D)
391 LOAD_FUNCPTR(glDisable)
392 LOAD_FUNCPTR(glDrawBuffer)
393 LOAD_FUNCPTR(glEnable)
394 LOAD_FUNCPTR(glEndList)
395 LOAD_FUNCPTR(glGetError)
396 LOAD_FUNCPTR(glGetIntegerv)
397 LOAD_FUNCPTR(glGetString)
398 LOAD_FUNCPTR(glIsEnabled)
399 LOAD_FUNCPTR(glNewList)
400 LOAD_FUNCPTR(glPixelStorei)
401 LOAD_FUNCPTR(glScissor)
402 LOAD_FUNCPTR(glViewport)
405 /* It doesn't matter if these fail. They'll only be used if the driver reports
406 the associated extension is available (and if a driver reports the extension
407 is available but fails to provide the functions, it's quite broken) */
408 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
409 /* NV GLX Extension */
410 LOAD_FUNCPTR(glXAllocateMemoryNV)
411 LOAD_FUNCPTR(glXFreeMemoryNV)
414 if(!X11DRV_WineGL_InitOpenglInfo()) {
415 ERR("Intialization of OpenGL info failed, disabling OpenGL!\n");
416 wine_dlclose(opengl_handle, NULL, 0);
417 opengl_handle = NULL;
422 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
423 TRACE("GLX is up and running error_base = %d\n", error_base);
425 wine_dlclose(opengl_handle, NULL, 0);
426 opengl_handle = NULL;
429 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
430 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
433 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
434 * depends on the reported GLX client / server version and on the client / server extension list.
435 * Those don't have to be the same.
437 * In general the server GLX information should be used in case of indirect rendering. When direct
438 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
439 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
440 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
441 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
442 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
443 * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
444 * is only available in the list of server extensions and not in the client list.
446 * The versioning checks below try to take into account the comments from above.
449 /* Depending on the use of direct or indirect rendering we need either the list of extensions
450 * exported by the client or by the server.
452 if(WineGLInfo.glxDirect)
453 glx_extensions = WineGLInfo.glxClientExtensions;
455 glx_extensions = WineGLInfo.glxServerExtensions;
457 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
458 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
459 * the client version is checked.
461 if ((!WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxServerVersion)) ||
462 (WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxClientVersion)))
464 if (NULL != strstr(glx_extensions, "GLX_SGIX_fbconfig")) {
465 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
466 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
467 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
469 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxClientVersion);
472 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
473 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
474 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
477 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
478 * enable this function when the Xserver understand GLX 1.3 or newer
480 if (!strcmp("1.2", WineGLInfo.glxServerVersion))
481 pglXQueryDrawable = NULL;
483 pglXQueryDrawable = wine_dlsym(RTLD_DEFAULT, "glXQueryDrawable", NULL, 0);
485 if (NULL != strstr(glx_extensions, "GLX_ATI_render_texture")) {
486 pglXBindTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageARB");
487 pglXReleaseTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageARB");
488 pglXDrawableAttribARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribARB");
491 X11DRV_WineGL_LoadExtensions();
494 return (opengl_handle != NULL);
497 wine_dlclose(opengl_handle, NULL, 0);
498 opengl_handle = NULL;
502 static inline Wine_GLContext *alloc_context(void)
506 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
508 ret->next = context_list;
509 if (context_list) context_list->prev = ret;
515 static inline void free_context(Wine_GLContext *context)
517 if (context->next != NULL) context->next->prev = context->prev;
518 if (context->prev != NULL) context->prev->next = context->next;
519 else context_list = context->next;
521 HeapFree(GetProcessHeap(), 0, context);
524 static inline Wine_GLContext *get_context_from_GLXContext(GLXContext ctx)
527 if (!ctx) return NULL;
528 for (ret = context_list; ret; ret = ret->next) if (ctx == ret->ctx) break;
533 * get_drawable (internal)
535 * Retrieve the GLX drawable to use on a given DC.
537 inline static Drawable get_drawable( HDC hdc )
539 GLXDrawable drawable;
540 enum x11drv_escape_codes escape = X11DRV_GET_GLX_DRAWABLE;
542 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
543 sizeof(drawable), (LPSTR)&drawable )) drawable = 0;
548 * get_hdc_from_Drawable (internal)
550 * For use by wglGetCurrentReadDCARB.
552 inline static HDC get_hdc_from_Drawable(GLXDrawable d)
555 for (ret = context_list; ret; ret = ret->next) {
556 if (d == ret->physDev->drawable) {
563 inline static BOOL is_valid_context( Wine_GLContext *ctx )
566 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
567 return (ptr != NULL);
570 static int describeContext(Wine_GLContext* ctx) {
573 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
574 pglXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_FBCONFIG_ID, &tmp);
575 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
576 pglXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_VISUAL_ID, &tmp);
577 TRACE(" - VISUAL_ID 0x%x\n", tmp);
582 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
585 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
588 if (pglXQueryDrawable == NULL) {
589 /** glXQueryDrawable not available so returns not supported */
593 TRACE(" Drawable %p have :\n", (void*) drawable);
594 pglXQueryDrawable(ctx->display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
595 TRACE(" - WIDTH as %d\n", tmp);
596 pglXQueryDrawable(ctx->display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
597 TRACE(" - HEIGHT as %d\n", tmp);
598 pglXQueryDrawable(ctx->display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
599 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
602 fbCfgs = pglXChooseFBConfig(ctx->display, DefaultScreen(ctx->display), attribList, &nElements);
603 if (fbCfgs == NULL) {
607 pglXGetFBConfigAttrib(ctx->display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
608 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
615 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
621 int wantColorBits = 0;
624 while (0 != iWGLAttr[cur]) {
625 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
627 switch (iWGLAttr[cur]) {
628 case WGL_COLOR_BITS_ARB:
629 pop = iWGLAttr[++cur];
630 wantColorBits = pop; /** see end */
632 case WGL_BLUE_BITS_ARB:
633 pop = iWGLAttr[++cur];
634 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
635 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
637 case WGL_RED_BITS_ARB:
638 pop = iWGLAttr[++cur];
639 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
640 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
642 case WGL_GREEN_BITS_ARB:
643 pop = iWGLAttr[++cur];
644 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
645 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
647 case WGL_ALPHA_BITS_ARB:
648 pop = iWGLAttr[++cur];
650 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
651 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
653 case WGL_DEPTH_BITS_ARB:
654 pop = iWGLAttr[++cur];
655 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
656 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
658 case WGL_STENCIL_BITS_ARB:
659 pop = iWGLAttr[++cur];
660 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
661 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
663 case WGL_DOUBLE_BUFFER_ARB:
664 pop = iWGLAttr[++cur];
665 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
666 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
669 case WGL_PIXEL_TYPE_ARB:
670 pop = iWGLAttr[++cur];
672 case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; isColor = 1; break ;
673 case WGL_TYPE_RGBA_ARB: pop = GLX_RGBA_BIT; break ;
674 case WGL_TYPE_RGBA_FLOAT_ATI: pop = GLX_RGBA_FLOAT_ATI_BIT; break ;
676 ERR("unexpected PixelType(%x)\n", pop);
679 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
680 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
683 case WGL_SUPPORT_GDI_ARB:
684 pop = iWGLAttr[++cur];
685 /* We only support a limited number of formats which are all renderable by X (similar to GDI).
686 * Ignore this attribute to prevent us from not finding a match due to the limited
687 * amount of formats supported right now. This option could be matched to GLX_X_RENDERABLE
688 * but the issue is that when a program asks for no GDI support, there's no format we can return
689 * as all our supported formats are renderable by X.
691 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
694 case WGL_DRAW_TO_BITMAP_ARB:
695 pop = iWGLAttr[++cur];
696 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
697 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
699 drawattrib |= GLX_PIXMAP_BIT;
703 case WGL_DRAW_TO_WINDOW_ARB:
704 pop = iWGLAttr[++cur];
705 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
706 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
708 drawattrib |= GLX_WINDOW_BIT;
712 case WGL_DRAW_TO_PBUFFER_ARB:
713 pop = iWGLAttr[++cur];
714 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
715 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
717 drawattrib |= GLX_PBUFFER_BIT;
721 case WGL_ACCELERATION_ARB:
722 case WGL_SUPPORT_OPENGL_ARB:
723 pop = iWGLAttr[++cur];
724 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
725 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
728 case WGL_PBUFFER_LARGEST_ARB:
729 pop = iWGLAttr[++cur];
730 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
731 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
734 case WGL_SAMPLE_BUFFERS_ARB:
735 pop = iWGLAttr[++cur];
736 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
737 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
740 case WGL_SAMPLES_ARB:
741 pop = iWGLAttr[++cur];
742 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
743 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
746 case WGL_TEXTURE_FORMAT_ARB:
747 case WGL_TEXTURE_TARGET_ARB:
748 case WGL_MIPMAP_TEXTURE_ARB:
749 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
750 pop = iWGLAttr[++cur];
752 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
754 if (use_render_texture_ati) {
755 /** nothing to do here */
757 else if (!use_render_texture_emulation) {
758 if (WGL_NO_TEXTURE_ARB != pop) {
759 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
760 return -1; /** error: don't support it */
762 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
763 drawattrib |= GLX_PBUFFER_BIT;
768 case WGL_BIND_TO_TEXTURE_RGB_ARB:
769 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
770 pop = iWGLAttr[++cur];
771 /** cannot be converted, see direct handling on
772 * - wglGetPixelFormatAttribivARB
773 * TODO: wglChoosePixelFormat
778 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
785 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
786 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
789 * The number of color bitplanes in each color buffer. For RGBA
790 * pixel types, it is the size of the color buffer, excluding the
791 * alpha bitplanes. For color-index pixels, it is the size of the
792 * color index buffer.
795 * This attribute defines the number of bits per color buffer.
796 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
797 * this is equal to the depth value reported in the X11 visual.
798 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
799 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
802 if (0 < wantColorBits) {
804 wantColorBits += sz_alpha;
806 if (32 < wantColorBits) {
807 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
810 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
811 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
814 /* Apply the OR'd drawable type bitmask now. */
816 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
817 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
823 BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, int *fmt_id, int *fmt_index)
825 GLXFBConfig* cfgs = NULL;
832 if(!display || !display) {
833 ERR("Invalid display or visual\n");
835 visualid = XVisualIDFromVisual(visual);
837 /* Get a list of all available framebuffer configurations */
838 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
839 if (NULL == cfgs || 0 == nCfgs) {
840 ERR("glXChooseFBConfig returns NULL\n");
841 if(cfgs != NULL) XFree(cfgs);
845 /* Find the requested offscreen format and count the number of offscreen formats */
846 for(i=0; i<nCfgs; i++) {
847 pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
848 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
850 /* We are looking up the GLX index of our main visual and have found it :) */
851 if(visualid == tmp_vis_id) {
852 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, i, tmp_vis_id);
854 *fmt_id = tmp_fmt_id;
860 ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid);
865 static BOOL init_formats(Display *display, int screen, Visual *visual)
867 int fmt_id, fmt_index;
869 /* Locate the fbconfig correspondig to our main visual */
870 if(!get_fbconfig_from_visualid(display, visual, &fmt_id, &fmt_index)) {
871 ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
875 /* Put Wine's internal format at the first index */
876 WineGLPixelFormatList[0].iPixelFormat = 1;
877 WineGLPixelFormatList[0].fbconfig = fmt_id;
878 WineGLPixelFormatList[0].fmt_index = fmt_index;
879 WineGLPixelFormatListSize = 1;
881 /* In the future test for compatible formats here */
886 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
887 * In our WGL implementation we only support a subset of these formats namely the format of
888 * Wine's main visual and offscreen formats (if they are available).
889 * This function converts a WGL format to its corresponding GLX one. It returns the index (zero-based)
890 * into the GLX FB config table and it returns the number of supported WGL formats in fmt_count.
892 static BOOL ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, int *fmt_index, int *fmt_count)
896 /* Init the list of pixel formats when we need it */
897 if(!WineGLPixelFormatListSize)
898 init_formats(display, DefaultScreen(display), visual);
900 if((iPixelFormat <= 0) || (iPixelFormat > WineGLPixelFormatListSize)) {
901 ERR("invalid iPixelFormat %d\n", iPixelFormat);
907 *fmt_index = WineGLPixelFormatList[iPixelFormat-1].fmt_index;
910 *fmt_count = WineGLPixelFormatListSize;
911 TRACE("Returning fmt_index=%d, fmt_count=%d for iPixelFormat=%d\n", *fmt_index, *fmt_count, iPixelFormat);
916 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
917 static int ConvertPixelFormatGLXtoWGL(Display *display, int fbconfig)
921 /* Init the list of pixel formats when we need it */
922 if(!WineGLPixelFormatListSize)
923 init_formats(display, DefaultScreen(display), visual);
925 for(i=0; i<WineGLPixelFormatListSize; i++) {
926 if(WineGLPixelFormatList[i].fbconfig == fbconfig) {
927 TRACE("Returning iPixelFormat %d for fbconfig 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fbconfig);
928 return WineGLPixelFormatList[i].iPixelFormat;
931 TRACE("No compatible format found for FBCONFIG_ID=0x%x\n", fbconfig);
936 * X11DRV_ChoosePixelFormat
938 * Equivalent to glXChooseVisual.
940 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
941 const PIXELFORMATDESCRIPTOR *ppfd) {
942 GLXFBConfig* cfgs = NULL;
949 ERR("No libGL on this box - disabling OpenGL support !\n");
953 if (TRACE_ON(opengl)) {
954 TRACE("(%p,%p)\n", physDev, ppfd);
956 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
961 ERR("Can't get an opengl visual!\n");
965 /* Get a list containing all supported FB configurations */
966 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
967 if (NULL == cfgs || 0 == nCfgs) {
968 ERR("glXGetFBConfigs returns NULL (glError: %d)\n", pglGetError());
972 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
973 if(!ConvertPixelFormatWGLtoGLX(gdi_display, 1 /* main visual */, &fmt_index, &value)) {
974 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual->visualid);
981 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_RENDER_TYPE, &value);
982 if (value & GLX_RGBA_BIT)
983 iPixelType = PFD_TYPE_RGBA;
985 iPixelType = PFD_TYPE_COLORINDEX;
987 if (ppfd->iPixelType != iPixelType) {
988 TRACE("pixel type mismatch\n");
993 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER;
994 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && (ppfd->dwFlags & PFD_DOUBLEBUFFER)) {
995 if (!(dwFlags & PFD_DOUBLEBUFFER)) {
996 TRACE("dbl buffer mismatch\n");
1002 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO;
1003 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO)) {
1004 if (!(dwFlags & PFD_STEREO)) {
1005 TRACE("stereo mismatch\n");
1011 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_ALPHA_SIZE, &value);
1012 if (ppfd->iPixelType==PFD_TYPE_RGBA && ppfd->cAlphaBits && !value) {
1013 TRACE("alpha mismatch\n");
1018 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DEPTH_SIZE, &value);
1019 if (ppfd->cDepthBits && !value) {
1020 TRACE("depth mismatch\n");
1025 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STENCIL_SIZE, &value);
1026 if (ppfd->cStencilBits && !value) {
1027 TRACE("stencil mismatch\n");
1032 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_AUX_BUFFERS, &value);
1033 if (ppfd->cAuxBuffers && !value) {
1034 TRACE("aux mismatch\n");
1038 /* When we pass all the checks we have found a matching format :) */
1040 TRACE("Successfully found a matching mode, returning index: %d\n", ret);
1045 TRACE("No matching mode was found returning 0\n");
1047 if (NULL != cfgs) XFree(cfgs);
1048 wine_tsx11_unlock();
1053 * X11DRV_DescribePixelFormat
1055 * Get the pixel-format descriptor associated to the given id
1057 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1060 PIXELFORMATDESCRIPTOR *ppfd) {
1061 /*XVisualInfo *vis;*/
1065 GLXFBConfig* cfgs = NULL;
1073 if (!has_opengl()) {
1074 ERR("No libGL on this box - disabling OpenGL support !\n");
1078 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1081 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1082 wine_tsx11_unlock();
1084 if (NULL == cfgs || 0 == nCfgs) {
1085 ERR("unexpected iPixelFormat(%d), returns NULL\n", iPixelFormat);
1086 return 0; /* unespected error */
1089 /* 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 */
1090 res = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &fmt_count);
1093 /* The application is only querying the number of visuals */
1095 if (NULL != cfgs) XFree(cfgs);
1096 wine_tsx11_unlock();
1098 } else if(res == FALSE) {
1099 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1101 if (NULL != cfgs) XFree(cfgs);
1102 wine_tsx11_unlock();
1106 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1107 ERR("Wrong structure size !\n");
1108 /* Should set error */
1113 cur = cfgs[fmt_index];
1115 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1116 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1119 /* These flags are always the same... */
1120 ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
1121 /* Now the flags extracted from the Visual */
1125 pglXGetFBConfigAttrib(gdi_display, cur, GLX_CONFIG_CAVEAT, &value);
1126 if(value == GLX_SLOW_CONFIG)
1127 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1129 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1130 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1133 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RENDER_TYPE, &value);
1134 if (value & GLX_RGBA_BIT)
1135 ppfd->iPixelType = PFD_TYPE_RGBA;
1137 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1140 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BUFFER_SIZE, &value);
1141 ppfd->cColorBits = value;
1143 /* Red, green, blue and alpha bits / shifts */
1144 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1145 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RED_SIZE, &rb);
1146 pglXGetFBConfigAttrib(gdi_display, cur, GLX_GREEN_SIZE, &gb);
1147 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BLUE_SIZE, &bb);
1148 pglXGetFBConfigAttrib(gdi_display, cur, GLX_ALPHA_SIZE, &ab);
1150 ppfd->cRedBits = rb;
1151 ppfd->cRedShift = gb + bb + ab;
1152 ppfd->cBlueBits = bb;
1153 ppfd->cBlueShift = ab;
1154 ppfd->cGreenBits = gb;
1155 ppfd->cGreenShift = bb + ab;
1156 ppfd->cAlphaBits = ab;
1157 ppfd->cAlphaShift = 0;
1160 ppfd->cRedShift = 0;
1161 ppfd->cBlueBits = 0;
1162 ppfd->cBlueShift = 0;
1163 ppfd->cGreenBits = 0;
1164 ppfd->cGreenShift = 0;
1165 ppfd->cAlphaBits = 0;
1166 ppfd->cAlphaShift = 0;
1168 /* Accums : to do ... */
1171 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DEPTH_SIZE, &value);
1172 ppfd->cDepthBits = value;
1175 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STENCIL_SIZE, &value);
1176 ppfd->cStencilBits = value;
1178 wine_tsx11_unlock();
1180 /* Aux : to do ... */
1182 ppfd->iLayerType = PFD_MAIN_PLANE;
1184 if (TRACE_ON(opengl)) {
1185 dump_PIXELFORMATDESCRIPTOR(ppfd);
1189 if (NULL != cfgs) XFree(cfgs);
1190 wine_tsx11_unlock();
1196 * X11DRV_GetPixelFormat
1198 * Get the pixel-format id used by this DC
1200 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1201 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1203 return physDev->current_pf;
1207 * X11DRV_SetPixelFormat
1209 * Set the pixel-format id used by this DC
1211 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1213 const PIXELFORMATDESCRIPTOR *ppfd) {
1217 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1219 if (!has_opengl()) {
1220 ERR("No libGL on this box - disabling OpenGL support !\n");
1224 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1225 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
1226 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1230 physDev->current_pf = iPixelFormat;
1232 if (TRACE_ON(opengl)) {
1234 GLXFBConfig* cfgs_fmt = NULL;
1235 GLXFBConfig cur_cfg;
1239 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1241 * in case of root window created HDCs we crash here :(
1243 Drawable drawable = get_drawable( physDev->hdc );
1244 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1245 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1246 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1247 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1248 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1249 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1250 TRACE(" - WIDTH as %d\n", tmp);
1251 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1252 TRACE(" - HEIGHT as %d\n", tmp);
1254 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1255 cur_cfg = cfgs_fmt[fmt_index];
1256 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1258 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1260 TRACE(" FBConfig have :\n");
1261 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1262 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_VISUAL_ID, &value);
1263 TRACE(" - VISUAL_ID 0x%x\n", value);
1264 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_DRAWABLE_TYPE, &value);
1265 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1273 * X11DRV_wglCreateContext
1275 * For OpenGL32 wglCreateContext.
1277 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1279 Wine_GLContext *ret;
1280 GLXFBConfig* cfgs_fmt = NULL;
1281 GLXFBConfig cur_cfg;
1282 int hdcPF = physDev->current_pf;
1288 HDC hdc = physDev->hdc;
1290 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1292 if (!has_opengl()) {
1293 ERR("No libGL on this box - disabling OpenGL support !\n");
1297 /* First, get the visual in use by the X11DRV */
1298 if (!gdi_display) return 0;
1300 /* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the corresponding GLX format.
1301 * If this fails something is very wrong on the system. */
1302 if(!ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, &fmt_index, &fmt_count)) {
1303 ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n");
1304 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1308 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1309 if (NULL == cfgs_fmt || 0 == nCfgs_fmt) {
1310 ERR("Cannot get FB Configs, expect problems.\n");
1311 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1315 if (fmt_count < hdcPF) {
1316 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, hdcPF, fmt_count);
1317 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1321 cur_cfg = cfgs_fmt[fmt_index];
1322 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1324 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1325 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1330 /* The context will be allocated in the wglMakeCurrent call */
1332 ret = alloc_context();
1333 wine_tsx11_unlock();
1335 ret->physDev = physDev;
1336 ret->display = gdi_display;
1337 ret->fb_conf = cur_cfg;
1339 ret->vis = pglXGetVisualFromFBConfig(gdi_display, cur_cfg);
1341 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1346 * X11DRV_wglDeleteContext
1348 * For OpenGL32 wglDeleteContext.
1350 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1352 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1355 TRACE("(%p)\n", hglrc);
1357 if (!has_opengl()) {
1358 ERR("No libGL on this box - disabling OpenGL support !\n");
1363 /* A game (Half Life not to name it) deletes twice the same context,
1364 * so make sure it is valid first */
1365 if (is_valid_context( ctx ))
1367 if (ctx->ctx) pglXDestroyContext(ctx->display, ctx->ctx);
1372 WARN("Error deleting context !\n");
1373 SetLastError(ERROR_INVALID_HANDLE);
1376 wine_tsx11_unlock();
1382 * X11DRV_wglGetCurrentReadDCARB
1384 * For OpenGL32 wglGetCurrentReadDCARB.
1386 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1394 gl_d = pglXGetCurrentReadDrawable();
1395 ret = get_hdc_from_Drawable(gl_d);
1396 wine_tsx11_unlock();
1398 TRACE(" returning %p (GL drawable %lu)\n", ret, gl_d);
1403 * X11DRV_wglGetProcAddress
1405 * For OpenGL32 wglGetProcAddress.
1407 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1410 const WineGLExtension *ext;
1412 int padding = 32 - strlen(lpszProc);
1416 if (!has_opengl()) {
1417 ERR("No libGL on this box - disabling OpenGL support !\n");
1421 /* Check the table of WGL extensions to see if we need to return a WGL extension
1422 * or a function pointer to a native OpenGL function. */
1423 if(strncmp(lpszProc, "wgl", 3) != 0) {
1424 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1426 TRACE("('%s'):%*s", lpszProc, padding, " ");
1427 for (i = 0; i < WineGLExtensionListSize; ++i) {
1428 ext = WineGLExtensionList[i];
1429 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1430 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1431 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1432 return ext->extEntryPoints[j].funcAddress;
1438 ERR("(%s) - not found\n", lpszProc);
1442 /***********************************************************************
1443 * sync_current_drawable
1445 * Adjust the current viewport and scissor in order to position
1446 * and size the current drawable correctly on the parent window.
1448 static void sync_current_drawable(void)
1454 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1458 if (ctx && ctx->physDev)
1460 GetClipBox(ctx->physDev->hdc, &rc); /* Make sure physDev is up to date */
1462 dy = ctx->physDev->drawable_rect.bottom - ctx->physDev->dc_rect.bottom;
1463 width = ctx->physDev->dc_rect.right - ctx->physDev->dc_rect.left;
1464 height = ctx->physDev->dc_rect.bottom - ctx->physDev->dc_rect.top;
1466 pglViewport(ctx->physDev->dc_rect.left + ctx->viewport.left,
1467 dy + ctx->viewport.top,
1468 ctx->viewport.right ? (ctx->viewport.right - ctx->viewport.left) : width,
1469 ctx->viewport.bottom ? (ctx->viewport.bottom - ctx->viewport.top) : height);
1471 pglEnable(GL_SCISSOR_TEST);
1473 if (ctx->scissor_enabled)
1474 pglScissor(ctx->physDev->dc_rect.left + min(width, max(0, ctx->scissor.left)),
1475 dy + min(height, max(0, ctx->scissor.top)),
1476 min(width, max(0, ctx->scissor.right - ctx->scissor.left)),
1477 min(height, max(0, ctx->scissor.bottom - ctx->scissor.top)));
1479 pglScissor(ctx->physDev->dc_rect.left, dy, width, height);
1485 * X11DRV_wglMakeCurrent
1487 * For OpenGL32 wglMakeCurrent.
1489 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1491 HDC hdc = physDev->hdc;
1492 DWORD type = GetObjectType(hdc);
1494 TRACE("(%p,%p)\n", hdc, hglrc);
1496 if (!has_opengl()) {
1497 ERR("No libGL on this box - disabling OpenGL support !\n");
1502 if (hglrc == NULL) {
1503 ret = pglXMakeCurrent(gdi_display, None, NULL);
1504 NtCurrentTeb()->glContext = NULL;
1506 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1507 Drawable drawable = physDev->drawable;
1508 if (ctx->ctx == NULL) {
1509 /* The describe lines below are for debugging purposes only */
1510 if (TRACE_ON(wgl)) {
1511 describeDrawable(ctx, drawable);
1512 describeContext(ctx);
1515 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1516 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1518 TRACE(" Creating GLX Context\n");
1519 ctx->ctx = pglXCreateContext(ctx->display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1520 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1522 TRACE(" make current for dis %p, drawable %p, ctx %p\n", ctx->display, (void*) drawable, ctx->ctx);
1523 ret = pglXMakeCurrent(ctx->display, drawable, ctx->ctx);
1524 NtCurrentTeb()->glContext = ctx;
1527 ctx->physDev = physDev;
1529 if (type == OBJ_MEMDC)
1531 ctx->do_escape = TRUE;
1532 pglDrawBuffer(GL_FRONT_LEFT);
1536 sync_current_drawable();
1540 wine_tsx11_unlock();
1541 TRACE(" returning %s\n", (ret ? "True" : "False"));
1546 * X11DRV_wglMakeContextCurrentARB
1548 * For OpenGL32 wglMakeContextCurrentARB
1550 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc)
1553 TRACE("(%p,%p,%p)\n", hDrawDev, hReadDev, hglrc);
1555 if (!has_opengl()) {
1556 ERR("No libGL on this box - disabling OpenGL support !\n");
1561 if (hglrc == NULL) {
1562 ret = pglXMakeCurrent(gdi_display, None, NULL);
1563 NtCurrentTeb()->glContext = NULL;
1565 if (NULL == pglXMakeContextCurrent) {
1568 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1569 Drawable d_draw = get_glxdrawable(hDrawDev);
1570 Drawable d_read = get_glxdrawable(hReadDev);
1572 if (ctx->ctx == NULL) {
1573 ctx->ctx = pglXCreateContext(ctx->display, ctx->vis, NULL, GetObjectType(hDrawDev->hdc) == OBJ_MEMDC ? False : True);
1574 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1576 ret = pglXMakeContextCurrent(ctx->display, d_draw, d_read, ctx->ctx);
1577 NtCurrentTeb()->glContext = ctx;
1580 wine_tsx11_unlock();
1582 TRACE(" returning %s\n", (ret ? "True" : "False"));
1587 * X11DRV_wglShareLists
1589 * For OpenGL32 wglShaderLists.
1591 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1592 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1593 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1595 TRACE("(%p, %p)\n", org, dest);
1597 if (!has_opengl()) {
1598 ERR("No libGL on this box - disabling OpenGL support !\n");
1602 if (NULL != dest && dest->ctx != NULL) {
1603 ERR("Could not share display lists, context already created !\n");
1606 if (org->ctx == NULL) {
1608 describeContext(org);
1609 org->ctx = pglXCreateContext(org->display, org->vis, NULL, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True);
1610 wine_tsx11_unlock();
1611 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1615 describeContext(dest);
1616 /* Create the destination context with display lists shared */
1617 dest->ctx = pglXCreateContext(org->display, dest->vis, org->ctx, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True);
1618 wine_tsx11_unlock();
1619 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1626 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1628 /* We are running using client-side rendering fonts... */
1632 void *bitmap = NULL, *gl_bitmap = NULL;
1636 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1637 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1638 wine_tsx11_unlock();
1640 for (glyph = first; glyph < first + count; glyph++) {
1641 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1642 int height, width_int;
1644 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1645 if (needed_size == GDI_ERROR) {
1646 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1649 TRACE(" - needed size : %d\n", needed_size);
1652 if (needed_size > size) {
1654 HeapFree(GetProcessHeap(), 0, bitmap);
1655 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1656 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1657 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1659 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1660 if (TRACE_ON(opengl)) {
1661 unsigned int height, width, bitmask;
1662 unsigned char *bitmap_ = (unsigned char *) bitmap;
1664 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1665 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1666 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1667 if (needed_size != 0) {
1668 TRACE(" - bitmap :\n");
1669 for (height = 0; height < gm.gmBlackBoxY; height++) {
1671 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1676 if (*bitmap_ & bitmask)
1681 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1687 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1688 * glyph for it to be drawn properly.
1690 if (needed_size != 0) {
1691 width_int = (gm.gmBlackBoxX + 31) / 32;
1692 for (height = 0; height < gm.gmBlackBoxY; height++) {
1694 for (width = 0; width < width_int; width++) {
1695 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1696 ((int *) bitmap)[height * width_int + width];
1702 pglNewList(listBase++, GL_COMPILE);
1703 if (needed_size != 0) {
1704 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1705 0 - (int) gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - (int) gm.gmptGlyphOrigin.y,
1706 gm.gmCellIncX, gm.gmCellIncY,
1709 /* This is the case of 'empty' glyphs like the space character */
1710 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1713 wine_tsx11_unlock();
1717 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1718 wine_tsx11_unlock();
1720 HeapFree(GetProcessHeap(), 0, bitmap);
1721 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1726 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1727 wine_tsx11_unlock();
1729 HeapFree(GetProcessHeap(), 0, bitmap);
1730 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1735 * X11DRV_wglUseFontBitmapsA
1737 * For OpenGL32 wglUseFontBitmapsA.
1739 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1741 Font fid = physDev->font;
1743 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1745 if (!has_opengl()) {
1746 ERR("No libGL on this box - disabling OpenGL support !\n");
1751 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1755 /* I assume that the glyphs are at the same position for X and for Windows */
1756 pglXUseXFont(fid, first, count, listBase);
1757 wine_tsx11_unlock();
1762 * X11DRV_wglUseFontBitmapsW
1764 * For OpenGL32 wglUseFontBitmapsW.
1766 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1768 Font fid = physDev->font;
1770 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1772 if (!has_opengl()) {
1773 ERR("No libGL on this box - disabling OpenGL support !\n");
1778 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
1781 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1784 /* I assume that the glyphs are at the same position for X and for Windows */
1785 pglXUseXFont(fid, first, count, listBase);
1786 wine_tsx11_unlock();
1790 static void WINAPI X11DRV_wglDisable(GLenum cap)
1792 if (cap == GL_SCISSOR_TEST)
1794 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1795 ctx->scissor_enabled = FALSE;
1803 static void WINAPI X11DRV_wglEnable(GLenum cap)
1805 if (cap == GL_SCISSOR_TEST)
1807 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1808 ctx->scissor_enabled = TRUE;
1816 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1817 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params) {
1818 TRACE("pname: 0x%x, params: %p\n", pname, params);
1819 if (pname == GL_DEPTH_BITS) {
1820 GLXContext gl_ctx = pglXGetCurrentContext();
1821 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1822 /*TRACE("returns Wine Ctx as %p\n", ret);*/
1824 * if we cannot find a Wine Context
1825 * we only have the default wine desktop context,
1826 * so if we have only a 24 depth say we have 32
1828 if (NULL == ret && 24 == *params) {
1831 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1833 if (pname == GL_ALPHA_BITS) {
1835 GLXContext gl_ctx = pglXGetCurrentContext();
1836 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1837 pglXGetFBConfigAttrib(ret->display, ret->fb_conf, GLX_ALPHA_SIZE, &tmp);
1838 TRACE("returns GL_ALPHA_BITS as '%d'\n", tmp);
1843 static GLboolean WINAPI X11DRV_wglIsEnabled(GLenum cap)
1847 if (cap == GL_SCISSOR_TEST)
1849 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1850 enabled = ctx->scissor_enabled;
1854 enabled = pglIsEnabled(cap);
1860 static void WINAPI X11DRV_wglScissor(GLint x, GLint y, GLsizei width, GLsizei height)
1862 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1864 ctx->scissor.left = x;
1865 ctx->scissor.top = y;
1866 ctx->scissor.right = x + width;
1867 ctx->scissor.bottom = y + height;
1869 sync_current_drawable();
1872 static void WINAPI X11DRV_wglViewport(GLint x, GLint y, GLsizei width, GLsizei height)
1874 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1876 ctx->viewport.left = x;
1877 ctx->viewport.top = y;
1878 ctx->viewport.right = x + width;
1879 ctx->viewport.bottom = y + height;
1881 sync_current_drawable();
1885 * X11DRV_wglGetExtensionsStringARB
1887 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1889 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
1890 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1891 return WineGLInfo.wglExtensions;
1895 * X11DRV_wglCreatePbufferARB
1897 * WGL_ARB_pbuffer: wglCreatePbufferARB
1899 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
1901 Wine_GLPBuffer* object = NULL;
1902 GLXFBConfig* cfgs = NULL;
1905 unsigned nAttribs = 0;
1908 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1910 if (0 >= iPixelFormat) {
1911 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
1912 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1913 return NULL; /* unexpected error */
1916 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1918 if (NULL == cfgs || 0 == nCfgs) {
1919 ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
1920 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1921 return NULL; /* unexpected error */
1924 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1925 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nCfgs)) {
1926 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
1927 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1928 goto create_failed; /* unexpected error */
1931 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
1932 if (NULL == object) {
1933 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1934 goto create_failed; /* unexpected error */
1937 object->display = gdi_display;
1938 object->width = iWidth;
1939 object->height = iHeight;
1940 object->pixelFormat = iPixelFormat;
1942 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
1943 if (-1 == nAttribs) {
1944 WARN("Cannot convert WGL to GLX attributes\n");
1947 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1948 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1949 while (0 != *piAttribList) {
1951 switch (*piAttribList) {
1952 case WGL_TEXTURE_FORMAT_ARB: {
1954 attr_v = *piAttribList;
1955 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
1956 if (use_render_texture_ati) {
1959 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
1960 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
1961 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
1963 SetLastError(ERROR_INVALID_DATA);
1966 object->use_render_texture = 1;
1967 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
1969 if (WGL_NO_TEXTURE_ARB == attr_v) {
1970 object->use_render_texture = 0;
1972 if (!use_render_texture_emulation) {
1973 SetLastError(ERROR_INVALID_DATA);
1977 case WGL_TEXTURE_RGB_ARB:
1978 object->use_render_texture = GL_RGB;
1980 case WGL_TEXTURE_RGBA_ARB:
1981 object->use_render_texture = GL_RGBA;
1984 SetLastError(ERROR_INVALID_DATA);
1992 case WGL_TEXTURE_TARGET_ARB: {
1994 attr_v = *piAttribList;
1995 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
1996 if (use_render_texture_ati) {
1999 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2000 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2001 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2002 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2004 SetLastError(ERROR_INVALID_DATA);
2007 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2009 if (WGL_NO_TEXTURE_ARB == attr_v) {
2010 object->texture_target = 0;
2012 if (!use_render_texture_emulation) {
2013 SetLastError(ERROR_INVALID_DATA);
2017 case WGL_TEXTURE_CUBE_MAP_ARB: {
2018 if (iWidth != iHeight) {
2019 SetLastError(ERROR_INVALID_DATA);
2022 object->texture_target = GL_TEXTURE_CUBE_MAP;
2023 object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
2026 case WGL_TEXTURE_1D_ARB: {
2028 SetLastError(ERROR_INVALID_DATA);
2031 object->texture_target = GL_TEXTURE_1D;
2032 object->texture_bind_target = GL_TEXTURE_1D;
2035 case WGL_TEXTURE_2D_ARB: {
2036 object->texture_target = GL_TEXTURE_2D;
2037 object->texture_bind_target = GL_TEXTURE_2D;
2041 SetLastError(ERROR_INVALID_DATA);
2049 case WGL_MIPMAP_TEXTURE_ARB: {
2051 attr_v = *piAttribList;
2052 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2053 if (use_render_texture_ati) {
2054 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2056 if (!use_render_texture_emulation) {
2057 SetLastError(ERROR_INVALID_DATA);
2067 PUSH1(attribs, None);
2068 object->drawable = pglXCreatePbuffer(gdi_display, cfgs[fmt_index], attribs);
2069 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2070 if (!object->drawable) {
2071 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2072 goto create_failed; /* unexpected error */
2074 TRACE("->(%p)\n", object);
2078 return (HPBUFFERARB) object;
2081 if (NULL != cfgs) XFree(cfgs);
2082 HeapFree(GetProcessHeap(), 0, object);
2083 TRACE("->(FAILED)\n");
2084 return (HPBUFFERARB) NULL;
2088 * X11DRV_wglDestroyPbufferARB
2090 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2092 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2094 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2095 TRACE("(%p)\n", hPbuffer);
2096 if (NULL == object) {
2097 SetLastError(ERROR_INVALID_HANDLE);
2100 pglXDestroyPbuffer(object->display, object->drawable);
2101 HeapFree(GetProcessHeap(), 0, object);
2106 * X11DRV_wglGetPbufferDCARB
2108 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2109 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2110 * Gdi32 implements the part of this function which creates a device context.
2111 * This part associates the physDev with the X drawable of the pbuffer.
2113 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2115 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2116 if (NULL == object) {
2117 SetLastError(ERROR_INVALID_HANDLE);
2121 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2122 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2123 physDev->current_pf = object->pixelFormat;
2124 physDev->drawable = object->drawable;
2126 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2127 return physDev->hdc;
2131 * X11DRV_wglQueryPbufferARB
2133 * WGL_ARB_pbuffer: wglQueryPbufferARB
2135 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2137 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2138 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2139 if (NULL == object) {
2140 SetLastError(ERROR_INVALID_HANDLE);
2143 switch (iAttribute) {
2144 case WGL_PBUFFER_WIDTH_ARB:
2145 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2147 case WGL_PBUFFER_HEIGHT_ARB:
2148 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2151 case WGL_PBUFFER_LOST_ARB:
2152 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
2155 case WGL_TEXTURE_FORMAT_ARB:
2156 if (use_render_texture_ati) {
2158 int type = WGL_NO_TEXTURE_ARB;
2159 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2161 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2162 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2163 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2167 if (!object->use_render_texture) {
2168 *piValue = WGL_NO_TEXTURE_ARB;
2170 if (!use_render_texture_emulation) {
2171 SetLastError(ERROR_INVALID_HANDLE);
2174 if (GL_RGBA == object->use_render_texture) {
2175 *piValue = WGL_TEXTURE_RGBA_ARB;
2177 *piValue = WGL_TEXTURE_RGB_ARB;
2183 case WGL_TEXTURE_TARGET_ARB:
2184 if (use_render_texture_ati) {
2186 int type = WGL_NO_TEXTURE_ARB;
2187 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2189 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2190 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2191 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2192 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2196 if (!object->texture_target) {
2197 *piValue = WGL_NO_TEXTURE_ARB;
2199 if (!use_render_texture_emulation) {
2200 SetLastError(ERROR_INVALID_DATA);
2203 switch (object->texture_target) {
2204 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2205 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_1D_ARB; break;
2206 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_2D_ARB; break;
2212 case WGL_MIPMAP_TEXTURE_ARB:
2213 if (use_render_texture_ati) {
2214 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2216 *piValue = GL_FALSE; /** don't support that */
2217 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2222 FIXME("unexpected attribute %x\n", iAttribute);
2230 * X11DRV_wglReleasePbufferDCARB
2232 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2234 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2236 TRACE("(%p, %p)\n", hPbuffer, hdc);
2242 * X11DRV_wglSetPbufferAttribARB
2244 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2246 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2248 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2249 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2250 if (NULL == object) {
2251 SetLastError(ERROR_INVALID_HANDLE);
2254 if (!object->use_render_texture) {
2255 SetLastError(ERROR_INVALID_HANDLE);
2258 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2261 if (NULL != pglXDrawableAttribARB) {
2262 if (use_render_texture_ati) {
2263 FIXME("Need conversion for GLX_ATI_render_texture\n");
2265 return pglXDrawableAttribARB(object->display, object->drawable, piAttribList);
2271 * X11DRV_wglChoosePixelFormatARB
2273 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2275 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2280 GLXFBConfig* cfgs = NULL;
2285 GLXFBConfig* cfgs_fmt = NULL;
2291 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2292 if (NULL != pfAttribFList) {
2293 FIXME("unused pfAttribFList\n");
2296 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2297 if (-1 == nAttribs) {
2298 WARN("Cannot convert WGL to GLX attributes\n");
2301 PUSH1(attribs, None);
2303 /* Search for FB configurations matching the requirements in attribs */
2304 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2306 WARN("Compatible Pixel Format not found\n");
2310 /* Get a list of all FB configurations */
2311 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
2312 if (NULL == cfgs_fmt) {
2313 ERR("Failed to get All FB Configs\n");
2318 /* Loop through all matching formats and check if they are suitable.
2319 * Note that this function should at max return nMaxFormats different formats */
2320 for (it = 0; pfmt_it < nMaxFormats && it < nCfgs; ++it) {
2321 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2323 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2327 /* Search for the format in our list of compatible formats */
2328 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2332 piFormats[pfmt_it] = fmt;
2333 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d/%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it], nCfgs_fmt);
2337 *nNumFormats = pfmt_it;
2345 * X11DRV_wglGetPixelFormatAttribivARB
2347 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2349 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2352 GLXFBConfig* cfgs = NULL;
2353 GLXFBConfig curCfg = NULL;
2358 int nWGLFormats = 0;
2361 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2363 if (0 < iLayerPlane) {
2364 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2368 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
2370 ERR("no FB Configs found for display(%p)\n", gdi_display);
2374 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2375 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2376 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2377 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nWGLFormats)) {
2378 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2381 for (i = 0; i < nAttributes; ++i) {
2382 const int curWGLAttr = piAttributes[i];
2383 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2385 switch (curWGLAttr) {
2386 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2387 piValues[i] = nWGLFormats;
2390 case WGL_SUPPORT_OPENGL_ARB:
2391 piValues[i] = GL_TRUE;
2394 case WGL_ACCELERATION_ARB:
2395 curGLXAttr = GLX_CONFIG_CAVEAT;
2397 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
2398 curCfg = cfgs[iPixelFormat - 1];
2400 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2401 if (hTest) goto get_error;
2403 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2404 case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
2405 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2407 ERR("unexpected Config Caveat(%x)\n", tmp);
2408 piValues[i] = WGL_NO_ACCELERATION_ARB;
2412 case WGL_TRANSPARENT_ARB:
2413 curGLXAttr = GLX_TRANSPARENT_TYPE;
2414 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2415 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2416 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2417 curCfg = cfgs[fmt_index];
2418 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2419 if (hTest) goto get_error;
2420 piValues[i] = GL_FALSE;
2421 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2424 case WGL_PIXEL_TYPE_ARB:
2425 curGLXAttr = GLX_RENDER_TYPE;
2426 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2427 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2428 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2429 curCfg = cfgs[fmt_index];
2430 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2431 if (hTest) goto get_error;
2432 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2433 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2434 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2435 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2436 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2438 ERR("unexpected RenderType(%x)\n", tmp);
2439 piValues[i] = WGL_TYPE_RGBA_ARB;
2443 case WGL_COLOR_BITS_ARB:
2444 /** see ConvertAttribWGLtoGLX for explain */
2445 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2446 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2447 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2448 curCfg = cfgs[fmt_index];
2449 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_BUFFER_SIZE, piValues + i);
2450 if (hTest) goto get_error;
2451 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues[i]);
2452 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_ALPHA_SIZE, &tmp);
2453 if (hTest) goto get_error;
2454 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp);
2455 piValues[i] = piValues[i] - tmp;
2458 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2459 if (use_render_texture_ati) {
2460 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2463 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2464 if (use_render_texture_ati) {
2465 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2468 if (!use_render_texture_emulation) {
2469 piValues[i] = GL_FALSE;
2472 curGLXAttr = GLX_RENDER_TYPE;
2473 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2474 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2475 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2476 curCfg = cfgs[fmt_index];
2477 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2478 if (hTest) goto get_error;
2479 if (GLX_COLOR_INDEX_BIT == tmp) {
2480 piValues[i] = GL_FALSE;
2483 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp);
2484 if (hTest) goto get_error;
2485 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2488 case WGL_BLUE_BITS_ARB:
2489 curGLXAttr = GLX_BLUE_SIZE;
2491 case WGL_RED_BITS_ARB:
2492 curGLXAttr = GLX_RED_SIZE;
2494 case WGL_GREEN_BITS_ARB:
2495 curGLXAttr = GLX_GREEN_SIZE;
2497 case WGL_ALPHA_BITS_ARB:
2498 curGLXAttr = GLX_ALPHA_SIZE;
2500 case WGL_DEPTH_BITS_ARB:
2501 curGLXAttr = GLX_DEPTH_SIZE;
2503 case WGL_STENCIL_BITS_ARB:
2504 curGLXAttr = GLX_STENCIL_SIZE;
2506 case WGL_DOUBLE_BUFFER_ARB:
2507 curGLXAttr = GLX_DOUBLEBUFFER;
2509 case WGL_STEREO_ARB:
2510 curGLXAttr = GLX_STEREO;
2512 case WGL_AUX_BUFFERS_ARB:
2513 curGLXAttr = GLX_AUX_BUFFERS;
2515 case WGL_SUPPORT_GDI_ARB:
2516 case WGL_DRAW_TO_WINDOW_ARB:
2517 case WGL_DRAW_TO_BITMAP_ARB:
2518 /* We only supported a limited number of formats right now which are all renderable by X 'GLX_X_RENDERABLE' */
2519 piValues[i] = GL_TRUE;
2521 case WGL_DRAW_TO_PBUFFER_ARB:
2522 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp);
2523 if (hTest) goto get_error;
2524 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2527 case WGL_PBUFFER_LARGEST_ARB:
2528 curGLXAttr = GLX_LARGEST_PBUFFER;
2531 case WGL_SAMPLE_BUFFERS_ARB:
2532 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2535 case WGL_SAMPLES_ARB:
2536 curGLXAttr = GLX_SAMPLES_ARB;
2540 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2543 if (0 != curGLXAttr) {
2544 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2545 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2546 if((iPixelFormat > 0) && ((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs))) goto pix_error;
2547 curCfg = cfgs[fmt_index];
2548 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, piValues + i);
2549 if (hTest) goto get_error;
2552 piValues[i] = GL_FALSE;
2558 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2563 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
2569 * X11DRV_wglGetPixelFormatAttribfvARB
2571 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2573 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2579 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2581 /* Allocate a temporary array to store integer values */
2582 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2584 ERR("couldn't allocate %d array\n", nAttributes);
2588 /* Piggy-back on wglGetPixelFormatAttribivARB */
2589 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2591 /* Convert integer values to float. Should also check for attributes
2592 that can give decimal values here */
2593 for (i=0; i<nAttributes;i++) {
2594 pfValues[i] = attr[i];
2598 HeapFree(GetProcessHeap(), 0, attr);
2603 * X11DRV_wglBindTexImageARB
2605 * WGL_ARB_render_texture: wglBindTexImageARB
2607 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2609 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2610 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2611 if (NULL == object) {
2612 SetLastError(ERROR_INVALID_HANDLE);
2615 if (!object->use_render_texture) {
2616 SetLastError(ERROR_INVALID_HANDLE);
2619 /* Disable WGL_ARB_render_texture support until it is implemented properly
2620 * using pbuffers or FBOs */
2622 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2624 GLint prev_binded_tex;
2625 pglGetIntegerv(object->texture_target, &prev_binded_tex);
2626 if (NULL == object->render_ctx) {
2627 object->render_hdc = X11DRV_wglGetPbufferDCARB(hPbuffer);
2628 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2629 object->render_ctx = wglCreateContext(object->render_hdc);
2632 object->prev_hdc = wglGetCurrentDC();
2633 object->prev_ctx = wglGetCurrentContext();
2634 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2635 wglMakeCurrent(object->render_hdc, object->render_ctx);
2638 glBindTexture(object->texture_target, object->texture);
2639 if (GL_RGBA == object->use_render_texture) {
2640 glTexImage2D(object->texture_target, 0, GL_RGBA8, object->width, object->height, 0, GL_RGBA, GL_FLOAT, NULL);
2642 glTexImage2D(object->texture_target, 0, GL_RGB8, object->width, object->height, 0, GL_RGB, GL_FLOAT, NULL);
2646 object->texture = prev_binded_tex;
2650 if (NULL != pglXBindTexImageARB) {
2651 return pglXBindTexImageARB(object->display, object->drawable, iBuffer);
2657 * X11DRV_wglReleaseTexImageARB
2659 * WGL_ARB_render_texture: wglReleaseTexImageARB
2661 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2663 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2664 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2665 if (NULL == object) {
2666 SetLastError(ERROR_INVALID_HANDLE);
2669 if (!object->use_render_texture) {
2670 SetLastError(ERROR_INVALID_HANDLE);
2673 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2675 GLint prev_binded_tex;
2676 glGetIntegerv(object->texture_target, &prev_binded_tex);
2677 if (GL_TEXTURE_1D == object->texture_target) {
2678 glCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2680 glCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2682 glBindTexture(object->texture_target, prev_binded_tex);
2683 SwapBuffers(object->render_hdc);
2685 pglBindTexture(object->texture_target, object->texture);
2686 if (GL_TEXTURE_1D == object->texture_target) {
2687 pglCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2689 pglCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2692 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2693 wglMakeCurrent(object->prev_hdc, object->prev_ctx);
2696 if (NULL != pglXReleaseTexImageARB) {
2697 return pglXReleaseTexImageARB(object->display, object->drawable, iBuffer);
2703 * X11DRV_wglGetExtensionsStringEXT
2705 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2707 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2708 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2709 return WineGLInfo.wglExtensions;
2713 * X11DRV_wglGetSwapIntervalEXT
2715 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2717 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2718 FIXME("(),stub!\n");
2719 return swap_interval;
2723 * X11DRV_wglSwapIntervalEXT
2725 * WGL_EXT_swap_control: wglSwapIntervalEXT
2727 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2728 TRACE("(%d)\n", interval);
2729 swap_interval = interval;
2730 if (NULL != pglXSwapIntervalSGI) {
2731 return 0 == pglXSwapIntervalSGI(interval);
2733 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2738 * X11DRV_wglAllocateMemoryNV
2740 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2742 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2743 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2744 if (pglXAllocateMemoryNV == NULL)
2747 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2751 * X11DRV_wglFreeMemoryNV
2753 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2755 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2756 TRACE("(%p)\n", pointer);
2757 if (pglXFreeMemoryNV == NULL)
2760 pglXFreeMemoryNV(pointer);
2764 * glxRequireVersion (internal)
2766 * Check if the supported GLX version matches requiredVersion.
2768 static BOOL glxRequireVersion(int requiredVersion)
2770 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2771 if(requiredVersion <= WineGLInfo.glxVersion[1])
2777 static BOOL glxRequireExtension(const char *requiredExtension)
2779 if (strstr(WineGLInfo.glxClientExtensions, requiredExtension) == NULL) {
2786 static BOOL register_extension(const WineGLExtension * ext)
2790 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
2791 WineGLExtensionList[WineGLExtensionListSize++] = ext;
2793 strcat(WineGLInfo.wglExtensions, " ");
2794 strcat(WineGLInfo.wglExtensions, ext->extName);
2796 TRACE("'%s'\n", ext->extName);
2798 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
2799 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
2804 static const WineGLExtension WGL_internal_functions =
2808 { "wglDisable", X11DRV_wglDisable },
2809 { "wglEnable", X11DRV_wglEnable },
2810 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
2811 { "wglIsEnabled", X11DRV_wglIsEnabled },
2812 { "wglScissor", X11DRV_wglScissor },
2813 { "wglViewport", X11DRV_wglViewport },
2818 static const WineGLExtension WGL_ARB_extensions_string =
2820 "WGL_ARB_extensions_string",
2822 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
2826 static const WineGLExtension WGL_ARB_make_current_read =
2828 "WGL_ARB_make_current_read",
2830 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
2831 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
2835 static const WineGLExtension WGL_ARB_multisample =
2837 "WGL_ARB_multisample",
2840 static const WineGLExtension WGL_ARB_pbuffer =
2844 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
2845 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
2846 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
2847 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
2848 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
2849 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
2853 static const WineGLExtension WGL_ARB_pixel_format =
2855 "WGL_ARB_pixel_format",
2857 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
2858 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
2859 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
2863 static const WineGLExtension WGL_ARB_render_texture =
2865 "WGL_ARB_render_texture",
2867 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
2868 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
2872 static const WineGLExtension WGL_EXT_extensions_string =
2874 "WGL_EXT_extensions_string",
2876 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
2880 static const WineGLExtension WGL_EXT_swap_control =
2882 "WGL_EXT_swap_control",
2884 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
2885 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
2889 static const WineGLExtension WGL_NV_vertex_array_range =
2891 "WGL_NV_vertex_array_range",
2893 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
2894 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
2899 * X11DRV_WineGL_LoadExtensions
2901 static void X11DRV_WineGL_LoadExtensions(void)
2903 WineGLInfo.wglExtensions[0] = 0;
2905 /* Load Wine internal functions */
2906 register_extension(&WGL_internal_functions);
2908 /* ARB Extensions */
2910 register_extension(&WGL_ARB_extensions_string);
2912 if (glxRequireVersion(3))
2913 register_extension(&WGL_ARB_make_current_read);
2915 if (glxRequireExtension("GLX_ARB_multisample"))
2916 register_extension(&WGL_ARB_multisample);
2918 if (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer"))
2919 register_extension(&WGL_ARB_pbuffer);
2921 register_extension(&WGL_ARB_pixel_format);
2923 if (glxRequireExtension("GLX_ATI_render_texture") ||
2924 glxRequireExtension("GLX_ARB_render_texture"))
2925 register_extension(&WGL_ARB_render_texture);
2927 /* EXT Extensions */
2929 register_extension(&WGL_EXT_extensions_string);
2931 if (glxRequireExtension("GLX_SGI_swap_control"))
2932 register_extension(&WGL_EXT_swap_control);
2934 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2935 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
2936 register_extension(&WGL_NV_vertex_array_range);
2940 static XID create_glxpixmap(X11DRV_PDEVICE *physDev)
2944 XVisualInfo template;
2949 /* Retrieve the visualid from our main visual which is the only visual we can use */
2950 template.visualid = XVisualIDFromVisual(visual);
2951 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
2953 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
2955 wine_tsx11_unlock();
2956 TRACE("return %lx\n", ret);
2960 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
2966 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
2967 ret = physDev->drawable; /* PBuffer */
2970 if(!physDev->bitmap->glxpixmap)
2971 physDev->bitmap->glxpixmap = create_glxpixmap(physDev);
2972 ret = physDev->bitmap->glxpixmap;
2976 ret = physDev->drawable;
2980 BOOL destroy_glxpixmap(XID glxpixmap)
2983 pglXDestroyGLXPixmap(gdi_display, glxpixmap);
2984 wine_tsx11_unlock();
2989 * X11DRV_SwapBuffers
2991 * Swap the buffers of this DC
2993 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
2995 GLXDrawable drawable;
2996 if (!has_opengl()) {
2997 ERR("No libGL on this box - disabling OpenGL support !\n");
3001 TRACE_(opengl)("(%p)\n", physDev);
3003 drawable = get_glxdrawable(physDev);
3005 pglXSwapBuffers(gdi_display, drawable);
3006 wine_tsx11_unlock();
3011 static long prev_time, frames;
3013 DWORD time = GetTickCount();
3015 /* every 1.5 seconds */
3016 if (time - prev_time > 1500) {
3017 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3026 /***********************************************************************
3027 * X11DRV_setup_opengl_visual
3029 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3030 * window (if it exists). If OpenGL isn't available, the visual is simply
3031 * set to the default visual for the display
3033 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3035 XVisualInfo *visual = NULL;
3036 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support, */
3037 int dblBuf[] = {GLX_RGBA,GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DOUBLEBUFFER, None};
3038 if (!has_opengl()) return NULL;
3041 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf);
3042 wine_tsx11_unlock();
3043 if (visual == NULL) {
3044 /* fallback to 16 bits depth, no alpha */
3045 int dblBuf2[] = {GLX_RGBA,GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, None};
3046 WARN("Failed to get a visual with at least 24 bits depth\n");
3049 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf2);
3050 wine_tsx11_unlock();
3051 if (visual == NULL) {
3052 /* fallback to no stencil */
3053 int dblBuf2[] = {GLX_RGBA,GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
3054 WARN("Failed to get a visual with at least 8 bits of stencil\n");
3057 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf2);
3058 wine_tsx11_unlock();
3059 if (visual == NULL) {
3060 /* This should only happen if we cannot find a match with a depth size 16 */
3061 FIXME("Failed to find a suitable visual\n");
3066 TRACE("Visual ID %lx Chosen\n",visual->visualid);
3070 #else /* no OpenGL includes */
3072 /***********************************************************************
3073 * ChoosePixelFormat (X11DRV.@)
3075 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3076 const PIXELFORMATDESCRIPTOR *ppfd) {
3077 ERR("No OpenGL support compiled in.\n");
3082 /***********************************************************************
3083 * DescribePixelFormat (X11DRV.@)
3085 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3088 PIXELFORMATDESCRIPTOR *ppfd) {
3089 ERR("No OpenGL support compiled in.\n");
3094 /***********************************************************************
3095 * GetPixelFormat (X11DRV.@)
3097 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3098 ERR("No OpenGL support compiled in.\n");
3103 /***********************************************************************
3104 * SetPixelFormat (X11DRV.@)
3106 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3108 const PIXELFORMATDESCRIPTOR *ppfd) {
3109 ERR("No OpenGL support compiled in.\n");
3114 /***********************************************************************
3115 * SwapBuffers (X11DRV.@)
3117 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3118 ERR_(opengl)("No OpenGL support compiled in.\n");
3124 * X11DRV_wglCreateContext
3126 * For OpenGL32 wglCreateContext.
3128 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3129 ERR_(opengl)("No OpenGL support compiled in.\n");
3134 * X11DRV_wglDeleteContext
3136 * For OpenGL32 wglDeleteContext.
3138 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3139 ERR_(opengl)("No OpenGL support compiled in.\n");
3144 * X11DRV_wglGetProcAddress
3146 * For OpenGL32 wglGetProcAddress.
3148 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3149 ERR_(opengl)("No OpenGL support compiled in.\n");
3153 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3155 ERR_(opengl)("No OpenGL support compiled in.\n");
3159 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3160 ERR_(opengl)("No OpenGL support compiled in.\n");
3165 * X11DRV_wglMakeCurrent
3167 * For OpenGL32 wglMakeCurrent.
3169 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3170 ERR_(opengl)("No OpenGL support compiled in.\n");
3175 * X11DRV_wglShareLists
3177 * For OpenGL32 wglShaderLists.
3179 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3180 ERR_(opengl)("No OpenGL support compiled in.\n");
3185 * X11DRV_wglUseFontBitmapsA
3187 * For OpenGL32 wglUseFontBitmapsA.
3189 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3191 ERR_(opengl)("No OpenGL support compiled in.\n");
3196 * X11DRV_wglUseFontBitmapsW
3198 * For OpenGL32 wglUseFontBitmapsW.
3200 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3202 ERR_(opengl)("No OpenGL support compiled in.\n");
3206 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3211 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3216 BOOL destroy_glxpixmap(XID glxpixmap)
3221 #endif /* defined(HAVE_OPENGL) */