blob: c2d808e4a54bdb63ba5544cdc6a5f2f481f60b1a [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"
15#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
71 enum FBFetchType {
72 kNone_FBFetchType,
73 /** GL_EXT_shader_framebuffer_fetch */
74 kEXT_FBFetchType,
75 /** GL_NV_shader_framebuffer_fetch */
76 kNV_FBFetchType,
77
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000078 kLast_FBFetchType = kNV_FBFetchType
79 };
80
81 enum InvalidateFBType {
82 kNone_InvalidateFBType,
83 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
84 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
85
86 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087 };
88
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000089 enum MapBufferType {
90 kNone_MapBufferType,
91 kMapBuffer_MapBufferType, // glMapBuffer()
92 kMapBufferRange_MapBufferType, // glMapBufferRange()
93 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
94
95 kLast_MapBufferType = kChromium_MapBufferType,
96 };
97
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 /**
99 * Creates a GrGLCaps that advertises no support for any extensions,
100 * formats, etc. Call init to initialize from a GrGLContextInfo.
101 */
102 GrGLCaps();
103
104 GrGLCaps(const GrGLCaps& caps);
105
106 GrGLCaps& operator = (const GrGLCaps& caps);
107
108 /**
109 * Resets the caps such that nothing is supported.
110 */
bsalomon@google.combcce8922013-03-25 15:38:39 +0000111 virtual void reset() SK_OVERRIDE;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112
113 /**
114 * Initializes the GrGLCaps to the set of features supported in the current
115 * OpenGL context accessible via ctxInfo.
116 */
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000117 bool init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000118
119 /**
120 * Call to note that a color config has been verified as a valid color
121 * attachment. This may save future calls to glCheckFramebufferStatus
122 * using isConfigVerifiedColorAttachment().
123 */
124 void markConfigAsValidColorAttachment(GrPixelConfig config) {
125 fVerifiedColorConfigs.markVerified(config);
126 }
127
128 /**
129 * Call to check whether a config has been verified as a valid color
130 * attachment.
131 */
132 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
133 return fVerifiedColorConfigs.isVerified(config);
134 }
135
136 /**
137 * Call to note that a color config / stencil format pair passed
138 * FBO status check. We may skip calling glCheckFramebufferStatus for
139 * this combination in the future using
140 * isColorConfigAndStencilFormatVerified().
141 */
142 void markColorConfigAndStencilFormatAsVerified(
143 GrPixelConfig config,
144 const GrGLStencilBuffer::Format& format);
145
146 /**
147 * Call to check whether color config / stencil format pair has already
148 * passed FBO status check.
149 */
150 bool isColorConfigAndStencilFormatVerified(
151 GrPixelConfig config,
152 const GrGLStencilBuffer::Format& format) const;
153
154 /**
155 * Reports the type of MSAA FBO support.
156 */
157 MSFBOType msFBOType() const { return fMSFBOType; }
158
159 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000160 * Does the supported MSAA FBO extension have MSAA renderbuffers?
161 */
162 bool usesMSAARenderBuffers() const {
163 return kNone_MSFBOType != fMSFBOType &&
164 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
165 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
166 }
167
168 /**
169 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
170 * then implicitly resolved when read.
171 */
172 bool usesImplicitMSAAResolve() const {
173 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
174 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
175 }
176
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000177 FBFetchType fbFetchType() const { return fFBFetchType; }
178
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000179 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
180
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000181 /// What type of buffer mapping is supported?
182 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000183
184 /**
185 * Gets an array of legal stencil formats. These formats are not guaranteed
186 * to be supported by the driver but are legal GLenum names given the GL
187 * version and extensions supported.
188 */
189 const SkTArray<StencilFormat, true>& stencilFormats() const {
190 return fStencilFormats;
191 }
192
193 /// The maximum number of fragment uniform vectors (GLES has min. 16).
194 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
195
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000196 /// maximum number of attribute values per vertex
bsalomon@google.com60da4172012-06-01 19:25:00 +0000197 int maxVertexAttributes() const { return fMaxVertexAttributes; }
198
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000199 /// maximum number of texture units accessible in the fragment shader.
200 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
201
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000202 /// maximum number of fixed-function texture coords, or zero if no fixed-function.
203 int maxFixedFunctionTextureCoords() const { return fMaxFixedFunctionTextureCoords; }
204
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000205 /// ES requires an extension to support RGBA8 in RenderBufferStorage
206 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
207
208 /// Is GL_BGRA supported
209 bool bgraFormatSupport() const { return fBGRAFormatSupport; }
210
211 /**
212 * Depending on the ES extensions present the BGRA external format may
213 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
214 * RGBA.
215 */
216 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
217
218 /// GL_ARB_texture_swizzle support
219 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
220
221 /// Is there support for GL_UNPACK_ROW_LENGTH
222 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
223
224 /// Is there support for GL_UNPACK_FLIP_Y
225 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
226
227 /// Is there support for GL_PACK_ROW_LENGTH
228 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
229
230 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
231 bool packFlipYSupport() const { return fPackFlipYSupport; }
232
233 /// Is there support for texture parameter GL_TEXTURE_USAGE
234 bool textureUsageSupport() const { return fTextureUsageSupport; }
235
236 /// Is there support for glTexStorage
237 bool texStorageSupport() const { return fTexStorageSupport; }
238
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000239 /// Is there support for GL_RED and GL_R8
240 bool textureRedSupport() const { return fTextureRedSupport; }
241
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000242 /// Is GL_ARB_IMAGING supported
243 bool imagingSupport() const { return fImagingSupport; }
244
bsalomon@google.com706f6682012-10-23 14:53:55 +0000245 /// Is GL_ARB_fragment_coord_conventions supported?
246 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
247
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000248 /// Is there support for Vertex Array Objects?
249 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
250
251 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000252 bool useNonVBOVertexAndIndexDynamicData() const {
253 return fUseNonVBOVertexAndIndexDynamicData;
254 }
255
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000256 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000257 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000258 GrGLenum format,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000259 GrGLenum type) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000260
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000261 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000262
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000263
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000264 bool fullClearIsFree() const { return fFullClearIsFree; }
265
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000266 bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; }
267
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000268 /**
269 * Returns a string containing the caps info.
270 */
271 virtual SkString dump() const SK_OVERRIDE;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000272
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000273private:
274 /**
275 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
276 * performing glCheckFrameBufferStatus for the same config.
277 */
278 struct VerifiedColorConfigs {
279 VerifiedColorConfigs() {
280 this->reset();
281 }
282
283 void reset() {
284 for (int i = 0; i < kNumUints; ++i) {
285 fVerifiedColorConfigs[i] = 0;
286 }
287 }
288
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +0000289 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000290 uint32_t fVerifiedColorConfigs[kNumUints];
291
292 void markVerified(GrPixelConfig config) {
293#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
294 return;
295#endif
296 int u32Idx = config / 32;
297 int bitIdx = config % 32;
298 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
299 }
300
301 bool isVerified(GrPixelConfig config) const {
302#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
303 return false;
304#endif
305 int u32Idx = config / 32;
306 int bitIdx = config % 32;
307 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
308 }
309 };
310
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000311 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
312 void initStencilFormats(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000313 // This must be called after initFSAASupport().
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000314 void initConfigRenderableTable(const GrGLContextInfo&);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000315
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000316 void initCompressedTextureSupport(const GrGLContextInfo &);
317
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000318 // tracks configs that have been verified to pass the FBO completeness when
319 // used as a color attachment
320 VerifiedColorConfigs fVerifiedColorConfigs;
321
322 SkTArray<StencilFormat, true> fStencilFormats;
323 // tracks configs that have been verified to pass the FBO completeness when
324 // used as a color attachment when a particular stencil format is used
325 // as a stencil attachment.
326 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
327
328 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000329 int fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000330 int fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000331 int fMaxFixedFunctionTextureCoords;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000332
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000333 MSFBOType fMSFBOType;
334 FBFetchType fFBFetchType;
335 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000336 MapBufferType fMapBufferType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000337
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000338 bool fRGBA8RenderbufferSupport : 1;
339 bool fBGRAFormatSupport : 1;
340 bool fBGRAIsInternalFormat : 1;
341 bool fTextureSwizzleSupport : 1;
342 bool fUnpackRowLengthSupport : 1;
343 bool fUnpackFlipYSupport : 1;
344 bool fPackRowLengthSupport : 1;
345 bool fPackFlipYSupport : 1;
346 bool fTextureUsageSupport : 1;
347 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000348 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000349 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000350 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000351 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000352 bool fVertexArrayObjectSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000353 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000354 bool fIsCoreProfile : 1;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000355 bool fFullClearIsFree : 1;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000356 bool fDropsTileOnZeroDivide : 1;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000357
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000358 typedef GrDrawTargetCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000359};
360
361#endif