[Mesa-dev] [PATCH 1/7] vbo: pull some code from api_noop.c into vbo module

Brian Paul brianp at vmware.com
Thu Nov 10 09:45:14 PST 2011


Only a handful of functions from api_noop.c are actually used by
the VBO module.  Move them to the VBO module.  With this change,
none of the code in api_noop.c is actually used anymore.
---
 src/mesa/vbo/vbo_exec_api.c |  142 +++++++++++++++++++++++++++++++++++++++++--
 src/mesa/vbo/vbo_save_api.c |   82 +++++++++++++++++++++---
 2 files changed, 208 insertions(+), 16 deletions(-)

diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c
index 5f3ed9d..9e8ae7d 100644
--- a/src/mesa/vbo/vbo_exec_api.c
+++ b/src/mesa/vbo/vbo_exec_api.c
@@ -41,7 +41,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/state.h"
 #include "main/light.h"
 #include "main/api_arrayelt.h"
-#include "main/api_noop.h"
 #include "main/api_validate.h"
 #include "main/dispatch.h"
 
@@ -546,13 +545,146 @@ static void GLAPIENTRY vbo_exec_EvalPoint2( GLint i, GLint j )
    vbo_exec_EvalCoord2f( u, v );
 }
 
-/* use noop eval mesh */
-#define vbo_exec_EvalMesh1 _mesa_noop_EvalMesh1
-#define vbo_exec_EvalMesh2 _mesa_noop_EvalMesh2
+
+static void GLAPIENTRY
+vbo_exec_EvalMesh1(GLenum mode, GLint i1, GLint i2)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   GLint i;
+   GLfloat u, du;
+   GLenum prim;
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   switch (mode) {
+   case GL_POINT:
+      prim = GL_POINTS;
+      break;
+   case GL_LINE:
+      prim = GL_LINE_STRIP;
+      break;
+   default:
+      _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh1(mode)" );
+      return;
+   }
+
+   /* No effect if vertex maps disabled.
+    */
+   if (!ctx->Eval.Map1Vertex4 && 
+       !ctx->Eval.Map1Vertex3 &&
+       !(ctx->VertexProgram._Enabled && ctx->Eval.Map1Attrib[VERT_ATTRIB_POS]))
+      return;
+
+   du = ctx->Eval.MapGrid1du;
+   u = ctx->Eval.MapGrid1u1 + i1 * du;
+
+   CALL_Begin(GET_DISPATCH(), (prim));
+   for (i=i1;i<=i2;i++,u+=du) {
+      CALL_EvalCoord1f(GET_DISPATCH(), (u));
+   }
+   CALL_End(GET_DISPATCH(), ());
+}
+
+
+static void GLAPIENTRY
+vbo_exec_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   GLfloat u, du, v, dv, v1, u1;
+   GLint i, j;
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   switch (mode) {
+   case GL_POINT:
+   case GL_LINE:
+   case GL_FILL:
+      break;
+   default:
+      _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh2(mode)" );
+      return;
+   }
+
+   /* No effect if vertex maps disabled.
+    */
+   if (!ctx->Eval.Map2Vertex4 && 
+       !ctx->Eval.Map2Vertex3 &&
+       !(ctx->VertexProgram._Enabled && ctx->Eval.Map2Attrib[VERT_ATTRIB_POS]))
+      return;
+
+   du = ctx->Eval.MapGrid2du;
+   dv = ctx->Eval.MapGrid2dv;
+   v1 = ctx->Eval.MapGrid2v1 + j1 * dv;
+   u1 = ctx->Eval.MapGrid2u1 + i1 * du;
+
+   switch (mode) {
+   case GL_POINT:
+      CALL_Begin(GET_DISPATCH(), (GL_POINTS));
+      for (v=v1,j=j1;j<=j2;j++,v+=dv) {
+	 for (u=u1,i=i1;i<=i2;i++,u+=du) {
+	    CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
+	 }
+      }
+      CALL_End(GET_DISPATCH(), ());
+      break;
+   case GL_LINE:
+      for (v=v1,j=j1;j<=j2;j++,v+=dv) {
+	 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP));
+	 for (u=u1,i=i1;i<=i2;i++,u+=du) {
+	    CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
+	 }
+	 CALL_End(GET_DISPATCH(), ());
+      }
+      for (u=u1,i=i1;i<=i2;i++,u+=du) {
+	 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP));
+	 for (v=v1,j=j1;j<=j2;j++,v+=dv) {
+	    CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
+	 }
+	 CALL_End(GET_DISPATCH(), ());
+      }
+      break;
+   case GL_FILL:
+      for (v=v1,j=j1;j<j2;j++,v+=dv) {
+	 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP));
+	 for (u=u1,i=i1;i<=i2;i++,u+=du) {
+	    CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
+	    CALL_EvalCoord2f(GET_DISPATCH(), (u, v+dv));
+	 }
+	 CALL_End(GET_DISPATCH(), ());
+      }
+      break;
+   default:
+      _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh2(mode)" );
+      return;
+   }
+}
 
 #endif /* FEATURE_evaluators */
 
 
+/**
+ * Execute a glRectf() function.  This is not suitable for GL_COMPILE
+ * modes (as the test for outside begin/end is not compiled),
+ * but may be useful for drivers in circumstances which exclude
+ * display list interactions.
+ *
+ * (None of the functions in this file are suitable for GL_COMPILE
+ * modes).
+ */
+static void GLAPIENTRY
+vbo_exec_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   CALL_Begin(GET_DISPATCH(), (GL_QUADS));
+   CALL_Vertex2f(GET_DISPATCH(), (x1, y1));
+   CALL_Vertex2f(GET_DISPATCH(), (x2, y1));
+   CALL_Vertex2f(GET_DISPATCH(), (x2, y2));
+   CALL_Vertex2f(GET_DISPATCH(), (x1, y2));
+   CALL_End(GET_DISPATCH(), ());
+}
+
 
 /**
  * Called via glBegin.
@@ -673,7 +805,7 @@ static void vbo_exec_vtxfmt_init( struct vbo_exec_context *exec )
    _MESA_INIT_DLIST_VTXFMT(vfmt, _mesa_);
    _MESA_INIT_EVAL_VTXFMT(vfmt, vbo_exec_);
 
-   vfmt->Rectf = _mesa_noop_Rectf;
+   vfmt->Rectf = vbo_exec_Rectf;
 
    /* from attrib_tmp.h:
     */
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 87a52e8..eba64b3 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -75,7 +75,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/eval.h"
 #include "main/macros.h"
 #include "main/mfeatures.h"
-#include "main/api_noop.h"
 #include "main/api_validate.h"
 #include "main/api_arrayelt.h"
 #include "main/vtxfmt.h"
@@ -933,6 +932,37 @@ _save_DrawArrays(GLenum mode, GLint start, GLsizei count)
 
 
 static void GLAPIENTRY
+_save_MultiDrawElements(GLenum mode, const GLsizei *count, GLenum type,
+                        const GLvoid **indices, GLsizei primcount)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   (void) mode;
+   (void) count;
+   (void) type;
+   (void) indices;
+   (void) primcount;
+   _mesa_compile_error(ctx, GL_INVALID_OPERATION, "glMultiDrawElements");
+}
+
+
+static void GLAPIENTRY
+_save_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei *count,
+                                  GLenum type, const GLvoid **indices,
+                                  GLsizei primcount, const GLint *basevertex)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   (void) mode;
+   (void) count;
+   (void) type;
+   (void) indices;
+   (void) primcount;
+   (void) basevertex;
+   _mesa_compile_error(ctx, GL_INVALID_OPERATION,
+                       "glMultiDrawElementsBaseVertex");
+}
+
+
+static void GLAPIENTRY
 _save_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -993,6 +1023,7 @@ _save_PrimitiveRestartNV(void)
 /* Unlike the functions above, these are to be hooked into the vtxfmt
  * maintained in ctx->ListState, active when the list is known or
  * suspected to be outside any begin/end primitive.
+ * Note: OBE = Outside Begin/End
  */
 static void GLAPIENTRY
 _save_OBE_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
@@ -1088,6 +1119,39 @@ _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)
+{
+   GLsizei i;
+
+   for (i = 0; i < primcount; i++) {
+      if (count[i] > 0) {
+	 CALL_DrawElements(GET_DISPATCH(), (mode, count[i], type, indices[i]));
+      }
+   }
+}
+
+
+static void GLAPIENTRY
+_save_OBE_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei *count,
+                                      GLenum type,
+                                      const GLvoid **indices,
+                                      GLsizei primcount,
+                                      const GLint *basevertex)
+{
+   GLsizei i;
+
+   for (i = 0; i < primcount; i++) {
+      if (count[i] > 0) {
+	 CALL_DrawElementsBaseVertex(GET_DISPATCH(), (mode, count[i], type,
+						      indices[i],
+						      basevertex[i]));
+      }
+   }
+}
+
+
 static void
 _save_vtxfmt_init(struct gl_context *ctx)
 {
@@ -1223,8 +1287,8 @@ _save_vtxfmt_init(struct gl_context *ctx)
 
    _MESA_INIT_EVAL_VTXFMT(vfmt, _save_);
 
-   /* These are all errors as we at least know we are in some sort of
-    * begin/end pair:
+   /* These calls all generate GL_INVALID_OPERATION since this vtxfmt is
+    * only used when we're inside a glBegin/End pair.
     */
    vfmt->Begin = _save_Begin;
    vfmt->Rectf = _save_Rectf;
@@ -1233,9 +1297,8 @@ _save_vtxfmt_init(struct gl_context *ctx)
    vfmt->DrawRangeElements = _save_DrawRangeElements;
    vfmt->DrawElementsBaseVertex = _save_DrawElementsBaseVertex;
    vfmt->DrawRangeElementsBaseVertex = _save_DrawRangeElementsBaseVertex;
-   /* Loops back into vfmt->DrawElements */
-   vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements;
-   vfmt->MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex;
+   vfmt->MultiDrawElementsEXT = _save_MultiDrawElements;
+   vfmt->MultiDrawElementsBaseVertex = _save_MultiDrawElementsBaseVertex;
 }
 
 
@@ -1436,11 +1499,8 @@ vbo_save_api_init(struct vbo_save_context *save)
    ctx->ListState.ListVtxfmt.DrawArrays = _save_OBE_DrawArrays;
    ctx->ListState.ListVtxfmt.DrawElements = _save_OBE_DrawElements;
    ctx->ListState.ListVtxfmt.DrawRangeElements = _save_OBE_DrawRangeElements;
-   /* loops back into _save_OBE_DrawElements */
-   ctx->ListState.ListVtxfmt.MultiDrawElementsEXT =
-      _mesa_noop_MultiDrawElements;
-   ctx->ListState.ListVtxfmt.MultiDrawElementsBaseVertex =
-      _mesa_noop_MultiDrawElementsBaseVertex;
+   ctx->ListState.ListVtxfmt.MultiDrawElementsEXT = _save_OBE_MultiDrawElements;
+   ctx->ListState.ListVtxfmt.MultiDrawElementsBaseVertex = _save_OBE_MultiDrawElementsBaseVertex;
    _mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt);
 }
 
-- 
1.7.3.4



More information about the mesa-dev mailing list