added depth-buffer to map
This commit is contained in:
parent
0e13d1c5ba
commit
28e5f47596
18
src/Main.hs
18
src/Main.hs
@ -90,8 +90,9 @@ main = do
|
|||||||
initRendering
|
initRendering
|
||||||
--generate map vertices
|
--generate map vertices
|
||||||
curMap <- exportedMap
|
curMap <- exportedMap
|
||||||
(glMap', tex) <- initMapShader 4 =<< getMapBufferObject curMap
|
(glMap', tex, dtex) <- initMapShader 4 =<< getMapBufferObject curMap
|
||||||
tex' <- newTVarIO tex
|
tex' <- newTVarIO tex
|
||||||
|
dtex' <- newTVarIO dtex
|
||||||
eventQueue <- newTQueueIO :: IO (TQueue SDL.Event)
|
eventQueue <- newTQueueIO :: IO (TQueue SDL.Event)
|
||||||
now <- getCurrentTime
|
now <- getCurrentTime
|
||||||
--font <- TTF.openFont "fonts/ttf-04B_03B_/04B_03B_.TTF" 10
|
--font <- TTF.openFont "fonts/ttf-04B_03B_/04B_03B_.TTF" 10
|
||||||
@ -143,6 +144,7 @@ main = do
|
|||||||
}
|
}
|
||||||
, _camera = cam'
|
, _camera = cam'
|
||||||
, _mapTexture = tex'
|
, _mapTexture = tex'
|
||||||
|
, _mapDepthTexture = dtex'
|
||||||
, _camStack = camStack'
|
, _camStack = camStack'
|
||||||
, _keyboard = KeyboardState
|
, _keyboard = KeyboardState
|
||||||
{ _arrowsPressed = aks
|
{ _arrowsPressed = aks
|
||||||
@ -296,7 +298,9 @@ adjustWindow = do
|
|||||||
|
|
||||||
let hudtexid = state ^. gl.glHud.hudTexture
|
let hudtexid = state ^. gl.glHud.hudTexture
|
||||||
smaptexid = state ^. gl.glMap.shadowMapTexture
|
smaptexid = state ^. gl.glMap.shadowMapTexture
|
||||||
maptexid <- liftIO $ readTVarIO (state ^. mapTexture)
|
maptexid <- readTVarIO (state ^. mapTexture)
|
||||||
|
mapdepthtexid <- readTVarIO (state ^. mapDepthTexture)
|
||||||
|
-- create & clear textures for hud & background (map)
|
||||||
allocaBytes (fbWidth*fbHeight*4) $ \ptr -> do
|
allocaBytes (fbWidth*fbHeight*4) $ \ptr -> do
|
||||||
--default to ugly pink to see if
|
--default to ugly pink to see if
|
||||||
--somethings go wrong.
|
--somethings go wrong.
|
||||||
@ -315,6 +319,16 @@ adjustWindow = do
|
|||||||
texImage2D Texture2D GL.NoProxy 0 RGBA8 (GL.TextureSize2D fbCWidth fbCHeight) 0
|
texImage2D Texture2D GL.NoProxy 0 RGBA8 (GL.TextureSize2D fbCWidth fbCHeight) 0
|
||||||
(GL.PixelData GL.RGBA GL.UnsignedByte ptr)
|
(GL.PixelData GL.RGBA GL.UnsignedByte ptr)
|
||||||
textureBinding Texture2D GL.$= Nothing
|
textureBinding Texture2D GL.$= Nothing
|
||||||
|
-- create & clear map depth texture
|
||||||
|
allocaBytes (fbWidth*fbHeight) $ \ptr -> do
|
||||||
|
let smapdata = genColorData (fbWidth*fbHeight) [0]
|
||||||
|
pokeArray ptr smapdata
|
||||||
|
textureBinding Texture2D GL.$= Just mapdepthtexid
|
||||||
|
textureFilter Texture2D GL.$= ((Linear', Nothing), Linear')
|
||||||
|
texImage2D Texture2D GL.NoProxy 0 GL.DepthComponent16 (GL.TextureSize2D fbCWidth fbCHeight) 0
|
||||||
|
(GL.PixelData GL.DepthComponent GL.UnsignedByte ptr)
|
||||||
|
textureBinding Texture2D GL.$= Nothing
|
||||||
|
-- create & clear depth texture for shadows
|
||||||
allocaBytes (2048*2048) $ \ptr -> do
|
allocaBytes (2048*2048) $ \ptr -> do
|
||||||
let smapdata = genColorData (2048*2048) [0]
|
let smapdata = genColorData (2048*2048) [0]
|
||||||
pokeArray ptr smapdata
|
pokeArray ptr smapdata
|
||||||
|
@ -62,7 +62,7 @@ initBuffer varray =
|
|||||||
initMapShader ::
|
initMapShader ::
|
||||||
Int -- ^ initial Tessallation-Factor
|
Int -- ^ initial Tessallation-Factor
|
||||||
-> (BufferObject,NumArrayIndices) -- ^ Buffer with Data and DataDescriptor
|
-> (BufferObject,NumArrayIndices) -- ^ Buffer with Data and DataDescriptor
|
||||||
-> IO (GLMapState, TextureObject)
|
-> IO (GLMapState, TextureObject, TextureObject)
|
||||||
initMapShader tessFac (buf, vertDes) = do
|
initMapShader tessFac (buf, vertDes) = do
|
||||||
! vertexSource <- B.readFile mapVertexShaderFile
|
! vertexSource <- B.readFile mapVertexShaderFile
|
||||||
! tessControlSource <- B.readFile mapTessControlShaderFile
|
! tessControlSource <- B.readFile mapTessControlShaderFile
|
||||||
@ -122,6 +122,7 @@ initMapShader tessFac (buf, vertDes) = do
|
|||||||
putStrLn $ unlines ["Map-Indices: ", show (colorIndex, normalIndex, vertexIndex)]
|
putStrLn $ unlines ["Map-Indices: ", show (colorIndex, normalIndex, vertexIndex)]
|
||||||
|
|
||||||
tex <- genObjectName
|
tex <- genObjectName
|
||||||
|
dtex <- genObjectName
|
||||||
overTex <- genObjectName
|
overTex <- genObjectName
|
||||||
|
|
||||||
textures <- genObjectNames 6
|
textures <- genObjectNames 6
|
||||||
@ -224,7 +225,7 @@ initMapShader tessFac (buf, vertDes) = do
|
|||||||
, _mapObjects = objs
|
, _mapObjects = objs
|
||||||
, _objectProgram = objProgram
|
, _objectProgram = objProgram
|
||||||
, _shadowMapProgram = shadowProgram
|
, _shadowMapProgram = shadowProgram
|
||||||
}, tex)
|
}, tex, dtex)
|
||||||
|
|
||||||
initHud :: IO GLHud
|
initHud :: IO GLHud
|
||||||
initHud = do
|
initHud = do
|
||||||
@ -397,16 +398,16 @@ render = do
|
|||||||
(state ^. gl.glRenderbuffer)-}
|
(state ^. gl.glRenderbuffer)-}
|
||||||
|
|
||||||
---- RENDER SHADOWMAP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
---- RENDER SHADOWMAP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||||
liftIO $ do
|
{- liftIO $ do
|
||||||
-- textureBinding Texture2D $= Just (state ^. gl.glMap.shadowMapTexture)
|
textureBinding Texture2D $= Just (state ^. gl.glMap.shadowMapTexture)
|
||||||
{- framebufferTexture2D
|
framebufferTexture2D
|
||||||
Framebuffer
|
Framebuffer
|
||||||
DepthAttachment
|
DepthAttachment
|
||||||
Texture2D
|
Texture2D
|
||||||
(state ^. gl.glMap.shadowMapTexture)
|
(state ^. gl.glMap.shadowMapTexture)
|
||||||
0-}
|
0
|
||||||
|
|
||||||
-- drawBuffer $= NoBuffers --color-buffer is not needed but must(?) be set up
|
drawBuffer $= NoBuffers --color-buffer is not needed but must(?) be set up
|
||||||
checkError "setup Render-Target"
|
checkError "setup Render-Target"
|
||||||
|
|
||||||
clear [DepthBuffer]
|
clear [DepthBuffer]
|
||||||
@ -426,7 +427,7 @@ render = do
|
|||||||
|
|
||||||
-- drawMap
|
-- drawMap
|
||||||
|
|
||||||
{- liftIO $ do
|
liftIO $ do
|
||||||
---- RENDER MAPOBJECTS --------------------------------------------
|
---- RENDER MAPOBJECTS --------------------------------------------
|
||||||
currentProgram $= Just (state ^. gl.glMap.objectProgram)
|
currentProgram $= Just (state ^. gl.glMap.objectProgram)
|
||||||
checkError "setting up shadowmap-program"
|
checkError "setting up shadowmap-program"
|
||||||
@ -453,14 +454,22 @@ render = do
|
|||||||
liftIO $ do
|
liftIO $ do
|
||||||
{-bindFramebuffer Framebuffer $= defaultFramebufferObject
|
{-bindFramebuffer Framebuffer $= defaultFramebufferObject
|
||||||
drawBuffer $= BackBuffers-}
|
drawBuffer $= BackBuffers-}
|
||||||
tex <- liftIO $ readTVarIO (state ^. mapTexture)
|
tex <- readTVarIO (state ^. mapTexture)
|
||||||
textureBinding Texture2D $= Just tex
|
dtex <- readTVarIO (state ^. mapDepthTexture)
|
||||||
|
-- add color to texture target
|
||||||
framebufferTexture2D
|
framebufferTexture2D
|
||||||
Framebuffer
|
Framebuffer
|
||||||
(ColorAttachment 0)
|
(ColorAttachment 0)
|
||||||
Texture2D
|
Texture2D
|
||||||
tex
|
tex
|
||||||
0
|
0
|
||||||
|
-- add depth to texture target
|
||||||
|
framebufferTexture2D
|
||||||
|
Framebuffer
|
||||||
|
DepthAttachment
|
||||||
|
Texture2D
|
||||||
|
dtex
|
||||||
|
0
|
||||||
|
|
||||||
-- Render to FrameBufferObject
|
-- Render to FrameBufferObject
|
||||||
drawBuffers $= [FBOColorAttachment 0]
|
drawBuffers $= [FBOColorAttachment 0]
|
||||||
@ -512,7 +521,7 @@ render = do
|
|||||||
uniform (hud ^. hudTexIndex) $= Index1 (0::GLint)
|
uniform (hud ^. hudTexIndex) $= Index1 (0::GLint)
|
||||||
|
|
||||||
activeTexture $= TextureUnit 1
|
activeTexture $= TextureUnit 1
|
||||||
tex <- liftIO $ readTVarIO (state ^. mapTexture)
|
tex <- readTVarIO (state ^. mapTexture)
|
||||||
textureBinding Texture2D $= Just tex
|
textureBinding Texture2D $= Just tex
|
||||||
uniform (hud ^. hudBackIndex) $= Index1 (1::GLint)
|
uniform (hud ^. hudBackIndex) $= Index1 (1::GLint)
|
||||||
|
|
||||||
|
@ -174,6 +174,7 @@ data State = State
|
|||||||
{ _window :: !WindowState
|
{ _window :: !WindowState
|
||||||
, _camera :: TVar CameraState
|
, _camera :: TVar CameraState
|
||||||
, _mapTexture :: TVar TextureObject
|
, _mapTexture :: TVar TextureObject
|
||||||
|
, _mapDepthTexture :: TVar TextureObject
|
||||||
, _camStack :: (Map.HashMap UIId (TVar CameraState, TVar TextureObject))
|
, _camStack :: (Map.HashMap UIId (TVar CameraState, TVar TextureObject))
|
||||||
, _io :: !IOState
|
, _io :: !IOState
|
||||||
, _keyboard :: !KeyboardState
|
, _keyboard :: !KeyboardState
|
||||||
|
Loading…
Reference in New Issue
Block a user