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 | #ifndef GrGLCaps_DEFINED |
| 10 | #define GrGLCaps_DEFINED |
| 11 | |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 12 | #include "SkTArray.h" |
| 13 | #include "SkTDArray.h" |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 14 | #include "GrGLStencilBuffer.h" |
| 15 | |
| 16 | class GrGLContextInfo; |
| 17 | |
| 18 | /** |
| 19 | * Stores some capabilities of a GL context. Most are determined by the GL |
| 20 | * version and the extensions string. It also tracks formats that have passed |
| 21 | * the FBO completeness test. |
| 22 | */ |
| 23 | class GrGLCaps { |
| 24 | public: |
| 25 | typedef GrGLStencilBuffer::Format StencilFormat; |
| 26 | |
| 27 | /** |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 28 | * Represents a supported multisampling/coverage-sampling mode. |
| 29 | */ |
| 30 | struct MSAACoverageMode { |
| 31 | // "Coverage samples" includes samples that actually have color, depth, |
| 32 | // stencil, ... as well as those that don't (coverage only). All samples |
| 33 | // are coverage samples. (We're using the word "coverage sample" to |
| 34 | // match the NV extension language.) |
| 35 | int fCoverageSampleCnt; |
| 36 | |
| 37 | // Color samples are samples that store data values (color, stencil, |
| 38 | // depth) rather than just representing coverage. They are a subset |
| 39 | // of coverage samples. (Again the wording was chosen to match the |
| 40 | // extension.) |
| 41 | int fColorSampleCnt; |
| 42 | }; |
| 43 | |
| 44 | /** |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 45 | * The type of MSAA for FBOs supported. Different extensions have different |
| 46 | * semantics of how / when a resolve is performed. |
| 47 | */ |
| 48 | enum MSFBOType { |
| 49 | /** |
| 50 | * no support for MSAA FBOs |
| 51 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 52 | kNone_MSFBOType = 0, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 53 | /** |
| 54 | * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object) |
| 55 | */ |
| 56 | kDesktopARB_MSFBOType, |
| 57 | /** |
| 58 | * earlier GL_EXT_framebuffer* extensions |
| 59 | */ |
| 60 | kDesktopEXT_MSFBOType, |
| 61 | /** |
| 62 | * GL_APPLE_framebuffer_multisample ES extension |
| 63 | */ |
| 64 | kAppleES_MSFBOType, |
| 65 | }; |
| 66 | |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 67 | enum CoverageAAType { |
| 68 | /** |
| 69 | * No coverage sample support |
| 70 | */ |
| 71 | kNone_CoverageAAType, |
| 72 | |
| 73 | /** |
| 74 | * GL_NV_framebuffer_multisample_coverage |
| 75 | */ |
| 76 | kNVDesktop_CoverageAAType, |
| 77 | }; |
| 78 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 79 | /** |
| 80 | * Creates a GrGLCaps that advertises no support for any extensions, |
| 81 | * formats, etc. Call init to initialize from a GrGLContextInfo. |
| 82 | */ |
| 83 | GrGLCaps(); |
| 84 | |
| 85 | GrGLCaps(const GrGLCaps& caps); |
| 86 | |
| 87 | GrGLCaps& operator = (const GrGLCaps& caps); |
| 88 | |
| 89 | /** |
| 90 | * Resets the caps such that nothing is supported. |
| 91 | */ |
| 92 | void reset(); |
| 93 | |
| 94 | /** |
| 95 | * Initializes the GrGLCaps to the set of features supported in the current |
| 96 | * OpenGL context accessible via ctxInfo. |
| 97 | */ |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 98 | void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * Call to note that a color config has been verified as a valid color |
| 102 | * attachment. This may save future calls to glCheckFramebufferStatus |
| 103 | * using isConfigVerifiedColorAttachment(). |
| 104 | */ |
| 105 | void markConfigAsValidColorAttachment(GrPixelConfig config) { |
| 106 | fVerifiedColorConfigs.markVerified(config); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Call to check whether a config has been verified as a valid color |
| 111 | * attachment. |
| 112 | */ |
| 113 | bool isConfigVerifiedColorAttachment(GrPixelConfig config) const { |
| 114 | return fVerifiedColorConfigs.isVerified(config); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Call to note that a color config / stencil format pair passed |
| 119 | * FBO status check. We may skip calling glCheckFramebufferStatus for |
| 120 | * this combination in the future using |
| 121 | * isColorConfigAndStencilFormatVerified(). |
| 122 | */ |
| 123 | void markColorConfigAndStencilFormatAsVerified( |
| 124 | GrPixelConfig config, |
| 125 | const GrGLStencilBuffer::Format& format); |
| 126 | |
| 127 | /** |
| 128 | * Call to check whether color config / stencil format pair has already |
| 129 | * passed FBO status check. |
| 130 | */ |
| 131 | bool isColorConfigAndStencilFormatVerified( |
| 132 | GrPixelConfig config, |
| 133 | const GrGLStencilBuffer::Format& format) const; |
| 134 | |
| 135 | /** |
| 136 | * Reports the type of MSAA FBO support. |
| 137 | */ |
| 138 | MSFBOType msFBOType() const { return fMSFBOType; } |
| 139 | |
| 140 | /** |
bsalomon@google.com | f6b070d | 2012-04-27 14:25:44 +0000 | [diff] [blame] | 141 | * Reports the maximum number of samples supported. |
| 142 | */ |
| 143 | int maxSampleCount() const { return fMaxSampleCount; } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 144 | |
bsalomon@google.com | f6b070d | 2012-04-27 14:25:44 +0000 | [diff] [blame] | 145 | /** |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 146 | * Reports the type of coverage sample AA support. |
| 147 | */ |
| 148 | CoverageAAType coverageAAType() const { return fCoverageAAType; } |
| 149 | |
| 150 | /** |
| 151 | * Chooses a supported coverage mode based on a desired sample count. The |
| 152 | * desired sample count is rounded up the next supported coverage sample |
| 153 | * count unless a it is larger than the max in which case it is rounded |
| 154 | * down. Once a coverage sample count is decided, the supported mode with |
| 155 | * the fewest color samples is chosen. |
| 156 | */ |
| 157 | const MSAACoverageMode& getMSAACoverageMode(int desiredSampleCount) const; |
| 158 | |
| 159 | /** |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 160 | * Prints the caps info using GrPrintf. |
| 161 | */ |
| 162 | void print() const; |
| 163 | |
| 164 | /** |
| 165 | * Gets an array of legal stencil formats. These formats are not guaranteed |
| 166 | * to be supported by the driver but are legal GLenum names given the GL |
| 167 | * version and extensions supported. |
| 168 | */ |
| 169 | const SkTArray<StencilFormat, true>& stencilFormats() const { |
| 170 | return fStencilFormats; |
| 171 | } |
| 172 | |
| 173 | /// The maximum number of fragment uniform vectors (GLES has min. 16). |
| 174 | int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } |
| 175 | |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 176 | // maximum number of attribute values per vertex |
| 177 | int maxVertexAttributes() const { return fMaxVertexAttributes; } |
| 178 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 179 | /// ES requires an extension to support RGBA8 in RenderBufferStorage |
| 180 | bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; } |
| 181 | |
| 182 | /// Is GL_BGRA supported |
| 183 | bool bgraFormatSupport() const { return fBGRAFormatSupport; } |
| 184 | |
| 185 | /** |
| 186 | * Depending on the ES extensions present the BGRA external format may |
| 187 | * correspond either a BGRA or RGBA internalFormat. On desktop GL it is |
| 188 | * RGBA. |
| 189 | */ |
| 190 | bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; } |
| 191 | |
| 192 | /// GL_ARB_texture_swizzle support |
| 193 | bool textureSwizzleSupport() const { return fTextureSwizzleSupport; } |
| 194 | |
| 195 | /// Is there support for GL_UNPACK_ROW_LENGTH |
| 196 | bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; } |
| 197 | |
| 198 | /// Is there support for GL_UNPACK_FLIP_Y |
| 199 | bool unpackFlipYSupport() const { return fUnpackFlipYSupport; } |
| 200 | |
| 201 | /// Is there support for GL_PACK_ROW_LENGTH |
| 202 | bool packRowLengthSupport() const { return fPackRowLengthSupport; } |
| 203 | |
| 204 | /// Is there support for GL_PACK_REVERSE_ROW_ORDER |
| 205 | bool packFlipYSupport() const { return fPackFlipYSupport; } |
| 206 | |
| 207 | /// Is there support for texture parameter GL_TEXTURE_USAGE |
| 208 | bool textureUsageSupport() const { return fTextureUsageSupport; } |
| 209 | |
| 210 | /// Is there support for glTexStorage |
| 211 | bool texStorageSupport() const { return fTexStorageSupport; } |
| 212 | |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 213 | /// Is there support for GL_RED and GL_R8 |
| 214 | bool textureRedSupport() const { return fTextureRedSupport; } |
| 215 | |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 216 | /// Is GL_ARB_IMAGING supported |
| 217 | bool imagingSupport() const { return fImagingSupport; } |
| 218 | |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 219 | /// Is GL_ARB_fragment_coord_conventions supported? |
| 220 | bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; } |
| 221 | |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 222 | // Use indices or vertices in CPU arrays rather than VBOs for dynamic content. |
| 223 | bool useNonVBOVertexAndIndexDynamicData() const { |
| 224 | return fUseNonVBOVertexAndIndexDynamicData; |
| 225 | } |
| 226 | |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 227 | // Does ReadPixels support the provided format/type combo? |
| 228 | bool readPixelsSupported(const GrGLInterface* intf, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 229 | GrGLenum format, |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 230 | GrGLenum type) const; |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame^] | 231 | |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 232 | bool isCoreProfile() const { return fIsCoreProfile; } |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 233 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 234 | private: |
| 235 | /** |
| 236 | * Maintains a bit per GrPixelConfig. It is used to avoid redundantly |
| 237 | * performing glCheckFrameBufferStatus for the same config. |
| 238 | */ |
| 239 | struct VerifiedColorConfigs { |
| 240 | VerifiedColorConfigs() { |
| 241 | this->reset(); |
| 242 | } |
| 243 | |
| 244 | void reset() { |
| 245 | for (int i = 0; i < kNumUints; ++i) { |
| 246 | fVerifiedColorConfigs[i] = 0; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | static const int kNumUints = (kGrPixelConfigCount + 31) / 32; |
| 251 | uint32_t fVerifiedColorConfigs[kNumUints]; |
| 252 | |
| 253 | void markVerified(GrPixelConfig config) { |
| 254 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 255 | return; |
| 256 | #endif |
| 257 | int u32Idx = config / 32; |
| 258 | int bitIdx = config % 32; |
| 259 | fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx; |
| 260 | } |
| 261 | |
| 262 | bool isVerified(GrPixelConfig config) const { |
| 263 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 264 | return false; |
| 265 | #endif |
| 266 | int u32Idx = config / 32; |
| 267 | int bitIdx = config % 32; |
| 268 | return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx)); |
| 269 | } |
| 270 | }; |
| 271 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 272 | void initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 273 | void initStencilFormats(const GrGLContextInfo& ctxInfo); |
| 274 | |
| 275 | // tracks configs that have been verified to pass the FBO completeness when |
| 276 | // used as a color attachment |
| 277 | VerifiedColorConfigs fVerifiedColorConfigs; |
| 278 | |
| 279 | SkTArray<StencilFormat, true> fStencilFormats; |
| 280 | // tracks configs that have been verified to pass the FBO completeness when |
| 281 | // used as a color attachment when a particular stencil format is used |
| 282 | // as a stencil attachment. |
| 283 | SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs; |
| 284 | |
| 285 | int fMaxFragmentUniformVectors; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 286 | int fMaxVertexAttributes; |
| 287 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 288 | MSFBOType fMSFBOType; |
bsalomon@google.com | f6b070d | 2012-04-27 14:25:44 +0000 | [diff] [blame] | 289 | int fMaxSampleCount; |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 290 | CoverageAAType fCoverageAAType; |
| 291 | SkTDArray<MSAACoverageMode> fMSAACoverageModes; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 292 | |
| 293 | bool fRGBA8RenderbufferSupport : 1; |
| 294 | bool fBGRAFormatSupport : 1; |
| 295 | bool fBGRAIsInternalFormat : 1; |
| 296 | bool fTextureSwizzleSupport : 1; |
| 297 | bool fUnpackRowLengthSupport : 1; |
| 298 | bool fUnpackFlipYSupport : 1; |
| 299 | bool fPackRowLengthSupport : 1; |
| 300 | bool fPackFlipYSupport : 1; |
| 301 | bool fTextureUsageSupport : 1; |
| 302 | bool fTexStorageSupport : 1; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 303 | bool fTextureRedSupport : 1; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 304 | bool fImagingSupport : 1; |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 305 | bool fTwoFormatLimit : 1; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 306 | bool fFragCoordsConventionSupport : 1; |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 307 | bool fUseNonVBOVertexAndIndexDynamicData : 1; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 308 | bool fIsCoreProfile : 1; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | #endif |