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

Author Topic: Why is drawing my sf::VertexArray so CPU-extensive?  (Read 1164 times)

0 Members and 2 Guests are viewing this topic.

smguyk

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
Why is drawing my sf::VertexArray so CPU-extensive?
« on: October 20, 2014, 06:41:58 pm »
I am using the code from the tutorial for my game's tilemap.

The tilemap of the test level of my game only has 17 * 20 tiles each 32x32 pixels (and I'm planning to add a whole lot more tiles) but the CPU usage goes to 25% when drawing the vertex array.

I call drawTiles(*window); to draw it which is just a member function of the tilemap class. The function is

void TileMap::drawTiles(sf::RenderTarget &target) {
  sf::RenderStates states = sf::RenderStates::Default;
  states.transform *= getTransform();
  states.texture = &tilesTexture_;
  target.draw(tilesVertexArray_, states);
}

I used the Visual Studio Performance Wizard to see what's causing the heavy CPU usage, and it says it's the vertex array draw call.

Indeed, when I comment out the drawTiles(*window); to no longer draw the tilemap, the CPU goes down to 0%, even with no framerate limit.

What am I doing wrong, please??
« Last Edit: October 20, 2014, 06:45:09 pm by smguyk »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Why is drawing my sf::VertexArray so CPU-extensive?
« Reply #1 on: October 20, 2014, 07:03:37 pm »
Well I don't know what kind of code VS generates when you don't draw anything, but if you have no framerate limit your loop will run as fast as possible, thus maxing out your CPU and since the most costly routine is the draw call for the vertex array, it's logical that the profiler will see it use up most of the time.

Set a framerate limit or activate vsync (don't mix them!) and if that doesn't help, provide a complete but minimal example with your full system specs.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/