Пример #1
0
 private SwapChain CreateSwapChain(SwapChainDescription swapChainDesc)
 {
     var factory = new Factory1();
     {
         factory.MakeWindowAssociation(_control.Handle, WindowAssociationFlags.IgnoreAll);
         return(new SwapChain(factory, _device, swapChainDesc));
     }
 }
    public CompanionWindow(Device device, ShaderCache shaderCache, StandardSamplers standardSamplers, string title, IArchiveDirectory dataDir)
    {
        this.device           = device;
        this.standardSamplers = standardSamplers;

        form = new RenderForm(title);

        // SwapChain description
        var desc = new SwapChainDescription()
        {
            BufferCount     = 1,
            ModeDescription =
                new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
                                    default(Rational), Format.R8G8B8A8_UNorm_SRgb),
            IsWindowed        = true,
            OutputHandle      = form.Handle,
            SampleDescription = new SampleDescription(1, 0),
            SwapEffect        = SwapEffect.Discard,      //TODO: consider using flip
            Usage             = Usage.RenderTargetOutput
        };

        using (var factory = new Factory1()) {
            factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
            swapChain = new SwapChain(factory, device, desc);
        }

        form.UserResized += OnUserResized;

        SetupBackbufferAndViewport();

        copyFromSourceVertexShader = shaderCache.GetVertexShader <CompanionWindow>("viewer/companion-window/CopyFromSource");
        copyFromSourcePixelShader  = shaderCache.GetPixelShader <CompanionWindow>("viewer/companion-window/CopyFromSource");

        uiBlendState = MakeUiBlendState(device);

        aspectRatiosBufferManager = new ConstantBufferManager <AspectRatios>(device);

        overlay = Overlay.Load(device, shaderCache, dataDir.Subdirectory("ui").File("put-on-headset-overlay.dds"));

        form.KeyPress  += OnKeyPress;
        form.MouseDown += OnMouseDown;
        form.MouseUp   += OnMouseUp;
        form.MouseMove += OnMouseMove;


        DebugInitialize();
    }
Пример #3
0
        public bool Initialize(out string errorMsg)
        {
            try
            {
                errorMsg = null;

                List <ModeDescription> adapterModes = new List <ModeDescription>();
                _dx11factory = new Factory1();

                using (Adapter1 adapter = _dx11factory.GetAdapter1(0))
                {
                    using (Output output = adapter.Outputs[0])
                    {
                        IsB8G8R8A8_UNormSupport = false;
                        foreach (var mode in output.GetDisplayModeList(Format.B8G8R8A8_UNorm, DisplayModeEnumerationFlags.Interlaced))
                        {
                            IsB8G8R8A8_UNormSupport = true;
                            adapterModes.Add(mode);
                        }

                        MainAdapter = adapter.Description.Description;
                        logger.Info("GPU found : {0}", MainAdapter);
                        //GetResource Level
                        FeatureLevel maxSupportLevel = Device.GetSupportedFeatureLevel(adapter);
                        logger.Info("Maximum supported DirectX11 level = {0}", maxSupportLevel.ToString());

                        if (maxSupportLevel == FeatureLevel.Level_9_1 ||
                            maxSupportLevel == FeatureLevel.Level_9_2 ||
                            maxSupportLevel == FeatureLevel.Level_9_3)
                        {
                            errorMsg = "Your graphical card doesn't support at minimum DirectX 10 feature, current feature : " + maxSupportLevel.ToString();
                            return(false);
                        }

                        int DedicatedGPU = adapter.Description.DedicatedVideoMemory / (1024 * 1024);
                        if (DedicatedGPU < 0)
                        {
                            DedicatedGPU = 0;
                        }
                        int DedicatedSystem = adapter.Description.DedicatedSystemMemory / (1024 * 1024);
                        if (DedicatedSystem < 0)
                        {
                            DedicatedSystem = 0;
                        }
                        int SharedSystem = adapter.Description.SharedSystemMemory / (1024 * 1024);
                        if (SharedSystem < 0)
                        {
                            SharedSystem = 0;
                        }

                        logger.Info("GPU Memory : Dedicated from GPU : {0}MB, Shared : {1}MB, Dedicated from System : {2}MB. Total : {3}MB", DedicatedGPU, DedicatedSystem, SharedSystem, DedicatedGPU + DedicatedSystem + SharedSystem);
                        logger.Info("B8G8R8A8_UNormSupport compatibility = {0}", IsB8G8R8A8_UNormSupport);

#if DEBUG
                        foreach (var mode in adapterModes)
                        {
                            logger.Trace("[{1}:{2}], format : {0}, RefreshRate : {3}hz, Scaling : {4}, ScanlineMode : {5}", mode.Format, mode.Width, mode.Height, (float)mode.RefreshRate.Numerator / mode.RefreshRate.Denominator, mode.Scaling, mode.ScanlineOrdering);
                        }
#endif
                    }
                }

                RefreshResources();

                GetMSAAQualities(Format.B8G8R8A8_UNorm);

                //Remove the some built-in fonctionnality of DXGI
                _dx11factory.MakeWindowAssociation(_renderForm.Handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter);

                _renderForm.ResizeBegin += _renderForm_ResizeBegin;
                _renderForm.ResizeEnd   += _renderForm_ResizeEnd;
                _renderForm.Resize      += _renderForm_Resize;
                _renderForm.LostFocus   += GameWindow_LostFocus;
                _renderForm.GotFocus    += GameWindow_GotFocus;

                _renderForm.Show();
                _renderForm.Focus();
                _renderForm.TopMost = true;
                HasFocus            = true;
                _renderForm.TopMost = false;

                return(true);
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
                return(false);
            }
        }