blob: 4123a01984803ee286dc71ddfcd3fcd015565553 [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
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"
robertphillips@google.com6177e692013-02-28 20:16:25 +000010#include "GrGLContext.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000011#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000012#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000013
bsalomon@google.combcce8922013-03-25 15:38:39 +000014SK_DEFINE_INST_COUNT(GrGLCaps)
15
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000016GrGLCaps::GrGLCaps() {
17 this->reset();
18}
19
20void GrGLCaps::reset() {
bsalomon@google.combcce8922013-03-25 15:38:39 +000021 INHERITED::reset();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fVerifiedColorConfigs.reset();
24 fStencilFormats.reset();
25 fStencilVerifiedColorConfigs.reset();
26 fMSFBOType = kNone_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000027 fCoverageAAType = kNone_CoverageAAType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000028 fFBFetchType = kNone_FBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000030 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000031 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032 fRGBA8RenderbufferSupport = false;
33 fBGRAFormatSupport = false;
34 fBGRAIsInternalFormat = false;
35 fTextureSwizzleSupport = false;
36 fUnpackRowLengthSupport = false;
37 fUnpackFlipYSupport = false;
38 fPackRowLengthSupport = false;
39 fPackFlipYSupport = false;
40 fTextureUsageSupport = false;
41 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000042 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000043 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000044 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000045 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000046 fVertexArrayObjectSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000047 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000048 fIsCoreProfile = false;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000049 fDiscardFBSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000050}
51
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000052GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000053 *this = caps;
54}
55
56GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000057 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000058 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
59 fStencilFormats = caps.fStencilFormats;
60 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
61 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000062 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000063 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000064 fMSFBOType = caps.fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000065 fCoverageAAType = caps.fCoverageAAType;
66 fMSAACoverageModes = caps.fMSAACoverageModes;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000067 fFBFetchType = caps.fFBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000068 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
69 fBGRAFormatSupport = caps.fBGRAFormatSupport;
70 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
71 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
72 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
73 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
74 fPackRowLengthSupport = caps.fPackRowLengthSupport;
75 fPackFlipYSupport = caps.fPackFlipYSupport;
76 fTextureUsageSupport = caps.fTextureUsageSupport;
77 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000078 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000079 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000080 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000081 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000082 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000083 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000084 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000085 fDiscardFBSupport = caps.fDiscardFBSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086
87 return *this;
88}
89
robertphillips@google.com6177e692013-02-28 20:16:25 +000090void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000091
92 this->reset();
93 if (!ctxInfo.isInitialized()) {
94 return;
95 }
96
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 GrGLBinding binding = ctxInfo.binding();
98 GrGLVersion version = ctxInfo.version();
99
bsalomon@google.combcce8922013-03-25 15:38:39 +0000100 /**************************************************************************
101 * Caps specific to GrGLCaps
102 **************************************************************************/
103
bsalomon@google.com791816a2013-08-15 18:54:39 +0000104 if (kES_GrGLBinding == binding) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000105 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
106 &fMaxFragmentUniformVectors);
107 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000108 SkASSERT(kDesktop_GrGLBinding == binding);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 GrGLint max;
110 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
111 fMaxFragmentUniformVectors = max / 4;
112 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000113 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000114 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000115
116 if (kDesktop_GrGLBinding == binding) {
117 fRGBA8RenderbufferSupport = true;
118 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000119 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
120 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000121 ctxInfo.hasExtension("GL_ARM_rgba8");
122 }
123
124 if (kDesktop_GrGLBinding == binding) {
125 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
126 ctxInfo.hasExtension("GL_EXT_bgra");
127 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000128 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
129 fBGRAFormatSupport = true;
130 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
131 fBGRAFormatSupport = true;
132 fBGRAIsInternalFormat = true;
133 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000134 SkASSERT(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000135 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000136 }
137
138 if (kDesktop_GrGLBinding == binding) {
139 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
140 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
141 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000142 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000143 }
144
145 if (kDesktop_GrGLBinding == binding) {
146 fUnpackRowLengthSupport = true;
147 fUnpackFlipYSupport = false;
148 fPackRowLengthSupport = true;
149 fPackFlipYSupport = false;
150 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000151 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
152 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000153 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000154 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
155 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000156 fPackFlipYSupport =
157 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
158 }
159
bsalomon@google.com791816a2013-08-15 18:54:39 +0000160 fTextureUsageSupport = (kES_GrGLBinding == binding) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000161 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
162
163 // Tex storage is in desktop 4.2 and can be an extension to desktop or ES.
164 fTexStorageSupport = (kDesktop_GrGLBinding == binding &&
165 version >= GR_GL_VER(4,2)) ||
166 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
167 ctxInfo.hasExtension("GL_EXT_texture_storage");
168
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000169 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
170 // it doesn't have ARB_texture_rg extension.
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000171 if (kDesktop_GrGLBinding == binding) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000172 if (ctxInfo.isMesa()) {
173 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
174 } else {
175 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
176 ctxInfo.hasExtension("GL_ARB_texture_rg");
177 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000178 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000179 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
180 ctxInfo.hasExtension("GL_EXT_texture_rg");
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000181 }
182
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000183 fImagingSupport = kDesktop_GrGLBinding == binding &&
184 ctxInfo.hasExtension("GL_ARB_imaging");
185
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000186 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
187 // ReadPixels. The other format has to checked at run-time since it
188 // can change based on which render target is bound
bsalomon@google.com791816a2013-08-15 18:54:39 +0000189 fTwoFormatLimit = kES_GrGLBinding == binding;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000190
bsalomon@google.com706f6682012-10-23 14:53:55 +0000191 // Known issue on at least some Intel platforms:
192 // http://code.google.com/p/skia/issues/detail?id=946
193 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
194 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
195 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
196 }
197
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000198 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
199 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
200 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
201 // limit this decision to specific GPU families rather than basing it on the vendor alone.
202 if (!GR_GL_MUST_USE_VBO &&
203 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000204 fUseNonVBOVertexAndIndexDynamicData = true;
205 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000206
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000207 if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) {
208 GrGLint profileMask;
209 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
210 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
211 }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000212
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000213 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
214
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000215 if (kDesktop_GrGLBinding == binding) {
216 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
217 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
218 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000219 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
220 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000221 }
222
bsalomon@google.com791816a2013-08-15 18:54:39 +0000223 if (kES_GrGLBinding == binding) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000224 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
225 fFBFetchType = kEXT_FBFetchType;
226 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
227 fFBFetchType = kNV_FBFetchType;
228 }
229 }
230
robertphillips@google.com6177e692013-02-28 20:16:25 +0000231 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000232 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000233
234 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000235 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000236 **************************************************************************/
bsalomon@google.combcce8922013-03-25 15:38:39 +0000237 GrGLint numFormats;
238 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
bungeman@google.com71033442013-05-01 14:21:20 +0000239 if (numFormats) {
240 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
241 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
242 for (int i = 0; i < numFormats; ++i) {
243 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
244 f8BitPaletteSupport = true;
245 break;
246 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000247 }
248 }
249
250 if (kDesktop_GrGLBinding == binding) {
251 // we could also look for GL_ATI_separate_stencil extension or
252 // GL_EXT_stencil_two_side but they use different function signatures
253 // than GL2.0+ (and than each other).
254 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
255 // supported on GL 1.4 and higher or by extension
256 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
257 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
258 } else {
259 // ES 2 has two sided stencil and stencil wrap
260 fTwoSidedStencilSupport = true;
261 fStencilWrapOpsSupport = true;
262 }
263
264 if (kDesktop_GrGLBinding == binding) {
265 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
266 // glMapBuffer.
267 } else {
268 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
269 }
270
271 if (kDesktop_GrGLBinding == binding) {
272 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
273 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
274 fNPOTTextureTileSupport = true;
275 } else {
276 fNPOTTextureTileSupport = false;
277 }
278 } else {
279 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000280 // ES3 has no limitations.
281 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
282 ctxInfo.hasExtension("GL_OES_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000283 }
284
285 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
286
287 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
288 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
289 // Our render targets are always created with textures as the color
290 // attachment, hence this min:
291 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
292
293 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
294 ctxInfo.hasExtension("GL_NV_path_rendering");
295
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000296 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
297
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000298#if 0
299 // This has to be temporarily disabled. On Android it causes the texture
300 // usage to become front loaded and the OS kills the process. It can
301 // be re-enabled once the more dynamic (ref-driven) cache clearing
302 // system is in place.
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000303 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000304#else
305 fReuseScratchTextures = true;
306#endif
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000307
bsalomon@google.combcce8922013-03-25 15:38:39 +0000308 // Enable supported shader-related caps
309 if (kDesktop_GrGLBinding == binding) {
310 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
311 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
312 fShaderDerivativeSupport = true;
313 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
314 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
315 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
316 } else {
317 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
318 }
319
bsalomon@google.com347c3822013-05-01 20:10:01 +0000320 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000321 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
322 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
323 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
324 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000325}
326
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000327bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000328 GrGLenum format,
329 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000330 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
331 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000332 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000333 }
334
335 if (!fTwoFormatLimit) {
336 // not limited by ES 2's constraints
337 return true;
338 }
339
bsalomon@google.com548a4332012-07-11 19:45:22 +0000340 GrGLint otherFormat = GR_GL_RGBA;
341 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000342
343 // The other supported format/type combo supported for ReadPixels
344 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000345 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000346 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
347 &otherFormat);
348
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000349 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000350 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
351 &otherType);
352
bsalomon@google.com548a4332012-07-11 19:45:22 +0000353 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000354}
355
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000356namespace {
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000357bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left,
358 const GrGLCaps::MSAACoverageMode& right) {
359 if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) {
360 return true;
361 } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) {
362 return false;
363 } else if (left.fColorSampleCnt < right.fColorSampleCnt) {
364 return true;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000365 }
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000366 return false;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000367}
368}
369
robertphillips@google.com6177e692013-02-28 20:16:25 +0000370void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000371
372 fMSFBOType = kNone_MSFBOType;
373 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
374 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
375 // chrome's extension is equivalent to the EXT msaa
376 // and fbo_blit extensions.
bsalomon@google.com347c3822013-05-01 20:10:01 +0000377 fMSFBOType = kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000378 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000379 fMSFBOType = kES_Apple_MSFBOType;
380 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
381 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000382 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000383 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000384 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000385 } else {
386 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
387 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000388 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000389 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
390 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000391 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000392 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000393 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
394 // on GL 4.2+. It's format-specific, though. See also
395 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
396 // rather than requested sample counts in cache key.
397 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
398 fCoverageAAType = kNVDesktop_CoverageAAType;
399 GrGLint count;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000400 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000401 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
402 &count);
403 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000404 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000405 GR_GL_MULTISAMPLE_COVERAGE_MODES,
406 (int*)&fMSAACoverageModes[0]);
407 // The NV driver seems to return the modes already sorted but the
408 // spec doesn't require this. So we sort.
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000409 typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_less> SortFunctor;
410 SortFunctor sortFunctor;
411 SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(),
412 fMSAACoverageModes.end() - 1,
413 sortFunctor);
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000414 }
415 }
416}
417
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000418const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000419 static const MSAACoverageMode kNoneMode = {0, 0};
420 if (0 == fMSAACoverageModes.count()) {
421 return kNoneMode;
422 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000423 SkASSERT(kNone_CoverageAAType != fCoverageAAType);
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000424 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
425 desiredSampleCount = GrMin(desiredSampleCount, max);
426 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000427 int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverageModes[0],
428 fMSAACoverageModes.count(),
429 desiredMode,
430 sizeof(MSAACoverageMode));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000431 if (idx < 0) {
432 idx = ~idx;
433 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000434 SkASSERT(idx >= 0 && idx < fMSAACoverageModes.count());
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000435 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000436 }
437}
438
439namespace {
440const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
441}
442
443void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
444
445 // Build up list of legal stencil formats (though perhaps not supported on
446 // the particular gpu/driver) from most preferred to least.
447
448 // these consts are in order of most preferred to least preferred
449 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
450
451 static const StencilFormat
452 // internal Format stencil bits total bits packed?
453 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
454 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
455 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
456 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000457 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000458 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
459
460 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
461 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000462 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000463 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
464 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
465
466 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
467 // require FBO support we can expect these are legal formats and don't
468 // check. These also all support the unsized GL_STENCIL_INDEX.
469 fStencilFormats.push_back() = gS8;
470 fStencilFormats.push_back() = gS16;
471 if (supportsPackedDS) {
472 fStencilFormats.push_back() = gD24S8;
473 }
474 fStencilFormats.push_back() = gS4;
475 if (supportsPackedDS) {
476 fStencilFormats.push_back() = gDS;
477 }
478 } else {
479 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
480 // for other formats.
481 // ES doesn't support using the unsized format.
482
483 fStencilFormats.push_back() = gS8;
484 //fStencilFormats.push_back() = gS16;
485 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
486 fStencilFormats.push_back() = gD24S8;
487 }
488 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
489 fStencilFormats.push_back() = gS4;
490 }
491 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000492 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000493 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
494}
495
496void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
497 GrPixelConfig config,
498 const GrGLStencilBuffer::Format& format) {
499#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
500 return;
501#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000502 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
503 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000504 int count = fStencilFormats.count();
505 // we expect a really small number of possible formats so linear search
506 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000507 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000508 for (int i = 0; i < count; ++i) {
509 if (format.fInternalFormat ==
510 fStencilFormats[i].fInternalFormat) {
511 fStencilVerifiedColorConfigs[i].markVerified(config);
512 return;
513 }
514 }
515 GrCrash("Why are we seeing a stencil format that "
516 "GrGLCaps doesn't know about.");
517}
518
519bool GrGLCaps::isColorConfigAndStencilFormatVerified(
520 GrPixelConfig config,
521 const GrGLStencilBuffer::Format& format) const {
522#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
523 return false;
524#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000525 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000526 int count = fStencilFormats.count();
527 // we expect a really small number of possible formats so linear search
528 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000529 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000530 for (int i = 0; i < count; ++i) {
531 if (format.fInternalFormat ==
532 fStencilFormats[i].fInternalFormat) {
533 return fStencilVerifiedColorConfigs[i].isVerified(config);
534 }
535 }
536 GrCrash("Why are we seeing a stencil format that "
537 "GLCaps doesn't know about.");
538 return false;
539}
540
541void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000542
543 INHERITED::print();
544
545 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000546 for (int i = 0; i < fStencilFormats.count(); ++i) {
547 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
548 i,
549 fStencilFormats[i].fStencilBits,
550 fStencilFormats[i].fTotalBits);
551 }
552
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000553 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000554 "None",
555 "ARB",
556 "EXT",
557 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000558 "IMG MS To Texture",
559 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000560 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000561 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
562 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
563 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
564 GR_STATIC_ASSERT(3 == kES_Apple_MSFBOType);
565 GR_STATIC_ASSERT(4 == kES_IMG_MsToTexture_MSFBOType);
566 GR_STATIC_ASSERT(5 == kES_EXT_MsToTexture_MSFBOType);
567 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
568
569 static const char* kFBFetchTypeStr[] = {
570 "None",
571 "EXT",
572 "NV",
573 };
574 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
575 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
576 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
577 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
578
579
580 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
581 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000582 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000583 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
584 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
585 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
586 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
587 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
588 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
589 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
590 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
591 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
592
593 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
594 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
595 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
596 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000597 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000598 GrPrintf("Fragment coord conventions support: %s\n",
599 (fFragCoordsConventionSupport ? "YES": "NO"));
600 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
601 GrPrintf("Use non-VBO for dynamic data: %s\n",
602 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
603 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000604 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000605}