Change VBO to store vertex size in bytes
This commit is contained in:
+2
-2
@@ -21,7 +21,7 @@ bufferPokedVBO theVBO numVs =
|
||||
glNamedBufferSubData
|
||||
(_vboName theVBO)
|
||||
0
|
||||
(fromIntegral $ floatSize * numVs * _vboVertexSize theVBO)
|
||||
(fromIntegral $ numVs * _vboVertexBytes theVBO)
|
||||
(_vboPtr theVBO)
|
||||
|
||||
bufferEBO :: EBO -> Int -> IO ()
|
||||
@@ -37,7 +37,7 @@ bufferShaderLayers shads counts = MV.imapM_ f shads
|
||||
where
|
||||
f i shad = do
|
||||
let theVBO = snd shad
|
||||
stride = _vboVertexSize theVBO
|
||||
stride = _vboVertexBytes theVBO `div` floatSize
|
||||
VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5]
|
||||
where
|
||||
g stride theVBO lay = do
|
||||
|
||||
+27
-5
@@ -97,7 +97,25 @@ setupVBO vertexsize = do
|
||||
(fromIntegral $ floatSize * numDrawableElements * vertexsize)
|
||||
nullPtr
|
||||
GL_STREAM_DRAW
|
||||
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexSize = vertexsize}
|
||||
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 =
|
||||
|
||||
|
||||
|
||||
setupVBOStatic :: Int -> IO VBO
|
||||
setupVBOStatic vertexsize = do
|
||||
@@ -109,7 +127,7 @@ setupVBOStatic vertexsize = do
|
||||
(fromIntegral $ floatSize * numDrawableElements * vertexsize)
|
||||
nullPtr
|
||||
GL_STATIC_DRAW
|
||||
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexSize = vertexsize}
|
||||
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexBytes = floatSize * vertexsize}
|
||||
|
||||
makeByteStringShaderUsingVAO ::
|
||||
-- | (Arbitrary) name of the shader
|
||||
@@ -203,11 +221,11 @@ setupVAOvbo sizes strd vbo = do
|
||||
|
||||
setupVAOUsingVBO :: [VertexAttribute] -> VBO -> IO VAO
|
||||
setupVAOUsingVBO vas vbo = do
|
||||
let strd = vbo ^. vboVertexSize
|
||||
let strd = vbo ^. vboVertexBytes
|
||||
vaoname <- mglCreate glCreateVertexArrays
|
||||
glBindVertexArray vaoname
|
||||
setupVertexAttribs (vbo ^. vboName) vaoname vas
|
||||
(fromIntegral strd * fromIntegral floatSize)
|
||||
(fromIntegral strd)
|
||||
return VAO{_vaoName = vaoname}
|
||||
|
||||
setupEBO :: VAO -> IO EBO
|
||||
@@ -227,8 +245,12 @@ setupVBOVAO sizes = do
|
||||
vaoname <- mglCreate glCreateVertexArrays
|
||||
glBindVertexArray vaoname
|
||||
vbo <- setupVBO (sum sizes)
|
||||
vao <- setupVAOvbo (toFloatVAs sizes) (sum sizes) (vbo ^. vboName)
|
||||
--vao <- setupVAOvbo (toFloatVAs sizes) (sum sizes) (vbo ^. vboName)
|
||||
vao <- setupVAOUsingVBO (toFloatVAs sizes) vbo
|
||||
return (vao,vbo)
|
||||
where
|
||||
vas = toFloatVAs sizes
|
||||
strd = vasTightStride vas
|
||||
|
||||
toFloatVAs :: [Int] -> [VertexAttribute]
|
||||
toFloatVAs = go 0
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ Vertex attributes are interleaved within the vbo.
|
||||
data VBO = VBO
|
||||
{ _vboName :: GLuint
|
||||
, _vboPtr :: Ptr Float
|
||||
, _vboVertexSize :: Int
|
||||
, _vboVertexBytes :: Int
|
||||
-- add int for AMOUNT of data poked!
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user