Start cleanup

This commit is contained in:
2021-08-12 15:02:26 +02:00
parent 62af1402ad
commit 53555865f6
10 changed files with 121 additions and 387 deletions
+40 -46
View File
@@ -1,22 +1,17 @@
--{-# LANGUAGE TupleSections #-}
{-# LANGUAGE BangPatterns #-}
module Shader.Poke
( pokeArrayOff
( pokeVerxs
, pokeLayVerxs
, pokeArrayOff
, pokePoint3s
, pokePoint33s
, pokeVerxs
, pokeLayVerxs
, poke224s
, picShadToUMV
, picShadToMV
, vToPicShad
, vToPicShadMV
) where
import Shader.Data
import Shader.Parameters
import Picture.Data
import Geometry.Data
--import Layers
--import qualified Streaming.Prelude as SP
--import Data.Maybe
@@ -32,16 +27,16 @@ import qualified Data.Vector.Fusion.Stream.Monadic as VS
import Control.Monad.Primitive
pokeVerxs
:: MV.MVector (PrimState IO) VShader
:: MV.MVector (PrimState IO) FullShader
-> UMV.MVector (PrimState IO) Int
-> [Verx]
-> IO ()
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 :: MV.MVector (PrimState IO) FullShader -> 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
basePtr <- _vboPtr . _vaoVBO . _shaderVAO <$> MV.read vbos sn
let thePtr = plusPtr basePtr (typeOff * pokeStride sn * floatSize)
poke34 thePtr thePos theCol
pokeArrayOff thePtr 7 ext
@@ -49,37 +44,37 @@ pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxExt=ext,_vxShadNum=the
where
sn = _unShadNum theShadNum
vToPicShad :: UMV.MVector (PrimState IO) Int -> IO (PicShads Int)
{-# INLINE vToPicShad #-}
vToPicShad mv = mapM (UMV.unsafeRead mv) $ PicShads 0 1 2 3 4 5
vToPicShadMV :: MV.MVector (PrimState IO) Int -> IO (PicShads Int)
{-# INLINE vToPicShadMV #-}
vToPicShadMV mv = mapM (MV.unsafeRead mv) $ PicShads 0 1 2 3 4 5
picShadToUMV :: PicShads Int -> IO (UMV.MVector (PrimState IO) Int)
{-# INLINE picShadToUMV #-}
picShadToUMV (PicShads a b c d e f) = do
theVec <- UMV.new 6
UMV.write theVec 0 a
UMV.write theVec 1 b
UMV.write theVec 2 c
UMV.write theVec 3 d
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
theVec <- MV.new 6
MV.write theVec 0 a
MV.write theVec 1 b
MV.write theVec 2 c
MV.write theVec 3 d
MV.write theVec 4 e
MV.write theVec 5 f
return theVec
--vToPicShad :: UMV.MVector (PrimState IO) Int -> IO (PicShads Int)
--{-# INLINE vToPicShad #-}
--vToPicShad mv = mapM (UMV.unsafeRead mv) $ PicShads 0 1 2 3 4 5
--
--vToPicShadMV :: MV.MVector (PrimState IO) Int -> IO (PicShads Int)
--{-# INLINE vToPicShadMV #-}
--vToPicShadMV mv = mapM (MV.unsafeRead mv) $ PicShads 0 1 2 3 4 5
--
--picShadToUMV :: PicShads Int -> IO (UMV.MVector (PrimState IO) Int)
--{-# INLINE picShadToUMV #-}
--picShadToUMV (PicShads a b c d e f) = do
-- theVec <- UMV.new 6
-- UMV.write theVec 0 a
-- UMV.write theVec 1 b
-- UMV.write theVec 2 c
-- UMV.write theVec 3 d
-- 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
-- theVec <- MV.new 6
-- MV.write theVec 0 a
-- MV.write theVec 1 b
-- MV.write theVec 2 c
-- MV.write theVec 3 d
-- MV.write theVec 4 e
-- MV.write theVec 5 f
-- return theVec
poke34 :: Ptr Float -> Point3 -> Point4 -> IO ()
@@ -125,17 +120,17 @@ pokePoint3s ptr vals0 = go vals0 0
off i = n*3 + i
pokeLayVerxs
:: MV.MVector (PrimState IO) VShader
:: MV.MVector (PrimState IO) FullShader
-> UMV.MVector (PrimState IO) Int
-> [Verx]
-> IO ()
pokeLayVerxs vbos counts vxs = VS.mapM_ (pokeLayVerx vbos counts) $ VS.fromList vxs
pokeLayVerx :: MV.MVector (PrimState IO) VShader -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
pokeLayVerx :: MV.MVector (PrimState IO) FullShader -> 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
basePtr <- _vboPtr . _vaoVBO . _shaderVAO <$> MV.unsafeRead vbos sn
let thePtr = plusPtr basePtr ((theOff + layOff) * theStride * floatSize)
poke34 thePtr thePos theCol
pokeArrayOff thePtr 7 (_vxExt vx)
@@ -146,7 +141,6 @@ pokeLayVerx vbos counts vx = do
theLayer = _vxLayer vx
thePos = _vxPos vx
theCol = _vxCol vx
--basePtr = _vboPtr $ vboFromType vbos sn
layOff = theLayer * numSubElements
theStride = pokeStride sn