gfx/gl/GLContextFeatures.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 #include "GLContext.h"
michael@0 8 #include "nsPrintfCString.h"
michael@0 9
michael@0 10 #ifdef XP_MACOSX
michael@0 11 #include "nsCocoaFeatures.h"
michael@0 12 #endif
michael@0 13
michael@0 14 namespace mozilla {
michael@0 15 namespace gl {
michael@0 16
michael@0 17 const size_t kMAX_EXTENSION_GROUP_SIZE = 5;
michael@0 18
michael@0 19 // ARB_ES2_compatibility is natively supported in OpenGL 4.1.
michael@0 20 static const unsigned int kGLCoreVersionForES2Compat = 410;
michael@0 21
michael@0 22 // ARB_ES3_compatibility is natively supported in OpenGL 4.3.
michael@0 23 static const unsigned int kGLCoreVersionForES3Compat = 430;
michael@0 24
michael@0 25 struct FeatureInfo
michael@0 26 {
michael@0 27 const char* mName;
michael@0 28 unsigned int mOpenGLVersion;
michael@0 29 unsigned int mOpenGLESVersion;
michael@0 30 GLContext::GLExtensions mExtensions[kMAX_EXTENSION_GROUP_SIZE];
michael@0 31 };
michael@0 32
michael@0 33 static const FeatureInfo sFeatureInfoArr[] = {
michael@0 34 {
michael@0 35 "bind_buffer_offset",
michael@0 36 0, // OpenGL version
michael@0 37 0, // OpenGL ES version
michael@0 38 {
michael@0 39 GLContext::EXT_transform_feedback,
michael@0 40 GLContext::NV_transform_feedback,
michael@0 41 GLContext::Extensions_End
michael@0 42 }
michael@0 43 },
michael@0 44 {
michael@0 45 "blend_minmax",
michael@0 46 200, // OpenGL version
michael@0 47 300, // OpenGL ES version
michael@0 48 {
michael@0 49 GLContext::EXT_blend_minmax,
michael@0 50 GLContext::Extensions_End
michael@0 51 }
michael@0 52 },
michael@0 53 {
michael@0 54 "depth_texture",
michael@0 55 200, // OpenGL version
michael@0 56 300, // OpenGL ES version
michael@0 57 {
michael@0 58 GLContext::ARB_depth_texture,
michael@0 59 GLContext::OES_depth_texture,
michael@0 60 // Intentionally avoid putting ANGLE_depth_texture here,
michael@0 61 // it does not offer quite the same functionality.
michael@0 62 GLContext::Extensions_End
michael@0 63 }
michael@0 64 },
michael@0 65 {
michael@0 66 "draw_buffers",
michael@0 67 200, // OpenGL version
michael@0 68 300, // OpenGL ES version
michael@0 69 {
michael@0 70 GLContext::ARB_draw_buffers,
michael@0 71 GLContext::EXT_draw_buffers,
michael@0 72 GLContext::Extensions_End
michael@0 73 }
michael@0 74 },
michael@0 75 {
michael@0 76 "draw_instanced",
michael@0 77 310, // OpenGL version
michael@0 78 300, // OpenGL ES version
michael@0 79 {
michael@0 80 GLContext::ARB_draw_instanced,
michael@0 81 GLContext::EXT_draw_instanced,
michael@0 82 GLContext::NV_draw_instanced,
michael@0 83 GLContext::ANGLE_instanced_arrays,
michael@0 84 GLContext::Extensions_End
michael@0 85 }
michael@0 86 },
michael@0 87 {
michael@0 88 "draw_range_elements",
michael@0 89 120, // OpenGL version
michael@0 90 300, // OpenGL ES version
michael@0 91 {
michael@0 92 GLContext::EXT_draw_range_elements,
michael@0 93 GLContext::Extensions_End
michael@0 94 }
michael@0 95 },
michael@0 96 {
michael@0 97 "element_index_uint",
michael@0 98 200, // OpenGL version
michael@0 99 300, // OpenGL ES version
michael@0 100 {
michael@0 101 GLContext::OES_element_index_uint,
michael@0 102 GLContext::Extensions_End
michael@0 103 }
michael@0 104 },
michael@0 105 {
michael@0 106 "ES2_compatibility",
michael@0 107 kGLCoreVersionForES2Compat,
michael@0 108 200, // OpenGL ES version
michael@0 109 {
michael@0 110 GLContext::ARB_ES2_compatibility,
michael@0 111 GLContext::Extensions_End
michael@0 112 }
michael@0 113 },
michael@0 114 {
michael@0 115 "ES3_compatibility",
michael@0 116 kGLCoreVersionForES3Compat,
michael@0 117 300, // OpenGL ES version
michael@0 118 {
michael@0 119 GLContext::ARB_ES3_compatibility,
michael@0 120 GLContext::Extensions_End
michael@0 121 }
michael@0 122 },
michael@0 123 {
michael@0 124 // Removes clamping for float color outputs from frag shaders.
michael@0 125 "frag_color_float",
michael@0 126 300, // OpenGL version
michael@0 127 300, // OpenGL ES version
michael@0 128 {
michael@0 129 GLContext::ARB_color_buffer_float,
michael@0 130 GLContext::EXT_color_buffer_float,
michael@0 131 GLContext::EXT_color_buffer_half_float,
michael@0 132 GLContext::Extensions_End
michael@0 133 }
michael@0 134 },
michael@0 135 {
michael@0 136 "frag_depth",
michael@0 137 200, // OpenGL version
michael@0 138 300, // OpenGL ES version
michael@0 139 {
michael@0 140 GLContext::EXT_frag_depth,
michael@0 141 GLContext::Extensions_End
michael@0 142 }
michael@0 143 },
michael@0 144 {
michael@0 145 "framebuffer_blit",
michael@0 146 300, // OpenGL version
michael@0 147 300, // OpenGL ES version
michael@0 148 {
michael@0 149 GLContext::EXT_framebuffer_blit,
michael@0 150 GLContext::ANGLE_framebuffer_blit,
michael@0 151 GLContext::Extensions_End
michael@0 152 }
michael@0 153 },
michael@0 154 {
michael@0 155 "framebuffer_multisample",
michael@0 156 300, // OpenGL version
michael@0 157 300, // OpenGL ES version
michael@0 158 {
michael@0 159 GLContext::EXT_framebuffer_multisample,
michael@0 160 GLContext::ANGLE_framebuffer_multisample,
michael@0 161 GLContext::Extensions_End
michael@0 162 }
michael@0 163 },
michael@0 164 {
michael@0 165 "framebuffer_object",
michael@0 166 300, // OpenGL version
michael@0 167 200, // OpenGL ES version
michael@0 168 {
michael@0 169 GLContext::ARB_framebuffer_object,
michael@0 170 GLContext::EXT_framebuffer_object,
michael@0 171 GLContext::Extensions_End
michael@0 172 }
michael@0 173 },
michael@0 174 {
michael@0 175 "get_query_object_iv",
michael@0 176 200, // OpenGL version
michael@0 177 0, // OpenGL ES version
michael@0 178 {
michael@0 179 GLContext::Extensions_End
michael@0 180 }
michael@0 181 /*
michael@0 182 * XXX_get_query_object_iv only provide GetQueryObjectiv provided by
michael@0 183 * ARB_occlusion_query (added by OpenGL 2.0).
michael@0 184 */
michael@0 185 },
michael@0 186 {
michael@0 187 "instanced_arrays",
michael@0 188 330, // OpenGL version
michael@0 189 300, // OpenGL ES version
michael@0 190 {
michael@0 191 GLContext::ARB_instanced_arrays,
michael@0 192 GLContext::NV_instanced_arrays,
michael@0 193 GLContext::ANGLE_instanced_arrays,
michael@0 194 GLContext::Extensions_End
michael@0 195 }
michael@0 196 },
michael@0 197 {
michael@0 198 "instanced_non_arrays",
michael@0 199 330, // OpenGL version
michael@0 200 300, // OpenGL ES version
michael@0 201 {
michael@0 202 GLContext::ARB_instanced_arrays,
michael@0 203 GLContext::Extensions_End
michael@0 204 }
michael@0 205 /* This is an expanded version of `instanced_arrays` that allows for all
michael@0 206 * enabled active attrib arrays to have non-zero divisors.
michael@0 207 * ANGLE_instanced_arrays and NV_instanced_arrays forbid this, but GLES3
michael@0 208 * has no such restriction.
michael@0 209 */
michael@0 210 },
michael@0 211 {
michael@0 212 "occlusion_query",
michael@0 213 200, // OpenGL version
michael@0 214 0, // OpenGL ES version
michael@0 215 {
michael@0 216 GLContext::Extensions_End
michael@0 217 }
michael@0 218 // XXX_occlusion_query depend on ARB_occlusion_query (added in OpenGL 2.0)
michael@0 219 },
michael@0 220 {
michael@0 221 "occlusion_query_boolean",
michael@0 222 kGLCoreVersionForES3Compat,
michael@0 223 300, // OpenGL ES version
michael@0 224 {
michael@0 225 GLContext::ARB_ES3_compatibility,
michael@0 226 GLContext::EXT_occlusion_query_boolean,
michael@0 227 GLContext::Extensions_End
michael@0 228 }
michael@0 229 /*
michael@0 230 * XXX_occlusion_query_boolean provide ANY_SAMPLES_PASSED_CONSERVATIVE,
michael@0 231 * but EXT_occlusion_query_boolean is only a OpenGL ES extension. But
michael@0 232 * it is supported on desktop if ARB_ES3_compatibility because
michael@0 233 * EXT_occlusion_query_boolean (added in OpenGL ES 3.0).
michael@0 234 */
michael@0 235 },
michael@0 236 {
michael@0 237 "occlusion_query2",
michael@0 238 330, // = min(330, kGLCoreVersionForES3Compat),
michael@0 239 300, // OpenGL ES version
michael@0 240 {
michael@0 241 GLContext::ARB_occlusion_query2,
michael@0 242 GLContext::ARB_ES3_compatibility,
michael@0 243 GLContext::EXT_occlusion_query_boolean,
michael@0 244 GLContext::Extensions_End
michael@0 245 }
michael@0 246 /*
michael@0 247 * XXX_occlusion_query2 (add in OpenGL 3.3) provide ANY_SAMPLES_PASSED,
michael@0 248 * which is provided by ARB_occlusion_query2, EXT_occlusion_query_boolean
michael@0 249 * (added in OpenGL ES 3.0) and ARB_ES3_compatibility
michael@0 250 */
michael@0 251 },
michael@0 252 {
michael@0 253 "packed_depth_stencil",
michael@0 254 300, // OpenGL version
michael@0 255 300, // OpenGL ES version
michael@0 256 {
michael@0 257 GLContext::EXT_packed_depth_stencil,
michael@0 258 GLContext::OES_packed_depth_stencil,
michael@0 259 GLContext::Extensions_End
michael@0 260 }
michael@0 261 },
michael@0 262 {
michael@0 263 "query_objects",
michael@0 264 200, // OpenGL version
michael@0 265 300, // OpenGL ES version
michael@0 266 {
michael@0 267 GLContext::EXT_occlusion_query_boolean,
michael@0 268 GLContext::Extensions_End
michael@0 269 }
michael@0 270 /*
michael@0 271 * XXX_query_objects only provide entry points commonly supported by
michael@0 272 * ARB_occlusion_query (added in OpenGL 2.0) and EXT_occlusion_query_boolean
michael@0 273 * (added in OpenGL ES 3.0)
michael@0 274 */
michael@0 275 },
michael@0 276 {
michael@0 277 "renderbuffer_float",
michael@0 278 300, // OpenGL version
michael@0 279 300, // OpenGL ES version
michael@0 280 {
michael@0 281 GLContext::ARB_texture_float,
michael@0 282 GLContext::EXT_color_buffer_float,
michael@0 283 GLContext::Extensions_End
michael@0 284 }
michael@0 285 },
michael@0 286 {
michael@0 287 "renderbuffer_half_float",
michael@0 288 300, // OpenGL version
michael@0 289 300, // OpenGL ES version
michael@0 290 {
michael@0 291 GLContext::ARB_texture_float,
michael@0 292 GLContext::EXT_color_buffer_half_float,
michael@0 293 GLContext::Extensions_End
michael@0 294 }
michael@0 295 },
michael@0 296 {
michael@0 297 "robustness",
michael@0 298 0, // OpenGL version
michael@0 299 0, // OpenGL ES version
michael@0 300 {
michael@0 301 GLContext::ARB_robustness,
michael@0 302 GLContext::EXT_robustness,
michael@0 303 GLContext::Extensions_End
michael@0 304 }
michael@0 305 },
michael@0 306 {
michael@0 307 "sRGB",
michael@0 308 300, // OpenGL version
michael@0 309 300, // OpenGL ES version
michael@0 310 {
michael@0 311 GLContext::EXT_sRGB,
michael@0 312 GLContext::Extensions_End
michael@0 313 }
michael@0 314 },
michael@0 315 {
michael@0 316 "standard_derivatives",
michael@0 317 200, // OpenGL version
michael@0 318 300, // OpenGL ES version
michael@0 319 {
michael@0 320 GLContext::OES_standard_derivatives,
michael@0 321 GLContext::Extensions_End
michael@0 322 }
michael@0 323 },
michael@0 324 {
michael@0 325 "texture_float",
michael@0 326 300, // OpenGL version
michael@0 327 300, // OpenGL ES version
michael@0 328 {
michael@0 329 GLContext::ARB_texture_float,
michael@0 330 GLContext::OES_texture_float,
michael@0 331 GLContext::Extensions_End
michael@0 332 }
michael@0 333 },
michael@0 334 {
michael@0 335 "texture_float_linear",
michael@0 336 310, // OpenGL version
michael@0 337 300, // OpenGL ES version
michael@0 338 {
michael@0 339 GLContext::ARB_texture_float,
michael@0 340 GLContext::OES_texture_float_linear,
michael@0 341 GLContext::Extensions_End
michael@0 342 }
michael@0 343 },
michael@0 344 {
michael@0 345 "texture_half_float",
michael@0 346 300, // OpenGL version
michael@0 347 300, // OpenGL ES version
michael@0 348 {
michael@0 349 GLContext::ARB_half_float_pixel,
michael@0 350 GLContext::ARB_texture_float,
michael@0 351 GLContext::NV_half_float,
michael@0 352 GLContext::Extensions_End
michael@0 353 }
michael@0 354 /**
michael@0 355 * We are not including OES_texture_half_float in this feature, because:
michael@0 356 * GL_HALF_FLOAT = 0x140B
michael@0 357 * GL_HALF_FLOAT_ARB = 0x140B == GL_HALF_FLOAT
michael@0 358 * GL_HALF_FLOAT_NV = 0x140B == GL_HALF_FLOAT
michael@0 359 * GL_HALF_FLOAT_OES = 0x8D61 != GL_HALF_FLOAT
michael@0 360 * WebGL handles this specifically with an OES_texture_half_float check.
michael@0 361 */
michael@0 362 },
michael@0 363 {
michael@0 364 "texture_half_float_linear",
michael@0 365 310, // OpenGL version
michael@0 366 300, // OpenGL ES version
michael@0 367 {
michael@0 368 GLContext::ARB_half_float_pixel,
michael@0 369 GLContext::ARB_texture_float,
michael@0 370 GLContext::NV_half_float,
michael@0 371 GLContext::OES_texture_half_float_linear,
michael@0 372 GLContext::Extensions_End
michael@0 373 }
michael@0 374 },
michael@0 375 {
michael@0 376 "texture_non_power_of_two",
michael@0 377 200, // OpenGL version
michael@0 378 300, // OpenGL ES version
michael@0 379 {
michael@0 380 GLContext::ARB_texture_non_power_of_two,
michael@0 381 GLContext::OES_texture_npot,
michael@0 382 GLContext::Extensions_End
michael@0 383 }
michael@0 384 },
michael@0 385 {
michael@0 386 "transform_feedback",
michael@0 387 300, // OpenGL version
michael@0 388 300, // OpenGL ES version
michael@0 389 {
michael@0 390 GLContext::EXT_transform_feedback,
michael@0 391 GLContext::NV_transform_feedback,
michael@0 392 GLContext::Extensions_End
michael@0 393 }
michael@0 394 },
michael@0 395 {
michael@0 396 "vertex_array_object",
michael@0 397 300, // OpenGL version
michael@0 398 300, // OpenGL ES version
michael@0 399 {
michael@0 400 GLContext::ARB_vertex_array_object,
michael@0 401 GLContext::OES_vertex_array_object,
michael@0 402 GLContext::APPLE_vertex_array_object,
michael@0 403 GLContext::Extensions_End
michael@0 404 }
michael@0 405 }
michael@0 406 };
michael@0 407
michael@0 408 static inline const FeatureInfo&
michael@0 409 GetFeatureInfo(GLFeature feature)
michael@0 410 {
michael@0 411 static_assert(MOZ_ARRAY_LENGTH(sFeatureInfoArr) == size_t(GLFeature::EnumMax),
michael@0 412 "Mismatched lengths for sFeatureInfoInfos and GLFeature enums");
michael@0 413
michael@0 414 MOZ_ASSERT(feature < GLFeature::EnumMax,
michael@0 415 "GLContext::GetFeatureInfoInfo : unknown <feature>");
michael@0 416
michael@0 417 return sFeatureInfoArr[size_t(feature)];
michael@0 418 }
michael@0 419
michael@0 420 static inline uint32_t
michael@0 421 ProfileVersionForFeature(GLFeature feature, ContextProfile profile)
michael@0 422 {
michael@0 423 MOZ_ASSERT(profile != ContextProfile::Unknown,
michael@0 424 "GLContext::ProfileVersionForFeature : unknown <profile>");
michael@0 425
michael@0 426 const FeatureInfo& featureInfo = GetFeatureInfo(feature);
michael@0 427
michael@0 428 if (profile == ContextProfile::OpenGLES) {
michael@0 429 return featureInfo.mOpenGLESVersion;
michael@0 430 }
michael@0 431
michael@0 432 return featureInfo.mOpenGLVersion;
michael@0 433 }
michael@0 434
michael@0 435 static inline bool
michael@0 436 IsFeatureIsPartOfProfileVersion(GLFeature feature,
michael@0 437 ContextProfile profile, unsigned int version)
michael@0 438 {
michael@0 439 unsigned int profileVersion = ProfileVersionForFeature(feature, profile);
michael@0 440
michael@0 441 /**
michael@0 442 * if `profileVersion` is zero, it means that no version of the profile
michael@0 443 * added support for the feature.
michael@0 444 */
michael@0 445 return profileVersion && version >= profileVersion;
michael@0 446 }
michael@0 447
michael@0 448 const char*
michael@0 449 GLContext::GetFeatureName(GLFeature feature)
michael@0 450 {
michael@0 451 return GetFeatureInfo(feature).mName;
michael@0 452 }
michael@0 453
michael@0 454 static bool
michael@0 455 CanReadSRGBFromFBOTexture(GLContext* gl)
michael@0 456 {
michael@0 457 if (!gl->WorkAroundDriverBugs())
michael@0 458 return true;
michael@0 459
michael@0 460 #ifdef XP_MACOSX
michael@0 461 // Bug 843668:
michael@0 462 // MacOSX 10.6 reports to support EXT_framebuffer_sRGB and
michael@0 463 // EXT_texture_sRGB but fails to convert from sRGB to linear
michael@0 464 // when writing to an sRGB texture attached to an FBO.
michael@0 465 if (!nsCocoaFeatures::OnLionOrLater()) {
michael@0 466 return false;
michael@0 467 }
michael@0 468 #endif // XP_MACOSX
michael@0 469 return true;
michael@0 470 }
michael@0 471
michael@0 472 void
michael@0 473 GLContext::InitFeatures()
michael@0 474 {
michael@0 475 for (size_t feature_index = 0; feature_index < size_t(GLFeature::EnumMax); feature_index++)
michael@0 476 {
michael@0 477 GLFeature feature = GLFeature(feature_index);
michael@0 478
michael@0 479 if (IsFeatureIsPartOfProfileVersion(feature, mProfile, mVersion)) {
michael@0 480 mAvailableFeatures[feature_index] = true;
michael@0 481 continue;
michael@0 482 }
michael@0 483
michael@0 484 mAvailableFeatures[feature_index] = false;
michael@0 485
michael@0 486 const FeatureInfo& featureInfo = GetFeatureInfo(feature);
michael@0 487
michael@0 488 for (size_t j = 0; true; j++)
michael@0 489 {
michael@0 490 MOZ_ASSERT(j < kMAX_EXTENSION_GROUP_SIZE, "kMAX_EXTENSION_GROUP_SIZE too small");
michael@0 491
michael@0 492 if (featureInfo.mExtensions[j] == GLContext::Extensions_End) {
michael@0 493 break;
michael@0 494 }
michael@0 495
michael@0 496 if (IsExtensionSupported(featureInfo.mExtensions[j])) {
michael@0 497 mAvailableFeatures[feature_index] = true;
michael@0 498 break;
michael@0 499 }
michael@0 500 }
michael@0 501 }
michael@0 502
michael@0 503 // Bug 843668: Work around limitation of the feature system.
michael@0 504 // For sRGB support under OpenGL to match OpenGL ES spec, check for both
michael@0 505 // EXT_texture_sRGB and EXT_framebuffer_sRGB is required.
michael@0 506 const bool aresRGBExtensionsAvailable =
michael@0 507 IsExtensionSupported(EXT_texture_sRGB) &&
michael@0 508 (IsExtensionSupported(ARB_framebuffer_sRGB) ||
michael@0 509 IsExtensionSupported(EXT_framebuffer_sRGB));
michael@0 510
michael@0 511 mAvailableFeatures[size_t(GLFeature::sRGB)] =
michael@0 512 aresRGBExtensionsAvailable &&
michael@0 513 CanReadSRGBFromFBOTexture(this);
michael@0 514 }
michael@0 515
michael@0 516 void
michael@0 517 GLContext::MarkUnsupported(GLFeature feature)
michael@0 518 {
michael@0 519 mAvailableFeatures[size_t(feature)] = false;
michael@0 520
michael@0 521 const FeatureInfo& featureInfo = GetFeatureInfo(feature);
michael@0 522
michael@0 523 for (size_t i = 0; true; i++)
michael@0 524 {
michael@0 525 MOZ_ASSERT(i < kMAX_EXTENSION_GROUP_SIZE, "kMAX_EXTENSION_GROUP_SIZE too small");
michael@0 526
michael@0 527 if (featureInfo.mExtensions[i] == GLContext::Extensions_End) {
michael@0 528 break;
michael@0 529 }
michael@0 530
michael@0 531 MarkExtensionUnsupported(featureInfo.mExtensions[i]);
michael@0 532 }
michael@0 533
michael@0 534 MOZ_ASSERT(!IsSupported(feature), "GLContext::MarkUnsupported has failed!");
michael@0 535
michael@0 536 NS_WARNING(nsPrintfCString("%s marked as unsupported", GetFeatureName(feature)).get());
michael@0 537 }
michael@0 538
michael@0 539 } /* namespace gl */
michael@0 540 } /* namespace mozilla */

mercurial