diff options
author | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-18 13:54:36 -0600 |
---|---|---|
committer | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-18 13:54:36 -0600 |
commit | e1662612bec40fc131ecd306b66f6cb99f7f33e6 (patch) | |
tree | 746a288748690d4352d0ee45fe7a0fea4ab2b67e /Graphics/Glyph/Shaders.hs | |
parent | e4754131548a55fea393d6fc9245b20fcd60c62c (diff) | |
download | terralloc-e1662612bec40fc131ecd306b66f6cb99f7f33e6.tar.gz terralloc-e1662612bec40fc131ecd306b66f6cb99f7f33e6.tar.bz2 terralloc-e1662612bec40fc131ecd306b66f6cb99f7f33e6.zip |
fixed reflection
Diffstat (limited to 'Graphics/Glyph/Shaders.hs')
-rw-r--r-- | Graphics/Glyph/Shaders.hs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/Graphics/Glyph/Shaders.hs b/Graphics/Glyph/Shaders.hs index c11886d..296e4a8 100644 --- a/Graphics/Glyph/Shaders.hs +++ b/Graphics/Glyph/Shaders.hs @@ -18,26 +18,31 @@ class IsShaderSource a where loadShader :: ShaderType -> a -> IO (String, Maybe Shader) instance IsShaderSource FilePath where - loadShader typ path = loadShader typ =<< BS.readFile path + loadShader typ path = loadShaderBS path typ =<< BS.readFile path instance IsShaderSource BS.ByteString where - loadShader typ src = do - shader <- createShader typ - shaderSourceBS shader $= src - compileShader shader - - ok <- get (compileStatus shader) - infoLog <- get (shaderInfoLog shader) - - unless ok $ - deleteObjectNames [shader] - - return ( infoLog, if not ok then Nothing else Just shader ); + loadShader = loadShaderBS "Inlined" instance IsShaderSource BSL.ByteString where loadShader typ = loadShader typ . toStrict where toStrict = BS.concat . BSL.toChunks +loadShaderBS :: String -> ShaderType -> BS.ByteString -> IO (String, Maybe Shader) +loadShaderBS ctx typ src = do + shader <- createShader typ + shaderSourceBS shader $= src + compileShader shader + + ok <- get (compileStatus shader) + infoLog <- get (shaderInfoLog shader) + + unless ok $ + deleteObjectNames [shader] + + if not ok then + return ( unlines $ map ((ctx ++ " " ++ show typ ++ ": ")++) $ lines infoLog, Nothing ) + else return ( infoLog, Just shader ); + {- Load multiple shaders -} loadShaders :: (IsShaderSource a) => [(ShaderType,a)] -> IO [(String, Maybe Shader)] |