Why does the first call to draw with some vertices cause a huge lag?
Example:
int main() {
sf::RenderWindow window{sf::VideoMode{640, 480}, "SFML"};
for (auto n : {1, 2, 3}) {
Timer p{"Draw"};
if (n > 1) window.draw(sf::RectangleShape{});
else window.draw(sf::VertexArray{sf::Triangles});
}
}
Typical output:
Draw 0.031ms
Draw 167.891ms
Draw 0.006ms
Yes that's what I was trying to show, that it doesn't lag on the empty draw call, then it does lag on the first, and only on the first rectangleshape draw call. More generally, the first call to draw some vertices.
I haven't looked into the source to see what happens when drawing a default rectangleshape, but I conjecture it draws some vertices because that would be consistent with how the lag appears in all other circumstances, I discovered it not by using rectangleshape but by using vertexarray.
Other example:
int main() {
sf::RenderWindow window{sf::VideoMode{640, 480}, "SFML"};
sf::VertexArray vs{sf::Points};
vs.append(sf::Vertex{sf::Vector2f{0, 0}});
for (auto n : {1, 2, 3}) {
Timer p{"Draw"};
if (n > 1) window.draw(vs); // lag once on first call
else window.draw(sf::VertexArray{sf::Points}); // no lag
}
}