Skip to content

Commit 549a89d

Browse files
[Rendering] Fixes to ImGUI;
1 parent cddf0b9 commit 549a89d

File tree

4 files changed

+82
-52
lines changed

4 files changed

+82
-52
lines changed

BuiltinResources/Hidden/Shaders/UI/imgui.shader

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Input
3030
{
3131
float3 position : POSITION;
3232
float2 coord : TEXCOORD0;
33-
int color : COLOR0;
33+
uint color : COLOR0;
3434
};
3535

3636
[shader("vertex")]
@@ -41,10 +41,10 @@ VertexOutput VertexMain(Input input)
4141
float3 position = input.position;
4242

4343
output.color = float4(
44-
(input.color & int(0xFF000000)) / 255.0,
45-
(input.color & int(0x00FF0000)) / 255.0,
46-
(input.color & int(0x0000FF00)) / 255.0,
47-
(input.color & int(0x000000FF)) / 255.0,
44+
(input.color & uint(0xFF000000)) / 255.0,
45+
(input.color & uint(0x00FF0000)) / 255.0,
46+
(input.color & uint(0x0000FF00)) / 255.0,
47+
(input.color & uint(0x000000FF)) / 255.0,
4848
);
4949

5050
output.coord = input.coord;

Engine/Staple.Core/Player/AppPlayer.cs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ internal class AppPlayer
1717

1818
private bool initialized = false;
1919

20-
public AppPlayer(string[] args, bool shouldConsoleLog)
20+
private readonly bool skipFlow;
21+
22+
public AppPlayer(string[] args, bool shouldConsoleLog, bool skipFlow)
2123
{
2224
instance = this;
2325

26+
#if _DEBUG
27+
this.skipFlow = skipFlow;
28+
#endif
29+
2430
Storage.Update(AppSettings.Current.appName, AppSettings.Current.companyName);
2531

2632
var path = Path.Combine(Storage.PersistentDataPath, "Player.log");
@@ -120,18 +126,21 @@ public void Create()
120126
ResetRendering(hasFocus);
121127
}
122128

123-
Scene.sceneList = ResourceManager.instance.LoadSceneList();
124-
125-
if (Scene.sceneList == null || Scene.sceneList.Count == 0)
129+
if(skipFlow == false)
126130
{
127-
Log.Error($"Failed to load scene list");
131+
Scene.sceneList = ResourceManager.instance.LoadSceneList();
128132

129-
renderWindow.shouldStop = true;
133+
if (Scene.sceneList == null || Scene.sceneList.Count == 0)
134+
{
135+
Log.Error($"Failed to load scene list");
130136

131-
throw new Exception("Failed to load scene list");
132-
}
137+
renderWindow.shouldStop = true;
138+
139+
throw new Exception("Failed to load scene list");
140+
}
133141

134-
Log.Info("Loaded scene list");
142+
Log.Info("Loaded scene list");
143+
}
135144

136145
if (Physics3D.ImplType != null && Physics3D.ImplType.IsAssignableTo(typeof(IPhysics3D)) == false)
137146
{
@@ -207,20 +216,23 @@ void HandleTypes<T>(string caption, Func<Type, bool> check, Action<T> callback)
207216
(typeof(IEntitySystemFixedUpdate).IsAssignableFrom(x) && x != typeof(IEntitySystemFixedUpdate))),
208217
(instance => EntitySystemManager.Instance.RegisterSystem(instance)));
209218

210-
var scene = ResourceManager.instance.LoadScene(Scene.sceneList[0]);
211-
212-
if (scene == null)
219+
if (skipFlow == false)
213220
{
214-
Log.Error($"Failed to load main scene");
221+
var scene = ResourceManager.instance.LoadScene(Scene.sceneList[0]);
215222

216-
renderWindow.shouldStop = true;
223+
if (scene == null)
224+
{
225+
Log.Error($"Failed to load main scene");
217226

218-
throw new Exception("Failed to load main scene");
219-
}
227+
renderWindow.shouldStop = true;
228+
229+
throw new Exception("Failed to load main scene");
230+
}
220231

221-
Scene.SetActiveScene(scene);
232+
Scene.SetActiveScene(scene);
222233

223-
Log.Info("Loaded first scene");
234+
Log.Info("Loaded first scene");
235+
}
224236

225237
Log.Info("Finished initializing");
226238

Engine/Staple.Core/Player/StaplePlayer.cs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ public static void Run(string[] args)
1919
baseDirectory = Environment.CurrentDirectory;
2020
#endif
2121

22+
var skipFlow =
23+
#if _DEBUG
24+
args.Any(x => x == "-skip-flow");
25+
#else
26+
false;
27+
#endif
28+
2229
try
2330
{
2431
var pakFiles = Directory.GetFiles(Path.Combine(baseDirectory, "Data"), "*.pak");
@@ -40,38 +47,49 @@ public static void Run(string[] args)
4047
Environment.Exit(1);
4148
}
4249

43-
try
50+
if(skipFlow == false)
4451
{
45-
var data = ResourceManager.instance.LoadFile("AppSettings");
52+
try
53+
{
54+
var data = ResourceManager.instance.LoadFile("AppSettings");
4655

47-
using var stream = new MemoryStream(data);
56+
using var stream = new MemoryStream(data);
4857

49-
var header = MessagePackSerializer.Deserialize<AppSettingsHeader>(stream);
58+
var header = MessagePackSerializer.Deserialize<AppSettingsHeader>(stream);
5059

51-
if (header == null || header.header.SequenceEqual(AppSettingsHeader.ValidHeader) == false ||
52-
header.version != AppSettingsHeader.ValidVersion)
53-
{
54-
throw new Exception($"Invalid app settings header");
55-
}
60+
if (header == null || header.header.SequenceEqual(AppSettingsHeader.ValidHeader) == false ||
61+
header.version != AppSettingsHeader.ValidVersion)
62+
{
63+
throw new Exception($"Invalid app settings header");
64+
}
5665

57-
AppSettings.Current = MessagePackSerializer.Deserialize<AppSettings>(stream);
66+
AppSettings.Current = MessagePackSerializer.Deserialize<AppSettings>(stream);
5867

59-
if(AppSettings.Current == null)
60-
{
61-
throw new Exception("Failed to deserialize app settings");
68+
if (AppSettings.Current == null)
69+
{
70+
throw new Exception("Failed to deserialize app settings");
71+
}
72+
73+
LayerMask.SetLayers(CollectionsMarshal.AsSpan(AppSettings.Current.layers),
74+
CollectionsMarshal.AsSpan(AppSettings.Current.sortingLayers));
6275
}
76+
catch (Exception e)
77+
{
78+
Platform.platformProvider.ConsoleLog($"Failed to load appsettings: {e}");
6379

64-
LayerMask.SetLayers(CollectionsMarshal.AsSpan(AppSettings.Current.layers), CollectionsMarshal.AsSpan(AppSettings.Current.sortingLayers));
80+
Environment.Exit(1);
81+
82+
return;
83+
}
6584
}
66-
catch (Exception e)
85+
else
6786
{
68-
Platform.platformProvider.ConsoleLog($"Failed to load appsettings: {e}");
69-
70-
Environment.Exit(1);
87+
AppSettings.Current = AppSettings.Default;
7188

72-
return;
89+
LayerMask.SetLayers(CollectionsMarshal.AsSpan(AppSettings.Current.layers),
90+
CollectionsMarshal.AsSpan(AppSettings.Current.sortingLayers));
7391
}
7492

75-
new AppPlayer(args, true).Run();
93+
new AppPlayer(args, true, skipFlow).Run();
7694
}
7795
}

Engine/Staple.Editor/ImGuiProxy.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,9 @@ public bool Initialize()
156156
layout = VertexLayoutBuilder.CreateNew()
157157
.Add(VertexAttribute.Position, VertexAttributeType.Float2)
158158
.Add(VertexAttribute.TexCoord0, VertexAttributeType.Float2)
159-
.Add(VertexAttribute.Color0, VertexAttributeType.Byte4)
159+
.Add(VertexAttribute.Color0, VertexAttributeType.UInt)
160160
.Build();
161161

162-
//textureUniform = bgfx.create_uniform("s_tex", bgfx.UniformType.Sampler, 1);
163-
164162
return true;
165163
}
166164

@@ -515,8 +513,9 @@ private void Render(ImDrawDataPtr drawData)
515513
}
516514
}
517515

518-
var ortho = Matrix4x4.CreateOrthographicOffCenter(drawData.DisplayPos.X, drawData.DisplayPos.X + drawData.DisplaySize.X,
519-
drawData.DisplayPos.Y + drawData.DisplaySize.Y, drawData.DisplayPos.Y, 0, 1000);
516+
var rect = new RectFloat(drawData.DisplayPos, drawData.DisplaySize);
517+
518+
var ortho = Matrix4x4.CreateOrthographicOffCenter(rect.Position.X, rect.Size.X, rect.Size.Y, rect.Position.Y, -1, 1);
520519

521520
var command = RenderSystem.Backend.BeginCommand();
522521

@@ -552,6 +551,8 @@ private void Render(ImDrawDataPtr drawData)
552551
var indexData = new Span<ushort>(cmdList.IdxBuffer.Data, cmdList.IdxBuffer.Size);
553552
var targetIndexData = new Span<ushort>(indices, currentIndex, cmdList.IdxBuffer.Size);
554553

554+
indexData.CopyTo(targetIndexData);
555+
555556
currentIndex += cmdList.IdxBuffer.Size;
556557
}
557558

@@ -564,7 +565,7 @@ private void Render(ImDrawDataPtr drawData)
564565

565566
if(needsUpdate == false)
566567
{
567-
vertexBuffer = RenderSystem.Backend.CreateVertexBuffer<ImDrawVert>(vertices, layout, RenderBufferFlags.None);
568+
vertexBuffer = RenderSystem.Backend.CreateVertexBuffer(vertices, layout, RenderBufferFlags.None);
568569
indexBuffer = RenderSystem.Backend.CreateIndexBuffer(indices, RenderBufferFlags.None);
569570
}
570571
else
@@ -663,17 +664,16 @@ public static ImTextureRef GetImGuiTexture(Texture texture)
663664
{
664665
unsafe
665666
{
666-
/*
667667
if (texture == null ||
668-
texture.handle.Valid == false ||
669668
texture.Disposed ||
670669
texture.metadata.readBack)
671-
*/
672670
{
673671
return new ImTextureRef(texId: ImTextureID.Null);
674672
}
675673

676674
//return new ImTextureRef(texId: new ImTextureID((ulong)texture.handle.idx));
675+
676+
return new ImTextureRef(texId: ImTextureID.Null);
677677
}
678678
}
679679

0 commit comments

Comments
 (0)