1e5c31af7Sopenharmony_ci#!amber 2e5c31af7Sopenharmony_ci# Copyright 2019 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_mipclear PASSTHROUGH 17e5c31af7Sopenharmony_ci 18e5c31af7Sopenharmony_ciSHADER vertex vert_shader_lod GLSL 19e5c31af7Sopenharmony_ci#version 430 20e5c31af7Sopenharmony_ci 21e5c31af7Sopenharmony_cilayout(location = 0) in vec3 position_in; 22e5c31af7Sopenharmony_cilayout(location = 0) out vec4 color_out; 23e5c31af7Sopenharmony_cilayout(set = 0, binding = 0) uniform highp sampler2D tex; 24e5c31af7Sopenharmony_ci 25e5c31af7Sopenharmony_civoid main() { 26e5c31af7Sopenharmony_ci gl_Position = vec4(position_in, 1.0); 27e5c31af7Sopenharmony_ci // Pick a color from the center of a mipmap. Each corner point gets its own mip level. 28e5c31af7Sopenharmony_ci color_out = vec4(textureLod(tex, vec2(0.5), float(gl_VertexIndex % 4))); 29e5c31af7Sopenharmony_ci} 30e5c31af7Sopenharmony_ciEND 31e5c31af7Sopenharmony_ci 32e5c31af7Sopenharmony_ciSHADER fragment frag_shader GLSL 33e5c31af7Sopenharmony_ci#version 430 34e5c31af7Sopenharmony_ci 35e5c31af7Sopenharmony_cilayout(location = 0) in vec4 color_in; 36e5c31af7Sopenharmony_cilayout(location = 0) out vec4 color_out; 37e5c31af7Sopenharmony_ci 38e5c31af7Sopenharmony_civoid main() { 39e5c31af7Sopenharmony_ci color_out = color_in; 40e5c31af7Sopenharmony_ci} 41e5c31af7Sopenharmony_ciEND 42e5c31af7Sopenharmony_ci 43e5c31af7Sopenharmony_ciBUFFER texture FORMAT B8G8R8A8_UNORM MIP_LEVELS 4 44e5c31af7Sopenharmony_ciBUFFER framebuffer FORMAT B8G8R8A8_UNORM 45e5c31af7Sopenharmony_ciSAMPLER sampler MAX_LOD 4.0 46e5c31af7Sopenharmony_ci 47e5c31af7Sopenharmony_ciPIPELINE graphics mipclear_pipeline0 48e5c31af7Sopenharmony_ci ATTACH vert_shader_mipclear 49e5c31af7Sopenharmony_ci ATTACH frag_shader 50e5c31af7Sopenharmony_ci BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 0 51e5c31af7Sopenharmony_ci FRAMEBUFFER_SIZE 512 512 52e5c31af7Sopenharmony_ciEND 53e5c31af7Sopenharmony_ci 54e5c31af7Sopenharmony_ciPIPELINE graphics mipclear_pipeline1 55e5c31af7Sopenharmony_ci ATTACH vert_shader_mipclear 56e5c31af7Sopenharmony_ci ATTACH frag_shader 57e5c31af7Sopenharmony_ci BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 1 58e5c31af7Sopenharmony_ci FRAMEBUFFER_SIZE 256 256 59e5c31af7Sopenharmony_ciEND 60e5c31af7Sopenharmony_ci 61e5c31af7Sopenharmony_ciPIPELINE graphics mipclear_pipeline2 62e5c31af7Sopenharmony_ci ATTACH vert_shader_mipclear 63e5c31af7Sopenharmony_ci ATTACH frag_shader 64e5c31af7Sopenharmony_ci BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 2 65e5c31af7Sopenharmony_ci FRAMEBUFFER_SIZE 128 128 66e5c31af7Sopenharmony_ciEND 67e5c31af7Sopenharmony_ci 68e5c31af7Sopenharmony_ciPIPELINE graphics mipclear_pipeline3 69e5c31af7Sopenharmony_ci ATTACH vert_shader_mipclear 70e5c31af7Sopenharmony_ci ATTACH frag_shader 71e5c31af7Sopenharmony_ci BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 3 72e5c31af7Sopenharmony_ci FRAMEBUFFER_SIZE 64 64 73e5c31af7Sopenharmony_ciEND 74e5c31af7Sopenharmony_ci 75e5c31af7Sopenharmony_ciPIPELINE graphics lod_pipeline 76e5c31af7Sopenharmony_ci ATTACH vert_shader_lod 77e5c31af7Sopenharmony_ci ATTACH frag_shader 78e5c31af7Sopenharmony_ci BIND BUFFER texture AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0 79e5c31af7Sopenharmony_ci BIND BUFFER framebuffer AS color LOCATION 0 80e5c31af7Sopenharmony_ci FRAMEBUFFER_SIZE 512 512 81e5c31af7Sopenharmony_ciEND 82e5c31af7Sopenharmony_ci 83e5c31af7Sopenharmony_ci# Clear all mip levels to different color. 84e5c31af7Sopenharmony_ciCLEAR_COLOR mipclear_pipeline0 255 0 0 255 85e5c31af7Sopenharmony_ciCLEAR mipclear_pipeline0 86e5c31af7Sopenharmony_ciCLEAR_COLOR mipclear_pipeline1 0 255 0 255 87e5c31af7Sopenharmony_ciCLEAR mipclear_pipeline1 88e5c31af7Sopenharmony_ciCLEAR_COLOR mipclear_pipeline2 0 0 255 255 89e5c31af7Sopenharmony_ciCLEAR mipclear_pipeline2 90e5c31af7Sopenharmony_ciCLEAR_COLOR mipclear_pipeline3 255 255 0 255 91e5c31af7Sopenharmony_ciCLEAR mipclear_pipeline3 92e5c31af7Sopenharmony_ci 93e5c31af7Sopenharmony_ciCLEAR_COLOR lod_pipeline 0 0 0 255 94e5c31af7Sopenharmony_ciCLEAR lod_pipeline 95e5c31af7Sopenharmony_ciRUN lod_pipeline DRAW_RECT POS 0 0 SIZE 512 512 96e5c31af7Sopenharmony_ci 97e5c31af7Sopenharmony_ci# Check corners of the frame buffer: each should have a color from a different mip level. 98e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 0 511 SIZE 1 1 EQ_RGBA 255 0 0 255 99e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 511 0 SIZE 1 1 EQ_RGBA 255 255 0 255 100e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 511 511 SIZE 1 1 EQ_RGBA 0 0 255 255 101e5c31af7Sopenharmony_ciEXPECT framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 0 255 0 255 102