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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - IGD

Pages: [1]
1
So I continued digging, and I found this:
https://en.sfml-dev.org/forums/index.php?topic=22780.0

Upon looking at my code deeper, I noticed I was in fact resizing the vertex array before utilizing append, which, as was the case with the previous poster, led to double the vertices.

2
When I build my vertex array using this code, I get like 2-350 FPS:
                sf::Vertex v0(sf::Vector2f(position.x * size.x, position.y * size.y), sf::Vector2f((tu * size.x)+5, (tv * size.y)+5));
                sf::Vertex v1(sf::Vector2f((position.x + 1) * size.x, position.y * size.y), sf::Vector2f(((tu + 1) * size.x)-5, (tv * size.y)+5));
                sf::Vertex v2(sf::Vector2f(position.x * size.x, (position.y + 1) * size.y), sf::Vector2f((tu * size.x)+5, ((tv + 1) * size.y)-5));
                sf::Vertex v3(sf::Vector2f(position.x * size.x, (position.y + 1) * size.y), sf::Vector2f((tu * size.x)+5, ((tv + 1) * size.y)-5));
                sf::Vertex v4(sf::Vector2f((position.x + 1) * size.x, position.y * size.y), sf::Vector2f(((tu + 1) * size.x)-5, (tv * size.y)+5));
                sf::Vertex v5(sf::Vector2f((position.x + 1) * size.x, (position.y + 1) * size.y), sf::Vector2f(((tu + 1) * size.x)-5, ((tv + 1) * size.y)-5));


                m_vertices.append(v0);
                m_vertices.append(v1);
                m_vertices.append(v2);
                m_vertices.append(v3);
                m_vertices.append(v4);
                m_vertices.append(v5);
 

BUT when I build that same vertex array with this code, I get 4-800 FPS:
sf::Vertex* triangles = &m_vertices[(i + j * width) * 6];

                // define the 6 corners of the two triangles
                triangles[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                triangles[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                triangles[2].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
                triangles[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
                triangles[4].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                triangles[5].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);

                // define the 6 matching texture coordinates
                triangles[0].texCoords = sf::Vector2f(tu * tileSize.x+5, tv * tileSize.y+5);
                triangles[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x-5, tv * tileSize.y+5);
                triangles[2].texCoords = sf::Vector2f(tu * tileSize.x+5, (tv + 1) * tileSize.y-5);
                triangles[3].texCoords = sf::Vector2f(tu * tileSize.x+5, (tv + 1) * tileSize.y-5);
                triangles[4].texCoords = sf::Vector2f((tu + 1) * tileSize.x-5, tv * tileSize.y+5);
                triangles[5].texCoords = sf::Vector2f((tu + 1) * tileSize.x-5, (tv + 1) * tileSize.y-5);
 

I would understand the FPS difference if the function was called each loop, but it is only called once when initializing. Why in the world is the FPS so different???

Pages: [1]