Geometry shader output streams (for binning instances)
Need some help from GLSL syntax gurus. I'm looking for a generic way to output to multiple streams without having to hard-code explicit logic for each stream in the geometry shader.
For example, I know you can do this:
Code glsl:
#version 400
layout( points ) in ;
layout( points, max_vertices = 1 ) out;
// Outputs
layout( stream=0 ) out float data0;
layout( stream=1 ) out float data1;
layout( stream=2 ) out float data2;
layout( stream=3 ) out float data3;
...
void main(void)
{
int output = determineOutput();
switch ( output )
{
case 0 : data0 = my_data; EmitStreamVertex(0); break;
case 1 : data1 = my_data; EmitStreamVertex(1); break;
case 2 : data2 = my_data; EmitStreamVertex(2); break;
case 3 : data3 = my_data; EmitStreamVertex(3); break;
...
}
};
But this copy/paste/modify code is undesirable, and I might have 10, 20, or 30+ different output streams with 4 or 5 outputs per stream.
Any tips? Trying to avoid re-sifting the list N times.
What I really want is something like this:
Code glsl:
#version 400
layout( points ) in ;
layout( points, max_vertices = 1 ) out;
// Outputs
layout( streams ) out float data;
void main(void)
{
int output = determineOutput();
data = my_data;
EmitStreamVertex( output );
};
where I don't have to hard-code the number of streams in the shader. But EmitStreamVertex explicitly says it only takes a constant integral argument, and I don't see a way to define an output that applies to any requested stream.
Thanks.