st_cb_bufferobjects.c File Reference

Include dependency graph for st_cb_bufferobjects.c:

Go to the source code of this file.

Functions

static struct gl_buffer_object * st_bufferobj_alloc (GLcontext *ctx, GLuint name, GLenum target)
 There is some duplication between mesa's bufferobjects and our bufmgr buffers.
static void st_bufferobj_free (GLcontext *ctx, struct gl_buffer_object *obj)
 Deallocate/free a vertex/pixel buffer object.
static void st_bufferobj_subdata (GLcontext *ctx, GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data, struct gl_buffer_object *obj)
 Replace data in a subrange of buffer object.
static void st_bufferobj_get_subdata (GLcontext *ctx, GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data, struct gl_buffer_object *obj)
 Called via glGetBufferSubDataARB().
static void st_bufferobj_data (GLcontext *ctx, GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage, struct gl_buffer_object *obj)
 Allocate space for and store data in a buffer object.
static void * st_bufferobj_map (GLcontext *ctx, GLenum target, GLenum access, struct gl_buffer_object *obj)
 Called via glMapBufferARB().
static GLboolean st_bufferobj_unmap (GLcontext *ctx, GLenum target, struct gl_buffer_object *obj)
 Called via glMapBufferARB().
void st_init_bufferobject_functions (struct dd_function_table *functions)


Function Documentation

static struct gl_buffer_object* st_bufferobj_alloc ( GLcontext *  ctx,
GLuint  name,
GLenum  target 
) [static, read]

There is some duplication between mesa's bufferobjects and our bufmgr buffers.

Both have an integer handle and a hashtable to lookup an opaque structure. It would be nice if the handles and internal structure where somehow shared.

Definition at line 56 of file st_cb_bufferobjects.c.

References st_buffer_object::Base, and CALLOC_STRUCT.

00057 {
00058    struct st_buffer_object *st_obj = CALLOC_STRUCT(st_buffer_object);
00059 
00060    if (!st_obj)
00061       return NULL;
00062 
00063    _mesa_initialize_buffer_object(&st_obj->Base, name, target);
00064 
00065    return &st_obj->Base;
00066 }

static void st_bufferobj_data ( GLcontext *  ctx,
GLenum  target,
GLsizeiptrARB  size,
const GLvoid *  data,
GLenum  usage,
struct gl_buffer_object *  obj 
) [static]

Allocate space for and store data in a buffer object.

Any data that was previously stored in the buffer object is lost. If data is NULL, memory will be allocated, but no copy will occur. Called via glBufferDataARB().

Definition at line 144 of file st_cb_bufferobjects.c.

References st_buffer_object::Base, st_buffer_object::buffer, st_context::pipe, pipe_buffer_create(), pipe_buffer_reference(), PIPE_BUFFER_USAGE_INDEX, PIPE_BUFFER_USAGE_PIXEL, PIPE_BUFFER_USAGE_VERTEX, pipe_context::screen, st_buffer_object::size, st_buffer_object(), st_bufferobj_subdata(), and st_context().

00150 {
00151    struct st_context *st = st_context(ctx);
00152    struct pipe_context *pipe = st->pipe;
00153    struct st_buffer_object *st_obj = st_buffer_object(obj);
00154    unsigned buffer_usage;
00155 
00156    st_obj->Base.Size = size;
00157    st_obj->Base.Usage = usage;
00158    
00159    switch(target) {
00160    case GL_PIXEL_PACK_BUFFER_ARB:
00161    case GL_PIXEL_UNPACK_BUFFER_ARB:
00162       buffer_usage = PIPE_BUFFER_USAGE_PIXEL;
00163       break;
00164    case GL_ARRAY_BUFFER_ARB:
00165       buffer_usage = PIPE_BUFFER_USAGE_VERTEX;
00166       break;
00167    case GL_ELEMENT_ARRAY_BUFFER_ARB:
00168       buffer_usage = PIPE_BUFFER_USAGE_INDEX;
00169       break;
00170    default:
00171       buffer_usage = 0;
00172    }
00173 
00174    pipe_buffer_reference( pipe->screen, &st_obj->buffer, NULL );
00175 
00176    st_obj->buffer = pipe_buffer_create( pipe->screen, 32, buffer_usage, size );
00177 
00178    st_obj->size = size;
00179 
00180    if (data)
00181       st_bufferobj_subdata(ctx, target, 0, size, data, obj);
00182 }

static void st_bufferobj_free ( GLcontext *  ctx,
struct gl_buffer_object *  obj 
) [static]

Deallocate/free a vertex/pixel buffer object.

Called via glDeleteBuffersARB().

Definition at line 75 of file st_cb_bufferobjects.c.

References st_buffer_object::buffer, st_context::pipe, pipe_buffer_reference(), pipe_context::screen, st_buffer_object(), and st_context().

00076 {
00077    struct pipe_context *pipe = st_context(ctx)->pipe;
00078    struct st_buffer_object *st_obj = st_buffer_object(obj);
00079 
00080    if (st_obj->buffer) 
00081       pipe_buffer_reference(pipe->screen, &st_obj->buffer, NULL);
00082 
00083    free(st_obj);
00084 }

static void st_bufferobj_get_subdata ( GLcontext *  ctx,
GLenum  target,
GLintptrARB  offset,
GLsizeiptrARB  size,
GLvoid *  data,
struct gl_buffer_object *  obj 
) [static]

Called via glGetBufferSubDataARB().

Definition at line 118 of file st_cb_bufferobjects.c.

References st_buffer_object::buffer, st_context::pipe, pipe_buffer_map(), pipe_buffer_unmap(), PIPE_BUFFER_USAGE_CPU_READ, pipe_context::screen, st_buffer_object::size, st_buffer_object(), and st_context().

00123 {
00124    struct pipe_context *pipe = st_context(ctx)->pipe;
00125    struct st_buffer_object *st_obj = st_buffer_object(obj);
00126    char *map;
00127 
00128    if (offset >= st_obj->size || size > (st_obj->size - offset))
00129       return;
00130 
00131    map = pipe_buffer_map(pipe->screen, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_READ);
00132    memcpy(data, map + offset, size);
00133    pipe_buffer_unmap(pipe->screen, st_obj->buffer);
00134 }

static void* st_bufferobj_map ( GLcontext *  ctx,
GLenum  target,
GLenum  access,
struct gl_buffer_object *  obj 
) [static]

Called via glMapBufferARB().

Definition at line 189 of file st_cb_bufferobjects.c.

References st_buffer_object::buffer, st_context::pipe, pipe_buffer_map(), PIPE_BUFFER_USAGE_CPU_READ, PIPE_BUFFER_USAGE_CPU_WRITE, pipe_context::screen, st_buffer_object(), and st_context().

00191 {
00192    struct pipe_context *pipe = st_context(ctx)->pipe;
00193    struct st_buffer_object *st_obj = st_buffer_object(obj);
00194    GLuint flags;
00195 
00196    switch (access) {
00197    case GL_WRITE_ONLY:
00198       flags = PIPE_BUFFER_USAGE_CPU_WRITE;
00199       break;
00200    case GL_READ_ONLY:
00201       flags = PIPE_BUFFER_USAGE_CPU_READ;
00202       break;
00203    case GL_READ_WRITE:
00204       /* fall-through */
00205    default:
00206       flags = PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE;
00207       break;      
00208    }
00209 
00210    obj->Pointer = pipe_buffer_map(pipe->screen, st_obj->buffer, flags);
00211    return obj->Pointer;
00212 }

static void st_bufferobj_subdata ( GLcontext *  ctx,
GLenum  target,
GLintptrARB  offset,
GLsizeiptrARB  size,
const GLvoid *  data,
struct gl_buffer_object *  obj 
) [static]

Replace data in a subrange of buffer object.

If the data range specified by size + offset extends beyond the end of the buffer or if data is NULL, no copy is performed. Called via glBufferSubDataARB().

Definition at line 95 of file st_cb_bufferobjects.c.

References st_buffer_object::buffer, st_context::pipe, pipe_buffer_map(), pipe_buffer_unmap(), PIPE_BUFFER_USAGE_CPU_WRITE, pipe_context::screen, st_buffer_object::size, st_buffer_object(), and st_context().

00100 {
00101    struct pipe_context *pipe = st_context(ctx)->pipe;
00102    struct st_buffer_object *st_obj = st_buffer_object(obj);
00103    char *map;
00104 
00105    if (offset >= st_obj->size || size > (st_obj->size - offset))
00106       return;
00107 
00108    map = pipe_buffer_map(pipe->screen, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_WRITE);
00109    memcpy(map + offset, data, size);
00110    pipe_buffer_unmap(pipe->screen, st_obj->buffer);
00111 }

static GLboolean st_bufferobj_unmap ( GLcontext *  ctx,
GLenum  target,
struct gl_buffer_object *  obj 
) [static]

Called via glMapBufferARB().

Definition at line 219 of file st_cb_bufferobjects.c.

References st_buffer_object::buffer, st_context::pipe, pipe_buffer_unmap(), pipe_context::screen, st_buffer_object(), and st_context().

00220 {
00221    struct pipe_context *pipe = st_context(ctx)->pipe;
00222    struct st_buffer_object *st_obj = st_buffer_object(obj);
00223 
00224    pipe_buffer_unmap(pipe->screen, st_obj->buffer);
00225    obj->Pointer = NULL;
00226    return GL_TRUE;
00227 }

void st_init_bufferobject_functions ( struct dd_function_table *  functions  ) 

Definition at line 231 of file st_cb_bufferobjects.c.

References st_bufferobj_alloc(), st_bufferobj_data(), st_bufferobj_free(), st_bufferobj_get_subdata(), st_bufferobj_map(), st_bufferobj_subdata(), and st_bufferobj_unmap().

00232 {
00233    functions->NewBufferObject = st_bufferobj_alloc;
00234    functions->DeleteBuffer = st_bufferobj_free;
00235    functions->BufferData = st_bufferobj_data;
00236    functions->BufferSubData = st_bufferobj_subdata;
00237    functions->GetBufferSubData = st_bufferobj_get_subdata;
00238    functions->MapBuffer = st_bufferobj_map;
00239    functions->UnmapBuffer = st_bufferobj_unmap;
00240 }


Generated on Tue Sep 29 06:25:52 2009 for Gallium3D by  doxygen 1.5.4