Here's the code:
#include <SFML/Graphics.hpp>
#include <cstdio>
#define QUANTITY (100000)
int main()
{
sf::RenderWindow window;
window.create(sf::VideoMode(1024, 768, 32), "test", sf::Style::Default);
int type;
printf("0 - normal\n");
printf("1 - atlas\n");
printf("2 - VA\n");
scanf("%d", &type);
sf::Clock _clock;
if(type == 0) {
sf::Texture tex[3];
sf::Sprite spr[3];
tex[0].loadFromFile("test1.png");
tex[1].loadFromFile("test2.png");
tex[2].loadFromFile("test3.png");
spr[0].setTexture(tex[0]);
spr[1].setTexture(tex[1]);
spr[2].setTexture(tex[2]);
sf::Time prevTime;
while(1) {
sf::Time time = _clock.getElapsedTime();
printf("normal time: %.2lf ms\n", (time.asMicroseconds()-prevTime.asMicroseconds())/1000.0);
prevTime = time;
for(int i=0; i<QUANTITY; ++i) {
int x = rand()%1024;
int y = rand()%768;
spr[i%3].setPosition(x, y);
window.draw(spr[i%3]);
}
window.display();
window.clear();
}
}
else if(type == 1) {
sf::Texture tex;
sf::Sprite spr[3];
tex.loadFromFile("atlas.png");
spr[0].setTexture(tex);
spr[0].setTextureRect(sf::IntRect(0, 0, 100, 100));
spr[1].setTexture(tex);
spr[1].setTextureRect(sf::IntRect(100, 0, 100, 100));
spr[2].setTexture(tex);
spr[2].setTextureRect(sf::IntRect(200, 0, 100, 100));
sf::Time prevTime;
while(1) {
sf::Time time = _clock.getElapsedTime();
printf("atlas time: %.2lf ms\n", (time.asMicroseconds()-prevTime.asMicroseconds())/1000.0);
prevTime = time;
for(int i=0; i<QUANTITY; ++i) {
int x = rand()%1024;
int y = rand()%768;
spr[i%3].setPosition(x, y);
window.draw(spr[i%3]);
}
window.display();
window.clear();
}
}
else {
sf::Texture tex;
sf::Sprite spr[3];
tex.loadFromFile("atlas.png");
spr[0].setTexture(tex);
spr[1].setTexture(tex);
spr[2].setTexture(tex);
sf::Time prevTime;
while(1) {
sf::Time time = _clock.getElapsedTime();
printf("VA time: %.2lf ms\n", (time.asMicroseconds()-prevTime.asMicroseconds())/1000.0);
prevTime = time;
sf::VertexArray VA(sf::Quads, QUANTITY*4);
for(int i=0; i<QUANTITY; ++i) {
int x = rand()%1024;
int y = rand()%768;
int w = 100;
int h = 100;
VA[i*4].position = sf::Vector2f(x, y);
VA[i*4+1].position = sf::Vector2f(x+w, y);
VA[i*4+2].position = sf::Vector2f(x+w, y+h);
VA[i*4+3].position = sf::Vector2f(x, y+h);
VA[i*4].texCoords = sf::Vector2f((i%3)*w, 0);
VA[i*4+1].texCoords = sf::Vector2f((i%3)*w+w, 0);
VA[i*4+2].texCoords = sf::Vector2f((i%3)*w+w, h);
VA[i*4+3].texCoords = sf::Vector2f((i%3)*w, h);
}
window.draw(VA, &tex);
window.display();
window.clear();
}
}
}
(yep, textures dimensions are hardcoded)
and textures used:
test1.png
test2.png
test3.png
atlas.png
with these textures i have ~725 ms for normal rendering and ~710 ms for VA
nvidia geforce 9600M GT, windows 7 32 bit