Skip to content

Dynamically creating VertexBufferLayout #2050

Answered by CatCode79
dragly asked this question in Q&A
Discussion options

You must be logged in to vote

Personally, as a rust newbie, I struggled with those type of things and in the end I solved with the builder pattern.
Brutal copy and paste from my framework:

`#[derive(Clone, Debug)]
pub struct VertexStateBuilder<'a> {
vertex_state: wgpu::VertexState<'a>
}

impl<'a> VertexStateBuilder<'a> {
pub const DEFAULT_ENTRY_POINT: &'static str = "main";

pub fn new(module: &'a wgpu::ShaderModule) -> Self {
    Self {
        vertex_state: wgpu::VertexState {
            module,
            entry_point: VertexStateBuilder::DEFAULT_ENTRY_POINT,
            buffers: &[],
        },
    }
}

// [...] Others setter methods here

pub fn buffers(mut self, buffers: &'a [wgpu::VertexBufferLayout]) -> Self {
…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@dragly
Comment options

Comment options

You must be logged in to vote
3 replies
@dragly
Comment options

@dragly
Comment options

@CatCode79
Comment options

Answer selected by dragly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants