private void InitializeCore() { Core = new RenderCore(); ThumbnailBinding.ThumbMan.SetTarget(Core.ThumbMan); ThumbnailBinding.TexLoad.SetTarget(Core.TexLoader); OperateTargets[0] = Core.TheScene.MainCamera; OperateTargets[1] = Core.TheScene.Drawables.LastOrDefault(); OperateTargets[2] = Core.TheScene.Lights.LastOrDefault(); Core.Resize((uint)glMain.ClientSize.Width, (uint)glMain.ClientSize.Height); this.Closed += (o, e) => { Core.Dispose(); Core = null; }; glMain.Draw += Core.Draw; glMain.Resize += (o, e) => { Core.Resize((uint)e.Width, (uint)e.Height); }; AutoRefresher = new Timer(o => { if (!ShouldRefresh) { return; } OperateTargets[1]?.Rotate(0, 3 * MULER, 0); this.Dispatcher.InvokeAsync(() => glMain.Invalidate(), System.Windows.Threading.DispatcherPriority.Normal); }, null, 0, 15); this.Closing += (o, e) => AutoRefresher.Change(Timeout.Infinite, 20); glMain.Invalidate(); WaitingCount = 0; var fpsTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.5) }; fpsTimer.Tick += (o, e) => { var timeUs = glMain?.AvgDrawTime ?? 0; txtFPS.Text = timeUs > 0 ? $"{1000000 / timeUs} FPS@{timeUs / 1000}ms" : ""; }; fpsTimer.Start(); Core.TheScene.Drawables.ObjectPropertyChanged += (s, t, e) => InvalidateOnPropChanged(e.PropertyName); drawablePage.DataContext = Core.TheScene.Drawables; Core.TheScene.Lights.ObjectPropertyChanged += (s, t, e) => InvalidateOnPropChanged(e.PropertyName); lightPage.DataContext = Core.TheScene.Lights; Core.Passes.ObjectPropertyChanged += (s, t, e) => InvalidateOnPropChanged(e.PropertyName); shaderPage.DataContext = Core.Passes; Core.Controls.ForEach(x => x.PropertyChanged += (o, e) => InvalidateOnPropChanged(e.PropertyName)); controlPage.DataContext = Core.Controls; Core.TheScene.MainCamera.PropertyChanged += (o, e) => InvalidateOnPropChanged(e.PropertyName); }
public Form1() { Common.ViewModelSyncRoot.Init(); InitializeComponent(); AllowDrop = true; DragEnter += (o, e) => { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Link; } else { e.Effect = DragDropEffects.None; } }; DragDrop += OnDropFileAsync; GLView = new OGLView() { Location = new System.Drawing.Point(0, 0), Name = "oglv", Size = ClientSize, ResizeBGDraw = false }; Core = new RenderCore(); OperateTargets[0] = Core.TheScene.MainCamera; OperateTargets[1] = Core.TheScene.Drawables.LastOrDefault(); OperateTargets[2] = Core.TheScene.Lights.LastOrDefault(); Core.Resize((uint)ClientSize.Width, (uint)ClientSize.Height); Controls.Add(GLView); Resize += (o, e) => { GLView.Size = ClientSize; }; FormClosing += (o, e) => { Core.Dispose(); Core = null; }; GLView.Draw += Core.Draw; GLView.Resize += (o, e) => { Core.Resize((uint)e.Width, (uint)e.Height); }; GLView.KeyDown += OnKeyDown; //oglv.KeyAction += OnKeyAction; GLView.MouseAction += OnMouse; }