blob: a913fbeca2fff8b052e15b33fa45a853cf61b315 [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;
282 }
283 else {
284 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
285
286 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
287 ctxInfo.hasExtension("GL_OES_standard_derivatives");
288 }
289
ethannicholas22793252016-01-30 09:59:10 -0800290 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
291 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
292 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
293 &glslCaps->fPixelLocalStorageSize);
294 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
295 }
296 else {
297 glslCaps->fPixelLocalStorageSize = 0;
298 glslCaps->fPLSPathRenderingSupport = false;
299 }
300
egdaniel05ded892015-10-26 07:38:05 -0700301 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700302 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000303 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700304
cdalton63f6c1f2015-11-06 07:09:43 -0800305 // We need dual source blending and the ability to disable multisample in order to support mixed
306 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800307 if (fMultisampleDisableSupport &&
308 glslCaps->dualSourceBlendingSupport() &&
309 fShaderCaps->pathRenderingSupport()) {
310 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800311 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800312 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800313 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
314 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800315 fDiscardRenderTargetSupport = false;
316 fInvalidateFBType = kNone_InvalidateFBType;
317 }
318 }
319
egdanieleed519e2016-01-15 11:36:18 -0800320 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700321 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700322 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700323 this->initStencilFormats(ctxInfo);
324
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000325 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000326 // we could also look for GL_ATI_separate_stencil extension or
327 // GL_EXT_stencil_two_side but they use different function signatures
328 // than GL2.0+ (and than each other).
329 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
330 // supported on GL 1.4 and higher or by extension
331 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
332 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
333 } else {
334 // ES 2 has two sided stencil and stencil wrap
335 fTwoSidedStencilSupport = true;
336 fStencilWrapOpsSupport = true;
337 }
338
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000339 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000340 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
341 // extension includes glMapBuffer.
342 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
343 fMapBufferFlags |= kSubset_MapFlag;
344 fMapBufferType = kMapBufferRange_MapBufferType;
345 } else {
346 fMapBufferType = kMapBuffer_MapBufferType;
347 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000348 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000349 // Unextended GLES2 doesn't have any buffer mapping.
350 fMapBufferFlags = kNone_MapBufferType;
351 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
352 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
353 fMapBufferType = kChromium_MapBufferType;
354 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
355 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
356 fMapBufferType = kMapBufferRange_MapBufferType;
357 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
358 fMapBufferFlags = kCanMap_MapFlag;
359 fMapBufferType = kMapBuffer_MapBufferType;
360 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000361 }
362
jvanverthd7a2c1f2015-12-07 07:36:44 -0800363 if (kGL_GrGLStandard == standard) {
364 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
365 fTransferBufferType = kPBO_TransferBufferType;
366 }
367 } else {
368 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
369 fTransferBufferType = kPBO_TransferBufferType;
370 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
371 fTransferBufferType = kChromium_TransferBufferType;
372 }
373 }
374
joshualitte5b74c62015-06-01 14:17:47 -0700375 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
376 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
377 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700378 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
379 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
380 // a small subset.
381#if 0
cdalton1acea862015-06-02 13:05:52 -0700382 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700383#else
384 fGeometryBufferMapThreshold = SK_MaxS32;
385#endif
joshualitte5b74c62015-06-01 14:17:47 -0700386 }
387
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000388 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000389 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
390 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
391 fNPOTTextureTileSupport = true;
392 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000393 } else {
394 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000395 // ES3 has no limitations.
396 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
397 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000398 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
399 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
400 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
401 // to alllow arbitrary wrap modes, however.
402 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000403 }
404
bsalomone72bd022015-10-26 07:33:03 -0700405 // Using MIPs on this GPU seems to be a source of trouble.
406 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
407 fMipMapSupport = false;
408 }
409
bsalomon@google.combcce8922013-03-25 15:38:39 +0000410 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
411 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
412 // Our render targets are always created with textures as the color
413 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000414 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000415
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000416 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
417
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000418 // Disable scratch texture reuse on Mali and Adreno devices
419 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
420 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000421
robertphillips1b8e1b52015-06-24 06:54:10 -0700422#if 0
423 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
424 kQualcomm_GrGLVendor != ctxInfo.vendor();
425#endif
426
egdaniel05ded892015-10-26 07:38:05 -0700427 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000428 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800429 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000430 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800431 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000432 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800433 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
434 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
435 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
436 // This is to guard against platforms that may not support as many samples for
437 // glRasterSamples as they do for framebuffers.
438 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
439 }
440 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000441
bsalomon63b21962014-11-05 07:05:34 -0800442 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800443 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800444 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800445 fUseDrawInsteadOfClear = true;
446 }
447
joshualitt83bc2292015-06-18 14:18:02 -0700448 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
449 fUseDrawInsteadOfPartialRenderTargetWrite = true;
450 }
451
robertphillips63926682015-08-20 09:39:02 -0700452#ifdef SK_BUILD_FOR_WIN
453 // On ANGLE deferring flushes can lead to GPU starvation
454 fPreferVRAMUseOverFlushes = !isANGLE;
455#endif
456
bsalomon7dea7b72015-08-19 08:26:51 -0700457 if (kChromium_GrGLDriver == ctxInfo.driver()) {
458 fMustClearUploadedBufferData = true;
459 }
460
bsalomond08ea5f2015-02-20 06:58:13 -0800461 if (kGL_GrGLStandard == standard) {
462 // ARB allows mixed size FBO attachments, EXT does not.
463 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
464 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
465 fOversizedStencilSupport = true;
466 } else {
467 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
468 }
469 } else {
470 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
471 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
472 }
473
joshualitt58001552015-06-26 12:46:36 -0700474 if (kGL_GrGLStandard == standard) {
475 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
476 // instanced arrays, but we could make this more granular if we wanted
477 fSupportsInstancedDraws =
478 version >= GR_GL_VER(3, 2) ||
479 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
480 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
481 } else {
482 fSupportsInstancedDraws =
483 version >= GR_GL_VER(3, 0) ||
484 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
485 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
486 }
487
cdalton06604b92016-02-05 10:09:51 -0800488 if (kGL_GrGLStandard == standard) {
489 // We don't use ARB_draw_indirect because it does not support a base instance.
490 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
491 fDrawIndirectSupport =
492 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
493 } else {
494 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
495 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
496 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
497 }
498
jvanverthcba99b82015-06-24 06:59:57 -0700499 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800500
501 if (contextOptions.fUseShaderSwizzling) {
502 fTextureSwizzleSupport = false;
503 }
504
505 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
506 // already been detected.
507 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700508
509 this->applyOptionsOverrides(contextOptions);
510 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000511}
512
egdaniel472d44e2015-10-22 08:20:00 -0700513const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
514 bool isCoreProfile) {
515 switch (generation) {
516 case k110_GrGLSLGeneration:
517 if (kGLES_GrGLStandard == standard) {
518 // ES2s shader language is based on version 1.20 but is version
519 // 1.00 of the ES language.
520 return "#version 100\n";
521 } else {
522 SkASSERT(kGL_GrGLStandard == standard);
523 return "#version 110\n";
524 }
525 case k130_GrGLSLGeneration:
526 SkASSERT(kGL_GrGLStandard == standard);
527 return "#version 130\n";
528 case k140_GrGLSLGeneration:
529 SkASSERT(kGL_GrGLStandard == standard);
530 return "#version 140\n";
531 case k150_GrGLSLGeneration:
532 SkASSERT(kGL_GrGLStandard == standard);
533 if (isCoreProfile) {
534 return "#version 150\n";
535 } else {
536 return "#version 150 compatibility\n";
537 }
538 case k330_GrGLSLGeneration:
539 if (kGLES_GrGLStandard == standard) {
540 return "#version 300 es\n";
541 } else {
542 SkASSERT(kGL_GrGLStandard == standard);
543 if (isCoreProfile) {
544 return "#version 330\n";
545 } else {
546 return "#version 330 compatibility\n";
547 }
548 }
549 case k310es_GrGLSLGeneration:
550 SkASSERT(kGLES_GrGLStandard == standard);
551 return "#version 310 es\n";
552 }
553 return "<no version>";
554}
555
egdaniel05ded892015-10-26 07:38:05 -0700556void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700557 GrGLStandard standard = ctxInfo.standard();
558 GrGLVersion version = ctxInfo.version();
559
560 /**************************************************************************
561 * Caps specific to GrGLSLCaps
562 **************************************************************************/
563
564 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
565 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700566 if (kGLES_GrGLStandard == standard) {
567 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
568 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
569 glslCaps->fFBFetchSupport = true;
570 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
571 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
572 }
573 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
574 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
575 glslCaps->fFBFetchNeedsCustomOutput = false;
576 glslCaps->fFBFetchSupport = true;
577 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
578 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
579 }
580 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
581 // The arm extension also requires an additional flag which we will set onResetContext
582 glslCaps->fFBFetchNeedsCustomOutput = false;
583 glslCaps->fFBFetchSupport = true;
584 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
585 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
586 }
587 glslCaps->fUsesPrecisionModifiers = true;
588 }
589
590 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
591
592 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
593 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
594
595 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
596 // function that may require a gradient calculation inside a conditional block may return
597 // undefined results". This appears to be an issue with the 'any' call since even the simple
598 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
599 // from our GrTextureDomain processor.
600 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
601
egdaniel472d44e2015-10-22 08:20:00 -0700602 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
603 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800604
605 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
606 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
607 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800608
609 // Frag Coords Convention support is not part of ES
610 // Known issue on at least some Intel platforms:
611 // http://code.google.com/p/skia/issues/detail?id=946
612 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
613 kGLES_GrGLStandard != standard &&
614 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
615 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
616 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
617 }
618
619 if (kGLES_GrGLStandard == standard) {
620 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
621 }
622
bsalomon7ea33f52015-11-22 14:51:00 -0800623 if (fExternalTextureSupport) {
624 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
625 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
626 } else {
627 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
628 }
629 }
630
egdaniel8dcdedc2015-11-11 06:27:20 -0800631 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
632 // the abs first in a separate expression.
633 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
634 glslCaps->fCanUseMinAndAbsTogether = false;
635 }
636
bsalomon7ea33f52015-11-22 14:51:00 -0800637 // 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 -0800638 // thus must us -1.0 * %s.x to work correctly
639 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
640 glslCaps->fMustForceNegatedAtanParamToFloat = true;
641 }
egdaniel472d44e2015-10-22 08:20:00 -0700642}
643
kkinnunencfe62e32015-07-01 02:58:50 -0700644bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700645 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
646
647 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700648 return false;
649 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700650
kkinnunencfe62e32015-07-01 02:58:50 -0700651 if (kGL_GrGLStandard == ctxInfo.standard()) {
652 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
653 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
654 return false;
655 }
656 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700657 if (!hasChromiumPathRendering &&
658 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700659 return false;
660 }
661 }
662 // We only support v1.3+ of GL_NV_path_rendering which allows us to
663 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
664 // additions are detected by checking the existence of the function.
665 // We also use *Then* functions that not all drivers might have. Check
666 // them for consistency.
halcanary96fcdcc2015-08-27 07:41:13 -0700667 if (nullptr == gli->fFunctions.fStencilThenCoverFillPath ||
668 nullptr == gli->fFunctions.fStencilThenCoverStrokePath ||
669 nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
670 nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
671 nullptr == gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700672 return false;
673 }
674 return true;
675}
bsalomon1aa20292016-01-22 08:16:09 -0800676
677bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800678 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800679 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
680 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800681 // If it's not possible to even have a render target of rtConfig then read pixels is
682 // not supported regardless of readConfig.
683 if (!this->isConfigRenderable(rtConfig, false)) {
684 return false;
685 }
bsalomon7928ef62016-01-05 10:26:39 -0800686
bsalomon76148af2016-01-12 11:13:47 -0800687 GrGLenum readFormat;
688 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800689 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800690 return false;
691 }
692
bsalomon1aa20292016-01-22 08:16:09 -0800693 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800694 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
695 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
696 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
697 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
698 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
699 readFormat != GR_GL_BGRA) {
700 return false;
701 }
702 // There is also a set of allowed types, but all the types we use are in the set:
703 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
704 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
705 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
706 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
707 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
708 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
709 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800710 return true;
piotaixre4b23142014-10-02 10:57:53 -0700711 }
bsalomon7928ef62016-01-05 10:26:39 -0800712
bsalomon76148af2016-01-12 11:13:47 -0800713 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800714
bsalomon1aa20292016-01-22 08:16:09 -0800715 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800716 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
717 return true;
718 }
719 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800720 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800721 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
722 return true;
723 }
724 }
725
bsalomon1aa20292016-01-22 08:16:09 -0800726 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800727 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800728 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800729 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800730 if (!bindRenderTarget()) {
731 return false;
732 }
733 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
734 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800735 rpFormat->fFormat = format;
736 rpFormat->fType = type;
737 }
738
bsalomon1aa20292016-01-22 08:16:09 -0800739 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
740 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700741}
742
robertphillips@google.com6177e692013-02-28 20:16:25 +0000743void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000744
745 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000746 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000747 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
748 // ES3 driver bugs on at least one device with a tiled GPU (N10).
749 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
750 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
751 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
752 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800753 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700754 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000755 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000756 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
757 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
758 // chrome's extension is equivalent to the EXT msaa
759 // and fbo_blit extensions.
760 fMSFBOType = kDesktop_EXT_MSFBOType;
761 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
762 fMSFBOType = kES_Apple_MSFBOType;
763 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000764 } else {
egdanieleed519e2016-01-15 11:36:18 -0800765 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700766 fMSFBOType = kMixedSamples_MSFBOType;
767 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000768 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000769 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000770 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
771 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000772 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000773 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000774 }
775}
776
cdalton1dd05422015-06-12 09:01:18 -0700777void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
778 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
779
780 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
781 // for now until its own blacklists can be updated.
782 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
783 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700784 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700785 return;
786 }
787
788 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
789 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
790 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
791 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
792 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
793 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
794 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
795 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
796 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
797 return;
798 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
799 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
800 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
801 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
802 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
803 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
804 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
805 // slow on a particular platform.
806 } else {
807 return; // No advanced blend support.
808 }
809
810 SkASSERT(this->advancedBlendEquationSupport());
811
812 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
813 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
814 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
815 (1 << kColorBurn_GrBlendEquation);
816 }
joel.liang9764c402015-07-09 19:46:18 -0700817 if (kARM_GrGLVendor == ctxInfo.vendor()) {
818 // Blacklist color-burn on ARM until the fix is released.
819 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
820 }
cdalton1dd05422015-06-12 09:01:18 -0700821}
822
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000823namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700824const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000825}
826
827void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
828
829 // Build up list of legal stencil formats (though perhaps not supported on
830 // the particular gpu/driver) from most preferred to least.
831
832 // these consts are in order of most preferred to least preferred
833 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
834
835 static const StencilFormat
836 // internal Format stencil bits total bits packed?
837 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
838 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
839 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
840 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000841 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000842 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
843
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000844 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000845 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000846 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000847 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
848 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
849
850 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
851 // require FBO support we can expect these are legal formats and don't
852 // check. These also all support the unsized GL_STENCIL_INDEX.
853 fStencilFormats.push_back() = gS8;
854 fStencilFormats.push_back() = gS16;
855 if (supportsPackedDS) {
856 fStencilFormats.push_back() = gD24S8;
857 }
858 fStencilFormats.push_back() = gS4;
859 if (supportsPackedDS) {
860 fStencilFormats.push_back() = gDS;
861 }
862 } else {
863 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
864 // for other formats.
865 // ES doesn't support using the unsized format.
866
867 fStencilFormats.push_back() = gS8;
868 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000869 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
870 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000871 fStencilFormats.push_back() = gD24S8;
872 }
873 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
874 fStencilFormats.push_back() = gS4;
875 }
876 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000877}
878
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000879SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000880
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000881 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000882
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000883 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000884 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000885 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000886 i,
887 fStencilFormats[i].fStencilBits,
888 fStencilFormats[i].fTotalBits);
889 }
890
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000891 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000892 "None",
893 "ARB",
894 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000895 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000896 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000897 "IMG MS To Texture",
898 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -0700899 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000900 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000901 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
902 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
903 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000904 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
905 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
906 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
907 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -0700908 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000909 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000910
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000911 static const char* kInvalidateFBTypeStr[] = {
912 "None",
913 "Discard",
914 "Invalidate",
915 };
916 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
917 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
918 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
919 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000920
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000921 static const char* kMapBufferTypeStr[] = {
922 "None",
923 "MapBuffer",
924 "MapBufferRange",
925 "Chromium",
926 };
927 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
928 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
929 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
930 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
931 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
932
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000933 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000934 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000935 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000936 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000937 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
938 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000939 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000940 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
941 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
942 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
943 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000944
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000945 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
946 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
947 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
948 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000949 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -0700950 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
951 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -0800952 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -0800953 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
954 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
955 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000956 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000957 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -0700958 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -0700959 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
960 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -0700961 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -0800962 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -0800963 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -0800964 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -0800965
966 r.append("Configs\n-------\n");
967 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
968 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -0800969 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
970 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -0800971 i,
972 fConfigTable[i].fFlags,
973 fConfigTable[i].fFormats.fBaseInternalFormat,
974 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -0800975 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
976 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -0800977 fConfigTable[i].fFormats.fExternalType,
978 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -0800979 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -0800980 }
981
jvanverthe9c0fc62015-04-29 11:18:05 -0700982 return r;
983}
984
jvanverthe9c0fc62015-04-29 11:18:05 -0700985static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
986 switch (p) {
987 case kLow_GrSLPrecision:
988 return GR_GL_LOW_FLOAT;
989 case kMedium_GrSLPrecision:
990 return GR_GL_MEDIUM_FLOAT;
991 case kHigh_GrSLPrecision:
992 return GR_GL_HIGH_FLOAT;
993 }
994 SkFAIL("Unknown precision.");
995 return -1;
996}
997
998static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
999 switch (type) {
1000 case kVertex_GrShaderType:
1001 return GR_GL_VERTEX_SHADER;
1002 case kGeometry_GrShaderType:
1003 return GR_GL_GEOMETRY_SHADER;
1004 case kFragment_GrShaderType:
1005 return GR_GL_FRAGMENT_SHADER;
1006 }
1007 SkFAIL("Unknown shader type.");
1008 return -1;
1009}
1010
jvanverthcba99b82015-06-24 06:59:57 -07001011void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1012 const GrGLInterface* intf,
1013 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001014 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1015 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1016 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1017 if (kGeometry_GrShaderType != s) {
1018 GrShaderType shaderType = static_cast<GrShaderType>(s);
1019 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001020 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001021 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001022 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1023 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1024 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1025 GrGLint range[2];
1026 GrGLint bits;
1027 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1028 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001029 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1030 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1031 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001032 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001033 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001034 }
jvanverthcba99b82015-06-24 06:59:57 -07001035 else if (!glslCaps->fShaderPrecisionVaries) {
1036 glslCaps->fShaderPrecisionVaries =
1037 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001038 }
1039 }
1040 }
1041 }
1042 }
1043 }
1044 else {
1045 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001046 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001047 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1048 if (kGeometry_GrShaderType != s) {
1049 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001050 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1051 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1052 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001053 }
1054 }
1055 }
1056 }
1057 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1058 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1059 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1060 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001061 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001062 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001063 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1064 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001065 }
1066 }
1067}
1068
bsalomon41e4384e2016-01-08 09:12:44 -08001069bool GrGLCaps::bgraIsInternalFormat() const {
1070 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1071}
1072
bsalomon76148af2016-01-12 11:13:47 -08001073bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1074 GrGLenum* internalFormat, GrGLenum* externalFormat,
1075 GrGLenum* externalType) const {
1076 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1077 externalFormat, externalType)) {
1078 return false;
1079 }
1080 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1081 return true;
1082}
1083
1084bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1085 GrGLenum* internalFormat) const {
1086 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1087 return false;
1088 }
1089 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1090 return true;
1091}
1092
1093bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1094 GrGLenum* externalFormat, GrGLenum* externalType) const {
1095 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1096 externalFormat, externalType)) {
1097 return false;
1098 }
1099 return true;
1100}
1101
1102bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1103 if (GrPixelConfigIsCompressed(config)) {
1104 return false;
1105 }
1106 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1107 return true;
1108}
1109
1110bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1111 ExternalFormatUsage usage, GrGLenum* externalFormat,
1112 GrGLenum* externalType) const {
1113 SkASSERT(externalFormat && externalType);
1114 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1115 return false;
1116 }
1117
1118 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1119 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1120
1121 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1122 // made to work in many cases using glPixelStore and what not but is not needed currently.
1123 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1124 return false;
1125 }
1126
1127 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1128 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1129
bsalomone9573312016-01-25 14:33:25 -08001130 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1131 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1132 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1133 // texture, not the red component.
1134 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1135 if (this->textureRedSupport()) {
1136 SkASSERT(GR_GL_RED == *externalFormat);
1137 *externalFormat = GR_GL_ALPHA;
1138 }
1139 }
1140
bsalomon76148af2016-01-12 11:13:47 -08001141 return true;
1142}
1143
bsalomoncdee0092016-01-08 13:20:12 -08001144void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1145 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001146 /*
1147 Comments on renderability of configs on various GL versions.
1148 OpenGL < 3.0:
1149 no built in support for render targets.
1150 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1151 format RGB, RGBA and NV float formats we don't use.
1152 This is the following:
1153 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1154 RGB10_A2, RGBA12,RGBA16
1155 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1156 since they aren't required by later standards and the driver can simply return
1157 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1158 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1159 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1160 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1161 This adds a lot of additional renderable sized formats, including ALPHA8.
1162 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1163 16F, 32I, 32UI, and 32F variants).
1164 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1165
1166 For both the above extensions we limit ourselves to those that are also required by
1167 OpenGL 3.0.
1168
1169 OpenGL 3.0:
1170 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1171 but are not required to be supported as renderable textures/renderbuffer.
1172 Required renderable color formats:
1173 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1174 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1175 RGB10_A2.
1176 - R11F_G11F_B10F.
1177 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1178 and RG8UI.
1179 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1180 - ALPHA8
1181
1182 OpenGL 3.1, 3.2, 3.3
1183 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1184 OpengGL 3.3, 4.0, 4.1
1185 Adds RGB10_A2UI.
1186 OpengGL 4.2
1187 Adds
1188 - RGB5_A1, RGBA4
1189 - RGB565
1190 OpenGL 4.4
1191 Does away with the separate list and adds a column to the sized internal color format
1192 table. However, no new formats become required color renderable.
1193
1194 ES 2.0
1195 color renderable: RGBA4, RGB5_A1, RGB565
1196 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1197 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1198 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1199 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1200 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1201 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1202
1203 ES 3.0
1204 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1205 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1206 RGB5_A1.
1207 - RGB8 and RGB565.
1208 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1209 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1210 ES 3.1
1211 Adds RGB10_A2, RGB10_A2UI,
1212 ES 3.2
1213 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1214 */
1215 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1216 if (kNone_MSFBOType != fMSFBOType) {
1217 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1218 }
1219
1220 GrGLStandard standard = ctxInfo.standard();
1221 GrGLVersion version = ctxInfo.version();
1222
bsalomon30447372015-12-21 09:03:05 -08001223 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1224 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001225 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001226 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001227 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001228 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001229
1230 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1231 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001232 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1233 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001234 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001235 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001236 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1237 if (kGL_GrGLStandard == standard) {
1238 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1239 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001240 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001241 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1242 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1243 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1244 }
egdaniel4999df82016-01-07 17:06:04 -08001245 }
bsalomoncdee0092016-01-08 13:20:12 -08001246 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001247
bsalomon76148af2016-01-12 11:13:47 -08001248 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1249 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001250 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001251 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001252 if (kGL_GrGLStandard == standard) {
1253 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1254 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1255 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1256 // Since the internal format is RGBA8, it is also renderable.
1257 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1258 allRenderFlags;
1259 }
1260 } else {
1261 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1262 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1263 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1264 // The APPLE extension doesn't make this renderable.
1265 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1266 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1267 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1268 // Though, that seems to not be the case if the texture storage extension is
1269 // present. The specs don't exactly make that clear.
1270 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1271 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1272 }
1273 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1274 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1275 ConfigInfo::kRenderable_Flag;
1276 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001277 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001278 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1279 ConfigInfo::kRenderableWithMSAA_Flag;
1280 }
1281 }
1282 }
bsalomoncdee0092016-01-08 13:20:12 -08001283 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001284
bsalomon41e4384e2016-01-08 09:12:44 -08001285 // We only enable srgb support if both textures and FBOs support srgb.
1286 bool srgbSupport = false;
1287 if (kGL_GrGLStandard == standard) {
1288 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1289 srgbSupport = true;
1290 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1291 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1292 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1293 srgbSupport = true;
1294 }
1295 }
1296 // All the above srgb extensions support toggling srgb writes
1297 fSRGBWriteControl = srgbSupport;
1298 } else {
1299 // See https://bug.skia.org/4148 for PowerVR issue.
1300 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1301 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1302 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1303 // sRGB writing for destinations.
1304 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1305 }
bsalomon30447372015-12-21 09:03:05 -08001306 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1307 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1308 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1309 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001310 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1311 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001312 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001313 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001314 if (srgbSupport) {
1315 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1316 allRenderFlags;
1317 }
bsalomoncdee0092016-01-08 13:20:12 -08001318 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001319
1320 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1321 if (this->ES2CompatibilitySupport()) {
1322 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1323 } else {
1324 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1325 }
bsalomon76148af2016-01-12 11:13:47 -08001326 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1327 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001328 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001329 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001330 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1331 if (kGL_GrGLStandard == standard) {
1332 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1333 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1334 }
1335 } else {
1336 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1337 }
bsalomoncdee0092016-01-08 13:20:12 -08001338 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001339
1340 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1341 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001342 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1343 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001344 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001345 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001346 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1347 if (kGL_GrGLStandard == standard) {
1348 if (version >= GR_GL_VER(4, 2)) {
1349 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1350 }
1351 } else {
1352 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1353 }
bsalomoncdee0092016-01-08 13:20:12 -08001354 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001355
1356 if (this->textureRedSupport()) {
1357 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1358 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001359 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1360 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001361 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001362 } else {
1363 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1364 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001365 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1366 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001367 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001368 }
1369 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001370 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001371 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1372 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1373 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1374 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1375 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1376 }
1377
1378 // Check for [half] floating point texture support
1379 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1380 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1381 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1382 bool hasFPTextures = false;
1383 bool hasHalfFPTextures = false;
1384 // for now we don't support floating point MSAA on ES
1385 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1386 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1387
1388 if (kGL_GrGLStandard == standard) {
1389 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1390 hasFPTextures = true;
1391 hasHalfFPTextures = true;
1392 }
1393 } else {
1394 if (version >= GR_GL_VER(3, 1)) {
1395 hasFPTextures = true;
1396 hasHalfFPTextures = true;
1397 } else {
1398 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1399 ctxInfo.hasExtension("GL_OES_texture_float")) {
1400 hasFPTextures = true;
1401 }
1402 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1403 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1404 hasHalfFPTextures = true;
1405 }
1406 }
1407 }
bsalomon30447372015-12-21 09:03:05 -08001408
1409 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1410 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001411 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1412 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001413 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001414 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001415 if (hasFPTextures) {
1416 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1417 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1418 // many precision issues and no clients actually want this yet.
1419 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1420 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1421 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1422 }
1423 }
bsalomoncdee0092016-01-08 13:20:12 -08001424 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001425
1426 if (this->textureRedSupport()) {
1427 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1428 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001429 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1430 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001431 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001432 } else {
1433 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1434 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001435 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1436 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001437 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001438 }
1439 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1440 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1441 } else {
1442 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1443 }
bsalomon7928ef62016-01-05 10:26:39 -08001444 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001445 if (hasHalfFPTextures) {
1446 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1447 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1448 // GL_RED internal format.
1449 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1450 (this->textureRedSupport() &&
1451 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1452 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1453 }
1454 }
bsalomon30447372015-12-21 09:03:05 -08001455
1456 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1457 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001458 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1459 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001460 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1461 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1462 } else {
1463 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1464 }
bsalomon7928ef62016-01-05 10:26:39 -08001465 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001466 if (hasHalfFPTextures) {
1467 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1468 // ES requires 3.2 or EXT_color_buffer_half_float.
1469 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1470 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1471 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1472 }
1473 }
bsalomoncdee0092016-01-08 13:20:12 -08001474 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001475
1476 // Compressed texture support
1477
1478 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1479 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1480
1481 // TODO: Fix command buffer bindings and remove this.
1482 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001483
1484 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001485 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001486
1487 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1488 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001489 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001490 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001491 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001492 // Disable this for now, while we investigate https://bug.skia.org/4333
1493 if (false) {
1494 // Check for 8-bit palette..
1495 GrGLint numFormats;
1496 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1497 if (numFormats) {
1498 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1499 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1500 for (int i = 0; i < numFormats; ++i) {
1501 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1502 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1503 break;
1504 }
1505 }
1506 }
1507 }
bsalomoncdee0092016-01-08 13:20:12 -08001508 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001509
bsalomon41e4384e2016-01-08 09:12:44 -08001510 // May change the internal format based on extensions.
1511 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1512 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1513 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1514 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1515 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1516 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1517 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1518 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1519 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1520 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1521 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1522 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1523 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1524 GR_GL_COMPRESSED_RED_RGTC1;
1525 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1526 GR_GL_COMPRESSED_RED_RGTC1;
1527 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1528 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1529 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1530 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1531 GR_GL_COMPRESSED_3DC_X;
1532
bsalomon30447372015-12-21 09:03:05 -08001533 }
bsalomon76148af2016-01-12 11:13:47 -08001534 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001535 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001536 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001537 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001538
1539 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1540 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001541 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001542 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001543 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001544 if (kGL_GrGLStandard == standard) {
1545 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1546 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1547 }
1548 } else {
1549 if (version >= GR_GL_VER(3, 0) ||
1550 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1551 // ETC2 is a superset of ETC1, so we can just check for that, too.
1552 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1553 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1554 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1555 }
1556 }
bsalomoncdee0092016-01-08 13:20:12 -08001557 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001558
1559 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1560 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001561 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001562 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001563 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001564 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1565 // decompressing the textures in the driver, and is generally slower.
1566 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1567 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1568 }
bsalomoncdee0092016-01-08 13:20:12 -08001569 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001570
1571 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1572 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1573 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1574 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001575 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1576 0;
bsalomon30447372015-12-21 09:03:05 -08001577 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001578 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001579 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1580 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1581 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1582 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1583 }
bsalomoncdee0092016-01-08 13:20:12 -08001584 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001585
1586 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1587
1588 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001589 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1590 ctxInfo.version() >= GR_GL_VER(3,0));
1591 // All ES versions (thus far) require sized internal formats for render buffers.
1592 // TODO: Always use sized internal format?
1593 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1594
bsalomon30447372015-12-21 09:03:05 -08001595 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001596 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1597 // param to glTex[Sub]Image.
1598 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1599 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1600 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1601 fConfigTable[i].fFormats.fSizedInternalFormat :
1602 fConfigTable[i].fFormats.fBaseInternalFormat;
1603 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001604 fConfigTable[i].fFormats.fSizedInternalFormat :
1605 fConfigTable[i].fFormats.fBaseInternalFormat;
1606 }
1607 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1608 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1609 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1610 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1611 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001612 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001613 GR_GL_SRGB_ALPHA;
1614 }
1615
1616 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1617 // as a base format.
1618 // GL_EXT_texture_format_BGRA8888:
1619 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1620 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1621 // formats.
1622 // GL_APPLE_texture_format_BGRA8888:
1623 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1624 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1625 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001626 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001627 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1628 }
1629
bsalomoncdee0092016-01-08 13:20:12 -08001630 // If we don't have texture swizzle support then the shader generator must insert the
1631 // swizzle into shader code.
1632 if (!this->textureSwizzleSupport()) {
1633 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1634 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1635 }
1636 }
1637
bsalomon7f9b2e42016-01-12 13:29:26 -08001638 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1639 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1640 // gets written to the single component.
1641 if (this->textureRedSupport()) {
1642 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1643 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1644 if (GrPixelConfigIsAlphaOnly(config) &&
1645 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1646 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1647 }
1648 }
1649 }
1650
bsalomon30447372015-12-21 09:03:05 -08001651#ifdef SK_DEBUG
1652 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001653 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001654 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001655 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1656 fConfigTable[i].fFormats.fBaseInternalFormat);
1657 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001658 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001659 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1660 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1661 fConfigTable[i].fFormats.fExternalFormat[j]);
1662 }
1663 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001664 }
1665#endif
1666}
1667
egdanielb7e7d572015-11-04 04:23:53 -08001668void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}