5 class UnpackAlignmentTest : public ANGLETest
13 setConfigGreenBits(8);
15 setConfigAlphaBits(8);
16 setConfigDepthBits(24);
25 const std::string vertexShaderSource = SHADER_SOURCE
27 precision highp float;
28 attribute vec4 position;
32 gl_Position = position;
36 const std::string fragmentShaderSource = SHADER_SOURCE
38 uniform sampler2D tex;
42 gl_FragColor = texture2D(tex, vec2(0.0, 1.0));
46 mProgram = compileProgram(vertexShaderSource, fragmentShaderSource);
49 FAIL() << "shader compilation failed.";
53 virtual void TearDown()
55 glDeleteProgram(mProgram);
57 ANGLETest::TearDown();
60 void getPixelSize(GLenum format, GLenum type, unsigned int* size)
64 case GL_UNSIGNED_SHORT_5_5_5_1:
65 case GL_UNSIGNED_SHORT_5_6_5:
66 case GL_UNSIGNED_SHORT_4_4_4_4:
67 *size = sizeof(GLushort);
70 case GL_UNSIGNED_BYTE:
72 unsigned int compCount = 0;
75 case GL_RGBA: compCount = 4; break;
76 case GL_RGB: compCount = 3; break;
77 case GL_LUMINANCE_ALPHA: compCount = 2; break;
78 case GL_LUMINANCE: compCount = 1; break;
79 case GL_ALPHA: compCount = 1; break;
80 FAIL() << "unknown pixel format.";
82 *size = sizeof(GLubyte) * compCount;
86 FAIL() << "unknown pixel type.";
90 bool formatHasRGB(GLenum format)
92 return (format != GL_ALPHA);
95 void testAlignment(int alignment, unsigned int offset, GLenum format, GLenum type)
97 static const unsigned int width = 7;
98 static const unsigned int height = 2;
100 glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
102 GLint readbackAlignment;
103 glGetIntegerv(GL_UNPACK_ALIGNMENT, &readbackAlignment);
104 EXPECT_EQ(alignment, readbackAlignment);
106 std::array<GLubyte, 1024> buf;
107 std::fill(buf.begin(), buf.end(), 0);
109 unsigned int pixelSize;
110 getPixelSize(format, type, &pixelSize);
111 for (unsigned int i = 0; i < pixelSize; i++)
113 buf[offset+i] = 0xFF;
117 glGenTextures(1, &tex);
118 glBindTexture(GL_TEXTURE_2D, tex);
120 glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, &buf[0]);
121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
122 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
125 drawQuad(mProgram, "position", 0.5f);
127 GLubyte expectedRGB = formatHasRGB(format) ? 255 : 0;
128 EXPECT_PIXEL_EQ(0, 0, expectedRGB, expectedRGB, expectedRGB, 255);
130 glDeleteTextures(1, &tex);
136 TEST_F(UnpackAlignmentTest, DefaultAlignment)
138 GLint defaultAlignment;
139 glGetIntegerv(GL_UNPACK_ALIGNMENT, &defaultAlignment);
140 EXPECT_EQ(defaultAlignment, 4);
144 TEST_F(UnpackAlignmentTest, Alignment1RGBAUByte)
146 testAlignment(1, 7 * 4, GL_RGBA, GL_UNSIGNED_BYTE);
149 TEST_F(UnpackAlignmentTest, Alignment1RGBUByte)
151 testAlignment(1, 7 * 3, GL_RGB, GL_UNSIGNED_BYTE);
154 TEST_F(UnpackAlignmentTest, Alignment1RGBAUShort4444)
156 testAlignment(1, 7 * 2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
159 TEST_F(UnpackAlignmentTest, Alignment1RGBAUShort5551)
161 testAlignment(1, 7 * 2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
164 TEST_F(UnpackAlignmentTest, Alignment1RGBAUShort565)
166 testAlignment(1, 7 * 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
169 TEST_F(UnpackAlignmentTest, Alignment1LAUByte)
171 testAlignment(1, 7 * 2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE);
174 TEST_F(UnpackAlignmentTest, Alignment1LUByte)
176 testAlignment(1, 7, GL_LUMINANCE, GL_UNSIGNED_BYTE);
179 TEST_F(UnpackAlignmentTest, Alignment1AUByte)
181 testAlignment(1, 7, GL_ALPHA, GL_UNSIGNED_BYTE);
185 TEST_F(UnpackAlignmentTest, Alignment2RGBAUByte)
187 testAlignment(2, 7 * 4, GL_RGBA, GL_UNSIGNED_BYTE);
190 TEST_F(UnpackAlignmentTest, Alignment2RGBUByte)
192 testAlignment(2, 7 * 3 + 1, GL_RGB, GL_UNSIGNED_BYTE);
195 TEST_F(UnpackAlignmentTest, Alignment2RGBAUShort4444)
197 testAlignment(2, 7 * 2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
200 TEST_F(UnpackAlignmentTest, Alignment2RGBAUShort5551)
202 testAlignment(2, 7 * 2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
205 TEST_F(UnpackAlignmentTest, Alignment2RGBAUShort565)
207 testAlignment(2, 7 * 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
210 TEST_F(UnpackAlignmentTest, Alignment2LAUByte)
212 testAlignment(2, 7 * 2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE);
215 TEST_F(UnpackAlignmentTest, Alignment2LAByte)
217 testAlignment(2, 7 + 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);
220 TEST_F(UnpackAlignmentTest, Alignment2AUByte)
222 testAlignment(2, 7 + 1, GL_ALPHA, GL_UNSIGNED_BYTE);
226 TEST_F(UnpackAlignmentTest, Alignment4RGBAUByte)
228 testAlignment(4, 7 * 4, GL_RGBA, GL_UNSIGNED_BYTE);
231 TEST_F(UnpackAlignmentTest, Alignment4RGBUByte)
233 testAlignment(4, 7 * 3 + 3, GL_RGB, GL_UNSIGNED_BYTE);
236 TEST_F(UnpackAlignmentTest, Alignment4RGBAUShort4444)
238 testAlignment(4, 7 * 2 + 2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
241 TEST_F(UnpackAlignmentTest, Alignment4RGBAUShort5551)
243 testAlignment(4, 7 * 2 + 2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
246 TEST_F(UnpackAlignmentTest, Alignment4RGBAUShort565)
248 testAlignment(4, 7 * 2 + 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
251 TEST_F(UnpackAlignmentTest, Alignment4LAUByte)
253 testAlignment(4, 7 * 2 + 2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE);
256 TEST_F(UnpackAlignmentTest, Alignment4LUByte)
258 testAlignment(4, 7 + 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);
261 TEST_F(UnpackAlignmentTest, Alignment4AUByte)
263 testAlignment(4, 7 + 1, GL_ALPHA, GL_UNSIGNED_BYTE);
267 TEST_F(UnpackAlignmentTest, Alignment8RGBAUByte)
269 testAlignment(8, 7 * 4 + 4, GL_RGBA, GL_UNSIGNED_BYTE);
272 TEST_F(UnpackAlignmentTest, Alignment8RGBUByte)
274 testAlignment(8, 7 * 3 + 3, GL_RGB, GL_UNSIGNED_BYTE);
277 TEST_F(UnpackAlignmentTest, Alignment8RGBAUShort4444)
279 testAlignment(8, 7 * 2 + 2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
282 TEST_F(UnpackAlignmentTest, Alignment8RGBAUShort5551)
284 testAlignment(8, 7 * 2 + 2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
287 TEST_F(UnpackAlignmentTest, Alignment8RGBAUShort565)
289 testAlignment(8, 7 * 2 + 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
292 TEST_F(UnpackAlignmentTest, Alignment8LAUByte)
294 testAlignment(8, 7 * 2 + 2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE);
297 TEST_F(UnpackAlignmentTest, Alignment8LUByte)
299 testAlignment(8, 7 + 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);
302 TEST_F(UnpackAlignmentTest, Alignment8AUByte)
304 testAlignment(8, 7 + 1, GL_ALPHA, GL_UNSIGNED_BYTE);