From 2daa4137b658569da542180442fc32ebc5608102 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sun, 31 Oct 2004 00:17:42 +0000 Subject: Remove redundant error checking. Added _mesa_buffer_unmap(). Minor clean-ups. --- src/mesa/main/bufferobj.c | 70 ++++++++++++++++++++++++++++++++--------------- src/mesa/main/bufferobj.h | 5 +++- 2 files changed, 52 insertions(+), 23 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 0d0e5f4bcf..c795d2f16a 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 6.2 + * Version: 6.3 * * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * @@ -123,7 +123,8 @@ buffer_object_subdata_range_good( GLcontext * ctx, GLenum target, return NULL; } - if ( bufObj->Pointer != NULL ) { + if ( bufObj->Pointer ) { + /* Buffer is currently mapped */ _mesa_error(ctx, GL_INVALID_OPERATION, "%s", str); return NULL; } @@ -318,16 +319,16 @@ _mesa_buffer_get_subdata( GLcontext *ctx, GLenum target, GLintptrARB offset, /** - * Maps the private data buffer into the processor's address space. + * Fallback function called via ctx->Driver.MapBuffer(). + * Hardware drivers that really implement buffer objects should never use + * function. * - * This function is intended to be called by \c dd_function_table::MapBuffer. - * This function need not set GL error codes. The input parameters will have - * been tested before calling. + * The input parameters will have been already tested for errors. * * \param ctx GL context. * \param target Buffer object target on which to operate. * \param access Information about how the buffer will be accessed. - * \param bufObj Object to be used. + * \param bufObj Object to be mapped. * \return A pointer to the object's internal data store that can be accessed * by the processor * @@ -335,10 +336,41 @@ _mesa_buffer_get_subdata( GLcontext *ctx, GLenum target, GLintptrARB offset, */ void * _mesa_buffer_map( GLcontext *ctx, GLenum target, GLenum access, - struct gl_buffer_object * bufObj ) + struct gl_buffer_object *bufObj ) +{ + (void) ctx; + (void) target; + (void) access; + ASSERT(!bufObj->OnCard); + /* Just return a direct pointer to the data */ + if (bufObj->Pointer) { + /* already mapped! */ + return NULL; + } + bufObj->Pointer = bufObj->Data; + return bufObj->Pointer; +} + + +/** + * Fallback function called via ctx->Driver.MapBuffer(). + * Hardware drivers that really implement buffer objects should never use + * function. + * + * The input parameters will have been already tested for errors. + * + * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer + */ +GLboolean +_mesa_buffer_unmap( GLcontext *ctx, GLenum target, + struct gl_buffer_object *bufObj ) { - (void) ctx; (void) target; (void) access; - return bufObj->Data; + (void) ctx; + (void) target; + ASSERT(!bufObj->OnCard); + /* XXX we might assert here that bufObj->Pointer is non-null */ + bufObj->Pointer = NULL; + return GL_TRUE; } @@ -383,6 +415,10 @@ _mesa_init_buffer_objects( GLcontext *ctx ) * glGetTexImage, etc) we call this function to check that we're not * going to read out of bounds. * + * XXX This would also be a convenient time to check that the PBO isn't + * currently mapped. Whoever calls this function should check for that. + * Remember, we can't use a PBO when it's mapped! + * * \param width width of image to read/write * \param height height of image to read/write * \param depth depth of image to read/write @@ -755,15 +791,10 @@ _mesa_BufferSubDataARB(GLenum target, GLintptrARB offset, bufObj = buffer_object_subdata_range_good( ctx, target, offset, size, "BufferSubDataARB" ); if (!bufObj) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferSubDataARB" ); + /* error already recorded */ return; } - if (bufObj->Pointer) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferSubDataARB(buffer is mapped)" ); - return; - } - ASSERT(ctx->Driver.BufferSubData); (*ctx->Driver.BufferSubData)( ctx, target, offset, size, data, bufObj ); } @@ -780,15 +811,10 @@ _mesa_GetBufferSubDataARB(GLenum target, GLintptrARB offset, bufObj = buffer_object_subdata_range_good( ctx, target, offset, size, "GetBufferSubDataARB" ); if (!bufObj) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferSubDataARB" ); + /* error already recorded */ return; } - if (bufObj->Pointer) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferSubDataARB(buffer is mapped)" ); - return; - } - ASSERT(ctx->Driver.GetBufferSubData); (*ctx->Driver.GetBufferSubData)( ctx, target, offset, size, data, bufObj ); } diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h index e6bd8b329a..635975d2f7 100644 --- a/src/mesa/main/bufferobj.h +++ b/src/mesa/main/bufferobj.h @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 6.1 + * Version: 6.3 * * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * @@ -73,6 +73,9 @@ extern void * _mesa_buffer_map( GLcontext *ctx, GLenum target, GLenum access, struct gl_buffer_object * bufObj ); +extern GLboolean +_mesa_buffer_unmap( GLcontext *ctx, GLenum target, + struct gl_buffer_object * bufObj ); extern GLboolean _mesa_validate_pbo_access(const struct gl_pixelstore_attrib *pack, -- cgit v1.2.3