View Full Version : Limit on no. of textures loaded?

Chirag Varde
03-10-2011, 05:41 AM
Recently I had been working on a game. For creating a GUI, I used many textures in the game. For example, to display start option I created a texture object from a file with start written in it and then mapped it to a quad. There are some concepts I would like to clear.

What I know about textures is that every time I read data from any file and attach it to some texture object, it dynamically stores all the values of r, g and b components of each pixel of the image. Now if I try to load many textures at the start of the program, around 15, the program starts slowing down. May be the total data it stores dynamically has reached its limit. What I ended up doing was to reduce the textures and develop a just-working game.

Now can you suggest me methods to load many textures at a go without any sacrifice in performance.

03-10-2011, 07:22 AM
You have not said much that would help us determine what the problem is.
What does your code look like? Are you creating your textures only once or are your creating them every time you draw the scene? Are you using mipmaps? What hardware?

Anyway, read the stuff at the Wiki

03-10-2011, 10:32 AM
It will always take more time to render with textures than without.

After, it depends on how you do things like V-man says. Use small textures for buttons. Use mipmaps whenever the rendered texture size is not the same size as for the original. Also, ensure you have acceleration (mainly under Linux).

Alfonse Reinheart
03-10-2011, 10:34 AM
Now if I try to load many textures at the start of the program, around 15, the program starts slowing down.

Define "slowing down." Did it go from 1000 FPS to 900 FPS? Did it go from 60FPS to 25FPS?

03-10-2011, 01:47 PM
15 textures is a very small amount - modern games use many many times this without any trouble. You're obviously doing something wrong if you can measure a slow down with this, but what could it be? Difficult to say unless you provide more information. What kind of hardware have you? What size are the textures? Could you post some of your code?

Chirag Varde
03-14-2011, 08:12 PM
sorry all for not replying early

let me tell you more about code

I used texture for creating a GUI for the game. Like the buttons for "start the game", "continue the game", etc. I loaded 256*256 .raw image for that.
I got one fault in my code. I was doing all these things in immediate mode. Since most of the textures I was using were static, I should have gone with display lists and with that the performance got improved (by performance I mean about 50fps and I do not exactly know the fps when the application slowed down, but it was quite visible).

Now when I render screen with display lists, the application is not slowing down.
For now, I have not included any texture to moving objects and I do want to do that.
About my graphics hardware, it is 512MB graphics card of nVidia called nVidia GeForce G 105M.

May be I should come to my real doubt now. The doubt is: how the things are going on when the textures are loaded in the program? I mean if I load more than say 15 textures, each of lets say 256*256 pixels and 3 bytes for each pixel, then at rum time will the program store 15*256*256*3 bytes of data?? Isn't it a large data?

Chirag Varde
03-14-2011, 08:16 PM
and yeah, I am not yet using mipmaps. I should probably learn about them.

03-14-2011, 08:22 PM
It's actually more likely 4 bytes, not 3. See http://www.opengl.org/wiki/Common_Mistakes#Texture_upload_and_pixel_reads for more info.

So let's add things up. A 256x256 texture is 256k, and 15 of them is 3.75mb. Nowhere near your 512. Even Quake, back in 1996, used a comparable amount of texture memory and ran fast enough on a 4mb card. So if you're noticing slowdown from 15 such textures, or if you have reason to be concerned about memory usage, then something is badly wrong with your code (like, for example, you may be calling glGenTextures/glTeximage2D each frame).