move camera_uniforms and skybox_texture

This commit is contained in:
Quaternions 2023-09-20 16:58:56 -07:00
parent fb4a5efa14
commit 91f6a5261f

View File

@ -390,11 +390,77 @@ impl strafe_client::framework::Example for GraphicsData {
hitbox_halfsize: glam::vec3(1.0,2.5,1.0), hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
}; };
let camera_uniforms = camera.to_uniform_data(physics.body.extrapolated_position(0)); let device_features = device.features();
let camera_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Camera"), let skybox_format = if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC) {
contents: bytemuck::cast_slice(&camera_uniforms), log::info!("Using ASTC");
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, wgpu::TextureFormat::Astc {
block: AstcBlock::B4x4,
channel: AstcChannel::UnormSrgb,
}
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) {
log::info!("Using ETC2");
wgpu::TextureFormat::Etc2Rgb8UnormSrgb
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) {
log::info!("Using BC");
wgpu::TextureFormat::Bc1RgbaUnormSrgb
} else {
log::info!("Using plain");
wgpu::TextureFormat::Bgra8UnormSrgb
};
let size = wgpu::Extent3d {
width: IMAGE_SIZE,
height: IMAGE_SIZE,
depth_or_array_layers: 6,
};
let layer_size = wgpu::Extent3d {
depth_or_array_layers: 1,
..size
};
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
log::debug!(
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
skybox_format,
IMAGE_SIZE,
IMAGE_SIZE,
max_mips,
);
let bytes = match skybox_format {
wgpu::TextureFormat::Astc {
block: AstcBlock::B4x4,
channel: AstcChannel::UnormSrgb,
} => &include_bytes!("../images/astc.dds")[..],
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => &include_bytes!("../images/etc2.dds")[..],
wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("../images/bc1.dds")[..],
wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("../images/bgra.dds")[..],
_ => unreachable!(),
};
let skybox_image = ddsfile::Dds::read(&mut std::io::Cursor::new(&bytes)).unwrap();
let skybox_texture = device.create_texture_with_data(
queue,
&wgpu::TextureDescriptor {
size,
mip_level_count: max_mips,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: skybox_format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("Skybox Texture"),
view_formats: &[],
},
&skybox_image.data,
);
let skybox_texture_view = skybox_texture.create_view(&wgpu::TextureViewDescriptor {
label: Some("Skybox Texture View"),
dimension: Some(wgpu::TextureViewDimension::Cube),
..wgpu::TextureViewDescriptor::default()
}); });
//drain the modeldata vec so entities can be /moved/ to models.entities //drain the modeldata vec so entities can be /moved/ to models.entities
@ -504,79 +570,12 @@ impl strafe_client::framework::Example for GraphicsData {
multiview: None, multiview: None,
}); });
let device_features = device.features(); let camera_uniforms = camera.to_uniform_data(physics.body.extrapolated_position(0));
let camera_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
let skybox_format = if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC) { label: Some("Camera"),
log::info!("Using ASTC"); contents: bytemuck::cast_slice(&camera_uniforms),
wgpu::TextureFormat::Astc { usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
block: AstcBlock::B4x4,
channel: AstcChannel::UnormSrgb,
}
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) {
log::info!("Using ETC2");
wgpu::TextureFormat::Etc2Rgb8UnormSrgb
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) {
log::info!("Using BC");
wgpu::TextureFormat::Bc1RgbaUnormSrgb
} else {
log::info!("Using plain");
wgpu::TextureFormat::Bgra8UnormSrgb
};
let size = wgpu::Extent3d {
width: IMAGE_SIZE,
height: IMAGE_SIZE,
depth_or_array_layers: 6,
};
let layer_size = wgpu::Extent3d {
depth_or_array_layers: 1,
..size
};
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
log::debug!(
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
skybox_format,
IMAGE_SIZE,
IMAGE_SIZE,
max_mips,
);
let bytes = match skybox_format {
wgpu::TextureFormat::Astc {
block: AstcBlock::B4x4,
channel: AstcChannel::UnormSrgb,
} => &include_bytes!("../images/astc.dds")[..],
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => &include_bytes!("../images/etc2.dds")[..],
wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("../images/bc1.dds")[..],
wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("../images/bgra.dds")[..],
_ => unreachable!(),
};
let skybox_image = ddsfile::Dds::read(&mut std::io::Cursor::new(&bytes)).unwrap();
let skybox_texture = device.create_texture_with_data(
queue,
&wgpu::TextureDescriptor {
size,
mip_level_count: max_mips,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: skybox_format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("Skybox Texture"),
view_formats: &[],
},
&skybox_image.data,
);
let skybox_texture_view = skybox_texture.create_view(&wgpu::TextureViewDescriptor {
label: Some("Skybox Texture View"),
dimension: Some(wgpu::TextureViewDimension::Cube),
..wgpu::TextureViewDescriptor::default()
}); });
let camera_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { let camera_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &camera_bind_group_layout, layout: &camera_bind_group_layout,
entries: &[ entries: &[