• 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[2];
44uniform layout(set=0, binding=1) sampler tex_sampler;
45void main() {
46  color_out = texture(sampler2D(tex[0], tex_sampler), texcoords_in);
47  color_out += texture(sampler2D(tex[1], tex_sampler), texcoords_in);
48}
49END
50
51IMAGE texture0 FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 256 HEIGHT 256
52IMAGE texture1 FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 256 HEIGHT 256
53IMAGE framebuffer FORMAT B8G8R8A8_UNORM DIM_2D WIDTH 256 HEIGHT 256
54SAMPLER sampler
55BUFFER position DATA_TYPE vec2<float> DATA
56-0.75 -0.75
57 0.75 -0.75
58 0.75  0.75
59-0.75  0.75
60END
61BUFFER texcoords DATA_TYPE vec2<float> DATA
620.0 0.0
632.0 0.0
642.0 2.0
650.0 2.0
66END
67
68PIPELINE graphics pipeline_texgen
69  ATTACH vert_shader
70  ATTACH frag_shader_texgen
71  BIND BUFFER texture0 AS color LOCATION 0
72  BIND BUFFER texture1 AS color LOCATION 1
73END
74
75PIPELINE graphics pipeline
76  ATTACH vert_shader_tex
77  ATTACH frag_shader_tex
78  BIND BUFFER_ARRAY texture0 texture1 AS sampled_image DESCRIPTOR_SET 0 BINDING 0
79  BIND SAMPLER sampler DESCRIPTOR_SET 0 BINDING 1
80  VERTEX_DATA position LOCATION 0
81  VERTEX_DATA texcoords LOCATION 1
82  BIND BUFFER framebuffer AS color LOCATION 0
83END
84
85# Generate a texture with a quad at the lower right corner.
86CLEAR_COLOR pipeline_texgen 0 0 255 255
87CLEAR pipeline_texgen
88RUN pipeline_texgen DRAW_RECT POS 128 128 SIZE 128 128
89
90# Draw the texture using a default sampler.
91CLEAR_COLOR pipeline 0 255 0 255
92CLEAR pipeline
93RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
94
95EXPECT framebuffer IDX 1 1 SIZE 1 1 EQ_RGBA 0 255 0 255
96EXPECT framebuffer IDX 81 81 SIZE 1 1 EQ_RGBA 255 255 0 255
97EXPECT framebuffer IDX 81 33 SIZE 1 1 EQ_RGBA 0 0 255 255
98