示例#1
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)
        {
            Debug.Assert(!isDisposed);

            if (!Bind())
            {
                return;
            }

            RectangleF texRect = textureRect != null
                ? new RectangleF(textureRect.Value.X, textureRect.Value.Y, textureRect.Value.Width, textureRect.Value.Height)
                : new RectangleF(0, 0, Width, Height);

            texRect.X      /= width;
            texRect.Y      /= height;
            texRect.Width  /= width;
            texRect.Height /= height;

            if (spriteBatch == null)
            {
                if (TextureGLSingle.spriteBatch == null)
                {
                    TextureGLSingle.spriteBatch = new QuadBatch <TexturedVertex2d>(1, 100);
                }
                spriteBatch = TextureGLSingle.spriteBatch;
            }

            spriteBatch.Add(new TexturedVertex2d
            {
                Position        = vertexQuad.BottomLeft,
                TexturePosition = new Vector2(texRect.Left, texRect.Bottom),
                Colour          = drawColour
            });
            spriteBatch.Add(new TexturedVertex2d
            {
                Position        = vertexQuad.BottomRight,
                TexturePosition = new Vector2(texRect.Right, texRect.Bottom),
                Colour          = drawColour
            });
            spriteBatch.Add(new TexturedVertex2d
            {
                Position        = vertexQuad.TopRight,
                TexturePosition = new Vector2(texRect.Right, texRect.Top),
                Colour          = drawColour
            });
            spriteBatch.Add(new TexturedVertex2d
            {
                Position        = vertexQuad.TopLeft,
                TexturePosition = new Vector2(texRect.Left, texRect.Top),
                Colour          = drawColour
            });
        }
示例#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);
        }
示例#3
0
            public override void Draw(Action <TexturedVertex2D> vertexAction)
            {
                base.Draw(vertexAction);

                shader.Bind();
                shader.GetUniform <float>("g_FadeClock").UpdateValue(ref time);

                for (int i = 0; i < parts.Length; ++i)
                {
                    Vector2 pos       = parts[i].Position;
                    float   localTime = parts[i].Time;

                    DrawQuad(
                        texture,
                        new Quad(pos.X - size.X / 2, pos.Y - size.Y / 2, size.X, size.Y),
                        DrawColourInfo.Colour,
                        null,
                        v => vertexBatch.Add(new TexturedTrailVertex
                    {
                        Position        = v.Position,
                        TexturePosition = v.TexturePosition,
                        Time            = localTime + 1,
                        Colour          = v.Colour,
                    }));
                }

                shader.Unbind();
            }
示例#4
0
        /// <summary>
        /// Blits sprite to OpenGL display with specified parameters.
        /// </summary>
        public override void Draw(Vector2 currentPos, Vector2 origin, Color drawColour, Vector2 scaleVector, float rotation, Rectangle?srcRect, VertexBatch <TexturedVertex2d> spriteBatch = null)
        {
            // We should never run raw OGL calls on another thread than the main thread due to race conditions.
            Debug.Assert(GameBase.MainThread == Thread.CurrentThread);
            Debug.Assert(!isDisposed);

            if (!Bind())
            {
                return;
            }

            Rectangle drawRect = srcRect == null ? new Rectangle(0, 0, Width, Height) : srcRect.Value;

            float drawHeight = drawRect.Height * Math.Abs(scaleVector.Y);
            float drawWidth  = drawRect.Width * Math.Abs(scaleVector.X);

            Vector2 originVector = new Vector2(origin.X * drawWidth / drawRect.Width, origin.Y * drawHeight / drawRect.Height);

            Vector2 topLeft     = new Vector2(0, 0);
            Vector2 topRight    = new Vector2(drawWidth, 0);
            Vector2 bottomLeft  = new Vector2(0, drawHeight);
            Vector2 bottomRight = new Vector2(drawWidth, drawHeight);

            topLeft     -= originVector;
            topRight    -= originVector;
            bottomLeft  -= originVector;
            bottomRight -= originVector;

            if (rotation != 0)
            {
                float sin = (float)Math.Sin(rotation);
                float cos = (float)Math.Cos(rotation);

                RotateVector(ref topLeft, sin, cos);
                RotateVector(ref topRight, sin, cos);
                RotateVector(ref bottomLeft, sin, cos);
                RotateVector(ref bottomRight, sin, cos);
            }

            topLeft     += currentPos;
            topRight    += currentPos;
            bottomLeft  += currentPos;
            bottomRight += currentPos;

            RectangleF textureRect = new RectangleF(
                (float)drawRect.X / potWidth,
                (float)drawRect.Y / potHeight,
                (float)drawRect.Width / potWidth,
                (float)drawRect.Height / potHeight);

            // Vertical flip
            if (scaleVector.Y < 0)
            {
                textureRect.Y      = textureRect.Bottom;
                textureRect.Height = -textureRect.Height;
            }

            // Horizontal flip
            if (scaleVector.X < 0)
            {
                textureRect.X     = textureRect.Right;
                textureRect.Width = -textureRect.Width;
            }

            if (spriteBatch == null)
            {
                spriteBatch = TextureGlSingle.spriteBatch;
            }

            spriteBatch.Add(new TexturedVertex2d()
            {
                Position = bottomLeft, TexturePosition = new Vector2(textureRect.Left, textureRect.Bottom), Colour = drawColour
            });
            spriteBatch.Add(new TexturedVertex2d()
            {
                Position = bottomRight, TexturePosition = new Vector2(textureRect.Right, textureRect.Bottom), Colour = drawColour
            });
            spriteBatch.Add(new TexturedVertex2d()
            {
                Position = topRight, TexturePosition = new Vector2(textureRect.Right, textureRect.Top), Colour = drawColour
            });
            spriteBatch.Add(new TexturedVertex2d()
            {
                Position = topLeft, TexturePosition = new Vector2(textureRect.Left, textureRect.Top), Colour = drawColour
            });
        }