mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 06:32:55 +08:00
Add shader precompile step
Resolves https://github.com/ppy/osu-framework/issues/1180 in a way.
This commit is contained in:
parent
c1b607fed9
commit
fb6408257a
@ -1,8 +1,12 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Shaders;
|
||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
@ -33,14 +37,28 @@ namespace osu.Game.Screens
|
|||||||
logo.FadeInFromZero(5000, Easing.OutQuint);
|
logo.FadeInFromZero(5000, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OsuScreen loadScreen;
|
||||||
|
private ShaderPrecompiler precompiler;
|
||||||
|
|
||||||
protected override void OnEntering(Screen last)
|
protected override void OnEntering(Screen last)
|
||||||
{
|
{
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
|
|
||||||
if (showDisclaimer)
|
LoadComponentAsync(precompiler = new ShaderPrecompiler(loadIfReady), Add);
|
||||||
LoadComponentAsync(new Disclaimer(), d => Push(d));
|
LoadComponentAsync(loadScreen = showDisclaimer ? (OsuScreen)new Disclaimer() : new Intro(), s => loadIfReady());
|
||||||
else
|
}
|
||||||
LoadComponentAsync(new Intro(), d => Push(d));
|
|
||||||
|
private void loadIfReady()
|
||||||
|
{
|
||||||
|
if (ChildScreen == loadScreen) return;
|
||||||
|
|
||||||
|
if (loadScreen.LoadState != LoadState.Ready)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!precompiler.FinishedCompiling)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Push(loadScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LogoSuspending(OsuLogo logo)
|
protected override void LogoSuspending(OsuLogo logo)
|
||||||
@ -54,5 +72,49 @@ namespace osu.Game.Screens
|
|||||||
{
|
{
|
||||||
showDisclaimer = game.IsDeployedBuild;
|
showDisclaimer = game.IsDeployedBuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles a set of shaders before continuing. Attempts to draw some frames between compilation by limiting to one compile per draw frame.
|
||||||
|
/// </summary>
|
||||||
|
public class ShaderPrecompiler : Drawable
|
||||||
|
{
|
||||||
|
private readonly Action onLoaded;
|
||||||
|
private readonly List<Shader> loadTargets = new List<Shader>();
|
||||||
|
|
||||||
|
public bool FinishedCompiling { get; private set; }
|
||||||
|
|
||||||
|
public ShaderPrecompiler(Action onLoaded)
|
||||||
|
{
|
||||||
|
this.onLoaded = onLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(ShaderManager manager)
|
||||||
|
{
|
||||||
|
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED));
|
||||||
|
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.BLUR));
|
||||||
|
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE));
|
||||||
|
|
||||||
|
loadTargets.Add(manager.Load(@"CursorTrail", FragmentShaderDescriptor.TEXTURE));
|
||||||
|
|
||||||
|
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_3, FragmentShaderDescriptor.TEXTURE_ROUNDED));
|
||||||
|
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_3, FragmentShaderDescriptor.TEXTURE));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Shader currentLoadTarget;
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
// if our target is null we are done.
|
||||||
|
if (loadTargets.All(s => s.Loaded))
|
||||||
|
{
|
||||||
|
FinishedCompiling = true;
|
||||||
|
Expire();
|
||||||
|
onLoaded?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user