--------------------------------------------------------------------------------
-- |
-- Module      :  Graphics.Rendering.OpenGL.GL.Texturing.Parameters
-- Copyright   :  (c) Sven Panne 2002-2019
-- License     :  BSD3
--
-- Maintainer  :  Sven Panne <svenpanne@gmail.com>
-- Stability   :  stable
-- Portability :  portable
--
-- This module corresponds to section 3.8.4 (Texture Parameters), section 3.8.7
-- (Texture Wrap Mode), section 3.8.8 (Texture Minification), and section 3.8.9
-- (Texture Magnification) of the OpenGL 2.1 specs.
--
--------------------------------------------------------------------------------

module Graphics.Rendering.OpenGL.GL.Texturing.Parameters (
   TextureFilter(..), MinificationFilter, MagnificationFilter, textureFilter,
   Repetition(..), Clamping(..), textureWrapMode,
   textureBorderColor, LOD, textureObjectLODBias, maxTextureLODBias,
   textureLODRange, textureMaxAnisotropy, maxTextureMaxAnisotropy,
   textureLevelRange, generateMipmap, depthTextureMode, textureCompareMode,
   textureCompareFailValue, TextureCompareOperator(..), textureCompareOperator
) where

import Control.Monad
import Data.StateVar
import Graphics.Rendering.OpenGL.GL.Capability
import Graphics.Rendering.OpenGL.GL.ComparisonFunction
import Graphics.Rendering.OpenGL.GL.CoordTrans
import Graphics.Rendering.OpenGL.GL.QueryUtils
import Graphics.Rendering.OpenGL.GL.Texturing.Filter
import Graphics.Rendering.OpenGL.GL.Texturing.PixelInternalFormat
import Graphics.Rendering.OpenGL.GL.Texturing.Specification
import Graphics.Rendering.OpenGL.GL.Texturing.TexParameter
import Graphics.Rendering.OpenGL.GL.VertexSpec
import Graphics.Rendering.OpenGL.GLU.ErrorsInternal
import Graphics.GL

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

textureFilter :: ParameterizedTextureTarget t => t -> StateVar (MinificationFilter, MagnificationFilter)
textureFilter :: forall t.
ParameterizedTextureTarget t =>
t -> StateVar (MinificationFilter, MagnificationFilter)
textureFilter =
   forall t a b.
(t -> StateVar a) -> (t -> StateVar b) -> t -> StateVar (a, b)
combineTexParams
      (forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami GLint -> MinificationFilter
unmarshalMinificationFilter  MinificationFilter -> GLint
marshalMinificationFilter  TexParameter
TextureMinFilter)
      (forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami GLint -> MagnificationFilter
unmarshalMagnificationFilter MagnificationFilter -> GLint
marshalMagnificationFilter TexParameter
TextureMagFilter)

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

data Repetition =
     Repeated
   | Mirrored
   deriving ( Repetition -> Repetition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Repetition -> Repetition -> Bool
$c/= :: Repetition -> Repetition -> Bool
== :: Repetition -> Repetition -> Bool
$c== :: Repetition -> Repetition -> Bool
Eq, Eq Repetition
Repetition -> Repetition -> Bool
Repetition -> Repetition -> Ordering
Repetition -> Repetition -> Repetition
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Repetition -> Repetition -> Repetition
$cmin :: Repetition -> Repetition -> Repetition
max :: Repetition -> Repetition -> Repetition
$cmax :: Repetition -> Repetition -> Repetition
>= :: Repetition -> Repetition -> Bool
$c>= :: Repetition -> Repetition -> Bool
> :: Repetition -> Repetition -> Bool
$c> :: Repetition -> Repetition -> Bool
<= :: Repetition -> Repetition -> Bool
$c<= :: Repetition -> Repetition -> Bool
< :: Repetition -> Repetition -> Bool
$c< :: Repetition -> Repetition -> Bool
compare :: Repetition -> Repetition -> Ordering
$ccompare :: Repetition -> Repetition -> Ordering
Ord, Int -> Repetition -> ShowS
[Repetition] -> ShowS
Repetition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Repetition] -> ShowS
$cshowList :: [Repetition] -> ShowS
show :: Repetition -> String
$cshow :: Repetition -> String
showsPrec :: Int -> Repetition -> ShowS
$cshowsPrec :: Int -> Repetition -> ShowS
Show )

data Clamping =
     Clamp
   | Repeat
   | ClampToEdge
   | ClampToBorder
   deriving ( Clamping -> Clamping -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Clamping -> Clamping -> Bool
$c/= :: Clamping -> Clamping -> Bool
== :: Clamping -> Clamping -> Bool
$c== :: Clamping -> Clamping -> Bool
Eq, Eq Clamping
Clamping -> Clamping -> Bool
Clamping -> Clamping -> Ordering
Clamping -> Clamping -> Clamping
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Clamping -> Clamping -> Clamping
$cmin :: Clamping -> Clamping -> Clamping
max :: Clamping -> Clamping -> Clamping
$cmax :: Clamping -> Clamping -> Clamping
>= :: Clamping -> Clamping -> Bool
$c>= :: Clamping -> Clamping -> Bool
> :: Clamping -> Clamping -> Bool
$c> :: Clamping -> Clamping -> Bool
<= :: Clamping -> Clamping -> Bool
$c<= :: Clamping -> Clamping -> Bool
< :: Clamping -> Clamping -> Bool
$c< :: Clamping -> Clamping -> Bool
compare :: Clamping -> Clamping -> Ordering
$ccompare :: Clamping -> Clamping -> Ordering
Ord, Int -> Clamping -> ShowS
[Clamping] -> ShowS
Clamping -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Clamping] -> ShowS
$cshowList :: [Clamping] -> ShowS
show :: Clamping -> String
$cshow :: Clamping -> String
showsPrec :: Int -> Clamping -> ShowS
$cshowsPrec :: Int -> Clamping -> ShowS
Show )

marshalTextureWrapMode :: (Repetition, Clamping) -> GLint
marshalTextureWrapMode :: (Repetition, Clamping) -> GLint
marshalTextureWrapMode (Repetition, Clamping)
x = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ case (Repetition, Clamping)
x of
   (Repetition
Repeated, Clamping
Clamp) -> GLenum
GL_CLAMP
   (Repetition
Repeated, Clamping
Repeat) -> GLenum
GL_REPEAT
   (Repetition
Repeated, Clamping
ClampToEdge) -> GLenum
GL_CLAMP_TO_EDGE
   (Repetition
Repeated, Clamping
ClampToBorder) -> GLenum
GL_CLAMP_TO_BORDER
   (Repetition
Mirrored, Clamping
Clamp) -> GLenum
GL_MIRROR_CLAMP_EXT
   (Repetition
Mirrored, Clamping
Repeat) -> GLenum
GL_MIRRORED_REPEAT
   (Repetition
Mirrored, Clamping
ClampToEdge) -> GLenum
GL_MIRROR_CLAMP_TO_EDGE
   (Repetition
Mirrored, Clamping
ClampToBorder) -> GLenum
GL_MIRROR_CLAMP_TO_BORDER_EXT

unmarshalTextureWrapMode :: GLint -> (Repetition, Clamping)
unmarshalTextureWrapMode :: GLint -> (Repetition, Clamping)
unmarshalTextureWrapMode GLint
x
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_CLAMP = (Repetition
Repeated, Clamping
Clamp)
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_REPEAT = (Repetition
Repeated, Clamping
Repeat)
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_CLAMP_TO_EDGE = (Repetition
Repeated, Clamping
ClampToEdge)
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_CLAMP_TO_BORDER = (Repetition
Repeated, Clamping
ClampToBorder)
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_MIRROR_CLAMP_EXT = (Repetition
Mirrored, Clamping
Clamp)
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_MIRRORED_REPEAT = (Repetition
Mirrored, Clamping
Repeat)
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_MIRROR_CLAMP_TO_EDGE = (Repetition
Mirrored, Clamping
ClampToEdge)
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_MIRROR_CLAMP_TO_BORDER_EXT = (Repetition
Mirrored, Clamping
ClampToBorder)
   | Bool
otherwise = forall a. HasCallStack => String -> a
error (String
"unmarshalTextureWrapMode: illegal value " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show GLint
x)
   where y :: GLenum
y = forall a b. (Integral a, Num b) => a -> b
fromIntegral GLint
x

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

textureWrapMode :: ParameterizedTextureTarget t => t -> TextureCoordName -> StateVar (Repetition,Clamping)
textureWrapMode :: forall t.
ParameterizedTextureTarget t =>
t -> TextureCoordName -> StateVar (Repetition, Clamping)
textureWrapMode t
t TextureCoordName
coord = case TextureCoordName
coord of
   TextureCoordName
S -> TexParameter -> StateVar (Repetition, Clamping)
wrap TexParameter
TextureWrapS
   TextureCoordName
T -> TexParameter -> StateVar (Repetition, Clamping)
wrap TexParameter
TextureWrapT
   TextureCoordName
R -> TexParameter -> StateVar (Repetition, Clamping)
wrap TexParameter
TextureWrapR
   TextureCoordName
Q -> StateVar (Repetition, Clamping)
invalidTextureCoord
   where wrap :: TexParameter -> StateVar (Repetition, Clamping)
wrap TexParameter
c = forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami GLint -> (Repetition, Clamping)
unmarshalTextureWrapMode (Repetition, Clamping) -> GLint
marshalTextureWrapMode TexParameter
c t
t

invalidTextureCoord :: StateVar (Repetition,Clamping)
invalidTextureCoord :: StateVar (Repetition, Clamping)
invalidTextureCoord =
   forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar
      (do IO ()
recordInvalidEnum; forall (m :: * -> *) a. Monad m => a -> m a
return (Repetition
Repeated, Clamping
Repeat))
      (forall a b. a -> b -> a
const IO ()
recordInvalidEnum)

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

textureBorderColor :: ParameterizedTextureTarget t => t -> StateVar (Color4 GLfloat)
textureBorderColor :: forall t.
ParameterizedTextureTarget t =>
t -> StateVar (Color4 GLfloat)
textureBorderColor = forall t.
ParameterizedTextureTarget t =>
TexParameter -> t -> StateVar (Color4 GLfloat)
texParamC4f TexParameter
TextureBorderColor

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

type LOD = GLfloat

textureObjectLODBias :: ParameterizedTextureTarget t => t -> StateVar LOD
textureObjectLODBias :: forall t. ParameterizedTextureTarget t => t -> StateVar GLfloat
textureObjectLODBias = forall t a.
ParameterizedTextureTarget t =>
(GLfloat -> a) -> (a -> GLfloat) -> TexParameter -> t -> StateVar a
texParamf forall a. a -> a
id forall a. a -> a
id TexParameter
TextureLODBias

maxTextureLODBias :: GettableStateVar LOD
maxTextureLODBias :: GettableStateVar GLfloat
maxTextureLODBias =
   forall a. IO a -> IO a
makeGettableStateVar (forall p a. GetPName1F p => (GLfloat -> a) -> p -> IO a
getFloat1 forall a. a -> a
id PName1F
GetMaxTextureLODBias)

textureLODRange :: ParameterizedTextureTarget t => t -> StateVar (LOD,LOD)
textureLODRange :: forall t.
ParameterizedTextureTarget t =>
t -> StateVar (GLfloat, GLfloat)
textureLODRange =
   forall t a b.
(t -> StateVar a) -> (t -> StateVar b) -> t -> StateVar (a, b)
combineTexParams
      (forall t a.
ParameterizedTextureTarget t =>
(GLfloat -> a) -> (a -> GLfloat) -> TexParameter -> t -> StateVar a
texParamf forall a. a -> a
id forall a. a -> a
id TexParameter
TextureMinLOD)
      (forall t a.
ParameterizedTextureTarget t =>
(GLfloat -> a) -> (a -> GLfloat) -> TexParameter -> t -> StateVar a
texParamf forall a. a -> a
id forall a. a -> a
id TexParameter
TextureMaxLOD)

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

textureMaxAnisotropy :: ParameterizedTextureTarget t => t -> StateVar GLfloat
textureMaxAnisotropy :: forall t. ParameterizedTextureTarget t => t -> StateVar GLfloat
textureMaxAnisotropy = forall t a.
ParameterizedTextureTarget t =>
(GLfloat -> a) -> (a -> GLfloat) -> TexParameter -> t -> StateVar a
texParamf forall a. a -> a
id forall a. a -> a
id TexParameter
TextureMaxAnisotropy

maxTextureMaxAnisotropy :: GettableStateVar GLfloat
maxTextureMaxAnisotropy :: GettableStateVar GLfloat
maxTextureMaxAnisotropy =
   forall a. IO a -> IO a
makeGettableStateVar (forall p a. GetPName1F p => (GLfloat -> a) -> p -> IO a
getFloat1 forall a. a -> a
id PName1F
GetMaxTextureMaxAnisotropy)

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

textureLevelRange :: ParameterizedTextureTarget t => t -> StateVar (Level,Level)
textureLevelRange :: forall t.
ParameterizedTextureTarget t =>
t -> StateVar (GLint, GLint)
textureLevelRange =
   forall t a b.
(t -> StateVar a) -> (t -> StateVar b) -> t -> StateVar (a, b)
combineTexParams
      (forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami forall a. a -> a
id forall a. a -> a
id TexParameter
TextureBaseLevel)
      (forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami forall a. a -> a
id forall a. a -> a
id TexParameter
TextureMaxLevel)

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

-- | Note: OpenGL 3.1 deprecated this texture parameter, use
-- 'Graphics.Rendering.OpenGL.GL.Texturing.Objects.generateMipmap'' instead.

generateMipmap :: ParameterizedTextureTarget t => t -> StateVar Capability
generateMipmap :: forall t. ParameterizedTextureTarget t => t -> StateVar Capability
generateMipmap = forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami GLint -> Capability
unmarshal Capability -> GLint
marshal TexParameter
GenerateMipmap
   where unmarshal :: GLint -> Capability
unmarshal = GLboolean -> Capability
unmarshalCapability forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral
         marshal :: Capability -> GLint
marshal = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. Capability -> GLboolean
marshalCapability

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

-- Only Luminance', Intensity, and Alpha' allowed
depthTextureMode :: ParameterizedTextureTarget t => t -> StateVar PixelInternalFormat
depthTextureMode :: forall t.
ParameterizedTextureTarget t =>
t -> StateVar PixelInternalFormat
depthTextureMode =
   forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami GLint -> PixelInternalFormat
unmarshalPixelInternalFormat PixelInternalFormat -> GLint
marshalPixelInternalFormat TexParameter
DepthTextureMode

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

marshalTextureCompareMode :: Capability -> GLint
marshalTextureCompareMode :: Capability -> GLint
marshalTextureCompareMode Capability
x = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ case Capability
x of
   Capability
Disabled -> GLenum
GL_NONE
   Capability
Enabled -> GLenum
GL_COMPARE_REF_TO_TEXTURE

unmarshalTextureCompareMode :: GLint -> Capability
unmarshalTextureCompareMode :: GLint -> Capability
unmarshalTextureCompareMode GLint
x
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_NONE = Capability
Disabled
   | GLenum
y forall a. Eq a => a -> a -> Bool
== GLenum
GL_COMPARE_REF_TO_TEXTURE = Capability
Enabled
   | Bool
otherwise = forall a. HasCallStack => String -> a
error (String
"unmarshalTextureCompareMode: illegal value " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show GLint
x)
   where y :: GLenum
y = forall a b. (Integral a, Num b) => a -> b
fromIntegral GLint
x

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

textureCompareMode :: ParameterizedTextureTarget t => t -> StateVar (Maybe ComparisonFunction)
textureCompareMode :: forall t.
ParameterizedTextureTarget t =>
t -> StateVar (Maybe ComparisonFunction)
textureCompareMode =
   forall t a.
(t -> StateVar Capability)
-> (t -> StateVar a) -> t -> StateVar (Maybe a)
combineTexParamsMaybe
      (forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami GLint -> Capability
unmarshalTextureCompareMode Capability -> GLint
marshalTextureCompareMode TexParameter
TextureCompareMode)
      (forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami GLint -> ComparisonFunction
unmarshal ComparisonFunction -> GLint
marshal TexParameter
TextureCompareFunc)
   where unmarshal :: GLint -> ComparisonFunction
unmarshal = GLenum -> ComparisonFunction
unmarshalComparisonFunction forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral
         marshal :: ComparisonFunction -> GLint
marshal = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComparisonFunction -> GLenum
marshalComparisonFunction

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

textureCompareFailValue :: ParameterizedTextureTarget t => t -> StateVar GLclampf
textureCompareFailValue :: forall t. ParameterizedTextureTarget t => t -> StateVar GLfloat
textureCompareFailValue = forall t a.
ParameterizedTextureTarget t =>
(GLfloat -> a) -> (a -> GLfloat) -> TexParameter -> t -> StateVar a
texParamf forall a b. (Real a, Fractional b) => a -> b
realToFrac forall a b. (Real a, Fractional b) => a -> b
realToFrac TexParameter
TextureCompareFailValue

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

data TextureCompareOperator =
     LequalR
   | GequalR
   deriving ( TextureCompareOperator -> TextureCompareOperator -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TextureCompareOperator -> TextureCompareOperator -> Bool
$c/= :: TextureCompareOperator -> TextureCompareOperator -> Bool
== :: TextureCompareOperator -> TextureCompareOperator -> Bool
$c== :: TextureCompareOperator -> TextureCompareOperator -> Bool
Eq, Eq TextureCompareOperator
TextureCompareOperator -> TextureCompareOperator -> Bool
TextureCompareOperator -> TextureCompareOperator -> Ordering
TextureCompareOperator
-> TextureCompareOperator -> TextureCompareOperator
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TextureCompareOperator
-> TextureCompareOperator -> TextureCompareOperator
$cmin :: TextureCompareOperator
-> TextureCompareOperator -> TextureCompareOperator
max :: TextureCompareOperator
-> TextureCompareOperator -> TextureCompareOperator
$cmax :: TextureCompareOperator
-> TextureCompareOperator -> TextureCompareOperator
>= :: TextureCompareOperator -> TextureCompareOperator -> Bool
$c>= :: TextureCompareOperator -> TextureCompareOperator -> Bool
> :: TextureCompareOperator -> TextureCompareOperator -> Bool
$c> :: TextureCompareOperator -> TextureCompareOperator -> Bool
<= :: TextureCompareOperator -> TextureCompareOperator -> Bool
$c<= :: TextureCompareOperator -> TextureCompareOperator -> Bool
< :: TextureCompareOperator -> TextureCompareOperator -> Bool
$c< :: TextureCompareOperator -> TextureCompareOperator -> Bool
compare :: TextureCompareOperator -> TextureCompareOperator -> Ordering
$ccompare :: TextureCompareOperator -> TextureCompareOperator -> Ordering
Ord, Int -> TextureCompareOperator -> ShowS
[TextureCompareOperator] -> ShowS
TextureCompareOperator -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TextureCompareOperator] -> ShowS
$cshowList :: [TextureCompareOperator] -> ShowS
show :: TextureCompareOperator -> String
$cshow :: TextureCompareOperator -> String
showsPrec :: Int -> TextureCompareOperator -> ShowS
$cshowsPrec :: Int -> TextureCompareOperator -> ShowS
Show )

marshalTextureCompareOperator :: TextureCompareOperator -> GLenum
marshalTextureCompareOperator :: TextureCompareOperator -> GLenum
marshalTextureCompareOperator TextureCompareOperator
x = case TextureCompareOperator
x of
   TextureCompareOperator
LequalR -> GLenum
GL_TEXTURE_LEQUAL_R_SGIX
   TextureCompareOperator
GequalR -> GLenum
GL_TEXTURE_GEQUAL_R_SGIX

unmarshalTextureCompareOperator :: GLenum -> TextureCompareOperator
unmarshalTextureCompareOperator :: GLenum -> TextureCompareOperator
unmarshalTextureCompareOperator GLenum
x
   | GLenum
x forall a. Eq a => a -> a -> Bool
== GLenum
GL_TEXTURE_LEQUAL_R_SGIX = TextureCompareOperator
LequalR
   | GLenum
x forall a. Eq a => a -> a -> Bool
== GLenum
GL_TEXTURE_GEQUAL_R_SGIX = TextureCompareOperator
GequalR
   | Bool
otherwise = forall a. HasCallStack => String -> a
error (String
"unmarshalTextureCompareOperator: illegal value " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show GLenum
x)

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

textureCompareOperator :: ParameterizedTextureTarget t => t -> StateVar (Maybe TextureCompareOperator)
textureCompareOperator :: forall t.
ParameterizedTextureTarget t =>
t -> StateVar (Maybe TextureCompareOperator)
textureCompareOperator =
   forall t a.
(t -> StateVar Capability)
-> (t -> StateVar a) -> t -> StateVar (Maybe a)
combineTexParamsMaybe
      (forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami (GLboolean -> Capability
unmarshalCapability forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) (forall a b. (Integral a, Num b) => a -> b
fromIntegralforall b c a. (b -> c) -> (a -> b) -> a -> c
. Capability -> GLboolean
marshalCapability) TexParameter
TextureCompare)
      (forall t a.
ParameterizedTextureTarget t =>
(GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
texParami (GLenum -> TextureCompareOperator
unmarshalTextureCompareOperator forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) (forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextureCompareOperator -> GLenum
marshalTextureCompareOperator) TexParameter
TextureCompareOperator)

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

combineTexParams :: (t -> StateVar a)
                 -> (t -> StateVar b)
                 -> (t -> StateVar (a,b))
combineTexParams :: forall t a b.
(t -> StateVar a) -> (t -> StateVar b) -> t -> StateVar (a, b)
combineTexParams t -> StateVar a
v t -> StateVar b
w t
t =
   forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar
      (forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) (forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get (t -> StateVar a
v t
t)) (forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get (t -> StateVar b
w t
t)))
      (\(a
x,b
y) -> do t -> StateVar a
v t
t forall t a (m :: * -> *).
(HasSetter t a, MonadIO m) =>
t -> a -> m ()
$= a
x; t -> StateVar b
w t
t forall t a (m :: * -> *).
(HasSetter t a, MonadIO m) =>
t -> a -> m ()
$= b
y)

combineTexParamsMaybe :: (t -> StateVar Capability)
                      -> (t -> StateVar a)
                      -> (t -> StateVar (Maybe a))
combineTexParamsMaybe :: forall t a.
(t -> StateVar Capability)
-> (t -> StateVar a) -> t -> StateVar (Maybe a)
combineTexParamsMaybe t -> StateVar Capability
enab t -> StateVar a
val t
t =
   forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar
      (do Capability
tcm <- forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get (t -> StateVar Capability
enab t
t)
          case Capability
tcm of
             Capability
Disabled -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
             Capability
Enabled -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get (t -> StateVar a
val t
t))
      (forall b a. b -> (a -> b) -> Maybe a -> b
maybe (t -> StateVar Capability
enab t
t forall t a (m :: * -> *).
(HasSetter t a, MonadIO m) =>
t -> a -> m ()
$= Capability
Disabled)
             (\a
tcf -> do t -> StateVar a
val t
t forall t a (m :: * -> *).
(HasSetter t a, MonadIO m) =>
t -> a -> m ()
$= a
tcf
                         t -> StateVar Capability
enab t
t forall t a (m :: * -> *).
(HasSetter t a, MonadIO m) =>
t -> a -> m ()
$= Capability
Enabled))