SFML community forums
Help => Graphics => Topic started by: XeRaCKeR on April 19, 2015, 04:47:56 pm
-
Hi, is there any reason to use sh::Shape or sf::Sprite instead of sf::Vertex and create your own class with your owns metods? Since sf::Vertex is more efficient, isn't it?
Regards
-
Assuming you mean sf::VertexArray and not sf::Vertex: it's a matter of abstraction. Shapes and sprites are a higher-level concepts that are easier to work with. If you look at the implementation, you'll see that sf::Shape and sf::Sprite use sf::VertexArray internally.
-
Well, I'm talking about sf::Vertex[4], forgot to mention.
Of course, shapes and sprites are easier to use, but not so fast as sf::Vertex[4] or sf::VertexArray would be, right? So, assuming that sf::Vertex[4] are faster and I can create my owns methods, can I prescind from sprites/shapes or would be it a mistake?
Thanks for reply
-
Of course, shapes and sprites are easier to use, but not so fast as sf::Vertex[4] or sf::VertexArray would be, right?
->
If you look at the implementation, you'll see that sf::Shape and sf::Sprite use sf::VertexArray internally.
(which is not entirely true, sf::Sprite uses a sf::Vertex[4])
-
But despite sf::Sprite uses sf::Vertex[4] internally, sf::Vertex[4] should be faster, am I wrong?
-
But despite sf::Sprite uses sf::Vertex[4] internally, sf::Vertex[4] should be faster, am I wrong?
What is faster? A data structure can't be faster, operations can be.
sf::Sprite provides a lot of additional functionality on top of raw vertices, and if you did that by yourself, you would have the same speed again. The whole point of using vertex arrays is to reduce the number of draw calls for many vertices, not 4. This is where the performance gain comes from, not by abandoning abstractions. Abstractions per se don't cost in C++
-
Got it, thanks
-
Additionnally, don't hesitate to have a look at the source code of SFML. sf::Sprite for example is really straight-forward, you can easily figure out by yourself.
-
Omg... That's what I should have done at first :-X thanks