Commits

smack0007 committed c702235

Repurposed RendererSettings to be used to instruct the Renderer how to draw.

  • Participants
  • Parent commits 8691a86

Comments (0)

Files changed (4)

File Snowball/Graphics/Renderer.cs

 		}
 		
 		SlimDX.Direct3D9.VertexDeclaration vertexDeclaration;
-
-		RendererSettings settings;
+				
 		RendererMode mode;
 		Vertex[] vertices;
 		int vertexCount;
 		Color[] colorStack;
 		int colorStackCount;
 
+		RendererSettings settings;
+
 		public GraphicsDevice GraphicsDevice
 		{
 			get;
 			private set;
 		}
 
+		/// <summary>
+		/// Constructor.
+		/// </summary>
+		/// <param name="graphicsDevice"></param>
 		public Renderer(GraphicsDevice graphicsDevice)
-			: this(graphicsDevice, RendererSettings.Default)
+			: this(graphicsDevice, 1024, 8, 8)
 		{
 		}
-
-		public Renderer(GraphicsDevice graphicsDevice, RendererSettings settings)
+		
+		/// <summary>
+		/// Constructor.
+		/// </summary>
+		/// <param name="graphicsDevice"></param>
+		/// <param name="vertexBufferSize"></param>
+		/// <param name="matrixStackSize"></param>
+		/// <param name="colorStackSize"></param>
+		public Renderer(GraphicsDevice graphicsDevice, int vertexBufferSize, int matrixStackSize, int colorStackSize)
 		{
 			if(graphicsDevice == null)
 				throw new ArgumentNullException("graphicsDevice");
 				new SlimDX.Direct3D9.VertexElement(0, 16, SlimDX.Direct3D9.DeclarationType.Float2, SlimDX.Direct3D9.DeclarationMethod.Default, SlimDX.Direct3D9.DeclarationUsage.TextureCoordinate, 0),
 				SlimDX.Direct3D9.VertexElement.VertexDeclarationEnd
         	});
-						
-			this.settings = settings;
+			
 			this.mode = RendererMode.None;
-			this.vertices = new Vertex[settings.VertexBufferSize * 4];
+			this.vertices = new Vertex[vertexBufferSize * 4];
 			this.vertexCount = 0;
-			this.indices = new short[settings.VertexBufferSize * 6];
+			this.indices = new short[vertexBufferSize * 6];
 			this.texture = null;
 									
 			for(short i = 0, vertex = 0; i < this.indices.Length; i += 6, vertex += 4)
 				this.indices[i + 5] = (short)(vertex + 3);
 			}
 
-			this.matrixStack = new Matrix[settings.MatrixStackSize];
+			this.matrixStack = new Matrix[matrixStackSize];
 			this.matrixStackCount = 0;
 
-			this.colorStack = new Color[settings.ColorStackSize];
+			this.colorStack = new Color[colorStackSize];
 			this.colorStackCount = 0;
 		}
 
 				throw new InvalidOperationException("The GraphicsDevice has not yet began drawing.");
 		}
 
+		/// <summary>
+		/// Begins rendering.
+		/// </summary>
 		public void Begin()
 		{
+			this.Begin(RendererSettings.Default);
+		}
+
+		/// <summary>
+		/// Begins rendering.
+		/// </summary>
+		/// <param name="settings"></param>
+		public void Begin(RendererSettings settings)
+		{
+			if(settings == null)
+				throw new ArgumentNullException("settings");
+
 			this.EnsureGraphicsDeviceHasDrawBegun();
 
 			if(this.HasBegun)
 				throw new InvalidOperationException("Already within Begin / End pair.");
-						
+
+			this.settings = settings;
+			this.ApplyGraphicsState();
+
+			this.HasBegun = true;
+		}
+
+		private void ApplyGraphicsState()
+		{
 			this.GraphicsDevice.InternalDevice.SetRenderState(SlimDX.Direct3D9.RenderState.AlphaBlendEnable, true);
 			this.GraphicsDevice.InternalDevice.SetRenderState<SlimDX.Direct3D9.Blend>(SlimDX.Direct3D9.RenderState.SourceBlend, SlimDX.Direct3D9.Blend.SourceAlpha);
 			this.GraphicsDevice.InternalDevice.SetRenderState<SlimDX.Direct3D9.Blend>(SlimDX.Direct3D9.RenderState.DestinationBlend, SlimDX.Direct3D9.Blend.InverseSourceAlpha);
 			this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.AddressV, SlimDX.Direct3D9.TextureAddress.Clamp);
 			this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.AddressW, SlimDX.Direct3D9.TextureAddress.Clamp);
 
-			this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MinFilter, SlimDX.Direct3D9.TextureFilter.Linear);
-			this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MagFilter, SlimDX.Direct3D9.TextureFilter.Linear);
-			this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MipFilter, SlimDX.Direct3D9.TextureFilter.Linear);
-
-			this.HasBegun = true;
+			if(this.settings.TextureFilter == TextureFilter.Linear)
+			{
+				this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MinFilter, SlimDX.Direct3D9.TextureFilter.Linear);
+				this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MagFilter, SlimDX.Direct3D9.TextureFilter.Linear);
+				this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MipFilter, SlimDX.Direct3D9.TextureFilter.Linear);
+			}
+			else if(this.settings.TextureFilter == TextureFilter.Point)
+			{
+				this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MinFilter, SlimDX.Direct3D9.TextureFilter.Point);
+				this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MagFilter, SlimDX.Direct3D9.TextureFilter.Point);
+				this.GraphicsDevice.InternalDevice.SetSamplerState(0, SlimDX.Direct3D9.SamplerState.MipFilter, SlimDX.Direct3D9.TextureFilter.Point);
+			}
 		}
 
 		private void EnsureHasBegun()

File Snowball/Graphics/RendererSettings.cs

 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 
 namespace Snowball.Graphics
 {
-	public struct RendererSettings
+	/// <summary>
+	/// Used to instuct the Renderer class how to render.
+	/// </summary>
+	public class RendererSettings
 	{
-		public static readonly RendererSettings Default = new RendererSettings()
+		public static readonly RendererSettings Default = new RendererSettings();
+
+		/// <summary>
+		/// The function to use when pushing and popping Color(s).
+		/// </summary>
+		public ColorFunction ColorStackFunction
 		{
-			VertexBufferSize = 1024,
-			MatrixStackSize = 8,
-			ColorStackSize = 8,
-			ColorStackFunction = ColorFunction.Limit
-		};
+			get;
+			set;
+		}
 
-		public int VertexBufferSize;
-		public int MatrixStackSize;
-		public int ColorStackSize;
-		public ColorFunction ColorStackFunction;
+		/// <summary>
+		/// The type of texture filtering to use.
+		/// </summary>
+		public TextureFilter TextureFilter
+		{
+			get;
+			set;
+		}
+
+		/// <summary>
+		/// Constructor.
+		/// </summary>
+		public RendererSettings()
+		{
+			this.ColorStackFunction = ColorFunction.Limit;
+			this.TextureFilter = TextureFilter.Linear;
+		}
 	}
 }

File Snowball/Graphics/TextureFilter.cs

+using System;
+
+namespace Snowball.Graphics
+{
+	public enum TextureFilter
+	{
+		Linear,
+
+		Point
+	}
+}

File Snowball/Snowball.csproj

     <Compile Include="Color.cs" />
     <Compile Include="Content\ContentLoader.cs" />
     <Compile Include="Content\ContentTypeLoader.cs" />
+    <Compile Include="Graphics\TextureFliter.cs" />
     <Compile Include="Input\GamePadDeadZone.cs" />
     <Compile Include="Input\GamePadDevice.cs" />
     <Compile Include="Input\GamePadButtons.cs" />