José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 1 | ########################################################################## |
| 2 | # |
| 3 | # Copyright 2008-2010 VMware, Inc. |
| 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 | """GL tracing generator.""" |
| 28 | |
| 29 | |
| 30 | from glxapi import glxapi |
| 31 | from trace import Tracer, dump_instance |
| 32 | |
| 33 | |
| 34 | class GlTracer(Tracer): |
| 35 | |
| 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", |
| 54 | |
| 55 | #"glVertexAttribPointer": "VertexAttribPointer", |
| 56 | #"glVertexAttribPointerARB": "VertexAttribPointer", |
| 57 | #"glVertexAttribPointerNV": "VertexAttribPointer", |
| 58 | #"glVertexAttribLPointer": "VertexAttribLPointer", |
| 59 | |
| 60 | #"glMatrixIndexPointerARB": "MatrixIndexPointer", |
| 61 | } |
| 62 | |
| 63 | def header(self, api): |
| 64 | Tracer.header(self, api) |
| 65 | self.state_tracker_decl(api) |
| 66 | |
| 67 | def footer(self, api): |
| 68 | Tracer.footer(self, api) |
| 69 | self.state_tracker_impl(api) |
| 70 | |
| 71 | def state_tracker_decl(self, api): |
| 72 | # A simple state tracker to track the pointer values |
| 73 | |
| 74 | atoms = list(set(self.pointer_function_names.itervalues())) |
| 75 | atoms.sort() |
| 76 | |
| 77 | # define the NEW_XXXX dirty flags |
| 78 | for i in range(len(atoms)): |
| 79 | atom = atoms[i] |
| 80 | dirtyflag = "NEW_%s" % atom.upper() |
| 81 | print '#define %s 0x%x' % (dirtyflag, 1 << i) |
| 82 | print |
| 83 | |
| 84 | # declare the state structure |
| 85 | print 'struct {' |
| 86 | for atom in atoms: |
| 87 | function = api.get_function_by_name('gl%s' % atom) |
| 88 | print ' struct {' |
| 89 | for arg in function.args: |
| 90 | print ' %s %s;' % (arg.type, arg.name) |
| 91 | print ' } %s;' % atom |
| 92 | print ' unsigned dirty;' |
| 93 | print '} __state;' |
| 94 | print |
| 95 | |
| 96 | def state_tracker_impl(self, api): |
| 97 | # A simple state tracker to track the pointer values |
| 98 | |
| 99 | atoms = list(set(self.pointer_function_names.itervalues())) |
| 100 | atoms.sort() |
| 101 | |
| 102 | # update the state |
| 103 | print 'void __state_update(GLsizei )' |
| 104 | print '{' |
| 105 | print ' GLint __array_buffer = 0;' |
| 106 | print ' glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' |
| 107 | for atom in atoms: |
| 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();' |
| 120 | print ' }' |
| 121 | print '}' |
| 122 | print |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |