PDA

View Full Version : Does a png use memory equal to its size?



Christian Knudsen
20-08-2009, 09:07 AM
I'm just wondering if a compressed file format such as png uses up memory equal to its size, or if it's "decompressed" before loaded into memory? I'm using OpenGL and SDL_image to open image files, by the way.

pstudio
20-08-2009, 10:36 AM
At some point the png file has to be decompressed before being displayed. So yes, you'll usually only have the uncompressed data in memory.

If you didn't have to decompress the data to display it, it wouldn't actually be compressed. Then you would have found a more effective way to represent the data.

Christian Knudsen
20-08-2009, 03:14 PM
That makes sense. :)

noeska
20-08-2009, 03:49 PM
But there is also a way to use compressed textures with opengl without decompressing them. Do a search on GL_ARB_texture_compression and/or s3tc (http://www.gamedev.net/reference/programming/features/oglch9excerpt/page2.asp)

WILL
21-08-2009, 03:02 AM
PNG uses a form of LZH encoding. I've dabbled with libpng and even zlib to try and figure out how to make a simple screenshot function with it, but no luck so far. ::)

Christian Knudsen
21-08-2009, 08:54 AM
But there is also a way to use compressed textures with opengl without decompressing them. Do a search on GL_ARB_texture_compression and/or s3tc (http://www.gamedev.net/reference/programming/features/oglch9excerpt/page2.asp)

That's very interesting. I'll play around with this and see how much memory I save. Thanks!

Christian Knudsen
21-08-2009, 10:35 AM
GL_COMPRESSED_RGBA doesn't seem to be supported by the current gl.pas header file. Anybody know how to add this?

EDIT: Never mind. I'm stupid. ::)

EDIT 2: The compression creates a lot of artifacts, so I can't use it for my player sprites, but I can use it for some big and blurry background sprites. Already saved me 15 MB by just compressing them. Nice!

User137
21-08-2009, 12:05 PM
You don't have to keep all textures in memory same time. Especially if its about fullscreen sized images you should load them on demand if its like more than 4 of them.

Christian Knudsen
21-08-2009, 12:26 PM
They're all used all the time, so loading them on demand is not an option, as that would cause a short lag while the program reads from disk.

noeska
21-08-2009, 02:41 PM
What kind of opengl unit are you using? Have a look at the delphigl site and at their dglopengl unit as that one is very complete.

Oops forgot the url: http://www.delphigl.com/

Christian Knudsen
21-08-2009, 04:22 PM
I'm using FreePascal and their OpenGL header files. But I've got it working now - just had to use the glext.pas header file as well.

noeska
21-08-2009, 05:16 PM
The compression ratio is not controlleable?
Btw it would be nice if you posted some info on how you got GL_COMPRESSED_RGBA working.

Christian Knudsen
21-08-2009, 06:05 PM
The compression ratio is not controlleable?
Btw it would be nice if you posted some info on how you got GL_COMPRESSED_RGBA working.


When creating your texture with glTexImage2D instead of using GL_RGBA for the internal format, just use GL_COMPRESSED_RGBA. I had a small problem with my compiler not recognizing this, but that was just because I also had to have glext.pas as a unit.

The documentation says that you can choose between a "FASTEST" and "NICEST" compression algorithm via glHint, but they seemed equally artifacty to me and the compressed textures used the same amount of memory (maybe my setup only supported the one compression algorithm - don't know).

noeska
21-08-2009, 09:41 PM
Ok but should not you use glGetCompressedTexImage or is that s3tc only?

Christian Knudsen
22-08-2009, 08:37 AM
As far as I understood, that's only to receive a texture from disk that has been compressed with the OpenGL compressions?

noeska
22-08-2009, 09:13 AM
::) You know i expected GL_COMPRESSED_RBGA to work the same as s3tc, but i guess it is not.

So with GL_COMPRESSED_RGBA the texture is compressed while sending it to the videocard. And with s3tc you send an already compressed texture to the videocard.

So there is no way to use and already compressed texture with GL_COMPRESSED_RGBA .

Hmm that makes that i bit less useable in my opinion. First you have to decompres your image when loading it from disk and next let opengl compres it again when uploading it to the videocard. With s3tc you can just pass on the already compressed texture in adition to the above method with compressing it on the fly. But you get at least a speed gain uploading the textures to video ram and save some video ram.

Christian Knudsen
22-08-2009, 04:31 PM
I suppose that's true. It's not really and issue for me, though, as I'm loading all the textures I'll need at the start of the "level", so I don't worry about image -> texture load times. I'm just glad that I can compress the textures in memory to save some precious video RAM. :)