Пример #1
0
        private void ReinitializeWindow()
        {
            if (_renderSetup == null)
            {
                return;
            }

            _renderSetup.Resize((int)XGrid.ActualWidth, (int)XGrid.ActualHeight);
            _D3DImageContainer.SetBackBufferSharpDX(_renderSetup.SharedTexture);

            var contextSettings = new ContextSettings();

            contextSettings.DisplayMode = new SharpDX.Direct3D9.DisplayMode()
            {
                Width       = _renderSetup.WindowWidth,
                Height      = _renderSetup.WindowHeight,
                RefreshRate = 60,
                Format      = D3DImageSharpDX.TranslateFormat(_renderSetup.SharedTexture)
            };
            contextSettings.AspectRatio = contextSettings.DisplayMode.AspectRatio;

            _defaultContext = OperatorPartContext.createDefault(contextSettings);

            if (_operator != null && _operator.Outputs.Count > 0)
            {
                var invalidator = new OperatorPart.InvalidateVariableAccessors("AspectRatio");
                _operator.Outputs[0].TraverseWithFunction(null, invalidator);
            }

            RenderContent();
        }
Пример #2
0
        private void OnLoadedHandler(object sender, RoutedEventArgs e)
        {
            App.Current.UpdateAfterUserInteractionEvent   += App_UpdateAfterUserInteractionHandler;
            App.Current.UpdateRequiredAfterUserInteraction = true;

            var contextSettings = new ContextSettings();

            _defaultContext = OperatorPartContext.createDefault(contextSettings);
        }
Пример #3
0
        private void CreateContextSettingsWithAspectRatio()
        {
            _D3DImageContainer.SetBackBufferSharpDX(_sharedTexture);

            var contextSettings = new ContextSettings();

            contextSettings.DisplayMode = new SharpDX.Direct3D9.DisplayMode()
            {
                Width       = RenderConfig.Width,
                Height      = RenderConfig.Height,
                RefreshRate = 60,
                Format      = D3DImageSharpDX.TranslateFormat(_sharedTexture)
            };
            contextSettings.AspectRatio = contextSettings.DisplayMode.AspectRatio;
            _defaultContext             = OperatorPartContext.createDefault(contextSettings);
        }
Пример #4
0
        private void SetupRendering()
        {
            XSceneImage.Source = _D3DImageContainer;
            _renderSetup       = new D3DRenderSetup((int)XGrid.ActualWidth, (int)XGrid.ActualHeight);
            _D3DImageContainer.SetBackBufferSharpDX(_renderSetup.SharedTexture);

            var contextSettings = new ContextSettings();

            contextSettings.DisplayMode = new SharpDX.Direct3D9.DisplayMode()
            {
                Width       = _renderSetup.WindowWidth,
                Height      = _renderSetup.WindowHeight,
                RefreshRate = 60,
                Format      = D3DImageSharpDX.TranslateFormat(_renderSetup.SharedTexture)
            };
            contextSettings.AspectRatio = contextSettings.DisplayMode.AspectRatio;
            _defaultContext             = OperatorPartContext.createDefault(contextSettings);
        }
Пример #5
0
        public void Run(ContextSettings settings)
        {
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, SharpDX.RawInput.DeviceFlags.None);
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericMouse, SharpDX.RawInput.DeviceFlags.None);
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericJoystick, SharpDX.RawInput.DeviceFlags.None);

            Logger.Debug("Start fullscreen with resolution: {0} x {1}...", settings.DisplayMode.Height, settings.DisplayMode.Width);

            Size            = new System.Drawing.Size(settings.DisplayMode.Width, settings.DisplayMode.Height);
            _defaultContext = OperatorPartContext.createDefault(settings);

            var desc = new SwapChainDescription()
            {
                BufferCount     = 3,
                ModeDescription = new ModeDescription(ClientSize.Width, ClientSize.Height,
                                                      new Rational(settings.DisplayMode.RefreshRate, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = false,
                OutputHandle      = Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.AllowModeSwitch
            };

            var dxgiDevice = D3DDevice.Device.QueryInterface <SharpDX.DXGI.Device>();
            var factory    = dxgiDevice.Adapter.GetParent <Factory>();

            _swapChain = new SwapChain(factory, D3DDevice.Device, desc);

            _swapChain.ResizeBuffers(3, ClientSize.Width, ClientSize.Height,
                                     _swapChain.Description.ModeDescription.Format, _swapChain.Description.Flags);

            using (var texture = Texture2D.FromSwapChain <Texture2D>(_swapChain, 0))
                _renderTargetView = new RenderTargetView(D3DDevice.Device, texture);

            var depthdesc = new Texture2DDescription
            {
                BindFlags         = BindFlags.DepthStencil,
                Format            = Format.D32_Float_S8X24_UInt,
                Width             = ClientSize.Width,
                Height            = ClientSize.Height,
                MipLevels         = 1,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                OptionFlags       = ResourceOptionFlags.None,
                CpuAccessFlags    = CpuAccessFlags.None,
                ArraySize         = 1
            };

            _depthTex         = new Texture2D(D3DDevice.Device, depthdesc);
            _depthStencilView = new DepthStencilView(D3DDevice.Device, _depthTex);

            D3DDevice.Device.ImmediateContext.OutputMerger.SetTargets(_depthStencilView, _renderTargetView);
            _viewport = new ViewportF(0, 0, ClientSize.Width, ClientSize.Height, 0.0f, 1.0f);
            D3DDevice.Device.ImmediateContext.Rasterizer.SetViewport(_viewport);

            _shaderResourceView = ShaderResourceView.FromFile(D3DDevice.Device, "./assets-common/image/white.png");

            _renderer = new DefaultRenderer();

            _globalTime.Start();

            RenderLoop.Run(this, UpdateLocalShownContent);
        }
Пример #6
0
        public bool Initialize(ContextSettings settings)
        {
            Logger.Info("Initializing ...");

//            GCSettings.LatencyMode = GCLatencyMode.LowLatency;

            _undoRedoStack = new UndoRedoStack(false);

            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;


            for (int i = 0; i < _numMeasureValues; ++i)
            {
                _averagedElapsed.Add(10000);
            }

            ProjectSettings = new Settings("Config/ProjectSettings.json");

            _settings = settings;

            _defaultContext = OperatorPartContext.createDefault(_settings);

            var registrationEmail = ProjectSettings.TryGet("Tooll.Sound.BassNetLicense.Email", "");
            var registrationKey   = ProjectSettings.TryGet("Tooll.Sound.BassNetLicense.Key", "");

            if (!String.IsNullOrEmpty(registrationEmail) && !String.IsNullOrEmpty(registrationKey))
            {
                BassNet.Registration(registrationEmail, registrationKey);
            }
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_LATENCY, IntPtr.Zero);

            var soundFilePath = (string)ProjectSettings["Soundtrack.Path"];

            _soundStream = Bass.BASS_StreamCreateFile(soundFilePath, 0, 0, BASSFlag.BASS_STREAM_PRESCAN);
            if (_soundStream == 0)
            {
                Logger.Error("Error loading sound file {0}", soundFilePath);
                return(false);
            }
            _soundLength = Bass.BASS_ChannelBytes2Seconds(_soundStream, Bass.BASS_ChannelGetLength(_soundStream, BASSMode.BASS_POS_BYTES));

            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, SharpDX.RawInput.DeviceFlags.None);
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericMouse, SharpDX.RawInput.DeviceFlags.None);
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericJoystick, SharpDX.RawInput.DeviceFlags.None);

            _form         = new RenderForm("Framefield T2 Player");
            _form.Icon    = Properties.Resources.t2;
            _form.Visible = true;
            _form.Size    = new Size(_settings.DisplayMode.Width, _settings.DisplayMode.Height);

            var desc = new SwapChainDescription()
            {
                BufferCount     = 3,
                ModeDescription = new ModeDescription(_settings.DisplayMode.Width, _settings.DisplayMode.Height,
                                                      new Rational(_settings.DisplayMode.RefreshRate, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = !_settings.FullScreen,
                OutputHandle      = _form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.AllowModeSwitch
            };

            var featureLevels = new FeatureLevel[] { FeatureLevel.Level_11_0, FeatureLevel.Level_10_1 };

            SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, featureLevels, desc,
                                                          out D3DDevice.Device, out D3DDevice.SwapChain);
            if (D3DDevice.Device == null)
            {
                Logger.Error("Failed to setup a Direct3d 11 device");
                return(false);
            }
            if (D3DDevice.SwapChain == null)
            {
                Logger.Error("Failed to setup swap chain");
                return(false);
            }

            using (var dxgiDevice = D3DDevice.Device.QueryInterface <SharpDX.DXGI.Device1>())
            {
                var adapter = dxgiDevice.Adapter;
                D3DDevice.DX10_1Device = new SharpDX.Direct3D10.Device1(adapter, SharpDX.Direct3D10.DeviceCreationFlags.BgraSupport, SharpDX.Direct3D10.FeatureLevel.Level_10_1);
            }
            D3DDevice.Direct2DFactory    = new SharpDX.Direct2D1.Factory();
            D3DDevice.DirectWriteFactory = new SharpDX.DirectWrite.Factory();

            _texture = ShaderResourceView.FromFile(D3DDevice.Device, "./assets-common/image/white.png");

            _renderer = new DefaultRenderer();

            _form.KeyUp   += KeyUpHandler;
            _form.KeyDown += KeyDownHandler;
            _form.Resize  += ResizeHandler;

            SetupRenderBuffers();

            if (_settings.FullScreen)
            {
                Cursor.Hide();
            }

            D3DDevice.TouchWidth  = 1920;
            D3DDevice.TouchHeight = 1080;

            return(true);
        }
Пример #7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _defaultContext = OperatorPartContext.createDefault(new ContextSettings());

            App.Current.UpdateAfterUserInteractionEvent += RefreshUiEventHandler;
        }