public static void Begin(GraphicsDevice gd, int width, int height) { Debug.Assert(batchMode == BatchMode.None, "Bad batch mode: " + batchMode); matrixStack.Clear(); matrix = Matrix.Identity; drawColor = Color.White; blendMode = AppBlendMode.AlphaBlend; samplerState = SamplerState.LinearClamp; if (graphicsDevice != gd) { graphicsDevice = gd; spriteBatch = new SpriteBatch(graphicsDevice); basicEffect = new BasicEffect(graphicsDevice); worldMatrix = Matrix.Identity; viewMatrix = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up); projection = Matrix.CreateOrthographicOffCenter(0.0f, width, height, 0, 1.0f, 1000.0f); basicEffect.World = worldMatrix; basicEffect.View = viewMatrix; basicEffect.Projection = projection; basicEffect.VertexColorEnabled = true; rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; } }
public static void SetBlendMode(AppBlendMode mode) { if (blendMode != mode) { blendMode = mode; EndBatch(); } }
private static BlendState toBlendState(AppBlendMode mode) { switch (mode) { case AppBlendMode.AlphaBlend: return(BlendState.AlphaBlend); case AppBlendMode.Additive: return(BlendState.Additive); case AppBlendMode.Opaque: return(BlendState.Opaque); case AppBlendMode.NonPremultiplied: return(BlendState.NonPremultiplied); default: throw new NotImplementedException(); } }
private static void BeginSpriteBatch(SpriteBatch sb, AppBlendMode blendMode, Matrix m, BatchMode mode) { Debug.Assert(mode != BatchMode.None); if (mode == BatchMode.Sprite) { BlendState blendState = toBlendState(blendMode); sb.Begin(SpriteSortMode.Immediate, blendState, samplerState, null, rasterizerState, drawEffect == null ? null : drawEffect.Effect, m); } else if (mode == BatchMode.BasicEffect) { basicEffect.World = Matrix.Multiply(worldMatrix, m); basicEffect.CurrentTechnique.Passes[0].Apply(); } else if (mode == BatchMode.CustomEffect) { customEffect.Parameters["World"].SetValue(Matrix.Multiply(worldMatrix, m)); customEffect.Parameters["View"].SetValue(viewMatrix); customEffect.Parameters["Projection"].SetValue(projection); customEffect.CurrentTechnique.Passes[0].Apply(); } batchMode = mode; }