Pre shader refactor commit

This commit is contained in:
jgk
2021-03-10 14:31:50 +01:00
parent d3c8504d21
commit fe2abc9266
5 changed files with 27 additions and 16 deletions
+1 -1
View File
@@ -8,5 +8,5 @@ void main()
vec2 pos = gl_FragCoord.xy; vec2 pos = gl_FragCoord.xy;
float dist = min(1 , 2*distance(pos,cenPosT) / (gParams.x)); float dist = min(1 , 2*distance(pos,cenPosT) / (gParams.x));
float c = gParams.y * pow(1-dist,2); float c = gParams.y * pow(1-dist,2);
fColor = vec4( c,c,c ,c ); fColor = vec4(c,c,c,c);
} }
+7 -5
View File
@@ -33,12 +33,14 @@ void main()
if (isLHS( lightPos - frontL, frontR - frontL) < 0) if (isLHS( lightPos - frontL, frontR - frontL) < 0)
// if (isLHS( lightPos - backL, backR - backL) < 0) // if (isLHS( lightPos - backL, backR - backL) < 0)
{ {
emitLine (frontL); // emitLine (frontL);
emitLine (backL); // emitLine (backL);
emitLine (frontL); // emitLine (frontL);
emitLine (frontR); // emitLine (frontR);
// emitLine (backR);
// emitLine (frontR);
emitLine (backR); emitLine (backR);
emitLine (frontR); emitLine (backL);
} }
else else
{ {
+17
View File
@@ -11,6 +11,16 @@ import Geometry.Data
import Control.Lens 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 RGBA = (Float,Float,Float,Float)
type Color = (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 flat3 #-}
{-# INLINE flat4 #-} {-# INLINE flat4 #-}
data FullShader = FullShader
{ _shaderProgram :: Program
, _shaderUniforms :: [UniformLocation]
, _shaderVAO :: VAO
-- , _shaderPokeStrategy :: [Ptr Float] -> F.FoldM IO RenderType Int
}
data RenderType data RenderType
= RenderPoly [(Point3,Point4)] = RenderPoly [(Point3,Point4)]
| RenderText [(Point3,Point4,Point3)] | RenderText [(Point3,Point4,Point3)]
+2 -5
View File
@@ -3,6 +3,8 @@
module Picture.Preload module Picture.Preload
where where
import Picture.Data
import Codec.Picture import Codec.Picture
import Graphics.Rendering.OpenGL hiding (Point (..),translate,scale,imageHeight,imageWidth) import Graphics.Rendering.OpenGL hiding (Point (..),translate,scale,imageHeight,imageWidth)
import qualified Graphics.Rendering.OpenGL as GL import qualified Graphics.Rendering.OpenGL as GL
@@ -40,13 +42,8 @@ data RenderData = RenderData
, _dummyVBO :: BufferObject , _dummyVBO :: BufferObject
, _dummyPtr :: Ptr Float , _dummyPtr :: Ptr Float
} }
data VAO = VAO
{ _vao :: VertexArrayObject
, _vaoBufferTargets :: [(BufferObject,Ptr Float,Int)]
}
makeLenses ''RenderData makeLenses ''RenderData
makeLenses ''VAO
floatSize = sizeOf (0.5 :: GLfloat) floatSize = sizeOf (0.5 :: GLfloat)
-5
View File
@@ -404,7 +404,6 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints p
wallPtr2 = (\(_,x,_) -> x) $ (_vaoBufferTargets $ _wallVAO pdata) !! 1 wallPtr2 = (\(_,x,_) -> x) $ (_vaoBufferTargets $ _wallVAO pdata) !! 1
foldWalls n ((x,y),(z,w),(a,b),(c,d)) = do foldWalls n ((x,y),(z,w),(a,b),(c,d)) = do
pokeFourOff wallPtr n (x,y,z,w) pokeFourOff wallPtr n (x,y,z,w)
-- pokeElemOff (_dummyPtr pdata) n (fromIntegral n)
pokeFourOff wallPtr2 n (a,b,c,d) pokeFourOff wallPtr2 n (a,b,c,d)
return $ n+1 return $ n+1
nWalls <- foldM foldWalls 0 wallPoints 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) bindVertexArrayObject $= Just (_vao $ _wallVAO pdata)
uniform (_wssLightPos pdata) $= Vector2 (x) (y) uniform (_wssLightPos pdata) $= Vector2 (x) (y)
blendFunc $= (Zero,One) 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) drawArrays Points (fromIntegral 0) (fromIntegral $ nWalls)
cullFace $= Nothing cullFace $= Nothing
currentProgram $= Just (fst $ _lightmapCircleShader pdata) currentProgram $= Just (fst $ _lightmapCircleShader pdata)