示例#1
0
        public WinformsDevice(WinformsEye eye, Direct3D direct3D, CAdapter adapter, 
            ControlWindow primaryWindow, SwapChainDescription implicitSwapChainDesc, 
            DeviceInitializationFlags flags, IFileSystem fileSystem)
        {
            this.eye = eye;
            this.adapter = adapter;
            this.primaryWindow = primaryWindow;
            this.implicitSwapChainDesc = implicitSwapChainDesc;
            this.flags = flags;

            caps = adapter.Info.GetCaps(DeviceType.Hardware);
            devicePresentParams = new PresentParameters();

            FillDevicePresentParams();
            d3dDevice = new Device(direct3D, adapter.Index, DeviceType.Hardware, primaryWindow.Handle, CreateFlags.FpuPreserve | CreateFlags.HardwareVertexProcessing, devicePresentParams);

            CreateBackBufferAndDepthStencil();

            additionalSwapChains = new List<CAdditionalSwapChain>();
            creator = new CDeviceChildCreator(this);
            immediateContext = new CDeviceContext(this);

            lastSwapChainSize = new IntSize(primaryWindow.SwapChainWidth, primaryWindow.SwapChainHeight);
            fullscreenState = FullscreenState.Windowed;
            fullscreenDisplayMode = adapter.GetSupportedDisplayModes().First();
        }
示例#2
0
        public DefaultWindow(DefaultDevice device, int width, int height, ref SwapChainDescription implicitSwapChainDescription, 
            string title, GameWindowFlags gameWindowFlags, DisplayDevice displayDevice, ref Context glContext)
            : base(width, height, GraphicsMode.Default, title, gameWindowFlags, displayDevice)
        {
            glContext = glContext ?? new Context(Context);
            this.glContext = glContext;

            this.device = device;
            implicitSwapChainDesc = implicitSwapChainDescription;
            swapChainSurfaces = new SwapChainSurfaces(device, width, height, ref implicitSwapChainDescription);

            keyboard = new Keyboard(this);
            mouse = new Mouse(this);
        }
示例#3
0
        public DefaultDevice(DefaultEye eye, CAdapter adapter, DeviceInitializationFlags flags,
            WindowHandle windowHandle, ref SwapChainDescription implicitSwapChainDescription,
            IFileSystem fileSystem)
        {
            this.eye = eye;
            this.adapter = adapter;
            this.flags = flags;

            primaryWindow = new DefaultWindow(this, windowHandle.ClientWidth, windowHandle.ClientHeight,
                ref implicitSwapChainDescription, windowHandle.Title, GameWindowFlags.Default,
                ((COutput)adapter.Outputs[0]).GLDisplayDevice, ref glContext);

            creator = new CDeviceChildCreator(this);
            immediateContext = new CDeviceContext(this, glContext);
        }
示例#4
0
        public SwapChainSurfaces(ICDevice device, int width, int height, ref SwapChainDescription implicitSwapChainDescription)
        {
            this.device = device;

            var glContext = device.GetCurrentContext();

            texture2DDescription = new Texture2DDescription
            {
                ArraySize = 1,
                ExtraFlags = ExtraFlags.None,
                Usage = Usage.Default,
                MipLevels = 1,
                MiscFlags = MiscFlags.None
            };

            OnReset(glContext, width, height, ref implicitSwapChainDescription);
        }
示例#5
0
        public WinformsDevice(Factory1 dxgiFactory, WinformsEye eye, CAdapter adapter,
            ControlWindow primaryWindow, SwapChainDescription primarySwapChainDesc,
            DeviceInitializationFlags flags, IFileSystem fileSystem)
        {
            this.flags = flags;
            this.eye = eye;
            this.dxgiFactory = dxgiFactory;
            this.adapter = adapter;

            d3dDevice = new Device(adapter.DXGIAdapter, CtSharpDX11.DeviceCreationFlags(flags));

            primarySwapChain = new CSwapChain(this, primaryWindow, ref primarySwapChainDesc,
                pswc => { }, () => !primaryWindow.IsVisible && additionalSwapChains.All(aswc => !aswc.Window.IsVisible));

            creator = new CDeviceChildCreator(this);
            immediateContext = new CDeviceContext(this, d3dDevice.ImmediateContext);

            additionalSwapChains = new List<CSwapChain>();
        }
示例#6
0
 public IAdditionalSwapChain CreateAdditionalSwapChain(IWindowHandle windowHandle, SwapChainDescription swapChainDesc)
 {
     throw new NotSupportedException("Additional swap chains are not yet supported by the ObjectGL.Default eye");
 }
示例#7
0
        public void Initialize(
            IAdapter adapter,
            IWindowHandle windowHandle, 
            BSwapChainDescription primarySwapChainDesc,
            DeviceInitializationFlags initializationFlags,
            IFileSystem fileSystem)
        {
            var cAdapter = (CAdapter)adapter;
            var window = (ControlWindow)windowHandle;
            device = new WinformsDevice(factory, this, cAdapter, window, primarySwapChainDesc, initializationFlags, fileSystem);
            window.SetSwapChain(device.PrimarySwapChain);
            windows.Add(window);

            window.Control.Show();

            IsInitialized = true;
        }
示例#8
0
 public IAdditionalSwapChain CreateAdditionalSwapChain(IWindowHandle windowHandle, SwapChainDescription swapChainDesc)
 {
     var window = (ControlWindow) windowHandle;
     var aswc = new CSwapChain(this, window, ref swapChainDesc, OnAdditionalSwapChainDisposed, () => false);
     window.SetSwapChain(aswc);
     additionalSwapChains.Add(aswc);
     return aswc;
 }
示例#9
0
        void IPrimarySwapChain.ResetToPseudoFullscreen(ref SwapChainDescription description)
        {
            implicitSwapChainDesc = description;

            var defaultDisplay = DisplayDevice.Default;

            if (fullscreenState == FullscreenState.Fullscreen)
                defaultDisplay.RestoreResolution();

            fullscreenState = FullscreenState.PseudoFullscreen;
            WindowState = WindowState.Fullscreen;
            ResetProcedure();
        }
示例#10
0
        public void OnReset(Context glContext, int width, int height, ref SwapChainDescription implicitSwapChainDescription)
        {
            if (backBuffer != null) { backBuffer.Dispose(); backBuffer = null; }
            if (autoDepthStencil != null) { autoDepthStencil.Dispose(); autoDepthStencil = null; }

            texture2DDescription.Width = width;
            texture2DDescription.Height = height;
            texture2DDescription.Sampling = implicitSwapChainDescription.Sampling;

            texture2DDescription.FormatID = implicitSwapChainDescription.ColorBufferFormatID;
            texture2DDescription.BindFlags = BindFlags.RenderTarget;

            backBuffer = new CBackBuffer(device, ref texture2DDescription);

            if (implicitSwapChainDescription.EnableAutoDepthStencil)
            {
                texture2DDescription.FormatID = implicitSwapChainDescription.DepthStencilFormatID;
                texture2DDescription.BindFlags = BindFlags.DepthStencil;
                autoDepthStencil = new CAutoDepthStencil(device, ref texture2DDescription);
            }
        }
示例#11
0
 public void GetDescription(out SwapChainDescription description)
 {
     description = implicitSwapChainDesc;
 }
示例#12
0
 public IAdditionalSwapChain CreateAdditionalSwapChain(IWindowHandle windowHandle, SwapChainDescription swapChainDesc)
 {
     var window = (ControlWindow)windowHandle;
     var aswc = new CAdditionalSwapChain(this, window, swapChainDesc, asc => additionalSwapChains.Remove(asc));
     window.SetSwapChain(aswc);
     additionalSwapChains.Add(aswc);
     return aswc;
 }
示例#13
0
        public void Initialize(IAdapter adapter,
            IWindowHandle windowHandle, 
            SwapChainDescription primarySwapChainDesc,
            DeviceInitializationFlags initializationFlags,
            IFileSystem fileSystem)
        {
            if (adapter != adapters[0])
                throw new ArgumentException("Provided adapter is not on of this eye's adapters");

            device = new DefaultDevice(this, (CAdapter)adapter, initializationFlags, (WindowHandle)windowHandle, ref primarySwapChainDesc, fileSystem);

            initialized = true;
        }
示例#14
0
        void ISwapChain.Reset(ref SwapChainDescription description)
        {
            implicitSwapChainDesc = description;

            if (fullscreenState == FullscreenState.Fullscreen)
                DisplayDevice.Default.RestoreResolution();

            fullscreenState = FullscreenState.Windowed;
            WindowState = WindowState.Normal;
            ResetProcedure();
        }
示例#15
0
 void ISwapChain.GetDescription(out SwapChainDescription description)
 {
     description = implicitSwapChainDesc;
 }
示例#16
0
        public void ResetToFullscreen(ref BDisplayMode displayMode, ref SwapChainDescription description)
        {
            fullscreenDisplayMode = displayMode;

            fullscreenState = FullscreenState.Fullscreen;
            implicitSwapChainDesc = description;

            primaryWindow.OnFullscreen(displayMode.Width, displayMode.Height, () => { }, () => { }); //todo: remove unneeded args

            var coopLevel = d3dDevice.TestCooperativeLevel();
            if (coopLevel.Success || coopLevel == ResultCode.DeviceNotReset)
                ResetProcedure();
        }
示例#17
0
        public void ResetToPseudoFullscreen(ref SwapChainDescription description)
        {
            fullscreenState = FullscreenState.PseudoFullscreen;
            implicitSwapChainDesc = description;

            primaryWindow.OnPseudoFullscreen();

            var coopLevel = d3dDevice.TestCooperativeLevel();
            if (coopLevel.Success || coopLevel == ResultCode.DeviceNotReset)
                ResetProcedure();
        }
示例#18
0
        public void Initialize(
            IAdapter adapter, 
            IWindowHandle windowHandle, 
            SwapChainDescription primarySwapChainDescription,
            DeviceInitializationFlags initializationFlags,
            IFileSystem fileSystem)
        {
            var cAdapter = (CAdapter)adapter;

            var primaryWindow = (ControlWindow)windowHandle;
            device = new WinformsDevice(this, direct3D, cAdapter, primaryWindow, primarySwapChainDescription, initializationFlags, fileSystem);
            primaryWindow.SetSwapChain(device);
            primaryWindow.Control.Show();

            windows.Add(primaryWindow);

            IsInitialized = true;
        }
示例#19
0
        void IPrimarySwapChain.ResetToFullscreen(ref DisplayMode displayMode, ref SwapChainDescription description)
        {
            fullscreenDisplayMode = displayMode;
            implicitSwapChainDesc = description;

            fullscreenState = FullscreenState.Fullscreen;
            DisplayDevice.Default.ChangeResolution(displayMode.Width, displayMode.Height, device.Adapter.GetFormatInfo(displayMode.FormatID).TotalBits, displayMode.RefreshRate.ToSingle());
            WindowState = WindowState.Fullscreen;
            ResetProcedure();
        }