Reverse the order for deleting the items in resetcontent to correctly
[wine] / dlls / opengl32 / wgl_ext.c
1 /* Support for window-specific OpenGL extensions.
2  *
3  * Copyright (c) 2004 Lionel Ulmer
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winerror.h"
31
32 #include "wgl.h"
33 #include "wgl_ext.h"
34 #include "opengl_ext.h"
35 #include "wine/library.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
39
40 /* Some WGL extensions... */
41 static const char *WGL_extensions_base = "WGL_ARB_extensions_string WGL_EXT_extensions_string";
42 static char *WGL_extensions = NULL;
43
44 /* Extensions-query functions */
45 BOOL query_function_pbuffers(const char *gl_version, const char *gl_extensions, const char *glx_extensions,
46                              const char *server_glx_extensions, const char *client_glx_extensions)
47 {
48     return FALSE;
49 }
50
51 /***********************************************************************
52  *              wglGetExtensionsStringEXT(OPENGL32.@)
53  */
54 const char * WINAPI wglGetExtensionsStringEXT(void) {
55     TRACE("() returning \"%s\"\n", WGL_extensions);
56
57     return WGL_extensions;
58 }
59
60 /***********************************************************************
61  *              wglGetExtensionsStringARB(OPENGL32.@)
62  */
63 const char * WINAPI wglGetExtensionsStringARB(HDC hdc) {
64     TRACE("() returning \"%s\"\n", WGL_extensions);
65
66     return WGL_extensions;    
67 }
68
69 static int swap_interval = 1;
70
71 /***********************************************************************
72  *              wglSwapIntervalEXT(OPENGL32.@)
73  */
74 BOOL WINAPI wglSwapIntervalEXT(int interval) {
75     FIXME("(%d),stub!\n", interval);
76
77     swap_interval = interval;
78     return TRUE;
79 }
80
81 /***********************************************************************
82  *              wglGetSwapIntervalEXT(OPENGL32.@)
83  */
84 int WINAPI wglGetSwapIntervalEXT(VOID) {
85     FIXME("(),stub!\n");
86     return swap_interval;
87 }
88
89 static const struct {
90     const char *name;
91     BOOL (*query_function)(const char *gl_version, const char *gl_extensions, const char *glx_extensions,
92                            const char *server_glx_extensions, const char *client_glx_extensions);
93 } extension_list[] = {
94     { "WGL_ARB_pbuffer", query_function_pbuffers }
95 };
96
97 /* Used to initialize the WGL extension string at DLL loading */
98 void wgl_ext_initialize_extensions(Display *display, int screen)
99 {
100     int size = strlen(WGL_extensions_base);
101     const char *glx_extensions = glXQueryExtensionsString(display, screen);
102     const char *server_glx_extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
103     const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
104     const char *gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
105     const char *gl_version = (const char *) glGetString(GL_VERSION);
106     int i;
107
108     TRACE("GL version      : %s.\n", debugstr_a(gl_version));
109     TRACE("GL exts         : %s.\n", debugstr_a(gl_extensions));
110     TRACE("GLX exts        : %s.\n", debugstr_a(glx_extensions));
111     TRACE("Server GLX exts : %s.\n", debugstr_a(server_glx_extensions));
112     TRACE("Client GLX exts : %s.\n", debugstr_a(client_glx_extensions));
113
114     for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
115         if (extension_list[i].query_function(gl_version, gl_extensions, glx_extensions,
116                                              server_glx_extensions, client_glx_extensions)) {
117             size += strlen(extension_list[i].name) + 1;
118         }
119     }
120
121     /* For the moment, only 'base' extensions are supported. */
122     WGL_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 1);
123     if (WGL_extensions == NULL) {
124         WGL_extensions = (char *) WGL_extensions_base;
125     } else {
126         strcpy(WGL_extensions, WGL_extensions_base);
127         for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
128             if (extension_list[i].query_function(gl_version, gl_extensions, glx_extensions,
129                                                  server_glx_extensions, client_glx_extensions)) {
130                 strcat(WGL_extensions, " ");
131                 strcat(WGL_extensions, extension_list[i].name);
132             }
133         }
134     }
135
136     TRACE("Supporting following WGL extensions : %s.\n", debugstr_a(WGL_extensions));
137 }
138
139 void wgl_ext_finalize_extensions(void)
140 {
141     if (WGL_extensions != WGL_extensions_base) {
142         HeapFree(GetProcessHeap(), 0, WGL_extensions);
143     }
144 }
145
146 /* Putting this at the end to prevent having to write the prototypes :-) */
147 WGL_extension wgl_extension_registry[] = {
148     { "wglGetExtensionsStringARB", (void *) wglGetExtensionsStringARB, NULL, NULL},
149     { "wglGetExtensionsStringEXT", (void *) wglGetExtensionsStringEXT, NULL, NULL},
150     { "wglGetSwapIntervalEXT", (void *) wglSwapIntervalEXT, NULL, NULL},
151     { "wglSwapIntervalEXT", (void *) wglSwapIntervalEXT, NULL, NULL}
152 };
153 int wgl_extension_registry_size = sizeof(wgl_extension_registry) / sizeof(wgl_extension_registry[0]);