public void DrawFrameCached(SliceFrame sliceFrame, Point size, ref Texture2D texture) { // If the given texture is null, create a new one. if (texture == null) { texture = graphicsDevice.Adapter.QueryRenderTargetFormat(graphicsDevice.GraphicsProfile, SurfaceFormat.Color, DepthFormat.None, 0, out SurfaceFormat supportedFormat, out DepthFormat supportedDepth, out int supportedSample) ? new RenderTarget2D(graphicsDevice, size.X, size.Y) : new RenderTarget2D(graphicsDevice, size.X, size.Y, false, supportedFormat, supportedDepth, supportedSample, RenderTargetUsage.DiscardContents); } // Set the render target to the given texture. if (!(texture is RenderTarget2D renderTarget)) { throw new ArgumentException("Given texture was not a render target."); } graphicsDevice.SetRenderTarget(renderTarget); // Clear the target. graphicsDevice.Clear(Color.Transparent); // Begin the spritebatch. creatorSpriteBatch.Begin(); // Create the destination rectangle, which is simply the size of the element. Rectangle destination = new Rectangle(Point.Zero, size); // Draw the frame. drawNineSlice(sliceFrame.Image, sliceFrame.NineSlice, destination, creatorSpriteBatch, null, null); // End the spritebatch, drawing to the texture. creatorSpriteBatch.End(); // Set the target to null, resetting it. graphicsDevice.SetRenderTarget(null); }
public static void DrawFrameOnDemand(SliceFrame sliceFrame, Rectangle destinationRectangle, IGuiCamera camera, Color?colour) => drawNineSlice(sliceFrame.Image, sliceFrame.NineSlice, destinationRectangle, null, camera, colour);