From 79d2c73dcf6fa74134a977368e21a33013fc9793 Mon Sep 17 00:00:00 2001 From: jgk Date: Thu, 10 Jun 2021 16:54:21 +0200 Subject: [PATCH] Remove Maybe from custom unis --- src/Dodge/Render.hs | 5 ++--- src/Picture/Render.hs | 21 ++++++++++----------- src/Shader.hs | 5 ++--- src/Shader/Data.hs | 13 ++++--------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index d9f7212db..ea94ef692 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -26,7 +26,6 @@ import Control.Lens import Control.Monad import qualified Control.Foldl as F import Data.Tuple.Extra -import Data.Maybe --import Data.List --import Data.Bifunctor --import Data.Function @@ -139,7 +138,7 @@ renderBlankWalls pdata wps pmat = do n <- F.foldM (pokeShader $ _wallBlankShader pdata) wps bindShaderBuffers [_wallBlankShader pdata] [n] currentProgram $= Just (_shaderProgram $ _wallBlankShader pdata) - uniform (head (fromJust $ _shaderCustomUnis $ _wallBlankShader pdata) ) + uniform (head ( _shaderCustomUnis $ _wallBlankShader pdata) ) $= pmat cullFace $= Just Back drawShader (_wallBlankShader pdata) n @@ -154,7 +153,7 @@ renderTextureWalls pdata wps pmat = do n <- F.foldM (pokeShader $ _wallTextureShader pdata) wps bindShaderBuffers [_wallTextureShader pdata] [n] currentProgram $= Just (_shaderProgram $ _wallTextureShader pdata) - uniform (head (fromJust $ _shaderCustomUnis $ _wallTextureShader pdata) ) + uniform (head ( _shaderCustomUnis $ _wallTextureShader pdata) ) $= pmat cullFace $= Just Back drawShader (_wallTextureShader pdata) n diff --git a/src/Picture/Render.hs b/src/Picture/Render.hs index 0586be1c1..d53a380a6 100644 --- a/src/Picture/Render.hs +++ b/src/Picture/Render.hs @@ -22,7 +22,6 @@ import Foreign hiding (rotate) import Graphics.Rendering.OpenGL hiding (Line,translate,scale,imageHeight,Polygon,Color,T) --import Data.Foldable import Data.Tuple.Extra -import Data.Maybe (fromJust) --import qualified Data.IntMap.Strict as IM import qualified SDL @@ -39,11 +38,11 @@ setWallDepth pdata wallPoints (viewFromx,viewFromy) pmat = do bindShaderBuffers [_lightingOccludeShader pdata] [nWalls] currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata) - uniform (head $ fromJust $ _shaderCustomUnis $ _lightingOccludeShader pdata) + uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata) $= Vector2 viewFromx viewFromy - uniform ( fromJust (_shaderCustomUnis $ _lightingOccludeShader pdata) !! 1) + uniform ( (_shaderCustomUnis $ _lightingOccludeShader pdata) !! 1) $= pmat - uniform ( fromJust (_shaderCustomUnis $ _lightingOccludeShader pdata) !! 2) + uniform ( (_shaderCustomUnis $ _lightingOccludeShader pdata) !! 2) $= (0 :: Float) -- cullFace $= Just Front drawShader (_lightingOccludeShader pdata) nWalls @@ -82,7 +81,7 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) pmat _ bindShaderBuffers [_lightingOccludeShader pdata] [nWalls] -- set uniforms for shader that draws lights currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata) - uniform ( fromJust (_shaderCustomUnis $ _lightingWallShader pdata) !! 1) + uniform ( (_shaderCustomUnis $ _lightingWallShader pdata) !! 1) $= pmat -- clear buffer to full alpha and furthest depth clearColor $= Color4 0 0 0 1 @@ -92,11 +91,11 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) pmat _ -- draw walls from your point of view in order to set z buffer colorMask $= Color4 Disabled Disabled Disabled Disabled currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata) - uniform (head $ fromJust $ _shaderCustomUnis $ _lightingOccludeShader pdata) + uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata) $= Vector2 viewFromx viewFromy - uniform ( fromJust (_shaderCustomUnis $ _lightingOccludeShader pdata) !! 1) + uniform ( (_shaderCustomUnis $ _lightingOccludeShader pdata) !! 1) $= pmat - uniform ( fromJust (_shaderCustomUnis $ _lightingOccludeShader pdata) !! 2) + uniform ( (_shaderCustomUnis $ _lightingOccludeShader pdata) !! 2) $= (0 :: Float) cullFace $= Just Back drawShader (_lightingOccludeShader pdata) nWalls @@ -127,7 +126,7 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) pmat _ stencilOp $= (OpKeep,OpKeep,OpIncr) stencilFunc $= (Always, 0, 255) currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata) - uniform (head $ fromJust $ _shaderCustomUnis $ _lightingOccludeShader pdata) + uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata) $= Vector2 x y drawShader (_lightingOccludeShader pdata) nWalls cullFace $= Just Front @@ -141,9 +140,9 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) pmat _ drawShader (_lightingFloorShader pdata) 1 -- draw wall light "circles" currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata) - uniform (head $ fromJust $ _shaderCustomUnis $ _lightingWallShader pdata) + uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata) $= Vector2 x y - uniform (fromJust (_shaderCustomUnis $ _lightingWallShader pdata) !! 2) + uniform ((_shaderCustomUnis $ _lightingWallShader pdata) !! 2) $= Vector2 r lum drawShader (_lightingWallShader pdata) nWallLights cullFace $= Nothing diff --git a/src/Shader.hs b/src/Shader.hs index 548865656..3e7d19ec8 100644 --- a/src/Shader.hs +++ b/src/Shader.hs @@ -26,7 +26,6 @@ import MatrixHelper import Foreign import Codec.Picture -import Data.Maybe (fromMaybe) import qualified Data.ByteString as BS import qualified Data.Vector.Storable as V import Control.Monad (unless, forM, zipWithM_, forM_, foldM) @@ -130,7 +129,7 @@ makeShader s shaderlist alocs pm renStrat = do , _shaderPokeStrategy = renStrat , _shaderDrawPrimitive = pm , _shaderTexture = Nothing - , _shaderCustomUnis = Nothing + , _shaderCustomUnis = [] } floatSize :: Int floatSize = sizeOf (0.5 :: GLfloat) @@ -184,7 +183,7 @@ makeSourcedShader s sts = do addUniforms :: [String] -> FullShader a -> IO (FullShader a) addUniforms uniStrings shad = do uniLocs <- mapM (uniformLocation $ _shaderProgram shad) uniStrings - return $ shad & shaderCustomUnis %~ Just . (++ uniLocs) . fromMaybe [] + return $ shad & shaderCustomUnis %~ (++ uniLocs) shaderTypeExt :: ShaderType -> String diff --git a/src/Shader/Data.hs b/src/Shader/Data.hs index a6bf83a0b..7acb787c4 100644 --- a/src/Shader/Data.hs +++ b/src/Shader/Data.hs @@ -24,15 +24,12 @@ import Graphics.Rendering.OpenGL import Foreign import Control.Lens {- | Vertex array object: contains the reference to the object, -and its buffer targets. --} +and its buffer targets. -} data VAO = VAO { _vao :: VertexArrayObject , _vaoBufferTargets :: [(BufferObject,Ptr Float,Int)] } -{- | -Datatype containing the necessary information for a single shader. --} +{- | Datatype containing the necessary information for a single shader. -} data FullShader a = FullShader { _shaderProgram :: Program , _shaderUniforms :: [UniformLocation] @@ -40,11 +37,9 @@ data FullShader a = FullShader , _shaderPokeStrategy :: a -> [[[Float]]]-- -> F.FoldM IO RenderType Int , _shaderDrawPrimitive :: PrimitiveMode , _shaderTexture :: Maybe ShaderTexture - , _shaderCustomUnis :: Maybe [UniformLocation] + , _shaderCustomUnis :: [UniformLocation] } -{- | -Datatype containing the reference to a texture object. --} +{- | Datatype containing the reference to a texture object. -} newtype ShaderTexture = ShaderTexture { _textureObject :: TextureObject }