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_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_white; 42uniform layout(set=0, binding=1) sampler2D tex_sampler_black; 43void main() { 44 // Use a sampler with a white border color for the right 45 // side of the color buffer and a sampler with a black 46 // border color for the left side. 47 if (gl_FragCoord.x > 128.0) 48 color_out = texture(tex_sampler_white, texcoords_in); 49 else 50 color_out = texture(tex_sampler_black, texcoords_in); 51} 52END 53 54BUFFER texture FORMAT R8G8B8A8_UNORM 55BUFFER framebuffer FORMAT B8G8R8A8_UNORM 56 57# A sampler that generates white when texture coordinates 58# go out of range [0..1]. 59SAMPLER sampler_white \ 60 ADDRESS_MODE_U clamp_to_border \ 61 ADDRESS_MODE_V clamp_to_border \ 62 BORDER_COLOR float_opaque_white 63 64# A sampler that generates black when texture coordinates 65# go out of range [0..1]. 66SAMPLER sampler_black \ 67 ADDRESS_MODE_U clamp_to_border \ 68 ADDRESS_MODE_V clamp_to_border \ 69 BORDER_COLOR float_opaque_black 70 71BUFFER position DATA_TYPE vec2<float> DATA 72-0.75 -0.75 73 0.75 -0.75 74 0.75 0.75 75-0.75 0.75 76END 77BUFFER texcoords DATA_TYPE vec2<float> DATA 78-0.5 -0.5 79 1.5 -0.5 80 1.5 1.5 81-0.5 1.5 82END 83 84# A pipeline for generating a texture. Renders pure red. 85PIPELINE graphics texgen 86 ATTACH vert_shader 87 ATTACH frag_shader_red 88 FRAMEBUFFER_SIZE 256 256 89 BIND BUFFER texture AS color LOCATION 0 90END 91 92# A pipeline for drawing a textured quad using two samplers. 93PIPELINE graphics pipeline 94 ATTACH vert_shader_tex 95 ATTACH frag_shader_tex 96 BIND BUFFER texture AS combined_image_sampler SAMPLER sampler_white DESCRIPTOR_SET 0 BINDING 0 97 BIND BUFFER texture AS combined_image_sampler SAMPLER sampler_black DESCRIPTOR_SET 0 BINDING 1 98 VERTEX_DATA position LOCATION 0 99 VERTEX_DATA texcoords LOCATION 1 100 FRAMEBUFFER_SIZE 256 256 101 BIND BUFFER framebuffer AS color LOCATION 0 102END 103 104# Generate a texture with a blue background and red quad at the lower right corner. 105CLEAR_COLOR texgen 0 0 255 255 106CLEAR texgen 107RUN texgen DRAW_RECT POS 128 128 SIZE 128 128 108 109# Clear to green and draw the generated texture in the center of the screen leaving 110# the background color to the edges. Use texture coordinates that go past the [0..1] 111# range to show border colors. The left side of the texture is using a sampler with 112# a black border, and the right side uses a sampler with a white border. 113CLEAR_COLOR pipeline 0 255 0 255 114CLEAR pipeline 115RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4 116 117# Check for the green background. 118EXPECT framebuffer IDX 1 1 SIZE 1 1 EQ_RGBA 0 255 0 255 119# Check for the black border color. 120EXPECT framebuffer IDX 55 55 SIZE 1 1 EQ_RGBA 0 0 0 255 121# Check for the blue part of the texture. 122EXPECT framebuffer IDX 105 105 SIZE 1 1 EQ_RGBA 0 0 255 255 123# Check for the red part of the texture. 124EXPECT framebuffer IDX 150 150 SIZE 1 1 EQ_RGBA 255 0 0 255 125# Check for the white border color. 126EXPECT framebuffer IDX 200 200 SIZE 1 1 EQ_RGBA 255 255 255 255 127