Closed planetis-m closed 1 year ago
One solution is to have global tables between textureId, meshId, shaderId and their count...
Idea, setMaterialTexture returns a MaterialTexture object that holds a reference to Model and Texture, on destroy they both get unref.
{.experimental: "views".}
type
MaterialTexture* = object
tex: ref Texture
mat: lent MaterialMap # tracks the lifetime of model/materialmap whatever.
var texture: ref Texture
new(texture)
texture[] = loadTextureFromImage(image) # Convert image to texture (VRAM)
model.materials[0].maps[MaterialMapIndex.Diffuse].texture = texture[] # Set map diffuse texture
let mattex = MaterialTexture(tex: texture, mat: model.materials[0].maps[MaterialMapIndex.Diffuse])
seems to work, but better left to be implemented by user code.
Nope doesn't work if you mutate model.
not worth it
One idea was to use ref T, setMaterialTexture is:
But to be unloaded it must unref, however:
We lose the ref association...