NJGUY
NJGUY

Reputation: 2085

Does opengl render a large mesh broken into smaller triangle faster?

If you render a large quad that extends beyond the borders of the screen would opengl render faster if you break that quad into smaller triangle/segments? To a point of course, say instead of two triangles in the quad you managed to break it up into 18 triangles or so. This way the triangles that are off the screen would not be sent to the fragment shader? Too many triangles obviously defeats the purpose and slows it down. Am I way off on that one? Based on my understanding of opengl when triangles are off screen they aren't rendered (sent to fragment shader) even if a draw call is called. The fragment shader is the slowest part and if less fo the quad is going to it, it would be more efficient?

Upvotes: 0

Views: 769

Answers (1)

Reto Koradi
Reto Koradi

Reputation: 54572

I wouldn't expect splitting large triangles into smaller triangles to be beneficial for performance.

Clipping happens in a fixed function block between vertex shader and fragment shader. The fragment shader will never see fragments that are outside the window. So you don't have to worry about processing fragments outside the window. They will be eliminated no matter how big or small the triangles are.

The spec suggests that clipping happens on the vertices in clip coordinate space, before rasterization. But as always, OpenGL implementations are free to handle this differently, as long as the end result is the same. So some hardware architectures may clip the vertices, while others may rasterize first and then perform clipping on the resulting fragments. Or they may use a hybrid between the two approaches.

Now, if you're running on a hardware architecture that (partly) clips in fragment space, it's theoretically possible that you have more rasterization overhead with large triangles that are mostly off screen. But it seems very unlikely that this would ever turn into a real bottleneck.

If a large part of your geometry is getting clipped, it may be beneficial to apply some form of culling before rendering, so that objects completely outside the view volume are never rendered.

Upvotes: 2

Related Questions