diff --git a/src/Shader/Compile.hs b/src/Shader/Compile.hs index b7eb55d60..23127ac77 100644 --- a/src/Shader/Compile.hs +++ b/src/Shader/Compile.hs @@ -236,14 +236,22 @@ setupVAOSized ndraw sizes = do , 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 ndraw vao sizes = do --vboName <- genObjectName --bindBuffer ArrayBuffer $= Just vboName vboname <- mglCreate glCreateBuffers glVertexArrayVertexBuffer vao 0 vboname 0 (fromIntegral $ floatSize * strd) - forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do - setupVertexAttribPointer vao loc siz off + 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 @@ -264,36 +272,38 @@ setupVBOSized ndraw vao sizes = do setupVertexAttribs :: VBO -> GLuint -> [Int] -> Int -> IO () setupVertexAttribs vbo vao sizes strd = do glVertexArrayVertexBuffer vao 0 (_vboName vbo) 0 (fromIntegral $ floatSize * strd) - forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do - setupVertexAttribPointer vao loc siz off + 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) - forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do - setupVertexAttribPointer vao loc siz off + 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 setupVertexAttribPointer :: GLuint -> - -- | vao name - Int -> - -- | Size - Int -> - -- | Offset + -- | Location (in shader) Int -> + VertexAttribute -> IO () -setupVertexAttribPointer vao loc siz off = do +setupVertexAttribPointer vao loc va = do 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 where loc' = fromIntegral loc - siz' = fromIntegral siz makeShaderProgram :: String ->