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 | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 22 | fCoverageAAType = kNone_CoverageAAType; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 23 | fMaxFragmentUniformVectors = 0; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 24 | fMaxVertexAttributes = 0; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 25 | fRGBA8RenderbufferSupport = false; |
| 26 | fBGRAFormatSupport = false; |
| 27 | fBGRAIsInternalFormat = false; |
| 28 | fTextureSwizzleSupport = false; |
| 29 | fUnpackRowLengthSupport = false; |
| 30 | fUnpackFlipYSupport = false; |
| 31 | fPackRowLengthSupport = false; |
| 32 | fPackFlipYSupport = false; |
| 33 | fTextureUsageSupport = false; |
| 34 | fTexStorageSupport = false; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 35 | fTextureRedSupport = false; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 36 | fImagingSupport = false; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 37 | fTwoFormatLimit = false; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 38 | fFragCoordsConventionSupport = false; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 39 | fVertexArrayObjectSupport = 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 | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 55 | fCoverageAAType = caps.fCoverageAAType; |
| 56 | fMSAACoverageModes = caps.fMSAACoverageModes; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 57 | fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; |
| 58 | fBGRAFormatSupport = caps.fBGRAFormatSupport; |
| 59 | fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; |
| 60 | fTextureSwizzleSupport = caps.fTextureSwizzleSupport; |
| 61 | fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; |
| 62 | fUnpackFlipYSupport = caps.fUnpackFlipYSupport; |
| 63 | fPackRowLengthSupport = caps.fPackRowLengthSupport; |
| 64 | fPackFlipYSupport = caps.fPackFlipYSupport; |
| 65 | fTextureUsageSupport = caps.fTextureUsageSupport; |
| 66 | fTexStorageSupport = caps.fTexStorageSupport; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 67 | fTextureRedSupport = caps.fTextureRedSupport; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 68 | fImagingSupport = caps.fImagingSupport; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 69 | fTwoFormatLimit = caps.fTwoFormatLimit; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 70 | fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 71 | fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport; |
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 | } |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 181 | |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 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 | |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 188 | if (kDesktop_GrGLBinding == binding) { |
| 189 | fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
| 190 | ctxInfo.hasExtension("GL_ARB_vertex_array_object"); |
| 191 | } else { |
| 192 | fVertexArrayObjectSupport = ctxInfo.hasExtension("GL_OES_vertex_array_object"); |
| 193 | } |
| 194 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 195 | this->initFSAASupport(ctxInfo, gli); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 196 | this->initStencilFormats(ctxInfo); |
| 197 | } |
| 198 | |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 199 | bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 200 | GrGLenum format, |
| 201 | GrGLenum type) const { |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 202 | if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { |
| 203 | // ES 2 guarantees this format is supported |
robertphillips@google.com | eca2dfb | 2012-06-27 20:13:49 +0000 | [diff] [blame] | 204 | return true; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | if (!fTwoFormatLimit) { |
| 208 | // not limited by ES 2's constraints |
| 209 | return true; |
| 210 | } |
| 211 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 212 | GrGLint otherFormat = GR_GL_RGBA; |
| 213 | GrGLint otherType = GR_GL_UNSIGNED_BYTE; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 214 | |
| 215 | // The other supported format/type combo supported for ReadPixels |
| 216 | // can change based on which render target is bound |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 217 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 218 | GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, |
| 219 | &otherFormat); |
| 220 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 221 | GR_GL_GetIntegerv(intf, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 222 | GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, |
| 223 | &otherType); |
| 224 | |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 225 | return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 226 | } |
| 227 | |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 228 | namespace { |
| 229 | int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left, |
| 230 | const GrGLCaps::MSAACoverageMode* right) { |
| 231 | if (left->fCoverageSampleCnt < right->fCoverageSampleCnt) { |
| 232 | return -1; |
| 233 | } else if (right->fCoverageSampleCnt < left->fCoverageSampleCnt) { |
| 234 | return 1; |
| 235 | } else if (left->fColorSampleCnt < right->fColorSampleCnt) { |
| 236 | return -1; |
| 237 | } else if (right->fColorSampleCnt < left->fColorSampleCnt) { |
| 238 | return 1; |
| 239 | } |
| 240 | return 0; |
| 241 | } |
| 242 | } |
| 243 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 244 | void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 245 | |
| 246 | fMSFBOType = kNone_MSFBOType; |
| 247 | if (kDesktop_GrGLBinding != ctxInfo.binding()) { |
| 248 | if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| 249 | // chrome's extension is equivalent to the EXT msaa |
| 250 | // and fbo_blit extensions. |
| 251 | fMSFBOType = kDesktopEXT_MSFBOType; |
| 252 | } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 253 | fMSFBOType = kAppleES_MSFBOType; |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame^] | 254 | } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { |
| 255 | fMSFBOType = kImaginationES_MSFBOType; |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 256 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 257 | } else { |
| 258 | if ((ctxInfo.version() >= GR_GL_VER(3,0)) || |
| 259 | ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
| 260 | fMSFBOType = GrGLCaps::kDesktopARB_MSFBOType; |
| 261 | } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
| 262 | ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
| 263 | fMSFBOType = GrGLCaps::kDesktopEXT_MSFBOType; |
| 264 | } |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 265 | // TODO: We could populate fMSAACoverageModes using GetInternalformativ |
| 266 | // on GL 4.2+. It's format-specific, though. See also |
| 267 | // http://code.google.com/p/skia/issues/detail?id=470 about using actual |
| 268 | // rather than requested sample counts in cache key. |
| 269 | if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) { |
| 270 | fCoverageAAType = kNVDesktop_CoverageAAType; |
| 271 | GrGLint count; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 272 | GR_GL_GetIntegerv(gli, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 273 | GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES, |
| 274 | &count); |
| 275 | fMSAACoverageModes.setCount(count); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 276 | GR_GL_GetIntegerv(gli, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 277 | GR_GL_MULTISAMPLE_COVERAGE_MODES, |
| 278 | (int*)&fMSAACoverageModes[0]); |
| 279 | // The NV driver seems to return the modes already sorted but the |
| 280 | // spec doesn't require this. So we sort. |
reed@google.com | c7a67cb | 2012-05-07 14:52:12 +0000 | [diff] [blame] | 281 | qsort(&fMSAACoverageModes[0], |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 282 | count, |
| 283 | sizeof(MSAACoverageMode), |
reed@google.com | c7a67cb | 2012-05-07 14:52:12 +0000 | [diff] [blame] | 284 | SkCastForQSort(coverage_mode_compare)); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 289 | const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const { |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 290 | static const MSAACoverageMode kNoneMode = {0, 0}; |
| 291 | if (0 == fMSAACoverageModes.count()) { |
| 292 | return kNoneMode; |
| 293 | } else { |
| 294 | GrAssert(kNone_CoverageAAType != fCoverageAAType); |
| 295 | int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt; |
| 296 | desiredSampleCount = GrMin(desiredSampleCount, max); |
| 297 | MSAACoverageMode desiredMode = {desiredSampleCount, 0}; |
| 298 | int idx = SkTSearch<MSAACoverageMode>(&fMSAACoverageModes[0], |
| 299 | fMSAACoverageModes.count(), |
| 300 | desiredMode, |
| 301 | sizeof(MSAACoverageMode), |
| 302 | &coverage_mode_compare); |
| 303 | if (idx < 0) { |
| 304 | idx = ~idx; |
| 305 | } |
| 306 | GrAssert(idx >= 0 && idx < fMSAACoverageModes.count()); |
| 307 | return fMSAACoverageModes[idx]; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
| 311 | namespace { |
| 312 | const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
| 313 | } |
| 314 | |
| 315 | void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { |
| 316 | |
| 317 | // Build up list of legal stencil formats (though perhaps not supported on |
| 318 | // the particular gpu/driver) from most preferred to least. |
| 319 | |
| 320 | // these consts are in order of most preferred to least preferred |
| 321 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
| 322 | |
| 323 | static const StencilFormat |
| 324 | // internal Format stencil bits total bits packed? |
| 325 | gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
| 326 | gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
| 327 | gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
| 328 | gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 329 | // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 330 | gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
| 331 | |
| 332 | if (kDesktop_GrGLBinding == ctxInfo.binding()) { |
| 333 | bool supportsPackedDS = |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 334 | ctxInfo.version() >= GR_GL_VER(3,0) || |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 335 | ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || |
| 336 | ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
| 337 | |
| 338 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 339 | // require FBO support we can expect these are legal formats and don't |
| 340 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 341 | fStencilFormats.push_back() = gS8; |
| 342 | fStencilFormats.push_back() = gS16; |
| 343 | if (supportsPackedDS) { |
| 344 | fStencilFormats.push_back() = gD24S8; |
| 345 | } |
| 346 | fStencilFormats.push_back() = gS4; |
| 347 | if (supportsPackedDS) { |
| 348 | fStencilFormats.push_back() = gDS; |
| 349 | } |
| 350 | } else { |
| 351 | // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
| 352 | // for other formats. |
| 353 | // ES doesn't support using the unsized format. |
| 354 | |
| 355 | fStencilFormats.push_back() = gS8; |
| 356 | //fStencilFormats.push_back() = gS16; |
| 357 | if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { |
| 358 | fStencilFormats.push_back() = gD24S8; |
| 359 | } |
| 360 | if (ctxInfo.hasExtension("GL_OES_stencil4")) { |
| 361 | fStencilFormats.push_back() = gS4; |
| 362 | } |
| 363 | } |
| 364 | GrAssert(0 == fStencilVerifiedColorConfigs.count()); |
| 365 | fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); |
| 366 | } |
| 367 | |
| 368 | void GrGLCaps::markColorConfigAndStencilFormatAsVerified( |
| 369 | GrPixelConfig config, |
| 370 | const GrGLStencilBuffer::Format& format) { |
| 371 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 372 | return; |
| 373 | #endif |
| 374 | GrAssert((unsigned)config < kGrPixelConfigCount); |
| 375 | GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); |
| 376 | int count = fStencilFormats.count(); |
| 377 | // we expect a really small number of possible formats so linear search |
| 378 | // should be OK |
| 379 | GrAssert(count < 16); |
| 380 | for (int i = 0; i < count; ++i) { |
| 381 | if (format.fInternalFormat == |
| 382 | fStencilFormats[i].fInternalFormat) { |
| 383 | fStencilVerifiedColorConfigs[i].markVerified(config); |
| 384 | return; |
| 385 | } |
| 386 | } |
| 387 | GrCrash("Why are we seeing a stencil format that " |
| 388 | "GrGLCaps doesn't know about."); |
| 389 | } |
| 390 | |
| 391 | bool GrGLCaps::isColorConfigAndStencilFormatVerified( |
| 392 | GrPixelConfig config, |
| 393 | const GrGLStencilBuffer::Format& format) const { |
| 394 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 395 | return false; |
| 396 | #endif |
| 397 | GrAssert((unsigned)config < kGrPixelConfigCount); |
| 398 | int count = fStencilFormats.count(); |
| 399 | // we expect a really small number of possible formats so linear search |
| 400 | // should be OK |
| 401 | GrAssert(count < 16); |
| 402 | for (int i = 0; i < count; ++i) { |
| 403 | if (format.fInternalFormat == |
| 404 | fStencilFormats[i].fInternalFormat) { |
| 405 | return fStencilVerifiedColorConfigs[i].isVerified(config); |
| 406 | } |
| 407 | } |
| 408 | GrCrash("Why are we seeing a stencil format that " |
| 409 | "GLCaps doesn't know about."); |
| 410 | return false; |
| 411 | } |
| 412 | |
| 413 | void GrGLCaps::print() const { |
| 414 | for (int i = 0; i < fStencilFormats.count(); ++i) { |
| 415 | GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", |
| 416 | i, |
| 417 | fStencilFormats[i].fStencilBits, |
| 418 | fStencilFormats[i].fTotalBits); |
| 419 | } |
| 420 | |
| 421 | GR_STATIC_ASSERT(0 == kNone_MSFBOType); |
| 422 | GR_STATIC_ASSERT(1 == kDesktopARB_MSFBOType); |
| 423 | GR_STATIC_ASSERT(2 == kDesktopEXT_MSFBOType); |
| 424 | GR_STATIC_ASSERT(3 == kAppleES_MSFBOType); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame^] | 425 | GR_STATIC_ASSERT(4 == kImaginationES_MSFBOType); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 426 | static const char* gMSFBOExtStr[] = { |
| 427 | "None", |
| 428 | "ARB", |
| 429 | "EXT", |
| 430 | "Apple", |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame^] | 431 | "IMG", |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 432 | }; |
| 433 | GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]); |
| 434 | GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); |
| 435 | GrPrintf("Support RGBA8 Render Buffer: %s\n", |
| 436 | (fRGBA8RenderbufferSupport ? "YES": "NO")); |
| 437 | GrPrintf("BGRA is an internal format: %s\n", |
| 438 | (fBGRAIsInternalFormat ? "YES": "NO")); |
| 439 | GrPrintf("Support texture swizzle: %s\n", |
| 440 | (fTextureSwizzleSupport ? "YES": "NO")); |
| 441 | GrPrintf("Unpack Row length support: %s\n", |
| 442 | (fUnpackRowLengthSupport ? "YES": "NO")); |
| 443 | GrPrintf("Unpack Flip Y support: %s\n", |
| 444 | (fUnpackFlipYSupport ? "YES": "NO")); |
| 445 | GrPrintf("Pack Row length support: %s\n", |
| 446 | (fPackRowLengthSupport ? "YES": "NO")); |
| 447 | GrPrintf("Pack Flip Y support: %s\n", |
| 448 | (fPackFlipYSupport ? "YES": "NO")); |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 449 | GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 450 | GrPrintf("Fragment coord conventions support: %s\n", (fFragCoordsConventionSupport ? "YES": "NO")); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 451 | } |