Scaling downwards
While writing a simple image viewer, I discovered that scaling down is not supported. That is, if the pixel buffer is larger than the surface texture. Would it be difficult to scale an image to fit the surface texture, adding borders horizontally or vertically as appropriate to keep the aspect ratio?
It would not be too difficult to add this. The main pieces of the puzzle are:
- Changing the min-filter to
Linearso that scaling down retains some image quality. https://github.com/parasyte/pixels/blob/94b87496c3715b6fcc4541c6a9370a5544569c7b/src/renderers.rs#L38 - Updating the resize constraints when creating the scaling matrix. The primary constraint is the
max(1.0).floor()call here: https://github.com/parasyte/pixels/blob/94b87496c3715b6fcc4541c6a9370a5544569c7b/src/renderers.rs#L233-L237
There are probably some other things that also need to be updated along the way. But these are the most prominent in my mind.
I initially thought that using mipmapping would also help with quality and efficiency when scaling below the texture's native resolution. But it would add some complexity by requiring each mip level to be regenerated on every frame. That would definitely have a negative impact on efficiency. Mipmaps are beneficial for static textures, not dynamic textures.
@parasyte
Updating the resize constraints when creating the scaling matrix. The primary constraint is the max(1.0).floor() call here:
Can you tell how to update it? I copied the renderer.rs in the fill-window branch and removed .max(1.0) but it doesn't work
I copied the
renderer.rsin thefill-windowbranch and removed.max(1.0)but it doesn't work
Did you also remove it in the default renderer? The default renderer is run first, followed by the custom renderer in the fill-window example.