Esempio n. 1
0
        private PresentParameters CreateFullScreenPresentParameters(MDX1_DisplayWindow displayWindow,
                                                                    int width, int height, int bpp)
        {
            PresentParameters present = new PresentParameters();

            present.AutoDepthStencilFormat = DepthFormat.Unknown;
            present.EnableAutoDepthStencil = false;
            present.DeviceWindowHandle     = displayWindow.RenderTarget.Handle;
            present.BackBufferWidth        = width;
            present.BackBufferHeight       = height;
            present.SwapEffect             = SwapEffect.Flip;
            present.Windowed    = false;
            present.PresentFlag = PresentFlag.None;

            if (VSync)
            {
                present.PresentationInterval = PresentInterval.Default;
            }
            else
            {
                present.PresentationInterval = PresentInterval.Immediate;
            }

            SelectBestDisplayMode(present, bpp);

            return(present);
        }
Esempio n. 2
0
        private PresentParameters CreateWindowedPresentParameters(MDX1_DisplayWindow displayWindow,
                                                                  int width, int height)
        {
            PresentParameters present = new PresentParameters();

            present.BackBufferCount        = 1;
            present.AutoDepthStencilFormat = DepthFormat.Unknown;
            present.EnableAutoDepthStencil = false;
            present.DeviceWindowHandle     = displayWindow.RenderTarget.Handle;
            present.BackBufferWidth        = width;
            present.BackBufferHeight       = height;
            present.BackBufferFormat       = Format.Unknown;
            present.SwapEffect             = SwapEffect.Copy;
            present.Windowed    = true;
            present.PresentFlag = PresentFlag.LockableBackBuffer;

            if (VSync)
            {
                present.PresentationInterval = PresentInterval.Default;
            }
            else
            {
                present.PresentationInterval = PresentInterval.Immediate;
            }

            return(present);
        }
Esempio n. 3
0
        internal void Initialize(MDX1_DisplayWindow window)
        {
            if (mInitialized)
            {
                return;
            }

            if (window.RenderTarget.TopLevelControl == null)
            {
                throw new ArgumentException("The specified render target does not have a Form object yet.  " +
                                            "It's TopLevelControl property is null.  You may not create DisplayWindow objects before " +
                                            "the control to render to is added to the Form.");
            }

            mInitialized = true;

            // ok, create D3D device
            PresentParameters present = CreateWindowedPresentParameters(window, 0, 0);

            present.BackBufferWidth  = 1;
            present.BackBufferHeight = 1;

            DeviceType dtype = DeviceType.Hardware;

            int adapterOrdinal = Direct3D.Manager.Adapters.Default.Adapter;

            Direct3D.Caps        caps  = Direct3D.Manager.GetDeviceCaps(adapterOrdinal, Direct3D.DeviceType.Hardware);
            Direct3D.CreateFlags flags = Direct3D.CreateFlags.SoftwareVertexProcessing;

            // Is there support for hardware vertex processing? If so, replace
            // software vertex processing.
            if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
            {
                flags = Direct3D.CreateFlags.HardwareVertexProcessing;
            }

            // Does the device support a pure device?
            if (caps.DeviceCaps.SupportsPureDevice)
            {
                flags |= Direct3D.CreateFlags.PureDevice;
            }

            Device device = new Device
                                (0, dtype, window.RenderTarget.TopLevelControl.Handle,
                                flags, present);

            device.DeviceLost  += new EventHandler(mDevice_DeviceLost);
            device.DeviceReset += new EventHandler(mDevice_DeviceReset);

            mDevice = new D3DDevice(device);

            // create primitive objects
            mLine = new Direct3D.Line(device);

            //CreateSurfaceVB();
        }
Esempio n. 4
0
        internal SwapChain CreateSwapChain(MDX1_DisplayWindow displayWindow,
                                           int width, int height, int bpp, bool fullScreen)
        {
            if (fullScreen == true)
            {
                PresentParameters present = CreateFullScreenPresentParameters(displayWindow, width, height, bpp);

                OnDeviceAboutToReset();

                System.Diagnostics.Debug.Print("{0} Going to full screen...", DateTime.Now);
                mDevice.Device.Reset(present);
                System.Diagnostics.Debug.Print("{0} Full screen success.", DateTime.Now);

                return(mDevice.Device.GetSwapChain(0));
            }
            else
            {
                PresentParameters present = CreateWindowedPresentParameters(displayWindow, width, height);

                if (displayWindow.mSwap != null && displayWindow.IsFullScreen == true)
                {
                    // if we are in full screen mode already, we must
                    // reset the device before creating the windowed swap chain.
                    present.BackBufferHeight   = 1;
                    present.BackBufferWidth    = 1;
                    present.DeviceWindowHandle = displayWindow.RenderTarget.TopLevelControl.Handle;

                    OnDeviceAboutToReset();

                    System.Diagnostics.Debug.Print("{0} Going to windowed mode...", DateTime.Now);
                    mDevice.Device.Reset(present);
                    System.Diagnostics.Debug.Print("{0} Windowed mode success.", DateTime.Now);


                    present = CreateWindowedPresentParameters(displayWindow, width, height);
                }

                return(new Direct3D.SwapChain(mDevice.Device, present));
            }
        }