+ # Whether we need user arrays
+ print 'static inline bool __need_user_arrays(void)'
+ print '{'
+ print ' if (!__user_arrays) {'
+ print ' return false;'
+ print ' }'
+ print
+
+ for camelcase_name, uppercase_name in self.arrays:
+ function_name = 'gl%sPointer' % camelcase_name
+ enable_name = 'GL_%s_ARRAY' % uppercase_name
+ binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
+ print ' // %s' % function_name
+ self.array_prolog(api, uppercase_name)
+ print ' if (__glIsEnabled(%s)) {' % enable_name
+ print ' GLint __binding = 0;'
+ print ' __glGetIntegerv(%s, &__binding);' % binding_name
+ print ' if (!__binding) {'
+ self.array_cleanup(api, uppercase_name)
+ print ' return true;'
+ print ' }'
+ print ' }'
+ self.array_epilog(api, uppercase_name)
+ print
+
+ print ' // glVertexAttribPointer'
+ print ' GLint __max_vertex_attribs = 0;'
+ print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);'
+ print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {'
+ print ' GLint __enabled = 0;'
+ print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);'
+ print ' if (__enabled) {'
+ print ' GLint __binding = 0;'
+ print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);'
+ print ' if (!__binding) {'
+ print ' return true;'
+ print ' }'
+ print ' }'
+ print ' }'
+ print
+
+ print ' return false;'
+ print '}'
+ print
+
+ print 'static void __trace_user_arrays(GLuint maxindex);'
+ print
+
+ print 'struct buffer_mapping {'
+ print ' void *map;'
+ print ' GLint length;'
+ print ' bool write;'
+ print ' bool explicit_flush;'
+ print '};'
+ print
+ for target in self.buffer_targets:
+ print 'struct buffer_mapping __%s_mapping;' % target.lower();
+ print
+ print 'static inline struct buffer_mapping *'
+ print 'get_buffer_mapping(GLenum target) {'
+ print ' switch(target) {'
+ for target in self.buffer_targets:
+ print ' case GL_%s:' % target
+ print ' return & __%s_mapping;' % target.lower()
+ print ' default:'
+ print ' OS::DebugMessage("warning: unknown buffer target 0x%04X\\n", target);'
+ print ' return NULL;'
+ print ' }'
+ print '}'
+ print
+
+ # Generate memcpy's signature
+ self.trace_function_decl(glapi.memcpy)
+
+ # Generate a helper function to determine whether a parameter name
+ # refers to a symbolic value or not
+ print 'static bool'
+ print 'is_symbolic_pname(GLenum pname) {'
+ print ' switch(pname) {'
+ for function, type, count, name in glparams.parameters:
+ if type is glapi.GLenum:
+ print ' case %s:' % name
+ print ' return true;'
+ print ' default:'
+ print ' return false;'
+ print ' }'
+ print '}'
+ print
+
+ # Generate a helper function to determine whether a parameter value is
+ # potentially symbolic or not; i.e., if the value can be represented in
+ # an enum or not
+ print 'template<class T>'
+ print 'static inline bool'
+ print 'is_symbolic_param(T param) {'
+ print ' return static_cast<T>(static_cast<GLenum>(param)) == param;'
+ print '}'
+ print
+
+ # Generate a helper function to know how many elements a parameter has
+ print 'static size_t'
+ print '__gl_param_size(GLenum pname) {'
+ print ' switch(pname) {'
+ for function, type, count, name in glparams.parameters:
+ if type is not None:
+ print ' case %s: return %u;' % (name, count)
+ print ' case GL_COMPRESSED_TEXTURE_FORMATS: {'
+ print ' GLint num_compressed_texture_formats = 0;'
+ print ' __glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num_compressed_texture_formats);'
+ print ' return num_compressed_texture_formats;'
+ print ' }'
+ print ' default:'
+ print r' OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);'
+ print ' return 1;'
+ print ' }'
+ print '}'
+ print
+