blob: 83f4650c975ab7b7c6017b3b6a5cddb8f24995ac [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
robertphillips@google.coma2d71482012-08-01 20:08:47 +000012#include "SkTArray.h"
13#include "SkTDArray.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000014#include "GrGLStencilBuffer.h"
15
16class GrGLContextInfo;
17
18/**
19 * Stores some capabilities of a GL context. Most are determined by the GL
20 * version and the extensions string. It also tracks formats that have passed
21 * the FBO completeness test.
22 */
23class GrGLCaps {
24public:
25 typedef GrGLStencilBuffer::Format StencilFormat;
26
27 /**
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000028 * Represents a supported multisampling/coverage-sampling mode.
29 */
30 struct MSAACoverageMode {
31 // "Coverage samples" includes samples that actually have color, depth,
32 // stencil, ... as well as those that don't (coverage only). All samples
33 // are coverage samples. (We're using the word "coverage sample" to
34 // match the NV extension language.)
35 int fCoverageSampleCnt;
36
37 // Color samples are samples that store data values (color, stencil,
38 // depth) rather than just representing coverage. They are a subset
39 // of coverage samples. (Again the wording was chosen to match the
40 // extension.)
41 int fColorSampleCnt;
42 };
43
44 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000045 * The type of MSAA for FBOs supported. Different extensions have different
46 * semantics of how / when a resolve is performed.
47 */
48 enum MSFBOType {
49 /**
50 * no support for MSAA FBOs
51 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000052 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000053 /**
54 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object)
55 */
56 kDesktopARB_MSFBOType,
57 /**
58 * earlier GL_EXT_framebuffer* extensions
59 */
60 kDesktopEXT_MSFBOType,
61 /**
62 * GL_APPLE_framebuffer_multisample ES extension
63 */
64 kAppleES_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000065 /**
66 * GL_IMG_multisampled_render_to_texture
67 */
68 kImaginationES_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000069 };
70
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000071 enum CoverageAAType {
72 /**
73 * No coverage sample support
74 */
75 kNone_CoverageAAType,
76
77 /**
78 * GL_NV_framebuffer_multisample_coverage
79 */
80 kNVDesktop_CoverageAAType,
81 };
82
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000083 /**
84 * Creates a GrGLCaps that advertises no support for any extensions,
85 * formats, etc. Call init to initialize from a GrGLContextInfo.
86 */
87 GrGLCaps();
88
89 GrGLCaps(const GrGLCaps& caps);
90
91 GrGLCaps& operator = (const GrGLCaps& caps);
92
93 /**
94 * Resets the caps such that nothing is supported.
95 */
96 void reset();
97
98 /**
99 * Initializes the GrGLCaps to the set of features supported in the current
100 * OpenGL context accessible via ctxInfo.
101 */
robertphillips@google.com6177e692013-02-28 20:16:25 +0000102 void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000103
104 /**
105 * Call to note that a color config has been verified as a valid color
106 * attachment. This may save future calls to glCheckFramebufferStatus
107 * using isConfigVerifiedColorAttachment().
108 */
109 void markConfigAsValidColorAttachment(GrPixelConfig config) {
110 fVerifiedColorConfigs.markVerified(config);
111 }
112
113 /**
114 * Call to check whether a config has been verified as a valid color
115 * attachment.
116 */
117 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
118 return fVerifiedColorConfigs.isVerified(config);
119 }
120
121 /**
122 * Call to note that a color config / stencil format pair passed
123 * FBO status check. We may skip calling glCheckFramebufferStatus for
124 * this combination in the future using
125 * isColorConfigAndStencilFormatVerified().
126 */
127 void markColorConfigAndStencilFormatAsVerified(
128 GrPixelConfig config,
129 const GrGLStencilBuffer::Format& format);
130
131 /**
132 * Call to check whether color config / stencil format pair has already
133 * passed FBO status check.
134 */
135 bool isColorConfigAndStencilFormatVerified(
136 GrPixelConfig config,
137 const GrGLStencilBuffer::Format& format) const;
138
139 /**
140 * Reports the type of MSAA FBO support.
141 */
142 MSFBOType msFBOType() const { return fMSFBOType; }
143
144 /**
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000145 * Reports the type of coverage sample AA support.
146 */
147 CoverageAAType coverageAAType() const { return fCoverageAAType; }
148
149 /**
150 * Chooses a supported coverage mode based on a desired sample count. The
151 * desired sample count is rounded up the next supported coverage sample
152 * count unless a it is larger than the max in which case it is rounded
153 * down. Once a coverage sample count is decided, the supported mode with
154 * the fewest color samples is chosen.
155 */
156 const MSAACoverageMode& getMSAACoverageMode(int desiredSampleCount) const;
157
158 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000159 * Prints the caps info using GrPrintf.
160 */
161 void print() const;
162
163 /**
164 * Gets an array of legal stencil formats. These formats are not guaranteed
165 * to be supported by the driver but are legal GLenum names given the GL
166 * version and extensions supported.
167 */
168 const SkTArray<StencilFormat, true>& stencilFormats() const {
169 return fStencilFormats;
170 }
171
172 /// The maximum number of fragment uniform vectors (GLES has min. 16).
173 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
174
bsalomon@google.com60da4172012-06-01 19:25:00 +0000175 // maximum number of attribute values per vertex
176 int maxVertexAttributes() const { return fMaxVertexAttributes; }
177
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000178 /// ES requires an extension to support RGBA8 in RenderBufferStorage
179 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
180
181 /// Is GL_BGRA supported
182 bool bgraFormatSupport() const { return fBGRAFormatSupport; }
183
184 /**
185 * Depending on the ES extensions present the BGRA external format may
186 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
187 * RGBA.
188 */
189 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
190
191 /// GL_ARB_texture_swizzle support
192 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
193
194 /// Is there support for GL_UNPACK_ROW_LENGTH
195 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
196
197 /// Is there support for GL_UNPACK_FLIP_Y
198 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
199
200 /// Is there support for GL_PACK_ROW_LENGTH
201 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
202
203 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
204 bool packFlipYSupport() const { return fPackFlipYSupport; }
205
206 /// Is there support for texture parameter GL_TEXTURE_USAGE
207 bool textureUsageSupport() const { return fTextureUsageSupport; }
208
209 /// Is there support for glTexStorage
210 bool texStorageSupport() const { return fTexStorageSupport; }
211
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000212 /// Is there support for GL_RED and GL_R8
213 bool textureRedSupport() const { return fTextureRedSupport; }
214
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000215 /// Is GL_ARB_IMAGING supported
216 bool imagingSupport() const { return fImagingSupport; }
217
bsalomon@google.com706f6682012-10-23 14:53:55 +0000218 /// Is GL_ARB_fragment_coord_conventions supported?
219 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
220
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000221 /// Is there support for Vertex Array Objects?
222 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
223
224 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000225 bool useNonVBOVertexAndIndexDynamicData() const {
226 return fUseNonVBOVertexAndIndexDynamicData;
227 }
228
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000229 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000230 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000231 GrGLenum format,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000232 GrGLenum type) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000233
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000234 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000235
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000236private:
237 /**
238 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
239 * performing glCheckFrameBufferStatus for the same config.
240 */
241 struct VerifiedColorConfigs {
242 VerifiedColorConfigs() {
243 this->reset();
244 }
245
246 void reset() {
247 for (int i = 0; i < kNumUints; ++i) {
248 fVerifiedColorConfigs[i] = 0;
249 }
250 }
251
252 static const int kNumUints = (kGrPixelConfigCount + 31) / 32;
253 uint32_t fVerifiedColorConfigs[kNumUints];
254
255 void markVerified(GrPixelConfig config) {
256#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
257 return;
258#endif
259 int u32Idx = config / 32;
260 int bitIdx = config % 32;
261 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
262 }
263
264 bool isVerified(GrPixelConfig config) const {
265#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
266 return false;
267#endif
268 int u32Idx = config / 32;
269 int bitIdx = config % 32;
270 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
271 }
272 };
273
robertphillips@google.com6177e692013-02-28 20:16:25 +0000274 void initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000275 void initStencilFormats(const GrGLContextInfo& ctxInfo);
276
277 // tracks configs that have been verified to pass the FBO completeness when
278 // used as a color attachment
279 VerifiedColorConfigs fVerifiedColorConfigs;
280
281 SkTArray<StencilFormat, true> fStencilFormats;
282 // tracks configs that have been verified to pass the FBO completeness when
283 // used as a color attachment when a particular stencil format is used
284 // as a stencil attachment.
285 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
286
287 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000288 int fMaxVertexAttributes;
289
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000290 MSFBOType fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000291 CoverageAAType fCoverageAAType;
292 SkTDArray<MSAACoverageMode> fMSAACoverageModes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000293
294 bool fRGBA8RenderbufferSupport : 1;
295 bool fBGRAFormatSupport : 1;
296 bool fBGRAIsInternalFormat : 1;
297 bool fTextureSwizzleSupport : 1;
298 bool fUnpackRowLengthSupport : 1;
299 bool fUnpackFlipYSupport : 1;
300 bool fPackRowLengthSupport : 1;
301 bool fPackFlipYSupport : 1;
302 bool fTextureUsageSupport : 1;
303 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000304 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000305 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000306 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000307 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000308 bool fVertexArrayObjectSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000309 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000310 bool fIsCoreProfile : 1;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000311};
312
313#endif