Refactor pointers into vaos
This commit is contained in:
+17
-76
@@ -25,29 +25,13 @@ data PreloadData = PreloadData
|
|||||||
, _arcShader :: Program
|
, _arcShader :: Program
|
||||||
, _fadeCircleShader :: Program
|
, _fadeCircleShader :: Program
|
||||||
, _triVAO :: VAO
|
, _triVAO :: VAO
|
||||||
, _textVAO' :: VAO
|
, _lineVAO :: VAO
|
||||||
, _circVAO' :: VAO
|
, _textVAO :: VAO
|
||||||
, _arcVAO' :: VAO
|
, _circVAO :: VAO
|
||||||
, _basicVAO :: VertexArrayObject
|
, _arcVAO :: VAO
|
||||||
, _textVAO :: VertexArrayObject
|
|
||||||
, _circVAO :: VertexArrayObject
|
|
||||||
, _arcVAO :: VertexArrayObject
|
|
||||||
, _posVBO :: BufferObject
|
, _posVBO :: BufferObject
|
||||||
, _colVBO :: BufferObject
|
, _colVBO :: BufferObject
|
||||||
, _texVBO :: BufferObject
|
, _texVBO :: BufferObject
|
||||||
, _ptrPosVBO :: Ptr Float
|
|
||||||
, _ptrColVBO :: Ptr Float
|
|
||||||
, _ptrCharPos :: Ptr Float
|
|
||||||
, _ptrCharCol :: Ptr Float
|
|
||||||
, _ptrCharTex :: Ptr Float
|
|
||||||
, _ptrCircPos :: Ptr Float
|
|
||||||
, _ptrCircCol :: Ptr Float
|
|
||||||
, _ptrCircSca :: Ptr Float
|
|
||||||
, _ptrArcPos :: Ptr Float
|
|
||||||
, _ptrArcCol :: Ptr Float
|
|
||||||
, _ptrArcSca :: Ptr Float
|
|
||||||
, _ptrLinePos :: Ptr Float
|
|
||||||
, _ptrLineCol :: Ptr Float
|
|
||||||
, _uniWinSize :: UniformLocation
|
, _uniWinSize :: UniformLocation
|
||||||
, _csZoomUni :: UniformLocation
|
, _csZoomUni :: UniformLocation
|
||||||
, _asWinUni :: UniformLocation
|
, _asWinUni :: UniformLocation
|
||||||
@@ -159,34 +143,10 @@ doPreload' = do
|
|||||||
textureFilter Texture2D $= ((Linear',Just Linear') , Nearest)
|
textureFilter Texture2D $= ((Linear',Just Linear') , Nearest)
|
||||||
|
|
||||||
trivao <- setupVAO' [(posVBO,0,3),(colVBO,1,4)]
|
trivao <- setupVAO' [(posVBO,0,3),(colVBO,1,4)]
|
||||||
|
linevao <- setupVAO' [(posVBO,0,3),(colVBO,1,4)]
|
||||||
textvao <- setupVAO' [(posVBO,0,3),(colVBO,1,4),(texVBO,2,2)]
|
textvao <- setupVAO' [(posVBO,0,3),(colVBO,1,4),(texVBO,2,2)]
|
||||||
circvao <- setupVAO' [(posVBO,0,3),(colVBO,1,4),(texVBO,2,1)]
|
circvao <- setupVAO' [(posVBO,0,3),(colVBO,1,4),(texVBO,2,1)]
|
||||||
arcvao <- setupVAO' [(posVBO,0,3),(colVBO,1,4),(texVBO,2,4)]
|
arcvao <- setupVAO' [(posVBO,0,3),(colVBO,1,4),(texVBO,2,4)]
|
||||||
-- setup VAOs: basic vao
|
|
||||||
basicVAO <- setupVAO [(posVBO,0,3),(colVBO,1,4)]
|
|
||||||
textVAO <- setupVAO [(posVBO,0,3),(colVBO,1,4),(texVBO,2,2)]
|
|
||||||
circVAO <- setupVAO [(posVBO,0,3),(colVBO,1,4),(texVBO,2,1)]
|
|
||||||
arcVAO <- setupVAO [(posVBO,0,3),(colVBO,1,4),(texVBO,2,4)]
|
|
||||||
|
|
||||||
-- allocate memory for vertex attributes
|
|
||||||
-- for triangles
|
|
||||||
ptrPosVBO <- mallocArray (3*3*20000)
|
|
||||||
ptrColVBO <- mallocArray (3*4*20000)
|
|
||||||
-- for characters
|
|
||||||
ptrCharPos <- mallocArray (3*20000)
|
|
||||||
ptrCharCol <- mallocArray (4*20000)
|
|
||||||
ptrCharTex <- mallocArray (2*20000)
|
|
||||||
-- for circles
|
|
||||||
ptrCircPos <- mallocArray (3*20000)
|
|
||||||
ptrCircCol <- mallocArray (4*20000)
|
|
||||||
ptrCircSca <- mallocArray (2*20000)
|
|
||||||
-- for lines
|
|
||||||
ptrLinePos <- mallocArray (3*20000)
|
|
||||||
ptrLineCol <- mallocArray (4*20000)
|
|
||||||
-- for arcs
|
|
||||||
ptrArcPos <- mallocArray (3*20000)
|
|
||||||
ptrArcCol <- mallocArray (4*20000)
|
|
||||||
ptrArcSca <- mallocArray (4*20000)
|
|
||||||
|
|
||||||
return $ PreloadData
|
return $ PreloadData
|
||||||
{ _charMap = convertRGBA8 cmap
|
{ _charMap = convertRGBA8 cmap
|
||||||
@@ -196,45 +156,26 @@ doPreload' = do
|
|||||||
, _arcShader = as
|
, _arcShader = as
|
||||||
, _fadeCircleShader = fcs
|
, _fadeCircleShader = fcs
|
||||||
, _triVAO = trivao
|
, _triVAO = trivao
|
||||||
, _textVAO' = textvao
|
, _textVAO = textvao
|
||||||
, _circVAO' = circvao
|
, _circVAO = circvao
|
||||||
, _arcVAO' = arcvao
|
, _arcVAO = arcvao
|
||||||
, _basicVAO = basicVAO
|
, _lineVAO = linevao
|
||||||
, _textVAO = textVAO
|
|
||||||
, _circVAO = circVAO
|
|
||||||
, _arcVAO = arcVAO
|
|
||||||
, _posVBO = posVBO
|
, _posVBO = posVBO
|
||||||
, _colVBO = colVBO
|
, _colVBO = colVBO
|
||||||
, _texVBO = texVBO
|
, _texVBO = texVBO
|
||||||
, _ptrPosVBO = ptrPosVBO
|
|
||||||
, _ptrColVBO = ptrColVBO
|
|
||||||
, _ptrCharPos = ptrCharPos
|
|
||||||
, _ptrCharCol = ptrCharCol
|
|
||||||
, _ptrCharTex = ptrCharTex
|
|
||||||
, _ptrCircPos = ptrCircPos
|
|
||||||
, _ptrCircCol = ptrCircCol
|
|
||||||
, _ptrCircSca = ptrCircSca
|
|
||||||
, _ptrArcPos = ptrArcPos
|
|
||||||
, _ptrArcCol = ptrArcCol
|
|
||||||
, _ptrArcSca = ptrArcSca
|
|
||||||
, _ptrLinePos = ptrLinePos
|
|
||||||
, _ptrLineCol = ptrLineCol
|
|
||||||
, _uniWinSize = winSizeUni
|
, _uniWinSize = winSizeUni
|
||||||
, _csZoomUni = zoomUni
|
, _csZoomUni = zoomUni
|
||||||
, _asWinUni = asWinSizeUniLoc
|
, _asWinUni = asWinSizeUniLoc
|
||||||
, _asZoomUni = asZoomUniLoc
|
, _asZoomUni = asZoomUniLoc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vaoPointers :: VAO -> [Ptr Float]
|
||||||
|
vaoPointers = (\(_,ps,_) -> ps) . unzip3 . _vaoBufferTargets
|
||||||
|
|
||||||
cleanUpPreload :: PreloadData -> IO ()
|
cleanUpPreload :: PreloadData -> IO ()
|
||||||
cleanUpPreload pd = do
|
cleanUpPreload pd = do
|
||||||
free (_ptrPosVBO pd)
|
mapM_ free $ vaoPointers $ _triVAO pd
|
||||||
free (_ptrColVBO pd)
|
mapM_ free $ vaoPointers $ _textVAO pd
|
||||||
free (_ptrCharPos pd)
|
mapM_ free $ vaoPointers $ _circVAO pd
|
||||||
free (_ptrCharCol pd)
|
mapM_ free $ vaoPointers $ _arcVAO pd
|
||||||
free (_ptrCharTex pd)
|
mapM_ free $ vaoPointers $ _lineVAO pd
|
||||||
free (_ptrCircPos pd)
|
|
||||||
free (_ptrCircCol pd)
|
|
||||||
free (_ptrCircSca pd)
|
|
||||||
free (_ptrArcPos pd)
|
|
||||||
free (_ptrArcCol pd)
|
|
||||||
free (_ptrArcSca pd)
|
|
||||||
|
|||||||
+12
-14
@@ -254,10 +254,10 @@ renderPicture' pdata zoom (winx,winy) pic = do
|
|||||||
(nTriVs,nTextVs,numCircVs,nLineVs,nArcVs)
|
(nTriVs,nTextVs,numCircVs,nLineVs,nArcVs)
|
||||||
-- <- F.foldM (theFold (_ptrPosVBO pdata, _ptrColVBO pdata)
|
-- <- F.foldM (theFold (_ptrPosVBO pdata, _ptrColVBO pdata)
|
||||||
<- F.foldM (theFold (twoPtrsVAO $ _triVAO pdata)
|
<- F.foldM (theFold (twoPtrsVAO $ _triVAO pdata)
|
||||||
(threePtrsVAO $ _textVAO' pdata)
|
(threePtrsVAO $ _textVAO pdata)
|
||||||
(threePtrsVAO $ _circVAO' pdata)
|
(threePtrsVAO $ _circVAO pdata)
|
||||||
(_ptrLinePos pdata, _ptrLineCol pdata)
|
(twoPtrsVAO $ _lineVAO pdata)
|
||||||
(threePtrsVAO $ _arcVAO' pdata)
|
(threePtrsVAO $ _arcVAO pdata)
|
||||||
) $ picToFTree pic
|
) $ picToFTree pic
|
||||||
|
|
||||||
depthFunc $= Just Less
|
depthFunc $= Just Less
|
||||||
@@ -268,29 +268,27 @@ renderPicture' pdata zoom (winx,winy) pic = do
|
|||||||
drawArrays Triangles (fromIntegral firstIndex) (fromIntegral $ nTriVs)
|
drawArrays Triangles (fromIntegral firstIndex) (fromIntegral $ nTriVs)
|
||||||
-- draw lines, don't need to change the program or vaos, just need to bind the
|
-- draw lines, don't need to change the program or vaos, just need to bind the
|
||||||
-- vbos and draw
|
-- vbos and draw
|
||||||
bindArrayBuffers nLineVs
|
bindVertexArrayObject $= Just (_vao $ _lineVAO pdata)
|
||||||
[(_posVBO pdata, _ptrLinePos pdata, 3)
|
bindArrayBuffers nTriVs $ _vaoBufferTargets $ _lineVAO pdata
|
||||||
,(_colVBO pdata, _ptrLineCol pdata, 4)
|
|
||||||
]
|
|
||||||
drawArrays Lines (fromIntegral firstIndex) (fromIntegral $ nLineVs)
|
drawArrays Lines (fromIntegral firstIndex) (fromIntegral $ nLineVs)
|
||||||
-- draw circles
|
-- draw circles
|
||||||
currentProgram $= Just (_circShader pdata)
|
currentProgram $= Just (_circShader pdata)
|
||||||
uniform (_uniWinSize pdata) $= Vector2 winx winy
|
uniform (_uniWinSize pdata) $= Vector2 winx winy
|
||||||
uniform (_csZoomUni pdata) $= zoom
|
uniform (_csZoomUni pdata) $= zoom
|
||||||
bindVertexArrayObject $= Just (_vao $ _circVAO' pdata)
|
bindVertexArrayObject $= Just (_vao $ _circVAO pdata)
|
||||||
bindArrayBuffers numCircVs $ _vaoBufferTargets $ _circVAO' pdata
|
bindArrayBuffers numCircVs $ _vaoBufferTargets $ _circVAO pdata
|
||||||
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ numCircVs)
|
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ numCircVs)
|
||||||
-- draw arcs
|
-- draw arcs
|
||||||
currentProgram $= Just (_arcShader pdata)
|
currentProgram $= Just (_arcShader pdata)
|
||||||
uniform (_asWinUni pdata) $= Vector2 winx winy
|
uniform (_asWinUni pdata) $= Vector2 winx winy
|
||||||
uniform (_asZoomUni pdata) $= zoom
|
uniform (_asZoomUni pdata) $= zoom
|
||||||
bindVertexArrayObject $= Just (_vao $ _arcVAO' pdata)
|
bindVertexArrayObject $= Just (_vao $ _arcVAO pdata)
|
||||||
bindArrayBuffers nArcVs $ _vaoBufferTargets $ _arcVAO' pdata
|
bindArrayBuffers nArcVs $ _vaoBufferTargets $ _arcVAO pdata
|
||||||
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ nArcVs)
|
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ nArcVs)
|
||||||
-- draw text
|
-- draw text
|
||||||
currentProgram $= Just (_textShader pdata)
|
currentProgram $= Just (_textShader pdata)
|
||||||
bindVertexArrayObject $= Just (_vao $ _textVAO' pdata)
|
bindVertexArrayObject $= Just (_vao $ _textVAO pdata)
|
||||||
bindArrayBuffers nTextVs $ _vaoBufferTargets $ _textVAO' pdata
|
bindArrayBuffers nTextVs $ _vaoBufferTargets $ _textVAO pdata
|
||||||
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ nTextVs)
|
drawArrays Points (fromIntegral firstIndex) (fromIntegral $ nTextVs)
|
||||||
|
|
||||||
bufferOffset :: Integral a => a -> Ptr b
|
bufferOffset :: Integral a => a -> Ptr b
|
||||||
|
|||||||
Reference in New Issue
Block a user