packages feed

fwgl-javascript 0.1.1.0 → 0.1.1.1

raw patch · 5 files changed

+81/−52 lines, 5 filesdep ~fwgl

Dependency ranges changed: fwgl

Files

FWGL/Backend/JavaScript.hs view
@@ -13,6 +13,7 @@ import Control.Concurrent import Data.Maybe import qualified Data.HashMap.Strict as H+import Data.Int (Int32) import Data.IORef import Data.Vect.Float import Data.Word@@ -58,9 +59,6 @@ foreign import javascript unsafe "$3.setAttribute($1, $2)"         setAttributeRaw :: JSString -> JSString -> JSRef a -> IO () -foreign import javascript unsafe "performance.now()"-        now :: IO Double- getAttribute :: String -> JSRef a -> IO String getAttribute attr e = fromJSString <$> getAttributeRaw (toJSString attr) e @@ -133,7 +131,8 @@                         dataFramebufferSize = Just $ (w, h),                         dataPointer = Nothing,                         dataButton = Nothing,-                        dataKey = Nothing } src+                        dataKey = Nothing,+                        dataTime = 0 } src          setCanvasTitle _ _ _ = return () @@ -166,10 +165,10 @@         type Ctx = JS.Ctx         type GLEnum = Word         type GLUInt = Word-        type GLInt = Int+        type GLInt = Int32         type GLPtr = Word         type GLPtrDiff = Word-        type GLSize = Int+        type GLSize = Int32         type GLString = JSString         type GLBool = Bool         type Buffer = JS.Buffer@@ -214,23 +213,46 @@                                                   , c1, c2, c3, c4                                                   , d1, d2, d3, d4 ]                                  >>= JS.float32Array-        encodeFloats v = JS.listToJSArray v >>= JS.float32View+        encodeFloats v = JS.listToJSArray v >>= JS.float32Array+        encodeInts v = JS.listToJSArray v >>= JS.int32Array          -- TODO: decent implementation-        encodeVec2s v = JS.toJSArray next (False, v) >>= JS.float32View+        encodeVec2s v = JS.toJSArray next (False, v) >>= JS.float32Array                 where next (False, xs@(Vec2 x _ : _)) = Just (x, (True, xs))                       next (True, Vec2 _ y : xs) = Just (y, (False, xs))                       next (_, []) = Nothing -        encodeVec3s v = JS.toJSArray next (0, v) >>= JS.float32View+        encodeVec3s v = JS.toJSArray next (0, v) >>= JS.float32Array                 where next (0, xs@(Vec3 x _ _ : _)) = Just (x, (1, xs))                       next (1, xs@(Vec3 _ y _ : _)) = Just (y, (2, xs))                       next (2, Vec3 _ _ z : xs) = Just (z, (0, xs))                       next (_, []) = Nothing -        -- TODO-        encodeVec4s = error "encodeVec4s: TODO"+        encodeVec4s v = JS.toJSArray next (0, v) >>= JS.float32Array+                where next (0, xs@(Vec4 x _ _ _ : _)) = Just (x, (1, xs))+                      next (1, xs@(Vec4 _ y _ _ : _)) = Just (y, (2, xs))+                      next (2, xs@(Vec4 _ _ z _ : _)) = Just (z, (3, xs))+                      next (3, Vec4 _ _ _ w : xs) = Just (w, (0, xs))+                      next (_, []) = Nothing +        encodeIVec2s v = JS.toJSArray next (False, v) >>= JS.int32Array+                where next (False, xs@(IVec2 x _ : _)) = Just (x, (True, xs))+                      next (True, IVec2 _ y : xs) = Just (y, (False, xs))+                      next (_, []) = Nothing++        encodeIVec3s v = JS.toJSArray next (0, v) >>= JS.int32Array+                where next (0, xs@(IVec3 x _ _ : _)) = Just (x, (1, xs))+                      next (1, xs@(IVec3 _ y _ : _)) = Just (y, (2, xs))+                      next (2, IVec3 _ _ z : xs) = Just (z, (0, xs))+                      next (_, []) = Nothing++        encodeIVec4s v = JS.toJSArray next (0, v) >>= JS.int32Array+                where next (0, xs@(IVec4 x _ _ _ : _)) = Just (x, (1, xs))+                      next (1, xs@(IVec4 _ y _ _ : _)) = Just (y, (2, xs))+                      next (2, xs@(IVec4 _ _ z _ : _)) = Just (z, (3, xs))+                      next (3, IVec4 _ _ _ w : xs) = Just (w, (0, xs))+                      next (_, []) = Nothing+         encodeUShorts v = JS.listToJSArray v >>= JS.uint16View          encodeColors v = JS.toJSArray next (0, v) >>= JS.uint8View@@ -241,6 +263,8 @@                       next (_, []) = Nothing          newByteArray = fmap castRef . JS.uint8ArraySize+        fromFloat32Array = castRef+        fromInt32Array = castRef          decodeBytes = (>>= mapM (fmap fromJust . fromJSRef))                       . fromArray . castRef
FWGL/Backend/JavaScript/Event.hs view
@@ -3,6 +3,7 @@ module FWGL.Backend.JavaScript.Event (         InputEvent(..),         Source,+        now,         source,         pushEvent,         addEvent,@@ -38,7 +39,7 @@  pushEvent :: Event -> EventData -> Source -> IO () pushEvent e eventData (Source _ map) =-        modifyIORef map $ H.insertWith (flip (++)) e [ eventData ]+        modifyIORef map $ H.insertWith ((++)) e [ eventData ]  events :: Source -> IO (H.HashMap Event [EventData]) events (Source _ c) = readIORef c@@ -69,6 +70,7 @@                                              )                                         <*> ((getButton <$>) <$> prop "button" d)                                         <*> ((getKey <$>) <$> prop "keyCode" d)+                                        <*> now                         pushEvent e eventData s  eventName :: Event -> String@@ -83,6 +85,9 @@  foreign import javascript unsafe "$1.addEventListener($2, $3)"         addHandler :: JSRef a -> JSString -> JSFun (JSRef b -> IO ()) -> IO ()++foreign import javascript unsafe "performance.now()"+        now :: IO Double  getKey :: Int -> Key getKey 65 = KeyA
FWGL/Backend/JavaScript/WebGL/Raw.hs view
@@ -77,7 +77,7 @@         glClearDepth :: Ctx -> Float -> IO ()  foreign import javascript unsafe "$1.clearStencil($2)"-        glClearStencil :: Ctx -> Int -> IO ()+        glClearStencil :: Ctx -> Int32 -> IO ()  foreign import javascript unsafe "$1.colorMask($2, $3, $4, $5)"         glColorMask :: Ctx -> Bool -> Bool -> Bool -> Bool -> IO ()@@ -86,16 +86,16 @@         glCompileShader :: Ctx -> Shader -> IO ()  foreign import javascript unsafe "$1.compressedTexImage2D($2, $3, $4, $5, $6, $7, $8)"-        glCompressedTexImage2D :: Ctx -> Word -> Int -> Word -> Int -> Int -> Int -> ArrayBufferView -> IO ()+        glCompressedTexImage2D :: Ctx -> Word -> Int32 -> Word -> Int32 -> Int32 -> Int32 -> ArrayBufferView -> IO ()  foreign import javascript unsafe "$1.compressedTexSubImage2D($2, $3, $4, $5, $6, $7, $8, $9)"-        glCompressedTexSubImage2D :: Ctx -> Word -> Int -> Int -> Int -> Int -> Int -> Word -> ArrayBufferView -> IO ()+        glCompressedTexSubImage2D :: Ctx -> Word -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Word -> ArrayBufferView -> IO ()  foreign import javascript unsafe "$1.copyTexImage2D($2, $3, $4, $5, $6, $7, $8, $9)"-        glCopyTexImage2D :: Ctx -> Word -> Int -> Word -> Int -> Int -> Int -> Int -> Int -> IO ()+        glCopyTexImage2D :: Ctx -> Word -> Int32 -> Word -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()  foreign import javascript unsafe "$1.copyTexSubImage2D($2, $3, $4, $5, $6, $7, $8, $9)"-        glCopyTexSubImage2D :: Ctx -> Word -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> IO ()+        glCopyTexSubImage2D :: Ctx -> Word -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()  foreign import javascript unsafe "$1.createBuffer()"         glCreateBuffer :: Ctx -> IO Buffer@@ -155,10 +155,10 @@         glDisableVertexAttribArray :: Ctx -> Word -> IO ()  foreign import javascript unsafe "$1.drawArrays($2, $3, $4)"-        glDrawArrays :: Ctx -> Word -> Int -> Int -> IO ()+        glDrawArrays :: Ctx -> Word -> Int32 -> Int32 -> IO ()  foreign import javascript unsafe "$1.drawElements($2, $3, $4, $5)"-        glDrawElements :: Ctx -> Word -> Int -> Word -> Word -> IO ()+        glDrawElements :: Ctx -> Word -> Int32 -> Word -> Word -> IO ()  foreign import javascript unsafe "$1.enable($2)"         glEnable :: Ctx -> Word -> IO ()@@ -176,7 +176,7 @@         glFramebufferRenderbuffer :: Ctx -> Word -> Word -> Word -> RenderBuffer -> IO ()  foreign import javascript unsafe "$1.framebufferTexture2D($2, $3, $4, $5, $6)"-        glFramebufferTexture2D :: Ctx -> Word -> Word -> Word -> Texture -> Int -> IO ()+        glFramebufferTexture2D :: Ctx -> Word -> Word -> Word -> Texture -> Int32 -> IO ()  foreign import javascript unsafe "$1.frontFace($2)"         glFrontFace :: Ctx -> Word -> IO ()@@ -196,7 +196,7 @@ -}  foreign import javascript unsafe "$1.getAttribLocation($2, $3)"-        glGetAttribLocation :: Ctx -> Program -> JSString -> IO Int+        glGetAttribLocation :: Ctx -> Program -> JSString -> IO Int32  foreign import javascript unsafe "$1.getBufferParameter($2, $3)"         glGetBufferParameter :: Ctx -> Word -> Word -> IO (JSRef a)@@ -274,31 +274,31 @@         glLinkProgram :: Ctx -> Program -> IO ()  foreign import javascript unsafe "$1.pixelStorei($2, $3)"-        glPixelStorei :: Ctx -> Word -> Int -> IO ()+        glPixelStorei :: Ctx -> Word -> Int32 -> IO ()  foreign import javascript unsafe "$1.polygonOffset($2, $3)"         glPolygonOffset :: Ctx -> Float -> Float -> IO ()  foreign import javascript unsafe "$1.readPixels($2, $3, $4, $5, $6, $7, $8)"-        glReadPixels :: Ctx -> Int -> Int -> Int -> Int -> Word -> Word -> ArrayBufferView -> IO ()+        glReadPixels :: Ctx -> Int32 -> Int32 -> Int32 -> Int32 -> Word -> Word -> ArrayBufferView -> IO ()  foreign import javascript unsafe "$1.renderbufferStorage($2, $3, $4, $5)"-        glRenderbufferStorage :: Ctx -> Word -> Word -> Int -> Int -> IO ()+        glRenderbufferStorage :: Ctx -> Word -> Word -> Int32 -> Int32 -> IO ()  foreign import javascript unsafe "$1.sampleCoverage($2, $3)"         glSampleCoverage :: Ctx -> Float -> Bool -> IO ()  foreign import javascript unsafe "$1.scissor($2, $3, $4, $5)"-        glScissor :: Ctx -> Int -> Int -> Int -> Int -> IO ()+        glScissor :: Ctx -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()  foreign import javascript unsafe "$1.shaderSource($2, $3)"         glShaderSource :: Ctx -> Shader -> JSString -> IO ()  foreign import javascript unsafe "$1.stencilFunc($2, $3, $4)"-        glStencilFunc :: Ctx -> Word -> Int -> Word -> IO ()+        glStencilFunc :: Ctx -> Word -> Int32 -> Word -> IO ()  foreign import javascript unsafe "$1.stencilFuncSeparate($2, $3, $4, $5)"-        glStencilFuncSeparate :: Ctx -> Word -> Word -> Int -> Word -> IO ()+        glStencilFuncSeparate :: Ctx -> Word -> Word -> Int32 -> Word -> IO ()  foreign import javascript unsafe "$1.stencilMask($2)"         glStencilMask :: Ctx -> Word -> IO ()@@ -313,35 +313,35 @@         glStencilOpSeparate :: Ctx -> Word -> Word -> Word -> Word -> IO ()  foreign import javascript unsafe "$1.texImage2D($2, $3, $4, $5, $6, $7, $8, $9, $10)"-        glTexImage2DBuffer :: Ctx -> Word -> Int -> Int -> Int -> Int -> Int -> Word -> Word -> ArrayBufferView -> IO ()+        glTexImage2DBuffer :: Ctx -> Word -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Word -> Word -> ArrayBufferView -> IO ()  foreign import javascript unsafe "$1.texImage2D($2, $3, $4, $5, $6, $7)"-        glTexImage2DElement :: Ctx -> Word -> Int -> Int -> Word -> Word -> Image -> IO ()+        glTexImage2DElement :: Ctx -> Word -> Int32 -> Int32 -> Word -> Word -> Image -> IO ()  {- foreign import javascript unsafe "$1.texImage2D()"-        glTexImage2D :: Ctx -> Word -> Int -> Word -> Word -> Word -> CanvasElement -> Void +        glTexImage2D :: Ctx -> Word -> Int32 -> Word -> Word -> Word -> CanvasElement -> Void   foreign import javascript unsafe "$1.texImage2D()"-        glTexImage2D :: Ctx -> Word -> Int -> Word -> Word -> Word -> VideoElement -> Void +        glTexImage2D :: Ctx -> Word -> Int32 -> Word -> Word -> Word -> VideoElement -> Void  -}  foreign import javascript unsafe "$1.texParameterf($2, $3, $4)"         glTexParameterf :: Ctx -> Word -> Word -> Float -> IO ()  foreign import javascript unsafe "$1.texParameteri($2, $3, $4)"-        glTexParameteri :: Ctx -> Word -> Word -> Int -> IO ()+        glTexParameteri :: Ctx -> Word -> Word -> Int32 -> IO ()  foreign import javascript unsafe "$1.texSubImage2D($2, $3, $4, $5, $6, $7, $8, $9, $10)"-        glTexSubImage2D :: Ctx -> Word -> Int -> Int -> Int -> Int -> Int -> Word -> Word -> ArrayBufferView -> IO ()+        glTexSubImage2D :: Ctx -> Word -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Word -> Word -> ArrayBufferView -> IO ()  {-  foreign import javascript unsafe "$1.texSubImage2D()"-        glTexSubImage2D :: Ctx -> Word -> Int -> Int -> Int -> Word -> Word -> CanvasElement -> Void +        glTexSubImage2D :: Ctx -> Word -> Int32 -> Int32 -> Int32 -> Word -> Word -> CanvasElement -> Void   foreign import javascript unsafe "$1.texSubImage2D()"-        glTexSubImage2D :: Ctx -> Word -> Int -> Int -> Int -> Word -> Word -> VideoElement -> Void +        glTexSubImage2D :: Ctx -> Word -> Int32 -> Int32 -> Int32 -> Word -> Word -> VideoElement -> Void   -} @@ -357,14 +357,14 @@ -}  foreign import javascript unsafe "$1.uniform1i($2, $3)"-        glUniform1i :: Ctx -> UniformLocation -> Int -> IO ()+        glUniform1i :: Ctx -> UniformLocation -> Int32 -> IO ()  foreign import javascript unsafe "$1.uniform1iv($2, $3)"         glUniform1iv :: Ctx -> UniformLocation -> Int32Array -> IO ()  {--foreign import javascript unsafe "$1.uniform1iv($2 Sequence Int ->)"-        glUniform1iv :: Ctx -> UniformLocation -> Sequence Int -> IO ()+foreign import javascript unsafe "$1.uniform1iv($2 Sequence Int32 ->)"+        glUniform1iv :: Ctx -> UniformLocation -> Sequence Int32 -> IO () -}  foreign import javascript unsafe "$1.uniform2f($2, $3, $4)"@@ -379,14 +379,14 @@ -}  foreign import javascript unsafe "$1.uniform2i($2, $3, $4)"-        glUniform2i :: Ctx -> UniformLocation -> Int -> Int -> IO ()+        glUniform2i :: Ctx -> UniformLocation -> Int32 -> Int32 -> IO ()  foreign import javascript unsafe "$1.uniform2iv($2, $3)"         glUniform2iv :: Ctx -> UniformLocation -> Int32Array -> IO ()  {--foreign import javascript unsafe "$1.uniform2iv($2 Sequence Int ->)"-        glUniform2iv :: Ctx -> UniformLocation -> Sequence Int -> IO ()+foreign import javascript unsafe "$1.uniform2iv($2 Sequence Int32 ->)"+        glUniform2iv :: Ctx -> UniformLocation -> Sequence Int32 -> IO () -}  foreign import javascript unsafe "$1.uniform3f($2, $3, $4, $5)"@@ -401,14 +401,14 @@ -}  foreign import javascript unsafe "$1.uniform3i($2, $3, $4, $5)"-        glUniform3i :: Ctx -> UniformLocation -> Int -> Int -> Int -> IO ()+        glUniform3i :: Ctx -> UniformLocation -> Int32 -> Int32 -> Int32 -> IO ()  foreign import javascript unsafe "$1.uniform3iv($2, $3)"         glUniform3iv :: Ctx -> UniformLocation -> Int32Array -> IO ()  {--foreign import javascript unsafe "$1.uniform3iv($2 Sequence Int ->)"-        glUniform3iv :: Ctx -> UniformLocation -> Sequence Int -> IO ()+foreign import javascript unsafe "$1.uniform3iv($2 Sequence Int32 ->)"+        glUniform3iv :: Ctx -> UniformLocation -> Sequence Int32 -> IO () -}  foreign import javascript unsafe "$1.uniform4f($2, $3, $4, $5, $6)"@@ -423,14 +423,14 @@ -}  foreign import javascript unsafe "$1.uniform4i($2, $3, $4, $5, $6)"-        glUniform4i :: Ctx -> UniformLocation -> Int -> Int -> Int -> Int -> IO ()+        glUniform4i :: Ctx -> UniformLocation -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()  foreign import javascript unsafe "$1.uniform4iv($2, $3)"         glUniform4iv :: Ctx -> UniformLocation -> Int32Array -> IO ()  {--foreign import javascript unsafe "$1.uniform4iv($2 Sequence Int ->)"-        glUniform4iv :: Ctx -> UniformLocation -> Sequence Int -> IO ()+foreign import javascript unsafe "$1.uniform4iv($2 Sequence Int32 ->)"+        glUniform4iv :: Ctx -> UniformLocation -> Sequence Int32 -> IO () -}  foreign import javascript unsafe "$1.uniformMatrix2fv($2, $3, $4)"@@ -508,10 +508,10 @@ -}  foreign import javascript unsafe "$1.vertexAttribPointer($2, $3, $4, $5, $6, $7)"-        glVertexAttribPointer :: Ctx -> Word -> Int -> Word -> Bool -> Int -> Word -> IO ()+        glVertexAttribPointer :: Ctx -> Word -> Int32 -> Word -> Bool -> Int32 -> Word -> IO ()  foreign import javascript unsafe "$1.viewport($2, $3, $4, $5)"-        glViewport :: Ctx -> Int -> Int -> Int -> Int -> IO ()+        glViewport :: Ctx -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()  -- Extensions 
LICENSE view
@@ -13,7 +13,7 @@       disclaimer in the documentation and/or other materials provided       with the distribution. -    * Neither the name of Luca "ZioCrocifisso" Prezzavento nor the names of other+    * Neither the name of Luca Prezzavento nor the names of other       contributors may be used to endorse or promote products derived       from this software without specific prior written permission. 
fwgl-javascript.cabal view
@@ -1,5 +1,5 @@ name:                fwgl-javascript-version:             0.1.1.0+version:             0.1.1.1 synopsis:            FWGL GHCJS backend description:         FWGL GHCJS backend homepage:            https://github.com/ziocroc/FWGL@@ -16,6 +16,6 @@   exposed-modules:     FWGL.Backend.JavaScript   other-modules:       FWGL.Backend.JavaScript.WebGL, FWGL.Backend.JavaScript.Event, FWGL.Backend.JavaScript.WebGL.Const, FWGL.Backend.JavaScript.WebGL.Types, FWGL.Backend.JavaScript.WebGL.Raw   other-extensions:    FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances-  build-depends:       fwgl >= 0.1.3 && < 0.1.4, base >=4.7 && <4.9, hashable >=1.2 && <1.3, unordered-containers >=0.2 && <0.3, ghcjs-base, vect+  build-depends:       fwgl >= 0.1.4 && < 0.1.5, base >=4.7 && <4.9, hashable >=1.2 && <1.3, unordered-containers >=0.2 && <0.3, ghcjs-base, vect   hs-source-dirs:      .   default-language:    Haskell2010