Commit 138064f5 by Martin Radev Committed by Commit Bot

Improve glCopyTexSubImage2D and glReadPixels validation

glCopyTexSubImage2d and glReadPixels should generate a GL_INVALID_OPERATION when GL_NONE is specified as a color buffer. There are two tests added which cover glCopyTexSubImage2D and glReadPixels. BUG=angleproject:1445 TEST=angle_end2end_tests Change-Id: I3ab1428aad7eee96ca2330909e2b6f765f539705 Reviewed-on: https://chromium-review.googlesource.com/360860Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 1be913cf
......@@ -1103,6 +1103,13 @@ bool ValidateReadPixels(ValidationContext *context,
const Framebuffer *framebuffer = context->getGLState().getReadFramebuffer();
ASSERT(framebuffer);
if (framebuffer->getReadBufferState() == GL_NONE)
{
context->handleError(Error(GL_INVALID_OPERATION, "Read buffer is GL_NONE"));
return false;
}
const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer();
if (!readBuffer)
{
......@@ -1599,6 +1606,13 @@ bool ValidateStateQuery(ValidationContext *context,
const Framebuffer *framebuffer = context->getGLState().getReadFramebuffer();
ASSERT(framebuffer);
if (framebuffer->getReadBufferState() == GL_NONE)
{
context->handleError(Error(GL_INVALID_OPERATION, "Read buffer is GL_NONE"));
return false;
}
const FramebufferAttachment *attachment = framebuffer->getReadColorbuffer();
if (!attachment)
{
......@@ -1674,6 +1688,12 @@ bool ValidateCopyTexImageParametersBase(ValidationContext *context,
return false;
}
if (readFramebuffer->getReadBufferState() == GL_NONE)
{
context->handleError(Error(GL_INVALID_OPERATION, "Read buffer is GL_NONE"));
return false;
}
const gl::Caps &caps = context->getCaps();
GLuint maxDimension = 0;
......
......@@ -298,6 +298,39 @@ TEST_P(CopyTexImageTest, SubImageRGBToL)
verifyResults(tex, expected1, 7, 7);
}
// specialization of CopyTexImageTest is added so that some tests can be explicitly run with an ES3
// context
class CopyTexImageTestES3 : public CopyTexImageTest
{
};
/*
The test verifies that glCopyTexSubImage2D generates a GL_INVALID_OPERATION error
when the read buffer is GL_NONE.
Reference: GLES 3.0.4, Section 3.8.5 Alternate Texture Image Specification Commands
*/
TEST_P(CopyTexImageTestES3, ReadBufferIsNone)
{
GLfloat color[] = {
0.25f, 1.0f, 0.75f, 0.5f,
};
GLuint fbo = createFramebuffer(GL_RGBA, GL_UNSIGNED_BYTE, color);
GLuint tex = createTextureFromCopyTexImage(fbo, GL_RGBA);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glBindTexture(GL_TEXTURE_2D, tex);
glReadBuffer(GL_NONE);
EXPECT_GL_NO_ERROR();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glDeleteFramebuffers(1, &fbo);
glDeleteTextures(1, &tex);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST(CopyTexImageTest,
......@@ -307,4 +340,6 @@ ANGLE_INSTANTIATE_TEST(CopyTexImageTest,
ES2_OPENGL(),
ES2_OPENGL(3, 3),
ES2_OPENGLES());
ANGLE_INSTANTIATE_TEST(CopyTexImageTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
}
......@@ -642,6 +642,54 @@ TEST_P(ReadPixelsTextureTest, MipLayerAttachment2DArrayPBO)
testPBORead(GL_TEXTURE_2D_ARRAY, 2, 1, 1);
}
// a test class to be used for error checking of glReadPixels
class ReadPixelsErrorTest : public ReadPixelsTest
{
protected:
ReadPixelsErrorTest() : mTexture(0), mFBO(0) {}
void SetUp() override
{
ANGLETest::SetUp();
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 1);
glGenFramebuffers(1, &mFBO);
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ASSERT_GL_NO_ERROR();
}
void TearDown() override
{
ANGLETest::TearDown();
glDeleteTextures(1, &mTexture);
glDeleteFramebuffers(1, &mFBO);
}
GLuint mTexture;
GLuint mFBO;
};
/*
The test verifies that glReadPixels generates a GL_INVALID_OPERATION error
when the read buffer is GL_NONE.
Reference: GLES 3.0.4, Section 4.3.2 Reading Pixels
*/
TEST_P(ReadPixelsErrorTest, ReadBufferIsNone)
{
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
glReadBuffer(GL_NONE);
std::vector<GLubyte> pixels(4);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
} // anonymous namespace
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
......@@ -650,3 +698,4 @@ ANGLE_INSTANTIATE_TEST(ReadPixelsPBOTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLE
ANGLE_INSTANTIATE_TEST(ReadPixelsPBODrawTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
ANGLE_INSTANTIATE_TEST(ReadPixelsMultisampleTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
ANGLE_INSTANTIATE_TEST(ReadPixelsTextureTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
ANGLE_INSTANTIATE_TEST(ReadPixelsErrorTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
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