/// <summary> /// Begins a new sprite and text batch with the specified render state. /// </summary> /// <param name="sortMode">The drawing order for sprite and text drawing. <see cref="SpriteSortMode.Deferred"/> by default.</param> /// <param name="blendState">State of the blending. Uses <see cref="BlendState.AlphaBlend"/> if null.</param> /// <param name="samplerState">State of the sampler. Uses <see cref="SamplerState.LinearClamp"/> if null.</param> /// <param name="depthStencilState">State of the depth-stencil buffer. Uses <see cref="DepthStencilState.None"/> if null.</param> /// <param name="rasterizerState">State of the rasterization. Uses <see cref="RasterizerState.CullCounterClockwise"/> if null.</param> /// <param name="effect">A custom <see cref="Effect"/> to override the default sprite effect. Uses default sprite effect if null.</param> /// <param name="transformMatrix">An optional matrix used to transform the sprite geometry. Uses <see cref="Matrix.Identity"/> if null.</param> /// <exception cref="InvalidOperationException">Thrown if <see cref="Begin"/> is called next time without previous <see cref="End"/>.</exception> /// <remarks>This method uses optional parameters.</remarks> /// <remarks>The <see cref="Begin"/> Begin should be called before drawing commands, and you cannot call it again before subsequent <see cref="End"/>.</remarks> public void Begin ( SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix? transformMatrix = null ) { if (_beginCalled) throw new InvalidOperationException("Begin cannot be called again until End has been successfully called."); // defaults _sortMode = sortMode; _blendState = blendState ?? BlendState.AlphaBlend; _samplerState = samplerState ?? SamplerState.LinearClamp; _depthStencilState = depthStencilState ?? DepthStencilState.None; _rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise; _effect = effect; _matrix = transformMatrix ?? Matrix.Identity; // Setup things now so a user can change them. if (sortMode == SpriteSortMode.Immediate) { Setup(); } _beginCalled = true; }
public void Begin(SpriteSortMode sortMode, SpriteBlendMode blendMode, SaveStateMode stateMode) { _blendMode = blendMode; _sortMode = sortMode; _saveMode = stateMode; _matrix = Matrix.Identity; }
/// <summary> /// Starts the specified batch. /// </summary> /// <param name="batch">The batch.</param> /// <param name="useCamera">if set to <c>true</c> camera matrix will be applied.</param> /// <param name="sortMode">The sort mode.</param> /// <param name="blendState">State of the blend.</param> /// <param name="samplerState">State of the sampler.</param> /// <param name="depthStencilState">State of the depth stencil.</param> /// <param name="rasterizerState">State of the rasterizer.</param> /// <param name="effect">The effect.</param> /// <param name="transform">The transformation matrix.</param> public static void Start(this SpriteBatch batch, bool useCamera = false, SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix? transform = null) { Matrix matrix = AlmiranteEngine.IsWinForms ? Matrix.Identity : AlmiranteEngine.Settings.Resolution.Matrix; if (useCamera) { matrix = AlmiranteEngine.Camera.Matrix * matrix; } if (transform.HasValue) { matrix = transform.Value * matrix; } BatchExtensions._sortMode = sortMode; BatchExtensions._blendState = blendState; BatchExtensions._samplerState = samplerState; BatchExtensions._depthStencilState = depthStencilState; BatchExtensions._rasterizerState = rasterizerState; BatchExtensions._effect = effect; BatchExtensions._matrix = matrix; batch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, matrix); }
public void Begin(SpriteSortMode sortMode, SpriteBlendMode blendMode, SaveStateMode stateMode, Matrix transformMatrix) { _blendMode = blendMode; _sortMode = sortMode; _saveMode = stateMode; _matrix = transformMatrix; }
public void DrawBatch(SpriteSortMode sortMode) { if (_items.Count == 0) return; SortItems(sortMode); var index = 0; // build the vertices array to send to the GPU foreach (var item in _items) { _vertices[index++] = item.Vertices[0]; _vertices[index++] = item.Vertices[1]; _vertices[index++] = item.Vertices[2]; _vertices[index++] = item.Vertices[3]; //add this item back to the pool _itemPool.Enqueue(item); } GL.BindVertexArray(_vertexHandle); GL.BindBuffer(BufferTarget.ElementArrayBuffer, _indexHandle); Draw(index, _items.Count); _items.Clear(); }
public override void Begin(GraphicsDevice device, SpriteBlendMode blendMode, SpriteSortMode sortMode, SaveStateMode stateMode, Local.Matrix transformMatrix) { _childRenderer = GetCurrentRenderer(); _childRenderer.Begin(device, blendMode, sortMode, stateMode, transformMatrix); currentSortMode = sortMode; base.Begin(device, blendMode, sortMode, stateMode, transformMatrix); }
public void Begin(SpriteSortMode sortMode, BlendState blendState) { _sortMode = sortMode; _blendState = (blendState == null) ? BlendState.AlphaBlend : blendState; _depthStencilState = DepthStencilState.None; _samplerState = SamplerState.LinearClamp; _rasterizerState = RasterizerState.CullCounterClockwise; _matrix = Matrix.Identity; }
internal static void StartBatch(BlendState blendState = null, SpriteSortMode sortMode = SpriteSortMode.Texture) { if (blendState == null) blendState = BlendState.NonPremultiplied; MainGame.SpriteBatch.Begin (sortMode, blendState, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone); IsBatching = true; }
public void Begin() { _sortMode = SpriteSortMode.Deferred; _blendState = BlendState.AlphaBlend; _depthStencilState = DepthStencilState.None; _samplerState = SamplerState.LinearClamp; _rasterizerState = RasterizerState.CullCounterClockwise; _matrix = Matrix.Identity; }
public static void SetSpriteBatch(SpriteBatch spriteBatch, SpriteSortMode spriteSortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, Effect effect = null, bool end = true) { // Use SetSpriteBatch(spriteBatch: spriteBatch); to set vanilla settings if (end) { spriteBatch.End(); } spriteBatch.Begin(spriteSortMode, blendState ?? BlendState.AlphaBlend, samplerState ?? Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, effect, Main.GameViewMatrix.TransformationMatrix); }
/// <summary> /// Constructor /// </summary> /// <param name="spriteBatchName">The string name used to access the sprite batch</param> /// <param name="desiredBlendMode">The blend mode to use for the sprite batch</param> /// <param name="desiredSortMode">The sort mode to use for the sprite batch</param> /// <param name="desiredSaveMode">The save mode to use for the sprite batch</param> /// <param name="updateCameraMatrix">The flag used to denote if the matrix needs to be updated every update cycle</param> public SpriteBatchDescription(string spriteBatchName, SpriteBlendMode desiredBlendMode, SpriteSortMode desiredSortMode, SaveStateMode desiredSaveMode, bool updateCameraMatrix) { this.spriteBatchName = spriteBatchName; this.desiredBlendMode = desiredBlendMode; this.desiredSortMode = desiredSortMode; this.desiredStateMode = desiredSaveMode; this.updateCameraMatrix = updateCameraMatrix; this.currentMatrix = Matrix.Identity; }
public DrawStackFrame(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, Matrix transform, Matrix projection, Microsoft.Xna.Framework.Graphics.Effect shader, Action <Matrix, Matrix> shaderSetup) { SortMode = sortMode; BlendState = blendState; SamplerState = samplerState; Transform = transform; Projection = projection; Shader = shader; ShaderSetup = shaderSetup; }
public void Begin( SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix?transformMatrix = null) { }
/// <summary> /// Begin the SpriteBatch /// </summary> /// <param name="SortMode">Self-explanatory.</param> /// <param name="BlendState">Self-explanatory.</param> /// <param name="SamplerState">Self-explanatory.</param> /// <param name="DepthStencilState">Self-explanatory.</param> /// <param name="RasterizerState">Self-explanatory.</param> /// <param name="Effect">Self-explanatory.</param> /// <param name="Matrix">Self-explanatory.</param> public void Begin(SpriteSortMode SortMode = SpriteSortMode.Deferred, BlendState BlendState = null, SamplerState SamplerState = null, DepthStencilState DepthStencilState = null, RasterizerState RasterizerState = null, Effect Effect = null, Matrix? Matrix = null, bool Backup = false) { if (Begun) End(); Begun = true; if (Backup) this.Backup(SortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix); SpriteBatch.Begin(SortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix); }
public virtual void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) { this.spriteSortMode = sortMode; this.blendState = blendState; this.samplerState = samplerState; this.depthStencilState = depthStencilState; this.rasterizerState = rasterizerState; this.customEffect = effect; this.transformMatrix = transformMatrix; }
public void Begin(TextureAtlas atlas, Camera camera) { if (_beginCalled) throw new Exception("Begin called twice without a call to end."); _atlas = atlas; _camera = camera; _blendState = BlendState.AlphaBlend; _sortMode = SpriteSortMode.None; _beginCalled = true; }
public DrawMode(DrawMode copy) { sortMode = copy.sortMode; blendState = copy.blendState; samplerState = copy.samplerState; depthStencilState = copy.depthStencilState; rasterizerState = copy.rasterizerState; effect = copy.effect; transform = copy.transform; }
// ================== CONSTRUCTORS ================== // public DrawMode() { sortMode = SpriteSortMode.Immediate; blendState = BlendState.NonPremultiplied; samplerState = SamplerState.LinearClamp; depthStencilState = DepthStencilState.None; rasterizerState = RasterizerState.CullNone; effect = null; transform = Matrix.Identity; }
/// <summary> /// Initializes a new instance of the <see cref="SpriteBatchState"/> structure. /// </summary> /// <param name="sortMode">The sprite batch's sort mode.</param> /// <param name="blendState">The sprite batch's blend state.</param> /// <param name="samplerState">The sprite batch's sampler state.</param> /// <param name="rasterizerState">The sprite batch's rasterizer state.</param> /// <param name="depthStencilState">The sprite batch's depth/stencil state.</param> /// <param name="effect">The sprite batch's custom effect.</param> /// <param name="transformMatrix">The sprite batch's transformation matrix.</param> public SpriteBatchState(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, RasterizerState rasterizerState, DepthStencilState depthStencilState, Effect effect, Matrix transformMatrix) { this.sortMode = sortMode; this.blendState = blendState; this.samplerState = samplerState; this.rasterizerState = rasterizerState; this.depthStencilState = depthStencilState; this.customEffect = effect; this.transformMatrix = transformMatrix; }
/// <summary> /// construct a TTSpriteBatch with custom rendering parameters for the batch /// </summary> public TTSpriteBatch(GraphicsDevice gfx, SpriteSortMode ssm, BlendState bs, SamplerState ss, DepthStencilState dss, RasterizerState rs, Effect fx) : base(gfx) { spriteSortMode = ssm; blendState = bs; samplerState = ss; depthStencilState = dss; rasterizerState = rs; effect = fx; }
public static void ChangeDrawCall(SpriteSortMode sortMode, Matrix?transformMatrix, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null) { if (SpriteBatchActive) { SpriteBatch.End(); } SpriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix); SpriteBatchActive = true; }
public CommandSpriteBatchBegin(RemoteSpriteBatch batch, SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencil, RasterizerState rasterizer, RemoteEffect effect) { Batch = batch; SortMode = sortMode; BlendState = blendState; SamplerState = samplerState; Effect = effect; DepthStencil = depthStencil; RasterizerState = rasterizer; }
public SBNode(batchEnum _name, SpriteSortMode _sort, BlendState _blend) { spriteBatch = new SpriteBatch(Game1.GameInstance.GraphicsDevice); batchName = _name; sort = _sort; blend = _blend; spriteListHead = null; }
public static IDisposable Block(this SpriteBatch spriteBatch, SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null) { return(new SpriteBatchBlock(spriteBatch, sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect)); }
public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect) { _sortMode = sortMode; _blendState = (blendState == null) ? BlendState.AlphaBlend : blendState; _depthStencilState = (depthStencilState == null) ? DepthStencilState.None : depthStencilState; _samplerState = (samplerState == null) ? SamplerState.LinearClamp : samplerState; _rasterizerState = (rasterizerState == null) ? RasterizerState.CullCounterClockwise : rasterizerState; _effect = effect; }
/// <summary> /// Begins a sprite batch operation using the specified sort and blend state /// object and default state objects (DepthStencilState.None, SamplerState.LinearClamp, /// RasterizerState.CullCounterClockwise). If you pass a null blend state, the /// default is BlendState.AlphaBlend. /// </summary> /// <param name="sortMode">Sprite drawing order.</param> /// <param name="blendState">Blending options.</param> public new void Begin(SpriteSortMode sortMode, BlendState blendState) { if (Camera.main == null) return; if (!active) { base.Begin(sortMode, blendState, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise, null, Camera.main.TransformMatrix); active = true; } }
/// <summary> /// Begins SpriteBatch drawing, and marks the beginning of a PIX event. /// </summary> /// <param name="spriteBatch">The SpriteBatch to use</param> /// <param name="blendMode">Blending options to use when rendering</param> /// <param name="sortMode">Sorting options to use when rendering</param> /// <param name="stateMode">Rendering state options</param> /// <param name="transformMatrix">A matrix to apply to position, rotation, scale, and depth data passed to SpriteBatch.Draw</param> /// <param name="userMessage">A string to append to the PIX event name. Pass null for no message.</param> public static void BeginPIX(this SpriteBatch spriteBatch, SpriteBlendMode blendMode, SpriteSortMode sortMode, SaveStateMode stateMode, Matrix transformMatrix, string userMessage) { BeginEvent(MakeName("SpriteBatch Drawing", userMessage)); SetMarker("SpriteBatch.Begin Called"); spriteBatch.Begin(blendMode, sortMode, stateMode, transformMatrix); }
/// <summary> /// Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil, rasterizer state objects and a custom effect. /// Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, depthStencilState.None, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). /// Passing a null effect selects the default effect shader. /// </summary> /// <param name="graphicsContext">The graphics context to use.</param> /// <param name="effect">The effect to use for this begin/end draw session (default effect if null)</param> /// <param name="sessionSortMode">Sprite drawing order used for the Begin/End session.</param> /// <param name="sessionBlendState">Blending state used for the Begin/End session</param> /// <param name="sessionSamplerState">Texture sampling used for the Begin/End session</param> /// <param name="sessionDepthStencilState">Depth and stencil state used for the Begin/End session</param> /// <param name="sessionRasterizerState">Rasterization state used for the Begin/End session</param> /// <param name="stencilValue">The value of the stencil buffer to take as reference for the Begin/End session</param> /// <exception cref="System.InvalidOperationException">Only one SpriteBatch at a time can use SpriteSortMode.Immediate</exception> protected void Begin(GraphicsContext graphicsContext, EffectInstance effect, SpriteSortMode sessionSortMode, BlendStateDescription?sessionBlendState, SamplerState sessionSamplerState, DepthStencilStateDescription?sessionDepthStencilState, RasterizerStateDescription?sessionRasterizerState, int stencilValue) { CheckEndHasBeenCalled("begin"); GraphicsContext = graphicsContext; sortMode = sessionSortMode; blendState = sessionBlendState; samplerState = sessionSamplerState; depthStencilState = sessionDepthStencilState; rasterizerState = sessionRasterizerState; stencilReferenceValue = stencilValue; Effect = effect ?? (graphicsDevice.ColorSpace == ColorSpace.Linear ? DefaultEffectSRgb : DefaultEffect); // Force the effect to update Effect.UpdateEffect(graphicsDevice); textureUpdater = null; if (Effect.Effect.HasParameter(TexturingKeys.Texture0)) { textureUpdater = Effect.Parameters.GetAccessor(TexturingKeys.Texture0); } if (Effect.Effect.HasParameter(TexturingKeys.TextureCube0)) { textureUpdater = Effect.Parameters.GetAccessor(TexturingKeys.TextureCube0); } if (Effect.Effect.HasParameter(TexturingKeys.Texture3D0)) { textureUpdater = Effect.Parameters.GetAccessor(TexturingKeys.Texture3D0); } samplerUpdater = null; if (Effect.Effect.HasParameter(TexturingKeys.Sampler)) { samplerUpdater = Effect.Parameters.GetAccessor(TexturingKeys.Sampler); } // Immediate mode, then prepare for rendering here instead of End() if (sessionSortMode == SpriteSortMode.Immediate) { if (ResourceContext.IsInImmediateMode) { throw new InvalidOperationException("Only one SpriteBatch at a time can use SpriteSortMode.Immediate"); } PrepareForRendering(); ResourceContext.IsInImmediateMode = true; } // Sets to true isBeginCalled isBeginCalled = true; }
public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState) { _sortMode = sortMode; _blendState = (blendState == null) ? BlendState.AlphaBlend : blendState; _depthStencilState = (depthStencilState == null) ? DepthStencilState.None : depthStencilState; _samplerState = (samplerState == null) ? SamplerState.LinearClamp : samplerState; _rasterizerState = (rasterizerState == null) ? RasterizerState.CullCounterClockwise : rasterizerState; _matrix = Matrix.Identity; }
internal static void StartBatch(BlendState blendState = null, SpriteSortMode sortMode = SpriteSortMode.Texture) { if (blendState == null) { blendState = BlendState.NonPremultiplied; } MainGame.SpriteBatch.Begin(sortMode, blendState, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone); IsBatching = true; }
public void Backup(SpriteSortMode SortMode = SpriteSortMode.Deferred, BlendState BlendState = null, SamplerState SamplerState = null, DepthStencilState DepthStencilState = null, RasterizerState RasterizerState = null, Effect Effect = null, Matrix?Matrix = null) { this.SortMode = SortMode; this.BlendState = BlendState; this.SamplerState = SamplerState; this.DepthStencilState = DepthStencilState; this.RasterizerState = RasterizerState; this.Effect = Effect; this.Matrix = Matrix; }
public SpriteBatchBlock(SpriteBatch spriteBatch, SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect) { if (spriteBatch == null) { throw new ArgumentNullException("spriteBatch"); } _spriteBatch = spriteBatch; _spriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect); }
public void Backup(SpriteSortMode SortMode = SpriteSortMode.Deferred, BlendState BlendState = null, SamplerState SamplerState = null, DepthStencilState DepthStencilState = null, RasterizerState RasterizerState = null, Effect Effect = null, Matrix? Matrix = null) { this.SortMode = SortMode; this.BlendState = BlendState; this.SamplerState = SamplerState; this.DepthStencilState = DepthStencilState; this.RasterizerState = RasterizerState; this.Effect = Effect; this.Matrix = Matrix; }
private static void SpriteBatchBegin(Matrix transformMatrix, SpriteSortMode sortMode, Effect effect) { _spriteBatch.Begin( sortMode, BlendState.NonPremultiplied,//BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, effect, transformMatrix ); }
public void Draw(SpriteBatch spriteBatch, Color tintColor, BlendState state, SpriteSortMode mode = SpriteSortMode.Deferred) { int row = frameList[currentFrame].Row; int column = frameList[currentFrame].Column; Rectangle sourceRectangle = new Rectangle(frameWidth * column, frameHeight * row, frameWidth, frameHeight); Rectangle destinationRectangle = new Rectangle((int)Location.X - frameWidth / 2, (int)Location.Y - frameHeight / 2, frameWidth, frameHeight); spriteBatch.Begin(mode, state); spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, tintColor); spriteBatch.End(); }
public GraphicsFragmentSettings(SpriteSortMode spriteSortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null) { SpriteSortMode = spriteSortMode; BlendState = blendState ?? BlendState.AlphaBlend; SamplerState = samplerState ?? SamplerState.PointWrap; DepthStencilState = depthStencilState ?? DepthStencilState.None; RasterizerState = rasterizerState ?? RasterizerState.CullClockwise; }
public override void Draw(SpriteBatch batch) { SpriteSortMode mode = SpriteSortMode.Deferred; batch.Begin(mode, BlendState.AlphaBlend); for (int i = 0; i < layers.Count; i++) { layers[i].Draw(batch); } m_DefaultLayer.Draw(batch); batch.End(); }
public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) { _sortMode = sortMode; _blendState = (blendState == null) ? BlendState.AlphaBlend : blendState; _depthStencilState = (depthStencilState == null) ? DepthStencilState.None : depthStencilState; _samplerState = (samplerState == null) ? SamplerState.LinearClamp : samplerState; _rasterizerState = (rasterizerState == null) ? RasterizerState.CullCounterClockwise : rasterizerState; _effect = effect; _matrix = transformMatrix; }
public SetRenderProperties(SpriteSortMode ssm = SpriteSortMode.Deferred , BlendState bs = null , SamplerState ss = null , DepthStencilState dss = null , RasterizerState rs = null , Effect e = null , Matrix?m = null , bool ignoreDefaults = true , bool applyMatrix = false) : this(new SpriteBatchPropertiesPacket(ssm, bs, ss, dss, rs, e, m), ignoreDefaults, applyMatrix) { }
internal static void OnBegin (SpriteBatch __instance, SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) { DrawState.OnBegin( __instance, sortMode, blendState ?? BlendState.AlphaBlend, samplerState ?? SamplerState.PointClamp, depthStencilState ?? DepthStencilState.None, rasterizerState ?? RasterizerState.CullCounterClockwise, effect, transformMatrix ); }
public void DrawGeometryBatch(SpriteSortMode sortMode) { if (this._geometryBatch.Count == 0) { return; } switch (sortMode) { case SpriteSortMode.BackToFront: this._geometryBatch.Sort(new Comparison <GeometryItem>(MTSpriteBatcher.CompareGeometryReverseDepth)); break; case SpriteSortMode.FrontToBack: this._geometryBatch.Sort(new Comparison <GeometryItem>(MTSpriteBatcher.CompareGeometryDepth)); break; } int num = 0; foreach (GeometryItem geometryItem in this._geometryBatch) { num += geometryItem.length; } this.EnsureGeometryArrayCapacity((num + 1) / 3); Material material = (Material)null; int start = 0; int end = 0; foreach (GeometryItem geometryItem in this._geometryBatch) { if (!object.ReferenceEquals((object)geometryItem.material, (object)material)) { this.FlushGeometryVertexArray(start, end); if (material != null && geometryItem.material == null) { this._batch.ReapplyEffect(true); } material = geometryItem.material; material?.Apply(); } for (int index = 0; index < geometryItem.length; index += 3) { this._geometryVertexArray[end++] = geometryItem.vertices[index]; this._geometryVertexArray[end++] = geometryItem.vertices[index + 1]; this._geometryVertexArray[end++] = geometryItem.vertices[index + 2]; } if (geometryItem.temporary) { this._freeGeometryBatch.Enqueue(geometryItem); } } this.FlushGeometryVertexArray(start, end); this._geometryBatch.Clear(); }
public DrawBatch(SpriteBatch inspriteBatch, GraphicsDevice ingraphicDevice, SpriteSortMode inSort, BlendState inBlend, SpriteBatchName inName, int buffersize = 10, int delta = 3) { GameSprites = new LinkedList(buffersize, delta, NodeType.GameSpr); DeltaGrow = delta; spriteBatch = inspriteBatch; graphicDevices = ingraphicDevice; sortMode = inSort; blendState = inBlend; Name = inName; _isActive = true; }
/// <summary> /// Set the next render order action to set the render properties to the given values. /// </summary> /// <param name="ssm"></param> /// <param name="bs"></param> /// <param name="ss"></param> /// <param name="dss"></param> /// <param name="rs"></param> /// <param name="e"></param> /// <param name="m"></param> /// <param name="ignoreDefaults"></param> /// <param name="applyMatrix"></param> public void AddSetRenderProperties(SpriteSortMode ssm = SpriteSortMode.Deferred , BlendState bs = null , SamplerState ss = null , DepthStencilState dss = null , RasterizerState rs = null , Effect e = null , Matrix?m = null , bool ignoreDefaults = true , bool applyMatrix = false) { Actions.Add(new SetRenderProperties(ssm, bs, ss, dss, rs, e, m, ignoreDefaults, applyMatrix)); }
public void ReplaceRenderStates(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix, Rectangle scissorRectangle) { bool isNewRender = currentParameters.HasValue == false; var newParameters = new BeginParameters(); newParameters.ChangeRecord = StateChangeInfoListPool.GetNextAvailable(); newParameters.ChangeRecord.Clear(); newParameters.SortMode = sortMode; newParameters.BlendState = blendState; newParameters.SamplerState = samplerState; newParameters.DepthStencilState = depthStencilState; newParameters.RasterizerState = rasterizerState; newParameters.Effect = effect; newParameters.TransformMatrix = transformMatrix; try { newParameters.ScissorRectangle = scissorRectangle; } catch (Exception e) { throw new Exception("Could not set scissor rectangle to:" + scissorRectangle.ToString(), e); } if (currentParameters != null) { beginParametersUsedThisFrame.Add(currentParameters.Value); } currentParameters = newParameters; if (beginEndState == SpriteBatchBeginEndState.Began) { SpriteBatch.End(); } try { SpriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle; } catch (Exception e) { throw new Exception("Error trying to set scissor rectangle:" + scissorRectangle.ToString()); } beginEndState = SpriteBatchBeginEndState.Began; SpriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix); }
public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) { _sortMode = sortMode; _blendState = blendState ?? BlendState.AlphaBlend; _depthStencilState = depthStencilState ?? DepthStencilState.None; _samplerState = samplerState ?? SamplerState.LinearClamp; _rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise; if(effect != null) _effect = effect; _matrix = transformMatrix; }
public static void SpriteBatchBegin ( SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Nullable <Matrix> transformMatrix = null ) { CakeEngine.spriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix); }
public new void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix?transformMatrix = null, Rectangle?scissor = null) { if (rasterizerState == null) { rasterizerState = GetRasterizerState(scissor); } base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix); if (Scissor != null) { GraphicsDevice.ScissorRectangle = Scissor.Value; } }
public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) { this._sortMode = sortMode; this._blendState = blendState ?? BlendState.AlphaBlend; this._samplerState = samplerState ?? SamplerState.LinearClamp; this._depthStencilState = depthStencilState ?? DepthStencilState.None; this._rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise; this._effect = effect; this._matrix = transformMatrix; if (sortMode == SpriteSortMode.Immediate) this.Setup(); this._beginCalled = true; }
public void Begin(SpriteSortMode sortMode, BlendState blendState, RasterizerState rasterizerState, SamplerState samplerState, DepthStencilState depthStencilState, Effect customEffect, Matrix worldMatrix) { if (_inBeginEnd) { throw new InvalidOperationException("SpriteBatch.End() must be called before another call to Begin() is initiated."); } _sortMode = sortMode; if (blendState == null) { _bs = BlendState.AlphaBlendPremultiplied; } else { _bs = blendState; } if (rasterizerState == null) { _rs = RasterizerState.CullBackClockwiseFront; } else { _rs = rasterizerState; } if (samplerState == null) { _ss = SamplerState.LinearClamp; } else { _ss = samplerState; } if (depthStencilState == null) { _dss = DepthStencilState.None; } else { _dss = depthStencilState; } _customEffect = customEffect; _worldMatrix = worldMatrix; _inBeginEnd = true; SetRenderStates(); SetBuffers(); if (customEffect == null) { ApplyEffect(); } }
public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) { // defaults _sortMode = sortMode; _blendState = blendState ?? BlendState.AlphaBlend; _samplerState = samplerState ?? SamplerState.LinearClamp; _depthStencilState = depthStencilState ?? DepthStencilState.None; _rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise; //if (effect != null) _effect = effect; _matrix = transformMatrix; }
public SpriteBatchStruct(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Camera camera) { SB = new SpriteBatch(Drawing.StaticGraphicsDevice); SB_SpriteSortMode = sortMode; SB_BlendState = blendState; SB_SamplerState = samplerState; SB_DepthStencilState = depthStencilState; SB_RasterizerState = rasterizerState; SB_Effect = effect; SB_Camera = camera; wasBegin = false; }
/// <summary> /// Begins a new sprite batch using the appropriate settings for rendering UPF. /// </summary> /// <param name="sortMode">The sorting mode to use when rendering interface elements.</param> /// <param name="blendState">The blend state to apply to the rendered elements.</param> /// <param name="samplerState">The sampler state to apply to the rendered interface elements.</param> /// <param name="effect">The custom effect to apply to the rendered interface elements.</param> /// <param name="localTransform">The transform matrix to apply to the rendered interface elements.</param> public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, Effect effect, Matrix localTransform) { if (SpriteBatch == null) throw new InvalidOperationException(PresentationStrings.DrawingContextDoesNotHaveSpriteBatch); this.localTransform = localTransform; this.combinedTransform = Matrix.Identity; Matrix.Concat(ref localTransform, ref globalTransform, out combinedTransform); SpriteBatch.Begin(sortMode, blendState ?? BlendState.AlphaBlend, samplerState ?? SamplerState.LinearClamp, StencilReadDepthState, RasterizerState.CullCounterClockwise, effect, combinedTransform); }
public RenderStep(RenderTarget2D renderTarget, SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix? transformMatrix = null, Color? clearColor = null, ShaderStep[] shaderSteps = null, Action<Camera2D, RenderStep, GameTime>[] preSteps = null, Action<Camera2D, RenderStep, GameTime>[] drawSteps = null) { RenderTarget = renderTarget; SpriteSortMode = sortMode; BlendState = blendState ?? BlendState.AlphaBlend; SamplerState = samplerState ?? SamplerState.LinearClamp; DepthStencilState = depthStencilState; RasterizerState = rasterizerState; Effect = effect; TransformMatrix = transformMatrix ?? Matrix.Identity; ClearColor = clearColor; ShaderSteps = new List<ShaderStep>(shaderSteps ?? new ShaderStep[0]); PreSteps = new List<Action<Camera2D, RenderStep, GameTime>>(preSteps ?? new Action<Camera2D, RenderStep, GameTime>[0]); DrawSteps = new List<Action<Camera2D, RenderStep, GameTime>>(drawSteps ?? new Action<Camera2D, RenderStep, GameTime>[0]); }
public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) { if (this._beginCalled) throw new InvalidOperationException("Begin cannot be called again until End has been successfully called."); this._sortMode = sortMode; this._blendState = blendState ?? BlendState.AlphaBlend; this._samplerState = samplerState ?? SamplerState.LinearClamp; this._depthStencilState = depthStencilState ?? DepthStencilState.None; this._rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise; this._effect = effect; this._matrix = transformMatrix; if (sortMode == SpriteSortMode.Immediate) this.Setup(); this._beginCalled = true; }
public SpriteBatchPropertiesPacket( SpriteSortMode ssm = SpriteSortMode.Deferred , BlendState bs = null , SamplerState ss = null , DepthStencilState dss = null , RasterizerState rs = null , Effect e = null , Matrix? m = null) { SpriteSortMode = ssm; BlendState = bs; SamplerState = ss; DepthStencilState = dss; RasterizerState = rs; Effect = e; Matrix = m; }
/* Constructors */ public Camera(GraphicsDevice graphicsDevice) { mRenderer = new SpriteBatch(graphicsDevice); mSpriteSortMode = Microsoft.Xna.Framework.Graphics.SpriteSortMode.Immediate; mBlendState = BlendState.AlphaBlend; mSamplerState = SamplerState.AnisotropicClamp; mDepthStencilState = DepthStencilState.Default; mRasterizerState = RasterizerState.CullNone; mEffect = null; MaxZoom = float.MaxValue; MinZoom = -float.MaxValue; Position = Vector2.Zero; mZoom = 1.0f; mRotation = 0.0f; }
/// <summary> /// Constructs a scenegraph for the passed in Game. /// Registers itself both with XNA's Services registry and TwoDEngine' (superior) Registry. /// </summary> /// <param name="game"></param> public Scenegraph(Game game,SpriteSortMode sortMode= SpriteSortMode.Deferred,BlendState blendState=null, SamplerState samplerState = null,DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect=null) : base(game) { // spriteBlendState = blendState==null?BlendState.AlphaBlend:blendState; //necc because cannot be default param spriteSamplerState = samplerState==null?SamplerState.LinearClamp:samplerState; // as above spriteDepthStencilState = depthStencilState==null?DepthStencilState.None:depthStencilState; // as above spriteRasterizerState = rasterizerState==null? RasterizerState.CullCounterClockwise:rasterizerState; spriteEffect = effect; // TODO: Construct any child components here\\Components.Add(scenegraph); game.Services.AddService(typeof(Scenegraph), this); game.Components.Add(this); Registry.Register(this); }