mesa: use new _mesa_map_pbo_source/dest() functions in more places
[mesa.git] / src / mesa / main / colortab.c
index b05c0513aa6cff2765084fb38ebb765d75f9d2a0..91c29882ecc831fe8751c49790445b18d90e4aa4 100644 (file)
@@ -179,27 +179,22 @@ store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
                         GLfloat bScale, GLfloat bBias,
                         GLfloat aScale, GLfloat aBias)
 {
-   if (ctx->Unpack.BufferObj->Name) {
-      /* Get/unpack the color table data from a PBO */
-      GLubyte *buf;
-      if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1,
-                                     format, type, data)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glColor[Sub]Table(bad PBO access)");
-         return;
-      }
-      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
-                                              GL_READ_ONLY_ARB,
-                                              ctx->Unpack.BufferObj);
-      if (!buf) {
+   if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1,
+                                  format, type, data)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glColor[Sub]Table(bad PBO access)");
+      return;
+   }
+
+   data = _mesa_map_pbo_source(ctx, &ctx->Unpack, data);
+   if (!data) {
+      if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glColor[Sub]Table(PBO mapped)");
-         return;
       }
-      data = ADD_POINTERS(buf, data);
+      return;
    }
 
-
    {
       /* convert user-provided data to GLfloat values */
       GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
@@ -279,10 +274,7 @@ store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
       }
    }
 
-   if (ctx->Unpack.BufferObj->Name) {
-      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
-                              ctx->Unpack.BufferObj);
-   }
+   _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
 }
 
 
@@ -696,34 +688,27 @@ _mesa_GetColorTable( GLenum target, GLenum format,
       return;
    }
 
-   if (ctx->Pack.BufferObj->Name) {
-      /* pack color table into PBO */
-      GLubyte *buf;
-      if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
-                                     format, type, data)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glGetColorTable(invalid PBO access)");
-         return;
-      }
-      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                                              GL_WRITE_ONLY_ARB,
-                                              ctx->Pack.BufferObj);
-      if (!buf) {
+   if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
+                                  format, type, data)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGetColorTable(invalid PBO access)");
+      return;
+   }
+
+   data = _mesa_map_pbo_dest(ctx, &ctx->Pack, data);
+   if (!data) {
+      if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
          /* buffer is already mapped - that's an error */
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glGetColorTable(PBO is mapped)");
-         return;
       }
-      data = ADD_POINTERS(buf, data);
+      return;
    }
 
    _mesa_pack_rgba_span_float(ctx, table->Size, rgba,
-                              format, type, data, &ctx->Pack, 0x0, GL_FALSE);
+                              format, type, data, &ctx->Pack, 0x0);
 
-   if (ctx->Pack.BufferObj->Name) {
-      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                              ctx->Pack.BufferObj);
-   }
+   _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
 }