Beispiel #1
0
        /// <summary>
        /// Render arbitrary vertices. Clockwise order is expected.
        /// </summary>
        /// <param name="vertices">The vertex to render.</param>
        /// <param name="colors">The color (or colors) of the vertex/vertices.</param>
        public void RenderVertices(Vector3[] vertices, params Color[] colors)
        {
            InvalidateStateBatches();

            int neededLength = vertices.Length * VertexData.SizeInBytes;

            if (neededLength > VertexBuffer.Size)
            {
                VertexBuffer.Upload(IntPtr.Zero, (uint)neededLength);
            }

            Span <VertexData> vertMapper = VertexBuffer.CreateMapper <VertexData>(0, vertices.Length * VertexData.SizeInBytes);

            for (var v = 0; v < vertices.Length; v++)
            {
                vertMapper[v].Vertex = vertices[v];
                vertMapper[v].Color  = v >= colors.Length ? colors.Length == 0 ? Color.White.ToUint() : colors[0].ToUint() : colors[v].ToUint();
                vertMapper[v].Tid    = -1;
            }

            VertexBuffer.FinishMapping();
            VertexArrayObject.EnsureBound(CommonVao);
            IndexBuffer.EnsureBound(IndexBuffer.SequentialIbo.Pointer);
            Gl.DrawElements(PrimitiveType.TriangleFan, vertices.Length, DrawElementsType.UnsignedShort, IntPtr.Zero);
        }