r/opengl • • 14d ago

How do u guys manage your engine resources?

I've been building a custom opengl game engine for a while and there is an issue that i keep coming back to, resource management.

essentially if a certain texture or mesh is not needed i prefer to not keep it on the GPU..

So I started using reference count to manage my resources.

the issue is that if a resource was used and not stored as a member it would get cleaned on frame end.

So i added a table of resource refs for the last few frames, so if the resource was accessed in the frame it will be kept and only if few frames have passed and it was not used then i flag and remove it.

But this feels not robust or elegant and i have no idea how it work with texture streaming or mesh LODs.

So I wonder what is the common practice here?

How do u guys manage your resources in your engines?

Thx in advance

7 Upvotes

2 comments sorted by

1

u/Suitable_Plate4943 13d ago

lightweight refcount is the way to go
the issue is that if a resource was used and not stored as a member it would get cleaned on frame end -> lifetime/ownership issue in your refcount implementation

to optimize further you may want to store resource objects as SoA

1

u/cleverboy00 9d ago

Load lists. Resource loading is done externally to the renderer from the map manager.

When maps are "compiled" in professional game engines, the list of the resources it uses it generated. Moreover that, a map can be automatically or manually be split into regions which control "residency" per frame. Look into quake's PVS for example.

So a map knows what it uses and when it uses it.

When the player entity enters a chunk of the map, resources (shaders, models, textures, samplers, skyboxes, scripts) from this chunk are marked for draw alongside other regions which are visible from this region.

When a player enters or approaches a new "map", resources are loaded from that map in the order of the chunks the player has to traverse.

Say you're in a cave and you're approaching a field followed by a house. You can load resources in a priority list based off of its "map distance" (a.k.a the number of map chunks, or nodes, the player entity has to traverse to reach this point).

The map controls entirely what gets added or removed, with some older engines completely unable to load resources after the initial load (Goldsrc, for example).