From fe2abc9266bb073d58195e52f0f19eea62e55f2c Mon Sep 17 00:00:00 2001 From: jgk Date: Wed, 10 Mar 2021 14:31:50 +0100 Subject: [PATCH] Pre shader refactor commit --- shader/lightmapCircle.frag | 2 +- shader/wallShadow.geom | 12 +++++++----- src/Picture/Data.hs | 17 +++++++++++++++++ src/Picture/Preload.hs | 7 ++----- src/Picture/Render.hs | 5 ----- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/shader/lightmapCircle.frag b/shader/lightmapCircle.frag index b1a804b5a..c29090cf5 100644 --- a/shader/lightmapCircle.frag +++ b/shader/lightmapCircle.frag @@ -8,5 +8,5 @@ void main() vec2 pos = gl_FragCoord.xy; float dist = min(1 , 2*distance(pos,cenPosT) / (gParams.x)); float c = gParams.y * pow(1-dist,2); - fColor = vec4( c,c,c ,c ); + fColor = vec4(c,c,c,c); } diff --git a/shader/wallShadow.geom b/shader/wallShadow.geom index 6f80907d9..9b141fe65 100644 --- a/shader/wallShadow.geom +++ b/shader/wallShadow.geom @@ -33,12 +33,14 @@ void main() if (isLHS( lightPos - frontL, frontR - frontL) < 0) // if (isLHS( lightPos - backL, backR - backL) < 0) { - emitLine (frontL); - emitLine (backL); - emitLine (frontL); - emitLine (frontR); +// emitLine (frontL); +// emitLine (backL); +// emitLine (frontL); +// emitLine (frontR); +// emitLine (backR); +// emitLine (frontR); emitLine (backR); - emitLine (frontR); + emitLine (backL); } else { diff --git a/src/Picture/Data.hs b/src/Picture/Data.hs index b545c19f4..f5ac91e7b 100644 --- a/src/Picture/Data.hs +++ b/src/Picture/Data.hs @@ -11,6 +11,16 @@ import Geometry.Data import Control.Lens +import Foreign + +import Graphics.Rendering.OpenGL hiding (Point (..),translate,scale,imageHeight,imageWidth) + +data VAO = VAO + { _vao :: VertexArrayObject + , _vaoBufferTargets :: [(BufferObject,Ptr Float,Int)] + } +makeLenses ''VAO + type RGBA = (Float,Float,Float,Float) type Color = (Float,Float,Float,Float) @@ -55,6 +65,13 @@ flat4 (x,y,z,w) = [x,y,z,w] {-# INLINE flat3 #-} {-# INLINE flat4 #-} +data FullShader = FullShader + { _shaderProgram :: Program + , _shaderUniforms :: [UniformLocation] + , _shaderVAO :: VAO +-- , _shaderPokeStrategy :: [Ptr Float] -> F.FoldM IO RenderType Int + } + data RenderType = RenderPoly [(Point3,Point4)] | RenderText [(Point3,Point4,Point3)] diff --git a/src/Picture/Preload.hs b/src/Picture/Preload.hs index 2ccc1dada..fb6372718 100644 --- a/src/Picture/Preload.hs +++ b/src/Picture/Preload.hs @@ -3,6 +3,8 @@ module Picture.Preload where +import Picture.Data + import Codec.Picture import Graphics.Rendering.OpenGL hiding (Point (..),translate,scale,imageHeight,imageWidth) import qualified Graphics.Rendering.OpenGL as GL @@ -40,13 +42,8 @@ data RenderData = RenderData , _dummyVBO :: BufferObject , _dummyPtr :: Ptr Float } -data VAO = VAO - { _vao :: VertexArrayObject - , _vaoBufferTargets :: [(BufferObject,Ptr Float,Int)] - } makeLenses ''RenderData -makeLenses ''VAO floatSize = sizeOf (0.5 :: GLfloat) diff --git a/src/Picture/Render.hs b/src/Picture/Render.hs index 0cb05014e..b448bf988 100644 --- a/src/Picture/Render.hs +++ b/src/Picture/Render.hs @@ -404,7 +404,6 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints p wallPtr2 = (\(_,x,_) -> x) $ (_vaoBufferTargets $ _wallVAO pdata) !! 1 foldWalls n ((x,y),(z,w),(a,b),(c,d)) = do pokeFourOff wallPtr n (x,y,z,w) --- pokeElemOff (_dummyPtr pdata) n (fromIntegral n) pokeFourOff wallPtr2 n (a,b,c,d) return $ n+1 nWalls <- foldM foldWalls 0 wallPoints @@ -417,10 +416,6 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints p bindVertexArrayObject $= Just (_vao $ _wallVAO pdata) uniform (_wssLightPos pdata) $= Vector2 (x) (y) blendFunc $= (Zero,One) --- drawElements Points (fromIntegral nWalls) UnsignedByte (_dummyPtr pdata) --- withArray [0..(nWalls-1)::Int] $ \ptr -> ----- --drawElements Points (fromIntegral nWalls) UnsignedByte ptr --- glDrawElements GL_POINTS (fromIntegral $ length wallPoints) GL_UNSIGNED_BYTE ptr drawArrays Points (fromIntegral 0) (fromIntegral $ nWalls) cullFace $= Nothing currentProgram $= Just (fst $ _lightmapCircleShader pdata)