1 module evael.renderer.resources.uniform_resource; 2 3 import evael.renderer.resources.resource; 4 import evael.renderer.enums.resource_type; 5 import evael.renderer.graphics_buffer; 6 7 import evael.lib.memory : MemoryHelper; 8 9 abstract class UniformResource(T) : Resource 10 { 11 protected T m_uniformStruct; 12 13 /// Uniform name in shader 14 protected string m_name; 15 16 /// Uniform buffer 17 protected UniformBuffer m_buffer; 18 19 @nogc 20 public this(in string name) 21 { 22 super(ResourceType.UniformBuffer); 23 24 this.m_name = name; 25 } 26 27 @nogc 28 public ~this() 29 { 30 MemoryHelper.dispose(this.m_buffer); 31 } 32 33 @nogc 34 public auto opDispatch(string key)() 35 { 36 return mixin("this.m_uniformStruct." ~ key); 37 } 38 39 @nogc 40 public void opDispatch(string key, T)(auto ref inout(T) value) 41 { 42 mixin("this.m_uniformStruct." ~ key) = value; 43 } 44 45 @nogc 46 public abstract void update() const nothrow; 47 48 @nogc 49 @property nothrow 50 { 51 public void value()(in auto ref T value) 52 { 53 this.m_uniformStruct = value; 54 } 55 56 public string name() const 57 { 58 return this.m_name; 59 } 60 61 public UniformBuffer buffer() 62 { 63 return this.m_buffer; 64 } 65 } 66 }