]> git.cworth.org Git - apitrace/blobdiff - wrappers/wgltrace.py
Fix build. Add copyright header to new files.
[apitrace] / wrappers / wgltrace.py
index 22db6f062856f3775b52a35bae862b120b12d636..52fd05182f62c3a664d68b378b4ea360591ceaad 100644 (file)
@@ -28,8 +28,6 @@
 
 
 from gltrace import GlTracer
-from dispatch import function_pointer_type, function_pointer_value
-from codegen import *
 from specs.stdapi import API
 from specs.glapi import glapi
 from specs.wglapi import wglapi
@@ -37,27 +35,33 @@ from specs.wglapi import wglapi
 
 class WglTracer(GlTracer):
 
-    def wrapRet(self, function, instance):
-        GlTracer.wrapRet(self, function, instance)
+    getProcAddressFunctionNames = [
+        "wglGetProcAddress",
+    ]
 
-        if function.name == "wglGetProcAddress":
-            print '    if (%s) {' % instance
-        
-            func_dict = dict([(f.name, f) for f in glapi.functions + wglapi.functions])
+    def traceFunctionImplBody(self, function):
+        GlTracer.traceFunctionImplBody(self, function)
 
-            def handle_case(function_name):
-                f = func_dict[function_name]
-                ptype = function_pointer_type(f)
-                pvalue = function_pointer_value(f)
-                print '    %s = (%s)%s;' % (pvalue, ptype, instance)
-                print '    %s = (%s)&%s;' % (instance, function.type, f.name);
-        
-            def handle_default():
-                print '    os::log("apitrace: warning: unknown function \\"%s\\"\\n", lpszProc);'
+        if function.name == 'wglCreateContext':
+            print '    if (_result)'
+            print '        gltrace::createContext((uintptr_t)_result);'
 
-            string_switch('lpszProc', func_dict.keys(), handle_case, handle_default)
+        if function.name == 'wglMakeCurrent':
+            print '    if (_result) {'
+            print '        if (hglrc != NULL)'
+            print '            gltrace::setContext((uintptr_t)hglrc);'
+            print '        else'
+            print '            gltrace::clearContext();'
             print '    }'
 
+        if function.name == 'wglDeleteContext':
+            # 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::destroyContext((uintptr_t)hglrc);'
+
 
 if __name__ == '__main__':
     print
@@ -80,4 +84,4 @@ if __name__ == '__main__':
     api.addApi(glapi)
     api.addApi(wglapi)
     tracer = WglTracer()
-    tracer.trace_api(api)
+    tracer.traceApi(api)