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
+1 -1
View File
@@ -23,7 +23,7 @@ drawCPUShadows pdata s pos rad = do
let theshad = pdata ^. positionalBlankShader let theshad = pdata ^. positionalBlankShader
theptr = _vboPtr $ _vaoVBO $ _shadVAO' theshad theptr = _vboPtr $ _vaoVBO $ _shadVAO' theshad
i <- VFSM.foldlM' (pokeShapeShad pos rad theptr) 0 $ VFSM.fromList s i <- VFSM.foldlM' (pokeShapeShad pos rad theptr) 0 $ VFSM.fromList s
bindBuffer ArrayBuffer $= (theshad ^? shadVAO' . vaoVBO . vbo) glBindBuffer GL_ARRAY_BUFFER (theshad ^. shadVAO' . vaoVBO . vboName)
bufferSubData bufferSubData
ArrayBuffer ArrayBuffer
WriteToBuffer WriteToBuffer
+13 -13
View File
@@ -32,20 +32,20 @@ preloadRender = do
bufferData UniformBuffer $= (64, nullPtr, StreamDraw) bufferData UniformBuffer $= (64, nullPtr, StreamDraw)
bindBufferBase IndexedUniformBuffer 0 $= Just theUBO bindBufferBase IndexedUniformBuffer 0 $= Just theUBO
-- setup wall points VBO, VAOs and shaders -- setup wall points VBO, VAOs and shaders
wpVBOname <- genObjectName wpVBOname <- mglCreateSingle glCreateBuffers
wpVBOptr <- mallocArray (8 * numDrawableWalls) wpVBOptr <- mallocArray (8 * numDrawableWalls)
bindBuffer ArrayBuffer $= Just wpVBOname glBindBuffer GL_ARRAY_BUFFER wpVBOname
bufferData ArrayBuffer bufferData ArrayBuffer
$= ( fromIntegral $ floatSize * numDrawableWalls * 8 $= ( fromIntegral $ floatSize * numDrawableWalls * 8
, nullPtr , nullPtr
, StreamDraw , StreamDraw
) )
let wpVBO = VBO{_vbo = wpVBOname, _vboPtr = wpVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8} let wpVBO = VBO{_vboName = wpVBOname, _vboPtr = wpVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8}
-- wpVAOname <- genObjectName -- wpVAOname <- genObjectName
-- bindVertexArrayObject $= Just wpVAOname -- bindVertexArrayObject $= Just wpVAOname
wpVAOname <- mglCreateSingle glCreateVertexArrays wpVAOname <- mglCreateSingle glCreateVertexArrays
glBindVertexArray wpVAOname glBindVertexArray wpVAOname
bindBuffer ArrayBuffer $= Just wpVBOname glBindBuffer GL_ARRAY_BUFFER wpVBOname
setupVertexAttribPointer 0 4 8 0 setupVertexAttribPointer 0 4 8 0
--wpColVAOname <- genObjectName --wpColVAOname <- genObjectName
--bindVertexArrayObject $= Just wpColVAOname --bindVertexArrayObject $= Just wpColVAOname
@@ -56,15 +56,15 @@ preloadRender = do
let wpVAO = VAO{_vaoName = wpVAOname, _vaoVBO = wpVBO} let wpVAO = VAO{_vaoName = wpVAOname, _vaoVBO = wpVBO}
wpColVAO = VAO{_vaoName = wpColVAOname, _vaoVBO = wpVBO} wpColVAO = VAO{_vaoName = wpColVAOname, _vaoVBO = wpVBO}
-- setup window points VBO, VAOs and shaders -- setup window points VBO, VAOs and shaders
winVBOname <- genObjectName winVBOname <- mglCreateSingle glCreateBuffers
winVBOptr <- mallocArray (8 * numDrawableWalls) winVBOptr <- mallocArray (8 * numDrawableWalls)
bindBuffer ArrayBuffer $= Just winVBOname glBindBuffer GL_ARRAY_BUFFER winVBOname
bufferData ArrayBuffer bufferData ArrayBuffer
$= ( fromIntegral $ floatSize * numDrawableWalls * 8 $= ( fromIntegral $ floatSize * numDrawableWalls * 8
, nullPtr , nullPtr
, StreamDraw , StreamDraw
) )
let winVBO = VBO{_vbo = winVBOname, _vboPtr = winVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8} let winVBO = VBO{_vboName = winVBOname, _vboPtr = winVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8}
--winColVAOname <- genObjectName --winColVAOname <- genObjectName
--bindVertexArrayObject $= Just winColVAOname --bindVertexArrayObject $= Just winColVAOname
winColVAOname <- mglCreateSingle glCreateVertexArrays winColVAOname <- mglCreateSingle glCreateVertexArrays
@@ -88,20 +88,20 @@ preloadRender = do
nullPtr nullPtr
GL_STREAM_DRAW GL_STREAM_DRAW
let shEBO = EBO{_eboName = shEBOname, _eboPtr = shEBOptr} let shEBO = EBO{_eboName = shEBOname, _eboPtr = shEBOptr}
shVBOname <- genObjectName shVBOname <- mglCreateSingle glCreateBuffers
shVBOptr <- mallocArray (7 * numDrawableElements) shVBOptr <- mallocArray (7 * numDrawableElements)
bindBuffer ArrayBuffer $= Just shVBOname glBindBuffer GL_ARRAY_BUFFER shVBOname
bufferData ArrayBuffer bufferData ArrayBuffer
$= ( fromIntegral $ floatSize * numDrawableElements * 7 $= ( fromIntegral $ floatSize * numDrawableElements * 7
, nullPtr , nullPtr
, StreamDraw , StreamDraw
) )
let shVBO = VBO{_vbo = shVBOname, _vboPtr = shVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8} let shVBO = VBO{_vboName = shVBOname, _vboPtr = shVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8}
--shPosColVAOname <- genObjectName --shPosColVAOname <- genObjectName
--bindVertexArrayObject $= Just shPosColVAOname --bindVertexArrayObject $= Just shPosColVAOname
shPosColVAOname <- mglCreateSingle glCreateVertexArrays shPosColVAOname <- mglCreateSingle glCreateVertexArrays
glBindVertexArray shPosColVAOname glBindVertexArray shPosColVAOname
bindBuffer ArrayBuffer $= Just shVBOname glBindBuffer GL_ARRAY_BUFFER shVBOname
setupVertexAttribPointer 0 3 7 0 setupVertexAttribPointer 0 3 7 0
setupVertexAttribPointer 1 4 7 3 setupVertexAttribPointer 1 4 7 3
--bindBuffer ElementArrayBuffer $= Just shEBOname --bindBuffer ElementArrayBuffer $= Just shEBOname
@@ -110,7 +110,7 @@ preloadRender = do
--bindVertexArrayObject $= Just shPosVAOname --bindVertexArrayObject $= Just shPosVAOname
shPosVAOname <- mglCreateSingle glCreateVertexArrays shPosVAOname <- mglCreateSingle glCreateVertexArrays
glBindVertexArray shPosVAOname glBindVertexArray shPosVAOname
bindBuffer ArrayBuffer $= Just shVBOname glBindBuffer GL_ARRAY_BUFFER shVBOname
setupVertexAttribPointer 0 3 7 0 setupVertexAttribPointer 0 3 7 0
--bindBuffer ElementArrayBuffer $= Just shEBOname --bindBuffer ElementArrayBuffer $= Just shEBOname
glBindBuffer GL_ELEMENT_ARRAY_BUFFER shEBOname glBindBuffer GL_ELEMENT_ARRAY_BUFFER shEBOname
@@ -121,7 +121,7 @@ preloadRender = do
--bindVertexArrayObject $= Just shEdgeVAOname --bindVertexArrayObject $= Just shEdgeVAOname
shEdgeVAOname <- mglCreateSingle glCreateVertexArrays shEdgeVAOname <- mglCreateSingle glCreateVertexArrays
glBindVertexArray shEdgeVAOname glBindVertexArray shEdgeVAOname
bindBuffer ArrayBuffer $= Just shVBOname glBindBuffer GL_ARRAY_BUFFER shVBOname
setupVertexAttribPointer 0 3 7 0 setupVertexAttribPointer 0 3 7 0
--setup ebo for silhouette edges --setup ebo for silhouette edges
silEBOname <- mglCreateSingle glCreateBuffers silEBOname <- mglCreateSingle glCreateBuffers
+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 qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import Control.Monad.Primitive import Control.Monad.Primitive
import Control.Monad import Control.Monad
import Graphics.GL.Core45
bindArrayBuffers :: Int -> VBO -> IO () bindArrayBuffers :: Int -> VBO -> IO ()
{-# INLINABLE bindArrayBuffers #-} {-# INLINABLE bindArrayBuffers #-}
bindArrayBuffers numVs theVBO = do bindArrayBuffers numVs theVBO = do
bindBuffer ArrayBuffer $= Just (_vbo theVBO) glBindBuffer GL_ARRAY_BUFFER (_vboName theVBO)
bufferSubData bufferSubData
ArrayBuffer ArrayBuffer
WriteToBuffer WriteToBuffer
@@ -32,7 +33,7 @@ bindShaderLayers shads counts = MV.imapM_ f shads
f i shad = do f i shad = do
let theVBO = _vaoVBO $ _shadVAO' shad let theVBO = _vaoVBO $ _shadVAO' shad
stride = sum $ _vboAttribSizes theVBO 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] VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5]
--S.mapM_ (g stride theVBO) $ S.each [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 :: Int -> [Int] -> IO VBO
setupVBOSized ndraw sizes = do setupVBOSized ndraw sizes = do
vboName <- genObjectName --vboName <- genObjectName
bindBuffer ArrayBuffer $= Just vboName --bindBuffer ArrayBuffer $= Just vboName
vboname <- mglCreateSingle glCreateBuffers
glBindBuffer GL_ARRAY_BUFFER vboname
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
setupVertexAttribPointer loc siz strd off setupVertexAttribPointer loc siz strd off
thePtr <- mallocArray (strd * ndraw) thePtr <- mallocArray (strd * ndraw)
@@ -154,7 +156,7 @@ setupVBOSized ndraw sizes = do
) )
return $ return $
VBO VBO
{ _vbo = vboName { _vboName = vboname
, _vboPtr = thePtr , _vboPtr = thePtr
, _vboAttribSizes = sizes , _vboAttribSizes = sizes
, _vboStride = sum sizes , _vboStride = sum sizes
+2 -2
View File
@@ -12,7 +12,7 @@ module Shader.Data
-- | Lens functions -- | Lens functions
, vaoName , vaoName
, vaoVBO , vaoVBO
, vbo , vboName
, vboPtr , vboPtr
, vboAttribSizes , vboAttribSizes
, vboStride , 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. and a list of attribute pointer sizes.
Vertex attributes are interleaved within the vbo. -} Vertex attributes are interleaved within the vbo. -}
data VBO = VBO data VBO = VBO
{ _vbo :: BufferObject { _vboName :: GLuint
, _vboPtr :: Ptr Float , _vboPtr :: Ptr Float
, _vboAttribSizes :: [Int] -- ^ It is not clear to me if this is necessary to store or not , _vboAttribSizes :: [Int] -- ^ It is not clear to me if this is necessary to store or not
, _vboStride :: Int , _vboStride :: Int