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

Seperate texture from the mesh object #656

Closed
wants to merge 1 commit into from
Closed

Seperate texture from the mesh object #656

wants to merge 1 commit into from

Conversation

ryanpeach
Copy link

I personally need a set of vertices and indices that update very irregularly (never) but a texture that updates every frame. The vertices and indices copying every frame is not ideal, and I haven't seen many libraries coupling them like this. This proposal is a lot cleaner in my codebase at the very least, because I can use a borrow for a permanent "mesh" object and a borrow for a new texture object. No copying the texture into the mesh, which prevents me from needing to re-make the mesh every frame, which prevents me from needing to do a clone on my vertices and indices every frame.

Profiling wise in my application it wasn't such a big deal, but every little clone does matter.

I personally need a set of vertices and indices that update very irregularly (never) but a texture that updates every frame. The vertices and indices copying every frame is too expensive. This is much more efficient.
@ryanpeach
Copy link
Author

I found a way to get around this using borrowing. Something like this works:

    // Pre-compute all vertices and indices
    let mut all_indices: Vec<Vec<u16>> = radial_mesh.get_indices();
    let mut all_vertices: Vec<Vec<Vertex>> = radial_mesh.get_vertices();

    loop {
        ...
        
        // Generate new textures and draw them
        let all_textures = radial_mesh.get_textures();
        for (i, texture) in all_textures.into_iter().enumerate() {
            let vertices = replace(&mut all_vertices[i], Vec::new());
            let indices = replace(&mut all_indices[i], Vec::new());
            let mesh = Mesh{
                vertices,
                indices,
                texture: Some(texture),
            };
            draw_mesh(&mesh);
            let _ = replace(&mut all_vertices[i], mesh.vertices);
            let _ = replace(&mut all_indices[i], mesh.indices);
        }
        
    }

It's a lot more verbose, but it will do.

@ryanpeach ryanpeach closed this Oct 7, 2023
@not-fl3
Copy link
Owner

not-fl3 commented Oct 7, 2023

I think this change makes sense, mind if I'll reopen and merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants