Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:set -fbyte-code
:set -fobject-code
:def rr const $ return $ unlines [":r","Test.target"]
2 changes: 2 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ extra-deps:
- 'vendor/elm-format'
# windows pinning for build issues
- ansi-terminal-0.11
- git: https://github.com/noteed/language-glsl.git
commit: 99c3aae76363b127679da640a6f00d61d2203830
flags:
regex-posix:
_regex-posix-clib: true
Expand Down
11 changes: 11 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ packages:
size: 1461
original:
hackage: ansi-terminal-0.11
- completed:
name: language-glsl
version: 0.4.0.0
git: https://github.com/noteed/language-glsl.git
pantry-tree:
size: 1066
sha256: 155d01f395cc7df3c511df6ff35835b9d54f88a629a58098af7b54a4eeff8e63
commit: 99c3aae76363b127679da640a6f00d61d2203830
original:
git: https://github.com/noteed/language-glsl.git
commit: 99c3aae76363b127679da640a6f00d61d2203830
snapshots:
- completed:
sha256: 9313df78f49519315342f4c51ffc5da12659d3735f8ac3c54a1fb98ff874474e
Expand Down
7 changes: 5 additions & 2 deletions test/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import qualified Test.Check
import qualified Test.Wire
import qualified Test.Ext.ElmPages.Check
import qualified Test.TypeHashes
import qualified Test.WebGL

import qualified Lamdera.Evergreen.TestMigrationHarness
import qualified Lamdera.Evergreen.TestMigrationGenerator
Expand Down Expand Up @@ -122,8 +123,8 @@ previewProject = do
Dir.withCurrentDirectory p $ Lamdera.CLI.Deploy.run () ()


target =
Test.Check.checkWithParams "/Users/mario/dev/projects/lamdera-dashboard"
--target =
-- Test.Check.checkWithParams "/Users/mario/dev/projects/lamdera-dashboard"
-- Test.Check.checkWithParams "/Users/mario/lamdera/test/sheep-game" "sheep-game"

-- target = buildTestHarnessToProductionJs
Expand Down Expand Up @@ -277,6 +278,7 @@ liveReloadLive = do
-- "src/Bytes/Encode.elm"
-- "withDebug"

target = EasyTest.run Test.WebGL.suite

all =
EasyTest.run allTests
Expand All @@ -299,4 +301,5 @@ allTests =
, scope "Test.Check -> " $ Test.Check.suite
, scope "Lamdera.Evergreen.TestMigrationHarness -> " $ Lamdera.Evergreen.TestMigrationHarness.suite
, scope "Lamdera.Evergreen.TestMigrationGenerator -> " $ Lamdera.Evergreen.TestMigrationGenerator.suite
, scope "Test.WebGL -> " $ Test.WebGL.suite
]
40 changes: 40 additions & 0 deletions test/Test/WebGL.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.WebGL where

import qualified System.Directory as Dir
import System.FilePath ((</>))
import Data.Text as T

import Lamdera
import EasyTest

import qualified Init
import qualified Lamdera.CLI.Login
import qualified Lamdera.AppConfig
import qualified Lamdera.Update
import qualified Lamdera.Compile
import qualified Lamdera.Evergreen.Snapshot
import qualified Lamdera.Relative
import Test.Helpers
import Test.Check

-- import qualified Lamdera.CLI.Check
-- import qualified Lamdera.CLI.Reset
-- import qualified Lamdera.CLI.Live
-- import qualified Lamdera.ReverseProxy
-- import Test.Wire
import qualified Ext.Common


suite :: Test ()
suite = tests
[ scope "make Elm app containing extension directive in shader" $ do
project <- io $ Lamdera.Relative.findDir "test/scenario-webgl-extensions"

_ <- io $ rmdir (project </> "elm-stuff")

actual <- catchOutput $ Lamdera.Compile.makeDev project [ "src/Triangle.elm" ]

expectTextContains actual "Success! Compiled 1 module."
]
26 changes: 26 additions & 0 deletions test/scenario-webgl-extensions/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.0",
"elm/core": "1.0.0",
"elm/html": "1.0.0",
"elm/json": "1.0.0",
"elm-explorations/linear-algebra": "1.0.0",
"elm-explorations/webgl": "1.1.3"
},
"indirect": {
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
105 changes: 105 additions & 0 deletions test/scenario-webgl-extensions/src/Triangle.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
module Triangle exposing (main)

{-
Rotating triangle, that is a "hello world" of the WebGL
-}

import Browser
import Browser.Events exposing (onAnimationFrameDelta)
import Html exposing (Html)
import Html.Attributes exposing (width, height, style)
import WebGL exposing (Mesh, Shader)
import Math.Matrix4 as Mat4 exposing (Mat4)
import Math.Vector3 as Vec3 exposing (vec3, Vec3)
import Json.Decode exposing (Value)


main : Program Value Float Float
main =
Browser.element
{ init = \_ -> ( 0, Cmd.none )
, view = view
, subscriptions = (\_ -> onAnimationFrameDelta Basics.identity)
, update = (\elapsed currentTime -> ( elapsed + currentTime, Cmd.none ))
}


view : Float -> Html msg
view t =
WebGL.toHtml
[ width 400
, height 400
, style "display" "block"
]
[ WebGL.entity
vertexShader
fragmentShader
mesh
{ perspective = perspective (t / 1000) }
]


perspective : Float -> Mat4
perspective t =
Mat4.mul
(Mat4.makePerspective 45 1 0.01 100)
(Mat4.makeLookAt (vec3 (4 * cos t) 0 (4 * sin t)) (vec3 0 0 0) (vec3 0 1 0))



-- Mesh


type alias Vertex =
{ position : Vec3
, color : Vec3
}


mesh : Mesh Vertex
mesh =
WebGL.triangles
[ ( Vertex (vec3 0 0 0) (vec3 1 0 0)
, Vertex (vec3 1 1 0) (vec3 0 1 0)
, Vertex (vec3 1 -1 0) (vec3 0 0 1)
)
]



-- Shaders


type alias Uniforms =
{ perspective : Mat4 }


vertexShader : Shader Vertex Uniforms { vcolor : Vec3 }
vertexShader =
[glsl|

attribute vec3 position;
attribute vec3 color;
uniform mat4 perspective;
varying vec3 vcolor;

void main () {
gl_Position = perspective * vec4(position, 1.0);
vcolor = color;
}

|]


fragmentShader : Shader {} Uniforms { vcolor : Vec3 }
fragmentShader =
[glsl|
#extension EXT_frag_depth : enable
precision mediump float;
varying vec3 vcolor;

void main () {
gl_FragColor = vec4(vcolor, 1.0);
}

|]