コード例 #1
0
            protected override void Dispose(bool isDisposing)
            {
                base.Dispose(isDisposing);

                halfCircleBatch.Dispose();
                quadBatch.Dispose();
            }
コード例 #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         vertexBatch.Dispose();
     }
 }
コード例 #3
0
            protected override void Dispose(bool isDisposing)
            {
                base.Dispose(isDisposing);

                quadBatch?.Dispose();
                triangleBatch?.Dispose();
            }
コード例 #4
0
            protected override void Dispose(bool isDisposing)
            {
                base.Dispose(isDisposing);

                // Children disposed via their source drawables
                Children = null;

                quadBatch?.Dispose();
                triangleBatch?.Dispose();
            }
コード例 #5
0
        private void updateVertexBuffer()
        {
            const float start_angle = 0;

            float dir    = Math.Sign(angle);
            float radius = Math.Max(drawSize.X, drawSize.Y);

            // The amount of points are selected such that discrete curvature is smaller than the provided tolerance.
            // The exact angle required to meet the tolerance is: 2 * Math.Acos(1 - TOLERANCE / r)
            // The special case is for extremely small circles where the radius is smaller than the tolerance.
            int amountPoints = 2 * radius <= arc_tolerance ? 2 : Math.Max(2, (int)Math.Ceiling(Math.PI / Math.Acos(1 - arc_tolerance / radius)));

            if (halfCircleBatch == null || halfCircleBatch.Size < amountPoints * 2)
            {
                halfCircleBatch?.Dispose();

                // Amount of points is multiplied by 2 to account for each part requiring two vertices.
                halfCircleBatch = new LinearBatch <TexturedVertex2D>(amountPoints * 2, 1, PrimitiveType.TriangleStrip);
            }

            Matrix3 transformationMatrix = DrawInfo.Matrix;

            MatrixExtensions.ScaleFromLeft(ref transformationMatrix, drawSize);

            Vector2 current       = origin + pointOnCircle(start_angle) * 0.5f;
            Color4  currentColour = colourAt(current);

            current = Vector2Extensions.Transform(current, transformationMatrix);

            Vector2 screenOrigin = Vector2Extensions.Transform(origin, transformationMatrix);
            Color4  originColour = colourAt(origin);

            // Offset by 0.5 pixels inwards to ensure we never sample texels outside the bounds
            RectangleF texRect = texture.GetTextureRect(new RectangleF(0.5f, 0.5f, texture.Width - 1, texture.Height - 1));

            float prevOffset = dir >= 0 ? 0 : 1;

            // First center point
            halfCircleBatch.Add(new TexturedVertex2D
            {
                Position        = Vector2.Lerp(current, screenOrigin, innerRadius),
                TexturePosition = new Vector2(dir >= 0 ? texRect.Left : texRect.Right, texRect.Top),
                Colour          = originColour
            });

            // First outer point.
            halfCircleBatch.Add(new TexturedVertex2D
            {
                Position        = new Vector2(current.X, current.Y),
                TexturePosition = new Vector2(dir >= 0 ? texRect.Left : texRect.Right, texRect.Bottom),
                Colour          = currentColour
            });

            for (int i = 1; i < amountPoints; i++)
            {
                float fract = (float)i / (amountPoints - 1);

                // Clamps the angle so we don't overshoot.
                // dir is used so negative angles result in negative angularOffset.
                float angularOffset    = Math.Min(fract * two_pi, dir * angle);
                float normalisedOffset = angularOffset / two_pi;

                if (dir < 0)
                {
                    normalisedOffset += 1.0f;
                }

                // Update `current`
                current       = origin + pointOnCircle(start_angle + angularOffset) * 0.5f;
                currentColour = colourAt(current);
                current       = Vector2Extensions.Transform(current, transformationMatrix);

                // current center point
                halfCircleBatch.Add(new TexturedVertex2D
                {
                    Position        = Vector2.Lerp(current, screenOrigin, innerRadius),
                    TexturePosition = new Vector2(texRect.Left + (normalisedOffset + prevOffset) / 2 * texRect.Width, texRect.Top),
                    Colour          = originColour
                });

                // current outer point
                halfCircleBatch.Add(new TexturedVertex2D
                {
                    Position        = new Vector2(current.X, current.Y),
                    TexturePosition = new Vector2(texRect.Left + normalisedOffset * texRect.Width, texRect.Bottom),
                    Colour          = currentColour
                });

                prevOffset = normalisedOffset;
            }
        }