public static void DrawBorder(VertexBatch vertexBatch, Vector2 position, Vector2 size) { //if (vertexBatch.primitiveType == PrimitiveType.TriangleList) vertexBatch.Draw(new Vertex[] { new Vertex(position), new Vertex(position + size.X_Vector()), new Vertex(position + size.Y_Vector()), new Vertex(position + size) }, 0, 1, 2, 1, 2, 3); //if (vertexBatch.primitiveType == PrimitiveType.TriangleStrip) vertexBatch.Draw(new Vertex[] { new Vertex(position), new Vertex(position + size.X_Vector()), new Vertex(position + size.Y_Vector()), new Vertex(position + size) }, 0, 1, 2, 3); //if (vertexBatch.primitiveType == PrimitiveType.LineList) vertexBatch.Draw(new Vertex[] { new Vertex(position), new Vertex(position + size.X_Vector()), new Vertex(position + size.Y_Vector()), new Vertex(position + size) }, 0, 1, 1, 3, 3, 2, 2, 0); //if (vertexBatch.primitiveType == PrimitiveType.LineStrip) vertexBatch.Draw(new Vertex[] { new Vertex(position), new Vertex(position + size.X_Vector()), new Vertex(position + size.Y_Vector()), new Vertex(position + size) }, 0, 1, 3, 2, 0); }
[Test] public void VertexAccess() { VertexBatch <VertexC1P3> typedBatch = new VertexBatch <VertexC1P3>(); IVertexBatch abstractBatch = typedBatch; typedBatch.Vertices.Add(new VertexC1P3 { Color = new ColorRgba(0) }); typedBatch.Vertices.Add(new VertexC1P3 { Color = new ColorRgba(1) }); typedBatch.Vertices.Add(new VertexC1P3 { Color = new ColorRgba(2) }); typedBatch.Vertices.Add(new VertexC1P3 { Color = new ColorRgba(3) }); Assert.AreEqual(4, typedBatch.Count); Assert.AreEqual(4, typedBatch.Vertices.Count); Assert.AreEqual(new ColorRgba(0), typedBatch.Vertices[0].Color); Assert.AreEqual(new ColorRgba(1), typedBatch.Vertices[1].Color); Assert.AreEqual(new ColorRgba(2), typedBatch.Vertices[2].Color); Assert.AreEqual(new ColorRgba(3), typedBatch.Vertices[3].Color); Assert.AreEqual(4, abstractBatch.Count); typedBatch.Clear(); Assert.AreEqual(0, typedBatch.Count); Assert.AreEqual(0, typedBatch.Vertices.Count); Assert.AreEqual(0, abstractBatch.Count); }
/// <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 }); }
[Test] public void EmptyArray() { VertexBatch <VertexC1P3> typedBatch = new VertexBatch <VertexC1P3>(); IVertexBatch abstractBatch = typedBatch; Assert.AreEqual(0, typedBatch.Count); Assert.AreEqual(VertexDeclaration.Get <VertexC1P3>(), typedBatch.Declaration); Assert.IsNotNull(typedBatch.Vertices); Assert.AreEqual(0, typedBatch.Vertices.Count); Assert.AreEqual(0, abstractBatch.Count); Assert.AreEqual(VertexDeclaration.Get <VertexC1P3>(), abstractBatch.Declaration); }
public VertexBatch Duplicate() { VertexBatch vb = new VertexBatch(); vb.vertices = new Vector3[vertices.Length]; vb.colors = new Color[colors.Length]; vb.uvs = new Vector2[uvs.Length]; System.Array.Copy(vertices, vb.vertices, vertices.Length); System.Array.Copy(colors, vb.colors, colors.Length); System.Array.Copy(uvs, vb.uvs, uvs.Length); return(vb); }
public VertexBatch Duplicate() { VertexBatch vb = new VertexBatch (); vb.vertices = new Vector3[vertices.Length]; vb.colors = new Color[colors.Length]; vb.uvs = new Vector2[uvs.Length]; System.Array.Copy ( vertices, vb.vertices, vertices.Length ); System.Array.Copy ( colors, vb.colors, colors.Length ); System.Array.Copy ( uvs, vb.uvs, uvs.Length ); return vb; }
[Test] public void Locking() { VertexBatch <VertexC1P3> typedBatch = new VertexBatch <VertexC1P3>(); IVertexBatch abstractBatch = typedBatch; typedBatch.Vertices.Add(new VertexC1P3 { Color = new ColorRgba(0) }); typedBatch.Vertices.Add(new VertexC1P3 { Color = new ColorRgba(1) }); typedBatch.Vertices.Add(new VertexC1P3 { Color = new ColorRgba(2) }); typedBatch.Vertices.Add(new VertexC1P3 { Color = new ColorRgba(3) }); // Assert that we can retrieve all data via unmanaged pointer access VertexDeclaration layout = typedBatch.Declaration; int vertexSize = layout.Size; int colorElementIndex = layout.Elements.IndexOfFirst(item => item.FieldName == VertexDeclaration.ShaderFieldPrefix + "Color"); int colorOffset = (int)layout.Elements[colorElementIndex].Offset; using (PinnedArrayHandle locked = typedBatch.Lock()) { Assert.AreEqual(new ColorRgba(0), ReadColor(locked.Address, vertexSize * 0 + colorOffset)); Assert.AreEqual(new ColorRgba(1), ReadColor(locked.Address, vertexSize * 1 + colorOffset)); Assert.AreEqual(new ColorRgba(2), ReadColor(locked.Address, vertexSize * 2 + colorOffset)); Assert.AreEqual(new ColorRgba(3), ReadColor(locked.Address, vertexSize * 3 + colorOffset)); } using (PinnedArrayHandle locked = abstractBatch.Lock()) { Assert.AreEqual(new ColorRgba(0), ReadColor(locked.Address, vertexSize * 0 + colorOffset)); Assert.AreEqual(new ColorRgba(1), ReadColor(locked.Address, vertexSize * 1 + colorOffset)); Assert.AreEqual(new ColorRgba(2), ReadColor(locked.Address, vertexSize * 2 + colorOffset)); Assert.AreEqual(new ColorRgba(3), ReadColor(locked.Address, vertexSize * 3 + colorOffset)); } // Make sure that our locks released properly, i.e. allowing the array to be garbage collected WeakReference weakRefToLockedData = new WeakReference(typedBatch.Vertices.Data); Assert.IsTrue(weakRefToLockedData.IsAlive); typedBatch = null; abstractBatch = null; GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true); GC.WaitForPendingFinalizers(); Assert.IsFalse(weakRefToLockedData.IsAlive); }
/// <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); }
protected override void Initialize() { Common.Initialize(this); Window.AllowUserResizing = true; bullets = new List <Bullet>(); graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; graphics.ApplyChanges(); a = new FlareFxAlt(graphicsDevice, 40, 40, "Test2"); MeteorBullet.flarefx = new FlareFx(graphicsDevice, 40, 40, "Test"); MeteorBullet.flarefxAlt = a as FlareFxAlt; mousePos = new Vector2[15]; text = new DynamicTextureText(graphicsDevice, new System.Drawing.Font("华文中宋", 50), "Stellaris"); vertexBatch = new VertexBatch(graphicsDevice); swordFx = new SwordFx(GraphicsDevice, 1); u = new UIBase(); base.Initialize(); }
public VertexBatchTest(Layer layer) : base(layer) { _monofoxeSprite = ResourceHub.GetResource <Sprite>("DefaultSprites", "AutismCat"); _vbatch = new VertexBatch( GraphicsMgr.Device, null, SamplerState.PointWrap, null, null ); _triangleListVertices = new VertexPositionColorTexture[5]; _triangleListVertices[0] = new VertexPositionColorTexture(new Vector3(100, 100, 0), Color.White, new Vector2(0, 0)); _triangleListVertices[1] = new VertexPositionColorTexture(new Vector3(100 + 32, 100, 0), Color.Red, new Vector2(1, 0)); _triangleListVertices[2] = new VertexPositionColorTexture(new Vector3(100 + 32, 100 + 32, 0), Color.White, new Vector2(1, 1)); _triangleListVertices[3] = new VertexPositionColorTexture(new Vector3(100 + 32, 100 + 64, 0), Color.White, Vector2.Zero); _triangleListVertices[4] = new VertexPositionColorTexture(new Vector3(100 - 32, 100 + 64, 0), Color.White, Vector2.Zero); _triangleListIndices = new short[] { 0, 1, 2, 0, 2, 3, 0, 3, 4, }; _lineListVertices = new VertexPositionColorTexture[5]; _lineListVertices[0] = new VertexPositionColorTexture(new Vector3(10, 10, 0), Color.White, new Vector2(0, 0)); _lineListVertices[1] = new VertexPositionColorTexture(new Vector3(10 + 32, 10, 0), Color.Red, new Vector2(1, 0)); _lineListVertices[2] = new VertexPositionColorTexture(new Vector3(00 + 32, 10 + 32, 0), Color.White, new Vector2(1, 1)); _lineListVertices[3] = new VertexPositionColorTexture(new Vector3(00 + 32, 10 + 64, 0), Color.White, Vector2.Zero); _lineListIndices = new short[] { 0, 1, 1, 2, 2, 3, 3, 0 }; }
public void DrawBorder(VertexBatch vertexBatch) { Vector2 size = Size; if (vertexBatch.primitiveType == PrimitiveType.TriangleList) { vertexBatch.Draw(new Vertex[] { new Vertex(postion), new Vertex(postion + size.X_Vector()), new Vertex(postion + size.Y_Vector()), new Vertex(postion + size) }, 0, 1, 2, 1, 2, 3); } if (vertexBatch.primitiveType == PrimitiveType.TriangleStrip) { vertexBatch.Draw(new Vertex[] { new Vertex(postion), new Vertex(postion + size.X_Vector()), new Vertex(postion + size.Y_Vector()), new Vertex(postion + size) }, 0, 1, 2, 3); } if (vertexBatch.primitiveType == PrimitiveType.LineList) { vertexBatch.Draw(new Vertex[] { new Vertex(postion), new Vertex(postion + size.X_Vector()), new Vertex(postion + size.Y_Vector()), new Vertex(postion + size) }, 0, 1, 1, 3, 3, 2, 2, 0); } if (vertexBatch.primitiveType == PrimitiveType.LineStrip) { vertexBatch.Draw(new Vertex[] { new Vertex(postion), new Vertex(postion + size.X_Vector()), new Vertex(postion + size.Y_Vector()), new Vertex(postion + size) }, 0, 1, 3, 2, 0); } }
protected override void Initialize() { Common.Initialize(this); Window.AllowUserResizing = true; bullets = new List <Bullet>(); graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; graphics.ApplyChanges(); a = new FlareFxAlt(graphicsDevice, 40, 40, "Test2"); MeteorBullet.flarefx = new FlareFx(graphicsDevice, 40, 40, "Test"); MeteorBullet.flarefxAlt = a as FlareFxAlt; mousePos = new Vector2[15]; vertexBatch = new VertexBatch(graphicsDevice); swordFx = new SwordFx(GraphicsDevice, 1); u = new UIBase(); text = new DynamicTextureTextGDI(graphicsDevice, Environment.CurrentDirectory + Path.DirectorySeparatorChar + "SourceHanSansCN-Regular.ttf", 40, "***ABCD文字绘制测试\nStellaris\n增益免疫汉化组"); dtt = new DynamicTextureFont(graphicsDevice, Environment.CurrentDirectory + Path.DirectorySeparatorChar + "SourceHanSansCN-Regular.ttf", 80); tex = Texture2D.FromStream(graphicsDevice, File.OpenRead(Environment.CurrentDirectory + @"\Extra_197.png")); tex2 = Texture2D.FromStream(graphicsDevice, File.OpenRead(Environment.CurrentDirectory + @"\Extra_194.png")); tt = new TestTex(graphicsDevice, 70, 70); base.Initialize(); }
protected override void Initialize() { Ste.Initialize(this, graphics); Window.AllowUserResizing = true; bullets = new List <Bullet>(); Ste.ChangeResolution(1920, 1080); a = new FlareFxAlt(graphicsDevice, 40, 40, "Test2"); MeteorBullet.flarefx = new FlareFx(graphicsDevice, 40, 40, "Test"); MeteorBullet.flarefxAlt = a as FlareFxAlt; mousePos = new Vector2[15]; vertexBatch = new VertexBatch(graphicsDevice); //var n = new FontStb_Native(Ste.GetAsset("SourceHanSansCN-Regular.ttf"), graphicsDevice); //text = new DynamicTextureTextGDI(graphicsDevice, Environment.CurrentDirectory + Path.DirectorySeparatorChar + "SourceHanSansCN-Regular.ttf", 40, "***ABCD文字绘制测试\nStellaris\n增益免疫汉化组"); dtt = new DynamicSpriteFont(graphicsDevice, Ste.GetAsset("SourceHanSansCN-Regular.ttf"), 80, useNative: false); var font = new FontStb_Native(Ste.GetAsset("Product-Sans-Regular.ttf")); font.ReverseFont = dtt.font; dtt2 = new DynamicSpriteFont(graphicsDevice, font, 80); tex3 = Texture2D.FromStream(graphicsDevice, Ste.GetAsset("trail3.png")); tex = Texture2D.FromStream(graphicsDevice, Ste.GetAsset("zzzz.png")); tex2 = Texture2D.FromStream(graphicsDevice, Ste.GetAsset("trail3.png")); z = new Effect(graphicsDevice, Ste.GetAsset("Blur.cfx").ToByteArray()); base.Initialize(); }
public void Draw(Quad vertexQuad, Color4 colour, RectangleF?textureRect = null, VertexBatch <TexturedVertex2d> spriteBatch = null) { RectangleF texRect = textureRect ?? new RectangleF(0, 0, DisplayWidth, DisplayHeight); if (DpiScale != 1) { texRect.Width *= DpiScale; texRect.Height *= DpiScale; texRect.X *= DpiScale; texRect.Y *= DpiScale; } TextureGL?.Draw(vertexQuad, texRect, colour, spriteBatch); }
/// <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) { Debug.Assert(!isDisposed); Upload(); Rectangle actualBounds = bounds; if (srcRect.HasValue) { Rectangle localBounds = srcRect.Value; actualBounds.X += localBounds.X; actualBounds.Y += localBounds.Y; actualBounds.Width = Math.Min(localBounds.Width, bounds.Width); actualBounds.Height = Math.Min(localBounds.Height, bounds.Height); } parent.Draw(currentPos, origin, drawColour, scaleVector, rotation, actualBounds, spriteBatch); }
public void Draw(Quad vertexQuad, Color4 colour, RectangleF?textureRect = null, VertexBatch <TexturedVertex2D> spriteBatch = null, Vector2?inflationPercentage = null) { if (TextureGL == null || !TextureGL.Bind()) { return; } TextureGL.Draw(vertexQuad, textureBounds(textureRect), colour, spriteBatch, inflationPercentage); }
/// <summary> /// Blits sprite to OpenGL display with specified parameters. /// </summary> public abstract void Draw(Quad vertexQuad, RectangleF?textureRect, Color4 drawColour, VertexBatch <TexturedVertex2D> spriteBatch = null, Vector2?inflationPercentage = null);
/// <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 }); }
public static void Initialize() { spriteBatch = new QuadBatch <TexturedVertex2d>(1, 100); }
public void DrawBorder(VertexBatch vertexBatch) { DrawBorder(vertexBatch); }
[Test] public void RentAndClear() { VertexBatchStore memory = new VertexBatchStore(); // Repeatedly rent slices of varying types from memory { VertexSlice <VertexC1P3> slice = memory.Rent <VertexC1P3>(4); slice[0] = new VertexC1P3 { Color = new ColorRgba(0) }; slice[1] = new VertexC1P3 { Color = new ColorRgba(1) }; slice[2] = new VertexC1P3 { Color = new ColorRgba(2) }; slice[3] = new VertexC1P3 { Color = new ColorRgba(3) }; } { VertexSlice <VertexC1P3T2> slice = memory.Rent <VertexC1P3T2>(3); slice[0] = new VertexC1P3T2 { Color = new ColorRgba(4) }; slice[1] = new VertexC1P3T2 { Color = new ColorRgba(5) }; slice[2] = new VertexC1P3T2 { Color = new ColorRgba(6) }; } { VertexSlice <VertexC1P3> slice = memory.Rent <VertexC1P3>(2); slice[0] = new VertexC1P3 { Color = new ColorRgba(7) }; slice[1] = new VertexC1P3 { Color = new ColorRgba(8) }; } { VertexSlice <VertexC1P3> slice = memory.Rent <VertexC1P3>(1); slice[0] = new VertexC1P3 { Color = new ColorRgba(9) }; } // Assert correct storage property values Assert.AreEqual( 1 + Math.Max( VertexDeclaration.Get <VertexC1P3>().TypeIndex, VertexDeclaration.Get <VertexC1P3T2>().TypeIndex), memory.TypeIndexCount); Assert.AreEqual(1, memory.GetBatchCount <VertexC1P3>()); Assert.AreEqual(1, memory.GetBatchCount <VertexC1P3T2>()); // Retrieve specific internal vertex arrays VertexBatch <VertexC1P3> batchA = memory.GetBatch <VertexC1P3>(0); VertexBatch <VertexC1P3T2> batchB = memory.GetBatch <VertexC1P3T2>(0); RawList <VertexC1P3> verticesA = batchA.Vertices; RawList <VertexC1P3T2> verticesB = batchB.Vertices; // Assert that they contain all the data we submitted in the correct order Assert.AreEqual(7, batchA.Count); Assert.AreEqual(3, batchB.Count); Assert.AreEqual(7, verticesA.Count); Assert.AreEqual(3, verticesB.Count); Assert.AreEqual(new ColorRgba(0), verticesA[0].Color); Assert.AreEqual(new ColorRgba(1), verticesA[1].Color); Assert.AreEqual(new ColorRgba(2), verticesA[2].Color); Assert.AreEqual(new ColorRgba(3), verticesA[3].Color); Assert.AreEqual(new ColorRgba(4), verticesB[0].Color); Assert.AreEqual(new ColorRgba(5), verticesB[1].Color); Assert.AreEqual(new ColorRgba(6), verticesB[2].Color); Assert.AreEqual(new ColorRgba(7), verticesA[4].Color); Assert.AreEqual(new ColorRgba(8), verticesA[5].Color); Assert.AreEqual(new ColorRgba(9), verticesA[6].Color); // Clear all vertices memory.Clear(); // Assert correct storage property values Assert.AreEqual(0, memory.TypeIndexCount); Assert.AreEqual(0, memory.GetBatchCount <VertexC1P3>()); Assert.AreEqual(0, memory.GetBatchCount <VertexC1P3T2>()); // Assert that the vertices are gone, but capacity isn't Assert.AreEqual(0, batchA.Count); Assert.AreEqual(0, batchB.Count); Assert.AreEqual(0, verticesA.Count); Assert.AreEqual(0, verticesB.Count); Assert.GreaterOrEqual(verticesA.Capacity, 7); Assert.GreaterOrEqual(verticesB.Capacity, 3); }
public void Set(QuadBatch qb) { vertexBatch = qb.vertexBatch.Duplicate(); }
/// <summary> /// Blits sprite to OpenGL display with specified parameters. /// </summary> public abstract void Draw(Vector2 currentPos, Vector2 origin, Color drawColour, Vector2 scaleVector, float rotation, Rectangle?srcRect, VertexBatch <TexturedVertex2d> spriteBatch = null);
public bool CheckReadMesh(BinaryReader dStream, BinaryReader gStream, int sName, int dOffset) { var strName = IO.ReadStringFrom(dStream, DataOffset + sName); Debug.WriteLine(string.Format("\tShader Name: {0}", strName)); if (!strName.StartsWith("shader", StringComparison.CurrentCulture)) { return(false); } //Debug.WriteLine(string.Format("Reading RenderGraph subMesh at 0x{0:X}.", dOffset)); long oldPos = dStream.BaseStream.Position; dStream.BaseStream.Seek(DataOffset + dOffset + 0x14, SeekOrigin.Begin); int tsDOffset = IO.ReadBig32(dStream); IO.ReadBig32(dStream); int vDOffset = IO.ReadBig32(dStream); dStream.BaseStream.Seek(DataOffset + dOffset + 0x50, SeekOrigin.Begin); int tsBatchCount = IO.ReadBig32(dStream); //first of all, check to make sure we haven't read this vertex batch first... //Debug.WriteLine(string.Format("Reading VertexBatch at 0x{0:X}...", vDOffset)); if (!VertexBatchMap.ContainsKey(vDOffset)) { //Hacky, but it works for now. if (vDOffset > (int)dStream.BaseStream.Length) { return(false); } dStream.BaseStream.Seek(DataOffset + vDOffset + 0x30, SeekOrigin.Begin); int vDOffset2 = IO.ReadBig32(dStream); dStream.BaseStream.Seek(DataOffset + vDOffset2, SeekOrigin.Begin); var tmpBatch = new VertexBatch(); tmpBatch.VDataOffset = vDOffset2; int tmpStride = IO.ReadBig32(dStream); IO.ReadBig32(dStream); IO.ReadBig32(dStream); int tmpGPUOffset = IO.ReadBig32(dStream); int tmpGPUBlockSize = IO.ReadBig32(dStream); string tmpVType = IO.ReadString(dStream); tmpBatch.VGPUOffset = tmpGPUOffset; gStream.BaseStream.Seek(GPUOffset + tmpGPUOffset, SeekOrigin.Begin); tmpBatch.Read(gStream, tmpStride, tmpGPUBlockSize, VertexBatches.Count); tmpBatch.VType = tmpVType; VertexBatches.Add(tmpBatch); VertexBatchMap[vDOffset] = VertexBatches.Count - 1; } //Now, read TriangleStrip Data... int vBatchID = VertexBatchMap[vDOffset]; /* * int nextBatchOffset = tsDOffset; * //for(int i = 0; i < tsBatchCount; i++) * while(nextBatchOffset != 0) * { * dStream.BaseStream.Seek(DataOffset + nextBatchOffset, SeekOrigin.Begin); * * int stallCheck = 0; * while(true) * { * int tmpCheck = IO.ReadBig32(dStream); * if(tmpCheck == tsDOffset) break; * if(stallCheck > 0x80) * { * Logger.LogError(string.Format("Stalled looking for TriangleStrip descriptor at 0x{0:X}\n", tsDOffset)); * return true; * } * stallCheck += 1; * nextBatchOffset = tmpCheck; * } * * dStream.BaseStream.Seek(0x1c, SeekOrigin.Current); * int gpuOffsetOffset = IO.ReadBig32(dStream); * IO.ReadBig32(dStream); * int gpuCountOffset = IO.ReadBig32(dStream); * int indexSize = IO.ReadBig16(dStream); * * dStream.BaseStream.Seek(DataOffset + gpuCountOffset, SeekOrigin.Begin); * int tsCount = IO.ReadBig32(dStream); * dStream.BaseStream.Seek(DataOffset + gpuOffsetOffset, SeekOrigin.Begin); * int tsOffset = IO.ReadBig32(dStream); * bool fullIndex = (indexSize == 1); * * var tmpTBatch = new TriStripBatch(); * gStream.BaseStream.Seek(GPUOffset + tsOffset, SeekOrigin.Begin); * tmpTBatch.Read(tsCount, vBatchID, gStream, fullIndex); * * dStream.BaseStream.Seek(DataOffset + sName, SeekOrigin.Begin); * * string tmpMaterialName = IO.ReadString(dStream); * TriStripBatches.Add(tmpTBatch); * * if(!MaterialMap.ContainsKey(tmpMaterialName)) * { * var tmpMaterial = new KameoMaterial(tmpMaterialName); * MaterialList.Add(tmpMaterial); * MaterialMap[tmpMaterialName] = MaterialList.Count - 1; * tmpTBatch.MaterialID = MaterialList.Count - 1; * } * else * { * int materialID = MaterialMap[tmpMaterialName]; * tmpTBatch.MaterialID = materialID; * } * } */ while (true) { int nextTSDescriptorOffset = ReadTriangleStripBatch(dStream, gStream, tsDOffset, vBatchID, sName); if (nextTSDescriptorOffset == 0) { break; } tsDOffset = nextTSDescriptorOffset; } dStream.BaseStream.Seek(oldPos, SeekOrigin.Begin); return(true); }
/// <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) { parent.Draw(vertexQuad, BoundsInParent(textureRect), drawColour, spriteBatch, inflationPercentage); }
[Test] public void MaxBatchSize() { VertexBatchStore memory = new VertexBatchStore(4); // Rent a few memory slices, but stay below the max batch size { VertexSlice <VertexC1P3> slice = memory.Rent <VertexC1P3>(2); slice[0] = new VertexC1P3 { Color = new ColorRgba(0) }; slice[1] = new VertexC1P3 { Color = new ColorRgba(1) }; } { VertexSlice <VertexC1P3> slice = memory.Rent <VertexC1P3>(1); slice[0] = new VertexC1P3 { Color = new ColorRgba(2) }; } // Assert that we only have one batch, with the correct contents Assert.AreEqual(1, memory.GetBatchCount <VertexC1P3>()); Assert.AreEqual(0, memory.GetBatchCount <VertexC1P3T2>()); VertexBatch <VertexC1P3> batchA = memory.GetBatch <VertexC1P3>(0); RawList <VertexC1P3> verticesA = batchA.Vertices; Assert.AreEqual(3, batchA.Count); Assert.AreEqual(new ColorRgba(0), verticesA[0].Color); Assert.AreEqual(new ColorRgba(1), verticesA[1].Color); Assert.AreEqual(new ColorRgba(2), verticesA[2].Color); // Rent a few more slices, this time exceeding max batch size { VertexSlice <VertexC1P3> slice = memory.Rent <VertexC1P3>(2); slice[0] = new VertexC1P3 { Color = new ColorRgba(3) }; slice[1] = new VertexC1P3 { Color = new ColorRgba(4) }; } { VertexSlice <VertexC1P3> slice = memory.Rent <VertexC1P3>(2); slice[0] = new VertexC1P3 { Color = new ColorRgba(5) }; slice[1] = new VertexC1P3 { Color = new ColorRgba(6) }; } // Assert that we now have two batches, each with the correct contents Assert.AreEqual(2, memory.GetBatchCount <VertexC1P3>()); Assert.AreEqual(0, memory.GetBatchCount <VertexC1P3T2>()); VertexBatch <VertexC1P3> batchB = memory.GetBatch <VertexC1P3>(1); RawList <VertexC1P3> verticesB = batchB.Vertices; Assert.AreEqual(3, batchA.Count); Assert.AreEqual(new ColorRgba(0), verticesA[0].Color); Assert.AreEqual(new ColorRgba(1), verticesA[1].Color); Assert.AreEqual(new ColorRgba(2), verticesA[2].Color); Assert.AreEqual(4, batchB.Count); Assert.AreEqual(new ColorRgba(3), verticesB[0].Color); Assert.AreEqual(new ColorRgba(4), verticesB[1].Color); Assert.AreEqual(new ColorRgba(5), verticesB[2].Color); Assert.AreEqual(new ColorRgba(6), verticesB[3].Color); // Clear all vertices memory.Clear(); // Assert that the vertices are gone, but capacity isn't Assert.AreEqual(0, memory.GetBatchCount <VertexC1P3>()); Assert.AreEqual(0, memory.GetBatchCount <VertexC1P3T2>()); Assert.AreEqual(0, batchA.Count); Assert.AreEqual(0, batchB.Count); Assert.AreEqual(0, verticesA.Count); Assert.AreEqual(0, verticesB.Count); Assert.GreaterOrEqual(verticesA.Capacity, 3); Assert.GreaterOrEqual(verticesB.Capacity, 4); // Rent some vertices again memory.Rent <VertexC1P3>(3); memory.Rent <VertexC1P3>(4); // Assert that the same storage is re-used Assert.AreEqual(2, memory.GetBatchCount <VertexC1P3>()); Assert.AreEqual(0, memory.GetBatchCount <VertexC1P3T2>()); Assert.AreEqual(3, batchA.Count); Assert.AreEqual(4, batchB.Count); Assert.AreEqual(3, verticesA.Count); Assert.AreEqual(4, verticesB.Count); // Assert that we're getting an exception when attempting to rent a slice that is too large Assert.Throws <ArgumentException>(() => memory.Rent <VertexC1P3>(5)); }
public QuadBatch() { vertexBatch = new VertexBatch(); }
public QuadBatch(VertexBatch vb) { vertexBatch = vb; }
/// <summary> /// Blits sprite to OpenGL display with specified parameters. /// </summary> public override void Draw(Quad vertexQuad, RectangleF?textureRect, Color4 drawColour, VertexBatch <TexturedVertex2d> spriteBatch = null) { RectangleF actualBounds = bounds; if (textureRect.HasValue) { RectangleF localBounds = textureRect.Value; actualBounds.X += localBounds.X; actualBounds.Y += localBounds.Y; actualBounds.Width = Math.Min(localBounds.Width, bounds.Width); actualBounds.Height = Math.Min(localBounds.Height, bounds.Height); } parent.Draw(vertexQuad, actualBounds, drawColour, spriteBatch); }
/// <summary> /// Blits sprite to OpenGL display with specified parameters. /// </summary> public abstract void Draw(Quad vertexQuad, RectangleF?textureRect, Color4 drawColour, VertexBatch <TexturedVertex2d> spriteBatch = null);