blob: b868d6a51f4349fcf6c489045f8ed50efaf52cc0 [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.comf7fa8062012-02-14 14:09:57 +000027 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000028 fMaxVertexAttributes = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fRGBA8RenderbufferSupport = false;
30 fBGRAFormatSupport = false;
31 fBGRAIsInternalFormat = false;
32 fTextureSwizzleSupport = false;
33 fUnpackRowLengthSupport = false;
34 fUnpackFlipYSupport = false;
35 fPackRowLengthSupport = false;
36 fPackFlipYSupport = false;
37 fTextureUsageSupport = false;
38 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000039 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000040 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000041 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000042 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000043 fVertexArrayObjectSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000044 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000046 fDiscardFBSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000047}
48
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000049GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000050 *this = caps;
51}
52
53GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000054 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000055 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
56 fStencilFormats = caps.fStencilFormats;
57 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
58 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000059 fMaxVertexAttributes = caps.fMaxVertexAttributes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060 fMSFBOType = caps.fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000061 fCoverageAAType = caps.fCoverageAAType;
62 fMSAACoverageModes = caps.fMSAACoverageModes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000063 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
64 fBGRAFormatSupport = caps.fBGRAFormatSupport;
65 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
66 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
67 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
68 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
69 fPackRowLengthSupport = caps.fPackRowLengthSupport;
70 fPackFlipYSupport = caps.fPackFlipYSupport;
71 fTextureUsageSupport = caps.fTextureUsageSupport;
72 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000073 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000074 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000075 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000076 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000077 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000078 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000079 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000080 fDiscardFBSupport = caps.fDiscardFBSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000081
82 return *this;
83}
84
robertphillips@google.com6177e692013-02-28 20:16:25 +000085void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086
87 this->reset();
88 if (!ctxInfo.isInitialized()) {
89 return;
90 }
91
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000092 GrGLBinding binding = ctxInfo.binding();
93 GrGLVersion version = ctxInfo.version();
94
bsalomon@google.combcce8922013-03-25 15:38:39 +000095 /**************************************************************************
96 * Caps specific to GrGLCaps
97 **************************************************************************/
98
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099 if (kES2_GrGLBinding == binding) {
100 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
101 &fMaxFragmentUniformVectors);
102 } else {
103 GrAssert(kDesktop_GrGLBinding == binding);
104 GrGLint max;
105 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
106 fMaxFragmentUniformVectors = max / 4;
107 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000108 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109
110 if (kDesktop_GrGLBinding == binding) {
111 fRGBA8RenderbufferSupport = true;
112 } else {
113 fRGBA8RenderbufferSupport = ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
114 ctxInfo.hasExtension("GL_ARM_rgba8");
115 }
116
117 if (kDesktop_GrGLBinding == binding) {
118 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
119 ctxInfo.hasExtension("GL_EXT_bgra");
120 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000121 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
122 fBGRAFormatSupport = true;
123 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
124 fBGRAFormatSupport = true;
125 fBGRAIsInternalFormat = true;
126 }
127 GrAssert(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000128 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000129 }
130
131 if (kDesktop_GrGLBinding == binding) {
132 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
133 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
134 } else {
135 fTextureSwizzleSupport = false;
136 }
137
138 if (kDesktop_GrGLBinding == binding) {
139 fUnpackRowLengthSupport = true;
140 fUnpackFlipYSupport = false;
141 fPackRowLengthSupport = true;
142 fPackFlipYSupport = false;
143 } else {
144 fUnpackRowLengthSupport =ctxInfo.hasExtension("GL_EXT_unpack_subimage");
145 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
146 // no extension for pack row length
147 fPackRowLengthSupport = false;
148 fPackFlipYSupport =
149 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
150 }
151
152 fTextureUsageSupport = (kES2_GrGLBinding == binding) &&
153 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
154
155 // Tex storage is in desktop 4.2 and can be an extension to desktop or ES.
156 fTexStorageSupport = (kDesktop_GrGLBinding == binding &&
157 version >= GR_GL_VER(4,2)) ||
158 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
159 ctxInfo.hasExtension("GL_EXT_texture_storage");
160
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000161 // ARB_texture_rg is part of OpenGL 3.0
162 if (kDesktop_GrGLBinding == binding) {
163 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
164 ctxInfo.hasExtension("GL_ARB_texture_rg");
165 } else {
166 fTextureRedSupport = ctxInfo.hasExtension("GL_EXT_texture_rg");
167 }
168
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000169 fImagingSupport = kDesktop_GrGLBinding == binding &&
170 ctxInfo.hasExtension("GL_ARB_imaging");
171
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000172 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
173 // ReadPixels. The other format has to checked at run-time since it
174 // can change based on which render target is bound
175 fTwoFormatLimit = kES2_GrGLBinding == binding;
176
bsalomon@google.com706f6682012-10-23 14:53:55 +0000177 // Known issue on at least some Intel platforms:
178 // http://code.google.com/p/skia/issues/detail?id=946
179 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
180 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
181 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
182 }
183
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000184 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
185 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
186 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
187 // limit this decision to specific GPU families rather than basing it on the vendor alone.
188 if (!GR_GL_MUST_USE_VBO &&
189 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000190 fUseNonVBOVertexAndIndexDynamicData = true;
191 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000192
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000193 if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) {
194 GrGLint profileMask;
195 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
196 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
197 }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000198
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000199 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
200
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000201 if (kDesktop_GrGLBinding == binding) {
202 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
203 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
204 } else {
205 fVertexArrayObjectSupport = ctxInfo.hasExtension("GL_OES_vertex_array_object");
206 }
207
robertphillips@google.com6177e692013-02-28 20:16:25 +0000208 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000209 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000210
211 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000212 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000213 **************************************************************************/
214 GrGLint maxTextureUnits;
215 // check FS and fixed-function texture unit limits
216 // we only use textures in the fragment stage currently.
217 // checks are > to make sure we have a spare unit.
218 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000219
220 GrGLint numFormats;
221 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
222 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
223 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
224 for (int i = 0; i < numFormats; ++i) {
225 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
226 f8BitPaletteSupport = true;
227 break;
228 }
229 }
230
231 if (kDesktop_GrGLBinding == binding) {
232 // we could also look for GL_ATI_separate_stencil extension or
233 // GL_EXT_stencil_two_side but they use different function signatures
234 // than GL2.0+ (and than each other).
235 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
236 // supported on GL 1.4 and higher or by extension
237 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
238 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
239 } else {
240 // ES 2 has two sided stencil and stencil wrap
241 fTwoSidedStencilSupport = true;
242 fStencilWrapOpsSupport = true;
243 }
244
245 if (kDesktop_GrGLBinding == binding) {
246 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
247 // glMapBuffer.
248 } else {
249 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
250 }
251
252 if (kDesktop_GrGLBinding == binding) {
253 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
254 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
255 fNPOTTextureTileSupport = true;
256 } else {
257 fNPOTTextureTileSupport = false;
258 }
259 } else {
260 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
261 fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot");
262 }
263
264 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
265
266 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
267 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
268 // Our render targets are always created with textures as the color
269 // attachment, hence this min:
270 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
271
272 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
273 ctxInfo.hasExtension("GL_NV_path_rendering");
274
275 // Enable supported shader-related caps
276 if (kDesktop_GrGLBinding == binding) {
277 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
278 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
279 fShaderDerivativeSupport = true;
280 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
281 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
282 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
283 } else {
284 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
285 }
286
287 if (GrGLCaps::kImaginationES_MSFBOType == fMSFBOType) {
288 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
289 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
290 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
291 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000292}
293
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000294bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000295 GrGLenum format,
296 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000297 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
298 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000299 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000300 }
301
302 if (!fTwoFormatLimit) {
303 // not limited by ES 2's constraints
304 return true;
305 }
306
bsalomon@google.com548a4332012-07-11 19:45:22 +0000307 GrGLint otherFormat = GR_GL_RGBA;
308 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000309
310 // The other supported format/type combo supported for ReadPixels
311 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000312 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000313 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
314 &otherFormat);
315
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000316 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000317 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
318 &otherType);
319
bsalomon@google.com548a4332012-07-11 19:45:22 +0000320 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000321}
322
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000323namespace {
324int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left,
325 const GrGLCaps::MSAACoverageMode* right) {
326 if (left->fCoverageSampleCnt < right->fCoverageSampleCnt) {
327 return -1;
328 } else if (right->fCoverageSampleCnt < left->fCoverageSampleCnt) {
329 return 1;
330 } else if (left->fColorSampleCnt < right->fColorSampleCnt) {
331 return -1;
332 } else if (right->fColorSampleCnt < left->fColorSampleCnt) {
333 return 1;
334 }
335 return 0;
336}
337}
338
robertphillips@google.com6177e692013-02-28 20:16:25 +0000339void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000340
341 fMSFBOType = kNone_MSFBOType;
342 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
343 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
344 // chrome's extension is equivalent to the EXT msaa
345 // and fbo_blit extensions.
346 fMSFBOType = kDesktopEXT_MSFBOType;
347 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000348 fMSFBOType = kAppleES_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000349 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
350 fMSFBOType = kImaginationES_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000351 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000352 } else {
353 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
354 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
355 fMSFBOType = GrGLCaps::kDesktopARB_MSFBOType;
356 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
357 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
358 fMSFBOType = GrGLCaps::kDesktopEXT_MSFBOType;
359 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000360 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
361 // on GL 4.2+. It's format-specific, though. See also
362 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
363 // rather than requested sample counts in cache key.
364 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
365 fCoverageAAType = kNVDesktop_CoverageAAType;
366 GrGLint count;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000367 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000368 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
369 &count);
370 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000371 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000372 GR_GL_MULTISAMPLE_COVERAGE_MODES,
373 (int*)&fMSAACoverageModes[0]);
374 // The NV driver seems to return the modes already sorted but the
375 // spec doesn't require this. So we sort.
reed@google.comc7a67cb2012-05-07 14:52:12 +0000376 qsort(&fMSAACoverageModes[0],
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000377 count,
378 sizeof(MSAACoverageMode),
reed@google.comc7a67cb2012-05-07 14:52:12 +0000379 SkCastForQSort(coverage_mode_compare));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000380 }
381 }
382}
383
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000384const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000385 static const MSAACoverageMode kNoneMode = {0, 0};
386 if (0 == fMSAACoverageModes.count()) {
387 return kNoneMode;
388 } else {
389 GrAssert(kNone_CoverageAAType != fCoverageAAType);
390 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
391 desiredSampleCount = GrMin(desiredSampleCount, max);
392 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
393 int idx = SkTSearch<MSAACoverageMode>(&fMSAACoverageModes[0],
394 fMSAACoverageModes.count(),
395 desiredMode,
396 sizeof(MSAACoverageMode),
397 &coverage_mode_compare);
398 if (idx < 0) {
399 idx = ~idx;
400 }
401 GrAssert(idx >= 0 && idx < fMSAACoverageModes.count());
402 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000403 }
404}
405
406namespace {
407const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
408}
409
410void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
411
412 // Build up list of legal stencil formats (though perhaps not supported on
413 // the particular gpu/driver) from most preferred to least.
414
415 // these consts are in order of most preferred to least preferred
416 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
417
418 static const StencilFormat
419 // internal Format stencil bits total bits packed?
420 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
421 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
422 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
423 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000424 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000425 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
426
427 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
428 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000429 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000430 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
431 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
432
433 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
434 // require FBO support we can expect these are legal formats and don't
435 // check. These also all support the unsized GL_STENCIL_INDEX.
436 fStencilFormats.push_back() = gS8;
437 fStencilFormats.push_back() = gS16;
438 if (supportsPackedDS) {
439 fStencilFormats.push_back() = gD24S8;
440 }
441 fStencilFormats.push_back() = gS4;
442 if (supportsPackedDS) {
443 fStencilFormats.push_back() = gDS;
444 }
445 } else {
446 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
447 // for other formats.
448 // ES doesn't support using the unsized format.
449
450 fStencilFormats.push_back() = gS8;
451 //fStencilFormats.push_back() = gS16;
452 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
453 fStencilFormats.push_back() = gD24S8;
454 }
455 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
456 fStencilFormats.push_back() = gS4;
457 }
458 }
459 GrAssert(0 == fStencilVerifiedColorConfigs.count());
460 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
461}
462
463void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
464 GrPixelConfig config,
465 const GrGLStencilBuffer::Format& format) {
466#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
467 return;
468#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000469 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000470 GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
471 int count = fStencilFormats.count();
472 // we expect a really small number of possible formats so linear search
473 // should be OK
474 GrAssert(count < 16);
475 for (int i = 0; i < count; ++i) {
476 if (format.fInternalFormat ==
477 fStencilFormats[i].fInternalFormat) {
478 fStencilVerifiedColorConfigs[i].markVerified(config);
479 return;
480 }
481 }
482 GrCrash("Why are we seeing a stencil format that "
483 "GrGLCaps doesn't know about.");
484}
485
486bool GrGLCaps::isColorConfigAndStencilFormatVerified(
487 GrPixelConfig config,
488 const GrGLStencilBuffer::Format& format) const {
489#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
490 return false;
491#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000492 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000493 int count = fStencilFormats.count();
494 // we expect a really small number of possible formats so linear search
495 // should be OK
496 GrAssert(count < 16);
497 for (int i = 0; i < count; ++i) {
498 if (format.fInternalFormat ==
499 fStencilFormats[i].fInternalFormat) {
500 return fStencilVerifiedColorConfigs[i].isVerified(config);
501 }
502 }
503 GrCrash("Why are we seeing a stencil format that "
504 "GLCaps doesn't know about.");
505 return false;
506}
507
508void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000509
510 INHERITED::print();
511
512 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000513 for (int i = 0; i < fStencilFormats.count(); ++i) {
514 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
515 i,
516 fStencilFormats[i].fStencilBits,
517 fStencilFormats[i].fTotalBits);
518 }
519
520 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
521 GR_STATIC_ASSERT(1 == kDesktopARB_MSFBOType);
522 GR_STATIC_ASSERT(2 == kDesktopEXT_MSFBOType);
523 GR_STATIC_ASSERT(3 == kAppleES_MSFBOType);
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000524 GR_STATIC_ASSERT(4 == kImaginationES_MSFBOType);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000525 static const char* gMSFBOExtStr[] = {
526 "None",
527 "ARB",
528 "EXT",
529 "Apple",
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000530 "IMG",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000531 };
532 GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]);
533 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000534 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
535 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
536 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
537 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
538 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
539 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
540 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
541 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
542 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
543
544 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
545 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
546 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
547 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000548 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000549 GrPrintf("Fragment coord conventions support: %s\n",
550 (fFragCoordsConventionSupport ? "YES": "NO"));
551 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
552 GrPrintf("Use non-VBO for dynamic data: %s\n",
553 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
554 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000555 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000556}