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

OpenGL/WebGl std140 support? #13

Open
Nazariglez opened this issue Jul 23, 2022 · 2 comments
Open

OpenGL/WebGl std140 support? #13

Nazariglez opened this issue Jul 23, 2022 · 2 comments

Comments

@Nazariglez
Copy link

Hey hi!

I am investigating about lib that helps me to set my buffers using std140 easily, I am using right now crevice but I am having some troubles with shaders that require sized arrays or dynamic size types, like:

struct PointLight {
   a: Vec3,
   b: Vec3,
   c: Vec3,
   ...
}

struct Material {
   attr: f32,
   attr2: Vec3,
   lights: Vec<PointLight>, // or [PointLight; 4]
}

So my question is, opengl/std140 is supported by encase? I see that the readme talks about WGPU only.
If so, is this kind of structs is supported? This is exactly the code that I am trying to make it work with crevice: https://github.com/Nazariglez/LearnOpenGL-Notan/blob/main/src/_2_lighting/_6_1_multiple_lights.rs#L264

Where #[uniform] it just adds AsStd140 and Uniform to control the input type when setting the buffer's data.

If encase support this it would be great.

@teoxoy
Copy link
Owner

teoxoy commented Jul 24, 2022

So my question is, opengl/std140 is supported by encase?

std140 and WGSL's uniform alignment rules are not that different. The only difference is how matrices of the form matCx2 (matrices with 2 rows and C columns) are laid out. As long as you make sure to not use those you should be fine.

As for officially supporting std140, I don't see a way to nicely fit it in the current architecture but we can leave this issue open and see how sought after support for this would be.

If so, is this kind of structs is supported?

Yeah, but the one with the Vec would only work if it's part of an std430 storage buffer.

If you'd like support for Vec-like data structures in uniform buffers, see #10.

@Nazariglez
Copy link
Author

Nazariglez commented Jul 26, 2022

Thanks for the clarification, notan is a lib so I cannot rely on the user to not use a matCx2 matrix because there could a case that they need it. But I am looking to use encase eventually for a (future) wgpu backend. Thanks!

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

No branches or pull requests

2 participants