1 /* Support for window-specific OpenGL extensions.
3 * Copyright (c) 2004 Lionel Ulmer
4 * Copyright (c) 2005 Alex Woods
5 * Copyright (c) 2005 Raphael Junqueira
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
36 #include "opengl_ext.h"
37 #include "wine/library.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
43 /* x11drv GDI escapes */
44 #define X11DRV_ESCAPE 6789
45 enum x11drv_escape_codes
47 X11DRV_GET_DISPLAY, /* get X11 display for a DC */
48 X11DRV_GET_DRAWABLE, /* get current drawable for a DC */
49 X11DRV_GET_FONT, /* get current X font for a DC */
50 X11DRV_SET_DRAWABLE, /* set current drawable for a DC */
52 struct x11drv_escape_set_drawable
54 enum x11drv_escape_codes code; /* escape code (X11DRV_SET_DRAWABLE) */
55 Drawable drawable; /* X drawable */
56 int mode; /* ClipByChildren or IncludeInferiors */
57 POINT org; /* origin of DC relative to drawable */
58 POINT drawable_org; /* origin of drawable relative to screen */
61 /* retrieve the X display to use on a given DC */
62 inline static Display *get_display( HDC hdc )
65 enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
67 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
68 sizeof(display), (LPSTR)&display )) display = NULL;
71 inline static void set_drawable( HDC hdc, Drawable drawable )
73 struct x11drv_escape_set_drawable escape;
75 escape.code = X11DRV_SET_DRAWABLE;
76 escape.drawable = drawable;
77 escape.mode = IncludeInferiors;
78 escape.org.x = escape.org.y = 0;
79 escape.drawable_org.x = escape.drawable_org.y = 0;
81 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL );
84 /* Some WGL extensions... */
85 static const char *WGL_extensions_base = "WGL_ARB_extensions_string WGL_EXT_extensions_string";
86 static char *WGL_extensions = NULL;
89 * Extensions-query functions
91 * @TODO: use a struct to handle parameters
93 BOOL query_function_multisample(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
94 const char* glx_version, const char *glx_extensions,
95 const char *server_glx_extensions, const char *client_glx_extensions)
97 return NULL != strstr("GLX_ARB_multisample", glx_extensions);
100 BOOL query_function_pbuffer(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
101 const char* glx_version, const char *glx_extensions,
102 const char *server_glx_extensions, const char *client_glx_extensions)
104 FIXME("gl_version is: \"%s\"\n", gl_version);
105 FIXME("glx_exts is: \"%s\"\n", glx_extensions);
107 return 0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGIX_pbuffer");
110 BOOL query_function_pixel_format(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
111 const char* glx_version, const char *glx_extensions,
112 const char *server_glx_extensions, const char *client_glx_extensions)
117 /** GLX_ARB_render_texture */
118 Bool (*p_glXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
119 Bool (*p_glXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
120 Bool (*p_glXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
122 BOOL query_function_render_texture(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
123 const char* glx_version, const char *glx_extensions,
124 const char *server_glx_extensions, const char *client_glx_extensions)
126 BOOL bTest = (0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGIX_pbuffer") || NULL != strstr(glx_extensions, "GLX_ARB_render_texture"));
128 p_glXBindTexImageARB = proc("glXBindTexImageARB");
129 p_glXReleaseTexImageARB = proc("glXReleaseTexImageARB");
130 p_glXDrawableAttribARB = proc("glXDrawableAttribARB");
131 bTest = (NULL != p_glXBindTexImageARB && NULL != p_glXReleaseTexImageARB && NULL != p_glXDrawableAttribARB);
136 /***********************************************************************
137 * wglGetExtensionsStringEXT(OPENGL32.@)
139 const char * WINAPI wglGetExtensionsStringEXT(void) {
140 TRACE("() returning \"%s\"\n", WGL_extensions);
142 return WGL_extensions;
145 /***********************************************************************
146 * wglGetExtensionsStringARB(OPENGL32.@)
148 const char * WINAPI wglGetExtensionsStringARB(HDC hdc) {
149 TRACE("() returning \"%s\"\n", WGL_extensions);
151 return WGL_extensions;
154 static int swap_interval = 1;
156 /***********************************************************************
157 * wglSwapIntervalEXT(OPENGL32.@)
159 BOOL WINAPI wglSwapIntervalEXT(int interval) {
160 FIXME("(%d),stub!\n", interval);
162 swap_interval = interval;
166 /***********************************************************************
167 * wglGetSwapIntervalEXT(OPENGL32.@)
169 int WINAPI wglGetSwapIntervalEXT(VOID) {
171 return swap_interval;
174 typedef struct wine_glpbuffer {
184 #define PUSH1(attribs,att) attribs[nAttribs++] = (att);
185 #define PUSH2(attribs,att,value) attribs[nAttribs++] = (att); attribs[nAttribs++] = (value);
187 #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
188 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
189 #define WGL_DRAW_TO_BITMAP_ARB 0x2002
190 #define WGL_ACCELERATION_ARB 0x2003
191 #define WGL_NEED_PALETTE_ARB 0x2004
192 #define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
193 #define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
194 #define WGL_SWAP_METHOD_ARB 0x2007
195 #define WGL_NUMBER_OVERLAYS_ARB 0x2008
196 #define WGL_NUMBER_UNDERLAYS_ARB 0x2009
197 #define WGL_TRANSPARENT_ARB 0x200A
198 #define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
199 #define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
200 #define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
201 #define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
202 #define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
203 #define WGL_SHARE_DEPTH_ARB 0x200C
204 #define WGL_SHARE_STENCIL_ARB 0x200D
205 #define WGL_SHARE_ACCUM_ARB 0x200E
206 #define WGL_SUPPORT_GDI_ARB 0x200F
207 #define WGL_SUPPORT_OPENGL_ARB 0x2010
208 #define WGL_DOUBLE_BUFFER_ARB 0x2011
209 #define WGL_STEREO_ARB 0x2012
210 #define WGL_PIXEL_TYPE_ARB 0x2013
211 #define WGL_COLOR_BITS_ARB 0x2014
212 #define WGL_RED_BITS_ARB 0x2015
213 #define WGL_RED_SHIFT_ARB 0x2016
214 #define WGL_GREEN_BITS_ARB 0x2017
215 #define WGL_GREEN_SHIFT_ARB 0x2018
216 #define WGL_BLUE_BITS_ARB 0x2019
217 #define WGL_BLUE_SHIFT_ARB 0x201A
218 #define WGL_ALPHA_BITS_ARB 0x201B
219 #define WGL_ALPHA_SHIFT_ARB 0x201C
220 #define WGL_ACCUM_BITS_ARB 0x201D
221 #define WGL_ACCUM_RED_BITS_ARB 0x201E
222 #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
223 #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
224 #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
225 #define WGL_DEPTH_BITS_ARB 0x2022
226 #define WGL_STENCIL_BITS_ARB 0x2023
227 #define WGL_AUX_BUFFERS_ARB 0x2024
229 #define WGL_PBUFFER_WIDTH_ARB 0x2034
230 #define WGL_PBUFFER_HEIGHT_ARB 0x2035
231 #define WGL_PBUFFER_LOST_ARB 0x2036
233 #if 0 /* not used yet */
234 static unsigned ConvertAttribGLXtoWGL(const int* iWGLAttr, int* oGLXAttr) {
235 unsigned nAttribs = 0;
236 FIXME("not yet implemented!\n");
241 static unsigned ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr) {
242 unsigned nAttribs = 0;
246 while (0 != iWGLAttr[cur]) {
247 switch (iWGLAttr[cur]) {
248 case WGL_COLOR_BITS_ARB:
249 pop = iWGLAttr[++cur];
250 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
252 case WGL_ALPHA_BITS_ARB:
253 pop = iWGLAttr[++cur];
254 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
256 case WGL_DEPTH_BITS_ARB:
257 pop = iWGLAttr[++cur];
258 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
260 case WGL_STENCIL_BITS_ARB:
261 pop = iWGLAttr[++cur];
262 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
264 case WGL_DOUBLE_BUFFER_ARB:
265 pop = iWGLAttr[++cur];
266 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
268 case WGL_DRAW_TO_WINDOW_ARB:
269 case WGL_SUPPORT_OPENGL_ARB:
270 case WGL_ACCELERATION_ARB:
272 case WGL_SAMPLE_BUFFERS_ARB:
273 case WGL_SAMPLES_ARB:
283 GLboolean WINAPI wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
285 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
289 GLboolean WINAPI wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
291 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
295 GLboolean WINAPI wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
297 Display* display = get_display( hdc );
298 GLXFBConfig* cfgs = NULL;
304 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
305 if (NULL != pfAttribFList) {
306 FIXME("unused pfAttribFList\n");
309 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs);
310 PUSH1(attribs, None);
312 cfgs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nCfgs);
313 for (it = 0; it < nMaxFormats && it < nCfgs; ++it) {
320 #define HPBUFFERARB void *
321 HPBUFFERARB WINAPI wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
323 Wine_GLPBuffer* object = NULL;
324 Display* display = get_display( hdc );
325 GLXFBConfig* cfgs = NULL;
330 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
332 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
334 object->display = display;
335 object->width = iWidth;
336 object->height = iHeight;
337 object->pixelFormat = iPixelFormat;
339 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs);
340 PUSH1(attribs, None);
342 cfgs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nCfgs);
343 if (nCfgs < iPixelFormat) return NULL; /* unespected error */
345 --nAttribs; /** append more to attribs now we have fbConfig */
346 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
347 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
348 PUSH1(attribs, None);
350 object->drawable = glXCreatePbuffer(display, cfgs[iPixelFormat], attribs);
351 TRACE("drawable as %p\n", (void*) object->drawable);
353 TRACE("->(%p)\n", object);
354 return (HPBUFFERARB) object;
357 HDC WINAPI wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
359 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
361 hDC = CreateCompatibleDC(object->hdc);
362 set_drawable(hDC, object->drawable); /* works ?? */
363 TRACE("(%p)\n", hPbuffer);
367 int WINAPI wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
369 TRACE("(%p, %p)\n", hPbuffer, hdc);
374 GLboolean WINAPI wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
376 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
377 TRACE("(%p)\n", hPbuffer);
379 glXDestroyPbuffer(object->display, object->drawable);
380 HeapFree(GetProcessHeap(), 0, object);
385 GLboolean WINAPI wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
387 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
388 TRACE("(%p, %d, %p)\n", hPbuffer, iAttribute, piValue);
390 /*glXQueryDrawable(object->display, object->drawable);*/
392 switch (iAttribute) {
393 case WGL_PBUFFER_WIDTH_ARB:
394 glXQueryDrawable(object->display, object->drawable, GLX_WIDTH, piValue);
396 case WGL_PBUFFER_HEIGHT_ARB:
397 glXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, piValue);
407 GLboolean WINAPI wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
409 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
410 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
411 return p_glXBindTexImageARB(object->display, object->drawable, iBuffer);
414 GLboolean WINAPI wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
416 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
417 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
418 return p_glXReleaseTexImageARB(object->display, object->drawable, iBuffer);
421 GLboolean WINAPI wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
423 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
424 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
425 return p_glXDrawableAttribARB(object->display, object->drawable, piAttribList);
428 static const struct {
430 BOOL (*query_function)(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
431 const char *glx_version, const char *glx_extensions,
432 const char *server_glx_extensions, const char *client_glx_extensions);
433 } extension_list[] = {
434 { "WGL_ARB_multisample", query_function_multisample },
435 { "WGL_ARB_pbuffer", query_function_pbuffer },
436 { "WGL_ARB_pixel_format" , query_function_pixel_format },
437 { "WGL_ARB_render_texture", query_function_render_texture }
440 /* Used to initialize the WGL extension string at DLL loading */
441 void wgl_ext_initialize_extensions(Display *display, int screen, glXGetProcAddressARB_t proc)
443 int size = strlen(WGL_extensions_base);
444 const char *glx_extensions = glXQueryExtensionsString(display, screen);
445 const char *server_glx_extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
446 const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
447 const char *gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
448 const char *gl_version = (const char *) glGetString(GL_VERSION);
449 const char *glx_version = glXGetClientString(display, GLX_VERSION);
452 TRACE("GL version : %s.\n", debugstr_a(gl_version));
453 TRACE("GL exts : %s.\n", debugstr_a(gl_extensions));
454 TRACE("GLX exts : %s.\n", debugstr_a(glx_extensions));
455 TRACE("Server GLX exts : %s.\n", debugstr_a(server_glx_extensions));
456 TRACE("Client GLX exts : %s.\n", debugstr_a(client_glx_extensions));
458 for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
459 if (extension_list[i].query_function(proc, gl_version, gl_extensions,
460 glx_version, glx_extensions,
461 server_glx_extensions, client_glx_extensions)) {
462 size += strlen(extension_list[i].name) + 1;
466 /* For the moment, only 'base' extensions are supported. */
467 WGL_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 1);
468 if (WGL_extensions == NULL) {
469 WGL_extensions = (char *) WGL_extensions_base;
471 strcpy(WGL_extensions, WGL_extensions_base);
472 for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
473 if (extension_list[i].query_function(proc, gl_version, gl_extensions,
474 glx_version, glx_extensions,
475 server_glx_extensions, client_glx_extensions)) {
476 strcat(WGL_extensions, " ");
477 strcat(WGL_extensions, extension_list[i].name);
482 TRACE("Supporting following WGL extensions : %s.\n", debugstr_a(WGL_extensions));
485 void wgl_ext_finalize_extensions(void)
487 if (WGL_extensions != WGL_extensions_base) {
488 HeapFree(GetProcessHeap(), 0, WGL_extensions);
493 * Putting this at the end to prevent having to write the prototypes :-)
495 * @WARNING: this list must be ordered by name
497 WGL_extension wgl_extension_registry[] = {
498 { "wglBindTexImageARB", (void *) wglBindTexImageARB, NULL, NULL},
499 { "wglChoosePixelFormatARB", (void *) wglChoosePixelFormatARB, NULL, NULL},
500 { "wglCreatePbufferARB", (void *) wglCreatePbufferARB, NULL, NULL},
501 { "wglDestroyPbufferARB", (void *) wglDestroyPbufferARB, NULL, NULL},
502 { "wglGetExtensionsStringARB", (void *) wglGetExtensionsStringARB, NULL, NULL},
503 { "wglGetExtensionsStringEXT", (void *) wglGetExtensionsStringEXT, NULL, NULL},
504 { "wglGetPbufferDCARB", (void *) wglGetPbufferDCARB, NULL, NULL},
505 { "wglGetPixelFormatAttribfvARB", (void *) wglGetPixelFormatAttribfvARB, NULL, NULL},
506 { "wglGetPixelFormatAttribivARB", (void *) wglGetPixelFormatAttribivARB, NULL, NULL},
507 { "wglGetSwapIntervalEXT", (void *) wglGetSwapIntervalEXT, NULL, NULL},
508 { "wglQueryPbufferARB", (void *) wglQueryPbufferARB, NULL, NULL},
509 { "wglReleasePbufferDCARB", (void *) wglReleasePbufferDCARB, NULL, NULL},
510 { "wglReleaseTexImageARB", (void *) wglReleaseTexImageARB, NULL, NULL},
511 { "wglSetPbufferAttribARB", (void *) wglSetPbufferAttribARB, NULL, NULL},
512 { "wglSwapIntervalEXT", (void *) wglSwapIntervalEXT, NULL, NULL}
514 int wgl_extension_registry_size = sizeof(wgl_extension_registry) / sizeof(wgl_extension_registry[0]);