diff --git a/librashader-runtime/src/scaling.rs b/librashader-runtime/src/scaling.rs index ab4e74e..2b76c09 100644 --- a/librashader-runtime/src/scaling.rs +++ b/librashader-runtime/src/scaling.rs @@ -5,24 +5,27 @@ use librashader_presets::{Scale2D, ScaleFactor, ScaleType, Scaling}; use num_traits::AsPrimitive; use std::ops::Mul; +pub const MAX_TEXEL_SIZE: f32 = 16384f32; + /// Trait for size scaling relative to the viewport. pub trait ViewportSize where - T: Mul + Copy + 'static, + T: Mul + Copy + Ord + 'static, f32: AsPrimitive, { /// Produce a `Size` scaled with the input scaling options. + /// The size will at minimum be 1x1, and at a maximum 16384x16384. fn scale_viewport(self, scaling: Scale2D, viewport: Size, original: Size) -> Size; } impl ViewportSize for Size where - T: Mul + Copy + 'static, + T: Mul + Copy + Ord + 'static, f32: AsPrimitive, { fn scale_viewport(self, scaling: Scale2D, viewport: Size, original: Size) -> Size where - T: Mul + Copy + 'static, + T: Mul + Copy + Ord + 'static, f32: AsPrimitive, { scaling::scale(scaling, self, viewport, original) @@ -35,6 +38,7 @@ pub trait MipmapSize { fn calculate_miplevels(self) -> T; /// Scale the size according to the given mipmap level. + /// The size will at minimum be 1x1, and at a maximum 16384x16384. fn scale_mipmap(self, miplevel: T) -> Size; } @@ -59,7 +63,7 @@ impl MipmapSize for Size { fn scale(scaling: Scale2D, source: Size, viewport: Size, original: Size) -> Size where - T: Mul + Copy + 'static, + T: Mul + Copy + Ord + 'static, f32: AsPrimitive, { let width = match scaling.x { @@ -101,8 +105,14 @@ where }; Size { - width: width.round().as_(), - height: height.round().as_(), + width: std::cmp::min( + std::cmp::max(width.round().as_(), 1f32.as_()), + MAX_TEXEL_SIZE.as_(), + ), + height: std::cmp::min( + std::cmp::max(height.round().as_(), 1f32.as_()), + MAX_TEXEL_SIZE.as_(), + ), } }