/// <summary> /// Update all methods required for this instance. /// </summary> /// <param name="gameTime">The current game time</param> protected override void Update(TimeSpan gameTime) { this.UpdateViewSettings(); this.totalTime += gameTime; if (this.renderer != null) { this.UpdateInputs(); try { this.view.Update(this.totalTime.TotalSeconds); } catch (Exception e) { // This usually happens when the view datacontext references undefined items or with some Noesis limitations NoesisErrorConsole.PrintPanelError(this.Owner.Name, e); } } }
/// <summary> /// Create the panel. /// </summary> private void CreatePanel() { if (!this.noesisService.StyleValid) { return; } this.viewSettingsDirty = false; this.totalTime = TimeSpan.Zero; try { if (!string.IsNullOrEmpty(this.Xaml)) { object root = Noesis.GUI.LoadXaml(this.Xaml); if (root == null) { throw new Exception($"Unable to load XAML {this.Xaml}"); } if (!(root is FrameworkElement)) { throw new Exception($"{this.Xaml} is not a FrameworkElement"); } this.view = Noesis.GUI.CreateView((FrameworkElement)root); if (!this.IsRenderToTexture) { var vsm = this.Owner.Scene.VirtualScreenManager.VirtualScreenRectangle; this.width = (int)vsm.Width; this.height = (int)vsm.Height; } if (this.width <= 0) { throw new Exception("Panel width must be positive"); } if (this.height <= 0) { throw new Exception("Panel height must be positive"); } this.view.SetSize(this.width, this.height); this.view.SetIsPPAAEnabled(this.antiAliasingMode == View.AntialiasingMode.PPAA); this.view.SetTessellationQuality(this.tessellationQuality); // In OpenGL platforms, enable FlipY when the component is rendering to texture View.RenderFlags renderFlags = this.renderFlags; bool doFlip = (WaveServices.Platform.AdapterType != AdapterType.DirectX && this.IsRenderToTexture) ^ this.flipY; renderFlags |= doFlip ? (View.RenderFlags)View.HiddenRenderFlags.FlipY : 0; this.view.SetFlags(renderFlags); this.renderer = this.view.Renderer; this.NoesisBegin(false); this.renderer.Init(this.noesisService.RenderDevice); this.NoesisEnd(); this.view.Update(0); if (!this.IsRenderToTexture) { this.camera.OnPreRender += this.Noesis_OnCameraPreRender; this.EnablePostProcess = this.enablePostProcess; } else { this.RenderManager.OnPreRender += this.Noesis_RenderToTexture; this.transform = this.Owner.FindComponent <Transform3D>(false); this.screenViewport = new Viewport(0, 0, this.width, this.height); this.renderTarget = this.graphicsDevice.RenderTargets.CreateRenderTarget(this.width, this.height); // Try to set the texture to the material. this.SetPanelMaterialTexture(this.Texture); } this.OnViewCreated?.Invoke(this, this.view); } } catch (Exception e) { // This usually happens when loading a XAML with undefined resources or with an incorrect root type NoesisErrorConsole.PrintPanelError(this.Owner.Name, e); // Set default texture this.SetPanelMaterialTexture(StaticResources.DefaultTexture); } }