parent
1cded31ecc
commit
7c8c7cac98
@ -333,6 +333,18 @@ drawMap = do
|
|||||||
(ColorAttachment 1) --sample 1
|
(ColorAttachment 1) --sample 1
|
||||||
Renderbuffer --const
|
Renderbuffer --const
|
||||||
rb --buffer-}
|
rb --buffer-}
|
||||||
|
mat44ToGPU :: L.M44 CFloat -> UniformLocation -> String -> IO ()
|
||||||
|
mat44ToGPU mat (UniformLocation dest) name = do
|
||||||
|
with (distribute mat) $ \ptr ->
|
||||||
|
glUniformMatrix4fv dest 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
||||||
|
checkError $ "copy Matrix (" ++ name ++ ")"
|
||||||
|
|
||||||
|
mat33ToGPU :: L.M33 CFloat -> UniformLocation -> String -> IO ()
|
||||||
|
mat33ToGPU mat (UniformLocation dest) name = do
|
||||||
|
with (distribute mat) $ \ptr ->
|
||||||
|
glUniformMatrix3fv dest 1 0 (castPtr (ptr :: Ptr (L.M33 CFloat)))
|
||||||
|
checkError $ "copy Matrix (" ++ name ++ ")"
|
||||||
|
|
||||||
|
|
||||||
render :: Pioneers ()
|
render :: Pioneers ()
|
||||||
render = do
|
render = do
|
||||||
@ -347,13 +359,13 @@ render = do
|
|||||||
camPos = cam ^. camObject
|
camPos = cam ^. camObject
|
||||||
zDist' = cam ^. zDist
|
zDist' = cam ^. zDist
|
||||||
d = state ^. gl.glMap.mapShaderData
|
d = state ^. gl.glMap.mapShaderData
|
||||||
(UniformLocation proj) = shdrProjMatIndex d
|
proj = shdrProjMatIndex d
|
||||||
(UniformLocation nmat) = shdrNormalMatIndex d
|
nmat = shdrNormalMatIndex d
|
||||||
(UniformLocation vmat) = shdrViewMatIndex d
|
vmat = shdrViewMatIndex d
|
||||||
dmo = state ^. gl.glMap.mapObjectShaderData
|
dmo = state ^. gl.glMap.mapObjectShaderData
|
||||||
(UniformLocation projmo) = shdrMOProjMatIndex dmo
|
projmo = shdrMOProjMatIndex dmo
|
||||||
(UniformLocation nmatmo) = shdrMONormalMatIndex dmo
|
nmatmo = shdrMONormalMatIndex dmo
|
||||||
(UniformLocation vmatmo) = shdrMOViewMatIndex dmo
|
vmatmo = shdrMOViewMatIndex dmo
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
|
|
||||||
bindFramebuffer Framebuffer $= (state ^. gl.glFramebuffer)
|
bindFramebuffer Framebuffer $= (state ^. gl.glFramebuffer)
|
||||||
@ -384,16 +396,12 @@ render = do
|
|||||||
|
|
||||||
--set up projection (= copy from state)
|
--set up projection (= copy from state)
|
||||||
--TODO: Fix width/depth
|
--TODO: Fix width/depth
|
||||||
with (distribute (createFrustumOrtho 20 20 0 100)) $ \ptr ->
|
mat44ToGPU (createFrustumOrtho 20 20 0 100) proj "shadowmap-projection"
|
||||||
glUniformMatrix4fv proj 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
|
||||||
checkError "copy shadowmap-projection"
|
|
||||||
|
|
||||||
--set up camera
|
--set up camera
|
||||||
--TODO: Fix magic constants... and camPos
|
--TODO: Fix magic constants... and camPos
|
||||||
let ! cam = getCam camPos 1 0.7 0
|
let ! cam = getCam camPos 1 0.7 0
|
||||||
with (distribute cam) $ \ptr ->
|
mat44ToGPU cam vmat "shadowmap-cam"
|
||||||
glUniformMatrix4fv vmat 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
|
||||||
checkError "copy shadowmap-cam"
|
|
||||||
|
|
||||||
--set up normal--Mat transpose((model*camera)^-1)
|
--set up normal--Mat transpose((model*camera)^-1)
|
||||||
--needed?
|
--needed?
|
||||||
@ -402,10 +410,7 @@ render = do
|
|||||||
Nothing -> L.eye3) :: L.M33 CFloat
|
Nothing -> L.eye3) :: L.M33 CFloat
|
||||||
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
||||||
|
|
||||||
with (distribute nmap) $ \ptr ->
|
mat33ToGPU nmap nmat "nmat"
|
||||||
glUniformMatrix3fv nmat 1 0 (castPtr (ptr :: Ptr (L.M33 CFloat)))
|
|
||||||
|
|
||||||
checkError "nmat"
|
|
||||||
|
|
||||||
drawMap
|
drawMap
|
||||||
|
|
||||||
@ -416,16 +421,12 @@ render = do
|
|||||||
|
|
||||||
--set up projection (= copy from state)
|
--set up projection (= copy from state)
|
||||||
--TODO: Fix width/depth
|
--TODO: Fix width/depth
|
||||||
with (distribute (createFrustumOrtho 20 20 0 100)) $ \ptr ->
|
mat44ToGPU (createFrustumOrtho 20 20 0 100) projmo "shadowmap-projection"
|
||||||
glUniformMatrix4fv projmo 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
|
||||||
checkError "copy shadowmap-projection"
|
|
||||||
|
|
||||||
--set up camera
|
--set up camera
|
||||||
--TODO: Fix magic constants... and camPos
|
--TODO: Fix magic constants... and camPos
|
||||||
let ! cam = getCam camPos 1 0.7 0
|
let ! cam = getCam camPos 1 0.7 0
|
||||||
with (distribute cam) $ \ptr ->
|
mat44ToGPU cam vmatmo "shadowmap-camera"
|
||||||
glUniformMatrix4fv vmatmo 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
|
||||||
checkError "copy shadowmap-cam"
|
|
||||||
|
|
||||||
--set up normal--Mat transpose((model*camera)^-1)
|
--set up normal--Mat transpose((model*camera)^-1)
|
||||||
--needed?
|
--needed?
|
||||||
@ -434,10 +435,8 @@ render = do
|
|||||||
Nothing -> L.eye3) :: L.M33 CFloat
|
Nothing -> L.eye3) :: L.M33 CFloat
|
||||||
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
||||||
|
|
||||||
with (distribute nmap) $ \ptr ->
|
mat33ToGPU nmap nmatmo "nmat"
|
||||||
glUniformMatrix3fv nmatmo 1 0 (castPtr (ptr :: Ptr (L.M33 CFloat)))
|
|
||||||
|
|
||||||
checkError "nmat"
|
|
||||||
mapM_ renderObject (state ^. gl.glMap.mapObjects)
|
mapM_ renderObject (state ^. gl.glMap.mapObjects)
|
||||||
checkError "draw mapobjects"
|
checkError "draw mapobjects"
|
||||||
|
|
||||||
@ -465,15 +464,11 @@ render = do
|
|||||||
|
|
||||||
checkError "setting up buffer"
|
checkError "setting up buffer"
|
||||||
--set up projection (= copy from state)
|
--set up projection (= copy from state)
|
||||||
with (distribute frust) $ \ptr ->
|
mat44ToGPU frust proj "projection"
|
||||||
glUniformMatrix4fv proj 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
|
||||||
checkError "copy projection"
|
|
||||||
|
|
||||||
--set up camera
|
--set up camera
|
||||||
let ! cam = getCam camPos zDist' xa ya
|
let ! cam = getCam camPos zDist' xa ya
|
||||||
with (distribute cam) $ \ptr ->
|
mat44ToGPU cam vmat "camera"
|
||||||
glUniformMatrix4fv vmat 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
|
||||||
checkError "copy cam"
|
|
||||||
|
|
||||||
--set up normal--Mat transpose((model*camera)^-1)
|
--set up normal--Mat transpose((model*camera)^-1)
|
||||||
let normal' = (case L.inv33 (fmap (^. L._xyz) cam ^. L._xyz) of
|
let normal' = (case L.inv33 (fmap (^. L._xyz) cam ^. L._xyz) of
|
||||||
@ -481,10 +476,7 @@ render = do
|
|||||||
Nothing -> L.eye3) :: L.M33 CFloat
|
Nothing -> L.eye3) :: L.M33 CFloat
|
||||||
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
||||||
|
|
||||||
with (distribute nmap) $ \ptr ->
|
mat33ToGPU nmap nmat "nmat"
|
||||||
glUniformMatrix3fv nmat 1 0 (castPtr (ptr :: Ptr (L.M33 CFloat)))
|
|
||||||
|
|
||||||
checkError "nmat"
|
|
||||||
|
|
||||||
drawMap --draw map -> put to another function for readability
|
drawMap --draw map -> put to another function for readability
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
@ -494,16 +486,12 @@ render = do
|
|||||||
|
|
||||||
--set up projection (= copy from state)
|
--set up projection (= copy from state)
|
||||||
--TODO: Fix width/depth
|
--TODO: Fix width/depth
|
||||||
with (distribute frust) $ \ptr ->
|
mat44ToGPU frust projmo "mapObjects-projection"
|
||||||
glUniformMatrix4fv projmo 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
|
||||||
checkError "copy projection"
|
|
||||||
|
|
||||||
--set up camera
|
--set up camera
|
||||||
--TODO: Fix magic constants... and camPos
|
--TODO: Fix magic constants... and camPos
|
||||||
let ! cam = getCam camPos zDist' xa ya
|
let ! cam = getCam camPos zDist' xa ya
|
||||||
with (distribute cam) $ \ptr ->
|
mat44ToGPU cam vmatmo "mapObjects-cam"
|
||||||
glUniformMatrix4fv vmatmo 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
|
|
||||||
checkError "copy shadowmap-cam"
|
|
||||||
|
|
||||||
--set up normal--Mat transpose((model*camera)^-1)
|
--set up normal--Mat transpose((model*camera)^-1)
|
||||||
--needed?
|
--needed?
|
||||||
@ -512,10 +500,8 @@ render = do
|
|||||||
Nothing -> L.eye3) :: L.M33 CFloat
|
Nothing -> L.eye3) :: L.M33 CFloat
|
||||||
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
||||||
|
|
||||||
with (distribute nmap) $ \ptr ->
|
mat33ToGPU nmap nmatmo "mapObjects-nmat"
|
||||||
glUniformMatrix3fv nmatmo 1 0 (castPtr (ptr :: Ptr (L.M33 CFloat)))
|
|
||||||
|
|
||||||
checkError "nmat"
|
|
||||||
mapM_ renderObject (state ^. gl.glMap.mapObjects)
|
mapM_ renderObject (state ^. gl.glMap.mapObjects)
|
||||||
checkError "draw mapobjects"
|
checkError "draw mapobjects"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user