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