예제 #1
0
파일: IRenderer.cs 프로젝트: shff/gk3tools
        public VertexElementSet(VertexElement[] elements)
        {
            Stride = (int)elements[elements.Length - 1].Offset +
                     (int)elements[elements.Length - 1].Format * sizeof(float);

            Elements = elements;

#if !D3D_DISABLED
            Direct3D9.Direct3D9Renderer renderer = RendererManager.CurrentRenderer as Direct3D9.Direct3D9Renderer;

            if (renderer != null)
            {
                SharpDX.Direct3D9.VertexElement[] d3d9Elements = new SharpDX.Direct3D9.VertexElement[elements.Length + 1];
                for (int i = 0; i < elements.Length; i++)
                {
                    d3d9Elements[i].Offset = (short)elements[i].Offset;

                    if (elements[i].Format == VertexElementFormat.Float)
                    {
                        d3d9Elements[i].Type = SharpDX.Direct3D9.DeclarationType.Float1;
                    }
                    else if (elements[i].Format == VertexElementFormat.Float2)
                    {
                        d3d9Elements[i].Type = SharpDX.Direct3D9.DeclarationType.Float2;
                    }
                    else if (elements[i].Format == VertexElementFormat.Float3)
                    {
                        d3d9Elements[i].Type = SharpDX.Direct3D9.DeclarationType.Float3;
                    }
                    else if (elements[i].Format == VertexElementFormat.Float4)
                    {
                        d3d9Elements[i].Type = SharpDX.Direct3D9.DeclarationType.Float4;
                    }

                    if (elements[i].Usage == VertexElementUsage.Position)
                    {
                        d3d9Elements[i].Usage = SharpDX.Direct3D9.DeclarationUsage.Position;
                    }
                    else if (elements[i].Usage == VertexElementUsage.TexCoord)
                    {
                        d3d9Elements[i].Usage = SharpDX.Direct3D9.DeclarationUsage.TextureCoordinate;
                    }
                    else if (elements[i].Usage == VertexElementUsage.Normal)
                    {
                        d3d9Elements[i].Usage = SharpDX.Direct3D9.DeclarationUsage.Normal;
                    }
                    else if (elements[i].Usage == VertexElementUsage.Color)
                    {
                        d3d9Elements[i].Usage = SharpDX.Direct3D9.DeclarationUsage.Color;
                    }

                    d3d9Elements[i].Stream     = 0;
                    d3d9Elements[i].UsageIndex = (byte)elements[i].UsageIndex;
                    d3d9Elements[i].Method     = SharpDX.Direct3D9.DeclarationMethod.Default;
                }
                d3d9Elements[d3d9Elements.Length - 1] = SharpDX.Direct3D9.VertexElement.VertexDeclarationEnd;
                D3D9Declaration = new SharpDX.Direct3D9.VertexDeclaration(renderer.Direct3D9Device, d3d9Elements);
            }
#endif
        }
예제 #2
0
 protected override void DisposeResource()
 {
     if (_VertexDeclaration != null)
     {
         _VertexDeclaration.Dispose();
         _VertexDeclaration = null;
     }
 }
예제 #3
0
        public VertexDeclaration( IGraphicsDevice graphicsDevice, VertexElement [] elements )
        {
            this.elements = elements.GetEnumerator ();
            SharpDX.Direct3D9.Device device = graphicsDevice.Handle as SharpDX.Direct3D9.Device;

            SharpDX.Direct3D9.VertexElement [] convedElements = new SharpDX.Direct3D9.VertexElement [ elements.Length + 1 ];
            for ( int i = 0, offset = 0; i < elements.Length; ++i )
            {
                convedElements [ i ] = new SharpDX.Direct3D9.VertexElement ( 0, ( short ) offset,
                    ConvertType ( elements [ i ].Size ), SharpDX.Direct3D9.DeclarationMethod.Default,
                    ConvertType ( elements [ i ].Type ), ( byte ) elements [ i ].UsageIndex );
                offset += ElementSizeToRealSize ( elements [ i ].Size );
            }
            convedElements [ elements.Length ] = SharpDX.Direct3D9.VertexElement.VertexDeclarationEnd;

            vertexDeclaration = new SharpDX.Direct3D9.VertexDeclaration ( device, convedElements );
        }
예제 #4
0
        /// <summary>
        /// Draw polygon on the layer with layer index.
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="points"></param>
        /// <param name="borderColor"></param>
        /// <param name="fillColor"></param>
        /// <param name="opacity"></param>
        /// <param name="fillPattern"></param>
        /// <param name="patternSize"></param>
        public void Draw(int layerIndex, System.Drawing.PointF[] points, System.Drawing.Color?borderColor, System.Drawing.Color?fillColor, float opacity, xPFT.Charting.Base.FillPattern fillPattern, float patternSize)
        {
            if (borderColor != null)
            {
                try
                {
                    if (line != null)
                    {
                        line.Begin();
                        line.Draw(DrawingBase.Convertor.ToVector2(points), Convertor.ColorConvertor((System.Drawing.Color)borderColor, opacity));
                        line.End();
                    }
                }
                catch (System.Exception ex)
                {
                    throw new Exception(ex.Message, ex);
                }
            }

            if (fillColor != null)
            {
                if (tex != null)
                {
                    var vertexElems = new[] {
                        new SharpDX.Direct3D9.VertexElement(0, 0, SharpDX.Direct3D9.DeclarationType.Float2, SharpDX.Direct3D9.DeclarationMethod.Default, SharpDX.Direct3D9.DeclarationUsage.PositionTransformed, 0),
                        new SharpDX.Direct3D9.VertexElement(0, 8, SharpDX.Direct3D9.DeclarationType.Color, SharpDX.Direct3D9.DeclarationMethod.Default, SharpDX.Direct3D9.DeclarationUsage.Color, 0),
                        SharpDX.Direct3D9.VertexElement.VertexDeclarationEnd
                    };
                    var vertexDecl = new SharpDX.Direct3D9.VertexDeclaration(device.device, vertexElems);
                    SharpDX.Direct3D9.VertexDeclaration tempVD = device.device.VertexDeclaration;
                    device.device.VertexDeclaration = vertexDecl;
                    Vertex[] verList = Shape.GetVertexArray(DrawingBase.Convertor.ToVector2(points), Convertor.ColorConvertor((System.Drawing.Color)fillColor, opacity));
                    device.device.DrawUserPrimitives <Vertex>(SharpDX.Direct3D9.PrimitiveType.TriangleStrip, verList.Length, verList);
                    device.device.VertexDeclaration = tempVD;
                    vertexDecl.Dispose();
                }
            }
        }
예제 #5
0
 public VertexDeclaration(SharpDX.Direct3D9.VertexDeclaration vertexDeclaration)
 {
     _VertexDeclaration = vertexDeclaration;
 }