2
\$\begingroup\$

My game will have a large number of objects moving offscreen at any given time, can i just render them all with SDL_RenderCopy even though they are off screen or should I only render them if they are on-screen? I will probably have many hundreds or throusands of objects loaded at a time. My dev machine is quite overpowered for what I'm trying to do but I am conserned that I just won't notice a preformance drop that may affect players with less powerful computers.

So, will checking if each object is on screen before drawing increase performance/lower CPU load, or can I safely let SDL handle this with clipping?

\$\endgroup\$
  • \$\begingroup\$ Why not try it ? \$\endgroup\$ – Quentin May 19 '15 at 7:40
  • \$\begingroup\$ I have tried it with a few objects, but my game isn't at the stage where this is a problem, yet. I want to know if drawing many objects will become an issue in the future. I will edit the question to clarify. \$\endgroup\$ – Amziraro May 19 '15 at 8:01
  • \$\begingroup\$ My point is, we can't know. It all depends on your code, of which we have nought, but even then performance problems don't just pop out when reading code. Graphics performance in particular depends heavily on your hardware. You need to actually perform a stress test with a big amount of objects, and see if culling helps on your particular instance. \$\endgroup\$ – Quentin May 19 '15 at 8:08
  • \$\begingroup\$ I do see your point, I guess I want to know how fast SDL's texture clipping is compared to a quick comparison of object x,y to window/view x,y. Will SDL's clipping become a bottleneck? \$\endgroup\$ – Amziraro May 19 '15 at 8:24
  • \$\begingroup\$ As SDL2 wraps the graphics API (OpenGL or DirectX), it boils down to knowing which of your CPU and your GPU is best at culling. I would bet on the GPU, but that's little more than a guess. \$\endgroup\$ – Quentin May 19 '15 at 8:33
2
\$\begingroup\$

As SDL2 is but a wrapper over the graphics API (OpenGL or DirectX), out-of-view triangles will be culled by the GPU before reaching the rasterizer. As GPU's have hardwired or heavily optimized triangle culling, my guess is that the GPU will be faster than the CPU to do it.

But !

The CPU/GPU bandwidth comes into play. The GPU may well be a triangle munching champion, but you need to send it those triangles. When the numbers increase, it's possible that you'll encounter bandwidth saturation well before the GPU starts grinding. In which case you'd need to, again, cut down the number of triangles you try to squeeze through.

In the end, the answer is as always with graphics programming : profile, and test. Results will vary wildly between hardware configurations, drivers versions, and your particular code.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.