-------------------------------------------------------------------------------- -- | -- Module : Graphics.Rendering.OGL.GL.Clipping -- Copyright : (c) Sven Panne 2002-2006 -- License : BSD-style (see the file libraries/OpenGL/LICENSE) -- -- Maintainer : sven.panne@aedion.de -- Stability : stable -- Portability : portable -- -- This module corresponds to section 2.12 (Clipping) of the OpenGL 2.1 specs. -- -------------------------------------------------------------------------------- module Graphics.Rendering.OGL.GL.Clipping ( ClipPlaneName(..), clipPlane, maxClipPlanes ) where import Foreign.Marshal.Alloc ( alloca ) import Foreign.Marshal.Utils ( with ) import Foreign.Ptr ( Ptr, castPtr ) import Graphics.Rendering.OGL.Monad import Graphics.Rendering.OGL.GL.BasicTypes ( GLenum, GLsizei, GLdouble ) import Graphics.Rendering.OGL.GL.Capability ( EnableCap(CapClipPlane), makeStateVarMaybe ) import Graphics.Rendering.OGL.GL.CoordTrans ( Plane(..) ) import Graphics.Rendering.OGL.GL.PeekPoke ( peek1 ) import Graphics.Rendering.OGL.GL.QueryUtils ( GetPName(GetClipPlane,GetMaxClipPlanes), clipPlaneIndexToEnum, getDoublev, getSizei1 ) import Graphics.Rendering.OGL.GL.StateVar ( GettableStateVar, makeGettableStateVar, StateVar ) import Graphics.Rendering.OGL.GLU.ErrorsInternal ( recordInvalidEnum ) -------------------------------------------------------------------------------- newtype ClipPlaneName = ClipPlaneName GLsizei deriving ( Eq, Ord, Show ) -------------------------------------------------------------------------------- clipPlane :: ClipPlaneName -> StateVar (Maybe (Plane GLdouble)) clipPlane (ClipPlaneName i) = makeStateVarMaybe (return (CapClipPlane i)) (alloca $ \buf -> do getDoublev (GetClipPlane i) (castPtr buf) peek1 id (buf :: Ptr (Plane GLdouble))) (\plane -> maybe recordInvalidEnum (with plane . glClipPlane) (clipPlaneIndexToEnum i)) foreign import CALLCONV unsafe "glClipPlane" glClipPlane :: GLenum -> Ptr (Plane GLdouble) -> IO () -------------------------------------------------------------------------------- maxClipPlanes :: GettableStateVar GLsizei maxClipPlanes = makeGettableStateVar (getSizei1 id GetMaxClipPlanes)