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);
        }
        /// <summary>
        /// Draw the batch. The data is expected to have been uploaded to the vbo at this point.
        /// </summary>
        /// <param name="vao">The vao to use.</param>
        protected void Draw(VertexArrayObject vao)
        {
            // Bind graphics objects.
            VertexArrayObject.EnsureBound(vao);
            if (vao.IBO == null)
            {
                IndexBuffer.EnsureBound(IndexBuffer.QuadIbo.Pointer);
            }
            BindTextures();

            // Render specified range.
            var  startIndex = (IntPtr)(_startIndex * sizeof(ushort));
            uint length     = _endIndex - _startIndex ?? (uint)(_mappedTo / 4) * 6 - _startIndex;

            Debug.Assert((uint)_mappedTo <= RenderComposer.MAX_INDICES);
            Debug.Assert((uint)startIndex + length <= RenderComposer.MAX_INDICES * 6);
            Gl.DrawElements(PrimitiveType.Triangles, (int)length, DrawElementsType.UnsignedShort, startIndex);
        }