Work on VertexAttribute usage
This commit is contained in:
@@ -69,7 +69,7 @@ preloadRender = do
|
||||
-- setup shape geometry/cap VBO and two VAOs
|
||||
putStrLn "Setup shape VBO, VAO, EBO"
|
||||
shVBO <- setupVBO nShapeVerxComp
|
||||
shPosVAO <- setupVAOUsingVBO [4] shVBO
|
||||
shPosVAO <- setupVAOUsingVBO [VertexAttribute 4 GL_FLOAT GL_FALSE 0] shVBO
|
||||
shEBO <- setupEBO shPosVAO
|
||||
-- note the shape shader vao is distinct from the position vao, but they
|
||||
-- share an EBO
|
||||
@@ -78,7 +78,7 @@ preloadRender = do
|
||||
|
||||
--setup silhouette edge VAO
|
||||
putStrLn "Setup silhouette VAO, EBO"
|
||||
shedgevao <- setupVAOUsingVBO [4] shVBO
|
||||
shedgevao <- setupVAOUsingVBO [VertexAttribute 4 GL_FLOAT GL_FALSE 0] shVBO
|
||||
shedgeebo <- setupEBO shedgevao
|
||||
|
||||
putStrLn "Setup wall/windows VBO, VAO, EBO, shader"
|
||||
|
||||
+10
-29
@@ -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 ::
|
||||
|
||||
Reference in New Issue
Block a user