Ejemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="waitForVSync"></param>
 public override void SwapBuffers(bool waitForVSync)
 {
     D3D.Device device = driver.Device;
     if (device != null)
     {
         int status;
         // tests coop level to make sure we are ok to render
         device.CheckCooperativeLevel(out status);
         if (status == (int)Microsoft.DirectX.Direct3D.ResultCode.Success)
         {
             // swap back buffer to the front
             if (isSwapChain)
             {
                 swapChain.Present();
             }
             else
             {
                 device.Present();
             }
         }
         else if (status == (int)Microsoft.DirectX.Direct3D.ResultCode.DeviceLost)
         {
             // Device is lost, and is not available for reset now
             log.Warn("Device State: DeviceLost");
             D3D9RenderSystem renderSystem = (D3D9RenderSystem)Root.Instance.RenderSystem;
             renderSystem.NotifyDeviceLost();
         }
         else if (status == (int)Microsoft.DirectX.Direct3D.ResultCode.DeviceNotReset)
         {
             // The device needs to be reset, and has not yet been reset.
             log.Warn("Device State: DeviceNotReset");
             device.Reset(device.PresentationParameters);
         }
         else
         {
             throw new Exception(string.Format("Unknown status code from CheckCooperativeLevel: {0}", status));
         }
     }
 }
Ejemplo n.º 2
0
        public void WindowMovedOrResized()
        {
            log.Info("D3DRenderWindow.WindowMovedOrResized called.");
            if (windowHandle == null)
            {
                return;
            }
            Form form = windowHandle.FindForm();

            if (form != null)
            {
                if (form.WindowState == FormWindowState.Minimized)
                {
                    return;
                }

                this.top  = form.DesktopLocation.Y;
                this.left = form.DesktopLocation.X;
            }

            if ((width == windowHandle.Size.Width) && (height == windowHandle.Size.Height))
            {
                return;
            }

            if (isSwapChain)
            {
                PresentParameters pp = new PresentParameters(presentParams);
                width  = windowHandle.Size.Width > 0 ? windowHandle.Size.Width : 1;
                height = windowHandle.Size.Height > 0 ? windowHandle.Size.Height : 1;
                if (presentParams.Windowed)
                {
                    pp.BackBufferWidth  = width;
                    pp.BackBufferHeight = height;
                }
                if (renderZBuffer != null)
                {
                    renderZBuffer.Dispose();
                    renderZBuffer = null;
                }
                if (swapChain != null)
                {
                    swapChain.Dispose();
                    swapChain = null;
                }
                if (renderSurface != null)
                {
                    renderSurface.Dispose();
                    renderSurface = null;
                }

                swapChain     = new SwapChain(driver.Device, pp);
                presentParams = pp;

                renderSurface = swapChain.GetBackBuffer(0, BackBufferType.Mono);
                renderZBuffer =
                    driver.Device.CreateDepthStencilSurface(presentParams.BackBufferWidth,
                                                            presentParams.BackBufferHeight,
                                                            presentParams.AutoDepthStencilFormat,
                                                            presentParams.MultiSample,
                                                            presentParams.MultiSampleQuality,
                                                            false);

                // TODO: Ogre releases here
                // renderSurface.Release();
            }
            else
            {
                // primary windows must reset the device
                width  = windowHandle.Size.Width > 0 ? windowHandle.Size.Width : 1;
                height = windowHandle.Size.Height > 0 ? windowHandle.Size.Height : 1;
                if (presentParams.Windowed)
                {
                    presentParams.BackBufferWidth  = width;
                    presentParams.BackBufferHeight = height;
                }
                D3D9RenderSystem renderSystem = (D3D9RenderSystem)Root.Instance.RenderSystem;
                renderSystem.NotifyDeviceLost();
            }
            // Notify viewports of resize
            foreach (Axiom.Core.Viewport viewport in viewportList)
            {
                viewport.UpdateDimensions();
            }
        }