1#!amber
2# Copyright 2019 The Amber Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16SHADER vertex vert_shader PASSTHROUGH
17
18SHADER fragment frag_shader_red GLSL
19#version 430
20layout(location = 0) out uvec4 color_out;
21void main() {
22  color_out = uvec4(255, 0.0, 0.0, 255);
23}
24END
25
26SHADER vertex vert_shader_tex GLSL
27#version 430
28layout(location = 0) in vec4 position;
29layout(location = 1) in vec2 texcoords_in;
30layout(location = 0) out vec2 texcoords_out;
31void main() {
32  gl_Position = position;
33  texcoords_out = texcoords_in;
34}
35END
36
37SHADER fragment frag_shader_tex GLSL
38#version 430
39layout(location = 0) in vec2 texcoords_in;
40layout(location = 0) out vec4 color_out;
41uniform layout(set=0, binding=0) utexture2D tex;
42uniform layout(set=0, binding=1) sampler tex_sampler;
43void main() {
44  color_out = texture(usampler2D(tex, tex_sampler), texcoords_in);
45}
46END
47
48BUFFER texture FORMAT R8G8B8A8_UINT
49BUFFER framebuffer FORMAT B8G8R8A8_UNORM
50
51# Define samplers for all integer border colors.
52SAMPLER sampler_int_opaque_white \
53  ADDRESS_MODE_U clamp_to_border \
54  ADDRESS_MODE_V clamp_to_border \
55  BORDER_COLOR int_opaque_white
56
57SAMPLER sampler_int_opaque_black \
58  ADDRESS_MODE_U clamp_to_border \
59  ADDRESS_MODE_V clamp_to_border \
60  BORDER_COLOR int_opaque_black
61
62SAMPLER sampler_int_transparent_black \
63  ADDRESS_MODE_U clamp_to_border \
64  ADDRESS_MODE_V clamp_to_border \
65  BORDER_COLOR int_transparent_black
66
67BUFFER position DATA_TYPE vec2<float> DATA
68-1.0 -1.0
69 0.0 -1.0
70 0.0  0.0
71-1.0  0.0
72
73 0.0 -1.0
74 1.0 -1.0
75 1.0  0.0
76 0.0  0.0
77
78-1.0  0.0
79 0.0  0.0
80 0.0  1.0
81-1.0  1.0
82END
83BUFFER texcoords DATA_TYPE vec2<float> DATA
84-1.0 -1.0
85 2.0 -1.0
86 2.0  2.0
87-1.0  2.0
88
89-1.0 -1.0
90 2.0 -1.0
91 2.0  2.0
92-1.0  2.0
93
94-1.0 -1.0
95 2.0 -1.0
96 2.0  2.0
97-1.0  2.0
98END
99
100PIPELINE graphics pipeline_texgen
101  ATTACH vert_shader
102  ATTACH frag_shader_red
103  FRAMEBUFFER_SIZE 256 256
104  BIND BUFFER texture AS color LOCATION 0
105END
106
107PIPELINE graphics pipeline_int_opaque_white
108  ATTACH vert_shader_tex
109  ATTACH frag_shader_tex
110  BIND BUFFER texture AS sampled_image DESCRIPTOR_SET 0 BINDING 0
111  BIND SAMPLER sampler_int_opaque_white DESCRIPTOR_SET 0 BINDING 1
112  VERTEX_DATA position LOCATION 0
113  VERTEX_DATA texcoords LOCATION 1
114  FRAMEBUFFER_SIZE 256 256
115  BIND BUFFER framebuffer AS color LOCATION 0
116END
117
118DERIVE_PIPELINE pipeline_int_opaque_black FROM pipeline_int_opaque_white
119  BIND SAMPLER sampler_int_opaque_black DESCRIPTOR_SET 0 BINDING 1
120END
121
122DERIVE_PIPELINE pipeline_int_transparent_black FROM pipeline_int_opaque_white
123  BIND SAMPLER sampler_int_transparent_black DESCRIPTOR_SET 0 BINDING 1
124END
125
126# Generate texture: a rectangle at the lower right corner.
127CLEAR_COLOR pipeline_texgen 0 0 255 255
128CLEAR pipeline_texgen
129RUN pipeline_texgen DRAW_RECT POS 128 128 SIZE 128 128
130
131# Draw the texture with coordinates going beyond 0 and 1 to trigger border color.
132RUN pipeline_int_opaque_white DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
133RUN pipeline_int_opaque_black DRAW_ARRAY AS TRIANGLE_FAN START_IDX 4 COUNT 4
134RUN pipeline_int_transparent_black DRAW_ARRAY AS TRIANGLE_FAN START_IDX 8 COUNT 4
135
136EXPECT framebuffer IDX 1 1 SIZE 1 1 EQ_RGBA 255 255 255 255
137EXPECT framebuffer IDX 129 1 SIZE 1 1 EQ_RGBA 0 0 0 255
138EXPECT framebuffer IDX 1 129 SIZE 1 1 EQ_RGBA 0 0 0 0
139