Merge branch 'mesa_7_6_branch'
[mesa.git] / src / mesa / state_tracker / st_cb_bufferobjects.c
index 7021d732089507f7c37fab3cec4ad743359aaddf..8e09d0b9324152ebb196665c949e314d10d48adc 100644 (file)
@@ -98,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);
@@ -118,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);
@@ -130,9 +134,10 @@ st_bufferobj_get_subdata(GLcontext *ctx,
  * 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().
+ * Called via ctx->Driver.BufferData().
+ * \return GL_TRUE for success, GL_FALSE if out of memory
  */
-static void
+static GLboolean
 st_bufferobj_data(GLcontext *ctx,
                  GLenum target,
                  GLsizeiptrARB size,
@@ -168,15 +173,13 @@ st_bufferobj_data(GLcontext *ctx,
    st_obj->buffer = pipe_buffer_create( pipe->screen, 32, buffer_usage, size );
 
    if (!st_obj->buffer) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB");
-      return;
+      return GL_FALSE;
    }
 
-   st_obj->size = size;
-
    if (data)
       st_no_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, 0,
                                    size, data);
+   return GL_TRUE;
 }
 
 
@@ -226,7 +229,6 @@ 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);
    uint flags = 0x0;
-   char *map;
 
    if (access & GL_MAP_WRITE_BIT)
       flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
@@ -234,6 +236,9 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target,
    if (access & GL_MAP_READ_BIT)
       flags |= PIPE_BUFFER_USAGE_CPU_READ;
 
+   if (access & GL_MAP_FLUSH_EXPLICIT_BIT)
+      flags |= PIPE_BUFFER_USAGE_FLUSH_EXPLICIT;
+   
    /* ... other flags ...
     */
 
@@ -245,14 +250,15 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target,
    assert(offset < obj->Size);
    assert(offset + length <= obj->Size);
 
-   map = obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags);
-   if(obj->Pointer) {
+   obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags);
+   if (obj->Pointer) {
+      obj->Pointer = (ubyte *) obj->Pointer + offset;
       obj->Offset = offset;
       obj->Length = length;
-      map += offset;
+      obj->AccessFlags = access;
    }
    
-   return map;
+   return obj->Pointer;
 }