GLenum Usage;
GLenum Access;
GLvoid *Pointer; /**< Only valid while buffer is mapped */
+ GLintptr Offset; /**< mapped offset */
+ GLsizeiptr Length; /**< mapped length */
GLsizeiptrARB Size; /**< Size of storage in bytes */
GLubyte *Data; /**< Location of storage either in RAM or VRAM. */
GLboolean OnCard; /**< Is buffer in VRAM? (hardware drivers) */
}
obj->Pointer = pipe_buffer_map(pipe->screen, st_obj->buffer, flags);
+ if(obj->Pointer) {
+ obj->Offset = 0;
+ obj->Length = obj->Size;
+ }
return obj->Pointer;
}
if (access & MESA_MAP_NOWAIT_BIT)
flags |= PIPE_BUFFER_USAGE_DONTBLOCK;
- map = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags);
- /* this is expected to point to the buffer start, in order to calculate the
- * vertices offsets
- */
- obj->Pointer = map ? map - offset : NULL;
+ assert(offset >= 0);
+ assert(length >= 0);
+ 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->Offset = 0;
+ obj->Length = obj->Size;
+ map += offset;
+ }
+
return map;
}
struct pipe_context *pipe = st_context(ctx)->pipe;
struct st_buffer_object *st_obj = st_buffer_object(obj);
- pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer, offset, length);
+ /* Subrange is relative to mapped range */
+ assert(offset >= 0);
+ assert(length >= 0);
+ assert(offset < obj->Length);
+ assert(offset + length <= obj->Length);
+
+ pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer,
+ obj->Offset + offset, length);
}
pipe_buffer_unmap(pipe->screen, st_obj->buffer);
obj->Pointer = NULL;
+ obj->Offset = 0;
+ obj->Length = 0;
return GL_TRUE;
}
if (exec->vtx.bufferobj->Name) {
GLcontext *ctx = exec->ctx;
- GLintptr offset = exec->vtx.buffer_used;
- GLsizeiptr length = (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float);
- if(ctx->Driver.FlushMappedBufferRange)
- ctx->Driver.FlushMappedBufferRange(ctx, target,
- offset, length,
- exec->vtx.bufferobj);
+ if(ctx->Driver.FlushMappedBufferRange) {
+ GLintptr offset = exec->vtx.buffer_used - exec->vtx.bufferobj->Offset;
+ GLsizeiptr length = (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float);
+
+ if(length)
+ ctx->Driver.FlushMappedBufferRange(ctx, target,
+ offset, length,
+ exec->vtx.bufferobj);
+ }
exec->vtx.buffer_used += (exec->vtx.buffer_ptr -
exec->vtx.buffer_map) * sizeof(float);