|
1 /* |
|
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 #include "GrGLCaps.h" |
|
10 #include "GrGLContext.h" |
|
11 #include "SkTSearch.h" |
|
12 #include "SkTSort.h" |
|
13 |
|
14 GrGLCaps::GrGLCaps() { |
|
15 this->reset(); |
|
16 } |
|
17 |
|
18 void GrGLCaps::reset() { |
|
19 INHERITED::reset(); |
|
20 |
|
21 fVerifiedColorConfigs.reset(); |
|
22 fStencilFormats.reset(); |
|
23 fStencilVerifiedColorConfigs.reset(); |
|
24 fMSFBOType = kNone_MSFBOType; |
|
25 fFBFetchType = kNone_FBFetchType; |
|
26 fMaxFragmentUniformVectors = 0; |
|
27 fMaxVertexAttributes = 0; |
|
28 fMaxFragmentTextureUnits = 0; |
|
29 fMaxFixedFunctionTextureCoords = 0; |
|
30 fRGBA8RenderbufferSupport = false; |
|
31 fBGRAFormatSupport = false; |
|
32 fBGRAIsInternalFormat = false; |
|
33 fTextureSwizzleSupport = false; |
|
34 fUnpackRowLengthSupport = false; |
|
35 fUnpackFlipYSupport = false; |
|
36 fPackRowLengthSupport = false; |
|
37 fPackFlipYSupport = false; |
|
38 fTextureUsageSupport = false; |
|
39 fTexStorageSupport = false; |
|
40 fTextureRedSupport = false; |
|
41 fImagingSupport = false; |
|
42 fTwoFormatLimit = false; |
|
43 fFragCoordsConventionSupport = false; |
|
44 fVertexArrayObjectSupport = false; |
|
45 fUseNonVBOVertexAndIndexDynamicData = false; |
|
46 fIsCoreProfile = false; |
|
47 fFixedFunctionSupport = false; |
|
48 fDiscardFBSupport = false; |
|
49 fFullClearIsFree = false; |
|
50 } |
|
51 |
|
52 GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() { |
|
53 *this = caps; |
|
54 } |
|
55 |
|
56 GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { |
|
57 INHERITED::operator=(caps); |
|
58 fVerifiedColorConfigs = caps.fVerifiedColorConfigs; |
|
59 fStencilFormats = caps.fStencilFormats; |
|
60 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; |
|
61 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; |
|
62 fMaxVertexAttributes = caps.fMaxVertexAttributes; |
|
63 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits; |
|
64 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords; |
|
65 fMSFBOType = caps.fMSFBOType; |
|
66 fFBFetchType = caps.fFBFetchType; |
|
67 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; |
|
68 fBGRAFormatSupport = caps.fBGRAFormatSupport; |
|
69 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; |
|
70 fTextureSwizzleSupport = caps.fTextureSwizzleSupport; |
|
71 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; |
|
72 fUnpackFlipYSupport = caps.fUnpackFlipYSupport; |
|
73 fPackRowLengthSupport = caps.fPackRowLengthSupport; |
|
74 fPackFlipYSupport = caps.fPackFlipYSupport; |
|
75 fTextureUsageSupport = caps.fTextureUsageSupport; |
|
76 fTexStorageSupport = caps.fTexStorageSupport; |
|
77 fTextureRedSupport = caps.fTextureRedSupport; |
|
78 fImagingSupport = caps.fImagingSupport; |
|
79 fTwoFormatLimit = caps.fTwoFormatLimit; |
|
80 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; |
|
81 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport; |
|
82 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData; |
|
83 fIsCoreProfile = caps.fIsCoreProfile; |
|
84 fFixedFunctionSupport = caps.fFixedFunctionSupport; |
|
85 fDiscardFBSupport = caps.fDiscardFBSupport; |
|
86 fFullClearIsFree = caps.fFullClearIsFree; |
|
87 |
|
88 return *this; |
|
89 } |
|
90 |
|
91 void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
|
92 |
|
93 this->reset(); |
|
94 if (!ctxInfo.isInitialized()) { |
|
95 return; |
|
96 } |
|
97 |
|
98 GrGLStandard standard = ctxInfo.standard(); |
|
99 GrGLVersion version = ctxInfo.version(); |
|
100 |
|
101 /************************************************************************** |
|
102 * Caps specific to GrGLCaps |
|
103 **************************************************************************/ |
|
104 |
|
105 if (kGLES_GrGLStandard == standard) { |
|
106 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
|
107 &fMaxFragmentUniformVectors); |
|
108 } else { |
|
109 SkASSERT(kGL_GrGLStandard == standard); |
|
110 GrGLint max; |
|
111 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
|
112 fMaxFragmentUniformVectors = max / 4; |
|
113 if (version >= GR_GL_VER(3, 2)) { |
|
114 GrGLint profileMask; |
|
115 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); |
|
116 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); |
|
117 } |
|
118 if (!fIsCoreProfile) { |
|
119 fFixedFunctionSupport = true; |
|
120 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords); |
|
121 // Sanity check |
|
122 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128); |
|
123 } |
|
124 } |
|
125 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); |
|
126 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits); |
|
127 |
|
128 if (kGL_GrGLStandard == standard) { |
|
129 fRGBA8RenderbufferSupport = true; |
|
130 } else { |
|
131 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) || |
|
132 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || |
|
133 ctxInfo.hasExtension("GL_ARM_rgba8"); |
|
134 } |
|
135 |
|
136 if (kGL_GrGLStandard == standard) { |
|
137 fBGRAFormatSupport = version >= GR_GL_VER(1,2) || |
|
138 ctxInfo.hasExtension("GL_EXT_bgra"); |
|
139 } else { |
|
140 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { |
|
141 fBGRAFormatSupport = true; |
|
142 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { |
|
143 fBGRAFormatSupport = true; |
|
144 fBGRAIsInternalFormat = true; |
|
145 } |
|
146 SkASSERT(fBGRAFormatSupport || |
|
147 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); |
|
148 } |
|
149 |
|
150 if (kGL_GrGLStandard == standard) { |
|
151 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || |
|
152 ctxInfo.hasExtension("GL_ARB_texture_swizzle"); |
|
153 } else { |
|
154 fTextureSwizzleSupport = version >= GR_GL_VER(3,0); |
|
155 } |
|
156 |
|
157 if (kGL_GrGLStandard == standard) { |
|
158 fUnpackRowLengthSupport = true; |
|
159 fUnpackFlipYSupport = false; |
|
160 fPackRowLengthSupport = true; |
|
161 fPackFlipYSupport = false; |
|
162 } else { |
|
163 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || |
|
164 ctxInfo.hasExtension("GL_EXT_unpack_subimage"); |
|
165 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); |
|
166 fPackRowLengthSupport = version >= GR_GL_VER(3,0) || |
|
167 ctxInfo.hasExtension("GL_NV_pack_subimage"); |
|
168 fPackFlipYSupport = |
|
169 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); |
|
170 } |
|
171 |
|
172 fTextureUsageSupport = (kGLES_GrGLStandard == standard) && |
|
173 ctxInfo.hasExtension("GL_ANGLE_texture_usage"); |
|
174 |
|
175 if (kGL_GrGLStandard == standard) { |
|
176 // The EXT version can apply to either GL or GLES. |
|
177 fTexStorageSupport = version >= GR_GL_VER(4,2) || |
|
178 ctxInfo.hasExtension("GL_ARB_texture_storage") || |
|
179 ctxInfo.hasExtension("GL_EXT_texture_storage"); |
|
180 } else { |
|
181 // Qualcomm Adreno drivers appear to have issues with texture storage. |
|
182 fTexStorageSupport = (version >= GR_GL_VER(3,0) && |
|
183 kQualcomm_GrGLVendor != ctxInfo.vendor()) || |
|
184 ctxInfo.hasExtension("GL_EXT_texture_storage"); |
|
185 } |
|
186 |
|
187 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if |
|
188 // it doesn't have ARB_texture_rg extension. |
|
189 if (kGL_GrGLStandard == standard) { |
|
190 if (ctxInfo.isMesa()) { |
|
191 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg"); |
|
192 } else { |
|
193 fTextureRedSupport = version >= GR_GL_VER(3,0) || |
|
194 ctxInfo.hasExtension("GL_ARB_texture_rg"); |
|
195 } |
|
196 } else { |
|
197 fTextureRedSupport = version >= GR_GL_VER(3,0) || |
|
198 ctxInfo.hasExtension("GL_EXT_texture_rg"); |
|
199 } |
|
200 |
|
201 fImagingSupport = kGL_GrGLStandard == standard && |
|
202 ctxInfo.hasExtension("GL_ARB_imaging"); |
|
203 |
|
204 // ES 2 only guarantees RGBA/uchar + one other format/type combo for |
|
205 // ReadPixels. The other format has to checked at run-time since it |
|
206 // can change based on which render target is bound |
|
207 fTwoFormatLimit = kGLES_GrGLStandard == standard; |
|
208 |
|
209 // Known issue on at least some Intel platforms: |
|
210 // http://code.google.com/p/skia/issues/detail?id=946 |
|
211 if (kIntel_GrGLVendor != ctxInfo.vendor()) { |
|
212 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || |
|
213 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"); |
|
214 } |
|
215 |
|
216 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with |
|
217 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex |
|
218 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and |
|
219 // limit this decision to specific GPU families rather than basing it on the vendor alone. |
|
220 if (!GR_GL_MUST_USE_VBO && |
|
221 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) { |
|
222 fUseNonVBOVertexAndIndexDynamicData = true; |
|
223 } |
|
224 |
|
225 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer"); |
|
226 |
|
227 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) { |
|
228 fFullClearIsFree = true; |
|
229 } |
|
230 |
|
231 if (kGL_GrGLStandard == standard) { |
|
232 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
|
233 ctxInfo.hasExtension("GL_ARB_vertex_array_object"); |
|
234 } else { |
|
235 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || |
|
236 ctxInfo.hasExtension("GL_OES_vertex_array_object"); |
|
237 } |
|
238 |
|
239 if (kGLES_GrGLStandard == standard) { |
|
240 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { |
|
241 fFBFetchType = kEXT_FBFetchType; |
|
242 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { |
|
243 fFBFetchType = kNV_FBFetchType; |
|
244 } |
|
245 } |
|
246 |
|
247 this->initFSAASupport(ctxInfo, gli); |
|
248 this->initStencilFormats(ctxInfo); |
|
249 |
|
250 /************************************************************************** |
|
251 * GrDrawTargetCaps fields |
|
252 **************************************************************************/ |
|
253 GrGLint numFormats; |
|
254 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); |
|
255 if (numFormats) { |
|
256 SkAutoSTMalloc<10, GrGLint> formats(numFormats); |
|
257 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); |
|
258 for (int i = 0; i < numFormats; ++i) { |
|
259 if (formats[i] == GR_GL_PALETTE8_RGBA8) { |
|
260 f8BitPaletteSupport = true; |
|
261 break; |
|
262 } |
|
263 } |
|
264 } |
|
265 |
|
266 if (kGL_GrGLStandard == standard) { |
|
267 // we could also look for GL_ATI_separate_stencil extension or |
|
268 // GL_EXT_stencil_two_side but they use different function signatures |
|
269 // than GL2.0+ (and than each other). |
|
270 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0)); |
|
271 // supported on GL 1.4 and higher or by extension |
|
272 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) || |
|
273 ctxInfo.hasExtension("GL_EXT_stencil_wrap"); |
|
274 } else { |
|
275 // ES 2 has two sided stencil and stencil wrap |
|
276 fTwoSidedStencilSupport = true; |
|
277 fStencilWrapOpsSupport = true; |
|
278 } |
|
279 |
|
280 if (kGL_GrGLStandard == standard) { |
|
281 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes |
|
282 // glMapBuffer. |
|
283 } else { |
|
284 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer"); |
|
285 } |
|
286 |
|
287 if (kGL_GrGLStandard == standard) { |
|
288 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) || |
|
289 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")); |
|
290 fNPOTTextureTileSupport = true; |
|
291 fMipMapSupport = true; |
|
292 } else { |
|
293 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only |
|
294 // ES3 has no limitations. |
|
295 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || |
|
296 ctxInfo.hasExtension("GL_OES_texture_npot"); |
|
297 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP |
|
298 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently, |
|
299 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to |
|
300 // to alllow arbitrary wrap modes, however. |
|
301 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot"); |
|
302 } |
|
303 |
|
304 fHWAALineSupport = (kGL_GrGLStandard == standard); |
|
305 |
|
306 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); |
|
307 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); |
|
308 // Our render targets are always created with textures as the color |
|
309 // attachment, hence this min: |
|
310 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize); |
|
311 |
|
312 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering"); |
|
313 SkASSERT(!fPathRenderingSupport || fFixedFunctionSupport); |
|
314 |
|
315 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker"); |
|
316 |
|
317 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType; |
|
318 |
|
319 // Disable scratch texture reuse on Mali and Adreno devices |
|
320 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() && |
|
321 kQualcomm_GrGLVendor != ctxInfo.vendor(); |
|
322 |
|
323 // Enable supported shader-related caps |
|
324 if (kGL_GrGLStandard == standard) { |
|
325 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) || |
|
326 ctxInfo.hasExtension("GL_ARB_blend_func_extended"); |
|
327 fShaderDerivativeSupport = true; |
|
328 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS |
|
329 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) && |
|
330 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; |
|
331 } else { |
|
332 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives"); |
|
333 } |
|
334 |
|
335 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { |
|
336 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount); |
|
337 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { |
|
338 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); |
|
339 } |
|
340 |
|
341 this->initConfigRenderableTable(ctxInfo); |
|
342 } |
|
343 |
|
344 void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) { |
|
345 |
|
346 // OpenGL < 3.0 |
|
347 // no support for render targets unless the GL_ARB_framebuffer_object |
|
348 // extension is supported (in which case we get ALPHA, RED, RG, RGB, |
|
349 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we |
|
350 // probably don't get R8 in this case. |
|
351 |
|
352 // OpenGL 3.0 |
|
353 // base color renderable: ALPHA, RED, RG, RGB, and RGBA |
|
354 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 |
|
355 |
|
356 // >= OpenGL 3.1 |
|
357 // base color renderable: RED, RG, RGB, and RGBA |
|
358 // sized derivatives: R8, RGBA4, RGBA8 |
|
359 // if the GL_ARB_compatibility extension is supported then we get back |
|
360 // support for GL_ALPHA and ALPHA8 |
|
361 |
|
362 // GL_EXT_bgra adds BGRA render targets to any version |
|
363 |
|
364 // ES 2.0 |
|
365 // color renderable: RGBA4, RGB5_A1, RGB565 |
|
366 // GL_EXT_texture_rg adds support for R8 as a color render target |
|
367 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 |
|
368 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support |
|
369 |
|
370 // ES 3.0 |
|
371 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called |
|
372 // below already account for this). |
|
373 |
|
374 enum { |
|
375 kNo_MSAA = 0, |
|
376 kYes_MSAA = 1, |
|
377 }; |
|
378 |
|
379 if (kGL_GrGLStandard == ctxInfo.standard()) { |
|
380 // Post 3.0 we will get R8 |
|
381 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) |
|
382 if (ctxInfo.version() >= GR_GL_VER(3,0) || |
|
383 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
|
384 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true; |
|
385 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true; |
|
386 } |
|
387 } else { |
|
388 // On ES we can only hope for R8 |
|
389 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport; |
|
390 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport; |
|
391 } |
|
392 |
|
393 if (kGL_GrGLStandard != ctxInfo.standard()) { |
|
394 // only available in ES |
|
395 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true; |
|
396 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true; |
|
397 } |
|
398 |
|
399 // we no longer support 444 as a render target |
|
400 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false; |
|
401 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false; |
|
402 |
|
403 if (this->fRGBA8RenderbufferSupport) { |
|
404 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true; |
|
405 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true; |
|
406 } |
|
407 |
|
408 if (this->fBGRAFormatSupport) { |
|
409 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true; |
|
410 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of |
|
411 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample. |
|
412 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms. |
|
413 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) { |
|
414 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true; |
|
415 } else { |
|
416 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = |
|
417 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers(); |
|
418 } |
|
419 } |
|
420 |
|
421 // If we don't support MSAA then undo any places above where we set a config as renderable with |
|
422 // msaa. |
|
423 if (kNone_MSFBOType == fMSFBOType) { |
|
424 for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
|
425 fConfigRenderSupport[i][kYes_MSAA] = false; |
|
426 } |
|
427 } |
|
428 } |
|
429 |
|
430 bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, |
|
431 GrGLenum format, |
|
432 GrGLenum type) const { |
|
433 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { |
|
434 // ES 2 guarantees this format is supported |
|
435 return true; |
|
436 } |
|
437 |
|
438 if (!fTwoFormatLimit) { |
|
439 // not limited by ES 2's constraints |
|
440 return true; |
|
441 } |
|
442 |
|
443 GrGLint otherFormat = GR_GL_RGBA; |
|
444 GrGLint otherType = GR_GL_UNSIGNED_BYTE; |
|
445 |
|
446 // The other supported format/type combo supported for ReadPixels |
|
447 // can change based on which render target is bound |
|
448 GR_GL_GetIntegerv(intf, |
|
449 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, |
|
450 &otherFormat); |
|
451 |
|
452 GR_GL_GetIntegerv(intf, |
|
453 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, |
|
454 &otherType); |
|
455 |
|
456 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; |
|
457 } |
|
458 |
|
459 void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { |
|
460 |
|
461 fMSFBOType = kNone_MSFBOType; |
|
462 if (kGL_GrGLStandard != ctxInfo.standard()) { |
|
463 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed |
|
464 // ES3 driver bugs on at least one device with a tiled GPU (N10). |
|
465 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { |
|
466 fMSFBOType = kES_EXT_MsToTexture_MSFBOType; |
|
467 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { |
|
468 fMSFBOType = kES_IMG_MsToTexture_MSFBOType; |
|
469 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { |
|
470 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; |
|
471 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
|
472 // chrome's extension is equivalent to the EXT msaa |
|
473 // and fbo_blit extensions. |
|
474 fMSFBOType = kDesktop_EXT_MSFBOType; |
|
475 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
|
476 fMSFBOType = kES_Apple_MSFBOType; |
|
477 } |
|
478 } else { |
|
479 if ((ctxInfo.version() >= GR_GL_VER(3,0)) || |
|
480 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
|
481 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; |
|
482 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
|
483 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
|
484 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; |
|
485 } |
|
486 } |
|
487 } |
|
488 |
|
489 namespace { |
|
490 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
|
491 } |
|
492 |
|
493 void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { |
|
494 |
|
495 // Build up list of legal stencil formats (though perhaps not supported on |
|
496 // the particular gpu/driver) from most preferred to least. |
|
497 |
|
498 // these consts are in order of most preferred to least preferred |
|
499 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
|
500 |
|
501 static const StencilFormat |
|
502 // internal Format stencil bits total bits packed? |
|
503 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
|
504 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
|
505 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
|
506 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
|
507 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
|
508 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
|
509 |
|
510 if (kGL_GrGLStandard == ctxInfo.standard()) { |
|
511 bool supportsPackedDS = |
|
512 ctxInfo.version() >= GR_GL_VER(3,0) || |
|
513 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || |
|
514 ctxInfo.hasExtension("GL_ARB_framebuffer_object"); |
|
515 |
|
516 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
|
517 // require FBO support we can expect these are legal formats and don't |
|
518 // check. These also all support the unsized GL_STENCIL_INDEX. |
|
519 fStencilFormats.push_back() = gS8; |
|
520 fStencilFormats.push_back() = gS16; |
|
521 if (supportsPackedDS) { |
|
522 fStencilFormats.push_back() = gD24S8; |
|
523 } |
|
524 fStencilFormats.push_back() = gS4; |
|
525 if (supportsPackedDS) { |
|
526 fStencilFormats.push_back() = gDS; |
|
527 } |
|
528 } else { |
|
529 // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
|
530 // for other formats. |
|
531 // ES doesn't support using the unsized format. |
|
532 |
|
533 fStencilFormats.push_back() = gS8; |
|
534 //fStencilFormats.push_back() = gS16; |
|
535 if (ctxInfo.version() >= GR_GL_VER(3,0) || |
|
536 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { |
|
537 fStencilFormats.push_back() = gD24S8; |
|
538 } |
|
539 if (ctxInfo.hasExtension("GL_OES_stencil4")) { |
|
540 fStencilFormats.push_back() = gS4; |
|
541 } |
|
542 } |
|
543 SkASSERT(0 == fStencilVerifiedColorConfigs.count()); |
|
544 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); |
|
545 } |
|
546 |
|
547 void GrGLCaps::markColorConfigAndStencilFormatAsVerified( |
|
548 GrPixelConfig config, |
|
549 const GrGLStencilBuffer::Format& format) { |
|
550 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
|
551 return; |
|
552 #endif |
|
553 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); |
|
554 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); |
|
555 int count = fStencilFormats.count(); |
|
556 // we expect a really small number of possible formats so linear search |
|
557 // should be OK |
|
558 SkASSERT(count < 16); |
|
559 for (int i = 0; i < count; ++i) { |
|
560 if (format.fInternalFormat == |
|
561 fStencilFormats[i].fInternalFormat) { |
|
562 fStencilVerifiedColorConfigs[i].markVerified(config); |
|
563 return; |
|
564 } |
|
565 } |
|
566 GrCrash("Why are we seeing a stencil format that " |
|
567 "GrGLCaps doesn't know about."); |
|
568 } |
|
569 |
|
570 bool GrGLCaps::isColorConfigAndStencilFormatVerified( |
|
571 GrPixelConfig config, |
|
572 const GrGLStencilBuffer::Format& format) const { |
|
573 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
|
574 return false; |
|
575 #endif |
|
576 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); |
|
577 int count = fStencilFormats.count(); |
|
578 // we expect a really small number of possible formats so linear search |
|
579 // should be OK |
|
580 SkASSERT(count < 16); |
|
581 for (int i = 0; i < count; ++i) { |
|
582 if (format.fInternalFormat == |
|
583 fStencilFormats[i].fInternalFormat) { |
|
584 return fStencilVerifiedColorConfigs[i].isVerified(config); |
|
585 } |
|
586 } |
|
587 GrCrash("Why are we seeing a stencil format that " |
|
588 "GLCaps doesn't know about."); |
|
589 return false; |
|
590 } |
|
591 |
|
592 SkString GrGLCaps::dump() const { |
|
593 |
|
594 SkString r = INHERITED::dump(); |
|
595 |
|
596 r.appendf("--- GL-Specific ---\n"); |
|
597 for (int i = 0; i < fStencilFormats.count(); ++i) { |
|
598 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", |
|
599 i, |
|
600 fStencilFormats[i].fStencilBits, |
|
601 fStencilFormats[i].fTotalBits); |
|
602 } |
|
603 |
|
604 static const char* kMSFBOExtStr[] = { |
|
605 "None", |
|
606 "ARB", |
|
607 "EXT", |
|
608 "ES 3.0", |
|
609 "Apple", |
|
610 "IMG MS To Texture", |
|
611 "EXT MS To Texture", |
|
612 }; |
|
613 GR_STATIC_ASSERT(0 == kNone_MSFBOType); |
|
614 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); |
|
615 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); |
|
616 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType); |
|
617 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType); |
|
618 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType); |
|
619 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType); |
|
620 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); |
|
621 |
|
622 static const char* kFBFetchTypeStr[] = { |
|
623 "None", |
|
624 "EXT", |
|
625 "NV", |
|
626 }; |
|
627 GR_STATIC_ASSERT(0 == kNone_FBFetchType); |
|
628 GR_STATIC_ASSERT(1 == kEXT_FBFetchType); |
|
629 GR_STATIC_ASSERT(2 == kNV_FBFetchType); |
|
630 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1); |
|
631 |
|
632 |
|
633 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); |
|
634 r.appendf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO")); |
|
635 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); |
|
636 r.appendf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]); |
|
637 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); |
|
638 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits); |
|
639 if (fFixedFunctionSupport) { |
|
640 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords); |
|
641 } |
|
642 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); |
|
643 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); |
|
644 r.appendf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO")); |
|
645 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); |
|
646 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); |
|
647 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); |
|
648 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); |
|
649 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); |
|
650 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); |
|
651 |
|
652 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); |
|
653 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); |
|
654 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); |
|
655 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); |
|
656 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); |
|
657 r.appendf("Fragment coord conventions support: %s\n", |
|
658 (fFragCoordsConventionSupport ? "YES": "NO")); |
|
659 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); |
|
660 r.appendf("Use non-VBO for dynamic data: %s\n", |
|
661 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); |
|
662 r.appendf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO")); |
|
663 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO")); |
|
664 return r; |
|
665 } |