blob: 8ec76a85aba772e97ce122bee3a2838142a7bd6b [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);
bungeman@google.com71033442013-05-01 14:21:20 +0000222 if (numFormats) {
223 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
224 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
225 for (int i = 0; i < numFormats; ++i) {
226 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
227 f8BitPaletteSupport = true;
228 break;
229 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000230 }
231 }
232
233 if (kDesktop_GrGLBinding == binding) {
234 // we could also look for GL_ATI_separate_stencil extension or
235 // GL_EXT_stencil_two_side but they use different function signatures
236 // than GL2.0+ (and than each other).
237 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
238 // supported on GL 1.4 and higher or by extension
239 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
240 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
241 } else {
242 // ES 2 has two sided stencil and stencil wrap
243 fTwoSidedStencilSupport = true;
244 fStencilWrapOpsSupport = true;
245 }
246
247 if (kDesktop_GrGLBinding == binding) {
248 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
249 // glMapBuffer.
250 } else {
251 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
252 }
253
254 if (kDesktop_GrGLBinding == binding) {
255 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
256 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
257 fNPOTTextureTileSupport = true;
258 } else {
259 fNPOTTextureTileSupport = false;
260 }
261 } else {
262 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
263 fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot");
264 }
265
266 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
267
268 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
269 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
270 // Our render targets are always created with textures as the color
271 // attachment, hence this min:
272 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
273
274 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
275 ctxInfo.hasExtension("GL_NV_path_rendering");
276
277 // Enable supported shader-related caps
278 if (kDesktop_GrGLBinding == binding) {
279 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
280 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
281 fShaderDerivativeSupport = true;
282 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
283 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
284 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
285 } else {
286 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
287 }
288
bsalomon@google.com347c3822013-05-01 20:10:01 +0000289 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000290 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
291 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
292 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
293 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000294}
295
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000296bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000297 GrGLenum format,
298 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000299 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
300 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000301 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000302 }
303
304 if (!fTwoFormatLimit) {
305 // not limited by ES 2's constraints
306 return true;
307 }
308
bsalomon@google.com548a4332012-07-11 19:45:22 +0000309 GrGLint otherFormat = GR_GL_RGBA;
310 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000311
312 // The other supported format/type combo supported for ReadPixels
313 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000314 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000315 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
316 &otherFormat);
317
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000318 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000319 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
320 &otherType);
321
bsalomon@google.com548a4332012-07-11 19:45:22 +0000322 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000323}
324
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000325namespace {
326int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left,
327 const GrGLCaps::MSAACoverageMode* right) {
328 if (left->fCoverageSampleCnt < right->fCoverageSampleCnt) {
329 return -1;
330 } else if (right->fCoverageSampleCnt < left->fCoverageSampleCnt) {
331 return 1;
332 } else if (left->fColorSampleCnt < right->fColorSampleCnt) {
333 return -1;
334 } else if (right->fColorSampleCnt < left->fColorSampleCnt) {
335 return 1;
336 }
337 return 0;
338}
339}
340
robertphillips@google.com6177e692013-02-28 20:16:25 +0000341void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000342
343 fMSFBOType = kNone_MSFBOType;
344 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
345 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
346 // chrome's extension is equivalent to the EXT msaa
347 // and fbo_blit extensions.
bsalomon@google.com347c3822013-05-01 20:10:01 +0000348 fMSFBOType = kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000349 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000350 fMSFBOType = kES_Apple_MSFBOType;
351 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
352 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000353 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000354 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000355 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000356 } else {
357 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
358 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000359 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000360 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
361 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000362 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000363 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000364 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
365 // on GL 4.2+. It's format-specific, though. See also
366 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
367 // rather than requested sample counts in cache key.
368 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
369 fCoverageAAType = kNVDesktop_CoverageAAType;
370 GrGLint 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_MAX_MULTISAMPLE_COVERAGE_MODES,
373 &count);
374 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000375 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000376 GR_GL_MULTISAMPLE_COVERAGE_MODES,
377 (int*)&fMSAACoverageModes[0]);
378 // The NV driver seems to return the modes already sorted but the
379 // spec doesn't require this. So we sort.
reed@google.comc7a67cb2012-05-07 14:52:12 +0000380 qsort(&fMSAACoverageModes[0],
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000381 count,
382 sizeof(MSAACoverageMode),
reed@google.comc7a67cb2012-05-07 14:52:12 +0000383 SkCastForQSort(coverage_mode_compare));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000384 }
385 }
386}
387
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000388const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000389 static const MSAACoverageMode kNoneMode = {0, 0};
390 if (0 == fMSAACoverageModes.count()) {
391 return kNoneMode;
392 } else {
393 GrAssert(kNone_CoverageAAType != fCoverageAAType);
394 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
395 desiredSampleCount = GrMin(desiredSampleCount, max);
396 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
397 int idx = SkTSearch<MSAACoverageMode>(&fMSAACoverageModes[0],
398 fMSAACoverageModes.count(),
399 desiredMode,
400 sizeof(MSAACoverageMode),
401 &coverage_mode_compare);
402 if (idx < 0) {
403 idx = ~idx;
404 }
405 GrAssert(idx >= 0 && idx < fMSAACoverageModes.count());
406 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000407 }
408}
409
410namespace {
411const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
412}
413
414void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
415
416 // Build up list of legal stencil formats (though perhaps not supported on
417 // the particular gpu/driver) from most preferred to least.
418
419 // these consts are in order of most preferred to least preferred
420 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
421
422 static const StencilFormat
423 // internal Format stencil bits total bits packed?
424 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
425 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
426 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
427 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000428 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000429 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
430
431 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
432 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000433 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000434 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
435 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
436
437 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
438 // require FBO support we can expect these are legal formats and don't
439 // check. These also all support the unsized GL_STENCIL_INDEX.
440 fStencilFormats.push_back() = gS8;
441 fStencilFormats.push_back() = gS16;
442 if (supportsPackedDS) {
443 fStencilFormats.push_back() = gD24S8;
444 }
445 fStencilFormats.push_back() = gS4;
446 if (supportsPackedDS) {
447 fStencilFormats.push_back() = gDS;
448 }
449 } else {
450 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
451 // for other formats.
452 // ES doesn't support using the unsized format.
453
454 fStencilFormats.push_back() = gS8;
455 //fStencilFormats.push_back() = gS16;
456 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
457 fStencilFormats.push_back() = gD24S8;
458 }
459 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
460 fStencilFormats.push_back() = gS4;
461 }
462 }
463 GrAssert(0 == fStencilVerifiedColorConfigs.count());
464 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
465}
466
467void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
468 GrPixelConfig config,
469 const GrGLStencilBuffer::Format& format) {
470#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
471 return;
472#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000473 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000474 GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
475 int count = fStencilFormats.count();
476 // we expect a really small number of possible formats so linear search
477 // should be OK
478 GrAssert(count < 16);
479 for (int i = 0; i < count; ++i) {
480 if (format.fInternalFormat ==
481 fStencilFormats[i].fInternalFormat) {
482 fStencilVerifiedColorConfigs[i].markVerified(config);
483 return;
484 }
485 }
486 GrCrash("Why are we seeing a stencil format that "
487 "GrGLCaps doesn't know about.");
488}
489
490bool GrGLCaps::isColorConfigAndStencilFormatVerified(
491 GrPixelConfig config,
492 const GrGLStencilBuffer::Format& format) const {
493#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
494 return false;
495#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000496 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000497 int count = fStencilFormats.count();
498 // we expect a really small number of possible formats so linear search
499 // should be OK
500 GrAssert(count < 16);
501 for (int i = 0; i < count; ++i) {
502 if (format.fInternalFormat ==
503 fStencilFormats[i].fInternalFormat) {
504 return fStencilVerifiedColorConfigs[i].isVerified(config);
505 }
506 }
507 GrCrash("Why are we seeing a stencil format that "
508 "GLCaps doesn't know about.");
509 return false;
510}
511
512void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000513
514 INHERITED::print();
515
516 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000517 for (int i = 0; i < fStencilFormats.count(); ++i) {
518 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
519 i,
520 fStencilFormats[i].fStencilBits,
521 fStencilFormats[i].fTotalBits);
522 }
523
524 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
bsalomon@google.com347c3822013-05-01 20:10:01 +0000525 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
526 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
527 GR_STATIC_ASSERT(3 == kES_Apple_MSFBOType);
528 GR_STATIC_ASSERT(4 == kES_IMG_MsToTexture_MSFBOType);
529 GR_STATIC_ASSERT(5 == kES_EXT_MsToTexture_MSFBOType);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000530 static const char* gMSFBOExtStr[] = {
531 "None",
532 "ARB",
533 "EXT",
534 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000535 "IMG MS To Texture",
536 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000537 };
538 GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]);
539 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000540 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
541 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
542 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
543 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
544 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
545 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
546 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
547 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
548 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
549
550 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
551 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
552 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
553 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000554 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000555 GrPrintf("Fragment coord conventions support: %s\n",
556 (fFragCoordsConventionSupport ? "YES": "NO"));
557 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
558 GrPrintf("Use non-VBO for dynamic data: %s\n",
559 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
560 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000561 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000562}