glapi / teximage: implement EGLImageTargetTexStorageEXT
[mesa.git] / src / mesa / main / draw.c
index 99ea4d928bee5526b85a874261c14898fc729af6..bfa318553f680788075d5bd7d3e81e46f33bc1df 100644 (file)
@@ -67,33 +67,28 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
                  GLuint attrib, GLuint j)
 {
    const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
-   if (array->Enabled) {
+   if (vao->Enabled & VERT_BIT(attrib)) {
       const struct gl_vertex_buffer_binding *binding =
          &vao->BufferBinding[array->BufferBindingIndex];
       struct gl_buffer_object *bo = binding->BufferObj;
       const void *data = array->Ptr;
       if (_mesa_is_bufferobj(bo)) {
-         if (!bo->Mappings[MAP_INTERNAL].Pointer) {
-            /* need to map now */
-            bo->Mappings[MAP_INTERNAL].Pointer =
-               ctx->Driver.MapBufferRange(ctx, 0, bo->Size,
-                                          GL_MAP_READ_BIT, bo, MAP_INTERNAL);
-         }
          data = ADD_POINTERS(_mesa_vertex_attrib_address(array, binding),
                              bo->Mappings[MAP_INTERNAL].Pointer);
       }
-      switch (array->Type) {
+      switch (array->Format.Type) {
       case GL_FLOAT:
          {
             GLfloat *f = (GLfloat *) ((GLubyte *) data + binding->Stride * j);
             GLint k;
-            for (k = 0; k < array->Size; k++) {
+            for (k = 0; k < array->Format.Size; k++) {
                if (IS_INF_OR_NAN(f[k]) || f[k] >= 1.0e20F || f[k] <= -1.0e10F) {
                   printf("Bad array data:\n");
                   printf("  Element[%u].%u = %f\n", j, k, f[k]);
                   printf("  Array %u at %p\n", attrib, (void *) array);
                   printf("  Type 0x%x, Size %d, Stride %d\n",
-                         array->Type, array->Size, binding->Stride);
+                         array->Format.Type, array->Format.Size,
+                         binding->Stride);
                   printf("  Address/offset %p in Buffer Object %u\n",
                          array->Ptr, bo->Name);
                   f[k] = 1.0F;  /* XXX replace the bad value! */
@@ -109,25 +104,6 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
 }
 
 
-/**
- * Unmap the buffer object referenced by given array, if mapped.
- */
-static void
-unmap_array_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao,
-                   GLuint attrib)
-{
-   const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
-   if (array->Enabled) {
-      const struct gl_vertex_buffer_binding *binding =
-         &vao->BufferBinding[array->BufferBindingIndex];
-      struct gl_buffer_object *bo = binding->BufferObj;
-      if (_mesa_is_bufferobj(bo) && _mesa_bufferobj_mapped(bo, MAP_INTERNAL)) {
-         ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
-      }
-   }
-}
-
-
 static inline int
 sizeof_ib_type(GLenum type)
 {
@@ -155,17 +131,14 @@ check_draw_elements_data(struct gl_context *ctx, GLsizei count,
                          GLint basevertex)
 {
    struct gl_vertex_array_object *vao = ctx->Array.VAO;
-   const void *elemMap;
    GLint i;
    GLuint k;
 
-   if (_mesa_is_bufferobj(vao->IndexBufferObj)) {
-      elemMap = ctx->Driver.MapBufferRange(ctx, 0,
-                                           vao->IndexBufferObj->Size,
-                                           GL_MAP_READ_BIT,
-                                           vao->IndexBufferObj, MAP_INTERNAL);
-      elements = ADD_POINTERS(elements, elemMap);
-   }
+   _mesa_vao_map(ctx, vao, GL_MAP_READ_BIT);
+
+   if (_mesa_is_bufferobj(vao->IndexBufferObj))
+       elements =
+          ADD_POINTERS(vao->IndexBufferObj->Mappings[MAP_INTERNAL].Pointer, elements);
 
    for (i = 0; i < count; i++) {
       GLuint j;
@@ -191,13 +164,7 @@ check_draw_elements_data(struct gl_context *ctx, GLsizei count,
       }
    }
 
-   if (_mesa_is_bufferobj(vao->IndexBufferObj)) {
-      ctx->Driver.UnmapBuffer(ctx, vao->IndexBufferObj, MAP_INTERNAL);
-   }
-
-   for (k = 0; k < VERT_ATTRIB_MAX; k++) {
-      unmap_array_buffer(ctx, vao, k);
-   }
+   _mesa_vao_unmap(ctx, vao);
 }
 
 
@@ -225,7 +192,7 @@ skip_validated_draw(struct gl_context *ctx)
    case API_OPENGLES:
       /* For OpenGL ES, only draw if we have vertex positions
        */
-      if (!ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled)
+      if (!(ctx->Array.VAO->Enabled & VERT_BIT_POS))
          return true;
       break;
 
@@ -252,8 +219,7 @@ skip_validated_draw(struct gl_context *ctx)
          /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic
           * array [0]).
           */
-         return (!ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled &&
-                 !ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled);
+         return !(ctx->Array.VAO->Enabled & (VERT_BIT_POS|VERT_BIT_GENERIC0));
       }
       break;
 
@@ -272,36 +238,35 @@ static void
 print_draw_arrays(struct gl_context *ctx,
                   GLenum mode, GLint start, GLsizei count)
 {
-   const struct gl_vertex_array_object *vao = ctx->Array.VAO;
+   struct gl_vertex_array_object *vao = ctx->Array.VAO;
 
    printf("_mesa_DrawArrays(mode 0x%x, start %d, count %d):\n",
           mode, start, count);
 
-   unsigned i;
-   for (i = 0; i < VERT_ATTRIB_MAX; ++i) {
+   _mesa_vao_map_arrays(ctx, vao, GL_MAP_READ_BIT);
+
+   GLbitfield mask = vao->Enabled;
+   while (mask) {
+      const gl_vert_attrib i = u_bit_scan(&mask);
       const struct gl_array_attributes *array = &vao->VertexAttrib[i];
-      if (!array->Enabled)
-         continue;
 
       const struct gl_vertex_buffer_binding *binding =
          &vao->BufferBinding[array->BufferBindingIndex];
       struct gl_buffer_object *bufObj = binding->BufferObj;
 
-      printf("attr %s: size %d stride %d  enabled %d  "
+      printf("attr %s: size %d stride %d  "
              "ptr %p  Bufobj %u\n",
              gl_vert_attrib_name((gl_vert_attrib) i),
-             array->Size, binding->Stride, array->Enabled,
+             array->Format.Size, binding->Stride,
              array->Ptr, bufObj->Name);
 
       if (_mesa_is_bufferobj(bufObj)) {
-         GLubyte *p = ctx->Driver.MapBufferRange(ctx, 0, bufObj->Size,
-                                                 GL_MAP_READ_BIT, bufObj,
-                                                 MAP_INTERNAL);
+         GLubyte *p = bufObj->Mappings[MAP_INTERNAL].Pointer;
          int offset = (int) (GLintptr)
             _mesa_vertex_attrib_address(array, binding);
 
          unsigned multiplier;
-         switch (array->Type) {
+         switch (array->Format.Type) {
          case GL_DOUBLE:
          case GL_INT64_ARB:
          case GL_UNSIGNED_INT64_ARB:
@@ -315,7 +280,7 @@ print_draw_arrays(struct gl_context *ctx,
          int *k = (int *) f;
          int i = 0;
          int n = (count - 1) * (binding->Stride / (4 * multiplier))
-           + array->Size;
+            + array->Format.Size;
          if (n > 32)
             n = 32;
          printf("  Data at offset %d:\n", offset);
@@ -327,9 +292,10 @@ print_draw_arrays(struct gl_context *ctx,
                printf("    float[%d] = 0x%08x %f\n", i, k[i], f[i]);
             i++;
          } while (i < n);
-         ctx->Driver.UnmapBuffer(ctx, bufObj, MAP_INTERNAL);
       }
    }
+
+   _mesa_vao_unmap_arrays(ctx, vao);
 }
 
 
@@ -1674,7 +1640,7 @@ _mesa_exec_DrawElementsIndirect(GLenum mode, GLenum type, const GLvoid *indirect
 
          /* Convert offset to pointer */
          void *offset = (void *)
-            ((cmd->firstIndex * _mesa_sizeof_type(type)) & 0xffffffffUL);
+            (uintptr_t)((cmd->firstIndex * _mesa_sizeof_type(type)) & 0xffffffffUL);
 
          _mesa_exec_DrawElementsInstancedBaseVertexBaseInstance(mode, cmd->count,
                                                                 type, offset,
@@ -1733,7 +1699,7 @@ _mesa_exec_MultiDrawArraysIndirect(GLenum mode, const GLvoid *indirect,
                                            "glMultiDrawArraysIndirect"))
          return;
 
-      const ubyte *ptr = (const ubyte *) indirect;
+      const uint8_t *ptr = (const uint8_t *) indirect;
       for (unsigned i = 0; i < primcount; i++) {
          DrawArraysIndirectCommand *cmd = (DrawArraysIndirectCommand *) ptr;
          _mesa_exec_DrawArraysInstancedBaseInstance(mode, cmd->first,
@@ -1815,7 +1781,7 @@ _mesa_exec_MultiDrawElementsIndirect(GLenum mode, GLenum type,
                                            "glMultiDrawArraysIndirect"))
          return;
 
-      const ubyte *ptr = (const ubyte *) indirect;
+      const uint8_t *ptr = (const uint8_t *) indirect;
       for (unsigned i = 0; i < primcount; i++) {
          _mesa_exec_DrawElementsIndirect(mode, type, ptr);