- if prefix == 'glGet':
- self.suffixes = {
- 'GLboolean': 'Booleanv',
- 'GLint': 'Intv',
- 'GLfloat': 'Floatv',
- 'GLdouble': 'Doublev',
- 'GLstring': 'String',
- }
- else:
- self.suffixes = {
- 'GLint': 'iv',
- 'GLfloat': 'fv',
- 'GLdouble': 'Doublev',
- 'GLstring': 'String',
- }
-
-
- def visit_const(self, const):
- return self.visit(const.type)
-
- def visit_alias(self, alias):
- if alias.expr == 'GLboolean':
- if self.long_suffix:
- return self.prefix + 'Booleanv', alias.expr
- else:
- return self.prefix + 'iv', 'GLint'
- elif alias.expr == 'GLdouble':
- if self.long_suffix:
- return self.prefix + 'Doublev', alias.expr
- else:
- return self.prefix + 'dv', alias.expr
- elif alias.expr == 'GLfloat':
- if self.long_suffix:
- return self.prefix + 'Floatv', alias.expr
- else:
- return self.prefix + 'fv', alias.expr
- elif alias.expr in ('GLint', 'GLuint', 'GLsizei'):
- if self.long_suffix:
- return self.prefix + 'Integerv', 'GLint'
- else:
- return self.prefix + 'iv', 'GLint'
+ def __init__(self, radical, suffixes):
+ self.radical = radical
+ self.suffixes = suffixes
+
+ def reduced_type(self, type):
+ if type in self.suffixes:
+ return type
+ if type in self.reduced_types:
+ return self.reduced_type(self.reduced_types[type])
+ raise NotImplementedError
+
+ def inflect(self, type):
+ return self.radical + self.suffix(type)
+
+ def suffix(self, type):
+ type = self.reduced_type(type)
+ assert type in self.suffixes
+ return self.suffixes[type]
+
+
+class StateGetter(Visitor):
+ '''Type visitor that is able to extract the state via one of the glGet*
+ functions.
+
+ It will declare any temporary variable
+ '''
+
+ def __init__(self, radical, suffixes):
+ self.inflector = GetInflector(radical, suffixes)
+
+ def __call__(self, *args):
+ pname = args[-1]
+
+ for function, type, count, name in parameters:
+ if type is X:
+ continue
+ if name == pname:
+ if count != 1:
+ type = Array(type, str(count))
+
+ return type, self.visit(type, args)
+
+ raise NotImplementedError
+
+ def temp_name(self, args):
+ '''Return the name of a temporary variable to hold the state.'''
+ pname = args[-1]
+
+ return pname[3:].lower()
+
+ def visit_const(self, const, args):
+ return self.visit(const.type, args)
+
+ def visit_scalar(self, type, args):
+ temp_name = self.temp_name(args)
+ elem_type = self.inflector.reduced_type(type)
+ inflection = self.inflector.inflect(type)
+ if inflection.endswith('v'):
+ print ' %s %s = 0;' % (elem_type, temp_name)
+ print ' %s(%s, &%s);' % (inflection, ', '.join(args), temp_name)