blob: ac90aa1db60b1ed1b47c2ca62329327eff7837a2 [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
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
bsalomoneb1cb5c2015-05-22 08:01:09 -070012#include "GrCaps.h"
jvanverthcba99b82015-06-24 06:59:57 -070013#include "glsl/GrGLSL.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070014#include "GrGLStencilAttachment.h"
piotaixre4b23142014-10-02 10:57:53 -070015#include "SkChecksum.h"
mtklein2aa1f7e2015-02-20 12:35:32 -080016#include "SkTHash.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000017#include "SkTArray.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000018
19class GrGLContextInfo;
jvanverthe9c0fc62015-04-29 11:18:05 -070020class GrGLSLCaps;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000021
22/**
23 * Stores some capabilities of a GL context. Most are determined by the GL
24 * version and the extensions string. It also tracks formats that have passed
25 * the FBO completeness test.
26 */
bsalomon4b91f762015-05-19 09:29:46 -070027class GrGLCaps : public GrCaps {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028public:
mtklein2766c002015-06-26 11:45:03 -070029
bsalomon@google.combcce8922013-03-25 15:38:39 +000030
egdaniel8dc7c3a2015-04-16 11:22:42 -070031 typedef GrGLStencilAttachment::Format StencilFormat;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032
33 /**
34 * The type of MSAA for FBOs supported. Different extensions have different
35 * semantics of how / when a resolve is performed.
36 */
37 enum MSFBOType {
38 /**
39 * no support for MSAA FBOs
40 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000041 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000042 /**
skia.committer@gmail.com6fc1b492013-09-06 07:01:45 +000043 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000044 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000045 kDesktop_ARB_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000046 /**
47 * earlier GL_EXT_framebuffer* extensions
48 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000049 kDesktop_EXT_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000050 /**
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000051 * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
52 */
53 kES_3_0_MSFBOType,
54 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000055 * GL_APPLE_framebuffer_multisample ES extension
56 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000057 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000058 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000059 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
60 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
61 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
62 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000063 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000064 kES_IMG_MsToTexture_MSFBOType,
65 /**
66 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
67 * GL_MAX_SAMPLES value.
68 */
69 kES_EXT_MsToTexture_MSFBOType,
vbuzinovdded6962015-06-12 08:59:45 -070070 /**
71 * GL_NV_framebuffer_mixed_samples.
72 */
73 kMixedSamples_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000074
vbuzinovdded6962015-06-12 08:59:45 -070075 kLast_MSFBOType = kMixedSamples_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000076 };
77
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000078 enum InvalidateFBType {
79 kNone_InvalidateFBType,
80 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
81 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
82
83 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000084 };
85
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000086 enum MapBufferType {
87 kNone_MapBufferType,
88 kMapBuffer_MapBufferType, // glMapBuffer()
89 kMapBufferRange_MapBufferType, // glMapBufferRange()
90 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
91
92 kLast_MapBufferType = kChromium_MapBufferType,
93 };
94
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096 * Initializes the GrGLCaps to the set of features supported in the current
97 * OpenGL context accessible via ctxInfo.
98 */
bsalomon682c2692015-05-22 14:01:46 -070099 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
100 const GrGLInterface* glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101
102 /**
103 * Call to note that a color config has been verified as a valid color
104 * attachment. This may save future calls to glCheckFramebufferStatus
105 * using isConfigVerifiedColorAttachment().
106 */
107 void markConfigAsValidColorAttachment(GrPixelConfig config) {
108 fVerifiedColorConfigs.markVerified(config);
109 }
110
111 /**
112 * Call to check whether a config has been verified as a valid color
113 * attachment.
114 */
115 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
116 return fVerifiedColorConfigs.isVerified(config);
117 }
118
119 /**
120 * Call to note that a color config / stencil format pair passed
121 * FBO status check. We may skip calling glCheckFramebufferStatus for
122 * this combination in the future using
123 * isColorConfigAndStencilFormatVerified().
124 */
125 void markColorConfigAndStencilFormatAsVerified(
126 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700127 const GrGLStencilAttachment::Format& format);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000128
129 /**
130 * Call to check whether color config / stencil format pair has already
131 * passed FBO status check.
132 */
133 bool isColorConfigAndStencilFormatVerified(
134 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700135 const GrGLStencilAttachment::Format& format) const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000136
137 /**
138 * Reports the type of MSAA FBO support.
139 */
140 MSFBOType msFBOType() const { return fMSFBOType; }
141
142 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000143 * Does the supported MSAA FBO extension have MSAA renderbuffers?
144 */
145 bool usesMSAARenderBuffers() const {
146 return kNone_MSFBOType != fMSFBOType &&
147 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
vbuzinovdded6962015-06-12 08:59:45 -0700148 kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
149 kMixedSamples_MSFBOType != fMSFBOType;
bsalomon@google.com347c3822013-05-01 20:10:01 +0000150 }
151
152 /**
153 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
154 * then implicitly resolved when read.
155 */
156 bool usesImplicitMSAAResolve() const {
157 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
158 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
159 }
160
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000161 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
162
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000163 /// What type of buffer mapping is supported?
164 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000165
166 /**
167 * Gets an array of legal stencil formats. These formats are not guaranteed
168 * to be supported by the driver but are legal GLenum names given the GL
169 * version and extensions supported.
170 */
171 const SkTArray<StencilFormat, true>& stencilFormats() const {
172 return fStencilFormats;
173 }
174
175 /// The maximum number of fragment uniform vectors (GLES has min. 16).
176 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
177
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000178 /// maximum number of attribute values per vertex
bsalomon@google.com60da4172012-06-01 19:25:00 +0000179 int maxVertexAttributes() const { return fMaxVertexAttributes; }
180
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000181 /// maximum number of texture units accessible in the fragment shader.
182 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
183
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000184 /// ES requires an extension to support RGBA8 in RenderBufferStorage
185 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
186
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000187 /**
188 * Depending on the ES extensions present the BGRA external format may
189 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
190 * RGBA.
191 */
192 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
193
194 /// GL_ARB_texture_swizzle support
195 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
196
197 /// Is there support for GL_UNPACK_ROW_LENGTH
198 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
199
200 /// Is there support for GL_UNPACK_FLIP_Y
201 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
202
203 /// Is there support for GL_PACK_ROW_LENGTH
204 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
205
206 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
207 bool packFlipYSupport() const { return fPackFlipYSupport; }
208
209 /// Is there support for texture parameter GL_TEXTURE_USAGE
210 bool textureUsageSupport() const { return fTextureUsageSupport; }
211
212 /// Is there support for glTexStorage
213 bool texStorageSupport() const { return fTexStorageSupport; }
214
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000215 /// Is there support for GL_RED and GL_R8
216 bool textureRedSupport() const { return fTextureRedSupport; }
217
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000218 /// Is GL_ARB_IMAGING supported
219 bool imagingSupport() const { return fImagingSupport; }
220
bsalomon@google.com706f6682012-10-23 14:53:55 +0000221 /// Is GL_ARB_fragment_coord_conventions supported?
222 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
223
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000224 /// Is there support for Vertex Array Objects?
225 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
226
cdalton626e1ff2015-06-12 13:56:46 -0700227 /// Is there support for glDraw*Instanced and glVertexAttribDivisor?
228 bool instancedDrawingSupport() const { return fInstancedDrawingSupport; }
229
230 /// Is there support for GL_EXT_direct_state_access?
231 bool directStateAccessSupport() const { return fDirectStateAccessSupport; }
232
233 /// Is there support for GL_KHR_debug?
234 bool debugSupport() const { return fDebugSupport; }
235
jvanverth3f801cb2014-12-16 09:49:38 -0800236 /// Is there support for ES2 compatability?
237 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
238
cdalton0edea2c2015-05-21 08:27:44 -0700239 /// Can we call glDisable(GL_MULTISAMPLE)?
vbuzinovdded6962015-06-12 08:59:45 -0700240 bool multisampleDisableSupport() const {
241 return fMultisampleDisableSupport;
242 }
cdalton0edea2c2015-05-21 08:27:44 -0700243
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000244 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000245 bool useNonVBOVertexAndIndexDynamicData() const {
246 return fUseNonVBOVertexAndIndexDynamicData;
247 }
248
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000249 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000250 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000251 GrGLenum format,
piotaixre4b23142014-10-02 10:57:53 -0700252 GrGLenum type,
253 GrGLenum currFboFormat) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000254
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000255 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000256
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000257
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000258 bool fullClearIsFree() const { return fFullClearIsFree; }
259
joshualittc1f56b52015-06-22 12:31:31 -0700260 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
261
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000262 /**
263 * Returns a string containing the caps info.
264 */
mtklein36352bf2015-03-25 18:17:31 -0700265 SkString dump() const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000266
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000267 /**
268 * LATC can appear under one of three possible names. In order to know
269 * which GL internal format to use, we need to keep track of which name
270 * we found LATC under. The default is LATC.
271 */
272 enum LATCAlias {
273 kLATC_LATCAlias,
274 kRGTC_LATCAlias,
275 k3DC_LATCAlias
276 };
277
278 LATCAlias latcAlias() const { return fLATCAlias; }
279
jvanverthe9c0fc62015-04-29 11:18:05 -0700280 GrGLSLCaps* glslCaps() const { return reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get()); }
281
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000282private:
cdalton4cd67132015-06-10 19:23:46 -0700283 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
kkinnunencfe62e32015-07-01 02:58:50 -0700284 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
bsalomon424cc262015-05-22 10:37:30 -0700285
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000286 /**
287 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
288 * performing glCheckFrameBufferStatus for the same config.
289 */
290 struct VerifiedColorConfigs {
291 VerifiedColorConfigs() {
292 this->reset();
293 }
294
295 void reset() {
296 for (int i = 0; i < kNumUints; ++i) {
297 fVerifiedColorConfigs[i] = 0;
298 }
299 }
300
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +0000301 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000302 uint32_t fVerifiedColorConfigs[kNumUints];
303
304 void markVerified(GrPixelConfig config) {
305#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
306 return;
307#endif
308 int u32Idx = config / 32;
309 int bitIdx = config % 32;
310 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
311 }
312
313 bool isVerified(GrPixelConfig config) const {
314#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
315 return false;
316#endif
317 int u32Idx = config / 32;
318 int bitIdx = config % 32;
319 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
320 }
321 };
322
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000323 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
cdalton1dd05422015-06-12 09:01:18 -0700324 void initBlendEqationSupport(const GrGLContextInfo&);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000325 void initStencilFormats(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000326 // This must be called after initFSAASupport().
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000327 void initConfigRenderableTable(const GrGLContextInfo&);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000328 void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000329
bsalomon17168df2014-12-09 09:00:49 -0800330 bool doReadPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const;
piotaixre4b23142014-10-02 10:57:53 -0700331
jvanverthcba99b82015-06-24 06:59:57 -0700332 void initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
333 const GrGLInterface* intf,
334 GrGLSLCaps* glslCaps);
335
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000336 // tracks configs that have been verified to pass the FBO completeness when
337 // used as a color attachment
338 VerifiedColorConfigs fVerifiedColorConfigs;
339
340 SkTArray<StencilFormat, true> fStencilFormats;
341 // tracks configs that have been verified to pass the FBO completeness when
342 // used as a color attachment when a particular stencil format is used
343 // as a stencil attachment.
344 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
345
346 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000347 int fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000348 int fMaxFragmentTextureUnits;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000349
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000350 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000351 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000352 MapBufferType fMapBufferType;
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000353 LATCAlias fLATCAlias;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000354
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000355 bool fRGBA8RenderbufferSupport : 1;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000356 bool fBGRAIsInternalFormat : 1;
357 bool fTextureSwizzleSupport : 1;
358 bool fUnpackRowLengthSupport : 1;
359 bool fUnpackFlipYSupport : 1;
360 bool fPackRowLengthSupport : 1;
361 bool fPackFlipYSupport : 1;
362 bool fTextureUsageSupport : 1;
363 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000364 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000365 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000366 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000367 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000368 bool fVertexArrayObjectSupport : 1;
cdalton626e1ff2015-06-12 13:56:46 -0700369 bool fInstancedDrawingSupport : 1;
370 bool fDirectStateAccessSupport : 1;
371 bool fDebugSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800372 bool fES2CompatibilitySupport : 1;
cdalton0edea2c2015-05-21 08:27:44 -0700373 bool fMultisampleDisableSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000374 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000375 bool fIsCoreProfile : 1;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000376 bool fFullClearIsFree : 1;
joshualittc1f56b52015-06-22 12:31:31 -0700377 bool fBindFragDataLocationSupport : 1;
joshualitt58162332014-08-01 06:44:53 -0700378
mtklein2aa1f7e2015-02-20 12:35:32 -0800379 struct ReadPixelsSupportedFormat {
380 GrGLenum fFormat;
381 GrGLenum fType;
382 GrGLenum fFboFormat;
piotaixre4b23142014-10-02 10:57:53 -0700383
mtklein2aa1f7e2015-02-20 12:35:32 -0800384 bool operator==(const ReadPixelsSupportedFormat& rhs) const {
385 return fFormat == rhs.fFormat
386 && fType == rhs.fType
387 && fFboFormat == rhs.fFboFormat;
piotaixre4b23142014-10-02 10:57:53 -0700388 }
piotaixre4b23142014-10-02 10:57:53 -0700389 };
mtklein02f46cf2015-03-20 13:48:42 -0700390 mutable SkTHashMap<ReadPixelsSupportedFormat, bool> fReadPixelsSupportedCache;
piotaixre4b23142014-10-02 10:57:53 -0700391
bsalomon4b91f762015-05-19 09:29:46 -0700392 typedef GrCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000393};
394
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000395#endif