st/mesa: implement/enable GL_ARB_copy_buffer extension
authorBrian Paul <brianp@vmware.com>
Wed, 3 Jun 2009 03:24:28 +0000 (21:24 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 3 Jun 2009 03:35:11 +0000 (21:35 -0600)
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_extensions.c

index f5d802055f501f4e764560c74f946a27ebee8ab8..340fbd9abaf2bc6982da6a3270b3db8eef0ded20 100644 (file)
@@ -296,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)
 {
@@ -308,6 +345,7 @@ 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;
index efa88c2481fdf785ad2325329b0338d092949a07..8ed1211db60a7f6a9ce41cb67ac9eccf070a5fb9 100644 (file)
@@ -138,6 +138,7 @@ void st_init_extensions(struct st_context *st)
    /*
     * Extensions that are supported by all Gallium drivers:
     */
+   ctx->Extensions.ARB_copy_buffer = GL_TRUE;
    ctx->Extensions.ARB_multisample = GL_TRUE;
    ctx->Extensions.ARB_fragment_program = GL_TRUE;
    ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */