コード例 #1
0
TexturePtr GLTextureManager::getBinding(NamedBindablePtr bindable)
{
    // Check if we got an empty MapExpression, and return the NOT FOUND texture
    // if so
    if (!bindable)
    {
        return getShaderNotFound();
    }

    // Check if we already have the texture, otherwise construct it
    std::string identifier = bindable->getIdentifier();
    TextureMap::iterator i = _textures.find(identifier);
    if (i != _textures.end())
    {
        // Found, return
        return i->second;
    }
    else
    {
        // Create and insert texture object, if it is valid
        TexturePtr texture = bindable->bindTexture(identifier);
        if (texture)
        {
            _textures.insert(TextureMap::value_type(identifier, texture));
            return texture;
        }
        else
        {
            rError() << "[shaders] Unable to load texture: "
                                << identifier << std::endl;
            return getShaderNotFound();
        }
    }
}
コード例 #2
0
TexturePtr GLTextureManager::getBinding(const std::string& fullPath,
                                          const std::string& moduleNames) 
{
    // check if the texture has to be loaded
    TextureMap::iterator i = _textures.find(fullPath);

	if (i == _textures.end()) 
    {
	    ImagePtr img = ImageFileLoader::imageFromFile(fullPath, moduleNames);

	    // see if the MapExpression returned a valid image
	    if (img != NULL) 
       {
            // Constructor returned a valid image, now create the texture object
            TexturePtr texture = img->bindTexture(fullPath);
			_textures[fullPath] = texture;
	
			globalOutputStream() << "[shaders] Loaded texture: " << fullPath << "\n";
	    }
	    else {
	    	globalErrorStream() << "[shaders] Unable to load texture: " << fullPath << "\n";
			// invalid image produced, return shader not found
			return getShaderNotFound();
	    }
	}

    // Cast should succeed since all single image textures will be Texture2D
    return _textures[fullPath];
}