OSDN Git Service

Packing fix
authorAlexis Hetu <sugoi@google.com>
Mon, 8 Feb 2016 16:08:03 +0000 (11:08 -0500)
committerAlexis Hétu <sugoi@google.com>
Thu, 18 Feb 2016 16:25:12 +0000 (16:25 +0000)
Unified and fixed packing and unpacking computations.

Change-Id: I1ea2bcf28945a9f105152a6836f11bcb2859750c
Reviewed-on: https://swiftshader-review.googlesource.com/4715
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
src/OpenGL/common/Image.cpp
src/OpenGL/common/Image.hpp
src/OpenGL/libGLESv2/Context.cpp

index ef335b8..81dd0c6 100644 (file)
@@ -1082,6 +1082,12 @@ namespace egl
                return (rawPitch + alignment - 1) & ~(alignment - 1);
        }
 
+       size_t ComputePackingOffset(GLenum format, GLenum type, GLsizei width, GLsizei height, GLint alignment, GLint skipImages, GLint skipRows, GLint skipPixels)
+       {
+               GLsizei pitchB = ComputePitch(width, format, type, alignment);
+               return (skipImages * height + skipRows) * pitchB + skipPixels * ComputePixelSize(format, type);
+       }
+
        inline GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)
        {
                return ComputeCompressedSize(width, 1, format);
@@ -1198,9 +1204,10 @@ namespace egl
 
        void Image::loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const UnpackInfo& unpackInfo, const void *input)
        {
-               GLsizei inputPitch = ComputePitch((unpackInfo.rowLength == 0) ? width : unpackInfo.rowLength, format, type, unpackInfo.alignment);
+               GLsizei inputWidth = (unpackInfo.rowLength == 0) ? width : unpackInfo.rowLength;
+               GLsizei inputPitch = ComputePitch(inputWidth, format, type, unpackInfo.alignment);
                GLsizei inputHeight = (unpackInfo.imageHeight == 0) ? height : unpackInfo.imageHeight;
-               input = ((char*)input) + (unpackInfo.skipImages * inputHeight + unpackInfo.skipRows) * inputPitch + unpackInfo.skipPixels;
+               input = ((char*)input) + ComputePackingOffset(format, type, inputWidth, inputHeight, unpackInfo.alignment, unpackInfo.skipImages, unpackInfo.skipRows, unpackInfo.skipPixels);
                sw::Format selectedInternalFormat = SelectInternalFormat(format, type);
                if(selectedInternalFormat == sw::FORMAT_NULL)
                {
index feabae9..8fa08c1 100644 (file)
@@ -30,6 +30,7 @@ sw::Format ConvertFormatType(GLenum format, GLenum type);
 sw::Format SelectInternalFormat(GLenum format, GLenum type);\r
 GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment);\r
 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);\r
+size_t ComputePackingOffset(GLenum format, GLenum type, GLsizei width, GLsizei height, GLint alignment, GLint skipImages, GLint skipRows, GLint skipPixels);\r
 \r
 class Image : public sw::Surface, public gl::Object\r
 {\r
index 420370d..430c71a 100644 (file)
@@ -3319,10 +3319,11 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
                return error(GL_INVALID_OPERATION);\r
        }\r
 \r
-       GLsizei outputPitch = egl::ComputePitch((mState.packRowLength > 0) ? mState.packRowLength : width, format, type, mState.packAlignment);\r
+       GLsizei outputWidth = (mState.packRowLength > 0) ? mState.packRowLength : width;\r
+       GLsizei outputPitch = egl::ComputePitch(outputWidth, format, type, mState.packAlignment);\r
        GLsizei outputHeight = (mState.packImageHeight == 0) ? height : mState.packImageHeight;\r
        pixels = getPixelPackBuffer() ? (unsigned char*)getPixelPackBuffer()->data() + (ptrdiff_t)pixels : (unsigned char*)pixels;\r
-       pixels = ((char*)pixels) + (mState.packSkipImages * outputHeight + mState.packSkipRows) * outputPitch + mState.packSkipPixels;\r
+       pixels = ((char*)pixels) + egl::ComputePackingOffset(format, type, outputWidth, outputHeight, mState.packAlignment, mState.packSkipImages, mState.packSkipRows, mState.packSkipPixels);\r
 \r
        // Sized query sanity check\r
     if(bufSize)\r
@@ -3341,8 +3342,6 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
         return error(GL_OUT_OF_MEMORY);\r
     }\r
 \r
-       x += mState.packSkipPixels;\r
-       y += mState.packSkipRows;\r
        sw::Rect rect = {x, y, x + width, y + height};\r
        sw::Rect dstRect = { 0, 0, width, height };\r
        rect.clip(0, 0, renderTarget->getWidth(), renderTarget->getHeight());\r