[oden] Correct circle layout to fix colors

This commit is contained in:
John Doty 2023-08-26 11:12:02 -07:00
parent 106db89e9b
commit 2322493efd
2 changed files with 24 additions and 19 deletions

View file

@ -8,11 +8,11 @@ struct VertexInput {
}; };
struct InstanceInput { struct InstanceInput {
@location(4) center: vec2<f32>, @location(5) center: vec2<f32>,
@location(5) radius: f32, @location(6) radius: f32,
@location(6) stroke_width: f32, @location(7) stroke_width: f32,
@location(7) stroke_color: vec4<f32>, @location(8) stroke_color: vec4<f32>,
@location(8) fill_color: vec4<f32>, @location(9) fill_color: vec4<f32>,
}; };
struct VertexOutput { struct VertexOutput {

View file

@ -26,7 +26,7 @@ struct Vertex {
impl Vertex { impl Vertex {
fn desc() -> wgpu::VertexBufferLayout<'static> { fn desc() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout { wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress, array_stride: std::mem::size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex, step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[ attributes: &[
wgpu::VertexAttribute { wgpu::VertexAttribute {
@ -57,7 +57,7 @@ pub struct SpriteInstance {
impl SpriteInstance { impl SpriteInstance {
fn desc() -> wgpu::VertexBufferLayout<'static> { fn desc() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout { wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<SpriteInstance>() as wgpu::BufferAddress, array_stride: std::mem::size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Instance, step_mode: wgpu::VertexStepMode::Instance,
attributes: &[ attributes: &[
wgpu::VertexAttribute { wgpu::VertexAttribute {
@ -98,40 +98,45 @@ pub struct CircleInstance {
impl CircleInstance { impl CircleInstance {
fn desc() -> wgpu::VertexBufferLayout<'static> { fn desc() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout { wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<SpriteInstance>() as wgpu::BufferAddress, array_stride: std::mem::size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Instance, step_mode: wgpu::VertexStepMode::Instance,
attributes: &[ attributes: &[
wgpu::VertexAttribute { wgpu::VertexAttribute {
// center
offset: 0, offset: 0,
shader_location: 4, shader_location: 5,
format: wgpu::VertexFormat::Float32x2, format: wgpu::VertexFormat::Float32x2,
}, },
wgpu::VertexAttribute { wgpu::VertexAttribute {
// radius
offset: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress, offset: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress,
shader_location: 5,
format: wgpu::VertexFormat::Float32,
},
wgpu::VertexAttribute {
offset: (std::mem::size_of::<[f32; 2]>() + std::mem::size_of::<f32>())
as wgpu::BufferAddress,
shader_location: 6, shader_location: 6,
format: wgpu::VertexFormat::Float32, format: wgpu::VertexFormat::Float32,
}, },
wgpu::VertexAttribute { wgpu::VertexAttribute {
// stroke_width
offset: (std::mem::size_of::<[f32; 2]>() + std::mem::size_of::<f32>())
as wgpu::BufferAddress,
shader_location: 7,
format: wgpu::VertexFormat::Float32,
},
wgpu::VertexAttribute {
// stroke_color
offset: (std::mem::size_of::<[f32; 2]>() offset: (std::mem::size_of::<[f32; 2]>()
+ std::mem::size_of::<f32>() + std::mem::size_of::<f32>()
+ std::mem::size_of::<f32>()) + std::mem::size_of::<f32>())
as wgpu::BufferAddress, as wgpu::BufferAddress,
shader_location: 7, shader_location: 8,
format: wgpu::VertexFormat::Float32x4, format: wgpu::VertexFormat::Float32x4,
}, },
wgpu::VertexAttribute { wgpu::VertexAttribute {
// fill_color
offset: (std::mem::size_of::<[f32; 2]>() offset: (std::mem::size_of::<[f32; 2]>()
+ std::mem::size_of::<f32>() + std::mem::size_of::<f32>()
+ std::mem::size_of::<f32>() + std::mem::size_of::<f32>()
+ std::mem::size_of::<[f32; 4]>()) + std::mem::size_of::<[f32; 4]>())
as wgpu::BufferAddress, as wgpu::BufferAddress,
shader_location: 8, shader_location: 9,
format: wgpu::VertexFormat::Float32x4, format: wgpu::VertexFormat::Float32x4,
}, },
], ],
@ -180,7 +185,7 @@ impl WindowAndDevice {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// Backends::all => Vulkan + Metal + DX12 + Browser WebGPU // Backends::all => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::all(), backends: wgpu::Backends::all() & !wgpu::Backends::VULKAN,
dx12_shader_compiler: Default::default(), dx12_shader_compiler: Default::default(),
}); });
@ -489,7 +494,7 @@ impl State {
let circle_pipeline_layout = let circle_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Sprite Pipeline Layout"), label: Some("Circle Pipeline Layout"),
bind_group_layouts: &[&screen_uniform_bind_group_layout], bind_group_layouts: &[&screen_uniform_bind_group_layout],
push_constant_ranges: &[], push_constant_ranges: &[],
}); });