A game framework written with osu! in mind.
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.Graphics.OpenGL;
5using System;
6
7namespace osu.Framework.Graphics.Shaders
8{
9 internal class GlobalUniform<T> : IUniformWithValue<T>
10 where T : struct, IEquatable<T>
11 {
12 public Shader Owner { get; }
13 public int Location { get; }
14 public string Name { get; }
15
16 /// <summary>
17 /// Non-null denotes a pending global change. Must be a field to allow for reference access.
18 /// </summary>
19 public UniformMapping<T> PendingChange;
20
21 public GlobalUniform(Shader owner, string name, int uniformLocation)
22 {
23 Owner = owner;
24 Name = name;
25 Location = uniformLocation;
26 }
27
28 internal void UpdateValue(UniformMapping<T> global)
29 {
30 PendingChange = global;
31 if (Owner.IsBound)
32 Update();
33 }
34
35 public void Update()
36 {
37 if (PendingChange == null)
38 return;
39
40 GLWrapper.SetUniform(this);
41 PendingChange = null;
42 }
43
44 ref T IUniformWithValue<T>.GetValueByRef() => ref PendingChange.GetValueByRef();
45 T IUniformWithValue<T>.GetValue() => PendingChange.Value;
46 }
47}