GrGLCaps.cpp revision 7839ce1af63bf12fe7b3caa866970bbbb3afb13d
1/* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 9#include "GrGLCaps.h" 10#include "GrGLContext.h" 11#include "SkTSearch.h" 12#include "SkTSort.h" 13 14SK_DEFINE_INST_COUNT(GrGLCaps) 15 16GrGLCaps::GrGLCaps() { 17 this->reset(); 18} 19 20void GrGLCaps::reset() { 21 INHERITED::reset(); 22 23 fVerifiedColorConfigs.reset(); 24 fStencilFormats.reset(); 25 fStencilVerifiedColorConfigs.reset(); 26 fMSFBOType = kNone_MSFBOType; 27 fCoverageAAType = kNone_CoverageAAType; 28 fFBFetchType = kNone_FBFetchType; 29 fMaxFragmentUniformVectors = 0; 30 fMaxVertexAttributes = 0; 31 fRGBA8RenderbufferSupport = false; 32 fBGRAFormatSupport = false; 33 fBGRAIsInternalFormat = false; 34 fTextureSwizzleSupport = false; 35 fUnpackRowLengthSupport = false; 36 fUnpackFlipYSupport = false; 37 fPackRowLengthSupport = false; 38 fPackFlipYSupport = false; 39 fTextureUsageSupport = false; 40 fTexStorageSupport = false; 41 fTextureRedSupport = false; 42 fImagingSupport = false; 43 fTwoFormatLimit = false; 44 fFragCoordsConventionSupport = false; 45 fVertexArrayObjectSupport = false; 46 fUseNonVBOVertexAndIndexDynamicData = false; 47 fIsCoreProfile = false; 48 fDiscardFBSupport = false; 49} 50 51GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() { 52 *this = caps; 53} 54 55GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { 56 INHERITED::operator=(caps); 57 fVerifiedColorConfigs = caps.fVerifiedColorConfigs; 58 fStencilFormats = caps.fStencilFormats; 59 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; 60 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; 61 fMaxVertexAttributes = caps.fMaxVertexAttributes; 62 fMSFBOType = caps.fMSFBOType; 63 fCoverageAAType = caps.fCoverageAAType; 64 fMSAACoverageModes = caps.fMSAACoverageModes; 65 fFBFetchType = caps.fFBFetchType; 66 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; 67 fBGRAFormatSupport = caps.fBGRAFormatSupport; 68 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; 69 fTextureSwizzleSupport = caps.fTextureSwizzleSupport; 70 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; 71 fUnpackFlipYSupport = caps.fUnpackFlipYSupport; 72 fPackRowLengthSupport = caps.fPackRowLengthSupport; 73 fPackFlipYSupport = caps.fPackFlipYSupport; 74 fTextureUsageSupport = caps.fTextureUsageSupport; 75 fTexStorageSupport = caps.fTexStorageSupport; 76 fTextureRedSupport = caps.fTextureRedSupport; 77 fImagingSupport = caps.fImagingSupport; 78 fTwoFormatLimit = caps.fTwoFormatLimit; 79 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; 80 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport; 81 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData; 82 fIsCoreProfile = caps.fIsCoreProfile; 83 fDiscardFBSupport = caps.fDiscardFBSupport; 84 85 return *this; 86} 87 88void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { 89 90 this->reset(); 91 if (!ctxInfo.isInitialized()) { 92 return; 93 } 94 95 GrGLBinding binding = ctxInfo.binding(); 96 GrGLVersion version = ctxInfo.version(); 97 98 /************************************************************************** 99 * Caps specific to GrGLCaps 100 **************************************************************************/ 101 102 if (kES2_GrGLBinding == binding) { 103 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, 104 &fMaxFragmentUniformVectors); 105 } else { 106 GrAssert(kDesktop_GrGLBinding == binding); 107 GrGLint max; 108 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); 109 fMaxFragmentUniformVectors = max / 4; 110 } 111 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); 112 113 if (kDesktop_GrGLBinding == binding) { 114 fRGBA8RenderbufferSupport = true; 115 } else { 116 fRGBA8RenderbufferSupport = ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || 117 ctxInfo.hasExtension("GL_ARM_rgba8"); 118 } 119 120 if (kDesktop_GrGLBinding == binding) { 121 fBGRAFormatSupport = version >= GR_GL_VER(1,2) || 122 ctxInfo.hasExtension("GL_EXT_bgra"); 123 } else { 124 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { 125 fBGRAFormatSupport = true; 126 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { 127 fBGRAFormatSupport = true; 128 fBGRAIsInternalFormat = true; 129 } 130 GrAssert(fBGRAFormatSupport || 131 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); 132 } 133 134 if (kDesktop_GrGLBinding == binding) { 135 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || 136 ctxInfo.hasExtension("GL_ARB_texture_swizzle"); 137 } else { 138 fTextureSwizzleSupport = false; 139 } 140 141 if (kDesktop_GrGLBinding == binding) { 142 fUnpackRowLengthSupport = true; 143 fUnpackFlipYSupport = false; 144 fPackRowLengthSupport = true; 145 fPackFlipYSupport = false; 146 } else { 147 fUnpackRowLengthSupport =ctxInfo.hasExtension("GL_EXT_unpack_subimage"); 148 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); 149 // no extension for pack row length 150 fPackRowLengthSupport = false; 151 fPackFlipYSupport = 152 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); 153 } 154 155 fTextureUsageSupport = (kES2_GrGLBinding == binding) && 156 ctxInfo.hasExtension("GL_ANGLE_texture_usage"); 157 158 // Tex storage is in desktop 4.2 and can be an extension to desktop or ES. 159 fTexStorageSupport = (kDesktop_GrGLBinding == binding && 160 version >= GR_GL_VER(4,2)) || 161 ctxInfo.hasExtension("GL_ARB_texture_storage") || 162 ctxInfo.hasExtension("GL_EXT_texture_storage"); 163 164 // ARB_texture_rg is part of OpenGL 3.0 165 if (kDesktop_GrGLBinding == binding) { 166 fTextureRedSupport = version >= GR_GL_VER(3,0) || 167 ctxInfo.hasExtension("GL_ARB_texture_rg"); 168 } else { 169 fTextureRedSupport = ctxInfo.hasExtension("GL_EXT_texture_rg"); 170 } 171 172 fImagingSupport = kDesktop_GrGLBinding == binding && 173 ctxInfo.hasExtension("GL_ARB_imaging"); 174 175 // ES 2 only guarantees RGBA/uchar + one other format/type combo for 176 // ReadPixels. The other format has to checked at run-time since it 177 // can change based on which render target is bound 178 fTwoFormatLimit = kES2_GrGLBinding == binding; 179 180 // Known issue on at least some Intel platforms: 181 // http://code.google.com/p/skia/issues/detail?id=946 182 if (kIntel_GrGLVendor != ctxInfo.vendor()) { 183 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || 184 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"); 185 } 186 187 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with 188 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex 189 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and 190 // limit this decision to specific GPU families rather than basing it on the vendor alone. 191 if (!GR_GL_MUST_USE_VBO && 192 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) { 193 fUseNonVBOVertexAndIndexDynamicData = true; 194 } 195 196 if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) { 197 GrGLint profileMask; 198 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); 199 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); 200 } 201 202 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer"); 203 204 if (kDesktop_GrGLBinding == binding) { 205 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || 206 ctxInfo.hasExtension("GL_ARB_vertex_array_object"); 207 } else { 208 fVertexArrayObjectSupport = ctxInfo.hasExtension("GL_OES_vertex_array_object"); 209 } 210 211 if (kES2_GrGLBinding == binding) { 212 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { 213 fFBFetchType = kEXT_FBFetchType; 214 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { 215 fFBFetchType = kNV_FBFetchType; 216 } 217 } 218 219 this->initFSAASupport(ctxInfo, gli); 220 this->initStencilFormats(ctxInfo); 221 222 /************************************************************************** 223 * GrDrawTargetCaps fields 224 **************************************************************************/ 225 GrGLint maxTextureUnits; 226 // check FS and fixed-function texture unit limits 227 // we only use textures in the fragment stage currently. 228 // checks are > to make sure we have a spare unit. 229 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); 230 231 GrGLint numFormats; 232 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); 233 if (numFormats) { 234 SkAutoSTMalloc<10, GrGLint> formats(numFormats); 235 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); 236 for (int i = 0; i < numFormats; ++i) { 237 if (formats[i] == GR_GL_PALETTE8_RGBA8) { 238 f8BitPaletteSupport = true; 239 break; 240 } 241 } 242 } 243 244 if (kDesktop_GrGLBinding == binding) { 245 // we could also look for GL_ATI_separate_stencil extension or 246 // GL_EXT_stencil_two_side but they use different function signatures 247 // than GL2.0+ (and than each other). 248 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0)); 249 // supported on GL 1.4 and higher or by extension 250 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) || 251 ctxInfo.hasExtension("GL_EXT_stencil_wrap"); 252 } else { 253 // ES 2 has two sided stencil and stencil wrap 254 fTwoSidedStencilSupport = true; 255 fStencilWrapOpsSupport = true; 256 } 257 258 if (kDesktop_GrGLBinding == binding) { 259 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes 260 // glMapBuffer. 261 } else { 262 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer"); 263 } 264 265 if (kDesktop_GrGLBinding == binding) { 266 if (ctxInfo.version() >= GR_GL_VER(2,0) || 267 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) { 268 fNPOTTextureTileSupport = true; 269 } else { 270 fNPOTTextureTileSupport = false; 271 } 272 } else { 273 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only 274 fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot"); 275 } 276 277 fHWAALineSupport = (kDesktop_GrGLBinding == binding); 278 279 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); 280 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); 281 // Our render targets are always created with textures as the color 282 // attachment, hence this min: 283 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize); 284 285 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING && 286 ctxInfo.hasExtension("GL_NV_path_rendering"); 287 288 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType; 289 290 // Enable supported shader-related caps 291 if (kDesktop_GrGLBinding == binding) { 292 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) || 293 ctxInfo.hasExtension("GL_ARB_blend_func_extended"); 294 fShaderDerivativeSupport = true; 295 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS 296 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) && 297 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; 298 } else { 299 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives"); 300 } 301 302 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { 303 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount); 304 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { 305 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); 306 } 307} 308 309bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, 310 GrGLenum format, 311 GrGLenum type) const { 312 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { 313 // ES 2 guarantees this format is supported 314 return true; 315 } 316 317 if (!fTwoFormatLimit) { 318 // not limited by ES 2's constraints 319 return true; 320 } 321 322 GrGLint otherFormat = GR_GL_RGBA; 323 GrGLint otherType = GR_GL_UNSIGNED_BYTE; 324 325 // The other supported format/type combo supported for ReadPixels 326 // can change based on which render target is bound 327 GR_GL_GetIntegerv(intf, 328 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, 329 &otherFormat); 330 331 GR_GL_GetIntegerv(intf, 332 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, 333 &otherType); 334 335 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; 336} 337 338namespace { 339bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left, 340 const GrGLCaps::MSAACoverageMode& right) { 341 if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) { 342 return true; 343 } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) { 344 return false; 345 } else if (left.fColorSampleCnt < right.fColorSampleCnt) { 346 return true; 347 } 348 return false; 349} 350} 351 352void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { 353 354 fMSFBOType = kNone_MSFBOType; 355 if (kDesktop_GrGLBinding != ctxInfo.binding()) { 356 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { 357 // chrome's extension is equivalent to the EXT msaa 358 // and fbo_blit extensions. 359 fMSFBOType = kDesktop_EXT_MSFBOType; 360 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { 361 fMSFBOType = kES_Apple_MSFBOType; 362 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { 363 fMSFBOType = kES_EXT_MsToTexture_MSFBOType; 364 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { 365 fMSFBOType = kES_IMG_MsToTexture_MSFBOType; 366 } 367 } else { 368 if ((ctxInfo.version() >= GR_GL_VER(3,0)) || 369 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { 370 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; 371 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && 372 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { 373 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; 374 } 375 // TODO: We could populate fMSAACoverageModes using GetInternalformativ 376 // on GL 4.2+. It's format-specific, though. See also 377 // http://code.google.com/p/skia/issues/detail?id=470 about using actual 378 // rather than requested sample counts in cache key. 379 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) { 380 fCoverageAAType = kNVDesktop_CoverageAAType; 381 GrGLint count; 382 GR_GL_GetIntegerv(gli, 383 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES, 384 &count); 385 fMSAACoverageModes.setCount(count); 386 GR_GL_GetIntegerv(gli, 387 GR_GL_MULTISAMPLE_COVERAGE_MODES, 388 (int*)&fMSAACoverageModes[0]); 389 // The NV driver seems to return the modes already sorted but the 390 // spec doesn't require this. So we sort. 391 typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_less> SortFunctor; 392 SortFunctor sortFunctor; 393 SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(), 394 fMSAACoverageModes.end() - 1, 395 sortFunctor); 396 } 397 } 398} 399 400const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const { 401 static const MSAACoverageMode kNoneMode = {0, 0}; 402 if (0 == fMSAACoverageModes.count()) { 403 return kNoneMode; 404 } else { 405 GrAssert(kNone_CoverageAAType != fCoverageAAType); 406 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt; 407 desiredSampleCount = GrMin(desiredSampleCount, max); 408 MSAACoverageMode desiredMode = {desiredSampleCount, 0}; 409 int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverageModes[0], 410 fMSAACoverageModes.count(), 411 desiredMode, 412 sizeof(MSAACoverageMode)); 413 if (idx < 0) { 414 idx = ~idx; 415 } 416 GrAssert(idx >= 0 && idx < fMSAACoverageModes.count()); 417 return fMSAACoverageModes[idx]; 418 } 419} 420 421namespace { 422const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; 423} 424 425void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { 426 427 // Build up list of legal stencil formats (though perhaps not supported on 428 // the particular gpu/driver) from most preferred to least. 429 430 // these consts are in order of most preferred to least preferred 431 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 432 433 static const StencilFormat 434 // internal Format stencil bits total bits packed? 435 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, 436 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, 437 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, 438 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, 439 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, 440 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; 441 442 if (kDesktop_GrGLBinding == ctxInfo.binding()) { 443 bool supportsPackedDS = 444 ctxInfo.version() >= GR_GL_VER(3,0) || 445 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || 446 ctxInfo.hasExtension("GL_ARB_framebuffer_object"); 447 448 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we 449 // require FBO support we can expect these are legal formats and don't 450 // check. These also all support the unsized GL_STENCIL_INDEX. 451 fStencilFormats.push_back() = gS8; 452 fStencilFormats.push_back() = gS16; 453 if (supportsPackedDS) { 454 fStencilFormats.push_back() = gD24S8; 455 } 456 fStencilFormats.push_back() = gS4; 457 if (supportsPackedDS) { 458 fStencilFormats.push_back() = gDS; 459 } 460 } else { 461 // ES2 has STENCIL_INDEX8 without extensions but requires extensions 462 // for other formats. 463 // ES doesn't support using the unsized format. 464 465 fStencilFormats.push_back() = gS8; 466 //fStencilFormats.push_back() = gS16; 467 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { 468 fStencilFormats.push_back() = gD24S8; 469 } 470 if (ctxInfo.hasExtension("GL_OES_stencil4")) { 471 fStencilFormats.push_back() = gS4; 472 } 473 } 474 GrAssert(0 == fStencilVerifiedColorConfigs.count()); 475 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); 476} 477 478void GrGLCaps::markColorConfigAndStencilFormatAsVerified( 479 GrPixelConfig config, 480 const GrGLStencilBuffer::Format& format) { 481#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 482 return; 483#endif 484 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt); 485 GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); 486 int count = fStencilFormats.count(); 487 // we expect a really small number of possible formats so linear search 488 // should be OK 489 GrAssert(count < 16); 490 for (int i = 0; i < count; ++i) { 491 if (format.fInternalFormat == 492 fStencilFormats[i].fInternalFormat) { 493 fStencilVerifiedColorConfigs[i].markVerified(config); 494 return; 495 } 496 } 497 GrCrash("Why are we seeing a stencil format that " 498 "GrGLCaps doesn't know about."); 499} 500 501bool GrGLCaps::isColorConfigAndStencilFormatVerified( 502 GrPixelConfig config, 503 const GrGLStencilBuffer::Format& format) const { 504#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 505 return false; 506#endif 507 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt); 508 int count = fStencilFormats.count(); 509 // we expect a really small number of possible formats so linear search 510 // should be OK 511 GrAssert(count < 16); 512 for (int i = 0; i < count; ++i) { 513 if (format.fInternalFormat == 514 fStencilFormats[i].fInternalFormat) { 515 return fStencilVerifiedColorConfigs[i].isVerified(config); 516 } 517 } 518 GrCrash("Why are we seeing a stencil format that " 519 "GLCaps doesn't know about."); 520 return false; 521} 522 523void GrGLCaps::print() const { 524 525 INHERITED::print(); 526 527 GrPrintf("--- GL-Specific ---\n"); 528 for (int i = 0; i < fStencilFormats.count(); ++i) { 529 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", 530 i, 531 fStencilFormats[i].fStencilBits, 532 fStencilFormats[i].fTotalBits); 533 } 534 535 static const char* kMSFBOExtStr[] = { 536 "None", 537 "ARB", 538 "EXT", 539 "Apple", 540 "IMG MS To Texture", 541 "EXT MS To Texture", 542 }; 543 GR_STATIC_ASSERT(0 == kNone_MSFBOType); 544 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); 545 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); 546 GR_STATIC_ASSERT(3 == kES_Apple_MSFBOType); 547 GR_STATIC_ASSERT(4 == kES_IMG_MsToTexture_MSFBOType); 548 GR_STATIC_ASSERT(5 == kES_EXT_MsToTexture_MSFBOType); 549 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); 550 551 static const char* kFBFetchTypeStr[] = { 552 "None", 553 "EXT", 554 "NV", 555 }; 556 GR_STATIC_ASSERT(0 == kNone_FBFetchType); 557 GR_STATIC_ASSERT(1 == kEXT_FBFetchType); 558 GR_STATIC_ASSERT(2 == kNV_FBFetchType); 559 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1); 560 561 562 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); 563 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]); 564 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); 565 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); 566 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); 567 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO")); 568 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); 569 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); 570 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); 571 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); 572 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); 573 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); 574 575 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); 576 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); 577 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); 578 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); 579 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); 580 GrPrintf("Fragment coord conventions support: %s\n", 581 (fFragCoordsConventionSupport ? "YES": "NO")); 582 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); 583 GrPrintf("Use non-VBO for dynamic data: %s\n", 584 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); 585 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); 586 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO")); 587} 588