]> git.cworth.org Git - apitrace/blobdiff - wrappers/wgltrace.py
trace: Unwrap all args before serializing them.
[apitrace] / wrappers / wgltrace.py
index f7625c6d895622a98d4470f4d35f1aac01376d7e..c001cb1a988ffcd54f0b1ad8e8bd2242480d87f1 100644 (file)
@@ -28,7 +28,7 @@
 
 
 from gltrace import GlTracer
-from specs.stdapi import API
+from specs.stdapi import Module, API
 from specs.glapi import glapi
 from specs.wglapi import wglapi
 
@@ -39,14 +39,38 @@ class WglTracer(GlTracer):
         "wglGetProcAddress",
     ]
 
+    createContextFunctionNames = [
+        'wglCreateContext',
+        'wglCreateContextAttribsARB',
+        'wglCreateLayerContext',
+    ]
+
+    destroyContextFunctionNames = [
+        'wglDeleteContext',
+    ]
+
+    makeCurrentFunctionNames = [
+        'wglMakeCurrent',
+        'wglMakeContextCurrentARB',
+        'wglMakeContextCurrentEXT',
+    ]
+
     def traceFunctionImplBody(self, function):
+        if function.name in self.destroyContextFunctionNames:
+            # Unlike other GL APIs like EGL or GLX, WGL will make the context
+            # inactive if it's currently the active context.
+            print '    if (_wglGetCurrentContext() == hglrc) {'
+            print '        gltrace::clearContext();'
+            print '    }'
+            print '    gltrace::releaseContext((uintptr_t)hglrc);'
+
         GlTracer.traceFunctionImplBody(self, function)
 
-        if function.name == 'wglCreateContext':
+        if function.name in self.createContextFunctionNames:
             print '    if (_result)'
             print '        gltrace::createContext((uintptr_t)_result);'
 
-        if function.name == 'wglMakeCurrent':
+        if function.name in self.makeCurrentFunctionNames:
             print '    if (_result) {'
             print '        if (hglrc != NULL)'
             print '            gltrace::setContext((uintptr_t)hglrc);'
@@ -54,14 +78,6 @@ class WglTracer(GlTracer):
             print '            gltrace::clearContext();'
             print '    }'
 
-        if function.name == 'wglDeleteContext':
-            print '    gltrace::Context *current_ctx = gltrace::getContext();'
-            # Unlike other GL APIs like EGL or GLX, WGL will make the context
-            # inactive if it's currently the active context.
-            print '    if (current_ctx == (uintptr_t)hglrc)'
-            print '        gltrace::clearContext();'
-            print '    gltrace::destroyContext((uintptr_t)ctx);'
-
 
 if __name__ == '__main__':
     print
@@ -80,8 +96,10 @@ if __name__ == '__main__':
     print '#include "glproc.hpp"'
     print '#include "glsize.hpp"'
     print
+    module = Module()
+    module.mergeModule(glapi)
+    module.mergeModule(wglapi)
     api = API()
-    api.addApi(glapi)
-    api.addApi(wglapi)
+    api.addModule(module)
     tracer = WglTracer()
     tracer.traceApi(api)