Move towards generalised vertex attributes
This commit is contained in:
+24
-14
@@ -236,14 +236,22 @@ setupVAOSized ndraw sizes = do
|
|||||||
, theVBO
|
, theVBO
|
||||||
)
|
)
|
||||||
|
|
||||||
|
toFloatVAs :: [Int] -> [VertexAttribute]
|
||||||
|
toFloatVAs = go 0
|
||||||
|
where
|
||||||
|
go _ [] = []
|
||||||
|
go x (i:is) = VertexAttribute (fromIntegral i) GL_FLOAT GL_FALSE x
|
||||||
|
: go (x + fromIntegral floatSize*fromIntegral i) is
|
||||||
|
|
||||||
setupVBOSized :: Int -> GLuint -> [Int] -> IO VBO
|
setupVBOSized :: Int -> GLuint -> [Int] -> IO VBO
|
||||||
setupVBOSized ndraw vao sizes = do
|
setupVBOSized ndraw vao sizes = do
|
||||||
--vboName <- genObjectName
|
--vboName <- genObjectName
|
||||||
--bindBuffer ArrayBuffer $= Just vboName
|
--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)
|
||||||
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
|
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
|
||||||
setupVertexAttribPointer vao loc siz off
|
-- 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
|
||||||
@@ -264,36 +272,38 @@ setupVBOSized ndraw vao sizes = do
|
|||||||
setupVertexAttribs :: VBO -> GLuint -> [Int] -> Int -> IO ()
|
setupVertexAttribs :: VBO -> GLuint -> [Int] -> Int -> IO ()
|
||||||
setupVertexAttribs vbo vao sizes strd = do
|
setupVertexAttribs vbo vao sizes strd = do
|
||||||
glVertexArrayVertexBuffer vao 0 (_vboName vbo) 0 (fromIntegral $ floatSize * strd)
|
glVertexArrayVertexBuffer vao 0 (_vboName vbo) 0 (fromIntegral $ floatSize * strd)
|
||||||
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
|
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
|
||||||
setupVertexAttribPointer vao loc siz off
|
--forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
|
||||||
|
-- setupVertexAttribPointer vao loc siz off
|
||||||
where
|
where
|
||||||
offs = scanl (+) 0 sizes
|
offs = scanl (+) 0 sizes
|
||||||
|
|
||||||
setupVertexAttribs' :: GLuint -> GLuint -> [Int] -> Int -> IO ()
|
setupVertexAttribs' :: GLuint -> GLuint -> [Int] -> Int -> IO ()
|
||||||
setupVertexAttribs' vbo vao sizes strd = do
|
setupVertexAttribs' vbo vao sizes strd = do
|
||||||
glVertexArrayVertexBuffer vao 0 vbo 0 (fromIntegral $ floatSize * strd)
|
glVertexArrayVertexBuffer vao 0 vbo 0 (fromIntegral $ floatSize * strd)
|
||||||
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
|
zipWithM_ (setupVertexAttribPointer vao) [0..] $ toFloatVAs sizes
|
||||||
setupVertexAttribPointer vao loc siz off
|
--forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
|
||||||
|
-- setupVertexAttribPointer vao loc siz off
|
||||||
where
|
where
|
||||||
offs = scanl (+) 0 sizes
|
offs = scanl (+) 0 sizes
|
||||||
|
|
||||||
-- | Assumes the correct VBO is bound
|
-- | Assumes the correct VBO is bound
|
||||||
setupVertexAttribPointer ::
|
setupVertexAttribPointer ::
|
||||||
GLuint ->
|
GLuint ->
|
||||||
-- | vao name
|
-- | Location (in shader)
|
||||||
Int ->
|
|
||||||
-- | Size
|
|
||||||
Int ->
|
|
||||||
-- | Offset
|
|
||||||
Int ->
|
Int ->
|
||||||
|
VertexAttribute ->
|
||||||
IO ()
|
IO ()
|
||||||
setupVertexAttribPointer vao loc siz off = do
|
setupVertexAttribPointer vao loc va = do
|
||||||
glEnableVertexArrayAttrib vao loc'
|
glEnableVertexArrayAttrib vao loc'
|
||||||
glVertexArrayAttribFormat vao loc' siz' GL_FLOAT GL_FALSE (fromIntegral $ floatSize * off)
|
glVertexArrayAttribFormat vao loc'
|
||||||
|
(va ^. vaNumberElements)
|
||||||
|
(va ^. vaElementType)
|
||||||
|
(va ^. vaToNormalize)
|
||||||
|
(va ^. vaOffset)
|
||||||
glVertexArrayAttribBinding vao loc' 0
|
glVertexArrayAttribBinding vao loc' 0
|
||||||
where
|
where
|
||||||
loc' = fromIntegral loc
|
loc' = fromIntegral loc
|
||||||
siz' = fromIntegral siz
|
|
||||||
|
|
||||||
makeShaderProgram ::
|
makeShaderProgram ::
|
||||||
String ->
|
String ->
|
||||||
|
|||||||
Reference in New Issue
Block a user