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 | 20f7f17 | 2013-05-17 19:05:03 +0000 | [diff] [blame] | 12 | #include "SkTSort.h" |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 13 | |
| 14 | GrGLCaps::GrGLCaps() { |
| 15 | this->reset(); |
| 16 | } |
| 17 | |
| 18 | void GrGLCaps::reset() { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 19 | INHERITED::reset(); |
| 20 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 21 | fVerifiedColorConfigs.reset(); |
| 22 | fStencilFormats.reset(); |
| 23 | fStencilVerifiedColorConfigs.reset(); |
| 24 | fMSFBOType = kNone_MSFBOType; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 25 | fFBFetchType = kNone_FBFetchType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 26 | fMaxFragmentUniformVectors = 0; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 27 | fMaxVertexAttributes = 0; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 28 | fMaxFragmentTextureUnits = 0; |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 29 | fMaxFixedFunctionTextureCoords = 0; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 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; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 40 | fTextureRedSupport = false; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 41 | fImagingSupport = false; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 42 | fTwoFormatLimit = false; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 43 | fFragCoordsConventionSupport = false; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 44 | fVertexArrayObjectSupport = false; |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 45 | fUseNonVBOVertexAndIndexDynamicData = false; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 46 | fIsCoreProfile = false; |
commit-bot@chromium.org | 3628ad9 | 2013-08-30 19:43:47 +0000 | [diff] [blame] | 47 | fFixedFunctionSupport = false; |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 48 | fDiscardFBSupport = false; |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 49 | fFullClearIsFree = false; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 50 | } |
| 51 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 52 | GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 53 | *this = caps; |
| 54 | } |
| 55 | |
| 56 | GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 57 | INHERITED::operator=(caps); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 58 | fVerifiedColorConfigs = caps.fVerifiedColorConfigs; |
| 59 | fStencilFormats = caps.fStencilFormats; |
| 60 | fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; |
| 61 | fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 62 | fMaxVertexAttributes = caps.fMaxVertexAttributes; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 63 | fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits; |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 64 | fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 65 | fMSFBOType = caps.fMSFBOType; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 66 | fFBFetchType = caps.fFBFetchType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 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; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 77 | fTextureRedSupport = caps.fTextureRedSupport; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 78 | fImagingSupport = caps.fImagingSupport; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 79 | fTwoFormatLimit = caps.fTwoFormatLimit; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 80 | fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 81 | fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport; |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 82 | fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 83 | fIsCoreProfile = caps.fIsCoreProfile; |
commit-bot@chromium.org | 3628ad9 | 2013-08-30 19:43:47 +0000 | [diff] [blame] | 84 | fFixedFunctionSupport = caps.fFixedFunctionSupport; |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 85 | fDiscardFBSupport = caps.fDiscardFBSupport; |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 86 | fFullClearIsFree = caps.fFullClearIsFree; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 87 | |
| 88 | return *this; |
| 89 | } |
| 90 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 91 | void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 92 | |
| 93 | this->reset(); |
| 94 | if (!ctxInfo.isInitialized()) { |
| 95 | return; |
| 96 | } |
| 97 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 98 | GrGLStandard standard = ctxInfo.standard(); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 99 | GrGLVersion version = ctxInfo.version(); |
| 100 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 101 | /************************************************************************** |
| 102 | * Caps specific to GrGLCaps |
| 103 | **************************************************************************/ |
| 104 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 105 | if (kGLES_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 106 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 107 | &fMaxFragmentUniformVectors); |
| 108 | } else { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 109 | SkASSERT(kGL_GrGLStandard == standard); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 110 | GrGLint max; |
| 111 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
| 112 | fMaxFragmentUniformVectors = max / 4; |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 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) { |
commit-bot@chromium.org | 3628ad9 | 2013-08-30 19:43:47 +0000 | [diff] [blame] | 119 | fFixedFunctionSupport = true; |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 120 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords); |
| 121 | // Sanity check |
| 122 | SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128); |
| 123 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 124 | } |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 125 | GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 126 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 127 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 128 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 129 | fRGBA8RenderbufferSupport = true; |
| 130 | } else { |
commit-bot@chromium.org | c5dffe4 | 2013-08-20 15:25:21 +0000 | [diff] [blame] | 131 | fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) || |
| 132 | ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 133 | ctxInfo.hasExtension("GL_ARM_rgba8"); |
| 134 | } |
| 135 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 136 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 137 | fBGRAFormatSupport = version >= GR_GL_VER(1,2) || |
| 138 | ctxInfo.hasExtension("GL_EXT_bgra"); |
| 139 | } else { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 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 | } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 146 | SkASSERT(fBGRAFormatSupport || |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 147 | kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 148 | } |
| 149 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 150 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 151 | fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || |
| 152 | ctxInfo.hasExtension("GL_ARB_texture_swizzle"); |
| 153 | } else { |
commit-bot@chromium.org | 6364b5e | 2013-08-20 20:22:52 +0000 | [diff] [blame] | 154 | fTextureSwizzleSupport = version >= GR_GL_VER(3,0); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 155 | } |
| 156 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 157 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 158 | fUnpackRowLengthSupport = true; |
| 159 | fUnpackFlipYSupport = false; |
| 160 | fPackRowLengthSupport = true; |
| 161 | fPackFlipYSupport = false; |
| 162 | } else { |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 163 | fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 164 | ctxInfo.hasExtension("GL_EXT_unpack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 165 | fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 166 | fPackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 167 | ctxInfo.hasExtension("GL_NV_pack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 168 | fPackFlipYSupport = |
| 169 | ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); |
| 170 | } |
| 171 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 172 | fTextureUsageSupport = (kGLES_GrGLStandard == standard) && |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 173 | ctxInfo.hasExtension("GL_ANGLE_texture_usage"); |
| 174 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 175 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 7a434a2 | 2013-08-21 14:01:56 +0000 | [diff] [blame] | 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 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 186 | |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 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. |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 189 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 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 | } |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 196 | } else { |
commit-bot@chromium.org | c5dffe4 | 2013-08-20 15:25:21 +0000 | [diff] [blame] | 197 | fTextureRedSupport = version >= GR_GL_VER(3,0) || |
| 198 | ctxInfo.hasExtension("GL_EXT_texture_rg"); |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 199 | } |
| 200 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 201 | fImagingSupport = kGL_GrGLStandard == standard && |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 202 | ctxInfo.hasExtension("GL_ARB_imaging"); |
| 203 | |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 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 |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 207 | fTwoFormatLimit = kGLES_GrGLStandard == standard; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 208 | |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 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 | |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 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())) { |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 222 | fUseNonVBOVertexAndIndexDynamicData = true; |
| 223 | } |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 224 | |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 225 | fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer"); |
| 226 | |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 227 | if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) { |
| 228 | fFullClearIsFree = true; |
| 229 | } |
| 230 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 231 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 232 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
| 233 | ctxInfo.hasExtension("GL_ARB_vertex_array_object"); |
| 234 | } else { |
commit-bot@chromium.org | 2276c01 | 2013-08-16 15:53:33 +0000 | [diff] [blame] | 235 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
| 236 | ctxInfo.hasExtension("GL_OES_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 237 | } |
| 238 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 239 | if (kGLES_GrGLStandard == standard) { |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 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 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 247 | this->initFSAASupport(ctxInfo, gli); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 248 | this->initStencilFormats(ctxInfo); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 249 | |
| 250 | /************************************************************************** |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 251 | * GrDrawTargetCaps fields |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 252 | **************************************************************************/ |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 253 | GrGLint numFormats; |
| 254 | GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); |
bungeman@google.com | 7103344 | 2013-05-01 14:21:20 +0000 | [diff] [blame] | 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 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 266 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 280 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 287 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 288 | SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) || |
| 289 | ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")); |
| 290 | fNPOTTextureTileSupport = true; |
| 291 | fMipMapSupport = true; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 292 | } else { |
| 293 | // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only |
commit-bot@chromium.org | 22dd6b9 | 2013-08-16 18:13:48 +0000 | [diff] [blame] | 294 | // ES3 has no limitations. |
| 295 | fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || |
| 296 | ctxInfo.hasExtension("GL_OES_texture_npot"); |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 297 | // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP |
| 298 | // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently, |
| 299 | // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to |
| 300 | // to alllow arbitrary wrap modes, however. |
| 301 | fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot"); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 302 | } |
| 303 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 304 | fHWAALineSupport = (kGL_GrGLStandard == standard); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 305 | |
| 306 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); |
| 307 | GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); |
| 308 | // Our render targets are always created with textures as the color |
| 309 | // attachment, hence this min: |
| 310 | fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize); |
| 311 | |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 312 | fPathRenderingSupport = GR_GL_USE_NV_PATH_RENDERING && |
| 313 | ctxInfo.hasExtension("GL_NV_path_rendering"); |
robertphillips@google.com | 1c6affb | 2014-01-09 13:20:48 +0000 | [diff] [blame] | 314 | SkASSERT(!fPathRenderingSupport || fFixedFunctionSupport); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 315 | |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 316 | fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType; |
robertphillips@google.com | 8995b7b | 2013-11-01 15:03:34 +0000 | [diff] [blame] | 317 | |
| 318 | // Disable scratch texture reuse on Mali and Adreno devices |
| 319 | fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() && |
| 320 | kQualcomm_GrGLVendor != ctxInfo.vendor(); |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 321 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 322 | // Enable supported shader-related caps |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 323 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 324 | fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) || |
| 325 | ctxInfo.hasExtension("GL_ARB_blend_func_extended"); |
| 326 | fShaderDerivativeSupport = true; |
| 327 | // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS |
| 328 | fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) && |
| 329 | ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; |
| 330 | } else { |
| 331 | fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives"); |
| 332 | } |
| 333 | |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 334 | if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 335 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount); |
| 336 | } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { |
| 337 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); |
| 338 | } |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 339 | |
| 340 | this->initConfigRenderableTable(ctxInfo); |
| 341 | } |
| 342 | |
| 343 | void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) { |
| 344 | |
| 345 | // OpenGL < 3.0 |
| 346 | // no support for render targets unless the GL_ARB_framebuffer_object |
| 347 | // extension is supported (in which case we get ALPHA, RED, RG, RGB, |
| 348 | // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we |
| 349 | // probably don't get R8 in this case. |
| 350 | |
| 351 | // OpenGL 3.0 |
| 352 | // base color renderable: ALPHA, RED, RG, RGB, and RGBA |
| 353 | // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 |
| 354 | |
| 355 | // >= OpenGL 3.1 |
| 356 | // base color renderable: RED, RG, RGB, and RGBA |
| 357 | // sized derivatives: R8, RGBA4, RGBA8 |
| 358 | // if the GL_ARB_compatibility extension is supported then we get back |
| 359 | // support for GL_ALPHA and ALPHA8 |
| 360 | |
| 361 | // GL_EXT_bgra adds BGRA render targets to any version |
| 362 | |
| 363 | // ES 2.0 |
| 364 | // color renderable: RGBA4, RGB5_A1, RGB565 |
| 365 | // GL_EXT_texture_rg adds support for R8 as a color render target |
| 366 | // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 |
| 367 | // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support |
| 368 | |
| 369 | // ES 3.0 |
| 370 | // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called |
| 371 | // below already account for this). |
| 372 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 373 | enum { |
| 374 | kNo_MSAA = 0, |
| 375 | kYes_MSAA = 1, |
| 376 | }; |
| 377 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 378 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 379 | // Post 3.0 we will get R8 |
| 380 | // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) |
| 381 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 382 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 383 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true; |
| 384 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 385 | } |
| 386 | } else { |
| 387 | // On ES we can only hope for R8 |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 388 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport; |
| 389 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 390 | } |
| 391 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 392 | if (kGL_GrGLStandard != ctxInfo.standard()) { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 393 | // only available in ES |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 394 | fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true; |
| 395 | fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // we no longer support 444 as a render target |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 399 | fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false; |
| 400 | fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 401 | |
| 402 | if (this->fRGBA8RenderbufferSupport) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 403 | fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true; |
commit-bot@chromium.org | da3d69c | 2013-10-28 15:09:13 +0000 | [diff] [blame] | 404 | fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | if (this->fBGRAFormatSupport) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 408 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true; |
| 409 | // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of |
| 410 | // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample. |
commit-bot@chromium.org | 4256d24 | 2013-10-17 16:29:41 +0000 | [diff] [blame] | 411 | // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms. |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame^] | 412 | if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) { |
commit-bot@chromium.org | 4256d24 | 2013-10-17 16:29:41 +0000 | [diff] [blame] | 413 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true; |
| 414 | } else { |
| 415 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = |
| 416 | !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers(); |
| 417 | } |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | // If we don't support MSAA then undo any places above where we set a config as renderable with |
| 421 | // msaa. |
| 422 | if (kNone_MSFBOType == fMSFBOType) { |
| 423 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 424 | fConfigRenderSupport[i][kYes_MSAA] = false; |
| 425 | } |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 426 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 427 | } |
| 428 | |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 429 | bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 430 | GrGLenum format, |
| 431 | GrGLenum type) const { |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 432 | if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { |
| 433 | // ES 2 guarantees this format is supported |
robertphillips@google.com | eca2dfb | 2012-06-27 20:13:49 +0000 | [diff] [blame] | 434 | return true; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | if (!fTwoFormatLimit) { |
| 438 | // not limited by ES 2's constraints |
| 439 | return true; |
| 440 | } |
| 441 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 442 | GrGLint otherFormat = GR_GL_RGBA; |
| 443 | GrGLint otherType = GR_GL_UNSIGNED_BYTE; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 444 | |
| 445 | // The other supported format/type combo supported for ReadPixels |
| 446 | // can change based on which render target is bound |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 447 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 448 | GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, |
| 449 | &otherFormat); |
| 450 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 451 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 452 | GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, |
| 453 | &otherType); |
| 454 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 455 | return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 456 | } |
| 457 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 458 | void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 459 | |
| 460 | fMSFBOType = kNone_MSFBOType; |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 461 | if (kGL_GrGLStandard != ctxInfo.standard()) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 462 | // We prefer the EXT/IMG extension over ES3 MSAA because we've observed |
| 463 | // ES3 driver bugs on at least one device with a tiled GPU (N10). |
| 464 | if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { |
| 465 | fMSFBOType = kES_EXT_MsToTexture_MSFBOType; |
| 466 | } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { |
| 467 | fMSFBOType = kES_IMG_MsToTexture_MSFBOType; |
commit-bot@chromium.org | 92b7884 | 2014-01-16 20:49:46 +0000 | [diff] [blame] | 468 | } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 469 | fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; |
| 470 | } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| 471 | // chrome's extension is equivalent to the EXT msaa |
| 472 | // and fbo_blit extensions. |
| 473 | fMSFBOType = kDesktop_EXT_MSFBOType; |
| 474 | } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
| 475 | fMSFBOType = kES_Apple_MSFBOType; |
| 476 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 477 | } else { |
| 478 | if ((ctxInfo.version() >= GR_GL_VER(3,0)) || |
| 479 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 480 | fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 481 | } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
| 482 | ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 483 | fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 484 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
| 488 | namespace { |
| 489 | const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
| 490 | } |
| 491 | |
| 492 | void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { |
| 493 | |
| 494 | // Build up list of legal stencil formats (though perhaps not supported on |
| 495 | // the particular gpu/driver) from most preferred to least. |
| 496 | |
| 497 | // these consts are in order of most preferred to least preferred |
| 498 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
| 499 | |
| 500 | static const StencilFormat |
| 501 | // internal Format stencil bits total bits packed? |
| 502 | gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
| 503 | gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
| 504 | gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
| 505 | gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 506 | // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 507 | gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
| 508 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 509 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 510 | bool supportsPackedDS = |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 511 | ctxInfo.version() >= GR_GL_VER(3,0) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 512 | ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || |
| 513 | ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
| 514 | |
| 515 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 516 | // require FBO support we can expect these are legal formats and don't |
| 517 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 518 | fStencilFormats.push_back() = gS8; |
| 519 | fStencilFormats.push_back() = gS16; |
| 520 | if (supportsPackedDS) { |
| 521 | fStencilFormats.push_back() = gD24S8; |
| 522 | } |
| 523 | fStencilFormats.push_back() = gS4; |
| 524 | if (supportsPackedDS) { |
| 525 | fStencilFormats.push_back() = gDS; |
| 526 | } |
| 527 | } else { |
| 528 | // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
| 529 | // for other formats. |
| 530 | // ES doesn't support using the unsized format. |
| 531 | |
| 532 | fStencilFormats.push_back() = gS8; |
| 533 | //fStencilFormats.push_back() = gS16; |
commit-bot@chromium.org | 04c500f | 2013-09-06 15:28:01 +0000 | [diff] [blame] | 534 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 535 | ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 536 | fStencilFormats.push_back() = gD24S8; |
| 537 | } |
| 538 | if (ctxInfo.hasExtension("GL_OES_stencil4")) { |
| 539 | fStencilFormats.push_back() = gS4; |
| 540 | } |
| 541 | } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 542 | SkASSERT(0 == fStencilVerifiedColorConfigs.count()); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 543 | fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); |
| 544 | } |
| 545 | |
| 546 | void GrGLCaps::markColorConfigAndStencilFormatAsVerified( |
| 547 | GrPixelConfig config, |
| 548 | const GrGLStencilBuffer::Format& format) { |
| 549 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 550 | return; |
| 551 | #endif |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 552 | SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); |
| 553 | SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 554 | int count = fStencilFormats.count(); |
| 555 | // we expect a really small number of possible formats so linear search |
| 556 | // should be OK |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 557 | SkASSERT(count < 16); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 558 | for (int i = 0; i < count; ++i) { |
| 559 | if (format.fInternalFormat == |
| 560 | fStencilFormats[i].fInternalFormat) { |
| 561 | fStencilVerifiedColorConfigs[i].markVerified(config); |
| 562 | return; |
| 563 | } |
| 564 | } |
| 565 | GrCrash("Why are we seeing a stencil format that " |
| 566 | "GrGLCaps doesn't know about."); |
| 567 | } |
| 568 | |
| 569 | bool GrGLCaps::isColorConfigAndStencilFormatVerified( |
| 570 | GrPixelConfig config, |
| 571 | const GrGLStencilBuffer::Format& format) const { |
| 572 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 573 | return false; |
| 574 | #endif |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 575 | SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 576 | int count = fStencilFormats.count(); |
| 577 | // we expect a really small number of possible formats so linear search |
| 578 | // should be OK |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 579 | SkASSERT(count < 16); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 580 | for (int i = 0; i < count; ++i) { |
| 581 | if (format.fInternalFormat == |
| 582 | fStencilFormats[i].fInternalFormat) { |
| 583 | return fStencilVerifiedColorConfigs[i].isVerified(config); |
| 584 | } |
| 585 | } |
| 586 | GrCrash("Why are we seeing a stencil format that " |
| 587 | "GLCaps doesn't know about."); |
| 588 | return false; |
| 589 | } |
| 590 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 591 | SkString GrGLCaps::dump() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 592 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 593 | SkString r = INHERITED::dump(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 594 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 595 | r.appendf("--- GL-Specific ---\n"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 596 | for (int i = 0; i < fStencilFormats.count(); ++i) { |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 597 | r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 598 | i, |
| 599 | fStencilFormats[i].fStencilBits, |
| 600 | fStencilFormats[i].fTotalBits); |
| 601 | } |
| 602 | |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 603 | static const char* kMSFBOExtStr[] = { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 604 | "None", |
| 605 | "ARB", |
| 606 | "EXT", |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 607 | "ES 3.0", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 608 | "Apple", |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 609 | "IMG MS To Texture", |
| 610 | "EXT MS To Texture", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 611 | }; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 612 | GR_STATIC_ASSERT(0 == kNone_MSFBOType); |
| 613 | GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); |
| 614 | GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 615 | GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType); |
| 616 | GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType); |
| 617 | GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType); |
| 618 | GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 619 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); |
| 620 | |
| 621 | static const char* kFBFetchTypeStr[] = { |
| 622 | "None", |
| 623 | "EXT", |
| 624 | "NV", |
| 625 | }; |
| 626 | GR_STATIC_ASSERT(0 == kNone_FBFetchType); |
| 627 | GR_STATIC_ASSERT(1 == kEXT_FBFetchType); |
| 628 | GR_STATIC_ASSERT(2 == kNV_FBFetchType); |
| 629 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1); |
| 630 | |
| 631 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 632 | r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); |
| 633 | r.appendf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO")); |
| 634 | r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); |
| 635 | r.appendf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]); |
| 636 | r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); |
| 637 | r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits); |
commit-bot@chromium.org | 3628ad9 | 2013-08-30 19:43:47 +0000 | [diff] [blame] | 638 | if (fFixedFunctionSupport) { |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 639 | r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords); |
commit-bot@chromium.org | 3628ad9 | 2013-08-30 19:43:47 +0000 | [diff] [blame] | 640 | } |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 641 | r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); |
| 642 | r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); |
| 643 | r.appendf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO")); |
| 644 | r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); |
| 645 | r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); |
| 646 | r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); |
| 647 | r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); |
| 648 | r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); |
| 649 | r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 650 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 651 | r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); |
| 652 | r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); |
| 653 | r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); |
| 654 | r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); |
| 655 | r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); |
| 656 | r.appendf("Fragment coord conventions support: %s\n", |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 657 | (fFragCoordsConventionSupport ? "YES": "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 658 | r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); |
| 659 | r.appendf("Use non-VBO for dynamic data: %s\n", |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 660 | (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 661 | r.appendf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO")); |
| 662 | r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO")); |
| 663 | return r; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 664 | } |