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