This commit is contained in:
2023-03-09 18:48:31 +00:00
parent e279e51b82
commit 487a904584
+34 -48
View File
@@ -105,26 +105,16 @@ resizeShadowFBO ::
Int -> Int ->
Int -> Int ->
IO (FBO, (TO, TO)) IO (FBO, (TO, TO))
resizeShadowFBO (fboname, (oldto1, oldto2)) xsize ysize = do resizeShadowFBO (fbo, (oldto1, oldto2)) x y = do
let xsize' = fromIntegral xsize glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
ysize' = fromIntegral ysize
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fboname)
mglDelete glDeleteTextures $ _unTO oldto1 mglDelete glDeleteTextures $ _unTO oldto1
mglDelete glDeleteTextures $ _unTO oldto2 mglDelete glDeleteTextures $ _unTO oldto2
to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D_ARRAY) to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 10 GL_NEAREST GL_NEAREST GL_RGBA8
to2 <- mglCreate (glCreateTextures GL_TEXTURE_2D_ARRAY) to2 <- initializeTexture2DArray
glTextureStorage3D to1 1 GL_RGBA8 xsize' ysize' 10 fbo GL_DEPTH_STENCIL_ATTACHMENT x y 10 GL_NEAREST GL_NEAREST GL_DEPTH24_STENCIL8
glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce GL_NEAREST) checkFBO fbo
glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce GL_NEAREST) return (fbo, (TO to1, TO to2))
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))
-- this currently has one mipmap level?
resizeFBOTO2 :: resizeFBOTO2 ::
(FBO, (TO, TO)) -> (FBO, (TO, TO)) ->
Int -> Int ->
@@ -138,26 +128,16 @@ resizeFBOTO2 ::
-- | internal color format2 -- | internal color format2
GLenum -> GLenum ->
IO (FBO, (TO, TO)) IO (FBO, (TO, TO))
resizeFBOTO2 (fboname, (toOld1, toOld2)) xsize ysize minfilt magfilt inFormat1 inFormat2 = do resizeFBOTO2 (fbo, (toOld1, toOld2)) xsize ysize minfilt magfilt inFormat1 inFormat2 = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fboname) glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
let xsize' = fromIntegral xsize
ysize' = fromIntegral ysize
mglDelete glDeleteTextures $ _unTO toOld1 mglDelete glDeleteTextures $ _unTO toOld1
mglDelete glDeleteTextures $ _unTO toOld2 mglDelete glDeleteTextures $ _unTO toOld2
to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D) to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt inFormat1
to2 <- mglCreate (glCreateTextures GL_TEXTURE_2D) to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt inFormat2
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
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $ \ptr -> withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $ \ptr ->
glNamedFramebufferDrawBuffers (_unFBO fboname) 2 ptr glNamedFramebufferDrawBuffers (_unFBO fbo) 2 ptr
checkFBO fboname checkFBO fbo
return (fboname, (TO to1, TO to2)) return (fbo, (TO to1, TO to2))
resizeFBOTO :: resizeFBOTO ::
(FBO, TO) -> (FBO, TO) ->
@@ -170,33 +150,39 @@ resizeFBOTO ::
-- | internal color format -- | internal color format
GLenum -> GLenum ->
IO (FBO, TO) IO (FBO, TO)
resizeFBOTO (fboname, oldto) xsize ysize minfilt magfilt inFormat = do resizeFBOTO (fbo, oldto) xsize ysize minfilt magfilt inFormat = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fboname) glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
let xsize' = fromIntegral xsize
ysize' = fromIntegral ysize
mglDelete glDeleteTextures $ _unTO oldto mglDelete glDeleteTextures $ _unTO oldto
to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D) to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt inFormat
glTextureStorage2D to1 1 inFormat xsize' ysize' checkFBO fbo
glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) return (fbo, TO to1)
glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
glNamedFramebufferTexture (_unFBO fboname) GL_COLOR_ATTACHMENT0 to1 0
checkFBO fboname
return (fboname, TO to1)
initializeTexture2D :: Int -> Int -> GLenum -> GLenum -> GLenum -> IO GLuint initializeTexture2D :: FBO -> GLenum -> Int -> Int -> GLenum -> GLenum -> GLenum -> IO GLuint
initializeTexture2D x y minfilt magfilt informat = do initializeTexture2D fbo attachpoint x y minfilt magfilt informat = do
let xsize' = fromIntegral x let xsize' = fromIntegral x
ysize' = fromIntegral y ysize' = fromIntegral y
to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D) to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D)
glTextureStorage2D to1 1 informat xsize' ysize' glTextureStorage2D to1 1 informat xsize' ysize'
glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt)
glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
glNamedFramebufferTexture (_unFBO fbo) attachpoint to1 0
return to1 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 -> IO ()
checkFBO fbo = do checkFBO fbo = do
fboStatus <- glCheckNamedFramebufferStatus (_unFBO fbo) GL_FRAMEBUFFER fboStatus <- glCheckNamedFramebufferStatus (_unFBO fbo) GL_FRAMEBUFFER
case fboStatus of case fboStatus of
36053 -> return () 36053 -> return () -- this should correspond to GL_COMPLETE or something
_ -> error $ "after resize, resizeFBOTO framebuffer status:" ++ show fboStatus _ -> error $ "after resize, resizeFBOTO framebuffer status:" ++ show fboStatus