/// <summary>Calculate fill in shape by using triangulation.</summary> /// <param name="_WindingOrder">Winding order of the shape used for triangulating.</param> private void CalculateFillInShape(Triangulator.WindingOrder _WindingOrder) { // Validate. if (m_VectorList.Count <= 2) { return; } // Create a list of vertices. Vector2[] vSourceVertices = new Vector2[m_VectorList.Count]; for (int i = m_VectorList.Count - 1; i >= 0; --i) { vSourceVertices[i] = m_VectorList[i]; } // Create a list of indices. int[] nSourceIndices; // Triangulate vertices and indices. Triangulator.Triangulator.Triangulate(vSourceVertices, _WindingOrder, out vSourceVertices, out nSourceIndices); // Store number of vertices and primitives for rendering. m_nVertices = vSourceVertices.Length; m_nPrimitives = nSourceIndices.Length / 3; // Create and setup the list of vertex data. VertexPositionColor[] verts = new VertexPositionColor[vSourceVertices.Length]; for (int i = vSourceVertices.Length - 1; i >= 0; --i) { verts[i] = new VertexPositionColor(m_GraphicsDevice.Viewport.Unproject(new Vector3(vSourceVertices[i], 0f), m_Projection, m_View, Matrix.Identity), m_FillInColor); } // Clean up old data. if (m_VertexBuffer != null) { m_VertexBuffer.Dispose(); m_VertexBuffer = null; } if (m_IndexBuffer != null) { m_IndexBuffer.Dispose(); m_IndexBuffer = null; } // Create vertex buffer. m_VertexBuffer = new VertexBuffer(m_GraphicsDevice, VertexPositionColor.VertexDeclaration, verts.Length * VertexPositionColor.VertexDeclaration.VertexStride, BufferUsage.WriteOnly); m_VertexBuffer.SetData(verts); // Branch here to convert our indices to shorts if possible for wider GPU support. if (verts.Length < UInt16.MaxValue /*65535*/) { // Create a list of indices. short[] sIndices = new short[nSourceIndices.Length]; for (int i = nSourceIndices.Length - 1; i >= 0; --i) { sIndices[i] = (short)nSourceIndices[i]; } // Create index buffer. m_IndexBuffer = new IndexBuffer(m_GraphicsDevice, IndexElementSize.SixteenBits, sIndices.Length * sizeof(short), BufferUsage.WriteOnly); m_IndexBuffer.SetData(sIndices); } else { // Create index buffer. m_IndexBuffer = new IndexBuffer(m_GraphicsDevice, IndexElementSize.ThirtyTwoBits, nSourceIndices.Length * sizeof(int), BufferUsage.WriteOnly); m_IndexBuffer.SetData(nSourceIndices); } }
/// <summary>Calculate outline shape by using textured quad.</summary> /// <param name="_WindingOrder">Winding order of the shape used for triangulating.</param> private void CalculateOutlineShape(Triangulator.WindingOrder _WindingOrder) { // Validate. if (m_VectorList.Count < 2) { return; } // Sharpness determines the line quality by offsetting pixels. Vector2 vOffsetSharpness = Vector2.Zero; switch (m_Antialiasing) { case Antialiasing.Disabled: vOffsetSharpness = new Vector2(3f, 3f); break; case Antialiasing.Enabled: vOffsetSharpness = new Vector2(1f, 1f); break; default: break; } // Create a list of vertices. Vector2[] vSourceVertices = new Vector2[4]; vSourceVertices[0] = Vector2.Zero; vSourceVertices[1] = new Vector2(0f, m_PixelTexture.Height); vSourceVertices[2] = new Vector2(m_PixelTexture.Width, m_PixelTexture.Height); vSourceVertices[3] = new Vector2(m_PixelTexture.Width, 0f); // Create a list of indices. int[] nSourceIndices; // Triangulate vertices and indices. Triangulator.Triangulator.Triangulate(vSourceVertices, _WindingOrder, out vSourceVertices, out nSourceIndices); // Store number of vertices and primitives for rendering. m_nVertices = vSourceVertices.Length; m_nPrimitives = nSourceIndices.Length / 3; // Create and setup the list of vertex data. VertexPositionColorTexture[] verts = new VertexPositionColorTexture[vSourceVertices.Length]; for (int i = vSourceVertices.Length - 1; i >= 0; --i) { verts[i] = new VertexPositionColorTexture(m_GraphicsDevice.Viewport.Unproject(new Vector3(vSourceVertices[i], 0f), m_Projection, m_View, Matrix.Identity), m_FillInColor, new Vector2(vSourceVertices[i].X / (m_PixelTexture.Width - vOffsetSharpness.X), vSourceVertices[i].Y / (m_PixelTexture.Height - vOffsetSharpness.Y))); } // Clean up old data. if (m_VertexBuffer != null) { m_VertexBuffer.Dispose(); m_VertexBuffer = null; } if (m_IndexBuffer != null) { m_IndexBuffer.Dispose(); m_IndexBuffer = null; } // Create vertex buffer. m_VertexBuffer = new VertexBuffer(m_GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, verts.Length * VertexPositionColorTexture.VertexDeclaration.VertexStride, BufferUsage.WriteOnly); m_VertexBuffer.SetData(verts); // Branch here to convert our indices to shorts if possible for wider GPU support. if (verts.Length < UInt16.MaxValue /*65535*/) { // Create a list of indices. short[] sIndices = new short[nSourceIndices.Length]; for (int i = nSourceIndices.Length - 1; i >= 0; --i) { sIndices[i] = (short)nSourceIndices[i]; } // Create index buffer. m_IndexBuffer = new IndexBuffer(m_GraphicsDevice, IndexElementSize.SixteenBits, sIndices.Length * sizeof(short), BufferUsage.WriteOnly); m_IndexBuffer.SetData(sIndices); } else { // Create index buffer. m_IndexBuffer = new IndexBuffer(m_GraphicsDevice, IndexElementSize.ThirtyTwoBits, nSourceIndices.Length * sizeof(int), BufferUsage.WriteOnly); m_IndexBuffer.SetData(nSourceIndices); } }