module Graphics.GL.Low.Framebuffer (
FBO,
RBO,
DefaultFramebuffer,
bindFramebuffer,
newFBO,
deleteFBO,
attachTex2D,
attachCubeMap,
attachRBO,
newRBO,
deleteRBO
) where
import Foreign.Ptr
import Foreign.Marshal
import Foreign.Storable
import Data.Default
import Graphics.GL
import Graphics.GL.Low.Classes
import Graphics.GL.Low.Common
import Graphics.GL.Low.Cube
import Graphics.GL.Low.Texture
newtype FBO = FBO GLuint deriving Show
data RBO a = RBO { unRBO :: GLuint } deriving Show
data DefaultFramebuffer = DefaultFramebuffer deriving Show
instance Default DefaultFramebuffer where
def = DefaultFramebuffer
instance Framebuffer DefaultFramebuffer where
framebufferName _ = 0
instance Framebuffer FBO where
framebufferName = glObjectName
instance GLObject FBO where
glObjectName (FBO n) = fromIntegral n
instance GLObject (RBO a) where
glObjectName (RBO n) = fromIntegral n
bindFramebuffer :: Framebuffer a => a -> IO ()
bindFramebuffer x = glBindFramebuffer GL_FRAMEBUFFER (framebufferName x)
newFBO :: IO FBO
newFBO = do
n <- alloca (\ptr -> glGenFramebuffers 1 ptr >> peek ptr)
return (FBO n)
deleteFBO :: FBO -> IO ()
deleteFBO (FBO n) = withArray [n] (\ptr -> glDeleteFramebuffers 1 ptr)
attachTex2D :: Attachable a => Tex2D a -> IO ()
attachTex2D tex =
glFramebufferTexture2D
GL_FRAMEBUFFER
(attachPoint tex)
GL_TEXTURE_2D
(glObjectName tex)
0
attachCubeMap :: Attachable a => CubeMap a -> Side -> IO ()
attachCubeMap cm side =
glFramebufferTexture2D
GL_FRAMEBUFFER
(attachPoint cm)
(side cubeSideCodes)
(glObjectName cm)
0
attachRBO :: Attachable a => RBO a -> IO ()
attachRBO rbo = glFramebufferRenderbuffer
GL_FRAMEBUFFER (attachPoint rbo) GL_RENDERBUFFER (unRBO rbo)
newRBO :: InternalFormat a => Int -> Int -> IO (RBO a)
newRBO w h = do
n <- alloca (\ptr -> glGenRenderbuffers 1 ptr >> peek ptr)
rbo <- return (RBO n)
glBindRenderbuffer GL_RENDERBUFFER n
glRenderbufferStorage
GL_RENDERBUFFER
(internalFormat rbo)
(fromIntegral w)
(fromIntegral h)
return rbo
deleteRBO :: RBO a -> IO ()
deleteRBO (RBO n) = withArray [n] (\ptr -> glDeleteRenderbuffers 1 ptr)