X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=wrappers%2Fwgltrace.py;h=c001cb1a988ffcd54f0b1ad8e8bd2242480d87f1;hb=6bb028d7223347f167c2a4e16f8bb0028c95ffe9;hp=22db6f062856f3775b52a35bae862b120b12d636;hpb=452d3256a3ba7f249222ef857d69c8caaaa753f3;p=apitrace diff --git a/wrappers/wgltrace.py b/wrappers/wgltrace.py index 22db6f0..c001cb1 100644 --- a/wrappers/wgltrace.py +++ b/wrappers/wgltrace.py @@ -28,34 +28,54 @@ from gltrace import GlTracer -from dispatch import function_pointer_type, function_pointer_value -from codegen import * -from specs.stdapi import API +from specs.stdapi import Module, API from specs.glapi import glapi from specs.wglapi import wglapi class WglTracer(GlTracer): - def wrapRet(self, function, instance): - GlTracer.wrapRet(self, function, instance) - - if function.name == "wglGetProcAddress": - print ' if (%s) {' % instance - - func_dict = dict([(f.name, f) for f in glapi.functions + wglapi.functions]) - - 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);' - - string_switch('lpszProc', func_dict.keys(), handle_case, handle_default) + getProcAddressFunctionNames = [ + "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 in self.createContextFunctionNames: + print ' if (_result)' + print ' gltrace::createContext((uintptr_t)_result);' + + if function.name in self.makeCurrentFunctionNames: + print ' if (_result) {' + print ' if (hglrc != NULL)' + print ' gltrace::setContext((uintptr_t)hglrc);' + print ' else' + print ' gltrace::clearContext();' print ' }' @@ -76,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.trace_api(api) + tracer.traceApi(api)