Refactor shaders, vbos and vaos

This commit is contained in:
2023-03-14 20:24:08 +00:00
parent 378af69ca5
commit ed0da4bf1d
11 changed files with 147 additions and 101 deletions
+27 -27
View File
@@ -1,25 +1,27 @@
module Shader.Bind
( bindShaderLayers
, bindShaderBuffers
, bindShader
) where
module Shader.Bind (
bindShaderLayers,
--, bindShaderBuffers
bufferPokedVBO,
bufferShaderVector,
) where
import Control.Monad.Primitive
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Unboxed.Mutable as UMV
import Foreign hiding (rotate)
--import Control.Monad
import Graphics.GL.Core45
import Shader.Data
import Shader.Parameters
import Foreign hiding (rotate)
import qualified Data.Vector.Unboxed.Mutable as UMV
import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import Control.Monad.Primitive
import Control.Monad
import Graphics.GL.Core45
bindArrayBuffers :: Int -> VBO -> IO ()
{-# INLINABLE bindArrayBuffers #-}
bindArrayBuffers numVs theVBO = glNamedBufferSubData
(_vboName theVBO)
0
(fromIntegral $ floatSize * numVs * sum (_vboAttribSizes theVBO))
bufferPokedVBO :: VBO -> Int -> IO ()
{-# INLINEABLE bufferPokedVBO #-}
bufferPokedVBO theVBO numVs =
glNamedBufferSubData
(_vboName theVBO)
0
(fromIntegral $ floatSize * numVs * _vboVertexSize theVBO)
(_vboPtr theVBO)
bindShaderLayers :: MV.MVector (PrimState IO) (FullShader, VBO) -> UMV.MVector (PrimState IO) Int -> IO ()
@@ -27,7 +29,7 @@ bindShaderLayers shads counts = MV.imapM_ f shads
where
f i shad = do
let theVBO = snd shad
stride = sum $ _vboAttribSizes theVBO
stride = _vboVertexSize theVBO
VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5]
where
g stride theVBO lay = do
@@ -41,12 +43,10 @@ bindShaderLayers shads counts = MV.imapM_ f shads
glNamedBufferSubDataH :: GLuint -> GLintptr -> GLsizeiptr -> Ptr a -> IO ()
glNamedBufferSubDataH = glNamedBufferSubData
bindShader :: MV.MVector (PrimState IO) (FullShader,VBO) -> UMV.MVector (PrimState IO) Int -> IO ()
bindShader shads counts = MV.imapM_ f shads
bufferShaderVector :: MV.MVector (PrimState IO) (FullShader, VBO) -> UMV.MVector (PrimState IO) Int -> IO ()
bufferShaderVector shads counts = MV.imapM_ f shads
where
f i shad = UMV.read counts i >>= flip bindArrayBuffers (snd shad)
f i shad = UMV.read counts i >>= bufferPokedVBO (snd shad)
bindShaderBuffers :: [VBO] -> [Int] -> IO ()
bindShaderBuffers = zipWithM_ f
where
f fs i = bindArrayBuffers i fs
--bindShaderBuffers :: [VBO] -> [Int] -> IO ()
--bindShaderBuffers = zipWithM_ bufferPokedVBO