1e5c31af7Sopenharmony_ci#!amber 2e5c31af7Sopenharmony_ci# Copyright 2020 The Amber Authors. 3e5c31af7Sopenharmony_ci# 4e5c31af7Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 5e5c31af7Sopenharmony_ci# you may not use this file except in compliance with the License. 6e5c31af7Sopenharmony_ci# You may obtain a copy of the License at 7e5c31af7Sopenharmony_ci# 8e5c31af7Sopenharmony_ci# https://www.apache.org/licenses/LICENSE-2.0 9e5c31af7Sopenharmony_ci# 10e5c31af7Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 11e5c31af7Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 12e5c31af7Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e5c31af7Sopenharmony_ci# See the License for the specific language governing permissions and 14e5c31af7Sopenharmony_ci# limitations under the License. 15e5c31af7Sopenharmony_ci 16e5c31af7Sopenharmony_ciSHADER vertex vert_shader PASSTHROUGH 17e5c31af7Sopenharmony_ci 18e5c31af7Sopenharmony_ciSHADER fragment frag_shader_red GLSL 19e5c31af7Sopenharmony_ci#version 430 20e5c31af7Sopenharmony_cilayout(location = 0) out vec4 color_out; 21e5c31af7Sopenharmony_civoid main() { 22e5c31af7Sopenharmony_ci color_out = vec4(1.0, 0.0, 0.0, 1.0); 23e5c31af7Sopenharmony_ci} 24e5c31af7Sopenharmony_ciEND 25e5c31af7Sopenharmony_ci 26e5c31af7Sopenharmony_ciSHADER vertex vert_shader_tex GLSL 27e5c31af7Sopenharmony_ci#version 430 28e5c31af7Sopenharmony_cilayout(location = 0) in vec4 position; 29e5c31af7Sopenharmony_cilayout(location = 1) in vec2 texcoords_in; 30e5c31af7Sopenharmony_cilayout(location = 0) out vec2 texcoords_out; 31e5c31af7Sopenharmony_civoid main() { 32e5c31af7Sopenharmony_ci gl_Position = position; 33e5c31af7Sopenharmony_ci texcoords_out = texcoords_in; 34e5c31af7Sopenharmony_ci} 35e5c31af7Sopenharmony_ciEND 36e5c31af7Sopenharmony_ci 37e5c31af7Sopenharmony_ciSHADER fragment frag_shader_tex GLSL 38e5c31af7Sopenharmony_ci#version 430 39e5c31af7Sopenharmony_cilayout(location = 0) in vec2 texcoords_in; 40e5c31af7Sopenharmony_cilayout(location = 0) out vec4 color_out; 41e5c31af7Sopenharmony_ciuniform layout(set=0, binding=0) sampler2D tex_sampler_white; 42e5c31af7Sopenharmony_ciuniform layout(set=0, binding=1) sampler2D tex_sampler_black; 43e5c31af7Sopenharmony_civoid main() { 44e5c31af7Sopenharmony_ci // Use a sampler with a white border color for the right 45e5c31af7Sopenharmony_ci // side of the color buffer and a sampler with a black 46e5c31af7Sopenharmony_ci // border color for the left side. 47e5c31af7Sopenharmony_ci if (gl_FragCoord.x > 128.0) 48e5c31af7Sopenharmony_ci color_out = texture(tex_sampler_white, texcoords_in); 49e5c31af7Sopenharmony_ci else 50e5c31af7Sopenharmony_ci color_out = texture(tex_sampler_black, texcoords_in); 51e5c31af7Sopenharmony_ci} 52e5c31af7Sopenharmony_ciEND 53e5c31af7Sopenharmony_ci 54e5c31af7Sopenharmony_ciBUFFER texture FORMAT R8G8B8A8_UNORM 55e5c31af7Sopenharmony_ciBUFFER framebuffer FORMAT B8G8R8A8_UNORM 56e5c31af7Sopenharmony_ci 57e5c31af7Sopenharmony_ci# A sampler that generates white when texture coordinates 58e5c31af7Sopenharmony_ci# go out of range [0..1]. 59e5c31af7Sopenharmony_ciSAMPLER sampler_white \ 60e5c31af7Sopenharmony_ci ADDRESS_MODE_U clamp_to_border \ 61e5c31af7Sopenharmony_ci ADDRESS_MODE_V clamp_to_border \ 62e5c31af7Sopenharmony_ci BORDER_COLOR float_opaque_white 63e5c31af7Sopenharmony_ci 64e5c31af7Sopenharmony_ci# A sampler that generates black when texture coordinates 65e5c31af7Sopenharmony_ci# go out of range [0..1]. 66e5c31af7Sopenharmony_ciSAMPLER sampler_black \ 67e5c31af7Sopenharmony_ci ADDRESS_MODE_U clamp_to_border \ 68e5c31af7Sopenharmony_ci ADDRESS_MODE_V clamp_to_border \ 69e5c31af7Sopenharmony_ci BORDER_COLOR float_opaque_black 70e5c31af7Sopenharmony_ci 71e5c31af7Sopenharmony_ciBUFFER position DATA_TYPE vec2<float> DATA 72e5c31af7Sopenharmony_ci-0.75 -0.75 73e5c31af7Sopenharmony_ci 0.75 -0.75 74e5c31af7Sopenharmony_ci 0.75 0.75 75e5c31af7Sopenharmony_ci-0.75 0.75 76e5c31af7Sopenharmony_ciEND 77e5c31af7Sopenharmony_ciBUFFER texcoords DATA_TYPE vec2<float> DATA 78e5c31af7Sopenharmony_ci-0.5 -0.5 79e5c31af7Sopenharmony_ci 1.5 -0.5 80e5c31af7Sopenharmony_ci 1.5 1.5 81e5c31af7Sopenharmony_ci-0.5 1.5 82e5c31af7Sopenharmony_ciEND 83e5c31af7Sopenharmony_ci 84e5c31af7Sopenharmony_ci# A pipeline for generating a texture. Renders pure red. 85e5c31af7Sopenharmony_ciPIPELINE graphics texgen 86e5c31af7Sopenharmony_ci ATTACH vert_shader 87e5c31af7Sopenharmony_ci ATTACH frag_shader_red 88e5c31af7Sopenharmony_ci FRAMEBUFFER_SIZE 256 256 89e5c31af7Sopenharmony_ci BIND BUFFER texture AS color LOCATION 0 90e5c31af7Sopenharmony_ciEND 91e5c31af7Sopenharmony_ci 92e5c31af7Sopenharmony_ci# A pipeline for drawing a textured quad using two samplers. 93e5c31af7Sopenharmony_ciPIPELINE graphics pipeline 94e5c31af7Sopenharmony_ci ATTACH vert_shader_tex 95e5c31af7Sopenharmony_ci ATTACH frag_shader_tex 96e5c31af7Sopenharmony_ci BIND BUFFER texture AS combined_image_sampler SAMPLER sampler_white DESCRIPTOR_SET 0 BINDING 0 97e5c31af7Sopenharmony_ci BIND BUFFER texture AS combined_image_sampler SAMPLER sampler_black DESCRIPTOR_SET 0 BINDING 1 98e5c31af7Sopenharmony_ci VERTEX_DATA position LOCATION 0 99e5c31af7Sopenharmony_ci VERTEX_DATA texcoords LOCATION 1 100e5c31af7Sopenharmony_ci FRAMEBUFFER_SIZE 256 256 101e5c31af7Sopenharmony_ci BIND BUFFER framebuffer AS color LOCATION 0 102e5c31af7Sopenharmony_ciEND 103e5c31af7Sopenharmony_ci 104e5c31af7Sopenharmony_ci# Generate a texture with a blue background and red quad at the lower right corner. 105e5c31af7Sopenharmony_ciCLEAR_COLOR texgen 0 0 255 255 106e5c31af7Sopenharmony_ciCLEAR texgen 107e5c31af7Sopenharmony_ciRUN texgen DRAW_RECT POS 128 128 SIZE 128 128 108e5c31af7Sopenharmony_ci 109e5c31af7Sopenharmony_ci# Clear to green and draw the generated texture in the center of the screen leaving 110e5c31af7Sopenharmony_ci# the background color to the edges. Use texture coordinates that go past the [0..1] 111e5c31af7Sopenharmony_ci# range to show border colors. The left side of the texture is using a sampler with 112e5c31af7Sopenharmony_ci# a black border, and the right side uses a sampler with a white border. 113e5c31af7Sopenharmony_ciCLEAR_COLOR pipeline 0 255 0 255 114e5c31af7Sopenharmony_ciCLEAR pipeline 115e5c31af7Sopenharmony_ciRUN pipeline DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4 116e5c31af7Sopenharmony_ci 117e5c31af7Sopenharmony_ci# Check for the green background. 118e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 1 1 SIZE 1 1 EQ_RGBA 0 255 0 255 119e5c31af7Sopenharmony_ci# Check for the black border color. 120e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 55 55 SIZE 1 1 EQ_RGBA 0 0 0 255 121e5c31af7Sopenharmony_ci# Check for the blue part of the texture. 122e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 105 105 SIZE 1 1 EQ_RGBA 0 0 255 255 123e5c31af7Sopenharmony_ci# Check for the red part of the texture. 124e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 150 150 SIZE 1 1 EQ_RGBA 255 0 0 255 125e5c31af7Sopenharmony_ci# Check for the white border color. 126e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 200 200 SIZE 1 1 EQ_RGBA 255 255 255 255 127