-----------------------------------------------------------------------------
-- |
-- Module      :  Graphics.Rendering.OpenGL.GL.FramebufferObjects.Attachments
-- Copyright   :  (c) Sven Panne 2011-2019, Lars Corbijn 2011-2016
-- License     :  BSD3
--
-- Maintainer  :  Sven Panne <svenpanne@gmail.com>
-- Stability   :  stable
-- Portability :  portable
--
-----------------------------------------------------------------------------

module Graphics.Rendering.OpenGL.GL.FramebufferObjects.Attachments (
   FramebufferObjectAttachment(..),

   fboaToBufferMode, fboaFromBufferMode,

   FramebufferAttachment(..),

   framebufferRenderbuffer, framebufferTexture1D, framebufferTexture2D,
   framebufferTexture3D, framebufferTextureLayer
) where

import Graphics.Rendering.OpenGL.GL.FramebufferObjects.FramebufferObjectAttachment
import Graphics.Rendering.OpenGL.GL.FramebufferObjects.FramebufferTarget
import Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferObject
import Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferTarget
import Graphics.Rendering.OpenGL.GL.Texturing.Specification
import Graphics.Rendering.OpenGL.GL.Texturing.TextureObject
import Graphics.Rendering.OpenGL.GL.Texturing.TextureTarget
import Graphics.Rendering.OpenGL.GLU.ErrorsInternal
import Graphics.GL

-----------------------------------------------------------------------------

framebufferRenderbuffer :: FramebufferTarget -> FramebufferObjectAttachment
   -> RenderbufferTarget -> RenderbufferObject -> IO ()
framebufferRenderbuffer :: FramebufferTarget
-> FramebufferObjectAttachment
-> RenderbufferTarget
-> RenderbufferObject
-> IO ()
framebufferRenderbuffer fbt :: FramebufferTarget
fbt fba :: FramebufferObjectAttachment
fba rbt :: RenderbufferTarget
rbt (RenderbufferObject rboi :: GLuint
rboi) =
   IO () -> (GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO ()
recordInvalidValue (\mfba :: GLuint
mfba ->  GLuint -> GLuint -> GLuint -> GLuint -> IO ()
forall (m :: * -> *).
MonadIO m =>
GLuint -> GLuint -> GLuint -> GLuint -> m ()
glFramebufferRenderbuffer (FramebufferTarget -> GLuint
marshalFramebufferTarget FramebufferTarget
fbt)
      GLuint
mfba (RenderbufferTarget -> GLuint
marshalRenderbufferTarget RenderbufferTarget
rbt) GLuint
rboi) (Maybe GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall a b. (a -> b) -> a -> b
$ FramebufferObjectAttachment -> Maybe GLuint
marshalFramebufferObjectAttachment FramebufferObjectAttachment
fba

framebufferTexture1D :: FramebufferTarget -> FramebufferObjectAttachment
   -> TextureTarget1D -> TextureObject -> Level -> IO ()
framebufferTexture1D :: FramebufferTarget
-> FramebufferObjectAttachment
-> TextureTarget1D
-> TextureObject
-> Level
-> IO ()
framebufferTexture1D fbt :: FramebufferTarget
fbt fba :: FramebufferObjectAttachment
fba tt :: TextureTarget1D
tt (TextureObject t :: GLuint
t) l :: Level
l  =  IO () -> (GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO ()
recordInvalidValue
   (\mfba :: GLuint
mfba -> GLuint -> GLuint -> GLuint -> GLuint -> Level -> IO ()
forall (m :: * -> *).
MonadIO m =>
GLuint -> GLuint -> GLuint -> GLuint -> Level -> m ()
glFramebufferTexture1D (FramebufferTarget -> GLuint
marshalFramebufferTarget FramebufferTarget
fbt) GLuint
mfba
      (TextureTarget1D -> GLuint
forall t. QueryableTextureTarget t => t -> GLuint
marshalQueryableTextureTarget TextureTarget1D
tt) GLuint
t Level
l) (Maybe GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall a b. (a -> b) -> a -> b
$ FramebufferObjectAttachment -> Maybe GLuint
marshalFramebufferObjectAttachment FramebufferObjectAttachment
fba

-- Note: Typing is too permissive, no TEXTURE_1D_ARRAY allowed per 4.4. spec.
framebufferTexture2D :: FramebufferTarget -> FramebufferObjectAttachment
   -> TextureTarget2D -> TextureObject -> Level -> IO ()
framebufferTexture2D :: FramebufferTarget
-> FramebufferObjectAttachment
-> TextureTarget2D
-> TextureObject
-> Level
-> IO ()
framebufferTexture2D fbt :: FramebufferTarget
fbt fba :: FramebufferObjectAttachment
fba tt :: TextureTarget2D
tt (TextureObject t :: GLuint
t) l :: Level
l = IO () -> (GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO ()
recordInvalidValue
   (\mfba :: GLuint
mfba -> GLuint -> GLuint -> GLuint -> GLuint -> Level -> IO ()
forall (m :: * -> *).
MonadIO m =>
GLuint -> GLuint -> GLuint -> GLuint -> Level -> m ()
glFramebufferTexture2D (FramebufferTarget -> GLuint
marshalFramebufferTarget FramebufferTarget
fbt) GLuint
mfba
      (TextureTarget2D -> GLuint
forall t. QueryableTextureTarget t => t -> GLuint
marshalQueryableTextureTarget TextureTarget2D
tt) GLuint
t Level
l)
         (Maybe GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall a b. (a -> b) -> a -> b
$ FramebufferObjectAttachment -> Maybe GLuint
marshalFramebufferObjectAttachment FramebufferObjectAttachment
fba

-- Note: Typing is too permissive, no TEXTURE_2D_ARRAY or TEXTURE_2D_MULTISAMPLE_ARRAY allowed per 4.4. spec.
framebufferTexture3D :: FramebufferTarget -> FramebufferObjectAttachment
   -> TextureTarget3D -> TextureObject -> Level -> GLint -> IO ()
framebufferTexture3D :: FramebufferTarget
-> FramebufferObjectAttachment
-> TextureTarget3D
-> TextureObject
-> Level
-> Level
-> IO ()
framebufferTexture3D fbt :: FramebufferTarget
fbt fba :: FramebufferObjectAttachment
fba tt :: TextureTarget3D
tt (TextureObject t :: GLuint
t) le :: Level
le la :: Level
la = IO () -> (GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO ()
recordInvalidValue
   (\mfba :: GLuint
mfba -> GLuint -> GLuint -> GLuint -> GLuint -> Level -> Level -> IO ()
forall (m :: * -> *).
MonadIO m =>
GLuint -> GLuint -> GLuint -> GLuint -> Level -> Level -> m ()
glFramebufferTexture3D (FramebufferTarget -> GLuint
marshalFramebufferTarget FramebufferTarget
fbt) GLuint
mfba
      (TextureTarget3D -> GLuint
forall t. QueryableTextureTarget t => t -> GLuint
marshalQueryableTextureTarget TextureTarget3D
tt) GLuint
t Level
le Level
la) (Maybe GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall a b. (a -> b) -> a -> b
$ FramebufferObjectAttachment -> Maybe GLuint
marshalFramebufferObjectAttachment FramebufferObjectAttachment
fba

framebufferTextureLayer :: FramebufferTarget -> FramebufferObjectAttachment
   -> TextureObject -> Level -> GLint -> IO()
framebufferTextureLayer :: FramebufferTarget
-> FramebufferObjectAttachment
-> TextureObject
-> Level
-> Level
-> IO ()
framebufferTextureLayer fbt :: FramebufferTarget
fbt fba :: FramebufferObjectAttachment
fba (TextureObject t :: GLuint
t) le :: Level
le la :: Level
la = IO () -> (GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO ()
recordInvalidValue
   (\mfba :: GLuint
mfba -> GLuint -> GLuint -> GLuint -> Level -> Level -> IO ()
forall (m :: * -> *).
MonadIO m =>
GLuint -> GLuint -> GLuint -> Level -> Level -> m ()
glFramebufferTextureLayer (FramebufferTarget -> GLuint
marshalFramebufferTarget FramebufferTarget
fbt)
      GLuint
mfba GLuint
t Level
le Level
la) (Maybe GLuint -> IO ()) -> Maybe GLuint -> IO ()
forall a b. (a -> b) -> a -> b
$ FramebufferObjectAttachment -> Maybe GLuint
marshalFramebufferObjectAttachment FramebufferObjectAttachment
fba