Commits

smack0007  committed 8691a86

Removed CreateRenderTarget from GraphicsDevice and made RenderTarget constructor
public.

  • Participants
  • Parent commits deb1252

Comments (0)

Files changed (4)

File Snowball.Demo/DemoGame.cs

 
 			this.renderer = new Renderer(this.graphics);
 
-			this.renderTarget = this.graphics.CreateRenderTarget(200, 200);
+			this.renderTarget = new RenderTarget(this.graphics, 200, 200);
 			this.DrawRenderTarget();
 		}
 		

File Snowball/Graphics/GraphicsDevice.cs

 			this.EnsureDeviceCreated();
 			return TextureFont.FromStream(this, stream, colorKey);
 		}
-
-		/// <summary>
-		/// Creates a new RenderTarget.
-		/// </summary>
-		/// <param name="width"></param>
-		/// <param name="height"></param>
-		/// <returns></returns>
-		public RenderTarget CreateRenderTarget(int width, int height)
-		{
-			this.EnsureDeviceCreated();
-			return new RenderTarget(this, width, height);
-		}
 	}
 }

File Snowball/Graphics/IGraphicsDevice.cs

 		/// <param name="colorKey"></param>
 		/// <returns></returns>
 		TextureFont LoadTextureFont(Stream stream, Color? colorKey);
-
-		/// <summary>
-		/// Creates a new RenderTarget.
-		/// </summary>
-		/// <param name="width"></param>
-		/// <param name="height"></param>
-		/// <returns></returns>
-		RenderTarget CreateRenderTarget(int width, int height);
 	}
 }

File Snowball/Graphics/RenderTarget.cs

 	/// <summary>
 	/// A surface which can be drawn onto.
 	/// </summary>
-	public class RenderTarget : GameResource
+	public sealed class RenderTarget : GameResource
 	{
 		GraphicsDevice graphicsManager;
 
 		internal SlimDX.Direct3D9.Texture InternalTexture;
 		internal SlimDX.Direct3D9.RenderToSurface InternalRenderToSurface;
 
+		/// <summary>
+		/// The width of the render target.
+		/// </summary>
 		public int Width
 		{
 			get;
 			protected set;
 		}
 
+		/// <summary>
+		/// The height of the render target.
+		/// </summary>
 		public int Height
 		{
 			get;
 			protected set;
 		}
 
-		internal RenderTarget(GraphicsDevice graphicsManager, int width, int height)
+		/// <summary>
+		/// Constructor.
+		/// </summary>
+		/// <param name="graphicsDevice"></param>
+		/// <param name="width"></param>
+		/// <param name="height"></param>
+		public RenderTarget(GraphicsDevice graphicsDevice, int width, int height)
 			: base()
 		{
-			if(graphicsManager == null)
+			if(graphicsDevice == null)
 			{
-				throw new ArgumentNullException("graphicsManager");
+				throw new ArgumentNullException("graphicsDevice");
 			}
 
-			this.graphicsManager = graphicsManager;
+			this.graphicsManager = graphicsDevice;
 			this.Width = width;
 			this.Height = height;
 
 			this.CreateResources();
 
-			this.graphicsManager.DeviceLost += this.GraphicsManager_DeviceLost;
-			this.graphicsManager.DeviceReset += this.GraphicsManager_DeviceReset;
+			this.graphicsManager.DeviceLost += this.GraphicsDevice_DeviceLost;
+			this.graphicsManager.DeviceReset += this.GraphicsDevice_DeviceReset;
 		}
 
 		private void CreateResources()
 			this.InternalRenderToSurface = new SlimDX.Direct3D9.RenderToSurface(this.graphicsManager.InternalDevice, this.Width, this.Height, SlimDX.Direct3D9.Format.A8R8G8B8);
 
 			this.InternalTexture = new SlimDX.Direct3D9.Texture(this.graphicsManager.InternalDevice, this.Width, this.Height, 0, SlimDX.Direct3D9.Usage.RenderTarget,
-														SlimDX.Direct3D9.Format.A8R8G8B8, SlimDX.Direct3D9.Pool.Default);
+															    SlimDX.Direct3D9.Format.A8R8G8B8, SlimDX.Direct3D9.Pool.Default);
 		}
 				
 		protected override void Dispose(bool disposing)
 			if(disposing)
 			{
 				this.DestroyResources();
+
+				if(this.graphicsManager != null)
+				{
+					this.graphicsManager.DeviceLost -= this.GraphicsDevice_DeviceLost;
+					this.graphicsManager.DeviceReset -= this.GraphicsDevice_DeviceReset;
+					this.graphicsManager = null;
+				}
 			}
 		}
 
 			}
 		}
 
-		private void GraphicsManager_DeviceLost(object sender, EventArgs e)
+		private void GraphicsDevice_DeviceLost(object sender, EventArgs e)
 		{
 			this.DestroyResources();
 		}
 
-		private void GraphicsManager_DeviceReset(object sender, EventArgs e)
+		private void GraphicsDevice_DeviceReset(object sender, EventArgs e)
 		{
 			this.CreateResources();
 		}