mirror of
				https://github.com/MaddyThorson/StrawberryBF.git
				synced 2025-11-04 01:41:33 +08:00 
			
		
		
		
	Rendering Matrix stuff
This commit is contained in:
		@ -53,6 +53,7 @@ namespace Strawberry
 | 
			
		||||
			Path.GetDirectoryPath(exePath, exeDir);
 | 
			
		||||
			Directory.SetCurrentDirectory(exeDir);
 | 
			
		||||
 | 
			
		||||
			platformLayer.UpdateScreenMatrix();
 | 
			
		||||
			platformLayer.Init();
 | 
			
		||||
			Batcher = platformLayer.CreateBatcher();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -9,22 +9,24 @@ namespace Strawberry
 | 
			
		||||
 | 
			
		||||
	public struct Batch
 | 
			
		||||
	{
 | 
			
		||||
		public Mat4x4 Matrix;
 | 
			
		||||
		public int IndicesStart;
 | 
			
		||||
		public int IndicesCount;
 | 
			
		||||
		public Texture Texture;
 | 
			
		||||
		public BatchModes Mode;
 | 
			
		||||
 | 
			
		||||
		public this(BatchModes mode, Texture texture, int start)
 | 
			
		||||
		public this(Mat4x4 matrix, BatchModes mode, Texture texture, int start)
 | 
			
		||||
		{
 | 
			
		||||
			Matrix = matrix;
 | 
			
		||||
			Mode = mode;
 | 
			
		||||
			Texture = texture;
 | 
			
		||||
			IndicesStart = start;
 | 
			
		||||
			IndicesCount = 0;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public bool Matches(BatchModes mode, Texture texture)
 | 
			
		||||
		public bool Matches(Mat4x4 matrix, BatchModes mode, Texture texture)
 | 
			
		||||
		{
 | 
			
		||||
			return Mode == mode && Texture == texture;
 | 
			
		||||
			return Matrix == matrix && Mode == mode && Texture == texture;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,12 +8,27 @@ namespace Strawberry
 | 
			
		||||
		protected List<Vertex> vertices = new .() ~ delete _;
 | 
			
		||||
		protected List<uint32> indices = new .() ~ delete _;
 | 
			
		||||
 | 
			
		||||
		public Mat4x4 Matrix;
 | 
			
		||||
 | 
			
		||||
		public this()
 | 
			
		||||
		{
 | 
			
		||||
			Reset();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public void Reset()
 | 
			
		||||
		{
 | 
			
		||||
			Matrix = Game.PlatformLayer.ScreenMatrix;
 | 
			
		||||
			batches.Clear();
 | 
			
		||||
			vertices.Clear();
 | 
			
		||||
			indices.Clear();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public abstract void Draw();
 | 
			
		||||
 | 
			
		||||
		protected ref Batch GetBatch(BatchModes mode, Texture texture)
 | 
			
		||||
		{
 | 
			
		||||
			if (batches.Count == 0 || !batches.Back.Matches(mode, texture))
 | 
			
		||||
				batches.Add(Batch(mode, texture, indices.Count));
 | 
			
		||||
			if (batches.Count == 0 || !batches.Back.Matches(Matrix, mode, texture))
 | 
			
		||||
				batches.Add(Batch(Matrix, mode, texture, indices.Count));
 | 
			
		||||
			return ref batches.Back;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,15 @@ namespace Strawberry
 | 
			
		||||
{
 | 
			
		||||
	public abstract class PlatformLayer
 | 
			
		||||
	{
 | 
			
		||||
		public Mat4x4 ScreenMatrix { get; private set; }
 | 
			
		||||
 | 
			
		||||
		public void UpdateScreenMatrix()
 | 
			
		||||
		{
 | 
			
		||||
			ScreenMatrix = Mat4x4.CreateOrthographic(Game.Width, Game.Height * 0.5f, 0, 1)
 | 
			
		||||
				* Mat4x4.CreateScale(.(1, -1, 1))
 | 
			
		||||
				* Mat4x4.CreateTranslation(.(-1, 1, 0));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public abstract void Init();
 | 
			
		||||
		public abstract bool Closed();			// Returns whether the game window has been closed
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -45,8 +45,10 @@ namespace Strawberry.SDL2
 | 
			
		||||
			GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
 | 
			
		||||
			GL.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.Count * sizeof(uint32), indices.Ptr, GL.GL_DYNAMIC_DRAW);
 | 
			
		||||
 | 
			
		||||
			for (let b in batches)
 | 
			
		||||
			for (var b in batches)
 | 
			
		||||
			{
 | 
			
		||||
				GL.glUniformMatrix4fv(platformLayer.TransformMatrixLocation, 1, GL.GL_FALSE, &b.Matrix.Values);
 | 
			
		||||
 | 
			
		||||
				if (b.Mode == .Shape)
 | 
			
		||||
					GL.glBindTexture(GL.GL_TEXTURE_2D, 0);
 | 
			
		||||
				else
 | 
			
		||||
@ -62,9 +64,7 @@ namespace Strawberry.SDL2
 | 
			
		||||
			
 | 
			
		||||
			GL.glBindVertexArray(0);
 | 
			
		||||
 | 
			
		||||
			vertices.Clear();
 | 
			
		||||
			indices.Clear();
 | 
			
		||||
			batches.Clear();
 | 
			
		||||
			Reset();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		protected override void PushQuad(BatchModes mode, Texture texture, Vertex a, Vertex b, Vertex c, Vertex d)
 | 
			
		||||
 | 
			
		||||
@ -154,12 +154,6 @@ namespace Strawberry.SDL2
 | 
			
		||||
			GL.glClearColor(Game.ClearColor.Rf, Game.ClearColor.Gf, Game.ClearColor.Bf, Game.ClearColor.Af);
 | 
			
		||||
			GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 | 
			
		||||
			GL.glUseProgram(glProgram);
 | 
			
		||||
 | 
			
		||||
			Mat4x4 mat = Mat4x4.CreateOrthographic(Game.Width, Game.Height * 0.5f, 0, 1);
 | 
			
		||||
			mat *= Mat4x4.CreateScale(.(1, -1, 1));
 | 
			
		||||
			mat *= Mat4x4.CreateTranslation(.(-1, 1, 0));
 | 
			
		||||
 | 
			
		||||
			GL.glUniformMatrix4fv(TransformMatrixLocation, 1, GL.GL_FALSE, &mat.Values);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public override void RenderEnd()
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user