Here’s a little trick that seems to work with OpenGL/GLSL on NVIDIA cards. When you have a geometry shader that outputs some primitives (in my case GL_POINTS) inside a loop and the number of iterations is not known at link time you’d normally write something like this:

for (int i = 0; i < pointCount; i++) {
   ...
}

If the total number of emitted vertices is always the same and doesn’t depend on pointCount (pointCount * shaderCalls = const) then you will still get a drastic slowdown when pointCount is higher then 1. If you replace pointCount with a constant number this doesn’t happen until the number is higher then some limit (8 in my case). The following code would do exactly the same as above for pointCount <= 8 but doesn't suffer from any performance loss:

for (int i = 0; i < 8; i++) {
   if (i < pointCount) {
      ...
   }
}

Are you interested in reading more from CodingClues?
Then subscribe to new postings via RSS or via E-Mail.




 
close Reblog this comment
blog comments powered by Disqus