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