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 vec4 color_out; 21void main() { 22 color_out = vec4(1.0, 0.0, 0.0, 1.0); 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) sampler2D tex_sampler; 42void main() { 43 color_out = texture(tex_sampler, texcoords_in); 44} 45END 46 47BUFFER texture FORMAT R8G8B8A8_UNORM 48BUFFER framebuffer FORMAT B8G8R8A8_UNORM 49SAMPLER sampler 50BUFFER position DATA_TYPE vec2<float> DATA 51-0.75 -0.75 52 0.75 -0.75 53 0.75 0.75 54-0.75 0.75 55END 56BUFFER texcoords DATA_TYPE vec2<float> DATA 570.0 0.0 582.0 0.0 592.0 2.0 600.0 2.0 61END 62 63PIPELINE graphics texgen 64 ATTACH vert_shader 65 ATTACH frag_shader_red 66 FRAMEBUFFER_SIZE 256 256 67 BIND BUFFER texture AS color LOCATION 0 68END 69 70PIPELINE graphics pipeline 71 ATTACH vert_shader_tex 72 ATTACH frag_shader_tex 73 BIND BUFFER texture AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0 74 VERTEX_DATA position LOCATION 0 75 VERTEX_DATA texcoords LOCATION 1 76 FRAMEBUFFER_SIZE 256 256 77 BIND BUFFER framebuffer AS color LOCATION 0 78END 79 80# Generate a texture with a quad at the lower right corner. 81CLEAR_COLOR texgen 0 0 255 255 82CLEAR texgen 83RUN texgen DRAW_RECT POS 128 128 SIZE 128 128 84 85# Draw the texture using a default sampler. 86CLEAR_COLOR pipeline 0 255 0 255 87CLEAR pipeline 88RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4 89 90EXPECT framebuffer IDX 1 1 SIZE 1 1 EQ_RGBA 0 255 0 255 91EXPECT framebuffer IDX 81 81 SIZE 1 1 EQ_RGBA 255 0 0 255 92EXPECT framebuffer IDX 81 33 SIZE 1 1 EQ_RGBA 0 0 255 255 93