diff --git a/app/Main.hs b/app/Main.hs index d0f1de9..ce1eec7 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -54,14 +54,13 @@ loadState = do <$> (SubWindow <$> newTVarIO []) <*> (SubMouse <$> newTVarIO []) - rawImg <- readImage "assets/img/lynx.jpg" - let img = case eRawImg of - Left err -> error err - Right dynImg -> convertRGBA8 dynImg + spriteDetails <- loadSprites return UserData { udSubsystems = subs - , udAssetSprites = M.singleton "lynx" (Sprite (V2 0 0) img) + , udRenderAssets = RenderAssets + { assetSprites = spriteDetails + } } handle = return () @@ -69,5 +68,6 @@ handle = return () updateLoop = return () drawLoop = do - ud@(UserData subs sprites) <- getAffection - draw + ud@(UserData subs rassets) <- getAffection + let (RenderAssets sDetails@(svo sso sdo)) = rassets + mapM_ (draw svo sso) (assocs sdo) diff --git a/app/Renderer.hs b/app/Renderer.hs index d33b0c3..0062c66 100644 --- a/app/Renderer.hs +++ b/app/Renderer.hs @@ -68,3 +68,21 @@ initSpriteShaderObjects = do GL.attachShader shaderProgram fragmentShader GL.linkProgram shaderProgram + + return (SpriteShaderObjects vertexShader fragmentShader shaderProgram) + +loadSprites :: IO (AssetDetails SpriteRenderObjects SpriteShaderObjects Sprite) +loadSprites = do + rawImg <- readImage "assets/img/lynx.jpg" + let img = case eRawImg of + Left err -> error err + Right dynImg -> convertRGBA8 dynImg + + vertObj <- initSpriteRenderObjects + shadObj <- initSpriteShaderobjects + + return AssetDetails + { adVertObj = vertObj + , adShadObj = shadObj + , adDataObj = M.singleton "lynx" (Sprite (V2 0 0) img) + } diff --git a/app/Types/UserData.hs b/app/Types/UserData.hs index 1769851..ebf3a25 100644 --- a/app/Types/UserData.hs +++ b/app/Types/UserData.hs @@ -17,11 +17,21 @@ import Codec.Picture import Types.Sprite data UserData = UserData - { udSubsystems :: Subsystems - , udAssetSprites :: M.Map ImgId Sprite + { udSubsystems :: Subsystems + , udRenderAssets :: RenderAssets } -type ImgId = String +data RenderAssets = RenderAssets + { assetSprites :: AssetDetails SpriteRenderObjects SpriteShaderObjects Sprite + } + +data Renderable dat => AssetDetails vo so dat = AssetDetails + { adVertObj :: vo + , adShadObj :: so + , adDataObj :: M.Map AssetId dat + } + +type AssetId = String data Subsystems = Subsystems { subWindow :: SubWindow