Large amount of Texture Data

Started by
20 comments, last by 3Dgonewild 15 years, 5 months ago
Hi, in my game using C++/DirectX9 I am loading multiple textures for objects, characters, etc. and it is beginning to slow down the game's load time. Right now the object/character sheets are 2048/1024 pixels and I load them all at the beginning of the game. It currently is like 5 seconds, but I only have a very small portion of the total planned art in the game. My question is, should I focus on trying to shrink and maximize the textures (shrinking them down to a smaller size, like 1024x1024 or 1024x512) or should I devise a better way of loading textures only when I need them? One idea I thought was to load a list of textures at run time, and when I need them, load only the file needed and then use it as needed. Loading textures as I need them, will that be too slow? Also do I just keep it in memory or release it after I have not needed it for awhile?
Advertisement
Five seconds is fantastic! Loading a Crysis level on my PC takes a lot longer than that.

The simplest method is to use smaller textures during development (e.g. in a separate folder, so you can switch instantly). Make 128x128 versions of those 2048x2048 textures, and they will load instantly.
How about coding a texture compiler tool?
Its really simple , here's how it will work:

Compiling :
-Load your texture as usual-Create a binary file( f )-Write header ( f){-Write texture width ( f)-Write texture height ( f )-Write texture channels (f)-Write texture buffer size-Finally , write the pixel buffer}


Loading a texture:
TextureCompiler_Header h;loadCompiledTexture(&h);h.m_Buffer contains image pixel dataNow , just assign the buffer to a texture ID   , and you're ready to go.For example , in opengl , you would have to do this:gen texturesbind textureset pixel unpack alignmentset parametersglTexImage2D (GL_TEXTURE_2D, 0,  h.m_Channels,h.m_Width, h.m_Height, 0,  h.m_Channels==4 ? rgba : rgb , GL_UNSIGNED_BYTE, h.m_Buffer);


I'm sure this will give a big performance boost since
your loader won't have to loop through each pixel and generating the final
surface...it will just copy a pre-compiled image buffer.

Hope it helps...
I would not call this 'compiling'. I'd call it 'creating your own texture image file format'. Does this solve anything?
Quote:Original post by Mattijs2
I would not call this 'compiling'. I'd call it 'creating your own texture image file format'. Does this solve anything?
Sometimes yes, sometimes no. Sometimes (particularly on laptops, which tend to have slow hard drives), hard drive access times will be your bottleneck, in which case you can speed things up by storing highly compressed images (such as JPEG). Other times image processing/decompression will be the bottleneck, so you store the images uncompressed on the HD, in the exact format to load up to the GPU, thus minimising processing.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Ok, so use the jpeg format when you have a slow harddisk. use targa when you have a slow processor. Use DXT compressed dds files when you have both. Each of these formats can be read by other programs.
JPEG texture decompressing for textures takes a lot of time, at least at several machines I have tried. My personal opinion that best results are gained with PNG texture format, and you have compression and alpha channel. Also a slightly better performance is gained if you load file as binary format in memory then load texture directly from memory and not from HD.
I remember that GTA 3 would convert all textures to an optimal format for my video card when I started it for the first time after installation. It took a lot of time... I have not seen any other game do this, however. not even Vice City.
I am using PNG and thank you all for your tips.

I am not sure on how to approach this problem though - The solution 3d Gone Wild seems that it will take just as long, but I could be wrong.

Also, 5 seconds is now with a very small portion of the art. It will be much longer than that later in development.
Quote:
The solution 3d Gone Wild seems that it will take just as long


No , you're wrong. Only the tool will need some tile to unpack/pack pixels...

Custom texture format vs PNG :

Loading a PNG:

open fread "magic number"check signaturecreate png read structcreate png info structinit png ioset sig bytesread nfoget bit depthget color tpehandle color typecheck if ptr is validget bit delpthset stripset packngupdate infoget ihdrallocate memory for textureallocate memory for row pointersloop through pixelsfill imagedestroy structdestroy row pointersclose filereturn pixels


Custom texture file format:

open fcheck header(optional) get width(optional) get height(optional) get channelsread size of pixel bufferallocate memoryf read offset , offset + pixel buffer size

This topic is closed to new replies.

Advertisement