Commit c41e42d4 by Geoff Lang

Early-out of *TexSubImage* calls when the width, height or depth is zero.

BUG=angle:622 Change-Id: I74ef5b684151895b24a15fa8f799a633174622c2 Reviewed-on: https://chromium-review.googlesource.com/197270Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 7faf1a14
......@@ -5178,6 +5178,12 @@ void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint
return;
}
// Zero sized uploads are valid but no-ops
if (width == 0 || height == 0)
{
return;
}
switch (target)
{
case GL_TEXTURE_2D:
......@@ -6224,6 +6230,12 @@ void __stdcall glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint
return;
}
// Zero sized uploads are valid but no-ops
if (width == 0 || height == 0 || depth == 0)
{
return;
}
switch(target)
{
case GL_TEXTURE_3D:
......@@ -6274,6 +6286,12 @@ void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GL
return;
}
// Zero sized copies are valid but no-ops
if (width == 0 || height == 0)
{
return;
}
gl::Framebuffer *framebuffer = context->getReadFramebuffer();
gl::Texture *texture = NULL;
switch (target)
......@@ -6391,6 +6409,12 @@ void __stdcall glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffs
return;
}
// Zero sized uploads are valid but no-ops
if (width == 0 || height == 0)
{
return;
}
switch(target)
{
case GL_TEXTURE_3D:
......
......@@ -328,6 +328,8 @@ bool Image9::copyToStorage(TextureStorageInterface2DArray *storage, int level, G
bool Image9::copyToSurface(IDirect3DSurface9 *destSurface, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
{
ASSERT(width > 0 && height > 0);
if (!destSurface)
return false;
......
......@@ -23,16 +23,53 @@ protected:
EXPECT_GL_NO_ERROR();
ASSERT_GL_NO_ERROR();
const std::string vertexShaderSource = SHADER_SOURCE
(
precision highp float;
attribute vec4 position;
varying vec2 texcoord;
void main()
{
gl_Position = position;
texcoord = (position.xy * 0.5) + 0.5;
}
);
const std::string fragmentShaderSource = SHADER_SOURCE
(
precision highp float;
uniform sampler2D tex;
varying vec2 texcoord;
void main()
{
gl_FragColor = texture2D(tex, texcoord);
}
);
mProgram = compileProgram(vertexShaderSource, fragmentShaderSource);
if (mProgram == 0)
{
FAIL() << "shader compilation failed.";
}
mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
}
virtual void TearDown()
{
glDeleteTextures(1, &mTexture);
glDeleteProgram(mProgram);
ANGLETest::TearDown();
}
GLuint mTexture;
GLuint mProgram;
GLint mTextureUniformLocation;
};
TEST_F(TextureTest, negative_api_subimage)
......@@ -44,3 +81,25 @@ TEST_F(TextureTest, negative_api_subimage)
glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
}
TEST_F(TextureTest, zero_sized_uploads)
{
glBindTexture(GL_TEXTURE_2D, mTexture);
EXPECT_GL_ERROR(GL_NO_ERROR);
// Use the texture first to make sure it's in video memory
glUseProgram(mProgram);
glUniform1i(mTextureUniformLocation, 0);
drawQuad(mProgram, "position", 0.5f);
const GLubyte *pixel[4] = { 0 };
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_GL_NO_ERROR();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_GL_NO_ERROR();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_GL_NO_ERROR();
}
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