Clear all warnings
This commit is contained in:
+28
-35
@@ -19,29 +19,22 @@ module Shader
|
||||
, module Shader.Data
|
||||
)
|
||||
where
|
||||
import Geometry
|
||||
import Shader.Data
|
||||
|
||||
import Foreign
|
||||
import Codec.Picture
|
||||
|
||||
import qualified Data.Vector.Storable as V
|
||||
|
||||
import Control.Monad (when, unless, forM, zipWithM_, forM_, foldM)
|
||||
import Control.Lens
|
||||
|
||||
import Data.Maybe (fromMaybe)
|
||||
|
||||
import qualified Control.Foldl as F
|
||||
|
||||
import Graphics.Rendering.OpenGL hiding (Point (..),translate,scale,imageHeight,imageWidth)
|
||||
--import Text.RawString.QQ
|
||||
import qualified Data.ByteString as BS
|
||||
|
||||
import qualified Data.Vector.Storable as V
|
||||
import Control.Monad (unless, forM, zipWithM_, forM_, foldM)
|
||||
import Control.Lens
|
||||
import qualified Control.Foldl as F
|
||||
import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight)
|
||||
--import Text.RawString.QQ
|
||||
import Linear.Matrix
|
||||
import Linear.V4
|
||||
|
||||
import Geometry
|
||||
|
||||
extractProgAndUnis :: FullShader a -> (Program,[UniformLocation])
|
||||
extractProgAndUnis s = (_shaderProgram s, _shaderUniforms s)
|
||||
|
||||
@@ -51,8 +44,7 @@ pokeShaders = traverse pokeShader
|
||||
pokeShader :: FullShader a -> F.FoldM IO a Int
|
||||
pokeShader fs = F.FoldM (pokeRender fls (zip ptrs nAtss)) (return 0) return
|
||||
where
|
||||
vao = _shaderVAO fs
|
||||
(_,ptrs,nAtss) = unzip3 $ _vaoBufferTargets vao
|
||||
(_,ptrs,nAtss) = unzip3 $ _vaoBufferTargets $ _shaderVAO fs
|
||||
fls = _shaderPokeStrategy fs
|
||||
|
||||
pokeRender :: (a -> [[[Float]]])
|
||||
@@ -93,8 +85,8 @@ drawShader fs i = do
|
||||
currentProgram $= Just (_shaderProgram fs)
|
||||
bindVertexArrayObject $= Just (_vao $ _shaderVAO fs)
|
||||
case _shaderTexture fs of
|
||||
Just ShaderTexture{_textureObject = to}
|
||||
-> textureBinding Texture2D $= Just to
|
||||
Just ShaderTexture{_textureObject = txo}
|
||||
-> textureBinding Texture2D $= Just txo
|
||||
_ -> return ()
|
||||
drawArrays (_shaderDrawPrimitive fs) 0 (fromIntegral i)
|
||||
|
||||
@@ -129,16 +121,16 @@ makeShader
|
||||
-> IO (FullShader a)
|
||||
makeShader s shaderlist alocs pm renStrat = do
|
||||
(prog,unis) <- makeSourcedShader s shaderlist
|
||||
vao <- setupVAO alocs
|
||||
vaob <- setupVAO alocs
|
||||
return $ FullShader { _shaderProgram = prog
|
||||
, _shaderUniforms = unis
|
||||
, _shaderVAO = vao
|
||||
, _shaderVAO = vaob
|
||||
, _shaderPokeStrategy = renStrat
|
||||
, _shaderDrawPrimitive = pm
|
||||
, _shaderTexture = Nothing
|
||||
, _shaderCustomUnis = Nothing
|
||||
}
|
||||
|
||||
floatSize :: Int
|
||||
floatSize = sizeOf (0.5 :: GLfloat)
|
||||
{-# INLINE floatSize #-}
|
||||
|
||||
@@ -171,7 +163,7 @@ setupArrayBuffer (aloc,i) = do
|
||||
, VertexArrayDescriptor (fromIntegral i)
|
||||
Float
|
||||
(fromIntegral $ floatSize * i)
|
||||
(bufferOffset 0)
|
||||
(bufferOffset (0::Int))
|
||||
)
|
||||
vertexAttribArray (AttribLocation aloc) $= Enabled
|
||||
return vbo
|
||||
@@ -197,30 +189,31 @@ shaderTypeExt :: ShaderType -> String
|
||||
shaderTypeExt VertexShader = ".vert"
|
||||
shaderTypeExt GeometryShader = ".geom"
|
||||
shaderTypeExt FragmentShader = ".frag"
|
||||
shaderTypeExt _ = undefined
|
||||
|
||||
makeShaderProgram :: String -> [(ShaderType,BS.ByteString)] -> IO Program
|
||||
makeShaderProgram str sources = do
|
||||
shaderProgram <- createProgram
|
||||
theShaderProgram <- createProgram
|
||||
shaders <- mapM (compileAndCheckShader str) sources
|
||||
mapM_ (attachShader shaderProgram) shaders
|
||||
mapM_ (attachShader theShaderProgram) shaders
|
||||
|
||||
linkProgram shaderProgram
|
||||
linkingSuccess <- linkStatus shaderProgram
|
||||
linkProgram theShaderProgram
|
||||
linkingSuccess <- linkStatus theShaderProgram
|
||||
unless linkingSuccess $ do
|
||||
infoLog <- get (programInfoLog shaderProgram)
|
||||
infoLog <- get (programInfoLog theShaderProgram)
|
||||
putStrLn $ str ++ ": Program Linking" ++ infoLog
|
||||
|
||||
return shaderProgram
|
||||
return theShaderProgram
|
||||
|
||||
compileAndCheckShader :: String -> (ShaderType,BS.ByteString) -> IO Shader
|
||||
compileAndCheckShader str (shaderType,sourceCode) = do
|
||||
theShader <- createShader shaderType
|
||||
compileAndCheckShader str (theShaderType,sourceCode) = do
|
||||
theShader <- createShader theShaderType
|
||||
shaderSourceBS theShader $= sourceCode
|
||||
compileShader theShader
|
||||
success <- compileStatus theShader
|
||||
unless success $ do
|
||||
infoLog <- get (shaderInfoLog theShader)
|
||||
putStrLn $ str ++ ": Shader compile: " ++ show shaderType ++ " : " ++ show infoLog
|
||||
putStrLn $ str ++ ": Shader compile: " ++ show theShaderType ++ " : " ++ show infoLog
|
||||
return theShader
|
||||
|
||||
resetShaderUniforms :: [(Program, [UniformLocation])] -> IO ()
|
||||
@@ -229,10 +222,10 @@ resetShaderUniforms = setShaderUniforms 0 1 (0,0) (2,2)
|
||||
|
||||
setShaderUniforms :: Float -> Float -> Point2 -> Point2 -> [(Program,[UniformLocation])] -> IO ()
|
||||
{-# INLINE setShaderUniforms #-}
|
||||
setShaderUniforms rot zoom (tranx,trany) (winx,winy) fss = do
|
||||
setShaderUniforms rot czoom (tranx,trany) (winx,winy) fss = do
|
||||
let scalMat = Linear.Matrix.transpose $
|
||||
V4 (V4 (2*zoom/winx) 0 0 (0::GLfloat))
|
||||
(V4 0 (2*zoom/winy) 0 0)
|
||||
V4 (V4 (2*czoom/winx) 0 0 (0::GLfloat))
|
||||
(V4 0 (2*czoom/winy) 0 0)
|
||||
(V4 0 0 1 0)
|
||||
(V4 0 0 0 1)
|
||||
let rotMat = Linear.Matrix.transpose $
|
||||
@@ -252,7 +245,7 @@ setShaderUniforms rot zoom (tranx,trany) (winx,winy) fss = do
|
||||
forM_ fss $ \shad -> do
|
||||
currentProgram $= Just (fst shad)
|
||||
uniform (snd shad !! 0) $= Vector2 winx winy
|
||||
uniform (snd shad !! 1) $= zoom
|
||||
uniform (snd shad !! 1) $= czoom
|
||||
uniform (snd shad !! 2) $= rot
|
||||
uniform (snd shad !! 3) $= Vector2 tranx trany
|
||||
uniform (snd shad !! 4) $= wmata
|
||||
|
||||
Reference in New Issue
Block a user