void BindTransform(Matrix4 a_transform, Matrix3 a_rotationMatrix) { UniformBufferObject ubo = m_graphics.TransformBufferObject; Graphics.TransformContainer transContainer = new Graphics.TransformContainer { Transform = a_transform, RotationMatrix = a_rotationMatrix }; ubo.UpdateData(transContainer); ubo.UpdateBuffer(); GL.BindBufferBase(BufferRangeTarget.UniformBuffer, Material.TransformUBOIndex, ((OpenTKUniformBufferObject)ubo.InternalObject).Handle); #if DEBUG_INFO Pipeline.GLError("Graphics: Binding Transform: "); #endif }
void BindTransform(Transform a_transform, ref int a_ubo) { if (a_ubo == -1 || (a_transform.StaticState & 0x1 << 1) == 0) { if (a_ubo == -1) { a_ubo = GL.GenBuffer(); } GL.BindBuffer(BufferTarget.UniformBuffer, a_ubo); Graphics.TransformContainer transform = new Graphics.TransformContainer() { Transform = a_transform.ToMatrix(), RotationMatrix = a_transform.RotationMatrix }; int size = Marshal.SizeOf(transform); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(transform, ptr, false); GL.BufferData(BufferTarget.UniformBuffer, size, ptr, BufferUsageHint.StaticDraw); Marshal.FreeHGlobal(ptr); a_transform.StaticState |= 0x1 << 1; #if DEBUG_INFO Pipeline.GLError("Graphics: Create Static Transform: "); #endif } GL.BindBufferBase(BufferRangeTarget.UniformBuffer, Material.TransformUBOIndex, a_ubo); #if DEBUG_INFO Pipeline.GLError("Graphics: Binding Static Transform: "); #endif }