Refactor preloading/rendering/update

This commit is contained in:
2023-03-24 11:52:40 +00:00
parent 4b92a43535
commit d524a14da4
8 changed files with 32 additions and 68 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

+3 -2
View File
@@ -6,8 +6,9 @@ const vec2 winSize = vec2 (300.0,300.0);
// this is so that the window size can be extracted and the shader recompiled on // this is so that the window size can be extracted and the shader recompiled on
// the fly // the fly
layout (binding = 0) uniform sampler2D screenTexture; layout (binding = 0) uniform sampler2D screenTexture;
const float hOff = 3 / winSize.x; // the 1.5 maximises the blend, so to speak
const float vOff = 3 / winSize.y; const float hOff = 1.5 / winSize.x;
const float vOff = 1.5 / winSize.y;
//const vec2 off[9] = vec2[] //const vec2 off[9] = vec2[]
// ( vec2( hOff, vOff ) // ( vec2( hOff, vOff )
// , vec2( hOff, 0.0 ) // , vec2( hOff, 0.0 )
+1 -5
View File
@@ -48,8 +48,4 @@ applyWorldConfig ::
IO PreloadData IO PreloadData
applyWorldConfig cfig pdata = do applyWorldConfig cfig pdata = do
setVol cfig setVol cfig
pdataResizeUpdate cfig (x `div` divRes) (y `div` divRes) x y pdata renderData (pdataResizeUpdate cfig) pdata
where
x = round $ _windowX cfig
y = round $ _windowY cfig
divRes = resFactorNum $ _graphics_world_resolution cfig
+5 -6
View File
@@ -15,11 +15,12 @@ module Dodge.Event (
handleEvent, handleEvent,
) where ) where
import Control.Monad
import qualified Data.Text as T import qualified Data.Text as T
import Dodge.Concurrent import Dodge.Concurrent
import Dodge.Data.Universe import Dodge.Data.Universe
import Dodge.Event.Input import Dodge.Event.Input
import Dodge.PreloadData import Preload.Update
import LensHelp import LensHelp
import SDL import SDL
@@ -56,9 +57,7 @@ handleResizeEvent sev u =
u u
& uvConfig . windowX .~ fromIntegral x & uvConfig . windowX .~ fromIntegral x
& uvConfig . windowY .~ fromIntegral y & uvConfig . windowY .~ fromIntegral y
& uvIOEffects %~ sideEffectUpdatePreload divRes x y -- & uvIOEffects %~ sideEffectUpdatePreload
& uvIOEffects %~ (updatePreload >=>)
where where
x = fromIntegral x' V2 x y = windowSizeChangedEventSize sev
y = fromIntegral y'
V2 x' y' = windowSizeChangedEventSize sev
divRes = resFactorNum $ u ^. uvConfig . graphics_world_resolution
+4 -4
View File
@@ -16,7 +16,7 @@ import Dodge.Data.Universe
import Dodge.Menu.Option import Dodge.Menu.Option
import Dodge.Menu.OptionType import Dodge.Menu.OptionType
import Dodge.Menu.PushPop import Dodge.Menu.PushPop
import Dodge.PreloadData import Preload.Update
import Dodge.Save import Dodge.Save
import Dodge.SoundLogic import Dodge.SoundLogic
import Dodge.StartNewGame import Dodge.StartNewGame
@@ -182,11 +182,11 @@ graphicsMenu = titleOptionsMenu "OPTIONS:GRAPHICS" graphicsMenuOptions
graphicsMenuOptions :: [MenuOption] graphicsMenuOptions :: [MenuOption]
graphicsMenuOptions = graphicsMenuOptions =
[ makeEnumOption graphics_world_resolution "World resolution" (uvIOEffects .~ updateFramebufferSize) [ makeEnumOption graphics_world_resolution "World resolution" (uvIOEffects .~ updatePreload)
, makeEnumOption graphics_downsize_resolution "Downsize resolution" , makeEnumOption graphics_downsize_resolution "Downsize resolution"
(uvIOEffects .~ updateFramebufferSize) (uvIOEffects .~ updatePreload)
, makeEnumOption graphics_overlay_resolution "Overlay resolution" , makeEnumOption graphics_overlay_resolution "Overlay resolution"
(uvIOEffects .~ updateFramebufferSize) (uvIOEffects .~ updatePreload)
, makeEnumOption graphics_object_shadows "SHADOW DETAIL" id , makeEnumOption graphics_object_shadows "SHADOW DETAIL" id
, makeEnumOption graphics_distortions "ENABLE DISTORTIONS" id , makeEnumOption graphics_distortions "ENABLE DISTORTIONS" id
, makeEnumOption graphics_bloom "ENABLE BLOOM" id , makeEnumOption graphics_bloom "ENABLE BLOOM" id
-23
View File
@@ -1,23 +0,0 @@
module Dodge.PreloadData where
import Control.Lens
import Dodge.Data.Universe
import Preload.Update
sideEffectUpdatePreload :: Int -> Int -> Int -> (Universe -> IO Universe) -> Universe -> IO Universe
sideEffectUpdatePreload divRes x y f u = do
-- GL.viewport $= (GL.Position 0 0, GL.Size (fromIntegral x) (fromIntegral y))
pdata <- pdataResizeUpdate (u ^. uvConfig) (x `div` divRes) (y `div` divRes) x y (_preloadData u)
f $ u & preloadData .~ pdata
updatePreload :: Int -> Int -> Int -> Universe -> IO Universe
updatePreload divRes x y u = do
pdata <- pdataResizeUpdate (u ^. uvConfig) (x `div` divRes) (y `div` divRes) x y (_preloadData u)
return $ u & preloadData .~ pdata
updateFramebufferSize :: Universe -> IO Universe
updateFramebufferSize u = updatePreload divRes x y u
where
(x, y) = (round $ _windowX cfig, round $ _windowY cfig)
cfig = _uvConfig u
divRes = resFactorNum $ u ^. uvConfig . graphics_world_resolution
-1
View File
@@ -51,7 +51,6 @@ doDrawing' win pdata u = do
wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig) wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig)
worldres = resFactorNum $ cfig ^. graphics_world_resolution worldres = resFactorNum $ cfig ^. graphics_world_resolution
downres = resFactorNum $ cfig ^. graphics_downsize_resolution downres = resFactorNum $ cfig ^. graphics_downsize_resolution
overlayres = resFactorNum $ cfig ^. graphics_overlay_resolution
(windowPoints, wallSPics, wallsToPoke) = wallsToDraw w (windowPoints, wallSPics, wallsToPoke) = wallsToDraw w
lightPoints = lightsToRender cfig (w ^. cWorld . camPos) (w ^. cWorld . lWorld) lightPoints = lightsToRender cfig (w ^. cWorld . camPos) (w ^. cWorld . lWorld)
viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom
+19 -27
View File
@@ -1,52 +1,39 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Preload.Update ( module Preload.Update (
updatePreload,
pdataResizeUpdate, pdataResizeUpdate,
) where ) where
import Dodge.Data.Config import Dodge.Data.Universe
import Control.Lens import Control.Lens
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString.Char8 as BSC
import Data.Preload
import Data.Preload.Render import Data.Preload.Render
import Framebuffer.Update import Framebuffer.Update
import Shader.Compile import Shader.Compile
import Shader.Data import Shader.Data
pdataResizeUpdate :: updatePreload :: Universe -> IO Universe
Configuration -> updatePreload u = do
-- | Scaled width pdata <- pdataResizeUpdate (u ^. uvConfig) (u ^?! preloadData . renderData)
Int -> return $ u & preloadData . renderData .~ pdata
-- | Scaled height
Int -> pdataResizeUpdate :: Configuration -> RenderData -> IO RenderData
-- | Full width pdataResizeUpdate cfig pdata = do
Int -> rd <- renderDataResizeUpdate cfig pdata
-- | Full height return rd
Int ->
PreloadData ->
IO PreloadData
pdataResizeUpdate cfig xsize ysize xfull yfull pdata = do
rd <- renderDataResizeUpdate cfig xsize ysize xfull yfull (_renderData pdata)
return (pdata{_renderData = rd})
renderDataResizeUpdate :: renderDataResizeUpdate ::
Configuration -> Configuration ->
-- | Scaled width
Int ->
-- | Scaled height
Int ->
-- | Full width
Int ->
-- | Full height
Int ->
RenderData -> RenderData ->
IO RenderData IO RenderData
renderDataResizeUpdate cfig xsize ysize xfull yfull rdata = do renderDataResizeUpdate cfig rdata = do
rdata' <- sizeFBOs cfig rdata rdata' <- sizeFBOs cfig rdata
bbVert <- BS.readFile "shader/texture/bloomBlur.vert" bbVert <- BS.readFile "shader/texture/bloomBlur.vert"
bbFrag <- BS.readFile "shader/texture/bloomBlur.frag" bbFrag <- BS.readFile "shader/texture/bloomBlur.frag"
let (bh, bmid) = BS.breakSubstring "(" bbFrag let (xsize,ysize) = getWindowSize _graphics_downsize_resolution cfig :: (Int,Int)
(bh, bmid) = BS.breakSubstring "(" bbFrag
(_, btt) = BS.breakSubstring ")" bmid (_, btt) = BS.breakSubstring ")" bmid
bbFrag' = BS.append bh $ BS.append (BSC.pack $ '(' : show xsize ++ "," ++ show ysize) btt bbFrag' = BS.append bh $ BS.append (BSC.pack $ '(' : show xsize ++ "," ++ show ysize) btt
--BSC.putStrLn bbFrag' --BSC.putStrLn bbFrag'
@@ -57,3 +44,8 @@ renderDataResizeUpdate cfig xsize ysize xfull yfull rdata = do
pmTriangleStrip pmTriangleStrip
(rdata ^. screenTextureVAO) (rdata ^. screenTextureVAO)
return (rdata'{_bloomBlurShader = bbShad}) return (rdata'{_bloomBlurShader = bbShad})
getWindowSize :: Integral a => (Configuration -> ResFactor) -> Configuration -> (a,a)
getWindowSize f cfig = (g _windowX,g _windowY)
where
g h = fromIntegral $ round (h cfig) `div` resFactorNum (f cfig)