summaryrefslogtreecommitdiff
path: root/tests/spec/arb_tessellation_shader/execution/quads.shader_test
blob: d2ba7839e2cccc8d630ce595c76a666d7485cc14 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# What it covers:
# * tessellation of quads
# * different number of input (pre-TCS) and output (post-TCS) control points
# * all inputs are read in each shader
# * gl_PatchVerticesIn in TCS and TES
#
# How it works:
# * There is a patch with 4 control points on the input (quad).
# * The TCS subdivides the patch into 9 control points (4 tiles in a 2x2 pattern).
# * A color is assigned to each tile, which is held in the upper-left corner
#   of the tile.
# * The 2x2 pattern is still a single quad from the tessellator point of view.
# * The tessellator should create 21*21 quads (21*21*2 triangles).
# * The quad should be tessellated such that you can clearly see 4 tiles that
#   have different colors. The triangles in the middle should smoothly blend
#   colors from both tiles (caused by interpolation of varyings).
#

[require]
GLSL >= 1.50
GL_ARB_tessellation_shader

[vertex shader]
#version 150
in vec4 vertex;

void main()
{
	gl_Position = vec4(vertex.xy, 0, 1);
}

[tessellation control shader]
#version 150
#extension GL_ARB_tessellation_shader : require

layout(vertices = 9) out;

out vec4 color[];
out vec4 pos[];

void main()
{
	float t = 21;
	gl_TessLevelInner[0] = t;
	gl_TessLevelInner[1] = t;

	gl_TessLevelOuter[0] = t;
	gl_TessLevelOuter[1] = t;
	gl_TessLevelOuter[2] = t;
	gl_TessLevelOuter[3] = t;

	float x = float(gl_InvocationID % 3) / 2;
	float y = float(gl_InvocationID / 3) / 2;

	vec4 x1 = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, x);
	vec4 x2 = mix(gl_in[2].gl_Position, gl_in[3].gl_Position, x);

	pos[gl_InvocationID] = mix(x1, x2, y);
	color[gl_InvocationID] = gl_PatchVerticesIn == 4 ? vec4(x, y, 0, 1) : vec4(0);
}

[tessellation evaluation shader]
#version 150
#extension GL_ARB_tessellation_shader : require

layout(quads, equal_spacing) in;

in vec4 pos[];
in vec4 color[];
out vec4 fs_color;

void main()
{
	float x = gl_TessCoord.x;
	float y = gl_TessCoord.y;
	vec4 vx[3], cx[3], v, c;

	for (int i = 0; i < 3; i++) {
		if (x <= 0.5) {
		    vx[i] = mix(pos[i*3], pos[i*3+1], x*2);
		    cx[i] = color[i*3];
		} else {
		    vx[i] = mix(pos[i*3+1], pos[i*3+2], (x-0.5)*2);
		    cx[i] = color[i*3+1];
		}
	}

	if (y <= 0.5) {
		v = mix(vx[0], vx[1], y*2);
		c = cx[0];
	} else {
		v = mix(vx[1], vx[2], (y-0.5)*2);
		c = cx[1];
	}

	gl_Position = v;
	fs_color = gl_PatchVerticesIn == 9 ? c : vec4(0);
}

[fragment shader]
#version 150

in vec4 fs_color;

void main()
{
	gl_FragColor = fs_color;
}

[vertex data]
vertex/float/2
-1.0 -1.0
 1.0 -1.0
-1.0  1.0
 1.0  1.0

[test]
clear color 0.1 0.1 0.1 0.1
clear
patch parameter vertices 4
draw arrays GL_PATCHES 0 4
relative probe rect rgb (0.0  , 0.0  , 0.476, 0.476) (0.0, 0.0, 0.0)
relative probe rect rgb (0.524, 0.0  , 0.476, 0.476) (0.5, 0.0, 0.0)
relative probe rect rgb (0.0  , 0.524, 0.476, 0.476) (0.0, 0.5, 0.0)
relative probe rect rgb (0.524, 0.524, 0.476, 0.476) (0.5, 0.5, 0.0)