Should you avoid drawing items outside screen

I wonder if it would be better that you do not call the draw on sprites that are outside the screen, or does the framework handle this without much resource cost?

I believe the GPU ‘culls’ sprites drawn off of the screen, so it won’t affect performance in terms of of the GPU (by much anyway), however, if you are looping through a particularly large scene and attempting to draw it, the CPU will still suffer as the loop will still have to fully execute. But overall, while its not a good habit to get into, it shouldn’t affect performance in any dramatic way.


1 Like

If you aren’t meeting your performance target I would run the profiler on your game and see whats it’s spending the most time doing.


For my own game, I found that only drawing what’s visible on the screen helped a lot with performances. Eventually I started using space partitioning algorithms like a quadtree or a dynamic tree to make my lookups be much faster.

1 Like

The GPU will not call the PixelShader in various cases. The VertexShader will always be called (as there is no position before VS had run) and you also pollute it with unneeded statechanges etc

What I currently don’t know is, if SpriteBatch does automatic culling, but I doubt it. Be also aware, that Batch uses an internal list, which may put additional overhead if most of the content isn’t rendered at all

So by not culling manually, you put a bit of unneeded work to the GPU. Checking for sprites being on the screen or not can be extremely cheap to do, so I would always do manual culling.

If we’re talking about a couple of sprites it should be no issue tho, it depends on the situation.

I don’t believe it does. Ages ago a friend and I developed a QuadTree for C# (can probably google it). There were significant performance gains in processing large quantities of sprites for rendering between using it and not using it.

I think, generally, it’s better to not bother submitting a sprite for rendering if it’s not in the visible screen area.

Yeah, its a good practice to cull everything. Yes Monogame will not draw outside of the viewport but it will help your loops and theyll thank you with higher fps.