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

Author Topic: One draw-call for all 2dStuff ..  (Read 4017 times)

0 Members and 2 Guests are viewing this topic.

HeinzK

  • Newbie
  • *
  • Posts: 41
    • View Profile
    • ZwiAner
    • Email
One draw-call for all 2dStuff ..
« on: August 21, 2017, 03:43:28 pm »
deleted
« Last Edit: December 04, 2019, 08:32:40 am by HeinzK »
The trees, that obstruct the view on the forest, can be allowed to fall! (Die Bäume, die die Sicht auf einen Wald versperren, dürfen gefällt werden!)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: One draw-call for all 2dStuff ..
« Reply #1 on: August 21, 2017, 04:11:34 pm »
Btw. we have [code=cpp][/code] for when posting code. ;)

Not sure what's your point here exactly.
If you use a vertex array of a certain primitive type, you can easily batch all the vertices together, no need for SFML to do anything.
If you have multiple different primitive types, you have to run multiple draw calls. That doesn't just go away by changing the interface, as it also requires multiple draw calls in OpenGL.

And if you just look for a vertex array struct thingy, then well we have that sf::VertexArray, but often you'll want to use your own custom thing, when you want direct access to the vector of vertices.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: One draw-call for all 2dStuff ..
« Reply #2 on: August 21, 2017, 04:58:47 pm »
There's no point in doing this. It would only add an unnecessary function to the API and otherwise have no advantage. You can draw all your objects simply like this:

std::vector<sf::Drawable*> drawables;
for(auto drawable : drawables) {
    window.draw(&drawable);
}

or for vertex arrays

struct VertexArray {
    std::vector<sf::Vertex> vertices;
    sf::PrimitiveType primitive_type;
}

std::vector<VertexArray> collection;

for(auto& vertex_array : collection) {
    window.draw(vertex_array.vertices.data(), vertex_array.vertices.size(), vertex_array.primitive_type);
}
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: One draw-call for all 2dStuff ..
« Reply #3 on: August 21, 2017, 05:38:17 pm »
As I mentioned.

If you use a vertex array of a certain primitive type, you can easily batch all the vertices together, no need for SFML to do anything.

If you have multiple different primitive types, you have to run multiple draw calls. That doesn't just go away by changing the interface, as it also requires multiple draw calls in OpenGL.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: One draw-call for all 2dStuff ..
« Reply #4 on: August 22, 2017, 12:39:50 pm »
Why should Vtx be an address?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: One draw-call for all 2dStuff ..
« Reply #5 on: August 22, 2017, 04:18:06 pm »
sf::Vertex Vtx = pVertices->front();
This creates a copy of a single vertex stored in k_PolyLines. So it's not only a completely different object, but it's not connected in any way to the vector and thus you can't use it for the draw call.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/