public override void Draw(GameTime gameTime) { if (SceneInstance == null || MainRenderFrame == null) { return; } // If the width or height changed, we have to recycle all temporary allocated resources. // NOTE: We assume that they are mostly resolution dependent. if (previousWidth != MainRenderFrame.Width || previousHeight != MainRenderFrame.Height) { // Force a recycle of all allocated temporary textures renderContext.Allocator.Recycle(link => true); } previousWidth = MainRenderFrame.Width; previousHeight = MainRenderFrame.Height; // Update the entities at draw time. renderContext.Time = gameTime; SceneInstance.Draw(renderContext); // Render phase SceneInstance.Draw(renderDrawContext, MainRenderFrame); }
protected override void LoadContent() { var assetManager = Services.GetSafeServiceAs <ContentManager>(); var graphicsContext = Services.GetSafeServiceAs <GraphicsContext>(); // Preload the scene if it exists if (InitialSceneUrl != null && assetManager.Exists(InitialSceneUrl)) { SceneInstance = new SceneInstance(Services, assetManager.Load <Scene>(InitialSceneUrl)); } if (MainRenderFrame == null) { // TODO GRAPHICS REFACTOR Check if this is a good idea to use Presenter targets MainRenderFrame = RenderFrame.FromTexture(GraphicsDevice.Presenter?.BackBuffer, GraphicsDevice.Presenter?.DepthStencilBuffer); if (MainRenderFrame != null) { previousWidth = MainRenderFrame.Width; previousHeight = MainRenderFrame.Height; } } // Create the drawing context renderContext = RenderContext.GetShared(Services); renderDrawContext = new RenderDrawContext(Services, renderContext, graphicsContext); }
protected override void LoadContent() { var assetManager = Services.GetSafeServiceAs<ContentManager>(); var graphicsContext = Services.GetSafeServiceAs<GraphicsContext>(); // Preload the scene if it exists if (InitialSceneUrl != null && assetManager.Exists(InitialSceneUrl)) { SceneInstance = new SceneInstance(Services, assetManager.Load<Scene>(InitialSceneUrl)); } if (MainRenderFrame == null) { // TODO GRAPHICS REFACTOR Check if this is a good idea to use Presenter targets MainRenderFrame = RenderFrame.FromTexture(GraphicsDevice.Presenter?.BackBuffer, GraphicsDevice.Presenter?.DepthStencilBuffer); if (MainRenderFrame != null) { previousWidth = MainRenderFrame.Width; previousHeight = MainRenderFrame.Height; } } // Create the drawing context renderContext = RenderContext.GetShared(Services); renderDrawContext = new RenderDrawContext(Services, renderContext, graphicsContext); }
public override void Update(GameTime gameTime) { if (SceneInstance != null) { SceneInstance.Update(gameTime); } }
private SceneInstance GetChildSceneInstance() { if (ChildScene == null || !ChildScene.Enabled) { return(null); } currentSceneInstance = SceneInstance.GetCurrent(Context); childSceneProcessor = childSceneProcessor ?? currentSceneInstance.GetProcessor <ChildSceneProcessor>(); return(childSceneProcessor?.GetSceneInstance(ChildScene)); }
private SceneInstance GetChildSceneInstance() { if (ChildScene == null || !ChildScene.Enabled) { return null; } currentSceneInstance = SceneInstance.GetCurrent(Context); childSceneProcessor = childSceneProcessor ?? currentSceneInstance.GetProcessor<ChildSceneProcessor>(); return childSceneProcessor?.GetSceneInstance(ChildScene); }
protected override void LoadContent() { var content = Services.GetSafeServiceAs <ContentManager>(); var graphicsContext = Services.GetSafeServiceAs <GraphicsContext>(); if (SplashScreenUrl != null && content.Exists(SplashScreenUrl)) { splashScreenTexture = content.Load <Texture>(SplashScreenUrl); splashScreenState = splashScreenTexture != null ? SplashScreenState.Intro : SplashScreenState.Invalid; SplashScreenEnabled = true; } // Preload the scene if it exists and show splash screen if (InitialSceneUrl != null && content.Exists(InitialSceneUrl)) { if (SplashScreenEnabled) { sceneTask = content.LoadAsync <Scene>(InitialSceneUrl); } else { SceneInstance = new SceneInstance(Services, content.Load <Scene>(InitialSceneUrl)); } } if (InitialGraphicsCompositorUrl != null && content.Exists(InitialGraphicsCompositorUrl)) { if (SplashScreenEnabled) { compositorTask = content.LoadAsync <GraphicsCompositor>(InitialGraphicsCompositorUrl); } else { GraphicsCompositor = content.Load <GraphicsCompositor>(InitialGraphicsCompositorUrl); } } // Create the drawing context renderContext = RenderContext.GetShared(Services); renderDrawContext = new RenderDrawContext(Services, renderContext, graphicsContext); }
protected override void DrawCore(RenderContext context, RenderFrame output) { if (ChildScene == null || !ChildScene.Enabled) { return; } currentSceneInstance = SceneInstance.GetCurrent(Context); childSceneProcessor = childSceneProcessor ?? currentSceneInstance.GetProcessor<ChildSceneProcessor>(); if (childSceneProcessor == null) { return; } SceneInstance sceneInstance = childSceneProcessor.GetSceneInstance(ChildScene); if (sceneInstance != null) { sceneInstance.Draw(context, output, GraphicsCompositorOverride); } }
protected override void LoadContent() { var assetManager = Services.GetSafeServiceAs <AssetManager>(); // Preload the scene if it exists if (InitialSceneUrl != null && assetManager.Exists(InitialSceneUrl)) { SceneInstance = new SceneInstance(Services, assetManager.Load <Scene>(InitialSceneUrl)); } if (MainRenderFrame == null) { MainRenderFrame = RenderFrame.FromTexture(GraphicsDevice.BackBuffer, GraphicsDevice.DepthStencilBuffer); if (MainRenderFrame != null) { previousWidth = MainRenderFrame.Width; previousHeight = MainRenderFrame.Height; } } // Create the drawing context renderContext = RenderContext.GetShared(Services); }
protected override void LoadContent() { var assetManager = Services.GetSafeServiceAs<AssetManager>(); // Preload the scene if it exists if (InitialSceneUrl != null && assetManager.Exists(InitialSceneUrl)) { SceneInstance = new SceneInstance(Services, assetManager.Load<Scene>(InitialSceneUrl)); } if (MainRenderFrame == null) { MainRenderFrame = RenderFrame.FromTexture(GraphicsDevice.BackBuffer, GraphicsDevice.DepthStencilBuffer); if (MainRenderFrame != null) { previousWidth = MainRenderFrame.Width; previousHeight = MainRenderFrame.Height; } } // Create the drawing context renderContext = RenderContext.GetShared(Services); }
protected override void DrawCore(RenderContext context, RenderFrame output) { if (ChildScene == null || !ChildScene.Enabled) { return; } currentSceneInstance = SceneInstance.GetCurrent(Context); childSceneProcessor = childSceneProcessor ?? currentSceneInstance.GetProcessor <ChildSceneProcessor>(); if (childSceneProcessor == null) { return; } SceneInstance sceneInstance = childSceneProcessor.GetSceneInstance(ChildScene); if (sceneInstance != null) { sceneInstance.Draw(context, output, GraphicsCompositorOverride); } }
public override void Draw(GameTime gameTime) { // Reset the context renderContext.Reset(); var renderTarget = renderDrawContext.CommandList.RenderTarget; // If the width or height changed, we have to recycle all temporary allocated resources. // NOTE: We assume that they are mostly resolution dependent. if (previousWidth != renderTarget.ViewWidth || previousHeight != renderTarget.ViewHeight) { // Force a recycle of all allocated temporary textures renderContext.Allocator.Recycle(link => true); } previousWidth = renderTarget.ViewWidth; previousHeight = renderTarget.ViewHeight; // Update the entities at draw time. renderContext.Time = gameTime; // Execute Draw step of SceneInstance // This will run entity processors SceneInstance?.Draw(renderContext); // Render phase // TODO GRAPHICS REFACTOR //context.GraphicsDevice.Parameters.Set(GlobalKeys.Time, (float)gameTime.Total.TotalSeconds); //context.GraphicsDevice.Parameters.Set(GlobalKeys.TimeStep, (float)gameTime.Elapsed.TotalSeconds); renderDrawContext.ResourceGroupAllocator.Flush(); renderDrawContext.QueryManager.Flush(); // Push context (pop after using) using (renderDrawContext.RenderContext.PushTagAndRestore(SceneInstance.Current, SceneInstance)) { GraphicsCompositor?.Draw(renderDrawContext); } //do this here, make sure GCompositor and Scene are updated/rendered the next frame! if (sceneTask != null && compositorTask != null) { switch (splashScreenState) { case SplashScreenState.Invalid: { if (sceneTask.IsCompleted && compositorTask.IsCompleted) { SceneInstance = new SceneInstance(Services, sceneTask.Result); GraphicsCompositor = compositorTask.Result; sceneTask = null; compositorTask = null; } } break; case SplashScreenState.Intro: { Game.GraphicsContext.CommandList.Clear(Game.GraphicsContext.CommandList.RenderTarget, SplashScreenColor); if (gameTime.Total.TotalSeconds > SplashScreenFadeTime) { splashScreenState = SplashScreenState.FadingIn; fadeTime = 0.0f; } } break; case SplashScreenState.FadingIn: { var color = Color4.White; var factor = MathUtil.SmoothStep((float)fadeTime / SplashScreenFadeTime); color *= factor; if (factor >= 1.0f) { splashScreenState = SplashScreenState.Showing; } fadeTime += gameTime.Elapsed.TotalSeconds; RenderSplashScreen(color, BlendStates.AlphaBlend); } break; case SplashScreenState.Showing: { RenderSplashScreen(Color4.White, BlendStates.Default); if (gameTime.Total.TotalSeconds > MinSplashScreenTime && sceneTask.IsCompleted && compositorTask.IsCompleted) { splashScreenState = SplashScreenState.FadingOut; fadeTime = 0.0f; } } break; case SplashScreenState.FadingOut: { var color = Color4.White; var factor = (MathUtil.SmoothStep((float)fadeTime / SplashScreenFadeTime) * -1) + 1; color *= factor; if (factor <= 0.0f) { splashScreenState = SplashScreenState.Invalid; } fadeTime += gameTime.Elapsed.TotalSeconds; RenderSplashScreen(color, BlendStates.AlphaBlend); } break; } } }
public override void Update(GameTime gameTime) { // Execute Update step of SceneInstance // This will run entity processors SceneInstance?.Update(gameTime); }