1 2 /* 3 * Copyright 2012 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #ifndef GrGLCaps_DEFINED 11 #define GrGLCaps_DEFINED 12 13 #include "GrGLStencilBuffer.h" 14 15 class GrGLContextInfo; 16 17 /** 18 * Stores some capabilities of a GL context. Most are determined by the GL 19 * version and the extensions string. It also tracks formats that have passed 20 * the FBO completeness test. 21 */ 22 class GrGLCaps { 23 public: 24 typedef GrGLStencilBuffer::Format StencilFormat; 25 26 /** 27 * The type of MSAA for FBOs supported. Different extensions have different 28 * semantics of how / when a resolve is performed. 29 */ 30 enum MSFBOType { 31 /** 32 * no support for MSAA FBOs 33 */ 34 kNone_MSFBOType = 0, 35 /** 36 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object) 37 */ 38 kDesktopARB_MSFBOType, 39 /** 40 * earlier GL_EXT_framebuffer* extensions 41 */ 42 kDesktopEXT_MSFBOType, 43 /** 44 * GL_APPLE_framebuffer_multisample ES extension 45 */ 46 kAppleES_MSFBOType, 47 }; 48 49 /** 50 * Creates a GrGLCaps that advertises no support for any extensions, 51 * formats, etc. Call init to initialize from a GrGLContextInfo. 52 */ 53 GrGLCaps(); 54 55 GrGLCaps(const GrGLCaps& caps); 56 57 GrGLCaps& operator = (const GrGLCaps& caps); 58 59 /** 60 * Resets the caps such that nothing is supported. 61 */ 62 void reset(); 63 64 /** 65 * Initializes the GrGLCaps to the set of features supported in the current 66 * OpenGL context accessible via ctxInfo. 67 */ 68 void init(const GrGLContextInfo& ctxInfo); 69 70 /** 71 * Call to note that a color config has been verified as a valid color 72 * attachment. This may save future calls to glCheckFramebufferStatus 73 * using isConfigVerifiedColorAttachment(). 74 */ markConfigAsValidColorAttachment(GrPixelConfig config)75 void markConfigAsValidColorAttachment(GrPixelConfig config) { 76 fVerifiedColorConfigs.markVerified(config); 77 } 78 79 /** 80 * Call to check whether a config has been verified as a valid color 81 * attachment. 82 */ isConfigVerifiedColorAttachment(GrPixelConfig config)83 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const { 84 return fVerifiedColorConfigs.isVerified(config); 85 } 86 87 /** 88 * Call to note that a color config / stencil format pair passed 89 * FBO status check. We may skip calling glCheckFramebufferStatus for 90 * this combination in the future using 91 * isColorConfigAndStencilFormatVerified(). 92 */ 93 void markColorConfigAndStencilFormatAsVerified( 94 GrPixelConfig config, 95 const GrGLStencilBuffer::Format& format); 96 97 /** 98 * Call to check whether color config / stencil format pair has already 99 * passed FBO status check. 100 */ 101 bool isColorConfigAndStencilFormatVerified( 102 GrPixelConfig config, 103 const GrGLStencilBuffer::Format& format) const; 104 105 /** 106 * Reports the type of MSAA FBO support. 107 */ msFBOType()108 MSFBOType msFBOType() const { return fMSFBOType; } 109 110 /** 111 * Prints the caps info using GrPrintf. 112 */ 113 void print() const; 114 115 /** 116 * Gets an array of legal stencil formats. These formats are not guaranteed 117 * to be supported by the driver but are legal GLenum names given the GL 118 * version and extensions supported. 119 */ stencilFormats()120 const SkTArray<StencilFormat, true>& stencilFormats() const { 121 return fStencilFormats; 122 } 123 124 /// The maximum number of fragment uniform vectors (GLES has min. 16). maxFragmentUniformVectors()125 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } 126 127 /// ES requires an extension to support RGBA8 in RenderBufferStorage rgba8RenderbufferSupport()128 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; } 129 130 /// Is GL_BGRA supported bgraFormatSupport()131 bool bgraFormatSupport() const { return fBGRAFormatSupport; } 132 133 /** 134 * Depending on the ES extensions present the BGRA external format may 135 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is 136 * RGBA. 137 */ bgraIsInternalFormat()138 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; } 139 140 /// GL_ARB_texture_swizzle support textureSwizzleSupport()141 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; } 142 143 /// Is there support for GL_UNPACK_ROW_LENGTH unpackRowLengthSupport()144 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; } 145 146 /// Is there support for GL_UNPACK_FLIP_Y unpackFlipYSupport()147 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; } 148 149 /// Is there support for GL_PACK_ROW_LENGTH packRowLengthSupport()150 bool packRowLengthSupport() const { return fPackRowLengthSupport; } 151 152 /// Is there support for GL_PACK_REVERSE_ROW_ORDER packFlipYSupport()153 bool packFlipYSupport() const { return fPackFlipYSupport; } 154 155 /// Is there support for texture parameter GL_TEXTURE_USAGE textureUsageSupport()156 bool textureUsageSupport() const { return fTextureUsageSupport; } 157 158 /// Is there support for glTexStorage texStorageSupport()159 bool texStorageSupport() const { return fTexStorageSupport; } 160 161 private: 162 /** 163 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly 164 * performing glCheckFrameBufferStatus for the same config. 165 */ 166 struct VerifiedColorConfigs { VerifiedColorConfigsVerifiedColorConfigs167 VerifiedColorConfigs() { 168 this->reset(); 169 } 170 resetVerifiedColorConfigs171 void reset() { 172 for (int i = 0; i < kNumUints; ++i) { 173 fVerifiedColorConfigs[i] = 0; 174 } 175 } 176 177 static const int kNumUints = (kGrPixelConfigCount + 31) / 32; 178 uint32_t fVerifiedColorConfigs[kNumUints]; 179 markVerifiedVerifiedColorConfigs180 void markVerified(GrPixelConfig config) { 181 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 182 return; 183 #endif 184 int u32Idx = config / 32; 185 int bitIdx = config % 32; 186 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx; 187 } 188 isVerifiedVerifiedColorConfigs189 bool isVerified(GrPixelConfig config) const { 190 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 191 return false; 192 #endif 193 int u32Idx = config / 32; 194 int bitIdx = config % 32; 195 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx)); 196 } 197 }; 198 199 void initFSAASupport(const GrGLContextInfo& ctxInfo); 200 void initStencilFormats(const GrGLContextInfo& ctxInfo); 201 202 // tracks configs that have been verified to pass the FBO completeness when 203 // used as a color attachment 204 VerifiedColorConfigs fVerifiedColorConfigs; 205 206 SkTArray<StencilFormat, true> fStencilFormats; 207 // tracks configs that have been verified to pass the FBO completeness when 208 // used as a color attachment when a particular stencil format is used 209 // as a stencil attachment. 210 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs; 211 212 int fMaxFragmentUniformVectors; 213 MSFBOType fMSFBOType; 214 215 bool fRGBA8RenderbufferSupport : 1; 216 bool fBGRAFormatSupport : 1; 217 bool fBGRAIsInternalFormat : 1; 218 bool fTextureSwizzleSupport : 1; 219 bool fUnpackRowLengthSupport : 1; 220 bool fUnpackFlipYSupport : 1; 221 bool fPackRowLengthSupport : 1; 222 bool fPackFlipYSupport : 1; 223 bool fTextureUsageSupport : 1; 224 bool fTexStorageSupport : 1; 225 }; 226 227 #endif 228