diff options
Diffstat (limited to 'engine/src/rendering')
| -rw-r--r-- | engine/src/rendering/shader/cursor.rs | 153 |
1 files changed, 69 insertions, 84 deletions
diff --git a/engine/src/rendering/shader/cursor.rs b/engine/src/rendering/shader/cursor.rs index 5cc742d..47b388a 100644 --- a/engine/src/rendering/shader/cursor.rs +++ b/engine/src/rendering/shader/cursor.rs @@ -212,94 +212,79 @@ impl BindingValue location_path: LocationPath, ) -> Result<(), BindingError> { - match ( - self, - ty.kind(), - ty.scalar_type(), - ty.element_type_layout() - .map(|elem_ty| elem_ty.scalar_type()), - ty.element_cnt(), - ty.resource_shape(), - ) { - (Self::Uint(_), TypeKind::Scalar, Some(ScalarType::Uint32), _, _, _) - | (Self::Int(_), TypeKind::Scalar, Some(ScalarType::Int32), _, _, _) - | (Self::Float(_), TypeKind::Scalar, Some(ScalarType::Float32), _, _, _) - | ( - Self::FVec3(_), - TypeKind::Vector, - _, - Some(Some(ScalarType::Float32)), - Some(3), - _, - ) - | ( - Self::Color(Color::Rgb(_)), - TypeKind::Vector, - _, - Some(Some(ScalarType::Float32)), - Some(3), - _, - ) - | ( - Self::Color(Color::Rgba(_)), - TypeKind::Vector, - _, - Some(Some(ScalarType::Float32)), - Some(4), - _, - ) - | ( - Self::Color(Color::Luma(_)), - TypeKind::Vector, - _, - Some(Some(ScalarType::Float32)), - Some(1), - _, - ) - | ( - Self::Color(Color::LumaA(_)), - TypeKind::Vector, - _, - Some(Some(ScalarType::Float32)), - Some(2), - _, - ) => Ok(()), - ( - Self::FMat4x4(_), - TypeKind::Matrix, - _, - Some(Some(ScalarType::Float32)), - _, - _, - ) if ty.row_cnt() == Some(4) && ty.column_cnt() == Some(4) => Ok(()), - ( - Self::Texture(_, BindingTextureKind::Texture2D), - TypeKind::Resource, - .., - Some(res_shape), - ) if (res_shape & ResourceShape::BASE) - .contains(ResourceShape::TEXTURE_2D) => - { - Ok(()) + let ty_kind = ty.kind(); + let scalar_ty = ty.scalar_type(); + + let element_scalar_ty = ty + .element_type_layout() + .and_then(|elem_ty| elem_ty.scalar_type()); + + let element_cnt = ty.element_cnt(); + + let is_valid = match self { + Self::Uint(_) => { + ty_kind == TypeKind::Scalar && scalar_ty == Some(ScalarType::Uint32) + } + Self::Int(_) => { + ty_kind == TypeKind::Scalar && scalar_ty == Some(ScalarType::Int32) + } + Self::Float(_) => { + ty_kind == TypeKind::Scalar && scalar_ty == Some(ScalarType::Float32) + } + Self::FVec3(_) => { + ty_kind == TypeKind::Vector + && element_scalar_ty == Some(ScalarType::Float32) + && element_cnt == Some(3) + } + Self::Color(Color::Rgb(_)) => { + ty_kind == TypeKind::Vector + && element_scalar_ty == Some(ScalarType::Float32) + && element_cnt == Some(3) + } + Self::Color(Color::Rgba(_)) => { + ty_kind == TypeKind::Vector + && element_scalar_ty == Some(ScalarType::Float32) + && element_cnt == Some(4) } - ( - Self::Texture(_, BindingTextureKind::Cube), - TypeKind::Resource, - .., - Some(res_shape), - ) if (res_shape & ResourceShape::BASE) - .contains(ResourceShape::TEXTURE_CUBE) => - { - Ok(()) + Self::Color(Color::Luma(_)) => { + ty_kind == TypeKind::Scalar && scalar_ty == Some(ScalarType::Float32) } - _ => { - cold_path(); - Err(BindingError::IncorrectValueType { - value: self.clone(), - location_path, - }) + Self::Color(Color::LumaA(_)) => { + ty_kind == TypeKind::Vector + && element_scalar_ty == Some(ScalarType::Float32) + && element_cnt == Some(2) } + Self::FMat4x4(_) => { + ty_kind == TypeKind::Matrix + && element_scalar_ty == Some(ScalarType::Float32) + && ty.row_cnt() == Some(4) + && ty.column_cnt() == Some(4) + } + Self::Texture(_, BindingTextureKind::Texture2D) => { + ty_kind == TypeKind::Resource + && ty.resource_shape().is_some_and(|res_shape| { + (res_shape & ResourceShape::BASE) + .contains(ResourceShape::TEXTURE_2D) + }) + } + Self::Texture(_, BindingTextureKind::Cube) => { + ty_kind == TypeKind::Resource + && ty.resource_shape().is_some_and(|res_shape| { + (res_shape & ResourceShape::BASE) + .contains(ResourceShape::TEXTURE_CUBE) + }) + } + }; + + if !is_valid { + cold_path(); + return Err(BindingError::IncorrectValueType { + value: self.clone(), + location_path, + }); } + + Ok(()) } } |
