summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/bufferobj.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-08-31 08:50:15 -0600
committerBrian Paul <[email protected]>2009-08-31 08:50:15 -0600
commit92033a9516942d7272ce4bf36ecd422009bbaf60 (patch)
tree4db20f17fa58ed4aa2e7751e7f6f20566fbe00fc /src/mesa/main/bufferobj.c
parentc69a4dce75d5282fc88f76da5ac0d27e65012727 (diff)
mesa: new assertions, comments about buffer mapping
Since ctx->Driver.MapBuffer() and ctx->Driver.MapBufferRange() may be called from other places in Mesa (such as VBO) it's important that the driver callbacks set all the buffer object fields properly (Pointer, Offset, Length, etc). Add assertions to make sure that the driver does that.
Diffstat (limited to 'src/mesa/main/bufferobj.c')
-rw-r--r--src/mesa/main/bufferobj.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index f96185a4b5d..715a6e650b2 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1165,6 +1165,8 @@ _mesa_MapBufferARB(GLenum target, GLenum access)
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object * bufObj;
GLbitfield accessFlags;
+ void *map;
+
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
switch (access) {
@@ -1197,14 +1199,21 @@ _mesa_MapBufferARB(GLenum target, GLenum access)
}
ASSERT(ctx->Driver.MapBuffer);
- bufObj->Pointer = ctx->Driver.MapBuffer( ctx, target, access, bufObj );
- if (!_mesa_bufferobj_mapped(bufObj)) {
+ map = ctx->Driver.MapBuffer( ctx, target, access, bufObj );
+ if (!map) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(access)");
}
- bufObj->AccessFlags = accessFlags;
- bufObj->Offset = 0;
- bufObj->Length = bufObj->Size;
+ if (map) {
+ /* The driver callback should have set these fields.
+ * This is important because other modules (like VBO) might call
+ * the driver function directly.
+ */
+ ASSERT(bufObj->Pointer == map);
+ ASSERT(bufObj->Length == bufObj->Size);
+ ASSERT(bufObj->Offset == 0);
+ bufObj->AccessFlags = accessFlags;
+ }
if (access == GL_WRITE_ONLY_ARB || access == GL_READ_WRITE_ARB)
bufObj->Written = GL_TRUE;
@@ -1455,6 +1464,8 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
+ void *map;
+
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
if (!ctx->Extensions.ARB_map_buffer_range) {
@@ -1518,14 +1529,20 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
}
ASSERT(ctx->Driver.MapBufferRange);
- bufObj->Pointer = ctx->Driver.MapBufferRange(ctx, target, offset, length,
- access, bufObj);
-
- bufObj->Offset = offset;
- bufObj->Length = length;
- bufObj->AccessFlags = access;
+ map = ctx->Driver.MapBufferRange(ctx, target, offset, length,
+ access, bufObj);
+ if (map) {
+ /* The driver callback should have set all these fields.
+ * This is important because other modules (like VBO) might call
+ * the driver function directly.
+ */
+ ASSERT(bufObj->Pointer == map);
+ ASSERT(bufObj->Length == length);
+ ASSERT(bufObj->Offset == offset);
+ ASSERT(bufObj->AccessFlags == access);
+ }
- return bufObj->Pointer;
+ return map;
}