[Mesa-dev] [PATCH] mesa : move bindbuffer{base, range} from transformfeedback.c

vlj vljn at ovi.com
Sat Nov 19 13:31:37 PST 2011


   BindBuffer* functions are part of tfb extension. They are however
   used by others extensions such as uniform buffer object.
   This patch moves the BindBuffer* definition to to bufferobj.c
   where it acts as a dispatcher calling original tfb function ;
   BindBuffer* functions can be used by others extensions, even if
   FEATURE_EXT_transform_feedback is not defined.
---
 src/mapi/glapi/gen/EXT_transform_feedback.xml |   21 ---
 src/mapi/glapi/gen/gl_API.xml                 |   21 +++
 src/mesa/main/api_exec.c                      |    3 +
 src/mesa/main/bufferobj.c                     |  215 +++++++++++++++++++++++++
 src/mesa/main/bufferobj.h                     |   12 ++
 src/mesa/main/transformfeedback.c             |  188 ---------------------
 src/mesa/main/transformfeedback.h             |   11 --
 7 files changed, 251 insertions(+), 220 deletions(-)

diff --git a/src/mapi/glapi/gen/EXT_transform_feedback.xml b/src/mapi/glapi/gen/EXT_transform_feedback.xml
index 051f1e0..ea902f3 100644
--- a/src/mapi/glapi/gen/EXT_transform_feedback.xml
+++ b/src/mapi/glapi/gen/EXT_transform_feedback.xml
@@ -24,27 +24,6 @@
   <enum name="TRANSFORM_FEEDBACK_BUFFER_MODE_EXT"             value="0x8C7F"/>
   <enum name="TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT"      value="0x8C76"/>
 
-  <function name="BindBufferRangeEXT" offset="assign">
-    <param name="target" type="GLenum"/>
-    <param name="index" type="GLuint"/>
-    <param name="buffer" type="GLuint"/>
-    <param name="offset" type="GLintptr"/>
-    <param name="size" type="GLsizeiptr"/>
-  </function>
-
-  <function name="BindBufferOffsetEXT" offset="assign">
-    <param name="target" type="GLenum"/>
-    <param name="index" type="GLuint"/>
-    <param name="buffer" type="GLuint"/>
-    <param name="offset" type="GLintptr"/>
-  </function>
-
-  <function name="BindBufferBaseEXT" offset="assign">
-    <param name="target" type="GLenum"/>
-    <param name="index" type="GLuint"/>
-    <param name="buffer" type="GLuint"/>
-  </function>
-
   <function name="BeginTransformFeedbackEXT" offset="assign">
     <param name="mode" type="GLenum"/>
   </function>
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index a9be003..d6c926d 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -4933,6 +4933,27 @@
         <param name="buffer" type="GLuint"/>
     </function>
 
+    <function name="BindBufferRangeEXT" offset="assign">
+        <param name="target" type="GLenum"/>
+        <param name="index" type="GLuint"/>
+        <param name="buffer" type="GLuint"/>
+        <param name="offset" type="GLintptr"/>
+        <param name="size" type="GLsizeiptr"/>
+    </function>
+
+    <function name="BindBufferOffsetEXT" offset="assign">
+        <param name="target" type="GLenum"/>
+        <param name="index" type="GLuint"/>
+        <param name="buffer" type="GLuint"/>
+        <param name="offset" type="GLintptr"/>
+    </function>
+
+    <function name="BindBufferBaseEXT" offset="assign">
+        <param name="target" type="GLenum"/>
+        <param name="index" type="GLuint"/>
+        <param name="buffer" type="GLuint"/>
+    </function>
+
     <function name="BufferData" alias="BufferDataARB">
         <param name="target" type="GLenum"/>
         <param name="size" type="GLsizeiptr"/>
diff --git a/src/mesa/main/api_exec.c b/src/mesa/main/api_exec.c
index 93214dd..023d83f 100644
--- a/src/mesa/main/api_exec.c
+++ b/src/mesa/main/api_exec.c
@@ -590,6 +590,9 @@ _mesa_create_exec_table(void)
    SET_IsBufferARB(exec, _mesa_IsBufferARB);
    SET_MapBufferARB(exec, _mesa_MapBufferARB);
    SET_UnmapBufferARB(exec, _mesa_UnmapBufferARB);
+   SET_BindBufferRangeEXT(exec, _mesa_BindBufferRange);
+   SET_BindBufferBaseEXT(exec, _mesa_BindBufferBase);
+   SET_BindBufferOffsetEXT(exec, _mesa_BindBufferOffsetEXT);
 #endif
 
    /* ARB 29. GL_ARB_occlusion_query */
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 431eafd..d584bac 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -703,6 +703,221 @@ _mesa_BindBufferARB(GLenum target, GLuint buffer)
    bind_buffer_object(ctx, target, buffer);
 }
 
+/**
+ * Helper used by BindBufferRange() and BindBufferBase() for
+ * TFB operations.
+ */
+static void
+bind_buffer_range_tfb(struct gl_context *ctx, GLuint index,
+                  struct gl_buffer_object *bufObj,
+                  GLintptr offset, GLsizeiptr size)
+{
+   struct gl_transform_feedback_object *obj =
+      ctx->TransformFeedback.CurrentObject;
+
+   /* The general binding point */
+   _mesa_reference_buffer_object(ctx,
+                                 &ctx->TransformFeedback.CurrentBuffer,
+                                 bufObj);
+
+   /* The per-attribute binding point */
+   _mesa_reference_buffer_object(ctx,
+                                 &obj->Buffers[index],
+                                 bufObj);
+
+   obj->BufferNames[index] = bufObj->Name;
+
+   obj->Offset[index] = offset;
+   obj->Size[index] = size;
+}
+
+/**
+ * Several extensions declare a BindBufferBase API function,
+ * this one dispatchs call according to target.
+ * TRANSFORM_FEEDBACK:
+ *    Specify a buffer object to receive vertex shader results.
+ *    As in BindBufferRange, but start at offset = 0.
+ */
+void GLAPIENTRY
+_mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
+{
+   struct gl_buffer_object *bufObj;
+   GLsizeiptr size;
+
+   GET_CURRENT_CONTEXT(ctx);
+   switch (target) {
+#if FEATURE_EXT_transform_feedback
+      case GL_TRANSFORM_FEEDBACK_BUFFER:
+         { /* GCC does not like declaration after a label, add a dummy block */}
+         struct gl_transform_feedback_object *obj;
+         obj = ctx->TransformFeedback.CurrentObject;
+
+         if (obj->Active) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glBindBufferBase(transform feedback active)");
+            return;
+         }
+
+         if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs) {
+            _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
+            return;
+         }
+
+         break;
+#endif
+      default:
+         _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferBase(target)");
+         break;
+   }
+
+   bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+   if (!bufObj) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glBindBufferBase(invalid buffer=%u)", buffer);
+      return;
+   }
+
+   switch (target) {
+#if FEATURE_EXT_transform_feedback
+      case GL_TRANSFORM_FEEDBACK_BUFFER:
+         /* default size is the buffer size rounded down to nearest
+          * multiple of four.
+          */
+         size = bufObj->Size & ~0x3;
+         bind_buffer_range_tfb(ctx, index, bufObj, 0, size);
+         break;
+#endif
+      default: /* should not go here */
+         break;
+   }
+
+   return;
+}
+
+/**
+ * Several extensions declare a BindBufferRange API function,
+ * this one dispatchs call according to target.
+ * TRANSFORM_FEEDBACK:
+ *    Specify a buffer object to receive vertex shader results.  Plus,
+ *    specify the starting offset to place the results, and max size.
+ */
+void GLAPIENTRY
+_mesa_BindBufferRange(GLenum target, GLuint index,
+                      GLuint buffer, GLintptr offset, GLsizeiptr size)
+{
+   struct gl_buffer_object *bufObj;
+
+   GET_CURRENT_CONTEXT(ctx);
+   switch (target) {
+#if FEATURE_EXT_transform_feedback
+      case GL_TRANSFORM_FEEDBACK_BUFFER:
+         { /* GCC does not like declaration after a label, add a dummy block */}
+         struct gl_transform_feedback_object *obj;
+         obj = ctx->TransformFeedback.CurrentObject;
+
+         if (obj->Active) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glBindBufferRange(transform feedback active)");
+            return;
+         }
+
+         if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs) {
+            _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(index=%d)", index);
+            return;
+         }
+
+         if ((size <= 0) || (size & 0x3)) {
+            /* must be positive and multiple of four */
+            _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size%d)", (int) size);
+            return;
+         }
+
+         if (offset & 0x3) {
+            /* must be multiple of four */
+            _mesa_error(ctx, GL_INVALID_VALUE,
+                        "glBindBufferRange(offset=%d)", (int) offset);
+            return;
+         }
+#endif
+      default:
+         _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferRange(target)");
+   }
+
+   bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+   if (!bufObj) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glBindBufferRange(invalid buffer=%u)", buffer);
+      return;
+   }
+
+   if (offset + size >= bufObj->Size) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                  "glBindBufferRange(offset + size %d > buffer size %d)",
+              (int) (offset + size), (int) (bufObj->Size));
+      return;
+   }
+
+   switch (target) {
+#if FEATURE_EXT_transform_feedback
+      case GL_TRANSFORM_FEEDBACK_BUFFER:
+         bind_buffer_range_tfb(ctx, index, bufObj, offset, size);
+         break;
+#endif
+      default: /* should not go there */
+         break;
+   }
+
+   return;
+}
+
+/**
+ * Specify a buffer object to receive vertex shader results, plus the
+ * offset in the buffer to start placing results.
+ * This function is part of GL_EXT_transform_feedback, but not GL3.
+ */
+void GLAPIENTRY
+_mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
+                          GLintptr offset)
+{
+   struct gl_transform_feedback_object *obj;
+   struct gl_buffer_object *bufObj;
+   GET_CURRENT_CONTEXT(ctx);
+   GLsizeiptr size;
+
+   if (target != GL_TRANSFORM_FEEDBACK_BUFFER) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferOffsetEXT(target)");
+      return;
+   }
+
+   obj = ctx->TransformFeedback.CurrentObject;
+
+   if (obj->Active) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glBindBufferOffsetEXT(transform feedback active)");
+      return;
+   }
+
+   if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                  "glBindBufferOffsetEXT(index=%d)", index);
+      return;
+   }
+
+   bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+   if (!bufObj) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glBindBufferOffsetEXT(invalid buffer=%u)", buffer);
+      return;
+   }
+
+   /* default size is the buffer size rounded down to nearest
+    * multiple of four.
+    */
+   size = (bufObj->Size - offset) & ~0x3;
+
+   bind_buffer_range_tfb(ctx, index, bufObj, offset, size);
+}
+
 
 /**
  * Delete a set of buffer objects.
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
index b4e70f2..c623655 100644
--- a/src/mesa/main/bufferobj.h
+++ b/src/mesa/main/bufferobj.h
@@ -154,6 +154,18 @@ _mesa_ObjectUnpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option);
 
 extern void GLAPIENTRY
 _mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum pname, GLint* params);
+
+extern void GLAPIENTRY
+_mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer);
+
+extern void GLAPIENTRY
+_mesa_BindBufferRange(GLenum target, GLuint index,
+                      GLuint buffer, GLintptr offset, GLsizeiptr size);
+
+extern void GLAPIENTRY
+_mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
+                          GLintptr offset);
+
 #endif
 
 #endif
diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c
index 47efad1..1eecc1d 100644
--- a/src/mesa/main/transformfeedback.c
+++ b/src/mesa/main/transformfeedback.c
@@ -329,9 +329,6 @@ _mesa_init_transform_feedback_dispatch(struct _glapi_table *disp)
 {
    SET_BeginTransformFeedbackEXT(disp, _mesa_BeginTransformFeedback);
    SET_EndTransformFeedbackEXT(disp, _mesa_EndTransformFeedback);
-   SET_BindBufferRangeEXT(disp, _mesa_BindBufferRange);
-   SET_BindBufferBaseEXT(disp, _mesa_BindBufferBase);
-   SET_BindBufferOffsetEXT(disp, _mesa_BindBufferOffsetEXT);
    SET_TransformFeedbackVaryingsEXT(disp, _mesa_TransformFeedbackVaryings);
    SET_GetTransformFeedbackVaryingEXT(disp, _mesa_GetTransformFeedbackVarying);
 }
@@ -395,191 +392,6 @@ _mesa_EndTransformFeedback(void)
    ctx->Driver.EndTransformFeedback(ctx, obj);
 }
 
-
-/**
- * Helper used by BindBufferRange() and BindBufferBase().
- */
-static void
-bind_buffer_range(struct gl_context *ctx, GLuint index,
-                  struct gl_buffer_object *bufObj,
-                  GLintptr offset, GLsizeiptr size)
-{
-   struct gl_transform_feedback_object *obj =
-      ctx->TransformFeedback.CurrentObject;
-
-   /* The general binding point */
-   _mesa_reference_buffer_object(ctx,
-                                 &ctx->TransformFeedback.CurrentBuffer,
-                                 bufObj);
-
-   /* The per-attribute binding point */
-   _mesa_reference_buffer_object(ctx,
-                                 &obj->Buffers[index],
-                                 bufObj);
-
-   obj->BufferNames[index] = bufObj->Name;
-
-   obj->Offset[index] = offset;
-   obj->Size[index] = size;
-}
-
-
-/**
- * Specify a buffer object to receive vertex shader results.  Plus,
- * specify the starting offset to place the results, and max size.
- */
-void GLAPIENTRY
-_mesa_BindBufferRange(GLenum target, GLuint index,
-                      GLuint buffer, GLintptr offset, GLsizeiptr size)
-{
-   struct gl_transform_feedback_object *obj;
-   struct gl_buffer_object *bufObj;
-   GET_CURRENT_CONTEXT(ctx);
-
-   if (target != GL_TRANSFORM_FEEDBACK_BUFFER) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferRange(target)");
-      return;
-   }
-
-   obj = ctx->TransformFeedback.CurrentObject;
-
-   if (obj->Active) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindBufferRange(transform feedback active)");
-      return;
-   }
-
-   if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(index=%d)", index);
-      return;
-   }
-
-   if ((size <= 0) || (size & 0x3)) {
-      /* must be positive and multiple of four */
-      _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size%d)", (int) size);
-      return;
-   }  
-
-   if (offset & 0x3) {
-      /* must be multiple of four */
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glBindBufferRange(offset=%d)", (int) offset);
-      return;
-   }  
-
-   bufObj = _mesa_lookup_bufferobj(ctx, buffer);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindBufferRange(invalid buffer=%u)", buffer);
-      return;
-   }
-
-   if (offset + size >= bufObj->Size) {
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glBindBufferRange(offset + size %d > buffer size %d)",
-		  (int) (offset + size), (int) (bufObj->Size));
-      return;
-   }  
-
-   bind_buffer_range(ctx, index, bufObj, offset, size);
-}
-
-
-/**
- * Specify a buffer object to receive vertex shader results.
- * As above, but start at offset = 0.
- */
-void GLAPIENTRY
-_mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
-{
-   struct gl_transform_feedback_object *obj;
-   struct gl_buffer_object *bufObj;
-   GLsizeiptr size;
-   GET_CURRENT_CONTEXT(ctx);
-
-   if (target != GL_TRANSFORM_FEEDBACK_BUFFER) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferBase(target)");
-      return;
-   }
-
-   obj = ctx->TransformFeedback.CurrentObject;
-
-   if (obj->Active) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindBufferBase(transform feedback active)");
-      return;
-   }
-
-   if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
-      return;
-   }
-
-   bufObj = _mesa_lookup_bufferobj(ctx, buffer);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindBufferBase(invalid buffer=%u)", buffer);
-      return;
-   }
-
-   /* default size is the buffer size rounded down to nearest
-    * multiple of four.
-    */
-   size = bufObj->Size & ~0x3;
-
-   bind_buffer_range(ctx, index, bufObj, 0, size);
-}
-
-
-/**
- * Specify a buffer object to receive vertex shader results, plus the
- * offset in the buffer to start placing results.
- * This function is part of GL_EXT_transform_feedback, but not GL3.
- */
-void GLAPIENTRY
-_mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
-                          GLintptr offset)
-{
-   struct gl_transform_feedback_object *obj;
-   struct gl_buffer_object *bufObj;
-   GET_CURRENT_CONTEXT(ctx);
-   GLsizeiptr size;
-
-   if (target != GL_TRANSFORM_FEEDBACK_BUFFER) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferOffsetEXT(target)");
-      return;
-   }
-
-   obj = ctx->TransformFeedback.CurrentObject;
-
-   if (obj->Active) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindBufferOffsetEXT(transform feedback active)");
-      return;
-   }
-
-   if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs) {
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glBindBufferOffsetEXT(index=%d)", index);
-      return;
-   }
-
-   bufObj = _mesa_lookup_bufferobj(ctx, buffer);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindBufferOffsetEXT(invalid buffer=%u)", buffer);
-      return;
-   }
-
-   /* default size is the buffer size rounded down to nearest
-    * multiple of four.
-    */
-   size = (bufObj->Size - offset) & ~0x3;
-
-   bind_buffer_range(ctx, index, bufObj, offset, size);
-}
-
-
 /**
  * This function specifies the vertex shader outputs to be written
  * to the feedback buffer(s), and in what order.
diff --git a/src/mesa/main/transformfeedback.h b/src/mesa/main/transformfeedback.h
index 9447eff..b05f659 100644
--- a/src/mesa/main/transformfeedback.h
+++ b/src/mesa/main/transformfeedback.h
@@ -64,17 +64,6 @@ extern void GLAPIENTRY
 _mesa_EndTransformFeedback(void);
 
 extern void GLAPIENTRY
-_mesa_BindBufferRange(GLenum target, GLuint index,
-                      GLuint buffer, GLintptr offset, GLsizeiptr size);
-
-extern void GLAPIENTRY
-_mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer);
-
-extern void GLAPIENTRY
-_mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
-                          GLintptr offset);
-
-extern void GLAPIENTRY
 _mesa_TransformFeedbackVaryings(GLuint program, GLsizei count,
                                 const GLchar **varyings, GLenum bufferMode);
 
-- 
1.7.7



More information about the mesa-dev mailing list