• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Texture management

Josepho

Member
Hi, I want to port a game that i have to game maker but im a bit confused about how game maker handles textures management. This game has lots and lots of graphics so thats why im so worried about it. I dont want to start porting to discover at the middle of the development that is not possible due to this memory management.

So, how exactly game maker handles with memory?
Are the whole textures included in the sprites loaded when the game is initialized?
If yes, there is any way to customize the loading screen?

Also in this game I have a gallery screen in which the player can browse throught a lot of images, so in the current system i load/unload the images that are being displayed at that time and I unload the ones that are not. Here i was thinking on archiving this by using sprite_add and sprite_flush and the sync: image loaded events. Is that the correct way to do it or is there any more efficient ways?

Many thanks for your help
 

MarceloP

Member
Hellow @Josepho,

1 - So, how exactly game maker handles with memory? Are the whole textures included in the sprites loaded when the game is initialized? - Yes, they're loaded in the memory from the disk when your game starts, but those texture pages are swapped to the video memory when they're are worked on (for example, when a sprite is going to be draw is in a certain texture, it goes to your VRAM).
2 - If yes, there is any way to customize the loading screen? Yes, you just need the paid version of your desired platform for that.

Another 2 infos here that may be valid for you:
1 - You can set the texture page, so if you want to reduce memory swaps to the VRAM and you're on PC or anything with "high" VRAM, you can increase the texture size to 2, or 4 times the normal value. With this combined with Texture Groups, you'll certainly have less texture swaps, although your platform will need a bit more processing time to that. Anyway, may be a valid option depending on your platform.
2 - You can actually force GameMaker to drop everything from the Video Memory by calling a function sprite_flush, but gamemaker usually does it by itself, unless you do need to control that for any reason, I'd let GM do it.

Also in this game I have a gallery screen in which the player can browse throught a lot of images, so in the current system i load/unload the images that are being displayed at that time and I unload the ones that are not. Here i was thinking on archiving this by using sprite_add and sprite_flush and the sync: image loaded events. Is that the correct way to do it or is there any more efficient ways?
If you're talking about using an URL in sprite_add and Async event Image Loaded, that's correct, those work perfectly.
 

kupo15

Member
If you're talking about using an URL in sprite_add and Async event Image Loaded, that's correct, those work perfectly.
I heard there was a way to async load sprites from disk using a url that's not online but no one remembers what the address you would have to do to get it working...if its even possible that is.
 

Josepho

Member
Many thanks for the replies @MarceloP and @kupo15

1 - So, how exactly game maker handles with memory? Are the whole textures included in the sprites loaded when the game is initialized? - Yes, they're loaded in the memory from the disk when your game starts, but those texture pages are swapped to the video memory when they're are worked on (for example, when a sprite is going to be draw is in a certain texture, it goes to your VRAM).

About the textures being loaded at the begining of the game, look for example right now im working in a game that has a result of more than 20 textures pages of 2000x2000 but if i compile it with the yyc it only looks that weights 19 mb in the process, which is a bit confusing it should be a lot more. Isnt it?

About the textures swapp, I read about it throguth internet but i am confused about how it works. So what i understood is that game maker only has 1 texture page loaded at the same time and he loads and unloads different texture pages in order to draw the scene? That would explain why the game weights so little in memory. Am I right about it?

2 - If yes, there is any way to customize the loading screen? Yes, you just need the paid version of your desired platform for that.

Ive got the paid version of windows, and mobile and the only thing i have seen related to that its just the image, but i was talking about a loading bar or something like that. Is it possible? But maybe its not important if its so fast loading the texture pages..

If you're talking about using an URL in sprite_add and Async event Image Loaded, that's correct, those work perfectly.

Not exactly, all the graphics can be inside the game bundle, but they are more than 400 drawings, they use 6 textures pages, the texture pages wont be used dinamicly depending on what im showing on that moment if I group them in the different texture groups and im sure they are not being draw by any draw event?

I heard there was a way to async load sprites from disk using a url that's not online but no one remembers what the address you would have to do to get it working...if its even possible that is.
At the begining i wanted to do it by loading from the external files included in the game, but if game maker has this dark magic system that loads and unloads things from vram then i would prefffer doing it like that.

Which is the proper way to do it?

Sorry about it im comming from using other system in which everything that was displayed on screen used large amounts of ram so i had to be very careful of what i had uploaded to the ram, thats why im so paranoic
 

Smiechu

Member
The real problem with texture swapping occurs when v-ram cannot store all texture pages / surfaces needed to draw the current frame (texture pages have to be constantly reloaded from ram to vram).
Jumping between texture pages has also impact on performance, but it's not so critical as long as all needed texture pages fit the video memory.
Ideal situation is when you have the sprites grouped by scenes, and layers.
I.e. forest enviroment - background, foreground, gui; desert enviroment - background, foreground, gui.
Also, keep the texture pages small as possible for more flexibility. Larger texture pages are needed when you need to have a big hi-res sprites i.e. as backgorund.
 

Josepho

Member
The real problem with texture swapping occurs when v-ram cannot store all texture pages / surfaces needed to draw the current frame (texture pages have to be constantly reloaded from ram to vram).
Jumping between texture pages has also impact on performance, but it's not so critical as long as all needed texture pages fit the video memory.
Ideal situation is when you have the sprites grouped by scenes, and layers.
I.e. forest enviroment - background, foreground, gui; desert enviroment - background, foreground, gui.
Also, keep the texture pages small as possible for more flexibility. Larger texture pages are needed when you need to have a big hi-res sprites i.e. as backgorund.
But for example if I have an scene, in which the player can browse per several assets, and temporally they see stuff from the texture page number 20 and suddenly they only see things for texture page number 21, 20 and 21 will be all time loaded in memory? Or once the page 20 is not used it would be unloaded from memory?
 

MarceloP

Member
Hello again @Josepho

About the textures being loaded at the begining of the game, look for example right now im working in a game that has a result of more than 20 textures pages of 2000x2000 but if i compile it with the yyc it only looks that weights 19 mb in the process, which is a bit confusing it should be a lot more. Isnt it?

About the textures swapp, I read about it throguth internet but i am confused about how it works. So what i understood is that game maker only has 1 texture page loaded at the same time and he loads and unloads different texture pages in order to draw the scene? That would explain why the game weights so little in memory. Am I right about it?
Please people, correct me here if I'm in anyway wrong. But think of it as always being page related.

If you have 2 things that are in different texture pages (or groups) and you're going to draw both in the same scene/surface/anything, you'll have a texture swap during the draw processing. Again, your VRAM is not your RAM, maybe you're just checking your RAM, and much more was already indexed in your VRAM, which you need some driver/program to check.

VRAM is what is loaded in the video card ram, that receives the texture page, draws it and then goes to the next texture page (which is also loaded to the VRAM, unloading the last one if necessary). Therefore, your VRAM may be able to hold more than one texture page, but that depends on your graphics card or the device you're playing on.

GM does all that for you, you simple needs to tell it the size of the texture page and set the texture groups. Which, if they're big, may improve to a lower number of pages to be swapped, but takes longer for each swap to happen (since more memory needs to be translated between RAM and VRAM).

Ive got the paid version of windows, and mobile and the only thing i have seen related to that its just the image, but i was talking about a loading bar or something like that. Is it possible? But maybe its not important if its so fast loading the texture pages..
For some platforms you can't. Usually those things are loaded with the binary at the very initialization of the program. In the case of Android and iOS, you may have load screens but no loading bars (as far as I know). Unless you create one of yourself while loading by code your sprites with sprite_add. For windows it doesn't have a loading screen at all, everything is loaded with the binary. And lastly (I don't know about the remaining ones) in HTML5 you can make an loading extension, which can be googled (i don't have the link anymore) and is pretty simple to build, since every texture page has to be received as an HTTP request for the image, and usually takes some time if you have too many pages or very big texture pages (in this case I can tell you that more pages is usually worse than bigger pages).

Not exactly, all the graphics can be inside the game bundle, but they are more than 400 drawings, they use 6 textures pages, the texture pages wont be used dinamicly depending on what im showing on that moment if I group them in the different texture groups and im sure they are not being draw by any draw event?
Well, it's like I said, they'll be probably loaded to your ram right at the start of the game (which is the slowest process, but believe me, wayyy better than not doing it at the beginning). The things that drop fps are the ones that takes too much of your draw time. Loading a texture page between rooms or when loading a new room is SLOW, since the disk is the slowest thing ever. Therefore, loading it at the beginning of the game allows you only to move from your RAM to your VRAM.

If you have an asset/sprite that is on a texture group, and is going to be draw, the texture group page will be loaded to the VRAM to allow it to be draw. But if you never use that asset at all, but any other asset in that texture page is needed at any given moment, a swap will happen so that other asset is able to be draw....

At the begining i wanted to do it by loading from the external files included in the game, but if game maker has this dark magic system that loads and unloads things from vram then i would prefffer doing it like that.
Which is the proper way to do it?
The proper way to do it is to load everything in the IDE. Memory wise you will be fine because its compressed and only uses one copy of it.
https://forum.yoyogames.com/index.p...jectively-worse-memory-wise-vs-ide-why.47258/
Well, that was a nice discussion, pretty important to take that in mind when deciding what to do. Great!
 

Josepho

Member
So i coded this screen of my game, i was displaying all the images and surprising ly the exe stays in 20 mb , i dont really understand how is possible. Unless game maker never has stored more than one texture page at the same time. I wish some yoyo members could explain if thats the case. It will be interesting
 

Jack S

Member
Going to add externally loaded sprites are written to their own texture page in GMS 2 causing a texture swap every time they are drawn. This is one reason using texture pages internally is important. If you want to load external content it can be a good idea to make external texture pages to reduce swaps. (You have to use an extension or your own code to manage external texture pages - GMS doesn't support manual / imported texture pages sadly.)
 
Ok let's assume i have like 200 texture pages of 2048x2048 and all of them will be loaded at the start of the game in ram. So the ram itself will get burst. There must be some way to load only the pages which are needed to the ram by code and remove when not needed. We can always make a loading screen to carry on such stuff in between game so there won't be any frame drop or freezing. As for vram we already have all the required functions.
 
Top