blob: 887e2e9e2ad0067a43902ee868d3dfe6ecae5b0e [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"
13#include "GrGLStencilBuffer.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000014#include "SkTArray.h"
bungemanc7af8122014-07-16 09:10:41 -070015#include "SkTDArray.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000016
17class GrGLContextInfo;
18
19/**
20 * Stores some capabilities of a GL context. Most are determined by the GL
21 * version and the extensions string. It also tracks formats that have passed
22 * the FBO completeness test.
23 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000024class GrGLCaps : public GrDrawTargetCaps {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000025public:
bsalomon@google.combcce8922013-03-25 15:38:39 +000026 SK_DECLARE_INST_COUNT(GrGLCaps)
27
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 typedef GrGLStencilBuffer::Format StencilFormat;
29
30 /**
31 * The type of MSAA for FBOs supported. Different extensions have different
32 * semantics of how / when a resolve is performed.
33 */
34 enum MSFBOType {
35 /**
36 * no support for MSAA FBOs
37 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000038 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000039 /**
skia.committer@gmail.com6fc1b492013-09-06 07:01:45 +000040 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000041 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000042 kDesktop_ARB_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000043 /**
44 * earlier GL_EXT_framebuffer* extensions
45 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000046 kDesktop_EXT_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000047 /**
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000048 * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
49 */
50 kES_3_0_MSFBOType,
51 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000052 * GL_APPLE_framebuffer_multisample ES extension
53 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000054 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000055 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000056 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
57 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
58 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
59 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000060 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000061 kES_IMG_MsToTexture_MSFBOType,
62 /**
63 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
64 * GL_MAX_SAMPLES value.
65 */
66 kES_EXT_MsToTexture_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000067
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +000068 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000069 };
70
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000071 enum InvalidateFBType {
72 kNone_InvalidateFBType,
73 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
74 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
75
76 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000077 };
78
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000079 enum MapBufferType {
80 kNone_MapBufferType,
81 kMapBuffer_MapBufferType, // glMapBuffer()
82 kMapBufferRange_MapBufferType, // glMapBufferRange()
83 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
84
85 kLast_MapBufferType = kChromium_MapBufferType,
86 };
87
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088 /**
89 * Creates a GrGLCaps that advertises no support for any extensions,
90 * formats, etc. Call init to initialize from a GrGLContextInfo.
91 */
92 GrGLCaps();
93
94 GrGLCaps(const GrGLCaps& caps);
95
96 GrGLCaps& operator = (const GrGLCaps& caps);
97
98 /**
99 * Resets the caps such that nothing is supported.
100 */
bsalomon@google.combcce8922013-03-25 15:38:39 +0000101 virtual void reset() SK_OVERRIDE;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000102
103 /**
104 * Initializes the GrGLCaps to the set of features supported in the current
105 * OpenGL context accessible via ctxInfo.
106 */
george7c4c63a2014-06-25 12:14:30 -0700107 bool init(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108
109 /**
110 * Call to note that a color config has been verified as a valid color
111 * attachment. This may save future calls to glCheckFramebufferStatus
112 * using isConfigVerifiedColorAttachment().
113 */
114 void markConfigAsValidColorAttachment(GrPixelConfig config) {
115 fVerifiedColorConfigs.markVerified(config);
116 }
117
118 /**
119 * Call to check whether a config has been verified as a valid color
120 * attachment.
121 */
122 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
123 return fVerifiedColorConfigs.isVerified(config);
124 }
125
126 /**
127 * Call to note that a color config / stencil format pair passed
128 * FBO status check. We may skip calling glCheckFramebufferStatus for
129 * this combination in the future using
130 * isColorConfigAndStencilFormatVerified().
131 */
132 void markColorConfigAndStencilFormatAsVerified(
133 GrPixelConfig config,
134 const GrGLStencilBuffer::Format& format);
135
136 /**
137 * Call to check whether color config / stencil format pair has already
138 * passed FBO status check.
139 */
140 bool isColorConfigAndStencilFormatVerified(
141 GrPixelConfig config,
142 const GrGLStencilBuffer::Format& format) const;
143
144 /**
145 * Reports the type of MSAA FBO support.
146 */
147 MSFBOType msFBOType() const { return fMSFBOType; }
148
149 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000150 * Does the supported MSAA FBO extension have MSAA renderbuffers?
151 */
152 bool usesMSAARenderBuffers() const {
153 return kNone_MSFBOType != fMSFBOType &&
154 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
155 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
156 }
157
158 /**
159 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
160 * then implicitly resolved when read.
161 */
162 bool usesImplicitMSAAResolve() const {
163 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
164 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
165 }
166
joshualitt58162332014-08-01 06:44:53 -0700167 /**
168 * Some helper functions for encapsulating various extensions to read FB Buffer on openglES
169 *
170 * TODO On desktop opengl 4.2+ we can achieve something similar to this effect
171 */
172 bool fbFetchSupport() const { return fFBFetchSupport; }
173
174 const char* fbFetchColorName() const { return fFBFetchColorName; }
175
176 const char* fbFetchExtensionString() const { return fFBFetchExtensionString; }
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000177
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000178 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
179
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000180 /// What type of buffer mapping is supported?
181 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000182
183 /**
184 * Gets an array of legal stencil formats. These formats are not guaranteed
185 * to be supported by the driver but are legal GLenum names given the GL
186 * version and extensions supported.
187 */
188 const SkTArray<StencilFormat, true>& stencilFormats() const {
189 return fStencilFormats;
190 }
191
192 /// The maximum number of fragment uniform vectors (GLES has min. 16).
193 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
194
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000195 /// maximum number of attribute values per vertex
bsalomon@google.com60da4172012-06-01 19:25:00 +0000196 int maxVertexAttributes() const { return fMaxVertexAttributes; }
197
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000198 /// maximum number of texture units accessible in the fragment shader.
199 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
200
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000201 /// maximum number of fixed-function texture coords, or zero if no fixed-function.
202 int maxFixedFunctionTextureCoords() const { return fMaxFixedFunctionTextureCoords; }
203
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000204 /// ES requires an extension to support RGBA8 in RenderBufferStorage
205 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
206
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000207 /**
208 * Depending on the ES extensions present the BGRA external format may
209 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
210 * RGBA.
211 */
212 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
213
214 /// GL_ARB_texture_swizzle support
215 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
216
217 /// Is there support for GL_UNPACK_ROW_LENGTH
218 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
219
220 /// Is there support for GL_UNPACK_FLIP_Y
221 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
222
223 /// Is there support for GL_PACK_ROW_LENGTH
224 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
225
226 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
227 bool packFlipYSupport() const { return fPackFlipYSupport; }
228
229 /// Is there support for texture parameter GL_TEXTURE_USAGE
230 bool textureUsageSupport() const { return fTextureUsageSupport; }
231
232 /// Is there support for glTexStorage
233 bool texStorageSupport() const { return fTexStorageSupport; }
234
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000235 /// Is there support for GL_RED and GL_R8
236 bool textureRedSupport() const { return fTextureRedSupport; }
237
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000238 /// Is GL_ARB_IMAGING supported
239 bool imagingSupport() const { return fImagingSupport; }
240
bsalomon@google.com706f6682012-10-23 14:53:55 +0000241 /// Is GL_ARB_fragment_coord_conventions supported?
242 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
243
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000244 /// Is there support for Vertex Array Objects?
245 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
246
247 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000248 bool useNonVBOVertexAndIndexDynamicData() const {
249 return fUseNonVBOVertexAndIndexDynamicData;
250 }
251
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000252 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000253 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000254 GrGLenum format,
bungemanc7af8122014-07-16 09:10:41 -0700255 GrGLenum type) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000256
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000257 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000258
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000259
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000260 bool fullClearIsFree() const { return fFullClearIsFree; }
261
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000262 bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; }
263
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000264 /**
265 * Returns a string containing the caps info.
266 */
267 virtual SkString dump() const SK_OVERRIDE;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000268
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000269 /**
270 * LATC can appear under one of three possible names. In order to know
271 * which GL internal format to use, we need to keep track of which name
272 * we found LATC under. The default is LATC.
273 */
274 enum LATCAlias {
275 kLATC_LATCAlias,
276 kRGTC_LATCAlias,
277 k3DC_LATCAlias
278 };
279
280 LATCAlias latcAlias() const { return fLATCAlias; }
281
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000282private:
283 /**
284 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
285 * performing glCheckFrameBufferStatus for the same config.
286 */
287 struct VerifiedColorConfigs {
288 VerifiedColorConfigs() {
289 this->reset();
290 }
291
292 void reset() {
293 for (int i = 0; i < kNumUints; ++i) {
294 fVerifiedColorConfigs[i] = 0;
295 }
296 }
297
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +0000298 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000299 uint32_t fVerifiedColorConfigs[kNumUints];
300
301 void markVerified(GrPixelConfig config) {
302#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
303 return;
304#endif
305 int u32Idx = config / 32;
306 int bitIdx = config % 32;
307 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
308 }
309
310 bool isVerified(GrPixelConfig config) const {
311#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
312 return false;
313#endif
314 int u32Idx = config / 32;
315 int bitIdx = config % 32;
316 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
317 }
318 };
319
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000320 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
321 void initStencilFormats(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000322 // This must be called after initFSAASupport().
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000323 void initConfigRenderableTable(const GrGLContextInfo&);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000324 void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000325
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000326 // tracks configs that have been verified to pass the FBO completeness when
327 // used as a color attachment
328 VerifiedColorConfigs fVerifiedColorConfigs;
329
330 SkTArray<StencilFormat, true> fStencilFormats;
331 // tracks configs that have been verified to pass the FBO completeness when
332 // used as a color attachment when a particular stencil format is used
333 // as a stencil attachment.
334 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
335
336 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000337 int fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000338 int fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000339 int fMaxFixedFunctionTextureCoords;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000340
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000341 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000342 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000343 MapBufferType fMapBufferType;
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000344 LATCAlias fLATCAlias;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000345
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000346 bool fRGBA8RenderbufferSupport : 1;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000347 bool fBGRAIsInternalFormat : 1;
348 bool fTextureSwizzleSupport : 1;
349 bool fUnpackRowLengthSupport : 1;
350 bool fUnpackFlipYSupport : 1;
351 bool fPackRowLengthSupport : 1;
352 bool fPackFlipYSupport : 1;
353 bool fTextureUsageSupport : 1;
354 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000355 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000356 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000357 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000358 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000359 bool fVertexArrayObjectSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000360 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000361 bool fIsCoreProfile : 1;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000362 bool fFullClearIsFree : 1;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000363 bool fDropsTileOnZeroDivide : 1;
joshualitt58162332014-08-01 06:44:53 -0700364 bool fFBFetchSupport : 1;
365
366 const char* fFBFetchColorName;
367 const char* fFBFetchExtensionString;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000368
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000369 typedef GrDrawTargetCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000370};
371
372#endif