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