/// <summary> /// Creates a new <see cref="ConstantBuffer" /> with the specified size in bytes. /// </summary> /// <param name="graphicsDevice"> The graphics device. </param> /// <param name="sizeInBytes"> The size in bytes. </param> /// <param name="resourceUsage"> (Optional) The resource usage. </param> /// <param name="cpuAccessFlags"> (Optional) The CPU access flags. </param> /// <returns> /// A <see cref="ConstantBuffer" />. /// </returns> /// <remarks> /// The <paramref name="sizeInBytes" /> must be a multiple of 16, /// if not it will be calculated to the minimum multiple of 16 fitting it in. /// e.g. /// - a size in bytes of 11 will be 16. /// - a size in bytes of 23 will be 32. /// - a size in bytes of 80 will be 80. /// > see https://docs.microsoft.com/de-de/windows/win32/api/d3d11/ns-d3d11-d3d11_buffer_desc#remarks /// </remarks> public static ConstantBuffer Create(IGraphicsDevice graphicsDevice, int sizeInBytes, ResourceUsage resourceUsage = ResourceUsage.Default, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { return(new ConstantBuffer( new Buffer( graphicsDevice.Device, Math2.Ceiling(sizeInBytes / 16.0f) * 16, resourceUsage, BindFlags.ConstantBuffer, cpuAccessFlags, ResourceOptionFlags.None, 0))); }
private static ushort E2S(byte[] data, int offset, int length, byte[] buffer, int bufferOffset, out int bufferLength) { bufferLength = length + Math2.Ceiling(length / 7.0f); uint checksum = s_h0; while (offset + 7 < length) { E2S(&checksum, buffer, bufferOffset, data, offset, 7); bufferOffset += 8; offset += 7; } E2S(&checksum, buffer, bufferOffset, data, offset, length - offset); return((ushort)(CONE | ((ushort)checksum ^ (checksum >> 16)))); }
internal static ushort S2E(byte *src, int offset, int length, byte[] buffer, out int bufferLength) { bufferLength = length - Math2.Ceiling(length / 8.0); uint checksum = s_h0; int o1 = 0; fixed(byte *dest = buffer) { while (offset + 8 < length) { Deserialize(&checksum, dest, o1, src, offset, 8); o1 += 7; offset += 8; } Deserialize(&checksum, dest, o1, src, offset, length - offset); } return((ushort)(CONE | ((ushort)checksum ^ (checksum >> 16)))); }
internal static int DecodedPayloadLength(int length) { return(length - Math2.Ceiling(length / 8.0)); }
internal static int EncodedPayloadLength(int length) { return(length + Math2.Ceiling(length / 7.0f)); }
internal static void SerializeTcp(uint commandID, byte[] data, int offset, int length, uint responseID, EncryptionMode encryptionMode, out byte[] send, out int size) { send = ByteArrayPool.Rent(Constants.TCP_HEADER_SIZE + 9 + length + Math2.Ceiling(length / 7.0f)); SerializeTcp(commandID, data, offset, length, responseID, encryptionMode, send, out size); }