Skip to content

Instantly share code, notes, and snippets.

@ChevyRay
Created October 28, 2020 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChevyRay/f078dcfecda71d6e2c1624b73dc010db to your computer and use it in GitHub Desktop.
Save ChevyRay/f078dcfecda71d6e2c1624b73dc010db to your computer and use it in GitHub Desktop.
vulkano vertex attributes
So my vertex shader inputs look like this, pretty basic:
layout(location = 0) in vec2 v_pos;
layout(location = 1) in vec2 v_tex;
layout(location = 2) in vec4 v_col;
layout(location = 3) in vec4 v_opt;
And after following the examples, I can implement the `Vertex` trait on my struct using this macro:
#[derive(Default, Debug, Clone)]
struct Vertex {
v_pos: [f32; 2],
v_tex: [f32; 2],
v_col: [f32; 4],
v_opt: [f32; 4],
}
vulkano::impl_vertex!(Vertex, v_pos, v_tex, v_col, v_opt);
All is good. But in OpenGL, I never use 4 32-bit floats for colors, I just use 4-byte colors and tell `glVertexAttribPointer` to normalize them. So I want my vertices to look like this...
#[derive(Default, Debug, Clone)]
struct Vertex {
v_pos: [f32; 2],
v_tex: [f32; 2],
v_col: [u8; 4],
v_opt: [u8; 4],
}
But when I actually create my pipeline later on...
GraphicsPipeline::start()
.vertex_input_single_buffer::<Vertex>()
...
I get this type mismatch error.
IncompatibleVertexDefinition(FormatMismatch { attribute: "v_col", shader: (R32G32B32A32Sfloat, 1), definition: (U8, 4) })
The error is very clear. But how do I tell Vulkano that `v_col` and `v_opt` should be R8G8B8A8Unorm formatted? I didn't see anywhere in the example code where I could specify the attribute format, only its offset and name.
thanks!
@derivator
Copy link

Hey :) Did you figure this out? I'm having the same problem.

@ChevyRay
Copy link
Author

No i did not, sorry. i’ve moved away from vulkano unfortunately.

@derivator
Copy link

Thanks for the reply :) Out of curiosity, what did you move to?

@ChevyRay
Copy link
Author

ChevyRay commented Mar 2, 2021

i'm using Glutin and OpenGL right now. i've set up my system so that i can swap out graphics systems, so i hope to get proper DX/Vulkan renderers at some point, but it's just too complicated for me at the moment. hopefully at some point we'll get a very usable library that wraps these things (if i was talented i would write it myself).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment