Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 8 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 10 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 11 | namespace |
| 12 | { |
| 13 | |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 14 | class UnpackAlignmentTest : public ANGLETest |
| 15 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 16 | protected: |
| 17 | UnpackAlignmentTest() |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 18 | { |
| 19 | setWindowWidth(128); |
| 20 | setWindowHeight(128); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 21 | setConfigRedBits(8); |
| 22 | setConfigGreenBits(8); |
| 23 | setConfigBlueBits(8); |
| 24 | setConfigAlphaBits(8); |
| 25 | setConfigDepthBits(24); |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 26 | |
| 27 | mProgram = 0; |
| 28 | } |
| 29 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 30 | void SetUp() override |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 31 | { |
| 32 | ANGLETest::SetUp(); |
| 33 | |
| 34 | const std::string vertexShaderSource = SHADER_SOURCE |
| 35 | ( |
| 36 | precision highp float; |
| 37 | attribute vec4 position; |
| 38 | |
| 39 | void main() |
| 40 | { |
| 41 | gl_Position = position; |
| 42 | } |
| 43 | ); |
| 44 | |
| 45 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 46 | ( |
| 47 | uniform sampler2D tex; |
| 48 | |
| 49 | void main() |
| 50 | { |
| 51 | gl_FragColor = texture2D(tex, vec2(0.0, 1.0)); |
| 52 | } |
| 53 | ); |
| 54 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 55 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 56 | if (mProgram == 0) |
| 57 | { |
| 58 | FAIL() << "shader compilation failed."; |
| 59 | } |
| 60 | } |
| 61 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 62 | void TearDown() override |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 63 | { |
| 64 | glDeleteProgram(mProgram); |
| 65 | |
| 66 | ANGLETest::TearDown(); |
| 67 | } |
| 68 | |
| 69 | void getPixelSize(GLenum format, GLenum type, unsigned int* size) |
| 70 | { |
| 71 | switch (type) |
| 72 | { |
| 73 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 74 | case GL_UNSIGNED_SHORT_5_6_5: |
| 75 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 76 | *size = sizeof(GLushort); |
| 77 | break; |
| 78 | |
| 79 | case GL_UNSIGNED_BYTE: |
| 80 | { |
| 81 | unsigned int compCount = 0; |
| 82 | switch (format) |
| 83 | { |
| 84 | case GL_RGBA: compCount = 4; break; |
| 85 | case GL_RGB: compCount = 3; break; |
| 86 | case GL_LUMINANCE_ALPHA: compCount = 2; break; |
| 87 | case GL_LUMINANCE: compCount = 1; break; |
| 88 | case GL_ALPHA: compCount = 1; break; |
Austin Kinross | c8ef69d | 2015-03-18 16:43:22 -0700 | [diff] [blame] | 89 | default: FAIL() << "unknown pixel format."; |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 90 | } |
| 91 | *size = sizeof(GLubyte) * compCount; |
| 92 | } |
| 93 | break; |
| 94 | default: |
| 95 | FAIL() << "unknown pixel type."; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | bool formatHasRGB(GLenum format) |
| 100 | { |
| 101 | return (format != GL_ALPHA); |
| 102 | } |
| 103 | |
| 104 | void testAlignment(int alignment, unsigned int offset, GLenum format, GLenum type) |
| 105 | { |
| 106 | static const unsigned int width = 7; |
| 107 | static const unsigned int height = 2; |
| 108 | |
| 109 | glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); |
| 110 | |
| 111 | GLint readbackAlignment; |
| 112 | glGetIntegerv(GL_UNPACK_ALIGNMENT, &readbackAlignment); |
| 113 | EXPECT_EQ(alignment, readbackAlignment); |
| 114 | |
Corentin Wallez | f0ca9a0 | 2015-09-14 11:53:10 -0700 | [diff] [blame] | 115 | GLubyte buf[1024]; |
| 116 | memset(buf, 0, sizeof(buf)); |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 117 | |
| 118 | unsigned int pixelSize; |
| 119 | getPixelSize(format, type, &pixelSize); |
| 120 | for (unsigned int i = 0; i < pixelSize; i++) |
| 121 | { |
| 122 | buf[offset+i] = 0xFF; |
| 123 | } |
| 124 | |
| 125 | GLuint tex; |
| 126 | glGenTextures(1, &tex); |
| 127 | glBindTexture(GL_TEXTURE_2D, tex); |
| 128 | |
| 129 | glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, &buf[0]); |
| 130 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 131 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 132 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 133 | |
| 134 | drawQuad(mProgram, "position", 0.5f); |
| 135 | |
| 136 | GLubyte expectedRGB = formatHasRGB(format) ? 255 : 0; |
| 137 | EXPECT_PIXEL_EQ(0, 0, expectedRGB, expectedRGB, expectedRGB, 255); |
| 138 | |
| 139 | glDeleteTextures(1, &tex); |
| 140 | } |
| 141 | |
| 142 | GLuint mProgram; |
| 143 | }; |
| 144 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 145 | TEST_P(UnpackAlignmentTest, DefaultAlignment) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 146 | { |
| 147 | GLint defaultAlignment; |
| 148 | glGetIntegerv(GL_UNPACK_ALIGNMENT, &defaultAlignment); |
| 149 | EXPECT_EQ(defaultAlignment, 4); |
| 150 | } |
| 151 | |
| 152 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 153 | TEST_P(UnpackAlignmentTest, Alignment1RGBAUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 154 | { |
| 155 | testAlignment(1, 7 * 4, GL_RGBA, GL_UNSIGNED_BYTE); |
| 156 | } |
| 157 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 158 | TEST_P(UnpackAlignmentTest, Alignment1RGBUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 159 | { |
| 160 | testAlignment(1, 7 * 3, GL_RGB, GL_UNSIGNED_BYTE); |
| 161 | } |
| 162 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 163 | TEST_P(UnpackAlignmentTest, Alignment1RGBAUShort4444) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 164 | { |
| 165 | testAlignment(1, 7 * 2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4); |
| 166 | } |
| 167 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 168 | TEST_P(UnpackAlignmentTest, Alignment1RGBAUShort5551) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 169 | { |
| 170 | testAlignment(1, 7 * 2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1); |
| 171 | } |
| 172 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 173 | TEST_P(UnpackAlignmentTest, Alignment1RGBAUShort565) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 174 | { |
| 175 | testAlignment(1, 7 * 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); |
| 176 | } |
| 177 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 178 | TEST_P(UnpackAlignmentTest, Alignment1LAUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 179 | { |
| 180 | testAlignment(1, 7 * 2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE); |
| 181 | } |
| 182 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 183 | TEST_P(UnpackAlignmentTest, Alignment1LUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 184 | { |
| 185 | testAlignment(1, 7, GL_LUMINANCE, GL_UNSIGNED_BYTE); |
| 186 | } |
| 187 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 188 | TEST_P(UnpackAlignmentTest, Alignment1AUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 189 | { |
| 190 | testAlignment(1, 7, GL_ALPHA, GL_UNSIGNED_BYTE); |
| 191 | } |
| 192 | |
| 193 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 194 | TEST_P(UnpackAlignmentTest, Alignment2RGBAUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 195 | { |
| 196 | testAlignment(2, 7 * 4, GL_RGBA, GL_UNSIGNED_BYTE); |
| 197 | } |
| 198 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 199 | TEST_P(UnpackAlignmentTest, Alignment2RGBUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 200 | { |
| 201 | testAlignment(2, 7 * 3 + 1, GL_RGB, GL_UNSIGNED_BYTE); |
| 202 | } |
| 203 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 204 | TEST_P(UnpackAlignmentTest, Alignment2RGBAUShort4444) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 205 | { |
| 206 | testAlignment(2, 7 * 2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4); |
| 207 | } |
| 208 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 209 | TEST_P(UnpackAlignmentTest, Alignment2RGBAUShort5551) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 210 | { |
| 211 | testAlignment(2, 7 * 2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1); |
| 212 | } |
| 213 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 214 | TEST_P(UnpackAlignmentTest, Alignment2RGBAUShort565) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 215 | { |
| 216 | testAlignment(2, 7 * 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); |
| 217 | } |
| 218 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 219 | TEST_P(UnpackAlignmentTest, Alignment2LAUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 220 | { |
| 221 | testAlignment(2, 7 * 2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE); |
| 222 | } |
| 223 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 224 | TEST_P(UnpackAlignmentTest, Alignment2LAByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 225 | { |
| 226 | testAlignment(2, 7 + 1, GL_LUMINANCE, GL_UNSIGNED_BYTE); |
| 227 | } |
| 228 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 229 | TEST_P(UnpackAlignmentTest, Alignment2AUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 230 | { |
| 231 | testAlignment(2, 7 + 1, GL_ALPHA, GL_UNSIGNED_BYTE); |
| 232 | } |
| 233 | |
| 234 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 235 | TEST_P(UnpackAlignmentTest, Alignment4RGBAUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 236 | { |
| 237 | testAlignment(4, 7 * 4, GL_RGBA, GL_UNSIGNED_BYTE); |
| 238 | } |
| 239 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 240 | TEST_P(UnpackAlignmentTest, Alignment4RGBUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 241 | { |
| 242 | testAlignment(4, 7 * 3 + 3, GL_RGB, GL_UNSIGNED_BYTE); |
| 243 | } |
| 244 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 245 | TEST_P(UnpackAlignmentTest, Alignment4RGBAUShort4444) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 246 | { |
| 247 | testAlignment(4, 7 * 2 + 2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4); |
| 248 | } |
| 249 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 250 | TEST_P(UnpackAlignmentTest, Alignment4RGBAUShort5551) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 251 | { |
| 252 | testAlignment(4, 7 * 2 + 2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1); |
| 253 | } |
| 254 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 255 | TEST_P(UnpackAlignmentTest, Alignment4RGBAUShort565) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 256 | { |
| 257 | testAlignment(4, 7 * 2 + 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); |
| 258 | } |
| 259 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 260 | TEST_P(UnpackAlignmentTest, Alignment4LAUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 261 | { |
| 262 | testAlignment(4, 7 * 2 + 2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE); |
| 263 | } |
| 264 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 265 | TEST_P(UnpackAlignmentTest, Alignment4LUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 266 | { |
| 267 | testAlignment(4, 7 + 1, GL_LUMINANCE, GL_UNSIGNED_BYTE); |
| 268 | } |
| 269 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 270 | TEST_P(UnpackAlignmentTest, Alignment4AUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 271 | { |
| 272 | testAlignment(4, 7 + 1, GL_ALPHA, GL_UNSIGNED_BYTE); |
| 273 | } |
| 274 | |
| 275 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 276 | TEST_P(UnpackAlignmentTest, Alignment8RGBAUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 277 | { |
| 278 | testAlignment(8, 7 * 4 + 4, GL_RGBA, GL_UNSIGNED_BYTE); |
| 279 | } |
| 280 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 281 | TEST_P(UnpackAlignmentTest, Alignment8RGBUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 282 | { |
| 283 | testAlignment(8, 7 * 3 + 3, GL_RGB, GL_UNSIGNED_BYTE); |
| 284 | } |
| 285 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 286 | TEST_P(UnpackAlignmentTest, Alignment8RGBAUShort4444) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 287 | { |
| 288 | testAlignment(8, 7 * 2 + 2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4); |
| 289 | } |
| 290 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 291 | TEST_P(UnpackAlignmentTest, Alignment8RGBAUShort5551) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 292 | { |
| 293 | testAlignment(8, 7 * 2 + 2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1); |
| 294 | } |
| 295 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 296 | TEST_P(UnpackAlignmentTest, Alignment8RGBAUShort565) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 297 | { |
| 298 | testAlignment(8, 7 * 2 + 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); |
| 299 | } |
| 300 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 301 | TEST_P(UnpackAlignmentTest, Alignment8LAUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 302 | { |
| 303 | testAlignment(8, 7 * 2 + 2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE); |
| 304 | } |
| 305 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 306 | TEST_P(UnpackAlignmentTest, Alignment8LUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 307 | { |
| 308 | testAlignment(8, 7 + 1, GL_LUMINANCE, GL_UNSIGNED_BYTE); |
| 309 | } |
| 310 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 311 | TEST_P(UnpackAlignmentTest, Alignment8AUByte) |
Geoff Lang | 7ff0104 | 2013-10-18 16:15:39 -0400 | [diff] [blame] | 312 | { |
| 313 | testAlignment(8, 7 + 1, GL_ALPHA, GL_UNSIGNED_BYTE); |
| 314 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 315 | |
| 316 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame^] | 317 | ANGLE_INSTANTIATE_TEST(UnpackAlignmentTest, |
| 318 | ES2_D3D9(), |
| 319 | ES2_D3D11(), |
| 320 | ES2_OPENGL(), |
| 321 | ES3_OPENGL(), |
| 322 | ES2_OPENGLES(), |
| 323 | ES3_OPENGLES()); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 324 | |
| 325 | } // namespace |