Continue transfer to mutable vectors

This commit is contained in:
jgk
2021-08-11 22:02:17 +02:00
parent 0c4c83abb5
commit 1f2f5431c0
5 changed files with 50 additions and 44 deletions
+14 -19
View File
@@ -31,14 +31,22 @@ import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Fusion.Stream.Monadic as VS
import Control.Monad.Primitive
pokeVerxs
:: PicShads VBO
--pokeVerxs
-- :: PicShads VBO
-- -> UMV.MVector (PrimState IO) Int
-- -> [Verx]
-- -> IO ()
--pokeVerxs vbos count vxs = do
-- s <- picShadToMV vbos
-- VS.mapM_ (pokeVerx s count) $ VS.fromList vxs
pokeVerxs
:: MV.MVector (PrimState IO) VShader
-> UMV.MVector (PrimState IO) Int
-> [Verx]
-> IO ()
pokeVerxs vbos count vxs = do
s <- picShadToMV vbos
VS.mapM_ (pokeVerx' s count) $ VS.fromList vxs
VS.mapM_ (pokeVerx vbos count) $ VS.fromList vxs
vToPicShad :: UMV.MVector (PrimState IO) Int -> IO (PicShads Int)
{-# INLINE vToPicShad #-}
@@ -71,23 +79,10 @@ picShadToMV (PicShads a b c d e f) = do
MV.write theVec 5 f
return theVec
pokeVerx :: PicShads VBO -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
--{-# INLINE pokeVerx #-}
pokeVerx :: MV.MVector (PrimState IO) VShader -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxExt=ext,_vxShadNum=theShadNum} = do
typeOff <- UMV.unsafeRead offsets sn
let thePtr = plusPtr (_vboPtr $ vboFromType vbos sn) (typeOff * pokeStride sn * floatSize)
poke34 thePtr thePos theCol
pokeArrayOff thePtr 7 ext
UMV.unsafeModify offsets (+1) sn
where
sn = _unShadNum theShadNum
pokeVerx' :: MV.MVector (PrimState IO) VBO -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
pokeVerx' vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxExt=ext,_vxShadNum=theShadNum} = do
typeOff <- UMV.unsafeRead offsets sn
theShad <- MV.read vbos sn
theShad <- fmap (_vaoVBO . _vshaderVAO) $ MV.read vbos sn
let thePtr = plusPtr (_vboPtr theShad) (typeOff * pokeStride sn * floatSize)
poke34 thePtr thePos theCol
pokeArrayOff thePtr 7 ext