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

Problem passing struct type to shader expression #33

Open
marklam opened this issue May 14, 2024 · 3 comments
Open

Problem passing struct type to shader expression #33

marklam opened this issue May 14, 2024 · 3 comments

Comments

@marklam
Copy link

marklam commented May 14, 2024

I wanted to be able to pass a struct to the shader, (so that I can use the same struct in a vertex attrib array and automatically do the required glVertexAttribPointer and glEnableVertexAttribArray).

Marking the parameter type with the StructAttribute, produces a compiler error within the automatically-build quotation: FS3155: A quotation may not involve an assignment to or taking the address of a captured local variable.

Helpful users on the F# Slack suggested a workaround involving getter functions for the struct, but then FShade loses the parameters entirely.

An example of what I've tried is in a branch at https://github.com/marklam/FShade/tree/struct-params

The attempts and failing tests are shown in this commit marklam@7c2a421

Is there any advice on how to get a struct to work as a parameter?

@krauthaufen
Copy link
Owner

Hey, I know the problem and sadly i don't really have a workaround for that. Did you try sonething like let v = v in the first line of your shader? Just a guess but maybe inside the builder or outside this could help.

My "reasoning" here is that local variable structs seem to be okay and this would make the input a local variable

@marklam
Copy link
Author

marklam commented May 15, 2024

Yes, this seems to work - thanks!
(I put it inside the builder)

@krauthaufen
Copy link
Owner

Nice 👍

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