Ejemplo n.º 1
0
		public void VertexPositionColorTextured2D()
		{
			var vertex = new VertexPosition2DColorUV(Vector2D.Zero, Color.Red, Vector2D.One);
			Assert.AreEqual(vertex.Position, Vector2D.Zero);
			Assert.AreEqual(vertex.Color, Color.Red);
			Assert.AreEqual(vertex.UV, Vector2D.One);
		}
Ejemplo n.º 2
0
        public void VertexFormatShouldMatchCircularBufferShaderVertexFormat()
        {
            var vertices = new VertexPosition2DColorUV[4];

            Assert.Throws <CircularBuffer.ShaderVertexFormatDoesNotMatchVertex>(
                () => buffer2D.Add(image, vertices));
        }
Ejemplo n.º 3
0
        protected override void ResizeColorUVVertices(int newNumberOfVertices)
        {
            var newVerticesColorUV = new VertexPosition2DColorUV[newNumberOfVertices];

            Array.Copy(verticesColorUV, newVerticesColorUV, verticesColorUV.Length);
            verticesColorUV = newVerticesColorUV;
        }
Ejemplo n.º 4
0
        public void VertexPositionColorTextured2D()
        {
            var vertex = new VertexPosition2DColorUV(Vector2D.Zero, Color.Red, Vector2D.One);

            Assert.AreEqual(vertex.Position, Vector2D.Zero);
            Assert.AreEqual(vertex.Color, Color.Red);
            Assert.AreEqual(vertex.UV, Vector2D.One);
        }
Ejemplo n.º 5
0
 public void LerpPositionColorTextured2D()
 {
     var vertex = new VertexPosition2DColorUV(Vector2D.UnitX, Color.White, Vector2D.One);
     var vertex2 = new VertexPosition2DColorUV(Vector2D.UnitY, Color.Black, Vector2D.Zero);
     var lerpedVertex = vertex.Lerp(vertex2, 0.5f);
     Assert.AreEqual(lerpedVertex.Position, Vector2D.Half);
     Assert.AreEqual(lerpedVertex.Color, new Color(127, 127, 127));
     Assert.AreEqual(lerpedVertex.UV, Vector2D.One);
 }
Ejemplo n.º 6
0
        public void LerpPositionColorTextured2D()
        {
            var vertex       = new VertexPosition2DColorUV(Vector2D.UnitX, Color.White, Vector2D.One);
            var vertex2      = new VertexPosition2DColorUV(Vector2D.UnitY, Color.Black, Vector2D.Zero);
            var lerpedVertex = vertex.Lerp(vertex2, 0.5f);

            Assert.AreEqual(lerpedVertex.Position, Vector2D.Half);
            Assert.AreEqual(lerpedVertex.Color, new Color(127, 127, 127));
            Assert.AreEqual(lerpedVertex.UV, Vector2D.One);
        }
Ejemplo n.º 7
0
        private void AddVerticesRotated(Sprite sprite, Vector2D rotationCenter)
        {
            float sin = MathExtensions.Sin(rotation);
            float cos = MathExtensions.Cos(rotation);

            if (!hasUV)
            {
                var color = sprite.Color;
                verticesColor[verticesIndex++] = new VertexPosition2DColor(
                    ScreenSpace.Current.ToPixelSpaceRounded(
                        drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), color);
                verticesColor[verticesIndex++] = new VertexPosition2DColor(
                    ScreenSpace.Current.ToPixelSpaceRounded(
                        drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), color);
                verticesColor[verticesIndex++] = new VertexPosition2DColor(
                    ScreenSpace.Current.ToPixelSpaceRounded(
                        drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), color);
                verticesColor[verticesIndex++] = new VertexPosition2DColor(
                    ScreenSpace.Current.ToPixelSpaceRounded(
                        drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), color);
            }
            else if (hasColor)
            {
                var color = sprite.Color;
                verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
                    ScreenSpace.Current.ToPixelSpaceRounded(
                        drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), color, uv.TopLeft);
                verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
                    ScreenSpace.Current.ToPixelSpaceRounded(
                        drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), color, uv.BottomLeft);
                verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
                    ScreenSpace.Current.ToPixelSpaceRounded(
                        drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), color, uv.BottomRight);
                verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
                    ScreenSpace.Current.ToPixelSpaceRounded(
                        drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), color, uv.TopRight);
            }
            else
            {
                verticesUV[verticesIndex++] = new VertexPosition2DUV(
                    screen.ToPixelSpaceRounded(drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)),
                    uv.TopLeft);
                verticesUV[verticesIndex++] = new VertexPosition2DUV(
                    screen.ToPixelSpaceRounded(drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)),
                    uv.BottomLeft);
                verticesUV[verticesIndex++] = new VertexPosition2DUV(
                    screen.ToPixelSpaceRounded(drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)),
                    uv.BottomRight);
                verticesUV[verticesIndex++] = new VertexPosition2DUV(
                    screen.ToPixelSpaceRounded(drawArea.TopRight.RotateAround(rotationCenter, sin, cos)),
                    uv.TopRight);
            }
        }
Ejemplo n.º 8
0
		public Batch2D(Material material, BlendMode blendMode, 
			int minimumNumberOfQuads = MinNumberOfQuads)
		{
			Material = material;
			BlendMode = blendMode;
			minimumNumberOfQuads = MathExtensions.Max(minimumNumberOfQuads, MinNumberOfQuads);
			hasUV = ((material.Shader.Flags & ShaderFlags.Textured) != 0);
			hasColor = ((material.Shader.Flags & ShaderFlags.Colored) != 0);
			indices = new short[minimumNumberOfQuads * IndicesPerQuad];
			if (!hasUV)
				verticesColor = new VertexPosition2DColor[minimumNumberOfQuads * VerticesPerQuad];
			else if (hasColor)
				verticesColorUV = new VertexPosition2DColorUV[minimumNumberOfQuads * VerticesPerQuad];
			else
				verticesUV = new VertexPosition2DUV[minimumNumberOfQuads * VerticesPerQuad];
		}
Ejemplo n.º 9
0
 public Batch2D(Material material, BlendMode blendMode,
                int minimumNumberOfQuads = MinNumberOfQuads)
 {
     Material             = material;
     BlendMode            = blendMode;
     minimumNumberOfQuads = MathExtensions.Max(minimumNumberOfQuads, MinNumberOfQuads);
     hasUV    = ((material.Shader.Flags & ShaderFlags.Textured) != 0);
     hasColor = ((material.Shader.Flags & ShaderFlags.Colored) != 0);
     indices  = new short[minimumNumberOfQuads * IndicesPerQuad];
     if (!hasUV)
     {
         verticesColor = new VertexPosition2DColor[minimumNumberOfQuads * VerticesPerQuad];
     }
     else if (hasColor)
     {
         verticesColorUV = new VertexPosition2DColorUV[minimumNumberOfQuads * VerticesPerQuad];
     }
     else
     {
         verticesUV = new VertexPosition2DUV[minimumNumberOfQuads * VerticesPerQuad];
     }
 }
Ejemplo n.º 10
0
        }         //ncrunch: no coverage end

        private void AddVerticesNotRotated(Sprite sprite)
        {
            if (!hasUV)
            {
                var color = sprite.Color;
                verticesColor[verticesIndex++] = new VertexPosition2DColor(
                    ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopLeft), color);
                verticesColor[verticesIndex++] = new VertexPosition2DColor(
                    ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomLeft), color);
                verticesColor[verticesIndex++] = new VertexPosition2DColor(
                    ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomRight), color);
                verticesColor[verticesIndex++] = new VertexPosition2DColor(
                    ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopRight), color);
            }
            else if (hasColor)
            {
                var color = sprite.Color;
                verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
                    ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopLeft), color, uv.TopLeft);
                verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
                    ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomLeft), color, uv.BottomLeft);
                verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
                    ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomRight), color, uv.BottomRight);
                verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
                    ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopRight), color, uv.TopRight);
            }
            else
            {
                verticesUV[verticesIndex++] =
                    new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.TopLeft), uv.TopLeft);
                verticesUV[verticesIndex++] =
                    new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.BottomLeft), uv.BottomLeft);
                verticesUV[verticesIndex++] =
                    new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.BottomRight), uv.BottomRight);
                verticesUV[verticesIndex++] =
                    new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.TopRight), uv.TopRight);
            }
        }
Ejemplo n.º 11
0
 public void VertexFormatShouldMatchCircularBufferShaderVertexFormat()
 {
     var vertices = new VertexPosition2DColorUV[4];
     Assert.Throws<CircularBuffer.ShaderVertexFormatDoesNotMatchVertex>(
         () => buffer2D.Add(image, vertices));
 }
Ejemplo n.º 12
0
		//ncrunch: no coverage start
		private void AddVerticesAtlasRotated(Sprite sprite)
		{
			if (!hasUV)
			{
				var color = sprite.Color;
				verticesColor[verticesIndex++] = new VertexPosition2DColor(
					ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopLeft), color);
				verticesColor[verticesIndex++] = new VertexPosition2DColor(
					ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomLeft), color);
				verticesColor[verticesIndex++] = new VertexPosition2DColor(
						ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomRight), color);
				verticesColor[verticesIndex++] = new VertexPosition2DColor(
					ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopRight), color);
			}
			else if (hasColor)
			{
				var color = sprite.Color;
				verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
					ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopLeft), color, uv.TopLeft);
				verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
					ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomLeft), color, uv.BottomLeft);
				verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
					ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomRight), color, uv.BottomRight);
				verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
					ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopRight), color, uv.TopRight);
			}
			else
			{
				verticesUV[verticesIndex++] =
					new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.TopLeft), uv.TopLeft);
				verticesUV[verticesIndex++] =
					new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.BottomLeft), uv.BottomLeft);
				verticesUV[verticesIndex++] =
					new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.BottomRight), uv.BottomRight);
				verticesUV[verticesIndex++] =
					new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.TopRight), uv.TopRight);
			}
		}
Ejemplo n.º 13
0
		protected override void ResizeColorUVVertices(int newNumberOfVertices)
		{
			var newVerticesColorUV = new VertexPosition2DColorUV[newNumberOfVertices];
			Array.Copy(verticesColorUV, newVerticesColorUV, verticesColorUV.Length);
			verticesColorUV = newVerticesColorUV;
		}
Ejemplo n.º 14
0
		private void AddVerticesRotated(Sprite sprite, Vector2D rotationCenter)
		{
			float sin = MathExtensions.Sin(rotation);
			float cos = MathExtensions.Cos(rotation);
			if (!hasUV)
			{
				var color = sprite.Color;
				verticesColor[verticesIndex++] = new VertexPosition2DColor(
					ScreenSpace.Current.ToPixelSpaceRounded(
					drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), color);
				verticesColor[verticesIndex++] = new VertexPosition2DColor(
					ScreenSpace.Current.ToPixelSpaceRounded(
					drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), color);
				verticesColor[verticesIndex++] = new VertexPosition2DColor(
						ScreenSpace.Current.ToPixelSpaceRounded(
						drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), color);
				verticesColor[verticesIndex++] = new VertexPosition2DColor(
					ScreenSpace.Current.ToPixelSpaceRounded(
					drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), color);
			}
			else if (hasColor)
			{
				var color = sprite.Color;
				verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
					ScreenSpace.Current.ToPixelSpaceRounded(
					drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), color, uv.TopLeft);
				verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
					ScreenSpace.Current.ToPixelSpaceRounded(
					drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), color, uv.BottomLeft);
				verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
					ScreenSpace.Current.ToPixelSpaceRounded(
					drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), color, uv.BottomRight);
				verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV(
					ScreenSpace.Current.ToPixelSpaceRounded(
					drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), color, uv.TopRight);
			}
			else
			{
				verticesUV[verticesIndex++] = new VertexPosition2DUV(
					screen.ToPixelSpaceRounded(drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)),
					uv.TopLeft);
				verticesUV[verticesIndex++] = new VertexPosition2DUV(
					screen.ToPixelSpaceRounded(drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)),
					uv.BottomLeft);
				verticesUV[verticesIndex++] = new VertexPosition2DUV(
					screen.ToPixelSpaceRounded(drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)),
					uv.BottomRight);
				verticesUV[verticesIndex++] = new VertexPosition2DUV(
					screen.ToPixelSpaceRounded(drawArea.TopRight.RotateAround(rotationCenter, sin, cos)),
					uv.TopRight);
			}
		}