diff options
Diffstat (limited to 'src/mesa/main/bufferobj.c')
-rw-r--r-- | src/mesa/main/bufferobj.c | 204 |
1 files changed, 116 insertions, 88 deletions
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index dd4ac4679e..c8d160baa9 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -1,8 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 7.2 + * Version: 7.5 * * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -25,7 +26,7 @@ /** * \file bufferobj.c - * \brief Functions for the GL_ARB_vertex_buffer_object extension. + * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions. * \author Brian Paul, Ian Romanick */ @@ -144,8 +145,7 @@ buffer_object_subdata_range_good( GLcontext * ctx, GLenum target, /** * Allocate and initialize a new buffer object. * - * This function is intended to be called via - * \c dd_function_table::NewBufferObject. + * Default callback for the \c dd_function_table::NewBufferObject() hook. */ struct gl_buffer_object * _mesa_new_buffer_object( GLcontext *ctx, GLuint name, GLenum target ) @@ -163,8 +163,7 @@ _mesa_new_buffer_object( GLcontext *ctx, GLuint name, GLenum target ) /** * Delete a buffer object. * - * This function is intended to be called via - * \c dd_function_table::DeleteBuffer. + * Default callback for the \c dd_function_table::DeleteBuffer() hook. */ void _mesa_delete_buffer_object( GLcontext *ctx, struct gl_buffer_object *bufObj ) @@ -271,9 +270,8 @@ _mesa_initialize_buffer_object( struct gl_buffer_object *obj, * previously stored in the buffer object is lost. If \c data is \c NULL, * memory will be allocated, but no copy will occur. * - * This function is intended to be called via - * \c dd_function_table::BufferData. This function need not set GL error - * codes. The input parameters will have been tested before calling. + * This is the default callback for \c dd_function_table::BufferData() + * Note that all GL error checking will have been done already. * * \param ctx GL context. * \param target Buffer object target on which to operate. @@ -312,9 +310,8 @@ _mesa_buffer_data( GLcontext *ctx, GLenum target, GLsizeiptrARB size, * specified by \c size + \c offset extends beyond the end of the buffer or * if \c data is \c NULL, no copy is performed. * - * This function is intended to be called by - * \c dd_function_table::BufferSubData. This function need not set GL error - * codes. The input parameters will have been tested before calling. + * This is the default callback for \c dd_function_table::BufferSubData() + * Note that all GL error checking will have been done already. * * \param ctx GL context. * \param target Buffer object target on which to operate. @@ -346,15 +343,14 @@ _mesa_buffer_subdata( GLcontext *ctx, GLenum target, GLintptrARB offset, * specified by \c size + \c offset extends beyond the end of the buffer or * if \c data is \c NULL, no copy is performed. * - * This function is intended to be called by - * \c dd_function_table::BufferGetSubData. This function need not set GL error - * codes. The input parameters will have been tested before calling. + * This is the default callback for \c dd_function_table::GetBufferSubData() + * Note that all GL error checking will have been done already. * * \param ctx GL context. * \param target Buffer object target on which to operate. - * \param offset Offset of the first byte to be modified. + * \param offset Offset of the first byte to be fetched. * \param size Size, in bytes, of the data range. - * \param data Pointer to the data to store in the buffer object. + * \param data Destination for data * \param bufObj Object to be used. * * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData. @@ -373,9 +369,7 @@ _mesa_buffer_get_subdata( GLcontext *ctx, GLenum target, GLintptrARB offset, /** - * Fallback function called via ctx->Driver.MapBuffer(). - * Hardware drivers that really implement buffer objects should never use - * this function. + * Default callback for \c dd_function_tabel::MapBuffer(). * * The function parameters will have been already tested for errors. * @@ -407,9 +401,7 @@ _mesa_buffer_map( GLcontext *ctx, GLenum target, GLenum access, /** - * Fallback function called via ctx->Driver.MapBuffer(). - * Hardware drivers that really implement buffer objects should never use - * function. + * Default callback for \c dd_function_table::MapBuffer(). * * The input parameters will have been already tested for errors. * @@ -448,6 +440,90 @@ _mesa_init_buffer_objects( GLcontext *ctx ) /** + * Bind the specified target to buffer for the specified context. + */ +static void +bind_buffer_object(GLcontext *ctx, GLenum target, GLuint buffer) +{ + struct gl_buffer_object *oldBufObj; + struct gl_buffer_object *newBufObj = NULL; + struct gl_buffer_object **bindTarget = NULL; + + switch (target) { + case GL_ARRAY_BUFFER_ARB: + bindTarget = &ctx->Array.ArrayBufferObj; + break; + case GL_ELEMENT_ARRAY_BUFFER_ARB: + bindTarget = &ctx->Array.ElementArrayBufferObj; + break; + case GL_PIXEL_PACK_BUFFER_EXT: + bindTarget = &ctx->Pack.BufferObj; + break; + case GL_PIXEL_UNPACK_BUFFER_EXT: + bindTarget = &ctx->Unpack.BufferObj; + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target)"); + return; + } + + /* Get pointer to old buffer object (to be unbound) */ + oldBufObj = get_buffer(ctx, target); + if (oldBufObj && oldBufObj->Name == buffer) + return; /* rebinding the same buffer object- no change */ + + /* + * Get pointer to new buffer object (newBufObj) + */ + if (buffer == 0) { + /* The spec says there's not a buffer object named 0, but we use + * one internally because it simplifies things. + */ + newBufObj = ctx->Array.NullBufferObj; + } + else { + /* non-default buffer object */ + newBufObj = _mesa_lookup_bufferobj(ctx, buffer); + if (!newBufObj) { + /* if this is a new buffer object id, allocate a buffer object now */ + ASSERT(ctx->Driver.NewBufferObject); + newBufObj = ctx->Driver.NewBufferObject(ctx, buffer, target); + if (!newBufObj) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindBufferARB"); + return; + } + _mesa_HashInsert(ctx->Shared->BufferObjects, buffer, newBufObj); + } + } + + /* bind new buffer */ + _mesa_reference_buffer_object(ctx, bindTarget, newBufObj); + + /* Pass BindBuffer call to device driver */ + if (ctx->Driver.BindBuffer && newBufObj) + ctx->Driver.BindBuffer( ctx, target, newBufObj ); +} + + +/** + * Update the default buffer objects in the given context to reference those + * specified in the shared state and release those referencing the old + * shared state. + */ +void +_mesa_update_default_objects_buffer_objects(GLcontext *ctx) +{ + /* Bind the NullBufferObj to remove references to those + * in the shared context hash table. + */ + bind_buffer_object( ctx, GL_ARRAY_BUFFER_ARB, 0); + bind_buffer_object( ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + bind_buffer_object( ctx, GL_PIXEL_PACK_BUFFER_ARB, 0); + bind_buffer_object( ctx, GL_PIXEL_UNPACK_BUFFER_ARB, 0); +} + + +/** * When we're about to read pixel data out of a PBO (via glDrawPixels, * glTexImage, etc) or write data into a PBO (via glReadPixels, * glGetTexImage, etc) we call this function to check that we're not @@ -684,64 +760,9 @@ void GLAPIENTRY _mesa_BindBufferARB(GLenum target, GLuint buffer) { GET_CURRENT_CONTEXT(ctx); - struct gl_buffer_object *oldBufObj; - struct gl_buffer_object *newBufObj = NULL; - struct gl_buffer_object **bindTarget = NULL; ASSERT_OUTSIDE_BEGIN_END(ctx); - switch (target) { - case GL_ARRAY_BUFFER_ARB: - bindTarget = &ctx->Array.ArrayBufferObj; - break; - case GL_ELEMENT_ARRAY_BUFFER_ARB: - bindTarget = &ctx->Array.ElementArrayBufferObj; - break; - case GL_PIXEL_PACK_BUFFER_EXT: - bindTarget = &ctx->Pack.BufferObj; - break; - case GL_PIXEL_UNPACK_BUFFER_EXT: - bindTarget = &ctx->Unpack.BufferObj; - break; - default: - _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target)"); - return; - } - - /* Get pointer to old buffer object (to be unbound) */ - oldBufObj = get_buffer(ctx, target); - if (oldBufObj && oldBufObj->Name == buffer) - return; /* rebinding the same buffer object- no change */ - - /* - * Get pointer to new buffer object (newBufObj) - */ - if (buffer == 0) { - /* The spec says there's not a buffer object named 0, but we use - * one internally because it simplifies things. - */ - newBufObj = ctx->Array.NullBufferObj; - } - else { - /* non-default buffer object */ - newBufObj = _mesa_lookup_bufferobj(ctx, buffer); - if (!newBufObj) { - /* if this is a new buffer object id, allocate a buffer object now */ - ASSERT(ctx->Driver.NewBufferObject); - newBufObj = ctx->Driver.NewBufferObject(ctx, buffer, target); - if (!newBufObj) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindBufferARB"); - return; - } - _mesa_HashInsert(ctx->Shared->BufferObjects, buffer, newBufObj); - } - } - - /* bind new buffer */ - _mesa_reference_buffer_object(ctx, bindTarget, newBufObj); - - /* Pass BindBuffer call to device driver */ - if (ctx->Driver.BindBuffer && newBufObj) - ctx->Driver.BindBuffer( ctx, target, newBufObj ); + bind_buffer_object(ctx, target, buffer); } @@ -768,11 +789,18 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids) for (i = 0; i < n; i++) { struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, ids[i]); if (bufObj) { - /* unbind any vertex pointers bound to this buffer */ GLuint j; ASSERT(bufObj->Name == ids[i]); + if (bufObj->Pointer) { + /* if mapped, unmap it now */ + ctx->Driver.UnmapBuffer(ctx, 0, bufObj); + bufObj->Access = DEFAULT_ACCESS; + bufObj->Pointer = NULL; + } + + /* unbind any vertex pointers bound to this buffer */ unbind(ctx, &ctx->Array.ArrayObj->Vertex.BufferObj, bufObj); unbind(ctx, &ctx->Array.ArrayObj->Normal.BufferObj, bufObj); unbind(ctx, &ctx->Array.ArrayObj->Color.BufferObj, bufObj); @@ -780,7 +808,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids) unbind(ctx, &ctx->Array.ArrayObj->FogCoord.BufferObj, bufObj); unbind(ctx, &ctx->Array.ArrayObj->Index.BufferObj, bufObj); unbind(ctx, &ctx->Array.ArrayObj->EdgeFlag.BufferObj, bufObj); - for (j = 0; j < MAX_TEXTURE_UNITS; j++) { + for (j = 0; j < MAX_TEXTURE_COORD_UNITS; j++) { unbind(ctx, &ctx->Array.ArrayObj->TexCoord[j].BufferObj, bufObj); } for (j = 0; j < VERT_ATTRIB_MAX; j++) { @@ -794,6 +822,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids) _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 ); } + /* unbind any pixel pack/unpack pointers bound to this buffer */ if (ctx->Pack.BufferObj == bufObj) { _mesa_BindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 ); } @@ -801,7 +830,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids) _mesa_BindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, 0 ); } - /* The ID is immediately freed for re-use */ + /* The ID is immediately freed for re-use */ _mesa_HashRemove(ctx->Shared->BufferObjects, bufObj->Name); _mesa_reference_buffer_object(ctx, &bufObj, NULL); } @@ -923,8 +952,10 @@ _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size, } if (bufObj->Pointer) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferDataARB(buffer is mapped)" ); - return; + /* Unmap the existing buffer. We'll replace it now. Not an error. */ + ctx->Driver.UnmapBuffer(ctx, target, bufObj); + bufObj->Access = DEFAULT_ACCESS; + bufObj->Pointer = NULL; } ASSERT(ctx->Driver.BufferData); @@ -1040,10 +1071,7 @@ _mesa_UnmapBufferARB(GLenum target) return GL_FALSE; } - if (ctx->Driver.UnmapBuffer) { - status = ctx->Driver.UnmapBuffer( ctx, target, bufObj ); - } - + status = ctx->Driver.UnmapBuffer( ctx, target, bufObj ); bufObj->Access = DEFAULT_ACCESS; bufObj->Pointer = NULL; |