FShade icon indicating copy to clipboard operation
FShade copied to clipboard

Problem passing struct type to shader expression

Open marklam opened this issue 1 year ago • 3 comments

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 https://github.com/marklam/FShade/commit/7c2a42174bd3bb5ed652264111ab7fb2ebc4b870

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

marklam avatar May 14 '24 08:05 marklam

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

krauthaufen avatar May 14 '24 20:05 krauthaufen

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

marklam avatar May 15 '24 12:05 marklam

Nice 👍

krauthaufen avatar May 15 '24 13:05 krauthaufen