Closed Rotaerk closed 5 years ago
Hmm, I stumbled upon the same problem in the vulkan-triangles
example, but I could not come up with a nice way to add the offset info to a PrimBytes
class.
Perhaps, I could add another class, something like
class PrimBytes t => PrimByteField (name :: Symbol) t where
offsetOf :: t -> Int
Then, I could add a generic-deriving mechanics for the record types too.
Sounds like a good exercise on Generics
! :)
UPDATE:
The class defined above would require writing the deriving
declaration for every record. Doesn't look very handy. Need to think of something a bit smarter.
Done via Numeric.PrimBytes! The examples are available in Numeric.PrimBytesTest and in vulkan-triangles.
I'm not really sure how this would work, exactly, but it seems like there should be some mechanism for easily getting the offset of a field in a PrimBytes instance. In my code I have this:
It'd be nice if I could just say something like
offsetOf @"vtxColor"
. (And for that matter, why notsizeOf @"vtxColor"
or justor something.) Edit: Eh, not thatsizeOf @Vec3f
sizeOf @Vec3f
is, itself, bad, but you wouldn't want to do that to get the size of thevtxColor
field, in case the type of that field changes.