private OpenGlRenderer(ModelView mv) { if (mv == null) { throw new ArgumentNullException(nameof(mv)); } GLDoubleBuffer = new GLDoubleBuffer(mv); _MView = mv; DoSetup(); _Disposable = _MView.BufferSwapNotifyObservable().Subscribe(args => { var time = DateTime.Now; var layers = GLDoubleBuffer.Front.GroupBy(o => o.Value.Item1) .OrderBy(o => o.Key) .Select(o => new { Index = o.Key, Renderables = o.Select(q => q.Value.Item2).ToList() }) .ToList(); foreach (var layer in layers) { // Clear the depth buffer after each subsequent layer. This // will ensure that they are drawn on top of each other. if (layer.Index != 0) { GL.Clear(ClearBufferMask.DepthBufferBit); } foreach (var r in layer.Renderables) { r.Render(time); } } }); }