module Graphics.Rendering.OGL.GL.ReadCopyPixels (
readPixels, readBuffer,
PixelCopyType(..), copyPixels
) where
import Foreign.Ptr ( Ptr )
import Graphics.Rendering.OGL.Monad
import Graphics.Rendering.OGL.GL.BasicTypes ( GLenum, GLint, GLsizei )
import Graphics.Rendering.OGL.GL.BufferMode (
marshalBufferMode, unmarshalBufferMode )
import Graphics.Rendering.OGL.GL.Framebuffer ( BufferMode(..) )
import Graphics.Rendering.OGL.GL.CoordTrans ( Position(..), Size(..) )
import Graphics.Rendering.OGL.GL.PixelData ( withPixelData )
import Graphics.Rendering.OGL.GL.PixelRectangles ( PixelData )
import Graphics.Rendering.OGL.GL.QueryUtils (
GetPName(GetReadBuffer), getEnum1 )
import Graphics.Rendering.OGL.GL.StateVar ( StateVar, makeStateVar )
import Graphics.Rendering.OGL.GLU.ErrorsInternal ( recordInvalidValue )
readPixels :: Position -> Size -> PixelData a -> GL ()
readPixels (Position x y) (Size w h) pd =
withPixelData pd $ glReadPixels x y w h
foreign import CALLCONV unsafe "glReadPixels" glReadPixels ::
GLint -> GLint -> GLsizei -> GLsizei -> GLenum -> GLenum -> Ptr a -> GL ()
readBuffer :: StateVar BufferMode
readBuffer =
makeStateVar
(getEnum1 unmarshalBufferMode GetReadBuffer)
(maybe recordInvalidValue glReadBuffer . marshalBufferMode)
foreign import CALLCONV unsafe "glReadBuffer" glReadBuffer :: GLenum -> IO ()
data PixelCopyType =
CopyColor
| CopyDepth
| CopyStencil
deriving ( Eq, Ord, Show )
marshalPixelCopyType :: PixelCopyType -> GLenum
marshalPixelCopyType x = case x of
CopyColor -> 0x1800
CopyDepth -> 0x1801
CopyStencil -> 0x1802
copyPixels :: Position -> Size -> PixelCopyType -> GL ()
copyPixels (Position x y) (Size w h) t =
glCopyPixels x y w h (marshalPixelCopyType t)
foreign import CALLCONV unsafe "glCopyPixels" glCopyPixels ::
GLint -> GLint -> GLsizei -> GLsizei -> GLenum -> GL ()