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.
10 #include "GrGLContext.h"
11 #include "SkTSearch.h"
14 GrGLCaps::GrGLCaps() {
18 void GrGLCaps::reset() {
21 fVerifiedColorConfigs.reset();
22 fStencilFormats.reset();
23 fStencilVerifiedColorConfigs.reset();
24 fMSFBOType = kNone_MSFBOType;
25 fInvalidateFBType = kNone_InvalidateFBType;
26 fLATCAlias = kLATC_LATCAlias;
27 fMapBufferType = kNone_MapBufferType;
28 fMaxFragmentUniformVectors = 0;
29 fMaxVertexAttributes = 0;
30 fMaxFragmentTextureUnits = 0;
31 fMaxFixedFunctionTextureCoords = 0;
32 fRGBA8RenderbufferSupport = false;
33 fBGRAIsInternalFormat = false;
34 fTextureSwizzleSupport = false;
35 fUnpackRowLengthSupport = false;
36 fUnpackFlipYSupport = false;
37 fPackRowLengthSupport = false;
38 fPackFlipYSupport = false;
39 fTextureUsageSupport = false;
40 fTexStorageSupport = false;
41 fTextureRedSupport = false;
42 fImagingSupport = false;
43 fTwoFormatLimit = false;
44 fFragCoordsConventionSupport = false;
45 fVertexArrayObjectSupport = false;
46 fUseNonVBOVertexAndIndexDynamicData = false;
47 fIsCoreProfile = false;
48 fFullClearIsFree = false;
49 fDropsTileOnZeroDivide = false;
50 fFBFetchSupport = false;
51 fFBFetchColorName = NULL;
52 fFBFetchExtensionString = NULL;
55 GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
59 GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) {
60 INHERITED::operator=(caps);
61 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
62 fStencilFormats = caps.fStencilFormats;
63 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
64 fLATCAlias = caps.fLATCAlias;
65 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
66 fMaxVertexAttributes = caps.fMaxVertexAttributes;
67 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
68 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
69 fMSFBOType = caps.fMSFBOType;
70 fInvalidateFBType = caps.fInvalidateFBType;
71 fMapBufferType = caps.fMapBufferType;
72 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
73 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
74 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
75 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
76 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
77 fPackRowLengthSupport = caps.fPackRowLengthSupport;
78 fPackFlipYSupport = caps.fPackFlipYSupport;
79 fTextureUsageSupport = caps.fTextureUsageSupport;
80 fTexStorageSupport = caps.fTexStorageSupport;
81 fTextureRedSupport = caps.fTextureRedSupport;
82 fImagingSupport = caps.fImagingSupport;
83 fTwoFormatLimit = caps.fTwoFormatLimit;
84 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
85 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
86 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
87 fIsCoreProfile = caps.fIsCoreProfile;
88 fFullClearIsFree = caps.fFullClearIsFree;
89 fDropsTileOnZeroDivide = caps.fDropsTileOnZeroDivide;
90 fFBFetchSupport = caps.fFBFetchSupport;
91 fFBFetchColorName = caps.fFBFetchColorName;
92 fFBFetchExtensionString = caps.fFBFetchExtensionString;
97 bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
100 if (!ctxInfo.isInitialized()) {
104 GrGLStandard standard = ctxInfo.standard();
105 GrGLVersion version = ctxInfo.version();
107 /**************************************************************************
108 * Caps specific to GrGLCaps
109 **************************************************************************/
111 if (kGLES_GrGLStandard == standard) {
112 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
113 &fMaxFragmentUniformVectors);
115 SkASSERT(kGL_GrGLStandard == standard);
117 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
118 fMaxFragmentUniformVectors = max / 4;
119 if (version >= GR_GL_VER(3, 2)) {
121 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
122 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
124 if (!fIsCoreProfile) {
125 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
127 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
130 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
131 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
133 if (kGL_GrGLStandard == standard) {
134 fRGBA8RenderbufferSupport = true;
136 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
137 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
138 ctxInfo.hasExtension("GL_ARM_rgba8");
141 if (kGL_GrGLStandard == standard) {
142 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
143 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
145 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
148 if (kGL_GrGLStandard == standard) {
149 fUnpackRowLengthSupport = true;
150 fUnpackFlipYSupport = false;
151 fPackRowLengthSupport = true;
152 fPackFlipYSupport = false;
154 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
155 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
156 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
157 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
158 ctxInfo.hasExtension("GL_NV_pack_subimage");
160 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
163 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
164 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
166 if (kGL_GrGLStandard == standard) {
167 // The EXT version can apply to either GL or GLES.
168 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
169 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
170 ctxInfo.hasExtension("GL_EXT_texture_storage");
172 // Qualcomm Adreno drivers appear to have issues with texture storage.
173 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
174 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
175 ctxInfo.hasExtension("GL_EXT_texture_storage");
178 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
179 // it doesn't have ARB_texture_rg extension.
180 if (kGL_GrGLStandard == standard) {
181 if (ctxInfo.isMesa()) {
182 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
184 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
185 ctxInfo.hasExtension("GL_ARB_texture_rg");
188 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
189 ctxInfo.hasExtension("GL_EXT_texture_rg");
192 fImagingSupport = kGL_GrGLStandard == standard &&
193 ctxInfo.hasExtension("GL_ARB_imaging");
195 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
196 // ReadPixels. The other format has to checked at run-time since it
197 // can change based on which render target is bound
198 fTwoFormatLimit = kGLES_GrGLStandard == standard;
200 // Known issue on at least some Intel platforms:
201 // http://code.google.com/p/skia/issues/detail?id=946
202 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
203 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
204 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
207 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
208 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
209 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
210 // limit this decision to specific GPU families rather than basing it on the vendor alone.
211 if (!GR_GL_MUST_USE_VBO &&
212 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
213 fUseNonVBOVertexAndIndexDynamicData = true;
216 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
217 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
218 ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
219 fDiscardRenderTargetSupport = true;
220 fInvalidateFBType = kInvalidate_InvalidateFBType;
221 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
222 fDiscardRenderTargetSupport = true;
223 fInvalidateFBType = kDiscard_InvalidateFBType;
226 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
227 fFullClearIsFree = true;
230 if (kGL_GrGLStandard == standard) {
231 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
232 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
234 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
235 ctxInfo.hasExtension("GL_OES_vertex_array_object");
238 if (kGLES_GrGLStandard == standard) {
239 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
240 fFBFetchSupport = true;
241 fFBFetchColorName = "gl_LastFragData[0]";
242 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
243 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
244 fFBFetchSupport = true;
245 fFBFetchColorName = "gl_LastFragData[0]";
246 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
247 } else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
248 // The arm extension also requires an additional flag which we will set onResetContext
249 // This is all temporary.
250 fFBFetchSupport = true;
251 fFBFetchColorName = "gl_LastFragColorARM";
252 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
256 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
257 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
259 this->initFSAASupport(ctxInfo, gli);
260 this->initStencilFormats(ctxInfo);
262 /**************************************************************************
263 * GrDrawTargetCaps fields
264 **************************************************************************/
265 if (kGL_GrGLStandard == standard) {
266 // we could also look for GL_ATI_separate_stencil extension or
267 // GL_EXT_stencil_two_side but they use different function signatures
268 // than GL2.0+ (and than each other).
269 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
270 // supported on GL 1.4 and higher or by extension
271 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
272 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
274 // ES 2 has two sided stencil and stencil wrap
275 fTwoSidedStencilSupport = true;
276 fStencilWrapOpsSupport = true;
279 if (kGL_GrGLStandard == standard) {
280 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
281 // extension includes glMapBuffer.
282 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
283 fMapBufferFlags |= kSubset_MapFlag;
284 fMapBufferType = kMapBufferRange_MapBufferType;
286 fMapBufferType = kMapBuffer_MapBufferType;
289 // Unextended GLES2 doesn't have any buffer mapping.
290 fMapBufferFlags = kNone_MapBufferType;
291 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
292 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
293 fMapBufferType = kChromium_MapBufferType;
294 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
295 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
296 fMapBufferType = kMapBufferRange_MapBufferType;
297 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
298 fMapBufferFlags = kCanMap_MapFlag;
299 fMapBufferType = kMapBuffer_MapBufferType;
303 if (kGL_GrGLStandard == standard) {
304 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
305 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
306 fNPOTTextureTileSupport = true;
307 fMipMapSupport = true;
309 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
310 // ES3 has no limitations.
311 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
312 ctxInfo.hasExtension("GL_OES_texture_npot");
313 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
314 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
315 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
316 // to alllow arbitrary wrap modes, however.
317 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
320 fHWAALineSupport = (kGL_GrGLStandard == standard);
322 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
323 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
324 // Our render targets are always created with textures as the color
325 // attachment, hence this min:
326 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
328 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
330 if (fPathRenderingSupport) {
331 if (kGL_GrGLStandard == standard) {
332 // We need one of the two possible texturing methods: using fixed function pipeline
333 // (PathTexGen, texcoords, ...) or using the newer NVPR API additions that support
334 // setting individual fragment inputs with ProgramPathFragmentInputGen. The API
335 // additions are detected by checking the existence of the function. Eventually we may
336 // choose to remove the fixed function codepath.
337 // Set fMaxFixedFunctionTextureCoords = 0 here if you want to force
338 // ProgramPathFragmentInputGen usage on desktop.
339 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
340 (fMaxFixedFunctionTextureCoords > 0 ||
341 ((ctxInfo.version() >= GR_GL_VER(4,3) ||
342 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
343 NULL != gli->fFunctions.fProgramPathFragmentInputGen));
345 // Note: path rendering is not yet implemented for GLES.
346 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3,1) && false;
350 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
352 // For now these two are equivalent but we could have dst read in shader via some other method
353 fDstReadInShaderSupport = fFBFetchSupport;
355 // Disable scratch texture reuse on Mali and Adreno devices
356 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
357 kQualcomm_GrGLVendor != ctxInfo.vendor();
359 // Enable supported shader-related caps
360 if (kGL_GrGLStandard == standard) {
361 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
362 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
363 fShaderDerivativeSupport = true;
364 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
365 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
366 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
368 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
371 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
372 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
373 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
374 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
377 this->initConfigTexturableTable(ctxInfo, gli);
378 this->initConfigRenderableTable(ctxInfo);
383 void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
386 // no support for render targets unless the GL_ARB_framebuffer_object
387 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
388 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
389 // probably don't get R8 in this case.
392 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
393 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
396 // base color renderable: RED, RG, RGB, and RGBA
397 // sized derivatives: R8, RGBA4, RGBA8
398 // if the GL_ARB_compatibility extension is supported then we get back
399 // support for GL_ALPHA and ALPHA8
401 // GL_EXT_bgra adds BGRA render targets to any version
404 // color renderable: RGBA4, RGB5_A1, RGB565
405 // GL_EXT_texture_rg adds support for R8 as a color render target
406 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
407 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
410 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
411 // below already account for this).
413 GrGLStandard standard = ctxInfo.standard();
420 if (kGL_GrGLStandard == standard) {
421 // Post 3.0 we will get R8
422 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
423 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
424 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
425 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
426 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
429 // On ES we can only hope for R8
430 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
431 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
434 if (kGL_GrGLStandard != standard) {
435 // only available in ES
436 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
437 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
440 // we no longer support 444 as a render target
441 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
442 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
444 if (this->fRGBA8RenderbufferSupport) {
445 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
446 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
449 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
450 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
451 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
452 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
453 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
454 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
455 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
457 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
458 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
462 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
463 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
466 // If we don't support MSAA then undo any places above where we set a config as renderable with
468 if (kNone_MSFBOType == fMSFBOType) {
469 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
470 fConfigRenderSupport[i][kYes_MSAA] = false;
475 void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
476 GrGLStandard standard = ctxInfo.standard();
477 GrGLVersion version = ctxInfo.version();
479 // Base texture support
480 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
481 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
482 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
483 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
485 // Check for 8-bit palette..
487 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
489 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
490 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
491 for (int i = 0; i < numFormats; ++i) {
492 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
493 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
500 if (kGL_GrGLStandard == standard) {
501 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
502 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
504 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
505 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
506 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
507 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
508 fBGRAIsInternalFormat = true;
510 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
511 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
514 // Compressed texture support
516 // glCompressedTexImage2D is available on all OpenGL ES devices...
517 // however, it is only available on standard OpenGL after version 1.3
518 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
520 fCompressedTexSubImageSupport =
521 hasCompressTex2D && (NULL != gli->fFunctions.fCompressedTexSubImage2D);
524 bool hasETC1 = false;
526 // First check version for support
527 if (kGL_GrGLStandard == standard) {
528 hasETC1 = hasCompressTex2D &&
529 (version >= GR_GL_VER(4, 3) ||
530 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
532 hasETC1 = hasCompressTex2D &&
533 (version >= GR_GL_VER(3, 0) ||
534 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
535 // ETC2 is a superset of ETC1, so we can just check for that, too.
536 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
537 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
539 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
541 // Check for LATC under its various forms
542 LATCAlias alias = kLATC_LATCAlias;
543 bool hasLATC = hasCompressTex2D &&
544 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
545 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
549 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
550 if (kGL_GrGLStandard == standard) {
551 hasLATC = version >= GR_GL_VER(3, 0);
556 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
557 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
561 alias = kRGTC_LATCAlias;
567 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
569 alias = k3DC_LATCAlias;
573 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
576 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
577 // cards default to decompressing the textures in the driver, and is
579 if (kGL_GrGLStandard != standard) {
580 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
584 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
585 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
586 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
587 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
589 // Check for floating point texture support
590 // NOTE: We disallow floating point textures on ES devices if linear
591 // filtering modes are not supported. This is for simplicity, but a more
592 // granular approach is possible. Coincidentally, floating point textures became part of
593 // the standard in ES3.1 / OGL 3.1, hence the shorthand
594 bool hasFPTextures = version >= GR_GL_VER(3, 1);
595 if (!hasFPTextures) {
596 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
597 (ctxInfo.hasExtension("OES_texture_float_linear") &&
598 ctxInfo.hasExtension("GL_OES_texture_float"));
600 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
603 bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
605 GrGLenum type) const {
606 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
607 // ES 2 guarantees this format is supported
611 if (!fTwoFormatLimit) {
612 // not limited by ES 2's constraints
616 GrGLint otherFormat = GR_GL_RGBA;
617 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
619 // The other supported format/type combo supported for ReadPixels
620 // can change based on which render target is bound
621 GR_GL_GetIntegerv(intf,
622 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
625 GR_GL_GetIntegerv(intf,
626 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
629 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
632 void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
634 fMSFBOType = kNone_MSFBOType;
635 if (kGL_GrGLStandard != ctxInfo.standard()) {
636 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
637 // ES3 driver bugs on at least one device with a tiled GPU (N10).
638 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
639 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
640 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
641 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
642 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
643 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
644 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
645 // chrome's extension is equivalent to the EXT msaa
646 // and fbo_blit extensions.
647 fMSFBOType = kDesktop_EXT_MSFBOType;
648 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
649 fMSFBOType = kES_Apple_MSFBOType;
652 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
653 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
654 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
655 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
656 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
657 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
663 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
666 void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
668 // Build up list of legal stencil formats (though perhaps not supported on
669 // the particular gpu/driver) from most preferred to least.
671 // these consts are in order of most preferred to least preferred
672 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
674 static const StencilFormat
675 // internal Format stencil bits total bits packed?
676 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
677 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
678 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
679 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
680 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
681 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
683 if (kGL_GrGLStandard == ctxInfo.standard()) {
684 bool supportsPackedDS =
685 ctxInfo.version() >= GR_GL_VER(3,0) ||
686 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
687 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
689 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
690 // require FBO support we can expect these are legal formats and don't
691 // check. These also all support the unsized GL_STENCIL_INDEX.
692 fStencilFormats.push_back() = gS8;
693 fStencilFormats.push_back() = gS16;
694 if (supportsPackedDS) {
695 fStencilFormats.push_back() = gD24S8;
697 fStencilFormats.push_back() = gS4;
698 if (supportsPackedDS) {
699 fStencilFormats.push_back() = gDS;
702 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
703 // for other formats.
704 // ES doesn't support using the unsized format.
706 fStencilFormats.push_back() = gS8;
707 //fStencilFormats.push_back() = gS16;
708 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
709 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
710 fStencilFormats.push_back() = gD24S8;
712 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
713 fStencilFormats.push_back() = gS4;
716 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
717 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
720 void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
721 GrPixelConfig config,
722 const GrGLStencilBuffer::Format& format) {
723 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
726 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
727 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
728 int count = fStencilFormats.count();
729 // we expect a really small number of possible formats so linear search
731 SkASSERT(count < 16);
732 for (int i = 0; i < count; ++i) {
733 if (format.fInternalFormat ==
734 fStencilFormats[i].fInternalFormat) {
735 fStencilVerifiedColorConfigs[i].markVerified(config);
739 SkFAIL("Why are we seeing a stencil format that "
740 "GrGLCaps doesn't know about.");
743 bool GrGLCaps::isColorConfigAndStencilFormatVerified(
744 GrPixelConfig config,
745 const GrGLStencilBuffer::Format& format) const {
746 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
749 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
750 int count = fStencilFormats.count();
751 // we expect a really small number of possible formats so linear search
753 SkASSERT(count < 16);
754 for (int i = 0; i < count; ++i) {
755 if (format.fInternalFormat ==
756 fStencilFormats[i].fInternalFormat) {
757 return fStencilVerifiedColorConfigs[i].isVerified(config);
760 SkFAIL("Why are we seeing a stencil format that "
761 "GLCaps doesn't know about.");
765 SkString GrGLCaps::dump() const {
767 SkString r = INHERITED::dump();
769 r.appendf("--- GL-Specific ---\n");
770 for (int i = 0; i < fStencilFormats.count(); ++i) {
771 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
773 fStencilFormats[i].fStencilBits,
774 fStencilFormats[i].fTotalBits);
777 static const char* kMSFBOExtStr[] = {
786 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
787 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
788 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
789 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
790 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
791 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
792 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
793 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
795 static const char* kInvalidateFBTypeStr[] = {
800 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
801 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
802 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
803 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
805 static const char* kMapBufferTypeStr[] = {
811 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
812 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
813 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
814 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
815 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
817 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
818 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
819 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
820 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
821 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
822 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
823 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
824 if (!fIsCoreProfile) {
825 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
827 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
828 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
829 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
830 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
831 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
832 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
833 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
834 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
836 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
837 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
838 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
839 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
840 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
841 r.appendf("Fragment coord conventions support: %s\n",
842 (fFragCoordsConventionSupport ? "YES": "NO"));
843 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
844 r.appendf("Use non-VBO for dynamic data: %s\n",
845 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
846 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
847 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));