Skip to content

Commit d85dc19

Browse files
committed
Update
1 parent d46eb3c commit d85dc19

File tree

11 files changed

+98
-44
lines changed

11 files changed

+98
-44
lines changed

GAIL/Application.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void Initialize(AppInfo? appInfo = null, (string windowTitle, int width,
134134
/// </summary>
135135
public void Start() {
136136
if (!IsDisposed) {
137-
Logger.LogError("Cannot start the application if it is disposed or initialized.");
137+
Logger.LogError("Cannot start the application if it is disposed or not initialized.");
138138
return;
139139
}
140140

@@ -211,7 +211,7 @@ public void Start() {
211211
/// Stops the application (see: <see cref="Dispose"/>).
212212
/// </summary>
213213
public void Stop() {
214-
Dispose();
214+
Dispose(); // TODO: implement a correct way of stopping.
215215
}
216216

217217
/// <inheritdoc/>

GAIL/GAIL.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<None Include="GAIL.nuspec" Pack="true" PackagePath="\" />
24+
<None Include="GAIL.nuspec" Pack="true" PackagePath="/" />
25+
<PackageReference Include="LambdaKit.Assertion" Version="5.0.0" />
2526
<PackageReference Include="LambdaKit.Logging" Version="5.0.0" />
2627
<PackageReference Include="Silk.NET" Version="2.22.0" /> <!-- TODO: Subdivide Silk.NET into smaller pieces (also in nuspec). -->
2728
<PackageReference Include="Silk.NET.Assimp" Version="2.22.0" /> <!-- is this used? -->

GAIL/Graphics/GraphicsManager.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using System.Runtime.InteropServices;
21
using GAIL.Core;
3-
using GAIL.Graphics.Layer;
42
using GAIL.Graphics.Material;
53
using GAIL.Graphics.Renderer;
64
using GAIL.Graphics.Renderer.Layer;
75
using GAIL.Graphics.Renderer.Vulkan;
6+
using LambdaKit.Assertion;
87
using LambdaKit.Logging;
9-
using Silk.NET.GLFW;
108

119
namespace GAIL.Graphics
1210
{
@@ -60,7 +58,7 @@ public void Initialize(Application.Globals globals, ref AppInfo appInfo, uint ma
6058

6159
IsDisposed = false;
6260

63-
globals.windowManager.OnFramebufferResize += (int width, int height) => {
61+
globals.windowManager.OnFramebufferResize += (width, height) => {
6462
Renderer.Resize(width, height);
6563
};
6664
}
@@ -70,19 +68,29 @@ public void Initialize(Application.Globals globals, ref AppInfo appInfo, uint ma
7068
public void Update() {
7169
Renderer!.Render();
7270
}
71+
7372
/// <summary>
7473
/// Creates a rasterization layer.
7574
/// </summary>
7675
/// <param name="settings">The default settings of the layer.</param>
7776
/// <returns>The created rasterization layer, if it succeeded in creating a rasterization layer.</returns>
78-
public IRasterizationLayer? CreateRasterizationLayer(RasterizationLayerSettings settings) {
77+
public IRasterizationLayer CreateRasterizationLayer(RasterizationLayerSettings settings) {
7978
if (Renderer == null) {
8079
Logger.LogError("Renderer is not initialized.");
8180
return default;
8281
}
83-
82+
8483
return Renderer.CreateRasterizationLayer(settings);
8584
}
85+
public IShader CreateShader(byte[] vertexShader, byte[]? fragmentShader = null, byte[]? geometryShader = null) {
86+
if (Renderer == null) {
87+
Logger.LogError("Renderer is not initialized.");
88+
return default;
89+
}
90+
91+
Assert.Throws(() => Renderer.CreateShader(vertexShader, fragmentShader, geometryShader))
92+
}
93+
8694

8795
/// <inheritdoc/>
8896
public void Dispose() {

GAIL/Graphics/Layer/Layer2D.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GAIL.Graphics.Material;
12
using GAIL.Graphics.Renderer.Layer;
23

34
namespace GAIL.Graphics.Layer;
@@ -6,6 +7,10 @@ namespace GAIL.Graphics.Layer;
67
/// A layer for 2D graphics.
78
/// </summary>
89
public class Layer2D : ILayer<IRasterizationLayer> {
10+
public static Layer2D Create(GraphicsManager manager, IShader shader) {
11+
Layer2D layer = new();
12+
manager.CreateRasterizationLayer(new() { Shaders = shader});
13+
}
914
/// <summary>
1015
/// If this 2D layer is disposed.
1116
/// </summary>
@@ -25,8 +30,14 @@ public void Initialize(IRasterizationLayer backendLayer) {
2530
this.backendLayer = backendLayer;
2631
}
2732

33+
/// <summary>
34+
///
35+
/// </summary>
36+
/// <param name="obj"></param>
37+
/// <exception cref="NullReferenceException"></exception>
2838
public void Render(Object obj) {
29-
39+
if (backendLayer == null) throw new NullReferenceException("Layer is not initialized");
40+
backendLayer.Render(obj);
3041
}
3142

3243
/// <inheritdoc/>

GAIL/Graphics/Material/Material.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System.Collections.ObjectModel;
2-
using GAIL.Core;
3-
using OxDED.Terminal.Assertion;
42

53
namespace GAIL.Graphics.Material;
64

@@ -18,25 +16,24 @@ public interface IMaterial {
1816
/// Contains information about how anything is drawn to the window, contains the shader and shader data.
1917
/// </summary>
2018
public abstract class Material : IMaterial {
21-
// private static IShader CreateShader(GraphicsManager manager, byte[] vertexShader, byte[]? fragmentShader = null, byte[]? geometryShader = null) {
22-
// IShader shader = Assert.IsNotNull(manager.CreateShader(vertexShader, fragmentShader, geometryShader)).OnFailure((Assertion _) => {
23-
// manager.Logger.LogError("Failed to create shader.");
24-
// throw new InvalidOperationException("Failed to create shader.");
25-
// }).As<ReferenceAssertion<IShader?>>()!.Asserter().value!;
26-
// return shader;
19+
// private static IShader CreateShader(GraphicsManager manager, ) {
20+
//
2721
// }
2822

23+
public readonly IShader Shader;
24+
25+
/// <inheritdoc/>
26+
public virtual ReadOnlyCollection<AttributeType> RequiredUniforms => Shader.RequiredUniforms;
27+
2928
/// <summary>
3029
/// Creates a new material.
3130
/// </summary>
32-
/// <param name="manager">The graphics manager used to create the shaders.</param>
33-
/// <param name="vertexShader">The per-vertex shader (in SPIR-V compiled).</param>
34-
/// <param name="fragmentShader">The per-pixel shader (in SPIR-V compiled).</param>
35-
/// <param name="geometryShader">The geometry shader (in SPIR-V compiled).</param>
36-
protected Material(GraphicsManager manager, byte[] vertexShader, byte[]? fragmentShader = null, byte[]? geometryShader = null) {
37-
31+
/// <param name="shader">The shader corresponding to this material.</param>
32+
protected Material(IShader shader) {
33+
Shader = shader;
3834
}
3935

40-
/// <inheritdoc/>
41-
public virtual ReadOnlyCollection<AttributeType> RequiredUniforms => RequiredUniforms;
36+
protected bool SetUniform() {
37+
38+
}
4239
}

GAIL/Graphics/Renderer/IRenderer.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,36 @@ namespace GAIL.Graphics.Renderer;
77
/// Represents a class that can render stuff.
88
/// </summary>
99
public interface IRenderer<TBackendLayer> : IDisposable where TBackendLayer : IBackendLayer {
10-
/// <summary>
11-
/// Renders the current frame.
12-
/// </summary>
13-
public void Render();
1410
/// <summary>
1511
/// The settings of the renderer.
1612
/// </summary>
1713
public IRendererSettings<TBackendLayer> Settings { get; }
14+
15+
/// <summary>
16+
/// Renders the current frame.
17+
/// </summary>
18+
public void Render();
1819
/// <summary>
1920
/// Resizes the renderer output.
2021
/// </summary>
2122
/// <param name="width">The new width.</param>
2223
/// <param name="height">The new height.</param>
2324
public void Resize(int width, int height);
25+
2426
/// <summary>
2527
/// Creates a back-end rasterization layer for rendering.
2628
/// </summary>
2729
/// <returns>
28-
/// True, if it could create a back-end layer.
30+
/// The back-end rasterization layer, if it could create a back-end layer.
2931
/// </returns>
30-
/// <param name="settings">The initial settings values of the back-end rasterization layer settings</param>
32+
/// <param name="settings">The initial settings values of the back-end rasterization layer settings.</param>
3133
public IRasterizationLayer? CreateRasterizationLayer(RasterizationLayerSettings settings);
34+
/// <summary>
35+
/// Creates a shader from the following stages.
36+
/// </summary>
37+
/// <param name="vertexShader">The per-vertex shader (in SPIR-V compiled).</param>
38+
/// <param name="fragmentShader">The per-pixel shader (in SPIR-V compiled).</param>
39+
/// <param name="geometryShader">The geometry shader (in SPIR-V compiled).</param>
40+
/// <returns>The shader, if it could create a shader.</returns>
41+
public IShader? CreateShader(byte[] vertexShader, byte[]? fragmentShader = null, byte[]? geometryShader = null);
3242
}

GAIL/Graphics/Renderer/Layer/IRasterizationLayer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ public interface IRasterizationLayer : IBackendLayer {
88
/// The rasterization layer settings.
99
/// </summary>
1010
public IRasterizationLayerSettings Settings { get; }
11+
/// <summary>
12+
/// Renders an object.
13+
/// </summary>
14+
/// <param name="obj">The object to render.</param>
15+
/// <returns>Whether it succeeded.</returns>
16+
public bool Render(Object obj);
1117
}

GAIL/Graphics/Renderer/Layer/LayerSettings.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GAIL.Graphics.Material;
12
using GAIL.Graphics.Renderer.Vulkan;
23
using Silk.NET.Vulkan;
34

@@ -115,7 +116,7 @@ public interface IRasterizationLayerSettings {
115116
/// <summary>
116117
/// The shader stages to use for this layer.
117118
/// </summary>
118-
public Shader Shader { get; set; }
119+
public IShader Shader { get; set; }
119120

120121
}
121122
/// <summary>
@@ -141,7 +142,7 @@ public class RasterizationLayerSettings {
141142
/// <summary>
142143
/// The shader stages to use for this layer.
143144
/// </summary>
144-
public required Shader Shaders;
145+
public required IShader Shaders;
145146

146147
/// <summary>
147148
/// Creates new values of the rasterization layer settings.
@@ -196,11 +197,11 @@ protected RasterizationLayerSettings(TLayer layer, RasterizationLayerSettings va
196197
/// </summary>
197198
protected CullMode cullMode;
198199
/// <inheritdoc/>
199-
public virtual Shader Shader { get => shader; set => throw new NotImplementedException(); }
200+
public virtual IShader Shader { get => shader; set => throw new NotImplementedException(); }
200201
/// <summary>
201202
/// The shader stages to use for this layer.
202203
/// </summary>
203-
protected Shader shader;
204+
protected IShader shader;
204205
}
205206

206207
// TODO: Raytracing settings

GAIL/Graphics/Renderer/Vulkan/Layer/VulkanRasterizationLayer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,10 @@ public void Dispose() {
100100
IsDisposed = true;
101101
GC.SuppressFinalize(this);
102102
}
103+
104+
/// <inheritdoc/>
105+
public bool Render(Object obj)
106+
{
107+
throw new NotImplementedException();
108+
}
103109
}

GAIL/Graphics/Renderer/VulkanRenderer.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using GAIL.Core;
2+
using GAIL.Graphics.Material;
23
using GAIL.Graphics.Renderer.Layer;
34
using GAIL.Graphics.Renderer.Vulkan;
45
using GAIL.Graphics.Renderer.Vulkan.Layer;
@@ -188,6 +189,15 @@ public void Resize(int width, int height) {
188189
}
189190
device.shouldRecreateSwapchain = true;
190191
}
192+
private void RecreateSwapchain() {
193+
device.WaitIdle();
194+
195+
Swapchain.Dispose();
196+
197+
Swapchain = new SwapChain(this, globals.windowManager);
198+
Swapchain.CreateFramebuffers(RenderPass);
199+
}
200+
191201
/// <inheritdoc/>
192202
public IRasterizationLayer? CreateRasterizationLayer(RasterizationLayerSettings settings) {
193203
try {
@@ -197,14 +207,10 @@ public void Resize(int width, int height) {
197207
return default;
198208
}
199209
}
200-
201-
private void RecreateSwapchain() {
202-
device.WaitIdle();
203-
204-
Swapchain.Dispose();
210+
/// <inheritdoc/>
211+
/// <exception cref="APIBackendException"/>
212+
public IShader CreateShader(byte[] vertexShader, byte[]? fragmentShader = null, byte[]? geometryShader = null) {
205213

206-
Swapchain = new SwapChain(this, globals.windowManager);
207-
Swapchain.CreateFramebuffers(RenderPass);
208214
}
209215

210216
/// <inheritdoc/>

0 commit comments

Comments
 (0)