OSDN Git Service

mesa: New feature FEATURE_beginend.
[android-x86/external-mesa.git] / src / mesa / vbo / vbo_exec_draw.c
index c939b7b..ee148df 100644 (file)
@@ -35,6 +35,9 @@
 #include "vbo_context.h"
 
 
+#if FEATURE_beginend
+
+
 static void
 vbo_exec_debug_verts( struct vbo_exec_context *exec )
 {
@@ -51,7 +54,7 @@ vbo_exec_debug_verts( struct vbo_exec_context *exec )
       struct _mesa_prim *prim = &exec->vtx.prim[i];
       _mesa_printf("   prim %d: %s%s %d..%d %s %s\n",
                   i, 
-                  _mesa_lookup_enum_by_nr(prim->mode),
+                  _mesa_lookup_prim_by_nr(prim->mode),
                   prim->weak ? " (weak)" : "",
                   prim->start, 
                   prim->start + prim->count,
@@ -214,11 +217,13 @@ vbo_exec_bind_arrays( GLcontext *ctx )
          /* override the default array set above */
          exec->vtx.inputs[attr] = &arrays[attr];
 
-         if (exec->vtx.bufferobj->Name) {
+         if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
             /* a real buffer obj: Ptr is an offset, not a pointer*/
             GLsizeiptr offset;
             assert(exec->vtx.bufferobj->Pointer);  /* buf should be mapped */
-            offset = (GLbyte *) data - (GLbyte *) exec->vtx.bufferobj->Pointer;
+            offset = (GLbyte *) data -
+              (GLbyte *) exec->vtx.bufferobj->Pointer +
+              exec->vtx.bufferobj->Offset;
             assert(offset >= 0);
             arrays[attr].Ptr = (void *) offset;
          }
@@ -251,7 +256,7 @@ vbo_exec_vtx_unmap( struct vbo_exec_context *exec )
 {
    GLenum target = GL_ARRAY_BUFFER_ARB;
 
-   if (exec->vtx.bufferobj->Name) {
+   if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
       GLcontext *ctx = exec->ctx;
       
       if (ctx->Driver.FlushMappedBufferRange) {
@@ -282,11 +287,16 @@ void
 vbo_exec_vtx_map( struct vbo_exec_context *exec )
 {
    GLcontext *ctx = exec->ctx;
-   GLenum target = GL_ARRAY_BUFFER_ARB;
-   GLenum access = GL_READ_WRITE_ARB;
-   GLenum usage = GL_STREAM_DRAW_ARB;
+   const GLenum target = GL_ARRAY_BUFFER_ARB;
+   const GLenum access = GL_READ_WRITE_ARB; /* for MapBuffer */
+   const GLenum accessRange = GL_MAP_WRITE_BIT |  /* for MapBufferRange */
+                              GL_MAP_INVALIDATE_RANGE_BIT |
+                              GL_MAP_UNSYNCHRONIZED_BIT |
+                              GL_MAP_FLUSH_EXPLICIT_BIT |
+                              MESA_MAP_NOWAIT_BIT;
+   const GLenum usage = GL_STREAM_DRAW_ARB;
    
-   if (exec->vtx.bufferobj->Name == 0)
+   if (!_mesa_is_bufferobj(exec->vtx.bufferobj))
       return;
 
    if (exec->vtx.buffer_map != NULL) {
@@ -303,10 +313,7 @@ vbo_exec_vtx_map( struct vbo_exec_context *exec )
                                                exec->vtx.buffer_used,
                                                (VBO_VERT_BUFFER_SIZE - 
                                                 exec->vtx.buffer_used),
-                                               (GL_MAP_WRITE_BIT |
-                                                GL_MAP_INVALIDATE_RANGE_BIT | 
-                                                GL_MAP_UNSYNCHRONIZED_BIT | 
-                                                MESA_MAP_NOWAIT_BIT),
+                                               accessRange,
                                                exec->vtx.bufferobj);
       exec->vtx.buffer_ptr = exec->vtx.buffer_map;
    }
@@ -318,8 +325,17 @@ vbo_exec_vtx_map( struct vbo_exec_context *exec )
                              VBO_VERT_BUFFER_SIZE, 
                              NULL, usage, exec->vtx.bufferobj);
 
-      exec->vtx.buffer_map = (GLfloat *)
-         ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj);
+
+      if (ctx->Driver.MapBufferRange)
+         exec->vtx.buffer_map = 
+            (GLfloat *)ctx->Driver.MapBufferRange(ctx, target,
+                                                  0, VBO_VERT_BUFFER_SIZE,
+                                                  accessRange,
+                                                  exec->vtx.bufferobj);
+      if (!exec->vtx.buffer_map)
+         exec->vtx.buffer_map =
+            (GLfloat *)ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj);
+      assert(exec->vtx.buffer_map);
       exec->vtx.buffer_ptr = exec->vtx.buffer_map;
    }
 
@@ -354,7 +370,7 @@ vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
          if (ctx->NewState)
             _mesa_update_state( ctx );
 
-         if (exec->vtx.bufferobj->Name) {
+         if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
             vbo_exec_vtx_unmap( exec );
          }
 
@@ -367,12 +383,13 @@ vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
                                       exec->vtx.prim, 
                                       exec->vtx.prim_count,
                                       NULL,
+                                      GL_TRUE,
                                       0,
                                       exec->vtx.vert_count - 1);
 
         /* If using a real VBO, get new storage -- unless asked not to.
           */
-         if (exec->vtx.bufferobj->Name && !unmap) {
+         if (_mesa_is_bufferobj(exec->vtx.bufferobj) && !unmap) {
             vbo_exec_vtx_map( exec );
          }
       }
@@ -381,12 +398,13 @@ vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
    /* May have to unmap explicitly if we didn't draw:
     */
    if (unmap && 
-       exec->vtx.bufferobj->Name &&
+       _mesa_is_bufferobj(exec->vtx.bufferobj) &&
        exec->vtx.buffer_map) {
       vbo_exec_vtx_unmap( exec );
    }
 
-   if (unmap) 
+
+   if (unmap || exec->vtx.vertex_size == 0)
       exec->vtx.max_vert = 0;
    else
       exec->vtx.max_vert = ((VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) / 
@@ -396,3 +414,6 @@ vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
    exec->vtx.prim_count = 0;
    exec->vtx.vert_count = 0;
 }
+
+
+#endif /* FEATURE_beginend */