Redo mutable changes
This commit is contained in:
+34
-46
@@ -32,13 +32,22 @@ import qualified Data.Vector.Fusion.Stream.Monadic as VS
|
||||
import Control.Monad.Primitive
|
||||
|
||||
pokeVerxs
|
||||
:: PicShads VBO
|
||||
:: 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
|
||||
pokeVerxs vbos count vxs = VS.mapM_ (pokeVerx vbos count) $ VS.fromList vxs
|
||||
|
||||
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
|
||||
basePtr <- fmap (_vboPtr . _vaoVBO . _vshaderVAO) $ MV.read vbos sn
|
||||
let thePtr = plusPtr basePtr (typeOff * pokeStride sn * floatSize)
|
||||
poke34 thePtr thePos theCol
|
||||
pokeArrayOff thePtr 7 ext
|
||||
UMV.unsafeModify offsets (+1) sn
|
||||
where
|
||||
sn = _unShadNum theShadNum
|
||||
|
||||
vToPicShad :: UMV.MVector (PrimState IO) Int -> IO (PicShads Int)
|
||||
{-# INLINE vToPicShad #-}
|
||||
@@ -59,6 +68,7 @@ picShadToUMV (PicShads a b c d e f) = do
|
||||
UMV.write theVec 4 e
|
||||
UMV.write theVec 5 f
|
||||
return theVec
|
||||
|
||||
picShadToMV :: PicShads a -> IO (MV.MVector (PrimState IO) a)
|
||||
{-# INLINE picShadToMV #-}
|
||||
picShadToMV (PicShads a b c d e f) = do
|
||||
@@ -72,29 +82,6 @@ picShadToMV (PicShads a b c d e f) = do
|
||||
return theVec
|
||||
|
||||
|
||||
|
||||
pokeVerx :: PicShads VBO -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
|
||||
--{-# INLINE pokeVerx #-}
|
||||
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
|
||||
let thePtr = plusPtr (_vboPtr theShad) (typeOff * pokeStride sn * floatSize)
|
||||
poke34 thePtr thePos theCol
|
||||
pokeArrayOff thePtr 7 ext
|
||||
UMV.unsafeModify offsets (+1) sn
|
||||
where
|
||||
sn = _unShadNum theShadNum
|
||||
|
||||
poke34 :: Ptr Float -> Point3 -> Point4 -> IO ()
|
||||
{-# INLINE poke34 #-}
|
||||
poke34 ptr (V3 a b c) (V4 d e f g) = do
|
||||
@@ -137,23 +124,6 @@ pokePoint3s ptr vals0 = go vals0 0
|
||||
where
|
||||
off i = n*3 + i
|
||||
|
||||
pokeLayVerx :: PicShads VBO -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
|
||||
--{-# INLINE pokeLayVerx #-}
|
||||
pokeLayVerx vbos counts vx = do
|
||||
theOff <- UMV.unsafeRead counts vecPos
|
||||
let thePtr = plusPtr basePtr ((theOff + layOff) * theStride * floatSize)
|
||||
poke34 thePtr thePos theCol
|
||||
pokeArrayOff thePtr 7 (_vxExt vx)
|
||||
UMV.unsafeModify counts (+ 1) vecPos
|
||||
where
|
||||
sn = _unShadNum (_vxShadNum vx)
|
||||
vecPos = theLayer * 6 + sn
|
||||
theLayer = _vxLayer vx
|
||||
thePos = _vxPos vx
|
||||
theCol = _vxCol vx
|
||||
basePtr = _vboPtr $ vboFromType vbos sn
|
||||
layOff = theLayer * numSubElements
|
||||
theStride = pokeStride sn
|
||||
|
||||
vboFromType :: PicShads VBO -> Int -> VBO
|
||||
{-# INLINE vboFromType #-}
|
||||
@@ -167,13 +137,31 @@ vboFromType ps sn = case sn of
|
||||
_ -> undefined
|
||||
|
||||
|
||||
pokeLayVerxs :: PicShads VBO -> [Verx] -> IO (IM.IntMap (PicShads Int))
|
||||
pokeLayVerxs :: MV.MVector (PrimState IO) VShader -> [Verx] -> IO (IM.IntMap (PicShads Int))
|
||||
pokeLayVerxs vbos vxs = do
|
||||
counts <- UMV.replicate (6*6) 0
|
||||
--SP.mapM_ (pokeLayVerx vbos counts) $ SP.each vxs
|
||||
VS.mapM_ (pokeLayVerx vbos counts) $ VS.fromList vxs
|
||||
vToLayPicShad counts
|
||||
|
||||
pokeLayVerx :: MV.MVector (PrimState IO) VShader -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
|
||||
--{-# INLINE pokeLayVerx #-}
|
||||
pokeLayVerx vbos counts vx = do
|
||||
theOff <- UMV.unsafeRead counts vecPos
|
||||
basePtr <- fmap (_vboPtr . _vaoVBO . _vshaderVAO) $ MV.unsafeRead vbos sn
|
||||
let thePtr = plusPtr basePtr ((theOff + layOff) * theStride * floatSize)
|
||||
poke34 thePtr thePos theCol
|
||||
pokeArrayOff thePtr 7 (_vxExt vx)
|
||||
UMV.unsafeModify counts (+ 1) vecPos
|
||||
where
|
||||
sn = _unShadNum (_vxShadNum vx)
|
||||
vecPos = theLayer * 6 + sn
|
||||
theLayer = _vxLayer vx
|
||||
thePos = _vxPos vx
|
||||
theCol = _vxCol vx
|
||||
--basePtr = _vboPtr $ vboFromType vbos sn
|
||||
layOff = theLayer * numSubElements
|
||||
theStride = pokeStride sn
|
||||
|
||||
vToLayPicShad :: UMV.MVector RealWorld Int -> IO (IM.IntMap (PicShads Int))
|
||||
{-# INLINE vToLayPicShad #-}
|
||||
vToLayPicShad mv = foldM f IM.empty [0..5]
|
||||
|
||||
Reference in New Issue
Block a user