mesa: generate error if pbo offset is not aligned with the size of specified type
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Mon, 17 Oct 2011 01:57:36 +0000 (09:57 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Wed, 19 Oct 2011 01:25:30 +0000 (09:25 +0800)
v2: quote the spec; explicitly exclude the GL_BITMAP case to make code
    more readable. (comments from Ian)

v3: Cast the offset by GLintptr to remove the compile warning(comments
    from Brian).

    I also found that I should use _mesa_sizeof_packed_type() instead,
    as it includes packed pixel type, like GL_UNSIGNED_SHORT_5_6_5.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/main/pbo.c

index 4e7e6f925ccbc39af83746a86e17ba2c8b0d9dd8..41ff2ff44f930e18b610fc39f5e68ce158305f7d 100644 (file)
@@ -82,6 +82,19 @@ _mesa_validate_pbo_access(GLuint dimensions,
    } else {
       offset = ptr;
       sizeAddr = ((const GLubyte *) 0) + pack->BufferObj->Size;
+      /* The ARB_pixel_buffer_object spec says:
+       *    "INVALID_OPERATION is generated by ColorTable, ColorSubTable,
+       *    ConvolutionFilter2D, ConvolutionFilter1D, SeparableFilter2D,
+       *    TexImage1D, TexImage2D, TexImage3D, TexSubImage1D,
+       *    TexSubImage2D, TexSubImage3D, and DrawPixels if the current
+       *    PIXEL_UNPACK_BUFFER_BINDING_ARB value is non-zero and the data
+       *    parameter is not evenly divisible into the number of basic machine
+       *    units needed to store in memory a datum indicated by the type
+       *    parameter."
+       */
+      if (type != GL_BITMAP &&
+          ((GLintptr)offset % _mesa_sizeof_packed_type(type)))
+         return GL_FALSE;
    }
 
    if (sizeAddr == 0)