• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2# Copyright 2020 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_texgen GLSL
19#version 430
20layout(location = 0) out vec4 color_out0;
21layout(location = 1) out vec4 color_out1;
22void main() {
23  color_out0 = vec4(1.0, 0.0, 0.0, 1.0);
24  color_out1 = vec4(0.0, 1.0, 0.0, 1.0);
25}
26END
27
28SHADER vertex vert_shader_tex GLSL
29#version 430
30layout(location = 0) in vec4 position;
31layout(location = 1) in vec2 texcoords_in;
32layout(location = 0) out vec2 texcoords_out;
33void main() {
34  gl_Position = position;
35  texcoords_out = texcoords_in;
36}
37END
38
39SHADER fragment frag_shader_tex GLSL
40#version 430
41layout(location = 0) in vec2 texcoords_in;
42layout(location = 0) out vec4 color_out;
43uniform layout(set=0, binding=0) texture2D tex_0[2];
44uniform layout(set=0, binding=1) sampler tex_sampler;
45uniform layout(set=0, binding=2) texture2D tex_1[2];
46void main() {
47  vec4 tex_0_color = texture(sampler2D(tex_0[0], tex_sampler), texcoords_in);
48  color_out = tex_0_color;
49  color_out += texture(sampler2D(tex_0[1], tex_sampler), texcoords_in);
50  // tex_1[0] and tex_1[1] should be equal to tex_0[0].
51  if (tex_0_color != texture(sampler2D(tex_1[0], tex_sampler), texcoords_in) ||
52      tex_0_color != texture(sampler2D(tex_1[1], tex_sampler), texcoords_in)) {
53      color_out = vec4(1.0);
54  }
55}
56END
57
58IMAGE texture0 FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 256 HEIGHT 256
59IMAGE texture1 FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 256 HEIGHT 256
60IMAGE framebuffer FORMAT B8G8R8A8_UNORM DIM_2D WIDTH 256 HEIGHT 256
61SAMPLER sampler
62BUFFER position DATA_TYPE vec2<float> DATA
63-0.75 -0.75
64 0.75 -0.75
65 0.75  0.75
66-0.75  0.75
67END
68BUFFER texcoords DATA_TYPE vec2<float> DATA
690.0 0.0
702.0 0.0
712.0 2.0
720.0 2.0
73END
74
75PIPELINE graphics pipeline_texgen
76  ATTACH vert_shader
77  ATTACH frag_shader_texgen
78  BIND BUFFER texture0 AS color LOCATION 0
79  BIND BUFFER texture1 AS color LOCATION 1
80END
81
82PIPELINE graphics pipeline
83  ATTACH vert_shader_tex
84  ATTACH frag_shader_tex
85  BIND BUFFER_ARRAY texture0 texture1 AS sampled_image DESCRIPTOR_SET 0 BINDING 0
86  BIND SAMPLER sampler DESCRIPTOR_SET 0 BINDING 1
87  BIND BUFFER_ARRAY texture0 texture0 AS sampled_image DESCRIPTOR_SET 0 BINDING 2
88  VERTEX_DATA position LOCATION 0
89  VERTEX_DATA texcoords LOCATION 1
90  BIND BUFFER framebuffer AS color LOCATION 0
91END
92
93# Generate a texture with a quad at the lower right corner.
94CLEAR_COLOR pipeline_texgen 0 0 255 255
95CLEAR pipeline_texgen
96RUN pipeline_texgen DRAW_RECT POS 128 128 SIZE 128 128
97
98# Draw the texture using a default sampler.
99CLEAR_COLOR pipeline 0 255 0 255
100CLEAR pipeline
101RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
102
103EXPECT framebuffer IDX 1 1 SIZE 1 1 EQ_RGBA 0 255 0 255
104EXPECT framebuffer IDX 81 81 SIZE 1 1 EQ_RGBA 255 255 0 255
105EXPECT framebuffer IDX 81 33 SIZE 1 1 EQ_RGBA 0 0 255 255
106