简体   繁体   中英

OpenGL textures taking up too much memory

I have 75 * 9 * 32 images, with a total of 64 MB on harddrive in PNG format. If I load the images, which are 128*256 pixels each, it takes up a whopping 1.5 GB of memory in RAM! I have no mipmapping enabled.

I am figuring this could be because the GPU only stores raw images, is there a way to tighten the memory usage?

I am loading the textures with the use of a framebuffer object, which is created only once.

I use the following for loading the textures:

        QImage catchImage = catchFbo->toImage();
        QImage t = QGLWidget::convertToGLFormat(catchImage);

        glGenTextures( 1, &Item::texture[i] );
        glBindTexture( GL_TEXTURE_2D, Item::texture[i] );
        glTexImage2D( GL_TEXTURE_2D, 0, GL_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 );

EDIT: GL_COMPRESSED_RGBA instead of GL_RGBA seems to make a large difference. It now uses 500 MB.

I am figuring this could be because the GPU only stores raw images,

Well, of course they are in raw format. Although it would be neat for GPUs to directly support Deflate and JPEG decompression, they don't support it.

is there a way to tighten the memory usage?

You could use a compressed texture format. Yes, modern GPUs do support on-the-fly decompression, but the codecs used are very different from PNG or JPEG.

I am loading the textures with the use of a framebuffer object, which is created only once.

Why? FBOs are meant for other things. You can load a QImage from a file directly without such a proxy.

You need to implement clipping. Of course that in of itself isn't going to prevent occupation of memory, so you need to lazy-load images if and when an image falls in your view scope. A decent article about this is here .

您可以将它们转换为更压缩的格式,或者从磁盘延迟加载它们,仅此而已。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM