Commits

smack0007 committed deb1252

BeginDraw is now used to the set the RenderTarget instead of having a sepearate
method.
Refactored some DeviceLost logic.

Comments (0)

Files changed (2)

Snowball.Demo/DemoGame.cs

 		}
 		
 		private void DrawRenderTarget()
-		{
-			this.graphics.SetRenderTarget(this.renderTarget);
-			
-			if(this.graphics.BeginDraw())
+		{			
+			if(this.graphics.BeginDraw(this.renderTarget))
 			{
 				this.graphics.Clear(Color.Blue);
 				this.renderer.Begin();
 				this.renderer.DrawLine(new Vector2(0, 0), new Vector2(200, 200), Color.Red);
 				this.renderer.End();
 				this.graphics.EndDraw();
-				this.graphics.SetRenderTarget(null);
 			}
 		}
 
 
 				this.starfield.Draw(this.renderer);
 				this.ship.Draw(this.renderer);
-				//this.renderer.DrawRenderTarget(this.renderTarget, Vector2.Zero, Color.White);
+				this.renderer.DrawRenderTarget(this.renderTarget, Vector2.Zero, Color.White);
 
 				this.console.Draw(this.renderer);
 

Snowball/Graphics/GraphicsDevice.cs

 			if(fullscreen)
 				this.window.AfterToggleFullscreen(true);
 
-			this.isDeviceLost = false;
+			this.IsDeviceLost = false;
 		}
 
 		/// <summary>
 				throw new InvalidOperationException("The graphics device has not yet been created.");
 		}
 
+		/// <summary>
+		/// Attempts to reset the graphics device.
+		/// </summary>
+		/// <returns></returns>
 		private bool ResetDevice()
 		{
 			if(!this.IsDeviceLost)
 
 			return false;
 		}
-
-		/// <summary>
-		/// Recovers the graphics device when it is lost.
-		/// </summary>
-		internal bool EnsureDeviceNotLost()
-		{
-			this.EnsureDeviceCreated();
-
-			if(this.isDeviceLost)
-				return this.ResetDevice();
-
-			return true;
-		}
-
+				
 		/// <summary>
 		/// Called when the client size of the IGameWindow changes.
 		/// </summary>
 				throw new InvalidOperationException("Not within BeginDraw / EndDraw pair.");
 		}
 
-		/// <summary>
-		/// Requests to begin drawing.
-		/// </summary>
-		public bool BeginDraw()
+		private bool DoBeginDraw()
 		{
 			this.EnsureDeviceCreated();
 
-			if(this.isDeviceLost)
+			if(this.IsDeviceLost && !this.ResetDevice())
 				return false;
 
 			if(this.HasDrawBegun)
 		}
 
 		/// <summary>
+		/// Requests to begin drawing.
+		/// </summary>
+		public bool BeginDraw()
+		{
+			return this.DoBeginDraw();
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="renderTarget"></param>
+		/// <returns></returns>
+		public bool BeginDraw(RenderTarget renderTarget)
+		{
+			if(renderTarget == null)
+				throw new ArgumentNullException("renderTarget");
+
+			this.RenderTarget = renderTarget;
+
+			return this.DoBeginDraw();
+		}
+
+		/// <summary>
 		/// Informs the manager drawing is ending.
 		/// </summary>
 		public void EndDraw()
 			else
 			{
 				this.RenderTarget.InternalRenderToSurface.EndScene(SlimDX.Direct3D9.Filter.None);
+				this.RenderTarget = null;
 			}
 
 			this.HasDrawBegun = false;
 			this.EnsureDeviceCreated();
 			return new RenderTarget(this, width, height);
 		}
-
-		/// <summary>
-		/// Sets the render target used in the next draw. Pass in null to use the backbuffer.
-		/// </summary>
-		/// <param name="renderTarget"></param>
-		public void SetRenderTarget(RenderTarget renderTarget)
-		{
-			this.EnsureDeviceCreated();
-
-			if(this.HasDrawBegun)
-				throw new InvalidOperationException("Render target cannot be set within BeginDraw / EndDraw pair.");
-
-			this.RenderTarget = renderTarget;
-		}
 	}
 }