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
+1 -6
View File
@@ -1,10 +1,5 @@
#version 450 core #version 450 core
in vec2 vTexPos; in vec2 vTexPos;
out vec4 fColor; out vec4 fColor;
layout(binding = 0) uniform sampler2D screenTexture; layout(binding = 0) uniform sampler2D screenTexture;
void main() { fColor = texture(screenTexture, vTexPos); }
void main()
{
fColor = texture(screenTexture, vTexPos);
}
+2 -3
View File
@@ -2,8 +2,7 @@
layout(location = 0) in vec2 pos; layout(location = 0) in vec2 pos;
layout(location = 1) in vec2 texPos; layout(location = 1) in vec2 texPos;
out vec2 vTexPos; out vec2 vTexPos;
void main() void main() {
{ gl_Position = vec4(pos, 0.0, 1.0);
gl_Position = vec4(pos,0,1);
vTexPos = texPos; vTexPos = texPos;
} }
+2 -2
View File
@@ -6,7 +6,7 @@ import Picture
winScale :: Configuration -> Picture -> Picture winScale :: Configuration -> Picture -> Picture
{-# INLINE winScale #-} {-# INLINE winScale #-}
winScale cfig = scale (2 / _windowX cfig) (2 / _windowY cfig) winScale cfig = scale (1 / _windowX cfig) (1 / _windowY cfig)
doWindowScale :: Configuration -> Point2 -> Point2 doWindowScale :: Configuration -> Point2 -> Point2
doWindowScale cfig (V2 x y) = V2 (x * 2 / _windowX cfig) (y * 2 / _windowY cfig) doWindowScale cfig (V2 x y) = V2 (x / _windowX cfig) (y / _windowY cfig)
+2 -4
View File
@@ -55,9 +55,7 @@ handleWindowMoveEvent mev =
handleResizeEvent :: WindowSizeChangedEventData -> Universe -> Universe handleResizeEvent :: WindowSizeChangedEventData -> Universe -> Universe
handleResizeEvent sev u = handleResizeEvent sev u =
u u
& uvConfig . windowX .~ fromIntegral x & uvIOEffects %~ ( (updatePreload . updateconfig) >=>)
& uvConfig . windowY .~ fromIntegral y
-- & uvIOEffects %~ sideEffectUpdatePreload
& uvIOEffects %~ (updatePreload >=>)
where where
updateconfig = (uvConfig . windowX .~ fromIntegral x) . (uvConfig . windowY .~ fromIntegral y)
V2 x y = windowSizeChangedEventSize sev V2 x y = windowSizeChangedEventSize sev
+20 -8
View File
@@ -103,10 +103,26 @@ doDrawing' win pdata u = do
, (_shapeEBO pdata, nIndices) , (_shapeEBO pdata, nIndices)
, (_silhouetteEBO pdata, nSilIndices) , (_silhouetteEBO pdata, nSilIndices)
] ]
-- draw the overlay
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboOverlay ._1 . unFBO)
withArray [0, 0, 0, 0] $ \ptr ->
glClearNamedFramebufferfv
(pdata ^. fboOverlay . _1 . unFBO)
GL_COLOR
0
ptr
glDepthFunc GL_ALWAYS
glDepthMask GL_FALSE
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
setViewport _graphics_overlay_resolution cfig
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. orthonormalMatUBO)
renderLayer FixedCoordLayer shadV layerCounts
-- set the coordinate uniform ready for drawing elements using world coordinates -- set the coordinate uniform ready for drawing elements using world coordinates
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO) glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO)
withArray (perspectiveMatrixb rot camzoom trans wins viewFroms) $ \ptr -> withArray (perspectiveMatrixb rot camzoom trans wins viewFroms) $ \ptr ->
glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr
renderLayer DebugLayer shadV layerCounts
setViewport _graphics_world_resolution cfig setViewport _graphics_world_resolution cfig
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase ._1 . unFBO) glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase ._1 . unFBO)
glDepthMask GL_TRUE glDepthMask GL_TRUE
@@ -335,7 +351,7 @@ doDrawing' win pdata u = do
drawShader (_fullscreenShader pdata) 4 drawShader (_fullscreenShader pdata) 4
--set viewport for radial distortion --set viewport for radial distortion
--setViewportSize (round winx) (round winy) --setViewportSize (round winx) (round winy)
setViewport _graphics_overlay_resolution cfig setViewport (const FullRes) cfig
glDepthFunc GL_ALWAYS glDepthFunc GL_ALWAYS
glBlendFunc GL_ONE GL_ZERO glBlendFunc GL_ONE GL_ZERO
-- perform any radial distortion -- perform any radial distortion
@@ -357,14 +373,10 @@ doDrawing' win pdata u = do
toList = (pdata ^. fboBase . _2 . _1) : concat (repeat [snd $ _fbo2 pdata, snd $ _fbo3 pdata]) toList = (pdata ^. fboBase . _2 . _1) : concat (repeat [snd $ _fbo2 pdata, snd $ _fbo3 pdata])
bindings = zipWith (>>) (map bindFBO fboList) (map (glBindTextureUnit 1 . _unTO) toList) bindings = zipWith (>>) (map bindFBO fboList) (map (glBindTextureUnit 1 . _unTO) toList)
zipWithM_ (>>) bindings $ map bindDrawDist rds zipWithM_ (>>) bindings $ map bindDrawDist rds
glDepthFunc GL_ALWAYS
glDepthMask GL_FALSE
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
renderLayer DebugLayer shadV layerCounts --draw overlay onto base buffer
-- draw overlay glBindTextureUnit 0 (pdata ^. fboOverlay . _2 . unTO)
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. orthonormalMatUBO) drawShader (_fullscreenShader pdata) 4
renderLayer FixedCoordLayer shadV layerCounts
SDL.glSwapWindow win SDL.glSwapWindow win
getDistortions :: Configuration -> World -> [Distortion] getDistortions :: Configuration -> World -> [Distortion]
+2
View File
@@ -13,6 +13,8 @@ import Dodge.Data.Universe
testStringInit :: Universe -> [String] testStringInit :: Universe -> [String]
testStringInit u = [show $ length $ lightsToRender (u ^. uvConfig) (u ^. uvWorld . cWorld . camPos) testStringInit u = [show $ length $ lightsToRender (u ^. uvConfig) (u ^. uvWorld . cWorld . camPos)
(u ^. uvWorld . cWorld . lWorld) (u ^. uvWorld . cWorld . lWorld)
, show $ u ^. uvConfig . windowX
, show $ u ^. uvConfig . windowY
, show $ u ^. uvWorld . input . scrollTestInt , show $ u ^. uvWorld . input . scrollTestInt
] ]
--[show $ u ^? uvWorld . hud . hudElement . diSections . sssExtra . sssSelPos . _Just] --[show $ u ^? uvWorld . hud . hudElement . diSections . sssExtra . sssSelPos . _Just]
+53 -22
View File
@@ -7,15 +7,15 @@ module Framebuffer.Update (
sizeFBOs, sizeFBOs,
) where ) where
import Dodge.Data.Config
import Shader.Data
import Framebuffer.Check
import Control.Lens import Control.Lens
import Control.Monad import Control.Monad
import Data.Preload.Render import Data.Preload.Render
import Dodge.Data.Config
import Foreign.Marshal.Array import Foreign.Marshal.Array
import Framebuffer.Check
import GLHelp import GLHelp
import Graphics.GL.Core45 import Graphics.GL.Core45
import Shader.Data
import Unsafe.Coerce import Unsafe.Coerce
sizeFBOs :: sizeFBOs ::
@@ -24,28 +24,50 @@ sizeFBOs ::
IO RenderData IO RenderData
sizeFBOs cfig rdata = sizeFBOs cfig rdata =
uncurry (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _graphics_world_resolution cfig) uncurry (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _graphics_world_resolution cfig)
>> uncurry updateFBOTO3 (getWindowSize _graphics_world_resolution cfig) >> foldM
GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F GL_RGBA16F rdata fboBase ( uncurry
>>= flip ( uncurry updateFBOTO3 (getWindowSize _graphics_world_resolution cfig) updateFBOTO3
GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F GL_RGBA16F) fboCloud (getWindowSize _graphics_world_resolution cfig)
>>= flip ( uncurry updateFBOTO (getWindowSize _graphics_world_resolution cfig) GL_NEAREST
GL_NEAREST GL_NEAREST GL_RGBA8) fboLighting GL_NEAREST
>>= GL_RGBA8
ffoldM GL_RGBA16F
(uncurry updateFBOTO (getWindowSize _graphics_world_resolution cfig) GL_RGBA16F
GL_LINEAR_MIPMAP_LINEAR GL_LINEAR 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] [fboBloom, fboPos]
>>= >>= ffoldM
ffoldM (uncurry updateFBOTO (getWindowSize _graphics_overlay_resolution cfig) GL_LINEAR GL_NEAREST GL_RGBA8)
(uncurry updateFBOTO (getWindowSize _graphics_overlay_resolution cfig) GL_NEAREST GL_NEAREST GL_RGBA8) [fbo2, fbo3, fboOverlay]
[fbo2, fbo3]
>>= ffoldM >>= ffoldM
(uncurry updateFBOTO (getWindowSize _graphics_downsize_resolution cfig) GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F) (uncurry updateFBOTO (getWindowSize _graphics_downsize_resolution cfig) GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F)
[fboHalf1, fboHalf2, fboHalf3] [fboHalf1, fboHalf2, fboHalf3]
>>= resizeShadowFBO' cfig >>= resizeShadowFBO' cfig
ffoldM :: (Foldable t, Monad m) => ffoldM ::
(a1 -> a2 -> m a1) -> t a2 -> a1 -> m a1 (Foldable t, Monad m) =>
(a1 -> a2 -> m a1) ->
t a2 ->
a1 ->
m a1
ffoldM f = flip $ foldM f ffoldM f = flip $ foldM f
resizeRBO :: resizeRBO ::
@@ -53,7 +75,8 @@ resizeRBO ::
GLsizei -> GLsizei ->
GLsizei -> GLsizei ->
IO () IO ()
resizeRBO rboName = glNamedRenderbufferStorage resizeRBO rboName =
glNamedRenderbufferStorage
rboName rboName
GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
@@ -125,8 +148,16 @@ resizeShadowFBO x y (fbo, (oldto1, oldto2)) = do
mglDelete glDeleteTextures $ _unTO oldto1 mglDelete glDeleteTextures $ _unTO oldto1
mglDelete glDeleteTextures $ _unTO oldto2 mglDelete glDeleteTextures $ _unTO oldto2
to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 20 GL_NEAREST GL_NEAREST GL_RGBA8 to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 20 GL_NEAREST GL_NEAREST GL_RGBA8
to2 <- initializeTexture2DArray to2 <-
fbo GL_DEPTH_STENCIL_ATTACHMENT x y 20 GL_NEAREST GL_NEAREST GL_DEPTH24_STENCIL8 initializeTexture2DArray
fbo
GL_DEPTH_STENCIL_ATTACHMENT
x
y
20
GL_NEAREST
GL_NEAREST
GL_DEPTH24_STENCIL8
checkFBO fbo checkFBO fbo
return (fbo, (TO to1, TO to2)) return (fbo, (TO to1, TO to2))
+3 -1
View File
@@ -37,7 +37,7 @@ preloadRender = do
glBindBufferBase GL_UNIFORM_BUFFER 0 theUBO glBindBufferBase GL_UNIFORM_BUFFER 0 theUBO
orthonormalUBO <- mglCreate glCreateBuffers orthonormalUBO <- mglCreate glCreateBuffers
withArray (isoMatrix 0 1 (V2 0 0) (V2 2 2)) $ \ptr -> withArray (isoMatrix 0 1 (V2 0 0) (V2 1 1)) $ \ptr ->
glNamedBufferStorage orthonormalUBO 64 ptr 0 glNamedBufferStorage orthonormalUBO 64 ptr 0
lightsubo <- mglCreate glCreateBuffers lightsubo <- mglCreate glCreateBuffers
@@ -84,6 +84,8 @@ preloadRender = do
cslist <- cslist <-
makeShaderVBO "picture/charArray" [vert, frag] [3, 4, 4] pmTriangles makeShaderVBO "picture/charArray" [vert, frag] [3, 4, 4] pmTriangles
initTexture2DArray 50 "data/texture/charMapVertBig.png" 2 32 64 95 GL_NEAREST_MIPMAP_LINEAR GL_LINEAR initTexture2DArray 50 "data/texture/charMapVertBig.png" 2 32 64 95 GL_NEAREST_MIPMAP_LINEAR GL_LINEAR
--initTexture2DArray 50 "data/texture/charMapVertBig.png" 2 32 64 95 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR
--initTexture2DArray 50 "data/texture/charMapVertBig.png" 2 32 64 95 GL_LINEAR_MIPMAP_NEAREST GL_LINEAR
screentexturevbo <- mglCreate glCreateBuffers screentexturevbo <- mglCreate glCreateBuffers
withArray (concat cornerList) $ \ptr -> withArray (concat cornerList) $ \ptr ->