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

Author Topic: UI performance and VertexArrays  (Read 3776 times)

0 Members and 1 Guest are viewing this topic.

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
UI performance and VertexArrays
« on: December 26, 2018, 05:34:03 pm »
Hello,
I use SFML to render my GUI, meaning that I implement the widgets, containers, event handlers etc. myself.
I have many Widgets of different types in the Software, and because of that, I am worried about the drawing performance.

Every widget holds a vector of it's components (sf::Drawable derivatives). For the example, buttons consist of rounded rectangles (custom shapes) which is textured, an outline, a sf::Text, and so on. It gets way more complicated with more complex composit widgets. All that would result in a very high number of draw calls.

Now, I read in the docs that it's especially slow to change the current texture (I think it's because of the underlying openGL bind () or whatever), so I think I can speed things up by drawing all the buttons with the same texture first.
Are there any further accelerations I should be aware of?
I read something about the sf:: Vertexarray, but I don't know how that would help me, because it seems like it's only for groups of primitives like tiles.
Thanks in advance

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: UI performance and VertexArrays
« Reply #1 on: December 30, 2018, 12:01:01 pm »
Yes, to reduce the switching of textures, you could draw all things with the same texture together.

A vertex array is a way of drawing the primitives directly. SFML shapes use these primitives (the triangle fan). SFML points use a primitive too (the point). You can have more flexibility by using other primitives.

Consider that everything you want can be drawn using triangles (including curved surfaces). Choose the triangles primitive and add all of the triangles to that vertex array. Voila! A single draw call for multiple objects that don't even have to be nearby or the same colour.
The two negative things to be aware of are:
1) you have to create the list of triangles yourself, and
2) you can only use one texture per vertex array.
However, since you are already considering grouping things up by texture, you could have a maximum draw calls based on the number of different textures used.

You may also way to consider a vertex buffer if the things don't change often.

Of course, text is a separate beast! Most single line text will need to have its own draw call unless you incorporate text into a vertex array using the font's texture but this would not be as easy.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything