openglonmetal / MGL

OpenGL 4.6 on Metal
Apache License 2.0
781 stars 30 forks source link

failing link phase with multiple similar definitions #16

Closed conversy closed 2 years ago

conversy commented 2 years ago

When the shaders share some code (e.g. structs or functions), MGL cannot produce a metal library, supposedly because it first concatenates all shader sources into one single file to be compiled.

An example, with slightly modified texture_test shaders (I added an add_vec4 in both vertex and frag shaders):

 GLSL(450 core,
    layout(location = 0) in vec3 position;
    layout(location = 1) in vec2 in_texcords;

    layout(location = 0) out vec2 out_texcoords;

    layout(binding = 0) uniform matrices
    {
        mat4 mvp;
    };

    vec4 add_vec4 (vec4 c) {
        return c+vec4(0.1,0.1,0.1,0.1);
    }

    void main() {
        gl_Position = mvp * add_vec4(vec4(position, 1.0));
        out_texcoords = in_texcords;
    }
);

const char* fragment_shader =
GLSL(450 core,
    layout(location = 0) in vec2 in_texcords;

    layout(location = 0) out vec4 frag_colour;

    uniform sampler2D image;

    vec4 add_vec4 (vec4 c) {
        return c+vec4(0.1,0.1,0.1,0.1);
    }

    void main() {
        vec4 tex_color = texture(image, in_texcords);

        frag_colour = add_vec4(tex_color);
    }
);