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

Author Topic: sf::Vertex V.S sf::Shape / sf::Sprite  (Read 3943 times)

0 Members and 1 Guest are viewing this topic.

XeRaCKeR

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
sf::Vertex V.S sf::Shape / sf::Sprite
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Vertex V.S sf::Shape / sf::Sprite
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

XeRaCKeR

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: sf::Vertex V.S sf::Shape / sf::Sprite
« Reply #2 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


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Vertex V.S sf::Shape / sf::Sprite
« Reply #3 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])
Laurent Gomila - SFML developer

XeRaCKeR

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: sf::Vertex V.S sf::Shape / sf::Sprite
« Reply #4 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Vertex V.S sf::Shape / sf::Sprite
« Reply #5 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++
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

XeRaCKeR

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: sf::Vertex V.S sf::Shape / sf::Sprite
« Reply #6 on: April 19, 2015, 05:55:36 pm »
Got it, thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Vertex V.S sf::Shape / sf::Sprite
« Reply #7 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.
Laurent Gomila - SFML developer

XeRaCKeR

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: sf::Vertex V.S sf::Shape / sf::Sprite
« Reply #8 on: April 19, 2015, 07:49:20 pm »
Omg... That's what I should have done at first  :-X thanks