23 #ifndef FASTUIDRAW_IMAGE_ATLAS_DISABLED 33 #define FASTUIDRAW_IMAGE_ATLAS_DISABLED 40 #define FASTUIDRAW_IMAGE_ATLAS_COLOR_TILE_SIZE 47 #define FASTUIDRAW_IMAGE_ATLAS_COLOR_TILE_RECIP_SIZE 53 #define FASTUIDRAW_IMAGE_ATLAS_COLOR_TILE_LOG2_SIZE 60 #define FASTUIDRAW_IMAGE_ATLAS_INDEX_TILE_SIZE 66 #define FASTUIDRAW_IMAGE_ATLAS_INDEX_TILE_RECIP_SIZE 72 #define FASTUIDRAW_IMAGE_ATLAS_INDEX_TILE_LOG2_SIZE 200 if (num_levels >= 1u)
221 float index_pows = float(1u << ww);
224 d.image_texel_size_on_master_index_tile = 1.0 / d.recip_image_texel_size_on_master_index_tile;
228 d.image_texel_size_on_master_index_tile = 1.0;
229 d.recip_image_texel_size_on_master_index_tile = 1.0;
254 relative = master_tile_tex_coord
260 return relative * image_info.recip_image_texel_size_on_master_index_tile;
275 out
float tile_min_dist,
276 out
float tile_max_dist)
280 tile_coord = root_image_coordinate
283 tile_min_dist = -tile_coord;
300 out
vec2 tile_min_dist,
301 out
vec2 tile_max_dist)
319 return_value = (master_tile_tex_coord - image_info.master_index_tile_bottom_left)
320 * image_info.base.recip_image_texel_size_on_master_index_tile;
337 return_value = image_coordinate * image_info.base.image_texel_size_on_master_index_tile
338 + image_info.master_index_tile_bottom_left;
353 return clamp(image_coordinate,
vec2(0.0), image_info.image_size);
368 return clamp(image_coordinate,
369 vec2(0.5 * pow2_lod),
370 image_info.image_size -
vec2(0.5 * pow2_lod));
383 return clamp(image_coordinate,
385 image_info.image_size -
vec2(2.0));
393 struct fastuidraw_compute_image_atlas_coord_helper_type
395 vec2 master_tile_texel_coord;
401 fastuidraw_compute_image_atlas_coord_helper_init(in
vec2 master_tile_texel_coord,
403 out fastuidraw_compute_image_atlas_coord_helper_type v)
405 v.master_tile_texel_coord = master_tile_texel_coord;
406 v.index_layer = index_layer;
408 ivec3(v.master_tile_texel_coord, v.index_layer),
410 v.index_layer = v.tile_id.z + 256u * v.tile_id.w;
414 fastuidraw_compute_image_atlas_coord_helper_iterate(inout fastuidraw_compute_image_atlas_coord_helper_type v)
416 vec2 index_tile_offset;
417 vec2 texel_coordinate;
419 v.master_tile_texel_coord -= floor(v.master_tile_texel_coord);
421 texel_coordinate = index_tile_offset
425 ivec3(texel_coordinate, v.index_layer),
427 v.index_layer = v.tile_id.z + 256u * v.tile_id.w;
428 v.master_tile_texel_coord = texel_coordinate;
432 fastuidraw_compute_image_atlas_coord_helper_fini(in fastuidraw_compute_image_atlas_coord_helper_type v,
440 uint subtile_image_size;
443 tile_offset = (v.master_tile_texel_coord - floor(v.master_tile_texel_coord)) *
float(subtile_image_size);
445 return_value.unnormalized_texcoord_xy = tile_offset
448 return_value.max_delta_within_tile =
451 return_value.layer = v.index_layer;
469 fastuidraw_compute_image_atlas_coord_helper_type v;
471 fastuidraw_compute_image_atlas_coord_helper_init(master_tile_texel_coord, index_layer, v);
474 fastuidraw_compute_image_atlas_coord_helper_iterate(v);
476 fastuidraw_compute_image_atlas_coord_helper_fini(v, return_value);
491 vec2 master_tile_texel_coord;
495 image_info.master_index_tile_layer,
496 image_info.base.num_levels,
502 fastuidraw_atlas_image_gather(in
int lod_i,
504 in
float inverse_lod_factor,
505 in
vec2 master_tile_texel_coord,
513 ivec3 t00, t10, t01, t11;
514 float next_pixel_delta, half_next_pixel_delta;
517 next_pixel_delta = lod_factor * image_info.image_texel_size_on_master_index_tile;
518 half_next_pixel_delta = 0.5 * next_pixel_delta;
523 delta = -
vec2(half_next_pixel_delta);
526 image_info.num_levels,
527 output_value.atlas_location_t00);
529 t00 =
ivec3(output_value.atlas_location_t00.unnormalized_texcoord_xy * inverse_lod_factor,
530 output_value.atlas_location_t00.layer);
531 if (output_value.atlas_location_t00.max_delta_within_tile.x >= lod_factor)
540 vec2 master_tile_texel_coord_nxt;
542 delta_nxt =
vec2(half_next_pixel_delta, -half_next_pixel_delta);
543 master_tile_texel_coord_nxt = master_tile_texel_coord + delta_nxt;
545 image_info.num_levels, atlas_location_t10);
547 atlas_location_t10.
layer);
550 if (output_value.atlas_location_t00.max_delta_within_tile.y >= lod_factor)
562 vec2 master_tile_texel_coord_nxt;
564 delta_nxt =
vec2(-half_next_pixel_delta, half_next_pixel_delta);
565 master_tile_texel_coord_nxt = master_tile_texel_coord + delta_nxt;
568 index_layer, image_info.num_levels,
571 atlas_location_t01.
layer);
573 if (output_value.atlas_location_t00.max_delta_within_tile.x >= lod_factor)
582 vec2 master_tile_texel_coord_nxt;
584 delta_nxt =
vec2(half_next_pixel_delta);
585 master_tile_texel_coord_nxt = master_tile_texel_coord + delta_nxt;
588 index_layer, image_info.num_levels,
591 atlas_location_t11.
layer);
620 atlas_location.
layer),
641 vec2 image_coordinate, min_tile_dist, max_tile_dist;
642 float slack_requirement;
650 slack_requirement = lod_factor;
661 if (max_tile_dist.x >= slack_requirement
662 && max_tile_dist.y >= slack_requirement
663 && min_tile_dist.x <= -slack_requirement
664 && min_tile_dist.y <= -slack_requirement)
669 index_layer, image_info.num_levels,
674 atlas_location.
layer),
680 float inverse_lod_factor = 1.0f / lod_factor;
685 fastuidraw_atlas_image_gather(lod_i, lod_factor, inverse_lod_factor,
686 master_tile_texel_coord,
687 index_layer, image_info,
714 vec2 master_tile_texel_coord;
717 lod_factor = float(1 << lod_i);
722 image_info, lod_factor);
725 master_tile_texel_coord =
729 image_info.master_index_tile_layer,
747 vec2 master_tile_texel_coord;
748 vec2 fract_image_coordinate;
749 vec2 min_tile_dist, max_tile_dist, linear_weight;
750 vec4 x_weights, y_weights, weight_sums, recip_weight_sums;
751 vec4 t00, t10, t01, t11;
754 index_layer = image_info.master_index_tile_layer;
759 master_tile_texel_coord =
763 master_tile_texel_coord -=
vec2(0.5 * image_info.base.image_texel_size_on_master_index_tile);
773 fract_image_coordinate = fract(image_coordinate);
774 image_coordinate -= fract_image_coordinate;
776 x_weights = fastuidraw_cubic_weights(fract_image_coordinate.x);
777 y_weights = fastuidraw_cubic_weights(fract_image_coordinate.y);
778 weight_sums =
vec4(x_weights.x + x_weights.y, x_weights.z + x_weights.w,
779 y_weights.x + y_weights.y, y_weights.z + y_weights.w);
780 recip_weight_sums =
vec4(1.0) / weight_sums;
782 linear_weight.
x = weight_sums.y / (weight_sums.x + weight_sums.y);
783 linear_weight.y = weight_sums.w / (weight_sums.z + weight_sums.w);
785 if (min_tile_dist.x <= -1.5
786 && min_tile_dist.y <= -1.5
787 && max_tile_dist.x >= 2.5
788 && max_tile_dist.y >= 2.5)
792 image_info.base.num_levels, atlas_location);
800 vec4 corner_coords, texture_coords;
803 texel_coord -= fract_image_coordinate;
805 corner_coords = texel_coord.xxyy;
806 corner_coords.xz -=
vec2(0.5);
807 corner_coords.yw +=
vec2(1.5);
809 texture_coords = corner_coords +
vec4(x_weights.y, x_weights.w, y_weights.y, y_weights.w) * recip_weight_sums;
810 texture_coords *= fastuidraw_imageAtlasLinear_size_reciprocal.xyxy;
819 vec2 master_texel_coord;
820 vec4 corner_coords, offset_coords, master_coords;
822 master_texel_coord = master_tile_texel_coord;
823 master_texel_coord -= fract_image_coordinate *
vec2(image_info.base.image_texel_size_on_master_index_tile);
825 corner_coords = master_texel_coord.xxyy;
826 corner_coords.xz -=
vec2(0.5 * image_info.base.image_texel_size_on_master_index_tile);
827 corner_coords.yw +=
vec2(1.5 * image_info.base.image_texel_size_on_master_index_tile);
829 offset_coords =
vec4(x_weights.y, x_weights.w, y_weights.y, y_weights.w) * recip_weight_sums;
830 offset_coords *= image_info.base.image_texel_size_on_master_index_tile;
832 master_coords = corner_coords + offset_coords;
839 image_color = mix(mix(t00, t10, linear_weight.x),
840 mix(t01, t11, linear_weight.x),
uniform sampler2DArray fastuidraw_imageAtlasLinear
vec4 fastuidraw_nearest_filter_atlas_image(in vec2 image_texel_coordinate, in fastuidraw_image_extended_info_type image_info, in float lod)
fastuidraw_image_info_type base
float image_texel_size_on_master_index_tile
Structure that holds the 2x2 texel block. Only available if FASTUIDRAW_IMAGE_ATLAS_DISABLED is not de...
#define FASTUIDRAW_IMAGE_ATLAS_COLOR_TILE_SIZE
#define FASTUIDRAW_IMAGE_ATLAS_INDEX_TILE_LOG2_SIZE
void fastuidraw_compute_image_atlas_coord(in vec2 master_tile_texel_coord, in uint index_layer, in uint num_levels, out fastuidraw_compute_image_atlas_coord_type return_value)
vec2 fastuidraw_image_coordinate_clamp_for_nearest_filtering(in vec2 image_coordinate, in fastuidraw_image_extended_info_type image_info)
float recip_image_texel_size_on_master_index_tile
fastuidraw_compute_image_atlas_coord_type atlas_location_t00
uint master_index_tile_layer
vec2 fastuidraw_image_coordinate_clamp_for_linear_filtering(in vec2 image_coordinate, in fastuidraw_image_extended_info_type image_info, float pow2_lod)
vecN< uint32_t, 4 > uvec4
vec4 fastuidraw_linear_filter_atlas_image(in vec2 master_tile_texel_coord, in uint index_layer, in fastuidraw_image_info_type image_info, in int lod_i, in float lod_factor)
vec2 fastuidraw_compute_root_image_coordinate(in vec2 master_tile_tex_coord, in fastuidraw_image_info_type image_info)
void fastuidraw_compute_image_info(in uint num_levels, out fastuidraw_image_info_type d)
#define FASTUIDRAW_IMAGE_ATLAS_INDEX_TILE_SIZE
Structure that fully describes a fastuidraw::Image or a sub-image of one. Only available if FASTUIDRA...
void fastuidraw_image_atlas_compute_tile_range(in float root_image_coordinate, out float tile_min_dist, out float tile_max_dist)
Structure that describes the relationship between the master index tile and the color tiles of an ima...
vec2 fastuidraw_image_coordinate_clamp_for_cubic_filtering(in vec2 image_coordinate, in fastuidraw_image_extended_info_type image_info)
Structure to give information about what tile and where within a tile an image texel is located...
uniform sampler2DArray fastuidraw_imageAtlasNearest
vec2 fastuidraw_compute_image_coordinate(in vec2 master_tile_tex_coord, in fastuidraw_image_extended_info_type image_info)
vec2 unnormalized_texcoord_xy
uniform usampler2DArray fastuidraw_imageIndexAtlas
vec2 master_index_tile_bottom_left
vec2 max_delta_within_tile
vec2 fastuidraw_compute_master_index_tile_coordinate(in vec2 image_coordinate, in fastuidraw_image_extended_info_type image_info)
vec4 fastuidraw_cubic_filter_atlas_image(in vec2 image_coordinate, in fastuidraw_image_extended_info_type image_info)