-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Field offsetof #79
Comments
That would only work on standard-layout types, no? I think it is a good idea to provide it somehow, just clarifying the restrictions the standard imposes. Non- |
Yes, you are right. |
Would that restriction prevent you from using it? It might be nice to know what the use-case is :) |
Wouldn't restrict me at all. My use-case is the same as in the reference from my initial post. Given the definition of a vertex: struct StandardVertex {
vec3 position;
vec3 normal;
vec4 tangent;
vec2 uv;
}; I'd like to generate the shader input description, required by the graphics API, using reflection. Currently I call REFL_TYPE(ikaros::StandardVertex)
REFL_FIELD(position, ikaros::attr::VertexFieldDescription(offsetof(ikaros::StandardVertex, position), "POSITION"));
REFL_FIELD(normal, ikaros::attr::VertexFieldDescription(offsetof(ikaros::StandardVertex, normal), "NORMAL"));
REFL_FIELD(tangent, ikaros::attr::VertexFieldDescription(offsetof(ikaros::StandardVertex, tangent), "TANGENT"));
REFL_FIELD(uv, ikaros::attr::VertexFieldDescription(offsetof(ikaros::StandardVertex, uv), "TEXCOORD", 0));
REFL_END However, this feature is not critical at all. I am not 100% convinced yet myself whether this is the best approach. But I feel like having the field offset being part of the descriptor would be very helpful for this case, and probably a few others. The standard layout restriction isn't too problematic, one can practically always wrap a management class around a standard layout struct. |
Apparently getting the offset of a field within a struct from a pointer-to-member is not trivial (see).
It would be very helpful to get a field's offset from its respective
field_descriptor
.The text was updated successfully, but these errors were encountered: