{-# OPTIONS_HADDOCK hide #-}

-- | Implements functions to dump portions of the OpenGL state to stdout.
--      Used for debugging.
module Graphics.Gloss.Internals.Interface.Debug
        ( dumpFramebufferState
        , dumpFragmentState )
where
import qualified Graphics.Rendering.OpenGL.GL   as GL
import Graphics.Rendering.OpenGL                (get)

-- | Dump internal state of the OpenGL framebuffer
dumpFramebufferState :: IO ()
dumpFramebufferState :: IO ()
dumpFramebufferState
 = do
        Int32
auxBuffers      <- GettableStateVar Int32 -> GettableStateVar Int32
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get GettableStateVar Int32
GL.auxBuffers
        Bool
doubleBuffer    <- GettableStateVar Bool -> GettableStateVar Bool
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get GettableStateVar Bool
GL.doubleBuffer
        BufferMode
drawBuffer      <- StateVar BufferMode -> IO BufferMode
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar BufferMode
GL.drawBuffer

        Color4 Int32
rgbaBits        <- GettableStateVar (Color4 Int32) -> GettableStateVar (Color4 Int32)
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get GettableStateVar (Color4 Int32)
GL.rgbaBits
        Int32
stencilBits     <- GettableStateVar Int32 -> GettableStateVar Int32
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get GettableStateVar Int32
GL.stencilBits
        Int32
depthBits       <- GettableStateVar Int32 -> GettableStateVar Int32
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get GettableStateVar Int32
GL.depthBits
        Color4 Int32
accumBits       <- GettableStateVar (Color4 Int32) -> GettableStateVar (Color4 Int32)
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get GettableStateVar (Color4 Int32)
GL.accumBits

        Color4 GLfloat
clearColor      <- StateVar (Color4 GLfloat) -> IO (Color4 GLfloat)
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar (Color4 GLfloat)
GL.clearColor
        Int32
clearStencil    <- StateVar Int32 -> GettableStateVar Int32
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar Int32
GL.clearStencil
        Double
clearDepth      <- StateVar Double -> IO Double
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar Double
GL.clearDepth
        Color4 GLfloat
clearAccum      <- StateVar (Color4 GLfloat) -> IO (Color4 GLfloat)
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar (Color4 GLfloat)
GL.clearAccum

        Color4 Capability
colorMask       <- StateVar (Color4 Capability) -> IO (Color4 Capability)
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar (Color4 Capability)
GL.colorMask
        Word32
stencilMask     <- StateVar Word32 -> IO Word32
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar Word32
GL.stencilMask
        Capability
depthMask       <- StateVar Capability -> IO Capability
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar Capability
GL.depthMask

        String -> IO ()
putStr  (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$  String
"* dumpFramebufferState\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  auxBuffers         = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int32 -> String
forall a. Show a => a -> String
show Int32
auxBuffers         String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  doubleBuffer       = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Bool -> String
forall a. Show a => a -> String
show Bool
doubleBuffer       String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  drawBuffer         = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ BufferMode -> String
forall a. Show a => a -> String
show BufferMode
drawBuffer         String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  bits       rgba    = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Color4 Int32 -> String
forall a. Show a => a -> String
show Color4 Int32
rgbaBits           String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"             stencil = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int32 -> String
forall a. Show a => a -> String
show Int32
stencilBits        String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"             depth   = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int32 -> String
forall a. Show a => a -> String
show Int32
depthBits          String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"             accum   = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Color4 Int32 -> String
forall a. Show a => a -> String
show Color4 Int32
accumBits          String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  clear      color   = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Color4 GLfloat -> String
forall a. Show a => a -> String
show Color4 GLfloat
clearColor         String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"             stencil = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int32 -> String
forall a. Show a => a -> String
show Int32
clearStencil       String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"             depth   = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Double -> String
forall a. Show a => a -> String
show Double
clearDepth         String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"             accum   = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Color4 GLfloat -> String
forall a. Show a => a -> String
show Color4 GLfloat
clearAccum         String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  mask       color   = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Color4 Capability -> String
forall a. Show a => a -> String
show Color4 Capability
colorMask          String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"             stencil = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Word32 -> String
forall a. Show a => a -> String
show Word32
stencilMask        String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"             depth   = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Capability -> String
forall a. Show a => a -> String
show Capability
depthMask          String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"


-- | Dump internal state of the fragment renderer.
dumpFragmentState :: IO ()
dumpFragmentState :: IO ()
dumpFragmentState
 = do
        Capability
blend           <- StateVar Capability -> IO Capability
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar Capability
GL.blend
        BlendEquation
blendEquation   <- StateVar BlendEquation -> IO BlendEquation
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar BlendEquation
GL.blendEquation
        (BlendingFactor, BlendingFactor)
blendFunc       <- StateVar (BlendingFactor, BlendingFactor)
-> IO (BlendingFactor, BlendingFactor)
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar (BlendingFactor, BlendingFactor)
GL.blendFunc

        String -> IO ()
putStr  (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$  String
"* dumpFragmentState\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  blend              = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Capability -> String
forall a. Show a => a -> String
show Capability
blend              String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  blend equation     = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ BlendEquation -> String
forall a. Show a => a -> String
show BlendEquation
blendEquation      String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"  blend func         = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ (BlendingFactor, BlendingFactor) -> String
forall a. Show a => a -> String
show (BlendingFactor, BlendingFactor)
blendFunc          String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"