module Resource.Combined.Textures
  ( Collection(..)
  , attachDebugNames
  ) where

import RIO

import GHC.Stack (withFrozenCallStack)

import Engine.Vulkan.Types (MonadVulkan)
import Resource.Texture (Texture, debugNameCollection)

data Collection textures fonts a = Collection
  -- XXX: textures go first, as there should be a filler texture at [0]
  { forall (textures :: * -> *) (fonts :: * -> *) a.
Collection textures fonts a -> textures a
textures :: textures a
  , forall (textures :: * -> *) (fonts :: * -> *) a.
Collection textures fonts a -> fonts a
fonts    :: fonts a
  }
  deriving (Int -> Collection textures fonts a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (textures :: * -> *) (fonts :: * -> *) a.
(Show (textures a), Show (fonts a)) =>
Int -> Collection textures fonts a -> ShowS
forall (textures :: * -> *) (fonts :: * -> *) a.
(Show (textures a), Show (fonts a)) =>
[Collection textures fonts a] -> ShowS
forall (textures :: * -> *) (fonts :: * -> *) a.
(Show (textures a), Show (fonts a)) =>
Collection textures fonts a -> String
showList :: [Collection textures fonts a] -> ShowS
$cshowList :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Show (textures a), Show (fonts a)) =>
[Collection textures fonts a] -> ShowS
show :: Collection textures fonts a -> String
$cshow :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Show (textures a), Show (fonts a)) =>
Collection textures fonts a -> String
showsPrec :: Int -> Collection textures fonts a -> ShowS
$cshowsPrec :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Show (textures a), Show (fonts a)) =>
Int -> Collection textures fonts a -> ShowS
Show, forall a b.
a -> Collection textures fonts b -> Collection textures fonts a
forall a b.
(a -> b)
-> Collection textures fonts a -> Collection textures fonts b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (textures :: * -> *) (fonts :: * -> *) a b.
(Functor textures, Functor fonts) =>
a -> Collection textures fonts b -> Collection textures fonts a
forall (textures :: * -> *) (fonts :: * -> *) a b.
(Functor textures, Functor fonts) =>
(a -> b)
-> Collection textures fonts a -> Collection textures fonts b
<$ :: forall a b.
a -> Collection textures fonts b -> Collection textures fonts a
$c<$ :: forall (textures :: * -> *) (fonts :: * -> *) a b.
(Functor textures, Functor fonts) =>
a -> Collection textures fonts b -> Collection textures fonts a
fmap :: forall a b.
(a -> b)
-> Collection textures fonts a -> Collection textures fonts b
$cfmap :: forall (textures :: * -> *) (fonts :: * -> *) a b.
(Functor textures, Functor fonts) =>
(a -> b)
-> Collection textures fonts a -> Collection textures fonts b
Functor, forall a. Collection textures fonts a -> Bool
forall m a.
Monoid m =>
(a -> m) -> Collection textures fonts a -> m
forall a b. (a -> b -> b) -> b -> Collection textures fonts a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts, Eq a) =>
a -> Collection textures fonts a -> Bool
forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts, Num a) =>
Collection textures fonts a -> a
forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts, Ord a) =>
Collection textures fonts a -> a
forall (textures :: * -> *) (fonts :: * -> *) m.
(Foldable textures, Foldable fonts, Monoid m) =>
Collection textures fonts m -> m
forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
Collection textures fonts a -> Bool
forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
Collection textures fonts a -> Int
forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
Collection textures fonts a -> [a]
forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
(a -> a -> a) -> Collection textures fonts a -> a
forall (textures :: * -> *) (fonts :: * -> *) m a.
(Foldable textures, Foldable fonts, Monoid m) =>
(a -> m) -> Collection textures fonts a -> m
forall (textures :: * -> *) (fonts :: * -> *) b a.
(Foldable textures, Foldable fonts) =>
(b -> a -> b) -> b -> Collection textures fonts a -> b
forall (textures :: * -> *) (fonts :: * -> *) a b.
(Foldable textures, Foldable fonts) =>
(a -> b -> b) -> b -> Collection textures fonts a -> b
product :: forall a. Num a => Collection textures fonts a -> a
$cproduct :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts, Num a) =>
Collection textures fonts a -> a
sum :: forall a. Num a => Collection textures fonts a -> a
$csum :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts, Num a) =>
Collection textures fonts a -> a
minimum :: forall a. Ord a => Collection textures fonts a -> a
$cminimum :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts, Ord a) =>
Collection textures fonts a -> a
maximum :: forall a. Ord a => Collection textures fonts a -> a
$cmaximum :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts, Ord a) =>
Collection textures fonts a -> a
elem :: forall a. Eq a => a -> Collection textures fonts a -> Bool
$celem :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts, Eq a) =>
a -> Collection textures fonts a -> Bool
length :: forall a. Collection textures fonts a -> Int
$clength :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
Collection textures fonts a -> Int
null :: forall a. Collection textures fonts a -> Bool
$cnull :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
Collection textures fonts a -> Bool
toList :: forall a. Collection textures fonts a -> [a]
$ctoList :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
Collection textures fonts a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Collection textures fonts a -> a
$cfoldl1 :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
(a -> a -> a) -> Collection textures fonts a -> a
foldr1 :: forall a. (a -> a -> a) -> Collection textures fonts a -> a
$cfoldr1 :: forall (textures :: * -> *) (fonts :: * -> *) a.
(Foldable textures, Foldable fonts) =>
(a -> a -> a) -> Collection textures fonts a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Collection textures fonts a -> b
$cfoldl' :: forall (textures :: * -> *) (fonts :: * -> *) b a.
(Foldable textures, Foldable fonts) =>
(b -> a -> b) -> b -> Collection textures fonts a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Collection textures fonts a -> b
$cfoldl :: forall (textures :: * -> *) (fonts :: * -> *) b a.
(Foldable textures, Foldable fonts) =>
(b -> a -> b) -> b -> Collection textures fonts a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Collection textures fonts a -> b
$cfoldr' :: forall (textures :: * -> *) (fonts :: * -> *) a b.
(Foldable textures, Foldable fonts) =>
(a -> b -> b) -> b -> Collection textures fonts a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Collection textures fonts a -> b
$cfoldr :: forall (textures :: * -> *) (fonts :: * -> *) a b.
(Foldable textures, Foldable fonts) =>
(a -> b -> b) -> b -> Collection textures fonts a -> b
foldMap' :: forall m a.
Monoid m =>
(a -> m) -> Collection textures fonts a -> m
$cfoldMap' :: forall (textures :: * -> *) (fonts :: * -> *) m a.
(Foldable textures, Foldable fonts, Monoid m) =>
(a -> m) -> Collection textures fonts a -> m
foldMap :: forall m a.
Monoid m =>
(a -> m) -> Collection textures fonts a -> m
$cfoldMap :: forall (textures :: * -> *) (fonts :: * -> *) m a.
(Foldable textures, Foldable fonts, Monoid m) =>
(a -> m) -> Collection textures fonts a -> m
fold :: forall m. Monoid m => Collection textures fonts m -> m
$cfold :: forall (textures :: * -> *) (fonts :: * -> *) m.
(Foldable textures, Foldable fonts, Monoid m) =>
Collection textures fonts m -> m
Foldable, forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> Collection textures fonts a -> f (Collection textures fonts b)
forall {textures :: * -> *} {fonts :: * -> *}.
(Traversable textures, Traversable fonts) =>
Functor (Collection textures fonts)
forall {textures :: * -> *} {fonts :: * -> *}.
(Traversable textures, Traversable fonts) =>
Foldable (Collection textures fonts)
forall (textures :: * -> *) (fonts :: * -> *) (m :: * -> *) a.
(Traversable textures, Traversable fonts, Monad m) =>
Collection textures fonts (m a) -> m (Collection textures fonts a)
forall (textures :: * -> *) (fonts :: * -> *) (f :: * -> *) a.
(Traversable textures, Traversable fonts, Applicative f) =>
Collection textures fonts (f a) -> f (Collection textures fonts a)
forall (textures :: * -> *) (fonts :: * -> *) (m :: * -> *) a b.
(Traversable textures, Traversable fonts, Monad m) =>
(a -> m b)
-> Collection textures fonts a -> m (Collection textures fonts b)
forall (textures :: * -> *) (fonts :: * -> *) (f :: * -> *) a b.
(Traversable textures, Traversable fonts, Applicative f) =>
(a -> f b)
-> Collection textures fonts a -> f (Collection textures fonts b)
sequence :: forall (m :: * -> *) a.
Monad m =>
Collection textures fonts (m a) -> m (Collection textures fonts a)
$csequence :: forall (textures :: * -> *) (fonts :: * -> *) (m :: * -> *) a.
(Traversable textures, Traversable fonts, Monad m) =>
Collection textures fonts (m a) -> m (Collection textures fonts a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> Collection textures fonts a -> m (Collection textures fonts b)
$cmapM :: forall (textures :: * -> *) (fonts :: * -> *) (m :: * -> *) a b.
(Traversable textures, Traversable fonts, Monad m) =>
(a -> m b)
-> Collection textures fonts a -> m (Collection textures fonts b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Collection textures fonts (f a) -> f (Collection textures fonts a)
$csequenceA :: forall (textures :: * -> *) (fonts :: * -> *) (f :: * -> *) a.
(Traversable textures, Traversable fonts, Applicative f) =>
Collection textures fonts (f a) -> f (Collection textures fonts a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> Collection textures fonts a -> f (Collection textures fonts b)
$ctraverse :: forall (textures :: * -> *) (fonts :: * -> *) (f :: * -> *) a b.
(Traversable textures, Traversable fonts, Applicative f) =>
(a -> f b)
-> Collection textures fonts a -> f (Collection textures fonts b)
Traversable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (textures :: * -> *) (fonts :: * -> *) a x.
Rep (Collection textures fonts a) x -> Collection textures fonts a
forall (textures :: * -> *) (fonts :: * -> *) a x.
Collection textures fonts a -> Rep (Collection textures fonts a) x
$cto :: forall (textures :: * -> *) (fonts :: * -> *) a x.
Rep (Collection textures fonts a) x -> Collection textures fonts a
$cfrom :: forall (textures :: * -> *) (fonts :: * -> *) a x.
Collection textures fonts a -> Rep (Collection textures fonts a) x
Generic)

instance
  ( Applicative t
  , Applicative f
  )
  => Applicative (Collection t f) where
  pure :: forall a. a -> Collection t f a
pure a
x = Collection
    { $sel:textures:Collection :: t a
textures = forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
    , $sel:fonts:Collection :: f a
fonts    = forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
    }

  Collection t f (a -> b)
af <*> :: forall a b.
Collection t f (a -> b) -> Collection t f a -> Collection t f b
<*> Collection t f a
ax = Collection
    { $sel:textures:Collection :: t b
textures = forall (textures :: * -> *) (fonts :: * -> *) a.
Collection textures fonts a -> textures a
textures Collection t f (a -> b)
af forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (textures :: * -> *) (fonts :: * -> *) a.
Collection textures fonts a -> textures a
textures Collection t f a
ax
    , $sel:fonts:Collection :: f b
fonts    = forall (textures :: * -> *) (fonts :: * -> *) a.
Collection textures fonts a -> fonts a
fonts Collection t f (a -> b)
af forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (textures :: * -> *) (fonts :: * -> *) a.
Collection textures fonts a -> fonts a
fonts Collection t f a
ax
    }

attachDebugNames
  :: ( Traversable textures
     , Traversable fonts
     , MonadVulkan env m
     , HasLogFunc env
     , HasCallStack
     )
  => Collection textures fonts (Texture a)
  -> textures FilePath
  -> fonts FilePath
  -> m ()
attachDebugNames :: forall (textures :: * -> *) (fonts :: * -> *) env (m :: * -> *) a.
(Traversable textures, Traversable fonts, MonadVulkan env m,
 HasLogFunc env, HasCallStack) =>
Collection textures fonts (Texture a)
-> textures String -> fonts String -> m ()
attachDebugNames Collection textures fonts (Texture a)
combined textures String
texturePaths fonts String
fontPaths =
  forall a. HasCallStack => (HasCallStack => a) -> a
withFrozenCallStack forall a b. (a -> b) -> a -> b
$
    forall (t :: * -> *) env (m :: * -> *) layers.
(Traversable t, MonadVulkan env m, HasLogFunc env, HasCallStack) =>
t (Texture layers) -> t String -> m ()
debugNameCollection Collection textures fonts (Texture a)
combined Collection
      { $sel:textures:Collection :: textures String
textures = textures String
texturePaths
      , $sel:fonts:Collection :: fonts String
fonts    = fonts String
fontPaths
      }