Skip to content

Commit

Permalink
Remove unused DepthCalculation enum (bevyengine#5684)
Browse files Browse the repository at this point in the history
# Objective

Remove unused `enum DepthCalculation` and its usages. This was used to compute visible entities in the [old renderer](https://github.com/bevyengine/bevy/blob/db665b96c07084f081b0c9ab367e67297fe35132/crates/bevy_render/src/camera/visible_entities.rs), but is now unused.

## Solution

`sed 's/DepthCalculation//g'`

---

## Changelog
### Changed
Removed `bevy_render::camera::DepthCalculation`.

## Migration Guide
Remove references to `bevy_render::camera::DepthCalculation`, such as `use bevy_render::camera::DepthCalculation`. Remove `depth_calculation` fields from Projections.
  • Loading branch information
contagnas committed Aug 14, 2022
1 parent e84e391 commit f1be89d
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 41 deletions.
5 changes: 1 addition & 4 deletions crates/bevy_core_pipeline/src/core_2d/camera_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::clear_color::ClearColorConfig;
use bevy_ecs::{prelude::*, query::QueryItem};
use bevy_reflect::Reflect;
use bevy_render::{
camera::{
Camera, CameraProjection, CameraRenderGraph, DepthCalculation, OrthographicProjection,
},
camera::{Camera, CameraProjection, CameraRenderGraph, OrthographicProjection},
extract_component::ExtractComponent,
primitives::Frustum,
view::VisibleEntities,
Expand Down Expand Up @@ -56,7 +54,6 @@ impl Camera2dBundle {
// the camera's translation by far and use a right handed coordinate system
let projection = OrthographicProjection {
far,
depth_calculation: DepthCalculation::ZDifference,
..Default::default()
};
let transform = Transform::from_xyz(0.0, 0.0, far - 0.1);
Expand Down
15 changes: 0 additions & 15 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use bevy_ecs::{
};
use bevy_math::{Mat4, UVec2, Vec2, Vec3};
use bevy_reflect::prelude::*;
use bevy_reflect::FromReflect;
use bevy_transform::components::GlobalTransform;
use bevy_utils::HashSet;
use bevy_window::{WindowCreated, WindowId, WindowResized, Windows};
Expand Down Expand Up @@ -82,8 +81,6 @@ pub struct Camera {
/// If this is set to true, this camera will be rendered to its specified [`RenderTarget`]. If false, this
/// camera will not be rendered.
pub is_active: bool,
/// The method used to calculate this camera's depth. This will be used for projections and visibility.
pub depth_calculation: DepthCalculation,
/// Computed values for this camera, such as the projection matrix and the render target size.
#[reflect(ignore)]
pub computed: ComputedCameraValues,
Expand All @@ -100,7 +97,6 @@ impl Default for Camera {
viewport: None,
computed: Default::default(),
target: Default::default(),
depth_calculation: Default::default(),
}
}
}
Expand Down Expand Up @@ -310,16 +306,6 @@ impl RenderTarget {
}
}

#[derive(Debug, Clone, Copy, Default, Reflect, FromReflect, Serialize, Deserialize)]
#[reflect(Serialize, Deserialize)]
pub enum DepthCalculation {
/// Pythagorean distance; works everywhere, more expensive to compute.
#[default]
Distance,
/// Optimization for 2D; assuming the camera points towards `-Z`.
ZDifference,
}

pub fn camera_system<T: CameraProjection + Component>(
mut window_resized_events: EventReader<WindowResized>,
mut window_created_events: EventReader<WindowCreated>,
Expand Down Expand Up @@ -378,7 +364,6 @@ pub fn camera_system<T: CameraProjection + Component>(
if let Some(size) = camera.logical_viewport_size() {
camera_projection.update(size.x, size.y);
camera.computed.projection_matrix = camera_projection.get_projection_matrix();
camera.depth_calculation = camera_projection.depth_calculation();
}
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_render/src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl Plugin for CameraPlugin {
.register_type::<VisibleEntities>()
.register_type::<WindowOrigin>()
.register_type::<ScalingMode>()
.register_type::<DepthCalculation>()
.register_type::<Aabb>()
.register_type::<CameraRenderGraph>()
.add_plugin(CameraProjectionPlugin::<Projection>::default())
Expand Down
19 changes: 0 additions & 19 deletions crates/bevy_render/src/camera/projection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::marker::PhantomData;

use super::DepthCalculation;
use bevy_app::{App, CoreStage, Plugin, StartupStage};
use bevy_ecs::{prelude::*, reflect::ReflectComponent};
use bevy_math::Mat4;
Expand Down Expand Up @@ -42,7 +41,6 @@ impl<T: CameraProjection + Component + GetTypeRegistration> Plugin for CameraPro
pub trait CameraProjection {
fn get_projection_matrix(&self) -> Mat4;
fn update(&mut self, width: f32, height: f32);
fn depth_calculation(&self) -> DepthCalculation;
fn far(&self) -> f32;
}

Expand Down Expand Up @@ -81,13 +79,6 @@ impl CameraProjection for Projection {
}
}

fn depth_calculation(&self) -> DepthCalculation {
match self {
Projection::Perspective(projection) => projection.depth_calculation(),
Projection::Orthographic(projection) => projection.depth_calculation(),
}
}

fn far(&self) -> f32 {
match self {
Projection::Perspective(projection) => projection.far(),
Expand Down Expand Up @@ -120,10 +111,6 @@ impl CameraProjection for PerspectiveProjection {
self.aspect_ratio = width / height;
}

fn depth_calculation(&self) -> DepthCalculation {
DepthCalculation::Distance
}

fn far(&self) -> f32 {
self.far
}
Expand Down Expand Up @@ -179,7 +166,6 @@ pub struct OrthographicProjection {
pub window_origin: WindowOrigin,
pub scaling_mode: ScalingMode,
pub scale: f32,
pub depth_calculation: DepthCalculation,
}

impl CameraProjection for OrthographicProjection {
Expand Down Expand Up @@ -245,10 +231,6 @@ impl CameraProjection for OrthographicProjection {
}
}

fn depth_calculation(&self) -> DepthCalculation {
self.depth_calculation
}

fn far(&self) -> f32 {
self.far
}
Expand All @@ -266,7 +248,6 @@ impl Default for OrthographicProjection {
window_origin: WindowOrigin::Center,
scaling_mode: ScalingMode::WindowSize,
scale: 1.0,
depth_calculation: DepthCalculation::Distance,
}
}
}
3 changes: 1 addition & 2 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bevy_ecs::prelude::*;
use bevy_math::{Mat4, Vec2, Vec3, Vec4Swizzles};
use bevy_reflect::TypeUuid;
use bevy_render::{
camera::{Camera, CameraProjection, DepthCalculation, OrthographicProjection, WindowOrigin},
camera::{Camera, CameraProjection, OrthographicProjection, WindowOrigin},
color::Color,
render_asset::RenderAssets,
render_graph::{RenderGraph, RunGraphOnViewNode, SlotInfo, SlotType},
Expand Down Expand Up @@ -245,7 +245,6 @@ pub fn extract_default_ui_camera_view<T: Component>(
let mut projection = OrthographicProjection {
far: UI_CAMERA_FAR,
window_origin: WindowOrigin::BottomLeft,
depth_calculation: DepthCalculation::ZDifference,
..Default::default()
};
projection.update(logical_size.x, logical_size.y);
Expand Down

0 comments on commit f1be89d

Please sign in to comment.