Start to move vbo objects to use DSA

This commit is contained in:
2023-03-09 13:17:43 +00:00
parent 9f37ed9944
commit f14d9bef60
5 changed files with 24 additions and 21 deletions
+3 -2
View File
@@ -14,11 +14,12 @@ 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 = do
bindBuffer ArrayBuffer $= Just (_vbo theVBO)
glBindBuffer GL_ARRAY_BUFFER (_vboName theVBO)
bufferSubData
ArrayBuffer
WriteToBuffer
@@ -32,7 +33,7 @@ bindShaderLayers shads counts = MV.imapM_ f shads
f i shad = do
let theVBO = _vaoVBO $ _shadVAO' shad
stride = sum $ _vboAttribSizes theVBO
bindBuffer ArrayBuffer $= (Just . _vbo $ theVBO)
glBindBuffer GL_ARRAY_BUFFER (_vboName $ theVBO)
VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5]
--S.mapM_ (g stride theVBO) $ S.each [0..5]
+5 -3
View File
@@ -141,8 +141,10 @@ setupVAOSized ndraw sizes = do
setupVBOSized :: Int -> [Int] -> IO VBO
setupVBOSized ndraw sizes = do
vboName <- genObjectName
bindBuffer ArrayBuffer $= Just vboName
--vboName <- genObjectName
--bindBuffer ArrayBuffer $= Just vboName
vboname <- mglCreateSingle glCreateBuffers
glBindBuffer GL_ARRAY_BUFFER vboname
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
setupVertexAttribPointer loc siz strd off
thePtr <- mallocArray (strd * ndraw)
@@ -154,7 +156,7 @@ setupVBOSized ndraw sizes = do
)
return $
VBO
{ _vbo = vboName
{ _vboName = vboname
, _vboPtr = thePtr
, _vboAttribSizes = sizes
, _vboStride = sum sizes
+2 -2
View File
@@ -12,7 +12,7 @@ module Shader.Data
-- | Lens functions
, vaoName
, vaoVBO
, vbo
, vboName
, vboPtr
, vboAttribSizes
, vboStride
@@ -53,7 +53,7 @@ a pointer to a location with space that can be written to the buffer,
and a list of attribute pointer sizes.
Vertex attributes are interleaved within the vbo. -}
data VBO = VBO
{ _vbo :: BufferObject
{ _vboName :: GLuint
, _vboPtr :: Ptr Float
, _vboAttribSizes :: [Int] -- ^ It is not clear to me if this is necessary to store or not
, _vboStride :: Int