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" |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -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 | |
Olli Etuaho | 356f516 | 2016-03-18 14:19:41 +0200 | [diff] [blame] | 14 | template <typename T> |
| 15 | void FillWithRGBA(size_t pixelCount, T red, T green, T blue, T alpha, T *outArray) |
| 16 | { |
| 17 | for (size_t i = 0u; i < pixelCount; ++i) |
| 18 | { |
| 19 | outArray[i * 4u] = red; |
| 20 | outArray[i * 4u + 1u] = green; |
| 21 | outArray[i * 4u + 2u] = blue; |
| 22 | outArray[i * 4u + 3u] = alpha; |
| 23 | } |
| 24 | } |
| 25 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 26 | class TexCoordDrawTest : public ANGLETest |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 27 | { |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 28 | protected: |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 29 | TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0) |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 30 | { |
| 31 | setWindowWidth(128); |
| 32 | setWindowHeight(128); |
| 33 | setConfigRedBits(8); |
| 34 | setConfigGreenBits(8); |
| 35 | setConfigBlueBits(8); |
| 36 | setConfigAlphaBits(8); |
| 37 | } |
| 38 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 39 | virtual std::string getVertexShaderSource() |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 40 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 41 | return std::string(SHADER_SOURCE |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 42 | ( |
| 43 | precision highp float; |
| 44 | attribute vec4 position; |
| 45 | varying vec2 texcoord; |
| 46 | |
| 47 | void main() |
| 48 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 49 | gl_Position = vec4(position.xy, 0.0, 1.0); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 50 | texcoord = (position.xy * 0.5) + 0.5; |
| 51 | } |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 52 | ) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 53 | ); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 54 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 55 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 56 | virtual std::string getFragmentShaderSource() = 0; |
| 57 | |
| 58 | void SetUp() override |
| 59 | { |
| 60 | ANGLETest::SetUp(); |
| 61 | const std::string vertexShaderSource = getVertexShaderSource(); |
| 62 | const std::string fragmentShaderSource = getFragmentShaderSource(); |
| 63 | |
| 64 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 65 | ASSERT_NE(0u, mProgram); |
| 66 | ASSERT_GL_NO_ERROR(); |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 67 | |
| 68 | setUpFramebuffer(); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void TearDown() override |
| 72 | { |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 73 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 74 | glDeleteFramebuffers(1, &mFramebuffer); |
| 75 | glDeleteTextures(1, &mFramebufferColorTexture); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 76 | glDeleteProgram(mProgram); |
| 77 | ANGLETest::TearDown(); |
| 78 | } |
| 79 | |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 80 | void setUpFramebuffer() |
| 81 | { |
| 82 | // We use an FBO to work around an issue where the default framebuffer applies SRGB |
| 83 | // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not |
| 84 | // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec |
| 85 | // section 4.4 says that the format of the default framebuffer is entirely up to the window |
| 86 | // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off |
| 87 | // SRGB conversion like desktop GL does. |
| 88 | // TODO(oetuaho): Get rid of this if the underlying issue is fixed. |
| 89 | glGenFramebuffers(1, &mFramebuffer); |
| 90 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 91 | |
| 92 | glGenTextures(1, &mFramebufferColorTexture); |
| 93 | glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture); |
| 94 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 95 | GL_UNSIGNED_BYTE, nullptr); |
| 96 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 97 | mFramebufferColorTexture, 0); |
| 98 | ASSERT_GL_NO_ERROR(); |
| 99 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 100 | glBindTexture(GL_TEXTURE_2D, 0); |
| 101 | } |
| 102 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 103 | // Returns the created texture ID. |
| 104 | GLuint create2DTexture() |
| 105 | { |
| 106 | GLuint texture2D; |
| 107 | glGenTextures(1, &texture2D); |
| 108 | glBindTexture(GL_TEXTURE_2D, texture2D); |
| 109 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 110 | EXPECT_GL_NO_ERROR(); |
| 111 | return texture2D; |
| 112 | } |
| 113 | |
| 114 | GLuint mProgram; |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 115 | GLuint mFramebuffer; |
| 116 | |
| 117 | private: |
| 118 | GLuint mFramebufferColorTexture; |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | class Texture2DTest : public TexCoordDrawTest |
| 122 | { |
| 123 | protected: |
| 124 | Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {} |
| 125 | |
| 126 | std::string getFragmentShaderSource() override |
| 127 | { |
| 128 | return std::string(SHADER_SOURCE |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 129 | ( |
| 130 | precision highp float; |
| 131 | uniform sampler2D tex; |
| 132 | varying vec2 texcoord; |
| 133 | |
| 134 | void main() |
| 135 | { |
| 136 | gl_FragColor = texture2D(tex, texcoord); |
| 137 | } |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 138 | ) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 139 | ); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 140 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 141 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 142 | void SetUp() override |
| 143 | { |
| 144 | TexCoordDrawTest::SetUp(); |
| 145 | mTexture2D = create2DTexture(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 146 | |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 147 | ASSERT_GL_NO_ERROR(); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 148 | |
| 149 | mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex"); |
| 150 | ASSERT_NE(-1, mTexture2DUniformLocation); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 153 | void TearDown() override |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 154 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 155 | glDeleteTextures(1, &mTexture2D); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 156 | TexCoordDrawTest::TearDown(); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 159 | // Tests CopyTexSubImage with floating point textures of various formats. |
| 160 | void testFloatCopySubImage(int sourceImageChannels, int destImageChannels) |
| 161 | { |
Geoff Lang | bde666a | 2015-04-07 17:17:08 -0400 | [diff] [blame] | 162 | // TODO(jmadill): Figure out why this is broken on Intel D3D11 |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 163 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE) |
Geoff Lang | bde666a | 2015-04-07 17:17:08 -0400 | [diff] [blame] | 164 | { |
| 165 | std::cout << "Test skipped on Intel D3D11." << std::endl; |
| 166 | return; |
| 167 | } |
| 168 | |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 169 | if (getClientVersion() < 3) |
| 170 | { |
| 171 | if (!extensionEnabled("GL_OES_texture_float")) |
| 172 | { |
| 173 | std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl; |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg")) |
| 178 | { |
| 179 | std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl; |
| 180 | return; |
| 181 | } |
| 182 | } |
| 183 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 184 | GLfloat sourceImageData[4][16] = |
| 185 | { |
| 186 | { // R |
| 187 | 1.0f, |
| 188 | 0.0f, |
| 189 | 0.0f, |
| 190 | 1.0f |
| 191 | }, |
| 192 | { // RG |
| 193 | 1.0f, 0.0f, |
| 194 | 0.0f, 1.0f, |
| 195 | 0.0f, 0.0f, |
| 196 | 1.0f, 1.0f |
| 197 | }, |
| 198 | { // RGB |
| 199 | 1.0f, 0.0f, 0.0f, |
| 200 | 0.0f, 1.0f, 0.0f, |
| 201 | 0.0f, 0.0f, 1.0f, |
| 202 | 1.0f, 1.0f, 0.0f |
| 203 | }, |
| 204 | { // RGBA |
| 205 | 1.0f, 0.0f, 0.0f, 1.0f, |
| 206 | 0.0f, 1.0f, 0.0f, 1.0f, |
| 207 | 0.0f, 0.0f, 1.0f, 1.0f, |
| 208 | 1.0f, 1.0f, 0.0f, 1.0f |
| 209 | }, |
| 210 | }; |
| 211 | |
| 212 | GLenum imageFormats[] = |
| 213 | { |
| 214 | GL_R32F, |
| 215 | GL_RG32F, |
| 216 | GL_RGB32F, |
| 217 | GL_RGBA32F, |
| 218 | }; |
| 219 | |
| 220 | GLenum sourceUnsizedFormats[] = |
| 221 | { |
| 222 | GL_RED, |
| 223 | GL_RG, |
| 224 | GL_RGB, |
| 225 | GL_RGBA, |
| 226 | }; |
| 227 | |
| 228 | GLuint textures[2]; |
| 229 | |
| 230 | glGenTextures(2, textures); |
| 231 | |
| 232 | GLfloat *imageData = sourceImageData[sourceImageChannels - 1]; |
| 233 | GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1]; |
| 234 | GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1]; |
| 235 | GLenum destImageFormat = imageFormats[destImageChannels - 1]; |
| 236 | |
| 237 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 238 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2); |
| 239 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 240 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 241 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData); |
| 242 | |
hendrikw | b27f79a | 2015-03-04 11:26:46 -0800 | [diff] [blame] | 243 | if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg")) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 244 | { |
| 245 | // This is not supported |
| 246 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | ASSERT_GL_NO_ERROR(); |
| 251 | } |
| 252 | |
| 253 | GLuint fbo; |
| 254 | glGenFramebuffers(1, &fbo); |
| 255 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 256 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 257 | |
| 258 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 259 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2); |
| 260 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 261 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 262 | |
| 263 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2); |
| 264 | ASSERT_GL_NO_ERROR(); |
| 265 | |
| 266 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 267 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 268 | |
| 269 | int testImageChannels = std::min(sourceImageChannels, destImageChannels); |
| 270 | |
| 271 | EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255); |
| 272 | if (testImageChannels > 1) |
| 273 | { |
| 274 | EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255); |
| 275 | EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255); |
| 276 | if (testImageChannels > 2) |
| 277 | { |
| 278 | EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | glDeleteFramebuffers(1, &fbo); |
| 283 | glDeleteTextures(2, textures); |
| 284 | |
| 285 | ASSERT_GL_NO_ERROR(); |
| 286 | } |
| 287 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 288 | GLuint mTexture2D; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 289 | GLint mTexture2DUniformLocation; |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 290 | }; |
| 291 | |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 292 | class Texture2DTestES3 : public Texture2DTest |
| 293 | { |
| 294 | protected: |
| 295 | Texture2DTestES3() : Texture2DTest() {} |
| 296 | |
| 297 | std::string getVertexShaderSource() override |
| 298 | { |
| 299 | return std::string( |
| 300 | "#version 300 es\n" |
| 301 | "out vec2 texcoord;\n" |
| 302 | "in vec4 position;\n" |
| 303 | "void main()\n" |
| 304 | "{\n" |
| 305 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 306 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 307 | "}\n"); |
| 308 | } |
| 309 | |
| 310 | std::string getFragmentShaderSource() override |
| 311 | { |
| 312 | return std::string( |
| 313 | "#version 300 es\n" |
| 314 | "precision highp float;\n" |
| 315 | "uniform highp sampler2D tex;\n" |
| 316 | "in vec2 texcoord;\n" |
| 317 | "out vec4 fragColor;\n" |
| 318 | "void main()\n" |
| 319 | "{\n" |
| 320 | " fragColor = texture(tex, texcoord);\n" |
| 321 | "}\n"); |
| 322 | } |
| 323 | }; |
| 324 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 325 | class Texture2DIntegerAlpha1TestES3 : public Texture2DTest |
| 326 | { |
| 327 | protected: |
| 328 | Texture2DIntegerAlpha1TestES3() : Texture2DTest() {} |
| 329 | |
| 330 | std::string getVertexShaderSource() override |
| 331 | { |
| 332 | return std::string( |
| 333 | "#version 300 es\n" |
| 334 | "out vec2 texcoord;\n" |
| 335 | "in vec4 position;\n" |
| 336 | "void main()\n" |
| 337 | "{\n" |
| 338 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 339 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 340 | "}\n"); |
| 341 | } |
| 342 | |
| 343 | std::string getFragmentShaderSource() override |
| 344 | { |
| 345 | return std::string( |
| 346 | "#version 300 es\n" |
| 347 | "precision highp float;\n" |
| 348 | "uniform highp isampler2D tex;\n" |
| 349 | "in vec2 texcoord;\n" |
| 350 | "out vec4 fragColor;\n" |
| 351 | "void main()\n" |
| 352 | "{\n" |
| 353 | " vec4 green = vec4(0, 1, 0, 1);\n" |
| 354 | " vec4 black = vec4(0, 0, 0, 0);\n" |
| 355 | " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n" |
| 356 | "}\n"); |
| 357 | } |
| 358 | }; |
| 359 | |
| 360 | class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest |
| 361 | { |
| 362 | protected: |
| 363 | Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {} |
| 364 | |
| 365 | std::string getVertexShaderSource() override |
| 366 | { |
| 367 | return std::string( |
| 368 | "#version 300 es\n" |
| 369 | "out vec2 texcoord;\n" |
| 370 | "in vec4 position;\n" |
| 371 | "void main()\n" |
| 372 | "{\n" |
| 373 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 374 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 375 | "}\n"); |
| 376 | } |
| 377 | |
| 378 | std::string getFragmentShaderSource() override |
| 379 | { |
| 380 | return std::string( |
| 381 | "#version 300 es\n" |
| 382 | "precision highp float;\n" |
| 383 | "uniform highp usampler2D tex;\n" |
| 384 | "in vec2 texcoord;\n" |
| 385 | "out vec4 fragColor;\n" |
| 386 | "void main()\n" |
| 387 | "{\n" |
| 388 | " vec4 green = vec4(0, 1, 0, 1);\n" |
| 389 | " vec4 black = vec4(0, 0, 0, 0);\n" |
| 390 | " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n" |
| 391 | "}\n"); |
| 392 | } |
| 393 | }; |
| 394 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 395 | class Texture2DTestWithDrawScale : public Texture2DTest |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 396 | { |
| 397 | protected: |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 398 | Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {} |
| 399 | |
| 400 | std::string getVertexShaderSource() override |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 401 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 402 | return std::string(SHADER_SOURCE |
| 403 | ( |
| 404 | precision highp float; |
| 405 | attribute vec4 position; |
| 406 | varying vec2 texcoord; |
| 407 | |
| 408 | uniform vec2 drawScale; |
| 409 | |
| 410 | void main() |
| 411 | { |
| 412 | gl_Position = vec4(position.xy * drawScale, 0.0, 1.0); |
| 413 | texcoord = (position.xy * 0.5) + 0.5; |
| 414 | } |
| 415 | ) |
| 416 | ); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | void SetUp() override |
| 420 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 421 | Texture2DTest::SetUp(); |
| 422 | mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale"); |
| 423 | ASSERT_NE(-1, mDrawScaleUniformLocation); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 424 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 425 | glUseProgram(mProgram); |
| 426 | glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f); |
| 427 | glUseProgram(0); |
| 428 | ASSERT_GL_NO_ERROR(); |
| 429 | } |
| 430 | |
| 431 | GLint mDrawScaleUniformLocation; |
| 432 | }; |
| 433 | |
Olli Etuaho | 4644a20 | 2016-01-12 15:12:53 +0200 | [diff] [blame] | 434 | class Sampler2DAsFunctionParameterTest : public Texture2DTest |
| 435 | { |
| 436 | protected: |
| 437 | Sampler2DAsFunctionParameterTest() : Texture2DTest() {} |
| 438 | |
| 439 | std::string getFragmentShaderSource() override |
| 440 | { |
| 441 | return std::string(SHADER_SOURCE |
| 442 | ( |
| 443 | precision highp float; |
| 444 | uniform sampler2D tex; |
| 445 | varying vec2 texcoord; |
| 446 | |
| 447 | vec4 computeFragColor(sampler2D aTex) |
| 448 | { |
| 449 | return texture2D(aTex, texcoord); |
| 450 | } |
| 451 | |
| 452 | void main() |
| 453 | { |
| 454 | gl_FragColor = computeFragColor(tex); |
| 455 | } |
| 456 | ) |
| 457 | ); |
| 458 | } |
| 459 | }; |
| 460 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 461 | class TextureCubeTest : public TexCoordDrawTest |
| 462 | { |
| 463 | protected: |
| 464 | TextureCubeTest() |
| 465 | : TexCoordDrawTest(), |
| 466 | mTexture2D(0), |
| 467 | mTextureCube(0), |
| 468 | mTexture2DUniformLocation(-1), |
| 469 | mTextureCubeUniformLocation(-1) |
| 470 | { |
| 471 | } |
| 472 | |
| 473 | std::string getFragmentShaderSource() override |
| 474 | { |
| 475 | return std::string(SHADER_SOURCE |
| 476 | ( |
| 477 | precision highp float; |
| 478 | uniform sampler2D tex2D; |
| 479 | uniform samplerCube texCube; |
| 480 | varying vec2 texcoord; |
| 481 | |
| 482 | void main() |
| 483 | { |
| 484 | gl_FragColor = texture2D(tex2D, texcoord); |
| 485 | gl_FragColor += textureCube(texCube, vec3(texcoord, 0)); |
| 486 | } |
| 487 | ) |
| 488 | ); |
| 489 | } |
| 490 | |
| 491 | void SetUp() override |
| 492 | { |
| 493 | TexCoordDrawTest::SetUp(); |
| 494 | |
| 495 | glGenTextures(1, &mTextureCube); |
| 496 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 497 | glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1); |
| 498 | EXPECT_GL_NO_ERROR(); |
| 499 | |
| 500 | mTexture2D = create2DTexture(); |
| 501 | |
| 502 | mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D"); |
| 503 | ASSERT_NE(-1, mTexture2DUniformLocation); |
| 504 | mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube"); |
| 505 | ASSERT_NE(-1, mTextureCubeUniformLocation); |
| 506 | } |
| 507 | |
| 508 | void TearDown() override |
| 509 | { |
| 510 | glDeleteTextures(1, &mTextureCube); |
| 511 | TexCoordDrawTest::TearDown(); |
| 512 | } |
| 513 | |
| 514 | GLuint mTexture2D; |
| 515 | GLuint mTextureCube; |
| 516 | GLint mTexture2DUniformLocation; |
| 517 | GLint mTextureCubeUniformLocation; |
| 518 | }; |
| 519 | |
Olli Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 520 | class SamplerArrayTest : public TexCoordDrawTest |
| 521 | { |
| 522 | protected: |
| 523 | SamplerArrayTest() |
| 524 | : TexCoordDrawTest(), |
| 525 | mTexture2DA(0), |
| 526 | mTexture2DB(0), |
| 527 | mTexture0UniformLocation(-1), |
| 528 | mTexture1UniformLocation(-1) |
| 529 | { |
| 530 | } |
| 531 | |
| 532 | std::string getFragmentShaderSource() override |
| 533 | { |
| 534 | return std::string(SHADER_SOURCE |
| 535 | ( |
| 536 | precision mediump float; |
| 537 | uniform highp sampler2D tex2DArray[2]; |
| 538 | varying vec2 texcoord; |
| 539 | void main() |
| 540 | { |
| 541 | gl_FragColor = texture2D(tex2DArray[0], texcoord); |
| 542 | gl_FragColor += texture2D(tex2DArray[1], texcoord); |
| 543 | } |
| 544 | ) |
| 545 | ); |
| 546 | } |
| 547 | |
| 548 | void SetUp() override |
| 549 | { |
| 550 | TexCoordDrawTest::SetUp(); |
| 551 | |
| 552 | mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]"); |
| 553 | ASSERT_NE(-1, mTexture0UniformLocation); |
| 554 | mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]"); |
| 555 | ASSERT_NE(-1, mTexture1UniformLocation); |
| 556 | |
| 557 | mTexture2DA = create2DTexture(); |
| 558 | mTexture2DB = create2DTexture(); |
| 559 | ASSERT_GL_NO_ERROR(); |
| 560 | } |
| 561 | |
| 562 | void TearDown() override |
| 563 | { |
| 564 | glDeleteTextures(1, &mTexture2DA); |
| 565 | glDeleteTextures(1, &mTexture2DB); |
| 566 | TexCoordDrawTest::TearDown(); |
| 567 | } |
| 568 | |
| 569 | void testSamplerArrayDraw() |
| 570 | { |
| 571 | GLubyte texData[4]; |
| 572 | texData[0] = 0; |
| 573 | texData[1] = 60; |
| 574 | texData[2] = 0; |
| 575 | texData[3] = 255; |
| 576 | |
| 577 | glActiveTexture(GL_TEXTURE0); |
| 578 | glBindTexture(GL_TEXTURE_2D, mTexture2DA); |
| 579 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 580 | |
| 581 | texData[1] = 120; |
| 582 | glActiveTexture(GL_TEXTURE1); |
| 583 | glBindTexture(GL_TEXTURE_2D, mTexture2DB); |
| 584 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 585 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 586 | |
| 587 | glUseProgram(mProgram); |
| 588 | glUniform1i(mTexture0UniformLocation, 0); |
| 589 | glUniform1i(mTexture1UniformLocation, 1); |
| 590 | drawQuad(mProgram, "position", 0.5f); |
| 591 | EXPECT_GL_NO_ERROR(); |
| 592 | |
| 593 | EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2); |
| 594 | } |
| 595 | |
| 596 | GLuint mTexture2DA; |
| 597 | GLuint mTexture2DB; |
| 598 | GLint mTexture0UniformLocation; |
| 599 | GLint mTexture1UniformLocation; |
| 600 | }; |
| 601 | |
| 602 | |
| 603 | class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest |
| 604 | { |
| 605 | protected: |
| 606 | SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {} |
| 607 | |
| 608 | std::string getFragmentShaderSource() override |
| 609 | { |
| 610 | return std::string(SHADER_SOURCE |
| 611 | ( |
| 612 | precision mediump float; |
| 613 | uniform highp sampler2D tex2DArray[2]; |
| 614 | varying vec2 texcoord; |
| 615 | |
| 616 | vec4 computeFragColor(highp sampler2D aTex2DArray[2]) |
| 617 | { |
| 618 | return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord); |
| 619 | } |
| 620 | |
| 621 | void main() |
| 622 | { |
| 623 | gl_FragColor = computeFragColor(tex2DArray); |
| 624 | } |
| 625 | ) |
| 626 | ); |
| 627 | } |
| 628 | }; |
| 629 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 630 | class Texture2DArrayTestES3 : public TexCoordDrawTest |
| 631 | { |
| 632 | protected: |
| 633 | Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {} |
| 634 | |
| 635 | std::string getVertexShaderSource() override |
| 636 | { |
| 637 | return std::string( |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 638 | "#version 300 es\n" |
| 639 | "out vec2 texcoord;\n" |
| 640 | "in vec4 position;\n" |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 641 | "void main()\n" |
| 642 | "{\n" |
| 643 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 644 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 645 | "}\n"); |
| 646 | } |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 647 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 648 | std::string getFragmentShaderSource() override |
| 649 | { |
| 650 | return std::string( |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 651 | "#version 300 es\n" |
| 652 | "precision highp float;\n" |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 653 | "uniform highp sampler2DArray tex2DArray;\n" |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 654 | "in vec2 texcoord;\n" |
| 655 | "out vec4 fragColor;\n" |
| 656 | "void main()\n" |
| 657 | "{\n" |
| 658 | " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n" |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 659 | "}\n"); |
| 660 | } |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 661 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 662 | void SetUp() override |
| 663 | { |
| 664 | TexCoordDrawTest::SetUp(); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 665 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 666 | mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray"); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 667 | ASSERT_NE(-1, mTextureArrayLocation); |
| 668 | |
| 669 | glGenTextures(1, &m2DArrayTexture); |
| 670 | ASSERT_GL_NO_ERROR(); |
| 671 | } |
| 672 | |
| 673 | void TearDown() override |
| 674 | { |
| 675 | glDeleteTextures(1, &m2DArrayTexture); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 676 | TexCoordDrawTest::TearDown(); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | GLuint m2DArrayTexture; |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 680 | GLint mTextureArrayLocation; |
| 681 | }; |
| 682 | |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 683 | class TextureSizeTextureArrayTest : public TexCoordDrawTest |
| 684 | { |
| 685 | protected: |
| 686 | TextureSizeTextureArrayTest() |
| 687 | : TexCoordDrawTest(), |
| 688 | mTexture2DA(0), |
| 689 | mTexture2DB(0), |
| 690 | mTexture0Location(-1), |
| 691 | mTexture1Location(-1) |
| 692 | { |
| 693 | } |
| 694 | |
| 695 | std::string getVertexShaderSource() override |
| 696 | { |
| 697 | return std::string( |
| 698 | "#version 300 es\n" |
| 699 | "in vec4 position;\n" |
| 700 | "void main()\n" |
| 701 | "{\n" |
| 702 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 703 | "}\n"); |
| 704 | } |
| 705 | |
| 706 | std::string getFragmentShaderSource() override |
| 707 | { |
| 708 | return std::string( |
| 709 | "#version 300 es\n" |
| 710 | "precision highp float;\n" |
| 711 | "uniform highp sampler2D tex2DArray[2];\n" |
| 712 | "out vec4 fragColor;\n" |
| 713 | "void main()\n" |
| 714 | "{\n" |
| 715 | " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n" |
| 716 | " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n" |
| 717 | " fragColor = vec4(red, green, 0.0, 1.0);\n" |
| 718 | "}\n"); |
| 719 | } |
| 720 | |
| 721 | void SetUp() override |
| 722 | { |
| 723 | TexCoordDrawTest::SetUp(); |
| 724 | |
| 725 | mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]"); |
| 726 | ASSERT_NE(-1, mTexture0Location); |
| 727 | mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]"); |
| 728 | ASSERT_NE(-1, mTexture1Location); |
| 729 | |
| 730 | mTexture2DA = create2DTexture(); |
| 731 | mTexture2DB = create2DTexture(); |
| 732 | ASSERT_GL_NO_ERROR(); |
| 733 | } |
| 734 | |
| 735 | void TearDown() override |
| 736 | { |
| 737 | glDeleteTextures(1, &mTexture2DA); |
| 738 | glDeleteTextures(1, &mTexture2DB); |
| 739 | TexCoordDrawTest::TearDown(); |
| 740 | } |
| 741 | |
| 742 | GLuint mTexture2DA; |
| 743 | GLuint mTexture2DB; |
| 744 | GLint mTexture0Location; |
| 745 | GLint mTexture1Location; |
| 746 | }; |
| 747 | |
Olli Etuaho | 1a67990 | 2016-01-14 12:21:47 +0200 | [diff] [blame] | 748 | class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest |
| 749 | { |
| 750 | protected: |
| 751 | ShadowSamplerPlusSampler3DTestES3() |
| 752 | : TexCoordDrawTest(), |
| 753 | mTextureShadow(0), |
| 754 | mTexture3D(0), |
| 755 | mTextureShadowUniformLocation(-1), |
| 756 | mTexture3DUniformLocation(-1), |
| 757 | mDepthRefUniformLocation(-1) |
| 758 | { |
| 759 | } |
| 760 | |
| 761 | std::string getVertexShaderSource() override |
| 762 | { |
| 763 | return std::string( |
| 764 | "#version 300 es\n" |
| 765 | "out vec2 texcoord;\n" |
| 766 | "in vec4 position;\n" |
| 767 | "void main()\n" |
| 768 | "{\n" |
| 769 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 770 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 771 | "}\n"); |
| 772 | } |
| 773 | |
| 774 | std::string getFragmentShaderSource() override |
| 775 | { |
| 776 | return std::string( |
| 777 | "#version 300 es\n" |
| 778 | "precision highp float;\n" |
| 779 | "uniform highp sampler2DShadow tex2DShadow;\n" |
| 780 | "uniform highp sampler3D tex3D;\n" |
| 781 | "in vec2 texcoord;\n" |
| 782 | "uniform float depthRef;\n" |
| 783 | "out vec4 fragColor;\n" |
| 784 | "void main()\n" |
| 785 | "{\n" |
| 786 | " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n" |
| 787 | " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n" |
| 788 | "}\n"); |
| 789 | } |
| 790 | |
| 791 | void SetUp() override |
| 792 | { |
| 793 | TexCoordDrawTest::SetUp(); |
| 794 | |
| 795 | glGenTextures(1, &mTexture3D); |
| 796 | |
| 797 | glGenTextures(1, &mTextureShadow); |
| 798 | glBindTexture(GL_TEXTURE_2D, mTextureShadow); |
| 799 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); |
| 800 | |
| 801 | mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow"); |
| 802 | ASSERT_NE(-1, mTextureShadowUniformLocation); |
| 803 | mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D"); |
| 804 | ASSERT_NE(-1, mTexture3DUniformLocation); |
| 805 | mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef"); |
| 806 | ASSERT_NE(-1, mDepthRefUniformLocation); |
| 807 | } |
| 808 | |
| 809 | void TearDown() override |
| 810 | { |
| 811 | glDeleteTextures(1, &mTextureShadow); |
| 812 | glDeleteTextures(1, &mTexture3D); |
| 813 | TexCoordDrawTest::TearDown(); |
| 814 | } |
| 815 | |
| 816 | GLuint mTextureShadow; |
| 817 | GLuint mTexture3D; |
| 818 | GLint mTextureShadowUniformLocation; |
| 819 | GLint mTexture3DUniformLocation; |
| 820 | GLint mDepthRefUniformLocation; |
| 821 | }; |
| 822 | |
Olli Etuaho | c8c99a0 | 2016-01-14 16:47:22 +0200 | [diff] [blame] | 823 | class SamplerTypeMixTestES3 : public TexCoordDrawTest |
| 824 | { |
| 825 | protected: |
| 826 | SamplerTypeMixTestES3() |
| 827 | : TexCoordDrawTest(), |
| 828 | mTexture2D(0), |
| 829 | mTextureCube(0), |
| 830 | mTexture2DShadow(0), |
| 831 | mTextureCubeShadow(0), |
| 832 | mTexture2DUniformLocation(-1), |
| 833 | mTextureCubeUniformLocation(-1), |
| 834 | mTexture2DShadowUniformLocation(-1), |
| 835 | mTextureCubeShadowUniformLocation(-1), |
| 836 | mDepthRefUniformLocation(-1) |
| 837 | { |
| 838 | } |
| 839 | |
| 840 | std::string getVertexShaderSource() override |
| 841 | { |
| 842 | return std::string( |
| 843 | "#version 300 es\n" |
| 844 | "out vec2 texcoord;\n" |
| 845 | "in vec4 position;\n" |
| 846 | "void main()\n" |
| 847 | "{\n" |
| 848 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 849 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 850 | "}\n"); |
| 851 | } |
| 852 | |
| 853 | std::string getFragmentShaderSource() override |
| 854 | { |
| 855 | return std::string( |
| 856 | "#version 300 es\n" |
| 857 | "precision highp float;\n" |
| 858 | "uniform highp sampler2D tex2D;\n" |
| 859 | "uniform highp samplerCube texCube;\n" |
| 860 | "uniform highp sampler2DShadow tex2DShadow;\n" |
| 861 | "uniform highp samplerCubeShadow texCubeShadow;\n" |
| 862 | "in vec2 texcoord;\n" |
| 863 | "uniform float depthRef;\n" |
| 864 | "out vec4 fragColor;\n" |
| 865 | "void main()\n" |
| 866 | "{\n" |
| 867 | " fragColor = texture(tex2D, texcoord);\n" |
| 868 | " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n" |
| 869 | " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n" |
| 870 | " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * " |
| 871 | "0.125);\n" |
| 872 | "}\n"); |
| 873 | } |
| 874 | |
| 875 | void SetUp() override |
| 876 | { |
| 877 | TexCoordDrawTest::SetUp(); |
| 878 | |
| 879 | glGenTextures(1, &mTexture2D); |
| 880 | glGenTextures(1, &mTextureCube); |
| 881 | |
| 882 | glGenTextures(1, &mTexture2DShadow); |
| 883 | glBindTexture(GL_TEXTURE_2D, mTexture2DShadow); |
| 884 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); |
| 885 | |
| 886 | glGenTextures(1, &mTextureCubeShadow); |
| 887 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow); |
| 888 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); |
| 889 | |
| 890 | mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D"); |
| 891 | ASSERT_NE(-1, mTexture2DUniformLocation); |
| 892 | mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube"); |
| 893 | ASSERT_NE(-1, mTextureCubeUniformLocation); |
| 894 | mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow"); |
| 895 | ASSERT_NE(-1, mTexture2DShadowUniformLocation); |
| 896 | mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow"); |
| 897 | ASSERT_NE(-1, mTextureCubeShadowUniformLocation); |
| 898 | mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef"); |
| 899 | ASSERT_NE(-1, mDepthRefUniformLocation); |
| 900 | |
| 901 | ASSERT_GL_NO_ERROR(); |
| 902 | } |
| 903 | |
| 904 | void TearDown() override |
| 905 | { |
| 906 | glDeleteTextures(1, &mTexture2D); |
| 907 | glDeleteTextures(1, &mTextureCube); |
| 908 | glDeleteTextures(1, &mTexture2DShadow); |
| 909 | glDeleteTextures(1, &mTextureCubeShadow); |
| 910 | TexCoordDrawTest::TearDown(); |
| 911 | } |
| 912 | |
| 913 | GLuint mTexture2D; |
| 914 | GLuint mTextureCube; |
| 915 | GLuint mTexture2DShadow; |
| 916 | GLuint mTextureCubeShadow; |
| 917 | GLint mTexture2DUniformLocation; |
| 918 | GLint mTextureCubeUniformLocation; |
| 919 | GLint mTexture2DShadowUniformLocation; |
| 920 | GLint mTextureCubeShadowUniformLocation; |
| 921 | GLint mDepthRefUniformLocation; |
| 922 | }; |
| 923 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 924 | TEST_P(Texture2DTest, NegativeAPISubImage) |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 925 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 926 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 927 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 928 | |
| 929 | const GLubyte *pixels[20] = { 0 }; |
| 930 | glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 931 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 932 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 933 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 934 | TEST_P(Texture2DTest, ZeroSizedUploads) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 935 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 936 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 937 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 938 | |
| 939 | // Use the texture first to make sure it's in video memory |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 940 | glUseProgram(mProgram); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 941 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 942 | drawQuad(mProgram, "position", 0.5f); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 943 | |
| 944 | const GLubyte *pixel[4] = { 0 }; |
| 945 | |
| 946 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 947 | EXPECT_GL_NO_ERROR(); |
| 948 | |
| 949 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 950 | EXPECT_GL_NO_ERROR(); |
| 951 | |
| 952 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 953 | EXPECT_GL_NO_ERROR(); |
| 954 | } |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 955 | |
| 956 | // Test drawing with two texture types, to trigger an ANGLE bug in validation |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 957 | TEST_P(TextureCubeTest, CubeMapBug) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 958 | { |
| 959 | glActiveTexture(GL_TEXTURE0); |
| 960 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 961 | glActiveTexture(GL_TEXTURE1); |
| 962 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 963 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 964 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 965 | glUseProgram(mProgram); |
| 966 | glUniform1i(mTexture2DUniformLocation, 0); |
| 967 | glUniform1i(mTextureCubeUniformLocation, 1); |
| 968 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 969 | EXPECT_GL_NO_ERROR(); |
| 970 | } |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 971 | |
Olli Etuaho | 53a2da1 | 2016-01-11 15:43:32 +0200 | [diff] [blame] | 972 | // Test drawing with two texture types accessed from the same shader and check that the result of |
| 973 | // drawing is correct. |
| 974 | TEST_P(TextureCubeTest, CubeMapDraw) |
| 975 | { |
| 976 | GLubyte texData[4]; |
| 977 | texData[0] = 0; |
| 978 | texData[1] = 60; |
| 979 | texData[2] = 0; |
| 980 | texData[3] = 255; |
| 981 | |
| 982 | glActiveTexture(GL_TEXTURE0); |
| 983 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 984 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 985 | |
| 986 | glActiveTexture(GL_TEXTURE1); |
| 987 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 988 | texData[1] = 120; |
| 989 | glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 990 | texData); |
| 991 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 992 | |
| 993 | glUseProgram(mProgram); |
| 994 | glUniform1i(mTexture2DUniformLocation, 0); |
| 995 | glUniform1i(mTextureCubeUniformLocation, 1); |
| 996 | drawQuad(mProgram, "position", 0.5f); |
| 997 | EXPECT_GL_NO_ERROR(); |
| 998 | |
| 999 | int px = getWindowWidth() - 1; |
| 1000 | int py = 0; |
| 1001 | EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2); |
| 1002 | } |
| 1003 | |
Olli Etuaho | 4644a20 | 2016-01-12 15:12:53 +0200 | [diff] [blame] | 1004 | TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter) |
| 1005 | { |
| 1006 | glActiveTexture(GL_TEXTURE0); |
| 1007 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1008 | GLubyte texData[4]; |
| 1009 | texData[0] = 0; |
| 1010 | texData[1] = 128; |
| 1011 | texData[2] = 0; |
| 1012 | texData[3] = 255; |
| 1013 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 1014 | glUseProgram(mProgram); |
| 1015 | glUniform1i(mTexture2DUniformLocation, 0); |
| 1016 | drawQuad(mProgram, "position", 0.5f); |
| 1017 | EXPECT_GL_NO_ERROR(); |
| 1018 | |
| 1019 | EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2); |
| 1020 | } |
| 1021 | |
Olli Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 1022 | // Test drawing with two textures passed to the shader in a sampler array. |
| 1023 | TEST_P(SamplerArrayTest, SamplerArrayDraw) |
| 1024 | { |
| 1025 | testSamplerArrayDraw(); |
| 1026 | } |
| 1027 | |
| 1028 | // Test drawing with two textures passed to the shader in a sampler array which is passed to a |
| 1029 | // user-defined function in the shader. |
| 1030 | TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter) |
| 1031 | { |
| 1032 | testSamplerArrayDraw(); |
| 1033 | } |
| 1034 | |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1035 | // Copy of a test in conformance/textures/texture-mips, to test generate mipmaps |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1036 | TEST_P(Texture2DTestWithDrawScale, MipmapsTwice) |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1037 | { |
| 1038 | int px = getWindowWidth() / 2; |
| 1039 | int py = getWindowHeight() / 2; |
| 1040 | |
| 1041 | glActiveTexture(GL_TEXTURE0); |
| 1042 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1043 | |
| 1044 | // Fill with red |
| 1045 | std::vector<GLubyte> pixels(4 * 16 * 16); |
Olli Etuaho | 356f516 | 2016-03-18 14:19:41 +0200 | [diff] [blame] | 1046 | FillWithRGBA<GLubyte>(16u * 16u, 255u, 0u, 0u, 255u, pixels.data()); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1047 | |
| 1048 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 1049 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 1050 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1051 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1052 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1053 | glUseProgram(mProgram); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1054 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1055 | glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f); |
| 1056 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1057 | EXPECT_GL_NO_ERROR(); |
| 1058 | EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255); |
| 1059 | |
| 1060 | // Fill with blue |
Olli Etuaho | 356f516 | 2016-03-18 14:19:41 +0200 | [diff] [blame] | 1061 | FillWithRGBA<GLubyte>(16u * 16u, 0u, 0u, 255u, 255u, pixels.data()); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1062 | |
| 1063 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 1064 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1065 | |
| 1066 | // Fill with green |
Olli Etuaho | 356f516 | 2016-03-18 14:19:41 +0200 | [diff] [blame] | 1067 | FillWithRGBA<GLubyte>(16u * 16u, 0u, 255u, 0u, 255u, pixels.data()); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1068 | |
| 1069 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 1070 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1071 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1072 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1073 | |
| 1074 | EXPECT_GL_NO_ERROR(); |
| 1075 | EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255); |
| 1076 | } |
Jamie Madill | f8fccb3 | 2014-11-12 15:05:26 -0500 | [diff] [blame] | 1077 | |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 1078 | // Test creating a FBO with a cube map render target, to test an ANGLE bug |
| 1079 | // https://code.google.com/p/angleproject/issues/detail?id=849 |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1080 | TEST_P(TextureCubeTest, CubeMapFBO) |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 1081 | { |
| 1082 | GLuint fbo; |
| 1083 | glGenFramebuffers(1, &fbo); |
| 1084 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1085 | |
| 1086 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 1087 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0); |
| 1088 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 1089 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 1090 | |
| 1091 | glDeleteFramebuffers(1, &fbo); |
| 1092 | |
| 1093 | EXPECT_GL_NO_ERROR(); |
| 1094 | } |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1095 | |
| 1096 | // Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1097 | TEST_P(Texture2DTest, TexStorage) |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1098 | { |
| 1099 | int width = getWindowWidth(); |
| 1100 | int height = getWindowHeight(); |
| 1101 | |
| 1102 | GLuint tex2D; |
| 1103 | glGenTextures(1, &tex2D); |
| 1104 | glActiveTexture(GL_TEXTURE0); |
| 1105 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 1106 | |
| 1107 | // Fill with red |
| 1108 | std::vector<GLubyte> pixels(3 * 16 * 16); |
| 1109 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 1110 | { |
| 1111 | pixels[pixelId * 3 + 0] = 255; |
| 1112 | pixels[pixelId * 3 + 1] = 0; |
| 1113 | pixels[pixelId * 3 + 2] = 0; |
| 1114 | } |
| 1115 | |
| 1116 | // ANGLE internally uses RGBA as the DirectX format for RGB images |
| 1117 | // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color. |
| 1118 | // The data is kept in a CPU-side image and the image is marked as dirty. |
| 1119 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16); |
| 1120 | |
| 1121 | // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched. |
| 1122 | // glTexSubImage2D should take into account that the image is dirty. |
| 1123 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data()); |
| 1124 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1125 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1126 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1127 | glUseProgram(mProgram); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1128 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1129 | drawQuad(mProgram, "position", 0.5f); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1130 | glDeleteTextures(1, &tex2D); |
| 1131 | EXPECT_GL_NO_ERROR(); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1132 | EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255); |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 1133 | |
| 1134 | // Validate that the region of the texture without data has an alpha of 1.0 |
| 1135 | GLubyte pixel[4]; |
| 1136 | glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 1137 | EXPECT_EQ(pixel[3], 255); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | // Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has initialized the image with a default color. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1141 | TEST_P(Texture2DTest, TexStorageWithPBO) |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1142 | { |
| 1143 | if (extensionEnabled("NV_pixel_buffer_object")) |
| 1144 | { |
| 1145 | int width = getWindowWidth(); |
| 1146 | int height = getWindowHeight(); |
| 1147 | |
| 1148 | GLuint tex2D; |
| 1149 | glGenTextures(1, &tex2D); |
| 1150 | glActiveTexture(GL_TEXTURE0); |
| 1151 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 1152 | |
| 1153 | // Fill with red |
| 1154 | std::vector<GLubyte> pixels(3 * 16 * 16); |
| 1155 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 1156 | { |
| 1157 | pixels[pixelId * 3 + 0] = 255; |
| 1158 | pixels[pixelId * 3 + 1] = 0; |
| 1159 | pixels[pixelId * 3 + 2] = 0; |
| 1160 | } |
| 1161 | |
| 1162 | // Read 16x16 region from red backbuffer to PBO |
| 1163 | GLuint pbo; |
| 1164 | glGenBuffers(1, &pbo); |
| 1165 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); |
| 1166 | glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW); |
| 1167 | |
| 1168 | // ANGLE internally uses RGBA as the DirectX format for RGB images |
| 1169 | // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color. |
| 1170 | // The data is kept in a CPU-side image and the image is marked as dirty. |
| 1171 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16); |
| 1172 | |
| 1173 | // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched. |
| 1174 | // glTexSubImage2D should take into account that the image is dirty. |
| 1175 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 1176 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1177 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1178 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1179 | glUseProgram(mProgram); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1180 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1181 | drawQuad(mProgram, "position", 0.5f); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1182 | glDeleteTextures(1, &tex2D); |
Olli Etuaho | 19d48db | 2016-01-13 14:43:21 +0200 | [diff] [blame] | 1183 | glDeleteBuffers(1, &pbo); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1184 | EXPECT_GL_NO_ERROR(); |
| 1185 | EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255); |
| 1186 | EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255); |
| 1187 | } |
| 1188 | } |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1189 | |
| 1190 | // See description on testFloatCopySubImage |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1191 | TEST_P(Texture2DTest, CopySubImageFloat_R_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1192 | { |
| 1193 | testFloatCopySubImage(1, 1); |
| 1194 | } |
| 1195 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1196 | TEST_P(Texture2DTest, CopySubImageFloat_RG_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1197 | { |
| 1198 | testFloatCopySubImage(2, 1); |
| 1199 | } |
| 1200 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1201 | TEST_P(Texture2DTest, CopySubImageFloat_RG_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1202 | { |
| 1203 | testFloatCopySubImage(2, 2); |
| 1204 | } |
| 1205 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1206 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1207 | { |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame] | 1208 | if (IsIntel() && IsLinux()) |
| 1209 | { |
| 1210 | // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346) |
| 1211 | std::cout << "Test disabled on Linux Intel OpenGL." << std::endl; |
| 1212 | return; |
| 1213 | } |
| 1214 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1215 | testFloatCopySubImage(3, 1); |
| 1216 | } |
| 1217 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1218 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1219 | { |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame] | 1220 | if (IsIntel() && IsLinux()) |
| 1221 | { |
| 1222 | // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346) |
| 1223 | std::cout << "Test disabled on Linux Intel OpenGL." << std::endl; |
| 1224 | return; |
| 1225 | } |
| 1226 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1227 | testFloatCopySubImage(3, 2); |
| 1228 | } |
| 1229 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1230 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1231 | { |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame] | 1232 | if (IsIntel() && IsLinux()) |
| 1233 | { |
| 1234 | // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346) |
| 1235 | std::cout << "Test disabled on Linux Intel OpenGL." << std::endl; |
| 1236 | return; |
| 1237 | } |
| 1238 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1239 | // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3 |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1240 | if (IsD3D11_FL93()) |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1241 | { |
| 1242 | std::cout << "Test skipped on Feature Level 9_3." << std::endl; |
| 1243 | return; |
| 1244 | } |
| 1245 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1246 | testFloatCopySubImage(3, 3); |
| 1247 | } |
| 1248 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1249 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1250 | { |
| 1251 | testFloatCopySubImage(4, 1); |
| 1252 | } |
| 1253 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1254 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1255 | { |
| 1256 | testFloatCopySubImage(4, 2); |
| 1257 | } |
| 1258 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1259 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1260 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1261 | // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3 |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1262 | if (IsD3D11_FL93()) |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1263 | { |
| 1264 | std::cout << "Test skipped on Feature Level 9_3." << std::endl; |
| 1265 | return; |
| 1266 | } |
| 1267 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1268 | testFloatCopySubImage(4, 3); |
| 1269 | } |
| 1270 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1271 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1272 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1273 | // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3 |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1274 | if (IsD3D11_FL93()) |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1275 | { |
| 1276 | std::cout << "Test skipped on Feature Level 9_3." << std::endl; |
| 1277 | return; |
| 1278 | } |
| 1279 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1280 | testFloatCopySubImage(4, 4); |
| 1281 | } |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1282 | |
| 1283 | // Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html |
| 1284 | // Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly handles GL_ALPHA |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1285 | TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE) |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1286 | { |
| 1287 | const int npotTexSize = 5; |
| 1288 | const int potTexSize = 4; // Should be less than npotTexSize |
| 1289 | GLuint tex2D; |
| 1290 | |
| 1291 | if (extensionEnabled("GL_OES_texture_npot")) |
| 1292 | { |
| 1293 | // This test isn't applicable if texture_npot is enabled |
| 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 1298 | |
Austin Kinross | 5faa15b | 2016-01-11 13:32:48 -0800 | [diff] [blame] | 1299 | // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1. |
| 1300 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 1301 | |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1302 | glActiveTexture(GL_TEXTURE0); |
| 1303 | glGenTextures(1, &tex2D); |
| 1304 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 1305 | |
| 1306 | std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize); |
| 1307 | for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId) |
| 1308 | { |
| 1309 | pixels[pixelId] = 64; |
| 1310 | } |
| 1311 | |
| 1312 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1313 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1314 | |
| 1315 | // Check that an NPOT texture not on level 0 generates INVALID_VALUE |
| 1316 | glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 1317 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 1318 | |
| 1319 | // Check that an NPOT texture on level 0 succeeds |
| 1320 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 1321 | EXPECT_GL_NO_ERROR(); |
| 1322 | |
| 1323 | // Check that generateMipmap fails on NPOT |
| 1324 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1325 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1326 | |
| 1327 | // Check that nothing is drawn if filtering is not correct for NPOT |
| 1328 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1329 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1330 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 1331 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 1332 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1333 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1334 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255); |
| 1335 | |
| 1336 | // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255 |
| 1337 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1338 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1339 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); |
| 1340 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1341 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1342 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255); |
| 1343 | |
| 1344 | // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw |
| 1345 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1346 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1347 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1348 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64); |
| 1349 | |
| 1350 | // Check that glTexImage2D for POT texture succeeds |
| 1351 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 1352 | EXPECT_GL_NO_ERROR(); |
| 1353 | |
| 1354 | // Check that generateMipmap for an POT texture succeeds |
| 1355 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1356 | EXPECT_GL_NO_ERROR(); |
| 1357 | |
| 1358 | // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw |
| 1359 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1360 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1361 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 1362 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 1363 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1364 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1365 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64); |
| 1366 | EXPECT_GL_NO_ERROR(); |
| 1367 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1368 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1369 | // Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions. |
| 1370 | // ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1371 | TEST_P(Texture2DTest, NPOTSubImageParameters) |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1372 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1373 | // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug |
| 1374 | // 1278) |
| 1375 | if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE || |
| 1376 | getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1377 | { |
| 1378 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1379 | return; |
| 1380 | } |
| 1381 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1382 | glActiveTexture(GL_TEXTURE0); |
| 1383 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1384 | |
| 1385 | // Create an 8x8 (i.e. power-of-two) texture. |
| 1386 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1387 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 1388 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1389 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1390 | |
| 1391 | // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture. |
| 1392 | // This should always work, even if GL_OES_texture_npot isn't active. |
| 1393 | glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1394 | |
| 1395 | EXPECT_GL_NO_ERROR(); |
| 1396 | } |
| 1397 | |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 1398 | // Test to check that texture completeness is determined correctly when the texture base level is |
| 1399 | // greater than 0, and also that level 0 is not sampled when base level is greater than 0. |
| 1400 | TEST_P(Texture2DTestES3, DrawWithBaseLevel1) |
| 1401 | { |
| 1402 | glActiveTexture(GL_TEXTURE0); |
| 1403 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1404 | GLubyte texDataRed[4u * 4u * 4u]; |
Olli Etuaho | 356f516 | 2016-03-18 14:19:41 +0200 | [diff] [blame] | 1405 | FillWithRGBA<GLubyte>(4u * 4u, 255u, 0u, 0u, 255u, texDataRed); |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 1406 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed); |
| 1407 | GLubyte texDataGreen[2u * 2u * 4u]; |
Olli Etuaho | 356f516 | 2016-03-18 14:19:41 +0200 | [diff] [blame] | 1408 | FillWithRGBA<GLubyte>(2u * 2u, 0u, 255u, 0u, 255u, texDataGreen); |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 1409 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataGreen); |
| 1410 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataGreen); |
| 1411 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1412 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1413 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1414 | |
| 1415 | EXPECT_GL_NO_ERROR(); |
| 1416 | |
| 1417 | drawQuad(mProgram, "position", 0.5f); |
| 1418 | |
| 1419 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 1420 | } |
| 1421 | |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 1422 | // In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0 |
| 1423 | // in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as |
| 1424 | // expected. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1425 | TEST_P(Texture2DArrayTestES3, RedefineInittableArray) |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 1426 | { |
| 1427 | std::vector<GLubyte> pixelData; |
| 1428 | for (size_t count = 0; count < 5000; count++) |
| 1429 | { |
| 1430 | pixelData.push_back(0u); |
| 1431 | pixelData.push_back(255u); |
| 1432 | pixelData.push_back(0u); |
| 1433 | } |
| 1434 | |
| 1435 | glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1436 | glUseProgram(mProgram); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 1437 | glUniform1i(mTextureArrayLocation, 0); |
| 1438 | |
| 1439 | // The first draw worked correctly. |
| 1440 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]); |
| 1441 | |
| 1442 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1443 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1444 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 1445 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1446 | drawQuad(mProgram, "position", 1.0f); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 1447 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 1448 | |
| 1449 | // The dimension of the respecification must match the original exactly to trigger the bug. |
| 1450 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1451 | drawQuad(mProgram, "position", 1.0f); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 1452 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 1453 | |
| 1454 | ASSERT_GL_NO_ERROR(); |
| 1455 | } |
| 1456 | |
Olli Etuaho | 1a67990 | 2016-01-14 12:21:47 +0200 | [diff] [blame] | 1457 | // Test shadow sampler and regular non-shadow sampler coexisting in the same shader. |
| 1458 | // This test is needed especially to confirm that sampler registers get assigned correctly on |
| 1459 | // the HLSL backend even when there's a mix of different HLSL sampler and texture types. |
| 1460 | TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw) |
| 1461 | { |
| 1462 | glActiveTexture(GL_TEXTURE0); |
| 1463 | glBindTexture(GL_TEXTURE_3D, mTexture3D); |
| 1464 | GLubyte texData[4]; |
| 1465 | texData[0] = 0; |
| 1466 | texData[1] = 60; |
| 1467 | texData[2] = 0; |
| 1468 | texData[3] = 255; |
| 1469 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 1470 | |
| 1471 | glActiveTexture(GL_TEXTURE1); |
| 1472 | glBindTexture(GL_TEXTURE_2D, mTextureShadow); |
| 1473 | GLfloat depthTexData[1]; |
| 1474 | depthTexData[0] = 0.5f; |
| 1475 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT, |
| 1476 | depthTexData); |
| 1477 | |
| 1478 | glUseProgram(mProgram); |
| 1479 | glUniform1f(mDepthRefUniformLocation, 0.3f); |
| 1480 | glUniform1i(mTexture3DUniformLocation, 0); |
| 1481 | glUniform1i(mTextureShadowUniformLocation, 1); |
| 1482 | |
| 1483 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); |
| 1484 | drawQuad(mProgram, "position", 0.5f); |
| 1485 | EXPECT_GL_NO_ERROR(); |
| 1486 | // The shader writes 0.5 * <comparison result (1.0)> + <texture color> |
| 1487 | EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2); |
| 1488 | |
| 1489 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER); |
| 1490 | drawQuad(mProgram, "position", 0.5f); |
| 1491 | EXPECT_GL_NO_ERROR(); |
| 1492 | // The shader writes 0.5 * <comparison result (0.0)> + <texture color> |
| 1493 | EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2); |
| 1494 | } |
| 1495 | |
Olli Etuaho | c8c99a0 | 2016-01-14 16:47:22 +0200 | [diff] [blame] | 1496 | // Test multiple different sampler types in the same shader. |
| 1497 | // This test makes sure that even if sampler / texture registers get grouped together based on type |
| 1498 | // or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer |
| 1499 | // still has the right register index information for each ESSL sampler. |
| 1500 | // The tested ESSL samplers have the following types in D3D11 HLSL: |
| 1501 | // sampler2D: Texture2D + SamplerState |
| 1502 | // samplerCube: TextureCube + SamplerState |
| 1503 | // sampler2DShadow: Texture2D + SamplerComparisonState |
| 1504 | // samplerCubeShadow: TextureCube + SamplerComparisonState |
| 1505 | TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw) |
| 1506 | { |
| 1507 | glActiveTexture(GL_TEXTURE0); |
| 1508 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1509 | GLubyte texData[4]; |
| 1510 | texData[0] = 0; |
| 1511 | texData[1] = 0; |
| 1512 | texData[2] = 120; |
| 1513 | texData[3] = 255; |
| 1514 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 1515 | |
| 1516 | glActiveTexture(GL_TEXTURE1); |
| 1517 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 1518 | texData[0] = 0; |
| 1519 | texData[1] = 90; |
| 1520 | texData[2] = 0; |
| 1521 | texData[3] = 255; |
| 1522 | glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1); |
| 1523 | glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1524 | texData); |
| 1525 | |
| 1526 | glActiveTexture(GL_TEXTURE2); |
| 1527 | glBindTexture(GL_TEXTURE_2D, mTexture2DShadow); |
| 1528 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); |
| 1529 | GLfloat depthTexData[1]; |
| 1530 | depthTexData[0] = 0.5f; |
| 1531 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT, |
| 1532 | depthTexData); |
| 1533 | |
| 1534 | glActiveTexture(GL_TEXTURE3); |
| 1535 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow); |
| 1536 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); |
| 1537 | depthTexData[0] = 0.2f; |
| 1538 | glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1); |
| 1539 | glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, |
| 1540 | depthTexData); |
| 1541 | |
| 1542 | EXPECT_GL_NO_ERROR(); |
| 1543 | |
| 1544 | glUseProgram(mProgram); |
| 1545 | glUniform1f(mDepthRefUniformLocation, 0.3f); |
| 1546 | glUniform1i(mTexture2DUniformLocation, 0); |
| 1547 | glUniform1i(mTextureCubeUniformLocation, 1); |
| 1548 | glUniform1i(mTexture2DShadowUniformLocation, 2); |
| 1549 | glUniform1i(mTextureCubeShadowUniformLocation, 3); |
| 1550 | |
| 1551 | drawQuad(mProgram, "position", 0.5f); |
| 1552 | EXPECT_GL_NO_ERROR(); |
| 1553 | // The shader writes: |
| 1554 | // <texture 2d color> + |
| 1555 | // <cube map color> + |
| 1556 | // 0.25 * <comparison result (1.0)> + |
| 1557 | // 0.125 * <comparison result (0.0)> |
| 1558 | EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2); |
| 1559 | } |
| 1560 | |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 1561 | // Test different base levels on textures accessed through the same sampler array. |
| 1562 | // Calling textureSize() on the samplers hits the D3D sampler metadata workaround. |
| 1563 | TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray) |
| 1564 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1565 | if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE) |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 1566 | { |
| 1567 | std::cout << "Test skipped on Intel and AMD D3D." << std::endl; |
| 1568 | return; |
| 1569 | } |
| 1570 | glActiveTexture(GL_TEXTURE0); |
| 1571 | glBindTexture(GL_TEXTURE_2D, mTexture2DA); |
| 1572 | GLsizei size = 64; |
| 1573 | for (GLint level = 0; level < 7; ++level) |
| 1574 | { |
| 1575 | ASSERT_LT(0, size); |
| 1576 | glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1577 | nullptr); |
| 1578 | size = size / 2; |
| 1579 | } |
| 1580 | ASSERT_EQ(0, size); |
| 1581 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1582 | |
| 1583 | glActiveTexture(GL_TEXTURE1); |
| 1584 | glBindTexture(GL_TEXTURE_2D, mTexture2DB); |
| 1585 | size = 128; |
| 1586 | for (GLint level = 0; level < 8; ++level) |
| 1587 | { |
| 1588 | ASSERT_LT(0, size); |
| 1589 | glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1590 | nullptr); |
| 1591 | size = size / 2; |
| 1592 | } |
| 1593 | ASSERT_EQ(0, size); |
| 1594 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3); |
| 1595 | EXPECT_GL_NO_ERROR(); |
| 1596 | |
| 1597 | glUseProgram(mProgram); |
| 1598 | glUniform1i(mTexture0Location, 0); |
| 1599 | glUniform1i(mTexture1Location, 1); |
| 1600 | |
| 1601 | drawQuad(mProgram, "position", 0.5f); |
| 1602 | EXPECT_GL_NO_ERROR(); |
| 1603 | // Red channel: width of level 1 of texture A: 32. |
| 1604 | // Green channel: width of level 3 of texture B: 16. |
| 1605 | EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2); |
| 1606 | } |
| 1607 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1608 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1609 | // ES 3.0.4 table 3.24 |
| 1610 | TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1) |
| 1611 | { |
| 1612 | glActiveTexture(GL_TEXTURE0); |
| 1613 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1614 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); |
| 1615 | EXPECT_GL_NO_ERROR(); |
| 1616 | |
| 1617 | drawQuad(mProgram, "position", 0.5f); |
| 1618 | |
| 1619 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1620 | } |
| 1621 | |
| 1622 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1623 | // ES 3.0.4 table 3.24 |
| 1624 | TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1) |
| 1625 | { |
| 1626 | glActiveTexture(GL_TEXTURE0); |
| 1627 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1628 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr); |
| 1629 | EXPECT_GL_NO_ERROR(); |
| 1630 | |
| 1631 | drawQuad(mProgram, "position", 0.5f); |
| 1632 | |
| 1633 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1634 | } |
| 1635 | |
| 1636 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1637 | // ES 3.0.4 table 3.24 |
| 1638 | TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1) |
| 1639 | { |
| 1640 | if (extensionEnabled("GL_OES_texture_float")) |
| 1641 | { |
| 1642 | glActiveTexture(GL_TEXTURE0); |
| 1643 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1644 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr); |
| 1645 | EXPECT_GL_NO_ERROR(); |
| 1646 | |
| 1647 | drawQuad(mProgram, "position", 0.5f); |
| 1648 | |
| 1649 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1654 | // ES 3.0.4 table 3.24 |
| 1655 | TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1) |
| 1656 | { |
| 1657 | if (extensionEnabled("GL_OES_texture_half_float")) |
| 1658 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1659 | if (IsNVIDIA() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1660 | { |
| 1661 | std::cout << "Test skipped on NVIDIA" << std::endl; |
| 1662 | return; |
| 1663 | } |
| 1664 | glActiveTexture(GL_TEXTURE0); |
| 1665 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1666 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, |
| 1667 | nullptr); |
| 1668 | EXPECT_GL_NO_ERROR(); |
| 1669 | |
| 1670 | drawQuad(mProgram, "position", 0.5f); |
| 1671 | |
| 1672 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1677 | // ES 3.0.4 table 3.24 |
| 1678 | TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1) |
| 1679 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1680 | if (IsIntel()) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1681 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1682 | std::cout << "Test disabled on Intel." << std::endl; |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1683 | return; |
| 1684 | } |
| 1685 | glActiveTexture(GL_TEXTURE0); |
| 1686 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1687 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr); |
| 1688 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1689 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1690 | EXPECT_GL_NO_ERROR(); |
| 1691 | |
| 1692 | drawQuad(mProgram, "position", 0.5f); |
| 1693 | |
| 1694 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1695 | } |
| 1696 | |
| 1697 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1698 | // ES 3.0.4 table 3.24 |
| 1699 | TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1) |
| 1700 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1701 | if (IsIntel()) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1702 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1703 | std::cout << "Test disabled on Intel." << std::endl; |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1704 | return; |
| 1705 | } |
| 1706 | glActiveTexture(GL_TEXTURE0); |
| 1707 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1708 | |
| 1709 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr); |
| 1710 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1711 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1712 | EXPECT_GL_NO_ERROR(); |
| 1713 | |
| 1714 | drawQuad(mProgram, "position", 0.5f); |
| 1715 | |
| 1716 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1717 | } |
| 1718 | |
| 1719 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1720 | // ES 3.0.4 table 3.24 |
| 1721 | TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1) |
| 1722 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1723 | if (IsIntel()) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1724 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1725 | std::cout << "Test disabled on Intel." << std::endl; |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1726 | return; |
| 1727 | } |
| 1728 | glActiveTexture(GL_TEXTURE0); |
| 1729 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1730 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr); |
| 1731 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1732 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1733 | EXPECT_GL_NO_ERROR(); |
| 1734 | |
| 1735 | drawQuad(mProgram, "position", 0.5f); |
| 1736 | |
| 1737 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1738 | } |
| 1739 | |
| 1740 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1741 | // ES 3.0.4 table 3.24 |
| 1742 | TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1) |
| 1743 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1744 | if (IsIntel()) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1745 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1746 | std::cout << "Test disabled on Intel." << std::endl; |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1747 | return; |
| 1748 | } |
| 1749 | glActiveTexture(GL_TEXTURE0); |
| 1750 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1751 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr); |
| 1752 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1753 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1754 | EXPECT_GL_NO_ERROR(); |
| 1755 | |
| 1756 | drawQuad(mProgram, "position", 0.5f); |
| 1757 | |
| 1758 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1759 | } |
| 1760 | |
| 1761 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1762 | // ES 3.0.4 table 3.24 |
| 1763 | TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1) |
| 1764 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1765 | if (IsIntel()) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1766 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1767 | std::cout << "Test disabled on Intel." << std::endl; |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1768 | return; |
| 1769 | } |
| 1770 | glActiveTexture(GL_TEXTURE0); |
| 1771 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1772 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr); |
| 1773 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1774 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1775 | EXPECT_GL_NO_ERROR(); |
| 1776 | |
| 1777 | drawQuad(mProgram, "position", 0.5f); |
| 1778 | |
| 1779 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1780 | } |
| 1781 | |
| 1782 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1783 | // ES 3.0.4 table 3.24 |
| 1784 | TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1) |
| 1785 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1786 | if (IsIntel()) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1787 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1788 | std::cout << "Test disabled on Intel." << std::endl; |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1789 | return; |
| 1790 | } |
| 1791 | glActiveTexture(GL_TEXTURE0); |
| 1792 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1793 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr); |
| 1794 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1795 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1796 | EXPECT_GL_NO_ERROR(); |
| 1797 | |
| 1798 | drawQuad(mProgram, "position", 0.5f); |
| 1799 | |
| 1800 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1801 | } |
| 1802 | |
| 1803 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1804 | // ES 3.0.4 table 3.24 |
| 1805 | TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1) |
| 1806 | { |
| 1807 | glActiveTexture(GL_TEXTURE0); |
| 1808 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1809 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr); |
| 1810 | EXPECT_GL_NO_ERROR(); |
| 1811 | |
| 1812 | drawQuad(mProgram, "position", 0.5f); |
| 1813 | |
| 1814 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1815 | } |
| 1816 | |
| 1817 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1818 | // ES 3.0.4 table 3.24 |
| 1819 | TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1) |
| 1820 | { |
| 1821 | glActiveTexture(GL_TEXTURE0); |
| 1822 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1823 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, |
| 1824 | nullptr); |
| 1825 | EXPECT_GL_NO_ERROR(); |
| 1826 | |
| 1827 | drawQuad(mProgram, "position", 0.5f); |
| 1828 | |
| 1829 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1830 | } |
| 1831 | |
| 1832 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1833 | // ES 3.0.4 table 3.24 |
| 1834 | TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1) |
| 1835 | { |
| 1836 | glActiveTexture(GL_TEXTURE0); |
| 1837 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1838 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr); |
| 1839 | EXPECT_GL_NO_ERROR(); |
| 1840 | |
| 1841 | drawQuad(mProgram, "position", 0.5f); |
| 1842 | |
| 1843 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1844 | } |
| 1845 | |
| 1846 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 1847 | // ES 3.0.4 table 3.24 |
| 1848 | TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1) |
| 1849 | { |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame] | 1850 | if (IsIntel() && IsLinux()) |
| 1851 | { |
| 1852 | // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346) |
| 1853 | std::cout << "Test disabled on Linux Intel OpenGL." << std::endl; |
| 1854 | return; |
| 1855 | } |
| 1856 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 1857 | glActiveTexture(GL_TEXTURE0); |
| 1858 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1859 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr); |
| 1860 | EXPECT_GL_NO_ERROR(); |
| 1861 | |
| 1862 | drawQuad(mProgram, "position", 0.5f); |
| 1863 | |
| 1864 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 1865 | } |
| 1866 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1867 | class TextureLimitsTest : public ANGLETest |
| 1868 | { |
| 1869 | protected: |
| 1870 | struct RGBA8 |
| 1871 | { |
| 1872 | uint8_t R, G, B, A; |
| 1873 | }; |
| 1874 | |
| 1875 | TextureLimitsTest() |
| 1876 | : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0) |
| 1877 | { |
| 1878 | setWindowWidth(128); |
| 1879 | setWindowHeight(128); |
| 1880 | setConfigRedBits(8); |
| 1881 | setConfigGreenBits(8); |
| 1882 | setConfigBlueBits(8); |
| 1883 | setConfigAlphaBits(8); |
| 1884 | } |
| 1885 | |
| 1886 | ~TextureLimitsTest() |
| 1887 | { |
| 1888 | if (mProgram != 0) |
| 1889 | { |
| 1890 | glDeleteProgram(mProgram); |
| 1891 | mProgram = 0; |
| 1892 | |
| 1893 | if (!mTextures.empty()) |
| 1894 | { |
| 1895 | glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]); |
| 1896 | } |
| 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | void SetUp() override |
| 1901 | { |
| 1902 | ANGLETest::SetUp(); |
| 1903 | |
| 1904 | glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures); |
| 1905 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures); |
| 1906 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures); |
| 1907 | |
| 1908 | ASSERT_GL_NO_ERROR(); |
| 1909 | } |
| 1910 | |
| 1911 | void compileProgramWithTextureCounts(const std::string &vertexPrefix, |
| 1912 | GLint vertexTextureCount, |
| 1913 | GLint vertexActiveTextureCount, |
| 1914 | const std::string &fragPrefix, |
| 1915 | GLint fragmentTextureCount, |
| 1916 | GLint fragmentActiveTextureCount) |
| 1917 | { |
| 1918 | std::stringstream vertexShaderStr; |
| 1919 | vertexShaderStr << "attribute vec2 position;\n" |
| 1920 | << "varying vec4 color;\n" |
| 1921 | << "varying vec2 texCoord;\n"; |
| 1922 | |
| 1923 | for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex) |
| 1924 | { |
| 1925 | vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n"; |
| 1926 | } |
| 1927 | |
| 1928 | vertexShaderStr << "void main() {\n" |
| 1929 | << " gl_Position = vec4(position, 0, 1);\n" |
| 1930 | << " texCoord = (position * 0.5) + 0.5;\n" |
| 1931 | << " color = vec4(0);\n"; |
| 1932 | |
| 1933 | for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex) |
| 1934 | { |
| 1935 | vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex |
| 1936 | << ", texCoord);\n"; |
| 1937 | } |
| 1938 | |
| 1939 | vertexShaderStr << "}"; |
| 1940 | |
| 1941 | std::stringstream fragmentShaderStr; |
| 1942 | fragmentShaderStr << "varying mediump vec4 color;\n" |
| 1943 | << "varying mediump vec2 texCoord;\n"; |
| 1944 | |
| 1945 | for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex) |
| 1946 | { |
| 1947 | fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n"; |
| 1948 | } |
| 1949 | |
| 1950 | fragmentShaderStr << "void main() {\n" |
| 1951 | << " gl_FragColor = color;\n"; |
| 1952 | |
| 1953 | for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex) |
| 1954 | { |
| 1955 | fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex |
| 1956 | << ", texCoord);\n"; |
| 1957 | } |
| 1958 | |
| 1959 | fragmentShaderStr << "}"; |
| 1960 | |
| 1961 | const std::string &vertexShaderSource = vertexShaderStr.str(); |
| 1962 | const std::string &fragmentShaderSource = fragmentShaderStr.str(); |
| 1963 | |
| 1964 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1965 | } |
| 1966 | |
| 1967 | RGBA8 getPixel(GLint texIndex) |
| 1968 | { |
| 1969 | RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3), |
| 1970 | 0, 255u}; |
| 1971 | return pixel; |
| 1972 | } |
| 1973 | |
| 1974 | void initTextures(GLint tex2DCount, GLint texCubeCount) |
| 1975 | { |
| 1976 | GLint totalCount = tex2DCount + texCubeCount; |
| 1977 | mTextures.assign(totalCount, 0); |
| 1978 | glGenTextures(totalCount, &mTextures[0]); |
| 1979 | ASSERT_GL_NO_ERROR(); |
| 1980 | |
| 1981 | std::vector<RGBA8> texData(16 * 16); |
| 1982 | |
| 1983 | GLint texIndex = 0; |
| 1984 | for (; texIndex < tex2DCount; ++texIndex) |
| 1985 | { |
| 1986 | texData.assign(texData.size(), getPixel(texIndex)); |
| 1987 | glActiveTexture(GL_TEXTURE0 + texIndex); |
| 1988 | glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]); |
| 1989 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1990 | &texData[0]); |
| 1991 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1992 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1993 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1994 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1995 | } |
| 1996 | |
| 1997 | ASSERT_GL_NO_ERROR(); |
| 1998 | |
| 1999 | for (; texIndex < texCubeCount; ++texIndex) |
| 2000 | { |
| 2001 | texData.assign(texData.size(), getPixel(texIndex)); |
| 2002 | glActiveTexture(GL_TEXTURE0 + texIndex); |
| 2003 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]); |
| 2004 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2005 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2006 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2007 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2008 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2009 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2010 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2011 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2012 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2013 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2014 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2015 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2016 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2017 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2018 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 2019 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 2020 | } |
| 2021 | |
| 2022 | ASSERT_GL_NO_ERROR(); |
| 2023 | } |
| 2024 | |
| 2025 | void testWithTextures(GLint vertexTextureCount, |
| 2026 | const std::string &vertexTexturePrefix, |
| 2027 | GLint fragmentTextureCount, |
| 2028 | const std::string &fragmentTexturePrefix) |
| 2029 | { |
| 2030 | // Generate textures |
| 2031 | initTextures(vertexTextureCount + fragmentTextureCount, 0); |
| 2032 | |
| 2033 | glUseProgram(mProgram); |
| 2034 | RGBA8 expectedSum = {0}; |
| 2035 | for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex) |
| 2036 | { |
| 2037 | std::stringstream uniformNameStr; |
| 2038 | uniformNameStr << vertexTexturePrefix << texIndex; |
| 2039 | const std::string &uniformName = uniformNameStr.str(); |
| 2040 | GLint location = glGetUniformLocation(mProgram, uniformName.c_str()); |
| 2041 | ASSERT_NE(-1, location); |
| 2042 | |
| 2043 | glUniform1i(location, texIndex); |
| 2044 | RGBA8 contribution = getPixel(texIndex); |
| 2045 | expectedSum.R += contribution.R; |
| 2046 | expectedSum.G += contribution.G; |
| 2047 | } |
| 2048 | |
| 2049 | for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex) |
| 2050 | { |
| 2051 | std::stringstream uniformNameStr; |
| 2052 | uniformNameStr << fragmentTexturePrefix << texIndex; |
| 2053 | const std::string &uniformName = uniformNameStr.str(); |
| 2054 | GLint location = glGetUniformLocation(mProgram, uniformName.c_str()); |
| 2055 | ASSERT_NE(-1, location); |
| 2056 | |
| 2057 | glUniform1i(location, texIndex + vertexTextureCount); |
| 2058 | RGBA8 contribution = getPixel(texIndex + vertexTextureCount); |
| 2059 | expectedSum.R += contribution.R; |
| 2060 | expectedSum.G += contribution.G; |
| 2061 | } |
| 2062 | |
| 2063 | ASSERT_GE(256u, expectedSum.G); |
| 2064 | |
| 2065 | drawQuad(mProgram, "position", 0.5f); |
| 2066 | ASSERT_GL_NO_ERROR(); |
| 2067 | EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255); |
| 2068 | } |
| 2069 | |
| 2070 | GLuint mProgram; |
| 2071 | std::vector<GLuint> mTextures; |
| 2072 | GLint mMaxVertexTextures; |
| 2073 | GLint mMaxFragmentTextures; |
| 2074 | GLint mMaxCombinedTextures; |
| 2075 | }; |
| 2076 | |
| 2077 | // Test rendering with the maximum vertex texture units. |
| 2078 | TEST_P(TextureLimitsTest, MaxVertexTextures) |
| 2079 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 2080 | // TODO(jmadill): Figure out why this fails on Intel. |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 2081 | if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 2082 | { |
| 2083 | std::cout << "Test skipped on Intel." << std::endl; |
| 2084 | return; |
| 2085 | } |
| 2086 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2087 | compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0); |
| 2088 | ASSERT_NE(0u, mProgram); |
| 2089 | ASSERT_GL_NO_ERROR(); |
| 2090 | |
| 2091 | testWithTextures(mMaxVertexTextures, "tex", 0, "tex"); |
| 2092 | } |
| 2093 | |
| 2094 | // Test rendering with the maximum fragment texture units. |
| 2095 | TEST_P(TextureLimitsTest, MaxFragmentTextures) |
| 2096 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 2097 | // TODO(jmadill): Figure out why this fails on Intel. |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 2098 | if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 2099 | { |
| 2100 | std::cout << "Test skipped on Intel." << std::endl; |
| 2101 | return; |
| 2102 | } |
| 2103 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2104 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures); |
| 2105 | ASSERT_NE(0u, mProgram); |
| 2106 | ASSERT_GL_NO_ERROR(); |
| 2107 | |
| 2108 | testWithTextures(mMaxFragmentTextures, "tex", 0, "tex"); |
| 2109 | } |
| 2110 | |
| 2111 | // Test rendering with maximum combined texture units. |
| 2112 | TEST_P(TextureLimitsTest, MaxCombinedTextures) |
| 2113 | { |
Jamie Madill | 412f17d | 2015-09-25 08:43:54 -0400 | [diff] [blame] | 2114 | // TODO(jmadill): Investigate workaround. |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 2115 | if (IsIntel() && GetParam() == ES2_OPENGL()) |
Jamie Madill | 412f17d | 2015-09-25 08:43:54 -0400 | [diff] [blame] | 2116 | { |
| 2117 | std::cout << "Test skipped on Intel." << std::endl; |
| 2118 | return; |
| 2119 | } |
| 2120 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2121 | GLint vertexTextures = mMaxVertexTextures; |
| 2122 | |
| 2123 | if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures) |
| 2124 | { |
| 2125 | vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures; |
| 2126 | } |
| 2127 | |
| 2128 | compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex", |
| 2129 | mMaxFragmentTextures, mMaxFragmentTextures); |
| 2130 | ASSERT_NE(0u, mProgram); |
| 2131 | ASSERT_GL_NO_ERROR(); |
| 2132 | |
| 2133 | testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex"); |
| 2134 | } |
| 2135 | |
| 2136 | // Negative test for exceeding the number of vertex textures |
| 2137 | TEST_P(TextureLimitsTest, ExcessiveVertexTextures) |
| 2138 | { |
| 2139 | compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0, |
| 2140 | 0); |
| 2141 | ASSERT_EQ(0u, mProgram); |
| 2142 | } |
| 2143 | |
| 2144 | // Negative test for exceeding the number of fragment textures |
| 2145 | TEST_P(TextureLimitsTest, ExcessiveFragmentTextures) |
| 2146 | { |
| 2147 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1, |
| 2148 | mMaxFragmentTextures + 1); |
| 2149 | ASSERT_EQ(0u, mProgram); |
| 2150 | } |
| 2151 | |
| 2152 | // Test active vertex textures under the limit, but excessive textures specified. |
| 2153 | TEST_P(TextureLimitsTest, MaxActiveVertexTextures) |
| 2154 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 2155 | // TODO(jmadill): Figure out why this fails on Intel. |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 2156 | if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 2157 | { |
| 2158 | std::cout << "Test skipped on Intel." << std::endl; |
| 2159 | return; |
| 2160 | } |
| 2161 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2162 | compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0); |
| 2163 | ASSERT_NE(0u, mProgram); |
| 2164 | ASSERT_GL_NO_ERROR(); |
| 2165 | |
| 2166 | testWithTextures(mMaxVertexTextures, "tex", 0, "tex"); |
| 2167 | } |
| 2168 | |
| 2169 | // Test active fragment textures under the limit, but excessive textures specified. |
| 2170 | TEST_P(TextureLimitsTest, MaxActiveFragmentTextures) |
| 2171 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 2172 | // TODO(jmadill): Figure out why this fails on Intel. |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 2173 | if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 2174 | { |
| 2175 | std::cout << "Test skipped on Intel." << std::endl; |
| 2176 | return; |
| 2177 | } |
| 2178 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2179 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4, |
| 2180 | mMaxFragmentTextures); |
| 2181 | ASSERT_NE(0u, mProgram); |
| 2182 | ASSERT_GL_NO_ERROR(); |
| 2183 | |
| 2184 | testWithTextures(0, "tex", mMaxFragmentTextures, "tex"); |
| 2185 | } |
| 2186 | |
| 2187 | // Negative test for pointing two sampler uniforms of different types to the same texture. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 2188 | // GLES 2.0.25 section 2.10.4 page 39. |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2189 | TEST_P(TextureLimitsTest, TextureTypeConflict) |
| 2190 | { |
| 2191 | const std::string &vertexShader = |
| 2192 | "attribute vec2 position;\n" |
| 2193 | "varying float color;\n" |
| 2194 | "uniform sampler2D tex2D;\n" |
| 2195 | "uniform samplerCube texCube;\n" |
| 2196 | "void main() {\n" |
| 2197 | " gl_Position = vec4(position, 0, 1);\n" |
| 2198 | " vec2 texCoord = (position * 0.5) + 0.5;\n" |
| 2199 | " color = texture2D(tex2D, texCoord).x;\n" |
| 2200 | " color += textureCube(texCube, vec3(texCoord, 0)).x;\n" |
| 2201 | "}"; |
| 2202 | const std::string &fragmentShader = |
| 2203 | "varying mediump float color;\n" |
| 2204 | "void main() {\n" |
| 2205 | " gl_FragColor = vec4(color, 0, 0, 1);\n" |
| 2206 | "}"; |
| 2207 | |
| 2208 | mProgram = CompileProgram(vertexShader, fragmentShader); |
| 2209 | ASSERT_NE(0u, mProgram); |
| 2210 | |
| 2211 | initTextures(1, 0); |
| 2212 | |
| 2213 | glUseProgram(mProgram); |
| 2214 | GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D"); |
| 2215 | ASSERT_NE(-1, tex2DLocation); |
| 2216 | GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube"); |
| 2217 | ASSERT_NE(-1, texCubeLocation); |
| 2218 | |
| 2219 | glUniform1i(tex2DLocation, 0); |
| 2220 | glUniform1i(texCubeLocation, 0); |
| 2221 | ASSERT_GL_NO_ERROR(); |
| 2222 | |
| 2223 | drawQuad(mProgram, "position", 0.5f); |
| 2224 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2225 | } |
| 2226 | |
| 2227 | // Negative test for rendering with texture outside the valid range. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 2228 | // TODO(jmadill): Possibly adjust the test according to the spec: |
| 2229 | // GLES 3.0.4 section 2.12.7 mentions that specifying an out-of-range sampler uniform value |
| 2230 | // generates an INVALID_VALUE error - GLES 2.0 doesn't yet have this mention. |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2231 | TEST_P(TextureLimitsTest, DrawWithTexturePastMaximum) |
| 2232 | { |
| 2233 | const std::string &vertexShader = |
| 2234 | "attribute vec2 position;\n" |
| 2235 | "varying float color;\n" |
| 2236 | "uniform sampler2D tex2D;\n" |
| 2237 | "void main() {\n" |
| 2238 | " gl_Position = vec4(position, 0, 1);\n" |
| 2239 | " vec2 texCoord = (position * 0.5) + 0.5;\n" |
| 2240 | " color = texture2D(tex2D, texCoord).x;\n" |
| 2241 | "}"; |
| 2242 | const std::string &fragmentShader = |
| 2243 | "varying mediump float color;\n" |
| 2244 | "void main() {\n" |
| 2245 | " gl_FragColor = vec4(color, 0, 0, 1);\n" |
| 2246 | "}"; |
| 2247 | |
| 2248 | mProgram = CompileProgram(vertexShader, fragmentShader); |
| 2249 | ASSERT_NE(0u, mProgram); |
| 2250 | |
| 2251 | glUseProgram(mProgram); |
| 2252 | GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D"); |
| 2253 | ASSERT_NE(-1, tex2DLocation); |
| 2254 | |
| 2255 | glUniform1i(tex2DLocation, mMaxCombinedTextures); |
| 2256 | ASSERT_GL_NO_ERROR(); |
| 2257 | |
| 2258 | drawQuad(mProgram, "position", 0.5f); |
| 2259 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2260 | } |
| 2261 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 2262 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 2263 | // TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 2264 | ANGLE_INSTANTIATE_TEST(Texture2DTest, |
| 2265 | ES2_D3D9(), |
| 2266 | ES2_D3D11(), |
| 2267 | ES2_D3D11_FL9_3(), |
| 2268 | ES2_OPENGL(), |
| 2269 | ES2_OPENGLES()); |
| 2270 | ANGLE_INSTANTIATE_TEST(TextureCubeTest, |
| 2271 | ES2_D3D9(), |
| 2272 | ES2_D3D11(), |
| 2273 | ES2_D3D11_FL9_3(), |
| 2274 | ES2_OPENGL(), |
| 2275 | ES2_OPENGLES()); |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 2276 | ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale, |
| 2277 | ES2_D3D9(), |
| 2278 | ES2_D3D11(), |
| 2279 | ES2_D3D11_FL9_3(), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 2280 | ES2_OPENGL(), |
| 2281 | ES2_OPENGLES()); |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 2282 | ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest, |
| 2283 | ES2_D3D9(), |
| 2284 | ES2_D3D11(), |
| 2285 | ES2_D3D11_FL9_3(), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 2286 | ES2_OPENGL(), |
| 2287 | ES2_OPENGLES()); |
| 2288 | ANGLE_INSTANTIATE_TEST(SamplerArrayTest, |
| 2289 | ES2_D3D9(), |
| 2290 | ES2_D3D11(), |
| 2291 | ES2_D3D11_FL9_3(), |
| 2292 | ES2_OPENGL(), |
| 2293 | ES2_OPENGLES()); |
| 2294 | ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest, |
| 2295 | ES2_D3D9(), |
| 2296 | ES2_D3D11(), |
| 2297 | ES2_D3D11_FL9_3(), |
| 2298 | ES2_OPENGL(), |
| 2299 | ES2_OPENGLES()); |
| 2300 | ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2301 | ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
| 2302 | ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3, |
| 2303 | ES3_D3D11(), |
| 2304 | ES3_OPENGL(), |
| 2305 | ES3_OPENGLES()); |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 2306 | ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3, |
| 2307 | ES3_D3D11(), |
| 2308 | ES3_OPENGL(), |
| 2309 | ES3_OPENGLES()); |
| 2310 | ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
| 2311 | ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 2312 | ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL()); |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 2313 | ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES()); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 2314 | |
| 2315 | } // namespace |