blob: a1d53e30fa3093cfc0f6dca1f7d2a26e9c0f4d8a [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
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000012#include "GrDrawTargetCaps.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070013#include "GrGLStencilAttachment.h"
piotaixre4b23142014-10-02 10:57:53 -070014#include "SkChecksum.h"
mtklein2aa1f7e2015-02-20 12:35:32 -080015#include "SkTHash.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000016#include "SkTArray.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000017
18class GrGLContextInfo;
19
20/**
21 * Stores some capabilities of a GL context. Most are determined by the GL
22 * version and the extensions string. It also tracks formats that have passed
23 * the FBO completeness test.
24 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000025class GrGLCaps : public GrDrawTargetCaps {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026public:
bsalomon@google.combcce8922013-03-25 15:38:39 +000027 SK_DECLARE_INST_COUNT(GrGLCaps)
28
egdaniel8dc7c3a2015-04-16 11:22:42 -070029 typedef GrGLStencilAttachment::Format StencilFormat;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030
31 /**
32 * The type of MSAA for FBOs supported. Different extensions have different
33 * semantics of how / when a resolve is performed.
34 */
35 enum MSFBOType {
36 /**
37 * no support for MSAA FBOs
38 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000039 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000040 /**
skia.committer@gmail.com6fc1b492013-09-06 07:01:45 +000041 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000042 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000043 kDesktop_ARB_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000044 /**
45 * earlier GL_EXT_framebuffer* extensions
46 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000047 kDesktop_EXT_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000048 /**
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000049 * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
50 */
51 kES_3_0_MSFBOType,
52 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000053 * GL_APPLE_framebuffer_multisample ES extension
54 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000055 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000056 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000057 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
58 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
59 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
60 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000061 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000062 kES_IMG_MsToTexture_MSFBOType,
63 /**
64 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
65 * GL_MAX_SAMPLES value.
66 */
67 kES_EXT_MsToTexture_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000068
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +000069 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000070 };
71
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000072 enum InvalidateFBType {
73 kNone_InvalidateFBType,
74 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
75 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
76
77 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000078 };
79
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000080 enum MapBufferType {
81 kNone_MapBufferType,
82 kMapBuffer_MapBufferType, // glMapBuffer()
83 kMapBufferRange_MapBufferType, // glMapBufferRange()
84 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
85
86 kLast_MapBufferType = kChromium_MapBufferType,
87 };
88
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089 /**
90 * Creates a GrGLCaps that advertises no support for any extensions,
91 * formats, etc. Call init to initialize from a GrGLContextInfo.
92 */
93 GrGLCaps();
94
95 GrGLCaps(const GrGLCaps& caps);
96
97 GrGLCaps& operator = (const GrGLCaps& caps);
98
99 /**
100 * Resets the caps such that nothing is supported.
101 */
mtklein36352bf2015-03-25 18:17:31 -0700102 void reset() override;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000103
104 /**
105 * Initializes the GrGLCaps to the set of features supported in the current
106 * OpenGL context accessible via ctxInfo.
107 */
george7c4c63a2014-06-25 12:14:30 -0700108 bool init(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109
110 /**
111 * Call to note that a color config has been verified as a valid color
112 * attachment. This may save future calls to glCheckFramebufferStatus
113 * using isConfigVerifiedColorAttachment().
114 */
115 void markConfigAsValidColorAttachment(GrPixelConfig config) {
116 fVerifiedColorConfigs.markVerified(config);
117 }
118
119 /**
120 * Call to check whether a config has been verified as a valid color
121 * attachment.
122 */
123 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
124 return fVerifiedColorConfigs.isVerified(config);
125 }
126
127 /**
128 * Call to note that a color config / stencil format pair passed
129 * FBO status check. We may skip calling glCheckFramebufferStatus for
130 * this combination in the future using
131 * isColorConfigAndStencilFormatVerified().
132 */
133 void markColorConfigAndStencilFormatAsVerified(
134 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700135 const GrGLStencilAttachment::Format& format);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000136
137 /**
138 * Call to check whether color config / stencil format pair has already
139 * passed FBO status check.
140 */
141 bool isColorConfigAndStencilFormatVerified(
142 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700143 const GrGLStencilAttachment::Format& format) const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000144
145 /**
146 * Reports the type of MSAA FBO support.
147 */
148 MSFBOType msFBOType() const { return fMSFBOType; }
149
150 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000151 * Does the supported MSAA FBO extension have MSAA renderbuffers?
152 */
153 bool usesMSAARenderBuffers() const {
154 return kNone_MSFBOType != fMSFBOType &&
155 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
156 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
157 }
158
159 /**
160 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
161 * then implicitly resolved when read.
162 */
163 bool usesImplicitMSAAResolve() const {
164 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
165 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
166 }
167
joshualitt58162332014-08-01 06:44:53 -0700168 /**
169 * Some helper functions for encapsulating various extensions to read FB Buffer on openglES
170 *
joshualittb4384b92014-10-21 12:53:15 -0700171 * TODO(joshualitt) On desktop opengl 4.2+ we can achieve something similar to this effect
joshualitt58162332014-08-01 06:44:53 -0700172 */
173 bool fbFetchSupport() const { return fFBFetchSupport; }
174
joshualitt3c1096f2015-01-13 13:13:59 -0800175 bool fbFetchNeedsCustomOutput() const { return fFBFetchNeedsCustomOutput; }
176
joshualitt58162332014-08-01 06:44:53 -0700177 const char* fbFetchColorName() const { return fFBFetchColorName; }
178
179 const char* fbFetchExtensionString() const { return fFBFetchExtensionString; }
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000180
vbuzinov08b4d292015-04-01 06:29:49 -0700181 bool fbMixedSamplesSupport() const { return fFBMixedSamplesSupport; }
182
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000183 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
184
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000185 /// What type of buffer mapping is supported?
186 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000187
188 /**
189 * Gets an array of legal stencil formats. These formats are not guaranteed
190 * to be supported by the driver but are legal GLenum names given the GL
191 * version and extensions supported.
192 */
193 const SkTArray<StencilFormat, true>& stencilFormats() const {
194 return fStencilFormats;
195 }
196
197 /// The maximum number of fragment uniform vectors (GLES has min. 16).
198 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
199
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000200 /// maximum number of attribute values per vertex
bsalomon@google.com60da4172012-06-01 19:25:00 +0000201 int maxVertexAttributes() const { return fMaxVertexAttributes; }
202
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000203 /// maximum number of texture units accessible in the fragment shader.
204 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
205
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000206 /// maximum number of fixed-function texture coords, or zero if no fixed-function.
207 int maxFixedFunctionTextureCoords() const { return fMaxFixedFunctionTextureCoords; }
208
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000209 /// ES requires an extension to support RGBA8 in RenderBufferStorage
210 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
211
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000212 /**
213 * Depending on the ES extensions present the BGRA external format may
214 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
215 * RGBA.
216 */
217 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
218
219 /// GL_ARB_texture_swizzle support
220 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
221
222 /// Is there support for GL_UNPACK_ROW_LENGTH
223 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
224
225 /// Is there support for GL_UNPACK_FLIP_Y
226 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
227
228 /// Is there support for GL_PACK_ROW_LENGTH
229 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
230
231 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
232 bool packFlipYSupport() const { return fPackFlipYSupport; }
233
234 /// Is there support for texture parameter GL_TEXTURE_USAGE
235 bool textureUsageSupport() const { return fTextureUsageSupport; }
236
237 /// Is there support for glTexStorage
238 bool texStorageSupport() const { return fTexStorageSupport; }
239
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000240 /// Is there support for GL_RED and GL_R8
241 bool textureRedSupport() const { return fTextureRedSupport; }
242
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000243 /// Is GL_ARB_IMAGING supported
244 bool imagingSupport() const { return fImagingSupport; }
245
bsalomon@google.com706f6682012-10-23 14:53:55 +0000246 /// Is GL_ARB_fragment_coord_conventions supported?
247 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
248
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000249 /// Is there support for Vertex Array Objects?
250 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
251
jvanverth3f801cb2014-12-16 09:49:38 -0800252 /// Is there support for ES2 compatability?
253 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
254
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000255 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000256 bool useNonVBOVertexAndIndexDynamicData() const {
257 return fUseNonVBOVertexAndIndexDynamicData;
258 }
259
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000260 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000261 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000262 GrGLenum format,
piotaixre4b23142014-10-02 10:57:53 -0700263 GrGLenum type,
264 GrGLenum currFboFormat) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000265
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000266 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000267
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000268
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000269 bool fullClearIsFree() const { return fFullClearIsFree; }
270
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000271 bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; }
272
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000273 /**
274 * Returns a string containing the caps info.
275 */
mtklein36352bf2015-03-25 18:17:31 -0700276 SkString dump() const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000277
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000278 /**
279 * LATC can appear under one of three possible names. In order to know
280 * which GL internal format to use, we need to keep track of which name
281 * we found LATC under. The default is LATC.
282 */
283 enum LATCAlias {
284 kLATC_LATCAlias,
285 kRGTC_LATCAlias,
286 k3DC_LATCAlias
287 };
288
289 LATCAlias latcAlias() const { return fLATCAlias; }
290
joshualittabb52a12015-01-13 15:02:10 -0800291 /**
292 * Which type of path rendering is supported, if any
293 * TODO delete this when we only support normal non-legacy nvpr
294 */
295 enum NvprSupport {
296 kNone_NvprSupport,
297 kLegacy_NvprSupport,
298 kNormal_NvprSupport,
299 };
300
301 NvprSupport nvprSupport() const { return fNvprSupport; }
302
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000303private:
304 /**
305 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
306 * performing glCheckFrameBufferStatus for the same config.
307 */
308 struct VerifiedColorConfigs {
309 VerifiedColorConfigs() {
310 this->reset();
311 }
312
313 void reset() {
314 for (int i = 0; i < kNumUints; ++i) {
315 fVerifiedColorConfigs[i] = 0;
316 }
317 }
318
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +0000319 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000320 uint32_t fVerifiedColorConfigs[kNumUints];
321
322 void markVerified(GrPixelConfig config) {
323#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
324 return;
325#endif
326 int u32Idx = config / 32;
327 int bitIdx = config % 32;
328 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
329 }
330
331 bool isVerified(GrPixelConfig config) const {
332#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
333 return false;
334#endif
335 int u32Idx = config / 32;
336 int bitIdx = config % 32;
337 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
338 }
339 };
340
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000341 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
342 void initStencilFormats(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000343 // This must be called after initFSAASupport().
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000344 void initConfigRenderableTable(const GrGLContextInfo&);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000345 void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000346
bsalomon17168df2014-12-09 09:00:49 -0800347 // Must be called after fGeometryShaderSupport is initialized.
348 void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*);
349
350 bool doReadPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const;
piotaixre4b23142014-10-02 10:57:53 -0700351
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000352 // tracks configs that have been verified to pass the FBO completeness when
353 // used as a color attachment
354 VerifiedColorConfigs fVerifiedColorConfigs;
355
356 SkTArray<StencilFormat, true> fStencilFormats;
357 // tracks configs that have been verified to pass the FBO completeness when
358 // used as a color attachment when a particular stencil format is used
359 // as a stencil attachment.
360 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
361
362 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000363 int fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000364 int fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000365 int fMaxFixedFunctionTextureCoords;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000366
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000367 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000368 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000369 MapBufferType fMapBufferType;
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000370 LATCAlias fLATCAlias;
joshualittabb52a12015-01-13 15:02:10 -0800371 NvprSupport fNvprSupport;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000372
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000373 bool fRGBA8RenderbufferSupport : 1;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000374 bool fBGRAIsInternalFormat : 1;
375 bool fTextureSwizzleSupport : 1;
376 bool fUnpackRowLengthSupport : 1;
377 bool fUnpackFlipYSupport : 1;
378 bool fPackRowLengthSupport : 1;
379 bool fPackFlipYSupport : 1;
380 bool fTextureUsageSupport : 1;
381 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000382 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000383 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000384 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000385 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000386 bool fVertexArrayObjectSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800387 bool fES2CompatibilitySupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000388 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000389 bool fIsCoreProfile : 1;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000390 bool fFullClearIsFree : 1;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000391 bool fDropsTileOnZeroDivide : 1;
joshualitt58162332014-08-01 06:44:53 -0700392 bool fFBFetchSupport : 1;
joshualitt3c1096f2015-01-13 13:13:59 -0800393 bool fFBFetchNeedsCustomOutput : 1;
vbuzinov08b4d292015-04-01 06:29:49 -0700394 bool fFBMixedSamplesSupport : 1;
joshualitt58162332014-08-01 06:44:53 -0700395
396 const char* fFBFetchColorName;
397 const char* fFBFetchExtensionString;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000398
mtklein2aa1f7e2015-02-20 12:35:32 -0800399 struct ReadPixelsSupportedFormat {
400 GrGLenum fFormat;
401 GrGLenum fType;
402 GrGLenum fFboFormat;
piotaixre4b23142014-10-02 10:57:53 -0700403
mtklein2aa1f7e2015-02-20 12:35:32 -0800404 bool operator==(const ReadPixelsSupportedFormat& rhs) const {
405 return fFormat == rhs.fFormat
406 && fType == rhs.fType
407 && fFboFormat == rhs.fFboFormat;
piotaixre4b23142014-10-02 10:57:53 -0700408 }
piotaixre4b23142014-10-02 10:57:53 -0700409 };
mtklein02f46cf2015-03-20 13:48:42 -0700410 mutable SkTHashMap<ReadPixelsSupportedFormat, bool> fReadPixelsSupportedCache;
piotaixre4b23142014-10-02 10:57:53 -0700411
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000412 typedef GrDrawTargetCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000413};
414
415#endif