Fix resize crash

This commit is contained in:
2023-03-24 14:21:12 +00:00
parent 000fcbc1c9
commit 20c05be23f
8 changed files with 99 additions and 60 deletions
+64 -33
View File
@@ -7,15 +7,15 @@ module Framebuffer.Update (
sizeFBOs,
) where
import Dodge.Data.Config
import Shader.Data
import Framebuffer.Check
import Control.Lens
import Control.Monad
import Data.Preload.Render
import Dodge.Data.Config
import Foreign.Marshal.Array
import Framebuffer.Check
import GLHelp
import Graphics.GL.Core45
import Shader.Data
import Unsafe.Coerce
sizeFBOs ::
@@ -24,28 +24,50 @@ sizeFBOs ::
IO RenderData
sizeFBOs cfig rdata =
uncurry (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _graphics_world_resolution cfig)
>> uncurry updateFBOTO3 (getWindowSize _graphics_world_resolution cfig)
GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F GL_RGBA16F rdata fboBase
>>= flip ( uncurry updateFBOTO3 (getWindowSize _graphics_world_resolution cfig)
GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F GL_RGBA16F) fboCloud
>>= flip ( uncurry updateFBOTO (getWindowSize _graphics_world_resolution cfig)
GL_NEAREST GL_NEAREST GL_RGBA8) fboLighting
>>=
ffoldM
(uncurry updateFBOTO (getWindowSize _graphics_world_resolution cfig)
GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F)
[fboBloom, fboPos]
>>=
ffoldM
(uncurry updateFBOTO (getWindowSize _graphics_overlay_resolution cfig) GL_NEAREST GL_NEAREST GL_RGBA8)
[fbo2, fbo3]
>>= ffoldM
(uncurry updateFBOTO (getWindowSize _graphics_downsize_resolution cfig) GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F)
[fboHalf1, fboHalf2, fboHalf3]
>>= resizeShadowFBO' cfig
>> foldM
( uncurry
updateFBOTO3
(getWindowSize _graphics_world_resolution cfig)
GL_NEAREST
GL_NEAREST
GL_RGBA8
GL_RGBA16F
GL_RGBA16F
)
rdata
[fboBase, fboCloud]
>>= flip
( uncurry
updateFBOTO
(getWindowSize _graphics_world_resolution cfig)
GL_NEAREST
GL_NEAREST
GL_RGBA8
)
fboLighting
>>= ffoldM
( uncurry
updateFBOTO
(getWindowSize _graphics_world_resolution cfig)
GL_LINEAR_MIPMAP_LINEAR
GL_LINEAR
GL_RGBA16F
)
[fboBloom, fboPos]
>>= ffoldM
(uncurry updateFBOTO (getWindowSize _graphics_overlay_resolution cfig) GL_LINEAR GL_NEAREST GL_RGBA8)
[fbo2, fbo3, fboOverlay]
>>= ffoldM
(uncurry updateFBOTO (getWindowSize _graphics_downsize_resolution cfig) GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F)
[fboHalf1, fboHalf2, fboHalf3]
>>= resizeShadowFBO' cfig
ffoldM :: (Foldable t, Monad m) =>
(a1 -> a2 -> m a1) -> t a2 -> a1 -> m a1
ffoldM ::
(Foldable t, Monad m) =>
(a1 -> a2 -> m a1) ->
t a2 ->
a1 ->
m a1
ffoldM f = flip $ foldM f
resizeRBO ::
@@ -53,7 +75,8 @@ resizeRBO ::
GLsizei ->
GLsizei ->
IO ()
resizeRBO rboName = glNamedRenderbufferStorage
resizeRBO rboName =
glNamedRenderbufferStorage
rboName
GL_DEPTH24_STENCIL8
@@ -125,8 +148,16 @@ resizeShadowFBO x y (fbo, (oldto1, oldto2)) = do
mglDelete glDeleteTextures $ _unTO oldto1
mglDelete glDeleteTextures $ _unTO oldto2
to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 20 GL_NEAREST GL_NEAREST GL_RGBA8
to2 <- initializeTexture2DArray
fbo GL_DEPTH_STENCIL_ATTACHMENT x y 20 GL_NEAREST GL_NEAREST GL_DEPTH24_STENCIL8
to2 <-
initializeTexture2DArray
fbo
GL_DEPTH_STENCIL_ATTACHMENT
x
y
20
GL_NEAREST
GL_NEAREST
GL_DEPTH24_STENCIL8
checkFBO fbo
return (fbo, (TO to1, TO to2))
@@ -155,7 +186,7 @@ resizeShadowFBO x y (fbo, (oldto1, oldto2)) = do
-- return (fbo, (TO to1, TO to2))
resizeFBOTO3 ::
(FBO, (TO, TO,TO)) ->
(FBO, (TO, TO, TO)) ->
Int ->
Int ->
-- | minification filter
@@ -168,8 +199,8 @@ resizeFBOTO3 ::
GLenum ->
-- | internal color format3
GLenum ->
IO (FBO, (TO, TO,TO))
resizeFBOTO3 (fbo, (toOld1, toOld2,told3)) xsize ysize minfilt magfilt inFormat1 inFormat2 inform3 = do
IO (FBO, (TO, TO, TO))
resizeFBOTO3 (fbo, (toOld1, toOld2, told3)) xsize ysize minfilt magfilt inFormat1 inFormat2 inform3 = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
mglDelete glDeleteTextures $ _unTO toOld1
mglDelete glDeleteTextures $ _unTO toOld2
@@ -180,7 +211,7 @@ resizeFBOTO3 (fbo, (toOld1, toOld2,told3)) xsize ysize minfilt magfilt inFormat1
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $ \ptr ->
glNamedFramebufferDrawBuffers (_unFBO fbo) 3 ptr
checkFBO fbo
return (fbo, (TO to1, TO to2,TO to3))
return (fbo, (TO to1, TO to2, TO to3))
resizeFBOTO ::
(FBO, TO) ->
@@ -223,7 +254,7 @@ initializeTexture2DArray fbo attachpoint x y z minfilt magfilt informat = do
glNamedFramebufferTexture (_unFBO fbo) attachpoint to1 0
return to1
getWindowSize :: Integral a => (Configuration -> ResFactor) -> Configuration -> (a,a)
getWindowSize f cfig = (g _windowX,g _windowY)
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)