From 100fdc102d410081a4d62f55f4a639b1167bd652 Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 16 Mar 2023 22:43:48 +0000 Subject: [PATCH] DSA glClear --- src/Dodge/Render.hs | 31 ++++++++++++++++------- src/Preload/Render.hs | 3 --- src/Render.hs | 59 +++++++++++++++++++++++++++++++++---------- src/Shader/Poke.hs | 5 ---- 4 files changed, 67 insertions(+), 31 deletions(-) diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index 6b173c1dc..513c096ab 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -112,8 +112,18 @@ doDrawing' win pdata u = do setViewportSize (round winx `div` resFact) (round winy `div` resFact) glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboBase pdata))) glDepthMask GL_TRUE - glClearColor 0 0 0 1 - glClear $ sum [GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT] +-- the following clear may not be necessary + withArray [0,0,0,1] $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboBase . _1 . unFBO) + GL_COLOR + 0 + ptr + with 1 $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboBase . _1 . unFBO) + GL_DEPTH + 0 + ptr + glDepthFunc GL_LESS -- draw wall occlusions from the camera's point of view glUseProgram (pdata ^. lightingWallShadShader . shadName) @@ -163,7 +173,6 @@ doDrawing' win pdata u = do (pdata ^. fboBase . _2 . _2) (drawCPUShadows pdata ws) glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE - glClearColor 0 0 0 0 --apply lightmap to base buffer glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO) glBindTexture GL_TEXTURE_2D (pdata ^. fboLighting . _2 . unTO) @@ -177,7 +186,11 @@ doDrawing' win pdata u = do ptr --draw bloom onto bloom buffer glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBloom . _1 . unFBO) - glClear GL_COLOR_BUFFER_BIT + withArray [0,0,0,0] $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboBloom . _1 . unFBO) + GL_COLOR + 0 + ptr glDepthFunc GL_LESS glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glDepthMask GL_FALSE @@ -198,10 +211,13 @@ doDrawing' win pdata u = do glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata))) glDepthFunc GL_LEQUAL glDepthMask GL_FALSE - glClearColor 0.5 0.5 0.5 0 glBlendFuncSeparate GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE GL_ONE_MINUS_SRC_ALPHA withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ \ptr -> glDrawBuffers 2 ptr - glClear GL_COLOR_BUFFER_BIT + withArray [0.5,0.5,0.5,0] $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboCloud . _1 . unFBO) + GL_COLOR + 0 + ptr renderLayer MidLayer shadV layerCounts drawShader (_windowShader pdata) nWins -- when (_graphics_cloud_shadows cfig) $ do @@ -225,11 +241,8 @@ doDrawing' win pdata u = do -- (_graphics_object_shadows $ _uvConfig u) -- (snd $ snd $ _fboCloud pdata) -- (drawCPUShadows pdata ws) --- glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE --- glClearColor 0 0 0 0 glInvalidateBufferData (pdata ^. vboShapes . vboName) --apply lightmap to cloud buffer - glClearColor 0 0 0 0 glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata))) glDepthMask GL_FALSE withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ \ptr -> glDrawBuffers 2 ptr diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index 05864f964..adfd64127 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -211,9 +211,6 @@ preloadRender = do -- reset to default framebuffer, ready for drawing direct to screen glBindFramebuffer GL_FRAMEBUFFER 0 - -- set the clearColor to have 1 alpha - glClearColor 0 0 0 1 - shadV <- MV.new 6 zipWithM_ (MV.write shadV) diff --git a/src/Render.hs b/src/Render.hs index 56a166dce..41bc1aaca 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -57,8 +57,11 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra glDepthMask GL_FALSE -- clearColor is specified differently in preloadRender -- the colors are inverted - glClearColor 1 1 1 1 - glClear GL_COLOR_BUFFER_BIT + withArray [1,1,1,1] $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboLighting . _1 . unFBO) + GL_COLOR + 0 + ptr -- for each of the lights: -- 1. stencil out the shadows from this light's point of view -- 2. calculate lighting based on each fragment's position @@ -71,7 +74,11 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra glDepthFunc GL_LESS -- setup stencil glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE - glClear GL_STENCIL_BUFFER_BIT + with 0 $ \ptr -> glClearNamedFramebufferiv + (pdata ^. fboLighting . _1 . unFBO) + GL_STENCIL + 0 + ptr glDisable GL_CULL_FACE glStencilFunc GL_ALWAYS 0 255 --draw lightmap itself @@ -94,11 +101,17 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra glDisable GL_STENCIL_TEST NoLighting -> do glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) - glClearColor 0 0 0 1 - -- glClearDepth 0 glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR - glClear $ GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT - -- glClearDepth 1 + withArray [0,0,0,1] $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboLighting . _1 . unFBO) + GL_COLOR + 0 + ptr + with 1 $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboLighting . _1 . unFBO) + GL_DEPTH + 0 + ptr glDisable GL_CULL_FACE --bindTO toPos glBindTextureUnit 0 (toPos ^. unTO) @@ -115,8 +128,11 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra glDepthMask GL_FALSE -- clearColor is specified differently in preloadRender -- the colors are inverted - glClearColor 1 1 1 1 - glClear GL_COLOR_BUFFER_BIT + withArray [1,1,1,1] $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboLighting . _1 . unFBO) + GL_COLOR + 0 + ptr -- for each of the lights: -- 1. stencil out the shadows from this light's point of view -- 2. calculate lighting based on each fragment's position @@ -129,7 +145,11 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra glDepthFunc GL_LESS -- setup stencil glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE - glClear GL_STENCIL_BUFFER_BIT + with 0 $ \ptr -> glClearNamedFramebufferiv + (pdata ^. fboLighting . _1 . unFBO) + GL_STENCIL + 0 + ptr glDisable GL_CULL_FACE glStencilFunc GL_ALWAYS 0 255 --draw wall shadows @@ -235,8 +255,16 @@ instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do 1 glBindFramebuffer GL_FRAMEBUFFER $ pdata ^. fboShadow . _1 . unFBO glDepthMask GL_FALSE - glClearColor 0 0 0 0 - glClear $ GL_COLOR_BUFFER_BIT + GL_STENCIL_BUFFER_BIT + withArray [0,0,0,0] $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboShadow . _1 . unFBO) + GL_COLOR + 0 + ptr + with 0 $ \ptr -> glClearNamedFramebufferiv + (pdata ^. fboShadow . _1 . unFBO) + GL_STENCIL + 0 + ptr -- stencil out the shadows from each light's point of view -- setup stencil glEnable GL_STENCIL_TEST @@ -289,8 +317,11 @@ instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do glDisable GL_STENCIL_TEST --draw to the lighting framebuffer here glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) - glClearColor 1 1 1 1 - glClear GL_COLOR_BUFFER_BIT + withArray [1,1,1,1] $ \ptr -> glClearNamedFramebufferfv + (pdata ^. fboLighting . _1 . unFBO) + GL_COLOR + 0 + ptr glBindTexture GL_TEXTURE_2D_ARRAY (pdata ^. fboShadow . _2 . _1 . unTO) glEnable GL_BLEND glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR diff --git a/src/Shader/Poke.hs b/src/Shader/Poke.hs index 22df75949..f8a1b3168 100644 --- a/src/Shader/Poke.hs +++ b/src/Shader/Poke.hs @@ -7,7 +7,6 @@ module Shader.Poke ( memoTopPrismEdgeIndices, ) where ---import Control.Monad import Control.Monad.Primitive import qualified Data.Vector as V import qualified Data.Vector.Fusion.Stream.Monadic as VFSM @@ -231,7 +230,6 @@ pokeTopPrism cp col size ptr iptr ieptr (nv, nsi, nei) svs = do nv' <- VFSM.foldlM' (pokeJustV cp col ptr) nv svs nsi' <- UV.foldM' - --(pokeTopPrismIndex nv iptr) (pokeIndex nv iptr) nsi (memoTopPrismIndices V.! (size - 3)) @@ -379,7 +377,6 @@ pokeJustV :: IO Int {-# INLINE pokeJustV #-} pokeJustV cp col ptr nv sh = do - --zipWithM_ f [0 ..] [x, y, z, 1, r, g, b, a, nx, ny, nz, 1] UV.imapM_ f $ UV.fromList [x, y, z, 1, r, g, b, a, nx, ny, nz, 1] return (nv + 1) where @@ -397,7 +394,6 @@ pokeJustVInvNormal :: IO Int {-# INLINE pokeJustVInvNormal #-} pokeJustVInvNormal cp col ptr nv sh = do - --zipWithM_ f [0 ..] [x, y, z, 1, r, g, b, a, nx, ny, nz, 1] UV.imapM_ f $ UV.fromList [x, y, z, 1, r, g, b, a, nx, ny, nz, 1] return (nv + 1) where @@ -415,7 +411,6 @@ pokeFlatV :: IO Int {-# INLINE pokeFlatV #-} pokeFlatV norm col ptr nv sh = do - --zipWithM_ f [0 ..] [x, y, z, 1, r, g, b, a, nx, ny, nz, 1] UV.imapM_ f $ UV.fromList [x, y, z, 1, r, g, b, a, nx, ny, nz, 1] return (nv + 1) where