Jump to content
  • Advertisement
Sign in to follow this  
Crazyfool

Large amount of Texture Data

This topic is 3552 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 data

Now , 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 textures
bind texture
set pixel unpack alignment
set parameters

glTexImage2D (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...

Share this post


Link to post
Share on other sites
I would not call this 'compiling'. I'd call it 'creating your own texture image file format'. Does this solve anything?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 f
read "magic number"
check signature
create png read struct
create png info struct
init png io
set sig bytes
read nfo
get bit depth
get color tpe
handle color type
check if ptr is valid
get bit delpth
set strip
set packng
update info
get ihdr
allocate memory for texture
allocate memory for row pointers
loop through pixels
fill image
destroy struct
destroy row pointers
close file
return pixels




Custom texture file format:


open f
check header
(optional) get width
(optional) get height
(optional) get channels
read size of pixel buffer
allocate memory
f read offset , offset + pixel buffer size


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!