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

Author Topic: export vertexes from the Shape class  (Read 383 times)

0 Members and 1 Guest are viewing this topic.

wdmitry

  • Newbie
  • *
  • Posts: 11
    • View Profile
export vertexes from the Shape class
« on: March 23, 2024, 01:28:47 pm »
The Shape class has this members. I assume it contains all the information required to draw basic sfml shapes.
But when you have too many shapes to draw, each shape require an individual draw call

Instead it would be possible to export memory to this vertexes of the shapes from the Shape class.
So that the user can build a huge array of vertexes from this shapes and just batch draw it in a single call.

VertexArray    m_vertices{PrimitiveType::TriangleFan};          //!< Vertex array containing the fill geometry
VertexArray    m_outlineVertices{PrimitiveType::TriangleStrip}; //!< Vertex array containing the outline geometry
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: export vertexes from the Shape class
« Reply #1 on: March 25, 2024, 11:01:06 am »
What you're essentially asking for is sprite/shape batching.

I believe it's a feature we will implement eventually, but it requires some underlying changes and API decisions that aren't trivial to solve it in a generic way.

Your best option is probably to build your own class around a vertex array and create your own batching.
But make sure you're actually experiencing performance impacts. Premature optimization is the root of all evil, etc ;)
« Last Edit: March 25, 2024, 01:35:57 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wdmitry

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: export vertexes from the Shape class
« Reply #2 on: March 25, 2024, 01:29:27 pm »
yes so far I think its an overkill. 1000 draw calls work just fine.
also calculating vertex again from shapes is cpu consuming.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: export vertexes from the Shape class
« Reply #3 on: March 27, 2024, 03:15:22 pm »
You can get each of the vertices by simply getting the shape's points:
for (std::size_t i{ 0u }; i < shape.getPointCount() ; ++i)
    std::cout << "Point " << i << ": (" << shape.getPoint(i).x << ", " << shape.getPoint(i).y << ")" << std::endl;

However, this is likely not how you would build the shape to draw (other than using its original primitive type).
Much more likely is you'd like to be able to build that shape with separated triangles (as any shape can be built this way) as you can then batch them together using that same primitive.
So, you could extract the triangles from the original shapes and then draw them as triangles. Since everything is just triangles, you can also batch them together if required.
To extract the triangles from a shape, you could use this:
https://github.com/SFML/SFML/wiki/Source%3A-Triangles-Extractor

Note that best results are observed if shapes don't change often and/or there are very many (to reduce those significant draw calls) and they are causing an speed issue.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything