]> git.cworth.org Git - apitrace/blob - glretrace_wgl.cpp
Bundle less (version 444) for Windows.
[apitrace] / glretrace_wgl.cpp
1 /**************************************************************************
2  *
3  * Copyright 2011 Jose Fonseca
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26
27 #include "glproc.hpp"
28 #include "retrace.hpp"
29 #include "glretrace.hpp"
30
31
32 using namespace glretrace;
33
34
35 typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
36 typedef std::map<unsigned long long, glws::Context *> ContextMap;
37 static DrawableMap drawable_map;
38 static DrawableMap pbuffer_map;
39 static ContextMap context_map;
40
41
42 static glws::Drawable *
43 getDrawable(unsigned long long hdc) {
44     if (hdc == 0) {
45         return NULL;
46     }
47
48     DrawableMap::const_iterator it;
49     it = drawable_map.find(hdc);
50     if (it == drawable_map.end()) {
51         return (drawable_map[hdc] = glws::createDrawable(visual[glretrace::defaultProfile]));
52     }
53
54     return it->second;
55 }
56
57 static void retrace_wglCreateContext(trace::Call &call) {
58     unsigned long long orig_context = call.ret->toUIntPtr();
59     glws::Context *context = glws::createContext(glretrace::visual[glretrace::defaultProfile], NULL, glretrace::defaultProfile);
60     context_map[orig_context] = context;
61 }
62
63 static void retrace_wglDeleteContext(trace::Call &call) {
64 }
65
66 static void retrace_wglMakeCurrent(trace::Call &call) {
67     if (drawable && context) {
68         glFlush();
69         if (!double_buffer) {
70             frame_complete(call);
71         }
72     }
73     
74     glws::Drawable *new_drawable = getDrawable(call.arg(0).toUIntPtr());
75     glws::Context *new_context = context_map[call.arg(1).toUIntPtr()];
76
77     bool result = glws::makeCurrent(new_drawable, new_context);
78
79     if (new_drawable && new_context && result) {
80         drawable = new_drawable;
81         context = new_context;
82     } else {
83         drawable = NULL;
84         context = NULL;
85     }
86 }
87
88 static void retrace_wglCopyContext(trace::Call &call) {
89 }
90
91 static void retrace_wglChoosePixelFormat(trace::Call &call) {
92 }
93
94 static void retrace_wglDescribePixelFormat(trace::Call &call) {
95 }
96
97 static void retrace_wglSetPixelFormat(trace::Call &call) {
98 }
99
100 static void retrace_wglSwapBuffers(trace::Call &call) {
101     frame_complete(call);
102     if (double_buffer) {
103         drawable->swapBuffers();
104     } else {
105         glFlush();
106     }
107 }
108
109 static void retrace_wglShareLists(trace::Call &call) {
110     unsigned long long hglrc1 = call.arg(0).toUIntPtr();
111     unsigned long long hglrc2 = call.arg(1).toUIntPtr();
112
113     glws::Context *share_context = context_map[hglrc1];
114     glws::Context *old_context = context_map[hglrc2];
115
116     glws::Context *new_context =
117         glws::createContext(old_context->visual, share_context, glretrace::defaultProfile);
118     if (new_context) {
119         if (context == old_context) {
120             glws::makeCurrent(drawable, new_context);
121         }
122
123         context_map[hglrc2] = new_context;
124         
125         delete old_context;
126     }
127 }
128
129 static void retrace_wglCreateLayerContext(trace::Call &call) {
130     retrace_wglCreateContext(call);
131 }
132
133 static void retrace_wglDescribeLayerPlane(trace::Call &call) {
134 }
135
136 static void retrace_wglSetLayerPaletteEntries(trace::Call &call) {
137 }
138
139 static void retrace_wglRealizeLayerPalette(trace::Call &call) {
140 }
141
142 static void retrace_wglSwapLayerBuffers(trace::Call &call) {
143     retrace_wglSwapBuffers(call);
144 }
145
146 static void retrace_wglUseFontBitmapsA(trace::Call &call) {
147 }
148
149 static void retrace_wglUseFontBitmapsW(trace::Call &call) {
150 }
151
152 static void retrace_wglSwapMultipleBuffers(trace::Call &call) {
153 }
154
155 static void retrace_wglUseFontOutlinesA(trace::Call &call) {
156 }
157
158 static void retrace_wglUseFontOutlinesW(trace::Call &call) {
159 }
160
161 static void retrace_wglCreateBufferRegionARB(trace::Call &call) {
162 }
163
164 static void retrace_wglDeleteBufferRegionARB(trace::Call &call) {
165 }
166
167 static void retrace_wglSaveBufferRegionARB(trace::Call &call) {
168 }
169
170 static void retrace_wglRestoreBufferRegionARB(trace::Call &call) {
171 }
172
173 static void retrace_wglChoosePixelFormatARB(trace::Call &call) {
174 }
175
176 static void retrace_wglMakeContextCurrentARB(trace::Call &call) {
177 }
178
179 static void retrace_wglCreatePbufferARB(trace::Call &call) {
180     int iWidth = call.arg(2).toUInt();
181     int iHeight = call.arg(3).toUInt();
182
183     unsigned long long orig_pbuffer = call.ret->toUIntPtr();
184     glws::Drawable *drawable = glws::createDrawable(glretrace::visual[glretrace::defaultProfile]);
185
186     drawable->resize(iWidth, iHeight);
187     drawable->show();
188
189     pbuffer_map[orig_pbuffer] = drawable;
190 }
191
192 static void retrace_wglGetPbufferDCARB(trace::Call &call) {
193     glws::Drawable *pbuffer = pbuffer_map[call.arg(0).toUIntPtr()];
194
195     unsigned long long orig_hdc = call.ret->toUIntPtr();
196
197     drawable_map[orig_hdc] = pbuffer;
198 }
199
200 static void retrace_wglReleasePbufferDCARB(trace::Call &call) {
201 }
202
203 static void retrace_wglDestroyPbufferARB(trace::Call &call) {
204 }
205
206 static void retrace_wglQueryPbufferARB(trace::Call &call) {
207 }
208
209 static void retrace_wglBindTexImageARB(trace::Call &call) {
210 }
211
212 static void retrace_wglReleaseTexImageARB(trace::Call &call) {
213 }
214
215 static void retrace_wglSetPbufferAttribARB(trace::Call &call) {
216 }
217
218 static void retrace_wglCreateContextAttribsARB(trace::Call &call) {
219     unsigned long long orig_context = call.ret->toUIntPtr();
220     glws::Context *share_context = NULL;
221
222     if (call.arg(1).toPointer()) {
223         share_context = context_map[call.arg(1).toUIntPtr()];
224     }
225
226     glws::Context *context = glws::createContext(glretrace::visual[glretrace::defaultProfile], share_context, glretrace::defaultProfile);
227     context_map[orig_context] = context;
228 }
229
230 static void retrace_wglMakeContextCurrentEXT(trace::Call &call) {
231 }
232
233 static void retrace_wglChoosePixelFormatEXT(trace::Call &call) {
234 }
235
236 static void retrace_wglSwapIntervalEXT(trace::Call &call) {
237 }
238
239 static void retrace_wglAllocateMemoryNV(trace::Call &call) {
240 }
241
242 static void retrace_wglFreeMemoryNV(trace::Call &call) {
243 }
244
245 static void retrace_glAddSwapHintRectWIN(trace::Call &call) {
246 }
247
248 static void retrace_wglGetProcAddress(trace::Call &call) {
249 }
250
251 const retrace::Entry glretrace::wgl_callbacks[] = {
252     {"glAddSwapHintRectWIN", &retrace_glAddSwapHintRectWIN},
253     {"wglAllocateMemoryNV", &retrace_wglAllocateMemoryNV},
254     {"wglBindTexImageARB", &retrace_wglBindTexImageARB},
255     {"wglChoosePixelFormat", &retrace_wglChoosePixelFormat},
256     {"wglChoosePixelFormatARB", &retrace_wglChoosePixelFormatARB},
257     {"wglChoosePixelFormatEXT", &retrace_wglChoosePixelFormatEXT},
258     {"wglCopyContext", &retrace_wglCopyContext},
259     {"wglCreateBufferRegionARB", &retrace_wglCreateBufferRegionARB},
260     {"wglCreateContext", &retrace_wglCreateContext},
261     {"wglCreateContextAttribsARB", &retrace_wglCreateContextAttribsARB},
262     {"wglCreateLayerContext", &retrace_wglCreateLayerContext},
263     {"wglCreatePbufferARB", &retrace_wglCreatePbufferARB},
264     {"wglDeleteBufferRegionARB", &retrace_wglDeleteBufferRegionARB},
265     {"wglDeleteContext", &retrace_wglDeleteContext},
266     {"wglDescribeLayerPlane", &retrace_wglDescribeLayerPlane},
267     {"wglDescribePixelFormat", &retrace_wglDescribePixelFormat},
268     {"wglDestroyPbufferARB", &retrace_wglDestroyPbufferARB},
269     {"wglFreeMemoryNV", &retrace_wglFreeMemoryNV},
270     {"wglGetCurrentContext", &retrace::ignore},
271     {"wglGetCurrentDC", &retrace::ignore},
272     {"wglGetCurrentReadDCARB", &retrace::ignore},
273     {"wglGetCurrentReadDCEXT", &retrace::ignore},
274     {"wglGetDefaultProcAddress", &retrace::ignore},
275     {"wglGetExtensionsStringARB", &retrace::ignore},
276     {"wglGetExtensionsStringEXT", &retrace::ignore},
277     {"wglGetLayerPaletteEntries", &retrace::ignore},
278     {"wglGetPbufferDCARB", &retrace_wglGetPbufferDCARB},
279     {"wglGetPixelFormat", &retrace::ignore},
280     {"wglGetPixelFormatAttribfvARB", &retrace::ignore},
281     {"wglGetPixelFormatAttribfvEXT", &retrace::ignore},
282     {"wglGetPixelFormatAttribivARB", &retrace::ignore},
283     {"wglGetPixelFormatAttribivEXT", &retrace::ignore},
284     {"wglGetProcAddress", &retrace_wglGetProcAddress},
285     {"wglGetSwapIntervalEXT", &retrace::ignore},
286     {"wglMakeContextCurrentARB", &retrace_wglMakeContextCurrentARB},
287     {"wglMakeContextCurrentEXT", &retrace_wglMakeContextCurrentEXT},
288     {"wglMakeCurrent", &retrace_wglMakeCurrent},
289     {"wglQueryPbufferARB", &retrace_wglQueryPbufferARB},
290     {"wglRealizeLayerPalette", &retrace_wglRealizeLayerPalette},
291     {"wglReleasePbufferDCARB", &retrace_wglReleasePbufferDCARB},
292     {"wglReleaseTexImageARB", &retrace_wglReleaseTexImageARB},
293     {"wglRestoreBufferRegionARB", &retrace_wglRestoreBufferRegionARB},
294     {"wglSaveBufferRegionARB", &retrace_wglSaveBufferRegionARB},
295     {"wglSetLayerPaletteEntries", &retrace_wglSetLayerPaletteEntries},
296     {"wglSetPbufferAttribARB", &retrace_wglSetPbufferAttribARB},
297     {"wglSetPixelFormat", &retrace_wglSetPixelFormat},
298     {"wglShareLists", &retrace_wglShareLists},
299     {"wglSwapBuffers", &retrace_wglSwapBuffers},
300     {"wglSwapIntervalEXT", &retrace_wglSwapIntervalEXT},
301     {"wglSwapLayerBuffers", &retrace_wglSwapLayerBuffers},
302     {"wglSwapMultipleBuffers", &retrace_wglSwapMultipleBuffers},
303     {"wglUseFontBitmapsA", &retrace_wglUseFontBitmapsA},
304     {"wglUseFontBitmapsW", &retrace_wglUseFontBitmapsW},
305     {"wglUseFontOutlinesA", &retrace_wglUseFontOutlinesA},
306     {"wglUseFontOutlinesW", &retrace_wglUseFontOutlinesW},
307     {NULL, NULL}
308 };
309