Work on VertexAttribute usage

This commit is contained in:
2023-04-12 18:42:31 +01:00
parent bea970bcd2
commit 2494f2cf8d
2 changed files with 12 additions and 31 deletions
+10 -29
View File
@@ -83,7 +83,7 @@ makeShaderUsingVBO ::
VBO ->
IO Shader
makeShaderUsingVBO s shaderlist sizes pm vbo = do
vao <- setupVAOUsingVBO sizes vbo
vao <- setupVAOUsingVBO (toFloatVAs sizes) vbo
makeShaderUsingVAO s shaderlist pm vao
setupVBO :: Int -> IO VBO
@@ -196,20 +196,19 @@ setupVAOvbo' :: [Int] -> Int -> GLuint -> IO VAO
setupVAOvbo' sizes strd vbo = do
vaoname <- mglCreate glCreateVertexArrays
glBindVertexArray vaoname
setupVertexAttribs' vbo vaoname sizes strd
setupVertexAttribs vbo vaoname (toFloatVAs sizes) (fromIntegral strd * fromIntegral floatSize)
return $
VAO
{ _vaoName = vaoname
}
setupVAOUsingVBO :: [Int] -> VBO -> IO VAO
setupVAOUsingVBO sizes vbo = do
setupVAOUsingVBO :: [VertexAttribute] -> VBO -> IO VAO
setupVAOUsingVBO vas vbo = do
let strd = vbo ^. vboVertexSize
when (strd < sum sizes) $
error "Tried to assign vertex attributes to VBO with too small a stride."
vaoname <- mglCreate glCreateVertexArrays
glBindVertexArray vaoname
setupVertexAttribs vbo vaoname sizes strd
setupVertexAttribs (vbo ^. vboName) vaoname vas
(fromIntegral strd * fromIntegral floatSize)
return VAO{_vaoName = vaoname}
setupEBO :: VAO -> IO EBO
@@ -245,13 +244,9 @@ toFloatVAs = go 0
setupVBOSized :: Int -> GLuint -> [Int] -> IO VBO
setupVBOSized ndraw vao sizes = do
--vboName <- genObjectName
--bindBuffer ArrayBuffer $= Just vboName
vboname <- mglCreate glCreateBuffers
glVertexArrayVertexBuffer vao 0 vboname 0 (fromIntegral $ floatSize * strd)
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
-- forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
-- setupVertexAttribPointer vao loc siz off
thePtr <- mallocArray (strd * ndraw)
-- Allocate space
glNamedBufferData
@@ -267,25 +262,11 @@ setupVBOSized ndraw vao sizes = do
}
where
strd = sum sizes
offs = scanl (+) 0 sizes
setupVertexAttribs :: VBO -> GLuint -> [Int] -> Int -> IO ()
setupVertexAttribs vbo vao sizes strd = do
glVertexArrayVertexBuffer vao 0 (_vboName vbo) 0 (fromIntegral $ floatSize * strd)
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
--forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
-- setupVertexAttribPointer vao loc siz off
where
offs = scanl (+) 0 sizes
setupVertexAttribs' :: GLuint -> GLuint -> [Int] -> Int -> IO ()
setupVertexAttribs' vbo vao sizes strd = do
glVertexArrayVertexBuffer vao 0 vbo 0 (fromIntegral $ floatSize * strd)
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
--forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
-- setupVertexAttribPointer vao loc siz off
where
offs = scanl (+) 0 sizes
setupVertexAttribs :: GLuint -> GLuint -> [VertexAttribute] -> GLsizei -> IO ()
setupVertexAttribs vbo vao vas strd = do
glVertexArrayVertexBuffer vao 0 vbo 0 strd
zipWithM_ (setupVertexAttribPointer vao) [0..] vas
-- | Assumes the correct VBO is bound
setupVertexAttribPointer ::