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