Refactor differing resolutions somewhat

This commit is contained in:
2023-03-24 11:14:49 +00:00
parent cd224437e7
commit 4b92a43535
11 changed files with 69 additions and 52 deletions
+17 -6
View File
@@ -1,6 +1,7 @@
-- | Contains the central drawing functions for the dodge loop.
module Dodge.Render (
doDrawing,
getWindowSize
) where
--import qualified Data.Vector as V
@@ -13,7 +14,6 @@ import qualified Data.Map.Strict as M
import Data.Preload.Render
import qualified Data.Vector.Unboxed.Mutable as UMV
import Dodge.Data.Universe
import Dodge.DownscaleSize
import Dodge.Render.Lights
import Dodge.Render.ShapePicture
import Dodge.Render.Walls
@@ -49,7 +49,9 @@ doDrawing' win pdata u = do
camzoom = w ^. cWorld . camPos . camZoom
trans = w ^. cWorld . camPos . camCenter
wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig)
resFact = resFactorNum $ cfig ^. graphics_resolution_factor
worldres = resFactorNum $ cfig ^. graphics_world_resolution
downres = resFactorNum $ cfig ^. graphics_downsize_resolution
overlayres = resFactorNum $ cfig ^. graphics_overlay_resolution
(windowPoints, wallSPics, wallsToPoke) = wallsToDraw w
lightPoints = lightsToRender cfig (w ^. cWorld . camPos) (w ^. cWorld . lWorld)
viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom
@@ -105,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` resFact) (round winy `div` resFact)
setViewportSize (round winx `div` worldres) (round winy `div` worldres)
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase ._1 . unFBO)
glDepthMask GL_TRUE
glDisable GL_BLEND
@@ -216,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` downSize) (round winy `div` downSize)
setViewportSize (round winx `div` downres) (round winy `div` downres)
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboHalf1 pdata)))
glDepthFunc GL_ALWAYS
glBindTextureUnit 0 (pdata ^. fboBloom . _2 . unTO)
@@ -224,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` resFact) (round winy `div` resFact)
setViewportSize (round winx `div` worldres) (round winy `div` worldres)
--draw clouds onto cloud buffer
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
glDepthFunc GL_LEQUAL
@@ -332,7 +334,8 @@ doDrawing' win pdata u = do
glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _1 . unTO)
drawShader (_fullscreenShader pdata) 4
--set viewport for radial distortion
setViewportSize (round winx) (round winy)
--setViewportSize (round winx) (round winy)
setViewportType _graphics_overlay_resolution cfig
glDepthFunc GL_ALWAYS
glBlendFunc GL_ONE GL_ZERO
-- perform any radial distortion
@@ -371,3 +374,11 @@ getDistortions cfig w
setViewportSize :: Int -> Int -> IO ()
setViewportSize x y = glViewport 0 0 (fromIntegral x) (fromIntegral y)
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)
setViewportType :: (Configuration -> ResFactor) -> Configuration -> IO ()
setViewportType f = uncurry (glViewport 0 0) . getWindowSize f