/// <summary> /// エンジンを初期化します。 /// </summary> /// <param name="title">ウィンドウタイトル</param> /// <param name="width">ウィンドウの横幅</param> /// <param name="height">ウィンドウの縦幅</param> /// <param name="config">設定</param> /// <returns>初期化に成功したらtrue、それ以外でfalse</returns> public static bool Initialize(string title, int width, int height, Configuration config = null) { _Config = (config ??= new Configuration()); if (Core.Initialize(title, width, height, config)) { Core = Core.GetInstance(); Log = Log.GetInstance(); Keyboard = Keyboard.GetInstance(); Mouse = Mouse.GetInstance(); Joystick = Joystick.GetInstance(); File = File.GetInstance(); Resources = Resources.GetInstance(); Window = Window.GetInstance(); Graphics = Graphics.GetInstance(); Renderer = Renderer.GetInstance(); CullingSystem = CullingSystem.GetInstance(); Context = new AltseedContext(); System.Threading.SynchronizationContext.SetSynchronizationContext(Context); if (config.ToolEnabled) { Tool = Tool.GetInstance(); } Sound = SoundMixer.GetInstance(); _RootNode = new RootNode(); _UpdatedNode = _RootNode; _DrawnNodes = new DrawnNodeCollection(); _PostEffectNodes = new PostEffectNodeCollection(); _CameraNodes = new CameraNodeCollection(); _DefaultCamera = RenderedCamera.Create(); _DefaultCamera.RenderPassParameter = new RenderPassParameter(new Color(50, 50, 50, 255), true, true); _RenderTextureCache = new RenderTextureCache(); PostEffectNode.InitializeCache(); return(true); } return(false); }
internal static void UpdatePostEffectNodeOrder(PostEffectNode node, int oldOrder) { _PostEffectNodes.UpdateOrder(node, oldOrder); }
internal static void UpdatePostEffectNodeCameraGroup(PostEffectNode node, uint oldCameraGroup) { _PostEffectNodes.UpdateCameraGroup(node, oldCameraGroup); }
internal static void UnregisterPostEffectNode(PostEffectNode node) { _PostEffectNodes.RemoveNode(node); }
internal static void RegisterPostEffectNode(PostEffectNode node) { _PostEffectNodes.AddNode(node); }
/// <summary> /// エンジンを更新します。 /// </summary> public static bool Update() { // ノードの更新 _UpdatedNode?.Update(); // Contextの更新 Context.Update(); // RenderedにTransform反映 foreach (var node in _DrawnNodes.Nodes.SelectMany(obj => obj.Value)) { node.UpdateInheritedTransform(); } // カリング用AABBの更新 CullingSystem.UpdateAABB(); // (ツール機能を使用しない場合は)描画を開始 if (!_Config.ToolEnabled) { //ツール機能を使用するときはDoEventsでフレームを開始 //使用しないときはUpdateでフレームを開始 if (!Graphics.BeginFrame(new RenderPassParameter(ClearColor, true, true))) { return(false); } } if (_CameraNodes.Count == 0) { // カメラが 1 つもない場合はデフォルトカメラを使用 Renderer.SetCamera(_DefaultCamera); { var cullingIds = CullingSystem.DrawingRenderedIds.ToArray(); var list = _DrawnNodes.Nodes; foreach (var z in list.Keys.OrderBy(x => x)) { var nodes = list[z]; foreach (var node in cullingIds.Join(nodes, id => id, n => n.CullingId, (id, n) => n)) { node.Draw(); } } Renderer.Render(); } { var list = _PostEffectNodes.Nodes; RenderTexture buffer = null; foreach (var z in list.Keys.OrderBy(x => x)) { foreach (var node in list[z]) { if (buffer is null) { buffer = _RenderTextureCache.GetRenderTexture(Graphics.CommandList.GetScreenTexture().Size); } Graphics.CommandList.CopyTexture(Graphics.CommandList.GetScreenTexture(), buffer); node.CallDraw(buffer); } } } } else { // 特定のカメラに映りこむノードを描画 for (int i = 0; i <= 31; i++) { foreach (var camera in _CameraNodes[i]) { Renderer.SetCamera(camera.RenderedCamera); { var cullingIds = CullingSystem.DrawingRenderedIds.ToArray(); var list = _DrawnNodes[i]; foreach (var z in list.Keys.OrderBy(x => x)) { var nodes = list[z]; foreach (var node in cullingIds.Join(nodes, id => id, n => n.CullingId, (id, n) => n)) { node.Draw(); } } Renderer.Render(); } { var list = _PostEffectNodes[i]; var target = camera.TargetTexture ?? Graphics.CommandList.GetScreenTexture(); RenderTexture buffer = null; foreach (var z in list.Keys.OrderBy(x => x)) { foreach (var node in list[z]) { if (buffer is null) { buffer = _RenderTextureCache.GetRenderTexture(target.Size); } Graphics.CommandList.CopyTexture(target, buffer); node.CallDraw(buffer); } } } } } } _RenderTextureCache.Update(); PostEffectNode.UpdateCache(); // (ツール機能を使用する場合は)ツールを描画 if (_Config.ToolEnabled) { Tool.Render(); } // 描画を終了 if (!Graphics.EndFrame()) { return(false); } return(true); }