intel: Transition intel_region_map() to being a miptree operation.
[mesa.git] / src / mesa / vbo / vbo_save_draw.c
index 52952a57ec8135df3cbceac25a7d9b45fb593c3d..efb386e5c93e7544079d0ea29c5b3cccc9b86f77 100644 (file)
@@ -39,9 +39,6 @@
 #include "vbo_context.h"
 
 
-#if FEATURE_dlist
-
-
 /**
  * After playback, copy everything but the position from the
  * last vertex to the saved state
@@ -70,7 +67,7 @@ _playback_copy_to_current(struct gl_context *ctx,
       else
          offset = node->buffer_offset;
 
-      ctx->Driver.GetBufferSubData( ctx, 0, offset, 
+      ctx->Driver.GetBufferSubData( ctx, offset,
                                     node->vertex_size * sizeof(GLfloat), 
                                     data, node->vertex_store->bufferobj );
 
@@ -82,16 +79,20 @@ _playback_copy_to_current(struct gl_context *ctx,
         GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
          GLfloat tmp[4];
 
-         COPY_CLEAN_4V(tmp, 
-                       node->attrsz[i], 
-                       data);
+         COPY_CLEAN_4V_TYPE_AS_FLOAT(tmp,
+                                     node->attrsz[i],
+                                     data,
+                                     node->attrtype[i]);
          
-         if (memcmp(current, tmp, 4 * sizeof(GLfloat)) != 0) {
+         if (node->attrtype[i] != vbo->currval[i].Type ||
+             memcmp(current, tmp, 4 * sizeof(GLfloat)) != 0) {
             memcpy(current, tmp, 4 * sizeof(GLfloat));
 
             vbo->currval[i].Size = node->attrsz[i];
-            assert(vbo->currval[i].Type == GL_FLOAT);
             vbo->currval[i]._ElementSize = vbo->currval[i].Size * sizeof(GLfloat);
+            vbo->currval[i].Type = node->attrtype[i];
+            vbo->currval[i].Integer =
+                  vbo_attrtype_to_integer_flag(node->attrtype[i]);
 
             if (i >= VBO_ATTRIB_FIRST_MATERIAL &&
                 i <= VBO_ATTRIB_LAST_MATERIAL)
@@ -137,32 +138,33 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
    const GLuint *map;
    GLuint attr;
    GLubyte node_attrsz[VBO_ATTRIB_MAX];  /* copy of node->attrsz[] */
-   GLbitfield varying_inputs = 0x0;
+   GLenum node_attrtype[VBO_ATTRIB_MAX];  /* copy of node->attrtype[] */
+   GLbitfield64 varying_inputs = 0x0;
 
    memcpy(node_attrsz, node->attrsz, sizeof(node->attrsz));
+   memcpy(node_attrtype, node->attrtype, sizeof(node->attrtype));
 
    /* Install the default (ie Current) attributes first, then overlay
     * all active ones.
     */
    switch (get_program_mode(ctx)) {
    case VP_NONE:
-      for (attr = 0; attr < 16; attr++) {
-         save->inputs[attr] = &vbo->legacy_currval[attr];
+      for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) {
+         save->inputs[attr] = &vbo->currval[VBO_ATTRIB_POS+attr];
       }
       for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) {
-         save->inputs[attr + 16] = &vbo->mat_currval[attr];
+         save->inputs[VERT_ATTRIB_GENERIC(attr)] =
+            &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT+attr];
       }
       map = vbo->map_vp_none;
       break;
-   case VP_NV:
    case VP_ARB:
-      /* The aliasing of attributes for NV vertex programs has already
-       * occurred.  NV vertex programs cannot access material values,
-       * nor attributes greater than VERT_ATTRIB_TEX7.  
-       */
-      for (attr = 0; attr < 16; attr++) {
-         save->inputs[attr] = &vbo->legacy_currval[attr];
-         save->inputs[attr + 16] = &vbo->generic_currval[attr];
+      for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) {
+         save->inputs[attr] = &vbo->currval[VBO_ATTRIB_POS+attr];
+      }
+      for (attr = 0; attr < VERT_ATTRIB_GENERIC_MAX; attr++) {
+         save->inputs[VERT_ATTRIB_GENERIC(attr)] =
+            &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
       }
       map = vbo->map_vp_arb;
 
@@ -172,8 +174,9 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
        */
       if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
           (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
-         save->inputs[16] = save->inputs[0];
-         node_attrsz[16] = node_attrsz[0];
+         save->inputs[VERT_ATTRIB_GENERIC0] = save->inputs[0];
+         node_attrsz[VERT_ATTRIB_GENERIC0] = node_attrsz[0];
+         node_attrtype[VERT_ATTRIB_GENERIC0] = node_attrtype[0];
          node_attrsz[0] = 0;
       }
       break;
@@ -189,10 +192,12 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
          save->inputs[attr] = &arrays[attr];
 
         arrays[attr].Ptr = (const GLubyte *) NULL + buffer_offset;
-        arrays[attr].Size = node->attrsz[src];
+        arrays[attr].Size = node_attrsz[src];
         arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat);
         arrays[attr].Stride = node->vertex_size * sizeof(GLfloat);
-        arrays[attr].Type = GL_FLOAT;
+         arrays[attr].Type = node_attrtype[src];
+         arrays[attr].Integer =
+               vbo_attrtype_to_integer_flag(node_attrtype[src]);
          arrays[attr].Format = GL_RGBA;
         arrays[attr].Enabled = 1;
          arrays[attr]._ElementSize = arrays[attr].Size * sizeof(GLfloat);
@@ -203,13 +208,13 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
         
         assert(arrays[attr].BufferObj->Name);
 
-        buffer_offset += node->attrsz[src] * sizeof(GLfloat);
-         varying_inputs |= 1<<attr;
-         ctx->NewState |= _NEW_ARRAY;
+        buffer_offset += node_attrsz[src] * sizeof(GLfloat);
+         varying_inputs |= VERT_BIT(attr);
       }
    }
 
    _mesa_set_varying_vp_inputs( ctx, varying_inputs );
+   ctx->NewDriverState |= ctx->DriverFlags.NewArray;
 }
 
 
@@ -217,9 +222,11 @@ static void
 vbo_save_loopback_vertex_list(struct gl_context *ctx,
                               const struct vbo_save_vertex_list *list)
 {
-   const char *buffer = ctx->Driver.MapBuffer(ctx, 
-                                             GL_READ_ONLY, /* ? */
-                                              list->vertex_store->bufferobj);
+   const char *buffer =
+      ctx->Driver.MapBufferRange(ctx, 0,
+                                list->vertex_store->bufferobj->Size,
+                                GL_MAP_READ_BIT, /* ? */
+                                list->vertex_store->bufferobj);
 
    vbo_loopback_vertex_list(ctx,
                             (const GLfloat *)(buffer + list->buffer_offset),
@@ -244,6 +251,19 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
    const struct vbo_save_vertex_list *node =
       (const struct vbo_save_vertex_list *) data;
    struct vbo_save_context *save = &vbo_context(ctx)->save;
+   GLboolean remap_vertex_store = GL_FALSE;
+
+   if (save->vertex_store->buffer) {
+      /* The vertex store is currently mapped but we're about to replay
+       * a display list.  This can happen when a nested display list is
+       * being build with GL_COMPILE_AND_EXECUTE.
+       * We never want to have mapped vertex buffers when we're drawing.
+       * Unmap the vertex store, execute the list, then remap the vertex
+       * store.
+       */
+      vbo_save_unmap_vertex_store(ctx, save->vertex_store);
+      remap_vertex_store = GL_TRUE;
+   }
 
    FLUSH_CURRENT(ctx, 0);
 
@@ -259,14 +279,16 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
            printf("displaylist recursive begin");
 
         vbo_save_loopback_vertex_list( ctx, node );
-        return;
+
+         goto end;
       }
       else if (save->replay_flags) {
         /* Various degnerate cases: translate into immediate mode
          * calls rather than trying to execute in place.
          */
         vbo_save_loopback_vertex_list( ctx, node );
-        return;
+
+         goto end;
       }
       
       if (ctx->NewState)
@@ -282,6 +304,8 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
 
       vbo_bind_vertex_list( ctx, node );
 
+      vbo_draw_method(vbo_context(ctx), DRAW_DISPLAY_LIST);
+
       /* Again...
        */
       if (ctx->NewState)
@@ -289,20 +313,22 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
 
       if (node->count > 0) {
          vbo_context(ctx)->draw_prims(ctx, 
-                                      save->inputs, 
-                                      node->prim, 
+                                      node->prim,
                                       node->prim_count,
                                       NULL,
                                       GL_TRUE,
                                       0,    /* Node is a VBO, so this is ok */
-                                      node->count - 1);
+                                      node->count - 1,
+                                      NULL);
       }
    }
 
    /* Copy to current?
     */
    _playback_copy_to_current( ctx, node );
-}
 
-
-#endif /* FEATURE_dlist */
+end:
+   if (remap_vertex_store) {
+      save->buffer_ptr = vbo_save_map_vertex_store(ctx, save->vertex_store);
+   }
+}