diff options
Diffstat (limited to 'src/mesa/state_tracker/st_cb_bufferobjects.c')
-rw-r--r-- | src/mesa/state_tracker/st_cb_bufferobjects.c | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index a627c0374ad..8c1fd5ce025 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -26,8 +26,14 @@ **************************************************************************/ +/** + * Functions for pixel buffer objects and vertex/element buffer objects. + */ + + #include "main/imports.h" #include "main/mtypes.h" +#include "main/arrayobj.h" #include "main/bufferobj.h" #include "st_inlines.h" @@ -39,14 +45,6 @@ #include "pipe/p_inlines.h" - -/* Pixel buffers and Vertex/index buffers are handled through these - * mesa callbacks. Framebuffer/Renderbuffer objects are - * created/managed elsewhere. - */ - - - /** * There is some duplication between mesa's bufferobjects and our * bufmgr buffers. Both have an integer handle and a hashtable to @@ -100,8 +98,10 @@ st_bufferobj_subdata(GLcontext *ctx, { struct st_buffer_object *st_obj = st_buffer_object(obj); - if (offset >= st_obj->size || size > (st_obj->size - offset)) - return; + /* we may be called from VBO code, so double-check params here */ + ASSERT(offset >= 0); + ASSERT(size >= 0); + ASSERT(offset + size <= obj->Size); st_cond_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, offset, size, data); @@ -120,8 +120,10 @@ st_bufferobj_get_subdata(GLcontext *ctx, { struct st_buffer_object *st_obj = st_buffer_object(obj); - if (offset >= st_obj->size || size > (st_obj->size - offset)) - return; + /* we may be called from VBO code, so double-check params here */ + ASSERT(offset >= 0); + ASSERT(size >= 0); + ASSERT(offset + size <= obj->Size); st_cond_flush_pipe_buffer_read(st_context(ctx), st_obj->buffer, offset, size, data); @@ -174,8 +176,6 @@ st_bufferobj_data(GLcontext *ctx, return; } - st_obj->size = size; - if (data) st_no_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, 0, size, data); @@ -190,7 +190,7 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, struct gl_buffer_object *obj) { struct st_buffer_object *st_obj = st_buffer_object(obj); - GLuint flags; + uint flags; switch (access) { case GL_WRITE_ONLY: @@ -209,7 +209,7 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, obj->Pointer = st_cond_flush_pipe_buffer_map(st_context(ctx), st_obj->buffer, flags); - if(obj->Pointer) { + if (obj->Pointer) { obj->Offset = 0; obj->Length = obj->Size; } @@ -217,7 +217,6 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, } - /** * Called via glMapBufferRange(). */ @@ -228,7 +227,7 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, { struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); - GLuint flags = 0; + uint flags = 0x0; char *map; if (access & GL_MAP_WRITE_BIT) @@ -297,6 +296,43 @@ st_bufferobj_unmap(GLcontext *ctx, GLenum target, struct gl_buffer_object *obj) } +/** + * Called via glCopyBufferSubData(). + */ +static void +st_copy_buffer_subdata(GLcontext *ctx, + struct gl_buffer_object *src, + struct gl_buffer_object *dst, + GLintptr readOffset, GLintptr writeOffset, + GLsizeiptr size) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *srcObj = st_buffer_object(src); + struct st_buffer_object *dstObj = st_buffer_object(dst); + ubyte *srcPtr, *dstPtr; + + /* buffer should not already be mapped */ + assert(!src->Pointer); + assert(!dst->Pointer); + + srcPtr = (ubyte *) pipe_buffer_map_range(pipe->screen, + srcObj->buffer, + readOffset, size, + PIPE_BUFFER_USAGE_CPU_READ); + + dstPtr = (ubyte *) pipe_buffer_map_range(pipe->screen, + dstObj->buffer, + writeOffset, size, + PIPE_BUFFER_USAGE_CPU_WRITE); + + if (srcPtr && dstPtr) + _mesa_memcpy(dstPtr + writeOffset, srcPtr + readOffset, size); + + pipe_buffer_unmap(pipe->screen, srcObj->buffer); + pipe_buffer_unmap(pipe->screen, dstObj->buffer); +} + + void st_init_bufferobject_functions(struct dd_function_table *functions) { @@ -309,4 +345,9 @@ st_init_bufferobject_functions(struct dd_function_table *functions) functions->MapBufferRange = st_bufferobj_map_range; functions->FlushMappedBufferRange = st_bufferobj_flush_mapped_range; functions->UnmapBuffer = st_bufferobj_unmap; + functions->CopyBufferSubData = st_copy_buffer_subdata; + + /* For GL_APPLE_vertex_array_object */ + functions->NewArrayObject = _mesa_new_array_object; + functions->DeleteArrayObject = _mesa_delete_array_object; } |