module Graphics.Rendering.OpenGL.GL.BufferMode (
BufferMode(..), marshalBufferMode, unmarshalBufferMode,
unmarshalBufferModeSafe,
maxColorAttachments,
) where
import Graphics.Rendering.OpenGL.Raw
data BufferMode =
NoBuffers
| FrontLeftBuffer
| FrontRightBuffer
| BackLeftBuffer
| BackRightBuffer
| FrontBuffers
| BackBuffers
| LeftBuffers
| RightBuffers
| FrontAndBackBuffers
| AuxBuffer GLsizei
| FBOColorAttachment GLsizei
deriving ( Eq, Ord, Show )
marshalBufferMode :: BufferMode -> Maybe GLenum
marshalBufferMode x = case x of
NoBuffers -> Just gl_NONE
FrontLeftBuffer -> Just gl_FRONT_LEFT
FrontRightBuffer -> Just gl_FRONT_RIGHT
BackLeftBuffer -> Just gl_BACK_LEFT
BackRightBuffer -> Just gl_BACK_RIGHT
FrontBuffers -> Just gl_FRONT
BackBuffers -> Just gl_BACK
LeftBuffers -> Just gl_LEFT
RightBuffers -> Just gl_RIGHT
FrontAndBackBuffers -> Just gl_FRONT_AND_BACK
AuxBuffer i
| fromIntegral i <= maxAuxBuffer -> Just (gl_AUX0 + fromIntegral i)
| otherwise -> Nothing
FBOColorAttachment i
| fromIntegral i <= maxColorAttachments -> Just (gl_COLOR_ATTACHMENT0 + fromIntegral i)
| otherwise -> Nothing
unmarshalBufferMode :: GLenum -> BufferMode
unmarshalBufferMode x = maybe
(error ("unmarshalBufferMode: illegal value " ++ show x)) id $ unmarshalBufferModeSafe x
unmarshalBufferModeSafe :: GLenum -> Maybe BufferMode
unmarshalBufferModeSafe x
| x == gl_NONE = Just NoBuffers
| x == gl_FRONT_LEFT = Just FrontLeftBuffer
| x == gl_FRONT_RIGHT = Just FrontRightBuffer
| x == gl_BACK_LEFT = Just BackLeftBuffer
| x == gl_BACK_RIGHT = Just BackRightBuffer
| x == gl_FRONT = Just FrontBuffers
| x == gl_BACK = Just BackBuffers
| x == gl_LEFT = Just LeftBuffers
| x == gl_RIGHT = Just RightBuffers
| x == gl_FRONT_AND_BACK = Just FrontAndBackBuffers
| gl_AUX0 <= x && x <= gl_AUX0 + maxAuxBuffer = Just . AuxBuffer . fromIntegral $ x gl_AUX0
| gl_COLOR_ATTACHMENT0 <= x && x <= gl_COLOR_ATTACHMENT0 + maxColorAttachments
= Just . FBOColorAttachment . fromIntegral $ x gl_COLOR_ATTACHMENT0
| otherwise = Nothing
maxAuxBuffer :: GLenum
maxAuxBuffer = 246
maxColorAttachments :: GLenum
maxColorAttachments = 16