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)}.");
 }
        private void _loadGodot(IResourceCache cache, ResourcePath path)
        {
            DebugTools.Assert(GameController.Mode == GameController.DisplayMode.Godot);

            using (var stream = cache.ContentFileRead(path))
            {
                var buffer = stream.ToArray();
                var image  = new Godot.Image();
                var error  = image.LoadPngFromBuffer(buffer);
                if (error != Godot.Error.Ok)
                {
                    throw new InvalidDataException($"Unable to load texture from buffer, reason: {error}");
                }
                godotTexture = new Godot.ImageTexture();
                godotTexture.CreateFromImage(image);
            }

            // Disable filter by default because pixel art.
            godotTexture.SetFlags(godotTexture.GetFlags() & ~(int)Godot.Texture.FlagsEnum.Filter);
            Texture = new GodotTextureSource(godotTexture);
        }
Example #3
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)}.");
 }