bevy_camera/clear_color.rs
1use bevy_color::Color;
2use bevy_derive::{Deref, DerefMut};
3use bevy_ecs::prelude::*;
4use bevy_reflect::prelude::*;
5use derive_more::derive::From;
6use serde::{Deserialize, Serialize};
7
8/// For a camera, specifies the color used to clear the viewport
9/// [before rendering](crate::camera::Camera::clear_color)
10/// or when [writing to the final render target texture](crate::camera::Camera::output_mode).
11#[derive(Reflect, Serialize, Deserialize, Copy, Clone, Debug, Default, From)]
12#[reflect(Serialize, Deserialize, Default, Clone)]
13pub enum ClearColorConfig {
14 /// The clear color is taken from the world's [`ClearColor`] resource.
15 #[default]
16 Default,
17 /// The given clear color is used, overriding the [`ClearColor`] resource defined in the world.
18 Custom(Color),
19 /// No clear color is used: the camera will simply draw on top of anything already in the viewport.
20 ///
21 /// This can be useful when multiple cameras are rendering to the same viewport.
22 None,
23}
24
25/// A [`Resource`] that stores the default color that cameras use to clear the screen between frames.
26///
27/// This color appears as the "background" color for simple apps,
28/// when there are portions of the screen with nothing rendered.
29///
30/// Individual cameras may use [`Camera.clear_color`] to specify a different
31/// clear color or opt out of clearing their viewport.
32///
33/// [`Camera.clear_color`]: crate::camera::Camera::clear_color
34#[derive(Resource, Clone, Debug, Deref, DerefMut, Reflect)]
35#[reflect(Resource, Default, Debug, Clone)]
36pub struct ClearColor(pub Color);
37
38/// Match the dark gray bevy website code block color by default.
39impl Default for ClearColor {
40 fn default() -> Self {
41 Self(Color::srgb_u8(43, 44, 47))
42 }
43}