Implement static VBO/VAO

This commit is contained in:
2023-04-13 00:03:15 +01:00
parent 9bb1a22ea5
commit 36734c7af5
2 changed files with 29 additions and 23 deletions
+20 -15
View File
@@ -13,8 +13,10 @@ module Shader.Compile (
setupVertexAttribPointer,
makeSourcedShader,
toFloatVAs,
setupStaticVBO
) where
import Foreign.C.Types
import Graphics.GL.Types
import Control.Lens
import Control.Monad
@@ -99,21 +101,24 @@ setupVBO vertexsize = do
GL_STREAM_DRAW
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexBytes = floatSize * vertexsize}
---- the input ptr is assumed to contain the correct amount of data according to
---- the specified number and type of vertices
---- note the VBO here does not have a sensible ptr value
--setupStaticVBO :: Int -> [VertexAttribute] -> Ptr a -> IO (VBO,VAO)
--setupStaticVBO numvs vas vdata = do
-- vboname <- mglCreate glCreateBuffers
-- glNamedBufferStorage
-- vboname
-- (CPtrdiff (fromIntegral (vasTightStride vas)))
-- vdata
-- 0
-- let vbo = VBO
-- { _vboName = vboname
-- , _vboPtr = nullPtr
-- , _vboVertexSize =
-- the input ptr is assumed to contain the correct amount of data according to
-- the specified number and type of vertices
-- note the VBO here does not have a sensible ptr value
setupStaticVBO :: Storable a => [VertexAttribute] -> [a] -> IO (VBO,VAO)
setupStaticVBO vas vdata = withArrayLen vdata $ \i ptr -> do
vboname <- mglCreate glCreateBuffers
glNamedBufferStorage
vboname
(CPtrdiff (fromIntegral (i * sizeOf (head vdata))))
ptr
0
let vbo = VBO
{ _vboName = vboname
, _vboPtr = nullPtr
, _vboVertexBytes = vasTightStride vas
}
vao <- setupVAOUsingVBO vas vbo
return (vbo,vao)