{-# 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
        GLsizei
auxBuffers      <- GettableStateVar GLsizei -> GettableStateVar GLsizei
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *).
MonadIO m =>
GettableStateVar GLsizei -> m GLsizei
get GettableStateVar GLsizei
GL.auxBuffers
        Bool
doubleBuffer    <- GettableStateVar Bool -> GettableStateVar Bool
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *). MonadIO m => GettableStateVar Bool -> m Bool
get GettableStateVar Bool
GL.doubleBuffer
        BufferMode
drawBuffer      <- StateVar BufferMode -> IO BufferMode
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *).
MonadIO m =>
StateVar BufferMode -> m BufferMode
get StateVar BufferMode
GL.drawBuffer

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

        Color4 GLfloat
clearColor      <- StateVar (Color4 GLfloat) -> IO (Color4 GLfloat)
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *).
MonadIO m =>
StateVar (Color4 GLfloat) -> m (Color4 GLfloat)
get StateVar (Color4 GLfloat)
GL.clearColor
        GLsizei
clearStencil    <- StateVar GLsizei -> GettableStateVar GLsizei
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *). MonadIO m => StateVar GLsizei -> m GLsizei
get StateVar GLsizei
GL.clearStencil
        GLdouble
clearDepth      <- StateVar GLdouble -> IO GLdouble
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *). MonadIO m => StateVar GLdouble -> m GLdouble
get StateVar GLdouble
GL.clearDepth
        Color4 GLfloat
clearAccum      <- StateVar (Color4 GLfloat) -> IO (Color4 GLfloat)
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *).
MonadIO m =>
StateVar (Color4 GLfloat) -> m (Color4 GLfloat)
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
forall (m :: * -> *).
MonadIO m =>
StateVar (Color4 Capability) -> m (Color4 Capability)
get StateVar (Color4 Capability)
GL.colorMask
        GLuint
stencilMask     <- StateVar GLuint -> IO GLuint
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *). MonadIO m => StateVar GLuint -> m GLuint
get StateVar GLuint
GL.stencilMask
        Capability
depthMask       <- StateVar Capability -> IO Capability
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *).
MonadIO m =>
StateVar Capability -> m Capability
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]
++ GLsizei -> String
forall a. Show a => a -> String
show GLsizei
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 GLsizei -> String
forall a. Show a => a -> String
show Color4 GLsizei
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]
++ GLsizei -> String
forall a. Show a => a -> String
show GLsizei
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]
++ GLsizei -> String
forall a. Show a => a -> String
show GLsizei
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 GLsizei -> String
forall a. Show a => a -> String
show Color4 GLsizei
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]
++ GLsizei -> String
forall a. Show a => a -> String
show GLsizei
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]
++ GLdouble -> String
forall a. Show a => a -> String
show GLdouble
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]
++ GLuint -> String
forall a. Show a => a -> String
show GLuint
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
forall (m :: * -> *).
MonadIO m =>
StateVar Capability -> m Capability
get StateVar Capability
GL.blend
        BlendEquation
blendEquation   <- StateVar BlendEquation -> IO BlendEquation
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
forall (m :: * -> *).
MonadIO m =>
StateVar BlendEquation -> m BlendEquation
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
forall (m :: * -> *).
MonadIO m =>
StateVar (BlendingFactor, BlendingFactor)
-> m (BlendingFactor, BlendingFactor)
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"