-- GENERATED by C->Haskell Compiler, version 0.28.1 Switcheroo, 1 April 2016 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/NanoVG/Internal/GL3.chs" #-}
module NanoVG.Internal.GL3 where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp



import qualified Data.Set as S
import           Data.Word
import           Foreign.C.Types

import           NanoVG.Internal.Types
import           NanoVG.Internal.Context
import           NanoVG.Internal.FFIHelpers

-- For now only the GL3 backend is supported

-- We need to include this to define GLuint





{-# LINE 22 "src/NanoVG/Internal/GL3.chs" #-}


data CreateFlags = Antialias
                 | StencilStrokes
                 | Debug
  deriving (Show,Read,Eq,Ord)
instance Enum CreateFlags where
  succ Antialias = StencilStrokes
  succ StencilStrokes = Debug
  succ Debug = error "CreateFlags.succ: Debug has no successor"

  pred StencilStrokes = Antialias
  pred Debug = StencilStrokes
  pred Antialias = error "CreateFlags.pred: Antialias has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from Debug

  fromEnum Antialias = 1
  fromEnum StencilStrokes = 2
  fromEnum Debug = 4

  toEnum 1 = Antialias
  toEnum 2 = StencilStrokes
  toEnum 4 = Debug
  toEnum unmatched = error ("CreateFlags.toEnum: Cannot match " ++ show unmatched)

{-# LINE 26 "src/NanoVG/Internal/GL3.chs" #-}


createGL3 :: (S.Set CreateFlags) -> IO ((Context))
createGL3 a1 =
  let {a1' = bitMask a1} in 
  createGL3'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 29 "src/NanoVG/Internal/GL3.chs" #-}

deleteGL3 :: (Context) -> IO ()
deleteGL3 a1 =
  let {a1' = id a1} in 
  deleteGL3'_ a1' >>
  return ()

{-# LINE 31 "src/NanoVG/Internal/GL3.chs" #-}


type GLuint = Word32

createImageFromHandleGL3 :: (Context) -> (GLuint) -> (CInt) -> (CInt) -> (CreateFlags) -> IO ((Image))
createImageFromHandleGL3 a1 a2 a3 a4 a5 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  let {a5' = (fromIntegral . fromEnum) a5} in 
  createImageFromHandleGL3'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = Image res} in
  return (res')

{-# LINE 36 "src/NanoVG/Internal/GL3.chs" #-}


imageHandleGL3 :: (Context) -> (Image) -> IO ((GLuint))
imageHandleGL3 a1 a2 =
  let {a1' = id a1} in 
  let {a2' = imageHandle a2} in 
  imageHandleGL3'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 39 "src/NanoVG/Internal/GL3.chs" #-}


foreign import ccall unsafe "NanoVG/Internal/GL3.chs.h nvgCreateGL3"
  createGL3'_ :: (C2HSImp.CInt -> (IO (Context)))

foreign import ccall unsafe "NanoVG/Internal/GL3.chs.h nvgDeleteGL3"
  deleteGL3'_ :: ((Context) -> (IO ()))

foreign import ccall unsafe "NanoVG/Internal/GL3.chs.h nvglCreateImageFromHandleGL3"
  createImageFromHandleGL3'_ :: ((Context) -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))

foreign import ccall unsafe "NanoVG/Internal/GL3.chs.h nvglImageHandleGL3"
  imageHandleGL3'_ :: ((Context) -> (C2HSImp.CInt -> (IO C2HSImp.CUInt)))