From 97ae4dad1cc24c5e969e6b99f07ece68e239964b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 26 Nov 2010 13:42:23 -0700 Subject: [PATCH] st/mesa: fix mapping of zero-sized buffer objects Fixes http://bugs.freedesktop.org/show_bug.cgi?id=31934 --- src/mesa/state_tracker/st_cb_bufferobjects.c | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 27540c36ce7..73c9c2de7a1 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -210,6 +210,13 @@ st_bufferobj_data(struct gl_context *ctx, } +/** + * Dummy data whose's pointer is used for zero size buffers or ranges. + */ +static long st_bufferobj_zero_length = 0; + + + /** * Called via glMapBufferARB(). */ @@ -233,10 +240,16 @@ st_bufferobj_map(struct gl_context *ctx, GLenum target, GLenum access, break; } - obj->Pointer = pipe_buffer_map(st_context(ctx)->pipe, - st_obj->buffer, - flags, - &st_obj->transfer); + /* Handle zero-size buffers here rather than in drivers */ + if (obj->Size == 0) { + obj->Pointer = &st_bufferobj_zero_length; + } + else { + obj->Pointer = pipe_buffer_map(st_context(ctx)->pipe, + st_obj->buffer, + flags, + &st_obj->transfer); + } if (obj->Pointer) { obj->Offset = 0; @@ -246,13 +259,6 @@ st_bufferobj_map(struct gl_context *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(). */ @@ -293,7 +299,7 @@ st_bufferobj_map_range(struct gl_context *ctx, GLenum target, * length range from the pipe driver. */ if (!length) { - obj->Pointer = &st_bufferobj_zero_length_range; + obj->Pointer = &st_bufferobj_zero_length; } else { obj->Pointer = pipe_buffer_map_range(pipe, -- 2.30.2