1 module evael.renderer.gl.gl_uniform_resource; 2 3 import evael.renderer.gl.gl_wrapper; 4 import evael.renderer.gl.gl_buffer; 5 6 import evael.renderer.resources.uniform_resource; 7 8 import evael.lib.memory : MemoryHelper; 9 10 private uint bindingPointIndex; 11 12 class GLUniformResource(T) : UniformResource!T 13 { 14 private uint m_blockIndex; 15 private uint m_bindingPointIndex; 16 17 /** 18 * GLUniformResource constructor. 19 */ 20 @nogc 21 public this(in string name, in uint programId, T defaultValue) 22 { 23 super(name); 24 25 assert(this.m_blockIndex != GL_INVALID_INDEX); 26 27 this.m_buffer = MemoryHelper.create!UniformBuffer(T.sizeof, &defaultValue); 28 this.m_blockIndex = gl.GetUniformBlockIndex(programId, cast(char*) this.m_name.ptr); 29 this.m_bindingPointIndex = bindingPointIndex++; 30 31 gl.BindBufferBase(GL_UNIFORM_BUFFER, this.m_bindingPointIndex, this.m_buffer.id); 32 gl.UniformBlockBinding(programId, this.m_blockIndex, this.m_bindingPointIndex); 33 34 gl.BindBuffer(GL_UNIFORM_BUFFER, 0); 35 } 36 37 @nogc 38 public override void apply() const nothrow 39 { 40 } 41 42 @nogc 43 public override void clear() const nothrow 44 { 45 } 46 47 @nogc 48 public override void update() const nothrow 49 { 50 this.m_buffer.update(0, T.sizeof, &this.m_uniformStruct); 51 } 52 53 @nogc 54 @property nothrow 55 { 56 public uint blockIndex() const 57 { 58 return this.m_blockIndex; 59 } 60 } 61 } 62