/// <summary> /// Initializes a new instance of the <see cref="ViewportCore"/> class. /// </summary> /// <param name="nativeWindowPointer">The native window pointer.</param> /// <param name="deferred">if set to <c>true</c> [deferred].</param> public ViewportCore(IntPtr nativeWindowPointer, bool deferred = false) { if (deferred) { RenderHost = new SwapChainRenderHost(nativeWindowPointer, (device) => { return(new DeferredContextRenderer(device, new AutoRenderTaskScheduler())); }) { Viewport = this, }; } else { RenderHost = new SwapChainRenderHost(nativeWindowPointer) { Viewport = this, }; } BackgroundColor = Color.Black; RenderHost.StartRenderLoop += RenderHost_StartRenderLoop; RenderHost.StopRenderLoop += RenderHost_StopRenderLoop; RenderHost.ExceptionOccurred += (s, e) => { HandleExceptionOccured(e.Exception); }; Items2D.ItemsInternal.Add(frameStatisticsNode); }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); if (IsInDesignMode && !EnableDesignModeRendering) { return; } itemsContainer = GetTemplateChild(ViewportPartNames.PART_ItemsContainer) as ItemsControl; if (itemsContainer == null) { throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_ItemsContainer); } else { itemsContainer.Items.Clear(); foreach (var item in Items) { itemsContainer.Items.Add(item); } } if (hostPresenter != null) { renderHostInternal.Rendered -= this.RaiseRenderHostRendered; renderHostInternal.ExceptionOccurred -= RenderHostInternal_ExceptionOccurred; } hostPresenter = GetTemplateChild(ViewportPartNames.PART_HostPresenter) as ContentPresenter; if (hostPresenter != null) { var host = new SwapChainRenderHost(EnableDeferredRendering); hostPresenter.Content = host; #if WINDOWS_UWP var view = DisplayInformation.GetForCurrentView(); var dpi = view.RawPixelsPerViewPixel; #else var dpi = 1; #endif host.DpiScale = (float)dpi; host.EnableDpiScale = EnableDpiScale; renderHostInternal = (hostPresenter.Content as SwapChainRenderHost).RenderHost; if (renderHostInternal != null) { renderHostInternal.RenderConfiguration.RenderD2D = false; renderHostInternal.Viewport = this; renderHostInternal.IsRendering = this.Visibility == VisibilityEnum.Visible; renderHostInternal.EffectsManager = this.EffectsManager; renderHostInternal.ClearColor = this.BackgroundColor.ToColor4(); renderHostInternal.EnableRenderFrustum = this.EnableRenderFrustum; renderHostInternal.IsShadowMapEnabled = this.IsShadowMappingEnabled; renderHostInternal.SharedModelContainer = this.SharedModelContainer; renderHostInternal.EnableSharingModelMode = this.EnableSharedModelMode; #if MSAA renderHostInternal.MSAA = this.MSAA; #endif renderHostInternal.RenderConfiguration.AutoUpdateOctree = this.EnableAutoOctreeUpdate; renderHostInternal.RenderConfiguration.EnableOITRendering = EnableOITRendering; renderHostInternal.RenderConfiguration.OITWeightPower = (float)OITWeightPower; renderHostInternal.RenderConfiguration.OITWeightDepthSlope = (float)OITWeightDepthSlope; renderHostInternal.RenderConfiguration.OITWeightMode = OITWeightMode; renderHostInternal.RenderConfiguration.FXAALevel = FXAALevel; renderHostInternal.RenderConfiguration.EnableRenderOrder = EnableRenderOrder; renderHostInternal.RenderConfiguration.EnableSSAO = EnableSSAO; renderHostInternal.RenderConfiguration.SSAORadius = (float)SSAOSamplingRadius; renderHostInternal.RenderConfiguration.SSAOIntensity = (float)SSAOIntensity; renderHostInternal.RenderConfiguration.SSAOQuality = SSAOQuality; renderHostInternal.RenderConfiguration.MinimumUpdateCount = (uint)Math.Max(0, MinimumUpdateCount); renderHostInternal.Rendered += this.RaiseRenderHostRendered; renderHostInternal.ExceptionOccurred += RenderHostInternal_ExceptionOccurred; if (ShowFrameRate) { this.renderHostInternal.ShowRenderDetail |= RenderDetail.FPS; } else { this.renderHostInternal.ShowRenderDetail &= ~RenderDetail.FPS; } if (ShowFrameDetails) { this.renderHostInternal.ShowRenderDetail |= RenderDetail.Statistics; } else { this.renderHostInternal.ShowRenderDetail &= ~RenderDetail.Statistics; } if (ShowTriangleCountInfo) { this.renderHostInternal.ShowRenderDetail |= RenderDetail.TriangleInfo; } else { this.renderHostInternal.ShowRenderDetail &= ~RenderDetail.TriangleInfo; } if (ShowCameraInfo) { this.renderHostInternal.ShowRenderDetail |= RenderDetail.Camera; } else { this.renderHostInternal.ShowRenderDetail &= ~RenderDetail.Camera; } } } var coordinateGroup = GetTemplateChild(ViewportPartNames.PART_CoordinateGroup) as ItemsControl; if (coordinateGroup == null) { throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_CoordinateGroup); } if (!coordinateGroup.Items.Contains(viewCube)) { coordinateGroup.Items.Add(viewCube); } if (!coordinateGroup.Items.Contains(coordinateSystem)) { coordinateGroup.Items.Add(coordinateSystem); } }