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" |
joshualitt | b4384b9 | 2014-10-21 12:53:15 -0700 | [diff] [blame] | 10 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 11 | #include "GrGLContext.h" |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 12 | #include "SkTSearch.h" |
bsalomon@google.com | 20f7f17 | 2013-05-17 19:05:03 +0000 | [diff] [blame] | 13 | #include "SkTSort.h" |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 14 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 15 | GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions, |
| 16 | const GrGLContextInfo& ctxInfo, |
| 17 | const GrGLInterface* glInterface) : INHERITED(contextOptions) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 18 | fVerifiedColorConfigs.reset(); |
| 19 | fStencilFormats.reset(); |
| 20 | fStencilVerifiedColorConfigs.reset(); |
| 21 | fMSFBOType = kNone_MSFBOType; |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 22 | fInvalidateFBType = kNone_InvalidateFBType; |
krajcevski | 3217c4a | 2014-06-09 09:10:04 -0700 | [diff] [blame] | 23 | fLATCAlias = kLATC_LATCAlias; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 24 | fMapBufferType = kNone_MapBufferType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 25 | fMaxFragmentUniformVectors = 0; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 26 | fMaxVertexAttributes = 0; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 27 | fMaxFragmentTextureUnits = 0; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 28 | fRGBA8RenderbufferSupport = false; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 29 | fBGRAIsInternalFormat = false; |
| 30 | fTextureSwizzleSupport = false; |
| 31 | fUnpackRowLengthSupport = false; |
| 32 | fUnpackFlipYSupport = false; |
| 33 | fPackRowLengthSupport = false; |
| 34 | fPackFlipYSupport = false; |
| 35 | fTextureUsageSupport = false; |
| 36 | fTexStorageSupport = false; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 37 | fTextureRedSupport = false; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 38 | fImagingSupport = false; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 39 | fTwoFormatLimit = false; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 40 | fFragCoordsConventionSupport = false; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 41 | fVertexArrayObjectSupport = false; |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 42 | fES2CompatibilitySupport = false; |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 43 | fMultisampleDisableSupport = 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 | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 46 | fFullClearIsFree = false; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 47 | |
| 48 | fReadPixelsSupportedCache.reset(); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 49 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 50 | this->init(ctxInfo, glInterface); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 51 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame^] | 52 | fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions, |
| 53 | ctxInfo, glInterface, *this))); |
| 54 | |
| 55 | this->applyOptionsOverrides(contextOptions); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 56 | } |
| 57 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 58 | void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 59 | GrGLStandard standard = ctxInfo.standard(); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 60 | GrGLVersion version = ctxInfo.version(); |
| 61 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 62 | /************************************************************************** |
| 63 | * Caps specific to GrGLCaps |
| 64 | **************************************************************************/ |
| 65 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 66 | if (kGLES_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 67 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 68 | &fMaxFragmentUniformVectors); |
| 69 | } else { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 70 | SkASSERT(kGL_GrGLStandard == standard); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 71 | GrGLint max; |
| 72 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
| 73 | fMaxFragmentUniformVectors = max / 4; |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 74 | if (version >= GR_GL_VER(3, 2)) { |
| 75 | GrGLint profileMask; |
| 76 | GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); |
| 77 | fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); |
| 78 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 79 | } |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 80 | GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 81 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 82 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 83 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 84 | fRGBA8RenderbufferSupport = true; |
| 85 | } else { |
commit-bot@chromium.org | c5dffe4 | 2013-08-20 15:25:21 +0000 | [diff] [blame] | 86 | fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) || |
| 87 | ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 88 | ctxInfo.hasExtension("GL_ARM_rgba8"); |
| 89 | } |
| 90 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 91 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 92 | fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || |
| 93 | ctxInfo.hasExtension("GL_ARB_texture_swizzle"); |
| 94 | } else { |
commit-bot@chromium.org | 6364b5e | 2013-08-20 20:22:52 +0000 | [diff] [blame] | 95 | fTextureSwizzleSupport = version >= GR_GL_VER(3,0); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 96 | } |
| 97 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 98 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 99 | fUnpackRowLengthSupport = true; |
| 100 | fUnpackFlipYSupport = false; |
| 101 | fPackRowLengthSupport = true; |
| 102 | fPackFlipYSupport = false; |
| 103 | } else { |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 104 | fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 105 | ctxInfo.hasExtension("GL_EXT_unpack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 106 | fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); |
commit-bot@chromium.org | dc3134c | 2013-08-16 16:12:23 +0000 | [diff] [blame] | 107 | fPackRowLengthSupport = version >= GR_GL_VER(3,0) || |
| 108 | ctxInfo.hasExtension("GL_NV_pack_subimage"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 109 | fPackFlipYSupport = |
| 110 | ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); |
| 111 | } |
| 112 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 113 | fTextureUsageSupport = (kGLES_GrGLStandard == standard) && |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 114 | ctxInfo.hasExtension("GL_ANGLE_texture_usage"); |
| 115 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 116 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 7a434a2 | 2013-08-21 14:01:56 +0000 | [diff] [blame] | 117 | // The EXT version can apply to either GL or GLES. |
| 118 | fTexStorageSupport = version >= GR_GL_VER(4,2) || |
| 119 | ctxInfo.hasExtension("GL_ARB_texture_storage") || |
| 120 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| 121 | } else { |
| 122 | // Qualcomm Adreno drivers appear to have issues with texture storage. |
| 123 | fTexStorageSupport = (version >= GR_GL_VER(3,0) && |
| 124 | kQualcomm_GrGLVendor != ctxInfo.vendor()) || |
| 125 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| 126 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 127 | |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 128 | if (kGL_GrGLStandard == standard) { |
| 129 | fTextureBarrierSupport = version >= GR_GL_VER(4,5) || |
| 130 | ctxInfo.hasExtension("GL_ARB_texture_barrier") || |
| 131 | ctxInfo.hasExtension("GL_NV_texture_barrier"); |
| 132 | } else { |
| 133 | fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier"); |
| 134 | } |
| 135 | |
hendrikw | a0d5ad7 | 2014-12-02 07:30:30 -0800 | [diff] [blame] | 136 | // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED |
| 137 | // and GL_RG on FBO textures. |
| 138 | if (!ctxInfo.isMesa()) { |
| 139 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 140 | fTextureRedSupport = version >= GR_GL_VER(3,0) || |
| 141 | ctxInfo.hasExtension("GL_ARB_texture_rg"); |
hendrikw | a0d5ad7 | 2014-12-02 07:30:30 -0800 | [diff] [blame] | 142 | } else { |
| 143 | fTextureRedSupport = version >= GR_GL_VER(3,0) || |
| 144 | ctxInfo.hasExtension("GL_EXT_texture_rg"); |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 145 | } |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 146 | } |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 147 | fImagingSupport = kGL_GrGLStandard == standard && |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 148 | ctxInfo.hasExtension("GL_ARB_imaging"); |
| 149 | |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 150 | // ES 2 only guarantees RGBA/uchar + one other format/type combo for |
| 151 | // ReadPixels. The other format has to checked at run-time since it |
| 152 | // can change based on which render target is bound |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 153 | fTwoFormatLimit = kGLES_GrGLStandard == standard; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 154 | |
rmistry | 63a9f84 | 2014-10-17 06:07:08 -0700 | [diff] [blame] | 155 | // Frag Coords Convention support is not part of ES |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 156 | // Known issue on at least some Intel platforms: |
| 157 | // http://code.google.com/p/skia/issues/detail?id=946 |
rmistry | 63a9f84 | 2014-10-17 06:07:08 -0700 | [diff] [blame] | 158 | if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) { |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 159 | fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || |
| 160 | ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"); |
| 161 | } |
| 162 | |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 163 | // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with |
| 164 | // frequently changing VBOs. We've measured a performance increase using non-VBO vertex |
| 165 | // data for dynamic content on these GPUs. Perhaps we should read the renderer string and |
| 166 | // limit this decision to specific GPU families rather than basing it on the vendor alone. |
| 167 | if (!GR_GL_MUST_USE_VBO && |
bsalomon | ed82c4e | 2014-09-02 07:54:47 -0700 | [diff] [blame] | 168 | (kARM_GrGLVendor == ctxInfo.vendor() || |
| 169 | kImagination_GrGLVendor == ctxInfo.vendor() || |
| 170 | kQualcomm_GrGLVendor == ctxInfo.vendor())) { |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 171 | fUseNonVBOVertexAndIndexDynamicData = true; |
| 172 | } |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 173 | |
egdaniel | 9250d24 | 2015-05-18 13:04:26 -0700 | [diff] [blame] | 174 | // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand. |
| 175 | // Thus we are blacklisting this extension for now on Adreno4xx devices. |
| 176 | if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() && |
| 177 | ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) || |
| 178 | (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) || |
| 179 | ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) { |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 180 | fDiscardRenderTargetSupport = true; |
| 181 | fInvalidateFBType = kInvalidate_InvalidateFBType; |
| 182 | } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) { |
| 183 | fDiscardRenderTargetSupport = true; |
| 184 | fInvalidateFBType = kDiscard_InvalidateFBType; |
| 185 | } |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 186 | |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 187 | if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) { |
| 188 | fFullClearIsFree = true; |
| 189 | } |
| 190 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 191 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 192 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
tomhudson | 612e926 | 2014-11-24 11:22:36 -0800 | [diff] [blame] | 193 | ctxInfo.hasExtension("GL_ARB_vertex_array_object") || |
| 194 | ctxInfo.hasExtension("GL_APPLE_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 195 | } else { |
commit-bot@chromium.org | 2276c01 | 2013-08-16 15:53:33 +0000 | [diff] [blame] | 196 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
| 197 | ctxInfo.hasExtension("GL_OES_vertex_array_object"); |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 198 | } |
| 199 | |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 200 | if (kGL_GrGLStandard == standard) { |
| 201 | fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility"); |
| 202 | } |
| 203 | else { |
| 204 | fES2CompatibilitySupport = true; |
| 205 | } |
| 206 | |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 207 | if (kGL_GrGLStandard == standard) { |
| 208 | fMultisampleDisableSupport = true; |
| 209 | } else { |
| 210 | fMultisampleDisableSupport = false; |
| 211 | } |
| 212 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 213 | this->initFSAASupport(ctxInfo, gli); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 214 | this->initStencilFormats(ctxInfo); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 215 | |
| 216 | /************************************************************************** |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 217 | * GrCaps fields |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 218 | **************************************************************************/ |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 219 | if (kGL_GrGLStandard == standard) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 220 | // we could also look for GL_ATI_separate_stencil extension or |
| 221 | // GL_EXT_stencil_two_side but they use different function signatures |
| 222 | // than GL2.0+ (and than each other). |
| 223 | fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0)); |
| 224 | // supported on GL 1.4 and higher or by extension |
| 225 | fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) || |
| 226 | ctxInfo.hasExtension("GL_EXT_stencil_wrap"); |
| 227 | } else { |
| 228 | // ES 2 has two sided stencil and stencil wrap |
| 229 | fTwoSidedStencilSupport = true; |
| 230 | fStencilWrapOpsSupport = true; |
| 231 | } |
| 232 | |
egdaniel | 28eee1a | 2015-05-08 14:42:43 -0700 | [diff] [blame] | 233 | // Disabling advanced blend until we can resolve various bugs |
| 234 | #if 0 |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 235 | if (kIntel_GrGLVendor != ctxInfo.vendor()) { |
| 236 | if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") || |
| 237 | ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) { |
| 238 | fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport; |
| 239 | } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") || |
| 240 | ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) { |
| 241 | fBlendEquationSupport = kAdvanced_BlendEquationSupport; |
| 242 | } else { |
| 243 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
| 244 | } |
| 245 | } else { |
| 246 | // On Intel platforms, KHR_blend_equation_advanced is not conformant. |
| 247 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
| 248 | } |
egdaniel | 28eee1a | 2015-05-08 14:42:43 -0700 | [diff] [blame] | 249 | #endif |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 250 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 251 | fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO |
| 252 | // extension includes glMapBuffer. |
| 253 | if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) { |
| 254 | fMapBufferFlags |= kSubset_MapFlag; |
| 255 | fMapBufferType = kMapBufferRange_MapBufferType; |
| 256 | } else { |
| 257 | fMapBufferType = kMapBuffer_MapBufferType; |
| 258 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 259 | } else { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 260 | // Unextended GLES2 doesn't have any buffer mapping. |
| 261 | fMapBufferFlags = kNone_MapBufferType; |
| 262 | if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) { |
| 263 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 264 | fMapBufferType = kChromium_MapBufferType; |
| 265 | } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) { |
| 266 | fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag; |
| 267 | fMapBufferType = kMapBufferRange_MapBufferType; |
| 268 | } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) { |
| 269 | fMapBufferFlags = kCanMap_MapFlag; |
| 270 | fMapBufferType = kMapBuffer_MapBufferType; |
| 271 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 272 | } |
| 273 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 274 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 275 | SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) || |
| 276 | ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")); |
| 277 | fNPOTTextureTileSupport = true; |
| 278 | fMipMapSupport = true; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 279 | } else { |
| 280 | // 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] | 281 | // ES3 has no limitations. |
| 282 | fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || |
| 283 | ctxInfo.hasExtension("GL_OES_texture_npot"); |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 284 | // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP |
| 285 | // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently, |
| 286 | // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to |
| 287 | // to alllow arbitrary wrap modes, however. |
| 288 | fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot"); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 289 | } |
| 290 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 291 | GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); |
| 292 | GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); |
| 293 | // Our render targets are always created with textures as the color |
| 294 | // attachment, hence this min: |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 295 | fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 296 | |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 297 | fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker"); |
| 298 | |
robertphillips@google.com | 8995b7b | 2013-11-01 15:03:34 +0000 | [diff] [blame] | 299 | // Disable scratch texture reuse on Mali and Adreno devices |
| 300 | fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() && |
| 301 | kQualcomm_GrGLVendor != ctxInfo.vendor(); |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 302 | |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 303 | if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 304 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount); |
| 305 | } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { |
| 306 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); |
| 307 | } |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 308 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 309 | if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() || |
bsalomon | e702d97 | 2015-01-29 10:07:32 -0800 | [diff] [blame] | 310 | kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() || |
bsalomon | a8fcea0 | 2015-02-13 09:00:39 -0800 | [diff] [blame] | 311 | kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 312 | fUseDrawInsteadOfClear = true; |
| 313 | } |
| 314 | |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 315 | if (kGL_GrGLStandard == standard) { |
| 316 | // ARB allows mixed size FBO attachments, EXT does not. |
| 317 | if (ctxInfo.version() >= GR_GL_VER(3, 0) || |
| 318 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
| 319 | fOversizedStencilSupport = true; |
| 320 | } else { |
| 321 | SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object")); |
| 322 | } |
| 323 | } else { |
| 324 | // ES 3.0 supports mixed size FBO attachments, 2.0 does not. |
| 325 | fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0); |
| 326 | } |
| 327 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 328 | this->initConfigTexturableTable(ctxInfo, gli); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 329 | this->initConfigRenderableTable(ctxInfo); |
| 330 | } |
| 331 | |
| 332 | void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 333 | // OpenGL < 3.0 |
| 334 | // no support for render targets unless the GL_ARB_framebuffer_object |
| 335 | // extension is supported (in which case we get ALPHA, RED, RG, RGB, |
| 336 | // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we |
| 337 | // probably don't get R8 in this case. |
| 338 | |
| 339 | // OpenGL 3.0 |
| 340 | // base color renderable: ALPHA, RED, RG, RGB, and RGBA |
| 341 | // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 |
| 342 | |
| 343 | // >= OpenGL 3.1 |
| 344 | // base color renderable: RED, RG, RGB, and RGBA |
| 345 | // sized derivatives: R8, RGBA4, RGBA8 |
| 346 | // if the GL_ARB_compatibility extension is supported then we get back |
| 347 | // support for GL_ALPHA and ALPHA8 |
| 348 | |
| 349 | // GL_EXT_bgra adds BGRA render targets to any version |
| 350 | |
| 351 | // ES 2.0 |
| 352 | // color renderable: RGBA4, RGB5_A1, RGB565 |
| 353 | // GL_EXT_texture_rg adds support for R8 as a color render target |
| 354 | // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 |
| 355 | // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support |
| 356 | |
| 357 | // ES 3.0 |
| 358 | // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called |
| 359 | // below already account for this). |
| 360 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 361 | GrGLStandard standard = ctxInfo.standard(); |
| 362 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 363 | enum { |
| 364 | kNo_MSAA = 0, |
| 365 | kYes_MSAA = 1, |
| 366 | }; |
| 367 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 368 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 369 | // Post 3.0 we will get R8 |
| 370 | // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) |
| 371 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 372 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 373 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true; |
| 374 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 375 | } |
| 376 | } else { |
| 377 | // On ES we can only hope for R8 |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 378 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport; |
| 379 | fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 380 | } |
| 381 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 382 | if (kGL_GrGLStandard != standard) { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 383 | // only available in ES |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 384 | fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true; |
| 385 | fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | // we no longer support 444 as a render target |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 389 | fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false; |
| 390 | fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 391 | |
| 392 | if (this->fRGBA8RenderbufferSupport) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 393 | fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true; |
commit-bot@chromium.org | da3d69c | 2013-10-28 15:09:13 +0000 | [diff] [blame] | 394 | fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 395 | } |
| 396 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 397 | if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 398 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true; |
| 399 | // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of |
| 400 | // 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] | 401 | // 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] | 402 | if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) { |
commit-bot@chromium.org | 4256d24 | 2013-10-17 16:29:41 +0000 | [diff] [blame] | 403 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true; |
| 404 | } else { |
| 405 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = |
| 406 | !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers(); |
| 407 | } |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 408 | } |
| 409 | |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 410 | if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) { |
| 411 | if (kGL_GrGLStandard == standard) { |
| 412 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 413 | ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") || |
| 414 | ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) { |
| 415 | fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true; |
| 416 | fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true; |
| 417 | } |
| 418 | } else { |
| 419 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 420 | ctxInfo.hasExtension("GL_EXT_sRGB")) { |
| 421 | fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true; |
| 422 | fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 427 | if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) { |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 428 | if (kGL_GrGLStandard == standard) { |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 429 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 430 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true; |
| 431 | } else { |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 432 | if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) { |
| 433 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true; |
| 434 | } else { |
| 435 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false; |
| 436 | } |
| 437 | // for now we don't support floating point MSAA on ES |
jvanverth | fb5df43 | 2015-05-21 08:12:27 -0700 | [diff] [blame] | 438 | fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 439 | } |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 440 | } |
| 441 | |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 442 | if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) { |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 443 | if (kGL_GrGLStandard == standard) { |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 444 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 445 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true; |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 446 | } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
| 447 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true; |
| 448 | // for now we don't support floating point MSAA on ES |
| 449 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 450 | } else { |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 451 | if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) { |
| 452 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true; |
| 453 | } else { |
| 454 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false; |
| 455 | } |
| 456 | // for now we don't support floating point MSAA on ES |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 457 | fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false; |
| 458 | } |
| 459 | } |
| 460 | |
jvanverth | fb5df43 | 2015-05-21 08:12:27 -0700 | [diff] [blame] | 461 | if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) { |
| 462 | if (kGL_GrGLStandard == standard) { |
| 463 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true; |
| 464 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true; |
| 465 | } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) { |
| 466 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true; |
| 467 | // for now we don't support floating point MSAA on ES |
| 468 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false; |
| 469 | } else { |
| 470 | if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) { |
| 471 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true; |
| 472 | } else { |
| 473 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false; |
| 474 | } |
| 475 | // for now we don't support floating point MSAA on ES |
| 476 | fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false; |
| 477 | } |
| 478 | } |
| 479 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 480 | // If we don't support MSAA then undo any places above where we set a config as renderable with |
| 481 | // msaa. |
| 482 | if (kNone_MSFBOType == fMSFBOType) { |
| 483 | for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 484 | fConfigRenderSupport[i][kYes_MSAA] = false; |
| 485 | } |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 486 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 487 | } |
| 488 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 489 | void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 490 | GrGLStandard standard = ctxInfo.standard(); |
| 491 | GrGLVersion version = ctxInfo.version(); |
| 492 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 493 | // Base texture support |
| 494 | fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true; |
| 495 | fConfigTextureSupport[kRGB_565_GrPixelConfig] = true; |
| 496 | fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true; |
| 497 | fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true; |
| 498 | |
| 499 | // Check for 8-bit palette.. |
| 500 | GrGLint numFormats; |
| 501 | GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); |
| 502 | if (numFormats) { |
| 503 | SkAutoSTMalloc<10, GrGLint> formats(numFormats); |
| 504 | GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); |
| 505 | for (int i = 0; i < numFormats; ++i) { |
| 506 | if (GR_GL_PALETTE8_RGBA8 == formats[i]) { |
| 507 | fConfigTextureSupport[kIndex_8_GrPixelConfig] = true; |
| 508 | break; |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | // Check for BGRA |
| 514 | if (kGL_GrGLStandard == standard) { |
| 515 | fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = |
| 516 | version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra"); |
| 517 | } else { |
| 518 | if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { |
| 519 | fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true; |
| 520 | } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { |
| 521 | fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true; |
| 522 | fBGRAIsInternalFormat = true; |
| 523 | } |
| 524 | SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] || |
| 525 | kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); |
| 526 | } |
| 527 | |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 528 | // Check for sRGBA |
| 529 | if (kGL_GrGLStandard == standard) { |
| 530 | fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = |
| 531 | (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB")); |
| 532 | } else { |
| 533 | fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = |
| 534 | (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB")); |
| 535 | } |
| 536 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 537 | // Compressed texture support |
| 538 | |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 539 | // glCompressedTexImage2D is available on all OpenGL ES devices... |
| 540 | // however, it is only available on standard OpenGL after version 1.3 |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 541 | bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3)); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 542 | |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 543 | fCompressedTexSubImageSupport = |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 544 | hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D); |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 545 | |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 546 | // Check for ETC1 |
| 547 | bool hasETC1 = false; |
| 548 | |
| 549 | // First check version for support |
| 550 | if (kGL_GrGLStandard == standard) { |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 551 | hasETC1 = hasCompressTex2D && |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 552 | (version >= GR_GL_VER(4, 3) || |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 553 | ctxInfo.hasExtension("GL_ARB_ES3_compatibility")); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 554 | } else { |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 555 | hasETC1 = hasCompressTex2D && |
| 556 | (version >= GR_GL_VER(3, 0) || |
| 557 | ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") || |
| 558 | // ETC2 is a superset of ETC1, so we can just check for that, too. |
| 559 | (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") && |
| 560 | ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 561 | } |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 562 | fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 563 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 564 | // Check for LATC under its various forms |
| 565 | LATCAlias alias = kLATC_LATCAlias; |
| 566 | bool hasLATC = hasCompressTex2D && |
| 567 | (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") || |
| 568 | ctxInfo.hasExtension("GL_NV_texture_compression_latc")); |
| 569 | |
| 570 | // Check for RGTC |
| 571 | if (!hasLATC) { |
| 572 | // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format. |
| 573 | if (kGL_GrGLStandard == standard) { |
| 574 | hasLATC = version >= GR_GL_VER(3, 0); |
| 575 | } |
| 576 | |
| 577 | if (!hasLATC) { |
| 578 | hasLATC = |
| 579 | ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") || |
| 580 | ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc"); |
| 581 | } |
| 582 | |
| 583 | if (hasLATC) { |
| 584 | alias = kRGTC_LATCAlias; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | // Check for 3DC |
| 589 | if (!hasLATC) { |
| 590 | hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture"); |
| 591 | if (hasLATC) { |
| 592 | alias = k3DC_LATCAlias; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC; |
| 597 | fLATCAlias = alias; |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 598 | |
krajcevski | b3abe90 | 2014-07-30 13:08:11 -0700 | [diff] [blame] | 599 | // Check for R11_EAC ... We don't support R11_EAC on desktop, as most |
| 600 | // cards default to decompressing the textures in the driver, and is |
| 601 | // generally slower. |
| 602 | if (kGL_GrGLStandard != standard) { |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 603 | fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0); |
| 604 | } |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 605 | |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 606 | // Check for ASTC |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 607 | fConfigTextureSupport[kASTC_12x12_GrPixelConfig] = |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 608 | ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") || |
| 609 | ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") || |
| 610 | ctxInfo.hasExtension("GL_OES_texture_compression_astc"); |
| 611 | |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 612 | // Check for floating point texture support |
| 613 | // NOTE: We disallow floating point textures on ES devices if linear |
| 614 | // filtering modes are not supported. This is for simplicity, but a more |
| 615 | // granular approach is possible. Coincidentally, floating point textures became part of |
| 616 | // the standard in ES3.1 / OGL 3.1, hence the shorthand |
| 617 | bool hasFPTextures = version >= GR_GL_VER(3, 1); |
| 618 | if (!hasFPTextures) { |
| 619 | hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") || |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 620 | (ctxInfo.hasExtension("GL_OES_texture_float_linear") && |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 621 | ctxInfo.hasExtension("GL_OES_texture_float")); |
| 622 | } |
| 623 | fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 624 | |
| 625 | // Check for fp16 texture support |
| 626 | // NOTE: We disallow floating point textures on ES devices if linear |
| 627 | // filtering modes are not supported. This is for simplicity, but a more |
| 628 | // granular approach is possible. Coincidentally, 16-bit floating point textures became part of |
| 629 | // the standard in ES3.1 / OGL 3.1, hence the shorthand |
| 630 | bool hasHalfFPTextures = version >= GR_GL_VER(3, 1); |
| 631 | if (!hasHalfFPTextures) { |
| 632 | hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") || |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 633 | (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") && |
| 634 | ctxInfo.hasExtension("GL_OES_texture_half_float")); |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 635 | } |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 636 | fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures; |
jvanverth | fb5df43 | 2015-05-21 08:12:27 -0700 | [diff] [blame] | 637 | fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 638 | } |
| 639 | |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 640 | bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf, |
| 641 | GrGLenum format, |
| 642 | GrGLenum type) const { |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 643 | if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { |
| 644 | // ES 2 guarantees this format is supported |
robertphillips@google.com | eca2dfb | 2012-06-27 20:13:49 +0000 | [diff] [blame] | 645 | return true; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | if (!fTwoFormatLimit) { |
| 649 | // not limited by ES 2's constraints |
| 650 | return true; |
| 651 | } |
| 652 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 653 | GrGLint otherFormat = GR_GL_RGBA; |
| 654 | GrGLint otherType = GR_GL_UNSIGNED_BYTE; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 655 | |
| 656 | // The other supported format/type combo supported for ReadPixels |
| 657 | // can change based on which render target is bound |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 658 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 659 | GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, |
| 660 | &otherFormat); |
| 661 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 662 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 663 | GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, |
| 664 | &otherType); |
| 665 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 666 | return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 667 | } |
| 668 | |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 669 | bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, |
| 670 | GrGLenum format, |
| 671 | GrGLenum type, |
| 672 | GrGLenum currFboFormat) const { |
mtklein | 2aa1f7e | 2015-02-20 12:35:32 -0800 | [diff] [blame] | 673 | ReadPixelsSupportedFormat key = {format, type, currFboFormat}; |
| 674 | if (const bool* supported = fReadPixelsSupportedCache.find(key)) { |
| 675 | return *supported; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 676 | } |
mtklein | 2aa1f7e | 2015-02-20 12:35:32 -0800 | [diff] [blame] | 677 | bool supported = this->doReadPixelsSupported(intf, format, type); |
| 678 | fReadPixelsSupportedCache.set(key, supported); |
| 679 | return supported; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 680 | } |
| 681 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 682 | void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 683 | |
| 684 | fMSFBOType = kNone_MSFBOType; |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 685 | if (kGL_GrGLStandard != ctxInfo.standard()) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 686 | // We prefer the EXT/IMG extension over ES3 MSAA because we've observed |
| 687 | // ES3 driver bugs on at least one device with a tiled GPU (N10). |
| 688 | if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { |
| 689 | fMSFBOType = kES_EXT_MsToTexture_MSFBOType; |
| 690 | } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { |
| 691 | fMSFBOType = kES_IMG_MsToTexture_MSFBOType; |
commit-bot@chromium.org | 92b7884 | 2014-01-16 20:49:46 +0000 | [diff] [blame] | 692 | } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 693 | fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; |
| 694 | } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| 695 | // chrome's extension is equivalent to the EXT msaa |
| 696 | // and fbo_blit extensions. |
| 697 | fMSFBOType = kDesktop_EXT_MSFBOType; |
| 698 | } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
| 699 | fMSFBOType = kES_Apple_MSFBOType; |
| 700 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 701 | } else { |
| 702 | if ((ctxInfo.version() >= GR_GL_VER(3,0)) || |
| 703 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 704 | fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 705 | } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
| 706 | ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 707 | fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 708 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
| 712 | namespace { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 713 | const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { |
| 717 | |
| 718 | // Build up list of legal stencil formats (though perhaps not supported on |
| 719 | // the particular gpu/driver) from most preferred to least. |
| 720 | |
| 721 | // these consts are in order of most preferred to least preferred |
| 722 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
| 723 | |
| 724 | static const StencilFormat |
| 725 | // internal Format stencil bits total bits packed? |
| 726 | gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
| 727 | gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
| 728 | gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
| 729 | gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 730 | // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 731 | gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
| 732 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 733 | if (kGL_GrGLStandard == ctxInfo.standard()) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 734 | bool supportsPackedDS = |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 735 | ctxInfo.version() >= GR_GL_VER(3,0) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 736 | ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || |
| 737 | ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
| 738 | |
| 739 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 740 | // require FBO support we can expect these are legal formats and don't |
| 741 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 742 | fStencilFormats.push_back() = gS8; |
| 743 | fStencilFormats.push_back() = gS16; |
| 744 | if (supportsPackedDS) { |
| 745 | fStencilFormats.push_back() = gD24S8; |
| 746 | } |
| 747 | fStencilFormats.push_back() = gS4; |
| 748 | if (supportsPackedDS) { |
| 749 | fStencilFormats.push_back() = gDS; |
| 750 | } |
| 751 | } else { |
| 752 | // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
| 753 | // for other formats. |
| 754 | // ES doesn't support using the unsized format. |
| 755 | |
| 756 | fStencilFormats.push_back() = gS8; |
| 757 | //fStencilFormats.push_back() = gS16; |
commit-bot@chromium.org | 04c500f | 2013-09-06 15:28:01 +0000 | [diff] [blame] | 758 | if (ctxInfo.version() >= GR_GL_VER(3,0) || |
| 759 | ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 760 | fStencilFormats.push_back() = gD24S8; |
| 761 | } |
| 762 | if (ctxInfo.hasExtension("GL_OES_stencil4")) { |
| 763 | fStencilFormats.push_back() = gS4; |
| 764 | } |
| 765 | } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 766 | SkASSERT(0 == fStencilVerifiedColorConfigs.count()); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 767 | fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); |
| 768 | } |
| 769 | |
| 770 | void GrGLCaps::markColorConfigAndStencilFormatAsVerified( |
| 771 | GrPixelConfig config, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 772 | const GrGLStencilAttachment::Format& format) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 773 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 774 | return; |
| 775 | #endif |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 776 | SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); |
| 777 | SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 778 | int count = fStencilFormats.count(); |
| 779 | // we expect a really small number of possible formats so linear search |
| 780 | // should be OK |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 781 | SkASSERT(count < 16); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 782 | for (int i = 0; i < count; ++i) { |
| 783 | if (format.fInternalFormat == |
| 784 | fStencilFormats[i].fInternalFormat) { |
| 785 | fStencilVerifiedColorConfigs[i].markVerified(config); |
| 786 | return; |
| 787 | } |
| 788 | } |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 789 | SkFAIL("Why are we seeing a stencil format that " |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 790 | "GrGLCaps doesn't know about."); |
| 791 | } |
| 792 | |
| 793 | bool GrGLCaps::isColorConfigAndStencilFormatVerified( |
| 794 | GrPixelConfig config, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 795 | const GrGLStencilAttachment::Format& format) const { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 796 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 797 | return false; |
| 798 | #endif |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 799 | SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 800 | int count = fStencilFormats.count(); |
| 801 | // we expect a really small number of possible formats so linear search |
| 802 | // should be OK |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 803 | SkASSERT(count < 16); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 804 | for (int i = 0; i < count; ++i) { |
| 805 | if (format.fInternalFormat == |
| 806 | fStencilFormats[i].fInternalFormat) { |
| 807 | return fStencilVerifiedColorConfigs[i].isVerified(config); |
| 808 | } |
| 809 | } |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 810 | SkFAIL("Why are we seeing a stencil format that " |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 811 | "GLCaps doesn't know about."); |
| 812 | return false; |
| 813 | } |
| 814 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 815 | SkString GrGLCaps::dump() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 816 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 817 | SkString r = INHERITED::dump(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 818 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 819 | r.appendf("--- GL-Specific ---\n"); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 820 | for (int i = 0; i < fStencilFormats.count(); ++i) { |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 821 | 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] | 822 | i, |
| 823 | fStencilFormats[i].fStencilBits, |
| 824 | fStencilFormats[i].fTotalBits); |
| 825 | } |
| 826 | |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 827 | static const char* kMSFBOExtStr[] = { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 828 | "None", |
| 829 | "ARB", |
| 830 | "EXT", |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 831 | "ES 3.0", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 832 | "Apple", |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 833 | "IMG MS To Texture", |
| 834 | "EXT MS To Texture", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 835 | }; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 836 | GR_STATIC_ASSERT(0 == kNone_MSFBOType); |
| 837 | GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); |
| 838 | GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 839 | GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType); |
| 840 | GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType); |
| 841 | GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType); |
| 842 | GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 843 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 844 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 845 | static const char* kInvalidateFBTypeStr[] = { |
| 846 | "None", |
| 847 | "Discard", |
| 848 | "Invalidate", |
| 849 | }; |
| 850 | GR_STATIC_ASSERT(0 == kNone_InvalidateFBType); |
| 851 | GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType); |
| 852 | GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType); |
| 853 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 854 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 855 | static const char* kMapBufferTypeStr[] = { |
| 856 | "None", |
| 857 | "MapBuffer", |
| 858 | "MapBufferRange", |
| 859 | "Chromium", |
| 860 | }; |
| 861 | GR_STATIC_ASSERT(0 == kNone_MapBufferType); |
| 862 | GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType); |
| 863 | GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType); |
| 864 | GR_STATIC_ASSERT(3 == kChromium_MapBufferType); |
| 865 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1); |
| 866 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 867 | r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 868 | r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 869 | r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 870 | r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 871 | r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); |
| 872 | r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 873 | r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); |
| 874 | r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 875 | r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); |
| 876 | r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); |
| 877 | r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); |
| 878 | r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); |
| 879 | r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); |
| 880 | r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 881 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 882 | r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); |
| 883 | r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); |
| 884 | r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); |
| 885 | r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); |
| 886 | r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); |
| 887 | r.appendf("Fragment coord conventions support: %s\n", |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 888 | (fFragCoordsConventionSupport ? "YES": "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 889 | r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 890 | r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 891 | r.appendf("Use non-VBO for dynamic data: %s\n", |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 892 | (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 893 | r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO")); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 894 | return r; |
| 895 | } |
| 896 | |
| 897 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 898 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame^] | 899 | GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options, |
| 900 | const GrGLContextInfo& ctxInfo, |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 901 | const GrGLInterface* gli, |
| 902 | const GrGLCaps& glCaps) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 903 | fDropsTileOnZeroDivide = false; |
| 904 | fFBFetchSupport = false; |
| 905 | fFBFetchNeedsCustomOutput = false; |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 906 | fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 907 | fFBFetchColorName = NULL; |
| 908 | fFBFetchExtensionString = NULL; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 909 | this->init(ctxInfo, gli, glCaps); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame^] | 910 | this->applyOptionsOverrides(options); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 911 | } |
| 912 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 913 | void GrGLSLCaps::init(const GrGLContextInfo& ctxInfo, |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 914 | const GrGLInterface* gli, |
| 915 | const GrGLCaps& glCaps) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 916 | GrGLStandard standard = ctxInfo.standard(); |
| 917 | GrGLVersion version = ctxInfo.version(); |
| 918 | |
| 919 | /************************************************************************** |
| 920 | * Caps specific to GrGLSLCaps |
| 921 | **************************************************************************/ |
| 922 | |
| 923 | if (kGLES_GrGLStandard == standard) { |
| 924 | if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { |
| 925 | fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0)); |
| 926 | fFBFetchSupport = true; |
| 927 | fFBFetchColorName = "gl_LastFragData[0]"; |
| 928 | fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch"; |
| 929 | } |
| 930 | else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { |
| 931 | // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know |
| 932 | fFBFetchNeedsCustomOutput = false; |
| 933 | fFBFetchSupport = true; |
| 934 | fFBFetchColorName = "gl_LastFragData[0]"; |
| 935 | fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch"; |
| 936 | } |
| 937 | else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) { |
| 938 | // The arm extension also requires an additional flag which we will set onResetContext |
| 939 | fFBFetchNeedsCustomOutput = false; |
| 940 | fFBFetchSupport = true; |
| 941 | fFBFetchColorName = "gl_LastFragColorARM"; |
| 942 | fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch"; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader |
| 947 | fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor(); |
| 948 | |
| 949 | /************************************************************************** |
| 950 | * GrShaderCaps fields |
| 951 | **************************************************************************/ |
| 952 | |
| 953 | fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering"); |
| 954 | |
| 955 | if (fPathRenderingSupport) { |
| 956 | if (kGL_GrGLStandard == standard) { |
| 957 | // We only support v1.3+ of GL_NV_path_rendering which allows us to |
| 958 | // set individual fragment inputs with ProgramPathFragmentInputGen. The API |
| 959 | // additions are detected by checking the existence of the function. |
| 960 | fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") && |
| 961 | ((ctxInfo.version() >= GR_GL_VER(4, 3) || |
| 962 | ctxInfo.hasExtension("GL_ARB_program_interface_query")) && |
| 963 | gli->fFunctions.fProgramPathFragmentInputGen); |
| 964 | } |
| 965 | else { |
| 966 | fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3, 1); |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | // For now these two are equivalent but we could have dst read in shader via some other method |
| 971 | fDstReadInShaderSupport = fFBFetchSupport; |
| 972 | |
| 973 | // Enable supported shader-related caps |
| 974 | if (kGL_GrGLStandard == standard) { |
| 975 | fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3, 3) || |
| 976 | ctxInfo.hasExtension("GL_ARB_blend_func_extended"); |
| 977 | fShaderDerivativeSupport = true; |
| 978 | // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS |
| 979 | fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) && |
| 980 | ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; |
| 981 | } |
| 982 | else { |
| 983 | fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) || |
| 984 | ctxInfo.hasExtension("GL_OES_standard_derivatives"); |
| 985 | } |
| 986 | |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame] | 987 | // We need dual source blending and the ability to disable multisample in order to support mixed |
| 988 | // samples in every corner case. |
| 989 | if (fDualSourceBlendingSupport && glCaps.multisampleDisableSupport()) { |
| 990 | // We understand "mixed samples" to mean the collective capability of 3 different extensions |
| 991 | fMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") && |
| 992 | ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") && |
| 993 | ctxInfo.hasExtension("GL_EXT_raster_multisample"); |
| 994 | } |
| 995 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 996 | if (glCaps.advancedBlendEquationSupport()) { |
| 997 | bool coherent = glCaps.advancedCoherentBlendEquationSupport(); |
| 998 | if (ctxInfo.hasExtension(coherent ? "GL_NV_blend_equation_advanced_coherent" |
| 999 | : "GL_NV_blend_equation_advanced")) { |
| 1000 | fAdvBlendEqInteraction = kAutomatic_AdvBlendEqInteraction; |
| 1001 | } else { |
| 1002 | fAdvBlendEqInteraction = kGeneralEnable_AdvBlendEqInteraction; |
| 1003 | // TODO: Use the following on any platform where "blend_support_all_equations" is slow. |
| 1004 | //fAdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction; |
| 1005 | } |
| 1006 | } |
| 1007 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1008 | this->initShaderPrecisionTable(ctxInfo, gli); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | SkString GrGLSLCaps::dump() const { |
| 1012 | SkString r = INHERITED::dump(); |
| 1013 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 1014 | static const char* kAdvBlendEqInteractionStr[] = { |
| 1015 | "Not Supported", |
| 1016 | "Automatic", |
| 1017 | "General Enable", |
| 1018 | "Specific Enables", |
| 1019 | }; |
| 1020 | GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction); |
| 1021 | GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction); |
| 1022 | GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction); |
| 1023 | GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction); |
| 1024 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1); |
| 1025 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1026 | r.appendf("--- GLSL-Specific ---\n"); |
| 1027 | |
| 1028 | r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO")); |
commit-bot@chromium.org | 4362a38 | 2014-03-26 19:49:03 +0000 | [diff] [blame] | 1029 | r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO")); |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 1030 | r.appendf("Advanced blend equation interaction: %s\n", |
| 1031 | kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1032 | return r; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1033 | } |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1034 | |
| 1035 | static GrGLenum precision_to_gl_float_type(GrSLPrecision p) { |
| 1036 | switch (p) { |
| 1037 | case kLow_GrSLPrecision: |
| 1038 | return GR_GL_LOW_FLOAT; |
| 1039 | case kMedium_GrSLPrecision: |
| 1040 | return GR_GL_MEDIUM_FLOAT; |
| 1041 | case kHigh_GrSLPrecision: |
| 1042 | return GR_GL_HIGH_FLOAT; |
| 1043 | } |
| 1044 | SkFAIL("Unknown precision."); |
| 1045 | return -1; |
| 1046 | } |
| 1047 | |
| 1048 | static GrGLenum shader_type_to_gl_shader(GrShaderType type) { |
| 1049 | switch (type) { |
| 1050 | case kVertex_GrShaderType: |
| 1051 | return GR_GL_VERTEX_SHADER; |
| 1052 | case kGeometry_GrShaderType: |
| 1053 | return GR_GL_GEOMETRY_SHADER; |
| 1054 | case kFragment_GrShaderType: |
| 1055 | return GR_GL_FRAGMENT_SHADER; |
| 1056 | } |
| 1057 | SkFAIL("Unknown shader type."); |
| 1058 | return -1; |
| 1059 | } |
| 1060 | |
| 1061 | void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, |
| 1062 | const GrGLInterface* intf) { |
| 1063 | if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) || |
| 1064 | ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) { |
| 1065 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 1066 | if (kGeometry_GrShaderType != s) { |
| 1067 | GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 1068 | GrGLenum glShader = shader_type_to_gl_shader(shaderType); |
| 1069 | PrecisionInfo* first = NULL; |
| 1070 | fShaderPrecisionVaries = false; |
| 1071 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 1072 | GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
| 1073 | GrGLenum glPrecision = precision_to_gl_float_type(precision); |
| 1074 | GrGLint range[2]; |
| 1075 | GrGLint bits; |
| 1076 | GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits); |
| 1077 | if (bits) { |
| 1078 | fFloatPrecisions[s][p].fLogRangeLow = range[0]; |
| 1079 | fFloatPrecisions[s][p].fLogRangeHigh = range[1]; |
| 1080 | fFloatPrecisions[s][p].fBits = bits; |
| 1081 | if (!first) { |
| 1082 | first = &fFloatPrecisions[s][p]; |
| 1083 | } |
| 1084 | else if (!fShaderPrecisionVaries) { |
| 1085 | fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | else { |
| 1093 | // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float. |
| 1094 | fShaderPrecisionVaries = false; |
| 1095 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 1096 | if (kGeometry_GrShaderType != s) { |
| 1097 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 1098 | fFloatPrecisions[s][p].fLogRangeLow = 127; |
| 1099 | fFloatPrecisions[s][p].fLogRangeHigh = 127; |
| 1100 | fFloatPrecisions[s][p].fBits = 23; |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're |
| 1106 | // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for |
| 1107 | // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that |
| 1108 | // are recommended against. |
| 1109 | if (fGeometryShaderSupport) { |
| 1110 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 1111 | fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p]; |
| 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |