isolated error. Map Rendering is missing Depth-Comp

- refactored a bit
This commit is contained in:
Nicole Dresselhaus 2014-08-29 21:18:49 +02:00
parent 581cb142bb
commit c10622d506
No known key found for this signature in database
GPG Key ID: BC16D887851A1A80
3 changed files with 41 additions and 37 deletions

View File

@ -308,11 +308,13 @@ adjustWindow = do
textureFilter Texture2D GL.$= ((Linear', Nothing), Linear') textureFilter Texture2D GL.$= ((Linear', Nothing), Linear')
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
-- MAP -- MAP
textureBinding Texture2D GL.$= Just maptexid textureBinding Texture2D GL.$= Just maptexid
textureFilter Texture2D GL.$= ((Linear', Nothing), Linear') textureFilter Texture2D GL.$= ((Linear', Nothing), Linear')
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
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
@ -320,6 +322,7 @@ adjustWindow = do
textureFilter Texture2D GL.$= ((Nearest,Nothing), Nearest) textureFilter Texture2D GL.$= ((Nearest,Nothing), Nearest)
texImage2D Texture2D GL.NoProxy 0 GL.DepthComponent16 (GL.TextureSize2D 2048 2048) 0 texImage2D Texture2D GL.NoProxy 0 GL.DepthComponent16 (GL.TextureSize2D 2048 2048) 0
(GL.PixelData GL.DepthComponent GL.UnsignedByte ptr) (GL.PixelData GL.DepthComponent GL.UnsignedByte ptr)
textureBinding Texture2D GL.$= Nothing
checkError "setting up HUD-Tex" checkError "setting up HUD-Tex"
return renderBuffer return renderBuffer
modify $ gl.glRenderbuffer .~ rb modify $ gl.glRenderbuffer .~ rb

View File

@ -9,6 +9,8 @@ import Graphics.Rendering.OpenGL.GL.StateVar
import Graphics.Rendering.OpenGL.GL.StringQueries import Graphics.Rendering.OpenGL.GL.StringQueries
import Graphics.Rendering.OpenGL.GLU.Errors import Graphics.Rendering.OpenGL.GLU.Errors
import Graphics.Rendering.OpenGL.GL.VertexArrayObjects import Graphics.Rendering.OpenGL.GL.VertexArrayObjects
import Graphics.Rendering.OpenGL.GL.VertexArrays
import Graphics.Rendering.OpenGL.GL.VertexSpec
import Graphics.Rendering.OpenGL.GL.BufferObjects import Graphics.Rendering.OpenGL.GL.BufferObjects
import Graphics.UI.SDL.Types (Texture) import Graphics.UI.SDL.Types (Texture)
import System.IO (hPutStrLn, stderr) import System.IO (hPutStrLn, stderr)
@ -180,3 +182,10 @@ withVBO b t a = do
ret <- a ret <- a
bindBuffer t $= Nothing bindBuffer t $= Nothing
return ret return ret
withVAA :: [AttribLocation] -> IO a -> IO a
withVAA atts action = do
mapM_ (\a -> vertexAttribArray a $= Enabled) atts
ret <- action
mapM_ (\a -> vertexAttribArray a $= Disabled) atts
return ret

View File

@ -287,8 +287,7 @@ initRendering = do
renderIQM :: IQM -> L.V3 CFloat -> L.V3 CFloat -> IO () renderIQM :: IQM -> L.V3 CFloat -> L.V3 CFloat -> IO ()
renderIQM m p@(L.V3 x y z) s@(L.V3 sx sy sz) = do renderIQM m p@(L.V3 x y z) s@(L.V3 sx sy sz) = do
withVAO (vertexArrayObject m) $ do withVAO (vertexArrayObject m) $ do
vertexAttribArray (AttribLocation 0) $= Enabled withVAA [(AttribLocation 0),(AttribLocation 1)] $ do
vertexAttribArray (AttribLocation 1) $= Enabled
checkError "setting array to enabled" checkError "setting array to enabled"
bindBuffer ElementArrayBuffer $= Just (triangleBufferObject m) bindBuffer ElementArrayBuffer $= Just (triangleBufferObject m)
checkError "bindBuffer" checkError "bindBuffer"
@ -297,7 +296,6 @@ renderIQM m p@(L.V3 x y z) s@(L.V3 sx sy sz) = do
drawElements Triangles n UnsignedInt nullPtr drawElements Triangles n UnsignedInt nullPtr
checkError "drawing model" checkError "drawing model"
bindBuffer ElementArrayBuffer $= Nothing bindBuffer ElementArrayBuffer $= Nothing
vertexAttribArray (AttribLocation 0) $= Disabled
checkError "unbind buffer" checkError "unbind buffer"
return () return ()
@ -322,13 +320,11 @@ drawMap = do
glUniform1f tli (fromIntegral tessFac) glUniform1f tli (fromIntegral tessFac)
glUniform1f tlo (fromIntegral tessFac) glUniform1f tlo (fromIntegral tessFac)
bindBuffer ArrayBuffer $= Just map' withVBO map' ArrayBuffer $ do
vertexAttribPointer ci $= fgColorIndex vertexAttribPointer ci $= fgColorIndex
vertexAttribArray ci $= Enabled
vertexAttribPointer ni $= fgNormalIndex vertexAttribPointer ni $= fgNormalIndex
vertexAttribArray ni $= Enabled
vertexAttribPointer vi $= fgVertexIndex vertexAttribPointer vi $= fgVertexIndex
vertexAttribArray vi $= Enabled withVAA [ci,ni,vi] $ do
checkError "beforeDraw" checkError "beforeDraw"
glPatchParameteri gl_PATCH_VERTICES 3 glPatchParameteri gl_PATCH_VERTICES 3
@ -339,10 +335,6 @@ drawMap = do
glDrawArrays gl_PATCHES 0 (fromIntegral numVert) glDrawArrays gl_PATCHES 0 (fromIntegral numVert)
checkError "draw map" checkError "draw map"
bindBuffer ArrayBuffer $= Nothing
vertexAttribArray ci $= Disabled
vertexAttribArray ni $= Disabled
vertexAttribArray vi $= Disabled
-- set sample 1 as target in renderbuffer -- set sample 1 as target in renderbuffer
{-framebufferRenderbuffer {-framebufferRenderbuffer
@ -405,16 +397,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]
@ -432,9 +424,9 @@ render = do
--TODO: needed? --TODO: needed?
mat33ToGPU sunnmap nmat "nmat" mat33ToGPU sunnmap nmat "nmat"
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"
@ -454,7 +446,7 @@ render = do
mapM_ renderObject (state ^. gl.glMap.mapObjects) mapM_ renderObject (state ^. gl.glMap.mapObjects)
checkError "draw mapobjects" checkError "draw mapobjects"
checkError "draw ShadowMap"-} checkError "draw ShadowMap"--}
---- RENDER MAP IN TEXTURE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ---- RENDER MAP IN TEXTURE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-- COLORMAP -- COLORMAP