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

Author Topic: setView() performance penalty  (Read 2280 times)

0 Members and 1 Guest are viewing this topic.

oomek

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • Email
setView() performance penalty
« on: April 26, 2018, 02:53:20 pm »
Is performance penalty signifficant if setView() is called before every draw() call?
I have a list of drawable class instances and each has defined to which view it belongs. I would like to keep the drawing order that way. Does the performance change significantly If I’ll do it that way?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: setView() performance penalty
« Reply #1 on: April 26, 2018, 03:06:24 pm »
Performances always depend on many things, other than the code that gets executed, especially the user environment. So you'd better benchmark it if you want to know for sure.

And if you look at the code, it is quite simple and you can easily see what happens when you call setView.
Laurent Gomila - SFML developer

oomek

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • Email
Re: setView() performance penalty
« Reply #2 on: April 26, 2018, 03:37:01 pm »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: setView() performance penalty
« Reply #3 on: April 26, 2018, 08:04:30 pm »
glViewport(viewport.left, top, viewport.width, viewport.height);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(m_view.getTransform().getMatrix());
glMatrixMode(GL_MODELVIEW);

This is basically what gets called when drawing, if setView was called. Is it expensive? It depends on your graphics driver. Is it impacting performances too much? Only you can know ;)
Laurent Gomila - SFML developer

oomek

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • Email
Re: setView() performance penalty
« Reply #4 on: April 26, 2018, 08:47:55 pm »
Fair enough Laurent.
Since this project is multiplatform and works even o Raspberry-PI I wouldn’t like to rush the choices and degrade the performance before making tests. No matter how I despise RPI I’m being forced to buy one :)

Chaia*

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: setView() performance penalty
« Reply #5 on: May 01, 2018, 11:52:17 am »
Generally for optimal performance you should sort your drawcalls by state changes. Of course, the most expensive ones should be changed the least often. I.e. Context switches (=rendertexture/window), framebuffer (=rendertexture), shader (but this is as far as I know useless with SFML, as shaders are always set again), textures, vertex buffers (if you use any) and then all the small stuff just as matrices, uniforms and so on. In SFML you further have to sort by "depth", i.e. the order you want things to be drawn. However, the order has only to be considered if the two entities somehow overlap.

Especially when you have a lot of overlapping entities, this can become very complex so you should first profile your application to see if there is a need for improvement here. But for optimal performance this is one of the ways to go there.

 

anything