Cleanup shader code

This commit is contained in:
2023-03-14 22:05:17 +00:00
parent b7d7bc2346
commit db0d24d044
4 changed files with 29 additions and 27 deletions
+12 -16
View File
@@ -1,7 +1,7 @@
module Shader.Compile (
trueSetupVBO,
setupVBO4,
makeShader,
makeShader',
makeShader4,
makeByteStringShaderUsingVAO,
makeShaderSized,
makeShaderUsingVAO,
@@ -9,6 +9,7 @@ module Shader.Compile (
setupVertexAttribPointer,
) where
import Control.Lens
import Control.Monad
import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BU
@@ -45,7 +46,7 @@ makeShader s shaderlist sizes pm = do
}
, vbo)
makeShader' ::
makeShader4 ::
-- | First part of the name of the shader
String ->
-- | shader types
@@ -55,7 +56,7 @@ makeShader' ::
EPrimitiveMode ->
VBO ->
IO FullShader
makeShader' s shaderlist sizes pm vbo = do
makeShader4 s shaderlist sizes pm vbo = do
prog <- makeSourcedShader s shaderlist
vao <- setupVAOvbo sizes vbo
return $ FullShader
@@ -66,8 +67,8 @@ makeShader' s shaderlist sizes pm vbo = do
, _shadUnis' = mempty
}
trueSetupVBO :: Int -> IO VBO
trueSetupVBO vertexsize = do
setupVBO4 :: Int -> IO VBO
setupVBO4 vertexsize = do
vboname <- mglCreate glCreateBuffers
thePtr <- mallocArray (vertexsize * numDrawableElements)
-- Allocate space
@@ -190,8 +191,9 @@ 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 vboname loc siz strd off
setupVertexAttribPointer vao loc siz off
thePtr <- mallocArray (strd * ndraw)
-- Allocate space
glNamedBufferData vboname
@@ -210,9 +212,9 @@ setupVBOSized ndraw vao sizes = do
setupVertexAttribs :: VBO -> GLuint -> [Int] -> IO ()
setupVertexAttribs vbo vao sizes = do
let vboname = _vboName vbo
glVertexArrayVertexBuffer vao 0 (vbo ^. vboName) 0 (fromIntegral $ floatSize * strd)
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
setupVertexAttribPointer vao vboname loc siz strd off
setupVertexAttribPointer vao loc siz off
where
strd = sum sizes
offs = scanl (+) 0 sizes
@@ -221,19 +223,13 @@ setupVertexAttribs vbo vao sizes = do
setupVertexAttribPointer ::
GLuint ->
-- | vao name
GLuint ->
-- | vbo name
Int ->
-- | Size
Int ->
-- | Stride
Int ->
-- | Offset
Int ->
IO ()
setupVertexAttribPointer vao vbo loc siz strd off = do
glVertexArrayVertexBuffer vao 0 vbo 0 (fromIntegral $ floatSize * strd)
-- the above is probably duplicated: needs moving out of this function
setupVertexAttribPointer vao loc siz off = do
glEnableVertexArrayAttrib vao loc'
glVertexArrayAttribFormat vao loc' siz' GL_FLOAT GL_FALSE (fromIntegral $ floatSize * off)
glVertexArrayAttribBinding vao loc' 0
+1
View File
@@ -18,6 +18,7 @@ module Shader.Data
, vboName
, vboPtr
, vboVertexSize
, eboName
, eboPtr