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