aboutsummaryrefslogtreecommitdiff
path: root/vendor/gioui.org/shader/gio/stencil.vert
blob: fd6f28b37cc3a4972f66ee4553ce8ff651f99356 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#version 310 es

// SPDX-License-Identifier: Unlicense OR MIT

#extension GL_GOOGLE_include_directive : enable

precision highp float;

#include "common.h"

layout(push_constant) uniform Block {
	vec4 transform;
	vec2 pathOffset;
} _block;

layout(location=0) in float corner;
layout(location=1) in float maxy;
layout(location=2) in vec2 from;
layout(location=3) in vec2 ctrl;
layout(location=4) in vec2 to;

layout(location=0) out vec2 vFrom;
layout(location=1) out vec2 vCtrl;
layout(location=2) out vec2 vTo;

void main() {
	// Add a one pixel overlap so curve quads cover their
	// entire curves. Could use conservative rasterization
	// if available.
	vec2 from = from + _block.pathOffset;
	vec2 ctrl = ctrl + _block.pathOffset;
	vec2 to = to + _block.pathOffset;
	float maxy = maxy + _block.pathOffset.y;
	vec2 pos;
	float c = corner;
	if (c >= 0.375) {
		// North.
		c -= 0.5;
		pos.y = maxy + 1.0;
	} else {
		// South.
		pos.y = min(min(from.y, ctrl.y), to.y) - 1.0;
	}
	if (c >= 0.125) {
		// East.
		pos.x = max(max(from.x, ctrl.x), to.x)+1.0;
	} else {
		// West.
		pos.x = min(min(from.x, ctrl.x), to.x)-1.0;
	}
	vFrom = from-pos;
	vCtrl = ctrl-pos;
	vTo = to-pos;
	pos = pos*_block.transform.xy + _block.transform.zw;
	gl_Position = vec4(transform3x2(fboTransform, vec3(pos, 0)), 1);
}