Exemplo n.º 1
0
        }         // GetParameters()

        #endregion

        #region Start
        /// <summary>
        /// Start this post screen shader, will just call SetRenderTarget.
        /// All render calls will now be drawn on the sceneMapTexture.
        /// Make sure you don't reset the RenderTarget until you call Show()!
        /// </summary>
        public void Start()
        {
            // Only apply post screen shader if texture is valid and effect is valid
            if (sceneMapTexture == null ||
                effect == null ||
                started == true ||
                // Also skip if we don't use post screen shaders at all!
                BaseGame.UsePostScreenShaders == false)
            {
                return;
            }

            RenderToTexture.SetRenderTarget(sceneMapTexture.RenderTarget, true);
            started = true;
        }         // Start()
        //*/

        /// <summary>
        /// Test create render to texture
        /// </summary>
        public static void TestCreateRenderToTexture()
        {
            Model testModel = null;
            RenderToTexture renderToTexture = null;

            TestGame.Start(
                "TestCreateRenderToTexture",
                delegate
                {
                    testModel = new Model("asteroid1");
                    renderToTexture = new RenderToTexture(
                        //SizeType.QuarterScreen);
                        SizeType.HalfScreen);
                        //SizeType.HalfScreenWithZBuffer);
                        //SizeType.FullScreen);
                        //SizeType.ShadowMap);
                },
                delegate
                {
                    bool renderToTextureWay =
                        Input.Keyboard.IsKeyUp(Keys.Space) &&
                        Input.GamePadAPressed == false;
                    BaseGame.Device.RenderState.DepthBufferEnable = true;

                    if (renderToTextureWay)
                    {
                        // Set render target to our texture
                        renderToTexture.SetRenderTarget();

                        // Clear background
                        renderToTexture.Clear(Color.Blue);

                        // Draw background lines
                        //Line.DrawGrid();
                        //Ui.LineManager.RenderAll3DLines();

                        // And draw object
                        testModel.Render(Matrix.CreateScale(7.5f));
                        //BaseGame.RenderManager.RenderAllMeshes();

                        // Do we need to resolve?
                        renderToTexture.Resolve(true);
                        //BaseGame.Device.ResolveRenderTarget(0);

                        // Reset background buffer
                        //not longer required, done in Resolve now:
                        //RenderToTexture.ResetRenderTarget(true);
                    } // if (renderToTextureWay)
                    else
                    {
                        // Copy backbuffer way, render stuff normally first
                        // Clear background
                        BaseGame.Device.Clear(Color.Blue);

                        // Draw background lines
                        //Line.DrawGrid();
                        //Ui.LineManager.RenderAll3DLines();

                        // And draw object
                        testModel.Render(Matrix.CreateScale(7.5f));
                        //BaseGame.RenderManager.RenderAllMeshes();
                    } // else

                    // Show render target in a rectangle on our screen
                    renderToTexture.RenderOnScreen(
                        //tst:
                        new Rectangle(100, 100, 256, 256));
                    //BaseGame.ScreenRectangle);
                    //no need: BaseGame.UI.FlushUI();

                    TextureFont.WriteText(2, 0,
                        "               Press Space to toogle full screen rendering");
                    TextureFont.WriteText(2, 30,
                        "renderToTexture.Width=" + renderToTexture.Width);
                    TextureFont.WriteText(2, 60,
                        "renderToTexture.Height=" + renderToTexture.Height);
                    TextureFont.WriteText(2, 90,
                        "renderToTexture.Valid=" + renderToTexture.IsValid);
                    TextureFont.WriteText(2, 120,
                        "renderToTexture.XnaTexture=" + renderToTexture.XnaTexture);
                    TextureFont.WriteText(2, 150,
                        "renderToTexture.ZBufferSurface=" + renderToTexture.ZBufferSurface);
                    TextureFont.WriteText(2, 180,
                        "renderToTexture.Filename=" + renderToTexture.Filename);
                });
        }
        }         // ResetRenderTarget(fullResetToBackBuffer)

        #endregion

        #region Unit Testing
#if DEBUG
        /// <summary>
        /// Test create render to texture
        /// </summary>
        static public void TestCreateRenderToTexture()
        {
            Model           testModel       = null;
            RenderToTexture renderToTexture = null;

            TestGame.Start(
                "TestCreateRenderToTexture",
                delegate
            {
                testModel       = new Model("asteroid1");
                renderToTexture = new RenderToTexture(
                    //SizeType.QuarterScreen);
                    SizeType.HalfScreen);
                //SizeType.HalfScreenWithZBuffer);
                //SizeType.FullScreen);
                //SizeType.ShadowMap);
            },
                delegate
            {
                bool renderToTextureWay =
                    Input.Keyboard.IsKeyUp(Keys.Space) &&
                    Input.GamePadAPressed == false;
                BaseGame.Device.RenderState.DepthBufferEnable = true;

                if (renderToTextureWay)
                {
                    // Set render target to our texture
                    renderToTexture.SetRenderTarget();

                    // Clear background
                    renderToTexture.Clear(Color.Blue);

                    // Draw background lines
                    //Line.DrawGrid();
                    //Ui.LineManager.RenderAll3DLines();

                    // And draw object
                    testModel.Render(Matrix.CreateScale(7.5f));
                    //BaseGame.RenderManager.RenderAllMeshes();

                    // Do we need to resolve?
                    renderToTexture.Resolve(true);
                    //BaseGame.Device.ResolveRenderTarget(0);

                    // Reset background buffer
                    //not longer required, done in Resolve now:
                    //RenderToTexture.ResetRenderTarget(true);
                }                         // if (renderToTextureWay)
                else
                {
                    // Copy backbuffer way, render stuff normally first
                    // Clear background
                    BaseGame.Device.Clear(Color.Blue);

                    // Draw background lines
                    //Line.DrawGrid();
                    //Ui.LineManager.RenderAll3DLines();

                    // And draw object
                    testModel.Render(Matrix.CreateScale(7.5f));
                    //BaseGame.RenderManager.RenderAllMeshes();
                }                         // else

                // Show render target in a rectangle on our screen
                renderToTexture.RenderOnScreen(
                    //tst:
                    new Rectangle(100, 100, 256, 256));
                //BaseGame.ScreenRectangle);
                //no need: BaseGame.UI.FlushUI();

                TextureFont.WriteText(2, 0,
                                      "               Press Space to toogle full screen rendering");
                TextureFont.WriteText(2, 30,
                                      "renderToTexture.Width=" + renderToTexture.Width);
                TextureFont.WriteText(2, 60,
                                      "renderToTexture.Height=" + renderToTexture.Height);
                TextureFont.WriteText(2, 90,
                                      "renderToTexture.Valid=" + renderToTexture.IsValid);
                TextureFont.WriteText(2, 120,
                                      "renderToTexture.XnaTexture=" + renderToTexture.XnaTexture);
                TextureFont.WriteText(2, 150,
                                      "renderToTexture.ZBufferSurface=" + renderToTexture.ZBufferSurface);
                TextureFont.WriteText(2, 180,
                                      "renderToTexture.Filename=" + renderToTexture.Filename);
            });
        }         // TestCreateRenderToTexture()