Continue shader refactor

This commit is contained in:
2023-04-13 00:43:01 +01:00
parent cd46998e05
commit f104b24e90
7 changed files with 40 additions and 39 deletions
+19 -21
View File
@@ -1,11 +1,11 @@
module Shader.Compile (
setupVBO',
setupVBO,
setupVBOStatic,
makeShaderEBO,
makeShaderVBO,
makeShaderUsingVBO,
makeByteStringShaderUsingVAO,
makeShaderFixedVertices,
makeStaticShader,
makeShaderUsingVAO,
setupVAOUsingVBO,
setupVAOvbo,
@@ -46,7 +46,7 @@ makeShaderVBO ::
IO (Shader, VBO)
makeShaderVBO s shaderlist sizes pm = do
prog <- makeSourcedShader s shaderlist
(vao, vbo) <- setupVBOVAO sizes
(vao, vbo) <- setupVBOVAO (toFloatVAs sizes)
return
( Shader
{ _shaderUINT = prog
@@ -89,8 +89,8 @@ makeShaderUsingVBO s shaderlist sizes pm vbo = do
vao <- setupVAOUsingVBO sizes vbo
makeShaderUsingVAO s shaderlist pm vao
setupVBO' :: Int -> IO VBO
setupVBO' vertexsize = do
setupVBO :: Int -> IO VBO
setupVBO vertexsize = do
vboname <- mglCreate glCreateBuffers
thePtr <- mallocBytes (vertexsize * numDrawableElements)
-- Allocate space
@@ -175,27 +175,25 @@ makeShaderUsingVAO s shaderlist pm theVAO = do
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.
-}
makeShaderFixedVertices ::
makeStaticShader ::
Storable a =>
-- | First part of the name of the shader
String ->
-- | shader types
[GLenum] ->
-- | The input vertex sizes
[Int] ->
-- | Number of vertexes that can be poked
Int ->
[VertexAttribute] ->
[a] ->
PrimitiveMode ->
IO (Shader, VBO)
makeShaderFixedVertices s shaderlist sizes ndraw pm = do
IO Shader
makeStaticShader s shaderlist vas vdata pm = do
prog <- makeSourcedShader s shaderlist
(vao, vbo) <- setupVBOVAO sizes
(_, vao) <- setupStaticVBOVAO vas vdata
return
( Shader
{ _shaderUINT = prog
, _shaderVAO = vao
, _shaderPrimitive = pm
}
, vbo
)
{- | Compile shader and get its uniform locations.
@@ -235,26 +233,25 @@ setupVAOUsingVBO vas vbo = do
setupEBO :: VAO -> IO EBO
setupEBO vao = do
eboptr <- mallocArray numDrawableElements
eboptr <- mallocArray numGLushort
eboname <- mglCreate glCreateBuffers
glNamedBufferData
eboname
(fromIntegral $ glushortSize * numDrawableElements)
(fromIntegral $ glushortSize * numGLushort)
nullPtr
GL_STREAM_DRAW
glVertexArrayElementBuffer (vao ^. vaoName) eboname
return $ EBO eboname eboptr
setupVBOVAO :: [Int] -> IO (VAO, VBO)
setupVBOVAO sizes = do
setupVBOVAO :: [VertexAttribute] -> IO (VAO, VBO)
setupVBOVAO vas = do
vaoname <- mglCreate glCreateVertexArrays
glBindVertexArray vaoname
vbo <- setupVBO' (floatSize * sum sizes)
vbo <- setupVBO strd
--vao <- setupVAOvbo (toFloatVAs sizes) (sum sizes) (vbo ^. vboName)
vao <- setupVAOUsingVBO (toFloatVAs sizes) vbo
vao <- setupVAOUsingVBO vas vbo
return (vao,vbo)
where
vas = toFloatVAs sizes
strd = vasTightStride vas
toFloatVAs :: [Int] -> [VertexAttribute]
@@ -367,6 +364,7 @@ attribSize x = case x of
-- GL_INT_2_10_10_10_REV -> sizeOf (0 :: GL_INT_2_10_10_10_REV)
-- GL_UNSIGNED_INT_2_10_10_10_REV -> sizeOf (0 :: GL_UNSIGNED_INT_2_10_10_10_REV)
-- GL_UNSIGNED_INT_10F_11F_11F_REV -> sizeOf (0 :: GL_UNSIGNED_INT_10F_11F_11F_REV)
_ -> error "attribSize : unkown GLenum attribute size"
-- https://hackage.haskell.org/package/OpenGL-3.0.3.0/docs/src/Graphics.Rendering.OpenGL.GL.ByteString.html#withByteStringP
withByteString :: Num t => BS.ByteString -> (Ptr b -> t -> IO a) -> IO a
+6 -1
View File
@@ -3,6 +3,7 @@ module Shader.Parameters
, numDrawableElements
, numSubElements
, glushortSize
, numGLushort
) where
import Graphics.GL.Core45
import Foreign
@@ -19,10 +20,14 @@ glushortSize :: Int
glushortSize = sizeOf (0 :: GLushort)
{-# INLINE glushortSize #-}
numGLushort :: Int
numGLushort = fromIntegral (maxBound :: GLushort) + 1
{-# INLINE numGLushort #-}
numDrawableElements :: Int
{-# INLINE numDrawableElements #-}
numDrawableElements = 6 * numSubElements
numSubElements :: Int
{-# INLINE numSubElements #-}
numSubElements = 100000
numSubElements = 65536