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 14 GrGLCaps::GrGLCaps() { 15 this->reset(); 16 } 17 18 void GrGLCaps::reset() { 19 INHERITED::reset(); 20 21 fVerifiedColorConfigs.reset(); 22 fStencilFormats.reset(); 23 fStencilVerifiedColorConfigs.reset(); 24 fMSFBOType = kNone_MSFBOType; 25 fFBFetchType = kNone_FBFetchType; 26 fMaxFragmentUniformVectors = 0; 27 fMaxVertexAttributes = 0; 28 fMaxFragmentTextureUnits = 0; 29 fMaxFixedFunctionTextureCoords = 0; 30 fRGBA8RenderbufferSupport = false; 31 fBGRAFormatSupport = false; 32 fBGRAIsInternalFormat = false; 33 fTextureSwizzleSupport = false; 34 fUnpackRowLengthSupport = false; 35 fUnpackFlipYSupport = false; 36 fPackRowLengthSupport = false; 37 fPackFlipYSupport = false; 38 fTextureUsageSupport = false; 39 fTexStorageSupport = false; 40 fTextureRedSupport = false; 41 fImagingSupport = false; 42 fTwoFormatLimit = false; 43 fFragCoordsConventionSupport = false; 44 fVertexArrayObjectSupport = false; 45 fUseNonVBOVertexAndIndexDynamicData = false; 46 fIsCoreProfile = false; 47 fFixedFunctionSupport = false; 48 fDiscardFBSupport = false; 49 fFullClearIsFree = false; 50 } 51 52 GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() { 53 *this = caps; 54 } 55 56 GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { 57 INHERITED::operator=(caps); 58 fVerifiedColorConfigs = caps.fVerifiedColorConfigs; 59 fStencilFormats = caps.fStencilFormats; 60 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; 61 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; 62 fMaxVertexAttributes = caps.fMaxVertexAttributes; 63 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits; 64 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords; 65 fMSFBOType = caps.fMSFBOType; 66 fFBFetchType = caps.fFBFetchType; 67 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; 68 fBGRAFormatSupport = caps.fBGRAFormatSupport; 69 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; 70 fTextureSwizzleSupport = caps.fTextureSwizzleSupport; 71 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; 72 fUnpackFlipYSupport = caps.fUnpackFlipYSupport; 73 fPackRowLengthSupport = caps.fPackRowLengthSupport; 74 fPackFlipYSupport = caps.fPackFlipYSupport; 75 fTextureUsageSupport = caps.fTextureUsageSupport; 76 fTexStorageSupport = caps.fTexStorageSupport; 77 fTextureRedSupport = caps.fTextureRedSupport; 78 fImagingSupport = caps.fImagingSupport; 79 fTwoFormatLimit = caps.fTwoFormatLimit; 80 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; 81 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport; 82 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData; 83 fIsCoreProfile = caps.fIsCoreProfile; 84 fFixedFunctionSupport = caps.fFixedFunctionSupport; 85 fDiscardFBSupport = caps.fDiscardFBSupport; 86 fFullClearIsFree = caps.fFullClearIsFree; 87 88 return *this; 89 } 90 91 void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { 92 93 this->reset(); 94 if (!ctxInfo.isInitialized()) { 95 return; 96 } 97 98 GrGLBinding binding = ctxInfo.binding(); 99 GrGLVersion version = ctxInfo.version(); 100 101 /************************************************************************** 102 * Caps specific to GrGLCaps 103 **************************************************************************/ 104 105 if (kES_GrGLBinding == binding) { 106 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, 107 &fMaxFragmentUniformVectors); 108 } else { 109 SkASSERT(kDesktop_GrGLBinding == binding); 110 GrGLint max; 111 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); 112 fMaxFragmentUniformVectors = max / 4; 113 if (version >= GR_GL_VER(3, 2)) { 114 GrGLint profileMask; 115 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); 116 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); 117 } 118 if (!fIsCoreProfile) { 119 fFixedFunctionSupport = true; 120 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords); 121 // Sanity check 122 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128); 123 } 124 } 125 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); 126 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits); 127 128 if (kDesktop_GrGLBinding == binding) { 129 fRGBA8RenderbufferSupport = true; 130 } else { 131 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) || 132 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || 133 ctxInfo.hasExtension("GL_ARM_rgba8"); 134 } 135 136 if (kDesktop_GrGLBinding == binding) { 137 fBGRAFormatSupport = version >= GR_GL_VER(1,2) || 138 ctxInfo.hasExtension("GL_EXT_bgra"); 139 } else { 140 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { 141 fBGRAFormatSupport = true; 142 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { 143 fBGRAFormatSupport = true; 144 fBGRAIsInternalFormat = true; 145 } 146 SkASSERT(fBGRAFormatSupport || 147 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); 148 } 149 150 if (kDesktop_GrGLBinding == binding) { 151 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || 152 ctxInfo.hasExtension("GL_ARB_texture_swizzle"); 153 } else { 154 fTextureSwizzleSupport = version >= GR_GL_VER(3,0); 155 } 156 157 if (kDesktop_GrGLBinding == binding) { 158 fUnpackRowLengthSupport = true; 159 fUnpackFlipYSupport = false; 160 fPackRowLengthSupport = true; 161 fPackFlipYSupport = false; 162 } else { 163 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || 164 ctxInfo.hasExtension("GL_EXT_unpack_subimage"); 165 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); 166 fPackRowLengthSupport = version >= GR_GL_VER(3,0) || 167 ctxInfo.hasExtension("GL_NV_pack_subimage"); 168 fPackFlipYSupport = 169 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); 170 } 171 172 fTextureUsageSupport = (kES_GrGLBinding == binding) && 173 ctxInfo.hasExtension("GL_ANGLE_texture_usage"); 174 175 if (kDesktop_GrGLBinding == binding) { 176 // The EXT version can apply to either GL or GLES. 177 fTexStorageSupport = version >= GR_GL_VER(4,2) || 178 ctxInfo.hasExtension("GL_ARB_texture_storage") || 179 ctxInfo.hasExtension("GL_EXT_texture_storage"); 180 } else { 181 // Qualcomm Adreno drivers appear to have issues with texture storage. 182 fTexStorageSupport = (version >= GR_GL_VER(3,0) && 183 kQualcomm_GrGLVendor != ctxInfo.vendor()) || 184 ctxInfo.hasExtension("GL_EXT_texture_storage"); 185 } 186 187 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if 188 // it doesn't have ARB_texture_rg extension. 189 if (kDesktop_GrGLBinding == binding) { 190 if (ctxInfo.isMesa()) { 191 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg"); 192 } else { 193 fTextureRedSupport = version >= GR_GL_VER(3,0) || 194 ctxInfo.hasExtension("GL_ARB_texture_rg"); 195 } 196 } else { 197 fTextureRedSupport = version >= GR_GL_VER(3,0) || 198 ctxInfo.hasExtension("GL_EXT_texture_rg"); 199 } 200 201 fImagingSupport = kDesktop_GrGLBinding == binding && 202 ctxInfo.hasExtension("GL_ARB_imaging"); 203 204 // ES 2 only guarantees RGBA/uchar + one other format/type combo for 205 // ReadPixels. The other format has to checked at run-time since it 206 // can change based on which render target is bound 207 fTwoFormatLimit = kES_GrGLBinding == binding; 208 209 // Known issue on at least some Intel platforms: 210 // http://code.google.com/p/skia/issues/detail?id=946 211 if (kIntel_GrGLVendor != ctxInfo.vendor()) { 212 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || 213 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"); 214 } 215 216 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with 217 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex 218 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and 219 // limit this decision to specific GPU families rather than basing it on the vendor alone. 220 if (!GR_GL_MUST_USE_VBO && 221 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) { 222 fUseNonVBOVertexAndIndexDynamicData = true; 223 } 224 225 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer"); 226 227 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) { 228 fFullClearIsFree = true; 229 } 230 231 if (kDesktop_GrGLBinding == binding) { 232 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || 233 ctxInfo.hasExtension("GL_ARB_vertex_array_object"); 234 } else { 235 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || 236 ctxInfo.hasExtension("GL_OES_vertex_array_object"); 237 } 238 239 if (kES_GrGLBinding == binding) { 240 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { 241 fFBFetchType = kEXT_FBFetchType; 242 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { 243 fFBFetchType = kNV_FBFetchType; 244 } 245 } 246 247 this->initFSAASupport(ctxInfo, gli); 248 this->initStencilFormats(ctxInfo); 249 250 /************************************************************************** 251 * GrDrawTargetCaps fields 252 **************************************************************************/ 253 GrGLint numFormats; 254 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); 255 if (numFormats) { 256 SkAutoSTMalloc<10, GrGLint> formats(numFormats); 257 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); 258 for (int i = 0; i < numFormats; ++i) { 259 if (formats[i] == GR_GL_PALETTE8_RGBA8) { 260 f8BitPaletteSupport = true; 261 break; 262 } 263 } 264 } 265 266 if (kDesktop_GrGLBinding == binding) { 267 // we could also look for GL_ATI_separate_stencil extension or 268 // GL_EXT_stencil_two_side but they use different function signatures 269 // than GL2.0+ (and than each other). 270 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0)); 271 // supported on GL 1.4 and higher or by extension 272 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) || 273 ctxInfo.hasExtension("GL_EXT_stencil_wrap"); 274 } else { 275 // ES 2 has two sided stencil and stencil wrap 276 fTwoSidedStencilSupport = true; 277 fStencilWrapOpsSupport = true; 278 } 279 280 if (kDesktop_GrGLBinding == binding) { 281 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes 282 // glMapBuffer. 283 } else { 284 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer"); 285 } 286 287 if (kDesktop_GrGLBinding == binding) { 288 if (ctxInfo.version() >= GR_GL_VER(2,0) || 289 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) { 290 fNPOTTextureTileSupport = true; 291 } else { 292 fNPOTTextureTileSupport = false; 293 } 294 } else { 295 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only 296 // ES3 has no limitations. 297 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || 298 ctxInfo.hasExtension("GL_OES_texture_npot"); 299 } 300 301 fHWAALineSupport = (kDesktop_GrGLBinding == binding); 302 303 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); 304 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); 305 // Our render targets are always created with textures as the color 306 // attachment, hence this min: 307 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize); 308 309 fPathRenderingSupport = GR_GL_USE_NV_PATH_RENDERING && 310 ctxInfo.hasExtension("GL_NV_path_rendering"); 311 312 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType; 313 314 // Disable scratch texture reuse on Mali and Adreno devices 315 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() && 316 kQualcomm_GrGLVendor != ctxInfo.vendor(); 317 318 // Enable supported shader-related caps 319 if (kDesktop_GrGLBinding == binding) { 320 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) || 321 ctxInfo.hasExtension("GL_ARB_blend_func_extended"); 322 fShaderDerivativeSupport = true; 323 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS 324 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) && 325 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; 326 } else { 327 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives"); 328 } 329 330 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { 331 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount); 332 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { 333 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); 334 } 335 336 this->initConfigRenderableTable(ctxInfo); 337 } 338 339 void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) { 340 341 // OpenGL < 3.0 342 // no support for render targets unless the GL_ARB_framebuffer_object 343 // extension is supported (in which case we get ALPHA, RED, RG, RGB, 344 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we 345 // probably don't get R8 in this case. 346 347 // OpenGL 3.0 348 // base color renderable: ALPHA, RED, RG, RGB, and RGBA 349 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 350 351 // >= OpenGL 3.1 352 // base color renderable: RED, RG, RGB, and RGBA 353 // sized derivatives: R8, RGBA4, RGBA8 354 // if the GL_ARB_compatibility extension is supported then we get back 355 // support for GL_ALPHA and ALPHA8 356 357 // GL_EXT_bgra adds BGRA render targets to any version 358 359 // ES 2.0 360 // color renderable: RGBA4, RGB5_A1, RGB565 361 // GL_EXT_texture_rg adds support for R8 as a color render target 362 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 363 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support 364 365 // ES 3.0 366 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called 367 // below already account for this). 368 369 enum { 370 kNo_MSAA = 0, 371 kYes_MSAA = 1, 372 }; 373 374 if (kDesktop_GrGLBinding == ctxInfo.binding()) { 375 // Post 3.0 we will get R8 376 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) 377 if (ctxInfo.version() >= GR_GL_VER(3,0) || 378 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { 379 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true; 380 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true; 381 } 382 } else { 383 // On ES we can only hope for R8 384 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport; 385 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport; 386 } 387 388 if (kDesktop_GrGLBinding != ctxInfo.binding()) { 389 // only available in ES 390 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true; 391 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true; 392 } 393 394 // we no longer support 444 as a render target 395 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false; 396 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false; 397 398 if (this->fRGBA8RenderbufferSupport) { 399 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true; 400 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true; 401 } 402 403 if (this->fBGRAFormatSupport) { 404 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true; 405 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of 406 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample. 407 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms. 408 if (ctxInfo.extensions().has("GL_CHROMIUM_renderbuffer_format_BGRA8888")) { 409 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true; 410 } else { 411 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = 412 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers(); 413 } 414 } 415 416 // If we don't support MSAA then undo any places above where we set a config as renderable with 417 // msaa. 418 if (kNone_MSFBOType == fMSFBOType) { 419 for (int i = 0; i < kGrPixelConfigCnt; ++i) { 420 fConfigRenderSupport[i][kYes_MSAA] = false; 421 } 422 } 423 } 424 425 bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, 426 GrGLenum format, 427 GrGLenum type) const { 428 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { 429 // ES 2 guarantees this format is supported 430 return true; 431 } 432 433 if (!fTwoFormatLimit) { 434 // not limited by ES 2's constraints 435 return true; 436 } 437 438 GrGLint otherFormat = GR_GL_RGBA; 439 GrGLint otherType = GR_GL_UNSIGNED_BYTE; 440 441 // The other supported format/type combo supported for ReadPixels 442 // can change based on which render target is bound 443 GR_GL_GetIntegerv(intf, 444 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, 445 &otherFormat); 446 447 GR_GL_GetIntegerv(intf, 448 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, 449 &otherType); 450 451 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; 452 } 453 454 void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { 455 456 fMSFBOType = kNone_MSFBOType; 457 if (kDesktop_GrGLBinding != ctxInfo.binding()) { 458 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed 459 // ES3 driver bugs on at least one device with a tiled GPU (N10). 460 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { 461 fMSFBOType = kES_EXT_MsToTexture_MSFBOType; 462 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { 463 fMSFBOType = kES_IMG_MsToTexture_MSFBOType; 464 } else if (!GR_GL_IGNORE_ES3_MSAA && ctxInfo.version() >= GR_GL_VER(3,0)) { 465 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; 466 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { 467 // chrome's extension is equivalent to the EXT msaa 468 // and fbo_blit extensions. 469 fMSFBOType = kDesktop_EXT_MSFBOType; 470 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { 471 fMSFBOType = kES_Apple_MSFBOType; 472 } 473 } else { 474 if ((ctxInfo.version() >= GR_GL_VER(3,0)) || 475 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { 476 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; 477 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && 478 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { 479 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; 480 } 481 } 482 } 483 484 namespace { 485 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; 486 } 487 488 void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { 489 490 // Build up list of legal stencil formats (though perhaps not supported on 491 // the particular gpu/driver) from most preferred to least. 492 493 // these consts are in order of most preferred to least preferred 494 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 495 496 static const StencilFormat 497 // internal Format stencil bits total bits packed? 498 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, 499 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, 500 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, 501 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, 502 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, 503 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; 504 505 if (kDesktop_GrGLBinding == ctxInfo.binding()) { 506 bool supportsPackedDS = 507 ctxInfo.version() >= GR_GL_VER(3,0) || 508 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || 509 ctxInfo.hasExtension("GL_ARB_framebuffer_object"); 510 511 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we 512 // require FBO support we can expect these are legal formats and don't 513 // check. These also all support the unsized GL_STENCIL_INDEX. 514 fStencilFormats.push_back() = gS8; 515 fStencilFormats.push_back() = gS16; 516 if (supportsPackedDS) { 517 fStencilFormats.push_back() = gD24S8; 518 } 519 fStencilFormats.push_back() = gS4; 520 if (supportsPackedDS) { 521 fStencilFormats.push_back() = gDS; 522 } 523 } else { 524 // ES2 has STENCIL_INDEX8 without extensions but requires extensions 525 // for other formats. 526 // ES doesn't support using the unsized format. 527 528 fStencilFormats.push_back() = gS8; 529 //fStencilFormats.push_back() = gS16; 530 if (ctxInfo.version() >= GR_GL_VER(3,0) || 531 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { 532 fStencilFormats.push_back() = gD24S8; 533 } 534 if (ctxInfo.hasExtension("GL_OES_stencil4")) { 535 fStencilFormats.push_back() = gS4; 536 } 537 } 538 SkASSERT(0 == fStencilVerifiedColorConfigs.count()); 539 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); 540 } 541 542 void GrGLCaps::markColorConfigAndStencilFormatAsVerified( 543 GrPixelConfig config, 544 const GrGLStencilBuffer::Format& format) { 545 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 546 return; 547 #endif 548 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); 549 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); 550 int count = fStencilFormats.count(); 551 // we expect a really small number of possible formats so linear search 552 // should be OK 553 SkASSERT(count < 16); 554 for (int i = 0; i < count; ++i) { 555 if (format.fInternalFormat == 556 fStencilFormats[i].fInternalFormat) { 557 fStencilVerifiedColorConfigs[i].markVerified(config); 558 return; 559 } 560 } 561 GrCrash("Why are we seeing a stencil format that " 562 "GrGLCaps doesn't know about."); 563 } 564 565 bool GrGLCaps::isColorConfigAndStencilFormatVerified( 566 GrPixelConfig config, 567 const GrGLStencilBuffer::Format& format) const { 568 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 569 return false; 570 #endif 571 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); 572 int count = fStencilFormats.count(); 573 // we expect a really small number of possible formats so linear search 574 // should be OK 575 SkASSERT(count < 16); 576 for (int i = 0; i < count; ++i) { 577 if (format.fInternalFormat == 578 fStencilFormats[i].fInternalFormat) { 579 return fStencilVerifiedColorConfigs[i].isVerified(config); 580 } 581 } 582 GrCrash("Why are we seeing a stencil format that " 583 "GLCaps doesn't know about."); 584 return false; 585 } 586 587 SkString GrGLCaps::dump() const { 588 589 SkString r = INHERITED::dump(); 590 591 r.appendf("--- GL-Specific ---\n"); 592 for (int i = 0; i < fStencilFormats.count(); ++i) { 593 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", 594 i, 595 fStencilFormats[i].fStencilBits, 596 fStencilFormats[i].fTotalBits); 597 } 598 599 static const char* kMSFBOExtStr[] = { 600 "None", 601 "ARB", 602 "EXT", 603 "ES 3.0", 604 "Apple", 605 "IMG MS To Texture", 606 "EXT MS To Texture", 607 }; 608 GR_STATIC_ASSERT(0 == kNone_MSFBOType); 609 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); 610 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); 611 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType); 612 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType); 613 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType); 614 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType); 615 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); 616 617 static const char* kFBFetchTypeStr[] = { 618 "None", 619 "EXT", 620 "NV", 621 }; 622 GR_STATIC_ASSERT(0 == kNone_FBFetchType); 623 GR_STATIC_ASSERT(1 == kEXT_FBFetchType); 624 GR_STATIC_ASSERT(2 == kNV_FBFetchType); 625 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1); 626 627 628 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); 629 r.appendf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO")); 630 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); 631 r.appendf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]); 632 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); 633 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits); 634 if (fFixedFunctionSupport) { 635 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords); 636 } 637 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); 638 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); 639 r.appendf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO")); 640 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); 641 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); 642 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); 643 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); 644 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); 645 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); 646 647 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); 648 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); 649 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); 650 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); 651 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); 652 r.appendf("Fragment coord conventions support: %s\n", 653 (fFragCoordsConventionSupport ? "YES": "NO")); 654 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); 655 r.appendf("Use non-VBO for dynamic data: %s\n", 656 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); 657 r.appendf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO")); 658 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO")); 659 return r; 660 } 661