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) texture2D tex; 42uniform layout(set=0, binding=1) sampler tex_sampler; 43void main() { 44 color_out = texture(sampler2D(tex, tex_sampler), texcoords_in); 45} 46END 47 48BUFFER texture_small FORMAT B8G8R8A8_UNORM 49BUFFER texture FORMAT B8G8R8A8_UNORM 50BUFFER framebuffer_linear FORMAT B8G8R8A8_UNORM 51BUFFER framebuffer_nearest FORMAT B8G8R8A8_UNORM 52SAMPLER sampler_linear MIN_FILTER linear MAG_FILTER nearest 53SAMPLER sampler_nearest MIN_FILTER nearest MAG_FILTER nearest 54BUFFER position DATA_TYPE vec2<float> DATA 55-1.0 -1.0 56 1.0 -1.0 57 1.0 1.0 58-1.0 1.0 59END 60BUFFER texcoords DATA_TYPE vec2<float> DATA 61 0.0 0.0 6216.0 0.0 6316.0 16.0 64 0.0 16.0 65END 66 67PIPELINE graphics pipeline_red 68 ATTACH vert_shader 69 ATTACH frag_shader_red 70 FRAMEBUFFER_SIZE 2 2 71 BIND BUFFER texture_small AS color LOCATION 0 72END 73 74PIPELINE graphics pipeline_tex_repeat 75 ATTACH vert_shader_tex 76 ATTACH frag_shader_tex 77 BIND BUFFER texture_small AS sampled_image DESCRIPTOR_SET 0 BINDING 0 78 BIND SAMPLER sampler_nearest DESCRIPTOR_SET 0 BINDING 1 79 VERTEX_DATA position LOCATION 0 80 VERTEX_DATA texcoords LOCATION 1 81 FRAMEBUFFER_SIZE 256 256 82 BIND BUFFER texture AS color LOCATION 0 83END 84 85PIPELINE graphics pipeline_linear 86 ATTACH vert_shader_tex 87 ATTACH frag_shader_tex 88 BIND BUFFER texture AS sampled_image DESCRIPTOR_SET 0 BINDING 0 89 BIND SAMPLER sampler_linear DESCRIPTOR_SET 0 BINDING 1 90 VERTEX_DATA position LOCATION 0 91 VERTEX_DATA texcoords LOCATION 1 92 FRAMEBUFFER_SIZE 256 256 93 BIND BUFFER framebuffer_linear AS color LOCATION 0 94END 95 96PIPELINE graphics pipeline_nearest 97 ATTACH vert_shader_tex 98 ATTACH frag_shader_tex 99 BIND BUFFER texture AS sampled_image DESCRIPTOR_SET 0 BINDING 0 100 BIND SAMPLER sampler_nearest DESCRIPTOR_SET 0 BINDING 1 101 VERTEX_DATA position LOCATION 0 102 VERTEX_DATA texcoords LOCATION 1 103 FRAMEBUFFER_SIZE 256 256 104 BIND BUFFER framebuffer_nearest AS color LOCATION 0 105END 106 107# Generate 2x2 pattern. 108CLEAR_COLOR pipeline_red 0 0 255 255 109CLEAR pipeline_red 110RUN pipeline_red DRAW_RECT POS 0 0 SIZE 1 1 111RUN pipeline_red DRAW_RECT POS 1 1 SIZE 1 1 112 113# Make the pattern repeat into 256x256 texture 114RUN pipeline_tex_repeat DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4 115 116# Draw the repeated texture into a quad and again repeat 16 times 117# to make it smaller. Do this with both nearest and linear filter mode. 118CLEAR_COLOR pipeline_linear 0 255 0 255 119CLEAR pipeline_linear 120RUN pipeline_linear DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4 121CLEAR_COLOR pipeline_nearest 0 255 0 255 122CLEAR pipeline_nearest 123RUN pipeline_nearest DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4 124 125# Linear and nearest filtering produce different results so this should fail. 126EXPECT framebuffer_nearest EQ_BUFFER framebuffer_linear 127