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??
Registriert: Do Dez 05, 2002 10:35 Beiträge: 4234 Wohnort: Dortmund
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.
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??
Registriert: Do Dez 05, 2002 10:35 Beiträge: 4234 Wohnort: Dortmund
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.
Registriert: Do Sep 25, 2003 15:56 Beiträge: 7804 Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
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... (or may vice versa. Im not sure... )
_________________ Blog: kevin-fleischer.de und fbaingermany.com
Registriert: Do Dez 05, 2002 10:35 Beiträge: 4234 Wohnort: Dortmund
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.
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??
Registriert: Do Dez 05, 2002 10:35 Beiträge: 4234 Wohnort: Dortmund
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.
Mitglieder in diesem Forum: 0 Mitglieder und 31 Gäste
Du darfst keine neuen Themen in diesem Forum erstellen. Du darfst keine Antworten zu Themen in diesem Forum erstellen. Du darfst deine Beiträge in diesem Forum nicht ändern. Du darfst deine Beiträge in diesem Forum nicht löschen. Du darfst keine Dateianhänge in diesem Forum erstellen.