public void Draw(TexturedQuad quad, Rectangle rect, Matrix transform) { if (quad == null) { throw new ArgumentNullException("quad"); } PInvokes.D3d9.BeginPixEvent(0, "DrawQuad"); Device.SetVertexBuffer(m_vertexBuffer); Device.Indices = null; Device.BlendState = quad.BlendState; Device.DepthStencilState = OverridingDepthStencilState ?? m_depthSettings[ (quad.Flags.HasFlag(TextureQuadFlags.ZTest) ? 2 : 0) | (quad.Flags.HasFlag(TextureQuadFlags.ZWrite) ? 1 : 0)]; Device.RasterizerState = RasterizerState.CullCounterClockwise; if (m_effect.CurrentTechnique != m_techStack.Peek()) { m_effect.CurrentTechnique = m_techStack.Peek(); } m_paramTransform.SetValue(transform); if (quad.Flags.HasFlag(TextureQuadFlags.OffsetByHalfTexel)) { rect.Left -= 0.5f; rect.Top -= 0.5f; } m_paramPosAdjust.SetValue(new Vector4(rect.Width, rect.Height, rect.Left, rect.Top)); float uvWidth = quad.Texture != null ? quad.Texture.XnaTexture.Width : Device.Viewport.Width; float uvHeight = quad.Texture != null ? quad.Texture.XnaTexture.Height : Device.Viewport.Height; float uvLeft = quad.UVBounds.Left + (quad.Texture != null ? quad.Texture.Bounds.Left : 0); float uvTop = quad.UVBounds.Top + (quad.Texture != null ? quad.Texture.Bounds.Top : 0); m_paramUVAdjust.SetValue(new Vector4(quad.UVBounds.Width / uvWidth, quad.UVBounds.Height / uvHeight, uvLeft / uvWidth, uvTop / uvHeight)); m_paramColorBias.SetValue(quad.ColorToAdd.ToVector4()); m_paramColorScale.SetValue(quad.ColorToModulate.ToVector4() * quad.ColorScale); m_paramTexture.SetValue(m_techStack.Peek() != m_techSimple ? quad.Texture != null ? quad.Texture.XnaTexture : m_whiteTexture : null); foreach (var pass in m_effect.CurrentTechnique.Passes) { pass.Apply(); Device.SamplerStates[0] = m_samplerStateSettings[ (quad.Flags.HasFlag(TextureQuadFlags.WrapUV) ? 2 : 0) | (quad.Flags.HasFlag(TextureQuadFlags.SharpLod) ? 1 : 0)]; Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } PInvokes.D3d9.EndPixEvent(); }
public void Draw(TexturedQuad quad, Point position, Matrix transform) { float width = quad.Texture != null ? quad.Texture.Width : Device.Viewport.Width; float height = quad.Texture != null ? quad.Texture.Height : Device.Viewport.Height; Draw(quad, new Rectangle(position, new Size(width, height)), transform); }