+/**
+ * This is called by glBegin, glDrawArrays and glDrawElements (and
+ * variations of those calls). When we transition from immediate mode
+ * drawing to array drawing we need to invalidate the array state.
+ *
+ * glBegin/End builds vertex arrays. Those arrays may look identical
+ * to glDrawArrays arrays except that the position of the elements may
+ * be different. For example, arrays of (position3v, normal3f) vs. arrays
+ * of (normal3f, position3f). So we need to make sure we notify drivers
+ * that arrays may be changing.
+ */
+static inline void
+vbo_draw_method(struct vbo_context *vbo, gl_draw_method method)
+{
+ struct gl_context *ctx = vbo->exec.ctx;
+
+ if (ctx->Array.DrawMethod != method) {
+ switch (method) {
+ case DRAW_ARRAYS:
+ ctx->Array._DrawArrays = vbo->exec.array.inputs;
+ break;
+ case DRAW_BEGIN_END:
+ ctx->Array._DrawArrays = vbo->exec.vtx.inputs;
+ break;
+ case DRAW_DISPLAY_LIST:
+ ctx->Array._DrawArrays = vbo->save.inputs;
+ break;
+ default:
+ assert(0);
+ }
+
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
+ ctx->Array.DrawMethod = method;
+ }
+}
+
+/**
+ * Return if format is integer. The immediate mode commands only emit floats
+ * for non-integer types, thus everything else is integer.
+ */
+static inline GLboolean
+vbo_attrtype_to_integer_flag(GLenum format)
+{
+ switch (format) {
+ case GL_FLOAT:
+ case GL_DOUBLE:
+ return GL_FALSE;
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ return GL_TRUE;
+ default:
+ assert(0);
+ return GL_FALSE;
+ }
+}
+
+static inline GLboolean
+vbo_attrtype_to_double_flag(GLenum format)
+{
+ switch (format) {
+ case GL_FLOAT:
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ return GL_FALSE;
+ case GL_DOUBLE:
+ return GL_TRUE;
+ default:
+ assert(0);
+ return GL_FALSE;
+ }
+}
+
+/**
+ * Return default component values for the given format.
+ * The return type is an array of fi_types, because that's how we declare
+ * the vertex storage : floats , integers or unsigned integers.
+ */
+static inline const fi_type *
+vbo_get_default_vals_as_union(GLenum format)
+{
+ static const GLfloat default_float[4] = { 0, 0, 0, 1 };
+ static const GLint default_int[4] = { 0, 0, 0, 1 };
+
+ switch (format) {
+ case GL_FLOAT:
+ return (fi_type *)default_float;
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ return (fi_type *)default_int;
+ default:
+ assert(0);
+ return NULL;
+ }
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+