1 ##########################################################################
3 # Copyright 2008-2010 VMware, Inc.
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:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
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
24 ##########################################################################/
27 """GL tracing generator."""
30 from glxapi import glxapi
31 from trace import Tracer, dump_instance
34 class GlTracer(Tracer):
36 pointer_function_names = {
37 "glVertexPointer": "VertexPointer",
38 "glVertexPointerEXT": "VertexPointer",
39 "glNormalPointer": "NormalPointer",
40 "glNormalPointerEXT": "NormalPointer",
41 "glColorPointer": "ColorPointer",
42 "glColorPointerEXT": "ColorPointer",
43 "glIndexPointer": "IndexPointer",
44 "glIndexPointerEXT": "IndexPointer",
45 "glTexCoordPointer": "TexCoordPointer",
46 "glTexCoordPointerEXT": "TexCoordPointer",
47 "glEdgeFlagPointer": "EdgeFlagPointer",
48 "glEdgeFlagPointerEXT": "EdgeFlagPointer",
49 "glFogCoordPointer": "FogCoordPointer",
50 "glFogCoordPointerEXT": "FogCoordPointer",
51 "glSecondaryColorPointer": "SecondaryColorPointer",
52 "glSecondaryColorPointerEXT": "SecondaryColorPointer",
53 "glInterleavedArrays": "InterleavedArrays",
55 #"glVertexAttribPointer": "VertexAttribPointer",
56 #"glVertexAttribPointerARB": "VertexAttribPointer",
57 #"glVertexAttribPointerNV": "VertexAttribPointer",
58 #"glVertexAttribLPointer": "VertexAttribLPointer",
60 #"glMatrixIndexPointerARB": "MatrixIndexPointer",
63 def header(self, api):
64 Tracer.header(self, api)
65 self.state_tracker_decl(api)
67 def footer(self, api):
68 Tracer.footer(self, api)
69 self.state_tracker_impl(api)
71 def state_tracker_decl(self, api):
72 # A simple state tracker to track the pointer values
74 atoms = list(set(self.pointer_function_names.itervalues()))
77 # define the NEW_XXXX dirty flags
78 for i in range(len(atoms)):
80 dirtyflag = "NEW_%s" % atom.upper()
81 print '#define %s 0x%x' % (dirtyflag, 1 << i)
84 # declare the state structure
87 function = api.get_function_by_name('gl%s' % atom)
89 for arg in function.args:
90 print ' %s %s;' % (arg.type, arg.name)
92 print ' unsigned dirty;'
96 def state_tracker_impl(self, api):
97 # A simple state tracker to track the pointer values
99 atoms = list(set(self.pointer_function_names.itervalues()))
103 print 'void __state_update(GLsizei )'
105 print ' GLint __array_buffer = 0;'
106 print ' glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);'
108 function = api.get_function_by_name('gl%s' % atom)
109 dirtyflag = "NEW_%s" % atom.upper()
110 print ' if (__state.dirty & %s) {' % dirtyflag
111 print ' unsigned __call = Trace::BeginEnter(__%s_sig);' % (function.name,)
112 for arg in function.args:
113 assert not arg.output
114 print ' Trace::BeginArg(%u);' % (arg.index,)
115 dump_instance(arg.type, '__state.%s.%s' % (atom, arg.name))
116 print ' Trace::EndArg();'
117 print ' Trace::EndEnter();'
118 print ' Trace::BeginLeave(__call);'
119 print ' Trace::EndLeave();'