コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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;
                }
            }
        }