I'm trying to figure out if the raspberry Pi has the GPU to run an application at 1080p, and I started off just setting up a 1080x1920 texture (my monitor is rotated
and drawing it. All well and good - takes about 9ms, which is glacial in desktop terms but perfectly adequate for my purposes.
Then I tried setting up a background texture - with the idea that in the real world, I'd update just parts of the background texture as they change, and then blit the background to the window. Figures were still good, but I wasn't seeing the effect I was expecting on the raspberry Pi. Here's the code:
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(1080, 1920), "SFML window");
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile("/users/simon/Downloads/bg.jpg"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
sf::RenderTexture backing;
if (!backing.create(1080,1920))
return EXIT_FAILURE;
backing.draw(sprite);
sf::Clock cron;
int msecs = 0;
int frames = 0;
// Start the game loop
while (window.isOpen())
{
msecs += cron.restart().asMilliseconds();
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window: exit
if (event.type == sf::Event::Closed)
window.close();
}
int w = random() % 320 + 320;
int h = random() % 200 + 200;
int x = random() % (1080-w);
int y = random() % (1920-h);
sf::RectangleShape rs(sf::Vector2f(w,h));
rs.setPosition(sf::Vector2f(x,y));
rs.setOutlineColor(sf::Color(255, 0, 0, 255));
rs.setFillColor(sf::Color(0,0,0,0));
rs.setOutlineThickness(1);
backing.draw(rs);
backing.display();
const sf::Texture& backingTexture = backing.getTexture();
sf::Sprite BG(backingTexture);
// Clear screen
window.clear();
// Draw the backing-texture sprite
window.draw(BG);
// Update the window
window.display();
// Aggregate/calculate frame rate
frames ++;
if (frames == 100)
{
fprintf(stderr, "Frame time: %d.%02d msecs = %5.3f fps\n", msecs/100, msecs%100, (100000.0f/msecs));
frames = 0;
msecs = 0;
}
}
return EXIT_SUCCESS;
}
... and since I'm not clearing the background texture at all, I'd expect this to steadily turn red as time went by. On the Mac, this is what happens. On the Pi, I only ever see about 50 (?) rectangles drawn (this is more obvious when you remove the setFillColor() call) - and they're frequently the same rectangles as well...
It's not just a crappy random number generator on the Pi because there's a flickering effect as rectangles are drawn then erased then redrawn ad infinitum. What I'm seeing would be what you expect if
(a) there was a call to srandom() at the start of every render loop.
(b) the backing texture was being cleared at the start of every render loop
So am I "holding this wrong" or is this a bug ?
FYI: this is self-compiled SFML 2.6.0 on an up-to-date r-pi bullseye...
@raspberrypi:~/src/SFML-2.6.0 $ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
... (without DRM, which I couldn't get to work, it just complained about permissions whenever I ran a compiled app), and without warnings=errors (because there's a few of those regarding tests being the same on both branches with gcc10, as well as the occasional type mismatch between variable and method/function signature)