[Mesa-dev] [PATCH] mesa : move bindbuffer{base, range} from transformfeedback.c
Vincent Lejeune
vljn at ovi.com
Tue Nov 22 03:43:51 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 | 14 ---
src/mapi/glapi/gen/gl_API.xml | 15 +++
src/mesa/main/api_exec.c | 2 +
src/mesa/main/bufferobj.c | 139 +++++++++++++++++++++++++
src/mesa/main/bufferobj.h | 12 ++
src/mesa/main/transformfeedback.c | 115 +--------------------
src/mesa/main/transformfeedback.h | 10 +-
7 files changed, 175 insertions(+), 132 deletions(-)
diff --git a/src/mapi/glapi/gen/EXT_transform_feedback.xml b/src/mapi/glapi/gen/EXT_transform_feedback.xml
index 051f1e0..060c424 100644
--- a/src/mapi/glapi/gen/EXT_transform_feedback.xml
+++ b/src/mapi/glapi/gen/EXT_transform_feedback.xml
@@ -24,14 +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"/>
@@ -39,12 +31,6 @@
<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..1ec0b2e 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -4933,6 +4933,21 @@
<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="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..0bbfa8b 100644
--- a/src/mesa/main/api_exec.c
+++ b/src/mesa/main/api_exec.c
@@ -590,6 +590,8 @@ _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);
#endif
/* ARB 29. GL_ARB_occlusion_query */
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 431eafd..1cc4415 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -703,6 +703,145 @@ _mesa_BindBufferARB(GLenum target, GLuint buffer)
bind_buffer_object(ctx, target, buffer);
}
+/**
+ * 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;
+ _mesa_bind_buffer_range_for_transform_feedback(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:
+ _mesa_bind_buffer_range_for_transform_feedback(ctx, index, bufObj, offset, size);
+ break;
+#endif
+ default: /* should not go there */
+ break;
+ }
+
+ return;
+}
+
/**
* 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..477d04a 100644
--- a/src/mesa/main/transformfeedback.c
+++ b/src/mesa/main/transformfeedback.c
@@ -329,8 +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);
@@ -399,8 +397,8 @@ _mesa_EndTransformFeedback(void)
/**
* Helper used by BindBufferRange() and BindBufferBase().
*/
-static void
-bind_buffer_range(struct gl_context *ctx, GLuint index,
+void
+_mesa_bind_buffer_range_for_transform_feedback(struct gl_context *ctx, GLuint index,
struct gl_buffer_object *bufObj,
GLintptr offset, GLsizeiptr size)
{
@@ -425,113 +423,6 @@ bind_buffer_range(struct gl_context *ctx, GLuint index,
/**
- * 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.
@@ -576,7 +467,7 @@ _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
*/
size = (bufObj->Size - offset) & ~0x3;
- bind_buffer_range(ctx, index, bufObj, offset, size);
+ _mesa_bind_buffer_range_for_transform_feedback(ctx, index, bufObj, offset, size);
}
diff --git a/src/mesa/main/transformfeedback.h b/src/mesa/main/transformfeedback.h
index 9447eff..c7c43fd 100644
--- a/src/mesa/main/transformfeedback.h
+++ b/src/mesa/main/transformfeedback.h
@@ -63,12 +63,10 @@ _mesa_BeginTransformFeedback(GLenum mode);
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
+_mesa_bind_buffer_range_for_transform_feedback(struct gl_context *ctx, GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size);
extern void GLAPIENTRY
_mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
--
1.7.7.3
More information about the mesa-dev
mailing list