Beispiel #1
0
        /// <summary>Create a new global MaterialBuffer bound to the register
        /// slot id. All shaders will have access to the data provided via
        /// this instance's `Set`.</summary>
        /// <param name="registerSlot">Valid values are 3-16. This is the
        /// register id that this data will be bound to. In HLSL, you'll see
        /// the slot id for '3' indicated like this `: register(b3)`</param>
        public MaterialBuffer(int registerSlot)
        {
            if (!(typeof(T).IsLayoutSequential || typeof(T).IsExplicitLayout))
            {
                throw new NotSupportedException("MaterialBuffer's data type must have a '[StructLayout(LayoutKind.Sequential)]' attribute for proper copying! Explicit would work too.");
            }

            int size = Marshal.SizeOf(typeof(T));

            _localMemory = Marshal.AllocHGlobal(size);
            _inst        = NativeAPI.material_buffer_create(registerSlot, size);
            if (_inst == IntPtr.Zero)
            {
                throw new ArgumentException("Bad slot id, see log.");
            }
        }