diff options
| author | andromeda <andromeda@lenovo> | 2026-02-06 01:18:36 +0100 |
|---|---|---|
| committer | andromeda <andromeda@lenovo> | 2026-02-06 01:18:36 +0100 |
| commit | 2a3c9bdafb22f0ee5353c8ca7761e897b09f1e83 (patch) | |
| tree | 3aa1a04613082a6e520f28559ea576e7eda7eb88 /src/Game/Internal/LoadShaders.hs | |
| parent | a62275f853be9d9f43772fe1969c225ae43c3d62 (diff) | |
Diffstat (limited to 'src/Game/Internal/LoadShaders.hs')
| -rw-r--r-- | src/Game/Internal/LoadShaders.hs | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/src/Game/Internal/LoadShaders.hs b/src/Game/Internal/LoadShaders.hs index 86b549f..43d423b 100644 --- a/src/Game/Internal/LoadShaders.hs +++ b/src/Game/Internal/LoadShaders.hs @@ -1,4 +1,7 @@ -------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- + -- | -- Module : LoadShaders -- Copyright : (c) Sven Panne 2013 @@ -10,13 +13,12 @@ -- -- Utilities for shader handling, adapted from LoadShaders.cpp which is (c) The -- Red Book Authors. --- --------------------------------------------------------------------------------- module Game.Internal.LoadShaders - ( ShaderSource(..) - , ShaderInfo(..) - , loadShaders - ) where + ( ShaderSource (..), + ShaderInfo (..), + loadShaders, + ) +where import Control.Exception import Control.Monad @@ -24,14 +26,15 @@ import qualified Data.ByteString as B import Graphics.Rendering.OpenGL -------------------------------------------------------------------------------- + -- | The source of the shader source code. data ShaderSource - = ByteStringSource B.ByteString - -- ^ The shader source code is directly given as a 'B.ByteString'. - | StringSource String - -- ^ The shader source code is directly given as a 'String'. - | FileSource FilePath - -- ^ The shader source code is located in the file at the given 'FilePath'. + = -- | The shader source code is directly given as a 'B.ByteString'. + ByteStringSource B.ByteString + | -- | The shader source code is directly given as a 'String'. + StringSource String + | -- | The shader source code is located in the file at the given 'FilePath'. + FileSource FilePath deriving (Eq, Ord, Show) getSource :: ShaderSource -> IO B.ByteString @@ -40,12 +43,14 @@ getSource (StringSource str) = return $ packUtf8 str getSource (FileSource path) = B.readFile path -------------------------------------------------------------------------------- + -- | A description of a shader: The type of the shader plus its source code. -data ShaderInfo = - ShaderInfo ShaderType ShaderSource +data ShaderInfo + = ShaderInfo ShaderType ShaderSource deriving (Eq, Ord, Show) -------------------------------------------------------------------------------- + -- | Create a new program object from the given shaders, throwing an -- 'IOException' if something goes wrong. loadShaders :: [ShaderInfo] -> IO Program @@ -60,7 +65,7 @@ linkAndCheck = checked linkProgram linkStatus programInfoLog "link" loadCompileAttach :: Program -> [ShaderInfo] -> IO () loadCompileAttach _ [] = return () -loadCompileAttach program (ShaderInfo shType source:infos) = +loadCompileAttach program (ShaderInfo shType source : infos) = createShader shType `bracketOnError` deleteObjectName $ \shader -> do src <- getSource source shaderSourceBS shader $= src @@ -72,12 +77,12 @@ compileAndCheck :: Shader -> IO () compileAndCheck = checked compileShader compileStatus shaderInfoLog "compile" checked :: - (t -> IO ()) - -> (t -> GettableStateVar Bool) - -> (t -> GettableStateVar String) - -> String - -> t - -> IO () + (t -> IO ()) -> + (t -> GettableStateVar Bool) -> + (t -> GettableStateVar String) -> + String -> + t -> + IO () checked action getStatus getInfoLog message object = do action object ok <- get (getStatus object) |
