Geoff Lang | f11dbdb | 2013-10-23 14:37:58 -0400 | [diff] [blame] | 1 | #include "ANGLETest.h" |
| 2 | |
| 3 | class ReadPixelsTest : public ANGLETest |
| 4 | { |
| 5 | protected: |
| 6 | ReadPixelsTest() |
| 7 | { |
| 8 | setWindowWidth(32); |
| 9 | setWindowHeight(32); |
| 10 | setConfigRedBits(8); |
| 11 | setConfigGreenBits(8); |
| 12 | setConfigBlueBits(8); |
| 13 | setConfigAlphaBits(8); |
| 14 | } |
| 15 | }; |
| 16 | |
| 17 | TEST_F(ReadPixelsTest, out_of_bounds) |
| 18 | { |
| 19 | glClearColor(1.0f, 0.0f, 0.0f, 1.0f); |
| 20 | glClear(GL_COLOR_BUFFER_BIT); |
| 21 | EXPECT_GL_NO_ERROR(); |
| 22 | |
| 23 | GLsizei pixelsWidth = 32; |
| 24 | GLsizei pixelsHeight = 32; |
Jamie Madill | 1eb5bd7 | 2014-03-28 10:43:39 -0400 | [diff] [blame^] | 25 | GLint offset = 16; |
| 26 | std::vector<GLubyte> pixels((pixelsWidth + offset) * (pixelsHeight + offset) * 4); |
Geoff Lang | f11dbdb | 2013-10-23 14:37:58 -0400 | [diff] [blame] | 27 | |
Jamie Madill | 1eb5bd7 | 2014-03-28 10:43:39 -0400 | [diff] [blame^] | 28 | glReadPixels(-offset, -offset, pixelsWidth + offset, pixelsHeight + offset, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
Geoff Lang | f11dbdb | 2013-10-23 14:37:58 -0400 | [diff] [blame] | 29 | EXPECT_GL_NO_ERROR(); |
| 30 | |
| 31 | for (int y = pixelsHeight / 2; y < pixelsHeight; y++) |
| 32 | { |
| 33 | for (int x = pixelsWidth / 2; x < pixelsWidth; x++) |
| 34 | { |
Jamie Madill | 1eb5bd7 | 2014-03-28 10:43:39 -0400 | [diff] [blame^] | 35 | const GLubyte* pixel = pixels.data() + ((y * (pixelsWidth + offset) + x) * 4); |
| 36 | unsigned int r = static_cast<unsigned int>(pixel[0]); |
| 37 | unsigned int g = static_cast<unsigned int>(pixel[1]); |
| 38 | unsigned int b = static_cast<unsigned int>(pixel[2]); |
| 39 | unsigned int a = static_cast<unsigned int>(pixel[3]); |
Geoff Lang | f11dbdb | 2013-10-23 14:37:58 -0400 | [diff] [blame] | 40 | |
| 41 | // Expect that all pixels which fell within the framebuffer are red |
Jamie Madill | 1eb5bd7 | 2014-03-28 10:43:39 -0400 | [diff] [blame^] | 42 | EXPECT_EQ(255, r); |
| 43 | EXPECT_EQ(0, g); |
| 44 | EXPECT_EQ(0, b); |
| 45 | EXPECT_EQ(255, a); |
Geoff Lang | f11dbdb | 2013-10-23 14:37:58 -0400 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |