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

vertex_array_object.rs VertexAttribPointer stride being set incorrectly #2028

Open
rnd-ash opened this issue Nov 20, 2022 · 2 comments
Open

Comments

@rnd-ash
Copy link
Contributor

rnd-ash commented Nov 20, 2022

So in my project, I have a mesh file that has the data already ready to be sent to the GPU. I create bindings dynamically, and call VertexBuffer::new_raw. Then, when VertexAttribPointer in vertex_array_object.rs is called, the stride parameter is incorrect.

Example:

Vertex attributes (Generated)

 [("position", 0, 0, F16F16F16, false), ("texturelocation", 6, 1, F16F16, false)]

So here we see the vertex consists of 3x F16 for position, and 2x F16 for texture location. This means that each vertex is 5x2 bytes long (10 bytes).

So I call VertexBuffer::new_raw like so:

VertexBuffer::new_raw(
                display,
                vertex_buffer.as_slice(),
                Cow::Owned(bindings),
                10,
            )

Note that vertex_buffer is simply a array of u8 bytes from the file being read into the GPU directly.

but then, when rendering, the vertex size is ignored and set to 1 instead!

Call (vertex_array_object.rs)

ctxt.gl.VertexAttribPointer(1, 2, 5131, 1, 6,)

Note how the 4th parameter here is 1 in the call withint glium? This should be 10 as it is what I set in my vertex stride size.

@rnd-ash
Copy link
Contributor Author

rnd-ash commented Nov 20, 2022

I had a further look at the source to VertexBuffer

    #[inline]
    pub unsafe fn new_raw<F: ?Sized>(facade: &F, data: &[T],
                             bindings: VertexFormat, elements_size: usize)
                             -> Result<VertexBuffer<T>, CreationError>
                             where F: Facade
    {
        // FIXME: check that the format is supported

        Ok(VertexBuffer {
            buffer: Buffer::new(facade, data, BufferType::ArrayBuffer,
                                         BufferMode::Default)?,
            bindings,
        })
    }

It appears the elements_size param is actually ignored

@est31
Copy link
Collaborator

est31 commented Nov 21, 2022

That's interesting, it seems that BufferAny has a parameter to allow you setting a custom elements_size.

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 a pull request may close this issue.

2 participants