private void Tick(object sender, EventArgs e) { lock (Draw._frameBuff) { UpdateScene(); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); //渲染流水线 while (!Rendering_pipeline.RenderEnd) { Rendering_pipeline.Render(); } watch.Stop(); TimeSpan timespan = watch.Elapsed; System.Diagnostics.Debug.WriteLine("渲染管线渲染一帧执行时间:{0}(毫秒)", timespan.TotalMilliseconds); //渲染 G.DrawImage(Draw._frameBuff, 0, 0); } }
/// <summary> /// 场景更新 /// </summary> private void UpdateScene() { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); Draw.Clear(G); Rendering_pipeline.Render(); foreach (GameObject go in Rendering_pipeline._models) { go.mesh.Reset(); } if (!isInit) { isInit = true; Init(); } foreach (GameObject go in Rendering_pipeline._models) { go.EventFunction?.Invoke(go); go.EventFunction = (a) => { }; go.UpdateFunction?.Invoke(go); go.ObjectToWorldMatrix = Matrix4x4.GetRotateX(go.rotation.x) * Matrix4x4.GetRotateY(go.rotation.y) * Matrix4x4.GetRotateZ(go.rotation.z) * Matrix4x4.GetTranslate(go.position); } watch.Stop(); TimeSpan timespan = watch.Elapsed; System.Diagnostics.Debug.WriteLine("0-场景更新执行时间:{0}(毫秒)", timespan.TotalMilliseconds); }