Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Automatic batching in sfml2 branch  (Read 25410 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Automatic batching in sfml2 branch
« Reply #45 on: November 02, 2010, 10:15:59 pm »
Quote
Sounds good, however, as it currently stands, does my approach above sound good for particles?

Why would it be better to first render to a RenderImage? What can you reuse?

Quote
Also, will your new idea be contained in the first release of sfml2 or is that for some time beyond that?

It will be included in SFML 2.0.
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Automatic batching in sfml2 branch
« Reply #46 on: November 02, 2010, 10:24:37 pm »
Currently I'm rendering 15000 particles draw-by-draw. Of course, this is rather stupid. I'd like to combine these into a single single draw call per frame, if possible. I thought the RenderImage approach would be suited here, is it not?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Automatic batching in sfml2 branch
« Reply #47 on: November 02, 2010, 11:56:20 pm »
Quote
I thought the RenderImage approach would be suited here, is it not?

But you still need to render your 15000 particles to the render image, don't you?
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Automatic batching in sfml2 branch
« Reply #48 on: November 03, 2010, 12:07:34 am »
To be honest, I haven't looked at the details of RenderImage at all. How would you efficiently draw lots of particles while trying to be light on draw calls? I SDL I used to blit all my particles onto a surface and then drew the surface to the screen. Any way of replicating this behavior?

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Automatic batching in sfml2 branch
« Reply #49 on: November 03, 2010, 01:32:42 am »
You would only want to draw to an off-screen surface (RenderImage) if your particles do not change each frame. That'd be a pretty boring particle effect, though.

Drawing to another surface every frame will only reduce the frame rate since the render target has to be changed every so often, plus you are using more resources.

I have particle effects in my engine, and just drawing like any other sprite works just fine. Granted, it is far from ideal since that is a lot of calls, but from what I have seen, draw calls do not have as much overhead in OpenGL as they do in DirectX.

The only places you can really use an off-screen surface for performance gains by drawing less is if you:
1. Have relatively static images (you don't need to update the RenderImage much... exactly how much depends on other variables)
2. The RenderImage you are creating is relatively complex (a bunch of overlaid sprites, like a GUI system)
3. The cost of managing the updates and tracking the state is relatively low

For many games, the number of places you can utilize an off-screen cache is relatively low, and it can add an incredible amount of complexity to your render logic. So my opinion - don't bother trying to cache parts of the screen.

If you want to display more than your system can handle, you're going to want to try to find some other ways to "cheat" it. Draw larger particles instead of smaller ones. Cluster multiple particles together in a single sprite to make it appear like there are really more. Make use of fragment shaders where you can. Etc.

Quote
I SDL I used to blit all my particles onto a surface and then drew the surface to the screen. Any way of replicating this behavior?


That is exactly the same as you are describing for SFML, and its very easy  with SFML 2.0. Its just that it doesn't bring any benefit unless the particles in your particle system are completely static.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Automatic batching in sfml2 branch
« Reply #50 on: November 03, 2010, 08:25:09 pm »
I see, thanks for the detailed explanation. I will try to group a bunch of particles depending on the effect.