namespace Brutal.VulkanApi.Abstractions;
///
/// Interface for a sub-image allocator object capable of allocating portions of an image (e.g.: texture atlas, or texture array)
///
public interface IImageViewPartitioner
{
///
/// Get the handle to the backing ImageView this partitioner is based on
///
///
public ImageViewPartitionInfo BackingPartition { get; protected set; }
///
/// Reset the partitioner to its initial state with the given partition info. Invalidates all current allocations.
///
///
public void Reset(ImageViewPartitionInfo info);
///
/// Get a partition of an imageview with the given creation info.
///
/// Partition creation info
/// The resulting partition
/// True if the allocation was successful
public bool TryCreatePartition(
in ImageViewPartitionInfo.CreateInfo createInfo,
out ImageViewPartitionInfo partition
);
}
///
/// Interface for a sub-image allocator object capable of allocating portions of an image (e.g.: texture atlas, or texture array)
///
public interface IRecycleImageViewPartitioner : IImageViewPartitioner
{
///
/// Free an imageview partition sourced from this partitioner
///
/// Struct containing all relevant information about the allocation/partition
public void FreePartition(in ImageViewPartitionInfo inAllocation);
}
public static class ImageViewPartitionerExtensions
{
public static ImageViewPartitionInfo CreatePartition(
this T partitioner,
in ImageViewPartitionInfo.CreateInfo createInfo
)
where T : IImageViewPartitioner
{
if (!partitioner.TryCreatePartition(createInfo, out var partition))
throw new OutOfMemoryException("Failed to create partition");
return partition;
}
}