/// <summary> /// Updates the vertex buffer object from the <see cref="Vertices"/> array. /// </summary> /// <typeparam name="TVertex">The type of vertex buffer to use.</typeparam> /// <param name="transform">Function that transforms the vertex array data to a interleaved struct format.</param> private void UpdateVertices <TVertex>( Func <Vector3, Vector3, Color4, TVertex> transform ) where TVertex : struct, IVertexData { // if the type of the vertex data has changed we need to create a new buffer if (m_vertexBuffer != null && m_vertexBuffer.GetType() != typeof(VertexBuffer <TVertex>)) { m_vertexBuffer.Dispose(); m_vertexBuffer = null; } // create vertex buffer if needed if (m_vertexBuffer == null) { m_vertexBuffer = new VertexBuffer <TVertex>(m_vertices.Length); } // copy the vertices into the buffer VertexBuffer <TVertex> buffer = m_vertexBuffer as VertexBuffer <TVertex>; buffer.Clear(); int offset; TVertex[] vertexArray = buffer.WriteDirectly(m_vertices.Length, out offset); for (int i = 0; i < m_vertices.Length; i++) { vertexArray[i] = transform(m_vertices[i], m_normals[i], m_colors[i]); } // upload to the GPU buffer.BufferData(); m_vertexBufferDirty = false; }