i965: Don't allocate a 1-level texture when GL_GENERATE_MIPMAP is set.
[mesa.git] / src / mesa / vbo / vbo_save_api.c
index b8dd90c67f165c5b4f9bbb2072d4005b6bf818ae..2028d8b2c8d1688115d11e9d58d2ce98867c56cf 100644 (file)
@@ -305,9 +305,9 @@ _save_reset_counters(struct gl_context *ctx)
  * previous prim.
  */
 static void
-vbo_merge_prims(struct gl_context *ctx,
-                struct _mesa_prim *prim_list,
-                GLuint *prim_count)
+merge_prims(struct gl_context *ctx,
+            struct _mesa_prim *prim_list,
+            GLuint *prim_count)
 {
    GLuint i;
    struct _mesa_prim *prev_prim = prim_list;
@@ -315,19 +315,13 @@ vbo_merge_prims(struct gl_context *ctx,
    for (i = 1; i < *prim_count; i++) {
       struct _mesa_prim *this_prim = prim_list + i;
 
-      if (this_prim->mode == prev_prim->mode &&
-          this_prim->mode == GL_QUADS &&
-          this_prim->count % 4 == 0 &&
-          prev_prim->count % 4 == 0 &&
-          this_prim->start == prev_prim->start + prev_prim->count &&
-          this_prim->basevertex == prev_prim->basevertex &&
-          this_prim->num_instances == prev_prim->num_instances &&
-          this_prim->base_instance == prev_prim->base_instance) {
+      vbo_try_prim_conversion(this_prim);
+
+      if (vbo_can_merge_prims(prev_prim, this_prim)) {
          /* We've found a prim that just extend the previous one.  Tack it
           * onto the previous one, and let this primitive struct get dropped.
           */
-         prev_prim->count += this_prim->count;
-         prev_prim->end = this_prim->end;
+         vbo_merge_prims(prev_prim, this_prim);
          continue;
       }
 
@@ -420,7 +414,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
     */
    save->copied.nr = _save_copy_vertices(ctx, node, save->buffer);
 
-   vbo_merge_prims(ctx, node->prim, &node->prim_count);
+   merge_prims(ctx, node->prim, &node->prim_count);
 
    /* Deal with GL_COMPILE_AND_EXECUTE:
     */
@@ -475,6 +469,8 @@ _save_compile_vertex_list(struct gl_context *ctx)
 
 
 /**
+ * This is called when we fill a vertex buffer before we hit a glEnd().
+ * We
  * TODO -- If no new vertices have been stored, don't bother saving it.
  */
 static void
@@ -583,7 +579,11 @@ _save_copy_from_current(struct gl_context *ctx)
 }
 
 
-/* Flush existing data, set new attrib size, replay copied vertices.
+/**
+ * Called when we increase the size of a vertex attribute.  For example,
+ * if we've seen one or more glTexCoord2f() calls and now we get a
+ * glTexCoord3f() call.
+ * Flush existing data, set new attrib size, replay copied vertices.
  */
 static void
 _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, GLuint newsz)
@@ -640,7 +640,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, GLuint newsz)
     * and will need fixup at runtime.
     */
    if (save->copied.nr) {
-      GLfloat *data = save->copied.buffer;
+      const GLfloat *data = save->copied.buffer;
       GLfloat *dest = save->buffer;
       GLuint j;
 
@@ -682,6 +682,11 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, GLuint newsz)
 }
 
 
+/**
+ * This is called when the size of a vertex attribute changes.
+ * For example, after seeing one or more glTexCoord2f() calls we
+ * get a glTexCoord4f() or glTexCoord1f() call.
+ */
 static void
 save_fixup_vertex(struct gl_context *ctx, GLuint attr, GLuint sz)
 {
@@ -708,6 +713,11 @@ save_fixup_vertex(struct gl_context *ctx, GLuint attr, GLuint sz)
 }
 
 
+/**
+ * Reset the current size of all vertex attributes to the default
+ * value of 0.  This signals that we haven't yet seen any per-vertex
+ * commands such as glNormal3f() or glTexCoord2f().
+ */
 static void
 _save_reset_vertex(struct gl_context *ctx)
 {
@@ -860,7 +870,7 @@ dlist_fallback(struct gl_context *ctx)
    else {
       _mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt);
    }
-   ctx->Driver.SaveNeedFlush = 0;
+   ctx->Driver.SaveNeedFlush = GL_FALSE;
 }
 
 
@@ -930,15 +940,16 @@ _save_CallLists(GLsizei n, GLenum type, const GLvoid * v)
 
 
 
-/* This begin is hooked into ...  Updating of
- * ctx->Driver.CurrentSavePrimitive is already taken care of.
+/**
+ * Called via ctx->Driver.NotifySaveBegin() when a glBegin is getting
+ * compiled into a display list.
+ * Updating of ctx->Driver.CurrentSavePrimitive is already taken care of.
  */
 GLboolean
 vbo_save_NotifyBegin(struct gl_context *ctx, GLenum mode)
 {
    struct vbo_save_context *save = &vbo_context(ctx)->save;
-
-   GLuint i = save->prim_count++;
+   const GLuint i = save->prim_count++;
 
    assert(i < save->prim_max);
    save->prim[i].mode = mode & VBO_SAVE_PRIM_MODE_MASK;
@@ -959,7 +970,13 @@ vbo_save_NotifyBegin(struct gl_context *ctx, GLenum mode)
    else {
       _mesa_install_save_vtxfmt(ctx, &save->vtxfmt);
    }
-   ctx->Driver.SaveNeedFlush = 1;
+
+   /* We need to call SaveFlushVertices() if there's state change */
+   ctx->Driver.SaveNeedFlush = GL_TRUE;
+
+   /* GL_TRUE means we've handled this glBegin here; don't compile a BEGIN
+    * opcode into the display list.
+    */
    return GL_TRUE;
 }
 
@@ -969,7 +986,7 @@ _save_End(void)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct vbo_save_context *save = &vbo_context(ctx)->save;
-   GLint i = save->prim_count - 1;
+   const GLint i = save->prim_count - 1;
 
    ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
    save->prim[i].end = 1;
@@ -1165,7 +1182,7 @@ _save_OBE_DrawRangeElements(GLenum mode, GLuint start, GLuint end,
 
 static void GLAPIENTRY
 _save_OBE_MultiDrawElements(GLenum mode, const GLsizei *count, GLenum type,
-                            const GLvoid **indices, GLsizei primcount)
+                            const GLvoid * const *indices, GLsizei primcount)
 {
    GLsizei i;
 
@@ -1378,7 +1395,7 @@ vbo_save_SaveFlushVertices(struct gl_context *ctx)
    _save_copy_to_current(ctx);
    _save_reset_vertex(ctx);
    _save_reset_counters(ctx);
-   ctx->Driver.SaveNeedFlush = 0;
+   ctx->Driver.SaveNeedFlush = GL_FALSE;
 }
 
 
@@ -1400,7 +1417,7 @@ vbo_save_NewList(struct gl_context *ctx, GLuint list, GLenum mode)
 
    _save_reset_vertex(ctx);
    _save_reset_counters(ctx);
-   ctx->Driver.SaveNeedFlush = 0;
+   ctx->Driver.SaveNeedFlush = GL_FALSE;
 }