Git Product home page Git Product logo

Comments (4)

veselink1 avatar veselink1 commented on June 12, 2024

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-std::is_standard_layout types would not have field offsets.

from refl-cpp.

W4RH4WK avatar W4RH4WK commented on June 12, 2024

Yes, you are right. offsetof is only defined for standard layout types. I forgot about this restriction.

from refl-cpp.

veselink1 avatar veselink1 commented on June 12, 2024

Would that restriction prevent you from using it? It might be nice to know what the use-case is :)

from refl-cpp.

W4RH4WK avatar W4RH4WK commented on June 12, 2024

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 offsetof manually and store that value in an attribute:

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.

from refl-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.