Broken binding of central picture in one pass

This commit is contained in:
jgk
2021-07-26 00:53:35 +02:00
parent 4f44b748bf
commit 5dfebd221d
9 changed files with 165 additions and 17 deletions
+55
View File
@@ -1,5 +1,6 @@
module Shader.Compile
( makeShader
, makeShaderSized
, makeShaderUsingShaderVAO
, makeSourcedShader
, setupVAO
@@ -52,6 +53,29 @@ makeShader s shaderlist sizes pm renStrat = do
, _shaderTexture = Nothing
, _shaderCustomUnis = []
}
{- |
Compiles a full shader found within the shader directory.
The shader is made up of files begining with the inputted string with extensions .vert, .geom etc.
-}
makeShaderSized
:: String -- ^ First part of the name of the shader
-> [ShaderType] -- ^ Filetype extensions
-> [Int] -- ^ The input vertex sizes
-> Int -- ^ Number of vertexes that can be poked
-> EPrimitiveMode
-> (RenderType -> [[Float]]) -- ^ Poke strategy: method for creating a list of vertex data to be bound
-> IO FullShader
makeShaderSized s shaderlist sizes ndraw pm renStrat = do
prog <- makeSourcedShader s shaderlist
vaob <- setupVAOSized sizes ndraw
return $ FullShader
{ _shaderProgram = prog
, _shaderVAO = vaob
, _shaderPokeStrategy = renStrat
, _shaderDrawPrimitive = pm
, _shaderTexture = Nothing
, _shaderCustomUnis = []
}
-- | Compile shader and get its uniform locations.
-- supposes the shader code is in the shader folder, with the string names
@@ -76,6 +100,15 @@ setupVAO sizes = do
{ _vao = theVAO
, _vaoVBO = theVBO
}
setupVAOSized :: [Int] -> Int -> IO VAO
setupVAOSized sizes ndraw = do
theVAO <- genObjectName
bindVertexArrayObject $= Just theVAO
theVBO <- setupVBOSized sizes ndraw
return $ VAO
{ _vao = theVAO
, _vaoVBO = theVBO
}
setupVBO :: [Int] -> IO VBO
setupVBO sizes = do
@@ -98,6 +131,28 @@ setupVBO sizes = do
where
strd = sum sizes
offs = scanl (+) 0 sizes
setupVBOSized :: [Int] -> Int -> IO VBO
setupVBOSized sizes ndraw = do
vboName <- genObjectName
bindBuffer ArrayBuffer $= Just vboName
forM_ (zip3 [0..] sizes offs) $ \(loc,siz,off) -> do
setupVertexAttribPointer loc siz strd off
thePtr <- mallocArray (strd * ndraw)
-- Allocate space
bufferData ArrayBuffer $=
(fromIntegral $ floatSize * ndraw * strd
, nullPtr
, DynamicDraw
)
return $ VBO
{ _vbo = vboName
, _vboPointer = thePtr
, _vboAttribSizes = sizes
}
where
strd = sum sizes
offs = scanl (+) 0 sizes
{- | Assumes the correct VBO is bound -}
setupVertexAttribPointer