private void UpdateScene() { if (RenderImage.IsFrontBufferAvailable) { int w = System.Convert.ToInt32(RenderTarget.ActualWidth); int h = System.Convert.ToInt32(RenderTarget.ActualHeight); if (w == 0 || h == 0) { return; } RenderImage.Lock(); if (RenderImage.PixelWidth != w || RenderImage.PixelHeight != h) { RenderImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero); Rush.RushResize(w, h); RenderSurface = Rush.RushGetBackBuffer(); RenderImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, RenderSurface); } Rush.RushUpdate(); if (RenderSurface != IntPtr.Zero) { Int32Rect rect = new Int32Rect(0, 0, w, h); RenderImage.AddDirtyRect(rect); } RenderImage.Unlock(); } }
private void BeginRenderingScene() { RenderSurface = Rush.RushGetBackBuffer(); if (RenderImage.IsFrontBufferAvailable && RenderSurface != IntPtr.Zero) { // set the back buffer using the new scene pointer RenderImage.Lock(); RenderImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, RenderSurface); RenderImage.Unlock(); // leverage the Rendering event of WPF's composition target to // update the custom D3D scene CompositionTarget.Rendering += OnRendering; } }