Vaious improvements to rendering performance, now runs at ok speed

This commit is contained in:
2021-03-02 01:28:53 +01:00
parent 18492f00d2
commit 81f5385710
2 changed files with 44 additions and 44 deletions
+26 -36
View File
@@ -34,8 +34,6 @@ data RenderData = RenderData
, _backVAO :: VAO
, _wallVAO :: VAO
, _fadeCircVAO :: VAO
, _posVBO :: BufferObject
, _colVBO :: BufferObject
, _texVBO :: BufferObject
, _wssLightPos :: UniformLocation
, _dummyVBO :: BufferObject
@@ -51,33 +49,35 @@ makeLenses ''VAO
floatSize = sizeOf (0.5 :: GLfloat)
setupVAO :: [(BufferObject,GLuint,Int)] -> IO VAO
setupVAO :: [(GLuint,Int)] -> IO VAO
setupVAO ps = do
theVAO <- genObjectName
bindVertexArrayObject $= Just theVAO
forM_ ps setupArrayBuffer
ptrs <- forM ps setupVBOPointers
vbos <- forM ps setupArrayBuffer
ptrs <- forM (zip vbos $ map snd ps) setupVBOPointers
return $ VAO theVAO ptrs
numDrawableElements :: Int
numDrawableElements = 50000
setupVBOPointers :: (BufferObject,GLuint,Int) -> IO (BufferObject,Ptr Float,Int)
setupVBOPointers (vbo,_,vsize) = do
setupVBOPointers :: (BufferObject,Int) -> IO (BufferObject,Ptr Float,Int)
setupVBOPointers (vbo,vsize) = do
thePtr <- mallocArray (vsize * numDrawableElements)
return (vbo,thePtr,vsize)
setupArrayBuffer :: (BufferObject,GLuint,Int) -> IO ()
setupArrayBuffer (vbo,aloc,i) = do
bindBuffer ArrayBuffer $= Just vbo
vertexAttribPointer (AttribLocation aloc) $=
( ToFloat
, VertexArrayDescriptor (fromIntegral i)
Float
(fromIntegral $ floatSize * i)
(bufferOffset 0)
)
vertexAttribArray (AttribLocation aloc) $= Enabled
setupArrayBuffer :: (GLuint,Int) -> IO BufferObject
setupArrayBuffer (aloc,i) = do
vbo <- genObjectName
bindBuffer ArrayBuffer $= Just vbo
vertexAttribPointer (AttribLocation aloc) $=
( ToFloat
, VertexArrayDescriptor (fromIntegral i)
Float
(fromIntegral $ floatSize * i)
(bufferOffset 0)
)
vertexAttribArray (AttribLocation aloc) $= Enabled
return vbo
loadTextures :: IO [Image PixelRGBA8]
@@ -106,13 +106,6 @@ preloadRender = do
wss <- makeSourcedShader "wallShadow" [VertexShader,GeometryShader,FragmentShader]
wssLightPosUniLoc <- GL.uniformLocation (fst wss) "lightPos"
-- get uniform locations
--setup vbos
--need to be bound before assigning the vertex attribute pointers
posVBO <- genObjectName
colVBO <- genObjectName
texVBO <- genObjectName
--the following vbo is set up to contain one fixed vertex
dummyvbo <- genObjectName
@@ -151,14 +144,14 @@ preloadRender = do
--textureBinding Texture2D $= Just chartex
trivao <- setupVAO [(posVBO,0,3),(colVBO,1,4)]
linevao <- setupVAO [(posVBO,0,3),(colVBO,1,4)]
textvao <- setupVAO [(posVBO,0,3),(colVBO,1,4),(texVBO,2,2)]
circvao <- setupVAO [(posVBO,0,3),(colVBO,1,4),(texVBO,2,1)]
arcvao <- setupVAO [(posVBO,0,3),(colVBO,1,4),(texVBO,2,4)]
backgroundvao <- setupVAO [(posVBO,0,4),(colVBO,1,2)]
wallvao <- setupVAO [(posVBO,0,4)]--,(colVBO,1,4)]
fadecircvao <- setupVAO [(posVBO,0,4)]
trivao <- setupVAO [(0,3),(1,4)]
linevao <- setupVAO [(0,3),(1,4)]
textvao <- setupVAO [(0,3),(1,4),(2,2)]
circvao <- setupVAO [(0,3),(1,4),(2,1)]
arcvao <- setupVAO [(0,3),(1,4),(2,4)]
backgroundvao <- setupVAO [(0,4),(1,2)]
wallvao <- setupVAO [(0,4)]--,(colVBO,1,4)]
fadecircvao <- setupVAO [(0,4)]
return $ RenderData
{ -- _charMap = convertRGBA8 cmap
@@ -178,9 +171,6 @@ preloadRender = do
, _backVAO = backgroundvao
, _wallVAO = wallvao
, _fadeCircVAO = fadecircvao
, _posVBO = posVBO
, _colVBO = colVBO
, _texVBO = texVBO
, _dummyVBO = dummyvbo
, _dummyPtr = dummyptr
, _wssLightPos = wssLightPosUniLoc