DSA glClear

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