From 487a904584225cf992965cd0a80f0481635d48c3 Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 9 Mar 2023 18:48:31 +0000 Subject: [PATCH] Cleanup --- src/Framebuffer/Update.hs | 82 ++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/src/Framebuffer/Update.hs b/src/Framebuffer/Update.hs index 3b40adc12..f8cd90356 100644 --- a/src/Framebuffer/Update.hs +++ b/src/Framebuffer/Update.hs @@ -105,26 +105,16 @@ resizeShadowFBO :: Int -> Int -> IO (FBO, (TO, TO)) -resizeShadowFBO (fboname, (oldto1, oldto2)) xsize ysize = do - let xsize' = fromIntegral xsize - ysize' = fromIntegral ysize - glBindFramebuffer GL_FRAMEBUFFER (_unFBO fboname) +resizeShadowFBO (fbo, (oldto1, oldto2)) x y = do + glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo) mglDelete glDeleteTextures $ _unTO oldto1 mglDelete glDeleteTextures $ _unTO oldto2 - to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D_ARRAY) - to2 <- mglCreate (glCreateTextures GL_TEXTURE_2D_ARRAY) - glTextureStorage3D to1 1 GL_RGBA8 xsize' ysize' 10 - glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce GL_NEAREST) - glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce GL_NEAREST) - glNamedFramebufferTexture (_unFBO fboname) GL_COLOR_ATTACHMENT0 to1 0 - glTextureStorage3D to2 1 GL_DEPTH24_STENCIL8 xsize' ysize' 10 - glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce GL_NEAREST) - glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce GL_NEAREST) - glNamedFramebufferTexture (_unFBO fboname) GL_DEPTH_STENCIL_ATTACHMENT to2 0 - checkFBO fboname - return (fboname, (TO to1, TO to2)) + to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 10 GL_NEAREST GL_NEAREST GL_RGBA8 + to2 <- initializeTexture2DArray + fbo GL_DEPTH_STENCIL_ATTACHMENT x y 10 GL_NEAREST GL_NEAREST GL_DEPTH24_STENCIL8 + checkFBO fbo + return (fbo, (TO to1, TO to2)) --- this currently has one mipmap level? resizeFBOTO2 :: (FBO, (TO, TO)) -> Int -> @@ -138,26 +128,16 @@ resizeFBOTO2 :: -- | internal color format2 GLenum -> IO (FBO, (TO, TO)) -resizeFBOTO2 (fboname, (toOld1, toOld2)) xsize ysize minfilt magfilt inFormat1 inFormat2 = do - glBindFramebuffer GL_FRAMEBUFFER (_unFBO fboname) - let xsize' = fromIntegral xsize - ysize' = fromIntegral ysize +resizeFBOTO2 (fbo, (toOld1, toOld2)) xsize ysize minfilt magfilt inFormat1 inFormat2 = do + glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo) mglDelete glDeleteTextures $ _unTO toOld1 mglDelete glDeleteTextures $ _unTO toOld2 - to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D) - to2 <- mglCreate (glCreateTextures GL_TEXTURE_2D) - glTextureStorage2D to1 1 inFormat1 xsize' ysize' - glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) - glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) - glNamedFramebufferTexture (_unFBO fboname) GL_COLOR_ATTACHMENT0 to1 0 - glTextureStorage2D to2 1 inFormat2 xsize' ysize' - glTextureParameteri to2 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) - glTextureParameteri to2 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) - glNamedFramebufferTexture (_unFBO fboname) GL_COLOR_ATTACHMENT1 to2 0 + to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt inFormat1 + to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt inFormat2 withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $ \ptr -> - glNamedFramebufferDrawBuffers (_unFBO fboname) 2 ptr - checkFBO fboname - return (fboname, (TO to1, TO to2)) + glNamedFramebufferDrawBuffers (_unFBO fbo) 2 ptr + checkFBO fbo + return (fbo, (TO to1, TO to2)) resizeFBOTO :: (FBO, TO) -> @@ -170,33 +150,39 @@ resizeFBOTO :: -- | internal color format GLenum -> IO (FBO, TO) -resizeFBOTO (fboname, oldto) xsize ysize minfilt magfilt inFormat = do - glBindFramebuffer GL_FRAMEBUFFER (_unFBO fboname) - let xsize' = fromIntegral xsize - ysize' = fromIntegral ysize +resizeFBOTO (fbo, oldto) xsize ysize minfilt magfilt inFormat = do + glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo) mglDelete glDeleteTextures $ _unTO oldto - to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D) - glTextureStorage2D to1 1 inFormat xsize' ysize' - glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) - glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) - glNamedFramebufferTexture (_unFBO fboname) GL_COLOR_ATTACHMENT0 to1 0 - checkFBO fboname - return (fboname, TO to1) + to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt inFormat + checkFBO fbo + return (fbo, TO to1) -initializeTexture2D :: Int -> Int -> GLenum -> GLenum -> GLenum -> IO GLuint -initializeTexture2D x y minfilt magfilt informat = do +initializeTexture2D :: FBO -> GLenum -> Int -> Int -> GLenum -> GLenum -> GLenum -> IO GLuint +initializeTexture2D fbo attachpoint x y minfilt magfilt informat = do let xsize' = fromIntegral x ysize' = fromIntegral y to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D) glTextureStorage2D to1 1 informat xsize' ysize' glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) + glNamedFramebufferTexture (_unFBO fbo) attachpoint to1 0 return to1 +initializeTexture2DArray :: FBO -> GLenum -> Int -> Int -> Int -> GLenum -> GLenum -> GLenum -> IO GLuint +initializeTexture2DArray fbo attachpoint x y z minfilt magfilt informat = do + let xsize = fromIntegral x + ysize = fromIntegral y + zsize = fromIntegral z + to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D_ARRAY) + glTextureStorage3D to1 1 informat xsize ysize zsize + glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) + glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) + glNamedFramebufferTexture (_unFBO fbo) attachpoint to1 0 + return to1 checkFBO :: FBO -> IO () checkFBO fbo = do fboStatus <- glCheckNamedFramebufferStatus (_unFBO fbo) GL_FRAMEBUFFER case fboStatus of - 36053 -> return () + 36053 -> return () -- this should correspond to GL_COMPLETE or something _ -> error $ "after resize, resizeFBOTO framebuffer status:" ++ show fboStatus