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 struct wine_glcontext *next;
78 struct wine_glcontext *prev;
81 typedef struct wine_glpbuffer {
90 int use_render_texture;
91 GLuint texture_target;
92 GLuint texture_bind_target;
101 typedef struct wine_glextension {
104 const char *funcName;
110 const char *glVersion;
111 const char *glExtensions;
115 const char *glxServerVersion;
116 const char *glxServerExtensions;
118 const char *glxClientVersion;
119 const char *glxClientExtensions;
121 const char *glxExtensions;
124 char wglExtensions[4096];
127 typedef struct wine_glpixelformat {
133 static Wine_GLContext *context_list;
134 static struct WineGLInfo WineGLInfo = { 0 };
135 static int use_render_texture_emulation = 0;
136 static int use_render_texture_ati = 0;
137 static int swap_interval = 1;
139 #define MAX_EXTENSIONS 16
140 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
141 static int WineGLExtensionListSize;
143 #define MAX_GLPIXELFORMATS 32
144 static WineGLPixelFormat WineGLPixelFormatList[MAX_GLPIXELFORMATS];
145 static int WineGLPixelFormatListSize = 0;
147 static void X11DRV_WineGL_LoadExtensions(void);
149 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
150 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
151 TRACE(" - dwFlags : ");
152 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
153 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
154 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
155 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
156 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
157 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
158 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
159 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
172 TRACE(" - iPixelType : ");
173 switch (ppfd->iPixelType) {
174 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
175 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
179 TRACE(" - Color : %d\n", ppfd->cColorBits);
180 TRACE(" - Red : %d\n", ppfd->cRedBits);
181 TRACE(" - Green : %d\n", ppfd->cGreenBits);
182 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
183 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
184 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
185 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
186 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
187 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
189 TRACE(" - iLayerType : ");
190 switch (ppfd->iLayerType) {
191 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
192 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
193 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
198 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and
199 include all dependencies
202 #define SONAME_LIBGL "libGL.so"
205 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
206 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
208 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
210 MAKE_FUNCPTR(glXChooseVisual)
211 MAKE_FUNCPTR(glXCreateContext)
212 MAKE_FUNCPTR(glXCreateGLXPixmap)
213 MAKE_FUNCPTR(glXGetCurrentContext)
214 MAKE_FUNCPTR(glXDestroyContext)
215 MAKE_FUNCPTR(glXDestroyGLXPixmap)
216 MAKE_FUNCPTR(glXGetConfig)
217 MAKE_FUNCPTR(glXIsDirect)
218 MAKE_FUNCPTR(glXMakeCurrent)
219 MAKE_FUNCPTR(glXSwapBuffers)
220 MAKE_FUNCPTR(glXQueryExtension)
221 MAKE_FUNCPTR(glXQueryVersion)
222 MAKE_FUNCPTR(glXUseXFont)
225 MAKE_FUNCPTR(glXGetClientString)
226 MAKE_FUNCPTR(glXQueryExtensionsString)
227 MAKE_FUNCPTR(glXQueryServerString)
230 MAKE_FUNCPTR(glXGetFBConfigs)
231 MAKE_FUNCPTR(glXChooseFBConfig)
232 MAKE_FUNCPTR(glXCreatePbuffer)
233 MAKE_FUNCPTR(glXDestroyPbuffer)
234 MAKE_FUNCPTR(glXGetFBConfigAttrib)
235 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
236 MAKE_FUNCPTR(glXMakeContextCurrent)
237 MAKE_FUNCPTR(glXQueryDrawable)
238 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
241 static void* (*pglXGetProcAddressARB)(const GLubyte *);
242 static BOOL (*pglXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
243 static BOOL (*pglXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
244 static BOOL (*pglXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
245 static int (*pglXSwapIntervalSGI)(int);
247 /* NV GLX Extension */
248 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
249 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
251 /* Standard OpenGL */
252 MAKE_FUNCPTR(glBindTexture)
253 MAKE_FUNCPTR(glBitmap)
254 MAKE_FUNCPTR(glCopyTexSubImage1D)
255 MAKE_FUNCPTR(glCopyTexSubImage2D)
256 MAKE_FUNCPTR(glDrawBuffer)
257 MAKE_FUNCPTR(glEndList)
258 MAKE_FUNCPTR(glGetError)
259 MAKE_FUNCPTR(glGetIntegerv)
260 MAKE_FUNCPTR(glGetString)
261 MAKE_FUNCPTR(glNewList)
262 MAKE_FUNCPTR(glPixelStorei)
265 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
267 static BOOL infoInitialized = FALSE;
269 int screen = DefaultScreen(gdi_display);
270 Window win = RootWindow(gdi_display, screen);
272 XVisualInfo template;
275 GLXContext ctx = NULL;
279 infoInitialized = TRUE;
283 visual = DefaultVisual(gdi_display, screen);
284 template.visualid = XVisualIDFromVisual(visual);
285 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
287 /* Create a GLX Context. Without one we can't query GL information */
288 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
292 pglXMakeCurrent(gdi_display, win, ctx);
294 ERR(" couldn't initialize OpenGL, expect problems\n");
299 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
300 WineGLInfo.glExtensions = (const char *) pglGetString(GL_EXTENSIONS);
302 /* Get the common GLX version supported by GLX client and server ( major/minor) */
303 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
305 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
306 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
308 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
309 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
311 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
312 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
314 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
315 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
316 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
317 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
318 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
322 pglXMakeCurrent(gdi_display, None, NULL);
323 pglXDestroyContext(gdi_display, ctx);
329 static BOOL has_opengl(void)
331 static int init_done;
332 static void *opengl_handle;
333 const char *glx_extensions;
335 int error_base, event_base;
337 if (init_done) return (opengl_handle != NULL);
340 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
341 if (opengl_handle == NULL) return FALSE;
343 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
344 if (pglXGetProcAddressARB == NULL) {
345 ERR("could not find glXGetProcAddressARB in libGL.\n");
349 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
351 LOAD_FUNCPTR(glXChooseVisual)
352 LOAD_FUNCPTR(glXCreateContext)
353 LOAD_FUNCPTR(glXCreateGLXPixmap)
354 LOAD_FUNCPTR(glXGetCurrentContext)
355 LOAD_FUNCPTR(glXDestroyContext)
356 LOAD_FUNCPTR(glXDestroyGLXPixmap)
357 LOAD_FUNCPTR(glXGetConfig)
358 LOAD_FUNCPTR(glXIsDirect)
359 LOAD_FUNCPTR(glXMakeCurrent)
360 LOAD_FUNCPTR(glXSwapBuffers)
361 LOAD_FUNCPTR(glXQueryExtension)
362 LOAD_FUNCPTR(glXQueryVersion)
363 LOAD_FUNCPTR(glXUseXFont)
366 LOAD_FUNCPTR(glXGetClientString)
367 LOAD_FUNCPTR(glXQueryExtensionsString)
368 LOAD_FUNCPTR(glXQueryServerString)
371 LOAD_FUNCPTR(glXCreatePbuffer)
372 LOAD_FUNCPTR(glXDestroyPbuffer)
373 LOAD_FUNCPTR(glXMakeContextCurrent)
374 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
375 LOAD_FUNCPTR(glXGetFBConfigs)
377 /* Standard OpenGL calls */
378 LOAD_FUNCPTR(glBindTexture)
379 LOAD_FUNCPTR(glBitmap)
380 LOAD_FUNCPTR(glEndList)
381 LOAD_FUNCPTR(glCopyTexSubImage1D)
382 LOAD_FUNCPTR(glCopyTexSubImage2D)
383 LOAD_FUNCPTR(glDrawBuffer)
384 LOAD_FUNCPTR(glGetError)
385 LOAD_FUNCPTR(glGetIntegerv)
386 LOAD_FUNCPTR(glGetString)
387 LOAD_FUNCPTR(glNewList)
388 LOAD_FUNCPTR(glPixelStorei)
391 /* It doesn't matter if these fail. They'll only be used if the driver reports
392 the associated extension is available (and if a driver reports the extension
393 is available but fails to provide the functions, it's quite broken) */
394 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
395 /* NV GLX Extension */
396 LOAD_FUNCPTR(glXAllocateMemoryNV)
397 LOAD_FUNCPTR(glXFreeMemoryNV)
400 if(!X11DRV_WineGL_InitOpenglInfo()) {
401 ERR("Intialization of OpenGL info failed, disabling OpenGL!\n");
402 wine_dlclose(opengl_handle, NULL, 0);
403 opengl_handle = NULL;
408 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
409 TRACE("GLX is up and running error_base = %d\n", error_base);
411 wine_dlclose(opengl_handle, NULL, 0);
412 opengl_handle = NULL;
415 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
416 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
419 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
420 * depends on the reported GLX client / server version and on the client / server extension list.
421 * Those don't have to be the same.
423 * In general the server GLX information should be used in case of indirect rendering. When direct
424 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
425 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
426 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
427 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
428 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
429 * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
430 * is only available in the list of server extensions and not in the client list.
432 * The versioning checks below try to take into account the comments from above.
435 /* Depending on the use of direct or indirect rendering we need either the list of extensions
436 * exported by the client or by the server.
438 if(WineGLInfo.glxDirect)
439 glx_extensions = WineGLInfo.glxClientExtensions;
441 glx_extensions = WineGLInfo.glxServerExtensions;
443 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
444 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
445 * the client version is checked.
447 if ((!WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxServerVersion)) ||
448 (WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxClientVersion)))
450 if (NULL != strstr(glx_extensions, "GLX_SGIX_fbconfig")) {
451 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
452 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
453 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
455 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxClientVersion);
458 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
459 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
460 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
463 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
464 * enable this function when the Xserver understand GLX 1.3 or newer
466 if (!strcmp("1.2", WineGLInfo.glxServerVersion))
467 pglXQueryDrawable = NULL;
469 pglXQueryDrawable = wine_dlsym(RTLD_DEFAULT, "glXQueryDrawable", NULL, 0);
471 if (NULL != strstr(glx_extensions, "GLX_ATI_render_texture")) {
472 pglXBindTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageARB");
473 pglXReleaseTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageARB");
474 pglXDrawableAttribARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribARB");
477 X11DRV_WineGL_LoadExtensions();
480 return (opengl_handle != NULL);
483 wine_dlclose(opengl_handle, NULL, 0);
484 opengl_handle = NULL;
488 static inline Wine_GLContext *alloc_context(void)
492 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
494 ret->next = context_list;
495 if (context_list) context_list->prev = ret;
501 static inline void free_context(Wine_GLContext *context)
503 if (context->next != NULL) context->next->prev = context->prev;
504 if (context->prev != NULL) context->prev->next = context->next;
505 else context_list = context->next;
507 HeapFree(GetProcessHeap(), 0, context);
510 static inline Wine_GLContext *get_context_from_GLXContext(GLXContext ctx)
513 if (!ctx) return NULL;
514 for (ret = context_list; ret; ret = ret->next) if (ctx == ret->ctx) break;
519 * get_drawable (internal)
521 * Retrieve the GLX drawable to use on a given DC.
523 inline static Drawable get_drawable( HDC hdc )
525 GLXDrawable drawable;
526 enum x11drv_escape_codes escape = X11DRV_GET_GLX_DRAWABLE;
528 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
529 sizeof(drawable), (LPSTR)&drawable )) drawable = 0;
533 inline static void set_drawable( HDC hdc, Drawable drawable )
535 struct x11drv_escape_set_drawable escape;
537 escape.code = X11DRV_SET_DRAWABLE;
538 escape.drawable = drawable;
539 escape.mode = IncludeInferiors;
540 escape.org.x = escape.org.y = 0;
541 escape.drawable_org.x = escape.drawable_org.y = 0;
543 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL );
547 * get_hdc_from_Drawable (internal)
549 * For use by wglGetCurrentReadDCARB.
551 inline static HDC get_hdc_from_Drawable(GLXDrawable d)
554 for (ret = context_list; ret; ret = ret->next) {
555 if (d == get_drawable( ret->hdc )) {
562 inline static BOOL is_valid_context( Wine_GLContext *ctx )
565 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
566 return (ptr != NULL);
569 static int describeContext(Wine_GLContext* ctx) {
572 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
573 pglXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_FBCONFIG_ID, &tmp);
574 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
575 pglXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_VISUAL_ID, &tmp);
576 TRACE(" - VISUAL_ID 0x%x\n", tmp);
581 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
584 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
587 if (pglXQueryDrawable == NULL) {
588 /** glXQueryDrawable not available so returns not supported */
592 TRACE(" Drawable %p have :\n", (void*) drawable);
593 pglXQueryDrawable(ctx->display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
594 TRACE(" - WIDTH as %d\n", tmp);
595 pglXQueryDrawable(ctx->display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
596 TRACE(" - HEIGHT as %d\n", tmp);
597 pglXQueryDrawable(ctx->display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
598 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
601 fbCfgs = pglXChooseFBConfig(ctx->display, DefaultScreen(ctx->display), attribList, &nElements);
602 if (fbCfgs == NULL) {
606 pglXGetFBConfigAttrib(ctx->display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
607 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
614 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
620 int wantColorBits = 0;
623 while (0 != iWGLAttr[cur]) {
624 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
626 switch (iWGLAttr[cur]) {
627 case WGL_COLOR_BITS_ARB:
628 pop = iWGLAttr[++cur];
629 wantColorBits = pop; /** see end */
631 case WGL_BLUE_BITS_ARB:
632 pop = iWGLAttr[++cur];
633 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
634 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
636 case WGL_RED_BITS_ARB:
637 pop = iWGLAttr[++cur];
638 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
639 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
641 case WGL_GREEN_BITS_ARB:
642 pop = iWGLAttr[++cur];
643 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
644 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
646 case WGL_ALPHA_BITS_ARB:
647 pop = iWGLAttr[++cur];
649 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
650 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
652 case WGL_DEPTH_BITS_ARB:
653 pop = iWGLAttr[++cur];
654 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
655 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
657 case WGL_STENCIL_BITS_ARB:
658 pop = iWGLAttr[++cur];
659 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
660 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
662 case WGL_DOUBLE_BUFFER_ARB:
663 pop = iWGLAttr[++cur];
664 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
665 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
668 case WGL_PIXEL_TYPE_ARB:
669 pop = iWGLAttr[++cur];
671 case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; isColor = 1; break ;
672 case WGL_TYPE_RGBA_ARB: pop = GLX_RGBA_BIT; break ;
673 case WGL_TYPE_RGBA_FLOAT_ATI: pop = GLX_RGBA_FLOAT_ATI_BIT; break ;
675 ERR("unexpected PixelType(%x)\n", pop);
678 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
679 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
682 case WGL_SUPPORT_GDI_ARB:
683 pop = iWGLAttr[++cur];
684 /* We only support a limited number of formats which are all renderable by X (similar to GDI).
685 * Ignore this attribute to prevent us from not finding a match due to the limited
686 * amount of formats supported right now. This option could be matched to GLX_X_RENDERABLE
687 * but the issue is that when a program asks for no GDI support, there's no format we can return
688 * as all our supported formats are renderable by X.
690 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
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. */
698 drawattrib |= GLX_PIXMAP_BIT;
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. */
707 drawattrib |= GLX_WINDOW_BIT;
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. */
716 drawattrib |= GLX_PBUFFER_BIT;
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);
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);
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);
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);
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];
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 */
761 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
762 drawattrib |= GLX_PBUFFER_BIT;
767 case WGL_BIND_TO_TEXTURE_RGB_ARB:
768 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
769 pop = iWGLAttr[++cur];
770 /** cannot be converted, see direct handling on
771 * - wglGetPixelFormatAttribivARB
772 * TODO: wglChoosePixelFormat
777 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
784 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
785 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
788 * The number of color bitplanes in each color buffer. For RGBA
789 * pixel types, it is the size of the color buffer, excluding the
790 * alpha bitplanes. For color-index pixels, it is the size of the
791 * color index buffer.
794 * This attribute defines the number of bits per color buffer.
795 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
796 * this is equal to the depth value reported in the X11 visual.
797 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
798 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
801 if (0 < wantColorBits) {
803 wantColorBits += sz_alpha;
805 if (32 < wantColorBits) {
806 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
809 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
810 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
813 /* Apply the OR'd drawable type bitmask now. */
815 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
816 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
822 BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, int *fmt_id, int *fmt_index)
824 GLXFBConfig* cfgs = NULL;
831 if(!display || !display) {
832 ERR("Invalid display or visual\n");
834 visualid = XVisualIDFromVisual(visual);
836 /* Get a list of all available framebuffer configurations */
837 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
838 if (NULL == cfgs || 0 == nCfgs) {
839 ERR("glXChooseFBConfig returns NULL\n");
840 if(cfgs != NULL) XFree(cfgs);
844 /* Find the requested offscreen format and count the number of offscreen formats */
845 for(i=0; i<nCfgs; i++) {
846 pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
847 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
849 /* We are looking up the GLX index of our main visual and have found it :) */
850 if(visualid == tmp_vis_id) {
851 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, i, tmp_vis_id);
853 *fmt_id = tmp_fmt_id;
859 ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid);
864 static BOOL init_formats(Display *display, int screen, Visual *visual)
866 int fmt_id, fmt_index;
868 /* Locate the fbconfig correspondig to our main visual */
869 if(!get_fbconfig_from_visualid(display, visual, &fmt_id, &fmt_index)) {
870 ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
874 /* Put Wine's internal format at the first index */
875 WineGLPixelFormatList[0].iPixelFormat = 1;
876 WineGLPixelFormatList[0].fbconfig = fmt_id;
877 WineGLPixelFormatList[0].fmt_index = fmt_index;
878 WineGLPixelFormatListSize = 1;
880 /* In the future test for compatible formats here */
885 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
886 * In our WGL implementation we only support a subset of these formats namely the format of
887 * Wine's main visual and offscreen formats (if they are available).
888 * This function converts a WGL format to its corresponding GLX one. It returns the index (zero-based)
889 * into the GLX FB config table and it returns the number of supported WGL formats in fmt_count.
891 static BOOL ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, int *fmt_index, int *fmt_count)
895 /* Init the list of pixel formats when we need it */
896 if(!WineGLPixelFormatListSize)
897 init_formats(display, DefaultScreen(display), visual);
899 if((iPixelFormat <= 0) || (iPixelFormat > WineGLPixelFormatListSize)) {
900 ERR("invalid iPixelFormat %d\n", iPixelFormat);
906 *fmt_index = WineGLPixelFormatList[iPixelFormat-1].fmt_index;
909 *fmt_count = WineGLPixelFormatListSize;
910 TRACE("Returning fmt_index=%d, fmt_count=%d for iPixelFormat=%d\n", *fmt_index, *fmt_count, iPixelFormat);
915 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
916 static int ConvertPixelFormatGLXtoWGL(Display *display, int fbconfig)
920 /* Init the list of pixel formats when we need it */
921 if(!WineGLPixelFormatListSize)
922 init_formats(display, DefaultScreen(display), visual);
924 for(i=0; i<WineGLPixelFormatListSize; i++) {
925 if(WineGLPixelFormatList[i].fbconfig == fbconfig) {
926 TRACE("Returning iPixelFormat %d for fbconfig 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fbconfig);
927 return WineGLPixelFormatList[i].iPixelFormat;
930 TRACE("No compatible format found for FBCONFIG_ID=0x%x\n", fbconfig);
935 * X11DRV_ChoosePixelFormat
937 * Equivalent to glXChooseVisual.
939 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
940 const PIXELFORMATDESCRIPTOR *ppfd) {
941 GLXFBConfig* cfgs = NULL;
948 ERR("No libGL on this box - disabling OpenGL support !\n");
952 if (TRACE_ON(opengl)) {
953 TRACE("(%p,%p)\n", physDev, ppfd);
955 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
960 ERR("Can't get an opengl visual!\n");
964 /* Get a list containing all supported FB configurations */
965 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
966 if (NULL == cfgs || 0 == nCfgs) {
967 ERR("glXGetFBConfigs returns NULL (glError: %d)\n", pglGetError());
971 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
972 if(!ConvertPixelFormatWGLtoGLX(gdi_display, 1 /* main visual */, &fmt_index, &value)) {
973 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual->visualid);
980 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_RENDER_TYPE, &value);
981 if (value & GLX_RGBA_BIT)
982 iPixelType = PFD_TYPE_RGBA;
984 iPixelType = PFD_TYPE_COLORINDEX;
986 if (ppfd->iPixelType != iPixelType) {
987 TRACE("pixel type mismatch\n");
992 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER;
993 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && (ppfd->dwFlags & PFD_DOUBLEBUFFER)) {
994 if (!(dwFlags & PFD_DOUBLEBUFFER)) {
995 TRACE("dbl buffer mismatch\n");
1001 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO;
1002 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO)) {
1003 if (!(dwFlags & PFD_STEREO)) {
1004 TRACE("stereo mismatch\n");
1010 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_ALPHA_SIZE, &value);
1011 if (ppfd->iPixelType==PFD_TYPE_RGBA && ppfd->cAlphaBits && !value) {
1012 TRACE("alpha mismatch\n");
1017 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DEPTH_SIZE, &value);
1018 if (ppfd->cDepthBits && !value) {
1019 TRACE("depth mismatch\n");
1024 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STENCIL_SIZE, &value);
1025 if (ppfd->cStencilBits && !value) {
1026 TRACE("stencil mismatch\n");
1031 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_AUX_BUFFERS, &value);
1032 if (ppfd->cAuxBuffers && !value) {
1033 TRACE("aux mismatch\n");
1037 /* When we pass all the checks we have found a matching format :) */
1039 TRACE("Successfully found a matching mode, returning index: %d\n", ret);
1044 TRACE("No matching mode was found returning 0\n");
1046 if (NULL != cfgs) XFree(cfgs);
1047 wine_tsx11_unlock();
1052 * X11DRV_DescribePixelFormat
1054 * Get the pixel-format descriptor associated to the given id
1056 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1059 PIXELFORMATDESCRIPTOR *ppfd) {
1060 /*XVisualInfo *vis;*/
1064 GLXFBConfig* cfgs = NULL;
1072 if (!has_opengl()) {
1073 ERR("No libGL on this box - disabling OpenGL support !\n");
1077 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1080 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1081 wine_tsx11_unlock();
1083 if (NULL == cfgs || 0 == nCfgs) {
1084 ERR("unexpected iPixelFormat(%d), returns NULL\n", iPixelFormat);
1085 return 0; /* unespected error */
1088 /* 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 */
1089 res = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &fmt_count);
1092 /* The application is only querying the number of visuals */
1094 if (NULL != cfgs) XFree(cfgs);
1095 wine_tsx11_unlock();
1097 } else if(res == FALSE) {
1098 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1100 if (NULL != cfgs) XFree(cfgs);
1101 wine_tsx11_unlock();
1105 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1106 ERR("Wrong structure size !\n");
1107 /* Should set error */
1112 cur = cfgs[fmt_index];
1114 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1115 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1118 /* These flags are always the same... */
1119 ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
1120 /* Now the flags extracted from the Visual */
1124 pglXGetFBConfigAttrib(gdi_display, cur, GLX_CONFIG_CAVEAT, &value);
1125 if(value == GLX_SLOW_CONFIG)
1126 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1128 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1129 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1132 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RENDER_TYPE, &value);
1133 if (value & GLX_RGBA_BIT)
1134 ppfd->iPixelType = PFD_TYPE_RGBA;
1136 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1139 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BUFFER_SIZE, &value);
1140 ppfd->cColorBits = value;
1142 /* Red, green, blue and alpha bits / shifts */
1143 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1144 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RED_SIZE, &rb);
1145 pglXGetFBConfigAttrib(gdi_display, cur, GLX_GREEN_SIZE, &gb);
1146 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BLUE_SIZE, &bb);
1147 pglXGetFBConfigAttrib(gdi_display, cur, GLX_ALPHA_SIZE, &ab);
1149 ppfd->cRedBits = rb;
1150 ppfd->cRedShift = gb + bb + ab;
1151 ppfd->cBlueBits = bb;
1152 ppfd->cBlueShift = ab;
1153 ppfd->cGreenBits = gb;
1154 ppfd->cGreenShift = bb + ab;
1155 ppfd->cAlphaBits = ab;
1156 ppfd->cAlphaShift = 0;
1159 ppfd->cRedShift = 0;
1160 ppfd->cBlueBits = 0;
1161 ppfd->cBlueShift = 0;
1162 ppfd->cGreenBits = 0;
1163 ppfd->cGreenShift = 0;
1164 ppfd->cAlphaBits = 0;
1165 ppfd->cAlphaShift = 0;
1167 /* Accums : to do ... */
1170 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DEPTH_SIZE, &value);
1171 ppfd->cDepthBits = value;
1174 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STENCIL_SIZE, &value);
1175 ppfd->cStencilBits = value;
1177 wine_tsx11_unlock();
1179 /* Aux : to do ... */
1181 ppfd->iLayerType = PFD_MAIN_PLANE;
1183 if (TRACE_ON(opengl)) {
1184 dump_PIXELFORMATDESCRIPTOR(ppfd);
1188 if (NULL != cfgs) XFree(cfgs);
1189 wine_tsx11_unlock();
1195 * X11DRV_GetPixelFormat
1197 * Get the pixel-format id used by this DC
1199 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1200 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1202 return physDev->current_pf;
1206 * X11DRV_SetPixelFormat
1208 * Set the pixel-format id used by this DC
1210 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1212 const PIXELFORMATDESCRIPTOR *ppfd) {
1216 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1218 if (!has_opengl()) {
1219 ERR("No libGL on this box - disabling OpenGL support !\n");
1223 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1224 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
1225 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1229 physDev->current_pf = iPixelFormat;
1231 if (TRACE_ON(opengl)) {
1233 GLXFBConfig* cfgs_fmt = NULL;
1234 GLXFBConfig cur_cfg;
1238 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1240 * in case of root window created HDCs we crash here :(
1242 Drawable drawable = get_drawable( physDev->hdc );
1243 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1244 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1245 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1246 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1247 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1248 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1249 TRACE(" - WIDTH as %d\n", tmp);
1250 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1251 TRACE(" - HEIGHT as %d\n", tmp);
1253 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1254 cur_cfg = cfgs_fmt[fmt_index];
1255 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1257 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1259 TRACE(" FBConfig have :\n");
1260 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1261 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_VISUAL_ID, &value);
1262 TRACE(" - VISUAL_ID 0x%x\n", value);
1263 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_DRAWABLE_TYPE, &value);
1264 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1272 * X11DRV_wglCreateContext
1274 * For OpenGL32 wglCreateContext.
1276 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1278 Wine_GLContext *ret;
1279 GLXFBConfig* cfgs_fmt = NULL;
1280 GLXFBConfig cur_cfg;
1281 int hdcPF = physDev->current_pf;
1287 HDC hdc = physDev->hdc;
1289 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1291 if (!has_opengl()) {
1292 ERR("No libGL on this box - disabling OpenGL support !\n");
1296 /* First, get the visual in use by the X11DRV */
1297 if (!gdi_display) return 0;
1299 /* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the corresponding GLX format.
1300 * If this fails something is very wrong on the system. */
1301 if(!ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, &fmt_index, &fmt_count)) {
1302 ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n");
1303 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1307 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1308 if (NULL == cfgs_fmt || 0 == nCfgs_fmt) {
1309 ERR("Cannot get FB Configs, expect problems.\n");
1310 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1314 if (fmt_count < hdcPF) {
1315 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, hdcPF, fmt_count);
1316 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1320 cur_cfg = cfgs_fmt[fmt_index];
1321 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1323 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1324 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1329 /* The context will be allocated in the wglMakeCurrent call */
1331 ret = alloc_context();
1332 wine_tsx11_unlock();
1334 ret->display = gdi_display;
1335 ret->fb_conf = cur_cfg;
1337 ret->vis = pglXGetVisualFromFBConfig(gdi_display, cur_cfg);
1339 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1344 * X11DRV_wglDeleteContext
1346 * For OpenGL32 wglDeleteContext.
1348 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1350 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1353 TRACE("(%p)\n", hglrc);
1355 if (!has_opengl()) {
1356 ERR("No libGL on this box - disabling OpenGL support !\n");
1361 /* A game (Half Life not to name it) deletes twice the same context,
1362 * so make sure it is valid first */
1363 if (is_valid_context( ctx ))
1365 if (ctx->ctx) pglXDestroyContext(ctx->display, ctx->ctx);
1370 WARN("Error deleting context !\n");
1371 SetLastError(ERROR_INVALID_HANDLE);
1374 wine_tsx11_unlock();
1380 * X11DRV_wglGetCurrentReadDCARB
1382 * For OpenGL32 wglGetCurrentReadDCARB.
1384 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1392 gl_d = pglXGetCurrentReadDrawable();
1393 ret = get_hdc_from_Drawable(gl_d);
1394 wine_tsx11_unlock();
1396 TRACE(" returning %p (GL drawable %lu)\n", ret, gl_d);
1401 * X11DRV_wglGetProcAddress
1403 * For OpenGL32 wglGetProcAddress.
1405 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1408 const WineGLExtension *ext;
1410 int padding = 32 - strlen(lpszProc);
1414 if (!has_opengl()) {
1415 ERR("No libGL on this box - disabling OpenGL support !\n");
1419 /* Check the table of WGL extensions to see if we need to return a WGL extension
1420 * or a function pointer to a native OpenGL function. */
1421 if(strncmp(lpszProc, "wgl", 3) != 0) {
1422 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1424 TRACE("('%s'):%*s", lpszProc, padding, " ");
1425 for (i = 0; i < WineGLExtensionListSize; ++i) {
1426 ext = WineGLExtensionList[i];
1427 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1428 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1429 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1430 return ext->extEntryPoints[j].funcAddress;
1436 ERR("(%s) - not found\n", lpszProc);
1442 * X11DRV_wglMakeCurrent
1444 * For OpenGL32 wglMakeCurrent.
1446 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1448 HDC hdc = physDev->hdc;
1449 DWORD type = GetObjectType(hdc);
1451 TRACE("(%p,%p)\n", hdc, hglrc);
1453 if (!has_opengl()) {
1454 ERR("No libGL on this box - disabling OpenGL support !\n");
1459 if (hglrc == NULL) {
1460 ret = pglXMakeCurrent(gdi_display, None, NULL);
1461 NtCurrentTeb()->glContext = NULL;
1463 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1464 Drawable drawable = physDev->drawable;
1465 if (ctx->ctx == NULL) {
1466 /* The describe lines below are for debugging purposes only */
1467 if (TRACE_ON(wgl)) {
1468 describeDrawable(ctx, drawable);
1469 describeContext(ctx);
1472 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1473 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1475 TRACE(" Creating GLX Context\n");
1476 ctx->ctx = pglXCreateContext(ctx->display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1477 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1479 TRACE(" make current for dis %p, drawable %p, ctx %p\n", ctx->display, (void*) drawable, ctx->ctx);
1480 ret = pglXMakeCurrent(ctx->display, drawable, ctx->ctx);
1481 NtCurrentTeb()->glContext = ctx;
1482 if(ret && type == OBJ_MEMDC)
1484 ctx->do_escape = TRUE;
1485 pglDrawBuffer(GL_FRONT_LEFT);
1488 wine_tsx11_unlock();
1489 TRACE(" returning %s\n", (ret ? "True" : "False"));
1494 * X11DRV_wglMakeContextCurrentARB
1496 * For OpenGL32 wglMakeContextCurrentARB
1498 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc)
1501 TRACE("(%p,%p,%p)\n", hDrawDev, hReadDev, hglrc);
1503 if (!has_opengl()) {
1504 ERR("No libGL on this box - disabling OpenGL support !\n");
1509 if (hglrc == NULL) {
1510 ret = pglXMakeCurrent(gdi_display, None, NULL);
1511 NtCurrentTeb()->glContext = NULL;
1513 if (NULL == pglXMakeContextCurrent) {
1516 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1517 Drawable d_draw = get_glxdrawable(hDrawDev);
1518 Drawable d_read = get_glxdrawable(hReadDev);
1520 if (ctx->ctx == NULL) {
1521 ctx->ctx = pglXCreateContext(ctx->display, ctx->vis, NULL, GetObjectType(hDrawDev->hdc) == OBJ_MEMDC ? False : True);
1522 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1524 ret = pglXMakeContextCurrent(ctx->display, d_draw, d_read, ctx->ctx);
1525 NtCurrentTeb()->glContext = ctx;
1528 wine_tsx11_unlock();
1530 TRACE(" returning %s\n", (ret ? "True" : "False"));
1535 * X11DRV_wglShareLists
1537 * For OpenGL32 wglShaderLists.
1539 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1540 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1541 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1543 TRACE("(%p, %p)\n", org, dest);
1545 if (!has_opengl()) {
1546 ERR("No libGL on this box - disabling OpenGL support !\n");
1550 if (NULL != dest && dest->ctx != NULL) {
1551 ERR("Could not share display lists, context already created !\n");
1554 if (org->ctx == NULL) {
1556 describeContext(org);
1557 org->ctx = pglXCreateContext(org->display, org->vis, NULL, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True);
1558 wine_tsx11_unlock();
1559 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1563 describeContext(dest);
1564 /* Create the destination context with display lists shared */
1565 dest->ctx = pglXCreateContext(org->display, dest->vis, org->ctx, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True);
1566 wine_tsx11_unlock();
1567 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1574 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1576 /* We are running using client-side rendering fonts... */
1580 void *bitmap = NULL, *gl_bitmap = NULL;
1584 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1585 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1586 wine_tsx11_unlock();
1588 for (glyph = first; glyph < first + count; glyph++) {
1589 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1590 int height, width_int;
1592 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1593 if (needed_size == GDI_ERROR) {
1594 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1597 TRACE(" - needed size : %d\n", needed_size);
1600 if (needed_size > size) {
1602 HeapFree(GetProcessHeap(), 0, bitmap);
1603 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1604 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1605 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1607 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1608 if (TRACE_ON(opengl)) {
1609 unsigned int height, width, bitmask;
1610 unsigned char *bitmap_ = (unsigned char *) bitmap;
1612 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1613 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1614 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1615 if (needed_size != 0) {
1616 TRACE(" - bitmap :\n");
1617 for (height = 0; height < gm.gmBlackBoxY; height++) {
1619 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1624 if (*bitmap_ & bitmask)
1629 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1635 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1636 * glyph for it to be drawn properly.
1638 if (needed_size != 0) {
1639 width_int = (gm.gmBlackBoxX + 31) / 32;
1640 for (height = 0; height < gm.gmBlackBoxY; height++) {
1642 for (width = 0; width < width_int; width++) {
1643 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1644 ((int *) bitmap)[height * width_int + width];
1650 pglNewList(listBase++, GL_COMPILE);
1651 if (needed_size != 0) {
1652 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1653 0 - (int) gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - (int) gm.gmptGlyphOrigin.y,
1654 gm.gmCellIncX, gm.gmCellIncY,
1657 /* This is the case of 'empty' glyphs like the space character */
1658 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1661 wine_tsx11_unlock();
1665 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1666 wine_tsx11_unlock();
1668 HeapFree(GetProcessHeap(), 0, bitmap);
1669 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1674 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1675 wine_tsx11_unlock();
1677 HeapFree(GetProcessHeap(), 0, bitmap);
1678 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1683 * X11DRV_wglUseFontBitmapsA
1685 * For OpenGL32 wglUseFontBitmapsA.
1687 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1689 Font fid = physDev->font;
1691 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1693 if (!has_opengl()) {
1694 ERR("No libGL on this box - disabling OpenGL support !\n");
1699 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1703 /* I assume that the glyphs are at the same position for X and for Windows */
1704 pglXUseXFont(fid, first, count, listBase);
1705 wine_tsx11_unlock();
1710 * X11DRV_wglUseFontBitmapsW
1712 * For OpenGL32 wglUseFontBitmapsW.
1714 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1716 Font fid = physDev->font;
1718 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1720 if (!has_opengl()) {
1721 ERR("No libGL on this box - disabling OpenGL support !\n");
1726 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
1729 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1732 /* I assume that the glyphs are at the same position for X and for Windows */
1733 pglXUseXFont(fid, first, count, listBase);
1734 wine_tsx11_unlock();
1738 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1739 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params) {
1740 TRACE("pname: 0x%x, params: %p\n", pname, params);
1741 if (pname == GL_DEPTH_BITS) {
1742 GLXContext gl_ctx = pglXGetCurrentContext();
1743 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1744 /*TRACE("returns Wine Ctx as %p\n", ret);*/
1746 * if we cannot find a Wine Context
1747 * we only have the default wine desktop context,
1748 * so if we have only a 24 depth say we have 32
1750 if (NULL == ret && 24 == *params) {
1753 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1755 if (pname == GL_ALPHA_BITS) {
1757 GLXContext gl_ctx = pglXGetCurrentContext();
1758 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1759 pglXGetFBConfigAttrib(ret->display, ret->fb_conf, GLX_ALPHA_SIZE, &tmp);
1760 TRACE("returns GL_ALPHA_BITS as '%d'\n", tmp);
1766 * X11DRV_wglGetExtensionsStringARB
1768 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1770 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
1771 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1772 return WineGLInfo.wglExtensions;
1776 * X11DRV_wglCreatePbufferARB
1778 * WGL_ARB_pbuffer: wglCreatePbufferARB
1780 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
1782 Wine_GLPBuffer* object = NULL;
1783 GLXFBConfig* cfgs = NULL;
1786 unsigned nAttribs = 0;
1789 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1791 if (0 >= iPixelFormat) {
1792 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
1793 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1794 return NULL; /* unexpected error */
1797 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1799 if (NULL == cfgs || 0 == nCfgs) {
1800 ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
1801 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1802 return NULL; /* unexpected error */
1805 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1806 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nCfgs)) {
1807 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
1808 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1809 goto create_failed; /* unexpected error */
1812 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
1813 if (NULL == object) {
1814 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1815 goto create_failed; /* unexpected error */
1818 object->display = gdi_display;
1819 object->width = iWidth;
1820 object->height = iHeight;
1821 object->pixelFormat = iPixelFormat;
1823 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
1824 if (-1 == nAttribs) {
1825 WARN("Cannot convert WGL to GLX attributes\n");
1828 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1829 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1830 while (0 != *piAttribList) {
1832 switch (*piAttribList) {
1833 case WGL_TEXTURE_FORMAT_ARB: {
1835 attr_v = *piAttribList;
1836 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
1837 if (use_render_texture_ati) {
1840 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
1841 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
1842 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
1844 SetLastError(ERROR_INVALID_DATA);
1847 object->use_render_texture = 1;
1848 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
1850 if (WGL_NO_TEXTURE_ARB == attr_v) {
1851 object->use_render_texture = 0;
1853 if (!use_render_texture_emulation) {
1854 SetLastError(ERROR_INVALID_DATA);
1858 case WGL_TEXTURE_RGB_ARB:
1859 object->use_render_texture = GL_RGB;
1861 case WGL_TEXTURE_RGBA_ARB:
1862 object->use_render_texture = GL_RGBA;
1865 SetLastError(ERROR_INVALID_DATA);
1873 case WGL_TEXTURE_TARGET_ARB: {
1875 attr_v = *piAttribList;
1876 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
1877 if (use_render_texture_ati) {
1880 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
1881 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
1882 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
1883 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
1885 SetLastError(ERROR_INVALID_DATA);
1888 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
1890 if (WGL_NO_TEXTURE_ARB == attr_v) {
1891 object->texture_target = 0;
1893 if (!use_render_texture_emulation) {
1894 SetLastError(ERROR_INVALID_DATA);
1898 case WGL_TEXTURE_CUBE_MAP_ARB: {
1899 if (iWidth != iHeight) {
1900 SetLastError(ERROR_INVALID_DATA);
1903 object->texture_target = GL_TEXTURE_CUBE_MAP;
1904 object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
1907 case WGL_TEXTURE_1D_ARB: {
1909 SetLastError(ERROR_INVALID_DATA);
1912 object->texture_target = GL_TEXTURE_1D;
1913 object->texture_bind_target = GL_TEXTURE_1D;
1916 case WGL_TEXTURE_2D_ARB: {
1917 object->texture_target = GL_TEXTURE_2D;
1918 object->texture_bind_target = GL_TEXTURE_2D;
1922 SetLastError(ERROR_INVALID_DATA);
1930 case WGL_MIPMAP_TEXTURE_ARB: {
1932 attr_v = *piAttribList;
1933 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
1934 if (use_render_texture_ati) {
1935 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
1937 if (!use_render_texture_emulation) {
1938 SetLastError(ERROR_INVALID_DATA);
1948 PUSH1(attribs, None);
1949 object->drawable = pglXCreatePbuffer(gdi_display, cfgs[fmt_index], attribs);
1950 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
1951 if (!object->drawable) {
1952 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1953 goto create_failed; /* unexpected error */
1955 TRACE("->(%p)\n", object);
1959 return (HPBUFFERARB) object;
1962 if (NULL != cfgs) XFree(cfgs);
1963 HeapFree(GetProcessHeap(), 0, object);
1964 TRACE("->(FAILED)\n");
1965 return (HPBUFFERARB) NULL;
1969 * X11DRV_wglDestroyPbufferARB
1971 * WGL_ARB_pbuffer: wglDestroyPbufferARB
1973 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
1975 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1976 TRACE("(%p)\n", hPbuffer);
1977 if (NULL == object) {
1978 SetLastError(ERROR_INVALID_HANDLE);
1981 pglXDestroyPbuffer(object->display, object->drawable);
1982 HeapFree(GetProcessHeap(), 0, object);
1987 * X11DRV_wglGetPbufferDCARB
1989 * WGL_ARB_pbuffer: wglGetPbufferDCARB
1990 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
1991 * Gdi32 implements the part of this function which creates a device context.
1992 * This part associates the physDev with the X drawable of the pbuffer.
1994 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
1996 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1997 if (NULL == object) {
1998 SetLastError(ERROR_INVALID_HANDLE);
2002 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2003 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2004 physDev->current_pf = object->pixelFormat;
2005 physDev->drawable = object->drawable;
2007 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2008 return physDev->hdc;
2012 * X11DRV_wglQueryPbufferARB
2014 * WGL_ARB_pbuffer: wglQueryPbufferARB
2016 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2018 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2019 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2020 if (NULL == object) {
2021 SetLastError(ERROR_INVALID_HANDLE);
2024 switch (iAttribute) {
2025 case WGL_PBUFFER_WIDTH_ARB:
2026 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2028 case WGL_PBUFFER_HEIGHT_ARB:
2029 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2032 case WGL_PBUFFER_LOST_ARB:
2033 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
2036 case WGL_TEXTURE_FORMAT_ARB:
2037 if (use_render_texture_ati) {
2039 int type = WGL_NO_TEXTURE_ARB;
2040 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2042 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2043 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2044 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2048 if (!object->use_render_texture) {
2049 *piValue = WGL_NO_TEXTURE_ARB;
2051 if (!use_render_texture_emulation) {
2052 SetLastError(ERROR_INVALID_HANDLE);
2055 if (GL_RGBA == object->use_render_texture) {
2056 *piValue = WGL_TEXTURE_RGBA_ARB;
2058 *piValue = WGL_TEXTURE_RGB_ARB;
2064 case WGL_TEXTURE_TARGET_ARB:
2065 if (use_render_texture_ati) {
2067 int type = WGL_NO_TEXTURE_ARB;
2068 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2070 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2071 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2072 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2073 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2077 if (!object->texture_target) {
2078 *piValue = WGL_NO_TEXTURE_ARB;
2080 if (!use_render_texture_emulation) {
2081 SetLastError(ERROR_INVALID_DATA);
2084 switch (object->texture_target) {
2085 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2086 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_1D_ARB; break;
2087 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_2D_ARB; break;
2093 case WGL_MIPMAP_TEXTURE_ARB:
2094 if (use_render_texture_ati) {
2095 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2097 *piValue = GL_FALSE; /** don't support that */
2098 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2103 FIXME("unexpected attribute %x\n", iAttribute);
2111 * X11DRV_wglReleasePbufferDCARB
2113 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2115 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2117 TRACE("(%p, %p)\n", hPbuffer, hdc);
2123 * X11DRV_wglSetPbufferAttribARB
2125 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2127 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2129 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2130 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2131 if (NULL == object) {
2132 SetLastError(ERROR_INVALID_HANDLE);
2135 if (!object->use_render_texture) {
2136 SetLastError(ERROR_INVALID_HANDLE);
2139 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2142 if (NULL != pglXDrawableAttribARB) {
2143 if (use_render_texture_ati) {
2144 FIXME("Need conversion for GLX_ATI_render_texture\n");
2146 return pglXDrawableAttribARB(object->display, object->drawable, piAttribList);
2152 * X11DRV_wglChoosePixelFormatARB
2154 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2156 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2161 GLXFBConfig* cfgs = NULL;
2166 GLXFBConfig* cfgs_fmt = NULL;
2172 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2173 if (NULL != pfAttribFList) {
2174 FIXME("unused pfAttribFList\n");
2177 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2178 if (-1 == nAttribs) {
2179 WARN("Cannot convert WGL to GLX attributes\n");
2182 PUSH1(attribs, None);
2184 /* Search for FB configurations matching the requirements in attribs */
2185 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2187 WARN("Compatible Pixel Format not found\n");
2191 /* Get a list of all FB configurations */
2192 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
2193 if (NULL == cfgs_fmt) {
2194 ERR("Failed to get All FB Configs\n");
2199 /* Loop through all matching formats and check if they are suitable.
2200 * Note that this function should at max return nMaxFormats different formats */
2201 for (it = 0; pfmt_it < nMaxFormats && it < nCfgs; ++it) {
2202 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2204 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2208 /* Search for the format in our list of compatible formats */
2209 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2213 piFormats[pfmt_it] = fmt;
2214 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d/%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it], nCfgs_fmt);
2218 *nNumFormats = pfmt_it;
2226 * X11DRV_wglGetPixelFormatAttribivARB
2228 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2230 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2233 GLXFBConfig* cfgs = NULL;
2234 GLXFBConfig curCfg = NULL;
2239 int nWGLFormats = 0;
2242 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2244 if (0 < iLayerPlane) {
2245 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2249 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
2251 ERR("no FB Configs found for display(%p)\n", gdi_display);
2255 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2256 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2257 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2258 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nWGLFormats)) {
2259 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2262 for (i = 0; i < nAttributes; ++i) {
2263 const int curWGLAttr = piAttributes[i];
2264 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2266 switch (curWGLAttr) {
2267 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2268 piValues[i] = nWGLFormats;
2271 case WGL_SUPPORT_OPENGL_ARB:
2272 piValues[i] = GL_TRUE;
2275 case WGL_ACCELERATION_ARB:
2276 curGLXAttr = GLX_CONFIG_CAVEAT;
2278 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
2279 curCfg = cfgs[iPixelFormat - 1];
2281 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2282 if (hTest) goto get_error;
2284 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2285 case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
2286 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2288 ERR("unexpected Config Caveat(%x)\n", tmp);
2289 piValues[i] = WGL_NO_ACCELERATION_ARB;
2293 case WGL_TRANSPARENT_ARB:
2294 curGLXAttr = GLX_TRANSPARENT_TYPE;
2295 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2296 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2297 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2298 curCfg = cfgs[fmt_index];
2299 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2300 if (hTest) goto get_error;
2301 piValues[i] = GL_FALSE;
2302 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2305 case WGL_PIXEL_TYPE_ARB:
2306 curGLXAttr = GLX_RENDER_TYPE;
2307 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2308 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2309 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2310 curCfg = cfgs[fmt_index];
2311 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2312 if (hTest) goto get_error;
2313 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2314 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2315 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2316 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2317 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2319 ERR("unexpected RenderType(%x)\n", tmp);
2320 piValues[i] = WGL_TYPE_RGBA_ARB;
2324 case WGL_COLOR_BITS_ARB:
2325 /** see ConvertAttribWGLtoGLX for explain */
2326 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2327 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2328 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2329 curCfg = cfgs[fmt_index];
2330 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_BUFFER_SIZE, piValues + i);
2331 if (hTest) goto get_error;
2332 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues[i]);
2333 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_ALPHA_SIZE, &tmp);
2334 if (hTest) goto get_error;
2335 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp);
2336 piValues[i] = piValues[i] - tmp;
2339 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2340 if (use_render_texture_ati) {
2341 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2344 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2345 if (use_render_texture_ati) {
2346 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2349 if (!use_render_texture_emulation) {
2350 piValues[i] = GL_FALSE;
2353 curGLXAttr = GLX_RENDER_TYPE;
2354 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2355 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2356 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2357 curCfg = cfgs[fmt_index];
2358 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2359 if (hTest) goto get_error;
2360 if (GLX_COLOR_INDEX_BIT == tmp) {
2361 piValues[i] = GL_FALSE;
2364 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp);
2365 if (hTest) goto get_error;
2366 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2369 case WGL_BLUE_BITS_ARB:
2370 curGLXAttr = GLX_BLUE_SIZE;
2372 case WGL_RED_BITS_ARB:
2373 curGLXAttr = GLX_RED_SIZE;
2375 case WGL_GREEN_BITS_ARB:
2376 curGLXAttr = GLX_GREEN_SIZE;
2378 case WGL_ALPHA_BITS_ARB:
2379 curGLXAttr = GLX_ALPHA_SIZE;
2381 case WGL_DEPTH_BITS_ARB:
2382 curGLXAttr = GLX_DEPTH_SIZE;
2384 case WGL_STENCIL_BITS_ARB:
2385 curGLXAttr = GLX_STENCIL_SIZE;
2387 case WGL_DOUBLE_BUFFER_ARB:
2388 curGLXAttr = GLX_DOUBLEBUFFER;
2390 case WGL_STEREO_ARB:
2391 curGLXAttr = GLX_STEREO;
2393 case WGL_AUX_BUFFERS_ARB:
2394 curGLXAttr = GLX_AUX_BUFFERS;
2396 case WGL_SUPPORT_GDI_ARB:
2397 case WGL_DRAW_TO_WINDOW_ARB:
2398 case WGL_DRAW_TO_BITMAP_ARB:
2399 /* We only supported a limited number of formats right now which are all renderable by X 'GLX_X_RENDERABLE' */
2400 piValues[i] = GL_TRUE;
2402 case WGL_DRAW_TO_PBUFFER_ARB:
2403 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp);
2404 if (hTest) goto get_error;
2405 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2408 case WGL_PBUFFER_LARGEST_ARB:
2409 curGLXAttr = GLX_LARGEST_PBUFFER;
2412 case WGL_SAMPLE_BUFFERS_ARB:
2413 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2416 case WGL_SAMPLES_ARB:
2417 curGLXAttr = GLX_SAMPLES_ARB;
2421 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2424 if (0 != curGLXAttr) {
2425 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2426 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2427 if((iPixelFormat > 0) && ((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs))) goto pix_error;
2428 curCfg = cfgs[fmt_index];
2429 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, piValues + i);
2430 if (hTest) goto get_error;
2433 piValues[i] = GL_FALSE;
2439 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2444 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
2450 * X11DRV_wglGetPixelFormatAttribfvARB
2452 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2454 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2460 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2462 /* Allocate a temporary array to store integer values */
2463 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2465 ERR("couldn't allocate %d array\n", nAttributes);
2469 /* Piggy-back on wglGetPixelFormatAttribivARB */
2470 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2472 /* Convert integer values to float. Should also check for attributes
2473 that can give decimal values here */
2474 for (i=0; i<nAttributes;i++) {
2475 pfValues[i] = attr[i];
2479 HeapFree(GetProcessHeap(), 0, attr);
2484 * X11DRV_wglBindTexImageARB
2486 * WGL_ARB_render_texture: wglBindTexImageARB
2488 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2490 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2491 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2492 if (NULL == object) {
2493 SetLastError(ERROR_INVALID_HANDLE);
2496 if (!object->use_render_texture) {
2497 SetLastError(ERROR_INVALID_HANDLE);
2500 /* Disable WGL_ARB_render_texture support until it is implemented properly
2501 * using pbuffers or FBOs */
2503 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2505 GLint prev_binded_tex;
2506 pglGetIntegerv(object->texture_target, &prev_binded_tex);
2507 if (NULL == object->render_ctx) {
2508 object->render_hdc = X11DRV_wglGetPbufferDCARB(hPbuffer);
2509 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2510 object->render_ctx = wglCreateContext(object->render_hdc);
2513 object->prev_hdc = wglGetCurrentDC();
2514 object->prev_ctx = wglGetCurrentContext();
2515 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2516 wglMakeCurrent(object->render_hdc, object->render_ctx);
2519 glBindTexture(object->texture_target, object->texture);
2520 if (GL_RGBA == object->use_render_texture) {
2521 glTexImage2D(object->texture_target, 0, GL_RGBA8, object->width, object->height, 0, GL_RGBA, GL_FLOAT, NULL);
2523 glTexImage2D(object->texture_target, 0, GL_RGB8, object->width, object->height, 0, GL_RGB, GL_FLOAT, NULL);
2527 object->texture = prev_binded_tex;
2531 if (NULL != pglXBindTexImageARB) {
2532 return pglXBindTexImageARB(object->display, object->drawable, iBuffer);
2538 * X11DRV_wglReleaseTexImageARB
2540 * WGL_ARB_render_texture: wglReleaseTexImageARB
2542 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2544 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2545 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2546 if (NULL == object) {
2547 SetLastError(ERROR_INVALID_HANDLE);
2550 if (!object->use_render_texture) {
2551 SetLastError(ERROR_INVALID_HANDLE);
2554 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2556 GLint prev_binded_tex;
2557 glGetIntegerv(object->texture_target, &prev_binded_tex);
2558 if (GL_TEXTURE_1D == object->texture_target) {
2559 glCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2561 glCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2563 glBindTexture(object->texture_target, prev_binded_tex);
2564 SwapBuffers(object->render_hdc);
2566 pglBindTexture(object->texture_target, object->texture);
2567 if (GL_TEXTURE_1D == object->texture_target) {
2568 pglCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2570 pglCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2573 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2574 wglMakeCurrent(object->prev_hdc, object->prev_ctx);
2577 if (NULL != pglXReleaseTexImageARB) {
2578 return pglXReleaseTexImageARB(object->display, object->drawable, iBuffer);
2584 * X11DRV_wglGetExtensionsStringEXT
2586 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2588 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2589 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2590 return WineGLInfo.wglExtensions;
2594 * X11DRV_wglGetSwapIntervalEXT
2596 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2598 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2599 FIXME("(),stub!\n");
2600 return swap_interval;
2604 * X11DRV_wglSwapIntervalEXT
2606 * WGL_EXT_swap_control: wglSwapIntervalEXT
2608 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2609 TRACE("(%d)\n", interval);
2610 swap_interval = interval;
2611 if (NULL != pglXSwapIntervalSGI) {
2612 return 0 == pglXSwapIntervalSGI(interval);
2614 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2619 * X11DRV_wglAllocateMemoryNV
2621 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2623 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2624 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2625 if (pglXAllocateMemoryNV == NULL)
2628 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2632 * X11DRV_wglFreeMemoryNV
2634 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2636 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2637 TRACE("(%p)\n", pointer);
2638 if (pglXFreeMemoryNV == NULL)
2641 pglXFreeMemoryNV(pointer);
2645 * glxRequireVersion (internal)
2647 * Check if the supported GLX version matches requiredVersion.
2649 static BOOL glxRequireVersion(int requiredVersion)
2651 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2652 if(requiredVersion <= WineGLInfo.glxVersion[1])
2658 static BOOL glxRequireExtension(const char *requiredExtension)
2660 if (strstr(WineGLInfo.glxClientExtensions, requiredExtension) == NULL) {
2667 static BOOL register_extension(const WineGLExtension * ext)
2671 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
2672 WineGLExtensionList[WineGLExtensionListSize++] = ext;
2674 strcat(WineGLInfo.wglExtensions, " ");
2675 strcat(WineGLInfo.wglExtensions, ext->extName);
2677 TRACE("'%s'\n", ext->extName);
2679 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
2680 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
2685 static const WineGLExtension WGL_internal_functions =
2689 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
2694 static const WineGLExtension WGL_ARB_extensions_string =
2696 "WGL_ARB_extensions_string",
2698 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
2702 static const WineGLExtension WGL_ARB_make_current_read =
2704 "WGL_ARB_make_current_read",
2706 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
2707 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
2711 static const WineGLExtension WGL_ARB_multisample =
2713 "WGL_ARB_multisample",
2716 static const WineGLExtension WGL_ARB_pbuffer =
2720 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
2721 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
2722 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
2723 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
2724 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
2725 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
2729 static const WineGLExtension WGL_ARB_pixel_format =
2731 "WGL_ARB_pixel_format",
2733 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
2734 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
2735 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
2739 static const WineGLExtension WGL_ARB_render_texture =
2741 "WGL_ARB_render_texture",
2743 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
2744 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
2748 static const WineGLExtension WGL_EXT_extensions_string =
2750 "WGL_EXT_extensions_string",
2752 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
2756 static const WineGLExtension WGL_EXT_swap_control =
2758 "WGL_EXT_swap_control",
2760 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
2761 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
2765 static const WineGLExtension WGL_NV_vertex_array_range =
2767 "WGL_NV_vertex_array_range",
2769 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
2770 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
2775 * X11DRV_WineGL_LoadExtensions
2777 static void X11DRV_WineGL_LoadExtensions(void)
2779 WineGLInfo.wglExtensions[0] = 0;
2781 /* Load Wine internal functions */
2782 register_extension(&WGL_internal_functions);
2784 /* ARB Extensions */
2786 register_extension(&WGL_ARB_extensions_string);
2788 if (glxRequireVersion(3))
2789 register_extension(&WGL_ARB_make_current_read);
2791 if (glxRequireExtension("GLX_ARB_multisample"))
2792 register_extension(&WGL_ARB_multisample);
2794 if (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer"))
2795 register_extension(&WGL_ARB_pbuffer);
2797 register_extension(&WGL_ARB_pixel_format);
2799 if (glxRequireExtension("GLX_ATI_render_texture") ||
2800 glxRequireExtension("GLX_ARB_render_texture"))
2801 register_extension(&WGL_ARB_render_texture);
2803 /* EXT Extensions */
2805 register_extension(&WGL_EXT_extensions_string);
2807 if (glxRequireExtension("GLX_SGI_swap_control"))
2808 register_extension(&WGL_EXT_swap_control);
2810 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2811 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
2812 register_extension(&WGL_NV_vertex_array_range);
2816 static XID create_glxpixmap(X11DRV_PDEVICE *physDev)
2820 XVisualInfo template;
2825 /* Retrieve the visualid from our main visual which is the only visual we can use */
2826 template.visualid = XVisualIDFromVisual(visual);
2827 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
2829 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
2831 wine_tsx11_unlock();
2832 TRACE("return %lx\n", ret);
2836 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
2842 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
2843 ret = physDev->drawable; /* PBuffer */
2846 if(!physDev->bitmap->glxpixmap)
2847 physDev->bitmap->glxpixmap = create_glxpixmap(physDev);
2848 ret = physDev->bitmap->glxpixmap;
2852 ret = physDev->drawable;
2856 BOOL destroy_glxpixmap(XID glxpixmap)
2859 pglXDestroyGLXPixmap(gdi_display, glxpixmap);
2860 wine_tsx11_unlock();
2865 * X11DRV_SwapBuffers
2867 * Swap the buffers of this DC
2869 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
2871 GLXDrawable drawable;
2872 if (!has_opengl()) {
2873 ERR("No libGL on this box - disabling OpenGL support !\n");
2877 TRACE_(opengl)("(%p)\n", physDev);
2879 drawable = get_glxdrawable(physDev);
2881 pglXSwapBuffers(gdi_display, drawable);
2882 wine_tsx11_unlock();
2887 static long prev_time, frames;
2889 DWORD time = GetTickCount();
2891 /* every 1.5 seconds */
2892 if (time - prev_time > 1500) {
2893 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
2902 /***********************************************************************
2903 * X11DRV_setup_opengl_visual
2905 * Setup the default visual used for OpenGL and Direct3D, and the desktop
2906 * window (if it exists). If OpenGL isn't available, the visual is simply
2907 * set to the default visual for the display
2909 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
2911 XVisualInfo *visual = NULL;
2912 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support, */
2913 int dblBuf[] = {GLX_RGBA,GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DOUBLEBUFFER, None};
2914 if (!has_opengl()) return NULL;
2917 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf);
2918 wine_tsx11_unlock();
2919 if (visual == NULL) {
2920 /* fallback to 16 bits depth, no alpha */
2921 int dblBuf2[] = {GLX_RGBA,GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, None};
2922 WARN("Failed to get a visual with at least 24 bits depth\n");
2925 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf2);
2926 wine_tsx11_unlock();
2927 if (visual == NULL) {
2928 /* fallback to no stencil */
2929 int dblBuf2[] = {GLX_RGBA,GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
2930 WARN("Failed to get a visual with at least 8 bits of stencil\n");
2933 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf2);
2934 wine_tsx11_unlock();
2935 if (visual == NULL) {
2936 /* This should only happen if we cannot find a match with a depth size 16 */
2937 FIXME("Failed to find a suitable visual\n");
2942 TRACE("Visual ID %lx Chosen\n",visual->visualid);
2946 #else /* no OpenGL includes */
2948 /***********************************************************************
2949 * ChoosePixelFormat (X11DRV.@)
2951 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
2952 const PIXELFORMATDESCRIPTOR *ppfd) {
2953 ERR("No OpenGL support compiled in.\n");
2958 /***********************************************************************
2959 * DescribePixelFormat (X11DRV.@)
2961 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
2964 PIXELFORMATDESCRIPTOR *ppfd) {
2965 ERR("No OpenGL support compiled in.\n");
2970 /***********************************************************************
2971 * GetPixelFormat (X11DRV.@)
2973 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
2974 ERR("No OpenGL support compiled in.\n");
2979 /***********************************************************************
2980 * SetPixelFormat (X11DRV.@)
2982 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
2984 const PIXELFORMATDESCRIPTOR *ppfd) {
2985 ERR("No OpenGL support compiled in.\n");
2990 /***********************************************************************
2991 * SwapBuffers (X11DRV.@)
2993 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
2994 ERR_(opengl)("No OpenGL support compiled in.\n");
3000 * X11DRV_wglCreateContext
3002 * For OpenGL32 wglCreateContext.
3004 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3005 ERR_(opengl)("No OpenGL support compiled in.\n");
3010 * X11DRV_wglDeleteContext
3012 * For OpenGL32 wglDeleteContext.
3014 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3015 ERR_(opengl)("No OpenGL support compiled in.\n");
3020 * X11DRV_wglGetProcAddress
3022 * For OpenGL32 wglGetProcAddress.
3024 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3025 ERR_(opengl)("No OpenGL support compiled in.\n");
3029 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3031 ERR_(opengl)("No OpenGL support compiled in.\n");
3035 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3036 ERR_(opengl)("No OpenGL support compiled in.\n");
3041 * X11DRV_wglMakeCurrent
3043 * For OpenGL32 wglMakeCurrent.
3045 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3046 ERR_(opengl)("No OpenGL support compiled in.\n");
3051 * X11DRV_wglShareLists
3053 * For OpenGL32 wglShaderLists.
3055 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3056 ERR_(opengl)("No OpenGL support compiled in.\n");
3061 * X11DRV_wglUseFontBitmapsA
3063 * For OpenGL32 wglUseFontBitmapsA.
3065 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3067 ERR_(opengl)("No OpenGL support compiled in.\n");
3072 * X11DRV_wglUseFontBitmapsW
3074 * For OpenGL32 wglUseFontBitmapsW.
3076 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3078 ERR_(opengl)("No OpenGL support compiled in.\n");
3082 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3087 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3092 BOOL destroy_glxpixmap(XID glxpixmap)
3097 #endif /* defined(HAVE_OPENGL) */