Пример #1
0
        public static Direct3D.VertexDeclaration CreateVertexDeclaration(Direct3D.Device d3dDevice, VertexLayout layout)
        {
            List <Direct3D.VertexElement> formats = new List <Direct3D.VertexElement>();
            short loc = 0;

            for (int i = 0; i < layout.Count; i++)
            {
                var element = layout[i];

                Direct3D.VertexElement d3d_element = ConvertElement(element, ref loc);

                formats.Add(d3d_element);
            }

            formats.Add(Direct3D.VertexElement.VertexDeclarationEnd);

            return(new Direct3D.VertexDeclaration(d3dDevice, formats.ToArray()));
        }
Пример #2
0
        private void CreateVertexDeclaration()
        {
            int elementIndex   = 0;
            var vertexElements = new VertexElementD3D9[Format.Elements.Length + 1];

            foreach (var vertexElement in Format.Elements)
            {
                if (vertexElement.ElementType == VertexElementType.Position3D)
                {
                    vertexElements[elementIndex++] = GetVertexPosition3D(vertexElement.Offset);
                }
                else if (vertexElement.ElementType == VertexElementType.Position2D)
                {
                    vertexElements[elementIndex++] = GetVertexPosition2D(vertexElement.Offset);
                }
                else if (vertexElement.ElementType == VertexElementType.Normal)
                {
                    vertexElements[elementIndex++] = GetVertexNormal(vertexElement.Offset);
                }
                else if (vertexElement.ElementType == VertexElementType.Color)
                {
                    vertexElements[elementIndex++] = GetVertexColor(vertexElement.Offset);
                }
                else if (vertexElement.ElementType == VertexElementType.TextureUV)
                {
                    vertexElements[elementIndex++] = GetVertexTextureCoordinate(vertexElement.Offset);
                }
                else if (vertexElement.ElementType == VertexElementType.LightMapUV)
                {
                    vertexElements[elementIndex++] = GetVertexLightMapUV(vertexElement.Offset);
                }
                else if (vertexElement.ElementType == VertexElementType.SkinIndices)
                {
                    vertexElements[elementIndex++] = GetVertexSkindIndices(vertexElement.Offset);
                }
                else if (vertexElement.ElementType == VertexElementType.SkinWeights)
                {
                    vertexElements[elementIndex++] = GetVertexSkindWeights(vertexElement.Offset);
                }
            }
            vertexElements[elementIndex] = VertexElementD3D9.VertexDeclarationEnd;
            vertexDeclaration            = new VertexDeclaration(NativeDevice, vertexElements);
        }