/// <summary> /// Fills the vertexUnit with the quad data. /// </summary> /// <param name="vertexUnit">The vertexUnit to fill with the quad data.</param> /// <param name="index">The start index in the index buffer.</param> public override void FillVertexUnit(Purple.Graphics.VertexUnit vertexUnit, int index) { Vector2 a = this.Position; Vector2 right = QuadManager.Instance.RotateUnit(new Vector2(Size.X * this.Scale.X, 0), this.RotationZ); Vector2 down = QuadManager.Instance.RotateUnit(new Vector2(0, Size.Y * this.Scale.Y), this.RotationZ); if (dirty) { PositionStream2 ps = PositionStream2.From(QuadFactory.VertexUnit); ColorStream cs = ColorStream.From(QuadFactory.VertexUnit); TextureStream ts = TextureStream.From(QuadFactory.VertexUnit); RectangleF tc = Texture.TextureCoordinates; for (int y = 0; y < vertices.GetLength(1); y++) { for (int x = 0; x < vertices.GetLength(0); x++) { MeshVertex vertex = vertices[x, y]; Vector2 pos = a + right * vertex.Position.X + down * vertex.Position.Y; ps[index] = new Vector2((pos.X - 0.5f) * 2, -(pos.Y - 0.5f) * 2); cs[index] = Color.SetAlpha(vertex.Color, (int)(Color.GetAlpha(vertex.Color) * Alpha)); Vector2 texture = new Vector2( tc.Left + tc.Width * (TextureRectangle.Left + TextureRectangle.Width * vertex.Texture.X), tc.Top + tc.Height * (TextureRectangle.Top + TextureRectangle.Height * vertex.Texture.Y)); ts[index] = texture; index++; } } dirty = false; } positionCache.CopyTo(vertexUnit[typeof(PositionStream2)].Data, index); colorCache.CopyTo(vertexUnit[typeof(ColorStream)].Data, index); textureCache.CopyTo(vertexUnit[typeof(TextureStream)].Data, index); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- private void Bind() { BinormalStream.Bind(); BoneIndicesStream.Bind(); BoneWeightsStream.Bind(); SoftwareBoneIndicesStream.Bind(); SoftwareBoneWeightsStream.Bind(); ColorStream.Bind(); CompressedNormalStream.Bind(); FloatStream.Bind(); IndexStream16.Bind(); IndexStream32.Bind(); IntStream.Bind(); NormalStream.Bind(); PositionStream.Bind(); PositionStream2.Bind(); PositionStream4.Bind(); TangentStream.Bind(); TextureStream.Bind(); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Updates the particle system. /// </summary> /// <param name="deltaTime">The time since the last update.</param> public override void Update(float deltaTime) { base.Update(deltaTime); // update streams PositionStream2 posStream = (PositionStream2)vertexUnit[typeof(PositionStream2)]; ColorStream colorStream = (ColorStream)vertexUnit[typeof(ColorStream)]; TextureStream textureStream = (TextureStream)vertexUnit[typeof(TextureStream)]; // Update all particles for (int i = 0; i < particles.Count; i++) { int offset = i * 4; IParticle particle = particles[i] as IParticle; IParticle2d particle2d = particles[i] as IParticle2d; if (particle2d != null) { Vector2 position = particle2d.Position; posStream[offset] = position + new Vector2(-particle.Size.X, particle.Size.Y); posStream[offset + 1] = position + new Vector2(particle.Size.X, particle.Size.Y); posStream[offset + 2] = position + new Vector2(particle.Size.X, -particle.Size.Y); posStream[offset + 3] = position + new Vector2(-particle.Size.X, -particle.Size.Y); } IParticleColor particleColor = particles[i] as IParticleColor; if (particleColor != null) { colorStream[offset] = particleColor.Color; colorStream[offset + 1] = particleColor.Color; colorStream[offset + 2] = particleColor.Color; colorStream[offset + 3] = particleColor.Color; } IParticleIndex particleIndex = particles[i] as IParticleIndex; System.Drawing.RectangleF tc; if (particleIndex == null || subTextures == null) { tc = (Texture as ITexture2d).TextureCoordinates; } else { tc = subTextures[(int)particleIndex.TextureIndex % subTextures.Length].TextureCoordinates; } textureStream[offset] = new Vector2(tc.Left, tc.Top); textureStream[offset + 1] = new Vector2(tc.Right, tc.Top); textureStream[offset + 2] = new Vector2(tc.Right, tc.Bottom); textureStream[offset + 3] = new Vector2(tc.Left, tc.Bottom); } posStream.Upload(); colorStream.Upload(); textureStream.Upload(); // Render all particles Device.Instance.VertexUnit = vertexUnit; Device.Instance.IndexStream = indexStream; textures.Apply(); int steps = Effect.Begin(); for (int i = 0; i < steps; i++) { Effect.BeginPass(i); Effect.CommitChanges(); // Oct Update BUG!!! Device.Instance.DrawIndexed(vertexUnit.Position, 0, particles.Count * 4, indexStream.Position, particles.Count * 2); Effect.EndPass(); } Effect.End(); }