Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to u32 indices by default #572

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use bevy_render::{

use anyhow::Result;
use bevy_asset::AssetLoader;
use gltf::{
buffer::Source,
mesh::{util::ReadIndices, Mode},
};
use gltf::{buffer::Source, mesh::Mode};
use std::{fs, io, path::Path};
use thiserror::Error;

Expand Down Expand Up @@ -101,12 +98,8 @@ fn load_node(buffer_data: &[Vec<u8>], node: &gltf::Node, depth: i32) -> Result<M
}

if let Some(indices) = reader.read_indices() {
mesh.indices = match indices {
ReadIndices::U8(iter) => Some(Indices::U16(iter.map(|i| i as u16).collect())),
ReadIndices::U16(iter) => Some(Indices::U16(iter.collect())),
ReadIndices::U32(iter) => Some(Indices::U32(iter.collect())),
}
};
mesh.indices = Some(Indices::U32(indices.into_u32().collect()));
}

return Ok(mesh);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/src/mesh/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub mod shape {
uvs.push(*uv);
}

let indices = Indices::U16(vec![
let indices = Indices::U32(vec![
0, 1, 2, 2, 3, 0, // top
4, 5, 6, 6, 7, 4, // bottom
8, 9, 10, 10, 11, 8, // right
Expand Down Expand Up @@ -333,7 +333,7 @@ pub mod shape {
]
};

let indices = Indices::U16(vec![0, 2, 1, 0, 3, 2]);
let indices = Indices::U32(vec![0, 2, 1, 0, 3, 2]);

let mut positions = Vec::new();
let mut normals = Vec::new();
Expand Down Expand Up @@ -373,7 +373,7 @@ pub mod shape {
([-extent, 0.0, -extent], [0.0, 1.0, 0.0], [0.0, 1.0]),
];

let indices = Indices::U16(vec![0, 2, 1, 0, 3, 2]);
let indices = Indices::U32(vec![0, 2, 1, 0, 3, 2]);

let mut positions = Vec::new();
let mut normals = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/pipeline/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl PipelineDescriptor {
shader_stages,
rasterization_state: None,
primitive_topology: PrimitiveTopology::TriangleList,
index_format: IndexFormat::Uint16,
index_format: IndexFormat::Uint32,
sample_count: 1,
sample_mask: !0,
alpha_to_coverage_enabled: false,
Expand All @@ -67,7 +67,7 @@ impl PipelineDescriptor {
name: None,
primitive_topology: PrimitiveTopology::TriangleList,
layout: None,
index_format: IndexFormat::Uint16,
index_format: IndexFormat::Uint32,
sample_count: 1,
sample_mask: !0,
alpha_to_coverage_enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/pipeline/pipeline_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Default for PipelineSpecialization {
shader_specialization: Default::default(),
primitive_topology: Default::default(),
dynamic_bindings: Default::default(),
index_format: IndexFormat::Uint16,
index_format: IndexFormat::Uint32,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/pipeline/render_pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn draw_render_pipelines_system(
let (index_range, index_format) = match mesh.indices.as_ref() {
Some(Indices::U32(indices)) => (Some(0..indices.len() as u32), IndexFormat::Uint32),
Some(Indices::U16(indices)) => (Some(0..indices.len() as u32), IndexFormat::Uint16),
None => (None, IndexFormat::Uint16),
None => (None, IndexFormat::Uint32),
};

let render_pipelines = &mut *render_pipelines;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/pipeline/state_descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,6 @@ pub enum IndexFormat {

impl Default for IndexFormat {
fn default() -> Self {
IndexFormat::Uint16
IndexFormat::Uint32
}
}