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 | ac3ab88 | 2015-05-12 13:31:28 -0400 | [diff] [blame] | 7 | #include "end2end_tests/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 | |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 14 | class TextureTest : public ANGLETest |
| 15 | { |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 16 | protected: |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 17 | TextureTest() |
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 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 27 | void SetUp() override |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 28 | { |
| 29 | ANGLETest::SetUp(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 30 | glGenTextures(1, &mTexture2D); |
| 31 | glGenTextures(1, &mTextureCube); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 32 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 33 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 34 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 35 | EXPECT_GL_NO_ERROR(); |
| 36 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 37 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 38 | glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1); |
| 39 | EXPECT_GL_NO_ERROR(); |
| 40 | |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 41 | ASSERT_GL_NO_ERROR(); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 42 | |
| 43 | const std::string vertexShaderSource = SHADER_SOURCE |
| 44 | ( |
| 45 | precision highp float; |
| 46 | attribute vec4 position; |
| 47 | varying vec2 texcoord; |
| 48 | |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 49 | uniform vec2 textureScale; |
| 50 | |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 51 | void main() |
| 52 | { |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 53 | gl_Position = vec4(position.xy * textureScale, 0.0, 1.0); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 54 | texcoord = (position.xy * 0.5) + 0.5; |
| 55 | } |
| 56 | ); |
| 57 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 58 | const std::string fragmentShaderSource2D = SHADER_SOURCE |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 59 | ( |
| 60 | precision highp float; |
| 61 | uniform sampler2D tex; |
| 62 | varying vec2 texcoord; |
| 63 | |
| 64 | void main() |
| 65 | { |
| 66 | gl_FragColor = texture2D(tex, texcoord); |
| 67 | } |
| 68 | ); |
| 69 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 70 | const std::string fragmentShaderSourceCube = SHADER_SOURCE |
| 71 | ( |
| 72 | precision highp float; |
| 73 | uniform sampler2D tex2D; |
| 74 | uniform samplerCube texCube; |
| 75 | varying vec2 texcoord; |
| 76 | |
| 77 | void main() |
| 78 | { |
| 79 | gl_FragColor = texture2D(tex2D, texcoord); |
| 80 | gl_FragColor += textureCube(texCube, vec3(texcoord, 0)); |
| 81 | } |
| 82 | ); |
| 83 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 84 | m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D); |
| 85 | mCubeProgram = CompileProgram(vertexShaderSource, fragmentShaderSourceCube); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 86 | if (m2DProgram == 0 || mCubeProgram == 0) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 87 | { |
| 88 | FAIL() << "shader compilation failed."; |
| 89 | } |
| 90 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 91 | mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex"); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 92 | ASSERT_NE(-1, mTexture2DUniformLocation); |
| 93 | |
| 94 | mTextureScaleUniformLocation = glGetUniformLocation(m2DProgram, "textureScale"); |
| 95 | ASSERT_NE(-1, mTextureScaleUniformLocation); |
| 96 | |
| 97 | glUseProgram(m2DProgram); |
| 98 | glUniform2f(mTextureScaleUniformLocation, 1.0f, 1.0f); |
| 99 | glUseProgram(0); |
| 100 | ASSERT_GL_NO_ERROR(); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 103 | void TearDown() override |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 104 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 105 | glDeleteTextures(1, &mTexture2D); |
| 106 | glDeleteTextures(1, &mTextureCube); |
| 107 | glDeleteProgram(m2DProgram); |
| 108 | glDeleteProgram(mCubeProgram); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 109 | |
| 110 | ANGLETest::TearDown(); |
| 111 | } |
| 112 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 113 | // Tests CopyTexSubImage with floating point textures of various formats. |
| 114 | void testFloatCopySubImage(int sourceImageChannels, int destImageChannels) |
| 115 | { |
Geoff Lang | bde666a | 2015-04-07 17:17:08 -0400 | [diff] [blame] | 116 | // TODO(jmadill): Figure out why this is broken on Intel D3D11 |
| 117 | if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE) |
| 118 | { |
| 119 | std::cout << "Test skipped on Intel D3D11." << std::endl; |
| 120 | return; |
| 121 | } |
| 122 | |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 123 | if (getClientVersion() < 3) |
| 124 | { |
| 125 | if (!extensionEnabled("GL_OES_texture_float")) |
| 126 | { |
| 127 | std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl; |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg")) |
| 132 | { |
| 133 | std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl; |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 138 | GLfloat sourceImageData[4][16] = |
| 139 | { |
| 140 | { // R |
| 141 | 1.0f, |
| 142 | 0.0f, |
| 143 | 0.0f, |
| 144 | 1.0f |
| 145 | }, |
| 146 | { // RG |
| 147 | 1.0f, 0.0f, |
| 148 | 0.0f, 1.0f, |
| 149 | 0.0f, 0.0f, |
| 150 | 1.0f, 1.0f |
| 151 | }, |
| 152 | { // RGB |
| 153 | 1.0f, 0.0f, 0.0f, |
| 154 | 0.0f, 1.0f, 0.0f, |
| 155 | 0.0f, 0.0f, 1.0f, |
| 156 | 1.0f, 1.0f, 0.0f |
| 157 | }, |
| 158 | { // RGBA |
| 159 | 1.0f, 0.0f, 0.0f, 1.0f, |
| 160 | 0.0f, 1.0f, 0.0f, 1.0f, |
| 161 | 0.0f, 0.0f, 1.0f, 1.0f, |
| 162 | 1.0f, 1.0f, 0.0f, 1.0f |
| 163 | }, |
| 164 | }; |
| 165 | |
| 166 | GLenum imageFormats[] = |
| 167 | { |
| 168 | GL_R32F, |
| 169 | GL_RG32F, |
| 170 | GL_RGB32F, |
| 171 | GL_RGBA32F, |
| 172 | }; |
| 173 | |
| 174 | GLenum sourceUnsizedFormats[] = |
| 175 | { |
| 176 | GL_RED, |
| 177 | GL_RG, |
| 178 | GL_RGB, |
| 179 | GL_RGBA, |
| 180 | }; |
| 181 | |
| 182 | GLuint textures[2]; |
| 183 | |
| 184 | glGenTextures(2, textures); |
| 185 | |
| 186 | GLfloat *imageData = sourceImageData[sourceImageChannels - 1]; |
| 187 | GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1]; |
| 188 | GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1]; |
| 189 | GLenum destImageFormat = imageFormats[destImageChannels - 1]; |
| 190 | |
| 191 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 192 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2); |
| 193 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 194 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 195 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData); |
| 196 | |
hendrikw | b27f79a | 2015-03-04 11:26:46 -0800 | [diff] [blame] | 197 | if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg")) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 198 | { |
| 199 | // This is not supported |
| 200 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 201 | } |
| 202 | else |
| 203 | { |
| 204 | ASSERT_GL_NO_ERROR(); |
| 205 | } |
| 206 | |
| 207 | GLuint fbo; |
| 208 | glGenFramebuffers(1, &fbo); |
| 209 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 210 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 211 | |
| 212 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 213 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2); |
| 214 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 215 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 216 | |
| 217 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2); |
| 218 | ASSERT_GL_NO_ERROR(); |
| 219 | |
| 220 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 221 | drawQuad(m2DProgram, "position", 0.5f); |
| 222 | swapBuffers(); |
| 223 | |
| 224 | int testImageChannels = std::min(sourceImageChannels, destImageChannels); |
| 225 | |
| 226 | EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255); |
| 227 | if (testImageChannels > 1) |
| 228 | { |
| 229 | EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255); |
| 230 | EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255); |
| 231 | if (testImageChannels > 2) |
| 232 | { |
| 233 | EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | glDeleteFramebuffers(1, &fbo); |
| 238 | glDeleteTextures(2, textures); |
| 239 | |
| 240 | ASSERT_GL_NO_ERROR(); |
| 241 | } |
| 242 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 243 | GLuint mTexture2D; |
| 244 | GLuint mTextureCube; |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 245 | |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 246 | GLuint m2DProgram; |
| 247 | GLuint mCubeProgram; |
| 248 | GLint mTexture2DUniformLocation; |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 249 | GLint mTextureScaleUniformLocation; |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 250 | }; |
| 251 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 252 | TEST_P(TextureTest, NegativeAPISubImage) |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 253 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 254 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 255 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 256 | |
| 257 | const GLubyte *pixels[20] = { 0 }; |
| 258 | glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 259 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 260 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 261 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 262 | TEST_P(TextureTest, ZeroSizedUploads) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 263 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 264 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 265 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 266 | |
| 267 | // Use the texture first to make sure it's in video memory |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 268 | glUseProgram(m2DProgram); |
| 269 | glUniform1i(mTexture2DUniformLocation, 0); |
| 270 | drawQuad(m2DProgram, "position", 0.5f); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 271 | |
| 272 | const GLubyte *pixel[4] = { 0 }; |
| 273 | |
| 274 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 275 | EXPECT_GL_NO_ERROR(); |
| 276 | |
| 277 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 278 | EXPECT_GL_NO_ERROR(); |
| 279 | |
| 280 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 281 | EXPECT_GL_NO_ERROR(); |
| 282 | } |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 283 | |
| 284 | // Test drawing with two texture types, to trigger an ANGLE bug in validation |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 285 | TEST_P(TextureTest, CubeMapBug) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 286 | { |
| 287 | glActiveTexture(GL_TEXTURE0); |
| 288 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 289 | glActiveTexture(GL_TEXTURE1); |
| 290 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 291 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 292 | |
| 293 | glUseProgram(mCubeProgram); |
| 294 | GLint tex2DUniformLocation = glGetUniformLocation(mCubeProgram, "tex2D"); |
| 295 | GLint texCubeUniformLocation = glGetUniformLocation(mCubeProgram, "texCube"); |
| 296 | EXPECT_NE(-1, tex2DUniformLocation); |
| 297 | EXPECT_NE(-1, texCubeUniformLocation); |
| 298 | glUniform1i(tex2DUniformLocation, 0); |
| 299 | glUniform1i(texCubeUniformLocation, 1); |
| 300 | drawQuad(mCubeProgram, "position", 0.5f); |
| 301 | EXPECT_GL_NO_ERROR(); |
| 302 | } |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 303 | |
| 304 | // Copy of a test in conformance/textures/texture-mips, to test generate mipmaps |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 305 | TEST_P(TextureTest, MipmapsTwice) |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 306 | { |
| 307 | int px = getWindowWidth() / 2; |
| 308 | int py = getWindowHeight() / 2; |
| 309 | |
| 310 | glActiveTexture(GL_TEXTURE0); |
| 311 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 312 | |
| 313 | // Fill with red |
| 314 | std::vector<GLubyte> pixels(4 * 16 * 16); |
| 315 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 316 | { |
| 317 | pixels[pixelId * 4 + 0] = 255; |
| 318 | pixels[pixelId * 4 + 1] = 0; |
| 319 | pixels[pixelId * 4 + 2] = 0; |
| 320 | pixels[pixelId * 4 + 3] = 255; |
| 321 | } |
| 322 | |
| 323 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 324 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 325 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 326 | glGenerateMipmap(GL_TEXTURE_2D); |
| 327 | |
| 328 | glUseProgram(m2DProgram); |
| 329 | glUniform1i(mTexture2DUniformLocation, 0); |
| 330 | glUniform2f(mTextureScaleUniformLocation, 0.0625f, 0.0625f); |
| 331 | drawQuad(m2DProgram, "position", 0.5f); |
| 332 | EXPECT_GL_NO_ERROR(); |
| 333 | EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255); |
| 334 | |
| 335 | // Fill with blue |
| 336 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 337 | { |
| 338 | pixels[pixelId * 4 + 0] = 0; |
| 339 | pixels[pixelId * 4 + 1] = 0; |
| 340 | pixels[pixelId * 4 + 2] = 255; |
| 341 | pixels[pixelId * 4 + 3] = 255; |
| 342 | } |
| 343 | |
| 344 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 345 | glGenerateMipmap(GL_TEXTURE_2D); |
| 346 | |
| 347 | // Fill with green |
| 348 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 349 | { |
| 350 | pixels[pixelId * 4 + 0] = 0; |
| 351 | pixels[pixelId * 4 + 1] = 255; |
| 352 | pixels[pixelId * 4 + 2] = 0; |
| 353 | pixels[pixelId * 4 + 3] = 255; |
| 354 | } |
| 355 | |
| 356 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 357 | glGenerateMipmap(GL_TEXTURE_2D); |
| 358 | |
| 359 | drawQuad(m2DProgram, "position", 0.5f); |
| 360 | |
| 361 | EXPECT_GL_NO_ERROR(); |
| 362 | EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255); |
| 363 | } |
Jamie Madill | f8fccb3 | 2014-11-12 15:05:26 -0500 | [diff] [blame] | 364 | |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 365 | // Test creating a FBO with a cube map render target, to test an ANGLE bug |
| 366 | // https://code.google.com/p/angleproject/issues/detail?id=849 |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 367 | TEST_P(TextureTest, CubeMapFBO) |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 368 | { |
| 369 | GLuint fbo; |
| 370 | glGenFramebuffers(1, &fbo); |
| 371 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 372 | |
| 373 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 374 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0); |
| 375 | |
| 376 | EXPECT_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 377 | |
| 378 | glDeleteFramebuffers(1, &fbo); |
| 379 | |
| 380 | EXPECT_GL_NO_ERROR(); |
| 381 | } |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 382 | |
| 383 | // Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 384 | TEST_P(TextureTest, TexStorage) |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 385 | { |
| 386 | int width = getWindowWidth(); |
| 387 | int height = getWindowHeight(); |
| 388 | |
| 389 | GLuint tex2D; |
| 390 | glGenTextures(1, &tex2D); |
| 391 | glActiveTexture(GL_TEXTURE0); |
| 392 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 393 | |
| 394 | // Fill with red |
| 395 | std::vector<GLubyte> pixels(3 * 16 * 16); |
| 396 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 397 | { |
| 398 | pixels[pixelId * 3 + 0] = 255; |
| 399 | pixels[pixelId * 3 + 1] = 0; |
| 400 | pixels[pixelId * 3 + 2] = 0; |
| 401 | } |
| 402 | |
| 403 | // ANGLE internally uses RGBA as the DirectX format for RGB images |
| 404 | // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color. |
| 405 | // The data is kept in a CPU-side image and the image is marked as dirty. |
| 406 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16); |
| 407 | |
| 408 | // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched. |
| 409 | // glTexSubImage2D should take into account that the image is dirty. |
| 410 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data()); |
| 411 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 412 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 413 | |
| 414 | glUseProgram(m2DProgram); |
| 415 | glUniform1i(mTexture2DUniformLocation, 0); |
| 416 | glUniform2f(mTextureScaleUniformLocation, 1.f, 1.f); |
| 417 | drawQuad(m2DProgram, "position", 0.5f); |
| 418 | glDeleteTextures(1, &tex2D); |
| 419 | EXPECT_GL_NO_ERROR(); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 420 | EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255); |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 421 | |
| 422 | // Validate that the region of the texture without data has an alpha of 1.0 |
| 423 | GLubyte pixel[4]; |
| 424 | glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
| 425 | EXPECT_EQ(pixel[3], 255); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | // Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has initialized the image with a default color. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 429 | TEST_P(TextureTest, TexStorageWithPBO) |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 430 | { |
| 431 | if (extensionEnabled("NV_pixel_buffer_object")) |
| 432 | { |
| 433 | int width = getWindowWidth(); |
| 434 | int height = getWindowHeight(); |
| 435 | |
| 436 | GLuint tex2D; |
| 437 | glGenTextures(1, &tex2D); |
| 438 | glActiveTexture(GL_TEXTURE0); |
| 439 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 440 | |
| 441 | // Fill with red |
| 442 | std::vector<GLubyte> pixels(3 * 16 * 16); |
| 443 | for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId) |
| 444 | { |
| 445 | pixels[pixelId * 3 + 0] = 255; |
| 446 | pixels[pixelId * 3 + 1] = 0; |
| 447 | pixels[pixelId * 3 + 2] = 0; |
| 448 | } |
| 449 | |
| 450 | // Read 16x16 region from red backbuffer to PBO |
| 451 | GLuint pbo; |
| 452 | glGenBuffers(1, &pbo); |
| 453 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); |
| 454 | glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW); |
| 455 | |
| 456 | // ANGLE internally uses RGBA as the DirectX format for RGB images |
| 457 | // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color. |
| 458 | // The data is kept in a CPU-side image and the image is marked as dirty. |
| 459 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16); |
| 460 | |
| 461 | // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched. |
| 462 | // glTexSubImage2D should take into account that the image is dirty. |
| 463 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 464 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 465 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 466 | |
| 467 | glUseProgram(m2DProgram); |
| 468 | glUniform1i(mTexture2DUniformLocation, 0); |
| 469 | glUniform2f(mTextureScaleUniformLocation, 1.f, 1.f); |
| 470 | drawQuad(m2DProgram, "position", 0.5f); |
| 471 | glDeleteTextures(1, &tex2D); |
| 472 | glDeleteTextures(1, &pbo); |
| 473 | EXPECT_GL_NO_ERROR(); |
| 474 | EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255); |
| 475 | EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255); |
| 476 | } |
| 477 | } |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 478 | |
| 479 | // See description on testFloatCopySubImage |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 480 | TEST_P(TextureTest, CopySubImageFloat_R_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 481 | { |
| 482 | testFloatCopySubImage(1, 1); |
| 483 | } |
| 484 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 485 | TEST_P(TextureTest, CopySubImageFloat_RG_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 486 | { |
| 487 | testFloatCopySubImage(2, 1); |
| 488 | } |
| 489 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 490 | TEST_P(TextureTest, CopySubImageFloat_RG_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 491 | { |
| 492 | testFloatCopySubImage(2, 2); |
| 493 | } |
| 494 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 495 | TEST_P(TextureTest, CopySubImageFloat_RGB_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 496 | { |
| 497 | testFloatCopySubImage(3, 1); |
| 498 | } |
| 499 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 500 | TEST_P(TextureTest, CopySubImageFloat_RGB_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 501 | { |
| 502 | testFloatCopySubImage(3, 2); |
| 503 | } |
| 504 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 505 | TEST_P(TextureTest, CopySubImageFloat_RGB_RGB) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 506 | { |
| 507 | testFloatCopySubImage(3, 3); |
| 508 | } |
| 509 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 510 | TEST_P(TextureTest, CopySubImageFloat_RGBA_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 511 | { |
| 512 | testFloatCopySubImage(4, 1); |
| 513 | } |
| 514 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 515 | TEST_P(TextureTest, CopySubImageFloat_RGBA_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 516 | { |
| 517 | testFloatCopySubImage(4, 2); |
| 518 | } |
| 519 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 520 | TEST_P(TextureTest, CopySubImageFloat_RGBA_RGB) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 521 | { |
| 522 | testFloatCopySubImage(4, 3); |
| 523 | } |
| 524 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 525 | TEST_P(TextureTest, CopySubImageFloat_RGBA_RGBA) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 526 | { |
| 527 | testFloatCopySubImage(4, 4); |
| 528 | } |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 529 | |
| 530 | // Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html |
| 531 | // Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly handles GL_ALPHA |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 532 | TEST_P(TextureTest, TextureNPOT_GL_ALPHA_UBYTE) |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 533 | { |
| 534 | const int npotTexSize = 5; |
| 535 | const int potTexSize = 4; // Should be less than npotTexSize |
| 536 | GLuint tex2D; |
| 537 | |
| 538 | if (extensionEnabled("GL_OES_texture_npot")) |
| 539 | { |
| 540 | // This test isn't applicable if texture_npot is enabled |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 545 | |
| 546 | glActiveTexture(GL_TEXTURE0); |
| 547 | glGenTextures(1, &tex2D); |
| 548 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 549 | |
| 550 | std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize); |
| 551 | for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId) |
| 552 | { |
| 553 | pixels[pixelId] = 64; |
| 554 | } |
| 555 | |
| 556 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 557 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 558 | |
| 559 | // Check that an NPOT texture not on level 0 generates INVALID_VALUE |
| 560 | glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 561 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 562 | |
| 563 | // Check that an NPOT texture on level 0 succeeds |
| 564 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 565 | EXPECT_GL_NO_ERROR(); |
| 566 | |
| 567 | // Check that generateMipmap fails on NPOT |
| 568 | glGenerateMipmap(GL_TEXTURE_2D); |
| 569 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 570 | |
| 571 | // Check that nothing is drawn if filtering is not correct for NPOT |
| 572 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 573 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 574 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 575 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 576 | glClear(GL_COLOR_BUFFER_BIT); |
| 577 | drawQuad(m2DProgram, "position", 1.0f); |
| 578 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255); |
| 579 | |
| 580 | // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255 |
| 581 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 582 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 583 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); |
| 584 | glClear(GL_COLOR_BUFFER_BIT); |
| 585 | drawQuad(m2DProgram, "position", 1.0f); |
| 586 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255); |
| 587 | |
| 588 | // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw |
| 589 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 590 | glClear(GL_COLOR_BUFFER_BIT); |
| 591 | drawQuad(m2DProgram, "position", 1.0f); |
| 592 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64); |
| 593 | |
| 594 | // Check that glTexImage2D for POT texture succeeds |
| 595 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data()); |
| 596 | EXPECT_GL_NO_ERROR(); |
| 597 | |
| 598 | // Check that generateMipmap for an POT texture succeeds |
| 599 | glGenerateMipmap(GL_TEXTURE_2D); |
| 600 | EXPECT_GL_NO_ERROR(); |
| 601 | |
| 602 | // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw |
| 603 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 604 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 605 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 606 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 607 | glClear(GL_COLOR_BUFFER_BIT); |
| 608 | drawQuad(m2DProgram, "position", 1.0f); |
| 609 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64); |
| 610 | EXPECT_GL_NO_ERROR(); |
| 611 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 612 | |
| 613 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 614 | ANGLE_INSTANTIATE_TEST(TextureTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3()); |
| 615 | |
| 616 | } // namespace |