Commit 950e1a4d by Geoff Lang Committed by Commit Bot

GL: Reset the pixel unpack state after initializing texture data.

Texture data initialization happens after dirty bit synchronization so TextureGL::initializeContents must be careful to leave the applied state the same way it found it. BUG=angleproject:3703 Change-Id: I1647cfc59c45fd9fad0fcde2e37af831e56f2e57 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1704215Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent f92fc916
...@@ -1736,6 +1736,11 @@ angle::Result TextureGL::initializeContents(const gl::Context *context, ...@@ -1736,6 +1736,11 @@ angle::Result TextureGL::initializeContents(const gl::Context *context,
} }
} }
// Reset the pixel unpack state. Because this call is made after synchronizing dirty bits in a
// glTexImage call, we need to make sure that the texture data to be uploaded later has the
// expected unpack state.
stateManager->setPixelUnpackState(context->getState().getUnpackState());
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -937,6 +937,35 @@ TEST_P(RobustResourceInitTest, Texture) ...@@ -937,6 +937,35 @@ TEST_P(RobustResourceInitTest, Texture)
checkFramebufferNonZeroPixels(0, 0, 0, 0, GLColor::black); checkFramebufferNonZeroPixels(0, 0, 0, 0, GLColor::black);
} }
// Test that uploading texture data with an unpack state set correctly initializes the texture and
// the data is uploaded correctly.
TEST_P(RobustResourceInitTest, TextureWithUnpackState)
{
ANGLE_SKIP_TEST_IF(!hasGLExtension());
// GL_UNPACK_ROW_LENGTH requires ES 3.0 or GL_EXT_unpack_subimage
ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
!EnsureGLExtensionEnabled("GL_EXT_unpack_subimage"));
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
// Upload a 2x2 rect using GL_UNPACK_ROW_LENGTH=4
GLColor colorData[8] = {
GLColor::green, GLColor::green, GLColor::red, GLColor::red,
GLColor::green, GLColor::green, GLColor::red, GLColor::red,
};
glPixelStorei(GL_UNPACK_ROW_LENGTH, 4);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, colorData);
GLFramebuffer framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
checkFramebufferNonZeroPixels(0, 0, 2, 2, GLColor::green);
}
template <typename PixelT> template <typename PixelT>
void RobustResourceInitTestES3::testIntegerTextureInit(const char *samplerType, void RobustResourceInitTestES3::testIntegerTextureInit(const char *samplerType,
GLenum internalFormatRGBA, GLenum internalFormatRGBA,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment