bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | #include "GrGLCaps.h" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 10 | #include "GrGLContext.h" |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 11 | #include "SkTSearch.h" |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 12 | |
| 13 | GrGLCaps::GrGLCaps() { |
| 14 | this->reset(); |
| 15 | } |
| 16 | |
| 17 | void GrGLCaps::reset() { |
| 18 | fVerifiedColorConfigs.reset(); |
| 19 | fStencilFormats.reset(); |
| 20 | fStencilVerifiedColorConfigs.reset(); |
| 21 | fMSFBOType = kNone_MSFBOType; |
bsalomon@google.com | f6b070d | 2012-04-27 14:25:44 +0000 | [diff] [blame] | 22 | fMaxSampleCount = 0; |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 23 | fCoverageAAType = kNone_CoverageAAType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 24 | fMaxFragmentUniformVectors = 0; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 25 | fMaxVertexAttributes = 0; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 26 | fRGBA8RenderbufferSupport = false; |
| 27 | fBGRAFormatSupport = false; |
| 28 | fBGRAIsInternalFormat = false; |
| 29 | fTextureSwizzleSupport = false; |
| 30 | fUnpackRowLengthSupport = false; |
| 31 | fUnpackFlipYSupport = false; |
| 32 | fPackRowLengthSupport = false; |
| 33 | fPackFlipYSupport = false; |
| 34 | fTextureUsageSupport = false; |
| 35 | fTexStorageSupport = false; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 36 | fTextureRedSupport = false; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 37 | fImagingSupport = false; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 38 | fTwoFormatLimit = false; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 39 | fFragCoordsConventionSupport = false; |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 40 | fUseNonVBOVertexAndIndexDynamicData = false; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame^] | 41 | fIsCoreProfile = false; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | GrGLCaps::GrGLCaps(const GrGLCaps& caps) { |
| 45 | *this = caps; |
| 46 | } |
| 47 | |
| 48 | GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { |
| 49 | fVerifiedColorConfigs = caps.fVerifiedColorConfigs; |
| 50 | fStencilFormats = caps.fStencilFormats; |
| 51 | fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; |
| 52 | fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 53 | fMaxVertexAttributes = caps.fMaxVertexAttributes; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 54 | fMSFBOType = caps.fMSFBOType; |
bsalomon@google.com | f6b070d | 2012-04-27 14:25:44 +0000 | [diff] [blame] | 55 | fMaxSampleCount = caps.fMaxSampleCount; |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 56 | fCoverageAAType = caps.fCoverageAAType; |
| 57 | fMSAACoverageModes = caps.fMSAACoverageModes; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 58 | fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; |
| 59 | fBGRAFormatSupport = caps.fBGRAFormatSupport; |
| 60 | fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; |
| 61 | fTextureSwizzleSupport = caps.fTextureSwizzleSupport; |
| 62 | fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; |
| 63 | fUnpackFlipYSupport = caps.fUnpackFlipYSupport; |
| 64 | fPackRowLengthSupport = caps.fPackRowLengthSupport; |
| 65 | fPackFlipYSupport = caps.fPackFlipYSupport; |
| 66 | fTextureUsageSupport = caps.fTextureUsageSupport; |
| 67 | fTexStorageSupport = caps.fTexStorageSupport; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 68 | fTextureRedSupport = caps.fTextureRedSupport; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 69 | fImagingSupport = caps.fImagingSupport; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 70 | fTwoFormatLimit = caps.fTwoFormatLimit; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 71 | fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 72 | fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame^] | 73 | fIsCoreProfile = caps.fIsCoreProfile; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 74 | |
| 75 | return *this; |
| 76 | } |
| 77 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 78 | void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 79 | |
| 80 | this->reset(); |
| 81 | if (!ctxInfo.isInitialized()) { |
| 82 | return; |
| 83 | } |
| 84 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 85 | GrGLBinding binding = ctxInfo.binding(); |
| 86 | GrGLVersion version = ctxInfo.version(); |
| 87 | |
| 88 | if (kES2_GrGLBinding == binding) { |
| 89 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 90 | &fMaxFragmentUniformVectors); |
| 91 | } else { |
| 92 | GrAssert(kDesktop_GrGLBinding == binding); |
| 93 | GrGLint max; |
| 94 | GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
| 95 | fMaxFragmentUniformVectors = max / 4; |
| 96 | } |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 97 | GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 98 | |
| 99 | if (kDesktop_GrGLBinding == binding) { |
| 100 | fRGBA8RenderbufferSupport = true; |
| 101 | } else { |
| 102 | fRGBA8RenderbufferSupport = ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || |
| 103 | ctxInfo.hasExtension("GL_ARM_rgba8"); |
| 104 | } |
| 105 | |
| 106 | if (kDesktop_GrGLBinding == binding) { |
| 107 | fBGRAFormatSupport = version >= GR_GL_VER(1,2) || |
| 108 | ctxInfo.hasExtension("GL_EXT_bgra"); |
| 109 | } else { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 110 | if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { |
| 111 | fBGRAFormatSupport = true; |
| 112 | } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { |
| 113 | fBGRAFormatSupport = true; |
| 114 | fBGRAIsInternalFormat = true; |
| 115 | } |
| 116 | GrAssert(fBGRAFormatSupport || |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 117 | kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | if (kDesktop_GrGLBinding == binding) { |
| 121 | fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || |
| 122 | ctxInfo.hasExtension("GL_ARB_texture_swizzle"); |
| 123 | } else { |
| 124 | fTextureSwizzleSupport = false; |
| 125 | } |
| 126 | |
| 127 | if (kDesktop_GrGLBinding == binding) { |
| 128 | fUnpackRowLengthSupport = true; |
| 129 | fUnpackFlipYSupport = false; |
| 130 | fPackRowLengthSupport = true; |
| 131 | fPackFlipYSupport = false; |
| 132 | } else { |
| 133 | fUnpackRowLengthSupport =ctxInfo.hasExtension("GL_EXT_unpack_subimage"); |
| 134 | fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); |
| 135 | // no extension for pack row length |
| 136 | fPackRowLengthSupport = false; |
| 137 | fPackFlipYSupport = |
| 138 | ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); |
| 139 | } |
| 140 | |
| 141 | fTextureUsageSupport = (kES2_GrGLBinding == binding) && |
| 142 | ctxInfo.hasExtension("GL_ANGLE_texture_usage"); |
| 143 | |
| 144 | // Tex storage is in desktop 4.2 and can be an extension to desktop or ES. |
| 145 | fTexStorageSupport = (kDesktop_GrGLBinding == binding && |
| 146 | version >= GR_GL_VER(4,2)) || |
| 147 | ctxInfo.hasExtension("GL_ARB_texture_storage") || |
| 148 | ctxInfo.hasExtension("GL_EXT_texture_storage"); |
| 149 | |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 150 | // ARB_texture_rg is part of OpenGL 3.0 |
| 151 | if (kDesktop_GrGLBinding == binding) { |
| 152 | fTextureRedSupport = version >= GR_GL_VER(3,0) || |
| 153 | ctxInfo.hasExtension("GL_ARB_texture_rg"); |
| 154 | } else { |
| 155 | fTextureRedSupport = ctxInfo.hasExtension("GL_EXT_texture_rg"); |
| 156 | } |
| 157 | |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 158 | fImagingSupport = kDesktop_GrGLBinding == binding && |
| 159 | ctxInfo.hasExtension("GL_ARB_imaging"); |
| 160 | |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 161 | // ES 2 only guarantees RGBA/uchar + one other format/type combo for |
| 162 | // ReadPixels. The other format has to checked at run-time since it |
| 163 | // can change based on which render target is bound |
| 164 | fTwoFormatLimit = kES2_GrGLBinding == binding; |
| 165 | |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 166 | // Known issue on at least some Intel platforms: |
| 167 | // http://code.google.com/p/skia/issues/detail?id=946 |
| 168 | if (kIntel_GrGLVendor != ctxInfo.vendor()) { |
| 169 | fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || |
| 170 | ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"); |
| 171 | } |
| 172 | |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 173 | // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with |
| 174 | // frequently changing VBOs. We've measured a performance increase using non-VBO vertex |
| 175 | // data for dynamic content on these GPUs. Perhaps we should read the renderer string and |
| 176 | // limit this decision to specific GPU families rather than basing it on the vendor alone. |
| 177 | if (!GR_GL_MUST_USE_VBO && |
| 178 | (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) { |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 179 | fUseNonVBOVertexAndIndexDynamicData = true; |
| 180 | } |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame^] | 181 | |
| 182 | if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) { |
| 183 | GrGLint profileMask; |
| 184 | GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); |
| 185 | fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); |
| 186 | } |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 187 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 188 | this->initFSAASupport(ctxInfo, gli); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 189 | this->initStencilFormats(ctxInfo); |
| 190 | } |
| 191 | |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 192 | bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 193 | GrGLenum format, |
| 194 | GrGLenum type) const { |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 195 | if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { |
| 196 | // ES 2 guarantees this format is supported |
robertphillips@google.com | eca2dfb | 2012-06-27 20:13:49 +0000 | [diff] [blame] | 197 | return true; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | if (!fTwoFormatLimit) { |
| 201 | // not limited by ES 2's constraints |
| 202 | return true; |
| 203 | } |
| 204 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 205 | GrGLint otherFormat = GR_GL_RGBA; |
| 206 | GrGLint otherType = GR_GL_UNSIGNED_BYTE; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 207 | |
| 208 | // The other supported format/type combo supported for ReadPixels |
| 209 | // can change based on which render target is bound |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 210 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 211 | GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, |
| 212 | &otherFormat); |
| 213 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 214 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 215 | GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, |
| 216 | &otherType); |
| 217 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 218 | return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 219 | } |
| 220 | |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 221 | namespace { |
| 222 | int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left, |
| 223 | const GrGLCaps::MSAACoverageMode* right) { |
| 224 | if (left->fCoverageSampleCnt < right->fCoverageSampleCnt) { |
| 225 | return -1; |
| 226 | } else if (right->fCoverageSampleCnt < left->fCoverageSampleCnt) { |
| 227 | return 1; |
| 228 | } else if (left->fColorSampleCnt < right->fColorSampleCnt) { |
| 229 | return -1; |
| 230 | } else if (right->fColorSampleCnt < left->fColorSampleCnt) { |
| 231 | return 1; |
| 232 | } |
| 233 | return 0; |
| 234 | } |
| 235 | } |
| 236 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 237 | void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 238 | |
| 239 | fMSFBOType = kNone_MSFBOType; |
| 240 | if (kDesktop_GrGLBinding != ctxInfo.binding()) { |
| 241 | if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| 242 | // chrome's extension is equivalent to the EXT msaa |
| 243 | // and fbo_blit extensions. |
| 244 | fMSFBOType = kDesktopEXT_MSFBOType; |
| 245 | } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 246 | fMSFBOType = kAppleES_MSFBOType; |
| 247 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 248 | } else { |
| 249 | if ((ctxInfo.version() >= GR_GL_VER(3,0)) || |
| 250 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
| 251 | fMSFBOType = GrGLCaps::kDesktopARB_MSFBOType; |
| 252 | } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
| 253 | ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
| 254 | fMSFBOType = GrGLCaps::kDesktopEXT_MSFBOType; |
| 255 | } |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 256 | // TODO: We could populate fMSAACoverageModes using GetInternalformativ |
| 257 | // on GL 4.2+. It's format-specific, though. See also |
| 258 | // http://code.google.com/p/skia/issues/detail?id=470 about using actual |
| 259 | // rather than requested sample counts in cache key. |
| 260 | if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) { |
| 261 | fCoverageAAType = kNVDesktop_CoverageAAType; |
| 262 | GrGLint count; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 263 | GR_GL_GetIntegerv(gli, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 264 | GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES, |
| 265 | &count); |
| 266 | fMSAACoverageModes.setCount(count); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 267 | GR_GL_GetIntegerv(gli, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 268 | GR_GL_MULTISAMPLE_COVERAGE_MODES, |
| 269 | (int*)&fMSAACoverageModes[0]); |
| 270 | // The NV driver seems to return the modes already sorted but the |
| 271 | // spec doesn't require this. So we sort. |
reed@google.com | c7a67cb | 2012-05-07 14:52:12 +0000 | [diff] [blame] | 272 | qsort(&fMSAACoverageModes[0], |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 273 | count, |
| 274 | sizeof(MSAACoverageMode), |
reed@google.com | c7a67cb | 2012-05-07 14:52:12 +0000 | [diff] [blame] | 275 | SkCastForQSort(coverage_mode_compare)); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 276 | } |
| 277 | } |
bsalomon@google.com | f6b070d | 2012-04-27 14:25:44 +0000 | [diff] [blame] | 278 | if (kNone_MSFBOType != fMSFBOType) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 279 | GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); |
bsalomon@google.com | f6b070d | 2012-04-27 14:25:44 +0000 | [diff] [blame] | 280 | } |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode( |
| 284 | int desiredSampleCount) const { |
| 285 | static const MSAACoverageMode kNoneMode = {0, 0}; |
| 286 | if (0 == fMSAACoverageModes.count()) { |
| 287 | return kNoneMode; |
| 288 | } else { |
| 289 | GrAssert(kNone_CoverageAAType != fCoverageAAType); |
| 290 | int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt; |
| 291 | desiredSampleCount = GrMin(desiredSampleCount, max); |
| 292 | MSAACoverageMode desiredMode = {desiredSampleCount, 0}; |
| 293 | int idx = SkTSearch<MSAACoverageMode>(&fMSAACoverageModes[0], |
| 294 | fMSAACoverageModes.count(), |
| 295 | desiredMode, |
| 296 | sizeof(MSAACoverageMode), |
| 297 | &coverage_mode_compare); |
| 298 | if (idx < 0) { |
| 299 | idx = ~idx; |
| 300 | } |
| 301 | GrAssert(idx >= 0 && idx < fMSAACoverageModes.count()); |
| 302 | return fMSAACoverageModes[idx]; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | namespace { |
| 307 | const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
| 308 | } |
| 309 | |
| 310 | void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { |
| 311 | |
| 312 | // Build up list of legal stencil formats (though perhaps not supported on |
| 313 | // the particular gpu/driver) from most preferred to least. |
| 314 | |
| 315 | // these consts are in order of most preferred to least preferred |
| 316 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
| 317 | |
| 318 | static const StencilFormat |
| 319 | // internal Format stencil bits total bits packed? |
| 320 | gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
| 321 | gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
| 322 | gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
| 323 | gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 324 | // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 325 | gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
| 326 | |
| 327 | if (kDesktop_GrGLBinding == ctxInfo.binding()) { |
| 328 | bool supportsPackedDS = |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 329 | ctxInfo.version() >= GR_GL_VER(3,0) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 330 | ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || |
| 331 | ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
| 332 | |
| 333 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 334 | // require FBO support we can expect these are legal formats and don't |
| 335 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 336 | fStencilFormats.push_back() = gS8; |
| 337 | fStencilFormats.push_back() = gS16; |
| 338 | if (supportsPackedDS) { |
| 339 | fStencilFormats.push_back() = gD24S8; |
| 340 | } |
| 341 | fStencilFormats.push_back() = gS4; |
| 342 | if (supportsPackedDS) { |
| 343 | fStencilFormats.push_back() = gDS; |
| 344 | } |
| 345 | } else { |
| 346 | // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
| 347 | // for other formats. |
| 348 | // ES doesn't support using the unsized format. |
| 349 | |
| 350 | fStencilFormats.push_back() = gS8; |
| 351 | //fStencilFormats.push_back() = gS16; |
| 352 | if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { |
| 353 | fStencilFormats.push_back() = gD24S8; |
| 354 | } |
| 355 | if (ctxInfo.hasExtension("GL_OES_stencil4")) { |
| 356 | fStencilFormats.push_back() = gS4; |
| 357 | } |
| 358 | } |
| 359 | GrAssert(0 == fStencilVerifiedColorConfigs.count()); |
| 360 | fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); |
| 361 | } |
| 362 | |
| 363 | void GrGLCaps::markColorConfigAndStencilFormatAsVerified( |
| 364 | GrPixelConfig config, |
| 365 | const GrGLStencilBuffer::Format& format) { |
| 366 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 367 | return; |
| 368 | #endif |
| 369 | GrAssert((unsigned)config < kGrPixelConfigCount); |
| 370 | GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); |
| 371 | int count = fStencilFormats.count(); |
| 372 | // we expect a really small number of possible formats so linear search |
| 373 | // should be OK |
| 374 | GrAssert(count < 16); |
| 375 | for (int i = 0; i < count; ++i) { |
| 376 | if (format.fInternalFormat == |
| 377 | fStencilFormats[i].fInternalFormat) { |
| 378 | fStencilVerifiedColorConfigs[i].markVerified(config); |
| 379 | return; |
| 380 | } |
| 381 | } |
| 382 | GrCrash("Why are we seeing a stencil format that " |
| 383 | "GrGLCaps doesn't know about."); |
| 384 | } |
| 385 | |
| 386 | bool GrGLCaps::isColorConfigAndStencilFormatVerified( |
| 387 | GrPixelConfig config, |
| 388 | const GrGLStencilBuffer::Format& format) const { |
| 389 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 390 | return false; |
| 391 | #endif |
| 392 | GrAssert((unsigned)config < kGrPixelConfigCount); |
| 393 | int count = fStencilFormats.count(); |
| 394 | // we expect a really small number of possible formats so linear search |
| 395 | // should be OK |
| 396 | GrAssert(count < 16); |
| 397 | for (int i = 0; i < count; ++i) { |
| 398 | if (format.fInternalFormat == |
| 399 | fStencilFormats[i].fInternalFormat) { |
| 400 | return fStencilVerifiedColorConfigs[i].isVerified(config); |
| 401 | } |
| 402 | } |
| 403 | GrCrash("Why are we seeing a stencil format that " |
| 404 | "GLCaps doesn't know about."); |
| 405 | return false; |
| 406 | } |
| 407 | |
| 408 | void GrGLCaps::print() const { |
| 409 | for (int i = 0; i < fStencilFormats.count(); ++i) { |
| 410 | GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", |
| 411 | i, |
| 412 | fStencilFormats[i].fStencilBits, |
| 413 | fStencilFormats[i].fTotalBits); |
| 414 | } |
| 415 | |
| 416 | GR_STATIC_ASSERT(0 == kNone_MSFBOType); |
| 417 | GR_STATIC_ASSERT(1 == kDesktopARB_MSFBOType); |
| 418 | GR_STATIC_ASSERT(2 == kDesktopEXT_MSFBOType); |
| 419 | GR_STATIC_ASSERT(3 == kAppleES_MSFBOType); |
| 420 | static const char* gMSFBOExtStr[] = { |
| 421 | "None", |
| 422 | "ARB", |
| 423 | "EXT", |
| 424 | "Apple", |
| 425 | }; |
| 426 | GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]); |
| 427 | GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); |
| 428 | GrPrintf("Support RGBA8 Render Buffer: %s\n", |
| 429 | (fRGBA8RenderbufferSupport ? "YES": "NO")); |
| 430 | GrPrintf("BGRA is an internal format: %s\n", |
| 431 | (fBGRAIsInternalFormat ? "YES": "NO")); |
| 432 | GrPrintf("Support texture swizzle: %s\n", |
| 433 | (fTextureSwizzleSupport ? "YES": "NO")); |
| 434 | GrPrintf("Unpack Row length support: %s\n", |
| 435 | (fUnpackRowLengthSupport ? "YES": "NO")); |
| 436 | GrPrintf("Unpack Flip Y support: %s\n", |
| 437 | (fUnpackFlipYSupport ? "YES": "NO")); |
| 438 | GrPrintf("Pack Row length support: %s\n", |
| 439 | (fPackRowLengthSupport ? "YES": "NO")); |
| 440 | GrPrintf("Pack Flip Y support: %s\n", |
| 441 | (fPackFlipYSupport ? "YES": "NO")); |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 442 | GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 443 | GrPrintf("Fragment coord conventions support: %s\n", (fFragCoordsConventionSupport ? "YES": "NO")); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 444 | } |