Add wall drawing capability (for shadows)
This commit is contained in:
+75
-5
@@ -247,8 +247,81 @@ threePtrsVAO :: VAO -> (Ptr Float, Ptr Float,Ptr Float)
|
||||
threePtrsVAO vao = case (\(_,ps,_) -> ps) $ unzip3 $ _vaoBufferTargets vao of
|
||||
(a:b:c:_) -> (a,b,c)
|
||||
|
||||
renderPicture' :: PreloadData -> Float -> Float -> (Float,Float) -> (Float,Float) -> Picture -> IO ()
|
||||
renderPicture' pdata rot zoom (tranx,trany) (winx,winy) pic = do
|
||||
renderPicture' :: PreloadData -> Float -> Float -> (Float,Float) -> (Float,Float) ->
|
||||
[(Point2,Point2,Point2,Point2)] -> Picture -> IO ()
|
||||
renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints pic = do
|
||||
let firstIndex = 0
|
||||
|
||||
(nTriVs,nTextVs,numCircVs,nLineVs,nArcVs)
|
||||
-- <- F.foldM (theFold (_ptrPosVBO pdata, _ptrColVBO pdata)
|
||||
<- F.foldM (theFold (twoPtrsVAO $ _triVAO pdata)
|
||||
(threePtrsVAO $ _textVAO pdata)
|
||||
(threePtrsVAO $ _circVAO pdata)
|
||||
(twoPtrsVAO $ _lineVAO pdata)
|
||||
(threePtrsVAO $ _arcVAO pdata)
|
||||
) $ picToFTree pic
|
||||
|
||||
depthFunc $= Just Less
|
||||
|
||||
currentProgram $= Just (_wallShadowShader pdata)
|
||||
bindVertexArrayObject $= Just (_vao $ _wallVAO pdata)
|
||||
let wallPtr = (\(_,x,_) -> x) $ head $ _vaoBufferTargets $ _wallVAO pdata
|
||||
wallPtr2 = (\(_,x,_) -> x) $ (_vaoBufferTargets $ _wallVAO pdata) !! 1
|
||||
foldWalls n ((x,y),(z,w),(a,b),(c,d)) = do
|
||||
pokeFourOff wallPtr n (x,y,z,w)
|
||||
pokeFourOff wallPtr2 n (a,b,c,d)
|
||||
return $ n+1
|
||||
nWalls <- foldM foldWalls 0 wallPoints
|
||||
bindArrayBuffers (length wallPoints) $ _vaoBufferTargets $ _wallVAO pdata
|
||||
drawArrays Points (fromIntegral 0) (fromIntegral $ length wallPoints)
|
||||
|
||||
currentProgram $= Just (_backShader pdata)
|
||||
bindVertexArrayObject $= Just (_vao $ _backVAO pdata)
|
||||
let backPtr = (\(_,x,_) -> x) $ head $ _vaoBufferTargets $ _backVAO pdata
|
||||
backPtr2 = (\(_,x,_) -> x) $ (_vaoBufferTargets $ _backVAO pdata) !! 1
|
||||
pokeFourOff backPtr 0 (tranx,trany,rot,zoom)
|
||||
pokeTwoOff backPtr2 0 (winx,winy)
|
||||
bindArrayBuffers 1 $ _vaoBufferTargets $ _backVAO pdata
|
||||
textureBinding Texture2D $= Just (_textures pdata !! 1)
|
||||
drawArrays Points (fromIntegral 0) (fromIntegral 1)
|
||||
|
||||
|
||||
-- draw triangles
|
||||
currentProgram $= Just (_basicShader pdata)
|
||||
bindVertexArrayObject $= Just (_vao $ _triVAO pdata)
|
||||
bindArrayBuffers nTriVs $ _vaoBufferTargets $ _triVAO pdata
|
||||
drawArrays Triangles (fromIntegral firstIndex) (fromIntegral $ nTriVs)
|
||||
-- draw lines, don't need to change the program or vaos, just need to bind the
|
||||
-- vbos and draw
|
||||
bindVertexArrayObject $= Just (_vao $ _lineVAO pdata)
|
||||
bindArrayBuffers nTriVs $ _vaoBufferTargets $ _lineVAO pdata
|
||||
drawArrays Lines (fromIntegral firstIndex) (fromIntegral $ nLineVs)
|
||||
-- draw circles
|
||||
currentProgram $= Just (_circShader pdata)
|
||||
uniform (_uniWinSize pdata) $= Vector2 winx winy
|
||||
uniform (_csZoomUni pdata) $= zoom
|
||||
bindVertexArrayObject $= Just (_vao $ _circVAO pdata)
|
||||
bindArrayBuffers numCircVs $ _vaoBufferTargets $ _circVAO pdata
|
||||
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ numCircVs)
|
||||
-- draw arcs
|
||||
currentProgram $= Just (_arcShader pdata)
|
||||
uniform (_asWinUni pdata) $= Vector2 winx winy
|
||||
uniform (_asZoomUni pdata) $= zoom
|
||||
bindVertexArrayObject $= Just (_vao $ _arcVAO pdata)
|
||||
bindArrayBuffers nArcVs $ _vaoBufferTargets $ _arcVAO pdata
|
||||
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ nArcVs)
|
||||
-- draw text
|
||||
currentProgram $= Just (_textShader pdata)
|
||||
bindVertexArrayObject $= Just (_vao $ _textVAO pdata)
|
||||
bindArrayBuffers nTextVs $ _vaoBufferTargets $ _textVAO pdata
|
||||
textureBinding Texture2D $= Just (_textures pdata !! 0)
|
||||
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ nTextVs)
|
||||
|
||||
bufferOffset :: Integral a => a -> Ptr b
|
||||
bufferOffset = plusPtr nullPtr . fromIntegral
|
||||
|
||||
renderPicture :: PreloadData -> Float -> Float -> (Float,Float) -> (Float,Float) -> Picture -> IO ()
|
||||
renderPicture pdata rot zoom (tranx,trany) (winx,winy) pic = do
|
||||
let firstIndex = 0
|
||||
|
||||
(nTriVs,nTextVs,numCircVs,nLineVs,nArcVs)
|
||||
@@ -303,6 +376,3 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) pic = do
|
||||
bindArrayBuffers nTextVs $ _vaoBufferTargets $ _textVAO pdata
|
||||
textureBinding Texture2D $= Just (_textures pdata !! 0)
|
||||
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ nTextVs)
|
||||
|
||||
bufferOffset :: Integral a => a -> Ptr b
|
||||
bufferOffset = plusPtr nullPtr . fromIntegral
|
||||
|
||||
Reference in New Issue
Block a user