Work on VertexAttribute usage
This commit is contained in:
@@ -69,7 +69,7 @@ preloadRender = do
|
|||||||
-- setup shape geometry/cap VBO and two VAOs
|
-- setup shape geometry/cap VBO and two VAOs
|
||||||
putStrLn "Setup shape VBO, VAO, EBO"
|
putStrLn "Setup shape VBO, VAO, EBO"
|
||||||
shVBO <- setupVBO nShapeVerxComp
|
shVBO <- setupVBO nShapeVerxComp
|
||||||
shPosVAO <- setupVAOUsingVBO [4] shVBO
|
shPosVAO <- setupVAOUsingVBO [VertexAttribute 4 GL_FLOAT GL_FALSE 0] shVBO
|
||||||
shEBO <- setupEBO shPosVAO
|
shEBO <- setupEBO shPosVAO
|
||||||
-- note the shape shader vao is distinct from the position vao, but they
|
-- note the shape shader vao is distinct from the position vao, but they
|
||||||
-- share an EBO
|
-- share an EBO
|
||||||
@@ -78,7 +78,7 @@ preloadRender = do
|
|||||||
|
|
||||||
--setup silhouette edge VAO
|
--setup silhouette edge VAO
|
||||||
putStrLn "Setup silhouette VAO, EBO"
|
putStrLn "Setup silhouette VAO, EBO"
|
||||||
shedgevao <- setupVAOUsingVBO [4] shVBO
|
shedgevao <- setupVAOUsingVBO [VertexAttribute 4 GL_FLOAT GL_FALSE 0] shVBO
|
||||||
shedgeebo <- setupEBO shedgevao
|
shedgeebo <- setupEBO shedgevao
|
||||||
|
|
||||||
putStrLn "Setup wall/windows VBO, VAO, EBO, shader"
|
putStrLn "Setup wall/windows VBO, VAO, EBO, shader"
|
||||||
|
|||||||
+10
-29
@@ -83,7 +83,7 @@ makeShaderUsingVBO ::
|
|||||||
VBO ->
|
VBO ->
|
||||||
IO Shader
|
IO Shader
|
||||||
makeShaderUsingVBO s shaderlist sizes pm vbo = do
|
makeShaderUsingVBO s shaderlist sizes pm vbo = do
|
||||||
vao <- setupVAOUsingVBO sizes vbo
|
vao <- setupVAOUsingVBO (toFloatVAs sizes) vbo
|
||||||
makeShaderUsingVAO s shaderlist pm vao
|
makeShaderUsingVAO s shaderlist pm vao
|
||||||
|
|
||||||
setupVBO :: Int -> IO VBO
|
setupVBO :: Int -> IO VBO
|
||||||
@@ -196,20 +196,19 @@ setupVAOvbo' :: [Int] -> Int -> GLuint -> IO VAO
|
|||||||
setupVAOvbo' sizes strd vbo = do
|
setupVAOvbo' sizes strd vbo = do
|
||||||
vaoname <- mglCreate glCreateVertexArrays
|
vaoname <- mglCreate glCreateVertexArrays
|
||||||
glBindVertexArray vaoname
|
glBindVertexArray vaoname
|
||||||
setupVertexAttribs' vbo vaoname sizes strd
|
setupVertexAttribs vbo vaoname (toFloatVAs sizes) (fromIntegral strd * fromIntegral floatSize)
|
||||||
return $
|
return $
|
||||||
VAO
|
VAO
|
||||||
{ _vaoName = vaoname
|
{ _vaoName = vaoname
|
||||||
}
|
}
|
||||||
|
|
||||||
setupVAOUsingVBO :: [Int] -> VBO -> IO VAO
|
setupVAOUsingVBO :: [VertexAttribute] -> VBO -> IO VAO
|
||||||
setupVAOUsingVBO sizes vbo = do
|
setupVAOUsingVBO vas vbo = do
|
||||||
let strd = vbo ^. vboVertexSize
|
let strd = vbo ^. vboVertexSize
|
||||||
when (strd < sum sizes) $
|
|
||||||
error "Tried to assign vertex attributes to VBO with too small a stride."
|
|
||||||
vaoname <- mglCreate glCreateVertexArrays
|
vaoname <- mglCreate glCreateVertexArrays
|
||||||
glBindVertexArray vaoname
|
glBindVertexArray vaoname
|
||||||
setupVertexAttribs vbo vaoname sizes strd
|
setupVertexAttribs (vbo ^. vboName) vaoname vas
|
||||||
|
(fromIntegral strd * fromIntegral floatSize)
|
||||||
return VAO{_vaoName = vaoname}
|
return VAO{_vaoName = vaoname}
|
||||||
|
|
||||||
setupEBO :: VAO -> IO EBO
|
setupEBO :: VAO -> IO EBO
|
||||||
@@ -245,13 +244,9 @@ toFloatVAs = go 0
|
|||||||
|
|
||||||
setupVBOSized :: Int -> GLuint -> [Int] -> IO VBO
|
setupVBOSized :: Int -> GLuint -> [Int] -> IO VBO
|
||||||
setupVBOSized ndraw vao sizes = do
|
setupVBOSized ndraw vao sizes = do
|
||||||
--vboName <- genObjectName
|
|
||||||
--bindBuffer ArrayBuffer $= Just vboName
|
|
||||||
vboname <- mglCreate glCreateBuffers
|
vboname <- mglCreate glCreateBuffers
|
||||||
glVertexArrayVertexBuffer vao 0 vboname 0 (fromIntegral $ floatSize * strd)
|
glVertexArrayVertexBuffer vao 0 vboname 0 (fromIntegral $ floatSize * strd)
|
||||||
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
|
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
|
||||||
-- forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
|
|
||||||
-- setupVertexAttribPointer vao loc siz off
|
|
||||||
thePtr <- mallocArray (strd * ndraw)
|
thePtr <- mallocArray (strd * ndraw)
|
||||||
-- Allocate space
|
-- Allocate space
|
||||||
glNamedBufferData
|
glNamedBufferData
|
||||||
@@ -267,25 +262,11 @@ setupVBOSized ndraw vao sizes = do
|
|||||||
}
|
}
|
||||||
where
|
where
|
||||||
strd = sum sizes
|
strd = sum sizes
|
||||||
offs = scanl (+) 0 sizes
|
|
||||||
|
|
||||||
setupVertexAttribs :: VBO -> GLuint -> [Int] -> Int -> IO ()
|
setupVertexAttribs :: GLuint -> GLuint -> [VertexAttribute] -> GLsizei -> IO ()
|
||||||
setupVertexAttribs vbo vao sizes strd = do
|
setupVertexAttribs vbo vao vas strd = do
|
||||||
glVertexArrayVertexBuffer vao 0 (_vboName vbo) 0 (fromIntegral $ floatSize * strd)
|
glVertexArrayVertexBuffer vao 0 vbo 0 strd
|
||||||
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
|
zipWithM_ (setupVertexAttribPointer vao) [0..] vas
|
||||||
--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
|
|
||||||
|
|
||||||
-- | Assumes the correct VBO is bound
|
-- | Assumes the correct VBO is bound
|
||||||
setupVertexAttribPointer ::
|
setupVertexAttribPointer ::
|
||||||
|
|||||||
Reference in New Issue
Block a user