blob: cf09506c057fa9f4575947b0ae07b4348213ef9f [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
48GrGLCaps::GrGLCaps(const GrGLCaps& caps) {
49 *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 /**************************************************************************
208 * GrDrawTarget::Caps fields
209 **************************************************************************/
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);
215 GrAssert(maxTextureUnits > GrDrawState::kNumStages);
216
217 GrGLint numFormats;
218 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
219 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
220 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
221 for (int i = 0; i < numFormats; ++i) {
222 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
223 f8BitPaletteSupport = true;
224 break;
225 }
226 }
227
228 if (kDesktop_GrGLBinding == binding) {
229 // we could also look for GL_ATI_separate_stencil extension or
230 // GL_EXT_stencil_two_side but they use different function signatures
231 // than GL2.0+ (and than each other).
232 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
233 // supported on GL 1.4 and higher or by extension
234 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
235 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
236 } else {
237 // ES 2 has two sided stencil and stencil wrap
238 fTwoSidedStencilSupport = true;
239 fStencilWrapOpsSupport = true;
240 }
241
242 if (kDesktop_GrGLBinding == binding) {
243 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
244 // glMapBuffer.
245 } else {
246 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
247 }
248
249 if (kDesktop_GrGLBinding == binding) {
250 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
251 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
252 fNPOTTextureTileSupport = true;
253 } else {
254 fNPOTTextureTileSupport = false;
255 }
256 } else {
257 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
258 fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot");
259 }
260
261 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
262
263 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
264 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
265 // Our render targets are always created with textures as the color
266 // attachment, hence this min:
267 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
268
269 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
270 ctxInfo.hasExtension("GL_NV_path_rendering");
271
272 // Enable supported shader-related caps
273 if (kDesktop_GrGLBinding == binding) {
274 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
275 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
276 fShaderDerivativeSupport = true;
277 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
278 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
279 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
280 } else {
281 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
282 }
283
284 if (GrGLCaps::kImaginationES_MSFBOType == fMSFBOType) {
285 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
286 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
287 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
288 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000289}
290
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000291bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000292 GrGLenum format,
293 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000294 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
295 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000296 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000297 }
298
299 if (!fTwoFormatLimit) {
300 // not limited by ES 2's constraints
301 return true;
302 }
303
bsalomon@google.com548a4332012-07-11 19:45:22 +0000304 GrGLint otherFormat = GR_GL_RGBA;
305 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000306
307 // The other supported format/type combo supported for ReadPixels
308 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000309 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000310 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
311 &otherFormat);
312
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000313 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000314 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
315 &otherType);
316
bsalomon@google.com548a4332012-07-11 19:45:22 +0000317 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000318}
319
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000320namespace {
321int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left,
322 const GrGLCaps::MSAACoverageMode* right) {
323 if (left->fCoverageSampleCnt < right->fCoverageSampleCnt) {
324 return -1;
325 } else if (right->fCoverageSampleCnt < left->fCoverageSampleCnt) {
326 return 1;
327 } else if (left->fColorSampleCnt < right->fColorSampleCnt) {
328 return -1;
329 } else if (right->fColorSampleCnt < left->fColorSampleCnt) {
330 return 1;
331 }
332 return 0;
333}
334}
335
robertphillips@google.com6177e692013-02-28 20:16:25 +0000336void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000337
338 fMSFBOType = kNone_MSFBOType;
339 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
340 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
341 // chrome's extension is equivalent to the EXT msaa
342 // and fbo_blit extensions.
343 fMSFBOType = kDesktopEXT_MSFBOType;
344 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000345 fMSFBOType = kAppleES_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000346 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
347 fMSFBOType = kImaginationES_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000348 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000349 } else {
350 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
351 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
352 fMSFBOType = GrGLCaps::kDesktopARB_MSFBOType;
353 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
354 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
355 fMSFBOType = GrGLCaps::kDesktopEXT_MSFBOType;
356 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000357 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
358 // on GL 4.2+. It's format-specific, though. See also
359 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
360 // rather than requested sample counts in cache key.
361 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
362 fCoverageAAType = kNVDesktop_CoverageAAType;
363 GrGLint count;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000364 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000365 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
366 &count);
367 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000368 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000369 GR_GL_MULTISAMPLE_COVERAGE_MODES,
370 (int*)&fMSAACoverageModes[0]);
371 // The NV driver seems to return the modes already sorted but the
372 // spec doesn't require this. So we sort.
reed@google.comc7a67cb2012-05-07 14:52:12 +0000373 qsort(&fMSAACoverageModes[0],
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000374 count,
375 sizeof(MSAACoverageMode),
reed@google.comc7a67cb2012-05-07 14:52:12 +0000376 SkCastForQSort(coverage_mode_compare));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000377 }
378 }
379}
380
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000381const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000382 static const MSAACoverageMode kNoneMode = {0, 0};
383 if (0 == fMSAACoverageModes.count()) {
384 return kNoneMode;
385 } else {
386 GrAssert(kNone_CoverageAAType != fCoverageAAType);
387 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
388 desiredSampleCount = GrMin(desiredSampleCount, max);
389 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
390 int idx = SkTSearch<MSAACoverageMode>(&fMSAACoverageModes[0],
391 fMSAACoverageModes.count(),
392 desiredMode,
393 sizeof(MSAACoverageMode),
394 &coverage_mode_compare);
395 if (idx < 0) {
396 idx = ~idx;
397 }
398 GrAssert(idx >= 0 && idx < fMSAACoverageModes.count());
399 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000400 }
401}
402
403namespace {
404const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
405}
406
407void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
408
409 // Build up list of legal stencil formats (though perhaps not supported on
410 // the particular gpu/driver) from most preferred to least.
411
412 // these consts are in order of most preferred to least preferred
413 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
414
415 static const StencilFormat
416 // internal Format stencil bits total bits packed?
417 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
418 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
419 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
420 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000421 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000422 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
423
424 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
425 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000426 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000427 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
428 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
429
430 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
431 // require FBO support we can expect these are legal formats and don't
432 // check. These also all support the unsized GL_STENCIL_INDEX.
433 fStencilFormats.push_back() = gS8;
434 fStencilFormats.push_back() = gS16;
435 if (supportsPackedDS) {
436 fStencilFormats.push_back() = gD24S8;
437 }
438 fStencilFormats.push_back() = gS4;
439 if (supportsPackedDS) {
440 fStencilFormats.push_back() = gDS;
441 }
442 } else {
443 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
444 // for other formats.
445 // ES doesn't support using the unsized format.
446
447 fStencilFormats.push_back() = gS8;
448 //fStencilFormats.push_back() = gS16;
449 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
450 fStencilFormats.push_back() = gD24S8;
451 }
452 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
453 fStencilFormats.push_back() = gS4;
454 }
455 }
456 GrAssert(0 == fStencilVerifiedColorConfigs.count());
457 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
458}
459
460void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
461 GrPixelConfig config,
462 const GrGLStencilBuffer::Format& format) {
463#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
464 return;
465#endif
466 GrAssert((unsigned)config < kGrPixelConfigCount);
467 GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
468 int count = fStencilFormats.count();
469 // we expect a really small number of possible formats so linear search
470 // should be OK
471 GrAssert(count < 16);
472 for (int i = 0; i < count; ++i) {
473 if (format.fInternalFormat ==
474 fStencilFormats[i].fInternalFormat) {
475 fStencilVerifiedColorConfigs[i].markVerified(config);
476 return;
477 }
478 }
479 GrCrash("Why are we seeing a stencil format that "
480 "GrGLCaps doesn't know about.");
481}
482
483bool GrGLCaps::isColorConfigAndStencilFormatVerified(
484 GrPixelConfig config,
485 const GrGLStencilBuffer::Format& format) const {
486#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
487 return false;
488#endif
489 GrAssert((unsigned)config < kGrPixelConfigCount);
490 int count = fStencilFormats.count();
491 // we expect a really small number of possible formats so linear search
492 // should be OK
493 GrAssert(count < 16);
494 for (int i = 0; i < count; ++i) {
495 if (format.fInternalFormat ==
496 fStencilFormats[i].fInternalFormat) {
497 return fStencilVerifiedColorConfigs[i].isVerified(config);
498 }
499 }
500 GrCrash("Why are we seeing a stencil format that "
501 "GLCaps doesn't know about.");
502 return false;
503}
504
505void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000506
507 INHERITED::print();
508
509 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000510 for (int i = 0; i < fStencilFormats.count(); ++i) {
511 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
512 i,
513 fStencilFormats[i].fStencilBits,
514 fStencilFormats[i].fTotalBits);
515 }
516
517 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
518 GR_STATIC_ASSERT(1 == kDesktopARB_MSFBOType);
519 GR_STATIC_ASSERT(2 == kDesktopEXT_MSFBOType);
520 GR_STATIC_ASSERT(3 == kAppleES_MSFBOType);
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000521 GR_STATIC_ASSERT(4 == kImaginationES_MSFBOType);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000522 static const char* gMSFBOExtStr[] = {
523 "None",
524 "ARB",
525 "EXT",
526 "Apple",
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000527 "IMG",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000528 };
529 GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]);
530 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000531 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
532 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
533 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
534 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
535 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
536 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
537 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
538 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
539 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
540
541 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
542 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
543 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
544 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000545 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000546 GrPrintf("Fragment coord conventions support: %s\n",
547 (fFragCoordsConventionSupport ? "YES": "NO"));
548 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
549 GrPrintf("Use non-VBO for dynamic data: %s\n",
550 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
551 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000552}