image_source.glsl (1472B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include gpu_buffer 6 7 #define VECS_PER_IMAGE_RESOURCE 2 8 9 #ifdef WR_VERTEX_SHADER 10 11 #include rect 12 13 struct ImageSource { 14 RectWithEndpoint uv_rect; 15 vec4 user_data; 16 }; 17 18 ImageSource fetch_image_source(int address) { 19 //Note: number of blocks has to match `renderer::BLOCKS_PER_UV_RECT` 20 vec4 data[2] = fetch_from_gpu_buffer_2f(address); 21 RectWithEndpoint uv_rect = RectWithEndpoint(data[0].xy, data[0].zw); 22 return ImageSource(uv_rect, data[1]); 23 } 24 25 ImageSource fetch_image_source_direct(ivec2 address) { 26 vec4 data[2] = fetch_from_gpu_buffer_2f_direct(address); 27 RectWithEndpoint uv_rect = RectWithEndpoint(data[0].xy, data[0].zw); 28 return ImageSource(uv_rect, data[1]); 29 } 30 31 // Fetch optional extra data for a texture cache resource. This can contain 32 // a polygon defining a UV rect within the texture cache resource. 33 // Note: the polygon coordinates are in homogeneous space. 34 struct ImageSourceExtra { 35 vec4 st_tl; 36 vec4 st_tr; 37 vec4 st_bl; 38 vec4 st_br; 39 }; 40 41 ImageSourceExtra fetch_image_source_extra(int address) { 42 vec4 data[4] = fetch_from_gpu_buffer_4f(address + VECS_PER_IMAGE_RESOURCE); 43 return ImageSourceExtra( 44 data[0], 45 data[1], 46 data[2], 47 data[3] 48 ); 49 } 50 51 #endif // WR_VERTEX_SHADER