A game framework written with osu! in mind.
at master 2.0 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osu.Framework.Statistics; 5using System; 6using System.Collections.Generic; 7using osu.Framework.Development; 8using osu.Framework.Graphics.OpenGL; 9using osu.Framework.Platform; 10using osuTK; 11 12namespace osu.Framework.Threading 13{ 14 public class DrawThread : GameThread 15 { 16 private readonly GameHost host; 17 18 public DrawThread(Action onNewFrame, GameHost host) 19 : base(onNewFrame, "Draw") 20 { 21 this.host = host; 22 } 23 24 public override bool IsCurrent => ThreadSafety.IsDrawThread; 25 26 protected sealed override void OnInitialize() 27 { 28 var window = host.Window; 29 30 if (window != null) 31 { 32 window.MakeCurrent(); 33 34 GLWrapper.Initialize(host); 35 GLWrapper.Reset(new Vector2(window.ClientSize.Width, window.ClientSize.Height)); 36 } 37 } 38 39 internal sealed override void MakeCurrent() 40 { 41 base.MakeCurrent(); 42 43 ThreadSafety.IsDrawThread = true; 44 45 // Seems to be required on some drivers as the context is lost from the draw thread. 46 host.Window?.MakeCurrent(); 47 } 48 49 protected sealed override void OnSuspended() 50 { 51 base.OnSuspended(); 52 host.Window?.ClearCurrent(); 53 } 54 55 internal override IEnumerable<StatisticsCounterType> StatisticsCounters => new[] 56 { 57 StatisticsCounterType.VBufBinds, 58 StatisticsCounterType.VBufOverflow, 59 StatisticsCounterType.TextureBinds, 60 StatisticsCounterType.FBORedraw, 61 StatisticsCounterType.DrawCalls, 62 StatisticsCounterType.ShaderBinds, 63 StatisticsCounterType.VerticesDraw, 64 StatisticsCounterType.VerticesUpl, 65 StatisticsCounterType.Pixels, 66 }; 67 } 68}