summaryrefslogtreecommitdiffstats
path: root/gfx/angle/src/tests/gl_tests/ReadPixelsTest.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-07-18 08:24:24 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-07-18 08:24:24 +0200
commitfc61780b35af913801d72086456f493f63197da6 (patch)
treef85891288a7bd988da9f0f15ae64e5c63f00d493 /gfx/angle/src/tests/gl_tests/ReadPixelsTest.cpp
parent69f7f9e5f1475891ce11cc4f431692f965b0cd30 (diff)
parent50d3e596bbe89c95615f96eb71f6bc5be737a1db (diff)
downloadUXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.gz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.lz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.xz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.zip
Merge commit '50d3e596bbe89c95615f96eb71f6bc5be737a1db' into Basilisk-releasev2018.07.18
# Conflicts: # browser/app/profile/firefox.js # browser/components/preferences/jar.mn
Diffstat (limited to 'gfx/angle/src/tests/gl_tests/ReadPixelsTest.cpp')
-rwxr-xr-xgfx/angle/src/tests/gl_tests/ReadPixelsTest.cpp145
1 files changed, 61 insertions, 84 deletions
diff --git a/gfx/angle/src/tests/gl_tests/ReadPixelsTest.cpp b/gfx/angle/src/tests/gl_tests/ReadPixelsTest.cpp
index 47d2e3dba..2a9fe8e5a 100755
--- a/gfx/angle/src/tests/gl_tests/ReadPixelsTest.cpp
+++ b/gfx/angle/src/tests/gl_tests/ReadPixelsTest.cpp
@@ -32,7 +32,7 @@ class ReadPixelsTest : public ANGLETest
}
};
-// Test out of bounds framebuffer reads.
+// Test out of bounds reads.
TEST_P(ReadPixelsTest, OutOfBounds)
{
// TODO: re-enable once root cause of http://anglebug.com/1413 is fixed
@@ -49,17 +49,26 @@ TEST_P(ReadPixelsTest, OutOfBounds)
GLsizei pixelsWidth = 32;
GLsizei pixelsHeight = 32;
GLint offset = 16;
- std::vector<GLColor> pixels((pixelsWidth + offset) * (pixelsHeight + offset));
+ std::vector<GLubyte> pixels((pixelsWidth + offset) * (pixelsHeight + offset) * 4);
glReadPixels(-offset, -offset, pixelsWidth + offset, pixelsHeight + offset, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
EXPECT_GL_NO_ERROR();
- // Expect that all pixels which fell within the framebuffer are red
for (int y = pixelsHeight / 2; y < pixelsHeight; y++)
{
for (int x = pixelsWidth / 2; x < pixelsWidth; x++)
{
- EXPECT_EQ(GLColor::red, pixels[y * (pixelsWidth + offset) + x]);
+ const GLubyte* pixel = &pixels[0] + ((y * (pixelsWidth + offset) + x) * 4);
+ unsigned int r = static_cast<unsigned int>(pixel[0]);
+ unsigned int g = static_cast<unsigned int>(pixel[1]);
+ unsigned int b = static_cast<unsigned int>(pixel[2]);
+ unsigned int a = static_cast<unsigned int>(pixel[3]);
+
+ // Expect that all pixels which fell within the framebuffer are red
+ EXPECT_EQ(255u, r);
+ EXPECT_EQ(0u, g);
+ EXPECT_EQ(0u, b);
+ EXPECT_EQ(255u, a);
}
}
}
@@ -74,22 +83,16 @@ class ReadPixelsPBOTest : public ReadPixelsTest
ANGLETest::SetUp();
glGenBuffers(1, &mPBO);
- glGenFramebuffers(1, &mFBO);
-
- Reset(4 * getWindowWidth() * getWindowHeight(), 4, 1);
- }
-
- void Reset(GLuint bufferSize, GLuint fboWidth, GLuint fboHeight)
- {
glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO);
- glBufferData(GL_PIXEL_PACK_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW);
+ glBufferData(GL_PIXEL_PACK_BUFFER, 4 * getWindowWidth() * getWindowHeight(), nullptr,
+ GL_STATIC_DRAW);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
- glDeleteTextures(1, &mTexture);
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
- glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, fboWidth, fboHeight);
+ 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);
@@ -106,60 +109,11 @@ class ReadPixelsPBOTest : public ReadPixelsTest
ANGLETest::TearDown();
}
- GLuint mPBO = 0;
- GLuint mTexture = 0;
- GLuint mFBO = 0;
+ GLuint mPBO;
+ GLuint mTexture;
+ GLuint mFBO;
};
-// Test basic usage of PBOs.
-TEST_P(ReadPixelsPBOTest, Basic)
-{
- glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- EXPECT_GL_NO_ERROR();
-
- glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO);
- glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-
- GLvoid *mappedPtr = glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, 32, GL_MAP_READ_BIT);
- GLColor *dataColor = static_cast<GLColor *>(mappedPtr);
- EXPECT_GL_NO_ERROR();
-
- EXPECT_EQ(GLColor::red, dataColor[0]);
-
- glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
- EXPECT_GL_NO_ERROR();
-}
-
-// Test an error is generated when the PBO is too small.
-TEST_P(ReadPixelsPBOTest, PBOTooSmall)
-{
- Reset(4 * 16 * 16 - 1, 16, 16);
-
- glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- EXPECT_GL_NO_ERROR();
-
- glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO);
- glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-
- EXPECT_GL_ERROR(GL_INVALID_OPERATION);
-}
-
-// Test an error is generated when the PBO is mapped.
-TEST_P(ReadPixelsPBOTest, PBOMapped)
-{
- glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- EXPECT_GL_NO_ERROR();
-
- glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO);
- glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, 32, GL_MAP_READ_BIT);
- glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-
- EXPECT_GL_ERROR(GL_INVALID_OPERATION);
-}
-
// Test that binding a PBO to ARRAY_BUFFER works as expected.
TEST_P(ReadPixelsPBOTest, ArrayBufferTarget)
{
@@ -174,10 +128,13 @@ TEST_P(ReadPixelsPBOTest, ArrayBufferTarget)
glBindBuffer(GL_ARRAY_BUFFER, mPBO);
GLvoid *mappedPtr = glMapBufferRange(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT);
- GLColor *dataColor = static_cast<GLColor *>(mappedPtr);
+ unsigned char *dataPtr = static_cast<unsigned char *>(mappedPtr);
EXPECT_GL_NO_ERROR();
- EXPECT_EQ(GLColor::red, dataColor[0]);
+ EXPECT_EQ(255, dataPtr[0]);
+ EXPECT_EQ(0, dataPtr[1]);
+ EXPECT_EQ(0, dataPtr[2]);
+ EXPECT_EQ(255, dataPtr[3]);
glUnmapBuffer(GL_ARRAY_BUFFER);
EXPECT_GL_NO_ERROR();
@@ -209,15 +166,21 @@ TEST_P(ReadPixelsPBOTest, ExistingDataPreserved)
// Read 16x16 region from green backbuffer to PBO at offset 16
glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(16));
- GLvoid *mappedPtr = glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, 32, GL_MAP_READ_BIT);
- GLColor *dataColor = static_cast<GLColor *>(mappedPtr);
+ GLvoid * mappedPtr = glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, 32, GL_MAP_READ_BIT);
+ unsigned char *dataPtr = static_cast<unsigned char *>(mappedPtr);
EXPECT_GL_NO_ERROR();
// Test pixel 0 is red (existing data)
- EXPECT_EQ(GLColor::red, dataColor[0]);
+ EXPECT_EQ(255, dataPtr[0]);
+ EXPECT_EQ(0, dataPtr[1]);
+ EXPECT_EQ(0, dataPtr[2]);
+ EXPECT_EQ(255, dataPtr[3]);
// Test pixel 16 is green (new data)
- EXPECT_EQ(GLColor::green, dataColor[16]);
+ EXPECT_EQ(0, dataPtr[16 * 4 + 0]);
+ EXPECT_EQ(255, dataPtr[16 * 4 + 1]);
+ EXPECT_EQ(0, dataPtr[16 * 4 + 2]);
+ EXPECT_EQ(255, dataPtr[16 * 4 + 3]);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
EXPECT_GL_NO_ERROR();
@@ -239,11 +202,14 @@ TEST_P(ReadPixelsPBOTest, SubDataPreservesContents)
glBindBuffer(GL_ARRAY_BUFFER, mPBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, 4, data);
- GLvoid *mappedPtr = glMapBufferRange(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT);
- GLColor *dataColor = static_cast<GLColor *>(mappedPtr);
+ GLvoid *mappedPtr = glMapBufferRange(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT);
+ unsigned char *dataPtr = static_cast<unsigned char *>(mappedPtr);
EXPECT_GL_NO_ERROR();
- EXPECT_EQ(GLColor(1, 2, 3, 4), dataColor[0]);
+ EXPECT_EQ(1, dataPtr[0]);
+ EXPECT_EQ(2, dataPtr[1]);
+ EXPECT_EQ(3, dataPtr[2]);
+ EXPECT_EQ(4, dataPtr[3]);
glUnmapBuffer(GL_ARRAY_BUFFER);
EXPECT_GL_NO_ERROR();
@@ -272,12 +238,19 @@ TEST_P(ReadPixelsPBOTest, SubDataOffsetPreservesContents)
glBindBuffer(GL_ARRAY_BUFFER, mPBO);
glBufferSubData(GL_ARRAY_BUFFER, 16, 4, data);
- GLvoid *mappedPtr = glMapBufferRange(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT);
- GLColor *dataColor = static_cast<GLColor *>(mappedPtr);
+ GLvoid *mappedPtr = glMapBufferRange(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT);
+ unsigned char *dataPtr = static_cast<unsigned char *>(mappedPtr);
EXPECT_GL_NO_ERROR();
- EXPECT_EQ(GLColor::red, dataColor[0]);
- EXPECT_EQ(GLColor(1, 2, 3, 4), dataColor[4]);
+ EXPECT_EQ(255, dataPtr[0]);
+ EXPECT_EQ(0, dataPtr[1]);
+ EXPECT_EQ(0, dataPtr[2]);
+ EXPECT_EQ(255, dataPtr[3]);
+
+ EXPECT_EQ(1, dataPtr[16]);
+ EXPECT_EQ(2, dataPtr[17]);
+ EXPECT_EQ(3, dataPtr[18]);
+ EXPECT_EQ(4, dataPtr[19]);
glUnmapBuffer(GL_ARRAY_BUFFER);
EXPECT_GL_NO_ERROR();
@@ -331,9 +304,10 @@ class ReadPixelsPBODrawTest : public ReadPixelsPBOTest
// Test that we can draw with PBO data.
TEST_P(ReadPixelsPBODrawTest, DrawWithPBO)
{
- GLColor color(1, 2, 3, 4);
+ unsigned char data[4] = { 1, 2, 3, 4 };
+
glBindTexture(GL_TEXTURE_2D, mTexture);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
EXPECT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, mFBO);
@@ -370,11 +344,14 @@ TEST_P(ReadPixelsPBODrawTest, DrawWithPBO)
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
- color = GLColor(0, 0, 0, 0);
- glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color);
+ memset(data, 0, 4);
+ glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
EXPECT_GL_NO_ERROR();
- EXPECT_EQ(GLColor(1, 2, 3, 4), color);
+ EXPECT_EQ(1, data[0]);
+ EXPECT_EQ(2, data[1]);
+ EXPECT_EQ(3, data[2]);
+ EXPECT_EQ(4, data[3]);
}
class ReadPixelsMultisampleTest : public ReadPixelsTest