blob: eb0b245d0b6785bff54428289d1aa74e1dc05ffa [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.com6b0cf022013-05-03 13:35:14 +000027 fFBFetchType = kNone_FBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000029 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000030 fMaxFragmentTextureUnits = 0;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000031 fMaxFixedFunctionTextureCoords = 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;
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +000049 fFixedFunctionSupport = false;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000050 fDiscardFBSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000051}
52
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000053GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000054 *this = caps;
55}
56
57GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000058 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
60 fStencilFormats = caps.fStencilFormats;
61 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
62 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000063 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000064 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000065 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000066 fMSFBOType = caps.fMSFBOType;
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;
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +000085 fFixedFunctionSupport = caps.fFixedFunctionSupport;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000086 fDiscardFBSupport = caps.fDiscardFBSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087
88 return *this;
89}
90
robertphillips@google.com6177e692013-02-28 20:16:25 +000091void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000092
93 this->reset();
94 if (!ctxInfo.isInitialized()) {
95 return;
96 }
97
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 GrGLBinding binding = ctxInfo.binding();
99 GrGLVersion version = ctxInfo.version();
100
bsalomon@google.combcce8922013-03-25 15:38:39 +0000101 /**************************************************************************
102 * Caps specific to GrGLCaps
103 **************************************************************************/
104
bsalomon@google.com791816a2013-08-15 18:54:39 +0000105 if (kES_GrGLBinding == binding) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000106 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
107 &fMaxFragmentUniformVectors);
108 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000109 SkASSERT(kDesktop_GrGLBinding == binding);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000110 GrGLint max;
111 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
112 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000113 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) {
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000119 fFixedFunctionSupport = true;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000120 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
121 // Sanity check
122 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
123 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000125 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000126 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127
128 if (kDesktop_GrGLBinding == binding) {
129 fRGBA8RenderbufferSupport = true;
130 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000131 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
132 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000133 ctxInfo.hasExtension("GL_ARM_rgba8");
134 }
135
136 if (kDesktop_GrGLBinding == binding) {
137 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
138 ctxInfo.hasExtension("GL_EXT_bgra");
139 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000140 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 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000146 SkASSERT(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000147 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000148 }
149
150 if (kDesktop_GrGLBinding == binding) {
151 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
152 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
153 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000154 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000155 }
156
157 if (kDesktop_GrGLBinding == binding) {
158 fUnpackRowLengthSupport = true;
159 fUnpackFlipYSupport = false;
160 fPackRowLengthSupport = true;
161 fPackFlipYSupport = false;
162 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000163 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
164 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000165 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000166 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
167 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000168 fPackFlipYSupport =
169 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
170 }
171
bsalomon@google.com791816a2013-08-15 18:54:39 +0000172 fTextureUsageSupport = (kES_GrGLBinding == binding) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000173 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
174
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000175 if (kDesktop_GrGLBinding == binding) {
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 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000186
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000187 // 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.
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000189 if (kDesktop_GrGLBinding == binding) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000190 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 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000196 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000197 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
198 ctxInfo.hasExtension("GL_EXT_texture_rg");
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000199 }
200
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000201 fImagingSupport = kDesktop_GrGLBinding == binding &&
202 ctxInfo.hasExtension("GL_ARB_imaging");
203
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000204 // 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
bsalomon@google.com791816a2013-08-15 18:54:39 +0000207 fTwoFormatLimit = kES_GrGLBinding == binding;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000208
bsalomon@google.com706f6682012-10-23 14:53:55 +0000209 // 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
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000216 // 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())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000222 fUseNonVBOVertexAndIndexDynamicData = true;
223 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000224
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000225 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
226
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000227 if (kDesktop_GrGLBinding == binding) {
228 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
229 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
230 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000231 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
232 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000233 }
234
bsalomon@google.com791816a2013-08-15 18:54:39 +0000235 if (kES_GrGLBinding == binding) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000236 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
237 fFBFetchType = kEXT_FBFetchType;
238 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
239 fFBFetchType = kNV_FBFetchType;
240 }
241 }
242
robertphillips@google.com6177e692013-02-28 20:16:25 +0000243 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000244 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000245
246 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000247 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000248 **************************************************************************/
bsalomon@google.combcce8922013-03-25 15:38:39 +0000249 GrGLint numFormats;
250 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
bungeman@google.com71033442013-05-01 14:21:20 +0000251 if (numFormats) {
252 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
253 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
254 for (int i = 0; i < numFormats; ++i) {
255 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
256 f8BitPaletteSupport = true;
257 break;
258 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000259 }
260 }
261
262 if (kDesktop_GrGLBinding == binding) {
263 // we could also look for GL_ATI_separate_stencil extension or
264 // GL_EXT_stencil_two_side but they use different function signatures
265 // than GL2.0+ (and than each other).
266 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
267 // supported on GL 1.4 and higher or by extension
268 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
269 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
270 } else {
271 // ES 2 has two sided stencil and stencil wrap
272 fTwoSidedStencilSupport = true;
273 fStencilWrapOpsSupport = true;
274 }
275
276 if (kDesktop_GrGLBinding == binding) {
277 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
278 // glMapBuffer.
279 } else {
280 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
281 }
282
283 if (kDesktop_GrGLBinding == binding) {
284 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
285 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
286 fNPOTTextureTileSupport = true;
287 } else {
288 fNPOTTextureTileSupport = false;
289 }
290 } else {
291 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000292 // ES3 has no limitations.
293 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
294 ctxInfo.hasExtension("GL_OES_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000295 }
296
297 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
298
299 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
300 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
301 // Our render targets are always created with textures as the color
302 // attachment, hence this min:
303 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
304
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000305 fPathRenderingSupport = GR_GL_USE_NV_PATH_RENDERING &&
306 ctxInfo.hasExtension("GL_NV_path_rendering");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000307
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000308 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
309
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000310#if 0
311 // This has to be temporarily disabled. On Android it causes the texture
312 // usage to become front loaded and the OS kills the process. It can
313 // be re-enabled once the more dynamic (ref-driven) cache clearing
314 // system is in place.
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000315 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000316#else
317 fReuseScratchTextures = true;
318#endif
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000319
bsalomon@google.combcce8922013-03-25 15:38:39 +0000320 // Enable supported shader-related caps
321 if (kDesktop_GrGLBinding == binding) {
322 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
323 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
324 fShaderDerivativeSupport = true;
325 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
326 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
327 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
328 } else {
329 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
330 }
331
bsalomon@google.com347c3822013-05-01 20:10:01 +0000332 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000333 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
334 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
335 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
336 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000337
338 this->initConfigRenderableTable(ctxInfo);
339}
340
341void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
342
343 // OpenGL < 3.0
344 // no support for render targets unless the GL_ARB_framebuffer_object
345 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
346 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
347 // probably don't get R8 in this case.
348
349 // OpenGL 3.0
350 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
351 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
352
353 // >= OpenGL 3.1
354 // base color renderable: RED, RG, RGB, and RGBA
355 // sized derivatives: R8, RGBA4, RGBA8
356 // if the GL_ARB_compatibility extension is supported then we get back
357 // support for GL_ALPHA and ALPHA8
358
359 // GL_EXT_bgra adds BGRA render targets to any version
360
361 // ES 2.0
362 // color renderable: RGBA4, RGB5_A1, RGB565
363 // GL_EXT_texture_rg adds support for R8 as a color render target
364 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
365 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
366
367 // ES 3.0
368 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
369 // below already account for this).
370
371 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
372 // Post 3.0 we will get R8
373 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
374 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
375 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
376 fConfigRenderSupport[kAlpha_8_GrPixelConfig] = true;
377 }
378 } else {
379 // On ES we can only hope for R8
380 fConfigRenderSupport[kAlpha_8_GrPixelConfig] = fTextureRedSupport;
381 }
382
383 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
384 // only available in ES
385 fConfigRenderSupport[kRGB_565_GrPixelConfig] = true;
386 }
387
388 // we no longer support 444 as a render target
389 fConfigRenderSupport[kRGBA_4444_GrPixelConfig] = false;
390
391 if (this->fRGBA8RenderbufferSupport) {
392 fConfigRenderSupport[kRGBA_8888_GrPixelConfig] = true;
393 }
394
395 if (this->fBGRAFormatSupport) {
396 fConfigRenderSupport[kBGRA_8888_GrPixelConfig] = true;
397 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000398}
399
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000400bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000401 GrGLenum format,
402 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000403 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
404 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000405 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000406 }
407
408 if (!fTwoFormatLimit) {
409 // not limited by ES 2's constraints
410 return true;
411 }
412
bsalomon@google.com548a4332012-07-11 19:45:22 +0000413 GrGLint otherFormat = GR_GL_RGBA;
414 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000415
416 // The other supported format/type combo supported for ReadPixels
417 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000418 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000419 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
420 &otherFormat);
421
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000422 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000423 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
424 &otherType);
425
bsalomon@google.com548a4332012-07-11 19:45:22 +0000426 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000427}
428
robertphillips@google.com6177e692013-02-28 20:16:25 +0000429void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000430
431 fMSFBOType = kNone_MSFBOType;
432 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000433 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
434 // ES3 driver bugs on at least one device with a tiled GPU (N10).
435 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
436 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
437 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
438 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
439 } else if (!GR_GL_IGNORE_ES3_MSAA && ctxInfo.version() >= GR_GL_VER(3,0)) {
440 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
441 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
442 // chrome's extension is equivalent to the EXT msaa
443 // and fbo_blit extensions.
444 fMSFBOType = kDesktop_EXT_MSFBOType;
445 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
446 fMSFBOType = kES_Apple_MSFBOType;
447 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000448 } else {
449 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
450 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000451 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000452 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
453 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000454 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000455 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000456 }
457}
458
459namespace {
460const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
461}
462
463void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
464
465 // Build up list of legal stencil formats (though perhaps not supported on
466 // the particular gpu/driver) from most preferred to least.
467
468 // these consts are in order of most preferred to least preferred
469 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
470
471 static const StencilFormat
472 // internal Format stencil bits total bits packed?
473 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
474 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
475 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
476 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000477 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000478 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
479
480 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
481 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000482 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000483 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
484 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
485
486 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
487 // require FBO support we can expect these are legal formats and don't
488 // check. These also all support the unsized GL_STENCIL_INDEX.
489 fStencilFormats.push_back() = gS8;
490 fStencilFormats.push_back() = gS16;
491 if (supportsPackedDS) {
492 fStencilFormats.push_back() = gD24S8;
493 }
494 fStencilFormats.push_back() = gS4;
495 if (supportsPackedDS) {
496 fStencilFormats.push_back() = gDS;
497 }
498 } else {
499 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
500 // for other formats.
501 // ES doesn't support using the unsized format.
502
503 fStencilFormats.push_back() = gS8;
504 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000505 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
506 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000507 fStencilFormats.push_back() = gD24S8;
508 }
509 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
510 fStencilFormats.push_back() = gS4;
511 }
512 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000513 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000514 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
515}
516
517void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
518 GrPixelConfig config,
519 const GrGLStencilBuffer::Format& format) {
520#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
521 return;
522#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000523 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
524 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000525 int count = fStencilFormats.count();
526 // we expect a really small number of possible formats so linear search
527 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000528 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000529 for (int i = 0; i < count; ++i) {
530 if (format.fInternalFormat ==
531 fStencilFormats[i].fInternalFormat) {
532 fStencilVerifiedColorConfigs[i].markVerified(config);
533 return;
534 }
535 }
536 GrCrash("Why are we seeing a stencil format that "
537 "GrGLCaps doesn't know about.");
538}
539
540bool GrGLCaps::isColorConfigAndStencilFormatVerified(
541 GrPixelConfig config,
542 const GrGLStencilBuffer::Format& format) const {
543#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
544 return false;
545#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000546 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000547 int count = fStencilFormats.count();
548 // we expect a really small number of possible formats so linear search
549 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000550 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000551 for (int i = 0; i < count; ++i) {
552 if (format.fInternalFormat ==
553 fStencilFormats[i].fInternalFormat) {
554 return fStencilVerifiedColorConfigs[i].isVerified(config);
555 }
556 }
557 GrCrash("Why are we seeing a stencil format that "
558 "GLCaps doesn't know about.");
559 return false;
560}
561
562void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000563
564 INHERITED::print();
565
566 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000567 for (int i = 0; i < fStencilFormats.count(); ++i) {
568 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
569 i,
570 fStencilFormats[i].fStencilBits,
571 fStencilFormats[i].fTotalBits);
572 }
573
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000574 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000575 "None",
576 "ARB",
577 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000578 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000579 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000580 "IMG MS To Texture",
581 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000582 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000583 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
584 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
585 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000586 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
587 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
588 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
589 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000590 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
591
592 static const char* kFBFetchTypeStr[] = {
593 "None",
594 "EXT",
595 "NV",
596 };
597 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
598 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
599 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
600 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
601
602
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000603 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
604 GrPrintf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO"));
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000605 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
606 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000607 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000608 GrPrintf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
609 if (fFixedFunctionSupport) {
610 GrPrintf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
611 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000612 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
613 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
614 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
615 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
616 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
617 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
618 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
619 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
620 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
621
622 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
623 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
624 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
625 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000626 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000627 GrPrintf("Fragment coord conventions support: %s\n",
628 (fFragCoordsConventionSupport ? "YES": "NO"));
629 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
630 GrPrintf("Use non-VBO for dynamic data: %s\n",
631 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000632 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000633}