blob: c2ace6cd368948d25d60f95b766895dcfd1ce740 [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"
joshualittb4384b92014-10-21 12:53:15 -070010
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000012#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080013#include "GrGLRenderTarget.h"
jvanverthcba99b82015-06-24 06:59:57 -070014#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000015#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000016#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000017
bsalomon682c2692015-05-22 14:01:46 -070018GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
19 const GrGLContextInfo& ctxInfo,
20 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080021 fStandard = ctxInfo.standard();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000025 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000026 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080027 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000029 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000030 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fUnpackRowLengthSupport = false;
32 fUnpackFlipYSupport = false;
33 fPackRowLengthSupport = false;
34 fPackFlipYSupport = false;
35 fTextureUsageSupport = false;
36 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000037 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDirectStateAccessSupport = false;
41 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080042 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080043 fMultisampleDisableSupport = false;
cdalton06604b92016-02-05 10:09:51 -080044 fDrawIndirectSupport = false;
45 fMultiDrawIndirectSupport = false;
46 fBaseInstanceSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000047 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000048 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070049 fBindFragDataLocationSupport = false;
bsalomon7ea33f52015-11-22 14:51:00 -080050 fExternalTextureSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080051 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080052 fTextureSwizzleSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070053 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070054 fRGBA8888PixelsOpsAreSlow = false;
55 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070056
halcanary385fe4d2015-08-26 13:07:48 -070057 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070058
cdalton4cd67132015-06-10 19:23:46 -070059 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060}
61
cdalton4cd67132015-06-10 19:23:46 -070062void GrGLCaps::init(const GrContextOptions& contextOptions,
63 const GrGLContextInfo& ctxInfo,
64 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000065 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000066 GrGLVersion version = ctxInfo.version();
67
bsalomon@google.combcce8922013-03-25 15:38:39 +000068 /**************************************************************************
69 * Caps specific to GrGLCaps
70 **************************************************************************/
71
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000072 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
74 &fMaxFragmentUniformVectors);
75 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000076 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000077 GrGLint max;
78 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
79 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000080 if (version >= GR_GL_VER(3, 2)) {
81 GrGLint profileMask;
82 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
83 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
84 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000085 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000086 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000087 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000089 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090 fUnpackRowLengthSupport = true;
91 fUnpackFlipYSupport = false;
92 fPackRowLengthSupport = true;
93 fPackFlipYSupport = false;
94 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000095 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
96 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000098 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
99 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000100 fPackFlipYSupport =
101 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
102 }
103
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000104 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000105 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
106
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000107 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000108 // The EXT version can apply to either GL or GLES.
109 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
110 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
111 ctxInfo.hasExtension("GL_EXT_texture_storage");
112 } else {
113 // Qualcomm Adreno drivers appear to have issues with texture storage.
114 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
115 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
116 ctxInfo.hasExtension("GL_EXT_texture_storage");
117 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000118
cdaltonfd4167d2015-04-21 11:45:56 -0700119 if (kGL_GrGLStandard == standard) {
120 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
121 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
122 ctxInfo.hasExtension("GL_NV_texture_barrier");
123 } else {
124 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
125 }
126
hendrikwa0d5ad72014-12-02 07:30:30 -0800127 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
128 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700129 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800130 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000131 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
132 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800133 } else {
134 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
135 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000136 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000137 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000138 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000139 ctxInfo.hasExtension("GL_ARB_imaging");
140
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000141 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
142 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
143 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
144 // limit this decision to specific GPU families rather than basing it on the vendor alone.
145 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700146 (kARM_GrGLVendor == ctxInfo.vendor() ||
147 kImagination_GrGLVendor == ctxInfo.vendor() ||
148 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000149 fUseNonVBOVertexAndIndexDynamicData = true;
150 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000151
egdaniel9250d242015-05-18 13:04:26 -0700152 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
153 // Thus we are blacklisting this extension for now on Adreno4xx devices.
154 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
155 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
156 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
157 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000158 fDiscardRenderTargetSupport = true;
159 fInvalidateFBType = kInvalidate_InvalidateFBType;
160 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
161 fDiscardRenderTargetSupport = true;
162 fInvalidateFBType = kDiscard_InvalidateFBType;
163 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000164
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000165 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
166 fFullClearIsFree = true;
167 }
168
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000169 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000170 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800171 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
172 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000173 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000174 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
175 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000176 }
177
cdalton626e1ff2015-06-12 13:56:46 -0700178 if (kGL_GrGLStandard == standard) {
179 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
180 } else {
181 fDirectStateAccessSupport = false;
182 }
183
184 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
185 fDebugSupport = true;
186 } else {
187 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
188 }
189
jvanverth3f801cb2014-12-16 09:49:38 -0800190 if (kGL_GrGLStandard == standard) {
191 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
192 }
193 else {
194 fES2CompatibilitySupport = true;
195 }
196
cdalton0edea2c2015-05-21 08:27:44 -0700197 if (kGL_GrGLStandard == standard) {
198 fMultisampleDisableSupport = true;
199 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700200 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700201 }
202
kkinnunend94708e2015-07-30 22:47:04 -0700203 if (kGL_GrGLStandard == standard) {
204 if (version >= GR_GL_VER(3, 0)) {
205 fBindFragDataLocationSupport = true;
206 }
207 } else {
208 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
209 fBindFragDataLocationSupport = true;
210 }
joshualittc1f56b52015-06-22 12:31:31 -0700211 }
212
bsalomonb8909d32016-01-28 07:09:52 -0800213#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700214 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800215#else
216 fBindUniformLocationSupport = false;
217#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700218
bsalomon7ea33f52015-11-22 14:51:00 -0800219 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
220 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
221 fExternalTextureSupport = true;
222 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
223 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
224 // At least one driver has been found that has this extension without the "GL_" prefix.
225 fExternalTextureSupport = true;
226 }
227 }
228
bsalomone179a912016-01-20 06:18:10 -0800229 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 1)) ||
bsalomone5286e02016-01-14 09:24:09 -0800230 ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
bsalomone179a912016-01-20 06:18:10 -0800231 // We also require textureSize() support for rectangle 2D samplers which was added in GLSL
232 // 1.40.
233 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
234 fRectangleTextureSupport = true;
235 }
bsalomone5286e02016-01-14 09:24:09 -0800236 }
237
bsalomoncdee0092016-01-08 13:20:12 -0800238 if (kGL_GrGLStandard == standard) {
239 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
240 fTextureSwizzleSupport = true;
241 }
242 } else {
243 if (version >= GR_GL_VER(3,0)) {
244 fTextureSwizzleSupport = true;
245 }
246 }
247
bsalomon88c7b982015-07-31 11:20:16 -0700248#ifdef SK_BUILD_FOR_WIN
249 // We're assuming that on Windows Chromium we're using ANGLE.
250 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
251 kChromium_GrGLDriver == ctxInfo.driver();
252 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
253 fRGBA8888PixelsOpsAreSlow = isANGLE;
254 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
255 // check DX11 ANGLE.
256 fPartialFBOReadIsSlow = isANGLE;
257#endif
258
cdalton4cd67132015-06-10 19:23:46 -0700259 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700260 * GrShaderCaps fields
261 **************************************************************************/
262
egdaniel0a482332015-10-26 08:59:10 -0700263 // This must be called after fCoreProfile is set on the GrGLCaps
264 this->initGLSL(ctxInfo);
265 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
266
egdaniel05ded892015-10-26 07:38:05 -0700267 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
268
269 // For now these two are equivalent but we could have dst read in shader via some other method.
270 // Before setting this, initGLSL() must have been called.
271 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
272
273 // Enable supported shader-related caps
274 if (kGL_GrGLStandard == standard) {
275 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
276 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
277 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
278 glslCaps->fShaderDerivativeSupport = true;
279 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
280 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
281 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800282 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
283 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700284 }
285 else {
286 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
287
288 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
289 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800290
291 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
292 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700293 }
294
ethannicholas22793252016-01-30 09:59:10 -0800295 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
296 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
297 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
298 &glslCaps->fPixelLocalStorageSize);
299 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
300 }
301 else {
302 glslCaps->fPixelLocalStorageSize = 0;
303 glslCaps->fPLSPathRenderingSupport = false;
304 }
305
egdaniel05ded892015-10-26 07:38:05 -0700306 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700307 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000308 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700309
cdalton63f6c1f2015-11-06 07:09:43 -0800310 // We need dual source blending and the ability to disable multisample in order to support mixed
311 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800312 if (fMultisampleDisableSupport &&
313 glslCaps->dualSourceBlendingSupport() &&
314 fShaderCaps->pathRenderingSupport()) {
315 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800316 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800317 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800318 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
319 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800320 fDiscardRenderTargetSupport = false;
321 fInvalidateFBType = kNone_InvalidateFBType;
322 }
323 }
324
egdanieleed519e2016-01-15 11:36:18 -0800325 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700326 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700327 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700328 this->initStencilFormats(ctxInfo);
329
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000330 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000331 // we could also look for GL_ATI_separate_stencil extension or
332 // GL_EXT_stencil_two_side but they use different function signatures
333 // than GL2.0+ (and than each other).
334 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
335 // supported on GL 1.4 and higher or by extension
336 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
337 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
338 } else {
339 // ES 2 has two sided stencil and stencil wrap
340 fTwoSidedStencilSupport = true;
341 fStencilWrapOpsSupport = true;
342 }
343
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000344 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000345 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
346 // extension includes glMapBuffer.
347 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
348 fMapBufferFlags |= kSubset_MapFlag;
349 fMapBufferType = kMapBufferRange_MapBufferType;
350 } else {
351 fMapBufferType = kMapBuffer_MapBufferType;
352 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000353 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000354 // Unextended GLES2 doesn't have any buffer mapping.
355 fMapBufferFlags = kNone_MapBufferType;
356 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
357 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
358 fMapBufferType = kChromium_MapBufferType;
359 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
360 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
361 fMapBufferType = kMapBufferRange_MapBufferType;
362 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
363 fMapBufferFlags = kCanMap_MapFlag;
364 fMapBufferType = kMapBuffer_MapBufferType;
365 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000366 }
367
jvanverthd7a2c1f2015-12-07 07:36:44 -0800368 if (kGL_GrGLStandard == standard) {
369 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
370 fTransferBufferType = kPBO_TransferBufferType;
371 }
372 } else {
373 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
374 fTransferBufferType = kPBO_TransferBufferType;
375 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
376 fTransferBufferType = kChromium_TransferBufferType;
377 }
378 }
379
joshualitte5b74c62015-06-01 14:17:47 -0700380 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
381 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
382 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700383 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
384 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
385 // a small subset.
386#if 0
cdalton1acea862015-06-02 13:05:52 -0700387 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700388#else
389 fGeometryBufferMapThreshold = SK_MaxS32;
390#endif
joshualitte5b74c62015-06-01 14:17:47 -0700391 }
392
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000393 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000394 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
395 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
396 fNPOTTextureTileSupport = true;
397 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000398 } else {
399 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000400 // ES3 has no limitations.
401 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
402 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000403 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
404 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
405 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
406 // to alllow arbitrary wrap modes, however.
407 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000408 }
409
bsalomone72bd022015-10-26 07:33:03 -0700410 // Using MIPs on this GPU seems to be a source of trouble.
411 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
412 fMipMapSupport = false;
413 }
414
bsalomon@google.combcce8922013-03-25 15:38:39 +0000415 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
416 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
417 // Our render targets are always created with textures as the color
418 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000419 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000420
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000421 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
422
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000423 // Disable scratch texture reuse on Mali and Adreno devices
424 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
425 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000426
robertphillips1b8e1b52015-06-24 06:54:10 -0700427#if 0
428 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
429 kQualcomm_GrGLVendor != ctxInfo.vendor();
430#endif
431
egdaniel05ded892015-10-26 07:38:05 -0700432 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000433 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800434 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000435 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800436 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000437 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800438 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
439 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
440 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
441 // This is to guard against platforms that may not support as many samples for
442 // glRasterSamples as they do for framebuffers.
443 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
444 }
445 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000446
bsalomon63b21962014-11-05 07:05:34 -0800447 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800448 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800449 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800450 fUseDrawInsteadOfClear = true;
451 }
452
joshualitt83bc2292015-06-18 14:18:02 -0700453 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
454 fUseDrawInsteadOfPartialRenderTargetWrite = true;
455 }
456
robertphillips63926682015-08-20 09:39:02 -0700457#ifdef SK_BUILD_FOR_WIN
458 // On ANGLE deferring flushes can lead to GPU starvation
459 fPreferVRAMUseOverFlushes = !isANGLE;
460#endif
461
bsalomon7dea7b72015-08-19 08:26:51 -0700462 if (kChromium_GrGLDriver == ctxInfo.driver()) {
463 fMustClearUploadedBufferData = true;
464 }
465
bsalomond08ea5f2015-02-20 06:58:13 -0800466 if (kGL_GrGLStandard == standard) {
467 // ARB allows mixed size FBO attachments, EXT does not.
468 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
469 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
470 fOversizedStencilSupport = true;
471 } else {
472 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
473 }
474 } else {
475 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
476 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
477 }
478
joshualitt58001552015-06-26 12:46:36 -0700479 if (kGL_GrGLStandard == standard) {
480 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
481 // instanced arrays, but we could make this more granular if we wanted
482 fSupportsInstancedDraws =
483 version >= GR_GL_VER(3, 2) ||
484 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
485 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
486 } else {
487 fSupportsInstancedDraws =
488 version >= GR_GL_VER(3, 0) ||
489 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
490 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
491 }
492
cdalton06604b92016-02-05 10:09:51 -0800493 if (kGL_GrGLStandard == standard) {
494 // We don't use ARB_draw_indirect because it does not support a base instance.
495 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
496 fDrawIndirectSupport =
497 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
498 } else {
499 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
500 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
501 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
502 }
503
jvanverthcba99b82015-06-24 06:59:57 -0700504 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800505
506 if (contextOptions.fUseShaderSwizzling) {
507 fTextureSwizzleSupport = false;
508 }
509
510 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
511 // already been detected.
512 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700513
514 this->applyOptionsOverrides(contextOptions);
515 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000516}
517
egdaniel472d44e2015-10-22 08:20:00 -0700518const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
519 bool isCoreProfile) {
520 switch (generation) {
521 case k110_GrGLSLGeneration:
522 if (kGLES_GrGLStandard == standard) {
523 // ES2s shader language is based on version 1.20 but is version
524 // 1.00 of the ES language.
525 return "#version 100\n";
526 } else {
527 SkASSERT(kGL_GrGLStandard == standard);
528 return "#version 110\n";
529 }
530 case k130_GrGLSLGeneration:
531 SkASSERT(kGL_GrGLStandard == standard);
532 return "#version 130\n";
533 case k140_GrGLSLGeneration:
534 SkASSERT(kGL_GrGLStandard == standard);
535 return "#version 140\n";
536 case k150_GrGLSLGeneration:
537 SkASSERT(kGL_GrGLStandard == standard);
538 if (isCoreProfile) {
539 return "#version 150\n";
540 } else {
541 return "#version 150 compatibility\n";
542 }
543 case k330_GrGLSLGeneration:
544 if (kGLES_GrGLStandard == standard) {
545 return "#version 300 es\n";
546 } else {
547 SkASSERT(kGL_GrGLStandard == standard);
548 if (isCoreProfile) {
549 return "#version 330\n";
550 } else {
551 return "#version 330 compatibility\n";
552 }
553 }
554 case k310es_GrGLSLGeneration:
555 SkASSERT(kGLES_GrGLStandard == standard);
556 return "#version 310 es\n";
557 }
558 return "<no version>";
559}
560
egdaniel05ded892015-10-26 07:38:05 -0700561void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700562 GrGLStandard standard = ctxInfo.standard();
563 GrGLVersion version = ctxInfo.version();
564
565 /**************************************************************************
566 * Caps specific to GrGLSLCaps
567 **************************************************************************/
568
569 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
570 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700571 if (kGLES_GrGLStandard == standard) {
572 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
573 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
574 glslCaps->fFBFetchSupport = true;
575 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
576 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
577 }
578 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
579 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
580 glslCaps->fFBFetchNeedsCustomOutput = false;
581 glslCaps->fFBFetchSupport = true;
582 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
583 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
584 }
585 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
586 // The arm extension also requires an additional flag which we will set onResetContext
587 glslCaps->fFBFetchNeedsCustomOutput = false;
588 glslCaps->fFBFetchSupport = true;
589 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
590 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
591 }
592 glslCaps->fUsesPrecisionModifiers = true;
593 }
594
595 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
596
597 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
598 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
599
600 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
601 // function that may require a gradient calculation inside a conditional block may return
602 // undefined results". This appears to be an issue with the 'any' call since even the simple
603 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
604 // from our GrTextureDomain processor.
605 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
606
egdaniel472d44e2015-10-22 08:20:00 -0700607 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
608 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800609
610 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
611 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
612 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800613
614 // Frag Coords Convention support is not part of ES
615 // Known issue on at least some Intel platforms:
616 // http://code.google.com/p/skia/issues/detail?id=946
617 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
618 kGLES_GrGLStandard != standard &&
619 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
620 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
621 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
622 }
623
624 if (kGLES_GrGLStandard == standard) {
625 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
626 }
627
bsalomon7ea33f52015-11-22 14:51:00 -0800628 if (fExternalTextureSupport) {
629 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
630 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
631 } else {
632 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
633 }
634 }
635
egdaniel8dcdedc2015-11-11 06:27:20 -0800636 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
637 // the abs first in a separate expression.
638 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
639 glslCaps->fCanUseMinAndAbsTogether = false;
640 }
641
bsalomon7ea33f52015-11-22 14:51:00 -0800642 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
egdaniel8dcdedc2015-11-11 06:27:20 -0800643 // thus must us -1.0 * %s.x to work correctly
644 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
645 glslCaps->fMustForceNegatedAtanParamToFloat = true;
646 }
egdaniel472d44e2015-10-22 08:20:00 -0700647}
648
kkinnunencfe62e32015-07-01 02:58:50 -0700649bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700650 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
651
652 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700653 return false;
654 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700655
kkinnunencfe62e32015-07-01 02:58:50 -0700656 if (kGL_GrGLStandard == ctxInfo.standard()) {
657 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
658 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
659 return false;
660 }
661 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700662 if (!hasChromiumPathRendering &&
663 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700664 return false;
665 }
666 }
667 // We only support v1.3+ of GL_NV_path_rendering which allows us to
668 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
669 // additions are detected by checking the existence of the function.
670 // We also use *Then* functions that not all drivers might have. Check
671 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800672 if (!gli->fFunctions.fStencilThenCoverFillPath ||
673 !gli->fFunctions.fStencilThenCoverStrokePath ||
674 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
675 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
676 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700677 return false;
678 }
679 return true;
680}
bsalomon1aa20292016-01-22 08:16:09 -0800681
682bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800683 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800684 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
685 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800686 // If it's not possible to even have a render target of rtConfig then read pixels is
687 // not supported regardless of readConfig.
688 if (!this->isConfigRenderable(rtConfig, false)) {
689 return false;
690 }
bsalomon7928ef62016-01-05 10:26:39 -0800691
bsalomon76148af2016-01-12 11:13:47 -0800692 GrGLenum readFormat;
693 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800694 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800695 return false;
696 }
697
bsalomon1aa20292016-01-22 08:16:09 -0800698 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800699 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
700 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
701 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
702 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
703 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
704 readFormat != GR_GL_BGRA) {
705 return false;
706 }
707 // There is also a set of allowed types, but all the types we use are in the set:
708 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
709 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
710 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
711 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
712 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
713 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
714 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800715 return true;
piotaixre4b23142014-10-02 10:57:53 -0700716 }
bsalomon7928ef62016-01-05 10:26:39 -0800717
bsalomon76148af2016-01-12 11:13:47 -0800718 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800719
bsalomon1aa20292016-01-22 08:16:09 -0800720 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800721 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
722 return true;
723 }
724 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800725 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800726 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
727 return true;
728 }
729 }
730
bsalomon1aa20292016-01-22 08:16:09 -0800731 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800732 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800733 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800734 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800735 if (!bindRenderTarget()) {
736 return false;
737 }
738 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
739 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800740 rpFormat->fFormat = format;
741 rpFormat->fType = type;
742 }
743
bsalomon1aa20292016-01-22 08:16:09 -0800744 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
745 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700746}
747
robertphillips@google.com6177e692013-02-28 20:16:25 +0000748void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000749
750 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000751 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000752 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
753 // ES3 driver bugs on at least one device with a tiled GPU (N10).
754 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
755 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
756 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
757 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800758 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700759 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000760 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000761 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
762 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
763 // chrome's extension is equivalent to the EXT msaa
764 // and fbo_blit extensions.
765 fMSFBOType = kDesktop_EXT_MSFBOType;
766 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
767 fMSFBOType = kES_Apple_MSFBOType;
768 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000769 } else {
egdanieleed519e2016-01-15 11:36:18 -0800770 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700771 fMSFBOType = kMixedSamples_MSFBOType;
772 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000773 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000774 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000775 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
776 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000777 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000778 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000779 }
780}
781
cdalton1dd05422015-06-12 09:01:18 -0700782void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
783 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
784
785 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
786 // for now until its own blacklists can be updated.
787 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
788 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700789 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700790 return;
791 }
792
793 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
794 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
795 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
796 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
797 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
798 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
799 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
800 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
801 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
802 return;
803 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
804 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
805 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
806 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
807 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
808 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
809 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
810 // slow on a particular platform.
811 } else {
812 return; // No advanced blend support.
813 }
814
815 SkASSERT(this->advancedBlendEquationSupport());
816
817 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
818 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
819 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
820 (1 << kColorBurn_GrBlendEquation);
821 }
joel.liang9764c402015-07-09 19:46:18 -0700822 if (kARM_GrGLVendor == ctxInfo.vendor()) {
823 // Blacklist color-burn on ARM until the fix is released.
824 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
825 }
cdalton1dd05422015-06-12 09:01:18 -0700826}
827
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000828namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700829const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000830}
831
832void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
833
834 // Build up list of legal stencil formats (though perhaps not supported on
835 // the particular gpu/driver) from most preferred to least.
836
837 // these consts are in order of most preferred to least preferred
838 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
839
840 static const StencilFormat
841 // internal Format stencil bits total bits packed?
842 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
843 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
844 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
845 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000846 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000847 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
848
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000849 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000850 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000851 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000852 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
853 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
854
855 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
856 // require FBO support we can expect these are legal formats and don't
857 // check. These also all support the unsized GL_STENCIL_INDEX.
858 fStencilFormats.push_back() = gS8;
859 fStencilFormats.push_back() = gS16;
860 if (supportsPackedDS) {
861 fStencilFormats.push_back() = gD24S8;
862 }
863 fStencilFormats.push_back() = gS4;
864 if (supportsPackedDS) {
865 fStencilFormats.push_back() = gDS;
866 }
867 } else {
868 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
869 // for other formats.
870 // ES doesn't support using the unsized format.
871
872 fStencilFormats.push_back() = gS8;
873 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000874 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
875 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000876 fStencilFormats.push_back() = gD24S8;
877 }
878 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
879 fStencilFormats.push_back() = gS4;
880 }
881 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000882}
883
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000884SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000885
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000886 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000887
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000888 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000889 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000890 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000891 i,
892 fStencilFormats[i].fStencilBits,
893 fStencilFormats[i].fTotalBits);
894 }
895
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000896 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000897 "None",
898 "ARB",
899 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000900 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000901 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000902 "IMG MS To Texture",
903 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -0700904 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000905 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000906 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
907 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
908 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000909 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
910 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
911 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
912 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -0700913 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000914 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000915
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000916 static const char* kInvalidateFBTypeStr[] = {
917 "None",
918 "Discard",
919 "Invalidate",
920 };
921 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
922 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
923 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
924 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000925
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000926 static const char* kMapBufferTypeStr[] = {
927 "None",
928 "MapBuffer",
929 "MapBufferRange",
930 "Chromium",
931 };
932 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
933 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
934 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
935 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
936 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
937
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000938 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000939 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000940 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000941 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000942 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
943 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000944 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000945 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
946 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
947 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
948 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000949
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000950 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
951 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
952 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
953 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000954 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -0700955 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
956 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -0800957 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -0800958 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
959 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
960 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000961 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000962 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -0700963 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -0700964 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
965 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -0700966 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -0800967 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -0800968 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -0800969 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -0800970
971 r.append("Configs\n-------\n");
972 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
973 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -0800974 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
975 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -0800976 i,
977 fConfigTable[i].fFlags,
978 fConfigTable[i].fFormats.fBaseInternalFormat,
979 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -0800980 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
981 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -0800982 fConfigTable[i].fFormats.fExternalType,
983 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -0800984 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -0800985 }
986
jvanverthe9c0fc62015-04-29 11:18:05 -0700987 return r;
988}
989
jvanverthe9c0fc62015-04-29 11:18:05 -0700990static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
991 switch (p) {
992 case kLow_GrSLPrecision:
993 return GR_GL_LOW_FLOAT;
994 case kMedium_GrSLPrecision:
995 return GR_GL_MEDIUM_FLOAT;
996 case kHigh_GrSLPrecision:
997 return GR_GL_HIGH_FLOAT;
998 }
999 SkFAIL("Unknown precision.");
1000 return -1;
1001}
1002
1003static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1004 switch (type) {
1005 case kVertex_GrShaderType:
1006 return GR_GL_VERTEX_SHADER;
1007 case kGeometry_GrShaderType:
1008 return GR_GL_GEOMETRY_SHADER;
1009 case kFragment_GrShaderType:
1010 return GR_GL_FRAGMENT_SHADER;
1011 }
1012 SkFAIL("Unknown shader type.");
1013 return -1;
1014}
1015
jvanverthcba99b82015-06-24 06:59:57 -07001016void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1017 const GrGLInterface* intf,
1018 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001019 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1020 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1021 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1022 if (kGeometry_GrShaderType != s) {
1023 GrShaderType shaderType = static_cast<GrShaderType>(s);
1024 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001025 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001026 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001027 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1028 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1029 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1030 GrGLint range[2];
1031 GrGLint bits;
1032 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1033 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001034 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1035 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1036 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001037 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001038 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001039 }
jvanverthcba99b82015-06-24 06:59:57 -07001040 else if (!glslCaps->fShaderPrecisionVaries) {
1041 glslCaps->fShaderPrecisionVaries =
1042 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001043 }
1044 }
1045 }
1046 }
1047 }
1048 }
1049 else {
1050 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001051 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001052 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1053 if (kGeometry_GrShaderType != s) {
1054 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001055 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1056 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1057 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001058 }
1059 }
1060 }
1061 }
1062 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1063 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1064 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1065 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001066 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001067 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001068 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1069 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001070 }
1071 }
1072}
1073
bsalomon41e4384e2016-01-08 09:12:44 -08001074bool GrGLCaps::bgraIsInternalFormat() const {
1075 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1076}
1077
bsalomon76148af2016-01-12 11:13:47 -08001078bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1079 GrGLenum* internalFormat, GrGLenum* externalFormat,
1080 GrGLenum* externalType) const {
1081 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1082 externalFormat, externalType)) {
1083 return false;
1084 }
1085 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1086 return true;
1087}
1088
1089bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1090 GrGLenum* internalFormat) const {
1091 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1092 return false;
1093 }
1094 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1095 return true;
1096}
1097
1098bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1099 GrGLenum* externalFormat, GrGLenum* externalType) const {
1100 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1101 externalFormat, externalType)) {
1102 return false;
1103 }
1104 return true;
1105}
1106
1107bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1108 if (GrPixelConfigIsCompressed(config)) {
1109 return false;
1110 }
1111 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1112 return true;
1113}
1114
1115bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1116 ExternalFormatUsage usage, GrGLenum* externalFormat,
1117 GrGLenum* externalType) const {
1118 SkASSERT(externalFormat && externalType);
1119 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1120 return false;
1121 }
1122
1123 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1124 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1125
1126 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1127 // made to work in many cases using glPixelStore and what not but is not needed currently.
1128 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1129 return false;
1130 }
1131
1132 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1133 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1134
bsalomone9573312016-01-25 14:33:25 -08001135 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1136 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1137 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1138 // texture, not the red component.
1139 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1140 if (this->textureRedSupport()) {
1141 SkASSERT(GR_GL_RED == *externalFormat);
1142 *externalFormat = GR_GL_ALPHA;
1143 }
1144 }
1145
bsalomon76148af2016-01-12 11:13:47 -08001146 return true;
1147}
1148
bsalomoncdee0092016-01-08 13:20:12 -08001149void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1150 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001151 /*
1152 Comments on renderability of configs on various GL versions.
1153 OpenGL < 3.0:
1154 no built in support for render targets.
1155 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1156 format RGB, RGBA and NV float formats we don't use.
1157 This is the following:
1158 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1159 RGB10_A2, RGBA12,RGBA16
1160 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1161 since they aren't required by later standards and the driver can simply return
1162 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1163 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1164 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1165 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1166 This adds a lot of additional renderable sized formats, including ALPHA8.
1167 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1168 16F, 32I, 32UI, and 32F variants).
1169 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1170
1171 For both the above extensions we limit ourselves to those that are also required by
1172 OpenGL 3.0.
1173
1174 OpenGL 3.0:
1175 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1176 but are not required to be supported as renderable textures/renderbuffer.
1177 Required renderable color formats:
1178 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1179 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1180 RGB10_A2.
1181 - R11F_G11F_B10F.
1182 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1183 and RG8UI.
1184 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1185 - ALPHA8
1186
1187 OpenGL 3.1, 3.2, 3.3
1188 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1189 OpengGL 3.3, 4.0, 4.1
1190 Adds RGB10_A2UI.
1191 OpengGL 4.2
1192 Adds
1193 - RGB5_A1, RGBA4
1194 - RGB565
1195 OpenGL 4.4
1196 Does away with the separate list and adds a column to the sized internal color format
1197 table. However, no new formats become required color renderable.
1198
1199 ES 2.0
1200 color renderable: RGBA4, RGB5_A1, RGB565
1201 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1202 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1203 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1204 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1205 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1206 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1207
1208 ES 3.0
1209 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1210 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1211 RGB5_A1.
1212 - RGB8 and RGB565.
1213 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1214 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1215 ES 3.1
1216 Adds RGB10_A2, RGB10_A2UI,
1217 ES 3.2
1218 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1219 */
1220 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1221 if (kNone_MSFBOType != fMSFBOType) {
1222 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1223 }
1224
1225 GrGLStandard standard = ctxInfo.standard();
1226 GrGLVersion version = ctxInfo.version();
1227
bsalomon30447372015-12-21 09:03:05 -08001228 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1229 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001230 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001231 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001232 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001233 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001234
1235 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1236 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001237 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1238 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001239 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001240 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001241 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1242 if (kGL_GrGLStandard == standard) {
1243 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1244 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001245 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001246 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1247 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1248 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1249 }
egdaniel4999df82016-01-07 17:06:04 -08001250 }
bsalomoncdee0092016-01-08 13:20:12 -08001251 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001252
bsalomon76148af2016-01-12 11:13:47 -08001253 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1254 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001255 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001256 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001257 if (kGL_GrGLStandard == standard) {
1258 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1259 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1260 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1261 // Since the internal format is RGBA8, it is also renderable.
1262 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1263 allRenderFlags;
1264 }
1265 } else {
1266 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1267 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1268 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1269 // The APPLE extension doesn't make this renderable.
1270 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1271 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1272 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1273 // Though, that seems to not be the case if the texture storage extension is
1274 // present. The specs don't exactly make that clear.
1275 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1276 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1277 }
1278 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1279 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1280 ConfigInfo::kRenderable_Flag;
1281 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001282 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001283 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1284 ConfigInfo::kRenderableWithMSAA_Flag;
1285 }
1286 }
1287 }
bsalomoncdee0092016-01-08 13:20:12 -08001288 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001289
bsalomon41e4384e2016-01-08 09:12:44 -08001290 // We only enable srgb support if both textures and FBOs support srgb.
1291 bool srgbSupport = false;
1292 if (kGL_GrGLStandard == standard) {
1293 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1294 srgbSupport = true;
1295 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1296 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1297 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1298 srgbSupport = true;
1299 }
1300 }
1301 // All the above srgb extensions support toggling srgb writes
1302 fSRGBWriteControl = srgbSupport;
1303 } else {
1304 // See https://bug.skia.org/4148 for PowerVR issue.
1305 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1306 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1307 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1308 // sRGB writing for destinations.
1309 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1310 }
bsalomon30447372015-12-21 09:03:05 -08001311 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1312 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1313 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1314 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001315 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1316 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001317 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001318 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001319 if (srgbSupport) {
1320 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1321 allRenderFlags;
1322 }
bsalomoncdee0092016-01-08 13:20:12 -08001323 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001324
1325 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1326 if (this->ES2CompatibilitySupport()) {
1327 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1328 } else {
1329 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1330 }
bsalomon76148af2016-01-12 11:13:47 -08001331 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1332 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001333 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001334 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001335 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1336 if (kGL_GrGLStandard == standard) {
1337 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1338 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1339 }
1340 } else {
1341 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1342 }
bsalomoncdee0092016-01-08 13:20:12 -08001343 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001344
1345 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1346 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001347 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1348 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001349 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001350 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001351 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1352 if (kGL_GrGLStandard == standard) {
1353 if (version >= GR_GL_VER(4, 2)) {
1354 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1355 }
1356 } else {
1357 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1358 }
bsalomoncdee0092016-01-08 13:20:12 -08001359 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001360
1361 if (this->textureRedSupport()) {
1362 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1363 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001364 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1365 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001366 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001367 } else {
1368 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1369 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001370 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1371 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001372 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001373 }
1374 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001375 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001376 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1377 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1378 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1379 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1380 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1381 }
1382
1383 // Check for [half] floating point texture support
1384 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1385 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1386 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1387 bool hasFPTextures = false;
1388 bool hasHalfFPTextures = false;
1389 // for now we don't support floating point MSAA on ES
1390 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1391 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1392
1393 if (kGL_GrGLStandard == standard) {
1394 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1395 hasFPTextures = true;
1396 hasHalfFPTextures = true;
1397 }
1398 } else {
1399 if (version >= GR_GL_VER(3, 1)) {
1400 hasFPTextures = true;
1401 hasHalfFPTextures = true;
1402 } else {
1403 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1404 ctxInfo.hasExtension("GL_OES_texture_float")) {
1405 hasFPTextures = true;
1406 }
1407 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1408 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1409 hasHalfFPTextures = true;
1410 }
1411 }
1412 }
bsalomon30447372015-12-21 09:03:05 -08001413
1414 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1415 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001416 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1417 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001418 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001419 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001420 if (hasFPTextures) {
1421 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1422 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1423 // many precision issues and no clients actually want this yet.
1424 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1425 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1426 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1427 }
1428 }
bsalomoncdee0092016-01-08 13:20:12 -08001429 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001430
1431 if (this->textureRedSupport()) {
1432 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1433 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001434 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1435 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001436 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001437 } else {
1438 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1439 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001440 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1441 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001442 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001443 }
1444 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1445 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1446 } else {
1447 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1448 }
bsalomon7928ef62016-01-05 10:26:39 -08001449 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001450 if (hasHalfFPTextures) {
1451 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1452 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1453 // GL_RED internal format.
1454 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1455 (this->textureRedSupport() &&
1456 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1457 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1458 }
1459 }
bsalomon30447372015-12-21 09:03:05 -08001460
1461 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1462 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001463 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1464 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001465 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1466 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1467 } else {
1468 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1469 }
bsalomon7928ef62016-01-05 10:26:39 -08001470 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001471 if (hasHalfFPTextures) {
1472 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1473 // ES requires 3.2 or EXT_color_buffer_half_float.
1474 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1475 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1476 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1477 }
1478 }
bsalomoncdee0092016-01-08 13:20:12 -08001479 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001480
1481 // Compressed texture support
1482
1483 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1484 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1485
1486 // TODO: Fix command buffer bindings and remove this.
1487 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001488
1489 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001490 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001491
1492 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1493 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001494 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001495 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001496 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001497 // Disable this for now, while we investigate https://bug.skia.org/4333
1498 if (false) {
1499 // Check for 8-bit palette..
1500 GrGLint numFormats;
1501 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1502 if (numFormats) {
1503 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1504 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1505 for (int i = 0; i < numFormats; ++i) {
1506 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1507 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1508 break;
1509 }
1510 }
1511 }
1512 }
bsalomoncdee0092016-01-08 13:20:12 -08001513 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001514
bsalomon41e4384e2016-01-08 09:12:44 -08001515 // May change the internal format based on extensions.
1516 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1517 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1518 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1519 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1520 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1521 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1522 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1523 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1524 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1525 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1526 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1527 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1528 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1529 GR_GL_COMPRESSED_RED_RGTC1;
1530 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1531 GR_GL_COMPRESSED_RED_RGTC1;
1532 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1533 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1534 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1535 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1536 GR_GL_COMPRESSED_3DC_X;
1537
bsalomon30447372015-12-21 09:03:05 -08001538 }
bsalomon76148af2016-01-12 11:13:47 -08001539 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001540 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001541 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001542 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001543
1544 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1545 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001546 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001547 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001548 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001549 if (kGL_GrGLStandard == standard) {
1550 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1551 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1552 }
1553 } else {
1554 if (version >= GR_GL_VER(3, 0) ||
1555 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1556 // ETC2 is a superset of ETC1, so we can just check for that, too.
1557 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1558 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1559 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1560 }
1561 }
bsalomoncdee0092016-01-08 13:20:12 -08001562 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001563
1564 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1565 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001566 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001567 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001568 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001569 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1570 // decompressing the textures in the driver, and is generally slower.
1571 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1572 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1573 }
bsalomoncdee0092016-01-08 13:20:12 -08001574 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001575
1576 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1577 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1578 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1579 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001580 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1581 0;
bsalomon30447372015-12-21 09:03:05 -08001582 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001583 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001584 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1585 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1586 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1587 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1588 }
bsalomoncdee0092016-01-08 13:20:12 -08001589 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001590
1591 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1592
1593 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001594 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1595 ctxInfo.version() >= GR_GL_VER(3,0));
1596 // All ES versions (thus far) require sized internal formats for render buffers.
1597 // TODO: Always use sized internal format?
1598 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1599
bsalomon30447372015-12-21 09:03:05 -08001600 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001601 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1602 // param to glTex[Sub]Image.
1603 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1604 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1605 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1606 fConfigTable[i].fFormats.fSizedInternalFormat :
1607 fConfigTable[i].fFormats.fBaseInternalFormat;
1608 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001609 fConfigTable[i].fFormats.fSizedInternalFormat :
1610 fConfigTable[i].fFormats.fBaseInternalFormat;
1611 }
1612 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1613 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1614 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1615 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1616 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001617 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001618 GR_GL_SRGB_ALPHA;
1619 }
1620
1621 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1622 // as a base format.
1623 // GL_EXT_texture_format_BGRA8888:
1624 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1625 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1626 // formats.
1627 // GL_APPLE_texture_format_BGRA8888:
1628 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1629 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1630 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001631 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001632 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1633 }
1634
bsalomoncdee0092016-01-08 13:20:12 -08001635 // If we don't have texture swizzle support then the shader generator must insert the
1636 // swizzle into shader code.
1637 if (!this->textureSwizzleSupport()) {
1638 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1639 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1640 }
1641 }
1642
bsalomon7f9b2e42016-01-12 13:29:26 -08001643 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1644 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1645 // gets written to the single component.
1646 if (this->textureRedSupport()) {
1647 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1648 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1649 if (GrPixelConfigIsAlphaOnly(config) &&
1650 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1651 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1652 }
1653 }
1654 }
1655
bsalomon30447372015-12-21 09:03:05 -08001656#ifdef SK_DEBUG
1657 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001658 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001659 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001660 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1661 fConfigTable[i].fFormats.fBaseInternalFormat);
1662 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001663 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001664 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1665 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1666 fConfigTable[i].fFormats.fExternalFormat[j]);
1667 }
1668 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001669 }
1670#endif
1671}
1672
egdanielb7e7d572015-11-04 04:23:53 -08001673void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}