blob: ec75a53428bf62ea4475e152a7f50541d7f316b1 [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
12#include "GrGLStencilBuffer.h"
13
14class GrGLContextInfo;
15
16/**
17 * Stores some capabilities of a GL context. Most are determined by the GL
18 * version and the extensions string. It also tracks formats that have passed
19 * the FBO completeness test.
20 */
21class GrGLCaps {
22public:
23 typedef GrGLStencilBuffer::Format StencilFormat;
24
25 /**
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000026 * Represents a supported multisampling/coverage-sampling mode.
27 */
28 struct MSAACoverageMode {
29 // "Coverage samples" includes samples that actually have color, depth,
30 // stencil, ... as well as those that don't (coverage only). All samples
31 // are coverage samples. (We're using the word "coverage sample" to
32 // match the NV extension language.)
33 int fCoverageSampleCnt;
34
35 // Color samples are samples that store data values (color, stencil,
36 // depth) rather than just representing coverage. They are a subset
37 // of coverage samples. (Again the wording was chosen to match the
38 // extension.)
39 int fColorSampleCnt;
40 };
41
42 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000043 * The type of MSAA for FBOs supported. Different extensions have different
44 * semantics of how / when a resolve is performed.
45 */
46 enum MSFBOType {
47 /**
48 * no support for MSAA FBOs
49 */
50 kNone_MSFBOType = 0,
51 /**
52 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object)
53 */
54 kDesktopARB_MSFBOType,
55 /**
56 * earlier GL_EXT_framebuffer* extensions
57 */
58 kDesktopEXT_MSFBOType,
59 /**
60 * GL_APPLE_framebuffer_multisample ES extension
61 */
62 kAppleES_MSFBOType,
63 };
64
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000065 enum CoverageAAType {
66 /**
67 * No coverage sample support
68 */
69 kNone_CoverageAAType,
70
71 /**
72 * GL_NV_framebuffer_multisample_coverage
73 */
74 kNVDesktop_CoverageAAType,
75 };
76
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000077 /**
78 * Creates a GrGLCaps that advertises no support for any extensions,
79 * formats, etc. Call init to initialize from a GrGLContextInfo.
80 */
81 GrGLCaps();
82
83 GrGLCaps(const GrGLCaps& caps);
84
85 GrGLCaps& operator = (const GrGLCaps& caps);
86
87 /**
88 * Resets the caps such that nothing is supported.
89 */
90 void reset();
91
92 /**
93 * Initializes the GrGLCaps to the set of features supported in the current
94 * OpenGL context accessible via ctxInfo.
95 */
96 void init(const GrGLContextInfo& ctxInfo);
97
98 /**
99 * Call to note that a color config has been verified as a valid color
100 * attachment. This may save future calls to glCheckFramebufferStatus
101 * using isConfigVerifiedColorAttachment().
102 */
103 void markConfigAsValidColorAttachment(GrPixelConfig config) {
104 fVerifiedColorConfigs.markVerified(config);
105 }
106
107 /**
108 * Call to check whether a config has been verified as a valid color
109 * attachment.
110 */
111 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
112 return fVerifiedColorConfigs.isVerified(config);
113 }
114
115 /**
116 * Call to note that a color config / stencil format pair passed
117 * FBO status check. We may skip calling glCheckFramebufferStatus for
118 * this combination in the future using
119 * isColorConfigAndStencilFormatVerified().
120 */
121 void markColorConfigAndStencilFormatAsVerified(
122 GrPixelConfig config,
123 const GrGLStencilBuffer::Format& format);
124
125 /**
126 * Call to check whether color config / stencil format pair has already
127 * passed FBO status check.
128 */
129 bool isColorConfigAndStencilFormatVerified(
130 GrPixelConfig config,
131 const GrGLStencilBuffer::Format& format) const;
132
133 /**
134 * Reports the type of MSAA FBO support.
135 */
136 MSFBOType msFBOType() const { return fMSFBOType; }
137
138 /**
bsalomon@google.comf6b070d2012-04-27 14:25:44 +0000139 * Reports the maximum number of samples supported.
140 */
141 int maxSampleCount() const { return fMaxSampleCount; }
142
143 /**
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000144 * Reports the type of coverage sample AA support.
145 */
146 CoverageAAType coverageAAType() const { return fCoverageAAType; }
147
148 /**
149 * Chooses a supported coverage mode based on a desired sample count. The
150 * desired sample count is rounded up the next supported coverage sample
151 * count unless a it is larger than the max in which case it is rounded
152 * down. Once a coverage sample count is decided, the supported mode with
153 * the fewest color samples is chosen.
154 */
155 const MSAACoverageMode& getMSAACoverageMode(int desiredSampleCount) const;
156
157 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000158 * Prints the caps info using GrPrintf.
159 */
160 void print() const;
161
162 /**
163 * Gets an array of legal stencil formats. These formats are not guaranteed
164 * to be supported by the driver but are legal GLenum names given the GL
165 * version and extensions supported.
166 */
167 const SkTArray<StencilFormat, true>& stencilFormats() const {
168 return fStencilFormats;
169 }
170
171 /// The maximum number of fragment uniform vectors (GLES has min. 16).
172 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
173
bsalomon@google.com60da4172012-06-01 19:25:00 +0000174 // maximum number of attribute values per vertex
175 int maxVertexAttributes() const { return fMaxVertexAttributes; }
176
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000177 /// ES requires an extension to support RGBA8 in RenderBufferStorage
178 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
179
180 /// Is GL_BGRA supported
181 bool bgraFormatSupport() const { return fBGRAFormatSupport; }
182
183 /**
184 * Depending on the ES extensions present the BGRA external format may
185 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
186 * RGBA.
187 */
188 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
189
190 /// GL_ARB_texture_swizzle support
191 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
192
193 /// Is there support for GL_UNPACK_ROW_LENGTH
194 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
195
196 /// Is there support for GL_UNPACK_FLIP_Y
197 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
198
199 /// Is there support for GL_PACK_ROW_LENGTH
200 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
201
202 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
203 bool packFlipYSupport() const { return fPackFlipYSupport; }
204
205 /// Is there support for texture parameter GL_TEXTURE_USAGE
206 bool textureUsageSupport() const { return fTextureUsageSupport; }
207
208 /// Is there support for glTexStorage
209 bool texStorageSupport() const { return fTexStorageSupport; }
210
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000211 /// Is there support for GL_RED and GL_R8
212 bool textureRedSupport() const { return fTextureRedSupport; }
213
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000214 /// Is GL_ARB_IMAGING supported
215 bool imagingSupport() const { return fImagingSupport; }
216
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000217private:
218 /**
219 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
220 * performing glCheckFrameBufferStatus for the same config.
221 */
222 struct VerifiedColorConfigs {
223 VerifiedColorConfigs() {
224 this->reset();
225 }
226
227 void reset() {
228 for (int i = 0; i < kNumUints; ++i) {
229 fVerifiedColorConfigs[i] = 0;
230 }
231 }
232
233 static const int kNumUints = (kGrPixelConfigCount + 31) / 32;
234 uint32_t fVerifiedColorConfigs[kNumUints];
235
236 void markVerified(GrPixelConfig config) {
237#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
238 return;
239#endif
240 int u32Idx = config / 32;
241 int bitIdx = config % 32;
242 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
243 }
244
245 bool isVerified(GrPixelConfig config) const {
246#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
247 return false;
248#endif
249 int u32Idx = config / 32;
250 int bitIdx = config % 32;
251 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
252 }
253 };
254
255 void initFSAASupport(const GrGLContextInfo& ctxInfo);
256 void initStencilFormats(const GrGLContextInfo& ctxInfo);
257
258 // tracks configs that have been verified to pass the FBO completeness when
259 // used as a color attachment
260 VerifiedColorConfigs fVerifiedColorConfigs;
261
262 SkTArray<StencilFormat, true> fStencilFormats;
263 // tracks configs that have been verified to pass the FBO completeness when
264 // used as a color attachment when a particular stencil format is used
265 // as a stencil attachment.
266 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
267
268 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000269 int fMaxVertexAttributes;
270
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000271 MSFBOType fMSFBOType;
bsalomon@google.comf6b070d2012-04-27 14:25:44 +0000272 int fMaxSampleCount;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000273 CoverageAAType fCoverageAAType;
274 SkTDArray<MSAACoverageMode> fMSAACoverageModes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000275
276 bool fRGBA8RenderbufferSupport : 1;
277 bool fBGRAFormatSupport : 1;
278 bool fBGRAIsInternalFormat : 1;
279 bool fTextureSwizzleSupport : 1;
280 bool fUnpackRowLengthSupport : 1;
281 bool fUnpackFlipYSupport : 1;
282 bool fPackRowLengthSupport : 1;
283 bool fPackFlipYSupport : 1;
284 bool fTextureUsageSupport : 1;
285 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000286 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000287 bool fImagingSupport : 1;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000288};
289
290#endif