mesa/get: fix enum16 big-endian getting.
[mesa.git] / src / mesa / main / pbo.c
index 0c16025320136b33680acba733a4e5301799f84f..7cb463d93fc989944936ae28cc5f16f464c85a38 100644 (file)
 
 
 
+#include "errors.h"
 #include "glheader.h"
 #include "bufferobj.h"
 #include "glformats.h"
 #include "image.h"
-#include "imports.h"
 #include "mtypes.h"
+#include "macros.h"
 #include "pbo.h"
 
 
@@ -78,7 +79,7 @@ _mesa_validate_pbo_access(GLuint dimensions,
       If a PBO is bound, 'ptr' is an offset into the bound PBO.
       In that case 'clientMemSize' is ignored: we just use the PBO's size.
     */
-   if (!_mesa_is_bufferobj(pack->BufferObj)) {
+   if (!pack->BufferObj) {
       offset = 0;
       size = (clientMemSize == INT_MAX) ? UINTPTR_MAX : clientMemSize;
    } else {
@@ -103,6 +104,12 @@ _mesa_validate_pbo_access(GLuint dimensions,
       /* no buffer! */
       return GL_FALSE;
 
+   /* If the size of the image is zero then no pixels are accessed so we
+    * don't need to check anything else.
+    */
+   if (width == 0 || height == 0 || depth == 0)
+      return GL_TRUE;
+
    /* get the offset to the first pixel we'll read/write */
    start = _mesa_image_offset(dimensions, pack, width, height,
                               format, type, 0, 0, 0);
@@ -144,7 +151,7 @@ _mesa_map_pbo_source(struct gl_context *ctx,
 {
    const GLubyte *buf;
 
-   if (_mesa_is_bufferobj(unpack->BufferObj)) {
+   if (unpack->BufferObj) {
       /* unpack from PBO */
       buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0,
                                                   unpack->BufferObj->Size,
@@ -181,7 +188,7 @@ _mesa_validate_pbo_source(struct gl_context *ctx, GLuint dimensions,
 
    if (!_mesa_validate_pbo_access(dimensions, unpack, width, height, depth,
                                   format, type, clientMemSize, ptr)) {
-      if (_mesa_is_bufferobj(unpack->BufferObj)) {
+      if (unpack->BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "%s(out of bounds PBO access)",
                      where);
@@ -193,7 +200,7 @@ _mesa_validate_pbo_source(struct gl_context *ctx, GLuint dimensions,
       return false;
    }
 
-   if (!_mesa_is_bufferobj(unpack->BufferObj)) {
+   if (!unpack->BufferObj) {
       /* non-PBO access: no further validation to be done */
       return true;
    }
@@ -218,7 +225,7 @@ _mesa_validate_pbo_source_compressed(struct gl_context *ctx, GLuint dimensions,
                                      GLsizei imageSize, const GLvoid *pixels,
                                      const char *where)
 {
-   if (!_mesa_is_bufferobj(unpack->BufferObj)) {
+   if (!unpack->BufferObj) {
       /* not using a PBO */
       return true;
    }
@@ -277,7 +284,7 @@ _mesa_unmap_pbo_source(struct gl_context *ctx,
                        const struct gl_pixelstore_attrib *unpack)
 {
    assert(unpack != &ctx->Pack); /* catch pack/unpack mismatch */
-   if (_mesa_is_bufferobj(unpack->BufferObj)) {
+   if (unpack->BufferObj) {
       ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj, MAP_INTERNAL);
    }
 }
@@ -298,7 +305,7 @@ _mesa_map_pbo_dest(struct gl_context *ctx,
 {
    void *buf;
 
-   if (_mesa_is_bufferobj(pack->BufferObj)) {
+   if (pack->BufferObj) {
       /* pack into PBO */
       buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0,
                                                   pack->BufferObj->Size,
@@ -339,7 +346,7 @@ _mesa_map_validate_pbo_dest(struct gl_context *ctx,
 
    if (!_mesa_validate_pbo_access(dimensions, unpack, width, height, depth,
                                   format, type, clientMemSize, ptr)) {
-      if (_mesa_is_bufferobj(unpack->BufferObj)) {
+      if (unpack->BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "%s(out of bounds PBO access)", where);
       } else {
@@ -350,7 +357,7 @@ _mesa_map_validate_pbo_dest(struct gl_context *ctx,
       return NULL;
    }
 
-   if (!_mesa_is_bufferobj(unpack->BufferObj)) {
+   if (!unpack->BufferObj) {
       /* non-PBO access: no further validation to be done */
       return ptr;
    }
@@ -374,7 +381,7 @@ _mesa_unmap_pbo_dest(struct gl_context *ctx,
                      const struct gl_pixelstore_attrib *pack)
 {
    assert(pack != &ctx->Unpack); /* catch pack/unpack mismatch */
-   if (_mesa_is_bufferobj(pack->BufferObj)) {
+   if (pack->BufferObj) {
       ctx->Driver.UnmapBuffer(ctx, pack->BufferObj, MAP_INTERNAL);
    }
 }
@@ -395,7 +402,7 @@ _mesa_validate_pbo_teximage(struct gl_context *ctx, GLuint dimensions,
 {
    GLubyte *buf;
 
-   if (!_mesa_is_bufferobj(unpack->BufferObj)) {
+   if (!unpack->BufferObj) {
       /* no PBO */
       return pixels;
    }
@@ -443,7 +450,7 @@ _mesa_validate_pbo_compressed_teximage(struct gl_context *ctx,
       return NULL;
    }
 
-   if (!_mesa_is_bufferobj(packing->BufferObj)) {
+   if (!packing->BufferObj) {
       /* not using a PBO - return pointer unchanged */
       return pixels;
    }
@@ -471,7 +478,7 @@ void
 _mesa_unmap_teximage_pbo(struct gl_context *ctx,
                          const struct gl_pixelstore_attrib *unpack)
 {
-   if (_mesa_is_bufferobj(unpack->BufferObj)) {
+   if (unpack->BufferObj) {
       ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj, MAP_INTERNAL);
    }
 }