robert_sasu wrote:When using the code like this:
Code: Select all
Ogre::ResourceGroupManager::getSingletonPtr()->loadResourceGroup(SKYX_RESOURCE_GROUP);
TraceWriteLine("EXISTS {0} {1}",Ogre::ResourceGroupManager::getSingletonPtr()->resourceExists(SKYX_RESOURCE_GROUP,destinationTextureName),
Ogre::ResourceGroupManager::getSingletonPtr()->resourceExists(SKYX_RESOURCE_GROUP,sourceTextureName));
Ogre::TextureManager *textureManager = Ogre::TextureManager::getSingletonPtr();
assert(textureManager != NULL);
const Ogre::TexturePtr sourceTexture = textureManager->getByName(sourceTextureName, SKYX_RESOURCE_GROUP);
if (textureManager->getByName(sourceTextureName, SKYX_RESOURCE_GROUP).isNull()) TraceWriteLine("SOURCE IS NULL");
I get in the output log file that SOURCE IS NULL, even if that it exists as I get TRUE TRUE on the 2nd line. So it's normal that when calling any method from sourceTexture it will fail, because of not an instance of an Object.
So the problem is that I can't load the resource, while the resource exists. Is there any other method for this ? Or am I missing something ?
loadResourceGroup will only load known resources. These are things added automatically by scripts, or manually declared resources. Meshes, skeletons and textures are not known (and will not be loaded by loadResourceGroup) unless declared with ResourceGroupManager::declareResource first (and then the group is initialised), or when you first try to use them (creating an entity with a mesh file works because ogre searches the resource paths for the file if it's not already in the mesh manager).
If you haven't declared those textures, they weren't loaded by the first line.
So why are they shown as true in the second line? Because resourceExists has three steps: 1 - do a case sensitive search of the resource manager. 2 - if that failed, do a case insensitive search. 3 - if both failed, search the hard drive in the resource group's registered paths.
Your files aren't declared or loaded, so they fail the first two checks, but the third succeeds because they do exist on disk.
TextureManager::getByName doesn't go that far, it purely looks at the list of known resources (could be loaded, unloaded, etc, as long as they were declared). So it can't see that the textures are on disk.
You could load them manually into Images (using Image::load) then create a texture from them with TextureManager::loadImage.
Or if they are known at the beginning you could declare them in the ResourceGroupManager so they will be known after initialiseResourceGroup is called (note: each resource group can only be declared once, there's a flag to block later calls. So you can't init the group, then later declare more stuff in it and init again.