SFML - 优化从 GPU 到 RAM 的复制

SFML - optimize copying from GPU to RAM

我的应用程序包含一个将 SFML GPU 缓冲区(sf::RenderTexture 转换为 sf::Image)复制到二维颜色数组(存储在 RAM 中并由 [=23= 处理)的短函数]).这是代码:

const sf::Image image = renderTexture.getTexture().copyToImage();

for (Point_t y = 0; y < totalHeight; ++y)
{
    for (Point_t x = 0; x < totalWidth; ++x)
    {
        const sf::Color& c = image.getPixel(x, totalHeight - y - 1);
        // here processing this c variable
    }
}

问题是:对于 256x64 像素的屏幕,我的帧率大约为 20 FPS - 这太低了,我的应用程序需要大约 50 FPS。我怎样才能提高这个过程的性能?

也许我应该使用额外的库来加快速度?

编辑:

有人建议我应该使用真正的图像库而不是 SFML。但重点是 SFML 是用于实时旋转对象等的完美库,所以我会坚持使用 SFML,只需要优化或其他方法将缓冲区从 GPU 复制到 CPU。

你不需要那样做,SFML 会自行优化这一切。你真的需要一个图像,你不能只通过 sf::Texture 和 sf::Sprite 吗?

有兴趣的朋友,我找到了解决办法:

从 GPU 复制到 CPU 加速由这个库提供:https://github.com/adafruit/rpi-fb-matrix

https://github.com/adafruit/rpi-fb-matrix/blob/master/rpi-fb-matrix.cpp(第 70 行)