| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GL_GLEXT_PROTOTYPES |
| 6 #define GL_GLEXT_PROTOTYPES |
| 7 #endif |
| 8 |
| 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> |
| 11 #include <GLES2/gl2extchromium.h> |
| 12 |
| 13 #include "gpu/command_buffer/tests/gl_manager.h" |
| 14 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 #define SHADER(src) #src |
| 19 |
| 20 namespace gpu { |
| 21 |
| 22 namespace { |
| 23 |
| 24 const uint8 kCompressedImageColor[4] = { 255u, 0u, 0u, 255u }; |
| 25 |
| 26 // Single compressed ATC block of source pixels all set to: kPixelColor. |
| 27 const uint8 kCompressedImageATC[8] = { |
| 28 0x0, 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 }; |
| 29 |
| 30 // Single compressed ATCIA block of source pixels all set to: kPixelColor. |
| 31 const uint8 kCompressedImageATCIA[16] = { |
| 32 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 33 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 }; |
| 34 |
| 35 // Single compressed DXT1 block of source pixels all set to: kPixelColor. |
| 36 const uint8 kCompressedImageDXT1[8] = { |
| 37 0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa }; |
| 38 |
| 39 // Single compressed DXT5 block of source pixels all set to: kPixelColor. |
| 40 const uint8 kCompressedImageDXT5[16] = { |
| 41 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 42 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa }; |
| 43 |
| 44 // Single compressed DXT1 block of source pixels all set to: kPixelColor. |
| 45 const uint8 kCompressedImageETC1[8] = { |
| 46 0x0, 0x0, 0xf8, 0x2, 0xff, 0xff, 0x0, 0x0 }; |
| 47 |
| 48 void glEnableDisable(GLint param, GLboolean value) { |
| 49 if (value) |
| 50 glEnable(param); |
| 51 else |
| 52 glDisable(param); |
| 53 } |
| 54 |
| 55 } // unnamed namespace |
| 56 |
| 57 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
| 58 class GLCopyCompressedTextureCHROMIUMTest |
| 59 : public testing::Test { |
| 60 protected: |
| 61 void SetUp() override { |
| 62 gl_.Initialize(GLManager::Options()); |
| 63 |
| 64 glGenTextures(2, textures_); |
| 65 } |
| 66 |
| 67 void TearDown() override { |
| 68 glDeleteTextures(2, textures_); |
| 69 gl_.Destroy(); |
| 70 } |
| 71 |
| 72 GLuint LoadProgram() { |
| 73 const char* v_shader_src = SHADER( |
| 74 attribute vec2 a_position; |
| 75 varying vec2 v_texcoord; |
| 76 void main() { |
| 77 gl_Position = vec4(a_position, 0.0, 1.0); |
| 78 v_texcoord = (a_position + 1.0) * 0.5; |
| 79 } |
| 80 ); |
| 81 const char* f_shader_src = SHADER( |
| 82 precision mediump float; |
| 83 uniform sampler2D u_texture; |
| 84 varying vec2 v_texcoord; |
| 85 void main() { |
| 86 gl_FragColor = texture2D(u_texture, v_texcoord); |
| 87 } |
| 88 ); |
| 89 return GLTestHelper::LoadProgram(v_shader_src, f_shader_src); |
| 90 } |
| 91 |
| 92 GLManager gl_; |
| 93 GLuint textures_[2]; |
| 94 GLuint framebuffer_id_; |
| 95 }; |
| 96 |
| 97 // Test to ensure that the basic functionality of the extension works. |
| 98 TEST_F(GLCopyCompressedTextureCHROMIUMTest, Basic) { |
| 99 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
| 100 LOG(INFO) << |
| 101 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
| 102 return; |
| 103 } |
| 104 |
| 105 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 110 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 111 4, 4, 0, |
| 112 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); |
| 113 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 114 |
| 115 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 116 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 117 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 118 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 119 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 120 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], |
| 121 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 122 GL_UNSIGNED_BYTE, |
| 123 sizeof(kCompressedImageDXT1)); |
| 124 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 125 |
| 126 // Load shader program. |
| 127 GLuint program = LoadProgram(); |
| 128 ASSERT_NE(program, 0u); |
| 129 GLint position_loc = glGetAttribLocation(program, "a_position"); |
| 130 GLint texture_loc = glGetUniformLocation(program, "u_texture"); |
| 131 ASSERT_NE(position_loc, -1); |
| 132 ASSERT_NE(texture_loc, -1); |
| 133 glUseProgram(program); |
| 134 |
| 135 // Load geometry. |
| 136 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); |
| 137 ASSERT_NE(vbo, 0u); |
| 138 |
| 139 // Load texture. |
| 140 glActiveTexture(GL_TEXTURE0); |
| 141 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 142 glUniform1i(texture_loc, 0); |
| 143 |
| 144 // Draw. |
| 145 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 146 glFlush(); |
| 147 |
| 148 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor); |
| 149 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 150 } |
| 151 |
| 152 TEST_F(GLCopyCompressedTextureCHROMIUMTest, InternalFormat) { |
| 153 struct Image { |
| 154 const GLint format; |
| 155 const uint8* data; |
| 156 const GLsizei data_size; |
| 157 }; |
| 158 std::vector<Image> supported_formats; |
| 159 |
| 160 if (GLTestHelper::HasExtension("GL_AMD_compressed_ATC_texture") || |
| 161 GLTestHelper::HasExtension("GL_ATI_texture_compression_atitc")) { |
| 162 supported_formats.push_back({ |
| 163 GL_ATC_RGB_AMD, |
| 164 kCompressedImageATC, |
| 165 sizeof(kCompressedImageATC)}); |
| 166 supported_formats.push_back({ |
| 167 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, |
| 168 kCompressedImageATCIA, |
| 169 sizeof(kCompressedImageATCIA)}); |
| 170 } |
| 171 if (GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
| 172 supported_formats.push_back({ |
| 173 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 174 kCompressedImageDXT1, |
| 175 sizeof(kCompressedImageDXT1)}); |
| 176 } |
| 177 if (GLTestHelper::HasExtension("GL_ANGLE_texture_compression_dxt5") || |
| 178 GLTestHelper::HasExtension("GL_EXT_texture_compression_s3tc")) { |
| 179 supported_formats.push_back({ |
| 180 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, |
| 181 kCompressedImageDXT5, |
| 182 sizeof(kCompressedImageDXT5)}); |
| 183 } |
| 184 if (GLTestHelper::HasExtension("GL_OES_compressed_ETC1_RGB8_texture")) { |
| 185 supported_formats.push_back({ |
| 186 GL_ETC1_RGB8_OES, |
| 187 kCompressedImageETC1, |
| 188 sizeof(kCompressedImageETC1)}); |
| 189 } |
| 190 |
| 191 for (const Image& image : supported_formats) { |
| 192 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 194 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 195 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 197 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image.format, |
| 198 4, 4, 0, image.data_size, image.data); |
| 199 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 200 |
| 201 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 202 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 203 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 204 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 205 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 206 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], |
| 207 image.format, GL_UNSIGNED_BYTE, |
| 208 image.data_size); |
| 209 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 210 } |
| 211 } |
| 212 |
| 213 TEST_F(GLCopyCompressedTextureCHROMIUMTest, InternalFormatNotSupportedX) { |
| 214 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
| 215 LOG(INFO) << |
| 216 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
| 217 return; |
| 218 } |
| 219 |
| 220 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 225 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 226 4, 4, 0, |
| 227 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); |
| 228 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 229 |
| 230 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 231 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 232 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 235 |
| 236 // Check unsupported format reports error. |
| 237 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_BGRA_EXT, GL_LUMINANCE, |
| 238 GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA}; |
| 239 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); |
| 240 dest_index++) { |
| 241 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], |
| 242 unsupported_dest_formats[dest_index], |
| 243 GL_UNSIGNED_BYTE, |
| 244 sizeof(kCompressedImageDXT1)); |
| 245 EXPECT_TRUE(GL_INVALID_ENUM == glGetError()) << |
| 246 "dest_index:" << dest_index; |
| 247 } |
| 248 } |
| 249 |
| 250 // Validate that some basic GL state is not touched upon execution of |
| 251 // the extension. |
| 252 TEST_F(GLCopyCompressedTextureCHROMIUMTest, BasicStatePreservation) { |
| 253 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
| 254 LOG(INFO) << |
| 255 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
| 256 return; |
| 257 } |
| 258 |
| 259 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 264 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 265 4, 4, 0, |
| 266 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); |
| 267 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 268 |
| 269 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 270 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 271 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 272 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 273 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 274 |
| 275 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE }; |
| 276 for (int x = 0; x < 2; ++x) { |
| 277 GLboolean setting = reference_settings[x]; |
| 278 glEnableDisable(GL_DEPTH_TEST, setting); |
| 279 glEnableDisable(GL_SCISSOR_TEST, setting); |
| 280 glEnableDisable(GL_STENCIL_TEST, setting); |
| 281 glEnableDisable(GL_CULL_FACE, setting); |
| 282 glEnableDisable(GL_BLEND, setting); |
| 283 glColorMask(setting, setting, setting, setting); |
| 284 glDepthMask(setting); |
| 285 |
| 286 glActiveTexture(GL_TEXTURE1 + x); |
| 287 |
| 288 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], |
| 289 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 290 GL_UNSIGNED_BYTE, |
| 291 sizeof(kCompressedImageDXT1)); |
| 292 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 293 |
| 294 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST)); |
| 295 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST)); |
| 296 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST)); |
| 297 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE)); |
| 298 EXPECT_EQ(setting, glIsEnabled(GL_BLEND)); |
| 299 |
| 300 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; |
| 301 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array); |
| 302 EXPECT_EQ(setting, bool_array[0]); |
| 303 |
| 304 bool_array[0] = GL_FALSE; |
| 305 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array); |
| 306 EXPECT_EQ(setting, bool_array[0]); |
| 307 EXPECT_EQ(setting, bool_array[1]); |
| 308 EXPECT_EQ(setting, bool_array[2]); |
| 309 EXPECT_EQ(setting, bool_array[3]); |
| 310 |
| 311 GLint active_texture = 0; |
| 312 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); |
| 313 EXPECT_EQ(GL_TEXTURE1 + x, active_texture); |
| 314 } |
| 315 |
| 316 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 317 }; |
| 318 |
| 319 // Verify that invocation of the extension does not modify the bound |
| 320 // texture state. |
| 321 TEST_F(GLCopyCompressedTextureCHROMIUMTest, TextureStatePreserved) { |
| 322 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
| 323 LOG(INFO) << |
| 324 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
| 325 return; |
| 326 } |
| 327 |
| 328 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 333 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 334 4, 4, 0, |
| 335 sizeof(kCompressedImageDXT1), kCompressedImageDXT1); |
| 336 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 337 |
| 338 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 339 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 340 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 343 |
| 344 GLuint texture_ids[2]; |
| 345 glGenTextures(2, texture_ids); |
| 346 |
| 347 glActiveTexture(GL_TEXTURE0); |
| 348 glBindTexture(GL_TEXTURE_2D, texture_ids[0]); |
| 349 |
| 350 glActiveTexture(GL_TEXTURE1); |
| 351 glBindTexture(GL_TEXTURE_2D, texture_ids[1]); |
| 352 |
| 353 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], |
| 354 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 355 GL_UNSIGNED_BYTE, |
| 356 sizeof(kCompressedImageDXT1)); |
| 357 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 358 |
| 359 GLint active_texture = 0; |
| 360 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); |
| 361 EXPECT_EQ(GL_TEXTURE1, active_texture); |
| 362 |
| 363 GLint bound_texture = 0; |
| 364 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
| 365 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture)); |
| 366 glBindTexture(GL_TEXTURE_2D, 0); |
| 367 |
| 368 bound_texture = 0; |
| 369 glActiveTexture(GL_TEXTURE0); |
| 370 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
| 371 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture)); |
| 372 glBindTexture(GL_TEXTURE_2D, 0); |
| 373 |
| 374 glDeleteTextures(2, texture_ids); |
| 375 |
| 376 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 377 } |
| 378 |
| 379 } // namespace gpu |
| OLD | NEW |