michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef GrGLCaps_DEFINED michael@0: #define GrGLCaps_DEFINED michael@0: michael@0: #include "GrDrawTargetCaps.h" michael@0: #include "GrGLStencilBuffer.h" michael@0: #include "SkTArray.h" michael@0: #include "SkTDArray.h" michael@0: michael@0: class GrGLContextInfo; michael@0: michael@0: /** michael@0: * Stores some capabilities of a GL context. Most are determined by the GL michael@0: * version and the extensions string. It also tracks formats that have passed michael@0: * the FBO completeness test. michael@0: */ michael@0: class GrGLCaps : public GrDrawTargetCaps { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(GrGLCaps) michael@0: michael@0: typedef GrGLStencilBuffer::Format StencilFormat; michael@0: michael@0: /** michael@0: * The type of MSAA for FBOs supported. Different extensions have different michael@0: * semantics of how / when a resolve is performed. michael@0: */ michael@0: enum MSFBOType { michael@0: /** michael@0: * no support for MSAA FBOs michael@0: */ michael@0: kNone_MSFBOType = 0, michael@0: /** michael@0: * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object). michael@0: */ michael@0: kDesktop_ARB_MSFBOType, michael@0: /** michael@0: * earlier GL_EXT_framebuffer* extensions michael@0: */ michael@0: kDesktop_EXT_MSFBOType, michael@0: /** michael@0: * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer. michael@0: */ michael@0: kES_3_0_MSFBOType, michael@0: /** michael@0: * GL_APPLE_framebuffer_multisample ES extension michael@0: */ michael@0: kES_Apple_MSFBOType, michael@0: /** michael@0: * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers. michael@0: * Instead the texture is multisampled when bound to the FBO and then resolved automatically michael@0: * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call michael@0: * GR_GL_MAX_SAMPLES_IMG). michael@0: */ michael@0: kES_IMG_MsToTexture_MSFBOType, michael@0: /** michael@0: * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard michael@0: * GL_MAX_SAMPLES value. michael@0: */ michael@0: kES_EXT_MsToTexture_MSFBOType, michael@0: michael@0: kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType michael@0: }; michael@0: michael@0: enum FBFetchType { michael@0: kNone_FBFetchType, michael@0: /** GL_EXT_shader_framebuffer_fetch */ michael@0: kEXT_FBFetchType, michael@0: /** GL_NV_shader_framebuffer_fetch */ michael@0: kNV_FBFetchType, michael@0: michael@0: kLast_FBFetchType = kNV_FBFetchType, michael@0: }; michael@0: michael@0: /** michael@0: * Creates a GrGLCaps that advertises no support for any extensions, michael@0: * formats, etc. Call init to initialize from a GrGLContextInfo. michael@0: */ michael@0: GrGLCaps(); michael@0: michael@0: GrGLCaps(const GrGLCaps& caps); michael@0: michael@0: GrGLCaps& operator = (const GrGLCaps& caps); michael@0: michael@0: /** michael@0: * Resets the caps such that nothing is supported. michael@0: */ michael@0: virtual void reset() SK_OVERRIDE; michael@0: michael@0: /** michael@0: * Initializes the GrGLCaps to the set of features supported in the current michael@0: * OpenGL context accessible via ctxInfo. michael@0: */ michael@0: void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface); michael@0: michael@0: /** michael@0: * Call to note that a color config has been verified as a valid color michael@0: * attachment. This may save future calls to glCheckFramebufferStatus michael@0: * using isConfigVerifiedColorAttachment(). michael@0: */ michael@0: void markConfigAsValidColorAttachment(GrPixelConfig config) { michael@0: fVerifiedColorConfigs.markVerified(config); michael@0: } michael@0: michael@0: /** michael@0: * Call to check whether a config has been verified as a valid color michael@0: * attachment. michael@0: */ michael@0: bool isConfigVerifiedColorAttachment(GrPixelConfig config) const { michael@0: return fVerifiedColorConfigs.isVerified(config); michael@0: } michael@0: michael@0: /** michael@0: * Call to note that a color config / stencil format pair passed michael@0: * FBO status check. We may skip calling glCheckFramebufferStatus for michael@0: * this combination in the future using michael@0: * isColorConfigAndStencilFormatVerified(). michael@0: */ michael@0: void markColorConfigAndStencilFormatAsVerified( michael@0: GrPixelConfig config, michael@0: const GrGLStencilBuffer::Format& format); michael@0: michael@0: /** michael@0: * Call to check whether color config / stencil format pair has already michael@0: * passed FBO status check. michael@0: */ michael@0: bool isColorConfigAndStencilFormatVerified( michael@0: GrPixelConfig config, michael@0: const GrGLStencilBuffer::Format& format) const; michael@0: michael@0: /** michael@0: * Reports the type of MSAA FBO support. michael@0: */ michael@0: MSFBOType msFBOType() const { return fMSFBOType; } michael@0: michael@0: /** michael@0: * Does the supported MSAA FBO extension have MSAA renderbuffers? michael@0: */ michael@0: bool usesMSAARenderBuffers() const { michael@0: return kNone_MSFBOType != fMSFBOType && michael@0: kES_IMG_MsToTexture_MSFBOType != fMSFBOType && michael@0: kES_EXT_MsToTexture_MSFBOType != fMSFBOType; michael@0: } michael@0: michael@0: /** michael@0: * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and michael@0: * then implicitly resolved when read. michael@0: */ michael@0: bool usesImplicitMSAAResolve() const { michael@0: return kES_IMG_MsToTexture_MSFBOType == fMSFBOType || michael@0: kES_EXT_MsToTexture_MSFBOType == fMSFBOType; michael@0: } michael@0: michael@0: FBFetchType fbFetchType() const { return fFBFetchType; } michael@0: michael@0: /** michael@0: * Returs a string containeng the caps info. michael@0: */ michael@0: virtual SkString dump() const SK_OVERRIDE; michael@0: michael@0: /** michael@0: * Gets an array of legal stencil formats. These formats are not guaranteed michael@0: * to be supported by the driver but are legal GLenum names given the GL michael@0: * version and extensions supported. michael@0: */ michael@0: const SkTArray& stencilFormats() const { michael@0: return fStencilFormats; michael@0: } michael@0: michael@0: /// The maximum number of fragment uniform vectors (GLES has min. 16). michael@0: int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } michael@0: michael@0: /// maximum number of attribute values per vertex michael@0: int maxVertexAttributes() const { return fMaxVertexAttributes; } michael@0: michael@0: /// maximum number of texture units accessible in the fragment shader. michael@0: int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; } michael@0: michael@0: /// maximum number of fixed-function texture coords, or zero if no fixed-function. michael@0: int maxFixedFunctionTextureCoords() const { return fMaxFixedFunctionTextureCoords; } michael@0: michael@0: /// ES requires an extension to support RGBA8 in RenderBufferStorage michael@0: bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; } michael@0: michael@0: /// Is GL_BGRA supported michael@0: bool bgraFormatSupport() const { return fBGRAFormatSupport; } michael@0: michael@0: /** michael@0: * Depending on the ES extensions present the BGRA external format may michael@0: * correspond either a BGRA or RGBA internalFormat. On desktop GL it is michael@0: * RGBA. michael@0: */ michael@0: bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; } michael@0: michael@0: /// GL_ARB_texture_swizzle support michael@0: bool textureSwizzleSupport() const { return fTextureSwizzleSupport; } michael@0: michael@0: /// Is there support for GL_UNPACK_ROW_LENGTH michael@0: bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; } michael@0: michael@0: /// Is there support for GL_UNPACK_FLIP_Y michael@0: bool unpackFlipYSupport() const { return fUnpackFlipYSupport; } michael@0: michael@0: /// Is there support for GL_PACK_ROW_LENGTH michael@0: bool packRowLengthSupport() const { return fPackRowLengthSupport; } michael@0: michael@0: /// Is there support for GL_PACK_REVERSE_ROW_ORDER michael@0: bool packFlipYSupport() const { return fPackFlipYSupport; } michael@0: michael@0: /// Is there support for texture parameter GL_TEXTURE_USAGE michael@0: bool textureUsageSupport() const { return fTextureUsageSupport; } michael@0: michael@0: /// Is there support for glTexStorage michael@0: bool texStorageSupport() const { return fTexStorageSupport; } michael@0: michael@0: /// Is there support for GL_RED and GL_R8 michael@0: bool textureRedSupport() const { return fTextureRedSupport; } michael@0: michael@0: /// Is GL_ARB_IMAGING supported michael@0: bool imagingSupport() const { return fImagingSupport; } michael@0: michael@0: /// Is GL_ARB_fragment_coord_conventions supported? michael@0: bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; } michael@0: michael@0: /// Is there support for Vertex Array Objects? michael@0: bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; } michael@0: michael@0: /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content. michael@0: bool useNonVBOVertexAndIndexDynamicData() const { michael@0: return fUseNonVBOVertexAndIndexDynamicData; michael@0: } michael@0: michael@0: /// Does ReadPixels support the provided format/type combo? michael@0: bool readPixelsSupported(const GrGLInterface* intf, michael@0: GrGLenum format, michael@0: GrGLenum type) const; michael@0: michael@0: bool isCoreProfile() const { return fIsCoreProfile; } michael@0: michael@0: bool fixedFunctionSupport() const { return fFixedFunctionSupport; } michael@0: michael@0: /// Is there support for discarding the frame buffer michael@0: bool discardFBSupport() const { return fDiscardFBSupport; } michael@0: michael@0: bool fullClearIsFree() const { return fFullClearIsFree; } michael@0: michael@0: private: michael@0: /** michael@0: * Maintains a bit per GrPixelConfig. It is used to avoid redundantly michael@0: * performing glCheckFrameBufferStatus for the same config. michael@0: */ michael@0: struct VerifiedColorConfigs { michael@0: VerifiedColorConfigs() { michael@0: this->reset(); michael@0: } michael@0: michael@0: void reset() { michael@0: for (int i = 0; i < kNumUints; ++i) { michael@0: fVerifiedColorConfigs[i] = 0; michael@0: } michael@0: } michael@0: michael@0: static const int kNumUints = (kGrPixelConfigCnt + 31) / 32; michael@0: uint32_t fVerifiedColorConfigs[kNumUints]; michael@0: michael@0: void markVerified(GrPixelConfig config) { michael@0: #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT michael@0: return; michael@0: #endif michael@0: int u32Idx = config / 32; michael@0: int bitIdx = config % 32; michael@0: fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx; michael@0: } michael@0: michael@0: bool isVerified(GrPixelConfig config) const { michael@0: #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT michael@0: return false; michael@0: #endif michael@0: int u32Idx = config / 32; michael@0: int bitIdx = config % 32; michael@0: return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx)); michael@0: } michael@0: }; michael@0: michael@0: void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*); michael@0: void initStencilFormats(const GrGLContextInfo&); michael@0: // This must be called after initFSAASupport(). michael@0: void initConfigRenderableTable(const GrGLContextInfo&); michael@0: michael@0: // tracks configs that have been verified to pass the FBO completeness when michael@0: // used as a color attachment michael@0: VerifiedColorConfigs fVerifiedColorConfigs; michael@0: michael@0: SkTArray fStencilFormats; michael@0: // tracks configs that have been verified to pass the FBO completeness when michael@0: // used as a color attachment when a particular stencil format is used michael@0: // as a stencil attachment. michael@0: SkTArray fStencilVerifiedColorConfigs; michael@0: michael@0: int fMaxFragmentUniformVectors; michael@0: int fMaxVertexAttributes; michael@0: int fMaxFragmentTextureUnits; michael@0: int fMaxFixedFunctionTextureCoords; michael@0: michael@0: MSFBOType fMSFBOType; michael@0: michael@0: FBFetchType fFBFetchType; michael@0: michael@0: bool fRGBA8RenderbufferSupport : 1; michael@0: bool fBGRAFormatSupport : 1; michael@0: bool fBGRAIsInternalFormat : 1; michael@0: bool fTextureSwizzleSupport : 1; michael@0: bool fUnpackRowLengthSupport : 1; michael@0: bool fUnpackFlipYSupport : 1; michael@0: bool fPackRowLengthSupport : 1; michael@0: bool fPackFlipYSupport : 1; michael@0: bool fTextureUsageSupport : 1; michael@0: bool fTexStorageSupport : 1; michael@0: bool fTextureRedSupport : 1; michael@0: bool fImagingSupport : 1; michael@0: bool fTwoFormatLimit : 1; michael@0: bool fFragCoordsConventionSupport : 1; michael@0: bool fVertexArrayObjectSupport : 1; michael@0: bool fUseNonVBOVertexAndIndexDynamicData : 1; michael@0: bool fIsCoreProfile : 1; michael@0: bool fFixedFunctionSupport : 1; michael@0: bool fDiscardFBSupport : 1; michael@0: bool fFullClearIsFree : 1; michael@0: michael@0: typedef GrDrawTargetCaps INHERITED; michael@0: }; michael@0: michael@0: #endif