Cleanup shaders
This commit is contained in:
@@ -14,18 +14,15 @@ data RenderData = RenderData
|
||||
{ _shadWallShader :: GLuint
|
||||
, _lightingLineShadowShader :: GLuint
|
||||
, _lightingCapShader :: GLuint
|
||||
, _lightingTextureShader :: Shader
|
||||
, _lightingTextureShader :: GLuint
|
||||
, _ceilingStencilShader :: GLuint
|
||||
, _alphaDivideShader :: Shader
|
||||
-- , _windowShader :: Shader
|
||||
, _alphaDivideShader :: GLuint
|
||||
, _windowPullShader :: GLuint
|
||||
, _pullWallShader :: GLuint
|
||||
, _fullscreenShader :: GLuint
|
||||
, _transparencyCompShader :: Shader
|
||||
, _bloomBlurShader :: Shader
|
||||
, _colorBlurShader :: Shader
|
||||
, _transparencyCompShader :: GLuint
|
||||
, _bloomBlurShader :: GLuint
|
||||
, _barrelShader :: (Shader,VBO)
|
||||
, _grayscaleShader :: Shader
|
||||
, _shapeShader :: GLuint
|
||||
, _shapeEBO :: UintBO
|
||||
, _silhouetteEBO :: UintBO
|
||||
@@ -43,10 +40,6 @@ data RenderData = RenderData
|
||||
, _rboBaseBloom :: GLuint -- RenderbufferObject id
|
||||
, _matUBO :: GLuint -- BufferObject id
|
||||
, _lightUBO :: GLuint -- BufferObject id
|
||||
-- , _winSSBO :: GLuint
|
||||
-- , _wallSSBO :: GLuint
|
||||
-- , _shapeSSBO :: GLuint
|
||||
-- , _ishapeSSBO :: GLuint
|
||||
, _vboShapes :: VBO
|
||||
, _floorVBO :: VBO
|
||||
, _floorShader :: Shader
|
||||
@@ -56,7 +49,6 @@ data RenderData = RenderData
|
||||
, _wallVBO :: VBO
|
||||
, _cloudVBO :: VBO
|
||||
, _cloudShader :: GLuint
|
||||
, _screenTextureVAO :: VAO
|
||||
, _dummyVAO :: VAO
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -242,9 +242,10 @@ doDrawing' win pdata u = do
|
||||
-- withArray [0, 0, 0, 0] $
|
||||
-- glClearNamedFramebufferfv (pdata ^. fboHalf2 . _1 . unFBO) GL_COLOR 0
|
||||
-- glBlendFunc GL_ONE GL_ONE_MINUS_SRC_ALPHA
|
||||
drawShader (_bloomBlurShader pdata) 4
|
||||
glUseProgram (_bloomBlurShader pdata)
|
||||
glDrawArrays GL_TRIANGLES 0 6
|
||||
when (cfig ^. gr_bloom) $ do
|
||||
replicateM_ 2 $
|
||||
replicateM_ 1 $
|
||||
pingPongBetween
|
||||
(_fboHalf1 pdata)
|
||||
(_fboHalf2 pdata)
|
||||
@@ -317,8 +318,7 @@ doDrawing' win pdata u = do
|
||||
ptr
|
||||
glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _2 . unTO)
|
||||
glDepthMask GL_FALSE
|
||||
-- drawShader (pdata ^. alphaDivideShader) 4
|
||||
glUseProgram (pdata ^. alphaDivideShader . shaderUINT)
|
||||
glUseProgram (pdata ^. alphaDivideShader)
|
||||
glDrawArrays GL_TRIANGLES 0 6
|
||||
----draw lightmap for cloud buffer
|
||||
glDepthMask GL_TRUE
|
||||
@@ -370,7 +370,6 @@ doDrawing' win pdata u = do
|
||||
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
|
||||
|
||||
-- bind base buffer for drawing clouds and bloom
|
||||
--glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboBase pdata)))
|
||||
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
|
||||
|
||||
-- --draw shadowed clouds onto base buffer
|
||||
@@ -385,7 +384,10 @@ doDrawing' win pdata u = do
|
||||
glBindTextureUnit 2 (pdata ^. fboCloud . _2 . _1 . unTO)
|
||||
--glBindTextureUnit 3 (pdata ^. fboCloud . _2 . _2 . unTO)
|
||||
glBindTextureUnit 3 (pdata ^. fboPos . _2 . unTO)
|
||||
drawShader (_transparencyCompShader pdata) 4
|
||||
|
||||
--drawShader (_transparencyCompShader pdata) 4
|
||||
glUseProgram (pdata ^. transparencyCompShader)
|
||||
glDrawArrays GL_TRIANGLES 0 6
|
||||
|
||||
--Draw blurred bloom onto base buffer
|
||||
glEnable GL_BLEND
|
||||
|
||||
+33
-21
@@ -20,20 +20,29 @@ import Unsafe.Coerce
|
||||
sizeFBOs :: Config -> RenderData -> IO RenderData
|
||||
sizeFBOs cfig rdata =
|
||||
uncurry (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _gr_world_res cfig)
|
||||
>> foldM
|
||||
( uncurry
|
||||
updateFBOTO3
|
||||
(getWindowSize _gr_world_res cfig)
|
||||
GL_NEAREST
|
||||
GL_NEAREST
|
||||
GL_RGBA8
|
||||
GL_RGBA16F -- could possibly recover using depth in a clever way
|
||||
-- but probably not, because the projection matrix is
|
||||
-- not always on-center
|
||||
GL_RGBA16F -- make this smaller?
|
||||
)
|
||||
>> uncurry
|
||||
updateFBOTO3
|
||||
(getWindowSize _gr_world_res cfig)
|
||||
GL_NEAREST
|
||||
GL_NEAREST
|
||||
GL_RGBA8
|
||||
GL_RGBA16F -- could possibly recover using depth in a clever way
|
||||
-- but probably not, because the projection matrix is
|
||||
-- not always on-center
|
||||
GL_RGBA16F -- make this smaller?
|
||||
rdata
|
||||
[fboBase, fboCloud]
|
||||
fboBase
|
||||
>>= flip
|
||||
( uncurry
|
||||
updateFBOTO3
|
||||
(getWindowSize _gr_world_res cfig)
|
||||
GL_NEAREST
|
||||
GL_NEAREST
|
||||
GL_RGBA8
|
||||
GL_RGBA16F
|
||||
GL_RGBA16F
|
||||
)
|
||||
fboCloud
|
||||
>>= foldUpdateFBOTO
|
||||
_gr_world_res
|
||||
GL_NEAREST
|
||||
@@ -58,12 +67,15 @@ sizeFBOs cfig rdata =
|
||||
GL_LINEAR
|
||||
GL_RGBA16F
|
||||
[fboHalf1, fboHalf2]
|
||||
>>= flip (uncurry updateFBOTO2
|
||||
(getWindowSize _gr_world_res cfig)
|
||||
GL_NEAREST
|
||||
GL_NEAREST
|
||||
GL_RGBA8
|
||||
GL_RGBA16F)
|
||||
>>= flip
|
||||
( uncurry
|
||||
updateFBOTO2
|
||||
(getWindowSize _gr_world_res cfig)
|
||||
GL_NEAREST
|
||||
GL_NEAREST
|
||||
GL_RGBA8
|
||||
GL_RGBA16F
|
||||
)
|
||||
fboWindow
|
||||
where
|
||||
updateFBOTO' f = uncurry updateFBOTO (getWindowSize f cfig)
|
||||
@@ -202,8 +214,8 @@ resizeFBOTO (fbo, oldto) xsize ysize minfilt magfilt form = do
|
||||
checkFBO fbo
|
||||
return (fbo, TO to1)
|
||||
|
||||
initializeTexture2D
|
||||
:: FBO -> GLenum -> Int -> Int -> GLenum -> GLenum -> GLenum -> IO GLuint
|
||||
initializeTexture2D ::
|
||||
FBO -> GLenum -> Int -> Int -> GLenum -> GLenum -> GLenum -> IO GLuint
|
||||
initializeTexture2D fbo attachpoint x y minfilt magfilt form = do
|
||||
let xsize' = fromIntegral x
|
||||
ysize' = fromIntegral y
|
||||
|
||||
+11
-37
@@ -31,7 +31,7 @@ preloadRender = do
|
||||
putStrLn "Number cores available:"
|
||||
getNumCapabilities >>= print
|
||||
|
||||
-- set up uniform buffer object
|
||||
-- set up uniform buffer objects
|
||||
putStrLn "Setup UBO"
|
||||
theUBO <- mglCreate glCreateBuffers
|
||||
glNamedBufferStorage theUBO 64 nullPtr GL_DYNAMIC_STORAGE_BIT
|
||||
@@ -43,7 +43,7 @@ preloadRender = do
|
||||
|
||||
fulltexbo <- mglCreate glCreateBuffers
|
||||
let ftsize = fromIntegral $ sizeOf (0::Float) * 6 * 4
|
||||
withArray cornerList' $ \ptr ->
|
||||
withArray cornerList $ \ptr ->
|
||||
glNamedBufferStorage fulltexbo ftsize ptr 0
|
||||
glBindBufferBase GL_UNIFORM_BUFFER 2 fulltexbo
|
||||
|
||||
@@ -121,20 +121,12 @@ preloadRender = do
|
||||
-- GL_NEAREST_MIPMAP_LINEAR GL_LINEAR ?
|
||||
initTexture2DArray 50 "data/charMaps/cMap16x32.Custom.png" 2 16 32 256 GL_NEAREST GL_NEAREST
|
||||
putStrLn "Setup full screen shaders"
|
||||
(_, screentexturevao) <- setupStaticVBOVAO (toFloatVAs [2, 2]) (concat cornerList)
|
||||
alphadivideshader <- makeShaderUsingVAO "texture2D/alphaDivide" [vert, frag] pmTriangleStrip screentexturevao
|
||||
-- (_, screentexturevao) <- setupStaticVBOVAO (toFloatVAs [2, 2]) (concat cornerList)
|
||||
alphadivideshader <- makeSourcedShader "texture2D/alphaDivide" [vert, frag]
|
||||
fsShad <- makeSourcedShader "texture/simple" [vert, frag]
|
||||
transcompshader <-
|
||||
makeShaderUsingVAO
|
||||
"fullscreen/transparencyComp"
|
||||
[vert, frag]
|
||||
pmTriangleStrip
|
||||
screentexturevao
|
||||
bloomBlurShad <- makeShaderUsingVAO "texture/bloomBlur" [vert, frag] pmTriangleStrip screentexturevao
|
||||
colorBlurShad <- makeShaderUsingVAO "texture/colorBlur" [vert, frag] pmTriangleStrip screentexturevao
|
||||
grayscaleShad <- makeShaderUsingVAO "texture/grayscale" [vert, frag] pmTriangleStrip screentexturevao
|
||||
lightingTextureShad <-
|
||||
makeShaderUsingVAO "lighting/texture" [vert, frag] pmTriangleStrip screentexturevao
|
||||
transcompshader <- makeSourcedShader "fullscreen/transparencyComp" [vert, frag]
|
||||
bloomBlurShad <- makeSourcedShader "texture/bloomBlur" [vert, frag]
|
||||
lightingTextureShad <- makeSourcedShader "lighting/texture" [vert, frag]
|
||||
barrelShad <- makeShaderVBO "texture/barrel" [vert, geom, frag] (toFloatVAs [2, 2, 2, 1]) pmPoints
|
||||
-- blank wallShader
|
||||
putStrLn "Setup floor VBO, shader"
|
||||
@@ -154,21 +146,12 @@ preloadRender = do
|
||||
(toFloatVAs [3])
|
||||
pmTriangles
|
||||
chasmvbo
|
||||
-- putStrLn "Setup cloud VBO, shader"
|
||||
-- let cloudverxsizes = [4, 4, 4]
|
||||
-- cloudvbo <- setupVBO (floatSize * sum cloudverxsizes)
|
||||
-- (cloudshader, cloudebo) <-
|
||||
-- makeShaderEBO "cloud/basic" [vert, frag] (toFloatVAs cloudverxsizes) pmTriangles cloudvbo
|
||||
framebuf2 <- newTextureFramebuffer
|
||||
framebuf3 <- newTextureFramebuffer
|
||||
|
||||
putStrLn "Setup framebuffers"
|
||||
rboBaseBloomName <- mglCreate glCreateRenderbuffers
|
||||
glNamedRenderbufferStorage
|
||||
rboBaseBloomName
|
||||
GL_DEPTH24_STENCIL8
|
||||
800
|
||||
600
|
||||
glNamedRenderbufferStorage rboBaseBloomName GL_DEPTH24_STENCIL8 800 600
|
||||
|
||||
-- if adding to this list, recall you need to sizeFBOs
|
||||
fboBaseName <- setupFramebuffer3GivenStencil rboBaseBloomName
|
||||
@@ -203,9 +186,7 @@ preloadRender = do
|
||||
, _alphaDivideShader = alphadivideshader
|
||||
, _lightingTextureShader = lightingTextureShad
|
||||
, _bloomBlurShader = bloomBlurShad
|
||||
, _colorBlurShader = colorBlurShad
|
||||
, _barrelShader = barrelShad
|
||||
, _grayscaleShader = grayscaleShad
|
||||
, _fbo2 = framebuf2
|
||||
, _fbo3 = framebuf3
|
||||
, _fboHalf1 = fboHalf1Name
|
||||
@@ -228,20 +209,13 @@ preloadRender = do
|
||||
, _winVBO = winvbo
|
||||
, _cloudVBO = cloudvbo
|
||||
, _cloudShader = cloudshader
|
||||
, _screenTextureVAO = screentexturevao
|
||||
-- , _screenTextureVAO = screentexturevao
|
||||
, _dummyVAO = VAO dummyvao
|
||||
}
|
||||
|
||||
--------------------end preloadRender
|
||||
cornerList :: [[Float]]
|
||||
cornerList =
|
||||
[ [-1, 1, 0, 1]
|
||||
, [-1, -1, 0, 0]
|
||||
, [1, 1, 1, 1]
|
||||
, [1, -1, 1, 0]
|
||||
]
|
||||
cornerList' :: [Float]
|
||||
cornerList' = concat
|
||||
cornerList :: [Float]
|
||||
cornerList = concat
|
||||
[ bl, br, tl
|
||||
, tl, br, tr
|
||||
]
|
||||
|
||||
@@ -32,10 +32,5 @@ renderDataResizeUpdate cfig rdata = do
|
||||
(bh, bmid) = BS.breakSubstring "(" bbFrag
|
||||
(_, btt) = BS.breakSubstring ")" bmid
|
||||
bbFrag' = BS.append bh $ BS.append (BSC.pack $ '(' : show xsize ++ "," ++ show ysize) btt
|
||||
bbShad <-
|
||||
makeByteStringShaderUsingVAO
|
||||
"bloomBlur"
|
||||
[(vert, bbVert), (frag, bbFrag')]
|
||||
pmTriangleStrip
|
||||
(rdata ^. screenTextureVAO)
|
||||
bbShad <- makeShaderProgram "bloomBlur" [(vert, bbVert), (frag, bbFrag')]
|
||||
return rdata'{_bloomBlurShader = bbShad}
|
||||
|
||||
+8
-12
@@ -70,6 +70,7 @@ renderLightingNoShadows positiontexture normaltexture lightPoints pdata = do
|
||||
glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP
|
||||
glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP
|
||||
flip VFSM.mapM_ (VFSM.fromList lightPoints) $ \(V3 x y z, rad, V3 r g b) -> do
|
||||
withArray [x,y,z,1,r,g,b,rad] $ glNamedBufferSubData (pdata ^. lightUBO) 0 32
|
||||
glDepthFunc GL_LESS
|
||||
-- setup stencil
|
||||
glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE
|
||||
@@ -88,14 +89,8 @@ renderLightingNoShadows positiontexture normaltexture lightPoints pdata = do
|
||||
glBindTextureUnit 1 (normaltexture ^. unTO)
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
|
||||
glStencilFunc GL_EQUAL 0 255
|
||||
glUseProgram (ltextShad ^. shaderUINT)
|
||||
glUniform3f 0 x y z
|
||||
glUniform4f 1 r g b rad
|
||||
glBindVertexArray $ ltextShad ^. shaderVAO . vaoName
|
||||
glDrawArrays
|
||||
(_unPrimitiveMode (_shaderPrimitive ltextShad))
|
||||
0
|
||||
(fromIntegral (4 :: Int))
|
||||
glUseProgram ltextShad
|
||||
glDrawArrays GL_TRIANGLES 0 6
|
||||
--cleanup: may not be necessary, depending on what comes after...
|
||||
glDisable GL_CULL_FACE
|
||||
glStencilFunc GL_NOTEQUAL 128 255
|
||||
@@ -200,7 +195,7 @@ renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture li
|
||||
glDisable GL_CULL_FACE
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_FALSE
|
||||
glStencilFunc GL_EQUAL 0 255
|
||||
glUseProgram (ltextShad ^. shaderUINT)
|
||||
glUseProgram ltextShad
|
||||
glDrawArrays GL_TRIANGLES 0 6
|
||||
--cleanup: may not be necessary, depending on what comes after...
|
||||
-- glDisable GL_STENCIL_TEST
|
||||
@@ -213,15 +208,16 @@ renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture li
|
||||
pingPongBetween ::
|
||||
(FBO, TO) ->
|
||||
(FBO, TO) ->
|
||||
Shader ->
|
||||
GLuint ->
|
||||
IO ()
|
||||
pingPongBetween (fb1, to1) (fb2, to2) fs = do
|
||||
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fb2)
|
||||
glBindTextureUnit 0 (_unTO to1)
|
||||
drawShader fs 4
|
||||
glUseProgram fs
|
||||
glDrawArrays GL_TRIANGLES 0 6
|
||||
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fb1)
|
||||
glBindTextureUnit 0 (_unTO to2)
|
||||
drawShader fs 4
|
||||
glDrawArrays GL_TRIANGLES 0 6
|
||||
|
||||
renderLayer ::
|
||||
Layer ->
|
||||
|
||||
+2
-18
@@ -4,7 +4,8 @@ module Shader.Compile (
|
||||
makeShaderEBO,
|
||||
makeShaderVBO,
|
||||
makeShaderUsingVBO,
|
||||
makeByteStringShaderUsingVAO,
|
||||
makeShaderProgram,
|
||||
-- makeByteStringShaderUsingVAO,
|
||||
makeShaderUsingVAO,
|
||||
setupVAOUsingVBO,
|
||||
setupEBO,
|
||||
@@ -131,23 +132,6 @@ setupVBOStatic vertexsize = do
|
||||
--GL_STATIC_DRAW
|
||||
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexBytes = vertexsize}
|
||||
|
||||
makeByteStringShaderUsingVAO ::
|
||||
-- | (Arbitrary) name of the shader
|
||||
String ->
|
||||
-- | Filetype extensions and shader data
|
||||
[(GLenum, BS.ByteString)] ->
|
||||
PrimitiveMode ->
|
||||
VAO ->
|
||||
IO Shader
|
||||
makeByteStringShaderUsingVAO s shaderlist pm vao = do
|
||||
prog <- makeShaderProgram s shaderlist
|
||||
return
|
||||
Shader
|
||||
{ _shaderUINT = prog
|
||||
, _shaderVAO = vao
|
||||
, _shaderPrimitive = pm
|
||||
}
|
||||
|
||||
-- | Takes the VAO from elsewhere
|
||||
makeShaderUsingVAO ::
|
||||
-- | First part of the name of the shader
|
||||
|
||||
Reference in New Issue
Block a user