Jump to content

[SOLVED] Questions on how to use NodeSector clear functions


photo

Recommended Posts

Hello all;

 

I need some dynamiclly loading and unloading resource function in my project.

I take a reference to the loading example in data/lightmap/loading.cpp. This example show

how to load resources, but it didnot give example about how to release resources from

memory.

 

In my own try out, i divide the whole scene into four SectorNode and keep these SectorNode

in an array like this:

 

SectorNode sectors[4];

 

sectors[0] = sector1;

sectors[2] = sector2;

sectors[3] = sector3;

sectors[4] = sector4;

 

and sector1, sector2, sector3, sector4 are successfully get from editor getnode functions.

 

I realize the logic that when get start fisrt loading sector1, then loading sector2, clear sector1, then loading sector3,clear sector2,and loading sector4, clear sector3 and loading sector1, clear sector4 and go on and on according to the movement and position of scene camera.

 

the loading and clear code i write is as follows pesudo code:

 

SectorNode oldSector = getCurrentSector(); // for example, sector2

SectotNode newSector = getNextSector(); // for example, sector3

newSector.loadMeshes();

nesSector.loadTextures();

oldSector.clearMeshes(sectors);

oldSector.clearTextures(sectors);

 

 

however, the above logic only works particially right. The load functions works fine while the clear functions seem have no effect. the clear functions runs correctly and didn't complain any errors or warnings, but I see the texture memory usage statistics in profiles is always going up and seems didn't release any thing..

 

 

so what is the right method to use these clear functions to manage resources? need you help.......................

Link to comment

You have to provide only the active sectors for which resources should be loaded, not all sectors. Otherwise no resource unloading can happen (as oldSector is also part of sectors)

 

oldSector.clearMeshes(newSector);

oldSector.clearTextures(newSector);

Link to comment

Thanks for your suggestions, ulf.

I have tried as what you suggested. The NodeSector clear functions must accept an array ID parameter, I put the newSector in a NodeSector array

it runs but still does not release texture resources from memory.

Any other suggestions? Thanks

Link to comment

Don't expect immediately 'visible' texture memory freeing. As far as I can remember Unigine caches resources in an internal memory cache which is cleared on demand. Actually what NodeSector:clear() does is to clear possibly still queued/pending asynchronous resource load operations for no longer required sectors.

Link to comment

Thanks, ulf. good explaination.

 

I wonder if the NodeSector clear functions would release the resource at the last?

If it wouldn't, according to your experience,

are there any functions or techniques in Unigine API can imediately release the specified resources?

 

many thanks again!

Link to comment

I wonder if the NodeSector clear functions would release the resource at the last?

If it wouldn't, according to your experience,

are there any functions or techniques in Unigine API can imediately release the specified resources?

 

Don't think so, Unigine streaming approach is more or less fully transparent (except NodeSector usage). Each managed resource (texture/mesh/mask image) has a timestamp which will be updated on frame access/usage. If a managed resource is not used for a certain count of frames (something like 128 frames if I remember correctly) this resource will be automatically unloaded. If the resource will be once again used (e.g. texture/mesh becomes visible again in the view frustum) it will be automatically reloaded.

Link to comment

BTW NodeSector::loadTextures/Meshes/Masks() uses the previously described automatic background resource loading by 'touching' referenced resources on each call. For not loaded resources this will trigger asynchronous background loading, for already loaded resources this will update each resource access frame timestamp and thereby disable automatic resource unload.

Link to comment
×
×
  • Create New...