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