summaryrefslogtreecommitdiff
path: root/engine/src/rendering/backend/opengl/graphics_mesh.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-08-12 17:48:48 +0200
committerHampusM <hampus@hampusmat.com>2026-08-12 17:48:48 +0200
commit47ac4d8ae714d562d969e8379e82e568a72d50fb (patch)
tree0b7a2daf0fdfc6c09f4f9251fd08bfe6a8a47386 /engine/src/rendering/backend/opengl/graphics_mesh.rs
parent99e69bc233caa9b73a5297286487476f44f539f9 (diff)
feat(engine): allow vertex shader inputs as params & nested in structs
Diffstat (limited to 'engine/src/rendering/backend/opengl/graphics_mesh.rs')
-rw-r--r--engine/src/rendering/backend/opengl/graphics_mesh.rs59
1 files changed, 13 insertions, 46 deletions
diff --git a/engine/src/rendering/backend/opengl/graphics_mesh.rs b/engine/src/rendering/backend/opengl/graphics_mesh.rs
index a1c903b..fba60c8 100644
--- a/engine/src/rendering/backend/opengl/graphics_mesh.rs
+++ b/engine/src/rendering/backend/opengl/graphics_mesh.rs
@@ -157,47 +157,27 @@ impl GraphicsMesh
shader_vertex_desc: &ShaderVertexDescription,
) -> Result<(), VertexAttrsUpdatingError>
{
- let vertex_field_desc_cnt = u32::try_from(shader_vertex_desc.fields.len())
- .expect("Shader has too many vertex fields. Count does not fit into u32");
+ let vertex_input_cnt = u32::try_from(shader_vertex_desc.inputs.len())
+ .expect("Shader has too many vertex inputs. Count does not fit into u32");
- if self.last_used_vertex_attr_cnt > vertex_field_desc_cnt {
- for index in vertex_field_desc_cnt..self.last_used_vertex_attr_cnt {
+ if self.last_used_vertex_attr_cnt > vertex_input_cnt {
+ for index in vertex_input_cnt..self.last_used_vertex_attr_cnt {
self.vertex_arr.disable_attrib(curr_gl_ctx, index);
}
}
let mut used_vertex_attr_cnt = 0u32;
- let mut last_attr_index: Option<u32> = None;
-
for vertex_attr_props in &self.vertex_attr_props {
- let Some(vertex_field_desc) =
- shader_vertex_desc.fields.iter().find(|vertex_field_desc| {
- *vertex_field_desc.name == vertex_attr_props.name
+ let Some(vertex_input_desc) =
+ shader_vertex_desc.inputs.iter().find(|vertex_input_desc| {
+ *vertex_input_desc.name == vertex_attr_props.name
})
else {
continue;
};
- let attrib_index: u32 =
- vertex_field_desc.varying_input_offset.try_into().unwrap();
-
- if let Some(last_attr_index) = last_attr_index {
- if last_attr_index.wrapping_add(1) != attrib_index {
- cold_path();
- return Err(
- VertexAttrsUpdatingError::VertexAttrIndicesNotConsecutive,
- );
- }
- } else if attrib_index != 0 {
- cold_path();
- return Err(VertexAttrsUpdatingError::FirstVertexAttrIndexNotZero {
- vertex_attr_name: vertex_attr_props.name.to_string().into_boxed_str(),
- unexpected_index: attrib_index,
- });
- }
-
- last_attr_index = Some(attrib_index);
+ let attrib_index: u32 = vertex_input_desc.index.try_into().unwrap();
self.vertex_arr.enable_attrib(curr_gl_ctx, attrib_index);
@@ -233,23 +213,23 @@ impl GraphicsMesh
self.last_used_vertex_attr_cnt = used_vertex_attr_cnt;
- if used_vertex_attr_cnt as usize != shader_vertex_desc.fields.len() {
+ if used_vertex_attr_cnt as usize != shader_vertex_desc.inputs.len() {
cold_path();
return Err(VertexAttrsUpdatingError::MissingVertexAttrs(
shader_vertex_desc
- .fields
+ .inputs
.iter()
- .filter_map(|vertex_field_desc| {
+ .filter_map(|vertex_input_desc| {
if self
.vertex_attr_props
.iter()
- .any(|prop| prop.name == *vertex_field_desc.name)
+ .any(|prop| prop.name == *vertex_input_desc.name)
{
return None;
}
- Some(vertex_field_desc.name.clone())
+ Some(vertex_input_desc.name.clone())
})
.collect(),
));
@@ -284,19 +264,6 @@ pub enum VertexAttrsUpdatingError
{
#[error("Mesh is missing vertex attribute(s) required by shader: {0:?}")]
MissingVertexAttrs(Vec<Box<str>>),
-
- #[error("Shader's vertex attribute indices are not consecutive")]
- VertexAttrIndicesNotConsecutive,
-
- #[error(
- "Shader's first vertex attribute ({vertex_attr_name}) index is not 0, is {}",
- unexpected_index
- )]
- FirstVertexAttrIndexNotZero
- {
- vertex_attr_name: Box<str>,
- unexpected_index: u32,
- },
}
fn mesh_usage_to_gl_buffer_usage(mesh_usage: MeshUsage) -> GlBufferUsage