]> git.cworth.org Git - apitrace/blob - retrace/glretrace_wgl.cpp
Check for ARB_sampler_objects before dumping its state.
[apitrace] / retrace / 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, 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] = glretrace::createDrawable());
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     Context *context = glretrace::createContext();
60     context_map[orig_context] = context;
61 }
62
63 static void retrace_wglDeleteContext(trace::Call &call) {
64     unsigned long long hglrc = call.arg(0).toUIntPtr();
65
66     ContextMap::iterator it;
67     it = context_map.find(hglrc);
68     if (it == context_map.end()) {
69         return;
70     }
71
72     delete it->second;
73     
74     context_map.erase(it);
75 }
76
77 static void retrace_wglMakeCurrent(trace::Call &call) {
78     glws::Drawable *new_drawable = getDrawable(call.arg(0).toUIntPtr());
79     Context *new_context = context_map[call.arg(1).toUIntPtr()];
80
81     glretrace::makeCurrent(call, new_drawable, new_context);
82 }
83
84 static void retrace_wglCopyContext(trace::Call &call) {
85 }
86
87 static void retrace_wglChoosePixelFormat(trace::Call &call) {
88 }
89
90 static void retrace_wglDescribePixelFormat(trace::Call &call) {
91 }
92
93 static void retrace_wglSetPixelFormat(trace::Call &call) {
94 }
95
96 static void retrace_wglSwapBuffers(trace::Call &call) {
97     glws::Drawable *drawable = getDrawable(call.arg(0).toUIntPtr());
98
99     frame_complete(call);
100     if (retrace::doubleBuffer) {
101         if (drawable) {
102             drawable->swapBuffers();
103         } else {
104             glretrace::Context *currentContext = glretrace::getCurrentContext();
105             if (currentContext) {
106                 currentContext->drawable->swapBuffers();
107             }
108         }
109     } else {
110         glFlush();
111     }
112 }
113
114 static void retrace_wglShareLists(trace::Call &call) {
115     unsigned long long hglrc1 = call.arg(0).toUIntPtr();
116     unsigned long long hglrc2 = call.arg(1).toUIntPtr();
117
118     Context *share_context = context_map[hglrc1];
119     Context *old_context = context_map[hglrc2];
120
121     Context *new_context = glretrace::createContext(share_context);
122     if (new_context) {
123         glretrace::Context *currentContext = glretrace::getCurrentContext();
124         if (currentContext == old_context) {
125             glretrace::makeCurrent(call, currentContext->drawable, new_context);
126         }
127
128         context_map[hglrc2] = new_context;
129         
130         delete old_context;
131     }
132 }
133
134 static void retrace_wglCreateLayerContext(trace::Call &call) {
135     retrace_wglCreateContext(call);
136 }
137
138 static void retrace_wglDescribeLayerPlane(trace::Call &call) {
139 }
140
141 static void retrace_wglSetLayerPaletteEntries(trace::Call &call) {
142 }
143
144 static void retrace_wglRealizeLayerPalette(trace::Call &call) {
145 }
146
147 static void retrace_wglSwapLayerBuffers(trace::Call &call) {
148     retrace_wglSwapBuffers(call);
149 }
150
151 static void retrace_wglUseFontBitmapsA(trace::Call &call) {
152 }
153
154 static void retrace_wglUseFontBitmapsW(trace::Call &call) {
155 }
156
157 static void retrace_wglSwapMultipleBuffers(trace::Call &call) {
158 }
159
160 static void retrace_wglUseFontOutlinesA(trace::Call &call) {
161 }
162
163 static void retrace_wglUseFontOutlinesW(trace::Call &call) {
164 }
165
166 static void retrace_wglCreateBufferRegionARB(trace::Call &call) {
167 }
168
169 static void retrace_wglDeleteBufferRegionARB(trace::Call &call) {
170 }
171
172 static void retrace_wglSaveBufferRegionARB(trace::Call &call) {
173 }
174
175 static void retrace_wglRestoreBufferRegionARB(trace::Call &call) {
176 }
177
178 static void retrace_wglChoosePixelFormatARB(trace::Call &call) {
179 }
180
181 static void retrace_wglMakeContextCurrentARB(trace::Call &call) {
182 }
183
184 static void retrace_wglCreatePbufferARB(trace::Call &call) {
185     int iWidth = call.arg(2).toUInt();
186     int iHeight = call.arg(3).toUInt();
187
188     unsigned long long orig_pbuffer = call.ret->toUIntPtr();
189     glws::Drawable *drawable = glretrace::createPbuffer(iWidth, iHeight);
190
191     pbuffer_map[orig_pbuffer] = drawable;
192 }
193
194 static void retrace_wglGetPbufferDCARB(trace::Call &call) {
195     glws::Drawable *pbuffer = pbuffer_map[call.arg(0).toUIntPtr()];
196
197     unsigned long long orig_hdc = call.ret->toUIntPtr();
198
199     drawable_map[orig_hdc] = pbuffer;
200 }
201
202 static void retrace_wglReleasePbufferDCARB(trace::Call &call) {
203 }
204
205 static void retrace_wglDestroyPbufferARB(trace::Call &call) {
206 }
207
208 static void retrace_wglQueryPbufferARB(trace::Call &call) {
209 }
210
211 static void retrace_wglBindTexImageARB(trace::Call &call) {
212 }
213
214 static void retrace_wglReleaseTexImageARB(trace::Call &call) {
215 }
216
217 static void retrace_wglSetPbufferAttribARB(trace::Call &call) {
218 }
219
220 static void retrace_wglCreateContextAttribsARB(trace::Call &call) {
221     unsigned long long orig_context = call.ret->toUIntPtr();
222     Context *share_context = NULL;
223
224     if (call.arg(1).toPointer()) {
225         share_context = context_map[call.arg(1).toUIntPtr()];
226     }
227
228     Context *context = glretrace::createContext(share_context);
229     context_map[orig_context] = context;
230 }
231
232 static void retrace_wglMakeContextCurrentEXT(trace::Call &call) {
233 }
234
235 static void retrace_wglChoosePixelFormatEXT(trace::Call &call) {
236 }
237
238 static void retrace_wglSwapIntervalEXT(trace::Call &call) {
239 }
240
241 static void retrace_wglAllocateMemoryNV(trace::Call &call) {
242 }
243
244 static void retrace_wglFreeMemoryNV(trace::Call &call) {
245 }
246
247 static void retrace_glAddSwapHintRectWIN(trace::Call &call) {
248 }
249
250 static void retrace_wglGetProcAddress(trace::Call &call) {
251 }
252
253 const retrace::Entry glretrace::wgl_callbacks[] = {
254     {"glAddSwapHintRectWIN", &retrace_glAddSwapHintRectWIN},
255     {"wglAllocateMemoryNV", &retrace_wglAllocateMemoryNV},
256     {"wglBindTexImageARB", &retrace_wglBindTexImageARB},
257     {"wglChoosePixelFormat", &retrace_wglChoosePixelFormat},
258     {"wglChoosePixelFormatARB", &retrace_wglChoosePixelFormatARB},
259     {"wglChoosePixelFormatEXT", &retrace_wglChoosePixelFormatEXT},
260     {"wglCopyContext", &retrace_wglCopyContext},
261     {"wglCreateBufferRegionARB", &retrace_wglCreateBufferRegionARB},
262     {"wglCreateContext", &retrace_wglCreateContext},
263     {"wglCreateContextAttribsARB", &retrace_wglCreateContextAttribsARB},
264     {"wglCreateLayerContext", &retrace_wglCreateLayerContext},
265     {"wglCreatePbufferARB", &retrace_wglCreatePbufferARB},
266     {"wglDeleteBufferRegionARB", &retrace_wglDeleteBufferRegionARB},
267     {"wglDeleteContext", &retrace_wglDeleteContext},
268     {"wglDescribeLayerPlane", &retrace_wglDescribeLayerPlane},
269     {"wglDescribePixelFormat", &retrace_wglDescribePixelFormat},
270     {"wglDestroyPbufferARB", &retrace_wglDestroyPbufferARB},
271     {"wglFreeMemoryNV", &retrace_wglFreeMemoryNV},
272     {"wglGetCurrentContext", &retrace::ignore},
273     {"wglGetCurrentDC", &retrace::ignore},
274     {"wglGetCurrentReadDCARB", &retrace::ignore},
275     {"wglGetCurrentReadDCEXT", &retrace::ignore},
276     {"wglGetDefaultProcAddress", &retrace::ignore},
277     {"wglGetExtensionsStringARB", &retrace::ignore},
278     {"wglGetExtensionsStringEXT", &retrace::ignore},
279     {"wglGetLayerPaletteEntries", &retrace::ignore},
280     {"wglGetPbufferDCARB", &retrace_wglGetPbufferDCARB},
281     {"wglGetPixelFormat", &retrace::ignore},
282     {"wglGetPixelFormatAttribfvARB", &retrace::ignore},
283     {"wglGetPixelFormatAttribfvEXT", &retrace::ignore},
284     {"wglGetPixelFormatAttribivARB", &retrace::ignore},
285     {"wglGetPixelFormatAttribivEXT", &retrace::ignore},
286     {"wglGetProcAddress", &retrace_wglGetProcAddress},
287     {"wglGetSwapIntervalEXT", &retrace::ignore},
288     {"wglMakeContextCurrentARB", &retrace_wglMakeContextCurrentARB},
289     {"wglMakeContextCurrentEXT", &retrace_wglMakeContextCurrentEXT},
290     {"wglMakeCurrent", &retrace_wglMakeCurrent},
291     {"wglQueryPbufferARB", &retrace_wglQueryPbufferARB},
292     {"wglRealizeLayerPalette", &retrace_wglRealizeLayerPalette},
293     {"wglReleasePbufferDCARB", &retrace_wglReleasePbufferDCARB},
294     {"wglReleaseTexImageARB", &retrace_wglReleaseTexImageARB},
295     {"wglRestoreBufferRegionARB", &retrace_wglRestoreBufferRegionARB},
296     {"wglSaveBufferRegionARB", &retrace_wglSaveBufferRegionARB},
297     {"wglSetLayerPaletteEntries", &retrace_wglSetLayerPaletteEntries},
298     {"wglSetPbufferAttribARB", &retrace_wglSetPbufferAttribARB},
299     {"wglSetPixelFormat", &retrace_wglSetPixelFormat},
300     {"wglShareLists", &retrace_wglShareLists},
301     {"wglSwapBuffers", &retrace_wglSwapBuffers},
302     {"wglSwapIntervalEXT", &retrace_wglSwapIntervalEXT},
303     {"wglSwapLayerBuffers", &retrace_wglSwapLayerBuffers},
304     {"wglSwapMultipleBuffers", &retrace_wglSwapMultipleBuffers},
305     {"wglUseFontBitmapsA", &retrace_wglUseFontBitmapsA},
306     {"wglUseFontBitmapsW", &retrace_wglUseFontBitmapsW},
307     {"wglUseFontOutlinesA", &retrace_wglUseFontOutlinesA},
308     {"wglUseFontOutlinesW", &retrace_wglUseFontOutlinesW},
309     {NULL, NULL}
310 };
311