我有大约六个文件,每个文件 250 KB 到 500 KB。这些文件中的每一个都有多个 QImage;每个文件大约 400 张 128x64 的图像。加载到内存的速度约为 60MB/s(因为 OpenGL 需要将 PNG 解压缩为它自己的格式)。
有没有可能加快这个过程?它非常缓慢,因为我有一个演出要填补。
QFile file("file.ucv");
if (file.open(QIODevice::ReadOnly)) {
qDebug() << "Read from hdd";
QDataStream r(&file);
r.setVersion(QDataStream::Qt_4_3);
QImage t;
int i = maxPics * place;
glGenTextures(maxPics, &texture[i]);
for (int y = 0; y < yNrPics; y++)
for (int x = 0; x < xNrPics; x++, i++) {
// Write to precomputed object
r >> t;
glBindTexture( GL_TEXTURE_2D, texture[i] );
glTexImage2D( GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
}
分析器发现这条线是最消耗量的:
glTexImage2D( GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
将压缩更改为非压缩可以节省一些时间,但仍然不多。
加载的 QImage 为 GL 格式。