blob: 5568c48123834ca6328bd207240f586c2adfc6e5 [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.comf7fa8062012-02-14 14:09:57 +000012
bsalomon@google.combcce8922013-03-25 15:38:39 +000013SK_DEFINE_INST_COUNT(GrGLCaps)
14
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000015GrGLCaps::GrGLCaps() {
16 this->reset();
17}
18
19void GrGLCaps::reset() {
bsalomon@google.combcce8922013-03-25 15:38:39 +000020 INHERITED::reset();
21
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000022 fVerifiedColorConfigs.reset();
23 fStencilFormats.reset();
24 fStencilVerifiedColorConfigs.reset();
25 fMSFBOType = kNone_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000026 fCoverageAAType = kNone_CoverageAAType;
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;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fRGBA8RenderbufferSupport = false;
31 fBGRAFormatSupport = false;
32 fBGRAIsInternalFormat = false;
33 fTextureSwizzleSupport = false;
34 fUnpackRowLengthSupport = false;
35 fUnpackFlipYSupport = false;
36 fPackRowLengthSupport = false;
37 fPackFlipYSupport = false;
38 fTextureUsageSupport = false;
39 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000040 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000041 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000042 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000043 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000044 fVertexArrayObjectSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000045 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000046 fIsCoreProfile = false;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000047 fDiscardFBSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000048}
49
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000050GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000051 *this = caps;
52}
53
54GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000055 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000056 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
57 fStencilFormats = caps.fStencilFormats;
58 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
59 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000060 fMaxVertexAttributes = caps.fMaxVertexAttributes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000061 fMSFBOType = caps.fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000062 fCoverageAAType = caps.fCoverageAAType;
63 fMSAACoverageModes = caps.fMSAACoverageModes;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000064 fFBFetchType = caps.fFBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000065 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
66 fBGRAFormatSupport = caps.fBGRAFormatSupport;
67 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
68 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
69 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
70 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
71 fPackRowLengthSupport = caps.fPackRowLengthSupport;
72 fPackFlipYSupport = caps.fPackFlipYSupport;
73 fTextureUsageSupport = caps.fTextureUsageSupport;
74 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000075 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000076 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000077 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000078 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000079 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000080 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000081 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000082 fDiscardFBSupport = caps.fDiscardFBSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000083
84 return *this;
85}
86
robertphillips@google.com6177e692013-02-28 20:16:25 +000087void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088
89 this->reset();
90 if (!ctxInfo.isInitialized()) {
91 return;
92 }
93
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094 GrGLBinding binding = ctxInfo.binding();
95 GrGLVersion version = ctxInfo.version();
96
bsalomon@google.combcce8922013-03-25 15:38:39 +000097 /**************************************************************************
98 * Caps specific to GrGLCaps
99 **************************************************************************/
100
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 if (kES2_GrGLBinding == binding) {
102 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
103 &fMaxFragmentUniformVectors);
104 } else {
105 GrAssert(kDesktop_GrGLBinding == binding);
106 GrGLint max;
107 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
108 fMaxFragmentUniformVectors = max / 4;
109 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000110 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111
112 if (kDesktop_GrGLBinding == binding) {
113 fRGBA8RenderbufferSupport = true;
114 } else {
115 fRGBA8RenderbufferSupport = ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
116 ctxInfo.hasExtension("GL_ARM_rgba8");
117 }
118
119 if (kDesktop_GrGLBinding == binding) {
120 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
121 ctxInfo.hasExtension("GL_EXT_bgra");
122 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000123 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
124 fBGRAFormatSupport = true;
125 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
126 fBGRAFormatSupport = true;
127 fBGRAIsInternalFormat = true;
128 }
129 GrAssert(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000130 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000131 }
132
133 if (kDesktop_GrGLBinding == binding) {
134 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
135 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
136 } else {
137 fTextureSwizzleSupport = false;
138 }
139
140 if (kDesktop_GrGLBinding == binding) {
141 fUnpackRowLengthSupport = true;
142 fUnpackFlipYSupport = false;
143 fPackRowLengthSupport = true;
144 fPackFlipYSupport = false;
145 } else {
146 fUnpackRowLengthSupport =ctxInfo.hasExtension("GL_EXT_unpack_subimage");
147 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
148 // no extension for pack row length
149 fPackRowLengthSupport = false;
150 fPackFlipYSupport =
151 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
152 }
153
154 fTextureUsageSupport = (kES2_GrGLBinding == binding) &&
155 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
156
157 // Tex storage is in desktop 4.2 and can be an extension to desktop or ES.
158 fTexStorageSupport = (kDesktop_GrGLBinding == binding &&
159 version >= GR_GL_VER(4,2)) ||
160 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
161 ctxInfo.hasExtension("GL_EXT_texture_storage");
162
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000163 // ARB_texture_rg is part of OpenGL 3.0
164 if (kDesktop_GrGLBinding == binding) {
165 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
166 ctxInfo.hasExtension("GL_ARB_texture_rg");
167 } else {
168 fTextureRedSupport = ctxInfo.hasExtension("GL_EXT_texture_rg");
169 }
170
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000171 fImagingSupport = kDesktop_GrGLBinding == binding &&
172 ctxInfo.hasExtension("GL_ARB_imaging");
173
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000174 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
175 // ReadPixels. The other format has to checked at run-time since it
176 // can change based on which render target is bound
177 fTwoFormatLimit = kES2_GrGLBinding == binding;
178
bsalomon@google.com706f6682012-10-23 14:53:55 +0000179 // Known issue on at least some Intel platforms:
180 // http://code.google.com/p/skia/issues/detail?id=946
181 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
182 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
183 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
184 }
185
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000186 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
187 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
188 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
189 // limit this decision to specific GPU families rather than basing it on the vendor alone.
190 if (!GR_GL_MUST_USE_VBO &&
191 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000192 fUseNonVBOVertexAndIndexDynamicData = true;
193 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000194
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000195 if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) {
196 GrGLint profileMask;
197 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
198 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
199 }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000200
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000201 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
202
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000203 if (kDesktop_GrGLBinding == binding) {
204 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
205 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
206 } else {
207 fVertexArrayObjectSupport = ctxInfo.hasExtension("GL_OES_vertex_array_object");
208 }
209
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000210 if (kES2_GrGLBinding == binding) {
211 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
212 fFBFetchType = kEXT_FBFetchType;
213 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
214 fFBFetchType = kNV_FBFetchType;
215 }
216 }
217
robertphillips@google.com6177e692013-02-28 20:16:25 +0000218 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000219 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000220
221 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000222 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000223 **************************************************************************/
224 GrGLint maxTextureUnits;
225 // check FS and fixed-function texture unit limits
226 // we only use textures in the fragment stage currently.
227 // checks are > to make sure we have a spare unit.
228 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000229
230 GrGLint numFormats;
231 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
bungeman@google.com71033442013-05-01 14:21:20 +0000232 if (numFormats) {
233 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
234 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
235 for (int i = 0; i < numFormats; ++i) {
236 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
237 f8BitPaletteSupport = true;
238 break;
239 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000240 }
241 }
242
243 if (kDesktop_GrGLBinding == binding) {
244 // we could also look for GL_ATI_separate_stencil extension or
245 // GL_EXT_stencil_two_side but they use different function signatures
246 // than GL2.0+ (and than each other).
247 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
248 // supported on GL 1.4 and higher or by extension
249 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
250 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
251 } else {
252 // ES 2 has two sided stencil and stencil wrap
253 fTwoSidedStencilSupport = true;
254 fStencilWrapOpsSupport = true;
255 }
256
257 if (kDesktop_GrGLBinding == binding) {
258 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
259 // glMapBuffer.
260 } else {
261 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
262 }
263
264 if (kDesktop_GrGLBinding == binding) {
265 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
266 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
267 fNPOTTextureTileSupport = true;
268 } else {
269 fNPOTTextureTileSupport = false;
270 }
271 } else {
272 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
273 fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot");
274 }
275
276 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
277
278 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
279 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
280 // Our render targets are always created with textures as the color
281 // attachment, hence this min:
282 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
283
284 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
285 ctxInfo.hasExtension("GL_NV_path_rendering");
286
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000287 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
288
bsalomon@google.combcce8922013-03-25 15:38:39 +0000289 // Enable supported shader-related caps
290 if (kDesktop_GrGLBinding == binding) {
291 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
292 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
293 fShaderDerivativeSupport = true;
294 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
295 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
296 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
297 } else {
298 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
299 }
300
bsalomon@google.com347c3822013-05-01 20:10:01 +0000301 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000302 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
303 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
304 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
305 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000306}
307
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000308bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000309 GrGLenum format,
310 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000311 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
312 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000313 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000314 }
315
316 if (!fTwoFormatLimit) {
317 // not limited by ES 2's constraints
318 return true;
319 }
320
bsalomon@google.com548a4332012-07-11 19:45:22 +0000321 GrGLint otherFormat = GR_GL_RGBA;
322 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000323
324 // The other supported format/type combo supported for ReadPixels
325 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000326 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000327 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
328 &otherFormat);
329
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000330 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000331 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
332 &otherType);
333
bsalomon@google.com548a4332012-07-11 19:45:22 +0000334 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000335}
336
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000337namespace {
338int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left,
339 const GrGLCaps::MSAACoverageMode* right) {
340 if (left->fCoverageSampleCnt < right->fCoverageSampleCnt) {
341 return -1;
342 } else if (right->fCoverageSampleCnt < left->fCoverageSampleCnt) {
343 return 1;
344 } else if (left->fColorSampleCnt < right->fColorSampleCnt) {
345 return -1;
346 } else if (right->fColorSampleCnt < left->fColorSampleCnt) {
347 return 1;
348 }
349 return 0;
350}
351}
352
robertphillips@google.com6177e692013-02-28 20:16:25 +0000353void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000354
355 fMSFBOType = kNone_MSFBOType;
356 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
357 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
358 // chrome's extension is equivalent to the EXT msaa
359 // and fbo_blit extensions.
bsalomon@google.com347c3822013-05-01 20:10:01 +0000360 fMSFBOType = kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000361 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000362 fMSFBOType = kES_Apple_MSFBOType;
363 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
364 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000365 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000366 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000367 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000368 } else {
369 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
370 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000371 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000372 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
373 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000374 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000375 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000376 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
377 // on GL 4.2+. It's format-specific, though. See also
378 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
379 // rather than requested sample counts in cache key.
380 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
381 fCoverageAAType = kNVDesktop_CoverageAAType;
382 GrGLint 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_MAX_MULTISAMPLE_COVERAGE_MODES,
385 &count);
386 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000387 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000388 GR_GL_MULTISAMPLE_COVERAGE_MODES,
389 (int*)&fMSAACoverageModes[0]);
390 // The NV driver seems to return the modes already sorted but the
391 // spec doesn't require this. So we sort.
reed@google.comc7a67cb2012-05-07 14:52:12 +0000392 qsort(&fMSAACoverageModes[0],
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000393 count,
394 sizeof(MSAACoverageMode),
reed@google.comc7a67cb2012-05-07 14:52:12 +0000395 SkCastForQSort(coverage_mode_compare));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000396 }
397 }
398}
399
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000400const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000401 static const MSAACoverageMode kNoneMode = {0, 0};
402 if (0 == fMSAACoverageModes.count()) {
403 return kNoneMode;
404 } else {
405 GrAssert(kNone_CoverageAAType != fCoverageAAType);
406 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
407 desiredSampleCount = GrMin(desiredSampleCount, max);
408 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
409 int idx = SkTSearch<MSAACoverageMode>(&fMSAACoverageModes[0],
410 fMSAACoverageModes.count(),
411 desiredMode,
412 sizeof(MSAACoverageMode),
413 &coverage_mode_compare);
414 if (idx < 0) {
415 idx = ~idx;
416 }
417 GrAssert(idx >= 0 && idx < fMSAACoverageModes.count());
418 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000419 }
420}
421
422namespace {
423const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
424}
425
426void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
427
428 // Build up list of legal stencil formats (though perhaps not supported on
429 // the particular gpu/driver) from most preferred to least.
430
431 // these consts are in order of most preferred to least preferred
432 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
433
434 static const StencilFormat
435 // internal Format stencil bits total bits packed?
436 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
437 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
438 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
439 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000440 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000441 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
442
443 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
444 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000445 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000446 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
447 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
448
449 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
450 // require FBO support we can expect these are legal formats and don't
451 // check. These also all support the unsized GL_STENCIL_INDEX.
452 fStencilFormats.push_back() = gS8;
453 fStencilFormats.push_back() = gS16;
454 if (supportsPackedDS) {
455 fStencilFormats.push_back() = gD24S8;
456 }
457 fStencilFormats.push_back() = gS4;
458 if (supportsPackedDS) {
459 fStencilFormats.push_back() = gDS;
460 }
461 } else {
462 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
463 // for other formats.
464 // ES doesn't support using the unsized format.
465
466 fStencilFormats.push_back() = gS8;
467 //fStencilFormats.push_back() = gS16;
468 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
469 fStencilFormats.push_back() = gD24S8;
470 }
471 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
472 fStencilFormats.push_back() = gS4;
473 }
474 }
475 GrAssert(0 == fStencilVerifiedColorConfigs.count());
476 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
477}
478
479void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
480 GrPixelConfig config,
481 const GrGLStencilBuffer::Format& format) {
482#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
483 return;
484#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000485 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000486 GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
487 int count = fStencilFormats.count();
488 // we expect a really small number of possible formats so linear search
489 // should be OK
490 GrAssert(count < 16);
491 for (int i = 0; i < count; ++i) {
492 if (format.fInternalFormat ==
493 fStencilFormats[i].fInternalFormat) {
494 fStencilVerifiedColorConfigs[i].markVerified(config);
495 return;
496 }
497 }
498 GrCrash("Why are we seeing a stencil format that "
499 "GrGLCaps doesn't know about.");
500}
501
502bool GrGLCaps::isColorConfigAndStencilFormatVerified(
503 GrPixelConfig config,
504 const GrGLStencilBuffer::Format& format) const {
505#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
506 return false;
507#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000508 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000509 int count = fStencilFormats.count();
510 // we expect a really small number of possible formats so linear search
511 // should be OK
512 GrAssert(count < 16);
513 for (int i = 0; i < count; ++i) {
514 if (format.fInternalFormat ==
515 fStencilFormats[i].fInternalFormat) {
516 return fStencilVerifiedColorConfigs[i].isVerified(config);
517 }
518 }
519 GrCrash("Why are we seeing a stencil format that "
520 "GLCaps doesn't know about.");
521 return false;
522}
523
524void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000525
526 INHERITED::print();
527
528 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000529 for (int i = 0; i < fStencilFormats.count(); ++i) {
530 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
531 i,
532 fStencilFormats[i].fStencilBits,
533 fStencilFormats[i].fTotalBits);
534 }
535
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000536 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000537 "None",
538 "ARB",
539 "EXT",
540 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000541 "IMG MS To Texture",
542 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000543 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000544 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
545 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
546 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
547 GR_STATIC_ASSERT(3 == kES_Apple_MSFBOType);
548 GR_STATIC_ASSERT(4 == kES_IMG_MsToTexture_MSFBOType);
549 GR_STATIC_ASSERT(5 == kES_EXT_MsToTexture_MSFBOType);
550 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
551
552 static const char* kFBFetchTypeStr[] = {
553 "None",
554 "EXT",
555 "NV",
556 };
557 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
558 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
559 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
560 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
561
562
563 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
564 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000565 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000566 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
567 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
568 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
569 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
570 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
571 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
572 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
573 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
574 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
575
576 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
577 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
578 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
579 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000580 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000581 GrPrintf("Fragment coord conventions support: %s\n",
582 (fFragCoordsConventionSupport ? "YES": "NO"));
583 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
584 GrPrintf("Use non-VBO for dynamic data: %s\n",
585 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
586 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000587 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000588}