Attach EBOs to VAOs using DSA

This commit is contained in:
2023-03-09 13:55:52 +00:00
parent f14d9bef60
commit 3e2b51b5e9
3 changed files with 101 additions and 93 deletions
+20 -12
View File
@@ -14,7 +14,13 @@ import Foreign
import Foreign.C.String
import GLHelp
import Graphics.GL.Core45
import Graphics.Rendering.OpenGL hiding (Point, imageHeight, scale, translate)
import Graphics.Rendering.OpenGL (vertexAttribPointer, AttribLocation (..), ($=)
, IntegerHandling (..)
, VertexArrayDescriptor (..)
, DataType (..)
, vertexAttribArray
, Capability (..)
)
import Shader.Data
import Shader.Parameters
@@ -132,28 +138,27 @@ setupVAOSized :: Int -> [Int] -> IO VAO
setupVAOSized ndraw sizes = do
vaoname <- mglCreateSingle glCreateVertexArrays
glBindVertexArray vaoname
theVBO <- setupVBOSized ndraw sizes
theVBO <- setupVBOSized ndraw vaoname sizes
return $
VAO
{ _vaoName = vaoname
, _vaoVBO = theVBO
}
setupVBOSized :: Int -> [Int] -> IO VBO
setupVBOSized ndraw sizes = do
setupVBOSized :: Int -> GLuint -> [Int] -> IO VBO
setupVBOSized ndraw vao sizes = do
--vboName <- genObjectName
--bindBuffer ArrayBuffer $= Just vboName
vboname <- mglCreateSingle glCreateBuffers
glBindBuffer GL_ARRAY_BUFFER vboname
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
setupVertexAttribPointer loc siz strd off
setupVertexAttribPointer vao vboname loc siz strd off
thePtr <- mallocArray (strd * ndraw)
-- Allocate space
bufferData ArrayBuffer
$= ( fromIntegral $ floatSize * ndraw * strd
, nullPtr
, StreamDraw
)
glNamedBufferData vboname
( fromIntegral $ floatSize * ndraw * strd)
nullPtr
GL_STREAM_DRAW
return $
VBO
{ _vboName = vboname
@@ -167,7 +172,10 @@ setupVBOSized ndraw sizes = do
-- | Assumes the correct VBO is bound
setupVertexAttribPointer ::
-- | Atrib location
GLuint ->
-- | vao name
GLuint ->
-- | vbo name
Int ->
-- | Size
Int ->
@@ -176,7 +184,7 @@ setupVertexAttribPointer ::
-- | Offset
Int ->
IO ()
setupVertexAttribPointer loc siz strd off = do
setupVertexAttribPointer vao vbo loc siz strd off = do
vertexAttribPointer (AttribLocation (fi loc))
$= (ToFloat, VertexArrayDescriptor (fi' siz) Float (fi'' $ floatSize * strd) (bufferOffset off))
vertexAttribArray (AttribLocation (fi loc)) $= Enabled