mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
Clippy improvements (#4665)
# Objective Follow up to my previous MR #3718 to add new clippy warnings to bevy: - [x] [~~option_if_let_else~~](https://rust-lang.github.io/rust-clippy/master/#option_if_let_else) (reverted) - [x] [redundant_else](https://rust-lang.github.io/rust-clippy/master/#redundant_else) - [x] [match_same_arms](https://rust-lang.github.io/rust-clippy/master/#match_same_arms) - [x] [semicolon_if_nothing_returned](https://rust-lang.github.io/rust-clippy/master/#semicolon_if_nothing_returned) - [x] [explicit_iter_loop](https://rust-lang.github.io/rust-clippy/master/#explicit_iter_loop) - [x] [map_flatten](https://rust-lang.github.io/rust-clippy/master/#map_flatten) There is one commit per clippy warning, and the matching flags are added to the CI execution. To test the CI execution you may run `cargo run -p ci -- clippy` at the root. I choose the add the flags in the `ci` tool crate to avoid having them in every `lib.rs` but I guess it could become an issue with suprise warnings coming up after a commit/push Co-authored-by: Carter Anderson <mcanders1@gmail.com>
This commit is contained in:
parent
e543941fb9
commit
f000c2b951
56 changed files with 302 additions and 703 deletions
|
@ -230,7 +230,7 @@ pub fn animation_player(
|
|||
match &curve.keyframes {
|
||||
Keyframes::Rotation(keyframes) => transform.rotation = keyframes[0],
|
||||
Keyframes::Translation(keyframes) => {
|
||||
transform.translation = keyframes[0]
|
||||
transform.translation = keyframes[0];
|
||||
}
|
||||
Keyframes::Scale(keyframes) => transform.scale = keyframes[0],
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ impl PluginGroupBuilder {
|
|||
/// Consumes the [`PluginGroupBuilder`] and [builds](Plugin::build) the contained [`Plugin`]s
|
||||
/// in the order specified.
|
||||
pub fn finish(self, app: &mut App) {
|
||||
for ty in self.order.iter() {
|
||||
for ty in &self.order {
|
||||
if let Some(entry) = self.plugins.get(ty) {
|
||||
if entry.enabled {
|
||||
debug!("added plugin: {}", entry.plugin.name());
|
||||
|
@ -173,7 +173,7 @@ mod tests {
|
|||
std::any::TypeId::of::<PluginB>(),
|
||||
std::any::TypeId::of::<PluginC>(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -190,7 +190,7 @@ mod tests {
|
|||
std::any::TypeId::of::<PluginC>(),
|
||||
std::any::TypeId::of::<PluginB>(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -207,7 +207,7 @@ mod tests {
|
|||
std::any::TypeId::of::<PluginC>(),
|
||||
std::any::TypeId::of::<PluginB>(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -225,7 +225,7 @@ mod tests {
|
|||
std::any::TypeId::of::<PluginC>(),
|
||||
std::any::TypeId::of::<PluginB>(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -243,7 +243,7 @@ mod tests {
|
|||
std::any::TypeId::of::<PluginC>(),
|
||||
std::any::TypeId::of::<PluginB>(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -261,6 +261,6 @@ mod tests {
|
|||
std::any::TypeId::of::<PluginC>(),
|
||||
std::any::TypeId::of::<PluginB>(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,8 +93,7 @@ pub(crate) fn sync_debug_assets<T: Asset + Clone>(
|
|||
let (changed_shaders, handle_map, debug_assets) = state.get_mut(world);
|
||||
for changed in changed_shaders.iter_current_update_events() {
|
||||
let debug_handle = match changed {
|
||||
AssetEvent::Created { handle } => handle,
|
||||
AssetEvent::Modified { handle } => handle,
|
||||
AssetEvent::Created { handle } | AssetEvent::Modified { handle } => handle,
|
||||
AssetEvent::Removed { .. } => continue,
|
||||
};
|
||||
if let Some(handle) = handle_map.handles.get(debug_handle) {
|
||||
|
|
|
@ -43,17 +43,15 @@ where
|
|||
Source: Asset + Decodable,
|
||||
{
|
||||
fn play_source(&self, audio_source: &Source, repeat: bool) -> Option<Sink> {
|
||||
if let Some(stream_handle) = &self.stream_handle {
|
||||
self.stream_handle.as_ref().map(|stream_handle| {
|
||||
let sink = Sink::try_new(stream_handle).unwrap();
|
||||
if repeat {
|
||||
sink.append(audio_source.decoder().repeat_infinite());
|
||||
} else {
|
||||
sink.append(audio_source.decoder());
|
||||
}
|
||||
Some(sink)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
sink
|
||||
})
|
||||
}
|
||||
|
||||
fn try_play_queued(
|
||||
|
|
|
@ -196,7 +196,7 @@ impl std::fmt::Debug for ComponentDescriptor {
|
|||
impl ComponentDescriptor {
|
||||
// SAFETY: The pointer points to a valid value of type `T` and it is safe to drop this value.
|
||||
unsafe fn drop_ptr<T>(x: OwningPtr<'_>) {
|
||||
x.drop_as::<T>()
|
||||
x.drop_as::<T>();
|
||||
}
|
||||
|
||||
/// Create a new `ComponentDescriptor` for the type `T`.
|
||||
|
|
|
@ -294,12 +294,11 @@ impl<T: SparseSetIndex> FilteredAccessSet<T> {
|
|||
pub fn is_compatible(&self, other: &FilteredAccessSet<T>) -> bool {
|
||||
if self.combined_access.is_compatible(other.combined_access()) {
|
||||
return true;
|
||||
} else {
|
||||
for filtered in self.filtered_accesses.iter() {
|
||||
for other_filtered in other.filtered_accesses.iter() {
|
||||
if !filtered.is_compatible(other_filtered) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for filtered in &self.filtered_accesses {
|
||||
for other_filtered in &other.filtered_accesses {
|
||||
if !filtered.is_compatible(other_filtered) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,8 +311,8 @@ impl<T: SparseSetIndex> FilteredAccessSet<T> {
|
|||
// if the unfiltered access is incompatible, must check each pair
|
||||
let mut conflicts = HashSet::new();
|
||||
if !self.combined_access.is_compatible(other.combined_access()) {
|
||||
for filtered in self.filtered_accesses.iter() {
|
||||
for other_filtered in other.filtered_accesses.iter() {
|
||||
for filtered in &self.filtered_accesses {
|
||||
for other_filtered in &other.filtered_accesses {
|
||||
conflicts.extend(filtered.get_conflicts(other_filtered).into_iter());
|
||||
}
|
||||
}
|
||||
|
@ -326,7 +325,7 @@ impl<T: SparseSetIndex> FilteredAccessSet<T> {
|
|||
// if the unfiltered access is incompatible, must check each pair
|
||||
let mut conflicts = HashSet::new();
|
||||
if !self.combined_access.is_compatible(filtered_access.access()) {
|
||||
for filtered in self.filtered_accesses.iter() {
|
||||
for filtered in &self.filtered_accesses {
|
||||
conflicts.extend(filtered.get_conflicts(filtered_access).into_iter());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ pub struct With<T>(PhantomData<T>);
|
|||
impl<T: Component> WorldQuery for With<T> {
|
||||
type State = WithState<T>;
|
||||
|
||||
#[allow(clippy::semicolon_if_nothing_returned)]
|
||||
fn shrink<'wlong: 'wshort, 'wshort>(
|
||||
item: super::QueryItem<'wlong, Self>,
|
||||
) -> super::QueryItem<'wshort, Self> {
|
||||
|
@ -186,6 +187,7 @@ pub struct Without<T>(PhantomData<T>);
|
|||
impl<T: Component> WorldQuery for Without<T> {
|
||||
type State = WithoutState<T>;
|
||||
|
||||
#[allow(clippy::semicolon_if_nothing_returned)]
|
||||
fn shrink<'wlong: 'wshort, 'wshort>(
|
||||
item: super::QueryItem<'wlong, Self>,
|
||||
) -> super::QueryItem<'wshort, Self> {
|
||||
|
|
|
@ -162,7 +162,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery, const K: usize> QueryCombinationIter<
|
|||
|
||||
let ptr = values.as_mut_ptr().cast::<QueryItem<'w, Q>>();
|
||||
for (offset, cursor) in self.cursors.iter_mut().enumerate() {
|
||||
ptr.add(offset).write(cursor.peek_last().unwrap())
|
||||
ptr.add(offset).write(cursor.peek_last().unwrap());
|
||||
}
|
||||
|
||||
Some(values.assume_init())
|
||||
|
|
|
@ -455,7 +455,7 @@ mod tests {
|
|||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(custom_param_data, normal_data)
|
||||
assert_eq!(custom_param_data, normal_data);
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -925,10 +925,9 @@ impl Stage for SystemStage {
|
|||
}
|
||||
}
|
||||
match criteria.should_run {
|
||||
ShouldRun::Yes => {
|
||||
run_system_loop = true;
|
||||
}
|
||||
ShouldRun::YesAndCheckAgain | ShouldRun::NoAndCheckAgain => {
|
||||
ShouldRun::Yes
|
||||
| ShouldRun::YesAndCheckAgain
|
||||
| ShouldRun::NoAndCheckAgain => {
|
||||
run_system_loop = true;
|
||||
}
|
||||
ShouldRun::No => (),
|
||||
|
|
|
@ -133,13 +133,8 @@ where
|
|||
let pred_clone = pred.clone();
|
||||
(move |state: Res<State<T>>, mut is_in_stack: Local<bool>| match &state.transition {
|
||||
Some(StateTransition::Entering(ref relevant, _))
|
||||
| Some(StateTransition::ExitingToResume(_, ref relevant)) => {
|
||||
if relevant == &pred {
|
||||
*is_in_stack = !*is_in_stack;
|
||||
}
|
||||
false
|
||||
}
|
||||
Some(StateTransition::ExitingFull(_, ref relevant)) => {
|
||||
| Some(StateTransition::ExitingToResume(_, ref relevant))
|
||||
| Some(StateTransition::ExitingFull(_, ref relevant)) => {
|
||||
if relevant == &pred {
|
||||
*is_in_stack = !*is_in_stack;
|
||||
}
|
||||
|
|
|
@ -357,7 +357,7 @@ mod tests {
|
|||
|
||||
// SAFETY: The pointer points to a valid value of type `T` and it is safe to drop this value.
|
||||
unsafe fn drop_ptr<T>(x: OwningPtr<'_>) {
|
||||
x.drop_as::<T>()
|
||||
x.drop_as::<T>();
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
|
|
|
@ -319,7 +319,6 @@ where
|
|||
world_id: Option<WorldId>,
|
||||
archetype_generation: ArchetypeGeneration,
|
||||
// NOTE: PhantomData<fn()-> T> gives this safe Send/Sync impls
|
||||
#[allow(clippy::type_complexity)]
|
||||
marker: PhantomData<fn() -> (In, Out, Marker)>,
|
||||
}
|
||||
|
||||
|
|
|
@ -561,7 +561,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
|
|||
f,
|
||||
self.last_change_tick,
|
||||
self.change_tick,
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1445,11 +1445,11 @@ unsafe impl<S: SystemParamState, P: SystemParam + 'static> SystemParamState
|
|||
}
|
||||
|
||||
fn new_archetype(&mut self, archetype: &Archetype, system_meta: &mut SystemMeta) {
|
||||
self.0.new_archetype(archetype, system_meta)
|
||||
self.0.new_archetype(archetype, system_meta);
|
||||
}
|
||||
|
||||
fn apply(&mut self, world: &mut World) {
|
||||
self.0.apply(world)
|
||||
self.0.apply(world);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -613,55 +613,45 @@ fn load_material(material: &Material, load_context: &mut LoadContext) -> Handle<
|
|||
let pbr = material.pbr_metallic_roughness();
|
||||
|
||||
let color = pbr.base_color_factor();
|
||||
let base_color_texture = if let Some(info) = pbr.base_color_texture() {
|
||||
let base_color_texture = pbr.base_color_texture().map(|info| {
|
||||
// TODO: handle info.tex_coord() (the *set* index for the right texcoords)
|
||||
let label = texture_label(&info.texture());
|
||||
let path = AssetPath::new_ref(load_context.path(), Some(&label));
|
||||
Some(load_context.get_handle(path))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
load_context.get_handle(path)
|
||||
});
|
||||
|
||||
let normal_map_texture: Option<Handle<Image>> =
|
||||
if let Some(normal_texture) = material.normal_texture() {
|
||||
material.normal_texture().map(|normal_texture| {
|
||||
// TODO: handle normal_texture.scale
|
||||
// TODO: handle normal_texture.tex_coord() (the *set* index for the right texcoords)
|
||||
let label = texture_label(&normal_texture.texture());
|
||||
let path = AssetPath::new_ref(load_context.path(), Some(&label));
|
||||
Some(load_context.get_handle(path))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
load_context.get_handle(path)
|
||||
});
|
||||
|
||||
let metallic_roughness_texture = if let Some(info) = pbr.metallic_roughness_texture() {
|
||||
let metallic_roughness_texture = pbr.metallic_roughness_texture().map(|info| {
|
||||
// TODO: handle info.tex_coord() (the *set* index for the right texcoords)
|
||||
let label = texture_label(&info.texture());
|
||||
let path = AssetPath::new_ref(load_context.path(), Some(&label));
|
||||
Some(load_context.get_handle(path))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
load_context.get_handle(path)
|
||||
});
|
||||
|
||||
let occlusion_texture = if let Some(occlusion_texture) = material.occlusion_texture() {
|
||||
let occlusion_texture = material.occlusion_texture().map(|occlusion_texture| {
|
||||
// TODO: handle occlusion_texture.tex_coord() (the *set* index for the right texcoords)
|
||||
// TODO: handle occlusion_texture.strength() (a scalar multiplier for occlusion strength)
|
||||
let label = texture_label(&occlusion_texture.texture());
|
||||
let path = AssetPath::new_ref(load_context.path(), Some(&label));
|
||||
Some(load_context.get_handle(path))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
load_context.get_handle(path)
|
||||
});
|
||||
|
||||
let emissive = material.emissive_factor();
|
||||
let emissive_texture = if let Some(info) = material.emissive_texture() {
|
||||
let emissive_texture = material.emissive_texture().map(|info| {
|
||||
// TODO: handle occlusion_texture.tex_coord() (the *set* index for the right texcoords)
|
||||
// TODO: handle occlusion_texture.strength() (a scalar multiplier for occlusion strength)
|
||||
let label = texture_label(&info.texture());
|
||||
let path = AssetPath::new_ref(load_context.path(), Some(&label));
|
||||
Some(load_context.get_handle(path))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
load_context.get_handle(path)
|
||||
});
|
||||
|
||||
load_context.set_labeled_asset(
|
||||
&material_label,
|
||||
|
|
|
@ -328,8 +328,7 @@ impl ClusterConfig {
|
|||
|
||||
fn first_slice_depth(&self) -> f32 {
|
||||
match self {
|
||||
ClusterConfig::None => 0.0,
|
||||
ClusterConfig::Single => 0.0,
|
||||
ClusterConfig::None | ClusterConfig::Single => 0.0,
|
||||
ClusterConfig::XYZ { z_config, .. } | ClusterConfig::FixedZ { z_config, .. } => {
|
||||
z_config.first_slice_depth
|
||||
}
|
||||
|
@ -880,7 +879,7 @@ pub(crate) fn assign_lights_to_clusters(
|
|||
|
||||
let inverse_projection = camera.projection_matrix.inverse();
|
||||
|
||||
for lights in clusters.lights.iter_mut() {
|
||||
for lights in &mut clusters.lights {
|
||||
lights.entities.clear();
|
||||
}
|
||||
clusters.lights.resize_with(
|
||||
|
|
|
@ -265,7 +265,7 @@ impl RenderAsset for StandardMaterial {
|
|||
| TextureFormat::Rg16Unorm
|
||||
| TextureFormat::Bc5RgUnorm
|
||||
| TextureFormat::EacRg11Unorm => {
|
||||
flags |= StandardMaterialFlags::TWO_COMPONENT_NORMAL_MAP
|
||||
flags |= StandardMaterialFlags::TWO_COMPONENT_NORMAL_MAP;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -741,7 +741,7 @@ pub fn prepare_skinned_meshes(
|
|||
skinned_mesh_uniform
|
||||
.buffer
|
||||
.reserve(extracted_joints.buffer.len(), &render_device);
|
||||
for joint in extracted_joints.buffer.iter() {
|
||||
for joint in &extracted_joints.buffer {
|
||||
skinned_mesh_uniform.buffer.push(*joint);
|
||||
}
|
||||
skinned_mesh_uniform
|
||||
|
|
|
@ -97,7 +97,6 @@ impl SpecializedMeshPipeline for WireframePipeline {
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn queue_wireframes(
|
||||
opaque_3d_draw_functions: Res<DrawFunctions<Opaque3d>>,
|
||||
render_meshes: Res<RenderAssets<Mesh>>,
|
||||
|
|
|
@ -180,7 +180,7 @@ impl<'a> OwningPtr<'a> {
|
|||
/// Must point to a valid `T`.
|
||||
#[inline]
|
||||
pub unsafe fn drop_as<T>(self) {
|
||||
self.as_ptr().cast::<T>().drop_in_place()
|
||||
self.as_ptr().cast::<T>().drop_in_place();
|
||||
}
|
||||
|
||||
/// Gets the underlying pointer, erasing the associated lifetime.
|
||||
|
|
|
@ -17,7 +17,7 @@ pub(crate) fn type_uuid_derive(input: proc_macro::TokenStream) -> proc_macro::To
|
|||
ast.generics.type_params_mut().for_each(|param| {
|
||||
param
|
||||
.bounds
|
||||
.push(syn::parse_quote!(#bevy_reflect_path::TypeUuid))
|
||||
.push(syn::parse_quote!(#bevy_reflect_path::TypeUuid));
|
||||
});
|
||||
|
||||
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
|
||||
|
|
|
@ -217,7 +217,7 @@ pub fn array_hash<A: Array>(array: &A) -> Option<u64> {
|
|||
std::any::Any::type_id(array).hash(&mut hasher);
|
||||
array.len().hash(&mut hasher);
|
||||
for value in array.iter() {
|
||||
hasher.write_u64(value.reflect_hash()?)
|
||||
hasher.write_u64(value.reflect_hash()?);
|
||||
}
|
||||
Some(hasher.finish())
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ unsafe impl<K: Reflect + Eq + Hash, V: Reflect> Reflect for HashMap<K, V> {
|
|||
if let ReflectRef::Map(map_value) = value.reflect_ref() {
|
||||
for (key, value) in map_value.iter() {
|
||||
if let Some(v) = Map::get_mut(self, key) {
|
||||
v.apply(value)
|
||||
v.apply(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -349,7 +349,6 @@ pub trait FromType<T> {
|
|||
/// [`FromType::from_type`].
|
||||
#[derive(Clone)]
|
||||
pub struct ReflectDeserialize {
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub func: fn(
|
||||
deserializer: &mut dyn erased_serde::Deserializer,
|
||||
) -> Result<Box<dyn Reflect>, erased_serde::Error>,
|
||||
|
|
|
@ -164,7 +164,6 @@ impl Camera {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn camera_system<T: CameraProjection + Component>(
|
||||
mut window_resized_events: EventReader<WindowResized>,
|
||||
mut window_created_events: EventReader<WindowCreated>,
|
||||
|
@ -339,5 +338,5 @@ pub fn extract_cameras<M: Component + Default>(
|
|||
}
|
||||
}
|
||||
|
||||
commands.insert_resource(active_camera.clone())
|
||||
commands.insert_resource(active_camera.clone());
|
||||
}
|
||||
|
|
|
@ -835,12 +835,8 @@ impl MulAssign<f32> for Color {
|
|||
match self {
|
||||
Color::Rgba {
|
||||
red, green, blue, ..
|
||||
} => {
|
||||
*red *= rhs;
|
||||
*green *= rhs;
|
||||
*blue *= rhs;
|
||||
}
|
||||
Color::RgbaLinear {
|
||||
| Color::RgbaLinear {
|
||||
red, green, blue, ..
|
||||
} => {
|
||||
*red *= rhs;
|
||||
|
@ -911,13 +907,8 @@ impl MulAssign<Vec4> for Color {
|
|||
green,
|
||||
blue,
|
||||
alpha,
|
||||
} => {
|
||||
*red *= rhs.x;
|
||||
*green *= rhs.y;
|
||||
*blue *= rhs.z;
|
||||
*alpha *= rhs.w;
|
||||
}
|
||||
Color::RgbaLinear {
|
||||
| Color::RgbaLinear {
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
|
@ -990,12 +981,8 @@ impl MulAssign<Vec3> for Color {
|
|||
match self {
|
||||
Color::Rgba {
|
||||
red, green, blue, ..
|
||||
} => {
|
||||
*red *= rhs.x;
|
||||
*green *= rhs.y;
|
||||
*blue *= rhs.z;
|
||||
}
|
||||
Color::RgbaLinear {
|
||||
| Color::RgbaLinear {
|
||||
red, green, blue, ..
|
||||
} => {
|
||||
*red *= rhs.x;
|
||||
|
@ -1066,13 +1053,8 @@ impl MulAssign<[f32; 4]> for Color {
|
|||
green,
|
||||
blue,
|
||||
alpha,
|
||||
} => {
|
||||
*red *= rhs[0];
|
||||
*green *= rhs[1];
|
||||
*blue *= rhs[2];
|
||||
*alpha *= rhs[3];
|
||||
}
|
||||
Color::RgbaLinear {
|
||||
| Color::RgbaLinear {
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
|
@ -1145,12 +1127,8 @@ impl MulAssign<[f32; 3]> for Color {
|
|||
match self {
|
||||
Color::Rgba {
|
||||
red, green, blue, ..
|
||||
} => {
|
||||
*red *= rhs[0];
|
||||
*green *= rhs[1];
|
||||
*blue *= rhs[2];
|
||||
}
|
||||
Color::RgbaLinear {
|
||||
| Color::RgbaLinear {
|
||||
red, green, blue, ..
|
||||
} => {
|
||||
*red *= rhs[0];
|
||||
|
|
|
@ -134,8 +134,9 @@ impl TryFrom<VertexAttributeValues> for Vec<[u8; 4]> {
|
|||
|
||||
fn try_from(value: VertexAttributeValues) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
VertexAttributeValues::Uint8x4(value) => Ok(value),
|
||||
VertexAttributeValues::Unorm8x4(value) => Ok(value),
|
||||
VertexAttributeValues::Uint8x4(value) | VertexAttributeValues::Unorm8x4(value) => {
|
||||
Ok(value)
|
||||
}
|
||||
_ => Err(FromVertexAttributeError::new::<Self>(value)),
|
||||
}
|
||||
}
|
||||
|
@ -146,8 +147,9 @@ impl TryFrom<VertexAttributeValues> for Vec<[i8; 4]> {
|
|||
|
||||
fn try_from(value: VertexAttributeValues) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
VertexAttributeValues::Sint8x4(value) => Ok(value),
|
||||
VertexAttributeValues::Snorm8x4(value) => Ok(value),
|
||||
VertexAttributeValues::Sint8x4(value) | VertexAttributeValues::Snorm8x4(value) => {
|
||||
Ok(value)
|
||||
}
|
||||
_ => Err(FromVertexAttributeError::new::<Self>(value)),
|
||||
}
|
||||
}
|
||||
|
@ -158,8 +160,9 @@ impl TryFrom<VertexAttributeValues> for Vec<[u8; 2]> {
|
|||
|
||||
fn try_from(value: VertexAttributeValues) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
VertexAttributeValues::Uint8x2(value) => Ok(value),
|
||||
VertexAttributeValues::Unorm8x2(value) => Ok(value),
|
||||
VertexAttributeValues::Uint8x2(value) | VertexAttributeValues::Unorm8x2(value) => {
|
||||
Ok(value)
|
||||
}
|
||||
_ => Err(FromVertexAttributeError::new::<Self>(value)),
|
||||
}
|
||||
}
|
||||
|
@ -170,8 +173,9 @@ impl TryFrom<VertexAttributeValues> for Vec<[i8; 2]> {
|
|||
|
||||
fn try_from(value: VertexAttributeValues) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
VertexAttributeValues::Sint8x2(value) => Ok(value),
|
||||
VertexAttributeValues::Snorm8x2(value) => Ok(value),
|
||||
VertexAttributeValues::Sint8x2(value) | VertexAttributeValues::Snorm8x2(value) => {
|
||||
Ok(value)
|
||||
}
|
||||
_ => Err(FromVertexAttributeError::new::<Self>(value)),
|
||||
}
|
||||
}
|
||||
|
@ -182,8 +186,9 @@ impl TryFrom<VertexAttributeValues> for Vec<[i16; 4]> {
|
|||
|
||||
fn try_from(value: VertexAttributeValues) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
VertexAttributeValues::Sint16x4(value) => Ok(value),
|
||||
VertexAttributeValues::Snorm16x4(value) => Ok(value),
|
||||
VertexAttributeValues::Sint16x4(value) | VertexAttributeValues::Snorm16x4(value) => {
|
||||
Ok(value)
|
||||
}
|
||||
_ => Err(FromVertexAttributeError::new::<Self>(value)),
|
||||
}
|
||||
}
|
||||
|
@ -194,8 +199,9 @@ impl TryFrom<VertexAttributeValues> for Vec<[u16; 4]> {
|
|||
|
||||
fn try_from(value: VertexAttributeValues) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
VertexAttributeValues::Uint16x4(value) => Ok(value),
|
||||
VertexAttributeValues::Unorm16x4(value) => Ok(value),
|
||||
VertexAttributeValues::Uint16x4(value) | VertexAttributeValues::Unorm16x4(value) => {
|
||||
Ok(value)
|
||||
}
|
||||
_ => Err(FromVertexAttributeError::new::<Self>(value)),
|
||||
}
|
||||
}
|
||||
|
@ -206,8 +212,9 @@ impl TryFrom<VertexAttributeValues> for Vec<[u16; 2]> {
|
|||
|
||||
fn try_from(value: VertexAttributeValues) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
VertexAttributeValues::Uint16x2(value) => Ok(value),
|
||||
VertexAttributeValues::Unorm16x2(value) => Ok(value),
|
||||
VertexAttributeValues::Uint16x2(value) | VertexAttributeValues::Unorm16x2(value) => {
|
||||
Ok(value)
|
||||
}
|
||||
_ => Err(FromVertexAttributeError::new::<Self>(value)),
|
||||
}
|
||||
}
|
||||
|
@ -218,8 +225,9 @@ impl TryFrom<VertexAttributeValues> for Vec<[i16; 2]> {
|
|||
|
||||
fn try_from(value: VertexAttributeValues) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
VertexAttributeValues::Sint16x2(value) => Ok(value),
|
||||
VertexAttributeValues::Snorm16x2(value) => Ok(value),
|
||||
VertexAttributeValues::Sint16x2(value) | VertexAttributeValues::Snorm16x2(value) => {
|
||||
Ok(value)
|
||||
}
|
||||
_ => Err(FromVertexAttributeError::new::<Self>(value)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ impl Mesh {
|
|||
/// Panics if the attributes have different vertex counts.
|
||||
pub fn count_vertices(&self) -> usize {
|
||||
let mut vertex_count: Option<usize> = None;
|
||||
for (attribute_id, attribute_data) in self.attributes.iter() {
|
||||
for (attribute_id, attribute_data) in &self.attributes {
|
||||
let attribute_len = attribute_data.values.len();
|
||||
if let Some(previous_vertex_count) = vertex_count {
|
||||
assert_eq!(previous_vertex_count, attribute_len,
|
||||
|
@ -253,6 +253,7 @@ impl Mesh {
|
|||
///
|
||||
/// This can dramatically increase the vertex count, so make sure this is what you want.
|
||||
/// Does nothing if no [Indices] are set.
|
||||
#[allow(clippy::match_same_arms)]
|
||||
pub fn duplicate_vertices(&mut self) {
|
||||
fn duplicate<T: Copy>(values: &[T], indices: impl Iterator<Item = usize>) -> Vec<T> {
|
||||
indices.map(|i| values[i]).collect()
|
||||
|
@ -430,7 +431,7 @@ impl InnerMeshVertexBufferLayout {
|
|||
format: layout_attribute.format,
|
||||
offset: layout_attribute.offset,
|
||||
shader_location: attribute_descriptor.shader_location,
|
||||
})
|
||||
});
|
||||
} else {
|
||||
return Err(MissingVertexAttributeError {
|
||||
id: attribute_descriptor.id,
|
||||
|
@ -491,6 +492,7 @@ pub trait VertexFormatSize {
|
|||
}
|
||||
|
||||
impl VertexFormatSize for wgpu::VertexFormat {
|
||||
#[allow(clippy::match_same_arms)]
|
||||
fn get_size(self) -> u64 {
|
||||
match self {
|
||||
VertexFormat::Uint8x2 => 2,
|
||||
|
@ -568,6 +570,7 @@ pub enum VertexAttributeValues {
|
|||
impl VertexAttributeValues {
|
||||
/// Returns the number of vertices in this [`VertexAttributeValues`]. For a single
|
||||
/// mesh, all of the [`VertexAttributeValues`] must have the same length.
|
||||
#[allow(clippy::match_same_arms)]
|
||||
pub fn len(&self) -> usize {
|
||||
match *self {
|
||||
VertexAttributeValues::Float32(ref values) => values.len(),
|
||||
|
@ -617,6 +620,7 @@ impl VertexAttributeValues {
|
|||
// TODO: add vertex format as parameter here and perform type conversions
|
||||
/// Flattens the [`VertexAttributeValues`] into a sequence of bytes. This is
|
||||
/// useful for serialization and sending to the GPU.
|
||||
#[allow(clippy::match_same_arms)]
|
||||
pub fn get_bytes(&self) -> &[u8] {
|
||||
match self {
|
||||
VertexAttributeValues::Float32(values) => cast_slice(&values[..]),
|
||||
|
|
|
@ -135,10 +135,7 @@ fn extract_render_asset<A: RenderAsset>(
|
|||
let mut removed = Vec::new();
|
||||
for event in events.iter() {
|
||||
match event {
|
||||
AssetEvent::Created { handle } => {
|
||||
changed_assets.insert(handle);
|
||||
}
|
||||
AssetEvent::Modified { handle } => {
|
||||
AssetEvent::Created { handle } | AssetEvent::Modified { handle } => {
|
||||
changed_assets.insert(handle);
|
||||
}
|
||||
AssetEvent::Removed { handle } => {
|
||||
|
|
|
@ -35,16 +35,14 @@ impl Edge {
|
|||
/// Returns the id of the `input_node`.
|
||||
pub fn get_input_node(&self) -> NodeId {
|
||||
match self {
|
||||
Edge::SlotEdge { input_node, .. } => *input_node,
|
||||
Edge::NodeEdge { input_node, .. } => *input_node,
|
||||
Edge::SlotEdge { input_node, .. } | Edge::NodeEdge { input_node, .. } => *input_node,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the id of the `output_node`.
|
||||
pub fn get_output_node(&self) -> NodeId {
|
||||
match self {
|
||||
Edge::SlotEdge { output_node, .. } => *output_node,
|
||||
Edge::NodeEdge { output_node, .. } => *output_node,
|
||||
Edge::SlotEdge { output_node, .. } | Edge::NodeEdge { output_node, .. } => *output_node,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,17 +114,8 @@ impl RenderGraph {
|
|||
// node, we don't need to remove its input edges
|
||||
for input_edge in node_state.edges.input_edges().iter() {
|
||||
match input_edge {
|
||||
Edge::SlotEdge {
|
||||
output_node,
|
||||
output_index: _,
|
||||
input_node: _,
|
||||
input_index: _,
|
||||
} => {
|
||||
if let Ok(output_node) = self.get_node_state_mut(*output_node) {
|
||||
output_node.edges.remove_output_edge(input_edge.clone())?;
|
||||
}
|
||||
}
|
||||
Edge::NodeEdge {
|
||||
Edge::SlotEdge { output_node, .. }
|
||||
| Edge::NodeEdge {
|
||||
input_node: _,
|
||||
output_node,
|
||||
} => {
|
||||
|
@ -143,12 +134,8 @@ impl RenderGraph {
|
|||
output_index: _,
|
||||
input_node,
|
||||
input_index: _,
|
||||
} => {
|
||||
if let Ok(input_node) = self.get_node_state_mut(*input_node) {
|
||||
input_node.edges.remove_input_edge(output_edge.clone())?;
|
||||
}
|
||||
}
|
||||
Edge::NodeEdge {
|
||||
| Edge::NodeEdge {
|
||||
output_node: _,
|
||||
input_node,
|
||||
} => {
|
||||
|
|
|
@ -135,14 +135,14 @@ impl<'a> TrackedRenderPass<'a> {
|
|||
dynamic_uniform_indices
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
trace!(
|
||||
"set bind_group {}: {:?} ({:?})",
|
||||
index,
|
||||
bind_group,
|
||||
dynamic_uniform_indices
|
||||
);
|
||||
}
|
||||
trace!(
|
||||
"set bind_group {}: {:?} ({:?})",
|
||||
index,
|
||||
bind_group,
|
||||
dynamic_uniform_indices
|
||||
);
|
||||
|
||||
self.pass
|
||||
.set_bind_group(index as u32, bind_group, dynamic_uniform_indices);
|
||||
self.state
|
||||
|
@ -169,14 +169,14 @@ impl<'a> TrackedRenderPass<'a> {
|
|||
offset
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
trace!(
|
||||
"set vertex buffer {}: {:?} ({})",
|
||||
slot_index,
|
||||
buffer_slice.id(),
|
||||
offset
|
||||
);
|
||||
}
|
||||
trace!(
|
||||
"set vertex buffer {}: {:?} ({})",
|
||||
slot_index,
|
||||
buffer_slice.id(),
|
||||
offset
|
||||
);
|
||||
|
||||
self.pass
|
||||
.set_vertex_buffer(slot_index as u32, *buffer_slice);
|
||||
self.state
|
||||
|
@ -203,9 +203,8 @@ impl<'a> TrackedRenderPass<'a> {
|
|||
offset
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
trace!("set index buffer: {:?} ({})", buffer_slice.id(), offset);
|
||||
}
|
||||
trace!("set index buffer: {:?} ({})", buffer_slice.id(), offset);
|
||||
self.pass.set_index_buffer(*buffer_slice, index_format);
|
||||
self.state
|
||||
.set_index_buffer(buffer_slice.id(), offset, index_format);
|
||||
|
|
|
@ -379,9 +379,8 @@ impl ShaderProcessor {
|
|||
Source::SpirV(source) => {
|
||||
if shader_defs.is_empty() {
|
||||
return Ok(ProcessedShader::SpirV(source.clone()));
|
||||
} else {
|
||||
return Err(ProcessShaderError::ShaderFormatDoesNotSupportShaderDefs);
|
||||
}
|
||||
return Err(ProcessShaderError::ShaderFormatDoesNotSupportShaderDefs);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -101,9 +101,8 @@ impl RenderGraphRunner {
|
|||
expected: input_slot.slot_type,
|
||||
label: input_slot.name.clone().into(),
|
||||
});
|
||||
} else {
|
||||
input_values.push(input_value.clone());
|
||||
}
|
||||
input_values.push(input_value.clone());
|
||||
} else {
|
||||
return Err(RenderGraphRunnerError::MissingInput {
|
||||
slot_index: i,
|
||||
|
|
|
@ -114,9 +114,9 @@ pub fn basis_buffer_to_image(
|
|||
image.texture_descriptor.mip_level_count = image0_mip_level_count;
|
||||
image.texture_descriptor.format = texture_format;
|
||||
image.texture_descriptor.dimension = match texture_type {
|
||||
BasisTextureType::TextureType2D => TextureDimension::D2,
|
||||
BasisTextureType::TextureType2DArray => TextureDimension::D2,
|
||||
BasisTextureType::TextureTypeCubemapArray => TextureDimension::D2,
|
||||
BasisTextureType::TextureType2D
|
||||
| BasisTextureType::TextureType2DArray
|
||||
| BasisTextureType::TextureTypeCubemapArray => TextureDimension::D2,
|
||||
BasisTextureType::TextureTypeVolume => TextureDimension::D3,
|
||||
basis_texture_type => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
|
|
|
@ -74,14 +74,14 @@ pub fn dds_format_to_texture_format(
|
|||
TextureFormat::Bc1RgbaUnorm
|
||||
}
|
||||
}
|
||||
D3DFormat::DXT3 => {
|
||||
D3DFormat::DXT3 | D3DFormat::DXT2 => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc2RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc2RgbaUnorm
|
||||
}
|
||||
}
|
||||
D3DFormat::DXT5 => {
|
||||
D3DFormat::DXT5 | D3DFormat::DXT4 => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc3RgbaUnormSrgb
|
||||
} else {
|
||||
|
@ -96,20 +96,6 @@ pub fn dds_format_to_texture_format(
|
|||
D3DFormat::R32F => TextureFormat::R32Float,
|
||||
D3DFormat::G32R32F => TextureFormat::Rg32Float,
|
||||
D3DFormat::A32B32G32R32F => TextureFormat::Rgba32Float,
|
||||
D3DFormat::DXT2 => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc2RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc2RgbaUnorm
|
||||
}
|
||||
}
|
||||
D3DFormat::DXT4 => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc3RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc3RgbaUnorm
|
||||
}
|
||||
}
|
||||
D3DFormat::A1R5G5B5
|
||||
| D3DFormat::R5G6B5
|
||||
// FIXME: Map to argb format and user has to know to ignore the alpha channel?
|
||||
|
@ -136,38 +122,28 @@ pub fn dds_format_to_texture_format(
|
|||
}
|
||||
} else if let Some(dxgi_format) = dds.get_dxgi_format() {
|
||||
match dxgi_format {
|
||||
DxgiFormat::R32G32B32A32_Typeless => TextureFormat::Rgba32Float,
|
||||
DxgiFormat::R32G32B32A32_Float => TextureFormat::Rgba32Float,
|
||||
DxgiFormat::R32G32B32A32_Typeless | DxgiFormat::R32G32B32A32_Float => {
|
||||
TextureFormat::Rgba32Float
|
||||
}
|
||||
DxgiFormat::R32G32B32A32_UInt => TextureFormat::Rgba32Uint,
|
||||
DxgiFormat::R32G32B32A32_SInt => TextureFormat::Rgba32Sint,
|
||||
DxgiFormat::R16G16B16A16_Typeless => TextureFormat::Rgba16Float,
|
||||
DxgiFormat::R16G16B16A16_Float => TextureFormat::Rgba16Float,
|
||||
DxgiFormat::R16G16B16A16_Typeless | DxgiFormat::R16G16B16A16_Float => {
|
||||
TextureFormat::Rgba16Float
|
||||
}
|
||||
DxgiFormat::R16G16B16A16_UNorm => TextureFormat::Rgba16Unorm,
|
||||
DxgiFormat::R16G16B16A16_UInt => TextureFormat::Rgba16Uint,
|
||||
DxgiFormat::R16G16B16A16_SNorm => TextureFormat::Rgba16Snorm,
|
||||
DxgiFormat::R16G16B16A16_SInt => TextureFormat::Rgba16Sint,
|
||||
DxgiFormat::R32G32_Typeless => TextureFormat::Rg32Float,
|
||||
DxgiFormat::R32G32_Float => TextureFormat::Rg32Float,
|
||||
DxgiFormat::R32G32_Typeless | DxgiFormat::R32G32_Float => TextureFormat::Rg32Float,
|
||||
DxgiFormat::R32G32_UInt => TextureFormat::Rg32Uint,
|
||||
DxgiFormat::R32G32_SInt => TextureFormat::Rg32Sint,
|
||||
DxgiFormat::R10G10B10A2_Typeless => TextureFormat::Rgb10a2Unorm,
|
||||
DxgiFormat::R10G10B10A2_UNorm => TextureFormat::Rgb10a2Unorm,
|
||||
DxgiFormat::R10G10B10A2_Typeless | DxgiFormat::R10G10B10A2_UNorm => {
|
||||
TextureFormat::Rgb10a2Unorm
|
||||
}
|
||||
DxgiFormat::R11G11B10_Float => TextureFormat::Rg11b10Float,
|
||||
DxgiFormat::R8G8B8A8_Typeless => {
|
||||
if is_srgb {
|
||||
TextureFormat::Rgba8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Rgba8Unorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::R8G8B8A8_UNorm => {
|
||||
if is_srgb {
|
||||
TextureFormat::Rgba8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Rgba8Unorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::R8G8B8A8_UNorm_sRGB => {
|
||||
DxgiFormat::R8G8B8A8_Typeless
|
||||
| DxgiFormat::R8G8B8A8_UNorm
|
||||
| DxgiFormat::R8G8B8A8_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Rgba8UnormSrgb
|
||||
} else {
|
||||
|
@ -177,121 +153,61 @@ pub fn dds_format_to_texture_format(
|
|||
DxgiFormat::R8G8B8A8_UInt => TextureFormat::Rgba8Uint,
|
||||
DxgiFormat::R8G8B8A8_SNorm => TextureFormat::Rgba8Snorm,
|
||||
DxgiFormat::R8G8B8A8_SInt => TextureFormat::Rgba8Sint,
|
||||
DxgiFormat::R16G16_Typeless => TextureFormat::Rg16Float,
|
||||
DxgiFormat::R16G16_Float => TextureFormat::Rg16Float,
|
||||
DxgiFormat::R16G16_Typeless | DxgiFormat::R16G16_Float => TextureFormat::Rg16Float,
|
||||
DxgiFormat::R16G16_UNorm => TextureFormat::Rg16Unorm,
|
||||
DxgiFormat::R16G16_UInt => TextureFormat::Rg16Uint,
|
||||
DxgiFormat::R16G16_SNorm => TextureFormat::Rg16Snorm,
|
||||
DxgiFormat::R16G16_SInt => TextureFormat::Rg16Sint,
|
||||
DxgiFormat::R32_Typeless => TextureFormat::R32Float,
|
||||
DxgiFormat::R32_Typeless | DxgiFormat::R32_Float => TextureFormat::R32Float,
|
||||
DxgiFormat::D32_Float => TextureFormat::Depth32Float,
|
||||
DxgiFormat::R32_Float => TextureFormat::R32Float,
|
||||
DxgiFormat::R32_UInt => TextureFormat::R32Uint,
|
||||
DxgiFormat::R32_SInt => TextureFormat::R32Sint,
|
||||
DxgiFormat::R24G8_Typeless => TextureFormat::Depth24PlusStencil8,
|
||||
DxgiFormat::D24_UNorm_S8_UInt => TextureFormat::Depth24PlusStencil8,
|
||||
DxgiFormat::R24G8_Typeless | DxgiFormat::D24_UNorm_S8_UInt => {
|
||||
TextureFormat::Depth24PlusStencil8
|
||||
}
|
||||
DxgiFormat::R24_UNorm_X8_Typeless => TextureFormat::Depth24Plus,
|
||||
DxgiFormat::R8G8_Typeless => TextureFormat::Rg8Unorm,
|
||||
DxgiFormat::R8G8_UNorm => TextureFormat::Rg8Unorm,
|
||||
DxgiFormat::R8G8_Typeless | DxgiFormat::R8G8_UNorm => TextureFormat::Rg8Unorm,
|
||||
DxgiFormat::R8G8_UInt => TextureFormat::Rg8Uint,
|
||||
DxgiFormat::R8G8_SNorm => TextureFormat::Rg8Snorm,
|
||||
DxgiFormat::R8G8_SInt => TextureFormat::Rg8Sint,
|
||||
DxgiFormat::R16_Typeless => TextureFormat::R16Float,
|
||||
DxgiFormat::R16_Float => TextureFormat::R16Float,
|
||||
DxgiFormat::R16_Typeless | DxgiFormat::R16_Float => TextureFormat::R16Float,
|
||||
DxgiFormat::R16_UNorm => TextureFormat::R16Unorm,
|
||||
DxgiFormat::R16_UInt => TextureFormat::R16Uint,
|
||||
DxgiFormat::R16_SNorm => TextureFormat::R16Snorm,
|
||||
DxgiFormat::R16_SInt => TextureFormat::R16Sint,
|
||||
DxgiFormat::R8_Typeless => TextureFormat::R8Unorm,
|
||||
DxgiFormat::R8_UNorm => TextureFormat::R8Unorm,
|
||||
DxgiFormat::R8_Typeless | DxgiFormat::R8_UNorm => TextureFormat::R8Unorm,
|
||||
DxgiFormat::R8_UInt => TextureFormat::R8Uint,
|
||||
DxgiFormat::R8_SNorm => TextureFormat::R8Snorm,
|
||||
DxgiFormat::R8_SInt => TextureFormat::R8Sint,
|
||||
DxgiFormat::R9G9B9E5_SharedExp => TextureFormat::Rgb9e5Ufloat,
|
||||
DxgiFormat::BC1_Typeless => {
|
||||
DxgiFormat::BC1_Typeless | DxgiFormat::BC1_UNorm | DxgiFormat::BC1_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc1RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc1RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC1_UNorm => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc1RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc1RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC1_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc1RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc1RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC2_Typeless => {
|
||||
DxgiFormat::BC2_Typeless | DxgiFormat::BC2_UNorm | DxgiFormat::BC2_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc2RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc2RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC2_UNorm => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc2RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc2RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC2_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc2RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc2RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC3_Typeless => {
|
||||
DxgiFormat::BC3_Typeless | DxgiFormat::BC3_UNorm | DxgiFormat::BC3_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc3RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc3RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC3_UNorm => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc3RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc3RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC3_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc3RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc3RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC4_Typeless => TextureFormat::Bc4RUnorm,
|
||||
DxgiFormat::BC4_UNorm => TextureFormat::Bc4RUnorm,
|
||||
DxgiFormat::BC4_Typeless | DxgiFormat::BC4_UNorm => TextureFormat::Bc4RUnorm,
|
||||
DxgiFormat::BC4_SNorm => TextureFormat::Bc4RSnorm,
|
||||
DxgiFormat::BC5_Typeless => TextureFormat::Bc5RgUnorm,
|
||||
DxgiFormat::BC5_UNorm => TextureFormat::Bc5RgUnorm,
|
||||
DxgiFormat::BC5_Typeless | DxgiFormat::BC5_UNorm => TextureFormat::Bc5RgUnorm,
|
||||
DxgiFormat::BC5_SNorm => TextureFormat::Bc5RgSnorm,
|
||||
DxgiFormat::B8G8R8A8_UNorm => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bgra8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bgra8Unorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::B8G8R8A8_Typeless => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bgra8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bgra8Unorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::B8G8R8A8_UNorm_sRGB => {
|
||||
DxgiFormat::B8G8R8A8_UNorm
|
||||
| DxgiFormat::B8G8R8A8_Typeless
|
||||
| DxgiFormat::B8G8R8A8_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bgra8UnormSrgb
|
||||
} else {
|
||||
|
@ -299,24 +215,9 @@ pub fn dds_format_to_texture_format(
|
|||
}
|
||||
}
|
||||
|
||||
DxgiFormat::BC6H_Typeless => TextureFormat::Bc6hRgbUfloat,
|
||||
DxgiFormat::BC6H_UF16 => TextureFormat::Bc6hRgbUfloat,
|
||||
DxgiFormat::BC6H_Typeless | DxgiFormat::BC6H_UF16 => TextureFormat::Bc6hRgbUfloat,
|
||||
DxgiFormat::BC6H_SF16 => TextureFormat::Bc6hRgbSfloat,
|
||||
DxgiFormat::BC7_Typeless => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc7RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc7RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC7_UNorm => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc7RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc7RgbaUnorm
|
||||
}
|
||||
}
|
||||
DxgiFormat::BC7_UNorm_sRGB => {
|
||||
DxgiFormat::BC7_Typeless | DxgiFormat::BC7_UNorm | DxgiFormat::BC7_UNorm_sRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc7RgbaUnormSrgb
|
||||
} else {
|
||||
|
|
|
@ -49,14 +49,12 @@ pub enum ImageFormat {
|
|||
impl ImageFormat {
|
||||
pub fn from_mime_type(mime_type: &str) -> Option<Self> {
|
||||
Some(match mime_type.to_ascii_lowercase().as_str() {
|
||||
"image/bmp" => ImageFormat::Bmp,
|
||||
"image/x-bmp" => ImageFormat::Bmp,
|
||||
"image/bmp" | "image/x-bmp" => ImageFormat::Bmp,
|
||||
"image/vnd-ms.dds" => ImageFormat::Dds,
|
||||
"image/jpeg" => ImageFormat::Jpeg,
|
||||
"image/ktx2" => ImageFormat::Ktx2,
|
||||
"image/png" => ImageFormat::Png,
|
||||
"image/x-targa" => ImageFormat::Tga,
|
||||
"image/x-tga" => ImageFormat::Tga,
|
||||
"image/x-targa" | "image/x-tga" => ImageFormat::Tga,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
@ -85,7 +83,6 @@ impl ImageFormat {
|
|||
pub fn as_image_crate_format(&self) -> Option<image::ImageFormat> {
|
||||
Some(match self {
|
||||
ImageFormat::Avif => image::ImageFormat::Avif,
|
||||
ImageFormat::Basis => return None,
|
||||
ImageFormat::Bmp => image::ImageFormat::Bmp,
|
||||
ImageFormat::Dds => image::ImageFormat::Dds,
|
||||
ImageFormat::Farbfeld => image::ImageFormat::Farbfeld,
|
||||
|
@ -93,12 +90,12 @@ impl ImageFormat {
|
|||
ImageFormat::Hdr => image::ImageFormat::Hdr,
|
||||
ImageFormat::Ico => image::ImageFormat::Ico,
|
||||
ImageFormat::Jpeg => image::ImageFormat::Jpeg,
|
||||
ImageFormat::Ktx2 => return None,
|
||||
ImageFormat::Png => image::ImageFormat::Png,
|
||||
ImageFormat::Pnm => image::ImageFormat::Pnm,
|
||||
ImageFormat::Tga => image::ImageFormat::Tga,
|
||||
ImageFormat::Tiff => image::ImageFormat::Tiff,
|
||||
ImageFormat::WebP => image::ImageFormat::WebP,
|
||||
ImageFormat::Basis | ImageFormat::Ktx2 => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -423,6 +420,7 @@ pub trait TextureFormatPixelInfo {
|
|||
}
|
||||
|
||||
impl TextureFormatPixelInfo for TextureFormat {
|
||||
#[allow(clippy::match_same_arms)]
|
||||
fn pixel_info(&self) -> PixelInfo {
|
||||
let type_size = match self {
|
||||
// 8bit
|
||||
|
@ -634,62 +632,58 @@ impl CompressedImageFormats {
|
|||
|
||||
pub fn supports(&self, format: TextureFormat) -> bool {
|
||||
match format {
|
||||
TextureFormat::Bc1RgbaUnorm => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc1RgbaUnormSrgb => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc2RgbaUnorm => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc2RgbaUnormSrgb => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc3RgbaUnorm => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc3RgbaUnormSrgb => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc4RUnorm => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc4RSnorm => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc5RgUnorm => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc5RgSnorm => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc6hRgbUfloat => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc6hRgbSfloat => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc7RgbaUnorm => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Bc7RgbaUnormSrgb => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Etc2Rgb8Unorm => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::Etc2Rgb8UnormSrgb => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::Etc2Rgb8A1Unorm => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::Etc2Rgb8A1UnormSrgb => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::Etc2Rgba8Unorm => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::Etc2Rgba8UnormSrgb => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::EacR11Unorm => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::EacR11Snorm => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::EacRg11Unorm => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::EacRg11Snorm => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::Astc4x4RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc4x4RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc5x4RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc5x4RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc5x5RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc5x5RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc6x5RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc6x5RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc6x6RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc6x6RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc8x5RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc8x5RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc8x6RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc8x6RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc10x5RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc10x5RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc10x6RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc10x6RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc8x8RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc8x8RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc10x8RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc10x8RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc10x10RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc10x10RgbaUnormSrgb => {
|
||||
self.contains(CompressedImageFormats::ASTC_LDR)
|
||||
}
|
||||
TextureFormat::Astc12x10RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc12x10RgbaUnormSrgb => {
|
||||
self.contains(CompressedImageFormats::ASTC_LDR)
|
||||
}
|
||||
TextureFormat::Astc12x12RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR),
|
||||
TextureFormat::Astc12x12RgbaUnormSrgb => {
|
||||
TextureFormat::Bc1RgbaUnorm
|
||||
| TextureFormat::Bc1RgbaUnormSrgb
|
||||
| TextureFormat::Bc2RgbaUnorm
|
||||
| TextureFormat::Bc2RgbaUnormSrgb
|
||||
| TextureFormat::Bc3RgbaUnorm
|
||||
| TextureFormat::Bc3RgbaUnormSrgb
|
||||
| TextureFormat::Bc4RUnorm
|
||||
| TextureFormat::Bc4RSnorm
|
||||
| TextureFormat::Bc5RgUnorm
|
||||
| TextureFormat::Bc5RgSnorm
|
||||
| TextureFormat::Bc6hRgbUfloat
|
||||
| TextureFormat::Bc6hRgbSfloat
|
||||
| TextureFormat::Bc7RgbaUnorm
|
||||
| TextureFormat::Bc7RgbaUnormSrgb => self.contains(CompressedImageFormats::BC),
|
||||
TextureFormat::Etc2Rgb8Unorm
|
||||
| TextureFormat::Etc2Rgb8UnormSrgb
|
||||
| TextureFormat::Etc2Rgb8A1Unorm
|
||||
| TextureFormat::Etc2Rgb8A1UnormSrgb
|
||||
| TextureFormat::Etc2Rgba8Unorm
|
||||
| TextureFormat::Etc2Rgba8UnormSrgb
|
||||
| TextureFormat::EacR11Unorm
|
||||
| TextureFormat::EacR11Snorm
|
||||
| TextureFormat::EacRg11Unorm
|
||||
| TextureFormat::EacRg11Snorm => self.contains(CompressedImageFormats::ETC2),
|
||||
TextureFormat::Astc4x4RgbaUnorm
|
||||
| TextureFormat::Astc4x4RgbaUnormSrgb
|
||||
| TextureFormat::Astc5x4RgbaUnorm
|
||||
| TextureFormat::Astc5x4RgbaUnormSrgb
|
||||
| TextureFormat::Astc5x5RgbaUnorm
|
||||
| TextureFormat::Astc5x5RgbaUnormSrgb
|
||||
| TextureFormat::Astc6x5RgbaUnorm
|
||||
| TextureFormat::Astc6x5RgbaUnormSrgb
|
||||
| TextureFormat::Astc6x6RgbaUnorm
|
||||
| TextureFormat::Astc6x6RgbaUnormSrgb
|
||||
| TextureFormat::Astc8x5RgbaUnorm
|
||||
| TextureFormat::Astc8x5RgbaUnormSrgb
|
||||
| TextureFormat::Astc8x6RgbaUnorm
|
||||
| TextureFormat::Astc8x6RgbaUnormSrgb
|
||||
| TextureFormat::Astc10x5RgbaUnorm
|
||||
| TextureFormat::Astc10x5RgbaUnormSrgb
|
||||
| TextureFormat::Astc10x6RgbaUnorm
|
||||
| TextureFormat::Astc10x6RgbaUnormSrgb
|
||||
| TextureFormat::Astc8x8RgbaUnorm
|
||||
| TextureFormat::Astc8x8RgbaUnormSrgb
|
||||
| TextureFormat::Astc10x8RgbaUnorm
|
||||
| TextureFormat::Astc10x8RgbaUnormSrgb
|
||||
| TextureFormat::Astc10x10RgbaUnorm
|
||||
| TextureFormat::Astc10x10RgbaUnormSrgb
|
||||
| TextureFormat::Astc12x10RgbaUnorm
|
||||
| TextureFormat::Astc12x10RgbaUnormSrgb
|
||||
| TextureFormat::Astc12x12RgbaUnorm
|
||||
| TextureFormat::Astc12x12RgbaUnormSrgb => {
|
||||
self.contains(CompressedImageFormats::ASTC_LDR)
|
||||
}
|
||||
_ => true,
|
||||
|
|
|
@ -85,7 +85,7 @@ pub fn ktx2_buffer_to_image(
|
|||
TranscodeFormat::Rgb8 => {
|
||||
let (mut original_width, mut original_height) = (width, height);
|
||||
|
||||
for level_data in levels.iter() {
|
||||
for level_data in &levels {
|
||||
let n_pixels = (original_width * original_height) as usize;
|
||||
|
||||
let mut rgba = vec![255u8; n_pixels * 4];
|
||||
|
@ -766,25 +766,19 @@ pub fn ktx2_dfd_to_texture_format(
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(ColorModel::YUVSDA) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::YIQSDA) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::LabSDA) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::CMYKA) => {
|
||||
Some(ColorModel::YUVSDA)
|
||||
| Some(ColorModel::YIQSDA)
|
||||
| Some(ColorModel::LabSDA)
|
||||
| Some(ColorModel::CMYKA)
|
||||
| Some(ColorModel::HSVAAng)
|
||||
| Some(ColorModel::HSLAAng)
|
||||
| Some(ColorModel::HSVAHex)
|
||||
| Some(ColorModel::HSLAHex)
|
||||
| Some(ColorModel::YCgCoA)
|
||||
| Some(ColorModel::YcCbcCrc)
|
||||
| Some(ColorModel::ICtCp)
|
||||
| Some(ColorModel::CIEXYZ)
|
||||
| Some(ColorModel::CIEXYY) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
|
@ -897,60 +891,6 @@ pub fn ktx2_dfd_to_texture_format(
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(ColorModel::HSVAAng) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::HSLAAng) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::HSVAHex) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::HSLAHex) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::YCgCoA) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::YcCbcCrc) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::ICtCp) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::CIEXYZ) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::CIEXYY) => {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
data_format_descriptor.color_model
|
||||
)));
|
||||
}
|
||||
Some(ColorModel::BC1A) => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc1RgbaUnormSrgb
|
||||
|
@ -1281,53 +1221,31 @@ pub fn ktx2_format_to_texture_format(
|
|||
is_srgb: bool,
|
||||
) -> Result<TextureFormat, TextureError> {
|
||||
Ok(match ktx2_format {
|
||||
ktx2::Format::R8_UNORM => {
|
||||
ktx2::Format::R8_UNORM | ktx2::Format::R8_SRGB => {
|
||||
if is_srgb {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
ktx2_format
|
||||
)));
|
||||
} else {
|
||||
TextureFormat::R8Unorm
|
||||
}
|
||||
TextureFormat::R8Unorm
|
||||
}
|
||||
ktx2::Format::R8_SNORM => TextureFormat::R8Snorm,
|
||||
ktx2::Format::R8_UINT => TextureFormat::R8Uint,
|
||||
ktx2::Format::R8_SINT => TextureFormat::R8Sint,
|
||||
ktx2::Format::R8_SRGB => {
|
||||
ktx2::Format::R8G8_UNORM | ktx2::Format::R8G8_SRGB => {
|
||||
if is_srgb {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
ktx2_format
|
||||
)));
|
||||
} else {
|
||||
TextureFormat::R8Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::R8G8_UNORM => {
|
||||
if is_srgb {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
ktx2_format
|
||||
)));
|
||||
} else {
|
||||
TextureFormat::Rg8Unorm
|
||||
}
|
||||
TextureFormat::Rg8Unorm
|
||||
}
|
||||
ktx2::Format::R8G8_SNORM => TextureFormat::Rg8Snorm,
|
||||
ktx2::Format::R8G8_UINT => TextureFormat::Rg8Uint,
|
||||
ktx2::Format::R8G8_SINT => TextureFormat::Rg8Sint,
|
||||
ktx2::Format::R8G8_SRGB => {
|
||||
if is_srgb {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
"{:?}",
|
||||
ktx2_format
|
||||
)));
|
||||
} else {
|
||||
TextureFormat::Rg8Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::R8G8B8A8_UNORM => {
|
||||
ktx2::Format::R8G8B8A8_UNORM | ktx2::Format::R8G8B8A8_SRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Rgba8UnormSrgb
|
||||
} else {
|
||||
|
@ -1337,21 +1255,7 @@ pub fn ktx2_format_to_texture_format(
|
|||
ktx2::Format::R8G8B8A8_SNORM => TextureFormat::Rgba8Snorm,
|
||||
ktx2::Format::R8G8B8A8_UINT => TextureFormat::Rgba8Uint,
|
||||
ktx2::Format::R8G8B8A8_SINT => TextureFormat::Rgba8Sint,
|
||||
ktx2::Format::R8G8B8A8_SRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Rgba8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Rgba8Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::B8G8R8A8_UNORM => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bgra8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bgra8Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::B8G8R8A8_SRGB => {
|
||||
ktx2::Format::B8G8R8A8_UNORM | ktx2::Format::B8G8R8A8_SRGB => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bgra8UnormSrgb
|
||||
} else {
|
||||
|
@ -1395,56 +1299,24 @@ pub fn ktx2_format_to_texture_format(
|
|||
|
||||
ktx2::Format::D24_UNORM_S8_UINT => TextureFormat::Depth24PlusStencil8,
|
||||
|
||||
ktx2::Format::BC1_RGB_UNORM_BLOCK => {
|
||||
ktx2::Format::BC1_RGB_UNORM_BLOCK
|
||||
| ktx2::Format::BC1_RGB_SRGB_BLOCK
|
||||
| ktx2::Format::BC1_RGBA_UNORM_BLOCK
|
||||
| ktx2::Format::BC1_RGBA_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc1RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc1RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::BC1_RGB_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc1RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc1RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::BC1_RGBA_UNORM_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc1RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc1RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::BC1_RGBA_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc1RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc1RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::BC2_UNORM_BLOCK => {
|
||||
ktx2::Format::BC2_UNORM_BLOCK | ktx2::Format::BC2_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc2RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc2RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::BC2_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc2RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc2RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::BC3_UNORM_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc3RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc3RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::BC3_SRGB_BLOCK => {
|
||||
ktx2::Format::BC3_UNORM_BLOCK | ktx2::Format::BC3_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc3RgbaUnormSrgb
|
||||
} else {
|
||||
|
@ -1457,56 +1329,28 @@ pub fn ktx2_format_to_texture_format(
|
|||
ktx2::Format::BC5_SNORM_BLOCK => TextureFormat::Bc5RgSnorm,
|
||||
ktx2::Format::BC6H_UFLOAT_BLOCK => TextureFormat::Bc6hRgbUfloat,
|
||||
ktx2::Format::BC6H_SFLOAT_BLOCK => TextureFormat::Bc6hRgbSfloat,
|
||||
ktx2::Format::BC7_UNORM_BLOCK => {
|
||||
ktx2::Format::BC7_UNORM_BLOCK | ktx2::Format::BC7_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc7RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc7RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::BC7_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Bc7RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Bc7RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ETC2_R8G8B8_UNORM_BLOCK => {
|
||||
ktx2::Format::ETC2_R8G8B8_UNORM_BLOCK | ktx2::Format::ETC2_R8G8B8_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Etc2Rgb8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Etc2Rgb8Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ETC2_R8G8B8_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Etc2Rgb8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Etc2Rgb8Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ETC2_R8G8B8A1_UNORM_BLOCK => {
|
||||
ktx2::Format::ETC2_R8G8B8A1_UNORM_BLOCK | ktx2::Format::ETC2_R8G8B8A1_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Etc2Rgb8A1UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Etc2Rgb8A1Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ETC2_R8G8B8A1_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Etc2Rgb8A1UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Etc2Rgb8A1Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ETC2_R8G8B8A8_UNORM_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Etc2Rgba8UnormSrgb
|
||||
} else {
|
||||
TextureFormat::Etc2Rgba8Unorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ETC2_R8G8B8A8_SRGB_BLOCK => {
|
||||
ktx2::Format::ETC2_R8G8B8A8_UNORM_BLOCK | ktx2::Format::ETC2_R8G8B8A8_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Etc2Rgba8UnormSrgb
|
||||
} else {
|
||||
|
@ -1517,196 +1361,98 @@ pub fn ktx2_format_to_texture_format(
|
|||
ktx2::Format::EAC_R11_SNORM_BLOCK => TextureFormat::EacR11Snorm,
|
||||
ktx2::Format::EAC_R11G11_UNORM_BLOCK => TextureFormat::EacRg11Unorm,
|
||||
ktx2::Format::EAC_R11G11_SNORM_BLOCK => TextureFormat::EacRg11Snorm,
|
||||
ktx2::Format::ASTC_4x4_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_4x4_UNORM_BLOCK | ktx2::Format::ASTC_4x4_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc4x4RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc4x4RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_4x4_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc4x4RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc4x4RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_5x4_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_5x4_UNORM_BLOCK | ktx2::Format::ASTC_5x4_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc5x4RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc5x4RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_5x4_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc5x4RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc5x4RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_5x5_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_5x5_UNORM_BLOCK | ktx2::Format::ASTC_5x5_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc5x5RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc5x5RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_5x5_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc5x5RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc5x5RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_6x5_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_6x5_UNORM_BLOCK | ktx2::Format::ASTC_6x5_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc6x5RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc6x5RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_6x5_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc6x5RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc6x5RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_6x6_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_6x6_UNORM_BLOCK | ktx2::Format::ASTC_6x6_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc6x6RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc6x6RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_6x6_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc6x6RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc6x6RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_8x5_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_8x5_UNORM_BLOCK | ktx2::Format::ASTC_8x5_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc8x5RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc8x5RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_8x5_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc8x5RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc8x5RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_8x6_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_8x6_UNORM_BLOCK | ktx2::Format::ASTC_8x6_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc8x6RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc8x6RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_8x6_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc8x6RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc8x6RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_8x8_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_8x8_UNORM_BLOCK | ktx2::Format::ASTC_8x8_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc8x8RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc8x8RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_8x8_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc8x8RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc8x8RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_10x5_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_10x5_UNORM_BLOCK | ktx2::Format::ASTC_10x5_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc10x5RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc10x5RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_10x5_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc10x5RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc10x5RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_10x6_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_10x6_UNORM_BLOCK | ktx2::Format::ASTC_10x6_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc10x6RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc10x6RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_10x6_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc10x6RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc10x6RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_10x8_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_10x8_UNORM_BLOCK | ktx2::Format::ASTC_10x8_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc10x8RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc10x8RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_10x8_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc10x8RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc10x8RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_10x10_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_10x10_UNORM_BLOCK | ktx2::Format::ASTC_10x10_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc10x10RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc10x10RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_10x10_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc10x10RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc10x10RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_12x10_UNORM_BLOCK => {
|
||||
ktx2::Format::ASTC_12x10_UNORM_BLOCK | ktx2::Format::ASTC_12x10_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc12x10RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc12x10RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_12x10_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc12x10RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc12x10RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_12x12_UNORM_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc12x12RgbaUnormSrgb
|
||||
} else {
|
||||
TextureFormat::Astc12x12RgbaUnorm
|
||||
}
|
||||
}
|
||||
ktx2::Format::ASTC_12x12_SRGB_BLOCK => {
|
||||
ktx2::Format::ASTC_12x12_UNORM_BLOCK | ktx2::Format::ASTC_12x12_SRGB_BLOCK => {
|
||||
if is_srgb {
|
||||
TextureFormat::Astc12x12RgbaUnormSrgb
|
||||
} else {
|
||||
|
|
|
@ -111,11 +111,7 @@ pub struct ViewTarget {
|
|||
impl ViewTarget {
|
||||
pub fn get_color_attachment(&self, ops: Operations<Color>) -> RenderPassColorAttachment {
|
||||
RenderPassColorAttachment {
|
||||
view: if let Some(sampled_target) = &self.sampled_target {
|
||||
sampled_target
|
||||
} else {
|
||||
&self.view
|
||||
},
|
||||
view: self.sampled_target.as_ref().unwrap_or(&self.view),
|
||||
resolve_target: if self.sampled_target.is_some() {
|
||||
Some(&self.view)
|
||||
} else {
|
||||
|
|
|
@ -354,8 +354,9 @@ pub fn queue_sprites(
|
|||
for event in &events.images {
|
||||
match event {
|
||||
AssetEvent::Created { .. } => None,
|
||||
AssetEvent::Modified { handle } => image_bind_groups.values.remove(handle),
|
||||
AssetEvent::Removed { handle } => image_bind_groups.values.remove(handle),
|
||||
AssetEvent::Modified { handle } | AssetEvent::Removed { handle } => {
|
||||
image_bind_groups.values.remove(handle)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -501,10 +502,10 @@ pub fn queue_sprites(
|
|||
|
||||
// Store the vertex data and add the item to the render phase
|
||||
if current_batch.colored {
|
||||
for i in QUAD_INDICES.iter() {
|
||||
for i in QUAD_INDICES {
|
||||
sprite_meta.colored_vertices.push(ColoredSpriteVertex {
|
||||
position: positions[*i],
|
||||
uv: uvs[*i].into(),
|
||||
position: positions[i],
|
||||
uv: uvs[i].into(),
|
||||
color: extracted_sprite.color.as_linear_rgba_f32(),
|
||||
});
|
||||
}
|
||||
|
@ -520,10 +521,10 @@ pub fn queue_sprites(
|
|||
batch_range: Some(item_start..item_end),
|
||||
});
|
||||
} else {
|
||||
for i in QUAD_INDICES.iter() {
|
||||
for i in QUAD_INDICES {
|
||||
sprite_meta.vertices.push(SpriteVertex {
|
||||
position: positions[*i],
|
||||
uv: uvs[*i].into(),
|
||||
position: positions[i],
|
||||
uv: uvs[i].into(),
|
||||
});
|
||||
}
|
||||
let item_start = index;
|
||||
|
|
|
@ -127,7 +127,7 @@ pub fn extract_text2d_sprite(
|
|||
|
||||
/// Updates the layout and size information whenever the text or style is changed.
|
||||
/// This information is computed by the `TextPipeline` on insertion, then stored.
|
||||
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn update_text2d_layout(
|
||||
// Text items which should be reprocessed again, generally when the font hasn't loaded yet.
|
||||
mut queue: Local<HashSet<Entity>>,
|
||||
|
|
|
@ -198,7 +198,7 @@ pub enum FlexError {
|
|||
StretchError(stretch::Error),
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn flex_node_system(
|
||||
windows: Res<Windows>,
|
||||
mut scale_factor_events: EventReader<WindowScaleFactorChanged>,
|
||||
|
|
|
@ -57,7 +57,6 @@ pub struct State {
|
|||
}
|
||||
|
||||
/// The system that sets Interaction for all UI elements based on the mouse cursor activity
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn ui_focus_system(
|
||||
mut state: Local<State>,
|
||||
windows: Res<Windows>,
|
||||
|
|
|
@ -408,8 +408,9 @@ pub fn queue_uinodes(
|
|||
for event in &events.images {
|
||||
match event {
|
||||
AssetEvent::Created { .. } => None,
|
||||
AssetEvent::Modified { handle } => image_bind_groups.values.remove(handle),
|
||||
AssetEvent::Removed { handle } => image_bind_groups.values.remove(handle),
|
||||
AssetEvent::Modified { handle } | AssetEvent::Removed { handle } => {
|
||||
image_bind_groups.values.remove(handle)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -56,8 +56,7 @@ impl AddAssign<f32> for Val {
|
|||
fn add_assign(&mut self, rhs: f32) {
|
||||
match self {
|
||||
Val::Undefined | Val::Auto => {}
|
||||
Val::Px(value) => *value += rhs,
|
||||
Val::Percent(value) => *value += rhs,
|
||||
Val::Px(value) | Val::Percent(value) => *value += rhs,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,15 +27,16 @@ pub fn text_constraint(min_size: Val, size: Val, max_size: Val, scale_factor: f6
|
|||
match (min_size, size, max_size) {
|
||||
(_, _, Val::Px(max)) => scale_value(max, scale_factor),
|
||||
(Val::Px(min), _, _) => scale_value(min, scale_factor),
|
||||
(Val::Undefined, Val::Px(size), Val::Undefined) => scale_value(size, scale_factor),
|
||||
(Val::Auto, Val::Px(size), Val::Auto) => scale_value(size, scale_factor),
|
||||
(Val::Undefined, Val::Px(size), Val::Undefined) | (Val::Auto, Val::Px(size), Val::Auto) => {
|
||||
scale_value(size, scale_factor)
|
||||
}
|
||||
_ => f32::MAX,
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the layout and size information whenever the text or style is changed.
|
||||
/// This information is computed by the `TextPipeline` on insertion, then stored.
|
||||
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn text_system(
|
||||
mut queued_text: Local<QueuedText>,
|
||||
mut last_scale_factor: Local<f64>,
|
||||
|
|
|
@ -126,8 +126,7 @@ impl WinitWindows {
|
|||
|
||||
if window_descriptor.cursor_locked {
|
||||
match winit_window.set_cursor_grab(true) {
|
||||
Ok(_) => {}
|
||||
Err(winit::error::ExternalError::NotSupported(_)) => {}
|
||||
Ok(_) | Err(winit::error::ExternalError::NotSupported(_)) => {}
|
||||
Err(err) => Err(err).unwrap(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ fn setup(
|
|||
fn rotate(mut query: Query<&mut Transform, With<Shape>>, time: Res<Time>) {
|
||||
for mut transform in query.iter_mut() {
|
||||
transform.rotation = Quat::from_rotation_y(time.seconds_since_startup() as f32 / 2.)
|
||||
* Quat::from_rotation_x(-std::f32::consts::PI / 4.)
|
||||
* Quat::from_rotation_x(-std::f32::consts::PI / 4.);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@ fn pause(
|
|||
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||
if let Some(sink) = audio_sinks.get(&music_controller.0) {
|
||||
if sink.is_paused() {
|
||||
sink.play()
|
||||
sink.play();
|
||||
} else {
|
||||
sink.pause()
|
||||
sink.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,10 +128,12 @@ impl WallLocation {
|
|||
assert!(arena_width > 0.0);
|
||||
|
||||
match self {
|
||||
WallLocation::Left => Vec2::new(WALL_THICKNESS, arena_height + WALL_THICKNESS),
|
||||
WallLocation::Right => Vec2::new(WALL_THICKNESS, arena_height + WALL_THICKNESS),
|
||||
WallLocation::Bottom => Vec2::new(arena_width + WALL_THICKNESS, WALL_THICKNESS),
|
||||
WallLocation::Top => Vec2::new(arena_width + WALL_THICKNESS, WALL_THICKNESS),
|
||||
WallLocation::Left | WallLocation::Right => {
|
||||
Vec2::new(WALL_THICKNESS, arena_height + WALL_THICKNESS)
|
||||
}
|
||||
WallLocation::Bottom | WallLocation::Top => {
|
||||
Vec2::new(arena_width + WALL_THICKNESS, WALL_THICKNESS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -359,10 +359,9 @@ mod menu {
|
|||
) {
|
||||
for (interaction, mut color, selected) in interaction_query.iter_mut() {
|
||||
*color = match (*interaction, selected) {
|
||||
(Interaction::Clicked, _) => PRESSED_BUTTON.into(),
|
||||
(Interaction::Clicked, _) | (Interaction::None, Some(_)) => PRESSED_BUTTON.into(),
|
||||
(Interaction::Hovered, Some(_)) => HOVERED_PRESSED_BUTTON.into(),
|
||||
(Interaction::Hovered, None) => HOVERED_BUTTON.into(),
|
||||
(Interaction::None, Some(_)) => PRESSED_BUTTON.into(),
|
||||
(Interaction::None, None) => NORMAL_BUTTON.into(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(clippy::match_same_arms)]
|
||||
//! This example illustrates how reflection works for simple data structures, like
|
||||
//! structs, tuples and vectors.
|
||||
|
||||
|
|
|
@ -187,14 +187,14 @@ impl render_graph::Node for GameOfLifeNode {
|
|||
if let CachedPipelineState::Ok(_) =
|
||||
pipeline_cache.get_compute_pipeline_state(pipeline.init_pipeline)
|
||||
{
|
||||
self.state = GameOfLifeState::Init
|
||||
self.state = GameOfLifeState::Init;
|
||||
}
|
||||
}
|
||||
GameOfLifeState::Init => {
|
||||
if let CachedPipelineState::Ok(_) =
|
||||
pipeline_cache.get_compute_pipeline_state(pipeline.update_pipeline)
|
||||
{
|
||||
self.state = GameOfLifeState::Update
|
||||
self.state = GameOfLifeState::Update;
|
||||
}
|
||||
}
|
||||
GameOfLifeState::Update => {}
|
||||
|
|
|
@ -187,7 +187,7 @@ fn main() {
|
|||
.add_plugin(TransformPlugin::default())
|
||||
.add_startup_system(setup)
|
||||
.add_system(update)
|
||||
.run()
|
||||
.run();
|
||||
}
|
||||
|
||||
/// test configuration
|
||||
|
|
|
@ -16,6 +16,17 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
const CLIPPY_FLAGS: [&str; 8] = [
|
||||
"-Aclippy::type_complexity",
|
||||
"-Wclippy::doc_markdown",
|
||||
"-Wclippy::redundant_else",
|
||||
"-Wclippy::match_same_arms",
|
||||
"-Wclippy::semicolon_if_nothing_returned",
|
||||
"-Wclippy::explicit_iter_loop",
|
||||
"-Wclippy::map_flatten",
|
||||
"-Dwarnings",
|
||||
];
|
||||
|
||||
fn main() {
|
||||
// When run locally, results may differ from actual CI runs triggered by
|
||||
// .github/workflows/ci.yml
|
||||
|
@ -51,7 +62,10 @@ fn main() {
|
|||
if what_to_run.contains(Check::CLIPPY) {
|
||||
// See if clippy has any complaints.
|
||||
// - Type complexity must be ignored because we use huge templates for queries
|
||||
cmd!(sh, "cargo clippy --workspace --all-targets --all-features -- -A clippy::type_complexity -W clippy::doc_markdown -D warnings")
|
||||
cmd!(
|
||||
sh,
|
||||
"cargo clippy --workspace --all-targets --all-features -- {CLIPPY_FLAGS...}"
|
||||
)
|
||||
.run()
|
||||
.expect("Please fix clippy errors in output above.");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue