Is it possible to receive a passed in SpriteBatch that already has had Begin() called, call End() on it because you want to change the RenderTarget, then call Begin() on it again with the same parameters that were passed in initially?
Asked
Active
Viewed 53 times
1 Answers
1
It's not possible to determine exactly which parameters were passed in and which overload of Begin()
was called; but it is possible to recreate the original state created by that call.
The parameters to Begin()
, such as BlendState
, DepthStencilState
, etc., are actually set on the GraphicsDevice
. Therefore, it is possible to read (and save) state information from SpriteBatch.GraphicsDevice
, and re-create it on the next call to Begin()

CoolBots
- 4,770
- 2
- 16
- 30
-
Cool, that's what I suspected. Is there a way to see the source for the GraphicsDevice class? – GameKyuubi Nov 14 '16 at 02:06
-
@GameKyuubi, XNA is close-sourced, but there is MonoGame, which is an open-source, cross-platform port of XNA. You don't need the source strictly to replicate the state though, as GraphicsDevice exposes public properties that contain all the info you need (see the documentation link in my answer) – CoolBots Nov 14 '16 at 02:43
-
Yes, I was analyzing the SpriteBatch class and it uses GraphicsDevice in a way that I want to investigate, specifically regarding GraphicsDevice.SetRenderTarget(). I'm trying to figure out the limits and order of calls I should be using when handling multiple SpriteBatches and multiple RenderTargets, specifically what property SetRenderTarget sets that SpriteBatch looks at when Begin() is called, since apparently I can't switch a SpriteBatch RenderTarget while the SpriteBatch is active.. – GameKyuubi Nov 14 '16 at 03:58