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 | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 14 | class TexCoordDrawTest : public ANGLETest |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 15 | { |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 16 | protected: |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 17 | TexCoordDrawTest() : ANGLETest(), mProgram(0) |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 18 | { |
| 19 | setWindowWidth(128); |
| 20 | setWindowHeight(128); |
| 21 | setConfigRedBits(8); |
| 22 | setConfigGreenBits(8); |
| 23 | setConfigBlueBits(8); |
| 24 | setConfigAlphaBits(8); |
| 25 | } |
| 26 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 27 | virtual std::string getVertexShaderSource() |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 28 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 29 | return std::string(SHADER_SOURCE |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 30 | ( |
| 31 | precision highp float; |
| 32 | attribute vec4 position; |
| 33 | varying vec2 texcoord; |
| 34 | |
| 35 | void main() |
| 36 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 37 | gl_Position = vec4(position.xy, 0.0, 1.0); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 38 | texcoord = (position.xy * 0.5) + 0.5; |
| 39 | } |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 40 | ) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 41 | ); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 42 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 43 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 44 | virtual std::string getFragmentShaderSource() = 0; |
| 45 | |
| 46 | void SetUp() override |
| 47 | { |
| 48 | ANGLETest::SetUp(); |
| 49 | const std::string vertexShaderSource = getVertexShaderSource(); |
| 50 | const std::string fragmentShaderSource = getFragmentShaderSource(); |
| 51 | |
| 52 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 53 | ASSERT_NE(0u, mProgram); |
| 54 | ASSERT_GL_NO_ERROR(); |
| 55 | } |
| 56 | |
| 57 | void TearDown() override |
| 58 | { |
| 59 | glDeleteProgram(mProgram); |
| 60 | ANGLETest::TearDown(); |
| 61 | } |
| 62 | |
| 63 | // Returns the created texture ID. |
| 64 | GLuint create2DTexture() |
| 65 | { |
| 66 | GLuint texture2D; |
| 67 | glGenTextures(1, &texture2D); |
| 68 | glBindTexture(GL_TEXTURE_2D, texture2D); |
| 69 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 70 | EXPECT_GL_NO_ERROR(); |
| 71 | return texture2D; |
| 72 | } |
| 73 | |
| 74 | GLuint mProgram; |
| 75 | }; |
| 76 | |
| 77 | class Texture2DTest : public TexCoordDrawTest |
| 78 | { |
| 79 | protected: |
| 80 | Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {} |
| 81 | |
| 82 | std::string getFragmentShaderSource() override |
| 83 | { |
| 84 | return std::string(SHADER_SOURCE |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 85 | ( |
| 86 | precision highp float; |
| 87 | uniform sampler2D tex; |
| 88 | varying vec2 texcoord; |
| 89 | |
| 90 | void main() |
| 91 | { |
| 92 | gl_FragColor = texture2D(tex, texcoord); |
| 93 | } |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 94 | ) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 95 | ); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 96 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 97 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 98 | void SetUp() override |
| 99 | { |
| 100 | TexCoordDrawTest::SetUp(); |
| 101 | mTexture2D = create2DTexture(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 102 | |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 103 | ASSERT_GL_NO_ERROR(); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 104 | |
| 105 | mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex"); |
| 106 | ASSERT_NE(-1, mTexture2DUniformLocation); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 109 | void TearDown() override |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 110 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 111 | glDeleteTextures(1, &mTexture2D); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 112 | TexCoordDrawTest::TearDown(); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 115 | // Tests CopyTexSubImage with floating point textures of various formats. |
| 116 | void testFloatCopySubImage(int sourceImageChannels, int destImageChannels) |
| 117 | { |
Geoff Lang | bde666a | 2015-04-07 17:17:08 -0400 | [diff] [blame] | 118 | // TODO(jmadill): Figure out why this is broken on Intel D3D11 |
| 119 | if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE) |
| 120 | { |
| 121 | std::cout << "Test skipped on Intel D3D11." << std::endl; |
| 122 | return; |
| 123 | } |
| 124 | |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 125 | if (getClientVersion() < 3) |
| 126 | { |
| 127 | if (!extensionEnabled("GL_OES_texture_float")) |
| 128 | { |
| 129 | std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl; |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg")) |
| 134 | { |
| 135 | std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl; |
| 136 | return; |
| 137 | } |
| 138 | } |
| 139 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 140 | GLfloat sourceImageData[4][16] = |
| 141 | { |
| 142 | { // R |
| 143 | 1.0f, |
| 144 | 0.0f, |
| 145 | 0.0f, |
| 146 | 1.0f |
| 147 | }, |
| 148 | { // RG |
| 149 | 1.0f, 0.0f, |
| 150 | 0.0f, 1.0f, |
| 151 | 0.0f, 0.0f, |
| 152 | 1.0f, 1.0f |
| 153 | }, |
| 154 | { // RGB |
| 155 | 1.0f, 0.0f, 0.0f, |
| 156 | 0.0f, 1.0f, 0.0f, |
| 157 | 0.0f, 0.0f, 1.0f, |
| 158 | 1.0f, 1.0f, 0.0f |
| 159 | }, |
| 160 | { // RGBA |
| 161 | 1.0f, 0.0f, 0.0f, 1.0f, |
| 162 | 0.0f, 1.0f, 0.0f, 1.0f, |
| 163 | 0.0f, 0.0f, 1.0f, 1.0f, |
| 164 | 1.0f, 1.0f, 0.0f, 1.0f |
| 165 | }, |
| 166 | }; |
| 167 | |
| 168 | GLenum imageFormats[] = |
| 169 | { |
| 170 | GL_R32F, |
| 171 | GL_RG32F, |
| 172 | GL_RGB32F, |
| 173 | GL_RGBA32F, |
| 174 | }; |
| 175 | |
| 176 | GLenum sourceUnsizedFormats[] = |
| 177 | { |
| 178 | GL_RED, |
| 179 | GL_RG, |
| 180 | GL_RGB, |
| 181 | GL_RGBA, |
| 182 | }; |
| 183 | |
| 184 | GLuint textures[2]; |
| 185 | |
| 186 | glGenTextures(2, textures); |
| 187 | |
| 188 | GLfloat *imageData = sourceImageData[sourceImageChannels - 1]; |
| 189 | GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1]; |
| 190 | GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1]; |
| 191 | GLenum destImageFormat = imageFormats[destImageChannels - 1]; |
| 192 | |
| 193 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 194 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2); |
| 195 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 196 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 197 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData); |
| 198 | |
hendrikw | b27f79a | 2015-03-04 11:26:46 -0800 | [diff] [blame] | 199 | if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg")) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 200 | { |
| 201 | // This is not supported |
| 202 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | ASSERT_GL_NO_ERROR(); |
| 207 | } |
| 208 | |
| 209 | GLuint fbo; |
| 210 | glGenFramebuffers(1, &fbo); |
| 211 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 212 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 213 | |
| 214 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 215 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2); |
| 216 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 217 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 218 | |
| 219 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2); |
| 220 | ASSERT_GL_NO_ERROR(); |
| 221 | |
| 222 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 223 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 224 | |
| 225 | int testImageChannels = std::min(sourceImageChannels, destImageChannels); |
| 226 | |
| 227 | EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255); |
| 228 | if (testImageChannels > 1) |
| 229 | { |
| 230 | EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255); |
| 231 | EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255); |
| 232 | if (testImageChannels > 2) |
| 233 | { |
| 234 | EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | glDeleteFramebuffers(1, &fbo); |
| 239 | glDeleteTextures(2, textures); |
| 240 | |
| 241 | ASSERT_GL_NO_ERROR(); |
| 242 | } |
| 243 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 244 | GLuint mTexture2D; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 245 | GLint mTexture2DUniformLocation; |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 246 | }; |
| 247 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 248 | class Texture2DTestWithDrawScale : public Texture2DTest |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 249 | { |
| 250 | protected: |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 251 | Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {} |
| 252 | |
| 253 | std::string getVertexShaderSource() override |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 254 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 255 | return std::string(SHADER_SOURCE |
| 256 | ( |
| 257 | precision highp float; |
| 258 | attribute vec4 position; |
| 259 | varying vec2 texcoord; |
| 260 | |
| 261 | uniform vec2 drawScale; |
| 262 | |
| 263 | void main() |
| 264 | { |
| 265 | gl_Position = vec4(position.xy * drawScale, 0.0, 1.0); |
| 266 | texcoord = (position.xy * 0.5) + 0.5; |
| 267 | } |
| 268 | ) |
| 269 | ); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void SetUp() override |
| 273 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 274 | Texture2DTest::SetUp(); |
| 275 | mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale"); |
| 276 | ASSERT_NE(-1, mDrawScaleUniformLocation); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 277 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 278 | glUseProgram(mProgram); |
| 279 | glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f); |
| 280 | glUseProgram(0); |
| 281 | ASSERT_GL_NO_ERROR(); |
| 282 | } |
| 283 | |
| 284 | GLint mDrawScaleUniformLocation; |
| 285 | }; |
| 286 | |
| 287 | class TextureCubeTest : public TexCoordDrawTest |
| 288 | { |
| 289 | protected: |
| 290 | TextureCubeTest() |
| 291 | : TexCoordDrawTest(), |
| 292 | mTexture2D(0), |
| 293 | mTextureCube(0), |
| 294 | mTexture2DUniformLocation(-1), |
| 295 | mTextureCubeUniformLocation(-1) |
| 296 | { |
| 297 | } |
| 298 | |
| 299 | std::string getFragmentShaderSource() override |
| 300 | { |
| 301 | return std::string(SHADER_SOURCE |
| 302 | ( |
| 303 | precision highp float; |
| 304 | uniform sampler2D tex2D; |
| 305 | uniform samplerCube texCube; |
| 306 | varying vec2 texcoord; |
| 307 | |
| 308 | void main() |
| 309 | { |
| 310 | gl_FragColor = texture2D(tex2D, texcoord); |
| 311 | gl_FragColor += textureCube(texCube, vec3(texcoord, 0)); |
| 312 | } |
| 313 | ) |
| 314 | ); |
| 315 | } |
| 316 | |
| 317 | void SetUp() override |
| 318 | { |
| 319 | TexCoordDrawTest::SetUp(); |
| 320 | |
| 321 | glGenTextures(1, &mTextureCube); |
| 322 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 323 | glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1); |
| 324 | EXPECT_GL_NO_ERROR(); |
| 325 | |
| 326 | mTexture2D = create2DTexture(); |
| 327 | |
| 328 | mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D"); |
| 329 | ASSERT_NE(-1, mTexture2DUniformLocation); |
| 330 | mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube"); |
| 331 | ASSERT_NE(-1, mTextureCubeUniformLocation); |
| 332 | } |
| 333 | |
| 334 | void TearDown() override |
| 335 | { |
| 336 | glDeleteTextures(1, &mTextureCube); |
| 337 | TexCoordDrawTest::TearDown(); |
| 338 | } |
| 339 | |
| 340 | GLuint mTexture2D; |
| 341 | GLuint mTextureCube; |
| 342 | GLint mTexture2DUniformLocation; |
| 343 | GLint mTextureCubeUniformLocation; |
| 344 | }; |
| 345 | |
| 346 | class Texture2DArrayTestES3 : public TexCoordDrawTest |
| 347 | { |
| 348 | protected: |
| 349 | Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {} |
| 350 | |
| 351 | std::string getVertexShaderSource() override |
| 352 | { |
| 353 | return std::string( |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 354 | "#version 300 es\n" |
| 355 | "out vec2 texcoord;\n" |
| 356 | "in vec4 position;\n" |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 357 | "void main()\n" |
| 358 | "{\n" |
| 359 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 360 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 361 | "}\n"); |
| 362 | } |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 363 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 364 | std::string getFragmentShaderSource() override |
| 365 | { |
| 366 | return std::string( |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 367 | "#version 300 es\n" |
| 368 | "precision highp float;\n" |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 369 | "uniform highp sampler2DArray tex2DArray;\n" |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 370 | "in vec2 texcoord;\n" |
| 371 | "out vec4 fragColor;\n" |
| 372 | "void main()\n" |
| 373 | "{\n" |
| 374 | " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n" |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 375 | "}\n"); |
| 376 | } |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 377 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 378 | void SetUp() override |
| 379 | { |
| 380 | TexCoordDrawTest::SetUp(); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 381 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 382 | mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray"); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 383 | ASSERT_NE(-1, mTextureArrayLocation); |
| 384 | |
| 385 | glGenTextures(1, &m2DArrayTexture); |
| 386 | ASSERT_GL_NO_ERROR(); |
| 387 | } |
| 388 | |
| 389 | void TearDown() override |
| 390 | { |
| 391 | glDeleteTextures(1, &m2DArrayTexture); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 392 | TexCoordDrawTest::TearDown(); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | GLuint m2DArrayTexture; |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 396 | GLint mTextureArrayLocation; |
| 397 | }; |
| 398 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 399 | TEST_P(Texture2DTest, NegativeAPISubImage) |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 400 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 401 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 402 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 403 | |
| 404 | const GLubyte *pixels[20] = { 0 }; |
| 405 | glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 406 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 407 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 408 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 409 | TEST_P(Texture2DTest, ZeroSizedUploads) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 410 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 411 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 412 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 413 | |
| 414 | // Use the texture first to make sure it's in video memory |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 415 | glUseProgram(mProgram); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 416 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 417 | drawQuad(mProgram, "position", 0.5f); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 418 | |
| 419 | const GLubyte *pixel[4] = { 0 }; |
| 420 | |
| 421 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 422 | EXPECT_GL_NO_ERROR(); |
| 423 | |
| 424 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 425 | EXPECT_GL_NO_ERROR(); |
| 426 | |
| 427 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 428 | EXPECT_GL_NO_ERROR(); |
| 429 | } |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 430 | |
| 431 | // 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^] | 432 | TEST_P(TextureCubeTest, CubeMapBug) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 433 | { |
| 434 | glActiveTexture(GL_TEXTURE0); |
| 435 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 436 | glActiveTexture(GL_TEXTURE1); |
| 437 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 438 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 439 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 440 | glUseProgram(mProgram); |
| 441 | glUniform1i(mTexture2DUniformLocation, 0); |
| 442 | glUniform1i(mTextureCubeUniformLocation, 1); |
| 443 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 444 | EXPECT_GL_NO_ERROR(); |
| 445 | } |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 446 | |
| 447 | // 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^] | 448 | TEST_P(Texture2DTestWithDrawScale, MipmapsTwice) |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 449 | { |
| 450 | int px = getWindowWidth() / 2; |
| 451 | int py = getWindowHeight() / 2; |
| 452 | |
| 453 | glActiveTexture(GL_TEXTURE0); |
| 454 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 455 | |
| 456 | // Fill with red |
| 457 | std::vector<GLubyte> pixels(4 * 16 * 16); |
| 458 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 459 | { |
| 460 | pixels[pixelId * 4 + 0] = 255; |
| 461 | pixels[pixelId * 4 + 1] = 0; |
| 462 | pixels[pixelId * 4 + 2] = 0; |
| 463 | pixels[pixelId * 4 + 3] = 255; |
| 464 | } |
| 465 | |
| 466 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 467 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 468 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 469 | glGenerateMipmap(GL_TEXTURE_2D); |
| 470 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 471 | glUseProgram(mProgram); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 472 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 473 | glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f); |
| 474 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 475 | EXPECT_GL_NO_ERROR(); |
| 476 | EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255); |
| 477 | |
| 478 | // Fill with blue |
| 479 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 480 | { |
| 481 | pixels[pixelId * 4 + 0] = 0; |
| 482 | pixels[pixelId * 4 + 1] = 0; |
| 483 | pixels[pixelId * 4 + 2] = 255; |
| 484 | pixels[pixelId * 4 + 3] = 255; |
| 485 | } |
| 486 | |
| 487 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 488 | glGenerateMipmap(GL_TEXTURE_2D); |
| 489 | |
| 490 | // Fill with green |
| 491 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 492 | { |
| 493 | pixels[pixelId * 4 + 0] = 0; |
| 494 | pixels[pixelId * 4 + 1] = 255; |
| 495 | pixels[pixelId * 4 + 2] = 0; |
| 496 | pixels[pixelId * 4 + 3] = 255; |
| 497 | } |
| 498 | |
| 499 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 500 | glGenerateMipmap(GL_TEXTURE_2D); |
| 501 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 502 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 503 | |
| 504 | EXPECT_GL_NO_ERROR(); |
| 505 | EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255); |
| 506 | } |
Jamie Madill | f8fccb3 | 2014-11-12 15:05:26 -0500 | [diff] [blame] | 507 | |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 508 | // Test creating a FBO with a cube map render target, to test an ANGLE bug |
| 509 | // https://code.google.com/p/angleproject/issues/detail?id=849 |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 510 | TEST_P(TextureCubeTest, CubeMapFBO) |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 511 | { |
| 512 | GLuint fbo; |
| 513 | glGenFramebuffers(1, &fbo); |
| 514 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 515 | |
| 516 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 517 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0); |
| 518 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 519 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 520 | |
| 521 | glDeleteFramebuffers(1, &fbo); |
| 522 | |
| 523 | EXPECT_GL_NO_ERROR(); |
| 524 | } |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 525 | |
| 526 | // 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^] | 527 | TEST_P(Texture2DTest, TexStorage) |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 528 | { |
| 529 | int width = getWindowWidth(); |
| 530 | int height = getWindowHeight(); |
| 531 | |
| 532 | GLuint tex2D; |
| 533 | glGenTextures(1, &tex2D); |
| 534 | glActiveTexture(GL_TEXTURE0); |
| 535 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 536 | |
| 537 | // Fill with red |
| 538 | std::vector<GLubyte> pixels(3 * 16 * 16); |
| 539 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 540 | { |
| 541 | pixels[pixelId * 3 + 0] = 255; |
| 542 | pixels[pixelId * 3 + 1] = 0; |
| 543 | pixels[pixelId * 3 + 2] = 0; |
| 544 | } |
| 545 | |
| 546 | // ANGLE internally uses RGBA as the DirectX format for RGB images |
| 547 | // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color. |
| 548 | // The data is kept in a CPU-side image and the image is marked as dirty. |
| 549 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16); |
| 550 | |
| 551 | // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched. |
| 552 | // glTexSubImage2D should take into account that the image is dirty. |
| 553 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data()); |
| 554 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 555 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 556 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 557 | glUseProgram(mProgram); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 558 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 559 | drawQuad(mProgram, "position", 0.5f); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 560 | glDeleteTextures(1, &tex2D); |
| 561 | EXPECT_GL_NO_ERROR(); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 562 | EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255); |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 563 | |
| 564 | // Validate that the region of the texture without data has an alpha of 1.0 |
| 565 | GLubyte pixel[4]; |
| 566 | glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 567 | EXPECT_EQ(pixel[3], 255); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | // 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^] | 571 | TEST_P(Texture2DTest, TexStorageWithPBO) |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 572 | { |
| 573 | if (extensionEnabled("NV_pixel_buffer_object")) |
| 574 | { |
| 575 | int width = getWindowWidth(); |
| 576 | int height = getWindowHeight(); |
| 577 | |
| 578 | GLuint tex2D; |
| 579 | glGenTextures(1, &tex2D); |
| 580 | glActiveTexture(GL_TEXTURE0); |
| 581 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 582 | |
| 583 | // Fill with red |
| 584 | std::vector<GLubyte> pixels(3 * 16 * 16); |
| 585 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 586 | { |
| 587 | pixels[pixelId * 3 + 0] = 255; |
| 588 | pixels[pixelId * 3 + 1] = 0; |
| 589 | pixels[pixelId * 3 + 2] = 0; |
| 590 | } |
| 591 | |
| 592 | // Read 16x16 region from red backbuffer to PBO |
| 593 | GLuint pbo; |
| 594 | glGenBuffers(1, &pbo); |
| 595 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); |
| 596 | glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW); |
| 597 | |
| 598 | // ANGLE internally uses RGBA as the DirectX format for RGB images |
| 599 | // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color. |
| 600 | // The data is kept in a CPU-side image and the image is marked as dirty. |
| 601 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16); |
| 602 | |
| 603 | // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched. |
| 604 | // glTexSubImage2D should take into account that the image is dirty. |
| 605 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 606 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 607 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 608 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 609 | glUseProgram(mProgram); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 610 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 611 | drawQuad(mProgram, "position", 0.5f); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 612 | glDeleteTextures(1, &tex2D); |
| 613 | glDeleteTextures(1, &pbo); |
| 614 | EXPECT_GL_NO_ERROR(); |
| 615 | EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255); |
| 616 | EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255); |
| 617 | } |
| 618 | } |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 619 | |
| 620 | // See description on testFloatCopySubImage |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 621 | TEST_P(Texture2DTest, CopySubImageFloat_R_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 622 | { |
| 623 | testFloatCopySubImage(1, 1); |
| 624 | } |
| 625 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 626 | TEST_P(Texture2DTest, CopySubImageFloat_RG_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 627 | { |
| 628 | testFloatCopySubImage(2, 1); |
| 629 | } |
| 630 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 631 | TEST_P(Texture2DTest, CopySubImageFloat_RG_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 632 | { |
| 633 | testFloatCopySubImage(2, 2); |
| 634 | } |
| 635 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 636 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 637 | { |
| 638 | testFloatCopySubImage(3, 1); |
| 639 | } |
| 640 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 641 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 642 | { |
| 643 | testFloatCopySubImage(3, 2); |
| 644 | } |
| 645 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 646 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 647 | { |
| 648 | testFloatCopySubImage(3, 3); |
| 649 | } |
| 650 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 651 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 652 | { |
| 653 | testFloatCopySubImage(4, 1); |
| 654 | } |
| 655 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 656 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 657 | { |
| 658 | testFloatCopySubImage(4, 2); |
| 659 | } |
| 660 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 661 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 662 | { |
| 663 | testFloatCopySubImage(4, 3); |
| 664 | } |
| 665 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 666 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 667 | { |
| 668 | testFloatCopySubImage(4, 4); |
| 669 | } |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 670 | |
| 671 | // Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html |
| 672 | // 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^] | 673 | TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE) |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 674 | { |
| 675 | const int npotTexSize = 5; |
| 676 | const int potTexSize = 4; // Should be less than npotTexSize |
| 677 | GLuint tex2D; |
| 678 | |
| 679 | if (extensionEnabled("GL_OES_texture_npot")) |
| 680 | { |
| 681 | // This test isn't applicable if texture_npot is enabled |
| 682 | return; |
| 683 | } |
| 684 | |
| 685 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 686 | |
| 687 | glActiveTexture(GL_TEXTURE0); |
| 688 | glGenTextures(1, &tex2D); |
| 689 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 690 | |
| 691 | std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize); |
| 692 | for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId) |
| 693 | { |
| 694 | pixels[pixelId] = 64; |
| 695 | } |
| 696 | |
| 697 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 698 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 699 | |
| 700 | // Check that an NPOT texture not on level 0 generates INVALID_VALUE |
| 701 | glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 702 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 703 | |
| 704 | // Check that an NPOT texture on level 0 succeeds |
| 705 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 706 | EXPECT_GL_NO_ERROR(); |
| 707 | |
| 708 | // Check that generateMipmap fails on NPOT |
| 709 | glGenerateMipmap(GL_TEXTURE_2D); |
| 710 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 711 | |
| 712 | // Check that nothing is drawn if filtering is not correct for NPOT |
| 713 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 714 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 715 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 716 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 717 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 718 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 719 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255); |
| 720 | |
| 721 | // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255 |
| 722 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 723 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 724 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); |
| 725 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 726 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 727 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255); |
| 728 | |
| 729 | // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw |
| 730 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 731 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 732 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 733 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64); |
| 734 | |
| 735 | // Check that glTexImage2D for POT texture succeeds |
| 736 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 737 | EXPECT_GL_NO_ERROR(); |
| 738 | |
| 739 | // Check that generateMipmap for an POT texture succeeds |
| 740 | glGenerateMipmap(GL_TEXTURE_2D); |
| 741 | EXPECT_GL_NO_ERROR(); |
| 742 | |
| 743 | // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw |
| 744 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 745 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 746 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 747 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 748 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 749 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 750 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64); |
| 751 | EXPECT_GL_NO_ERROR(); |
| 752 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 753 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 754 | // Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions. |
| 755 | // 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^] | 756 | TEST_P(Texture2DTest, NPOTSubImageParameters) |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 757 | { |
| 758 | glActiveTexture(GL_TEXTURE0); |
| 759 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 760 | |
| 761 | // Create an 8x8 (i.e. power-of-two) texture. |
| 762 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 763 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 764 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 765 | glGenerateMipmap(GL_TEXTURE_2D); |
| 766 | |
| 767 | // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture. |
| 768 | // This should always work, even if GL_OES_texture_npot isn't active. |
| 769 | glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 770 | |
| 771 | EXPECT_GL_NO_ERROR(); |
| 772 | } |
| 773 | |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 774 | // In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0 |
| 775 | // in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as |
| 776 | // expected. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 777 | TEST_P(Texture2DArrayTestES3, RedefineInittableArray) |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 778 | { |
| 779 | std::vector<GLubyte> pixelData; |
| 780 | for (size_t count = 0; count < 5000; count++) |
| 781 | { |
| 782 | pixelData.push_back(0u); |
| 783 | pixelData.push_back(255u); |
| 784 | pixelData.push_back(0u); |
| 785 | } |
| 786 | |
| 787 | glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 788 | glUseProgram(mProgram); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 789 | glUniform1i(mTextureArrayLocation, 0); |
| 790 | |
| 791 | // The first draw worked correctly. |
| 792 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]); |
| 793 | |
| 794 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 795 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 796 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 797 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 798 | drawQuad(mProgram, "position", 1.0f); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 799 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 800 | |
| 801 | // The dimension of the respecification must match the original exactly to trigger the bug. |
| 802 | 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^] | 803 | drawQuad(mProgram, "position", 1.0f); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 804 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 805 | |
| 806 | ASSERT_GL_NO_ERROR(); |
| 807 | } |
| 808 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 809 | class TextureLimitsTest : public ANGLETest |
| 810 | { |
| 811 | protected: |
| 812 | struct RGBA8 |
| 813 | { |
| 814 | uint8_t R, G, B, A; |
| 815 | }; |
| 816 | |
| 817 | TextureLimitsTest() |
| 818 | : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0) |
| 819 | { |
| 820 | setWindowWidth(128); |
| 821 | setWindowHeight(128); |
| 822 | setConfigRedBits(8); |
| 823 | setConfigGreenBits(8); |
| 824 | setConfigBlueBits(8); |
| 825 | setConfigAlphaBits(8); |
| 826 | } |
| 827 | |
| 828 | ~TextureLimitsTest() |
| 829 | { |
| 830 | if (mProgram != 0) |
| 831 | { |
| 832 | glDeleteProgram(mProgram); |
| 833 | mProgram = 0; |
| 834 | |
| 835 | if (!mTextures.empty()) |
| 836 | { |
| 837 | glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]); |
| 838 | } |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | void SetUp() override |
| 843 | { |
| 844 | ANGLETest::SetUp(); |
| 845 | |
| 846 | glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures); |
| 847 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures); |
| 848 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures); |
| 849 | |
| 850 | ASSERT_GL_NO_ERROR(); |
| 851 | } |
| 852 | |
| 853 | void compileProgramWithTextureCounts(const std::string &vertexPrefix, |
| 854 | GLint vertexTextureCount, |
| 855 | GLint vertexActiveTextureCount, |
| 856 | const std::string &fragPrefix, |
| 857 | GLint fragmentTextureCount, |
| 858 | GLint fragmentActiveTextureCount) |
| 859 | { |
| 860 | std::stringstream vertexShaderStr; |
| 861 | vertexShaderStr << "attribute vec2 position;\n" |
| 862 | << "varying vec4 color;\n" |
| 863 | << "varying vec2 texCoord;\n"; |
| 864 | |
| 865 | for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex) |
| 866 | { |
| 867 | vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n"; |
| 868 | } |
| 869 | |
| 870 | vertexShaderStr << "void main() {\n" |
| 871 | << " gl_Position = vec4(position, 0, 1);\n" |
| 872 | << " texCoord = (position * 0.5) + 0.5;\n" |
| 873 | << " color = vec4(0);\n"; |
| 874 | |
| 875 | for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex) |
| 876 | { |
| 877 | vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex |
| 878 | << ", texCoord);\n"; |
| 879 | } |
| 880 | |
| 881 | vertexShaderStr << "}"; |
| 882 | |
| 883 | std::stringstream fragmentShaderStr; |
| 884 | fragmentShaderStr << "varying mediump vec4 color;\n" |
| 885 | << "varying mediump vec2 texCoord;\n"; |
| 886 | |
| 887 | for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex) |
| 888 | { |
| 889 | fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n"; |
| 890 | } |
| 891 | |
| 892 | fragmentShaderStr << "void main() {\n" |
| 893 | << " gl_FragColor = color;\n"; |
| 894 | |
| 895 | for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex) |
| 896 | { |
| 897 | fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex |
| 898 | << ", texCoord);\n"; |
| 899 | } |
| 900 | |
| 901 | fragmentShaderStr << "}"; |
| 902 | |
| 903 | const std::string &vertexShaderSource = vertexShaderStr.str(); |
| 904 | const std::string &fragmentShaderSource = fragmentShaderStr.str(); |
| 905 | |
| 906 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 907 | } |
| 908 | |
| 909 | RGBA8 getPixel(GLint texIndex) |
| 910 | { |
| 911 | RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3), |
| 912 | 0, 255u}; |
| 913 | return pixel; |
| 914 | } |
| 915 | |
| 916 | void initTextures(GLint tex2DCount, GLint texCubeCount) |
| 917 | { |
| 918 | GLint totalCount = tex2DCount + texCubeCount; |
| 919 | mTextures.assign(totalCount, 0); |
| 920 | glGenTextures(totalCount, &mTextures[0]); |
| 921 | ASSERT_GL_NO_ERROR(); |
| 922 | |
| 923 | std::vector<RGBA8> texData(16 * 16); |
| 924 | |
| 925 | GLint texIndex = 0; |
| 926 | for (; texIndex < tex2DCount; ++texIndex) |
| 927 | { |
| 928 | texData.assign(texData.size(), getPixel(texIndex)); |
| 929 | glActiveTexture(GL_TEXTURE0 + texIndex); |
| 930 | glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]); |
| 931 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 932 | &texData[0]); |
| 933 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 934 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 935 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 936 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 937 | } |
| 938 | |
| 939 | ASSERT_GL_NO_ERROR(); |
| 940 | |
| 941 | for (; texIndex < texCubeCount; ++texIndex) |
| 942 | { |
| 943 | texData.assign(texData.size(), getPixel(texIndex)); |
| 944 | glActiveTexture(GL_TEXTURE0 + texIndex); |
| 945 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]); |
| 946 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 947 | GL_UNSIGNED_BYTE, &texData[0]); |
| 948 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 949 | GL_UNSIGNED_BYTE, &texData[0]); |
| 950 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 951 | GL_UNSIGNED_BYTE, &texData[0]); |
| 952 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 953 | GL_UNSIGNED_BYTE, &texData[0]); |
| 954 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 955 | GL_UNSIGNED_BYTE, &texData[0]); |
| 956 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 957 | GL_UNSIGNED_BYTE, &texData[0]); |
| 958 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 959 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 960 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 961 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 962 | } |
| 963 | |
| 964 | ASSERT_GL_NO_ERROR(); |
| 965 | } |
| 966 | |
| 967 | void testWithTextures(GLint vertexTextureCount, |
| 968 | const std::string &vertexTexturePrefix, |
| 969 | GLint fragmentTextureCount, |
| 970 | const std::string &fragmentTexturePrefix) |
| 971 | { |
| 972 | // Generate textures |
| 973 | initTextures(vertexTextureCount + fragmentTextureCount, 0); |
| 974 | |
| 975 | glUseProgram(mProgram); |
| 976 | RGBA8 expectedSum = {0}; |
| 977 | for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex) |
| 978 | { |
| 979 | std::stringstream uniformNameStr; |
| 980 | uniformNameStr << vertexTexturePrefix << texIndex; |
| 981 | const std::string &uniformName = uniformNameStr.str(); |
| 982 | GLint location = glGetUniformLocation(mProgram, uniformName.c_str()); |
| 983 | ASSERT_NE(-1, location); |
| 984 | |
| 985 | glUniform1i(location, texIndex); |
| 986 | RGBA8 contribution = getPixel(texIndex); |
| 987 | expectedSum.R += contribution.R; |
| 988 | expectedSum.G += contribution.G; |
| 989 | } |
| 990 | |
| 991 | for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex) |
| 992 | { |
| 993 | std::stringstream uniformNameStr; |
| 994 | uniformNameStr << fragmentTexturePrefix << texIndex; |
| 995 | const std::string &uniformName = uniformNameStr.str(); |
| 996 | GLint location = glGetUniformLocation(mProgram, uniformName.c_str()); |
| 997 | ASSERT_NE(-1, location); |
| 998 | |
| 999 | glUniform1i(location, texIndex + vertexTextureCount); |
| 1000 | RGBA8 contribution = getPixel(texIndex + vertexTextureCount); |
| 1001 | expectedSum.R += contribution.R; |
| 1002 | expectedSum.G += contribution.G; |
| 1003 | } |
| 1004 | |
| 1005 | ASSERT_GE(256u, expectedSum.G); |
| 1006 | |
| 1007 | drawQuad(mProgram, "position", 0.5f); |
| 1008 | ASSERT_GL_NO_ERROR(); |
| 1009 | EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255); |
| 1010 | } |
| 1011 | |
| 1012 | GLuint mProgram; |
| 1013 | std::vector<GLuint> mTextures; |
| 1014 | GLint mMaxVertexTextures; |
| 1015 | GLint mMaxFragmentTextures; |
| 1016 | GLint mMaxCombinedTextures; |
| 1017 | }; |
| 1018 | |
| 1019 | // Test rendering with the maximum vertex texture units. |
| 1020 | TEST_P(TextureLimitsTest, MaxVertexTextures) |
| 1021 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 1022 | // TODO(jmadill): Figure out why this fails on Intel. |
| 1023 | if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
| 1024 | { |
| 1025 | std::cout << "Test skipped on Intel." << std::endl; |
| 1026 | return; |
| 1027 | } |
| 1028 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1029 | compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0); |
| 1030 | ASSERT_NE(0u, mProgram); |
| 1031 | ASSERT_GL_NO_ERROR(); |
| 1032 | |
| 1033 | testWithTextures(mMaxVertexTextures, "tex", 0, "tex"); |
| 1034 | } |
| 1035 | |
| 1036 | // Test rendering with the maximum fragment texture units. |
| 1037 | TEST_P(TextureLimitsTest, MaxFragmentTextures) |
| 1038 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 1039 | // TODO(jmadill): Figure out why this fails on Intel. |
| 1040 | if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
| 1041 | { |
| 1042 | std::cout << "Test skipped on Intel." << std::endl; |
| 1043 | return; |
| 1044 | } |
| 1045 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1046 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures); |
| 1047 | ASSERT_NE(0u, mProgram); |
| 1048 | ASSERT_GL_NO_ERROR(); |
| 1049 | |
| 1050 | testWithTextures(mMaxFragmentTextures, "tex", 0, "tex"); |
| 1051 | } |
| 1052 | |
| 1053 | // Test rendering with maximum combined texture units. |
| 1054 | TEST_P(TextureLimitsTest, MaxCombinedTextures) |
| 1055 | { |
Jamie Madill | 412f17d | 2015-09-25 08:43:54 -0400 | [diff] [blame] | 1056 | // TODO(jmadill): Investigate workaround. |
| 1057 | if (isIntel() && GetParam() == ES2_OPENGL()) |
| 1058 | { |
| 1059 | std::cout << "Test skipped on Intel." << std::endl; |
| 1060 | return; |
| 1061 | } |
| 1062 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1063 | GLint vertexTextures = mMaxVertexTextures; |
| 1064 | |
| 1065 | if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures) |
| 1066 | { |
| 1067 | vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures; |
| 1068 | } |
| 1069 | |
| 1070 | compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex", |
| 1071 | mMaxFragmentTextures, mMaxFragmentTextures); |
| 1072 | ASSERT_NE(0u, mProgram); |
| 1073 | ASSERT_GL_NO_ERROR(); |
| 1074 | |
| 1075 | testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex"); |
| 1076 | } |
| 1077 | |
| 1078 | // Negative test for exceeding the number of vertex textures |
| 1079 | TEST_P(TextureLimitsTest, ExcessiveVertexTextures) |
| 1080 | { |
| 1081 | compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0, |
| 1082 | 0); |
| 1083 | ASSERT_EQ(0u, mProgram); |
| 1084 | } |
| 1085 | |
| 1086 | // Negative test for exceeding the number of fragment textures |
| 1087 | TEST_P(TextureLimitsTest, ExcessiveFragmentTextures) |
| 1088 | { |
| 1089 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1, |
| 1090 | mMaxFragmentTextures + 1); |
| 1091 | ASSERT_EQ(0u, mProgram); |
| 1092 | } |
| 1093 | |
| 1094 | // Test active vertex textures under the limit, but excessive textures specified. |
| 1095 | TEST_P(TextureLimitsTest, MaxActiveVertexTextures) |
| 1096 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 1097 | // TODO(jmadill): Figure out why this fails on Intel. |
| 1098 | if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
| 1099 | { |
| 1100 | std::cout << "Test skipped on Intel." << std::endl; |
| 1101 | return; |
| 1102 | } |
| 1103 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1104 | compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0); |
| 1105 | ASSERT_NE(0u, mProgram); |
| 1106 | ASSERT_GL_NO_ERROR(); |
| 1107 | |
| 1108 | testWithTextures(mMaxVertexTextures, "tex", 0, "tex"); |
| 1109 | } |
| 1110 | |
| 1111 | // Test active fragment textures under the limit, but excessive textures specified. |
| 1112 | TEST_P(TextureLimitsTest, MaxActiveFragmentTextures) |
| 1113 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 1114 | // TODO(jmadill): Figure out why this fails on Intel. |
| 1115 | if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
| 1116 | { |
| 1117 | std::cout << "Test skipped on Intel." << std::endl; |
| 1118 | return; |
| 1119 | } |
| 1120 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1121 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4, |
| 1122 | mMaxFragmentTextures); |
| 1123 | ASSERT_NE(0u, mProgram); |
| 1124 | ASSERT_GL_NO_ERROR(); |
| 1125 | |
| 1126 | testWithTextures(0, "tex", mMaxFragmentTextures, "tex"); |
| 1127 | } |
| 1128 | |
| 1129 | // 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^] | 1130 | // GLES 2.0.25 section 2.10.4 page 39. |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1131 | TEST_P(TextureLimitsTest, TextureTypeConflict) |
| 1132 | { |
| 1133 | const std::string &vertexShader = |
| 1134 | "attribute vec2 position;\n" |
| 1135 | "varying float color;\n" |
| 1136 | "uniform sampler2D tex2D;\n" |
| 1137 | "uniform samplerCube texCube;\n" |
| 1138 | "void main() {\n" |
| 1139 | " gl_Position = vec4(position, 0, 1);\n" |
| 1140 | " vec2 texCoord = (position * 0.5) + 0.5;\n" |
| 1141 | " color = texture2D(tex2D, texCoord).x;\n" |
| 1142 | " color += textureCube(texCube, vec3(texCoord, 0)).x;\n" |
| 1143 | "}"; |
| 1144 | const std::string &fragmentShader = |
| 1145 | "varying mediump float color;\n" |
| 1146 | "void main() {\n" |
| 1147 | " gl_FragColor = vec4(color, 0, 0, 1);\n" |
| 1148 | "}"; |
| 1149 | |
| 1150 | mProgram = CompileProgram(vertexShader, fragmentShader); |
| 1151 | ASSERT_NE(0u, mProgram); |
| 1152 | |
| 1153 | initTextures(1, 0); |
| 1154 | |
| 1155 | glUseProgram(mProgram); |
| 1156 | GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D"); |
| 1157 | ASSERT_NE(-1, tex2DLocation); |
| 1158 | GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube"); |
| 1159 | ASSERT_NE(-1, texCubeLocation); |
| 1160 | |
| 1161 | glUniform1i(tex2DLocation, 0); |
| 1162 | glUniform1i(texCubeLocation, 0); |
| 1163 | ASSERT_GL_NO_ERROR(); |
| 1164 | |
| 1165 | drawQuad(mProgram, "position", 0.5f); |
| 1166 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1167 | } |
| 1168 | |
| 1169 | // Negative test for rendering with texture outside the valid range. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 1170 | // TODO(jmadill): Possibly adjust the test according to the spec: |
| 1171 | // GLES 3.0.4 section 2.12.7 mentions that specifying an out-of-range sampler uniform value |
| 1172 | // 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] | 1173 | TEST_P(TextureLimitsTest, DrawWithTexturePastMaximum) |
| 1174 | { |
| 1175 | const std::string &vertexShader = |
| 1176 | "attribute vec2 position;\n" |
| 1177 | "varying float color;\n" |
| 1178 | "uniform sampler2D tex2D;\n" |
| 1179 | "void main() {\n" |
| 1180 | " gl_Position = vec4(position, 0, 1);\n" |
| 1181 | " vec2 texCoord = (position * 0.5) + 0.5;\n" |
| 1182 | " color = texture2D(tex2D, texCoord).x;\n" |
| 1183 | "}"; |
| 1184 | const std::string &fragmentShader = |
| 1185 | "varying mediump float color;\n" |
| 1186 | "void main() {\n" |
| 1187 | " gl_FragColor = vec4(color, 0, 0, 1);\n" |
| 1188 | "}"; |
| 1189 | |
| 1190 | mProgram = CompileProgram(vertexShader, fragmentShader); |
| 1191 | ASSERT_NE(0u, mProgram); |
| 1192 | |
| 1193 | glUseProgram(mProgram); |
| 1194 | GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D"); |
| 1195 | ASSERT_NE(-1, tex2DLocation); |
| 1196 | |
| 1197 | glUniform1i(tex2DLocation, mMaxCombinedTextures); |
| 1198 | ASSERT_GL_NO_ERROR(); |
| 1199 | |
| 1200 | drawQuad(mProgram, "position", 0.5f); |
| 1201 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1202 | } |
| 1203 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1204 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame^] | 1205 | // TODO(geofflang): Figure out why tests below fail on Intel OpenGL: |
| 1206 | ANGLE_INSTANTIATE_TEST(Texture2DTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3()); |
| 1207 | ANGLE_INSTANTIATE_TEST(TextureCubeTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3()); |
| 1208 | ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3()); |
| 1209 | ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 1210 | ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL()); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1211 | |
| 1212 | } // namespace |