blob: 60c0dfaf1027e8ef8a485d486b109ac2d2d67d72 [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;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000051 fFullClearIsFree = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000052}
53
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000054GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000055 *this = caps;
56}
57
58GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000059 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
61 fStencilFormats = caps.fStencilFormats;
62 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
63 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000064 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000065 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000066 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000067 fMSFBOType = caps.fMSFBOType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000068 fFBFetchType = caps.fFBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000069 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
70 fBGRAFormatSupport = caps.fBGRAFormatSupport;
71 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
72 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
73 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
74 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
75 fPackRowLengthSupport = caps.fPackRowLengthSupport;
76 fPackFlipYSupport = caps.fPackFlipYSupport;
77 fTextureUsageSupport = caps.fTextureUsageSupport;
78 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000079 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000080 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000081 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000082 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000083 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000084 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000085 fIsCoreProfile = caps.fIsCoreProfile;
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +000086 fFixedFunctionSupport = caps.fFixedFunctionSupport;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000087 fDiscardFBSupport = caps.fDiscardFBSupport;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000088 fFullClearIsFree = caps.fFullClearIsFree;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089
90 return *this;
91}
92
robertphillips@google.com6177e692013-02-28 20:16:25 +000093void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094
95 this->reset();
96 if (!ctxInfo.isInitialized()) {
97 return;
98 }
99
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000100 GrGLBinding binding = ctxInfo.binding();
101 GrGLVersion version = ctxInfo.version();
102
bsalomon@google.combcce8922013-03-25 15:38:39 +0000103 /**************************************************************************
104 * Caps specific to GrGLCaps
105 **************************************************************************/
106
bsalomon@google.com791816a2013-08-15 18:54:39 +0000107 if (kES_GrGLBinding == binding) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
109 &fMaxFragmentUniformVectors);
110 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000111 SkASSERT(kDesktop_GrGLBinding == binding);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112 GrGLint max;
113 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
114 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000115 if (version >= GR_GL_VER(3, 2)) {
116 GrGLint profileMask;
117 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
118 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
119 }
120 if (!fIsCoreProfile) {
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000121 fFixedFunctionSupport = true;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000122 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
123 // Sanity check
124 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
125 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000126 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000127 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000128 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000129
130 if (kDesktop_GrGLBinding == binding) {
131 fRGBA8RenderbufferSupport = true;
132 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000133 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
134 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000135 ctxInfo.hasExtension("GL_ARM_rgba8");
136 }
137
138 if (kDesktop_GrGLBinding == binding) {
139 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
140 ctxInfo.hasExtension("GL_EXT_bgra");
141 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000142 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
143 fBGRAFormatSupport = true;
144 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
145 fBGRAFormatSupport = true;
146 fBGRAIsInternalFormat = true;
147 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000148 SkASSERT(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000149 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000150 }
151
152 if (kDesktop_GrGLBinding == binding) {
153 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
154 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
155 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000156 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000157 }
158
159 if (kDesktop_GrGLBinding == binding) {
160 fUnpackRowLengthSupport = true;
161 fUnpackFlipYSupport = false;
162 fPackRowLengthSupport = true;
163 fPackFlipYSupport = false;
164 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000165 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
166 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000167 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000168 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
169 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000170 fPackFlipYSupport =
171 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
172 }
173
bsalomon@google.com791816a2013-08-15 18:54:39 +0000174 fTextureUsageSupport = (kES_GrGLBinding == binding) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000175 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
176
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000177 if (kDesktop_GrGLBinding == binding) {
178 // The EXT version can apply to either GL or GLES.
179 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
180 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
181 ctxInfo.hasExtension("GL_EXT_texture_storage");
182 } else {
183 // Qualcomm Adreno drivers appear to have issues with texture storage.
184 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
185 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
186 ctxInfo.hasExtension("GL_EXT_texture_storage");
187 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000188
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000189 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
190 // it doesn't have ARB_texture_rg extension.
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000191 if (kDesktop_GrGLBinding == binding) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000192 if (ctxInfo.isMesa()) {
193 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
194 } else {
195 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
196 ctxInfo.hasExtension("GL_ARB_texture_rg");
197 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000198 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000199 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
200 ctxInfo.hasExtension("GL_EXT_texture_rg");
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000201 }
202
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000203 fImagingSupport = kDesktop_GrGLBinding == binding &&
204 ctxInfo.hasExtension("GL_ARB_imaging");
205
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000206 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
207 // ReadPixels. The other format has to checked at run-time since it
208 // can change based on which render target is bound
bsalomon@google.com791816a2013-08-15 18:54:39 +0000209 fTwoFormatLimit = kES_GrGLBinding == binding;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000210
bsalomon@google.com706f6682012-10-23 14:53:55 +0000211 // Known issue on at least some Intel platforms:
212 // http://code.google.com/p/skia/issues/detail?id=946
213 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
214 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
215 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
216 }
217
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000218 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
219 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
220 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
221 // limit this decision to specific GPU families rather than basing it on the vendor alone.
222 if (!GR_GL_MUST_USE_VBO &&
223 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000224 fUseNonVBOVertexAndIndexDynamicData = true;
225 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000226
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000227 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
228
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000229 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
230 fFullClearIsFree = true;
231 }
232
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000233 if (kDesktop_GrGLBinding == binding) {
234 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
235 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
236 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000237 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
238 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000239 }
240
bsalomon@google.com791816a2013-08-15 18:54:39 +0000241 if (kES_GrGLBinding == binding) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000242 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
243 fFBFetchType = kEXT_FBFetchType;
244 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
245 fFBFetchType = kNV_FBFetchType;
246 }
247 }
248
robertphillips@google.com6177e692013-02-28 20:16:25 +0000249 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000250 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000251
252 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000253 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000254 **************************************************************************/
bsalomon@google.combcce8922013-03-25 15:38:39 +0000255 GrGLint numFormats;
256 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
bungeman@google.com71033442013-05-01 14:21:20 +0000257 if (numFormats) {
258 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
259 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
260 for (int i = 0; i < numFormats; ++i) {
261 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
262 f8BitPaletteSupport = true;
263 break;
264 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000265 }
266 }
267
268 if (kDesktop_GrGLBinding == binding) {
269 // we could also look for GL_ATI_separate_stencil extension or
270 // GL_EXT_stencil_two_side but they use different function signatures
271 // than GL2.0+ (and than each other).
272 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
273 // supported on GL 1.4 and higher or by extension
274 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
275 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
276 } else {
277 // ES 2 has two sided stencil and stencil wrap
278 fTwoSidedStencilSupport = true;
279 fStencilWrapOpsSupport = true;
280 }
281
282 if (kDesktop_GrGLBinding == binding) {
283 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
284 // glMapBuffer.
285 } else {
286 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
287 }
288
289 if (kDesktop_GrGLBinding == binding) {
290 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
291 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
292 fNPOTTextureTileSupport = true;
293 } else {
294 fNPOTTextureTileSupport = false;
295 }
296 } else {
297 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000298 // ES3 has no limitations.
299 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
300 ctxInfo.hasExtension("GL_OES_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000301 }
302
303 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
304
305 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
306 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
307 // Our render targets are always created with textures as the color
308 // attachment, hence this min:
309 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
310
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000311 fPathRenderingSupport = GR_GL_USE_NV_PATH_RENDERING &&
312 ctxInfo.hasExtension("GL_NV_path_rendering");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000313
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000314 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000315 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
316
bsalomon@google.combcce8922013-03-25 15:38:39 +0000317 // Enable supported shader-related caps
318 if (kDesktop_GrGLBinding == binding) {
319 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
320 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
321 fShaderDerivativeSupport = true;
322 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
323 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
324 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
325 } else {
326 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
327 }
328
bsalomon@google.com347c3822013-05-01 20:10:01 +0000329 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000330 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
331 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
332 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
333 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000334
335 this->initConfigRenderableTable(ctxInfo);
336}
337
338void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
339
340 // OpenGL < 3.0
341 // no support for render targets unless the GL_ARB_framebuffer_object
342 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
343 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
344 // probably don't get R8 in this case.
345
346 // OpenGL 3.0
347 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
348 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
349
350 // >= OpenGL 3.1
351 // base color renderable: RED, RG, RGB, and RGBA
352 // sized derivatives: R8, RGBA4, RGBA8
353 // if the GL_ARB_compatibility extension is supported then we get back
354 // support for GL_ALPHA and ALPHA8
355
356 // GL_EXT_bgra adds BGRA render targets to any version
357
358 // ES 2.0
359 // color renderable: RGBA4, RGB5_A1, RGB565
360 // GL_EXT_texture_rg adds support for R8 as a color render target
361 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
362 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
363
364 // ES 3.0
365 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
366 // below already account for this).
367
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000368 enum {
369 kNo_MSAA = 0,
370 kYes_MSAA = 1,
371 };
372
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000373 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
374 // Post 3.0 we will get R8
375 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
376 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
377 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000378 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
379 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000380 }
381 } else {
382 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000383 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
384 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000385 }
386
387 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
388 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000389 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
390 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000391 }
392
393 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000394 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
395 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000396
397 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000398 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000399 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000400 }
401
402 if (this->fBGRAFormatSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000403 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
404 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
405 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000406 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
407 if (ctxInfo.extensions().has("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
408 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
409 } else {
410 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
411 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
412 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000413 }
414
415 // If we don't support MSAA then undo any places above where we set a config as renderable with
416 // msaa.
417 if (kNone_MSFBOType == fMSFBOType) {
418 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
419 fConfigRenderSupport[i][kYes_MSAA] = false;
420 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000421 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000422}
423
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000424bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000425 GrGLenum format,
426 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000427 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
428 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000429 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000430 }
431
432 if (!fTwoFormatLimit) {
433 // not limited by ES 2's constraints
434 return true;
435 }
436
bsalomon@google.com548a4332012-07-11 19:45:22 +0000437 GrGLint otherFormat = GR_GL_RGBA;
438 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000439
440 // The other supported format/type combo supported for ReadPixels
441 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000442 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000443 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
444 &otherFormat);
445
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000446 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000447 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
448 &otherType);
449
bsalomon@google.com548a4332012-07-11 19:45:22 +0000450 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000451}
452
robertphillips@google.com6177e692013-02-28 20:16:25 +0000453void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000454
455 fMSFBOType = kNone_MSFBOType;
456 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000457 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
458 // ES3 driver bugs on at least one device with a tiled GPU (N10).
459 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
460 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
461 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
462 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
463 } else if (!GR_GL_IGNORE_ES3_MSAA && ctxInfo.version() >= GR_GL_VER(3,0)) {
464 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
465 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
466 // chrome's extension is equivalent to the EXT msaa
467 // and fbo_blit extensions.
468 fMSFBOType = kDesktop_EXT_MSFBOType;
469 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
470 fMSFBOType = kES_Apple_MSFBOType;
471 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000472 } else {
473 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
474 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000475 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000476 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
477 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000478 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000479 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000480 }
481}
482
483namespace {
484const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
485}
486
487void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
488
489 // Build up list of legal stencil formats (though perhaps not supported on
490 // the particular gpu/driver) from most preferred to least.
491
492 // these consts are in order of most preferred to least preferred
493 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
494
495 static const StencilFormat
496 // internal Format stencil bits total bits packed?
497 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
498 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
499 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
500 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000501 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000502 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
503
504 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
505 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000506 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000507 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
508 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
509
510 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
511 // require FBO support we can expect these are legal formats and don't
512 // check. These also all support the unsized GL_STENCIL_INDEX.
513 fStencilFormats.push_back() = gS8;
514 fStencilFormats.push_back() = gS16;
515 if (supportsPackedDS) {
516 fStencilFormats.push_back() = gD24S8;
517 }
518 fStencilFormats.push_back() = gS4;
519 if (supportsPackedDS) {
520 fStencilFormats.push_back() = gDS;
521 }
522 } else {
523 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
524 // for other formats.
525 // ES doesn't support using the unsized format.
526
527 fStencilFormats.push_back() = gS8;
528 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000529 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
530 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000531 fStencilFormats.push_back() = gD24S8;
532 }
533 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
534 fStencilFormats.push_back() = gS4;
535 }
536 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000537 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000538 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
539}
540
541void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
542 GrPixelConfig config,
543 const GrGLStencilBuffer::Format& format) {
544#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
545 return;
546#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000547 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
548 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000549 int count = fStencilFormats.count();
550 // we expect a really small number of possible formats so linear search
551 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000552 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000553 for (int i = 0; i < count; ++i) {
554 if (format.fInternalFormat ==
555 fStencilFormats[i].fInternalFormat) {
556 fStencilVerifiedColorConfigs[i].markVerified(config);
557 return;
558 }
559 }
560 GrCrash("Why are we seeing a stencil format that "
561 "GrGLCaps doesn't know about.");
562}
563
564bool GrGLCaps::isColorConfigAndStencilFormatVerified(
565 GrPixelConfig config,
566 const GrGLStencilBuffer::Format& format) const {
567#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
568 return false;
569#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000570 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000571 int count = fStencilFormats.count();
572 // we expect a really small number of possible formats so linear search
573 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000574 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000575 for (int i = 0; i < count; ++i) {
576 if (format.fInternalFormat ==
577 fStencilFormats[i].fInternalFormat) {
578 return fStencilVerifiedColorConfigs[i].isVerified(config);
579 }
580 }
581 GrCrash("Why are we seeing a stencil format that "
582 "GLCaps doesn't know about.");
583 return false;
584}
585
586void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000587
588 INHERITED::print();
589
590 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000591 for (int i = 0; i < fStencilFormats.count(); ++i) {
592 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
593 i,
594 fStencilFormats[i].fStencilBits,
595 fStencilFormats[i].fTotalBits);
596 }
597
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000598 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000599 "None",
600 "ARB",
601 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000602 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000603 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000604 "IMG MS To Texture",
605 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000606 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000607 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
608 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
609 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000610 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
611 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
612 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
613 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000614 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
615
616 static const char* kFBFetchTypeStr[] = {
617 "None",
618 "EXT",
619 "NV",
620 };
621 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
622 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
623 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
624 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
625
626
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000627 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
628 GrPrintf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO"));
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000629 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
630 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000631 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000632 GrPrintf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
633 if (fFixedFunctionSupport) {
634 GrPrintf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
635 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000636 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
637 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
638 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
639 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
640 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
641 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
642 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
643 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
644 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
645
646 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
647 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
648 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
649 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000650 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000651 GrPrintf("Fragment coord conventions support: %s\n",
652 (fFragCoordsConventionSupport ? "YES": "NO"));
653 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
654 GrPrintf("Use non-VBO for dynamic data: %s\n",
655 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000656 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000657 GrPrintf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000658}