Exemplo n.º 1
0
        internal void UpdateVertices(Vertex[] vertices)
        {
            Matrix2x3 inverseTransform = Transform.Invert();

            for (int i = 0; i < vertices.Length; i++)
            {
                SharpDX.Vector4 vertexPos = vertices[i].Position;
                Math.Vector2 texturePos = GetTexturePosition(new Math.Vector2(vertexPos.X, vertexPos.Y), inverseTransform);
                vertices[i].TexturePosition = new SharpDX.Vector2(texturePos.X, texturePos.Y);
            }
        }
Exemplo n.º 2
0
            public Glyph(BinaryReader reader)
            {
                AdvanceWidth = reader.ReadInt32();
                LeftSideBearing = reader.ReadInt32();

                Indices = new int[reader.ReadInt32()];
                for (int i = 0; i < Indices.Length; i++)
                    Indices[i] = reader.ReadInt32();

                Vertices = new Vertex[reader.ReadInt32()];
                for (int i = 0; i < Vertices.Length; i++)
                {
                    var v = new Vertex(reader.ReadSingle(), reader.ReadSingle());
                    v.Mode = (VertexMode)reader.ReadByte();
                    if (v.Mode != VertexMode.Default)
                        v.BezierCoordinates = new Vector2(reader.ReadSingle(), reader.ReadSingle());

                    Vertices[i] = v;
                }
            }
Exemplo n.º 3
0
 internal Vertex[] ApplyTo(Vertex[] vertices)
 {
     var result = new Vertex[vertices.Length];
     for (int i = 0; i < vertices.Length; i++)
         result[i] = this.ApplyTo(vertices[i]);
     return result;
 }
Exemplo n.º 4
0
 private Vertex ApplyTo(Vertex vertex)
 {
     fixed (float* values = this.values)
     {
         float x = vertex.Position.X * values[0] + vertex.Position.Y * values[1] + values[2];
         float y = vertex.Position.X * values[3] + vertex.Position.Y * values[4] + values[5];
         return new Vertex(x, y);
     }
 }
Exemplo n.º 5
0
 void DrawVertices(int[] indices, Vertex[] vertices)
 {
     for (int i = 0, indexBufferSize = IndexBufferStartSize, vertexBufferSize = VertexBufferStartSize;
          i < BufferCount;
          i++, indexBufferSize <<= BufferSizeStep, vertexBufferSize <<= BufferSizeStep)
     {
         if (indices.Length <= indexBufferSize && vertices.Length <= vertexBufferSize)
         {
             DrawVertices(indices, vertices, i);
             break;
         }
     }
 }
Exemplo n.º 6
0
        unsafe void DrawVertices(int[] indices, Vertex[] vertices, int bufferIndex)
        {
            if (bufferIndex != currentBufferIndex)
            {
                indexBuffer = indexBuffers[bufferIndex];
                vertexBuffer = vertexBuffers[bufferIndex];
                currentBufferIndex = bufferIndex;

                deviceContext.InputAssembler.SetIndexBuffer(indexBuffer, DXGI.Format.R32_UInt, 0);
                deviceContext.InputAssembler.SetVertexBuffers(0, new D3D11.VertexBufferBinding(vertexBuffer, sizeof(Vertex), 0));
            }

            DataStream stream;
            deviceContext.MapSubresource(indexBuffer, D3D11.MapMode.WriteDiscard, D3D11.MapFlags.None, out stream);
            stream.Position = 0;
            stream.WriteRange(indices);
            deviceContext.UnmapSubresource(indexBuffer, 0);
            stream.Dispose();

            deviceContext.MapSubresource(vertexBuffer, D3D11.MapMode.WriteDiscard, D3D11.MapFlags.None, out stream);
            stream.Position = 0;
            stream.WriteRange(vertices);
            deviceContext.UnmapSubresource(vertexBuffer, 0);
            stream.Dispose();

            deviceContext.DrawIndexed(indices.Length, 0, 0);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets the clipping region to the specified triangles.
        /// </summary>
        /// <param name="indices">The index buffer.</param>
        /// <param name="vertices">The vertex buffer.</param>
        /// <param name="reset">Optional. If set to true the old clipping region is discarded, otherweise the new region adds to the old one.</param>
        /// <remarks>The clipping region is reset automatically before every render cycle.</remarks>
        public void SetClip(int[] indices, Vector2[] vertices, bool reset = true)
        {
            SetBrushBuffer(ClipBrush);

            if (reset) ResetClip();
            deviceContext.OutputMerger.SetDepthStencilState(clipDepthStencilState, 1);

            var realVertices = new Vertex[vertices.Length];
            for (int i = 0; i < vertices.Length; i++)
                realVertices[i] = new Vertex(vertices[i]);
            DrawVertices(indices, realVertices);

            deviceContext.OutputMerger.SetDepthStencilState(clippingDepthStencilState, 1);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Fills a set of triangles with a brush.
        /// </summary>
        /// <param name="indices">The index buffer.</param>
        /// <param name="vertices">The vertex buffer.</param>
        /// <param name="brush">The brush used to fill the triangles.</param>
        public void FillTriangleList(int[] indices, Vector2[] vertices, Brush brush)
        {
            SetBrush(brush);

            var realVertices = new Vertex[vertices.Length];
            for (int i = 0; i < vertices.Length; i++)
                realVertices[i] = new Vertex(vertices[i]);
            brush.UpdateVertices(realVertices);

            DrawVertices(indices, realVertices);
        }