blob: 461b3d6618e4fd2e5bc698dbb1004f4f339271a4 [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;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000046}
47
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000048GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000049 *this = caps;
50}
51
52GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000053 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000054 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
55 fStencilFormats = caps.fStencilFormats;
56 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
57 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000058 fMaxVertexAttributes = caps.fMaxVertexAttributes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059 fMSFBOType = caps.fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000060 fCoverageAAType = caps.fCoverageAAType;
61 fMSAACoverageModes = caps.fMSAACoverageModes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000062 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
63 fBGRAFormatSupport = caps.fBGRAFormatSupport;
64 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
65 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
66 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
67 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
68 fPackRowLengthSupport = caps.fPackRowLengthSupport;
69 fPackFlipYSupport = caps.fPackFlipYSupport;
70 fTextureUsageSupport = caps.fTextureUsageSupport;
71 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000072 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000073 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000074 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000075 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000076 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000077 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000078 fIsCoreProfile = caps.fIsCoreProfile;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079
80 return *this;
81}
82
robertphillips@google.com6177e692013-02-28 20:16:25 +000083void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000084
85 this->reset();
86 if (!ctxInfo.isInitialized()) {
87 return;
88 }
89
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090 GrGLBinding binding = ctxInfo.binding();
91 GrGLVersion version = ctxInfo.version();
92
bsalomon@google.combcce8922013-03-25 15:38:39 +000093 /**************************************************************************
94 * Caps specific to GrGLCaps
95 **************************************************************************/
96
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 if (kES2_GrGLBinding == binding) {
98 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
99 &fMaxFragmentUniformVectors);
100 } else {
101 GrAssert(kDesktop_GrGLBinding == binding);
102 GrGLint max;
103 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
104 fMaxFragmentUniformVectors = max / 4;
105 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000106 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107
108 if (kDesktop_GrGLBinding == binding) {
109 fRGBA8RenderbufferSupport = true;
110 } else {
111 fRGBA8RenderbufferSupport = ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
112 ctxInfo.hasExtension("GL_ARM_rgba8");
113 }
114
115 if (kDesktop_GrGLBinding == binding) {
116 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
117 ctxInfo.hasExtension("GL_EXT_bgra");
118 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000119 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
120 fBGRAFormatSupport = true;
121 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
122 fBGRAFormatSupport = true;
123 fBGRAIsInternalFormat = true;
124 }
125 GrAssert(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000126 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127 }
128
129 if (kDesktop_GrGLBinding == binding) {
130 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
131 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
132 } else {
133 fTextureSwizzleSupport = false;
134 }
135
136 if (kDesktop_GrGLBinding == binding) {
137 fUnpackRowLengthSupport = true;
138 fUnpackFlipYSupport = false;
139 fPackRowLengthSupport = true;
140 fPackFlipYSupport = false;
141 } else {
142 fUnpackRowLengthSupport =ctxInfo.hasExtension("GL_EXT_unpack_subimage");
143 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
144 // no extension for pack row length
145 fPackRowLengthSupport = false;
146 fPackFlipYSupport =
147 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
148 }
149
150 fTextureUsageSupport = (kES2_GrGLBinding == binding) &&
151 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
152
153 // Tex storage is in desktop 4.2 and can be an extension to desktop or ES.
154 fTexStorageSupport = (kDesktop_GrGLBinding == binding &&
155 version >= GR_GL_VER(4,2)) ||
156 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
157 ctxInfo.hasExtension("GL_EXT_texture_storage");
158
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000159 // ARB_texture_rg is part of OpenGL 3.0
160 if (kDesktop_GrGLBinding == binding) {
161 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
162 ctxInfo.hasExtension("GL_ARB_texture_rg");
163 } else {
164 fTextureRedSupport = ctxInfo.hasExtension("GL_EXT_texture_rg");
165 }
166
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000167 fImagingSupport = kDesktop_GrGLBinding == binding &&
168 ctxInfo.hasExtension("GL_ARB_imaging");
169
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000170 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
171 // ReadPixels. The other format has to checked at run-time since it
172 // can change based on which render target is bound
173 fTwoFormatLimit = kES2_GrGLBinding == binding;
174
bsalomon@google.com706f6682012-10-23 14:53:55 +0000175 // Known issue on at least some Intel platforms:
176 // http://code.google.com/p/skia/issues/detail?id=946
177 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
178 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
179 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
180 }
181
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000182 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
183 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
184 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
185 // limit this decision to specific GPU families rather than basing it on the vendor alone.
186 if (!GR_GL_MUST_USE_VBO &&
187 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000188 fUseNonVBOVertexAndIndexDynamicData = true;
189 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000190
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000191 if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) {
192 GrGLint profileMask;
193 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
194 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
195 }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000196
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000197 if (kDesktop_GrGLBinding == binding) {
198 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
199 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
200 } else {
201 fVertexArrayObjectSupport = ctxInfo.hasExtension("GL_OES_vertex_array_object");
202 }
203
robertphillips@google.com6177e692013-02-28 20:16:25 +0000204 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000205 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000206
207 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000208 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000209 **************************************************************************/
210 GrGLint maxTextureUnits;
211 // check FS and fixed-function texture unit limits
212 // we only use textures in the fragment stage currently.
213 // checks are > to make sure we have a spare unit.
214 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000215
216 GrGLint numFormats;
217 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
218 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
219 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
220 for (int i = 0; i < numFormats; ++i) {
221 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
222 f8BitPaletteSupport = true;
223 break;
224 }
225 }
226
227 if (kDesktop_GrGLBinding == binding) {
228 // we could also look for GL_ATI_separate_stencil extension or
229 // GL_EXT_stencil_two_side but they use different function signatures
230 // than GL2.0+ (and than each other).
231 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
232 // supported on GL 1.4 and higher or by extension
233 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
234 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
235 } else {
236 // ES 2 has two sided stencil and stencil wrap
237 fTwoSidedStencilSupport = true;
238 fStencilWrapOpsSupport = true;
239 }
240
241 if (kDesktop_GrGLBinding == binding) {
242 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
243 // glMapBuffer.
244 } else {
245 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
246 }
247
248 if (kDesktop_GrGLBinding == binding) {
249 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
250 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
251 fNPOTTextureTileSupport = true;
252 } else {
253 fNPOTTextureTileSupport = false;
254 }
255 } else {
256 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
257 fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot");
258 }
259
260 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
261
262 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
263 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
264 // Our render targets are always created with textures as the color
265 // attachment, hence this min:
266 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
267
268 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
269 ctxInfo.hasExtension("GL_NV_path_rendering");
270
271 // Enable supported shader-related caps
272 if (kDesktop_GrGLBinding == binding) {
273 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
274 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
275 fShaderDerivativeSupport = true;
276 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
277 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
278 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
279 } else {
280 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
281 }
282
283 if (GrGLCaps::kImaginationES_MSFBOType == fMSFBOType) {
284 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
285 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
286 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
287 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000288}
289
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000290bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000291 GrGLenum format,
292 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000293 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
294 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000295 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000296 }
297
298 if (!fTwoFormatLimit) {
299 // not limited by ES 2's constraints
300 return true;
301 }
302
bsalomon@google.com548a4332012-07-11 19:45:22 +0000303 GrGLint otherFormat = GR_GL_RGBA;
304 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000305
306 // The other supported format/type combo supported for ReadPixels
307 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000308 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000309 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
310 &otherFormat);
311
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_TYPE,
314 &otherType);
315
bsalomon@google.com548a4332012-07-11 19:45:22 +0000316 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000317}
318
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000319namespace {
320int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left,
321 const GrGLCaps::MSAACoverageMode* right) {
322 if (left->fCoverageSampleCnt < right->fCoverageSampleCnt) {
323 return -1;
324 } else if (right->fCoverageSampleCnt < left->fCoverageSampleCnt) {
325 return 1;
326 } else if (left->fColorSampleCnt < right->fColorSampleCnt) {
327 return -1;
328 } else if (right->fColorSampleCnt < left->fColorSampleCnt) {
329 return 1;
330 }
331 return 0;
332}
333}
334
robertphillips@google.com6177e692013-02-28 20:16:25 +0000335void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000336
337 fMSFBOType = kNone_MSFBOType;
338 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
339 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
340 // chrome's extension is equivalent to the EXT msaa
341 // and fbo_blit extensions.
342 fMSFBOType = kDesktopEXT_MSFBOType;
343 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000344 fMSFBOType = kAppleES_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000345 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
346 fMSFBOType = kImaginationES_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000347 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000348 } else {
349 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
350 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
351 fMSFBOType = GrGLCaps::kDesktopARB_MSFBOType;
352 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
353 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
354 fMSFBOType = GrGLCaps::kDesktopEXT_MSFBOType;
355 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000356 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
357 // on GL 4.2+. It's format-specific, though. See also
358 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
359 // rather than requested sample counts in cache key.
360 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
361 fCoverageAAType = kNVDesktop_CoverageAAType;
362 GrGLint count;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000363 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000364 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
365 &count);
366 fMSAACoverageModes.setCount(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_MULTISAMPLE_COVERAGE_MODES,
369 (int*)&fMSAACoverageModes[0]);
370 // The NV driver seems to return the modes already sorted but the
371 // spec doesn't require this. So we sort.
reed@google.comc7a67cb2012-05-07 14:52:12 +0000372 qsort(&fMSAACoverageModes[0],
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000373 count,
374 sizeof(MSAACoverageMode),
reed@google.comc7a67cb2012-05-07 14:52:12 +0000375 SkCastForQSort(coverage_mode_compare));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000376 }
377 }
378}
379
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000380const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000381 static const MSAACoverageMode kNoneMode = {0, 0};
382 if (0 == fMSAACoverageModes.count()) {
383 return kNoneMode;
384 } else {
385 GrAssert(kNone_CoverageAAType != fCoverageAAType);
386 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
387 desiredSampleCount = GrMin(desiredSampleCount, max);
388 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
389 int idx = SkTSearch<MSAACoverageMode>(&fMSAACoverageModes[0],
390 fMSAACoverageModes.count(),
391 desiredMode,
392 sizeof(MSAACoverageMode),
393 &coverage_mode_compare);
394 if (idx < 0) {
395 idx = ~idx;
396 }
397 GrAssert(idx >= 0 && idx < fMSAACoverageModes.count());
398 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000399 }
400}
401
402namespace {
403const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
404}
405
406void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
407
408 // Build up list of legal stencil formats (though perhaps not supported on
409 // the particular gpu/driver) from most preferred to least.
410
411 // these consts are in order of most preferred to least preferred
412 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
413
414 static const StencilFormat
415 // internal Format stencil bits total bits packed?
416 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
417 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
418 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
419 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000420 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000421 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
422
423 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
424 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000425 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000426 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
427 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
428
429 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
430 // require FBO support we can expect these are legal formats and don't
431 // check. These also all support the unsized GL_STENCIL_INDEX.
432 fStencilFormats.push_back() = gS8;
433 fStencilFormats.push_back() = gS16;
434 if (supportsPackedDS) {
435 fStencilFormats.push_back() = gD24S8;
436 }
437 fStencilFormats.push_back() = gS4;
438 if (supportsPackedDS) {
439 fStencilFormats.push_back() = gDS;
440 }
441 } else {
442 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
443 // for other formats.
444 // ES doesn't support using the unsized format.
445
446 fStencilFormats.push_back() = gS8;
447 //fStencilFormats.push_back() = gS16;
448 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
449 fStencilFormats.push_back() = gD24S8;
450 }
451 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
452 fStencilFormats.push_back() = gS4;
453 }
454 }
455 GrAssert(0 == fStencilVerifiedColorConfigs.count());
456 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
457}
458
459void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
460 GrPixelConfig config,
461 const GrGLStencilBuffer::Format& format) {
462#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
463 return;
464#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000465 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000466 GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
467 int count = fStencilFormats.count();
468 // we expect a really small number of possible formats so linear search
469 // should be OK
470 GrAssert(count < 16);
471 for (int i = 0; i < count; ++i) {
472 if (format.fInternalFormat ==
473 fStencilFormats[i].fInternalFormat) {
474 fStencilVerifiedColorConfigs[i].markVerified(config);
475 return;
476 }
477 }
478 GrCrash("Why are we seeing a stencil format that "
479 "GrGLCaps doesn't know about.");
480}
481
482bool GrGLCaps::isColorConfigAndStencilFormatVerified(
483 GrPixelConfig config,
484 const GrGLStencilBuffer::Format& format) const {
485#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
486 return false;
487#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000488 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000489 int count = fStencilFormats.count();
490 // we expect a really small number of possible formats so linear search
491 // should be OK
492 GrAssert(count < 16);
493 for (int i = 0; i < count; ++i) {
494 if (format.fInternalFormat ==
495 fStencilFormats[i].fInternalFormat) {
496 return fStencilVerifiedColorConfigs[i].isVerified(config);
497 }
498 }
499 GrCrash("Why are we seeing a stencil format that "
500 "GLCaps doesn't know about.");
501 return false;
502}
503
504void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000505
506 INHERITED::print();
507
508 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000509 for (int i = 0; i < fStencilFormats.count(); ++i) {
510 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
511 i,
512 fStencilFormats[i].fStencilBits,
513 fStencilFormats[i].fTotalBits);
514 }
515
516 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
517 GR_STATIC_ASSERT(1 == kDesktopARB_MSFBOType);
518 GR_STATIC_ASSERT(2 == kDesktopEXT_MSFBOType);
519 GR_STATIC_ASSERT(3 == kAppleES_MSFBOType);
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000520 GR_STATIC_ASSERT(4 == kImaginationES_MSFBOType);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000521 static const char* gMSFBOExtStr[] = {
522 "None",
523 "ARB",
524 "EXT",
525 "Apple",
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000526 "IMG",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000527 };
528 GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]);
529 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000530 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
531 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
532 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
533 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
534 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
535 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
536 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
537 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
538 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
539
540 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
541 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
542 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
543 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000544 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000545 GrPrintf("Fragment coord conventions support: %s\n",
546 (fFragCoordsConventionSupport ? "YES": "NO"));
547 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
548 GrPrintf("Use non-VBO for dynamic data: %s\n",
549 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
550 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000551}