Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VertexBufferBinding"/> struct.
        /// </summary>
        /// <param name="vertexStride">Jump size to the next element. if -1, it gets auto-discovered from the vertexDeclaration</param>
        /// <param name="vertexOffset">Offset (in Vertex ElementCount) from the beginning of the buffer to the first vertex to use.</param>
        public VertexBufferBinding(Buffer vertexBuffer, VertexDeclaration vertexDeclaration, int vertexCount, int vertexStride = -1, int vertexOffset = 0) : this()
        {
            if (vertexBuffer == null)
            {
                throw new ArgumentNullException("vertexBuffer");
            }
            if (vertexDeclaration == null)
            {
                throw new ArgumentNullException("vertexDeclaration");
            }

            Buffer      = vertexBuffer;
            Stride      = vertexStride != -1 ? vertexStride : vertexDeclaration.VertexStride;
            Offset      = vertexOffset;
            Count       = vertexCount;
            Declaration = vertexDeclaration;

            unchecked
            {
                hashCode = Buffer.GetHashCode();
                hashCode = (hashCode * 397) ^ Offset;
                hashCode = (hashCode * 397) ^ Stride;
                hashCode = (hashCode * 397) ^ Count;
                hashCode = (hashCode * 397) ^ Declaration.GetHashCode();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="VertexBufferBinding"/> struct.
        /// </summary>
        /// <param name="vertexBuffer">The buffer containing the vertices.</param>
        /// <param name="vertexDeclaration">A <see cref="VertexDeclaration"/> specifying tha layout of the vertices.</param>
        /// <param name="vertexCount">The number of vertices.</param>
        /// <param name="vertexStride">
        ///   Number of bytes to advance to get to the next vertex.
        ///   If -1, it gets auto-discovered from the <paramref name="vertexDeclaration"/>.
        /// </param>
        /// <param name="vertexOffset">
        ///   Offset (in Vertex ElementCount) from the beginning of the buffer to the first vertex to use.
        /// </param>
        public VertexBufferBinding(Buffer vertexBuffer, VertexDeclaration vertexDeclaration, int vertexCount, int vertexStride = -1, int vertexOffset = 0) : this()
        {
            Buffer      = vertexBuffer ?? throw new ArgumentNullException(nameof(vertexBuffer));
            Declaration = vertexDeclaration ?? throw new ArgumentNullException(nameof(vertexDeclaration));

            Stride = vertexStride != -1 ? vertexStride : vertexDeclaration.VertexStride;
            Offset = vertexOffset;
            Count  = vertexCount;

            HashCode hash = default;

            hash.Add(Buffer.GetHashCode());
            hash.Add(Offset);
            hash.Add(Stride);
            hash.Add(Count);
            hash.Add(Declaration.GetHashCode());
            hashCode = hash.ToHashCode();
        }