I'm attempting to create vertex structs in OpenGL by using macros to define the vertex basics and having the macro eventually generate the boilerplate code needed for use with OpenGL (glGetAttribLocation, glEnableVertexAttribArray, glVertexAttribPointer etc.).
My macros are defined as such:
#define DEFINE_GPU_VERTEX_ATTRIBUTE(R, DATA, ELEM) BOOST_PP_CAT(ELEM, DATA);
#define DEFINE_GPU_VERTEX(NAME, ...) struct NAME##_gpu_vertex_t \
{ \
BOOST_PP_SEQ_FOR_EACH(DEFINE_GPU_VERTEX_ATTRIBUTE, _, __VA_ARGS__) \
}
This is a sample of how I intend to use the macro:
DEFINE_GPU_VERTEX(bsp,
((vec3_t), position),
((vec3_t), normal),
((vec2_t), texcoord));
Where the first argument (bsp) is the name prefix, and all variadic arguments are pairs of types and names of attributes.
I expect it to generate a struct definition like so:
struct bsp_gpu_vertex_t
{
vec3_t position;
vec3_t normal;
vec2_t texcoord;
}
However, it appears to generate an empty struct. What am I doing wrong here?
I'm not familiar with C macros, let alone Boost macros as I've never really had reason to use them or learn what makes them tick until now.
Any help is appreciated!
g++ -C -Eor by using appropriately your compiler and IDE) and look inside with an editor or pager (e.g.less). Also tell what compiler and operating system you are using, and what is your compilation command. - Basile StarynkevitchBOOST_PP_**SEQ**_FOR_EACHrequires a sequence and you are not providing one. There is a macro that converts variadic data to a seq that may help. I believe the "usual" way to do this (at least the one used in fusion adaptations/definitions of structs) is to use directly a sequence. The 2nd and 3rd approaches in this answer could be of help. - llonesmiz