예제 #1
0
 private void Reserve(int new_capacity)
 {
     if (new_capacity <= capacity)
     {
         return;
     }
     DrawVertex[] new_data = new DrawVertex[new_capacity];
     if (this.data != null)
     {
         unsafe
         {
             var dest_byte_size = new_capacity * Marshal.SizeOf <DrawVertex>();
             var src_byte_size  = size * Marshal.SizeOf <DrawVertex>();
             fixed(DrawVertex *data_ptr = this.data)
             fixed(DrawVertex * new_data_ptr = new_data)
             {
                 Buffer.MemoryCopy(data_ptr, new_data_ptr, dest_byte_size, src_byte_size);
             }
         }
     }
     this.data     = null;
     this.data     = new_data;
     this.capacity = new_capacity;
     UpdatePointer();
 }
예제 #2
0
        /// <summary>
        /// Add a poly line.
        /// </summary>
        /// <param name="points">points</param>
        /// <param name="color">color</param>
        /// <param name="close">Should this method close the polyline for you? A line segment from the last point to first point will be added if this is true.</param>
        /// <param name="thickness">thickness</param>
        /// <param name="antiAliased">anti-aliased</param>
        public void AddPolyline(IList <Point> points, Color color, bool close, double thickness, bool antiAliased = false)
        {
            var pointsCount = points.Count;

            if (pointsCount < 2)
            {
                return;
            }

            int count = pointsCount;

            if (!close)
            {
                count = pointsCount - 1;
            }

            if (antiAliased)
            {
                throw new NotImplementedException();
            }
            else
            {
                // Non Anti-aliased Stroke
                int idxCount = count * 6;
                int vtxCount = count * 4; // FIXME: Not sharing edges
                this.ShapeMesh.PrimReserve(idxCount, vtxCount);

                for (int i1 = 0; i1 < count; i1++)
                {
                    int    i2   = (i1 + 1) == pointsCount ? 0 : i1 + 1;
                    Point  p1   = points[i1];
                    Point  p2   = points[i2];
                    Vector diff = p2 - p1;
                    diff *= MathEx.InverseLength(diff, 1.0f);

                    float dx      = (float)(diff.X * (thickness * 0.5f));
                    float dy      = (float)(diff.Y * (thickness * 0.5f));
                    var   vertex0 = new DrawVertex {
                        pos = new Point(p1.X + dy, p1.Y - dx), uv = Point.Zero, color = color
                    };
                    var vertex1 = new DrawVertex {
                        pos = new Point(p2.X + dy, p2.Y - dx), uv = Point.Zero, color = color
                    };
                    var vertex2 = new DrawVertex {
                        pos = new Point(p2.X - dy, p2.Y + dx), uv = Point.Zero, color = color
                    };
                    var vertex3 = new DrawVertex {
                        pos = new Point(p1.X - dy, p1.Y + dx), uv = Point.Zero, color = color
                    };
                    this.ShapeMesh.AppendVertex(vertex0);
                    this.ShapeMesh.AppendVertex(vertex1);
                    this.ShapeMesh.AppendVertex(vertex2);
                    this.ShapeMesh.AppendVertex(vertex3);

                    this.ShapeMesh.AppendIndex(0);
                    this.ShapeMesh.AppendIndex(1);
                    this.ShapeMesh.AppendIndex(2);
                    this.ShapeMesh.AppendIndex(0);
                    this.ShapeMesh.AppendIndex(2);
                    this.ShapeMesh.AppendIndex(3);

                    this.ShapeMesh.currentIdx += 4;
                }
            }
        }
예제 #3
0
 public void AppendVertex(DrawVertex vertex)
 {
     this.VertexBuffer[this.vtxWritePosition] = vertex;
     this.vtxWritePosition++;
 }