Skip to content

Commit

Permalink
Fix #395 panic when picking on mesh with color (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
asny committed Oct 7, 2023
1 parent 3e3d011 commit 35d94ba
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/renderer/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,10 @@ impl BaseMesh {
);
}

if let Some(colors) = &self.colors {
program.use_vertex_attribute("color", colors);
if attributes.color {
if let Some(colors) = &self.colors {
program.use_vertex_attribute("color", colors);
}
}
}
}
12 changes: 6 additions & 6 deletions src/renderer/geometry/instanced_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ impl Geometry for InstancedMesh {
} else {
""
},
if self.base_mesh.colors.is_some() {
if required_attributes.color && self.base_mesh.colors.is_some() {
"#define USE_VERTEX_COLORS\n"
} else {
""
},
if instance_buffers.contains_key("instance_color") {
if required_attributes.color && instance_buffers.contains_key("instance_color") {
"#define USE_INSTANCE_COLORS\n"
} else {
""
Expand All @@ -298,7 +298,7 @@ impl Geometry for InstancedMesh {
} else {
"#define USE_INSTANCE_TRANSFORMS\n"
},
if instance_buffers.contains_key("tex_transform_row1") {
if required_attributes.uv && instance_buffers.contains_key("tex_transform_row1") {
"#define USE_INSTANCE_TEXTURE_TRANSFORMATION\n"
} else {
""
Expand All @@ -324,16 +324,16 @@ impl Geometry for InstancedMesh {
if required_attributes.uv {
id |= 0b1u16 << 2;
}
if self.base_mesh.colors.is_some() {
if required_attributes.color && self.base_mesh.colors.is_some() {
id |= 0b1u16 << 3;
}
if instance_buffers.contains_key("instance_color") {
if required_attributes.color && instance_buffers.contains_key("instance_color") {
id |= 0b1u16 << 4;
}
if instance_buffers.contains_key("instance_translation") {
id |= 0b1u16 << 5;
}
if instance_buffers.contains_key("tex_transform_row1") {
if required_attributes.uv && instance_buffers.contains_key("tex_transform_row1") {
id |= 0b1u16 << 6;
}
id
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/geometry/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Geometry for Mesh {
} else {
""
},
if self.base_mesh.colors.is_some() {
if required_attributes.color && self.base_mesh.colors.is_some() {
"#define USE_VERTEX_COLORS\n"
} else {
""
Expand All @@ -163,7 +163,7 @@ impl Geometry for Mesh {
if required_attributes.uv {
id |= 0b1u16 << 2;
}
if self.base_mesh.colors.is_some() {
if required_attributes.color && self.base_mesh.colors.is_some() {
id |= 0b1u16 << 3;
}
id
Expand Down
23 changes: 11 additions & 12 deletions src/renderer/geometry/particles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,21 @@ impl Geometry for ParticleSystem {
if required_attributes.uv {
id |= 0b1u16 << 2;
}
if self.base_mesh.colors.is_some() {
if required_attributes.color && self.base_mesh.colors.is_some() {
id |= 0b1u16 << 3;
}
if self.instance_buffers.contains_key("instance_color") {
if required_attributes.color && self.instance_buffers.contains_key("instance_color") {
id |= 0b1u16 << 4;
}
if self.instance_buffers.contains_key("tex_transform_row1") {
if required_attributes.uv && self.instance_buffers.contains_key("tex_transform_row1") {
id |= 0b1u16 << 5;
}
id
}

fn vertex_shader_source(&self, required_attributes: FragmentAttributes) -> String {
format!(
"#define PARTICLES\n{}{}{}{}{}{}{}",
"#define PARTICLES\n{}{}{}{}{}{}{}{}",
if required_attributes.normal {
"#define USE_NORMALS\n"
} else {
Expand All @@ -228,18 +228,17 @@ impl Geometry for ParticleSystem {
} else {
""
},
if self.instance_buffers.contains_key("instance_color")
&& self.base_mesh.colors.is_some()
{
"#define USE_VERTEX_COLORS\n#define USE_INSTANCE_COLORS\n"
} else if self.instance_buffers.contains_key("instance_color") {
"#define USE_INSTANCE_COLORS\n"
} else if self.base_mesh.colors.is_some() {
if required_attributes.color && self.base_mesh.colors.is_some() {
"#define USE_VERTEX_COLORS\n"
} else {
""
},
if self.instance_buffers.contains_key("tex_transform_row1") {
if required_attributes.color && self.instance_buffers.contains_key("instance_color") {
"#define USE_INSTANCE_COLORS\n"
} else {
""
},
if required_attributes.uv && self.instance_buffers.contains_key("tex_transform_row1") {
"#define USE_INSTANCE_TEXTURE_TRANSFORMATION\n"
} else {
""
Expand Down

0 comments on commit 35d94ba

Please sign in to comment.