1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // This shader must remain compatible with ESSL 1, at least for the
6 // WR_FEATURE_TEXTURE_EXTERNAL_ESSL1 feature, so that it can be used to render
7 // video on GLES devices without GL_OES_EGL_image_external_essl3 support.
8 // This means we cannot use textureSize(), int inputs/outputs, etc.
12 varying highp vec2 vUv;
13 flat varying highp vec4 vUvRect;
14 #ifdef WR_FEATURE_TEXTURE_EXTERNAL_ESSL1
15 uniform vec2 uTextureSize;
18 #ifdef WR_VERTEX_SHADER
20 PER_INSTANCE attribute vec4 aScaleTargetRect;
21 PER_INSTANCE attribute vec4 aScaleSourceRect;
24 vec2 src_offset = aScaleSourceRect.xy;
25 vec2 src_size = aScaleSourceRect.zw - aScaleSourceRect.xy;
27 // If this is in WR_FEATURE_TEXTURE_RECT mode, the rect and size use
28 // non-normalized texture coordinates.
29 #ifdef WR_FEATURE_TEXTURE_RECT
30 vec2 texture_size = vec2(1, 1);
31 #elif defined(WR_FEATURE_TEXTURE_EXTERNAL_ESSL1)
32 vec2 texture_size = uTextureSize;
34 vec2 texture_size = vec2(TEX_SIZE(sColor0));
37 // The uvs may be inverted, so use the min and max for the bounds
38 vUvRect = vec4(min(aScaleSourceRect.xy, aScaleSourceRect.zw) + vec2(0.5),
39 max(aScaleSourceRect.xy, aScaleSourceRect.zw) - vec2(0.5)) / texture_size.xyxy;
41 vec2 pos = mix(aScaleTargetRect.xy, aScaleTargetRect.zw, aPosition.xy);
42 vUv = (src_offset + src_size * aPosition.xy) / texture_size;
44 gl_Position = uTransform * vec4(pos, 0.0, 1.0);
49 #ifdef WR_FRAGMENT_SHADER
52 vec2 st = clamp(vUv, vUvRect.xy, vUvRect.zw);
53 oFragColor = TEX_SAMPLE(sColor0, st);
57 void swgl_drawSpanRGBA8() {
58 swgl_commitTextureLinearRGBA8(sColor0, vUv, vUvRect);