Example #1
0
 public override void Load(IResourceCache cache, string diskPath)
 {
     if (!File.Exists(diskPath))
     {
         throw new FileNotFoundException(diskPath);
     }
     godotTexture = new Godot.ImageTexture();
     godotTexture.Load(diskPath);
     // If it fails to load it won't change the texture dimensions, so they'll still be at zero.
     if (godotTexture.GetWidth() == 0)
     {
         throw new InvalidDataException();
     }
     // Disable filter by default because pixel art.
     godotTexture.SetFlags(godotTexture.GetFlags() & ~(int)Godot.Texture.FlagsEnum.Filter);
     Texture = new GodotTextureSource(godotTexture);
     // Primarily for tracking down iCCP sRGB errors in the image files.
     Logger.Debug($"Loaded texture {Path.GetFullPath(diskPath)}.");
 }
Example #2
0
 public override void Load(IResourceCache cache, ResourcePath path)
 {
     if (!cache.ContentFileExists(path))
     {
         throw new FileNotFoundException("Content file does not exist for texture");
     }
     if (!cache.TryGetDiskFilePath(path, out string diskPath))
     {
         throw new InvalidOperationException("Textures can only be loaded from disk.");
     }
     godotTexture = new Godot.ImageTexture();
     godotTexture.Load(diskPath);
     // If it fails to load it won't change the texture dimensions, so they'll still be at zero.
     if (godotTexture.GetWidth() == 0)
     {
         throw new InvalidDataException();
     }
     // Disable filter by default because pixel art.
     godotTexture.SetFlags(godotTexture.GetFlags() & ~(int)Godot.Texture.FlagsEnum.Filter);
     Texture = new GodotTextureSource(godotTexture);
     // Primarily for tracking down iCCP sRGB errors in the image files.
     Logger.Debug($"Loaded texture {Path.GetFullPath(diskPath)}.");
 }