diff options
author | José Fonseca <[email protected]> | 2010-01-03 19:58:54 +0000 |
---|---|---|
committer | José Fonseca <[email protected]> | 2010-01-03 20:00:19 +0000 |
commit | eb5d9e6f70037d4dc12430302f82a116cb1e00ca (patch) | |
tree | b04fb32ec867d975101faeded3a62f266580ab5e /src/mesa/state_tracker | |
parent | f3739bdb60edc051348526d469d5222bb6934917 (diff) |
mesa: Cope with the degenerate case of zero length ranges.
Fixes assertion failures on glean's bufferObject test.
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r-- | src/mesa/state_tracker/st_cb_bufferobjects.c | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 494a3a99c87..0102d8a6f7d 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -103,6 +103,17 @@ st_bufferobj_subdata(GLcontext *ctx, ASSERT(size >= 0); ASSERT(offset + size <= obj->Size); + if (!size) + return; + + /* + * According to ARB_vertex_buffer_object specification, if data is null, + * then the contents of the buffer object's data store is undefined. We just + * ignore, and leave it unchanged. + */ + if (!data) + return; + st_cond_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, offset, size, data); } @@ -125,6 +136,9 @@ st_bufferobj_get_subdata(GLcontext *ctx, ASSERT(size >= 0); ASSERT(offset + size <= obj->Size); + if (!size) + return; + st_cond_flush_pipe_buffer_read(st_context(ctx), st_obj->buffer, offset, size, data); } @@ -223,6 +237,13 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, /** + * Dummy data whose's pointer is used for zero length ranges. + */ +static long +st_bufferobj_zero_length_range = 0; + + +/** * Called via glMapBufferRange(). */ static void * @@ -257,14 +278,26 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, assert(offset < obj->Size); assert(offset + length <= obj->Size); - obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); + /* + * We go out of way here to hide the degenerate yet valid case of zero + * length range from the pipe driver. + */ + if (!length) { + obj->Pointer = &st_bufferobj_zero_length_range; + } + else { + obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); + if (obj->Pointer) { + obj->Pointer = (ubyte *) obj->Pointer + offset; + } + } + if (obj->Pointer) { - obj->Pointer = (ubyte *) obj->Pointer + offset; obj->Offset = offset; obj->Length = length; obj->AccessFlags = access; } - + return obj->Pointer; } @@ -282,6 +315,9 @@ st_bufferobj_flush_mapped_range(GLcontext *ctx, GLenum target, assert(length >= 0); assert(offset + length <= obj->Length); + if (!length) + return; + pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer, obj->Offset + offset, length); } @@ -296,7 +332,9 @@ st_bufferobj_unmap(GLcontext *ctx, GLenum target, struct gl_buffer_object *obj) struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); - pipe_buffer_unmap(pipe->screen, st_obj->buffer); + if(obj->Length) + pipe_buffer_unmap(pipe->screen, st_obj->buffer); + obj->Pointer = NULL; obj->Offset = 0; obj->Length = 0; @@ -319,6 +357,9 @@ st_copy_buffer_subdata(GLcontext *ctx, struct st_buffer_object *dstObj = st_buffer_object(dst); ubyte *srcPtr, *dstPtr; + if(!size) + return; + /* buffer should not already be mapped */ assert(!src->Pointer); assert(!dst->Pointer); |