mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-28 16:58:56 +08:00
Rendering Matrix stuff
This commit is contained in:
parent
0203ffbef7
commit
7603c2e795
|
@ -53,6 +53,7 @@ namespace Strawberry
|
||||||
Path.GetDirectoryPath(exePath, exeDir);
|
Path.GetDirectoryPath(exePath, exeDir);
|
||||||
Directory.SetCurrentDirectory(exeDir);
|
Directory.SetCurrentDirectory(exeDir);
|
||||||
|
|
||||||
|
platformLayer.UpdateScreenMatrix();
|
||||||
platformLayer.Init();
|
platformLayer.Init();
|
||||||
Batcher = platformLayer.CreateBatcher();
|
Batcher = platformLayer.CreateBatcher();
|
||||||
|
|
||||||
|
|
|
@ -9,22 +9,24 @@ namespace Strawberry
|
||||||
|
|
||||||
public struct Batch
|
public struct Batch
|
||||||
{
|
{
|
||||||
|
public Mat4x4 Matrix;
|
||||||
public int IndicesStart;
|
public int IndicesStart;
|
||||||
public int IndicesCount;
|
public int IndicesCount;
|
||||||
public Texture Texture;
|
public Texture Texture;
|
||||||
public BatchModes Mode;
|
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;
|
Mode = mode;
|
||||||
Texture = texture;
|
Texture = texture;
|
||||||
IndicesStart = start;
|
IndicesStart = start;
|
||||||
IndicesCount = 0;
|
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<Vertex> vertices = new .() ~ delete _;
|
||||||
protected List<uint32> indices = 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();
|
public abstract void Draw();
|
||||||
|
|
||||||
protected ref Batch GetBatch(BatchModes mode, Texture texture)
|
protected ref Batch GetBatch(BatchModes mode, Texture texture)
|
||||||
{
|
{
|
||||||
if (batches.Count == 0 || !batches.Back.Matches(mode, texture))
|
if (batches.Count == 0 || !batches.Back.Matches(Matrix, mode, texture))
|
||||||
batches.Add(Batch(mode, texture, indices.Count));
|
batches.Add(Batch(Matrix, mode, texture, indices.Count));
|
||||||
return ref batches.Back;
|
return ref batches.Back;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,15 @@ namespace Strawberry
|
||||||
{
|
{
|
||||||
public abstract class PlatformLayer
|
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 void Init();
|
||||||
public abstract bool Closed(); // Returns whether the game window has been closed
|
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.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
|
||||||
GL.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.Count * sizeof(uint32), indices.Ptr, GL.GL_DYNAMIC_DRAW);
|
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)
|
if (b.Mode == .Shape)
|
||||||
GL.glBindTexture(GL.GL_TEXTURE_2D, 0);
|
GL.glBindTexture(GL.GL_TEXTURE_2D, 0);
|
||||||
else
|
else
|
||||||
|
@ -62,9 +64,7 @@ namespace Strawberry.SDL2
|
||||||
|
|
||||||
GL.glBindVertexArray(0);
|
GL.glBindVertexArray(0);
|
||||||
|
|
||||||
vertices.Clear();
|
Reset();
|
||||||
indices.Clear();
|
|
||||||
batches.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PushQuad(BatchModes mode, Texture texture, Vertex a, Vertex b, Vertex c, Vertex d)
|
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.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.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
|
||||||
GL.glUseProgram(glProgram);
|
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()
|
public override void RenderEnd()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user