blob: 0b625a5a3a689d6cece0c24c2f0ad52b20f66861 [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 /**
57 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object)
58 */
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 /**
65 * GL_APPLE_framebuffer_multisample ES extension
66 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000067 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000068 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000069 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
70 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
71 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
72 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000073 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000074 kES_IMG_MsToTexture_MSFBOType,
75 /**
76 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
77 * GL_MAX_SAMPLES value.
78 */
79 kES_EXT_MsToTexture_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000080
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +000081 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000082 };
83
84 enum FBFetchType {
85 kNone_FBFetchType,
86 /** GL_EXT_shader_framebuffer_fetch */
87 kEXT_FBFetchType,
88 /** GL_NV_shader_framebuffer_fetch */
89 kNV_FBFetchType,
90
91 kLast_FBFetchType = kNV_FBFetchType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000092 };
93
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000094 enum CoverageAAType {
95 /**
96 * No coverage sample support
97 */
98 kNone_CoverageAAType,
99
100 /**
101 * GL_NV_framebuffer_multisample_coverage
102 */
103 kNVDesktop_CoverageAAType,
104 };
105
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000106 /**
107 * Creates a GrGLCaps that advertises no support for any extensions,
108 * formats, etc. Call init to initialize from a GrGLContextInfo.
109 */
110 GrGLCaps();
111
112 GrGLCaps(const GrGLCaps& caps);
113
114 GrGLCaps& operator = (const GrGLCaps& caps);
115
116 /**
117 * Resets the caps such that nothing is supported.
118 */
bsalomon@google.combcce8922013-03-25 15:38:39 +0000119 virtual void reset() SK_OVERRIDE;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000120
121 /**
122 * Initializes the GrGLCaps to the set of features supported in the current
123 * OpenGL context accessible via ctxInfo.
124 */
robertphillips@google.com6177e692013-02-28 20:16:25 +0000125 void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000126
127 /**
128 * Call to note that a color config has been verified as a valid color
129 * attachment. This may save future calls to glCheckFramebufferStatus
130 * using isConfigVerifiedColorAttachment().
131 */
132 void markConfigAsValidColorAttachment(GrPixelConfig config) {
133 fVerifiedColorConfigs.markVerified(config);
134 }
135
136 /**
137 * Call to check whether a config has been verified as a valid color
138 * attachment.
139 */
140 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
141 return fVerifiedColorConfigs.isVerified(config);
142 }
143
144 /**
145 * Call to note that a color config / stencil format pair passed
146 * FBO status check. We may skip calling glCheckFramebufferStatus for
147 * this combination in the future using
148 * isColorConfigAndStencilFormatVerified().
149 */
150 void markColorConfigAndStencilFormatAsVerified(
151 GrPixelConfig config,
152 const GrGLStencilBuffer::Format& format);
153
154 /**
155 * Call to check whether color config / stencil format pair has already
156 * passed FBO status check.
157 */
158 bool isColorConfigAndStencilFormatVerified(
159 GrPixelConfig config,
160 const GrGLStencilBuffer::Format& format) const;
161
162 /**
163 * Reports the type of MSAA FBO support.
164 */
165 MSFBOType msFBOType() const { return fMSFBOType; }
166
167 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000168 * Does the supported MSAA FBO extension have MSAA renderbuffers?
169 */
170 bool usesMSAARenderBuffers() const {
171 return kNone_MSFBOType != fMSFBOType &&
172 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
173 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
174 }
175
176 /**
177 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
178 * then implicitly resolved when read.
179 */
180 bool usesImplicitMSAAResolve() const {
181 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
182 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
183 }
184
185 /**
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000186 * Reports the type of coverage sample AA support.
187 */
188 CoverageAAType coverageAAType() const { return fCoverageAAType; }
189
190 /**
191 * Chooses a supported coverage mode based on a desired sample count. The
192 * desired sample count is rounded up the next supported coverage sample
193 * count unless a it is larger than the max in which case it is rounded
194 * down. Once a coverage sample count is decided, the supported mode with
195 * the fewest color samples is chosen.
196 */
197 const MSAACoverageMode& getMSAACoverageMode(int desiredSampleCount) const;
198
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000199 FBFetchType fbFetchType() const { return fFBFetchType; }
200
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000201 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000202 * Prints the caps info using GrPrintf.
203 */
bsalomon@google.combcce8922013-03-25 15:38:39 +0000204 virtual void print() const SK_OVERRIDE;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000205
206 /**
207 * Gets an array of legal stencil formats. These formats are not guaranteed
208 * to be supported by the driver but are legal GLenum names given the GL
209 * version and extensions supported.
210 */
211 const SkTArray<StencilFormat, true>& stencilFormats() const {
212 return fStencilFormats;
213 }
214
215 /// The maximum number of fragment uniform vectors (GLES has min. 16).
216 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
217
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000218 /// maximum number of attribute values per vertex
bsalomon@google.com60da4172012-06-01 19:25:00 +0000219 int maxVertexAttributes() const { return fMaxVertexAttributes; }
220
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000221 /// maximum number of texture units accessible in the fragment shader.
222 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
223
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000224 /// ES requires an extension to support RGBA8 in RenderBufferStorage
225 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
226
227 /// Is GL_BGRA supported
228 bool bgraFormatSupport() const { return fBGRAFormatSupport; }
229
230 /**
231 * Depending on the ES extensions present the BGRA external format may
232 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
233 * RGBA.
234 */
235 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
236
237 /// GL_ARB_texture_swizzle support
238 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
239
240 /// Is there support for GL_UNPACK_ROW_LENGTH
241 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
242
243 /// Is there support for GL_UNPACK_FLIP_Y
244 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
245
246 /// Is there support for GL_PACK_ROW_LENGTH
247 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
248
249 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
250 bool packFlipYSupport() const { return fPackFlipYSupport; }
251
252 /// Is there support for texture parameter GL_TEXTURE_USAGE
253 bool textureUsageSupport() const { return fTextureUsageSupport; }
254
255 /// Is there support for glTexStorage
256 bool texStorageSupport() const { return fTexStorageSupport; }
257
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000258 /// Is there support for GL_RED and GL_R8
259 bool textureRedSupport() const { return fTextureRedSupport; }
260
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000261 /// Is GL_ARB_IMAGING supported
262 bool imagingSupport() const { return fImagingSupport; }
263
bsalomon@google.com706f6682012-10-23 14:53:55 +0000264 /// Is GL_ARB_fragment_coord_conventions supported?
265 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
266
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000267 /// Is there support for Vertex Array Objects?
268 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
269
270 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000271 bool useNonVBOVertexAndIndexDynamicData() const {
272 return fUseNonVBOVertexAndIndexDynamicData;
273 }
274
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000275 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000276 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000277 GrGLenum format,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000278 GrGLenum type) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000279
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000280 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000281
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000282 /// Is there support for discarding the frame buffer
283 bool discardFBSupport() const { return fDiscardFBSupport; }
284
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000285private:
286 /**
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
robertphillips@google.com6177e692013-02-28 20:16:25 +0000323 void initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000324 void initStencilFormats(const GrGLContextInfo& ctxInfo);
325
326 // 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;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000339
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000340 MSFBOType fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000341 CoverageAAType fCoverageAAType;
342 SkTDArray<MSAACoverageMode> fMSAACoverageModes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000343
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000344 FBFetchType fFBFetchType;
345
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000346 bool fRGBA8RenderbufferSupport : 1;
347 bool fBGRAFormatSupport : 1;
348 bool fBGRAIsInternalFormat : 1;
349 bool fTextureSwizzleSupport : 1;
350 bool fUnpackRowLengthSupport : 1;
351 bool fUnpackFlipYSupport : 1;
352 bool fPackRowLengthSupport : 1;
353 bool fPackFlipYSupport : 1;
354 bool fTextureUsageSupport : 1;
355 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000356 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000357 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000358 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000359 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000360 bool fVertexArrayObjectSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000361 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000362 bool fIsCoreProfile : 1;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000363 bool fDiscardFBSupport : 1;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000364
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000365 typedef GrDrawTargetCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000366};
367
368#endif