I now understand what needs to change to fix this issue. The LookupKey for the _textures map in texturePool.h needs to contain more information. Right now it just keys off the file path where the texture is described, which leads to the bug. From discussion with @rdb the parameters that need to be followed are:
- format
- compression
- quality
- wrap mode
- minfilter
- magfilter
- and other things recorded in a sampler state
The first three I can add to loaderOptions that gets passed to Texture *TexturePool::ns_load_texture and then put those in the LookupKey. The others can all be encapsulated in a SamplerState object. My question is, how do I create this object? Since the object needs to survive beyond the scope of the loader (eggLoader) and becomes part of the map object _textures in TexturePool, I sense I need to allocate this memory and pass a pointer to the TexturePool. The TexturePool would then be responsible for deallocating that memory if that texture is removed from the _textures map object. Deallocation would happen in ns_release_texture and ns_release_all_textures. This would happen like so:
void TexturePool::
ns_release_texture(Texture *tex) {
MutexHolder holder(_lock);
Textures::iterator ti;
for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
if (tex == (*ti).second) {
LookupKey key = (*ti).first;
delete key._texture_sampler;
_textures.erase(ti);
tex->_texture_pool_key = string();
break;
}
}
One other thing, I noticed that apply_texture_attributes creates the sampler object that I want. However, this is called after the load. I am assuming that other texture attributes get populated during this load, so I do not want to move the apply_texture_attributes call to earlier in the function. Is that correct?
Let me know if this is not the best way to do this. Thanks