This repository has been archived on 2025-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
htanks/Bindings/GLX.hs

331 lines
12 KiB
Haskell
Raw Normal View History

2010-02-22 16:50:42 +01:00
{-# INCLUDE <GL/glx.h> #-}
{-# LINE 1 "GLX.chs" #-}
{-# LANGUAGE ForeignFunctionInterface, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
{-# LINE 2 "GLX.chs" #-}
module Bindings.GLX ( createColormap
, createWindow
, setClassHint
2010-02-22 16:50:42 +01:00
, chooseFBConfig
, getVisualFromFBConfig
2010-02-22 18:27:18 +01:00
, VisualInfo(..)
, SetWindowAttributes(..)
2010-02-22 16:50:42 +01:00
, nullSetWindowAttributes
2010-02-22 18:27:18 +01:00
, renderType
, rgbaBit
, drawableType
, windowBit
, xRenderable
, doublebuffer
, depthSize
, stencilSize
, createContext
, makeCurrent
2010-02-22 22:25:06 +01:00
, destroyContext
, swapBuffers
2010-02-22 18:27:18 +01:00
, Context(..)
, Drawable
2010-02-22 16:50:42 +01:00
) where
import Data.Generics
import Data.Int
import Data.Word
import Foreign.C.String (withCString)
2010-02-22 16:50:42 +01:00
import Foreign.C.Types
import Foreign.Ptr
import Foreign.Marshal.Alloc (alloca, allocaBytes)
2010-02-22 16:50:42 +01:00
import Foreign.Marshal.Array (peekArray, withArray0)
import Foreign.Storable
import Graphics.X11.Types (AttributeMask, Colormap, ColormapAlloc, Cursor, EventMask, Pixmap, Window, WindowClass, VisualID, XID)
import Graphics.X11.Xlib.Extras (none, xFree, ClassHint, resName, resClass, TextProperty)
2010-02-22 16:50:42 +01:00
import Graphics.X11.Xlib.Types (Dimension, Display, Pixel, Position)
2010-02-25 02:15:26 +01:00
{-# LINE 44 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
type Drawable = XID
2010-02-22 18:27:18 +01:00
newtype FBConfig = FBConfig (Ptr FBConfig)
2010-02-22 16:50:42 +01:00
deriving (Eq, Ord, Show, Typeable, Data, Storable)
2010-02-22 18:27:18 +01:00
newtype Context = Context (Ptr Context)
2010-02-22 16:50:42 +01:00
deriving (Eq, Ord, Show, Typeable, Data, Storable)
newtype Visual = Visual (Ptr Visual)
deriving (Eq, Ord, Show, Typeable, Data, Storable)
2010-02-22 18:27:18 +01:00
data VisualInfo = VisualInfo
{ viVisual :: !Visual
, viVisualid :: !VisualID
, viScreen :: !CInt
, viDepth :: !CInt
, viClass :: !CInt
, viRedMask :: !CULong
, viGreenMask :: !CULong
, viBlueMask :: !CULong
, viColormapSize :: !CInt
, viBitsPerRgb :: !CInt
2010-02-22 16:50:42 +01:00
} deriving (Eq, Ord, Show, Typeable)
2010-02-22 18:27:18 +01:00
instance Storable VisualInfo where
2010-02-22 16:50:42 +01:00
sizeOf _ = ((40))
2010-02-25 02:15:26 +01:00
{-# LINE 72 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
alignment _ = alignment (undefined :: CULong)
peek vi = do
visual <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 76 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
visualid <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 77 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
screen <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 78 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
depth <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 79 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
viclass <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 80 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
red_mask <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 81 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
green_mask <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 82 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
blue_mask <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 83 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
colormap_size <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 84 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
bits_per_rgb <- ((\hsc_ptr -> peekByteOff hsc_ptr 36)) vi
2010-02-25 02:15:26 +01:00
{-# LINE 85 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
return (VisualInfo visual visualid screen depth viclass red_mask green_mask blue_mask colormap_size bits_per_rgb)
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
poke vi (VisualInfo visual visualid screen depth viclass red_mask green_mask blue_mask colormap_size bits_per_rgb) = do
2010-02-22 16:50:42 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) vi visual
2010-02-25 02:15:26 +01:00
{-# LINE 91 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) vi visualid
2010-02-25 02:15:26 +01:00
{-# LINE 92 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) vi screen
2010-02-25 02:15:26 +01:00
{-# LINE 93 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) vi depth
2010-02-25 02:15:26 +01:00
{-# LINE 94 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) vi viclass
2010-02-25 02:15:26 +01:00
{-# LINE 95 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) vi red_mask
2010-02-25 02:15:26 +01:00
{-# LINE 96 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) vi green_mask
2010-02-25 02:15:26 +01:00
{-# LINE 97 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 28)) vi blue_mask
2010-02-25 02:15:26 +01:00
{-# LINE 98 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) vi colormap_size
2010-02-25 02:15:26 +01:00
{-# LINE 99 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 36)) vi bits_per_rgb
2010-02-25 02:15:26 +01:00
{-# LINE 100 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
data SetWindowAttributes = SetWindowAttributes
{ swaBackgroundPixmap :: !Pixmap
, swaBackgroundPixel :: !Pixel
, swaBorderPixmap :: !Pixmap
, swaBitGravity :: !CInt
, swaWinGravity :: !CInt
, swaBackingStore :: !CInt
, swaBackingPlanes :: !CULong
, swaBackingPixel :: !CULong
, swaSaveUnder :: !Bool
, swaEventMask :: !EventMask
, swaDoNotPropagateMask :: !CULong
, swaOverrideRedirect :: !Bool
, swaColormap :: !Colormap
, swaCursor :: !Cursor
2010-02-22 16:50:42 +01:00
} deriving (Eq, Ord, Show, Typeable)
2010-02-22 18:27:18 +01:00
instance Storable SetWindowAttributes where
2010-02-22 16:50:42 +01:00
sizeOf _ = ((60))
2010-02-25 02:15:26 +01:00
{-# LINE 121 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
alignment _ = alignment (undefined :: CULong)
peek swa = do
background_pixmap <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 125 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
background_pixel <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 126 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
border_pixmap <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 127 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
bit_gravity <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 128 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
win_gravity <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 129 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
backing_store <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 130 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
backing_planes <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 131 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
backing_pixel <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 132 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
save_under <- ((\hsc_ptr -> peekByteOff hsc_ptr 36)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 133 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
event_mask <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 134 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
do_not_propagate_mask <- ((\hsc_ptr -> peekByteOff hsc_ptr 44)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 135 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
override_redirect <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 136 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
colormap <- ((\hsc_ptr -> peekByteOff hsc_ptr 52)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 137 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
cursor <- ((\hsc_ptr -> peekByteOff hsc_ptr 56)) swa
2010-02-25 02:15:26 +01:00
{-# LINE 138 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
return (SetWindowAttributes
2010-02-22 16:50:42 +01:00
background_pixmap
background_pixel
border_pixmap
bit_gravity
win_gravity
backing_store
backing_planes
backing_pixel
save_under
event_mask
do_not_propagate_mask
override_redirect
colormap
cursor)
2010-02-22 18:27:18 +01:00
poke swa (SetWindowAttributes
2010-02-22 16:50:42 +01:00
background_pixmap
background_pixel
border_pixmap
bit_gravity
win_gravity
backing_store
backing_planes
backing_pixel
save_under
event_mask
do_not_propagate_mask
override_redirect
colormap
cursor) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) swa background_pixmap
2010-02-25 02:15:26 +01:00
{-# LINE 171 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) swa background_pixel
2010-02-25 02:15:26 +01:00
{-# LINE 172 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) swa border_pixmap
2010-02-25 02:15:26 +01:00
{-# LINE 173 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) swa bit_gravity
2010-02-25 02:15:26 +01:00
{-# LINE 174 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) swa win_gravity
2010-02-25 02:15:26 +01:00
{-# LINE 175 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) swa backing_store
2010-02-25 02:15:26 +01:00
{-# LINE 176 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 28)) swa backing_planes
2010-02-25 02:15:26 +01:00
{-# LINE 177 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) swa backing_pixel
2010-02-25 02:15:26 +01:00
{-# LINE 178 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 36)) swa save_under
2010-02-25 02:15:26 +01:00
{-# LINE 179 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 40)) swa event_mask
2010-02-25 02:15:26 +01:00
{-# LINE 180 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 44)) swa do_not_propagate_mask
2010-02-25 02:15:26 +01:00
{-# LINE 181 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 48)) swa override_redirect
2010-02-25 02:15:26 +01:00
{-# LINE 182 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 52)) swa colormap
2010-02-25 02:15:26 +01:00
{-# LINE 183 "GLX.chs" #-}
2010-02-22 22:25:06 +01:00
((\hsc_ptr -> pokeByteOff hsc_ptr 56)) swa cursor
2010-02-25 02:15:26 +01:00
{-# LINE 184 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
nullSetWindowAttributes :: SetWindowAttributes
nullSetWindowAttributes = (SetWindowAttributes 0 0 0 0 0 0 0 0 False 0 0 False 0 0)
2010-02-22 16:50:42 +01:00
foreign import ccall unsafe "GL/glx.h XCreateColormap"
createColormap :: Display -> Window -> Visual -> ColormapAlloc -> IO Colormap
foreign import ccall unsafe "GL/glx.h XCreateWindow"
createWindow :: Display -> Window -> Position -> Position ->
Dimension -> Dimension -> CInt -> CInt -> WindowClass ->
2010-02-22 18:27:18 +01:00
Visual -> AttributeMask -> Ptr SetWindowAttributes -> IO Window
2010-02-22 16:50:42 +01:00
foreign import ccall unsafe "GL/glx.h XSetClassHint"
xSetClassHint :: Display -> Window -> Ptr ClassHint -> IO ()
setClassHint :: Display -> Window -> ClassHint -> IO ()
setClassHint disp wnd hint = allocaBytes ((8)) $ \p ->
2010-02-25 02:15:26 +01:00
{-# LINE 202 "GLX.chs" #-}
withCString (resName hint) $ \res_name ->
withCString (resClass hint) $ \res_class -> do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p res_name
2010-02-25 02:15:26 +01:00
{-# LINE 205 "GLX.chs" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) p res_class
2010-02-25 02:15:26 +01:00
{-# LINE 206 "GLX.chs" #-}
xSetClassHint disp wnd p
2010-02-22 16:50:42 +01:00
foreign import ccall unsafe "GL/glx.h glXChooseFBConfig"
2010-02-22 18:27:18 +01:00
glXChooseFBConfig :: Display -> CInt -> Ptr CInt -> Ptr CInt -> IO (Ptr FBConfig)
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
chooseFBConfig :: Display -> CInt -> [(CInt, CInt)] -> IO [FBConfig]
2010-02-22 16:50:42 +01:00
chooseFBConfig disp sc attr = alloca $ \n -> withArray0 (fromIntegral none) (concatMap (\(a,b) -> [a,b]) attr) $ \attrp -> do
configs <- glXChooseFBConfig disp sc attrp n
nelements <- peek n
2010-02-22 18:42:09 +01:00
configlist <- peekArray (fromIntegral nelements) configs
xFree configs
return configlist
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
renderType :: CInt
renderType = (32785)
2010-02-25 02:15:26 +01:00
{-# LINE 223 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
rgbaBit :: CInt
rgbaBit = (1)
2010-02-25 02:15:26 +01:00
{-# LINE 226 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
drawableType :: CInt
drawableType = (32784)
2010-02-25 02:15:26 +01:00
{-# LINE 229 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
windowBit :: CInt
windowBit = (1)
2010-02-25 02:15:26 +01:00
{-# LINE 232 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
xRenderable :: CInt
xRenderable = (32786)
2010-02-25 02:15:26 +01:00
{-# LINE 235 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
doublebuffer :: CInt
doublebuffer = (5)
2010-02-25 02:15:26 +01:00
{-# LINE 238 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
depthSize :: CInt
depthSize = (12)
2010-02-25 02:15:26 +01:00
{-# LINE 241 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
stencilSize :: CInt
stencilSize = (13)
2010-02-25 02:15:26 +01:00
{-# LINE 244 "GLX.chs" #-}
2010-02-22 16:50:42 +01:00
foreign import ccall unsafe "GL/glx.h glXGetVisualFromFBConfig"
2010-02-22 18:27:18 +01:00
glXGetVisualFromFBConfig :: Display -> FBConfig -> IO (Ptr VisualInfo)
2010-02-22 16:50:42 +01:00
2010-02-22 18:27:18 +01:00
getVisualFromFBConfig :: Display -> FBConfig -> IO (VisualInfo)
2010-02-22 16:50:42 +01:00
getVisualFromFBConfig disp config = do
2010-02-22 18:42:09 +01:00
viptr <- glXGetVisualFromFBConfig disp config
vi <- peek viptr
xFree viptr
return vi
2010-02-22 16:50:42 +01:00
foreign import ccall unsafe "GL/glx.h glXCreateContext"
2010-02-22 18:27:18 +01:00
createContext :: Display -> Ptr VisualInfo -> Context -> Bool -> IO Context
2010-02-22 16:50:42 +01:00
foreign import ccall unsafe "GL/glx.h glXMakeCurrent"
makeCurrent :: Display -> Drawable -> Context -> IO Bool
2010-02-22 22:25:06 +01:00
foreign import ccall unsafe "GL/glx.h glXDestroyContext"
destroyContext :: Display -> Context -> IO ()
foreign import ccall unsafe "GL/glx.h glXSwapBuffers"
swapBuffers :: Display -> Drawable -> IO ()