GLSL 1.50 + OpenGL 3.3 + Geometry shaders: passing through gl_ClipDistance doesn't work on Mac

I have a geometry shader and I’m attempting to output gl_ClipDistance from my shader. I’m attempting to pass gl_ClipDistance that was set from the vertex shader. The code goes something like this:

layout(lines) in;
layout(triangle_strip, max_vertices = 4) out;

...

void passThroughForEmittedVertex(int inPoint)
{
    for (int i=0; i < 6; i++)
        gl_ClipDistance[i] = gl_in[inPoint].gl_ClipDistance[i];
}

void main() {
   ...
    // generate the triangle strip
    gl_Position = vec4( p0.xy + widthToAdd, p0.z, 1.0 )*w0;
    passThroughForEmittedVertex(0);
    EmitVertex();

    gl_Position = vec4( p0.xy - widthToAdd, p0.z, 1.0 )*w0;
    passThroughForEmittedVertex(0);
    EmitVertex();

    gl_Position = vec4( p1.xy + widthToAdd, p1.z, 1.0 )*w1;
    passThroughForEmittedVertex(1);
    EmitVertex();

    gl_Position = vec4( p1.xy - widthToAdd, p1.z, 1.0 )*w1;
    passThroughForEmittedVertex(1);
    EmitVertex();

    EndPrimitive();
}

The clipping functionality works well on Windows, but when tested on Mac, it’s almost as if the gl_ClipDistance parameters don’t get propagated correctly from the vertex shader.

Does anyone have any ideas of what I can check particularly on Mac that can help me here?

  • I’m currently using OpenGL 3.3 core, with no compatibility
  • I’m using GLSL 1.5

Thanks for any help you can provide in advance.

Just as an update to this post, I was able to work around this issue by reimplementing the clipping logic in world coordinates within the geometry shader, but it seems weird that this code above wouldn’t work on some implementations of GLSL, even if it compiles.

Glad you got it figured out. Assuming you’ve found a driver bug, report it to the folks that wrote the GL drivers so they can fix it. However, if it’s Apple, they may not care (e.g. see this and this).

Devs are finding other ways to run OpenGL and Vulkan apps on Apple OSs (e.g. Zink, MoltenVK, etc.), rather than depend on Apple for cross-platform API support.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.