// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics.OpenGL; using System; namespace osu.Framework.Graphics.Shaders { internal class GlobalUniform : IUniformWithValue where T : struct, IEquatable { public Shader Owner { get; } public int Location { get; } public string Name { get; } /// /// Non-null denotes a pending global change. Must be a field to allow for reference access. /// public UniformMapping PendingChange; public GlobalUniform(Shader owner, string name, int uniformLocation) { Owner = owner; Name = name; Location = uniformLocation; } internal void UpdateValue(UniformMapping global) { PendingChange = global; if (Owner.IsBound) Update(); } public void Update() { if (PendingChange == null) return; GLWrapper.SetUniform(this); PendingChange = null; } ref T IUniformWithValue.GetValueByRef() => ref PendingChange.GetValueByRef(); T IUniformWithValue.GetValue() => PendingChange.Value; } }