mvp
This commit is contained in:
32
src/Main.hs
32
src/Main.hs
@@ -7,7 +7,37 @@ module Main (main) where
|
|||||||
|
|
||||||
import Relude
|
import Relude
|
||||||
|
|
||||||
|
import Types
|
||||||
|
|
||||||
-- MAIN --
|
-- MAIN --
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = putTextLn "hallo Welt"
|
main = do
|
||||||
|
putTextLn "hallo Welt"
|
||||||
|
putStrLn $ generateGLSL vertShader
|
||||||
|
putStrLn $ generateGLSL fragShader
|
||||||
|
|
||||||
|
fragShader :: Program
|
||||||
|
fragShader =
|
||||||
|
[ VersionDeclaration 450 Core
|
||||||
|
, VariableDeclaration Nothing In fragColorIn
|
||||||
|
, VariableDeclaration Nothing Out fragColorOut
|
||||||
|
, MainStart
|
||||||
|
, VariableAssignment fragColorOut fragColorIn
|
||||||
|
]
|
||||||
|
|
||||||
|
vertShader :: Program
|
||||||
|
vertShader =
|
||||||
|
[ VersionDeclaration 450 Core
|
||||||
|
, VariableDeclaration (Just $ Location 0) In vertexPosition
|
||||||
|
, VariableDeclaration (Just $ Location 1) In vertexColor
|
||||||
|
, VariableDeclaration Nothing Out fragColorOut
|
||||||
|
, MainStart
|
||||||
|
, VariableAssignment GL_POSITION vertexPosition
|
||||||
|
, VariableAssignment fragColorIn vertexColor
|
||||||
|
]
|
||||||
|
|
||||||
|
fragColorIn = Variable "fragColorIn" $ GLSLVec4 GLSLFloat
|
||||||
|
fragColorOut = Variable "fragColorOut" $ GLSLVec4 GLSLFloat
|
||||||
|
vertexPosition = Variable "vertexPosition" $ GLSLVec4 GLSLFloat
|
||||||
|
vertexColor = Variable "vertexColor" $ GLSLVec4 GLSLFloat
|
||||||
|
|||||||
122
src/Types.hs
Normal file
122
src/Types.hs
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
{-# LANGUAGE NoImplicitPrelude #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
|
module Types where
|
||||||
|
|
||||||
|
-- IMPORTS --
|
||||||
|
|
||||||
|
import Relude
|
||||||
|
import qualified Text.Show
|
||||||
|
|
||||||
|
-- TYPES --
|
||||||
|
|
||||||
|
type Program = Expressions
|
||||||
|
|
||||||
|
-- version declaration
|
||||||
|
|
||||||
|
type RequestedGLVersion = Int
|
||||||
|
data RequestedGLType
|
||||||
|
= Core
|
||||||
|
|
||||||
|
instance Show RequestedGLType where
|
||||||
|
show Core = "core"
|
||||||
|
|
||||||
|
-- variables
|
||||||
|
|
||||||
|
data ParameterQualifier
|
||||||
|
= In
|
||||||
|
| Out
|
||||||
|
|
||||||
|
instance Show ParameterQualifier where
|
||||||
|
show In = "in"
|
||||||
|
show Out = "out"
|
||||||
|
|
||||||
|
data LayoutQualifier
|
||||||
|
= Location Int
|
||||||
|
|
||||||
|
type Variables = [Variable]
|
||||||
|
type VariableName = String
|
||||||
|
|
||||||
|
data Variable
|
||||||
|
= Variable
|
||||||
|
VariableName
|
||||||
|
GLSLType
|
||||||
|
| GL_POSITION
|
||||||
|
|
||||||
|
nameOf :: Variable -> String
|
||||||
|
nameOf GL_POSITION = "gl_position"
|
||||||
|
nameOf (Variable name _) = name
|
||||||
|
|
||||||
|
data GLSLType
|
||||||
|
= GLSLFloat
|
||||||
|
| GLSLVec4 GLSLType
|
||||||
|
|
||||||
|
instance Show GLSLType where
|
||||||
|
show (GLSLVec4 _) = "vec4"
|
||||||
|
show GLSLFloat = "float"
|
||||||
|
|
||||||
|
-- expressions
|
||||||
|
|
||||||
|
type Expressions = [Expression]
|
||||||
|
|
||||||
|
data Expression
|
||||||
|
= VersionDeclaration
|
||||||
|
RequestedGLVersion
|
||||||
|
RequestedGLType
|
||||||
|
| VariableDeclaration
|
||||||
|
(Maybe LayoutQualifier)
|
||||||
|
ParameterQualifier
|
||||||
|
Variable
|
||||||
|
| MainStart
|
||||||
|
| VariableAssignment
|
||||||
|
Variable
|
||||||
|
Variable
|
||||||
|
|
||||||
|
generateGLSL :: Program -> String
|
||||||
|
generateGLSL [] = "}"
|
||||||
|
generateGLSL (expression:expressions) =
|
||||||
|
(++)
|
||||||
|
(
|
||||||
|
case expression of
|
||||||
|
VersionDeclaration
|
||||||
|
requestedGLVersion
|
||||||
|
requestedGLType ->
|
||||||
|
"#version " ++
|
||||||
|
(show requestedGLVersion) ++
|
||||||
|
" " ++
|
||||||
|
(show requestedGLType) ++
|
||||||
|
"\n"
|
||||||
|
VariableDeclaration
|
||||||
|
(Just layoutQualifier@(Location location))
|
||||||
|
parameterQualifier
|
||||||
|
(Variable variableName glslType) ->
|
||||||
|
"layout (location = " ++
|
||||||
|
(show location) ++
|
||||||
|
") " ++
|
||||||
|
(show parameterQualifier) ++
|
||||||
|
" " ++
|
||||||
|
(show glslType) ++
|
||||||
|
" " ++
|
||||||
|
variableName ++
|
||||||
|
";\n"
|
||||||
|
VariableDeclaration
|
||||||
|
Nothing
|
||||||
|
parameterQualifier
|
||||||
|
(Variable variableName glslType) ->
|
||||||
|
(show parameterQualifier) ++
|
||||||
|
" " ++
|
||||||
|
(show glslType) ++
|
||||||
|
" " ++
|
||||||
|
variableName ++
|
||||||
|
";\n"
|
||||||
|
MainStart ->
|
||||||
|
"void main()\n{\n"
|
||||||
|
VariableAssignment
|
||||||
|
variable0
|
||||||
|
variable1 ->
|
||||||
|
(nameOf variable0) ++
|
||||||
|
" = " ++
|
||||||
|
(nameOf variable1) ++
|
||||||
|
";\n"
|
||||||
|
)
|
||||||
|
$ generateGLSL expressions
|
||||||
Reference in New Issue
Block a user