gpu/shaders: avoid first-class arrays

Safari's WebGL1 implementation (rightly) complains that first-class
array types are not supported as function result types. Define and
use a struct type instead.

While we're here, use const variables instead of functions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-04-28 14:33:27 +02:00
parent 22f964548b
commit 1062d4e79d
4 changed files with 87 additions and 95 deletions
+62 -68
View File
File diff suppressed because one or more lines are too long
+21 -20
View File
@@ -1,38 +1,39 @@
// SPDX-License-Identifier: Unlicense OR MIT
// fboTextureTransform returns a transformation
struct m3x2 {
vec3 r0;
vec3 r1;
};
// fboTextureTransform is the transformation
// that cancels the implied transformation between
// the framebuffer and its texture.
// Only two rows are returned. The last is implied
// to be [0, 0, 1].
vec3[2] fboTextureTransform() {
vec3[2] t;
const m3x2 fboTextureTransform = m3x2(
#ifdef HLSL
t[0] = vec3(1.0, 0.0, 0.0);
t[1] = vec3(0.0, -1.0, 1.0);
vec3(1.0, 0.0, 0.0),
vec3(0.0, -1.0, 1.0)
#else
t[0] = vec3(1.0, 0.0, 0.0);
t[1] = vec3(0.0, 1.0, 0.0);
vec3(1.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0)
#endif
return t;
}
);
// fboTransform returns a transformation
// fboTransform is the transformation
// that cancels the implied transformation between
// the clip space and the framebuffer.
// Only two rows are returned. The last is implied
// to be [0, 0, 1].
vec3[2] fboTransform() {
vec3[2] t;
const m3x2 fboTransform = m3x2(
#ifdef HLSL
t[0] = vec3(1.0, 0.0, 0.0);
t[1] = vec3(0.0, 1.0, 0.0);
vec3(1.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0)
#else
t[0] = vec3(1.0, 0.0, 0.0);
t[1] = vec3(0.0, -1.0, 0.0);
vec3(1.0, 0.0, 0.0),
vec3(0.0, -1.0, 0.0)
#endif
return t;
}
);
// toClipSpace converts an OpenGL gl_Position value to a
// native GPU position.
@@ -45,6 +46,6 @@ vec4 toClipSpace(vec4 pos) {
#endif
}
vec3 transform3x2(vec3[2] t, vec3 v) {
return vec3(dot(t[0], v), dot(t[1], v), dot(vec3(0.0, 0.0, 1.0), v));
vec3 transform3x2(m3x2 t, vec3 v) {
return vec3(dot(t.r0, v), dot(t.r1, v), dot(vec3(0.0, 0.0, 1.0), v));
}
+1 -2
View File
@@ -23,7 +23,6 @@ layout(location = 1) out vec2 vUV;
void main() {
gl_Position = toClipSpace(vec4(pos*transform.xy + transform.zw, z, 1));
vUV = uv*uvTransform.xy + uvTransform.zw;
vec3[2] fboTrans = fboTextureTransform();
vec3 uv3 = transform3x2(fboTrans, vec3(uv, 1.0));
vec3 uv3 = transform3x2(fboTextureTransform, vec3(uv, 1.0));
vCoverUV = (uv3*vec3(uvCoverTransform.xy, 1.0)+vec3(uvCoverTransform.zw, 0.0)).xy;
}
+3 -5
View File
@@ -17,12 +17,10 @@ layout(binding = 0) uniform Block {
layout(location = 0) out vec2 vUV;
void main() {
vec3[2] fboTrans = fboTransform();
vec3 p = transform3x2(fboTrans, vec3(pos, 1.0));
vec3 p = transform3x2(fboTransform, vec3(pos, 1.0));
gl_Position = vec4(p, 1);
vec3[2] fboTexTrans = fboTextureTransform();
vec3 uv3 = transform3x2(fboTexTrans, vec3(uv, 1.0));
vec3 uv3 = transform3x2(fboTextureTransform, vec3(uv, 1.0));
vUV = uv3.xy*subUVTransform.xy + subUVTransform.zw;
vUV = transform3x2(fboTexTrans, vec3(vUV, 1.0)).xy;
vUV = transform3x2(fboTextureTransform, vec3(vUV, 1.0)).xy;
vUV = vUV*uvTransform.xy + uvTransform.zw;
}