0

Boost::spirit seems to contain so much template magic that I can't understand the docs.. I would like to parse GLSL (OpenGL Shader source) and extract in and out attribute names and their types from the source. I'm restricting GL API version to GL 3.3 so usingsimply GL_ARB_interface_query is no option and I need to read the strings directly from the shader source.

Here is the GLSL source from what I try extract "in vec2 ks_Vertex;" "flat out int SpriteTexID;" parts. Tricky part is that some of the out varyings are in interface block like this:

out VertexData {
    smooth vec4 Color;
    smooth vec2 TexCoord;
};

I need to extract the "VertexData", "vec4 Color" and "vec2 TexCoord" strings. The full source:

#version 150
uniform isamplerBuffer ks_MaterialIDBuffer;
in vec2 ks_Vertex;
in vec4 ks_Color;
in vec2 ks_TexCoord;

layout(shared) uniform Camera {
    vec2 Position;
    vec4 Viewport;
    mat4 ModelviewProjMatrix;
    mat4 ModelviewMatrix;
    mat4 ProjectionMatrix;
};

out VertexData {
    smooth vec4 Color;
    smooth vec2 TexCoord;
} Out;

flat out int SpriteTexID;
flat out int SpriteMaterialID;

void main()
{
    int sprid = gl_VertexID / 4;
    ivec4 material = texelFetch(ks_MaterialIDBuffer, sprid);
    Out.Color = ks_Color;
    Out.TexCoord = ks_TexCoord;
    gl_Position = ModelviewProjMatrix * vec4(ks_Vertex, 0.0f, 1.0f);
    SpriteTexID = material.r;
    SpriteMaterialID = material.g;
}

I especially need the out varying names, but I have no idea how to construct such parser with boost::spirit. I barely made a lexer that counts words.. How do I define such parser with boost::spirit?

JATothrim
  • 842
  • 1
  • 8
  • 24

0 Answers0