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

Author Topic: Everything In Batches?  (Read 2867 times)

0 Members and 1 Guest are viewing this topic.

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Everything In Batches?
« on: October 27, 2014, 09:33:14 pm »
Mainly for fun I want to have a large number of square sprites, flying around the screen every which way. That would mean that there would be a graphics card draw call for each one of the sprites right? And this would effectively bottleneck me to a few thousand objects.

I have done stuff with the tilemap and vertex arrays in the past, so I was thinking I could just have these objects have a reference to a tilemap, and these objects can access their sf::Quads from the vertex array when it needs them, to update position and rotation and texture coordinates for animation. Then I would just draw the vertex array with no rotation or position changes. This way, all of these objects that use the same texture, just cause one draw call. I know then I couldn't draw one object before another in this case, but that doesn't matter. Is this a good way to draw a ton of separate squares?

Also, I have the angle of one of these objects, so when I compute the new positions of each vertex, is there any better way to find the 4 positions other than sin() and cos() or a lookup table? I have taken some Linear Algebra, but the only ways I know of don't avoid sin and cos.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Everything In Batches?
« Reply #1 on: October 27, 2014, 09:45:26 pm »
Is this a good way to draw a ton of separate squares?
Yes.

Also, I have the angle of one of these objects, so when I compute the new positions of each vertex, is there any better way to find the 4 positions other than sin() and cos() or a lookup table?
You could use the sf::Transform class. Depending on what you do, the functions in Thor's Vectors module are also a possibility. Both are abstractions on top of trigonometry functions.
« Last Edit: October 27, 2014, 09:47:12 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Everything In Batches?
« Reply #2 on: October 27, 2014, 09:53:57 pm »
You could use the sf::Transform class
Right as I realized that, I came back here to edit my answer, haha. And I would use Thor, (looks awesome by the way, I have read some of the documentation and tutorials) but my project is already using a lot of dependencies and I don't want to add any more if possible.

Although, I do have a few questions about Animation techniques and procedures that I would like to ask you. Should I do that here, email you, or something else?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Everything In Batches?
« Reply #3 on: October 27, 2014, 10:16:03 pm »
You can do both. A public discussion has the advantage that other people may participate, and people with the same problem can find it in the future. If you think the problem is very specific, you can write me an e-mail.

In case you decide to write in the forum, please open a new thread for a new problem ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Everything In Batches?
« Reply #4 on: November 06, 2014, 06:53:06 am »
So I have implemented this, and just for fun, I tried it with 100,000 squares.(400,000 vertices all in one list)
Even if that is all that the program does, I only get about 35 fps. I don't ever plan to draw that many, and I plan to stick with what I have, but I thought my graphics card could do way more than that. They are all of course using the same texture, and I'm not even doing ANY transforms on them. They are all getting drawn with the same draw call. That's only ~13 million a second. ("only 12 million a second"<-- lol).

But I thought it could handle hundreds of millions? What am I missing? Does that hundred million figure imply I would need need to use a VBO to step up the performance even more?(once again, just for curiosity)
Here is my code:
void QuadBatchContainer::draw(sf::RenderTarget& rTarget, sf::RenderStates states) const
{
    for(auto it = m_vertexLists.cbegin(); it != m_vertexLists.cend(); ++it)
    {
        cout << "\n" << it->second->vertexList.getVertexCount();
        states.texture = it->second->pTexture;
        rTarget.draw(it->second->vertexList, states);
    }
}
« Last Edit: November 06, 2014, 07:00:44 am by Strikerklm96 »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Everything In Batches?
« Reply #5 on: November 06, 2014, 08:10:46 am »
Did you try without spamming cout?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
AW: Everything In Batches?
« Reply #6 on: November 06, 2014, 08:16:51 am »
And in optimized release mode?

If you're really all that much into performance checks, you should also know how to use CPU and GPU profilers...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything