/// <summary> /// Everything between <c>BeginRenderTarget()</c> and <c>EndRenderTarget()</c> will be drawn to the <see cref="RenderTarget2D"/>. /// </summary> /// <param name="key">Please enter a previously set key of the <see cref="RenderTarget2D"/> you want to end.</param> /// <param name="drawToSpriteBatch"><c>true</c> to automatically draw the result to the <see cref="SpriteBatch"/>.</param> /// <param name="clearGraphics"><c>false</c> if you don't want to to call <see cref="graphics"/>.Clear() after setting the <see cref="RenderTarget2D"/>.</param> /// <param name="clearColor">The <see cref="Color"/> to be used to clear the <see cref="graphics"/> after setting the <see cref="RenderTarget2D"/>.</param> /// <returns>The resulting <see cref="RenderTarget2D"/>.</returns> public RenderTarget2D EndRenderTarget(string key, bool drawToSpriteBatch = true, bool clearGraphics = true, Color?clearColor = null) { if (GetRenderTargetManager.GetRenderTarget2D(key) == null || GetRenderTargetManager.RenderTargets[key].IsRefreshing || !GetRenderTargetManager.RenderTargets[key].Enabled) { return(null); } graphics.SetRenderTarget(SwapChainRenderTarget); if (clearGraphics) { graphics.Clear(clearColor ?? BackgroundColor); } if (drawToSpriteBatch) { spriteBatch.Begin(); spriteBatch.Draw(GetRenderTargetManager.GetRenderTarget2D(key), Vector2.Zero, Color.White); spriteBatch.End(); } return(GetRenderTargetManager.GetRenderTarget2D(key)); }
/// <summary> /// Everything between <c>BeginRenderTarget()</c> and <c>EndRenderTarget()</c> will be drawn to the <see cref="RenderTarget2D"/>. /// </summary> /// <param name="key">Please enter a previously set key of the <see cref="RenderTarget2D"/> you want to end.</param> /// <param name="drawToSpriteBatch"><c>true</c> to automatically draw the result to the <see cref="SpriteBatch"/>.</param> /// <param name="clearGraphics"><c>false</c> if you don't want to to call <see cref="graphics"/>.Clear() after setting the <see cref="RenderTarget2D"/>.</param> /// <param name="clearColor">The <see cref="Color"/> to be used to clear the <see cref="graphics"/> after setting the <see cref="RenderTarget2D"/>.</param> /// <param name="clearOptions">Define your custom <see cref="ClearOptions"/>.</param> /// <param name="depth">The depth.</param> /// <param name="stencil">The stencil</param> /// <returns>The resulting <see cref="RenderTarget2D"/>.</returns> public RenderTarget2D EndRenderTarget( string key, bool drawToSpriteBatch = true, bool clearGraphics = true, Color?clearColor = null, ClearOptions clearOptions = ClearOptions.DepthBuffer | ClearOptions.Stencil | ClearOptions.Target, float depth = 0f, int stencil = 0) { if (GetRenderTargetManager.GetRenderTarget2D(key) == null || GetRenderTargetManager.RenderTargets[key].IsRefreshing || !GetRenderTargetManager.RenderTargets[key].Enabled) { return(null); } graphics.SetRenderTarget(SwapChainRenderTarget); if (clearGraphics) { graphics.Clear(clearOptions, clearColor ?? BackgroundColor, depth, stencil); } if (drawToSpriteBatch) { spriteBatch.Begin(); spriteBatch.Draw(GetRenderTargetManager.GetRenderTarget2D(key), Vector2.Zero, Color.White); spriteBatch.End(); } return(GetRenderTargetManager.GetRenderTarget2D(key)); }
/// <summary> /// Everything between <c>BeginRenderTarget()</c> and <c>EndRenderTarget()</c> will be drawn to the <see cref="RenderTarget2D"/>. /// </summary> /// <example> /// <code> /// protected override void Draw() /// { /// base.Draw(); /// /// Editor.BeginRenderTarget("MyRenderTarget"); /// /// Editor.spriteBatch.Begin(); /// /// //Your drawings /// /// Editor.spriteBatch.End(); /// /// Editor.EndRenderTarget("MyRenderTarget", false); /// } /// </code> /// </example> /// <param name="key">Please enter a previously set key of the <see cref="RenderTarget2D"/> you want to begin with.</param> /// <param name="clearGraphics"><c>false</c> if you don't want to to call <see cref="graphics"/>.Clear() after setting the <see cref="RenderTarget2D"/>.</param> /// <param name="clearColor">The <see cref="Color"/> to be used to clear the <see cref="graphics"/> after setting the <see cref="RenderTarget2D"/>.</param> public void BeginRenderTarget(string key, bool clearGraphics = true, Color?clearColor = null) { if (GetRenderTargetManager.GetRenderTarget2D(key) == null || GetRenderTargetManager.RenderTargets[key].IsRefreshing || !GetRenderTargetManager.RenderTargets[key].Enabled) { return; } graphics.SetRenderTarget(GetRenderTargetManager.GetRenderTarget2D(key)); if (clearGraphics) { graphics.Clear(clearColor ?? BackgroundColor); } }
/// <summary> /// Everything between <c>BeginRenderTarget()</c> and <c>EndRenderTarget()</c> will be drawn to the <see cref="RenderTarget2D"/>. /// </summary> /// <example> /// <code> /// protected override void Draw() /// { /// base.Draw(); /// /// Editor.BeginRenderTarget("MyRenderTarget"); /// /// Editor.spriteBatch.Begin(); /// /// //Your drawings /// /// Editor.spriteBatch.End(); /// /// Editor.EndRenderTarget("MyRenderTarget", false); /// } /// </code> /// </example> /// <param name="key">Please enter a previously set key of the <see cref="RenderTarget2D"/> you want to begin with.</param> /// <param name="clearGraphics"><c>false</c> if you don't want to to call <see cref="graphics"/>.Clear() after setting the <see cref="RenderTarget2D"/>.</param> /// <param name="clearColor">The <see cref="Color"/> to be used to clear the <see cref="graphics"/> after setting the <see cref="RenderTarget2D"/>.</param> /// <param name="clearOptions">Define your custom <see cref="ClearOptions"/>.</param> /// <param name="depth">The depth.</param> /// <param name="stencil">The stencil</param> public void BeginRenderTarget( string key, bool clearGraphics = true, Color?clearColor = null, ClearOptions clearOptions = ClearOptions.DepthBuffer | ClearOptions.Stencil | ClearOptions.Target, float depth = 0f, int stencil = 0) { if (GetRenderTargetManager.GetRenderTarget2D(key) == null || GetRenderTargetManager.RenderTargets[key].IsRefreshing || !GetRenderTargetManager.RenderTargets[key].Enabled) { return; } graphics.SetRenderTarget(GetRenderTargetManager.GetRenderTarget2D(key)); if (clearGraphics) { graphics.Clear(clearOptions, clearColor ?? BackgroundColor, depth, stencil); } }