Add more mutability

This commit is contained in:
2021-08-11 20:34:34 +02:00
parent b77683bafd
commit 0c4c83abb5
3 changed files with 34 additions and 15 deletions
+8 -5
View File
@@ -25,6 +25,7 @@ import Graphics.Rendering.OpenGL hiding (Line,translate,scale,imageHeight,Polygo
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
import qualified SDL import qualified SDL
import qualified Data.Vector.Unboxed.Mutable as UMV import qualified Data.Vector.Unboxed.Mutable as UMV
import qualified Data.Vector.Mutable as MV
divideSize :: Int -> Size -> Size divideSize :: Int -> Size -> Size
divideSize i (Size x y) = Size (div x $ fromIntegral i) (div y $ fromIntegral i) divideSize i (Size x y) = Size (div x $ fromIntegral i) (div y $ fromIntegral i)
@@ -144,11 +145,10 @@ drawTextureOnFramebuffer fs fbo to = do
drawShader fs 4 drawShader fs 4
pokeBindFoldable pokeBindFoldable
:: RenderData :: PicShads VShader
-> [Verx] -> [Verx]
-> IO (PicShads Int) -> IO (PicShads Int)
pokeBindFoldable pdata m = do pokeBindFoldable shads m = do
let shads = _pictureShaders pdata
counts <- UMV.replicate 6 0 counts <- UMV.replicate 6 0
pokeVerxs (fmap (_vaoVBO . _vshaderVAO) shads) counts m pokeVerxs (fmap (_vaoVBO . _vshaderVAO) shads) counts m
shads' <- picShadToMV shads shads' <- picShadToMV shads
@@ -175,9 +175,12 @@ renderFoldable
-> IO Word32 -> IO Word32
renderFoldable pdata struct = do renderFoldable pdata struct = do
pokeStartTicks <- SDL.ticks pokeStartTicks <- SDL.ticks
count <- pokeBindFoldable pdata struct
let shads = _pictureShaders pdata let shads = _pictureShaders pdata
sequence_ (drawShaderLay 0 <$> shads <*> count) count <- pokeBindFoldable shads struct
s <- picShadToMV shads
c <- picShadToUMV count
MV.imapM_ (drawShaderLay' 0 c) s
--sequence_ (drawShaderLay 0 <$> shads <*> count)
pokeEndTicks <- SDL.ticks pokeEndTicks <- SDL.ticks
return $ pokeEndTicks - pokeStartTicks return $ pokeEndTicks - pokeStartTicks
------------------------------end renderFoldable ------------------------------end renderFoldable
+13 -7
View File
@@ -5,6 +5,7 @@ module Shader
, drawShader , drawShader
, freeShaderPointers , freeShaderPointers
, drawShaderLay , drawShaderLay
, drawShaderLay'
, shadVBOptr , shadVBOptr
) where ) where
--import Geometry.Data --import Geometry.Data
@@ -57,13 +58,6 @@ bindShaderLay shads = mapM_ (uncurry f) . IM.toList
where where
f lay counts = sequence_ $ bindArrayBuffersLayer lay <$> counts <*> (_vaoVBO . _vshaderVAO <$> shads) f lay counts = sequence_ $ bindArrayBuffersLayer lay <$> counts <*> (_vaoVBO . _vshaderVAO <$> shads)
--bindShader :: PicShads VShader -> PicShads Int -> IO ()
----bindShader shads counts = sequence_ $ bindArrayBuffers <$> counts <*> (_vaoVBO . _vshaderVAO <$> shads)
--bindShader shads count = do
-- s <- picShadToMV shads
-- c <- picShadToUMV count
-- bindShader' s c
bindShader :: MV.MVector (PrimState IO) VShader -> UMV.MVector (PrimState IO) Int -> IO () bindShader :: MV.MVector (PrimState IO) VShader -> UMV.MVector (PrimState IO) Int -> IO ()
bindShader shads counts = MV.imapM_ f shads bindShader shads counts = MV.imapM_ f shads
where where
@@ -86,6 +80,18 @@ drawShaderLay l fs i = do
_ -> return () _ -> return ()
glDrawArrays (marshalEPrimitiveMode $ _vshaderDrawPrimitive fs) (fromIntegral $ l*numSubElements) (fromIntegral i) glDrawArrays (marshalEPrimitiveMode $ _vshaderDrawPrimitive fs) (fromIntegral $ l*numSubElements) (fromIntegral i)
drawShaderLay' :: Int -> UMV.MVector (PrimState IO) Int -> Int -> VShader -> IO ()
{-# INLINE drawShaderLay' #-}
drawShaderLay' l countsVector index fs = do
i <- UMV.read countsVector index
currentProgram $= Just (_vshaderProgram fs)
bindVertexArrayObject $= Just (_vao $ _vshaderVAO fs)
case _vshaderTexture fs of
Just ShaderTexture{_textureObject = txo}
-> textureBinding Texture2D $= Just txo
_ -> return ()
glDrawArrays (marshalEPrimitiveMode $ _vshaderDrawPrimitive fs) (fromIntegral $ l*numSubElements) (fromIntegral i)
drawShader :: FullShader -> Int -> IO () drawShader :: FullShader -> Int -> IO ()
{-# INLINE drawShader #-} {-# INLINE drawShader #-}
drawShader fs i = do drawShader fs i = do
+13 -3
View File
@@ -37,9 +37,8 @@ pokeVerxs
-> [Verx] -> [Verx]
-> IO () -> IO ()
pokeVerxs vbos count vxs = do pokeVerxs vbos count vxs = do
--count <- UMV.replicate 6 0 s <- picShadToMV vbos
VS.mapM_ (pokeVerx vbos count) $ VS.fromList vxs VS.mapM_ (pokeVerx' s count) $ VS.fromList vxs
--vToPicShad count
vToPicShad :: UMV.MVector (PrimState IO) Int -> IO (PicShads Int) vToPicShad :: UMV.MVector (PrimState IO) Int -> IO (PicShads Int)
{-# INLINE vToPicShad #-} {-# INLINE vToPicShad #-}
@@ -85,6 +84,17 @@ pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxExt=ext,_vxShadNum=the
where where
sn = _unShadNum theShadNum 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 () poke34 :: Ptr Float -> Point3 -> Point4 -> IO ()
{-# INLINE poke34 #-} {-# INLINE poke34 #-}
poke34 ptr (V3 a b c) (V4 d e f g) = do poke34 ptr (V3 a b c) (V4 d e f g) = do