Continue adding mutability

This commit is contained in:
2021-08-12 05:10:06 +02:00
parent 27cf763805
commit c84bafb267
3 changed files with 10 additions and 34 deletions
+9 -8
View File
@@ -26,6 +26,7 @@ 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 import qualified Data.Vector.Mutable as MV
import Control.Monad.Primitive
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)
@@ -146,15 +147,15 @@ drawTextureOnFramebuffer fs fbo to = do
pokeBindFoldable pokeBindFoldable
:: PicShads VShader :: PicShads VShader
-> UMV.MVector (PrimState IO) Int
-> [Verx] -> [Verx]
-> IO (PicShads Int) -> IO ()
pokeBindFoldable shads m = do pokeBindFoldable shads counts m = do
counts <- UMV.replicate 6 0
shadV <- picShadToMV shads shadV <- picShadToMV shads
pokeVerxs shadV counts m pokeVerxs shadV counts m
bindShader shadV counts bindShader shadV counts
elist <- vToPicShad counts --elist <- vToPicShad counts
return elist --return elist
zeroCounts :: PicShads Int zeroCounts :: PicShads Int
zeroCounts = PicShads 0 0 0 0 0 0 zeroCounts = PicShads 0 0 0 0 0 0
@@ -178,10 +179,10 @@ renderFoldable
renderFoldable pdata struct = do renderFoldable pdata struct = do
pokeStartTicks <- SDL.ticks pokeStartTicks <- SDL.ticks
let shads = _pictureShaders pdata let shads = _pictureShaders pdata
count <- pokeBindFoldable shads struct counts <- UMV.replicate 6 0
pokeBindFoldable shads counts struct
s <- picShadToMV shads s <- picShadToMV shads
c <- picShadToUMV count MV.imapM_ (drawShaderLay' 0 counts) s
MV.imapM_ (drawShaderLay' 0 c) s
--sequence_ (drawShaderLay 0 <$> shads <*> count) --sequence_ (drawShaderLay 0 <$> shads <*> count)
pokeEndTicks <- SDL.ticks pokeEndTicks <- SDL.ticks
return $ pokeEndTicks - pokeStartTicks return $ pokeEndTicks - pokeStartTicks
+1 -13
View File
@@ -23,7 +23,7 @@ import Foreign
import Control.Monad import Control.Monad
import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight) import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight)
import Graphics.GL.Core43 import Graphics.GL.Core43
import qualified Data.IntMap.Strict as IM --import qualified Data.IntMap.Strict as IM
--import Data.Bifunctor --import Data.Bifunctor
--import Text.RawString.QQ --import Text.RawString.QQ
--import Linear.Matrix --import Linear.Matrix
@@ -41,18 +41,6 @@ bindArrayBuffers numVs theVBO = do
(fromIntegral $ floatSize * numVs * sum (_vboAttribSizes theVBO)) (fromIntegral $ floatSize * numVs * sum (_vboAttribSizes theVBO))
(_vboPtr theVBO) (_vboPtr theVBO)
bindArrayBuffersLayer :: Int -> Int -> VBO -> IO ()
bindArrayBuffersLayer lay numVs theVBO = do
bindBuffer ArrayBuffer $= Just (_vbo theVBO)
bufferSubData
ArrayBuffer
WriteToBuffer
(fromIntegral $ floatSize * stride * numSubElements * lay)
(fromIntegral $ floatSize * numVs * stride)
(_vboPtr theVBO `plusPtr` (floatSize * stride * numSubElements * lay))
where
stride = sum $ _vboAttribSizes theVBO
bindShaderLayers :: MV.MVector (PrimState IO) VShader -> UMV.MVector (PrimState IO) Int -> IO () bindShaderLayers :: MV.MVector (PrimState IO) VShader -> UMV.MVector (PrimState IO) Int -> IO ()
bindShaderLayers shads counts = MV.imapM_ f shads bindShaderLayers shads counts = MV.imapM_ f shads
where where
-13
View File
@@ -124,19 +124,6 @@ pokePoint3s ptr vals0 = go vals0 0
where where
off i = n*3 + i off i = n*3 + i
vboFromType :: PicShads VBO -> Int -> VBO
{-# INLINE vboFromType #-}
vboFromType ps sn = case sn of
0 -> _psPoly ps
1 -> _psPolyz ps
2 -> _psBez ps
3 -> _psText ps
4 -> _psArc ps
5 -> _psEll ps
_ -> undefined
pokeLayVerxs :: MV.MVector (PrimState IO) VShader pokeLayVerxs :: MV.MVector (PrimState IO) VShader
-> UMV.MVector (PrimState IO) Int -> UMV.MVector (PrimState IO) Int
-> [Verx] -> IO (IM.IntMap (PicShads Int)) -> [Verx] -> IO (IM.IntMap (PicShads Int))