Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / vbo / vbo_exec_api.c
index c90565eae8c726912f297ab459ad3b74445f7d61..80ca1d866e7fc9029ede31cc079d196c996d8e58 100644 (file)
@@ -41,7 +41,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/light.h"
 #include "main/api_arrayelt.h"
 #include "main/api_noop.h"
-#include "glapi/dispatch.h"
+#include "main/dispatch.h"
 
 #include "vbo_context.h"
 
@@ -126,8 +126,8 @@ void vbo_exec_vtx_wrap( struct vbo_exec_context *exec )
    assert(exec->vtx.max_vert - exec->vtx.vert_count > exec->vtx.copied.nr);
 
    for (i = 0 ; i < exec->vtx.copied.nr ; i++) {
-      _mesa_memcpy( exec->vtx.buffer_ptr, data, 
-                   exec->vtx.vertex_size * sizeof(GLfloat));
+      memcpy( exec->vtx.buffer_ptr, data, 
+             exec->vtx.vertex_size * sizeof(GLfloat));
       exec->vtx.buffer_ptr += exec->vtx.vertex_size;
       data += exec->vtx.vertex_size;
       exec->vtx.vert_count++;
@@ -142,7 +142,7 @@ void vbo_exec_vtx_wrap( struct vbo_exec_context *exec )
  */
 static void vbo_exec_copy_to_current( struct vbo_exec_context *exec )
 {
-   GLcontext *ctx = exec->ctx;
+   struct gl_context *ctx = exec->ctx;
    struct vbo_context *vbo = vbo_context(ctx);
    GLuint i;
 
@@ -193,7 +193,7 @@ static void vbo_exec_copy_to_current( struct vbo_exec_context *exec )
 
 static void vbo_exec_copy_from_current( struct vbo_exec_context *exec )
 {
-   GLcontext *ctx = exec->ctx;
+   struct gl_context *ctx = exec->ctx;
    struct vbo_context *vbo = vbo_context(ctx);
    GLint i;
 
@@ -217,7 +217,7 @@ static void vbo_exec_wrap_upgrade_vertex( struct vbo_exec_context *exec,
                                          GLuint attr,
                                          GLuint newsz )
 {
-   GLcontext *ctx = exec->ctx;
+   struct gl_context *ctx = exec->ctx;
    struct vbo_context *vbo = vbo_context(ctx);
    GLint lastcount = exec->vtx.vert_count;
    GLfloat *tmp;
@@ -318,7 +318,7 @@ static void vbo_exec_wrap_upgrade_vertex( struct vbo_exec_context *exec,
 }
 
 
-static void vbo_exec_fixup_vertex( GLcontext *ctx,
+static void vbo_exec_fixup_vertex( struct gl_context *ctx,
                                   GLuint attr, GLuint sz )
 {
    struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
@@ -358,10 +358,12 @@ static void vbo_exec_fixup_vertex( GLcontext *ctx,
 #define ATTR( A, N, V0, V1, V2, V3 )                           \
 do {                                                           \
    struct vbo_exec_context *exec = &vbo_context(ctx)->exec;    \
-                                                               \
-   if (exec->vtx.active_sz[A] != N)                            \
-      vbo_exec_fixup_vertex(ctx, A, N);                        \
-                                                               \
+                                                                       \
+   if (unlikely(!(exec->ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT))) \
+      ctx->Driver.BeginVertices( ctx );                                 \
+   if (unlikely(exec->vtx.active_sz[A] != N))                          \
+      vbo_exec_fixup_vertex(ctx, A, N);                                        \
+                                                                       \
    {                                                           \
       GLfloat *dest = exec->vtx.attrptr[A];                    \
       if (N>0) dest[0] = V0;                                   \
@@ -414,13 +416,13 @@ static void GLAPIENTRY vbo_exec_EvalCoord1f( GLfloat u )
    }
 
 
-   _mesa_memcpy( exec->vtx.copied.buffer, exec->vtx.vertex, 
-                 exec->vtx.vertex_size * sizeof(GLfloat));
+   memcpy( exec->vtx.copied.buffer, exec->vtx.vertex, 
+           exec->vtx.vertex_size * sizeof(GLfloat));
 
    vbo_exec_do_EvalCoord1f( exec, u );
 
-   _mesa_memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
-                 exec->vtx.vertex_size * sizeof(GLfloat));
+   memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
+           exec->vtx.vertex_size * sizeof(GLfloat));
 }
 
 static void GLAPIENTRY vbo_exec_EvalCoord2f( GLfloat u, GLfloat v )
@@ -444,13 +446,13 @@ static void GLAPIENTRY vbo_exec_EvalCoord2f( GLfloat u, GLfloat v )
            vbo_exec_fixup_vertex( ctx, VBO_ATTRIB_NORMAL, 3 );
    }
 
-   _mesa_memcpy( exec->vtx.copied.buffer, exec->vtx.vertex, 
-                 exec->vtx.vertex_size * sizeof(GLfloat));
+   memcpy( exec->vtx.copied.buffer, exec->vtx.vertex, 
+           exec->vtx.vertex_size * sizeof(GLfloat));
 
    vbo_exec_do_EvalCoord2f( exec, u, v );
 
-   _mesa_memcpy( exec->vtx.vertex, exec->vtx.copied.buffer, 
-                 exec->vtx.vertex_size * sizeof(GLfloat));
+   memcpy( exec->vtx.vertex, exec->vtx.copied.buffer, 
+           exec->vtx.vertex_size * sizeof(GLfloat));
 }
 
 static void GLAPIENTRY vbo_exec_EvalCoord1fv( const GLfloat *u )
@@ -531,6 +533,7 @@ static void GLAPIENTRY vbo_exec_Begin( GLenum mode )
       exec->vtx.prim[i].pad = 0;
       exec->vtx.prim[i].start = exec->vtx.vert_count;
       exec->vtx.prim[i].count = 0;
+      exec->vtx.prim[i].num_instances = 1;
 
       ctx->Driver.CurrentExecPrimitive = mode;
    }
@@ -739,7 +742,7 @@ static void vbo_exec_vtxfmt_init( struct vbo_exec_context *exec )
  * This replaces the malloced buffer which was created in
  * vb_exec_vtx_init() below.
  */
-void vbo_use_buffer_objects(GLcontext *ctx)
+void vbo_use_buffer_objects(struct gl_context *ctx)
 {
    struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
    /* Any buffer name but 0 can be used here since this bufferobj won't
@@ -759,6 +762,7 @@ void vbo_use_buffer_objects(GLcontext *ctx)
    }
 
    /* Allocate a real buffer object now */
+   _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
    exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, bufName, target);
    ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj);
 }
@@ -767,7 +771,7 @@ void vbo_use_buffer_objects(GLcontext *ctx)
 
 void vbo_exec_vtx_init( struct vbo_exec_context *exec )
 {
-   GLcontext *ctx = exec->ctx;
+   struct gl_context *ctx = exec->ctx;
    struct vbo_context *vbo = vbo_context(ctx);
    GLuint i;
 
@@ -780,7 +784,7 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec )
                                  ctx->Shared->NullBufferObj);
 
    ASSERT(!exec->vtx.buffer_map);
-   exec->vtx.buffer_map = (GLfloat *)ALIGN_MALLOC(VBO_VERT_BUFFER_SIZE, 64);
+   exec->vtx.buffer_map = (GLfloat *)_mesa_align_malloc(VBO_VERT_BUFFER_SIZE, 64);
    exec->vtx.buffer_ptr = exec->vtx.buffer_map;
 
    vbo_exec_vtxfmt_init( exec );
@@ -803,8 +807,19 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec )
    
    {
       struct gl_client_array *arrays = exec->vtx.arrays;
+      unsigned i;
+
       memcpy(arrays,      vbo->legacy_currval,  16 * sizeof(arrays[0]));
       memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
+
+      for (i = 0; i < 16; ++i) {
+         arrays[i     ].BufferObj = NULL;
+         arrays[i + 16].BufferObj = NULL;
+         _mesa_reference_buffer_object(ctx, &arrays[i     ].BufferObj,
+                                       vbo->legacy_currval[i].BufferObj);
+         _mesa_reference_buffer_object(ctx, &arrays[i + 16].BufferObj,
+                                       vbo->generic_currval[i].BufferObj);
+      }
    }
 
    exec->vtx.vertex_size = 0;
@@ -814,7 +829,7 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec )
 void vbo_exec_vtx_destroy( struct vbo_exec_context *exec )
 {
    /* using a real VBO for vertex data */
-   GLcontext *ctx = exec->ctx;
+   struct gl_context *ctx = exec->ctx;
    unsigned i;
 
    /* True VBOs should already be unmapped
@@ -823,7 +838,7 @@ void vbo_exec_vtx_destroy( struct vbo_exec_context *exec )
       ASSERT(exec->vtx.bufferobj->Name == 0 ||
              exec->vtx.bufferobj->Name == IMM_BUFFER_NAME);
       if (exec->vtx.bufferobj->Name == 0) {
-         ALIGN_FREE(exec->vtx.buffer_map);
+         _mesa_align_free(exec->vtx.buffer_map);
          exec->vtx.buffer_map = NULL;
          exec->vtx.buffer_ptr = NULL;
       }
@@ -837,22 +852,25 @@ void vbo_exec_vtx_destroy( struct vbo_exec_context *exec )
                                     NULL);
    }
 
-   /* Free the vertex buffer:
+   /* Free the vertex buffer.  Unmap first if needed.
     */
+   if (_mesa_bufferobj_mapped(exec->vtx.bufferobj)) {
+      ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER, exec->vtx.bufferobj);
+   }
    _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
 }
 
-void vbo_exec_BeginVertices( GLcontext *ctx )
+void vbo_exec_BeginVertices( struct gl_context *ctx )
 {
    struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
-   if (0) _mesa_printf("%s\n", __FUNCTION__);
+   if (0) printf("%s\n", __FUNCTION__);
    vbo_exec_vtx_map( exec );
 
    assert((exec->ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) == 0);
    exec->ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;
 }
 
-void vbo_exec_FlushVertices_internal( GLcontext *ctx, GLboolean unmap )
+void vbo_exec_FlushVertices_internal( struct gl_context *ctx, GLboolean unmap )
 {
    struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
 
@@ -870,23 +888,23 @@ void vbo_exec_FlushVertices_internal( GLcontext *ctx, GLboolean unmap )
 /**
  * \param flags  bitmask of FLUSH_STORED_VERTICES, FLUSH_UPDATE_CURRENT
  */
-void vbo_exec_FlushVertices( GLcontext *ctx, GLuint flags )
+void vbo_exec_FlushVertices( struct gl_context *ctx, GLuint flags )
 {
    struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
 
 #ifdef DEBUG
    /* debug check: make sure we don't get called recursively */
-   static GLuint callDepth = 0;
-   callDepth++;
-   assert(callDepth == 1);
+   exec->flush_call_depth++;
+   assert(exec->flush_call_depth == 1);
 #endif
 
-   if (0) _mesa_printf("%s\n", __FUNCTION__);
+   if (0) printf("%s\n", __FUNCTION__);
 
    if (exec->ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
-      if (0) _mesa_printf("%s - inside begin/end\n", __FUNCTION__);
+      if (0) printf("%s - inside begin/end\n", __FUNCTION__);
 #ifdef DEBUG
-      callDepth--;
+      exec->flush_call_depth--;
+      assert(exec->flush_call_depth == 0);
 #endif
       return;
    }
@@ -895,15 +913,14 @@ void vbo_exec_FlushVertices( GLcontext *ctx, GLuint flags )
 
    /* Need to do this to ensure BeginVertices gets called again:
     */
-   if (exec->ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) {
-      _mesa_restore_exec_vtxfmt( ctx );
+   if (exec->ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT)
       exec->ctx->Driver.NeedFlush &= ~FLUSH_UPDATE_CURRENT;
-   }
 
    exec->ctx->Driver.NeedFlush &= ~flags;
 
 #ifdef DEBUG
-   callDepth--;
+   exec->flush_call_depth--;
+   assert(exec->flush_call_depth == 0);
 #endif
 }
 
@@ -941,6 +958,7 @@ _vbo_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
    vbo_MultiTexCoord4f(target, s, t, r, q);
 }
 
+
 void GLAPIENTRY
 _vbo_Materialfv(GLenum face, GLenum pname, const GLfloat *params)
 {
@@ -948,8 +966,67 @@ _vbo_Materialfv(GLenum face, GLenum pname, const GLfloat *params)
 }
 
 
+void GLAPIENTRY
+_vbo_Materialf(GLenum face, GLenum pname, GLfloat param)
+{
+   GLfloat p[4];
+   p[0] = param;
+   p[1] = p[2] = p[3] = 0.0F;
+   vbo_Materialfv(face, pname, p);
+}
+
+
 void GLAPIENTRY
 _vbo_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
 {
    vbo_VertexAttrib4fARB(index, x, y, z, w);
 }
+
+
+void GLAPIENTRY
+_vbo_VertexAttrib1f(GLuint indx, GLfloat x)
+{
+   vbo_VertexAttrib1fARB(indx, x);
+}
+
+
+void GLAPIENTRY
+_vbo_VertexAttrib1fv(GLuint indx, const GLfloat* values)
+{
+   vbo_VertexAttrib1fvARB(indx, values);
+}
+
+
+void GLAPIENTRY
+_vbo_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
+{
+   vbo_VertexAttrib2fARB(indx, x, y);
+}
+
+
+void GLAPIENTRY
+_vbo_VertexAttrib2fv(GLuint indx, const GLfloat* values)
+{
+   vbo_VertexAttrib2fvARB(indx, values);
+}
+
+
+void GLAPIENTRY
+_vbo_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
+{
+   vbo_VertexAttrib3fARB(indx, x, y, z);
+}
+
+
+void GLAPIENTRY
+_vbo_VertexAttrib3fv(GLuint indx, const GLfloat* values)
+{
+   vbo_VertexAttrib3fvARB(indx, values);
+}
+
+
+void GLAPIENTRY
+_vbo_VertexAttrib4fv(GLuint indx, const GLfloat* values)
+{
+   vbo_VertexAttrib4fvARB(indx, values);
+}