Skip to content

Commit f8e8f34

Browse files
committed
commit
1 parent d85dc19 commit f8e8f34

22 files changed

+362
-129
lines changed

GAIL/Application.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using LambdaKit.Logging.Targets;
77
using LambdaKit.Terminal;
88

9+
// TODO: Add #if DEBUG when using LogDebug(string).
10+
911
namespace GAIL
1012
{
1113
/// <summary>
@@ -211,7 +213,7 @@ public void Start() {
211213
/// Stops the application (see: <see cref="Dispose"/>).
212214
/// </summary>
213215
public void Stop() {
214-
Dispose(); // TODO: implement a correct way of stopping.
216+
Dispose(); // layer.settings: implement a correct way of stopping.
215217
}
216218

217219
/// <inheritdoc/>
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ namespace GAIL.Graphics
44
/// The type of the attribute. <para/>
55
///
66
/// Long = 64-bit <br/>
7-
/// (Default) = 32-bit<br/>
7+
/// (Default) / Int = 32-bit<br/>
88
/// Short = 16-bit <br/>
99
/// Byte = 8-bit <para/>
1010
/// U- = unsigned (no negatives) <br/>
1111
/// -Float = signed, floating-point number <br/>
1212
/// Int (default) = signed, integer <br/>
1313
/// -(2, 3, 4) = multiple components
1414
/// </summary>
15-
public enum AttributeType {
15+
public enum FormatType : int {
1616
///
1717
Byte = Silk.NET.Vulkan.Format.R8Sint,
1818
///
@@ -104,6 +104,35 @@ public enum AttributeType {
104104
///
105105
Float4 = Silk.NET.Vulkan.Format.R32G32B32A32Sfloat,
106106
///
107-
LongFloat4 = Silk.NET.Vulkan.Format.R64G64B64A64Sfloat,
107+
LongFloat4 = Silk.NET.Vulkan.Format.R64G64B64A64Sfloat,
108+
}
109+
110+
/// <summary>
111+
/// Represents a class that describes a format.
112+
/// </summary>
113+
public class FormatInfo {
114+
/// <summary>
115+
/// The type of the format (see: <see cref="FormatType"/>).
116+
/// </summary>
117+
public FormatType type;
118+
/// <summary>
119+
/// The size of the type.
120+
/// </summary>
121+
public uint size;
122+
/// <summary>
123+
/// Creates a new format info.
124+
/// </summary>
125+
/// <param name="type">The type of the format (see: <see cref="FormatType"/>).</param>
126+
/// <param name="size">The size of the type.</param>
127+
public FormatInfo(FormatType type, uint size) {
128+
this.type = type;
129+
this.size = size;
130+
}
131+
/// <summary>
132+
/// Creates a new format info from a Vulkan type.
133+
/// </summary>
134+
/// <param name="type">The Vulkan type of the format.</param>
135+
/// <param name="size">The size of the type.</param>
136+
public FormatInfo(Silk.NET.Vulkan.Format type, uint size) : this((FormatType)type, size) { }
108137
}
109138
}

GAIL/Graphics/Material/IShader.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Immutable;
12
using System.Collections.ObjectModel;
23

34
namespace GAIL.Graphics.Material;
@@ -9,9 +10,9 @@ public interface IShader : IDisposable {
910
/// <summary>
1011
/// Which attributes a vertex must contain in order for this shader to work correctly.
1112
/// </summary>
12-
public ReadOnlyCollection<AttributeType> RequiredAttributes { get; }
13+
public ImmutableArray<FormatInfo> RequiredAttributes { get; }
1314
/// <summary>
1415
/// Which uniforms must be set in order for this shader to work correctly.
1516
/// </summary>
16-
public ReadOnlyCollection<AttributeType> RequiredUniforms { get; }
17+
public ImmutableArray<FormatInfo> RequiredUniforms { get; }
1718
}

GAIL/Graphics/Material/Material.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,26 @@ namespace GAIL.Graphics.Material;
77
/// </summary>
88
public interface IMaterial {
99
/// <summary>
10-
/// Which uniforms must be set in order for this shader to work correctly.
10+
/// Applies all the uniforms.
1111
/// </summary>
12-
public ReadOnlyCollection<AttributeType> RequiredUniforms { get; }
12+
/// <param name="shader">The shader of which to set the uniforms.</param>
13+
public abstract void Apply(IShader shader);
1314
}
1415

1516
/// <summary>
1617
/// Contains information about how anything is drawn to the window, contains the shader and shader data.
1718
/// </summary>
1819
public abstract class Material : IMaterial {
19-
// private static IShader CreateShader(GraphicsManager manager, ) {
20-
//
21-
// }
22-
23-
public readonly IShader Shader;
24-
25-
/// <inheritdoc/>
26-
public virtual ReadOnlyCollection<AttributeType> RequiredUniforms => Shader.RequiredUniforms;
2720

2821
/// <summary>
2922
/// Creates a new material.
3023
/// </summary>
31-
/// <param name="shader">The shader corresponding to this material.</param>
32-
protected Material(IShader shader) {
33-
Shader = shader;
34-
}
24+
protected Material() { }
3525

36-
protected bool SetUniform() {
26+
// protected bool SetUniform() {
3727

38-
}
28+
// }
29+
30+
/// <inheritdoc/>
31+
public abstract void Apply(IShader shader);
3932
}

GAIL/Graphics/Material/Uniform.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ namespace GAIL.Graphics.Material;
55
/// </summary>
66
public abstract class Uniform {
77
/// <summary>
8-
/// The type of this uniform.
8+
/// The info about the format of this uniform.
99
/// </summary>
10-
public AttributeType Type;
10+
public FormatInfo info;
1111
/// <summary>
1212
/// The value of this uniform.
1313
/// </summary>
14-
public byte[] Value;
14+
public byte[] value;
1515

1616
/// <summary>
1717
/// Creates a new Uniform
1818
/// </summary>
19-
/// <param name="type">The type of this uniform.</param>
19+
/// <param name="info">The info about the format of this uniform.</param>
2020
/// <param name="value">The value of this uniform.</param>
21-
public Uniform(AttributeType type, byte[] value) {
22-
Type = type;
23-
Value = value;
21+
public Uniform(FormatInfo info, byte[] value) {
22+
this.info = info;
23+
this.value = value;
2424
}
2525
}

GAIL/Graphics/Mesh/Attributes.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace GAIL.Graphics.Mesh
77
/// A basic position attribute (Float3).
88
/// </summary>
99
/// <param name="position">The position of this attribute.</param>
10-
public class PositionAttribute(Vector3 position) : VertexAttribute(AttributeType.Float3) {
10+
public class PositionAttribute(Vector3 position) : VertexAttribute(FormatType.Float3) {
1111
/// <summary>
1212
/// The color of this color attribute.
1313
/// </summary>
@@ -25,7 +25,7 @@ public override byte[] Use() {
2525
/// Creates a color attribute (Float4).
2626
/// </remarks>
2727
/// <param name="color">The color of this attribute.</param>
28-
public class ColorAttribute(Color color) : VertexAttribute(AttributeType.Float4) {
28+
public class ColorAttribute(Color color) : VertexAttribute(FormatType.Float4) {
2929
/// <summary>
3030
/// The color of this color attribute.
3131
/// </summary>
@@ -43,7 +43,7 @@ public override byte[] Use() {
4343
/// Creates a normal attribute.
4444
/// </remarks>
4545
/// <param name="normal">The normal vector of this attribute.</param>
46-
public class NormalAttribute(Vector3 normal) : VertexAttribute(AttributeType.Float3) {
46+
public class NormalAttribute(Vector3 normal) : VertexAttribute(FormatType.Float3) {
4747
/// <summary>
4848
/// The normal vector of this normal attribute.
4949
/// </summary>
@@ -61,7 +61,7 @@ public override byte[] Use() {
6161
/// Creates a uv (texture coordinates) attribute (Float2).
6262
/// </remarks>
6363
/// <param name="uv">The uv vector of this attribute.</param>
64-
public class UVAttribute(Vector2 uv) : VertexAttribute(AttributeType.Float2) {
64+
public class UVAttribute(Vector2 uv) : VertexAttribute(FormatType.Float2) {
6565
/// <summary>
6666
/// The uv vector of this uv attribute.
6767
/// </summary>

GAIL/Graphics/Mesh/Mesh.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ public class Mesh {
2222
public static Mesh FromObj(string path) { return Obj.Parse(path); }
2323

2424
/// <summary>
25-
/// (Face0-p1, Face0-p2, Face0-p3, Face1-p1, etc)
25+
/// The vertices for the <see cref="indexFaces"/>.
2626
/// </summary>
27-
public List<uint> indexFaces = [];
27+
public Vertex[] vertices = [];
2828

2929
/// <summary>
30-
/// The vertices for the <see cref="indexFaces"/>.
30+
/// (Face0-p1, Face0-p2, Face0-p3, Face1-p1, etc)
3131
/// </summary>
32-
public List<Vertex> vertices = [];
32+
public uint[] indexFaces = [];
33+
3334

3435
/// <summary>
3536
/// Creates an mesh from faces.
@@ -43,7 +44,7 @@ public Mesh(List<Face> faces) {
4344
/// </summary>
4445
/// <param name="vertices">The vertices for the indices.</param>
4546
/// <param name="indexFaces">The face indices.</param>
46-
public Mesh(List<Vertex> vertices, List<uint> indexFaces) {
47+
public Mesh(Vertex[] vertices, uint[] indexFaces) {
4748
this.vertices = vertices;
4849
this.indexFaces = indexFaces;
4950
}

GAIL/Graphics/Mesh/Vertex.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public Vertex(Vector3 position) : this() {
3636
/// <param name="requiredAttributes">The attribute types that are required by the shader.</param>
3737
/// <returns>The nessecary vertex attributes.</returns>
3838
/// <exception cref="NotSupportedException">This exception is fired when this vertex does not supply sufficient attributes.</exception>
39-
public VertexAttribute[] Supply(ReadOnlyCollection<AttributeType> requiredAttributes) {
39+
public VertexAttribute[] Supply(ReadOnlyCollection<FormatInfo> requiredAttributes) {
4040
VertexAttribute[] result = new VertexAttribute[requiredAttributes.Count];
4141
int requiredIndex = 0;
4242
foreach (VertexAttribute attribute in Attributes) {
43-
if (attribute.type == requiredAttributes[requiredIndex]) {
43+
if (attribute.info.type == requiredAttributes[requiredIndex].type) {
4444
result[requiredIndex] = attribute;
4545
requiredIndex++;
4646
}

GAIL/Graphics/Mesh/VertexAttribute.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ namespace GAIL.Graphics.Mesh
66
/// </summary>
77
public abstract class VertexAttribute : IEquatable<VertexAttribute> {
88
/// <summary>
9-
/// The type of this attribute.
9+
/// The info of the format of this attribute.
1010
/// </summary>
11-
public readonly AttributeType type;
11+
public readonly FormatInfo info;
1212

1313
/// <summary>
1414
/// Creates a new vertex attribute.
1515
/// </summary>
16-
/// <param name="type">The type of the attribute.</param>
17-
protected VertexAttribute(AttributeType type) { this.type = type; }
16+
/// <param name="info">The info of the format of this attribute.</param>
17+
protected VertexAttribute(FormatInfo info) { this.info = info; }
1818

1919
/// <summary>
2020
/// Generates the data for this attribute.
@@ -28,7 +28,7 @@ public bool Equals(VertexAttribute? other) {
2828

2929
if (ReferenceEquals(this, other)) return true;
3030

31-
return type.Equals(other.type);
31+
return info.Equals(other.info);
3232
}
3333

3434
/// <inheritdoc/>

GAIL/Graphics/Object.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
namespace GAIL.Graphics;
22

3+
/// <summary>
4+
/// A renderable object.
5+
/// </summary>
36
public class Object {
4-
7+
/// <summary>
8+
/// The mesh or shape of this object.
9+
/// </summary>
10+
public Mesh.Mesh mesh;
11+
/// <summary>
12+
/// The material or style of this object.
13+
/// </summary>
14+
public Material.Material material;
15+
/// <summary>
16+
/// Creates a new object.
17+
/// </summary>
18+
/// <param name="mesh">The mesh or shape of this object.</param>
19+
/// <param name="material">The material or style of this object.</param>
20+
public Object(Mesh.Mesh mesh, Material.Material material) {
21+
this.mesh = mesh;
22+
this.material = material;
23+
}
524
}

0 commit comments

Comments
 (0)