Loading a lot of Textures is slow

Hello Community,

I am currently working in an application that requires to load a lot of different images (png, jpg, …) to the scene.

For each image,

  1. I create a Texture
  2. I attached this texture to a TextureState
  3. I create a Quad and make the previously created TextureState be it's renderState.
  4. Then i add this to the a Node, which is then added to the RootNode.

    Currently I am adding 90 images using the steps described above, and is taking around 2.5 minutes to do this.

    Is there a faster way I can load a high quantity of images?



You could also consider combining those thumbnails into a single texture.

Thanks core-dump. That helps.

I think instead of displaying all the images in the scene, I will use a small 64 x 64 image icon for all images. This way the user can click in the icon, and then the real Image will appear and it will unlock the node.

Hi there,

What are the dimensions of the images?  Of course higher resolution textures take longer to load, but images sized in powers of 2 also load better (i.e: 512x512, 1024,1024, 2048,2048)…

Hello sbook,

51 of those images are powers of 2, the other 39 of them aren't.

For those that aren't, I'm using TextureState.overrideNonPowersOfTwoTextureSupport, which then re-scales the images to be of powers of two.

And the size of the images vary, some are as small as 128 x 128, and some as big as 1052 x 1052

If the GPU on which you run this application supports NPOT textures then there's no reason to override the support so that they are scaled. I would suggest you convert all your PNG/JPG/… images to DDS format with DXT compression and pre-generated mipmaps, then you could load all these textures in a few seconds.

I should have noted that the way I was doing it at first was by downloading images from a server, which was making it take soo long. Just for the sake of testing,I am now loading 900 images that are read from a local folder on my computer and it only takes 13 seconds to load the scene with all 900 nodes.

Thanks for the hint Momoko_fan, I was overridingNonPowersoftwo since some machines can't handle powers of two (like a mac I have for testing purposes), but your comment about NPOT made me realize I could easily check to see if a computer supports powers of two and don't waste time rescaling images if it isn't necessary. To check if your computer supports powers of two you can use GLContext.getCapabilities().GL_ARB_texture_non_power_of_two which will return true or false.

Now I have another issue though, the frames per second gets really really crappy with 900 nodes in the scene, which is to be expected. Any ideas on how to speed things up ?

I started looking at shareNode, but I don't see how it will be useful for my situation since each of those 900 nodes needs to be unique for the user to be able to pick them and manipulate them. If the user edits one Node I don't want those changes to transfer to other nodes and i think using sharedNode will transfer the changes to the other node.

Thanks for your help guys.

Try Node.lock() which will create a display list. (if the Node is static)

You need to unlock it to be able to move/rotate it.

Thanks for the input Alric.

I am now using DiscreteLodNode with two switchmodels, one represents a 64 thumbnail image attached to a quad and the other the original image attached to a quad. This is working great for me.

Thanks to all who helped.

In order to speed things up, I will now convert the png and jpg images to DDS.

However, before I do this, I wanted to ask if anyone knows if there are issues applying DDS images to Textures in Linux and on Macs. DDS stands for Microsoft DirectDraw Surface, so I am wondering if it will cause problems while rendering this images in linux and Macs.



You could try this: http://www.jmonkeyengine.com/forum/index.php?topic=7931.msg62221#msg62221