How to load textures faster?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

How to load textures faster?

Post by blackMasoon »

Hello everyone.

I need to play a sequence made of a lot of images in my app (I mean e.g. 640 or 1280 images)... I do sth like this for now:

Code: Select all

 
for(int i = 0; i < filepath.size(); ++i)
        {
                tex.push_back( driver->getTexture( filepath[i].c_str()  ) );
        }
 
Is there any way to make it faster? And I'm not satisfied with better image compression ideas.... I can't modify them. Each image is in JPG format and has ~35 kB.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to load textures faster?

Post by CuteAlien »

Loading depends mostly on your harddisc. So ... getting a faster hd would work. But maybe you can load first and display later - would that be a solution?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Re: How to load textures faster?

Post by blackMasoon »

I'm doing this already... But it takes ages when app starts. Just thought there is an other way to do it faster in the code...
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: How to load textures faster?

Post by mongoose7 »

Well, you could preallocate the 'tex' array with tex.reallocate(1024).
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to load textures faster?

Post by CuteAlien »

No, that's not the allocating - it's the loading. I don't know if the loader itself could be improved, but we use the jpeg lib for that so it's nothing we can change anyway without replacing that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Re: How to load textures faster?

Post by blackMasoon »

Ok thanks for the answer.
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Re: How to load textures faster?

Post by wing64 »

May be this help.
Pack all image in one file and allocate to swap memory then load image from memory to memory.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: How to load textures faster?

Post by hybrid »

Don't know if it's really the loader to blame. In many cases, it's the driver. Make sure you disable mipmaps and avoid NPOT images. These may be scaled in SW otherwise.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Re: How to load textures faster?

Post by Insomniacp »

you can thread your program to preload the textures, if you have a menu or something to begin with then it will work well. just load all the image files into memory or an IIMage then get the data back to the main thread and load them in as textures. This will make it so you don't have to load them all in at once rather over time and only from memory. This will leave the main thread running fast while the other thread takes on the slow disk reads. If you don't have a menu this is kind of useless... Then doing only one disk read like wing64 stated would most likely be the best choice.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: How to load textures faster?

Post by hybrid »

Threading will only work for loading images. If you create textures, you need to do it from the main thread.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Re: How to load textures faster?

Post by Insomniacp »

you can create a texture from the image though can you not? makes it so the texture is loaded in the main thread by doesn't need to read from the hard disk only memory.
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Re: How to load textures faster?

Post by blackMasoon »

Well... multithreading seems to be useless in my case because that video sequence made of those textures must be shown right after the program starts. I could spread that into threads for loading just the first frame, set the video paused and then load the rest of images and create textures with a loading bar...
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: How to load textures faster?

Post by mongoose7 »

You could do it single-threaded by loading the first image and displaying it, then load the second image and display it, etc. So there is always an image on the screen and they do form a sort of movie. How fast the movie plays depends on how fast the images load, but at least you are showing something that is moving.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: How to load textures faster?

Post by hybrid »

If this is all about movie rendering, you might want to look into the video lib support provided by several people here on the forum. This is usually far more resource preserving and uses less data to load from disk etc.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: How to load textures faster?

Post by serengeor »

Most(if not all I played) of the games that show a movie at the start of the game first show some static image for some time (maybe loads the movie at that time?) and then plays the movie.
Working on game: Marrbles (Currently stopped).
Post Reply