Refactor framebuffer update

This commit is contained in:
2023-03-24 13:14:49 +00:00
parent bd9f32875e
commit 4d09927d42
9 changed files with 59 additions and 83 deletions
-7
View File
@@ -3,7 +3,6 @@ IO actions that apply config side effects and save configuration settings to dis
-}
module Dodge.Config.Update (
saveConfig,
setVolThen,
applyWorldConfig,
setVol,
) where
@@ -33,12 +32,6 @@ setVol cfig = do
setSoundVolume (_volume_master cfig * _volume_sound cfig)
setMusicVolume (_volume_master cfig * _volume_music cfig)
-- what?
setVolThen :: Configuration -> (a -> IO a) -> a -> IO a
setVolThen cfig f a = do
setVol cfig
f a
{- |
Apply /all/ of the values in the world configuration to the running game.
-}
+11 -14
View File
@@ -31,10 +31,12 @@ import Shader.Data
import Shader.Poke
import Shader.Poke.Cloud
doDrawing :: SDL.Window -> RenderData -> Universe -> IO ()
doDrawing window rdata u
doDrawing :: SDL.Window -> Universe -> IO ()
doDrawing window u
| SDL.ScancodeT `M.member` (u ^. uvWorld . input . pressedKeys) = doTestDrawing rdata u
| otherwise = doDrawing' window rdata u
where
rdata = u ^. preloadData . renderData
doTestDrawing :: RenderData -> Universe -> IO ()
doTestDrawing _ _ = do
@@ -49,9 +51,7 @@ doDrawing' win pdata u = do
rot = w ^. cWorld . camPos . camRot
camzoom = w ^. cWorld . camPos . camZoom
trans = w ^. cWorld . camPos . camCenter
wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig)
worldres = resFactorNum $ cfig ^. graphics_world_resolution
downres = resFactorNum $ cfig ^. graphics_downsize_resolution
wins = V2 (_windowX cfig) (_windowY cfig)
(windowPoints, wallSPics, wallsToPoke) = wallsToDraw w
lightPoints = lightsToRender cfig (w ^. cWorld . camPos) (w ^. cWorld . lWorld)
viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom
@@ -107,7 +107,7 @@ doDrawing' win pdata u = do
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO)
withArray (perspectiveMatrixb rot camzoom trans wins viewFroms) $ \ptr ->
glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr
setViewportSize (round winx `div` worldres) (round winy `div` worldres)
setViewport _graphics_world_resolution cfig
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase ._1 . unFBO)
glDepthMask GL_TRUE
glDisable GL_BLEND
@@ -218,7 +218,7 @@ doDrawing' win pdata u = do
renderLayer BloomLayer shadV layerCounts
--setup downscale viewport for blurring bloom
--setViewportSize (round winx `div` (2 * resFact)) (round winy `div` (2 * resFact))
setViewportSize (round winx `div` downres) (round winy `div` downres)
setViewport _graphics_downsize_resolution cfig
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboHalf1 pdata)))
glDepthFunc GL_ALWAYS
glBindTextureUnit 0 (pdata ^. fboBloom . _2 . unTO)
@@ -226,7 +226,7 @@ doDrawing' win pdata u = do
drawShader (_bloomBlurShader pdata) 4
replicateM_ 2 $ pingPongBetween (_fboHalf1 pdata) (_fboHalf2 pdata) (_bloomBlurShader pdata)
glEnable GL_BLEND
setViewportSize (round winx `div` worldres) (round winy `div` worldres)
setViewport _graphics_world_resolution cfig
--draw clouds onto cloud buffer
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
glDepthFunc GL_LEQUAL
@@ -335,7 +335,7 @@ doDrawing' win pdata u = do
drawShader (_fullscreenShader pdata) 4
--set viewport for radial distortion
--setViewportSize (round winx) (round winy)
setViewportType _graphics_overlay_resolution cfig
setViewport _graphics_overlay_resolution cfig
glDepthFunc GL_ALWAYS
glBlendFunc GL_ONE GL_ZERO
-- perform any radial distortion
@@ -372,8 +372,5 @@ getDistortions cfig w
| cfig ^. graphics_distortions = w ^. cWorld . lWorld . distortions
| otherwise = []
setViewportSize :: Int -> Int -> IO ()
setViewportSize x y = glViewport 0 0 (fromIntegral x) (fromIntegral y)
setViewportType :: (Configuration -> ResFactor) -> Configuration -> IO ()
setViewportType f = uncurry (glViewport 0 0) . getWindowSize f
setViewport :: (Configuration -> ResFactor) -> Configuration -> IO ()
setViewport f = uncurry (glViewport 0 0) . getWindowSize f