SFML community forums

Help => Graphics => Topic started by: XeRaCKeR on April 19, 2015, 04:47:56 pm

Title: sf::Vertex V.S sf::Shape / sf::Sprite
Post 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
Title: Re: sf::Vertex V.S sf::Shape / sf::Sprite
Post by: Nexus on April 19, 2015, 05:01:10 pm
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.
Title: Re: sf::Vertex V.S sf::Shape / sf::Sprite
Post by: XeRaCKeR on April 19, 2015, 05:12:55 pm
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

Title: Re: sf::Vertex V.S sf::Shape / sf::Sprite
Post by: Laurent on April 19, 2015, 05:18:32 pm
Quote
Of course, shapes and sprites are easier to use, but not so fast as sf::Vertex[4] or sf::VertexArray would be, right?
->
Quote
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])
Title: Re: sf::Vertex V.S sf::Shape / sf::Sprite
Post by: XeRaCKeR on April 19, 2015, 05:33:52 pm
But despite sf::Sprite uses sf::Vertex[4] internally, sf::Vertex[4] should be faster, am I wrong?
Title: Re: sf::Vertex V.S sf::Shape / sf::Sprite
Post by: Nexus on April 19, 2015, 05:41:50 pm
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++
Title: Re: sf::Vertex V.S sf::Shape / sf::Sprite
Post by: XeRaCKeR on April 19, 2015, 05:55:36 pm
Got it, thanks
Title: Re: sf::Vertex V.S sf::Shape / sf::Sprite
Post by: Laurent on April 19, 2015, 07:13:16 pm
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.
Title: Re: sf::Vertex V.S sf::Shape / sf::Sprite
Post by: XeRaCKeR on April 19, 2015, 07:49:20 pm
Omg... That's what I should have done at first  :-X thanks