/// <summary>
        /// Attaches the the painter to the given target panel.
        /// </summary>
        /// <param name="targetPanel">The target panel.</param>
        /// <exception cref="System.InvalidOperationException">Unable to attach to new SwapChainBackgroundPanel: Renderer is already attached to another one!</exception>
        public void Attach(DrawingSurface targetPanel)
        {
            if (m_targetPanel != null)
            {
                throw new InvalidOperationException("Unable to attach to new SwapChainBackgroundPanel: Renderer is already attached to another one!");
            }

            // Set default values
            m_lastRefreshTargetSize = new Size2(0, 0);
            m_targetPanel           = targetPanel;

            // Attach to SizeChanged event (refresh view resources only after a specific time)
            m_observerSizeChanged = Observable.FromEventPattern <SizeChangedEventArgs>(m_targetPanel, "SizeChanged")
                                    .Throttle(TimeSpan.FromSeconds(0.5))
                                    .ObserveOn(SynchronizationContext.Current)
                                    .Subscribe((eArgs) => OnTargetPanelThrottledSizeChanged(eArgs.Sender, eArgs.EventArgs));

            m_targetPanel.SizeChanged += OnTargetPanelSizeChanged;
            m_targetPanel.Loaded      += OnTargetPanelLoaded;
            m_targetPanel.Unloaded    += OnTargetPanelUnloaded;

            // Hook-up native component to DrawingSurface
            m_drawingInterop = new WP8DrawingSurfaceInterop(this);
            m_targetPanel.SetContentProvider(m_drawingInterop);
            //m_targetPanel.SetManipulationHandler(m_drawingInterop);

            // Define unloading behavior
            if (VisualTreeHelper.GetParent(m_targetPanel) != null)
            {
                m_renderLoop.RegisterRenderLoop();
            }

            //// Register simple mouse movement
            //InitializeMouseMovement();
        }
        /// <summary>
        /// Attaches the renderer to the given SwapChainBackgroundPanel.
        /// </summary>
        /// <param name="targetPanel">The target panel to attach to.</param>
        private void AttachInternal(SwapChainPanelWrapper targetPanel)
        {
            if (m_targetPanel != null)
            {
                throw new InvalidOperationException("Unable to attach to new SwapChainBackgroundPanel: Renderer is already attached to another one!");
            }

            m_lastRefreshTargetSize = new Size(0.0, 0.0);
            m_targetPanel           = targetPanel;

            // Attach to SizeChanged event (refresh view resources only after a specific time)
            m_observerSizeChanged = Observable.FromEventPattern <SizeChangedEventArgs>(m_targetPanel, "SizeChanged")
                                    .Throttle(TimeSpan.FromSeconds(0.5))
                                    .ObserveOn(SynchronizationContext.Current)
                                    .Subscribe((eArgs) => OnTargetPanelThrottled_SizeChanged(eArgs.Sender, eArgs.EventArgs));

            m_targetPanel.SizeChanged             += OnTargetPanel_SizeChanged;
            m_targetPanel.Loaded                  += OnTargetPanel_Loaded;
            m_targetPanel.Unloaded                += OnTargetPanel_Unloaded;
            m_targetPanel.CompositionScaleChanged += OnTargetPanel_CompositionScaleChanged;

            UpdateRenderLoopViewSize();

            // Define unloading behavior
            if (VisualTreeHelper.GetParent(m_targetPanel.Panel) != null)
            {
                m_renderLoop.RegisterRenderLoop();
            }
        }
示例#3
0
        /// <summary>
        /// Called when the image is loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (!GraphicsCore.IsInitialized)
            {
                return;
            }
            if (this.IsInDesignMode())
            {
                return;
            }

            // Update render size
            m_renderLoop.Camera.SetScreenSize((int)this.RenderSize.Width, (int)this.RenderSize.Height);

            // Now connect this view with the main renderloop
            m_renderLoop.RegisterRenderLoop();

            // Initialize Wpf performance meausre
            //  (first call performs initialization, all following are ignored)
            GraphicsCore.Current.InitializeWpfRenderPerformanceMeasure();

            //m_refreshTimer = new DispatcherTimer(DispatcherPriority.Render);
            //m_refreshTimer.Tick += M_refreshTimer_Tick;
            //m_refreshTimer.Interval = TimeSpan.FromMilliseconds(7.0);
            //m_refreshTimer.Start();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SeeingSharpCoreWindowPainter"/> class.
        /// </summary>
        /// <param name="targetWindow">The target window.</param>
        public SeeingSharpCoreWindowPainter(CoreWindow targetWindow)
        {
            // Attach to SizeChanged event (refresh view resources only after a specific time)
            m_targetWindow              = targetWindow;
            m_targetWindow.SizeChanged += OnTargetWindow_SizeChanged;
            m_observerSizeChanged       = Observable.FromEventPattern <WindowSizeChangedEventArgs>(m_targetWindow, "SizeChanged")
                                          .Throttle(TimeSpan.FromSeconds(0.5))
                                          .ObserveOn(SynchronizationContext.Current)
                                          .Subscribe((eArgs) => OnTargetWindow_ThrottledSizeChanged(eArgs.Sender as CoreWindow, eArgs.EventArgs));

            // Attach to display setting changes
            m_displayInfo                     = DisplayInformation.GetForCurrentView();
            m_displayInfo.DpiChanged         += OnDisplayInfo_DpiChanged;
            m_displayInfo.OrientationChanged += OnDisplayInfo_OrientationChanged;

            // Store current dpi setting
            m_dpiScaling = new DpiScaling(m_displayInfo.LogicalDpi, m_displayInfo.LogicalDpi);

            // Create the RenderLoop object
            GraphicsCore.Touch();
            m_renderLoop                       = new Core.RenderLoop(SynchronizationContext.Current, this);
            m_renderLoop.ClearColor            = Color4.CornflowerBlue;
            m_renderLoop.CallPresentInUIThread = true;

            m_lastRefreshTargetSize = new Size(0.0, 0.0);

            UpdateRenderLoopViewSize();

            m_renderLoop.RegisterRenderLoop();
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryRenderTarget" /> class.
        /// </summary>
        /// <param name="pixelHeight">Height of the offline render target in pixels.</param>
        /// <param name="pixelWidth">Width of the offline render target in pixels.</param>
        /// <param name="syncContext">Sets the SynchronizationContext which should be used by default.</param>
        public MemoryRenderTarget(int pixelWidth, int pixelHeight, SynchronizationContext syncContext = null)
        {
            //Set confiugration
            m_pixelWidth  = pixelWidth;
            m_pixelHeight = pixelHeight;

            m_renderAwaitors = new ThreadSaveQueue <TaskCompletionSource <object> >();
            if (syncContext == null)
            {
                syncContext = new SynchronizationContext();
            }

            //Create the RenderLoop object
            GraphicsCore.Touch();
            m_renderLoop = new RenderLoop(syncContext, this);
            m_renderLoop.Camera.SetScreenSize(pixelWidth, pixelHeight);
            m_renderLoop.RegisterRenderLoop();
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FullscreenRenderTarget" /> class.
        /// </summary>
        /// <param name="outputInfo">The target output monitor.</param>
        /// <param name="initialMode">The initial view mode.</param>
        public FullscreenRenderTarget(EngineOutputInfo outputInfo, EngineOutputModeInfo initialMode = default(EngineOutputModeInfo))
        {
            outputInfo.EnsureNotNull(nameof(outputInfo));

            // Check whether we are inside a win.forms application
            System.Windows.Forms.WindowsFormsSynchronizationContext syncContext = SynchronizationContext.Current
                                                                                  as System.Windows.Forms.WindowsFormsSynchronizationContext;
            if (syncContext == null)
            {
                throw new SeeingSharpException($"{nameof(FullscreenRenderTarget)} muss be created inside a Windows.Forms application context!");
            }
            m_syncContext = syncContext;

            //Set confiugration
            m_targetOutput     = outputInfo;
            m_targetOutputMode = initialMode;
            if (m_targetOutputMode.HostOutput != outputInfo)
            {
                m_targetOutputMode = m_targetOutput.DefaultMode;
            }
            m_renderAwaitors = new ThreadSaveQueue <TaskCompletionSource <object> >();

            // Ensure that graphics is initialized
            GraphicsCore.Touch();

            // Create the dummy form
            m_dummyForm = new DummyForm();
            m_dummyForm.SetStyleCustom(ControlStyles.AllPaintingInWmPaint, true);
            m_dummyForm.SetStyleCustom(ControlStyles.ResizeRedraw, true);
            m_dummyForm.SetStyleCustom(ControlStyles.OptimizedDoubleBuffer, false);
            m_dummyForm.SetStyleCustom(ControlStyles.Opaque, true);
            m_dummyForm.SetStyleCustom(ControlStyles.Selectable, true);
            m_dummyForm.SetDoubleBuffered(false);
            m_dummyForm.MouseEnter      += (sender, eArgs) => Cursor.Hide();
            m_dummyForm.MouseLeave      += (sender, eArgs) => Cursor.Show();
            m_dummyForm.HandleDestroyed += OnDummyForm_HandleDestroyed;
            m_dummyForm.GotFocus        += OnDummyForm_GotFocus;
            m_dummyForm.CreateControl();

            // Create and start the renderloop
            m_renderLoop = new RenderLoop(syncContext, this);
            m_renderLoop.Camera.SetScreenSize(m_targetOutputMode.PixelWidth, m_targetOutputMode.PixelHeight);
            m_renderLoop.RegisterRenderLoop();
        }
示例#7
0
        /// <summary>
        /// Stops rendering.
        /// </summary>
        private void StartRendering()
        {
            if (this.DesignMode)
            {
                return;
            }
            if (!SeeingSharpApplication.IsInitialized)
            {
                return;
            }
            if (!GraphicsCore.IsInitialized)
            {
                return;
            }

            if (!m_renderLoop.IsRegisteredOnMainLoop)
            {
                m_renderLoop.SetCurrentViewSize(this.Width, this.Height);
                m_renderLoop.DiscardRendering = false;
                m_renderLoop.RegisterRenderLoop();
            }
        }