Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / vbo / vbo_exec_draw.c
index d76c45f356069b3365dedda7908e460063f57bf1..71ac0066cac5c164a3adff0f2102e09d0d818f6a 100644 (file)
 
 #include "main/glheader.h"
 #include "main/bufferobj.h"
-#include "main/context.h"
+#include "main/compiler.h"
 #include "main/enums.h"
 #include "main/state.h"
-#include "main/macros.h"
 
 #include "vbo_context.h"
 
 
+#if FEATURE_beginend
+
+
 static void
 vbo_exec_debug_verts( struct vbo_exec_context *exec )
 {
    GLuint count = exec->vtx.vert_count;
    GLuint i;
 
-   _mesa_printf("%s: %u vertices %d primitives, %d vertsize\n",
-               __FUNCTION__,
-               count,
-               exec->vtx.prim_count,
-               exec->vtx.vertex_size);
+   printf("%s: %u vertices %d primitives, %d vertsize\n",
+         __FUNCTION__,
+         count,
+         exec->vtx.prim_count,
+         exec->vtx.vertex_size);
 
    for (i = 0 ; i < exec->vtx.prim_count ; i++) {
       struct _mesa_prim *prim = &exec->vtx.prim[i];
-      _mesa_printf("   prim %d: %s%s %d..%d %s %s\n",
-                  i, 
-                  _mesa_lookup_prim_by_nr(prim->mode),
-                  prim->weak ? " (weak)" : "",
-                  prim->start, 
-                  prim->start + prim->count,
-                  prim->begin ? "BEGIN" : "(wrap)",
-                  prim->end ? "END" : "(wrap)");
+      printf("   prim %d: %s%s %d..%d %s %s\n",
+            i, 
+            _mesa_lookup_prim_by_nr(prim->mode),
+            prim->weak ? " (weak)" : "",
+            prim->start, 
+            prim->start + prim->count,
+            prim->begin ? "BEGIN" : "(wrap)",
+            prim->end ? "END" : "(wrap)");
    }
 }
 
@@ -83,24 +85,24 @@ vbo_copy_vertices( struct vbo_exec_context *exec )
    case GL_LINES:
       ovf = nr&1;
       for (i = 0 ; i < ovf ; i++)
-        _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+        memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
       return i;
    case GL_TRIANGLES:
       ovf = nr%3;
       for (i = 0 ; i < ovf ; i++)
-        _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+        memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
       return i;
    case GL_QUADS:
       ovf = nr&3;
       for (i = 0 ; i < ovf ; i++)
-        _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+        memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
       return i;
    case GL_LINE_STRIP:
       if (nr == 0) {
         return 0;
       }
       else {
-        _mesa_memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) );
+        memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) );
         return 1;
       }
    case GL_LINE_LOOP:
@@ -110,12 +112,12 @@ vbo_copy_vertices( struct vbo_exec_context *exec )
         return 0;
       }
       else if (nr == 1) {
-        _mesa_memcpy( dst, src+0, sz * sizeof(GLfloat) );
+        memcpy( dst, src+0, sz * sizeof(GLfloat) );
         return 1;
       }
       else {
-        _mesa_memcpy( dst, src+0, sz * sizeof(GLfloat) );
-        _mesa_memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) );
+        memcpy( dst, src+0, sz * sizeof(GLfloat) );
+        memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) );
         return 2;
       }
    case GL_TRIANGLE_STRIP:
@@ -137,7 +139,7 @@ vbo_copy_vertices( struct vbo_exec_context *exec )
          break;
       }
       for (i = 0 ; i < ovf ; i++)
-        _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+        memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
       return i;
    case PRIM_OUTSIDE_BEGIN_END:
       return 0;
@@ -152,7 +154,7 @@ vbo_copy_vertices( struct vbo_exec_context *exec )
 /* TODO: populate these as the vertex is defined:
  */
 static void
-vbo_exec_bind_arrays( GLcontext *ctx )
+vbo_exec_bind_arrays( struct gl_context *ctx )
 {
    struct vbo_context *vbo = vbo_context(ctx);
    struct vbo_exec_context *exec = &vbo->exec;
@@ -172,6 +174,7 @@ vbo_exec_bind_arrays( GLcontext *ctx )
          exec->vtx.inputs[attr] = &vbo->legacy_currval[attr];
       }
       for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) {
+         ASSERT(attr + 16 < Elements(exec->vtx.inputs));
          exec->vtx.inputs[attr + 16] = &vbo->mat_currval[attr];
       }
       map = vbo->map_vp_none;
@@ -184,6 +187,7 @@ vbo_exec_bind_arrays( GLcontext *ctx )
        */
       for (attr = 0; attr < 16; attr++) {
          exec->vtx.inputs[attr] = &vbo->legacy_currval[attr];
+         ASSERT(attr + 16 < Elements(exec->vtx.inputs));
          exec->vtx.inputs[attr + 16] = &vbo->generic_currval[attr];
       }
       map = vbo->map_vp_arb;
@@ -212,13 +216,17 @@ vbo_exec_bind_arrays( GLcontext *ctx )
 
       if (exec->vtx.attrsz[src]) {
          /* override the default array set above */
+         ASSERT(attr < Elements(exec->vtx.inputs));
+         ASSERT(attr < Elements(exec->vtx.arrays)); /* arrays[] */
          exec->vtx.inputs[attr] = &arrays[attr];
 
          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;
          }
@@ -252,7 +260,7 @@ vbo_exec_vtx_unmap( struct vbo_exec_context *exec )
    GLenum target = GL_ARRAY_BUFFER_ARB;
 
    if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
-      GLcontext *ctx = exec->ctx;
+      struct gl_context *ctx = exec->ctx;
       
       if (ctx->Driver.FlushMappedBufferRange) {
          GLintptr offset = exec->vtx.buffer_used - exec->vtx.bufferobj->Offset;
@@ -281,7 +289,7 @@ vbo_exec_vtx_unmap( struct vbo_exec_context *exec )
 void
 vbo_exec_vtx_map( struct vbo_exec_context *exec )
 {
-   GLcontext *ctx = exec->ctx;
+   struct gl_context *ctx = exec->ctx;
    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 */
@@ -335,7 +343,7 @@ vbo_exec_vtx_map( struct vbo_exec_context *exec )
    }
 
    if (0)
-      _mesa_printf("map %d..\n", exec->vtx.buffer_used);
+      printf("map %d..\n", exec->vtx.buffer_used);
 }
 
 
@@ -355,7 +363,7 @@ vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
       exec->vtx.copied.nr = vbo_copy_vertices( exec ); 
 
       if (exec->vtx.copied.nr != exec->vtx.vert_count) {
-        GLcontext *ctx = exec->ctx;
+        struct gl_context *ctx = exec->ctx;
         
         /* Before the update_state() as this may raise _NEW_ARRAY
           * from _mesa_set_varying_vp_inputs().
@@ -370,8 +378,8 @@ vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
          }
 
          if (0)
-            _mesa_printf("%s %d %d\n", __FUNCTION__, exec->vtx.prim_count,
-                         exec->vtx.vert_count);
+            printf("%s %d %d\n", __FUNCTION__, exec->vtx.prim_count,
+                  exec->vtx.vert_count);
 
         vbo_context(ctx)->draw_prims( ctx, 
                                       exec->vtx.inputs, 
@@ -398,7 +406,8 @@ vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
       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) / 
@@ -408,3 +417,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 */