Ejemplo n.º 1
0
SharedResourcePtr GraphicsResourceManager::getResourceAsset(const URI &id, GraphicsResource::Type resourceType)
{
  WeakResourcePtr curWeakPtr;
  SharedResourcePtr curSharedPtr;
  if (ResourceManager::getSingleton().isMHashScheme(id)) {
    try {
      curWeakPtr = getResource(RemoteFileId(id).fingerprint().convertToHexString());
      curSharedPtr = curWeakPtr.lock();
    } catch (std::invalid_argument &ia) {
    }
  }
  if (!curSharedPtr) {
    curWeakPtr = getResource(id.toString());
    curSharedPtr = curWeakPtr.lock();
  }
  if (curSharedPtr)
    return curSharedPtr;
  else {
    try {
      if (ResourceManager::getSingleton().isMHashScheme(id)) {
        // std::invalid_argument may be thrown, but is caught by the "catch" below.
        RemoteFileId resourceId(id);
        if (resourceType == GraphicsResource::MESH) {
          curSharedPtr = GraphicsResource::construct<GraphicsResourceMesh>(resourceId);
        }
        else if (resourceType == GraphicsResource::MATERIAL) {
          curSharedPtr = GraphicsResource::construct<GraphicsResourceMaterial>(resourceId);
        }
        else if (resourceType == GraphicsResource::TEXTURE) {
          curSharedPtr = GraphicsResource::construct<GraphicsResourceTexture>(resourceId);
        }
        else if (resourceType == GraphicsResource::SHADER) {
          curSharedPtr = GraphicsResource::construct<GraphicsResourceShader>(resourceId);
        }
        else {
          assert(false);
        }
      }
      else {
        curSharedPtr = GraphicsResource::construct<GraphicsResourceName>(id, resourceType);
      }

      mIDResourceMap[curSharedPtr->getID()] = curSharedPtr;
      mResources.insert(curSharedPtr.get());
    }
    catch (std::invalid_argument& exc) {

    }

    return curSharedPtr;
  }
}
Ejemplo n.º 2
0
SharedResourcePtr GraphicsResourceManager::getResourceEntity(const SpaceObjectReference &id, GraphicsEntity *graphicsEntity)
{
  WeakResourcePtr curWeakPtr = getResource(id.toString());
  SharedResourcePtr curSharedPtr = curWeakPtr.lock();
  if (curSharedPtr)
    return curSharedPtr;
  else {
    curSharedPtr = GraphicsResource::construct<GraphicsResourceEntity>(id, graphicsEntity);
    mIDResourceMap[id.toString()] = curSharedPtr;
    mEntities.insert(curSharedPtr.get());

    return curSharedPtr;
  }
}