コード例 #1
0
ファイル: VSCollection.cs プロジェクト: thakgit/StiLib
        /// <summary>
        /// Get Instancing VertexDeclaration
        /// </summary>
        /// <param name="gd"></param>
        /// <returns></returns>
        public VertexDeclaration InstancingVDec(GraphicsDevice gd)
        {
            // When using hardware instancing, the instance transform matrix is
            // specified using a second vertex stream that provides 4x4 matrices
            // in texture coordinate channels 1 to 4. We must modify our vertex
            // declaration to include these channels.
            VertexElement[] extraElements = new VertexElement[4];
            short           offset        = 0;
            byte            usageIndex    = 1;
            short           stream        = 1;

            for (int i = 0; i < extraElements.Length; i++)
            {
                extraElements[i] = new VertexElement(stream, offset,
                                                     VertexElementFormat.Vector4,
                                                     VertexElementMethod.Default,
                                                     VertexElementUsage.TextureCoordinate,
                                                     usageIndex);

                offset += SLConstant.SizeOfVector4;
                usageIndex++;
            }

            // Append the new elements to the original format.
            int length = VertexPositionColor.VertexElements.Length + extraElements.Length;

            VertexElement[] elements = new VertexElement[length];
            VertexPositionColor.VertexElements.CopyTo(elements, 0);
            extraElements.CopyTo(elements, VertexPositionColor.VertexElements.Length);

            // Create a new vertex declaration.
            return(new VertexDeclaration(gd, elements));
        }