Remove renderbuffer from ping-pong framebuffers

This commit is contained in:
jgk
2021-07-11 17:56:43 +02:00
parent 26c6c3e426
commit 75254cd3e4
5 changed files with 17 additions and 87 deletions
+2 -2
View File
@@ -26,8 +26,8 @@ data RenderData = RenderData
, _spareFBO :: FramebufferObject
, _fboTexture :: TextureObject
, _fboRenderbufferObject :: RenderbufferObject
, _fbo2 :: (FramebufferObject, TextureObject, RenderbufferObject)
, _fbo3 :: (FramebufferObject, TextureObject, RenderbufferObject)
, _fbo2 :: (FramebufferObject, TextureObject)
, _fbo3 :: (FramebufferObject, TextureObject)
, _fboFourth1 :: (FramebufferObject, TextureObject)
, _fboFourth2 :: (FramebufferObject, TextureObject)
, _fboBase :: (FramebufferObject, TextureObject)
+3 -30
View File
@@ -54,7 +54,6 @@ doDrawing pdata w = do
--viewFroms@(viewFromx,viewFromy) = _cameraViewFrom w
viewFroms = _cameraViewFrom w
pic = worldPictures w
-- bind wall points and colors to vbo
nWalls <- F.foldM (pokeShader $ _wallTextureShader pdata) (map Render22x4 wallPointsCol)
bindShaderBuffers [_wallTextureShader pdata] [nWalls]
@@ -143,7 +142,7 @@ doDrawing pdata w = do
depthFunc $= Just Always
blendFunc $= (One,Zero)
-- perform any radial distortion
case _radDistortion w of
[] -> do
bindTO $ snd $ _fboBase pdata
@@ -156,32 +155,13 @@ doDrawing pdata w = do
_ <- F.foldM (pokeShader $ _barrelShader pdata) [Render2221 distParam]
bindShaderBuffers [_barrelShader pdata] [1]
drawShader (_barrelShader pdata) 1
fboList = take (length rds - 1) (concat (repeat [fst3 $ _fbo2 pdata,fst3 $ _fbo3 pdata]))
fboList = take (length rds - 1) (concat (repeat [fst $ _fbo2 pdata,fst $ _fbo3 pdata]))
++ [defaultFramebufferObject]
toList = snd (_fboBase pdata) : concat (repeat [snd3 $ _fbo2 pdata,snd3 $ _fbo3 pdata])
toList = snd (_fboBase pdata) : concat (repeat [snd $ _fbo2 pdata,snd $ _fbo3 pdata])
bindings = zipWith (>>) (map bindFBO fboList) (map bindTO toList)
activeTexture $= TextureUnit 1
sequence_ $ zipWith (>>) bindings $ map bindDrawDist rds
activeTexture $= TextureUnit 0
--activeTexture $= TextureUnit 1
--bindTO $ snd $ _fboBase pdata
--let fbolist =
--let bindDrawDist :: (Point2,Point2,Point2,Float) -> IO ()
-- bindDrawDist distParam = do
-- _ <- F.foldM (pokeShader $ _barrelShader pdata) [Render2221 distParam]
-- bindShaderBuffers [_barrelShader pdata] [1]
-- drawShader (_barrelShader pdata) 1
--sequence_ $ zipWith (>>)
-- (map bindFBO $ concat $ repeat [fst3 $ _fbo2 pdata, fst3 $ _fbo3 pdata])
-- $ zipWith (>>)
-- (map bindDrawDist (_radDistortion w) ++ [activeTexture $= TextureUnit 0])
-- (map bindTO $ concat $ repeat [snd3 $ _fbo2 pdata, snd3 $ _fbo3 pdata])
--bindFramebuffer Framebuffer $= defaultFramebufferObject
----bufferUBO $ perspectiveMatrixb rot camzoom trans wins viewFroms
--drawShader (_fullscreenShader pdata) 4
-- draw overlay
bufferUBO $ isoMatrix 0 1 (0,0) (2,2)
--depthFunc $= Just Always
@@ -199,11 +179,6 @@ bindTO t = textureBinding Texture2D $= Just t
bindFBO :: FramebufferObject -> IO ()
bindFBO fb = bindFramebuffer Framebuffer $= fb
fst3 :: (a,b,c) -> a
fst3 (x,_,_) = x
snd3 :: (a,b,c) -> b
snd3 (_,x,_) = x
--------------------------------------------------------------------------------
-- note: currently assume there is only one UBO, we only bind it once at setup
bufferUBO :: [Float] -> IO ()
@@ -213,7 +188,6 @@ bufferUBO mat = withArray mat $ \ptr ->
renderBlankWalls
:: RenderData
-> Int -- ^ number of walls
-- -> GLmatrix GLfloat
-> IO ()
renderBlankWalls pdata nWalls = do
cullFace $= Just Back
@@ -223,7 +197,6 @@ renderBlankWalls pdata nWalls = do
renderWindows
:: RenderData
-> [((Point2,Point2),Point4)] -- ^ List: wall positions and color
-- -> GLmatrix GLfloat
-> IO ()
renderWindows pdata wps = do
n <- F.foldM (pokeShader $ _wallBlankShader pdata) (map Render22x4 wps)
+2 -2
View File
@@ -95,8 +95,8 @@ preloadRender = do
bindShaderBuffers [fsShad,fullscreenAlphaHalveShad] [4,4]
-- framebuffer for lighting
(fbo,fboTO,fboRBO) <- setupFramebufferWithStencil
framebuf2 <- setupFramebufferWithStencil
framebuf3 <- setupFramebufferWithStencil
framebuf2 <- setupTextureFramebuffer 600 600
framebuf3 <- setupTextureFramebuffer 600 600
rboLightingName <- genObjectName
bindRenderbuffer Renderbuffer $= rboLightingName
+2 -22
View File
@@ -32,8 +32,8 @@ resizeSpareFBO xsize ysize xfull yfull pdata = do
framebufferRenderbuffer Framebuffer DepthStencilAttachment Renderbuffer fboRBO
fboStatus <- framebufferStatus Framebuffer
putStrLn $ "after resize, framebuffer status:" ++ show fboStatus
resizeTextureFBO (_fbo2 rdata) xfull yfull
resizeTextureFBO (_fbo3 rdata) xfull yfull
resizeFBOTO (_fbo2 rdata) xfull yfull
resizeFBOTO (_fbo3 rdata) xfull yfull
resizeRBO (_rboBaseBloom rdata) xfull yfull
resizeFBOTO (_fboBase rdata) xfull yfull
resizeFBOTO (_fboBloom rdata) xfull yfull
@@ -43,26 +43,6 @@ resizeSpareFBO xsize ysize xfull yfull pdata = do
return pdata
resizeTextureFBO
:: (FramebufferObject , TextureObject, RenderbufferObject)
-> Int
-> Int
-> IO ()
resizeTextureFBO (fboName,fboTO,fboRBO) xsize ysize = do
let xsize' = fromIntegral xsize
ysize' = fromIntegral ysize
bindFramebuffer Framebuffer $= fboName
textureBinding Texture2D $= Just fboTO
texImage2D Texture2D NoProxy 0 RGBA8 (TextureSize2D xsize' ysize') 0 (PixelData RGBA UnsignedByte nullPtr)
framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D fboTO 0
bindRenderbuffer Renderbuffer $= fboRBO
renderbufferStorage Renderbuffer Depth24Stencil8 (RenderbufferSize xsize' ysize')
framebufferRenderbuffer Framebuffer DepthStencilAttachment Renderbuffer fboRBO
fboStatus <- framebufferStatus Framebuffer
putStrLn $ "after resize, framebuffer status:" ++ show fboStatus
resizeRBO
:: RenderbufferObject
-> Int
+8 -31
View File
@@ -18,46 +18,23 @@ import qualified Control.Foldl as F
import Foreign hiding (rotate)
import Graphics.Rendering.OpenGL hiding (Line,translate,scale,imageHeight,Polygon,Color,T)
--import Data.Foldable
import Data.Tuple.Extra
--import Data.Tuple.Extra
--import qualified Data.IntMap.Strict as IM
import qualified SDL
--setWallDepth
-- :: RenderData
-- -> [(Point2,Point2)] -- ^ Wall points
-- -> (Float,Float) -- ^ View from point
-- -> IO Word32
--setWallDepth pdata wallPoints (viewFromx,viewFromy) = do
-- startTicks <- SDL.ticks
-- colorMask $= Color4 Disabled Disabled Disabled Disabled
-- nWalls <- F.foldM (pokeShader $ _lightingOccludeShader pdata) (map Render22 wallPoints)
-- bindShaderBuffers [_lightingOccludeShader pdata] [nWalls]
--
-- currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
-- -- reseting this uniform appears to be necessary
-- uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
-- $= Vector2 viewFromx viewFromy
---- cullFace $= Just Front
-- drawShader (_lightingOccludeShader pdata) nWalls
-- colorMask $= Color4 Enabled Enabled Enabled Enabled
-- endTicks <- SDL.ticks
-- return $ endTicks - startTicks
divideSize :: Int -> Size -> Size
divideSize i (Size x y) = Size (div x $ fromIntegral i) (div y $ fromIntegral i)
sizeToTexSize :: Size -> TextureSize2D
sizeToTexSize (Size x y) = TextureSize2D x y
{- |
Determine where light is shining in the world.
-}
{- | Determine where light is shining in the world. -}
createLightMap
:: RenderData
-> Int -- Resolution division
-> [(Point3,Float,Float)] -- Lights
-> [Polyhedra] -- foreground geometry
-> [Point2]
-> [Point2] -- ^ screen polygon
-> Int -- ^ number of walls
-> IO ()
createLightMap pdata resDiv lightPoints fpics scPol nWalls = do
@@ -156,16 +133,16 @@ createLightMap pdata resDiv lightPoints fpics scPol nWalls = do
-- disable depth testing for blurring
{- |
Blur between two framebuffers.
Assumes no depth testing is done (depthFunc %= Just Always).
Assumes no depth testing is done
-}
pingPongBlur :: RenderData -> IO ()
pingPongBlur pdata = do
bindFramebuffer Framebuffer $= fst3 (_fbo3 pdata)
textureBinding Texture2D $= Just (snd3 $ _fbo2 pdata)
bindFramebuffer Framebuffer $= fst (_fbo3 pdata)
textureBinding Texture2D $= Just (snd $ _fbo2 pdata)
drawShader (_bloomBlurShader pdata) 4
bindFramebuffer Framebuffer $= fst3 (_fbo2 pdata)
textureBinding Texture2D $= Just (snd3 $ _fbo3 pdata)
bindFramebuffer Framebuffer $= fst (_fbo2 pdata)
textureBinding Texture2D $= Just (snd $ _fbo3 pdata)
drawShader (_bloomBlurShader pdata) 4
-- assumes that vertices have already been sent to the shader