예제 #1
0
        // NumVertsPerPrimitive is a boring helper function that tells how many vertices
        // it will take to draw each kind of primitive.
        static private int NumVertsPerPrimitive(ePrimitiveType primitive)
        {
            int numVertsPerPrimitive;

            switch (primitive)
            {
            case ePrimitiveType.PointList:
                numVertsPerPrimitive = 1;
                break;

            case ePrimitiveType.LineList:
                numVertsPerPrimitive = 2;
                break;

            case ePrimitiveType.TriangleList:
                numVertsPerPrimitive = 3;
                break;

            case ePrimitiveType.RoundedLineList:
                numVertsPerPrimitive = 2;
                break;

            default:
                throw new InvalidOperationException("primitive is not valid");
            }
            return(numVertsPerPrimitive);
        }
예제 #2
0
        // Begin is called to tell the PrimitiveBatch what kind of primitives will be
        // drawn, and to prepare the graphics card to render those primitives.
        public void Begin(ePrimitiveType primitiveType)
        {
            if (hasBegun)
            {
                throw new InvalidOperationException
                          ("End must be called before Begin can be called again.");
            }

            this.primitiveType = primitiveType;

            // how many verts will each of these primitives require?
            this.numVertsPerPrimitive = NumVertsPerPrimitive(primitiveType);

            // prepare the graphics device for drawing by setting the vertex declaration
            // and telling our basic effect to begin.
            if (primitiveType != ePrimitiveType.RoundedLineList)
            {
                device.VertexDeclaration = vertexDeclaration;
                basicEffect.Begin();
                basicEffect.CurrentTechnique.Passes[0].Begin();
            }
            // flip the error checking boolean. It's now ok to call AddVertex, Flush,
            // and End.
            hasBegun = true;
        }