public static int GetPrimitiveSize(PrimitiveType primitive)
        {
            switch (primitive)
            {
            case PrimitiveType.LineList: return(IndexLine.GetSizeInShortInts());

            case PrimitiveType.PointList: return(IndexPoint.GetSizeInShortInts());

            case PrimitiveType.TriangleList: return(IndexTriangle.GetSizeInShortInts());

            default: break;
            }
            return(IndexTriangle.GetSizeInShortInts());
        }
Beispiel #2
0
        // A helper function, analogous to ProcessFaces.
        private void ProcessPoints(RenderingPassBufferStorage bufferStorage)
        {
            var points = bufferStorage.Points;

            if (points.Count == 0)
            {
                return;
            }

            // Edges are encoded as line segment primitives whose vertices contain only position information.
            bufferStorage.FormatBits = VertexFormatBits.PositionColored;

            //int edgeVertexBufferSizeInFloats = VertexPosition.GetSizeInFloats() * bufferStorage.VertexBufferCount;
            int vertexBufferSizeInFloats = VertexPositionColored.GetSizeInFloats() * bufferStorage.VertexBufferCount;

            int numPoints = points.Count;

            bufferStorage.VertexBuffer = new VertexBuffer(vertexBufferSizeInFloats);
            bufferStorage.VertexBuffer.Map(vertexBufferSizeInFloats);

            var vertexStream = bufferStorage.VertexBuffer.GetVertexStreamPositionColored();

            for (int i = 0; i < numPoints; i++)
            {
                var pointInfo = points[i];
                var vertex    = pointInfo.Vertex;
                vertexStream.AddVertex(new VertexPositionColored(vertex + pointInfo.Offset, pointInfo.Color));
            }

            bufferStorage.VertexBuffer.Unmap();

            bufferStorage.IndexBufferCount = bufferStorage.PrimitiveCount * IndexPoint.GetSizeInShortInts();
            int indexBufferSizeInShortInts = 1 * bufferStorage.IndexBufferCount;

            bufferStorage.IndexBuffer = new IndexBuffer(indexBufferSizeInShortInts);
            bufferStorage.IndexBuffer.Map(indexBufferSizeInShortInts);
            {
                IndexStreamPoint indexStream = bufferStorage.IndexBuffer.GetIndexStreamPoint();
                for (int i = 0; i < numPoints; i++)
                {
                    indexStream.AddPoint(new IndexPoint(i));
                }
            }
            bufferStorage.IndexBuffer.Unmap();

            bufferStorage.VertexFormat   = new VertexFormat(bufferStorage.FormatBits);
            bufferStorage.EffectInstance = new EffectInstance(bufferStorage.FormatBits);
        }
        static IndexBuffer IndexPointsBuffer(int pointsCount)
        {
            Debug.Assert(pointsCount <= VertexThreshold);

            if (indexPointsBuffer == null)
            {
                indexPointsBuffer = new IndexBuffer(VertexThreshold * IndexPoint.GetSizeInShortInts());
                indexPointsBuffer.Map(VertexThreshold * IndexPoint.GetSizeInShortInts());
                using (var istream = indexPointsBuffer.GetIndexStreamPoint())
                {
                    for (int vi = 0; vi < VertexThreshold; ++vi)
                    {
                        istream.AddPoint(new IndexPoint(vi));
                    }
                }
                indexPointsBuffer.Unmap();
            }

            Debug.Assert(indexPointsBuffer.IsValid());
            return(indexPointsBuffer);
        }