Began trying to fix primitive batch. Added a default camera to the configuration.

This commit is contained in:
2019-01-30 07:46:58 -06:00
parent 8387cbc604
commit e1e2bbb3d7
13 changed files with 68 additions and 40 deletions

View File

@@ -20,21 +20,22 @@ namespace RecrownedAthenaeum.Render
BasicEffect basicEffect;
PrimitiveType primitiveType;
int verticesPerPrimitive;
GraphicsDevice graphicsDevice = Configuration.graphicsDeviceManager.GraphicsDevice;
GraphicsDevice graphicsDevice;
bool began;
bool disposed;
/// <summary>
/// Creates a batch used to draw primitives.
/// </summary>
/// <param name="camera">The current camera being used.</param>
/// <param name="camera">The current camera being used. Will use default set in <see cref="Configuration"/> if left null.</param>
/// <param name="graphicsDevice">The graphics device used to draw the primitives. Will be using <see cref="Configuration"/>'s graphics device from graphics device manager if null. Default is null.</param>
/// <param name="verticesPerBatch">The amount of vertices every batch can hold before flushing. Default is 450. Should be changed to be the most optimal number if possible to prevent unnecessary resizing. Especially if using strip primitive types.</param>
public PrimitiveBatch(Camera2D camera, GraphicsDevice graphicsDevice = null, int verticesPerBatch = 500)
public PrimitiveBatch(Camera2D camera = null, GraphicsDevice graphicsDevice = null, int verticesPerBatch = 500)
{
if (graphicsDevice != null) this.graphicsDevice = graphicsDevice;
if (this.graphicsDevice == null) throw new ArgumentNullException("Graphics device can't be null in setup and argument. One must not be null for use.");
basicEffect = new BasicEffect(graphicsDevice);
this.graphicsDevice = graphicsDevice ?? (Configuration.GraphicsDeviceManager.GraphicsDevice);
camera = camera ?? (Configuration.Camera2D);
basicEffect = new BasicEffect(this.graphicsDevice);
basicEffect.VertexColorEnabled = true;
basicEffect.View = camera.Matrix;
@@ -93,9 +94,8 @@ namespace RecrownedAthenaeum.Render
throw new InvalidOperationException("Buffer size isn't large enough.");
}
}
vertices[bufferPosition] = new VertexPositionColor(new Vector3(vertex, 0), color);
bufferPosition++;
vertices.Add(new VertexPositionColor(new Vector3(vertex, 0), color));
bufferPosition = vertices.Count;
}
/// <summary>

View File

@@ -29,7 +29,7 @@ namespace RecrownedAthenaeum.Render
/// Begins the render batch.
/// </summary>
/// <param name="filled">Whether or not to fill the rectangle.</param>
public void Begin(bool filled)
public void Begin(bool filled = false)
{
filling = filled;
if (began) throw new InvalidOperationException("Cannot begin twice.");
@@ -75,7 +75,8 @@ namespace RecrownedAthenaeum.Render
primitiveBatch.AddVertex(corners[2], color);
primitiveBatch.AddVertex(corners[0], color);
primitiveBatch.AddVertex(corners[3], color);
} else
}
else
{
primitiveBatch.AddVertex(corners[0], color);
primitiveBatch.AddVertex(corners[1], color);