From 5572de8e7e71a15cefe6425b3e082c721052ef1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 30 Aug 2011 19:10:06 +0200 Subject: [PATCH] mesa: handle zero-size buffers in MapBuffer and ranges in MapBufferRange (v3) Reviewed-by: Brian Paul --- src/mesa/main/bufferobj.c | 24 ++++++++++++++- src/mesa/state_tracker/st_cb_bufferobjects.c | 32 +++++--------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index c453f9c8554..a303401748c 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -1004,6 +1004,12 @@ _mesa_MapBufferARB(GLenum target, GLenum access) return NULL; } + if (!bufObj->Size) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, + "glMapBuffer(buffer size = 0)"); + return NULL; + } + ASSERT(ctx->Driver.MapBufferRange); map = ctx->Driver.MapBufferRange(ctx, 0, bufObj->Size, accessFlags, bufObj); if (!map) { @@ -1410,7 +1416,23 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, "glMapBufferRange(buffer already mapped)"); return NULL; } - + + if (!bufObj->Size) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, + "glMapBufferRange(buffer size = 0)"); + return NULL; + } + + /* Mapping zero bytes should return a non-null pointer. */ + if (!length) { + static long dummy = 0; + bufObj->Pointer = &dummy; + bufObj->Length = length; + bufObj->Offset = offset; + bufObj->AccessFlags = access; + return bufObj->Pointer; + } + ASSERT(ctx->Driver.MapBufferRange); map = ctx->Driver.MapBufferRange(ctx, offset, length, access, bufObj); if (!map) { diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index a451b44049e..aab7444e201 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -228,13 +228,6 @@ 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 glMapBufferRange(). */ @@ -280,24 +273,15 @@ st_bufferobj_map_range(struct gl_context *ctx, assert(offset < obj->Size); assert(offset + length <= obj->Size); - /* - * 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; - } - else { - obj->Pointer = pipe_buffer_map_range(pipe, - st_obj->buffer, - offset, length, - flags, - &st_obj->transfer); - if (obj->Pointer) { - obj->Pointer = (ubyte *) obj->Pointer + offset; - } + obj->Pointer = pipe_buffer_map_range(pipe, + st_obj->buffer, + offset, length, + flags, + &st_obj->transfer); + if (obj->Pointer) { + obj->Pointer = (ubyte *) obj->Pointer + offset; } - + if (obj->Pointer) { obj->Offset = offset; obj->Length = length; -- 2.30.2