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