1
votes

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.

3

3 Answers

3
votes

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.

0
votes

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.

0
votes

You can convert them to a more compressed format or lazy-load them from the disk, but that's about it.