简体   繁体   中英

Variable output primitives count in geometry shader GLSL

I want to do something like this in my geometry shader:

uniform int maxOutputVert;

layout(points) in;
layout(points, max_vertices=maxOutputVert) out;

However I get error while compiling it:

Error: error(#132) Syntax error: 'maxOutputVert' parse error

and shader won't compile.

I could understand that it might be too hard for memory management if that variable would change in each shader run, but here it would be constant thorough single drawing call, because uniforms are constant. It also fails if I define some integer constant right in shader and use it as max_vertices count:

const int a = 5;
layout(points, max_vertices=a) out;

Same error is generated. So is there way to do this or do I simply have to put a number inside that call or it won't compile. If the second is the case, how can I assure that I won't exceed the maximum output number queried inside main process by:

glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &maxoutput);

Edit: Sorry for I forgot to mention I'm using ATI/AMD and the Catalyst version is 2010.1105.19.41785 (it's the most stable I've tried...)

The shader layout is something determined at compilation time, and it cannot be parametized like this. For each difference in layout you need a own shader. So what you can do is, modify the shader sourcecode before upload. Something like this:

Start with a template shader source:

uniform int maxOutputVert;

layout(points) in;
layout(points, max_vertices=$MAXOUTPUTVERTICES$) out;

And before submitting this as to glShaderSource, replace the string $MAXOUTPUTVERTICES$ with the number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM