In #48 we added an alternative downsampling path specifically for normal maps which renormalizes them and allows for format that have the Z-component reconstructed from X and Y. Also, due to our app using 4-channel texture for the normal maps during asset building, we needed to introduce a pixel stride parameter so we can correctly sample the normal maps.
This lead to several API changes which, in hindsight, were not done the best, such as exposing a mandatory pixel stride parameter for the downsampling function and the format getting separated from the Image struct because of the existence of two different format enums.
This PR attempts to correct these issues by doing a few things:
A new trait ImagePixelFormat is added which establishes an interface that both NormalMapFormat and AlbedoFormat (Previously named only Format) need to fulfil.
struct Image now uses a generic F: ImagePixelFormat so that the struct can be reused for both regular images and for normal maps.
The pixel stride parameter was moved into the Image struct. Using Image::new() will assume the stride is the same as the Format's pixel side, while a newly added Image::new_with_pixel_stride() allows a specific value to be given to the stride.
The format and pixel stride parameters were removed from the downsampling function signatures, as they should now be accessed from the source Image instead. downsample_normal_map requires Image to use a NormalMapFormat, while downsample and scale_alpha_to_original_coverage require AlbedoFormat to be used instead.
In #48 we added an alternative downsampling path specifically for normal maps which renormalizes them and allows for format that have the Z-component reconstructed from X and Y. Also, due to our app using 4-channel texture for the normal maps during asset building, we needed to introduce a pixel stride parameter so we can correctly sample the normal maps.
This lead to several API changes which, in hindsight, were not done the best, such as exposing a mandatory pixel stride parameter for the downsampling function and the format getting separated from the
Image
struct because of the existence of two different format enums.This PR attempts to correct these issues by doing a few things:
trait ImagePixelFormat
is added which establishes an interface that bothNormalMapFormat
andAlbedoFormat
(Previously named onlyFormat
) need to fulfil.struct Image
now uses a genericF: ImagePixelFormat
so that the struct can be reused for both regular images and for normal maps.Image
struct. UsingImage::new()
will assume the stride is the same as the Format's pixel side, while a newly addedImage::new_with_pixel_stride()
allows a specific value to be given to the stride.Image
instead.downsample_normal_map
requiresImage
to use aNormalMapFormat
, whiledownsample
andscale_alpha_to_original_coverage
requireAlbedoFormat
to be used instead.