internal void DestroyViewport()
            {
                if (renderTargetListener != null)
                {
                    RenderTarget renderTarget = texture.GetBuffer().GetRenderTarget();
                    renderTarget.RemoveListener(renderTargetListener);
                    renderTargetListener.Dispose();
                    renderTargetListener = null;
                }
                if (viewport != null)
                {
                    viewport.Dispose();
                    viewport = null;
                }
                if (camera != null)
                {
                    camera.Dispose();
                    camera = null;
                }
                if (texture != null)
                {
                    texture.Dispose();
                    texture = null;
                    instance.preventTextureCreationRemainingFrames = 2;
                }

                initializedTextureSize = Vec2I.Zero;
            }
            private void CreateViewport()
            {
                int index = instance.views.IndexOf(this);

                DestroyViewport();

                Vec2I textureSize = GetNeededTextureSize();

                string textureName = TextureManager.Instance.GetUniqueName(
                    string.Format("MultiViewRendering{0}", index));
                PixelFormat format = PixelFormat.R8G8B8;

                int fsaa;
                if (!int.TryParse(RendererWorld.InitializationOptions.FullSceneAntialiasing, out fsaa))
                    fsaa = 0;

                texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D,
                    textureSize, 1, 0, format, Texture.Usage.RenderTarget, false, fsaa);
                if (texture == null)
                {
                    Log.Fatal("MultiViewRenderingManager: Unable to create texture.");
                    return;
                }

                RenderTarget renderTarget = texture.GetBuffer().GetRenderTarget();
                renderTarget.AutoUpdate = true;
                renderTarget.AllowAdditionalMRTs = true;

                //create camera
                camera = SceneManager.Instance.CreateCamera(
                    SceneManager.Instance.GetUniqueCameraName(string.Format("MultiViewRendering{0}", index)));
                camera.Purpose = Camera.Purposes.MainCamera;

                //add viewport
                viewport = renderTarget.AddViewport(camera, 0);
                viewport.ShadowsEnabled = true;

                //Create compositor for HDR render technique
                bool hdrCompositor =
                    RendererWorld.Instance.DefaultViewport.GetCompositorInstance("HDR") != null;
                if (hdrCompositor)
                {
                    viewport.AddCompositor("HDR");
                    viewport.SetCompositorEnabled("HDR", true);
                }

                //FXAA antialiasing post effect
                bool fxaaCompositor =
                    RendererWorld.Instance.DefaultViewport.GetCompositorInstance("FXAA") != null;
                if (fxaaCompositor)
                {
                    viewport.AddCompositor("FXAA");
                    viewport.SetCompositorEnabled("FXAA", true);
                }

                //add listener
                renderTargetListener = new ViewRenderTargetListener(this);
                renderTarget.AddListener(renderTargetListener);

                initializedTextureSize = textureSize;
            }
Exemplo n.º 3
0
        void DestroyRenderTarget()
        {
            if( renderTexture != null )
            {
                // set output to background image
                Background = null;

                if( d3dImage != null )
                {
                    d3dImage.Lock();
                    d3dImage.SetBackBuffer( D3DResourceType.IDirect3DSurface9, IntPtr.Zero );
                    d3dImage.Unlock();
                }

                if( renderTargetListener != null )
                {
                    renderTexture.RemoveListener( renderTargetListener );
                    renderTargetListener.Dispose();
                    renderTargetListener = null;
                }

                viewport.Dispose();
                viewport = null;

                camera.Dispose();
                camera = null;

                texture.Dispose();
                texture = null;

                renderTexture = null;
            }
        }
Exemplo n.º 4
0
        bool CreateRenderTarget()
        {
            DestroyRenderTarget();

            if( RendererWorld.Instance == null )
                return false;

            Vec2I textureSize = GetDemandTextureSize();
            if( textureSize.X < 1 || textureSize.Y < 1 )
                return false;

            string textureName = TextureManager.Instance.GetUniqueName( "WPFRenderTexture" );

            int hardwareFSAA = 0;
            if( !RendererWorld.InitializationOptions.AllowSceneMRTRendering )
            {
                if( !int.TryParse( RendererWorld.InitializationOptions.FullSceneAntialiasing, out hardwareFSAA ) )
                    hardwareFSAA = 0;
            }

            texture = TextureManager.Instance.Create( textureName, Texture.Type.Type2D, textureSize,
                1, 0, Engine.Renderer.PixelFormat.R8G8B8, Texture.Usage.RenderTarget, false, hardwareFSAA );

            if( texture == null )
                return false;

            currentTextureSize = textureSize;

            renderTexture = texture.GetBuffer().GetRenderTarget();
            renderTexture.AutoUpdate = false;
            renderTexture.AllowAdditionalMRTs = true;

            camera = SceneManager.Instance.CreateCamera(
                SceneManager.Instance.GetUniqueCameraName( "UserControl" ) );
            camera.Purpose = Camera.Purposes.MainCamera;

            //update camera settings
            camera.NearClipDistance = cameraNearFarClipDistance.Minimum;
            camera.FarClipDistance = cameraNearFarClipDistance.Maximum;
            camera.AspectRatio = (float)texture.Size.X / (float)texture.Size.Y;
            camera.FixedUp = cameraFixedUp;
            camera.Position = cameraPosition;
            camera.Direction = cameraDirection;
            camera.Fov = cameraFov;
            camera.ProjectionType = cameraProjectionType;
            camera.OrthoWindowHeight = cameraOrthoWindowHeight;

            viewport = renderTexture.AddViewport( camera );

            //Initialize HDR compositor for HDR render technique
            if( EngineApp.RenderTechnique == "HDR" )
            {
                viewport.AddCompositor( "HDR", 0 );
                viewport.SetCompositorEnabled( "HDR", true );
            }

            //Initialize Fast Approximate Antialiasing (FXAA)
            {
                bool useMRT = RendererWorld.InitializationOptions.AllowSceneMRTRendering;
                string fsaa = RendererWorld.InitializationOptions.FullSceneAntialiasing;
                if( ( useMRT && ( fsaa == "" || fsaa == "RecommendedSetting" ) && IsActivateFXAAByDefault() ) ||
                    fsaa == "FXAA" )
                {
                    if( RenderSystem.Instance.HasShaderModel3() )
                        InitializeFXAACompositor();
                }
            }

            //add listener
            renderTargetListener = new ViewRenderTargetListener( this );
            renderTexture.AddListener( renderTargetListener );

            if( guiRenderer == null )
                guiRenderer = new GuiRenderer( viewport );
            else
                guiRenderer.ChangeViewport( viewport );

            if( controlManager == null )
                controlManager = new ScreenControlManager( guiRenderer );

            //initialize D3DImage output
            if( d3dImageIsSupported && allowUsingD3DImage )
            {
                // create a D3DImage to host the scene and monitor it for changes in front buffer availability
                if( d3dImage == null )
                {
                    d3dImage = new D3DImage();
                    d3dImage.IsFrontBufferAvailableChanged += D3DImage_IsFrontBufferAvailableChanged;
                    CompositionTarget.Rendering += D3DImage_OnRendering;
                }

                // set output to background image
                Background = new ImageBrush( d3dImage );

                // set the back buffer using the new scene pointer
                HardwarePixelBuffer buffer = texture.GetBuffer( 0, 0 );
                GetD3D9HardwarePixelBufferData data = new GetD3D9HardwarePixelBufferData();
                data.hardwareBuffer = buffer._GetRealObject();
                data.outPointer = IntPtr.Zero;
                unsafe
                {
                    GetD3D9HardwarePixelBufferData* pData = &data;
                    if( !RenderSystem.Instance.CallCustomMethod( "Get D3D9HardwarePixelBuffer getSurface", (IntPtr)pData ) )
                        Log.Fatal( "Get D3D9HardwarePixelBuffer getSurface failed." );
                }
                d3dImage.Lock();
                d3dImage.SetBackBuffer( D3DResourceType.IDirect3DSurface9, data.outPointer );
                d3dImage.Unlock();
            }

            return true;
        }
        public void DestroyRenderTarget()
        {
            if (renderWindow != null)
            {
                if (renderTargetListener != null)
                {
                    renderWindow.RemoveListener(renderTargetListener);
                    renderTargetListener.Dispose();
                    renderTargetListener = null;
                }

                viewport.Dispose();
                viewport = null;

                camera.Dispose();
                camera = null;

                renderWindow.Dispose();
                renderWindow = null;
            }
        }
        private bool CreateRenderTarget()
        {
            DestroyRenderTarget();

            if (RendererWorld.Instance == null)
                return false;

            Vec2I size = new Vec2I(ClientRectangle.Size.Width, ClientRectangle.Size.Height);
            if (size.X < 1 || size.Y < 1)
                return false;

            renderWindow = RendererWorld.Instance.CreateRenderWindow(Handle, size);
            if (renderWindow == null)
                return false;

            renderWindow.AutoUpdate = false;
            renderWindow.AllowAdditionalMRTs = true;

            camera = SceneManager.Instance.CreateCamera(
                SceneManager.Instance.GetUniqueCameraName("UserControl"));
            camera.Purpose = Camera.Purposes.MainCamera;

            //update camera settings
            camera.NearClipDistance = cameraNearFarClipDistance.Minimum;
            camera.FarClipDistance = cameraNearFarClipDistance.Maximum;
            camera.AspectRatio = (float)renderWindow.Size.X / (float)renderWindow.Size.Y;
            camera.FixedUp = cameraFixedUp;
            camera.Position = cameraPosition;
            camera.Direction = cameraDirection;
            camera.Fov = cameraFov;
            camera.ProjectionType = cameraProjectionType;
            camera.OrthoWindowHeight = cameraOrthoWindowHeight;

            viewport = renderWindow.AddViewport(camera);

            //Initialize HDR compositor for HDR render technique
            if (EngineApp.RenderTechnique == "HDR")
            {
                viewport.AddCompositor("HDR", 0);
                viewport.SetCompositorEnabled("HDR", true);
            }

            //Initialize Fast Approximate Antialiasing (FXAA)
            {
                bool useMRT = RendererWorld.InitializationOptions.AllowSceneMRTRendering;
                string fsaa = RendererWorld.InitializationOptions.FullSceneAntialiasing;
                if ((useMRT && (fsaa == "" || fsaa == "RecommendedSetting") && IsActivateFXAAByDefault()) ||
                    fsaa == "FXAA")
                {
                    if (RenderSystem.Instance.HasShaderModel3())
                        InitializeFXAACompositor();
                }
            }

            //add listener
            renderTargetListener = new ViewRenderTargetListener(this);
            renderWindow.AddListener(renderTargetListener);

            if (guiRenderer == null)
                guiRenderer = new GuiRenderer(viewport);
            else
                guiRenderer.ChangeViewport(viewport);

            if (controlManager == null)
                controlManager = new ScreenControlManager(guiRenderer);

            return true;
        }