Skip to content

Commit

Permalink
Merge branch 'main' into interpolate-tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
mweatherley committed Oct 15, 2024
2 parents 6b332b7 + a09104b commit 359f79d
Show file tree
Hide file tree
Showing 17 changed files with 783 additions and 395 deletions.
141 changes: 0 additions & 141 deletions crates/bevy_image/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,147 +78,6 @@ macro_rules! feature_gate {
}

impl ImageFormat {
/// Number of image formats, used for computing other constants.
const COUNT: usize = {
let mut count = 0;
#[cfg(feature = "avif")]
{
count += 1;
}
#[cfg(feature = "basis-universal")]
{
count += 1;
}
#[cfg(feature = "bmp")]
{
count += 1;
}
#[cfg(feature = "dds")]
{
count += 1;
}
#[cfg(feature = "ff")]
{
count += 1;
}
#[cfg(feature = "gif")]
{
count += 1;
}
#[cfg(feature = "exr")]
{
count += 1;
}
#[cfg(feature = "hdr")]
{
count += 1;
}
#[cfg(feature = "ico")]
{
count += 1;
}
#[cfg(feature = "jpeg")]
{
count += 1;
}
#[cfg(feature = "ktx2")]
{
count += 1;
}
#[cfg(feature = "pnm")]
{
count += 1;
}
#[cfg(feature = "png")]
{
count += 1;
}
#[cfg(feature = "qoi")]
{
count += 1;
}
#[cfg(feature = "tga")]
{
count += 1;
}
#[cfg(feature = "tiff")]
{
count += 1;
}
#[cfg(feature = "webp")]
{
count += 1;
}
count
};

/// Full list of supported formats.
pub const SUPPORTED: &'static [ImageFormat] = &[
#[cfg(feature = "avif")]
ImageFormat::Avif,
#[cfg(feature = "basis-universal")]
ImageFormat::Basis,
#[cfg(feature = "bmp")]
ImageFormat::Bmp,
#[cfg(feature = "dds")]
ImageFormat::Dds,
#[cfg(feature = "ff")]
ImageFormat::Farbfeld,
#[cfg(feature = "gif")]
ImageFormat::Gif,
#[cfg(feature = "exr")]
ImageFormat::OpenExr,
#[cfg(feature = "hdr")]
ImageFormat::Hdr,
#[cfg(feature = "ico")]
ImageFormat::Ico,
#[cfg(feature = "jpeg")]
ImageFormat::Jpeg,
#[cfg(feature = "ktx2")]
ImageFormat::Ktx2,
#[cfg(feature = "png")]
ImageFormat::Png,
#[cfg(feature = "pnm")]
ImageFormat::Pnm,
#[cfg(feature = "qoi")]
ImageFormat::Qoi,
#[cfg(feature = "tga")]
ImageFormat::Tga,
#[cfg(feature = "tiff")]
ImageFormat::Tiff,
#[cfg(feature = "webp")]
ImageFormat::WebP,
];

/// Total count of file extensions, for computing supported file extensions list.
const COUNT_FILE_EXTENSIONS: usize = {
let mut count = 0;
let mut idx = 0;
while idx < ImageFormat::COUNT {
count += ImageFormat::SUPPORTED[idx].to_file_extensions().len();
idx += 1;
}
count
};

/// Gets the list of file extensions for all formats.
pub const SUPPORTED_FILE_EXTENSIONS: &'static [&'static str] = &{
let mut exts = [""; ImageFormat::COUNT_FILE_EXTENSIONS];
let mut ext_idx = 0;
let mut fmt_idx = 0;
while fmt_idx < ImageFormat::COUNT {
let mut off = 0;
let fmt_exts = ImageFormat::SUPPORTED[fmt_idx].to_file_extensions();
while off < fmt_exts.len() {
exts[ext_idx] = fmt_exts[off];
off += 1;
ext_idx += 1;
}
fmt_idx += 1;
}
exts
};

/// Gets the file extensions for a given format.
pub const fn to_file_extensions(&self) -> &'static [&'static str] {
match self {
Expand Down
131 changes: 130 additions & 1 deletion crates/bevy_image/src/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,135 @@ pub struct ImageLoader {
}

impl ImageLoader {
/// Number of image formats, used for computing other constants.
const COUNT: usize = {
let mut count = 0;
#[cfg(feature = "avif")]
{
count += 1;
}
#[cfg(feature = "basis-universal")]
{
count += 1;
}
#[cfg(feature = "bmp")]
{
count += 1;
}
#[cfg(feature = "dds")]
{
count += 1;
}
#[cfg(feature = "ff")]
{
count += 1;
}
#[cfg(feature = "gif")]
{
count += 1;
}
#[cfg(feature = "ico")]
{
count += 1;
}
#[cfg(feature = "jpeg")]
{
count += 1;
}
#[cfg(feature = "ktx2")]
{
count += 1;
}
#[cfg(feature = "pnm")]
{
count += 1;
}
#[cfg(feature = "png")]
{
count += 1;
}
#[cfg(feature = "qoi")]
{
count += 1;
}
#[cfg(feature = "tga")]
{
count += 1;
}
#[cfg(feature = "tiff")]
{
count += 1;
}
#[cfg(feature = "webp")]
{
count += 1;
}
count
};

/// Full list of supported formats.
pub const SUPPORTED_FORMATS: &'static [ImageFormat] = &[
#[cfg(feature = "avif")]
ImageFormat::Avif,
#[cfg(feature = "basis-universal")]
ImageFormat::Basis,
#[cfg(feature = "bmp")]
ImageFormat::Bmp,
#[cfg(feature = "dds")]
ImageFormat::Dds,
#[cfg(feature = "ff")]
ImageFormat::Farbfeld,
#[cfg(feature = "gif")]
ImageFormat::Gif,
#[cfg(feature = "ico")]
ImageFormat::Ico,
#[cfg(feature = "jpeg")]
ImageFormat::Jpeg,
#[cfg(feature = "ktx2")]
ImageFormat::Ktx2,
#[cfg(feature = "png")]
ImageFormat::Png,
#[cfg(feature = "pnm")]
ImageFormat::Pnm,
#[cfg(feature = "qoi")]
ImageFormat::Qoi,
#[cfg(feature = "tga")]
ImageFormat::Tga,
#[cfg(feature = "tiff")]
ImageFormat::Tiff,
#[cfg(feature = "webp")]
ImageFormat::WebP,
];

/// Total count of file extensions, for computing supported file extensions list.
const COUNT_FILE_EXTENSIONS: usize = {
let mut count = 0;
let mut idx = 0;
while idx < Self::COUNT {
count += Self::SUPPORTED_FORMATS[idx].to_file_extensions().len();
idx += 1;
}
count
};

/// Gets the list of file extensions for all formats.
pub const SUPPORTED_FILE_EXTENSIONS: &'static [&'static str] = &{
let mut exts = [""; Self::COUNT_FILE_EXTENSIONS];
let mut ext_idx = 0;
let mut fmt_idx = 0;
while fmt_idx < Self::COUNT {
let mut off = 0;
let fmt_exts = Self::SUPPORTED_FORMATS[fmt_idx].to_file_extensions();
while off < fmt_exts.len() {
exts[ext_idx] = fmt_exts[off];
off += 1;
ext_idx += 1;
}
fmt_idx += 1;
}
exts
};

/// Creates a new image loader that supports the provided formats.
pub fn new(supported_compressed_formats: CompressedImageFormats) -> Self {
Self {
Expand Down Expand Up @@ -105,7 +234,7 @@ impl AssetLoader for ImageLoader {
}

fn extensions(&self) -> &[&str] {
ImageFormat::SUPPORTED_FILE_EXTENSIONS
Self::SUPPORTED_FILE_EXTENSIONS
}
}

Expand Down
13 changes: 3 additions & 10 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,13 @@ impl Plugin for PbrPlugin {
app.add_plugins(DeferredPbrLightingPlugin);
}

// Initialize the default material.
// Initialize the default material handle.
app.world_mut()
.resource_mut::<Assets<StandardMaterial>>()
.insert(
&Handle::<StandardMaterial>::default(),
StandardMaterial {
base_color: Color::WHITE,
base_color: Color::srgb(1.0, 0.0, 0.5),
..Default::default()
},
);
Expand All @@ -439,14 +439,7 @@ impl Plugin for PbrPlugin {

// Extract the required data from the main world
render_app
.add_systems(
ExtractSchedule,
(
extract_clusters,
extract_lights,
extract_default_materials.after(clear_material_instances::<StandardMaterial>),
),
)
.add_systems(ExtractSchedule, (extract_clusters, extract_lights))
.add_systems(
Render,
(
Expand Down
26 changes: 3 additions & 23 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ where
fn build(&self, app: &mut App) {
app.init_asset::<M>()
.register_type::<MeshMaterial3d<M>>()
.register_type::<HasMaterial3d>()
.add_plugins(RenderAssetPlugin::<PreparedMaterial<M>>::default());

if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
Expand All @@ -283,10 +282,7 @@ where
.add_render_command::<Opaque3d, DrawMaterial<M>>()
.add_render_command::<AlphaMask3d, DrawMaterial<M>>()
.init_resource::<SpecializedMeshPipelines<MaterialPipeline<M>>>()
.add_systems(
ExtractSchedule,
(clear_material_instances::<M>, extract_mesh_materials::<M>).chain(),
)
.add_systems(ExtractSchedule, extract_mesh_materials::<M>)
.add_systems(
Render,
queue_material_meshes::<M>
Expand Down Expand Up @@ -550,35 +546,19 @@ pub const fn screen_space_specular_transmission_pipeline_key(
}
}

pub(super) fn clear_material_instances<M: Material>(
mut material_instances: ResMut<RenderMaterialInstances<M>>,
) {
material_instances.clear();
}

fn extract_mesh_materials<M: Material>(
mut material_instances: ResMut<RenderMaterialInstances<M>>,
query: Extract<Query<(Entity, &ViewVisibility, &MeshMaterial3d<M>)>>,
) {
material_instances.clear();

for (entity, view_visibility, material) in &query {
if view_visibility.get() {
material_instances.insert(entity.into(), material.id());
}
}
}

/// Extracts default materials for 3D meshes with no [`MeshMaterial3d`].
pub(super) fn extract_default_materials(
mut material_instances: ResMut<RenderMaterialInstances<StandardMaterial>>,
query: Extract<Query<(Entity, &ViewVisibility), (With<Mesh3d>, Without<HasMaterial3d>)>>,
) {
for (entity, view_visibility) in &query {
if view_visibility.get() {
material_instances.insert(entity.into(), AssetId::default());
}
}
}

/// For each view, iterates over all the meshes visible from that view and adds
/// them to [`BinnedRenderPhase`]s or [`SortedRenderPhase`]s as appropriate.
#[allow(clippy::too_many_arguments)]
Expand Down
Loading

0 comments on commit 359f79d

Please sign in to comment.