blob: fd74d50d715b1a28c20b0fc4e5ae1616418d0aaf [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.comf7fa8062012-02-14 14:09:57 +0000104 if (kES2_GrGLBinding == binding) {
105 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
106 &fMaxFragmentUniformVectors);
107 } else {
108 GrAssert(kDesktop_GrGLBinding == binding);
109 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 {
119 fRGBA8RenderbufferSupport = ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
120 ctxInfo.hasExtension("GL_ARM_rgba8");
121 }
122
123 if (kDesktop_GrGLBinding == binding) {
124 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
125 ctxInfo.hasExtension("GL_EXT_bgra");
126 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
128 fBGRAFormatSupport = true;
129 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
130 fBGRAFormatSupport = true;
131 fBGRAIsInternalFormat = true;
132 }
133 GrAssert(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000134 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000135 }
136
137 if (kDesktop_GrGLBinding == binding) {
138 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
139 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
140 } else {
141 fTextureSwizzleSupport = false;
142 }
143
144 if (kDesktop_GrGLBinding == binding) {
145 fUnpackRowLengthSupport = true;
146 fUnpackFlipYSupport = false;
147 fPackRowLengthSupport = true;
148 fPackFlipYSupport = false;
149 } else {
150 fUnpackRowLengthSupport =ctxInfo.hasExtension("GL_EXT_unpack_subimage");
151 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
152 // no extension for pack row length
153 fPackRowLengthSupport = false;
154 fPackFlipYSupport =
155 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
156 }
157
158 fTextureUsageSupport = (kES2_GrGLBinding == binding) &&
159 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
160
161 // Tex storage is in desktop 4.2 and can be an extension to desktop or ES.
162 fTexStorageSupport = (kDesktop_GrGLBinding == binding &&
163 version >= GR_GL_VER(4,2)) ||
164 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
165 ctxInfo.hasExtension("GL_EXT_texture_storage");
166
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000167 // ARB_texture_rg is part of OpenGL 3.0
168 if (kDesktop_GrGLBinding == binding) {
169 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
170 ctxInfo.hasExtension("GL_ARB_texture_rg");
171 } else {
172 fTextureRedSupport = ctxInfo.hasExtension("GL_EXT_texture_rg");
173 }
174
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000175 fImagingSupport = kDesktop_GrGLBinding == binding &&
176 ctxInfo.hasExtension("GL_ARB_imaging");
177
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000178 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
179 // ReadPixels. The other format has to checked at run-time since it
180 // can change based on which render target is bound
181 fTwoFormatLimit = kES2_GrGLBinding == binding;
182
bsalomon@google.com706f6682012-10-23 14:53:55 +0000183 // Known issue on at least some Intel platforms:
184 // http://code.google.com/p/skia/issues/detail?id=946
185 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
186 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
187 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
188 }
189
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000190 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
191 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
192 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
193 // limit this decision to specific GPU families rather than basing it on the vendor alone.
194 if (!GR_GL_MUST_USE_VBO &&
195 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000196 fUseNonVBOVertexAndIndexDynamicData = true;
197 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000198
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000199 if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) {
200 GrGLint profileMask;
201 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
202 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
203 }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000204
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000205 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
206
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000207 if (kDesktop_GrGLBinding == binding) {
208 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
209 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
210 } else {
211 fVertexArrayObjectSupport = ctxInfo.hasExtension("GL_OES_vertex_array_object");
212 }
213
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000214 if (kES2_GrGLBinding == binding) {
215 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
216 fFBFetchType = kEXT_FBFetchType;
217 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
218 fFBFetchType = kNV_FBFetchType;
219 }
220 }
221
robertphillips@google.com6177e692013-02-28 20:16:25 +0000222 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000223 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000224
225 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000226 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000227 **************************************************************************/
bsalomon@google.combcce8922013-03-25 15:38:39 +0000228 GrGLint numFormats;
229 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
bungeman@google.com71033442013-05-01 14:21:20 +0000230 if (numFormats) {
231 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
232 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
233 for (int i = 0; i < numFormats; ++i) {
234 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
235 f8BitPaletteSupport = true;
236 break;
237 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000238 }
239 }
240
241 if (kDesktop_GrGLBinding == binding) {
242 // we could also look for GL_ATI_separate_stencil extension or
243 // GL_EXT_stencil_two_side but they use different function signatures
244 // than GL2.0+ (and than each other).
245 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
246 // supported on GL 1.4 and higher or by extension
247 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
248 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
249 } else {
250 // ES 2 has two sided stencil and stencil wrap
251 fTwoSidedStencilSupport = true;
252 fStencilWrapOpsSupport = true;
253 }
254
255 if (kDesktop_GrGLBinding == binding) {
256 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
257 // glMapBuffer.
258 } else {
259 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
260 }
261
262 if (kDesktop_GrGLBinding == binding) {
263 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
264 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
265 fNPOTTextureTileSupport = true;
266 } else {
267 fNPOTTextureTileSupport = false;
268 }
269 } else {
270 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
271 fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot");
272 }
273
274 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
275
276 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
277 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
278 // Our render targets are always created with textures as the color
279 // attachment, hence this min:
280 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
281
282 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
283 ctxInfo.hasExtension("GL_NV_path_rendering");
284
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000285 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
286
bsalomon@google.combcce8922013-03-25 15:38:39 +0000287 // Enable supported shader-related caps
288 if (kDesktop_GrGLBinding == binding) {
289 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
290 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
291 fShaderDerivativeSupport = true;
292 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
293 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
294 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
295 } else {
296 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
297 }
298
bsalomon@google.com347c3822013-05-01 20:10:01 +0000299 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000300 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
301 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
302 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
303 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000304}
305
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000306bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000307 GrGLenum format,
308 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000309 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
310 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000311 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000312 }
313
314 if (!fTwoFormatLimit) {
315 // not limited by ES 2's constraints
316 return true;
317 }
318
bsalomon@google.com548a4332012-07-11 19:45:22 +0000319 GrGLint otherFormat = GR_GL_RGBA;
320 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000321
322 // The other supported format/type combo supported for ReadPixels
323 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000324 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000325 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
326 &otherFormat);
327
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000328 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000329 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
330 &otherType);
331
bsalomon@google.com548a4332012-07-11 19:45:22 +0000332 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000333}
334
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000335namespace {
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000336bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left,
337 const GrGLCaps::MSAACoverageMode& right) {
338 if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) {
339 return true;
340 } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) {
341 return false;
342 } else if (left.fColorSampleCnt < right.fColorSampleCnt) {
343 return true;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000344 }
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000345 return false;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000346}
347}
348
robertphillips@google.com6177e692013-02-28 20:16:25 +0000349void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000350
351 fMSFBOType = kNone_MSFBOType;
352 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
353 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
354 // chrome's extension is equivalent to the EXT msaa
355 // and fbo_blit extensions.
bsalomon@google.com347c3822013-05-01 20:10:01 +0000356 fMSFBOType = kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000357 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000358 fMSFBOType = kES_Apple_MSFBOType;
359 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
360 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000361 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000362 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000363 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000364 } else {
365 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
366 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000367 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000368 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
369 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000370 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000371 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000372 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
373 // on GL 4.2+. It's format-specific, though. See also
374 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
375 // rather than requested sample counts in cache key.
376 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
377 fCoverageAAType = kNVDesktop_CoverageAAType;
378 GrGLint count;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000379 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000380 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
381 &count);
382 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000383 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000384 GR_GL_MULTISAMPLE_COVERAGE_MODES,
385 (int*)&fMSAACoverageModes[0]);
386 // The NV driver seems to return the modes already sorted but the
387 // spec doesn't require this. So we sort.
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000388 typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_less> SortFunctor;
389 SortFunctor sortFunctor;
390 SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(),
391 fMSAACoverageModes.end() - 1,
392 sortFunctor);
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000393 }
394 }
395}
396
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000397const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000398 static const MSAACoverageMode kNoneMode = {0, 0};
399 if (0 == fMSAACoverageModes.count()) {
400 return kNoneMode;
401 } else {
402 GrAssert(kNone_CoverageAAType != fCoverageAAType);
403 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
404 desiredSampleCount = GrMin(desiredSampleCount, max);
405 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000406 int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverageModes[0],
407 fMSAACoverageModes.count(),
408 desiredMode,
409 sizeof(MSAACoverageMode));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000410 if (idx < 0) {
411 idx = ~idx;
412 }
413 GrAssert(idx >= 0 && idx < fMSAACoverageModes.count());
414 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000415 }
416}
417
418namespace {
419const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
420}
421
422void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
423
424 // Build up list of legal stencil formats (though perhaps not supported on
425 // the particular gpu/driver) from most preferred to least.
426
427 // these consts are in order of most preferred to least preferred
428 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
429
430 static const StencilFormat
431 // internal Format stencil bits total bits packed?
432 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
433 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
434 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
435 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000436 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000437 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
438
439 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
440 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000441 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000442 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
443 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
444
445 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
446 // require FBO support we can expect these are legal formats and don't
447 // check. These also all support the unsized GL_STENCIL_INDEX.
448 fStencilFormats.push_back() = gS8;
449 fStencilFormats.push_back() = gS16;
450 if (supportsPackedDS) {
451 fStencilFormats.push_back() = gD24S8;
452 }
453 fStencilFormats.push_back() = gS4;
454 if (supportsPackedDS) {
455 fStencilFormats.push_back() = gDS;
456 }
457 } else {
458 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
459 // for other formats.
460 // ES doesn't support using the unsized format.
461
462 fStencilFormats.push_back() = gS8;
463 //fStencilFormats.push_back() = gS16;
464 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
465 fStencilFormats.push_back() = gD24S8;
466 }
467 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
468 fStencilFormats.push_back() = gS4;
469 }
470 }
471 GrAssert(0 == fStencilVerifiedColorConfigs.count());
472 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
473}
474
475void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
476 GrPixelConfig config,
477 const GrGLStencilBuffer::Format& format) {
478#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
479 return;
480#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000481 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000482 GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
483 int count = fStencilFormats.count();
484 // we expect a really small number of possible formats so linear search
485 // should be OK
486 GrAssert(count < 16);
487 for (int i = 0; i < count; ++i) {
488 if (format.fInternalFormat ==
489 fStencilFormats[i].fInternalFormat) {
490 fStencilVerifiedColorConfigs[i].markVerified(config);
491 return;
492 }
493 }
494 GrCrash("Why are we seeing a stencil format that "
495 "GrGLCaps doesn't know about.");
496}
497
498bool GrGLCaps::isColorConfigAndStencilFormatVerified(
499 GrPixelConfig config,
500 const GrGLStencilBuffer::Format& format) const {
501#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
502 return false;
503#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000504 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000505 int count = fStencilFormats.count();
506 // we expect a really small number of possible formats so linear search
507 // should be OK
508 GrAssert(count < 16);
509 for (int i = 0; i < count; ++i) {
510 if (format.fInternalFormat ==
511 fStencilFormats[i].fInternalFormat) {
512 return fStencilVerifiedColorConfigs[i].isVerified(config);
513 }
514 }
515 GrCrash("Why are we seeing a stencil format that "
516 "GLCaps doesn't know about.");
517 return false;
518}
519
520void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000521
522 INHERITED::print();
523
524 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000525 for (int i = 0; i < fStencilFormats.count(); ++i) {
526 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
527 i,
528 fStencilFormats[i].fStencilBits,
529 fStencilFormats[i].fTotalBits);
530 }
531
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000532 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000533 "None",
534 "ARB",
535 "EXT",
536 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000537 "IMG MS To Texture",
538 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000539 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000540 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
541 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
542 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
543 GR_STATIC_ASSERT(3 == kES_Apple_MSFBOType);
544 GR_STATIC_ASSERT(4 == kES_IMG_MsToTexture_MSFBOType);
545 GR_STATIC_ASSERT(5 == kES_EXT_MsToTexture_MSFBOType);
546 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
547
548 static const char* kFBFetchTypeStr[] = {
549 "None",
550 "EXT",
551 "NV",
552 };
553 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
554 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
555 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
556 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
557
558
559 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
560 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000561 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000562 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
563 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
564 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
565 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
566 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
567 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
568 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
569 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
570 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
571
572 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
573 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
574 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
575 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000576 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000577 GrPrintf("Fragment coord conventions support: %s\n",
578 (fFragCoordsConventionSupport ? "YES": "NO"));
579 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
580 GrPrintf("Use non-VBO for dynamic data: %s\n",
581 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
582 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000583 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000584}