Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
 public void Begin(SpriteSortMode sortMode, SpriteBlendMode blendMode,  SaveStateMode stateMode)
 {
     _blendMode = blendMode;
     _sortMode = sortMode;
     _saveMode = stateMode;
     _matrix = Matrix.Identity;
 }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
 public void Begin(SpriteSortMode sortMode, SpriteBlendMode blendMode, SaveStateMode stateMode, Matrix transformMatrix)
 {
     _blendMode = blendMode;
     _sortMode = sortMode;
     _saveMode = stateMode;
     _matrix = transformMatrix;
 }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
 public void Begin()
 {
     _sortMode = SpriteSortMode.Deferred;
     _blendState = BlendState.AlphaBlend;
     _depthStencilState = DepthStencilState.None;
     _samplerState = SamplerState.LinearClamp;
     _rasterizerState = RasterizerState.CullCounterClockwise;
     _matrix = Matrix.Identity;
 }
Exemplo n.º 10
0
        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;
 }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 13
0
 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)
 {
 }
Exemplo n.º 14
0
 /// <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);
 }
Exemplo n.º 15
0
 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;
 }
Exemplo n.º 16
0
        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;
        }
Exemplo n.º 17
0
 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;
 }
Exemplo n.º 18
0
        // ================== CONSTRUCTORS ================== //

        public DrawMode()
        {
            sortMode          = SpriteSortMode.Immediate;
            blendState        = BlendState.NonPremultiplied;
            samplerState      = SamplerState.LinearClamp;
            depthStencilState = DepthStencilState.None;
            rasterizerState   = RasterizerState.CullNone;
            effect            = null;
            transform         = Matrix.Identity;
        }
Exemplo n.º 19
0
 /// <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;
 }
Exemplo n.º 20
0
 /// <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;
 }
Exemplo n.º 21
0
 // ================== CONSTRUCTORS ================== //
 public DrawMode()
 {
     sortMode          = SpriteSortMode.Immediate;
     blendState        = BlendState.NonPremultiplied;
     samplerState      = SamplerState.LinearClamp;
     depthStencilState = DepthStencilState.None;
     rasterizerState   = RasterizerState.CullNone;
     effect            = null;
     transform         = Matrix.Identity;
 }
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
        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;
        }
Exemplo n.º 24
0
 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;
 }
Exemplo n.º 25
0
        public SBNode(batchEnum _name, SpriteSortMode _sort, BlendState _blend)
        {
            spriteBatch = new SpriteBatch(Game1.GameInstance.GraphicsDevice);

            batchName = _name;

            sort  = _sort;
            blend = _blend;

            spriteListHead = null;
        }
Exemplo n.º 26
0
 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));
 }
Exemplo n.º 27
0
        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;
        }
Exemplo n.º 28
0
        /// <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;
            }
        }
Exemplo n.º 29
0
 /// <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);
 }
Exemplo n.º 30
0
        public SBNode(batchEnum _name, SpriteSortMode _sort, BlendState _blend)
        {
            spriteBatch = new SpriteBatch(Game1.GameInstance.GraphicsDevice);

            batchName = _name;

            sort = _sort;
            blend = _blend;

            spriteListHead = null;
        }
Exemplo n.º 31
0
        /// <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;
        }
Exemplo n.º 32
0
        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;
        }
Exemplo n.º 33
0
        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;
        }
Exemplo n.º 34
0
 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;
 }
Exemplo n.º 35
0
 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);
 }
Exemplo n.º 36
0
 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;
 }
Exemplo n.º 37
0
 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
         );
 }
Exemplo n.º 38
0
        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();
        }
Exemplo n.º 39
0
 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;
 }
Exemplo n.º 40
0
        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();
        }
Exemplo n.º 41
0
		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;
		}
Exemplo n.º 42
0
 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)
 {
 }
Exemplo n.º 43
0
		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();
        }
Exemplo n.º 45
0
        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;
        }
Exemplo n.º 46
0
 /// <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));
 }
Exemplo n.º 47
0
        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);
        }
Exemplo n.º 48
0
        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;
        }
Exemplo n.º 49
0
 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);
 }
Exemplo n.º 50
0
        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;
            }
        }
Exemplo n.º 51
0
 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;
 }
Exemplo n.º 52
0
        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();
            }
        }
Exemplo n.º 53
0
        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;
        }
Exemplo n.º 54
0
 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;
 }
Exemplo n.º 55
0
        /// <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);
        }
Exemplo n.º 56
0
 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]);
 }
Exemplo n.º 57
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;
 }
Exemplo n.º 59
0
        /* 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;
        }
Exemplo n.º 60
0
 /// <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);
 }