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 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 12 | #include <functional> |
| 13 | |
mtklein | 3183a41 | 2016-01-08 12:11:39 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSL.h" |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 15 | #include "GrCaps.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 16 | #include "GrGLStencilAttachment.h" |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 17 | #include "GrSwizzle.h" |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 18 | #include "SkChecksum.h" |
mtklein | 2aa1f7e | 2015-02-20 12:35:32 -0800 | [diff] [blame] | 19 | #include "SkTHash.h" |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 20 | #include "SkTArray.h" |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 21 | |
| 22 | class GrGLContextInfo; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 23 | class GrGLSLCaps; |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 24 | class GrGLRenderTarget; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Stores some capabilities of a GL context. Most are determined by the GL |
| 28 | * version and the extensions string. It also tracks formats that have passed |
| 29 | * the FBO completeness test. |
| 30 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 31 | class GrGLCaps : public GrCaps { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 32 | public: |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 33 | typedef GrGLStencilAttachment::Format StencilFormat; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * The type of MSAA for FBOs supported. Different extensions have different |
| 37 | * semantics of how / when a resolve is performed. |
| 38 | */ |
| 39 | enum MSFBOType { |
| 40 | /** |
| 41 | * no support for MSAA FBOs |
| 42 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 43 | kNone_MSFBOType = 0, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 44 | /** |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 45 | * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object). |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 46 | */ |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 47 | kDesktop_ARB_MSFBOType, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 48 | /** |
| 49 | * earlier GL_EXT_framebuffer* extensions |
| 50 | */ |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 51 | kDesktop_EXT_MSFBOType, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 52 | /** |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 53 | * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer. |
| 54 | */ |
| 55 | kES_3_0_MSFBOType, |
| 56 | /** |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 57 | * GL_APPLE_framebuffer_multisample ES extension |
| 58 | */ |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 59 | kES_Apple_MSFBOType, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 60 | /** |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 61 | * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers. |
| 62 | * Instead the texture is multisampled when bound to the FBO and then resolved automatically |
| 63 | * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call |
| 64 | * GR_GL_MAX_SAMPLES_IMG). |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 65 | */ |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 66 | kES_IMG_MsToTexture_MSFBOType, |
| 67 | /** |
| 68 | * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard |
| 69 | * GL_MAX_SAMPLES value. |
| 70 | */ |
| 71 | kES_EXT_MsToTexture_MSFBOType, |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 72 | /** |
| 73 | * GL_NV_framebuffer_mixed_samples. |
| 74 | */ |
| 75 | kMixedSamples_MSFBOType, |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 76 | |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 77 | kLast_MSFBOType = kMixedSamples_MSFBOType |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame^] | 80 | enum BlitFramebufferSupport { |
| 81 | kNone_BlitFramebufferSupport, |
| 82 | /** |
| 83 | * ANGLE exposes a limited blit framebuffer extension that does not allow for stretching |
| 84 | * or mirroring. |
| 85 | */ |
| 86 | kNoScalingNoMirroring_BlitFramebufferSupport, |
| 87 | kFull_BlitFramebufferSupport |
| 88 | }; |
| 89 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 90 | enum InvalidateFBType { |
| 91 | kNone_InvalidateFBType, |
| 92 | kDiscard_InvalidateFBType, //<! glDiscardFramebuffer() |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame^] | 93 | kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer() |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 94 | |
| 95 | kLast_InvalidateFBType = kInvalidate_InvalidateFBType |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 98 | enum MapBufferType { |
| 99 | kNone_MapBufferType, |
| 100 | kMapBuffer_MapBufferType, // glMapBuffer() |
| 101 | kMapBufferRange_MapBufferType, // glMapBufferRange() |
| 102 | kChromium_MapBufferType, // GL_CHROMIUM_map_sub |
| 103 | |
| 104 | kLast_MapBufferType = kChromium_MapBufferType, |
| 105 | }; |
| 106 | |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 107 | enum TransferBufferType { |
| 108 | kNone_TransferBufferType, |
| 109 | kPBO_TransferBufferType, // ARB_pixel_buffer_object |
| 110 | kChromium_TransferBufferType, // CHROMIUM_pixel_transfer_buffer_object |
| 111 | |
| 112 | kLast_TransferBufferType = kChromium_TransferBufferType, |
| 113 | }; |
| 114 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 115 | /** |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 116 | * Initializes the GrGLCaps to the set of features supported in the current |
| 117 | * OpenGL context accessible via ctxInfo. |
| 118 | */ |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 119 | GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo, |
| 120 | const GrGLInterface* glInterface); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 121 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 122 | bool isConfigTexturable(GrPixelConfig config) const override { |
| 123 | SkASSERT(kGrPixelConfigCnt > config); |
| 124 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag); |
| 125 | } |
| 126 | |
| 127 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { |
| 128 | SkASSERT(kGrPixelConfigCnt > config); |
| 129 | if (withMSAA) { |
| 130 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kRenderableWithMSAA_Flag); |
| 131 | } else { |
| 132 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kRenderable_Flag); |
| 133 | } |
| 134 | } |
| 135 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 136 | /** Returns the mapping between GrPixelConfig components and GL internal format components. */ |
| 137 | const GrSwizzle& configSwizzle(GrPixelConfig config) const { |
| 138 | return fConfigTable[config].fSwizzle; |
| 139 | } |
| 140 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 141 | bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, |
| 142 | GrGLenum* internalFormat, GrGLenum* externalFormat, |
| 143 | GrGLenum* externalType) const; |
| 144 | |
| 145 | bool getCompressedTexImageFormats(GrPixelConfig surfaceConfig, GrGLenum* internalFormat) const; |
| 146 | |
| 147 | bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, |
| 148 | GrGLenum* externalFormat, GrGLenum* externalType) const; |
| 149 | |
| 150 | bool getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const; |
| 151 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 152 | /** |
| 153 | * Gets an array of legal stencil formats. These formats are not guaranteed |
| 154 | * to be supported by the driver but are legal GLenum names given the GL |
| 155 | * version and extensions supported. |
| 156 | */ |
| 157 | const SkTArray<StencilFormat, true>& stencilFormats() const { |
| 158 | return fStencilFormats; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Has a stencil format index been found for the config (or we've found that no format works). |
| 163 | */ |
| 164 | bool hasStencilFormatBeenDeterminedForConfig(GrPixelConfig config) const { |
| 165 | return fConfigTable[config].fStencilFormatIndex != ConfigInfo::kUnknown_StencilIndex; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Gets the stencil format index for the config. This assumes |
| 170 | * hasStencilFormatBeenDeterminedForConfig has already been checked. Returns a value < 0 if |
| 171 | * no stencil format is supported with the config. Otherwise, returned index refers to the array |
| 172 | * returned by stencilFormats(). |
| 173 | */ |
| 174 | int getStencilFormatIndexForConfig(GrPixelConfig config) const { |
| 175 | SkASSERT(this->hasStencilFormatBeenDeterminedForConfig(config)); |
| 176 | return fConfigTable[config].fStencilFormatIndex; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * If index is >= 0 this records an index into stencilFormats() as the best stencil format for |
| 181 | * the config. If < 0 it records that the config has no supported stencil format index. |
| 182 | */ |
| 183 | void setStencilFormatIndexForConfig(GrPixelConfig config, int index) { |
| 184 | SkASSERT(!this->hasStencilFormatBeenDeterminedForConfig(config)); |
| 185 | if (index < 0) { |
| 186 | fConfigTable[config].fStencilFormatIndex = ConfigInfo::kUnsupported_StencilFormatIndex; |
| 187 | } else { |
| 188 | fConfigTable[config].fStencilFormatIndex = index; |
| 189 | } |
| 190 | } |
| 191 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 192 | /** |
| 193 | * Call to note that a color config has been verified as a valid color |
| 194 | * attachment. This may save future calls to glCheckFramebufferStatus |
| 195 | * using isConfigVerifiedColorAttachment(). |
| 196 | */ |
| 197 | void markConfigAsValidColorAttachment(GrPixelConfig config) { |
bsalomon | 480e8c0 | 2015-12-21 13:44:18 -0800 | [diff] [blame] | 198 | fConfigTable[config].fFlags |= ConfigInfo::kVerifiedColorAttachment_Flag; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Call to check whether a config has been verified as a valid color |
| 203 | * attachment. |
| 204 | */ |
| 205 | bool isConfigVerifiedColorAttachment(GrPixelConfig config) const { |
bsalomon | 480e8c0 | 2015-12-21 13:44:18 -0800 | [diff] [blame] | 206 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kVerifiedColorAttachment_Flag); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /** |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 210 | * Reports the type of MSAA FBO support. |
| 211 | */ |
| 212 | MSFBOType msFBOType() const { return fMSFBOType; } |
| 213 | |
| 214 | /** |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame^] | 215 | * Does the preferred MSAA FBO extension have MSAA renderbuffers? |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 216 | */ |
| 217 | bool usesMSAARenderBuffers() const { |
| 218 | return kNone_MSFBOType != fMSFBOType && |
| 219 | kES_IMG_MsToTexture_MSFBOType != fMSFBOType && |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 220 | kES_EXT_MsToTexture_MSFBOType != fMSFBOType && |
| 221 | kMixedSamples_MSFBOType != fMSFBOType; |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /** |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame^] | 225 | * What functionality is supported by glBlitFramebuffer. |
| 226 | */ |
| 227 | BlitFramebufferSupport blitFramebufferSupport() const { return fBlitFramebufferSupport; } |
| 228 | |
| 229 | /** |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 230 | * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and |
| 231 | * then implicitly resolved when read. |
| 232 | */ |
| 233 | bool usesImplicitMSAAResolve() const { |
| 234 | return kES_IMG_MsToTexture_MSFBOType == fMSFBOType || |
| 235 | kES_EXT_MsToTexture_MSFBOType == fMSFBOType; |
| 236 | } |
| 237 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 238 | InvalidateFBType invalidateFBType() const { return fInvalidateFBType; } |
| 239 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 240 | /// What type of buffer mapping is supported? |
| 241 | MapBufferType mapBufferType() const { return fMapBufferType; } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 242 | |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 243 | /// What type of transfer buffer is supported? |
| 244 | TransferBufferType transferBufferType() const { return fTransferBufferType; } |
| 245 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 246 | /// The maximum number of fragment uniform vectors (GLES has min. 16). |
| 247 | int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } |
| 248 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 249 | /// maximum number of attribute values per vertex |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 250 | int maxVertexAttributes() const { return fMaxVertexAttributes; } |
| 251 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 252 | /// maximum number of texture units accessible in the fragment shader. |
| 253 | int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; } |
| 254 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 255 | /** |
| 256 | * Depending on the ES extensions present the BGRA external format may |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 257 | * correspond to either a BGRA or RGBA internalFormat. On desktop GL it is |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 258 | * RGBA. |
| 259 | */ |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 260 | bool bgraIsInternalFormat() const; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 261 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 262 | /// Is there support for GL_UNPACK_ROW_LENGTH |
| 263 | bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; } |
| 264 | |
| 265 | /// Is there support for GL_UNPACK_FLIP_Y |
| 266 | bool unpackFlipYSupport() const { return fUnpackFlipYSupport; } |
| 267 | |
| 268 | /// Is there support for GL_PACK_ROW_LENGTH |
| 269 | bool packRowLengthSupport() const { return fPackRowLengthSupport; } |
| 270 | |
| 271 | /// Is there support for GL_PACK_REVERSE_ROW_ORDER |
| 272 | bool packFlipYSupport() const { return fPackFlipYSupport; } |
| 273 | |
| 274 | /// Is there support for texture parameter GL_TEXTURE_USAGE |
| 275 | bool textureUsageSupport() const { return fTextureUsageSupport; } |
| 276 | |
| 277 | /// Is there support for glTexStorage |
| 278 | bool texStorageSupport() const { return fTexStorageSupport; } |
| 279 | |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 280 | /// Is there support for GL_RED and GL_R8 |
| 281 | bool textureRedSupport() const { return fTextureRedSupport; } |
| 282 | |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 283 | /// Is GL_ARB_IMAGING supported |
| 284 | bool imagingSupport() const { return fImagingSupport; } |
| 285 | |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 286 | /// Is there support for Vertex Array Objects? |
| 287 | bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; } |
| 288 | |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 289 | /// Is there support for GL_EXT_direct_state_access? |
| 290 | bool directStateAccessSupport() const { return fDirectStateAccessSupport; } |
| 291 | |
| 292 | /// Is there support for GL_KHR_debug? |
| 293 | bool debugSupport() const { return fDebugSupport; } |
| 294 | |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 295 | /// Is there support for ES2 compatability? |
| 296 | bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; } |
| 297 | |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 298 | /// Can we call glDisable(GL_MULTISAMPLE)? |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 299 | bool multisampleDisableSupport() const { return fMultisampleDisableSupport; } |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 300 | |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 301 | /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw |
| 302 | /// commands cannot be used unless we have base instance support. |
| 303 | bool drawIndirectSupport() const { return fDrawIndirectSupport; } |
| 304 | |
| 305 | /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect |
| 306 | /// draw commands cannot be used unless we have base instance support. |
| 307 | bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; } |
| 308 | |
| 309 | /// Are the baseInstance fields supported in indirect draw commands? |
| 310 | bool baseInstanceSupport() const { return fBaseInstanceSupport; } |
| 311 | |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 312 | /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 313 | bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; } |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 314 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 315 | /// Does ReadPixels support reading readConfig pixels from a FBO that is renderTargetConfig? |
| 316 | bool readPixelsSupported(GrPixelConfig renderTargetConfig, |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 317 | GrPixelConfig readConfig, |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 318 | std::function<void (GrGLenum, GrGLint*)> getIntegerv, |
| 319 | std::function<bool ()> bindRenderTarget) const; |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 320 | |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 321 | bool isCoreProfile() const { return fIsCoreProfile; } |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 322 | |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 323 | bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; } |
| 324 | |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 325 | bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; } |
| 326 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 327 | /// Are textures with GL_TEXTURE_EXTERNAL_OES type supported. |
| 328 | bool externalTextureSupport() const { return fExternalTextureSupport; } |
| 329 | |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 330 | /// Are textures with GL_TEXTURE_RECTANGLE type supported. |
| 331 | bool rectangleTextureSupport() const { return fRectangleTextureSupport; } |
| 332 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 333 | /// GL_ARB_texture_swizzle |
| 334 | bool textureSwizzleSupport() const { return fTextureSwizzleSupport; } |
| 335 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 336 | /** |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 337 | * Is there support for enabling/disabling sRGB writes for sRGB-capable color attachments? |
| 338 | * If false this does not mean sRGB is not supported but rather that if it is supported |
| 339 | * it cannot be turned off for configs that support it. |
| 340 | */ |
| 341 | bool srgbWriteControl() const { return fSRGBWriteControl; } |
| 342 | |
| 343 | /** |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 344 | * Returns a string containing the caps info. |
| 345 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 346 | SkString dump() const override; |
commit-bot@chromium.org | beb8b3a | 2014-04-15 15:37:51 +0000 | [diff] [blame] | 347 | |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 348 | bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; } |
| 349 | bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; } |
| 350 | |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 351 | const GrGLSLCaps* glslCaps() const { return reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get()); } |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 352 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 353 | private: |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 354 | enum ExternalFormatUsage { |
| 355 | kTexImage_ExternalFormatUsage, |
| 356 | kOther_ExternalFormatUsage, |
| 357 | |
| 358 | kLast_ExternalFormatUsage = kOther_ExternalFormatUsage |
| 359 | }; |
| 360 | static const int kExternalFormatUsageCnt = kLast_ExternalFormatUsage + 1; |
| 361 | bool getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig, |
| 362 | ExternalFormatUsage usage, GrGLenum* externalFormat, |
| 363 | GrGLenum* externalType) const; |
| 364 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 365 | void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*); |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 366 | void initGLSL(const GrGLContextInfo&); |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 367 | bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 368 | |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 369 | void onApplyOptionsOverrides(const GrContextOptions& options) override; |
| 370 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 371 | void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 372 | void initBlendEqationSupport(const GrGLContextInfo&); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 373 | void initStencilFormats(const GrGLContextInfo&); |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 374 | // This must be called after initFSAASupport(). |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 375 | void initConfigTable(const GrGLContextInfo&, const GrGLInterface* gli, GrGLSLCaps* glslCaps); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 376 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 377 | void initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, |
| 378 | const GrGLInterface* intf, |
| 379 | GrGLSLCaps* glslCaps); |
| 380 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 381 | GrGLStandard fStandard; |
| 382 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 383 | SkTArray<StencilFormat, true> fStencilFormats; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 384 | |
| 385 | int fMaxFragmentUniformVectors; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 386 | int fMaxVertexAttributes; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 387 | int fMaxFragmentTextureUnits; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 388 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 389 | MSFBOType fMSFBOType; |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 390 | InvalidateFBType fInvalidateFBType; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 391 | MapBufferType fMapBufferType; |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 392 | TransferBufferType fTransferBufferType; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 393 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 394 | bool fUnpackRowLengthSupport : 1; |
| 395 | bool fUnpackFlipYSupport : 1; |
| 396 | bool fPackRowLengthSupport : 1; |
| 397 | bool fPackFlipYSupport : 1; |
| 398 | bool fTextureUsageSupport : 1; |
| 399 | bool fTexStorageSupport : 1; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 400 | bool fTextureRedSupport : 1; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 401 | bool fImagingSupport : 1; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 402 | bool fVertexArrayObjectSupport : 1; |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 403 | bool fDirectStateAccessSupport : 1; |
| 404 | bool fDebugSupport : 1; |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 405 | bool fES2CompatibilitySupport : 1; |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 406 | bool fMultisampleDisableSupport : 1; |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 407 | bool fDrawIndirectSupport : 1; |
| 408 | bool fMultiDrawIndirectSupport : 1; |
| 409 | bool fBaseInstanceSupport : 1; |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 410 | bool fUseNonVBOVertexAndIndexDynamicData : 1; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 411 | bool fIsCoreProfile : 1; |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 412 | bool fBindFragDataLocationSupport : 1; |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 413 | bool fSRGBWriteControl : 1; |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 414 | bool fRGBA8888PixelsOpsAreSlow : 1; |
| 415 | bool fPartialFBOReadIsSlow : 1; |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 416 | bool fBindUniformLocationSupport : 1; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 417 | bool fExternalTextureSupport : 1; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 418 | bool fRectangleTextureSupport : 1; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 419 | bool fTextureSwizzleSupport : 1; |
joshualitt | 5816233 | 2014-08-01 06:44:53 -0700 | [diff] [blame] | 420 | |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame^] | 421 | BlitFramebufferSupport fBlitFramebufferSupport; |
| 422 | |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 423 | /** Number type of the components (with out considering number of bits.) */ |
| 424 | enum FormatType { |
| 425 | kNormalizedFixedPoint_FormatType, |
| 426 | kFloat_FormatType, |
| 427 | }; |
| 428 | |
| 429 | struct ReadPixelsFormat { |
| 430 | ReadPixelsFormat() : fFormat(0), fType(0) {} |
| 431 | GrGLenum fFormat; |
| 432 | GrGLenum fType; |
| 433 | }; |
| 434 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 435 | struct ConfigFormats { |
| 436 | ConfigFormats() { |
| 437 | // Inits to known bad GL enum values. |
| 438 | memset(this, 0xAB, sizeof(ConfigFormats)); |
| 439 | } |
| 440 | GrGLenum fBaseInternalFormat; |
| 441 | GrGLenum fSizedInternalFormat; |
| 442 | |
| 443 | /** The external format and type are to be used when uploading/downloading data using this |
| 444 | config where both the CPU data and GrSurface are the same config. To get the external |
| 445 | format and type when converting between configs while copying to/from memory use |
| 446 | getExternalFormat(). |
| 447 | The kTexImage external format is usually the same as kOther except for kSRGBA on some |
| 448 | GL contexts. */ |
| 449 | GrGLenum fExternalFormat[kExternalFormatUsageCnt]; |
| 450 | GrGLenum fExternalType; |
| 451 | |
| 452 | |
| 453 | // Either the base or sized internal format depending on the GL and config. |
| 454 | GrGLenum fInternalFormatTexImage; |
| 455 | GrGLenum fInternalFormatRenderbuffer; |
| 456 | }; |
| 457 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 458 | struct ConfigInfo { |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 459 | ConfigInfo() : fStencilFormatIndex(kUnknown_StencilIndex), fFlags(0) {} |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 460 | |
| 461 | ConfigFormats fFormats; |
| 462 | |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 463 | FormatType fFormatType; |
| 464 | |
| 465 | // On ES contexts there are restrictions on type type/format that may be used for |
| 466 | // ReadPixels. One is implicitly specified by the current FBO's format. The other is |
| 467 | // queryable. This stores the queried option (lazily). |
| 468 | ReadPixelsFormat fSecondReadPixelsFormat; |
| 469 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 470 | enum { |
| 471 | // This indicates that a stencil format has not yet been determined for the config. |
| 472 | kUnknown_StencilIndex = -1, |
| 473 | // This indicates that there is no supported stencil format for the config. |
| 474 | kUnsupported_StencilFormatIndex = -2 |
| 475 | }; |
bsalomon | 480e8c0 | 2015-12-21 13:44:18 -0800 | [diff] [blame] | 476 | |
| 477 | // Index fStencilFormats. |
| 478 | int fStencilFormatIndex; |
| 479 | |
| 480 | enum { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 481 | kVerifiedColorAttachment_Flag = 0x1, |
| 482 | kTextureable_Flag = 0x2, |
| 483 | kRenderable_Flag = 0x4, |
| 484 | kRenderableWithMSAA_Flag = 0x8, |
bsalomon | 480e8c0 | 2015-12-21 13:44:18 -0800 | [diff] [blame] | 485 | }; |
| 486 | uint32_t fFlags; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 487 | |
| 488 | GrSwizzle fSwizzle; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 489 | }; |
| 490 | |
| 491 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
| 492 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 493 | typedef GrCaps INHERITED; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 494 | }; |
| 495 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 496 | #endif |