    {-# LINE 2 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
    -- -*-haskell-*-
    -- GIMP Toolkit (GTK) OpenGL Extension: Interface GLDrawable
    --
    -- Author : Duncan Coutts
    --
    -- Created: 9 June 2005
    --
    -- Copyright (C) 2005 Duncan Coutts
    --
    -- This library is free software; you can redistribute it and/or
    -- modify it under the terms of the GNU Lesser General Public
    -- License as published by the Free Software Foundation; either
    -- version 2.1 of the License, or (at your option) any later version.
    --
    -- This library is distributed in the hope that it will be useful,
    -- but WITHOUT ANY WARRANTY; without even the implied warranty of
    -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    -- Lesser General Public License for more details.
    --
    -- |
    -- Maintainer : gtk2hs-users@lists.sourceforge.net
    -- Stability : provisional
    -- Portability : portable (depends on GHC)
    --
    -- OpenGL rendering surface interface
    --
    module Graphics.UI.Gtk.OpenGL.Drawable (

    -- * Class Hierarchy
    -- |
    -- @
    -- | GObject
    -- | +----GLDrawable
    -- @

    -- * Types
      GLDrawable,
      GLDrawableClass,
      castToGLDrawable,
      toGLDrawable,

    -- * Methods
      glDrawableMakeCurrent,
      glDrawableIsDoubleBuffered,
      glDrawableSwapBuffers,
      glDrawableWaitGL,
      glDrawableWaitGdk,
      glDrawableGLBegin,
      glDrawableGLEnd,
      glDrawableGetGLConfig,
      glDrawableGetSize,
      glDrawableGetCurrent,
      ) where

    import Control.Monad (liftM)

    import System.Glib.FFI
    import System.Glib.GObject (makeNewGObject)
    import Graphics.UI.Gtk.OpenGL.Types
    {-# LINE 61 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}

    {-# LINE 63 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}

    --------------------
    -- Methods

    -- | Attach an OpenGL rendering context to a GL drawable.
    --
    glDrawableMakeCurrent :: GLDrawableClass self => self
     -> GLContext
     -> IO Bool -- ^ returns @True@ if it is successful, @False@ otherwise.
    glDrawableMakeCurrent self glcontext =
      liftM toBool $
      (\(GLDrawable arg1) (GLContext arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gdk_gl_drawable_make_current argPtr1 argPtr2)
    {-# LINE 75 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)
        (toGLContext glcontext)

    -- | Returns whether the GL drawable supports the double-buffered visual.
    --
    glDrawableIsDoubleBuffered :: GLDrawableClass self => self
     -> IO Bool -- ^ returns @True@ if the double-buffered visual is supported,
                -- @False@ otherwise.
    glDrawableIsDoubleBuffered self =
      liftM toBool $
      (\(GLDrawable arg1) -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_drawable_is_double_buffered argPtr1)
    {-# LINE 86 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)

    -- | Exchange front and back buffers.
    --
    glDrawableSwapBuffers :: GLDrawableClass self => self -> IO ()
    glDrawableSwapBuffers self =
      (\(GLDrawable arg1) -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_drawable_swap_buffers argPtr1)
    {-# LINE 93 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)

    -- | Complete OpenGL execution prior to subsequent Gdk drawing calls.
    --
    glDrawableWaitGL :: GLDrawableClass self => self -> IO ()
    glDrawableWaitGL self =
      (\(GLDrawable arg1) -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_drawable_wait_gl argPtr1)
    {-# LINE 100 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)

    -- | Complete Gdk drawing execution prior to subsequent OpenGL calls.
    --
    glDrawableWaitGdk :: GLDrawableClass self => self -> IO ()
    glDrawableWaitGdk self =
      (\(GLDrawable arg1) -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_drawable_wait_gdk argPtr1)
    {-# LINE 107 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)

    -- | Delimits the begining of the OpenGL execution.
    --
    glDrawableGLBegin :: GLDrawableClass self => self
     -> GLContext -- ^ @glcontext@ - a 'GLContext'.
     -> IO Bool -- ^ returns @True@ if it is successful, @False@ otherwise.
    glDrawableGLBegin self glcontext =
      liftM toBool $
      (\(GLDrawable arg1) (GLContext arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gdk_gl_drawable_gl_begin argPtr1 argPtr2)
    {-# LINE 117 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)
        (toGLContext glcontext)

    -- | Delimits the end of the OpenGL execution.
    --
    glDrawableGLEnd :: GLDrawableClass self => self -> IO ()
    glDrawableGLEnd self =
      (\(GLDrawable arg1) -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_drawable_gl_end argPtr1)
    {-# LINE 125 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)

    -- | Gets 'GLConfig' with which the GL drawable is configured.
    --
    glDrawableGetGLConfig :: GLDrawableClass self => self -> IO GLConfig
    glDrawableGetGLConfig self =
      makeNewGObject mkGLConfig $
      (\(GLDrawable arg1) -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_drawable_get_gl_config argPtr1)
    {-# LINE 133 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)

    -- | Returns the width and height of the GL drawable.
    --
    glDrawableGetSize :: GLDrawableClass self => self
     -> IO (Int, Int) -- ^ @(width, height)@
    glDrawableGetSize self =
      alloca $ \widthPtr ->
      alloca $ \heightPtr ->
      (\(GLDrawable arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_drawable_get_size argPtr1 arg2 arg3)
    {-# LINE 143 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}
        (toGLDrawable self)
        widthPtr
        heightPtr
      >>
      peek widthPtr >>= \width ->
      peek heightPtr >>= \height ->
      return (fromIntegral width, fromIntegral height)

    -- | Returns the current 'GLDrawable'.
    --
    glDrawableGetCurrent ::
        IO (Maybe GLDrawable) -- ^ returns the current 'Drawable' or @Nothing@ if
                              -- there is no current drawable.
    glDrawableGetCurrent =
      maybeNull (makeNewGObject mkGLDrawable) $
      gdk_gl_drawable_get_current
    {-# LINE 159 "./Graphics/UI/Gtk/OpenGL/Drawable.chs" #-}

    foreign import ccall safe "gdk_gl_drawable_make_current"
      gdk_gl_drawable_make_current :: ((Ptr GLDrawable) -> ((Ptr GLContext) -> (IO CInt)))

    foreign import ccall safe "gdk_gl_drawable_is_double_buffered"
      gdk_gl_drawable_is_double_buffered :: ((Ptr GLDrawable) -> (IO CInt))

    foreign import ccall safe "gdk_gl_drawable_swap_buffers"
      gdk_gl_drawable_swap_buffers :: ((Ptr GLDrawable) -> (IO ()))

    foreign import ccall safe "gdk_gl_drawable_wait_gl"
      gdk_gl_drawable_wait_gl :: ((Ptr GLDrawable) -> (IO ()))

    foreign import ccall safe "gdk_gl_drawable_wait_gdk"
      gdk_gl_drawable_wait_gdk :: ((Ptr GLDrawable) -> (IO ()))

    foreign import ccall safe "gdk_gl_drawable_gl_begin"
      gdk_gl_drawable_gl_begin :: ((Ptr GLDrawable) -> ((Ptr GLContext) -> (IO CInt)))

    foreign import ccall safe "gdk_gl_drawable_gl_end"
      gdk_gl_drawable_gl_end :: ((Ptr GLDrawable) -> (IO ()))

    foreign import ccall safe "gdk_gl_drawable_get_gl_config"
      gdk_gl_drawable_get_gl_config :: ((Ptr GLDrawable) -> (IO (Ptr GLConfig)))

    foreign import ccall safe "gdk_gl_drawable_get_size"
      gdk_gl_drawable_get_size :: ((Ptr GLDrawable) -> ((Ptr CInt) -> ((Ptr CInt) -> (IO ()))))

    foreign import ccall safe "gdk_gl_drawable_get_current"
      gdk_gl_drawable_get_current :: (IO (Ptr GLDrawable))