blob: d90122f4d5292baf96865fe148b8220398544803 [file] [log] [blame]
Geoff Langf11dbdb2013-10-23 14:37:58 -04001#include "ANGLETest.h"
2
3class ReadPixelsTest : public ANGLETest
4{
5protected:
6 ReadPixelsTest()
7 {
8 setWindowWidth(32);
9 setWindowHeight(32);
10 setConfigRedBits(8);
11 setConfigGreenBits(8);
12 setConfigBlueBits(8);
13 setConfigAlphaBits(8);
14 }
15};
16
17TEST_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 Madill1eb5bd72014-03-28 10:43:39 -040025 GLint offset = 16;
26 std::vector<GLubyte> pixels((pixelsWidth + offset) * (pixelsHeight + offset) * 4);
Geoff Langf11dbdb2013-10-23 14:37:58 -040027
Jamie Madill1eb5bd72014-03-28 10:43:39 -040028 glReadPixels(-offset, -offset, pixelsWidth + offset, pixelsHeight + offset, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
Geoff Langf11dbdb2013-10-23 14:37:58 -040029 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 Madill1eb5bd72014-03-28 10:43:39 -040035 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 Langf11dbdb2013-10-23 14:37:58 -040040
41 // Expect that all pixels which fell within the framebuffer are red
Jamie Madill1eb5bd72014-03-28 10:43:39 -040042 EXPECT_EQ(255, r);
43 EXPECT_EQ(0, g);
44 EXPECT_EQ(0, b);
45 EXPECT_EQ(255, a);
Geoff Langf11dbdb2013-10-23 14:37:58 -040046 }
47 }
48}