partial work toward keeping multiple render targets around for GIF encoding

GitOrigin-RevId: 8061896562453a95013ada91df852afc9e904c76
This commit is contained in:
Colin McMillen 2019-12-09 17:21:22 -05:00
parent 524ed70b9d
commit df6cee8df1

View File

@ -2,13 +2,16 @@
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Jumpy { namespace Jumpy {
public class JumpyGame : Game { public class JumpyGame : Game {
GraphicsDeviceManager graphics; GraphicsDeviceManager graphics;
RenderTarget2D renderTarget;
const int numRenderTargets = 1;
RenderTarget2D[] renderTargets = new RenderTarget2D[numRenderTargets];
int renderTargetIdx = 0;
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
SpriteFont font; SpriteFont font;
KeyboardInput keyboardInput = new KeyboardInput(); KeyboardInput keyboardInput = new KeyboardInput();
@ -30,9 +33,11 @@ namespace Jumpy {
display.Initialize(Window, graphics); display.Initialize(Window, graphics);
display.SetFullScreen(fullScreen); display.SetFullScreen(fullScreen);
renderTarget = new RenderTarget2D( for (int i = 0; i < renderTargets.Length; i++) {
GraphicsDevice, Camera.Width, Camera.Height, false /* mipmap */, renderTargets[i] = new RenderTarget2D(
GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); GraphicsDevice, Camera.Width, Camera.Height, false /* mipmap */,
GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
}
base.Initialize(); base.Initialize();
} }
@ -77,8 +82,9 @@ namespace Jumpy {
fpsCounter.Update(); fpsCounter.Update();
// Draw scene to RenderTarget. // Draw scene to RenderTarget.
RenderTarget2D renderTarget = renderTargets[renderTargetIdx];
renderTargetIdx = (renderTargetIdx + 1) % renderTargets.Length;
GraphicsDevice.SetRenderTarget(renderTarget); GraphicsDevice.SetRenderTarget(renderTarget);
// GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(); spriteBatch.Begin();
player.Draw(gameTime, spriteBatch); player.Draw(gameTime, spriteBatch);