Exemple #1
0
        public override void DrawQuad(Quad vertexQuad, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null, Vector2?blendRangeOverride = null)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(ToString(), "Can not draw a quad with a disposed texture.");
            }

            RectangleF texRect         = GetTextureRect(textureRect);
            Vector2    inflationAmount = inflationPercentage.HasValue ? new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height) : Vector2.Zero;
            RectangleF inflatedTexRect = texRect.Inflate(inflationAmount);
            Vector2    blendRange      = blendRangeOverride ?? inflationAmount;

            if (vertexAction == null)
            {
                if (quadBatch == null)
                {
                    quadBatch = new QuadBatch <TexturedVertex2D>(512, 128);
                }
                vertexAction = quadBatch.Add;
            }

            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomLeft,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = blendRange,
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomRight,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = blendRange,
                Colour          = drawColour.BottomRight.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.TopRight,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = blendRange,
                Colour          = drawColour.TopRight.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.TopLeft,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = blendRange,
                Colour          = drawColour.TopLeft.Linear,
            });

            FrameStatistics.Increment(StatisticsCounterType.KiloPixels, (long)vertexQuad.ConservativeArea);
        }
Exemple #2
0
        /// <summary>
        /// Blits sprite to OpenGL display with specified parameters.
        /// </summary>
        public override void Draw(Quad vertexQuad, RectangleF?textureRect, Color4 drawColour, VertexBatch <TexturedVertex2D> spriteBatch = null, Vector2?inflationPercentage = null)
        {
            Debug.Assert(!isDisposed);

            RectangleF texRect = GetTextureRect(textureRect);

            if (inflationPercentage.HasValue)
            {
                texRect = texRect.Inflate(new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height));
            }

            if (spriteBatch == null)
            {
                if (TextureGLSingle.spriteBatch == null)
                {
                    TextureGLSingle.spriteBatch = new QuadBatch <TexturedVertex2D>(512, 128);
                }
                spriteBatch = TextureGLSingle.spriteBatch;
            }

            Color4 linearColour = drawColour.toLinear();

            spriteBatch.Add(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomLeft,
                TexturePosition = new Vector2(texRect.Left, texRect.Bottom),
                Colour          = linearColour
            });
            spriteBatch.Add(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomRight,
                TexturePosition = new Vector2(texRect.Right, texRect.Bottom),
                Colour          = linearColour
            });
            spriteBatch.Add(new TexturedVertex2D
            {
                Position        = vertexQuad.TopRight,
                TexturePosition = new Vector2(texRect.Right, texRect.Top),
                Colour          = linearColour
            });
            spriteBatch.Add(new TexturedVertex2D
            {
                Position        = vertexQuad.TopLeft,
                TexturePosition = new Vector2(texRect.Left, texRect.Top),
                Colour          = linearColour
            });

            FrameStatistics.Increment(StatisticsCounterType.KiloPixels, (long)vertexQuad.ConservativeArea);
        }
Exemple #3
0
        public override void DrawQuad(Quad vertexQuad, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null)
        {
            Debug.Assert(!isDisposed);

            RectangleF texRect = GetTextureRect(textureRect);

            if (inflationPercentage.HasValue)
            {
                texRect = texRect.Inflate(new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height));
            }

            if (vertexAction == null)
            {
                if (quadBatch == null)
                {
                    quadBatch = new QuadBatch <TexturedVertex2D>(512, 128);
                }
                vertexAction = quadBatch.Add;
            }

            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomLeft,
                TexturePosition = new Vector2(texRect.Left, texRect.Bottom),
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomRight,
                TexturePosition = new Vector2(texRect.Right, texRect.Bottom),
                Colour          = drawColour.BottomRight.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.TopRight,
                TexturePosition = new Vector2(texRect.Right, texRect.Top),
                Colour          = drawColour.TopRight.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.TopLeft,
                TexturePosition = new Vector2(texRect.Left, texRect.Top),
                Colour          = drawColour.TopLeft.Linear,
            });

            FrameStatistics.Increment(StatisticsCounterType.KiloPixels, (long)vertexQuad.ConservativeArea);
        }
        public override void DrawTriangle(Triangle vertexTriangle, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null)
        {
            Debug.Assert(!isDisposed);

            RectangleF texRect = GetTextureRect(textureRect);

            if (inflationPercentage.HasValue)
            {
                texRect = texRect.Inflate(new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height));
            }

            if (vertexAction == null)
            {
                if (triangleBatch == null)
                {
                    // We multiply the size param by 3 such that the amount of vertices is a multiple of the amount of vertices
                    // per primitive (triangles in this case). Otherwise overflowing the batch will result in wrong
                    // grouping of vertices into primitives.
                    triangleBatch = new LinearBatch <TexturedVertex2D>(512 * 3, 128, PrimitiveType.Triangles);
                }
                vertexAction = triangleBatch.Add;
            }

            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2((texRect.Left + texRect.Right) / 2, texRect.Top),
                Colour          = drawColour.TopLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P1,
                TexturePosition = new Vector2(texRect.Left, texRect.Bottom),
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P2,
                TexturePosition = new Vector2(texRect.Right, texRect.Bottom),
                Colour          = drawColour.BottomRight.Linear,
            });

            FrameStatistics.Increment(StatisticsCounterType.KiloPixels, (long)vertexTriangle.ConservativeArea);
        }
Exemple #5
0
        public override void DrawTriangle(Triangle vertexTriangle, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null)
        {
            Debug.Assert(!IsDisposed);

            RectangleF texRect         = GetTextureRect(textureRect);
            Vector2    inflationAmount = inflationPercentage.HasValue ? new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height) : Vector2.Zero;
            RectangleF inflatedTexRect = texRect.Inflate(inflationAmount);

            if (vertexAction == null)
            {
                if (triangleBatch == null)
                {
                    // We multiply the size param by 3 such that the amount of vertices is a multiple of the amount of vertices
                    // per primitive (triangles in this case). Otherwise overflowing the batch will result in wrong
                    // grouping of vertices into primitives.
                    triangleBatch = new LinearBatch <TexturedVertex2D>(512 * 3, 128, PrimitiveType.Triangles);
                }
                vertexAction = triangleBatch.Add;
            }

            // We split the triangle into two, such that we can obtain smooth edges with our
            // texture coordinate trick. We might want to revert this to drawing a single
            // triangle in case we ever need proper texturing, or if the additional vertices
            // end up becoming an overhead (unlikely).
            SRGBColour topColour    = (drawColour.TopLeft + drawColour.TopRight) / 2;
            SRGBColour bottomColour = (drawColour.BottomLeft + drawColour.BottomRight) / 2;

            // Left triangle half
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = topColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P1,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = (vertexTriangle.P1 + vertexTriangle.P2) / 2,
                TexturePosition = new Vector2((inflatedTexRect.Left + inflatedTexRect.Right) / 2, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = bottomColour.Linear,
            });

            // Right triangle half
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = topColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = (vertexTriangle.P1 + vertexTriangle.P2) / 2,
                TexturePosition = new Vector2((inflatedTexRect.Left + inflatedTexRect.Right) / 2, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = bottomColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P2,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = drawColour.BottomRight.Linear,
            });

            FrameStatistics.Increment(StatisticsCounterType.KiloPixels, (long)vertexTriangle.ConservativeArea);
        }
        public override void DrawTriangle(Triangle vertexTriangle, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(ToString(), "Can not draw a triangle with a disposed texture.");
            }

            RectangleF texRect         = GetTextureRect(textureRect);
            Vector2    inflationAmount = inflationPercentage.HasValue ? new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height) : Vector2.Zero;
            RectangleF inflatedTexRect = texRect.Inflate(inflationAmount);

            if (vertexAction == null)
            {
                vertexAction = default_triangle_action;
            }

            // We split the triangle into two, such that we can obtain smooth edges with our
            // texture coordinate trick. We might want to revert this to drawing a single
            // triangle in case we ever need proper texturing, or if the additional vertices
            // end up becoming an overhead (unlikely).
            SRGBColour topColour    = (drawColour.TopLeft + drawColour.TopRight) / 2;
            SRGBColour bottomColour = (drawColour.BottomLeft + drawColour.BottomRight) / 2;

            // Left triangle half
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = topColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P1,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = (vertexTriangle.P1 + vertexTriangle.P2) / 2,
                TexturePosition = new Vector2((inflatedTexRect.Left + inflatedTexRect.Right) / 2, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = bottomColour.Linear,
            });

            // Right triangle half
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = topColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = (vertexTriangle.P1 + vertexTriangle.P2) / 2,
                TexturePosition = new Vector2((inflatedTexRect.Left + inflatedTexRect.Right) / 2, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = bottomColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P2,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = drawColour.BottomRight.Linear,
            });

            FrameStatistics.Add(StatisticsCounterType.Pixels, (long)vertexTriangle.ConservativeArea);
        }