我目前正在学习cg,并且必须加载一些纹理。我尝试使用stb_images,但效果很好,但是当我将图像加载到内存中时会占用太多空间。
我正在使用一个小的jpg(512 * 512,154kb),但是如果我加载10次,它将占用大约12 MB的内存。 (我使用Visual Studio诊断工具检查过程内存)
如何消除浪费的内存量。
struct Image {
int width, height, bpp;
unsigned char* rgba;
Image(const std::string& filePath) {
rgba = stbi_load(filePath.c_str(), &width, &height, &bpp, 4);
}
~Image() {
stbi_image_free(rgba);
}
};
std::vector<Image> images;
images.reserve(10);
for (int i = 0; i < 10; ++i)
images.emplace_back("res/textures/image.jpg");