DGL
https://delphigl.com/forum/

Many textures
https://delphigl.com/forum/viewtopic.php?f=19&t=4993
Seite 1 von 1

Autor:  lol [ Mo Dez 26, 2005 08:51 ]
Betreff des Beitrags:  Many textures

Hi
i have to load about ~10000 sprites.
How to do it?? I tried with textures(512x512, 256 images per texture) i get about 42 textures, but when i load it into memory, program takes about 66MB! What should i do??

Autor:  Lossy eX [ Mo Dez 26, 2005 10:37 ]
Betreff des Beitrags: 

10000 sprites are really much. I think the best way should be to load not all at ones. Load it if you need them. Otherway you should check if you can use some smaller texture format. Try to load RGBA4 instread of RGBA (8 Bit). If the sprite are gray then use GL_LUMINANCE instead GL_RGB.

Autor:  lol [ Mi Dez 28, 2005 12:02 ]
Betreff des Beitrags: 

ok i did it whis way: i load bmpdata into arrays[3072 bytes each sprite]. It takes me about 30Mb, it's not so bad. But then i have problem. I crete textures when rendering, and memory using grows and grows... I should free texture after render, but how to do it??

Autor:  Lossy eX [ Mi Dez 28, 2005 13:50 ]
Betreff des Beitrags: 

That's an very good question. I dosn't know your application so ich can't tell you the one and only 100 percent right answer. One thing you should never do. Dosn't create your texture every frame. You can create the texture for the sprites you need at this moment. Create twice isn't necessary. If you can group your sprites into regions could help. You entered region 1 (terrain like) sprites 1-2000 were loaded.

Try to find out what sprites you need and how long. For example. The sprite xy is used by 20 Objects. All objects were destroyed so you also can destroy the sprite. New object is creates so you must also create the sprite. If you can't count which sprites you need you also can use some time (30 seconds etc.). If isn't needed since 30 seconds you can free ist. But the best way is the reference count way. Count how many objects used the sprite.

Autor:  Flash [ Mi Dez 28, 2005 14:13 ]
Betreff des Beitrags: 

I feel like I heared that it is faster to use allready allocated textures again, instead of deleating them and recreate. May Lossy can say something about that... 8) (or may vice versa. Im not sure... :oops: )

Autor:  Lossy eX [ Mi Dez 28, 2005 14:26 ]
Betreff des Beitrags: 

If you trys to update some region of an Texture you should use the methode glTexSubImage2D. But if the size or internal format has changes and you must to use the methode glTexImage2D on an allocated texture its better to delete and regenerate it. So OpenGL dosn't must recycle the memory. They could easily free and reallocate the memory.

Autor:  lol [ Fr Dez 30, 2005 13:53 ]
Betreff des Beitrags: 

ok i did it this way:
when it renders frame it cheks that sprite "z" is already loaded. If no then loads it. When i'm using this sprite i making "timestamp". Every "x" frames i check which sprites were'n use for "y" time and the unload them. Working very good. CPU usage is 0-5%(never was higher than 10%).

But i have one more problem:
I have to make sprites transparent when the color is ex. 255,0,255. Well, I need a mask. I cant create masks on start(data such as sprites) because memory using will be ~80MB. The question is: how "dynamic" create a mask??

Autor:  Lossy eX [ Fr Dez 30, 2005 14:05 ]
Betreff des Beitrags: 

You can create mask before you upload texturedata such as at the begining. On small sprites the generation of an mask dosn't take much time.

What you're using to load textures? With my textureloader you easily can create an mask with the method AddAlphaFromColorKey. With other loaders we need to see some code.

To reduce your cpu usage you can run the check only one in a second. Or check it every frame but only 500 sprites. In the next frame the next 500 sprites (500-1000 etc). It gaves you smaller constant usage instead sometimes bigger usage.

Autor:  lol [ Fr Dez 30, 2005 14:10 ]
Betreff des Beitrags: 

i'm using Jan Horn's unit to load textures. But now i'll test Yours one :wink:

Autor:  Lossy eX [ Fr Dez 30, 2005 14:20 ]
Betreff des Beitrags: 

For some code look in our wiki. Use it in object oriented way. In the procedural way you can't add an mask.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/