Exemplo n.º 1
0
        /// <summary>
        /// Configures the data source for a floating point vertex attribute.
        /// An exception is thrown if the specified parameters would result in an invalid buffer access.
        /// </summary>
        /// <param name="vertexAttribute">The vertex attribute information></param>
        /// <param name="bufferName">The name of the buffer used for <see cref="AddBuffer{T}(string, T[])"/></param>
        /// <param name="offsetInBytes">The offset in bytes for the start of the vertex data in the buffer</param>
        /// <param name="strideInBytes">The stride in bytes for the buffer data</param>
        /// <exception cref="ArgumentOutOfRangeException">The specified parameters would result in an invalid buffer access.</exception>
        public void ConfigureAttribute(VertexAttribute vertexAttribute, string bufferName, int offsetInBytes, int strideInBytes)
        {
            if (strideInBytes < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(strideInBytes), invalidAccessMessage);
            }

            if (!bufferByName.ContainsKey(bufferName))
            {
                throw new ArgumentException($"The buffer {bufferName} has not been added.", nameof(bufferName));
            }
            var buffer = bufferByName[bufferName];

            var elementSize = AttribPointerUtils.GetSizeInBytes(vertexAttribute.Type) * (int)vertexAttribute.ValueCount;

            if (!BufferValidation.IsValidAccess(offsetInBytes, strideInBytes, elementSize, VertexCount, buffer.SizeInBytes))
            {
                throw new ArgumentOutOfRangeException("", invalidAccessMessage);
            }

            // Associate attributes with the appropriate buffer, so the buffer can be bound later.
            attributesByBuffer[buffer].Add(new VertexAttributeExtended(vertexAttribute, offsetInBytes, strideInBytes));
        }
Exemplo n.º 2
0
 private static void CheckAttribPointerSize(int expected, VertexAttribPointerType type)
 {
     Assert.AreEqual(expected, AttribPointerUtils.GetSizeInBytes(type));
 }