2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #ifndef GrGLCaps_DEFINED
10 #define GrGLCaps_DEFINED
12 #include "GrDrawTargetCaps.h"
13 #include "GrGLStencilBuffer.h"
14 #include "SkChecksum.h"
18 class GrGLContextInfo;
21 * Stores some capabilities of a GL context. Most are determined by the GL
22 * version and the extensions string. It also tracks formats that have passed
23 * the FBO completeness test.
25 class GrGLCaps : public GrDrawTargetCaps {
27 SK_DECLARE_INST_COUNT(GrGLCaps)
29 typedef GrGLStencilBuffer::Format StencilFormat;
32 * The type of MSAA for FBOs supported. Different extensions have different
33 * semantics of how / when a resolve is performed.
37 * no support for MSAA FBOs
41 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
43 kDesktop_ARB_MSFBOType,
45 * earlier GL_EXT_framebuffer* extensions
47 kDesktop_EXT_MSFBOType,
49 * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
53 * GL_APPLE_framebuffer_multisample ES extension
57 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
58 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
59 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
60 * GR_GL_MAX_SAMPLES_IMG).
62 kES_IMG_MsToTexture_MSFBOType,
64 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
65 * GL_MAX_SAMPLES value.
67 kES_EXT_MsToTexture_MSFBOType,
69 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType
72 enum InvalidateFBType {
73 kNone_InvalidateFBType,
74 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
75 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
77 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
82 kMapBuffer_MapBufferType, // glMapBuffer()
83 kMapBufferRange_MapBufferType, // glMapBufferRange()
84 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
86 kLast_MapBufferType = kChromium_MapBufferType,
90 * Creates a GrGLCaps that advertises no support for any extensions,
91 * formats, etc. Call init to initialize from a GrGLContextInfo.
95 GrGLCaps(const GrGLCaps& caps);
97 GrGLCaps& operator = (const GrGLCaps& caps);
100 * Resets the caps such that nothing is supported.
102 void reset() SK_OVERRIDE;
105 * Initializes the GrGLCaps to the set of features supported in the current
106 * OpenGL context accessible via ctxInfo.
108 bool init(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface);
111 * Call to note that a color config has been verified as a valid color
112 * attachment. This may save future calls to glCheckFramebufferStatus
113 * using isConfigVerifiedColorAttachment().
115 void markConfigAsValidColorAttachment(GrPixelConfig config) {
116 fVerifiedColorConfigs.markVerified(config);
120 * Call to check whether a config has been verified as a valid color
123 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
124 return fVerifiedColorConfigs.isVerified(config);
128 * Call to note that a color config / stencil format pair passed
129 * FBO status check. We may skip calling glCheckFramebufferStatus for
130 * this combination in the future using
131 * isColorConfigAndStencilFormatVerified().
133 void markColorConfigAndStencilFormatAsVerified(
134 GrPixelConfig config,
135 const GrGLStencilBuffer::Format& format);
138 * Call to check whether color config / stencil format pair has already
139 * passed FBO status check.
141 bool isColorConfigAndStencilFormatVerified(
142 GrPixelConfig config,
143 const GrGLStencilBuffer::Format& format) const;
146 * Reports the type of MSAA FBO support.
148 MSFBOType msFBOType() const { return fMSFBOType; }
151 * Does the supported MSAA FBO extension have MSAA renderbuffers?
153 bool usesMSAARenderBuffers() const {
154 return kNone_MSFBOType != fMSFBOType &&
155 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
156 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
160 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
161 * then implicitly resolved when read.
163 bool usesImplicitMSAAResolve() const {
164 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
165 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
169 * Some helper functions for encapsulating various extensions to read FB Buffer on openglES
171 * TODO(joshualitt) On desktop opengl 4.2+ we can achieve something similar to this effect
173 bool fbFetchSupport() const { return fFBFetchSupport; }
175 bool fbFetchNeedsCustomOutput() const { return fFBFetchNeedsCustomOutput; }
177 const char* fbFetchColorName() const { return fFBFetchColorName; }
179 const char* fbFetchExtensionString() const { return fFBFetchExtensionString; }
181 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
183 /// What type of buffer mapping is supported?
184 MapBufferType mapBufferType() const { return fMapBufferType; }
187 * Gets an array of legal stencil formats. These formats are not guaranteed
188 * to be supported by the driver but are legal GLenum names given the GL
189 * version and extensions supported.
191 const SkTArray<StencilFormat, true>& stencilFormats() const {
192 return fStencilFormats;
195 /// The maximum number of fragment uniform vectors (GLES has min. 16).
196 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
198 /// maximum number of attribute values per vertex
199 int maxVertexAttributes() const { return fMaxVertexAttributes; }
201 /// maximum number of texture units accessible in the fragment shader.
202 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
204 /// maximum number of fixed-function texture coords, or zero if no fixed-function.
205 int maxFixedFunctionTextureCoords() const { return fMaxFixedFunctionTextureCoords; }
207 /// ES requires an extension to support RGBA8 in RenderBufferStorage
208 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
211 * Depending on the ES extensions present the BGRA external format may
212 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
215 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
217 /// GL_ARB_texture_swizzle support
218 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
220 /// Is there support for GL_UNPACK_ROW_LENGTH
221 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
223 /// Is there support for GL_UNPACK_FLIP_Y
224 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
226 /// Is there support for GL_PACK_ROW_LENGTH
227 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
229 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
230 bool packFlipYSupport() const { return fPackFlipYSupport; }
232 /// Is there support for texture parameter GL_TEXTURE_USAGE
233 bool textureUsageSupport() const { return fTextureUsageSupport; }
235 /// Is there support for glTexStorage
236 bool texStorageSupport() const { return fTexStorageSupport; }
238 /// Is there support for GL_RED and GL_R8
239 bool textureRedSupport() const { return fTextureRedSupport; }
241 /// Is GL_ARB_IMAGING supported
242 bool imagingSupport() const { return fImagingSupport; }
244 /// Is GL_ARB_fragment_coord_conventions supported?
245 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
247 /// Is there support for Vertex Array Objects?
248 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
250 /// Is there support for ES2 compatability?
251 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
253 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
254 bool useNonVBOVertexAndIndexDynamicData() const {
255 return fUseNonVBOVertexAndIndexDynamicData;
258 /// Does ReadPixels support the provided format/type combo?
259 bool readPixelsSupported(const GrGLInterface* intf,
262 GrGLenum currFboFormat) const;
264 bool isCoreProfile() const { return fIsCoreProfile; }
267 bool fullClearIsFree() const { return fFullClearIsFree; }
269 bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; }
272 * Returns a string containing the caps info.
274 SkString dump() const SK_OVERRIDE;
277 * LATC can appear under one of three possible names. In order to know
278 * which GL internal format to use, we need to keep track of which name
279 * we found LATC under. The default is LATC.
287 LATCAlias latcAlias() const { return fLATCAlias; }
290 * Which type of path rendering is supported, if any
291 * TODO delete this when we only support normal non-legacy nvpr
299 NvprSupport nvprSupport() const { return fNvprSupport; }
303 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
304 * performing glCheckFrameBufferStatus for the same config.
306 struct VerifiedColorConfigs {
307 VerifiedColorConfigs() {
312 for (int i = 0; i < kNumUints; ++i) {
313 fVerifiedColorConfigs[i] = 0;
317 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
318 uint32_t fVerifiedColorConfigs[kNumUints];
320 void markVerified(GrPixelConfig config) {
321 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
324 int u32Idx = config / 32;
325 int bitIdx = config % 32;
326 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
329 bool isVerified(GrPixelConfig config) const {
330 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
333 int u32Idx = config / 32;
334 int bitIdx = config % 32;
335 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
339 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
340 void initStencilFormats(const GrGLContextInfo&);
341 // This must be called after initFSAASupport().
342 void initConfigRenderableTable(const GrGLContextInfo&);
343 void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*);
345 // Must be called after fGeometryShaderSupport is initialized.
346 void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*);
348 bool doReadPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const;
350 // tracks configs that have been verified to pass the FBO completeness when
351 // used as a color attachment
352 VerifiedColorConfigs fVerifiedColorConfigs;
354 SkTArray<StencilFormat, true> fStencilFormats;
355 // tracks configs that have been verified to pass the FBO completeness when
356 // used as a color attachment when a particular stencil format is used
357 // as a stencil attachment.
358 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
360 int fMaxFragmentUniformVectors;
361 int fMaxVertexAttributes;
362 int fMaxFragmentTextureUnits;
363 int fMaxFixedFunctionTextureCoords;
365 MSFBOType fMSFBOType;
366 InvalidateFBType fInvalidateFBType;
367 MapBufferType fMapBufferType;
368 LATCAlias fLATCAlias;
369 NvprSupport fNvprSupport;
371 bool fRGBA8RenderbufferSupport : 1;
372 bool fBGRAIsInternalFormat : 1;
373 bool fTextureSwizzleSupport : 1;
374 bool fUnpackRowLengthSupport : 1;
375 bool fUnpackFlipYSupport : 1;
376 bool fPackRowLengthSupport : 1;
377 bool fPackFlipYSupport : 1;
378 bool fTextureUsageSupport : 1;
379 bool fTexStorageSupport : 1;
380 bool fTextureRedSupport : 1;
381 bool fImagingSupport : 1;
382 bool fTwoFormatLimit : 1;
383 bool fFragCoordsConventionSupport : 1;
384 bool fVertexArrayObjectSupport : 1;
385 bool fES2CompatibilitySupport : 1;
386 bool fUseNonVBOVertexAndIndexDynamicData : 1;
387 bool fIsCoreProfile : 1;
388 bool fFullClearIsFree : 1;
389 bool fDropsTileOnZeroDivide : 1;
390 bool fFBFetchSupport : 1;
391 bool fFBFetchNeedsCustomOutput : 1;
393 const char* fFBFetchColorName;
394 const char* fFBFetchExtensionString;
396 struct ReadPixelsSupportedFormat {
401 bool operator==(const ReadPixelsSupportedFormat& rhs) const {
402 return fFormat == rhs.fFormat
403 && fType == rhs.fType
404 && fFboFormat == rhs.fFboFormat;
407 mutable SkTHashMap<ReadPixelsSupportedFormat, bool> fReadPixelsSupportedCache;
409 typedef GrDrawTargetCaps INHERITED;