blob: a05d2b6faa33d6ecdc638818df8288c724b612b1 [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 /**
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000031 * Represents a supported multisampling/coverage-sampling mode.
32 */
33 struct MSAACoverageMode {
34 // "Coverage samples" includes samples that actually have color, depth,
35 // stencil, ... as well as those that don't (coverage only). All samples
36 // are coverage samples. (We're using the word "coverage sample" to
37 // match the NV extension language.)
38 int fCoverageSampleCnt;
39
40 // Color samples are samples that store data values (color, stencil,
41 // depth) rather than just representing coverage. They are a subset
42 // of coverage samples. (Again the wording was chosen to match the
43 // extension.)
44 int fColorSampleCnt;
45 };
46
47 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000048 * The type of MSAA for FBOs supported. Different extensions have different
49 * semantics of how / when a resolve is performed.
50 */
51 enum MSFBOType {
52 /**
53 * no support for MSAA FBOs
54 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000056 /**
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000057 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000058 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000059 kDesktop_ARB_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060 /**
61 * earlier GL_EXT_framebuffer* extensions
62 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000063 kDesktop_EXT_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000064 /**
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000065 * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
66 */
67 kES_3_0_MSFBOType,
68 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000069 * GL_APPLE_framebuffer_multisample ES extension
70 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000071 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000072 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000073 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
74 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
75 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
76 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000077 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000078 kES_IMG_MsToTexture_MSFBOType,
79 /**
80 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
81 * GL_MAX_SAMPLES value.
82 */
83 kES_EXT_MsToTexture_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000084
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +000085 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000086 };
87
88 enum FBFetchType {
89 kNone_FBFetchType,
90 /** GL_EXT_shader_framebuffer_fetch */
91 kEXT_FBFetchType,
92 /** GL_NV_shader_framebuffer_fetch */
93 kNV_FBFetchType,
94
95 kLast_FBFetchType = kNV_FBFetchType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096 };
97
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000098 enum CoverageAAType {
99 /**
100 * No coverage sample support
101 */
102 kNone_CoverageAAType,
103
104 /**
105 * GL_NV_framebuffer_multisample_coverage
106 */
107 kNVDesktop_CoverageAAType,
108 };
109
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000110 /**
111 * Creates a GrGLCaps that advertises no support for any extensions,
112 * formats, etc. Call init to initialize from a GrGLContextInfo.
113 */
114 GrGLCaps();
115
116 GrGLCaps(const GrGLCaps& caps);
117
118 GrGLCaps& operator = (const GrGLCaps& caps);
119
120 /**
121 * Resets the caps such that nothing is supported.
122 */
bsalomon@google.combcce8922013-03-25 15:38:39 +0000123 virtual void reset() SK_OVERRIDE;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124
125 /**
126 * Initializes the GrGLCaps to the set of features supported in the current
127 * OpenGL context accessible via ctxInfo.
128 */
robertphillips@google.com6177e692013-02-28 20:16:25 +0000129 void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000130
131 /**
132 * Call to note that a color config has been verified as a valid color
133 * attachment. This may save future calls to glCheckFramebufferStatus
134 * using isConfigVerifiedColorAttachment().
135 */
136 void markConfigAsValidColorAttachment(GrPixelConfig config) {
137 fVerifiedColorConfigs.markVerified(config);
138 }
139
140 /**
141 * Call to check whether a config has been verified as a valid color
142 * attachment.
143 */
144 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
145 return fVerifiedColorConfigs.isVerified(config);
146 }
147
148 /**
149 * Call to note that a color config / stencil format pair passed
150 * FBO status check. We may skip calling glCheckFramebufferStatus for
151 * this combination in the future using
152 * isColorConfigAndStencilFormatVerified().
153 */
154 void markColorConfigAndStencilFormatAsVerified(
155 GrPixelConfig config,
156 const GrGLStencilBuffer::Format& format);
157
158 /**
159 * Call to check whether color config / stencil format pair has already
160 * passed FBO status check.
161 */
162 bool isColorConfigAndStencilFormatVerified(
163 GrPixelConfig config,
164 const GrGLStencilBuffer::Format& format) const;
165
166 /**
167 * Reports the type of MSAA FBO support.
168 */
169 MSFBOType msFBOType() const { return fMSFBOType; }
170
171 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000172 * Does the supported MSAA FBO extension have MSAA renderbuffers?
173 */
174 bool usesMSAARenderBuffers() const {
175 return kNone_MSFBOType != fMSFBOType &&
176 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
177 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
178 }
179
180 /**
181 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
182 * then implicitly resolved when read.
183 */
184 bool usesImplicitMSAAResolve() const {
185 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
186 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
187 }
188
189 /**
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000190 * Reports the type of coverage sample AA support.
191 */
192 CoverageAAType coverageAAType() const { return fCoverageAAType; }
193
194 /**
195 * Chooses a supported coverage mode based on a desired sample count. The
196 * desired sample count is rounded up the next supported coverage sample
197 * count unless a it is larger than the max in which case it is rounded
198 * down. Once a coverage sample count is decided, the supported mode with
199 * the fewest color samples is chosen.
200 */
201 const MSAACoverageMode& getMSAACoverageMode(int desiredSampleCount) const;
202
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000203 FBFetchType fbFetchType() const { return fFBFetchType; }
204
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000205 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000206 * Prints the caps info using GrPrintf.
207 */
bsalomon@google.combcce8922013-03-25 15:38:39 +0000208 virtual void print() const SK_OVERRIDE;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000209
210 /**
211 * Gets an array of legal stencil formats. These formats are not guaranteed
212 * to be supported by the driver but are legal GLenum names given the GL
213 * version and extensions supported.
214 */
215 const SkTArray<StencilFormat, true>& stencilFormats() const {
216 return fStencilFormats;
217 }
218
219 /// The maximum number of fragment uniform vectors (GLES has min. 16).
220 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
221
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000222 /// maximum number of attribute values per vertex
bsalomon@google.com60da4172012-06-01 19:25:00 +0000223 int maxVertexAttributes() const { return fMaxVertexAttributes; }
224
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000225 /// maximum number of texture units accessible in the fragment shader.
226 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
227
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000228 /// maximum number of fixed-function texture coords, or zero if no fixed-function.
229 int maxFixedFunctionTextureCoords() const { return fMaxFixedFunctionTextureCoords; }
230
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000231 /// ES requires an extension to support RGBA8 in RenderBufferStorage
232 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
233
234 /// Is GL_BGRA supported
235 bool bgraFormatSupport() const { return fBGRAFormatSupport; }
236
237 /**
238 * Depending on the ES extensions present the BGRA external format may
239 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
240 * RGBA.
241 */
242 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
243
244 /// GL_ARB_texture_swizzle support
245 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
246
247 /// Is there support for GL_UNPACK_ROW_LENGTH
248 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
249
250 /// Is there support for GL_UNPACK_FLIP_Y
251 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
252
253 /// Is there support for GL_PACK_ROW_LENGTH
254 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
255
256 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
257 bool packFlipYSupport() const { return fPackFlipYSupport; }
258
259 /// Is there support for texture parameter GL_TEXTURE_USAGE
260 bool textureUsageSupport() const { return fTextureUsageSupport; }
261
262 /// Is there support for glTexStorage
263 bool texStorageSupport() const { return fTexStorageSupport; }
264
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000265 /// Is there support for GL_RED and GL_R8
266 bool textureRedSupport() const { return fTextureRedSupport; }
267
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000268 /// Is GL_ARB_IMAGING supported
269 bool imagingSupport() const { return fImagingSupport; }
270
bsalomon@google.com706f6682012-10-23 14:53:55 +0000271 /// Is GL_ARB_fragment_coord_conventions supported?
272 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
273
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000274 /// Is there support for Vertex Array Objects?
275 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
276
277 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000278 bool useNonVBOVertexAndIndexDynamicData() const {
279 return fUseNonVBOVertexAndIndexDynamicData;
280 }
281
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000282 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000283 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000284 GrGLenum format,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000285 GrGLenum type) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000286
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000287 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000288
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000289 bool fixedFunctionSupport() const { return fFixedFunctionSupport; }
290
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000291 /// Is there support for discarding the frame buffer
292 bool discardFBSupport() const { return fDiscardFBSupport; }
293
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000294private:
295 /**
296 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
297 * performing glCheckFrameBufferStatus for the same config.
298 */
299 struct VerifiedColorConfigs {
300 VerifiedColorConfigs() {
301 this->reset();
302 }
303
304 void reset() {
305 for (int i = 0; i < kNumUints; ++i) {
306 fVerifiedColorConfigs[i] = 0;
307 }
308 }
309
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +0000310 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000311 uint32_t fVerifiedColorConfigs[kNumUints];
312
313 void markVerified(GrPixelConfig config) {
314#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
315 return;
316#endif
317 int u32Idx = config / 32;
318 int bitIdx = config % 32;
319 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
320 }
321
322 bool isVerified(GrPixelConfig config) const {
323#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
324 return false;
325#endif
326 int u32Idx = config / 32;
327 int bitIdx = config % 32;
328 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
329 }
330 };
331
robertphillips@google.com6177e692013-02-28 20:16:25 +0000332 void initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000333 void initStencilFormats(const GrGLContextInfo& ctxInfo);
334
335 // tracks configs that have been verified to pass the FBO completeness when
336 // used as a color attachment
337 VerifiedColorConfigs fVerifiedColorConfigs;
338
339 SkTArray<StencilFormat, true> fStencilFormats;
340 // tracks configs that have been verified to pass the FBO completeness when
341 // used as a color attachment when a particular stencil format is used
342 // as a stencil attachment.
343 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
344
345 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000346 int fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000347 int fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000348 int fMaxFixedFunctionTextureCoords;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000349
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000350 MSFBOType fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000351 CoverageAAType fCoverageAAType;
352 SkTDArray<MSAACoverageMode> fMSAACoverageModes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000353
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000354 FBFetchType fFBFetchType;
355
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000356 bool fRGBA8RenderbufferSupport : 1;
357 bool fBGRAFormatSupport : 1;
358 bool fBGRAIsInternalFormat : 1;
359 bool fTextureSwizzleSupport : 1;
360 bool fUnpackRowLengthSupport : 1;
361 bool fUnpackFlipYSupport : 1;
362 bool fPackRowLengthSupport : 1;
363 bool fPackFlipYSupport : 1;
364 bool fTextureUsageSupport : 1;
365 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000366 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000367 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000368 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000369 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000370 bool fVertexArrayObjectSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000371 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000372 bool fIsCoreProfile : 1;
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000373 bool fFixedFunctionSupport : 1;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000374 bool fDiscardFBSupport : 1;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000375
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000376 typedef GrDrawTargetCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000377};
378
379#endif