Change VBO to store vertex size in bytes

This commit is contained in:
2023-04-12 23:47:52 +01:00
parent 589f663b65
commit 9bb1a22ea5
3 changed files with 30 additions and 8 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ bufferPokedVBO theVBO numVs =
glNamedBufferSubData glNamedBufferSubData
(_vboName theVBO) (_vboName theVBO)
0 0
(fromIntegral $ floatSize * numVs * _vboVertexSize theVBO) (fromIntegral $ numVs * _vboVertexBytes theVBO)
(_vboPtr theVBO) (_vboPtr theVBO)
bufferEBO :: EBO -> Int -> IO () bufferEBO :: EBO -> Int -> IO ()
@@ -37,7 +37,7 @@ bufferShaderLayers shads counts = MV.imapM_ f shads
where where
f i shad = do f i shad = do
let theVBO = snd shad let theVBO = snd shad
stride = _vboVertexSize theVBO stride = _vboVertexBytes theVBO `div` floatSize
VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5] VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5]
where where
g stride theVBO lay = do g stride theVBO lay = do
+27 -5
View File
@@ -97,7 +97,25 @@ setupVBO vertexsize = do
(fromIntegral $ floatSize * numDrawableElements * vertexsize) (fromIntegral $ floatSize * numDrawableElements * vertexsize)
nullPtr nullPtr
GL_STREAM_DRAW GL_STREAM_DRAW
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexSize = vertexsize} return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexBytes = floatSize * vertexsize}
---- the input ptr is assumed to contain the correct amount of data according to
---- the specified number and type of vertices
---- note the VBO here does not have a sensible ptr value
--setupStaticVBO :: Int -> [VertexAttribute] -> Ptr a -> IO (VBO,VAO)
--setupStaticVBO numvs vas vdata = do
-- vboname <- mglCreate glCreateBuffers
-- glNamedBufferStorage
-- vboname
-- (CPtrdiff (fromIntegral (vasTightStride vas)))
-- vdata
-- 0
-- let vbo = VBO
-- { _vboName = vboname
-- , _vboPtr = nullPtr
-- , _vboVertexSize =
setupVBOStatic :: Int -> IO VBO setupVBOStatic :: Int -> IO VBO
setupVBOStatic vertexsize = do setupVBOStatic vertexsize = do
@@ -109,7 +127,7 @@ setupVBOStatic vertexsize = do
(fromIntegral $ floatSize * numDrawableElements * vertexsize) (fromIntegral $ floatSize * numDrawableElements * vertexsize)
nullPtr nullPtr
GL_STATIC_DRAW GL_STATIC_DRAW
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexSize = vertexsize} return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexBytes = floatSize * vertexsize}
makeByteStringShaderUsingVAO :: makeByteStringShaderUsingVAO ::
-- | (Arbitrary) name of the shader -- | (Arbitrary) name of the shader
@@ -203,11 +221,11 @@ setupVAOvbo sizes strd vbo = do
setupVAOUsingVBO :: [VertexAttribute] -> VBO -> IO VAO setupVAOUsingVBO :: [VertexAttribute] -> VBO -> IO VAO
setupVAOUsingVBO vas vbo = do setupVAOUsingVBO vas vbo = do
let strd = vbo ^. vboVertexSize let strd = vbo ^. vboVertexBytes
vaoname <- mglCreate glCreateVertexArrays vaoname <- mglCreate glCreateVertexArrays
glBindVertexArray vaoname glBindVertexArray vaoname
setupVertexAttribs (vbo ^. vboName) vaoname vas setupVertexAttribs (vbo ^. vboName) vaoname vas
(fromIntegral strd * fromIntegral floatSize) (fromIntegral strd)
return VAO{_vaoName = vaoname} return VAO{_vaoName = vaoname}
setupEBO :: VAO -> IO EBO setupEBO :: VAO -> IO EBO
@@ -227,8 +245,12 @@ setupVBOVAO sizes = do
vaoname <- mglCreate glCreateVertexArrays vaoname <- mglCreate glCreateVertexArrays
glBindVertexArray vaoname glBindVertexArray vaoname
vbo <- setupVBO (sum sizes) vbo <- setupVBO (sum sizes)
vao <- setupVAOvbo (toFloatVAs sizes) (sum sizes) (vbo ^. vboName) --vao <- setupVAOvbo (toFloatVAs sizes) (sum sizes) (vbo ^. vboName)
vao <- setupVAOUsingVBO (toFloatVAs sizes) vbo
return (vao,vbo) return (vao,vbo)
where
vas = toFloatVAs sizes
strd = vasTightStride vas
toFloatVAs :: [Int] -> [VertexAttribute] toFloatVAs :: [Int] -> [VertexAttribute]
toFloatVAs = go 0 toFloatVAs = go 0
+1 -1
View File
@@ -81,7 +81,7 @@ Vertex attributes are interleaved within the vbo.
data VBO = VBO data VBO = VBO
{ _vboName :: GLuint { _vboName :: GLuint
, _vboPtr :: Ptr Float , _vboPtr :: Ptr Float
, _vboVertexSize :: Int , _vboVertexBytes :: Int
-- add int for AMOUNT of data poked! -- add int for AMOUNT of data poked!
} }