Start cleanup
This commit is contained in:
+20
-122
@@ -1,154 +1,55 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE StrictData #-}
|
||||
{- |
|
||||
Datatypes used to setup and pass data to shaders.
|
||||
-}
|
||||
{- | Datatypes used to setup and pass data to shaders. -}
|
||||
module Shader.Data
|
||||
( VAO (..)
|
||||
, VBO (..)
|
||||
, FullShader (..)
|
||||
, VShader (..)
|
||||
, ShaderTexture (..)
|
||||
, EPrimitiveMode (..)
|
||||
, PicShads (..)
|
||||
-- | Lens functions
|
||||
, vao
|
||||
, vaoVBO
|
||||
|
||||
, shaderProgram
|
||||
, shaderVAO
|
||||
, shaderDrawPrimitive
|
||||
, shaderTexture
|
||||
, shaderCustomUnis
|
||||
|
||||
, vshaderProgram
|
||||
, vshaderVAO
|
||||
, vshaderDrawPrimitive
|
||||
, vshaderTexture
|
||||
, vshaderCustomUnis
|
||||
|
||||
, psPoly
|
||||
, psPolyz
|
||||
, psBez
|
||||
, psText
|
||||
, psArc
|
||||
, psEll
|
||||
|
||||
, vbo
|
||||
, vboPtr
|
||||
, vboAttribSizes
|
||||
, vboStride
|
||||
-- | Synonyms
|
||||
, vert
|
||||
, geom
|
||||
, frag
|
||||
|
||||
-- TODO make lenses for VBO object
|
||||
-- , textureObject
|
||||
) where
|
||||
--import Geometry.Data
|
||||
|
||||
import Graphics.Rendering.OpenGL
|
||||
import Foreign
|
||||
import Control.Lens
|
||||
--import Graphics.GL.Types
|
||||
{- | Datatype containing the necessary information for a single shader. -}
|
||||
data FullShader = FullShader
|
||||
{ _shaderProgram :: Program
|
||||
, _shaderVAO :: VAO
|
||||
, _shaderDrawPrimitive :: EPrimitiveMode
|
||||
, _shaderTexture :: Maybe ShaderTexture
|
||||
, _shaderCustomUnis :: [UniformLocation]
|
||||
}
|
||||
{- | Vertex array object: contains the reference to the object,
|
||||
and its buffer targets. -}
|
||||
data VAO = VAO
|
||||
{ _vao :: VertexArrayObject
|
||||
, _vaoVBO :: VBO
|
||||
{ _vao :: VertexArrayObject
|
||||
, _vaoVBO :: VBO
|
||||
}
|
||||
{- | Vertex buffer object: contains the reference to the object,
|
||||
a pointer to a location with space that can be written to the buffer,
|
||||
and a list of attribute pointer sizes.
|
||||
Vertex attributes are interleaved within the vbo. -}
|
||||
data VBO = VBO
|
||||
{ _vbo :: BufferObject
|
||||
, _vboPtr :: Ptr Float
|
||||
{ _vbo :: BufferObject
|
||||
, _vboPtr :: Ptr Float
|
||||
, _vboAttribSizes :: [Int] -- ^ It is not clear to me if this is necessary to store or not
|
||||
, _vboStride :: Int
|
||||
}
|
||||
data VShader = VShader
|
||||
{ _vshaderProgram :: Program
|
||||
, _vshaderVAO :: VAO
|
||||
, _vshaderDrawPrimitive :: EPrimitiveMode
|
||||
, _vshaderTexture :: Maybe ShaderTexture
|
||||
, _vshaderCustomUnis :: [UniformLocation]
|
||||
}
|
||||
data PicShads a = PicShads
|
||||
{ _psPoly :: a
|
||||
, _psPolyz :: a
|
||||
, _psBez :: a
|
||||
, _psText :: a
|
||||
, _psArc :: a
|
||||
, _psEll :: a
|
||||
}
|
||||
-- boilerplate folows
|
||||
instance Functor PicShads where
|
||||
fmap f PicShads
|
||||
{ _psPoly = thePoly
|
||||
, _psPolyz = thePolyz
|
||||
, _psBez = theBez
|
||||
, _psText = theText
|
||||
, _psArc = theArc
|
||||
, _psEll = theEll
|
||||
}
|
||||
= PicShads
|
||||
{ _psPoly = f thePoly
|
||||
, _psPolyz = f thePolyz
|
||||
, _psBez = f theBez
|
||||
, _psText = f theText
|
||||
, _psArc = f theArc
|
||||
, _psEll = f theEll
|
||||
}
|
||||
instance Applicative PicShads where
|
||||
pure a = PicShads a a a a a a
|
||||
(<*>) PicShads
|
||||
{ _psPoly = fPoly
|
||||
, _psPolyz = fPolyz
|
||||
, _psBez = fBez
|
||||
, _psText = fText
|
||||
, _psArc = fArc
|
||||
, _psEll = fEll
|
||||
}
|
||||
PicShads
|
||||
{ _psPoly = thePoly
|
||||
, _psPolyz = thePolyz
|
||||
, _psBez = theBez
|
||||
, _psText = theText
|
||||
, _psArc = theArc
|
||||
, _psEll = theEll
|
||||
}
|
||||
= PicShads
|
||||
{ _psPoly = fPoly thePoly
|
||||
, _psPolyz = fPolyz thePolyz
|
||||
, _psBez = fBez theBez
|
||||
, _psText = fText theText
|
||||
, _psArc = fArc theArc
|
||||
, _psEll = fEll theEll
|
||||
}
|
||||
instance Foldable PicShads where
|
||||
foldr f x PicShads
|
||||
{ _psPoly = thePoly
|
||||
, _psPolyz = thePolyz
|
||||
, _psBez = theBez
|
||||
, _psText = theText
|
||||
, _psArc = theArc
|
||||
, _psEll = theEll
|
||||
}
|
||||
= f thePoly . f thePolyz . f theBez . f theText . f theArc $ f theEll x
|
||||
instance Traversable PicShads where
|
||||
{-# INLINE traverse #-}
|
||||
traverse f PicShads
|
||||
{ _psPoly = x0
|
||||
, _psPolyz = x1
|
||||
, _psBez = x2
|
||||
, _psText = x3
|
||||
, _psArc = x4
|
||||
, _psEll = x5
|
||||
} = PicShads <$> f x0 <*> f x1 <*> f x2 <*> f x3 <*> f x4 <*> f x5
|
||||
{- | Datatype containing the necessary information for a single shader. -}
|
||||
data FullShader = FullShader
|
||||
{ _shaderProgram :: Program
|
||||
, _shaderVAO :: VAO
|
||||
, _shaderDrawPrimitive :: EPrimitiveMode
|
||||
, _shaderTexture :: Maybe ShaderTexture
|
||||
, _shaderCustomUnis :: [UniformLocation]
|
||||
, _vboStride :: Int
|
||||
}
|
||||
{- | Datatype containing the reference to a texture object. -}
|
||||
newtype ShaderTexture = ShaderTexture
|
||||
@@ -166,14 +67,11 @@ data EPrimitiveMode
|
||||
| EQuadStrip
|
||||
| EPolygon
|
||||
| EPatches
|
||||
|
||||
-- | Short synonyms for shader types
|
||||
vert, geom, frag :: ShaderType
|
||||
vert = VertexShader
|
||||
geom = GeometryShader
|
||||
frag = FragmentShader
|
||||
|
||||
makeLenses ''VAO
|
||||
makeLenses ''VBO
|
||||
makeLenses ''FullShader
|
||||
makeLenses ''VShader
|
||||
makeLenses ''PicShads
|
||||
|
||||
Reference in New Issue
Block a user