Skip to content

Commit 9224524

Browse files
[Rendering] Restore some APIs;
1 parent cca9696 commit 9224524

File tree

4 files changed

+45
-69
lines changed

4 files changed

+45
-69
lines changed

Engine/Staple.Core/Rendering/Mesh/Mesh.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ namespace Staple;
1212
/// </summary>
1313
public sealed partial class Mesh : IGuidAsset
1414
{
15+
public struct StandardVertex
16+
{
17+
public Vector3 position;
18+
public Vector2 uv;
19+
public Vector3 normal;
20+
public Vector3 tangent;
21+
public Vector3 bitangent;
22+
public Color color;
23+
}
24+
25+
public static Lazy<VertexLayout> StandardVertexLayout = new(() =>
26+
{
27+
return VertexLayoutBuilder.CreateNew()
28+
.Add(VertexAttribute.Position, VertexAttributeType.Float3)
29+
.Add(VertexAttribute.TexCoord0, VertexAttributeType.Float2)
30+
.Add(VertexAttribute.Normal, VertexAttributeType.Float3)
31+
.Add(VertexAttribute.Tangent, VertexAttributeType.Float3)
32+
.Add(VertexAttribute.Bitangent, VertexAttributeType.Float3)
33+
.Add(VertexAttribute.Color0, VertexAttributeType.Float4)
34+
.Build();
35+
});
36+
1537
/// <summary>
1638
/// Whether this mesh is readable by the CPU
1739
/// </summary>

Engine/Staple.Core/Rendering/RenderSystem/Backend/Impls/SDLGPU/SDLGPURendererBackend.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ public void CreateBuffers()
393393
private readonly TextureResource[] textures = new TextureResource[ushort.MaxValue - 1];
394394

395395
private bool iteratingCommands = false;
396+
private int commandIndex;
396397

397398
public bool SupportsTripleBuffering => SDL.SDL_WindowSupportsGPUPresentMode(device, window.window,
398399
SDL.SDL_GPUPresentMode.SDL_GPU_PRESENTMODE_MAILBOX);
@@ -626,14 +627,15 @@ public void Destroy()
626627

627628
private void AddCommand(IRenderCommand command)
628629
{
630+
//If we're iterating, add the new command in front of the current one
629631
if(iteratingCommands)
630632
{
631-
Log.Error($"[Rendering] Adding a command to the command list while iterating the list!");
632-
633-
return;
633+
commands.Insert(commandIndex + 1, command);
634+
}
635+
else
636+
{
637+
commands.Add(command);
634638
}
635-
636-
commands.Add(command);
637639
}
638640

639641
public void BeginFrame()
@@ -675,9 +677,11 @@ public void EndFrame()
675677

676678
iteratingCommands = true;
677679

678-
foreach (var command in commands)
680+
for(var i = 0; i < commands.Count; i++)
679681
{
680-
command.Update(this);
682+
commandIndex = i;
683+
684+
commands[i].Update(this);
681685
}
682686

683687
iteratingCommands = false;

Engine/Staple.Core/Rendering/Text/TextRenderer.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -470,24 +470,10 @@ public void DrawText(string text, Matrix4x4 transform, TextParameters parameters
470470

471471
if (MakeTextGeometry(text, parameters, scale, flipY, out var vertices, out var indices))
472472
{
473-
/*
474-
if(VertexBuffer.TransientBufferHasSpace(vertices.Length, VertexLayout.Value) &&
475-
IndexBuffer.TransientBufferHasSpace(indices.Length, false))
476-
{
477-
var vertexBuffer = VertexBuffer.CreateTransient(vertices.AsSpan(), VertexLayout.Value);
478-
var indexBuffer = IndexBuffer.CreateTransient(indices);
479-
480-
if(vertexBuffer == null || indexBuffer == null)
481-
{
482-
return;
483-
}
484-
485-
material.MainTexture = font.Texture;
473+
material.MainTexture = font.Texture;
486474

487-
Graphics.RenderGeometry(vertexBuffer, indexBuffer, 0, vertices.Length, 0, indices.Length,
488-
material, Vector3.Zero, transform, MeshTopology.Triangles, MaterialLighting.Unlit, viewID);
489-
}
490-
*/
475+
Graphics.RenderSimple(vertices, VertexLayout.Value, indices, material, Vector3.Zero, transform, MeshTopology.Triangles,
476+
MaterialLighting.Unlit);
491477
}
492478
}
493479

Engine/Staple.Core/UI/UIPanel+API.cs

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ protected void DrawSprite(Vector2Int position, Vector2Int size, Texture texture,
3131
vertices[3].position = new(size.X, size.Y, 0);
3232
vertices[3].uv = new(1, 1);
3333

34-
/*
35-
var vertexBuffer = VertexBuffer.CreateTransient(vertices.AsSpan(), SpriteUtils.VertexLayout.Value);
36-
37-
var indexBuffer = IndexBuffer.CreateTransient(indices);
38-
39-
if (vertexBuffer == null || indexBuffer == null)
40-
{
41-
return;
42-
}
43-
4434
var c = material.MainColor;
4535
var t = material.MainTexture;
4636

@@ -50,13 +40,11 @@ protected void DrawSprite(Vector2Int position, Vector2Int size, Texture texture,
5040
material.DisableShaderKeyword(Shader.SkinningKeyword);
5141
material.DisableShaderKeyword(Shader.InstancingKeyword);
5242

53-
Graphics.RenderGeometry(vertexBuffer, indexBuffer, 0, 4, 0, 6, material, Vector3.Zero,
54-
Matrix4x4.CreateTranslation(new Vector3(position.X, position.Y, 0)), MeshTopology.Triangles, MaterialLighting.Unlit,
55-
Manager.ViewID);
43+
Graphics.RenderSimple(vertices, SpriteUtils.VertexLayout.Value, indices, material, Vector3.Zero,
44+
Matrix4x4.CreateTranslation(new Vector3(position.X, position.Y, 0)), MeshTopology.Triangles, MaterialLighting.Unlit);
5645

5746
material.MainColor = c;
5847
material.MainTexture = t;
59-
*/
6048
}
6149

6250
/// <summary>
@@ -85,16 +73,6 @@ protected void DrawSprite(Vector2Int position, Vector2Int size, Texture texture,
8573
vertices[3].position = new(size.X, size.Y, 0);
8674
vertices[3].uv = new(rect.right / (float)texture.Width, rect.bottom / (float)texture.Height);
8775

88-
/*
89-
var vertexBuffer = VertexBuffer.CreateTransient(vertices.AsSpan(), SpriteUtils.VertexLayout.Value);
90-
91-
var indexBuffer = IndexBuffer.CreateTransient(indices);
92-
93-
if (vertexBuffer == null || indexBuffer == null)
94-
{
95-
return;
96-
}
97-
9876
var c = material.MainColor;
9977
var t = material.MainTexture;
10078

@@ -104,13 +82,11 @@ protected void DrawSprite(Vector2Int position, Vector2Int size, Texture texture,
10482
material.DisableShaderKeyword(Shader.SkinningKeyword);
10583
material.DisableShaderKeyword(Shader.InstancingKeyword);
10684

107-
Graphics.RenderGeometry(vertexBuffer, indexBuffer, 0, 4, 0, 6, material, Vector3.Zero,
108-
Matrix4x4.CreateTranslation(new Vector3(position.X, position.Y, 0)), MeshTopology.Triangles, MaterialLighting.Unlit,
109-
Manager.ViewID);
85+
Graphics.RenderSimple(vertices, SpriteUtils.VertexLayout.Value, indices, material, Vector3.Zero,
86+
Matrix4x4.CreateTranslation(new Vector3(position.X, position.Y, 0)), MeshTopology.Triangles, MaterialLighting.Unlit);
11087

11188
material.MainColor = c;
11289
material.MainTexture = t;
113-
*/
11490
}
11591

11692
/// <summary>
@@ -147,14 +123,10 @@ protected void DrawSpriteSliced(Vector2Int position, Vector2Int size, Texture te
147123
var vertexBuffer = VertexBuffer.CreateTransient(ninePatchVertices.AsSpan(), SpriteUtils.VertexLayout.Value);
148124
149125
var indexBuffer = IndexBuffer.CreateTransient(ninePatchIndices);
126+
*/
150127

151128
material ??= new(SpriteUtils.DefaultMaterial.Value);
152129

153-
if (vertexBuffer == null || indexBuffer == null)
154-
{
155-
return;
156-
}
157-
158130
var c = material.MainColor;
159131
var t = material.MainTexture;
160132

@@ -164,13 +136,11 @@ protected void DrawSpriteSliced(Vector2Int position, Vector2Int size, Texture te
164136
material.DisableShaderKeyword(Shader.SkinningKeyword);
165137
material.DisableShaderKeyword(Shader.InstancingKeyword);
166138

167-
Graphics.RenderGeometry(vertexBuffer, indexBuffer, 0, ninePatchVertices.Length, 0, ninePatchIndices.Length, material, Vector3.Zero,
168-
Matrix4x4.CreateTranslation(new Vector3(position.X, position.Y, 0)), MeshTopology.Triangles, MaterialLighting.Unlit,
169-
Manager.ViewID);
139+
Graphics.RenderSimple(ninePatchVertices, SpriteUtils.VertexLayout.Value, ninePatchIndices, material, Vector3.Zero,
140+
Matrix4x4.CreateTranslation(new Vector3(position.X, position.Y, 0)), MeshTopology.Triangles, MaterialLighting.Unlit);
170141

171142
material.MainColor = c;
172143
material.MainTexture = t;
173-
*/
174144
}
175145

176146
/// <summary>
@@ -225,15 +195,9 @@ protected void RenderText(string str, TextParameters parameters)
225195
return;
226196
}
227197

228-
/*
229-
var vertexBuffer = VertexBuffer.CreateTransient(textVertices.AsSpan(), TextRenderer.VertexLayout.Value);
230-
231-
var indexBuffer = IndexBuffer.CreateTransient(textIndices);
232-
233198
material.MainTexture = texture;
234199

235-
Graphics.RenderGeometry(vertexBuffer, indexBuffer, 0, vertexCount, 0, indexCount, material, Vector3.Zero,
236-
Matrix4x4.Identity, MeshTopology.Triangles, MaterialLighting.Unlit, Manager.ViewID);
237-
*/
200+
Graphics.RenderSimple(textVertices, TextRenderer.VertexLayout.Value, textIndices, material, Vector3.Zero,
201+
Matrix4x4.Identity, MeshTopology.Triangles, MaterialLighting.Unlit);
238202
}
239203
}

0 commit comments

Comments
 (0)