1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
{-# OPTIONS_HADDOCK hide #-}
-- | Rendering options
module Graphics.Gloss.Internals.Rendering.State
( State (..)
, initState
, Texture (..))
where
import Graphics.Gloss.Internals.Data.Picture
import Foreign.ForeignPtr
import System.Mem.StableName
import Data.Word
import Data.IORef
import qualified Graphics.Rendering.OpenGL.GL as GL
-- | Abstract Gloss render state which holds references to textures
-- loaded into the GPU context.
data State
= State
{ -- | Whether to use color
stateColor :: !Bool
-- | Whether to force wireframe mode only
, stateWireframe :: !Bool
-- | Whether to use alpha blending
, stateBlendAlpha :: !Bool
-- | Whether to use line smoothing
, stateLineSmooth :: !Bool
-- | Cache of Textures that we've sent to OpenGL.
, stateTextures :: !(IORef [Texture])
}
-- | A texture that we've sent to OpenGL.
data Texture
= Texture
{ -- | Stable name derived from the `BitmapData` that the user gives us.
texName :: StableName BitmapData
-- | Width of the image, in pixels.
, texWidth :: Int
-- | Height of the image, in pixels.
, texHeight :: Int
-- | Pointer to the Raw texture data.
, texData :: ForeignPtr Word8
-- | The OpenGL texture object.
, texObject :: GL.TextureObject
-- | Whether we want to leave this in OpenGL texture memory between frames.
, texCacheMe :: Bool }
-- | A mutable render state holds references to the textures currently loaded
-- into the OpenGL context. To ensure that textures are cached in GPU memory,
-- pass the same `State` each time you call `displayPicture` or `renderPicture`.
initState :: IO State
initState
= do textures <- newIORef []
return State
{ stateColor = True
, stateWireframe = False
, stateBlendAlpha = True
, stateLineSmooth = False
, stateTextures = textures }
|