core | glapi | vbo | math | shader | swrast | swrast_setup | tnl | tnl_dd

bufferobj.c File Reference


Detailed Description

Functions for the GL_ARB_vertex/pixel_buffer_object extensions.

Author:
Brian Paul, Ian Romanick

#include "glheader.h"
#include "hash.h"
#include "imports.h"
#include "image.h"
#include "context.h"
#include "bufferobj.h"

Defines

#define DEFAULT_ACCESS   (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)

Functions

static INLINE struct
gl_buffer_object
get_buffer (GLcontext *ctx, GLenum target)
 Get the buffer object bound to the specified target in a GL context.
static GLenum simplified_access_mode (GLbitfield access)
 Convert a GLbitfield describing the mapped buffer access flags into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
static struct gl_buffer_objectbuffer_object_subdata_range_good (GLcontext *ctx, GLenum target, GLintptrARB offset, GLsizeiptrARB size, const char *caller)
 Tests the subdata range parameters and sets the GL error code for glBufferSubDataARB and glGetBufferSubDataARB.
static struct gl_buffer_object_mesa_new_buffer_object (GLcontext *ctx, GLuint name, GLenum target)
 Allocate and initialize a new buffer object.
static void _mesa_delete_buffer_object (GLcontext *ctx, struct gl_buffer_object *bufObj)
 Delete a buffer object.
void _mesa_reference_buffer_object (GLcontext *ctx, struct gl_buffer_object **ptr, struct gl_buffer_object *bufObj)
 Set ptr to bufObj w/ reference counting.
void _mesa_initialize_buffer_object (struct gl_buffer_object *obj, GLuint name, GLenum target)
 Initialize a buffer object to default values.
static GLboolean _mesa_buffer_data (GLcontext *ctx, GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage, struct gl_buffer_object *bufObj)
 Allocate space for and store data in a buffer object.
static void _mesa_buffer_subdata (GLcontext *ctx, GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data, struct gl_buffer_object *bufObj)
 Replace data in a subrange of buffer object.
static void _mesa_buffer_get_subdata (GLcontext *ctx, GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data, struct gl_buffer_object *bufObj)
 Retrieve data from a subrange of buffer object.
static void * _mesa_buffer_map (GLcontext *ctx, GLenum target, GLenum access, struct gl_buffer_object *bufObj)
 Default callback for dd_function_tabel::MapBuffer().
static void * _mesa_buffer_map_range (GLcontext *ctx, GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, struct gl_buffer_object *bufObj)
 Default fallback for dd_function_table::MapBufferRange().
static void _mesa_buffer_flush_mapped_range (GLcontext *ctx, GLenum target, GLintptr offset, GLsizeiptr length, struct gl_buffer_object *obj)
 Default fallback for dd_function_table::FlushMappedBufferRange().
static GLboolean _mesa_buffer_unmap (GLcontext *ctx, GLenum target, struct gl_buffer_object *bufObj)
 Default callback for dd_function_table::MapBuffer().
static void _mesa_copy_buffer_subdata (GLcontext *ctx, struct gl_buffer_object *src, struct gl_buffer_object *dst, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
 Default fallback for dd_function_table::CopyBufferSubData().
void _mesa_init_buffer_objects (GLcontext *ctx)
 Initialize the state associated with buffer objects.
static void bind_buffer_object (GLcontext *ctx, GLenum target, GLuint buffer)
 Bind the specified target to buffer for the specified context.
void _mesa_update_default_objects_buffer_objects (GLcontext *ctx)
 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.
GLboolean _mesa_validate_pbo_access (GLuint dimensions, const struct gl_pixelstore_attrib *pack, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *ptr)
 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 going to read out of bounds.
const GLvoid * _mesa_map_pbo_source (GLcontext *ctx, const struct gl_pixelstore_attrib *unpack, const GLvoid *src)
 For commands that read from a PBO (glDrawPixels, glTexImage, glPolygonStipple, etc), if we're reading from a PBO, map it read-only and return the pointer into the PBO.
const GLvoid * _mesa_map_validate_pbo_source (GLcontext *ctx, GLuint dimensions, const struct gl_pixelstore_attrib *unpack, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *ptr, const char *where)
 Combine PBO-read validation and mapping.
void _mesa_unmap_pbo_source (GLcontext *ctx, const struct gl_pixelstore_attrib *unpack)
 Counterpart to _mesa_map_pbo_source().
void * _mesa_map_pbo_dest (GLcontext *ctx, const struct gl_pixelstore_attrib *pack, GLvoid *dest)
 For commands that write to a PBO (glReadPixels, glGetColorTable, etc), if we're writing to a PBO, map it write-only and return the pointer into the PBO.
GLvoid * _mesa_map_validate_pbo_dest (GLcontext *ctx, GLuint dimensions, const struct gl_pixelstore_attrib *unpack, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *ptr, const char *where)
 Combine PBO-write validation and mapping.
void _mesa_unmap_pbo_dest (GLcontext *ctx, const struct gl_pixelstore_attrib *pack)
 Counterpart to _mesa_map_pbo_dest().
struct gl_buffer_object_mesa_lookup_bufferobj (GLcontext *ctx, GLuint buffer)
 Return the gl_buffer_object for the given ID.
static void unbind (GLcontext *ctx, struct gl_buffer_object **ptr, struct gl_buffer_object *obj)
 If *ptr points to obj, set ptr = the Null/default buffer object.
void _mesa_init_buffer_object_functions (struct dd_function_table *driver)
 Plug default/fallback buffer object functions into the device driver hooks.
void GLAPIENTRY _mesa_BindBufferARB (GLenum target, GLuint buffer)
void GLAPIENTRY _mesa_DeleteBuffersARB (GLsizei n, const GLuint *ids)
 Delete a set of buffer objects.
void GLAPIENTRY _mesa_GenBuffersARB (GLsizei n, GLuint *buffer)
 Generate a set of unique buffer object IDs and store them in buffer.
GLboolean GLAPIENTRY _mesa_IsBufferARB (GLuint id)
 Determine if ID is the name of a buffer object.
void GLAPIENTRY _mesa_BufferDataARB (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage)
void GLAPIENTRY _mesa_BufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data)
void GLAPIENTRY _mesa_GetBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, void *data)
void *GLAPIENTRY _mesa_MapBufferARB (GLenum target, GLenum access)
GLboolean GLAPIENTRY _mesa_UnmapBufferARB (GLenum target)
void GLAPIENTRY _mesa_GetBufferParameterivARB (GLenum target, GLenum pname, GLint *params)
void GLAPIENTRY _mesa_GetBufferPointervARB (GLenum target, GLenum pname, GLvoid **params)
void GLAPIENTRY _mesa_CopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
void *GLAPIENTRY _mesa_MapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
 See GL_ARB_map_buffer_range spec.
void GLAPIENTRY _mesa_FlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length)
 See GL_ARB_map_buffer_range spec.


Define Documentation

#define DEFAULT_ACCESS   (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)


Function Documentation

void GLAPIENTRY _mesa_BindBufferARB ( GLenum  target,
GLuint  buffer 
)

static GLboolean _mesa_buffer_data ( GLcontext ctx,
GLenum  target,
GLsizeiptrARB  size,
const GLvoid *  data,
GLenum  usage,
struct gl_buffer_object bufObj 
) [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.

This is the default callback for dd_function_table::BufferData() Note that all GL error checking will have been done already.

Parameters:
ctx GL context.
target Buffer object target on which to operate.
size Size, in bytes, of the new data store.
data Pointer to the data to store in the buffer object. This pointer may be NULL.
usage Hints about how the data will be used.
bufObj Object to be used.
Returns:
GL_TRUE for success, GL_FALSE for failure
See also:
glBufferDataARB, dd_function_table::BufferData.

static void _mesa_buffer_flush_mapped_range ( GLcontext ctx,
GLenum  target,
GLintptr  offset,
GLsizeiptr  length,
struct gl_buffer_object obj 
) [static]

Default fallback for dd_function_table::FlushMappedBufferRange().

Called via glFlushMappedBufferRange().

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

Retrieve data from 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.

This is the default callback for dd_function_table::GetBufferSubData() Note that all GL error checking will have been done already.

Parameters:
ctx GL context.
target Buffer object target on which to operate.
offset Offset of the first byte to be fetched.
size Size, in bytes, of the data range.
data Destination for data
bufObj Object to be used.
See also:
glBufferGetSubDataARB, dd_function_table::GetBufferSubData.

static void* _mesa_buffer_map ( GLcontext ctx,
GLenum  target,
GLenum  access,
struct gl_buffer_object bufObj 
) [static]

Default callback for dd_function_tabel::MapBuffer().

The function parameters will have been already tested for errors.

Parameters:
ctx GL context.
target Buffer object target on which to operate.
access Information about how the buffer will be accessed.
bufObj Object to be mapped.
Returns:
A pointer to the object's internal data store that can be accessed by the processor
See also:
glMapBufferARB, dd_function_table::MapBuffer

static void* _mesa_buffer_map_range ( GLcontext ctx,
GLenum  target,
GLintptr  offset,
GLsizeiptr  length,
GLbitfield  access,
struct gl_buffer_object bufObj 
) [static]

Default fallback for dd_function_table::MapBufferRange().

Called via glMapBufferRange().

static void _mesa_buffer_subdata ( GLcontext ctx,
GLenum  target,
GLintptrARB  offset,
GLsizeiptrARB  size,
const GLvoid *  data,
struct gl_buffer_object bufObj 
) [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.

This is the default callback for dd_function_table::BufferSubData() Note that all GL error checking will have been done already.

Parameters:
ctx GL context.
target Buffer object target on which to operate.
offset Offset of the first byte to be modified.
size Size, in bytes, of the data range.
data Pointer to the data to store in the buffer object.
bufObj Object to be used.
See also:
glBufferSubDataARB, dd_function_table::BufferSubData.

static GLboolean _mesa_buffer_unmap ( GLcontext ctx,
GLenum  target,
struct gl_buffer_object bufObj 
) [static]

Default callback for dd_function_table::MapBuffer().

The input parameters will have been already tested for errors.

See also:
glUnmapBufferARB, dd_function_table::UnmapBuffer

void GLAPIENTRY _mesa_BufferDataARB ( GLenum  target,
GLsizeiptrARB  size,
const GLvoid *  data,
GLenum  usage 
)

void GLAPIENTRY _mesa_BufferSubDataARB ( GLenum  target,
GLintptrARB  offset,
GLsizeiptrARB  size,
const GLvoid *  data 
)

static void _mesa_copy_buffer_subdata ( GLcontext ctx,
struct gl_buffer_object src,
struct gl_buffer_object dst,
GLintptr  readOffset,
GLintptr  writeOffset,
GLsizeiptr  size 
) [static]

Default fallback for dd_function_table::CopyBufferSubData().

Called via glCopyBuffserSubData().

void GLAPIENTRY _mesa_CopyBufferSubData ( GLenum  readTarget,
GLenum  writeTarget,
GLintptr  readOffset,
GLintptr  writeOffset,
GLsizeiptr  size 
)

static void _mesa_delete_buffer_object ( GLcontext ctx,
struct gl_buffer_object bufObj 
) [static]

Delete a buffer object.

Default callback for the dd_function_table::DeleteBuffer() hook.

void GLAPIENTRY _mesa_DeleteBuffersARB ( GLsizei  n,
const GLuint *  ids 
)

Delete a set of buffer objects.

Parameters:
n Number of buffer objects to delete.
ids Array of n buffer object IDs.

void GLAPIENTRY _mesa_FlushMappedBufferRange ( GLenum  target,
GLintptr  offset,
GLsizeiptr  length 
)

See GL_ARB_map_buffer_range spec.

void GLAPIENTRY _mesa_GenBuffersARB ( GLsizei  n,
GLuint *  buffer 
)

Generate a set of unique buffer object IDs and store them in buffer.

Parameters:
n Number of IDs to generate.
buffer Array of n locations to store the IDs.

void GLAPIENTRY _mesa_GetBufferParameterivARB ( GLenum  target,
GLenum  pname,
GLint *  params 
)

void GLAPIENTRY _mesa_GetBufferPointervARB ( GLenum  target,
GLenum  pname,
GLvoid **  params 
)

void GLAPIENTRY _mesa_GetBufferSubDataARB ( GLenum  target,
GLintptrARB  offset,
GLsizeiptrARB  size,
void *  data 
)

void _mesa_init_buffer_object_functions ( struct dd_function_table driver  ) 

Plug default/fallback buffer object functions into the device driver hooks.

void _mesa_init_buffer_objects ( GLcontext ctx  ) 

Initialize the state associated with buffer objects.

void _mesa_initialize_buffer_object ( struct gl_buffer_object obj,
GLuint  name,
GLenum  target 
)

Initialize a buffer object to default values.

GLboolean GLAPIENTRY _mesa_IsBufferARB ( GLuint  id  ) 

Determine if ID is the name of a buffer object.

Parameters:
id ID of the potential buffer object.
Returns:
GL_TRUE if id is the name of a buffer object, GL_FALSE otherwise.

struct gl_buffer_object* _mesa_lookup_bufferobj ( GLcontext ctx,
GLuint  buffer 
) [read]

Return the gl_buffer_object for the given ID.

Always return NULL for ID 0.

void* _mesa_map_pbo_dest ( GLcontext ctx,
const struct gl_pixelstore_attrib pack,
GLvoid *  dest 
)

For commands that write to a PBO (glReadPixels, glGetColorTable, etc), if we're writing to a PBO, map it write-only and return the pointer into the PBO.

If we're not writing to a PBO, return dst as-is. If non-null return, must call _mesa_unmap_pbo_dest() when done.

Returns:
NULL if error, else pointer to start of data

const GLvoid* _mesa_map_pbo_source ( GLcontext ctx,
const struct gl_pixelstore_attrib unpack,
const GLvoid *  src 
)

For commands that read from a PBO (glDrawPixels, glTexImage, glPolygonStipple, etc), if we're reading from a PBO, map it read-only and return the pointer into the PBO.

If we're not reading from a PBO, return src as-is. If non-null return, must call _mesa_unmap_pbo_source() when done.

Returns:
NULL if error, else pointer to start of data

GLvoid* _mesa_map_validate_pbo_dest ( GLcontext ctx,
GLuint  dimensions,
const struct gl_pixelstore_attrib unpack,
GLsizei  width,
GLsizei  height,
GLsizei  depth,
GLenum  format,
GLenum  type,
GLvoid *  ptr,
const char *  where 
)

Combine PBO-write validation and mapping.

If any GL errors are detected, they'll be recorded and NULL returned.

See also:
_mesa_validate_pbo_access

_mesa_map_pbo_dest A call to this function should have a matching call to _mesa_unmap_pbo_dest().

const GLvoid* _mesa_map_validate_pbo_source ( GLcontext ctx,
GLuint  dimensions,
const struct gl_pixelstore_attrib unpack,
GLsizei  width,
GLsizei  height,
GLsizei  depth,
GLenum  format,
GLenum  type,
const GLvoid *  ptr,
const char *  where 
)

Combine PBO-read validation and mapping.

If any GL errors are detected, they'll be recorded and NULL returned.

See also:
_mesa_validate_pbo_access

_mesa_map_pbo_source A call to this function should have a matching call to _mesa_unmap_pbo_source().

void* GLAPIENTRY _mesa_MapBufferARB ( GLenum  target,
GLenum  access 
)

void* GLAPIENTRY _mesa_MapBufferRange ( GLenum  target,
GLintptr  offset,
GLsizeiptr  length,
GLbitfield  access 
)

See GL_ARB_map_buffer_range spec.

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

Allocate and initialize a new buffer object.

Default callback for the dd_function_table::NewBufferObject() hook.

void _mesa_reference_buffer_object ( GLcontext ctx,
struct gl_buffer_object **  ptr,
struct gl_buffer_object bufObj 
)

Set ptr to bufObj w/ reference counting.

void _mesa_unmap_pbo_dest ( GLcontext ctx,
const struct gl_pixelstore_attrib pack 
)

Counterpart to _mesa_map_pbo_dest().

void _mesa_unmap_pbo_source ( GLcontext ctx,
const struct gl_pixelstore_attrib unpack 
)

Counterpart to _mesa_map_pbo_source().

GLboolean GLAPIENTRY _mesa_UnmapBufferARB ( GLenum  target  ) 

void _mesa_update_default_objects_buffer_objects ( GLcontext ctx  ) 

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.

GLboolean _mesa_validate_pbo_access ( GLuint  dimensions,
const struct gl_pixelstore_attrib pack,
GLsizei  width,
GLsizei  height,
GLsizei  depth,
GLenum  format,
GLenum  type,
const GLvoid *  ptr 
)

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 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!

If we're not using a PBO, this is a no-op.

Parameters:
width width of image to read/write
height height of image to read/write
depth depth of image to read/write
format format of image to read/write
type datatype of image to read/write
ptr the user-provided pointer/offset
Returns:
GL_TRUE if the PBO access is OK, GL_FALSE if the access would go out of bounds.

static void bind_buffer_object ( GLcontext ctx,
GLenum  target,
GLuint  buffer 
) [static]

Bind the specified target to buffer for the specified context.

static struct gl_buffer_object* buffer_object_subdata_range_good ( GLcontext ctx,
GLenum  target,
GLintptrARB  offset,
GLsizeiptrARB  size,
const char *  caller 
) [static, read]

Tests the subdata range parameters and sets the GL error code for glBufferSubDataARB and glGetBufferSubDataARB.

Parameters:
ctx GL context.
target Buffer object target on which to operate.
offset Offset of the first byte of the subdata range.
size Size, in bytes, of the subdata range.
caller Name of calling function for recording errors.
Returns:
A pointer to the buffer object bound to target in the specified context or NULL if any of the parameter or state conditions for glBufferSubDataARB or glGetBufferSubDataARB are invalid.
See also:
glBufferSubDataARB, glGetBufferSubDataARB

static INLINE struct gl_buffer_object* get_buffer ( GLcontext ctx,
GLenum  target 
) [static, read]

Get the buffer object bound to the specified target in a GL context.

Parameters:
ctx GL context
target Buffer object target to be retrieved. Currently this must be either GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.
Returns:
A pointer to the buffer object bound to target in the specified context or NULL if target is invalid.

static GLenum simplified_access_mode ( GLbitfield  access  )  [static]

Convert a GLbitfield describing the mapped buffer access flags into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.

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

If *ptr points to obj, set ptr = the Null/default buffer object.

This is a helper for buffer object deletion. The GL spec says that deleting a buffer object causes it to get unbound from all arrays in the current context.


Generated on Sun Sep 27 06:47:45 2009 for Mesa Main by  doxygen 1.5.4