Mesa (master): mesa: Add a helper function for determining the restart index.

Kenneth Graunke kwg at kemper.freedesktop.org
Wed May 29 21:20:55 UTC 2013


Module: Mesa
Branch: master
Commit: 959d076b30fce8aa9f09c68e5fe885e98c55aaa5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=959d076b30fce8aa9f09c68e5fe885e98c55aaa5

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed May 29 08:07:01 2013 -0700

mesa: Add a helper function for determining the restart index.

The derived state approach currently used (_RestartIndex) doesn't work:
in the GL_PRIMITIVE_RESTART_FIXED_INDEX case, the restart index depends
on the index buffer's data type, and that isn't known until draw time.

The existing code also fails to obey the GL 4.3 rules which say that
FIXED_INDEX takes precedence over normal primitive restart.

This helper function correctly determines the restart index, and will
replace the derived state.

NOTE: This is a candidate for the 9.1 branch.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/mesa/main/varray.c |   24 ++++++++++++++++++++++++
 src/mesa/main/varray.h |    2 ++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index abdaf96..dff0070 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -1149,6 +1149,30 @@ _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
 }
 
 
+unsigned
+_mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
+{
+   /* From the OpenGL 4.3 core specification, page 302:
+    * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
+    *  enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
+    *  is used."
+    */
+   if (ctx->Array.PrimitiveRestartFixedIndex) {
+      switch (ib_type) {
+      case GL_UNSIGNED_BYTE:
+         return 0xff;
+      case GL_UNSIGNED_SHORT:
+         return 0xffff;
+      case GL_UNSIGNED_INT:
+         return 0xffffffff;
+      default:
+         assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
+      }
+   }
+
+   return ctx->Array.RestartIndex;
+}
+
 
 /**
  * Copy one client vertex array to another.
diff --git a/src/mesa/main/varray.h b/src/mesa/main/varray.h
index b3d5a6a..a178bc1 100644
--- a/src/mesa/main/varray.h
+++ b/src/mesa/main/varray.h
@@ -248,6 +248,8 @@ _mesa_PrimitiveRestartIndex(GLuint index);
 extern void GLAPIENTRY
 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor);
 
+extern unsigned
+_mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type);
 
 extern void
 _mesa_copy_client_array(struct gl_context *ctx,




More information about the mesa-commit mailing list