0
votes

EndStreamPrimitive() can only be used in case of Geometry shader with streams. Geometry shader with streams can only emit GL_POINTS. But In GL_POINTS, each vertex itself is a primitive.

So what is the point of having a function like EndStreamPrimitive()? Just specifying EmitStreamVertex() when primitive type = GL_POINT means end of primitive.

My next question is What is max_vertices in a Geometry shader?

layout(points, max_vertices = 6) out;

I suppose it is the maximum number of vertices a Geometry shader will emit (irrespective of weather it is using streams or not). If I have 2 streams in my Geometry shader, and I emit 2 vertices to stream 0, 3 vertices to stream 1. should the value of max_vertices be set to 5?

1

1 Answers

1
votes

As far as I know, EndStreamPrimitive (...) currently has no use; likely provided simply for consistency with the non-stream GLSL design. If the restriction on points being the only type of output primitive is lifted it may become useful in the future.


To answer your second question, that is the maximum number of vertices you will ever emit in a single invocation of your GS. Geometry Shaders are different from other stages in that the size of their output data can vary at run-time. You could decide because of some condition at run-time that you want to output 8 vertices to stream 1 -- GLSL needs to know an upper-bound and it cannot figure that out if your flow control is based on a variable set elsewhere.

There are implementation limits set on both the number of vertices (GL_MAX_GEOMETRY_OUTPUT_VERTICES) a GS invocation can emit and the sum total number of vector components (GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS). These limits are also defined in the shading language.

Implementations must support the following minimums:

const int gl_MaxGeometryOutputVertices        = 256;
const int gl_MaxGeometryTotalOutputComponents = 1024;

If your shader exceeds those limits, you will need to split it into multiple invocations. You can either do that using multiple draw calls or you can have GL4+ automatically invoke your GS multiple times:

layout (invocations = <num_invocations​>) in;

You can determine which invocation the GS is performing by the value of gl_InvocationID​ (GL4+).