Skip to content

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Terria-K committed Jan 30, 2024
1 parent 22b9fe2 commit 6b3e058
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Riateu/Core/ImGui/Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Riateu.ImGuiRend;

public static unsafe class Clipboard
internal static unsafe class Clipboard
{
private static IntPtr clipboard;
private static readonly Dictionary<Delegate, IntPtr> pinned = new();
Expand Down
58 changes: 29 additions & 29 deletions Riateu/Core/ImGui/ImGuiRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using ImGuiNET;
using MoonWorks;
using MoonWorks.Graphics;
Expand All @@ -13,6 +12,9 @@

namespace Riateu.ImGuiRend;

/// <summary>
/// A canvas renderer to render ImGui library.
/// </summary>
public class ImGuiRenderer
{
private Dictionary<nint, Texture> PtrMap = new();
Expand All @@ -26,6 +28,14 @@ public class ImGuiRenderer
private MBuffer imGuiIndexBuffer;
private Color clearColor;

/// <summary>
/// A initilization for the ImGui renderer and to create its context.
/// </summary>
/// <param name="device">An application device</param>
/// <param name="window">An application window</param>
/// <param name="width">A width of the canvas</param>
/// <param name="height">A height of the canvas</param>
/// <param name="clearColor">A clear color of the canvas on its first draw frame</param>
public ImGuiRenderer(GraphicsDevice device, Window window, int width, int height, Color clearColor)
{
this.clearColor = clearColor;
Expand Down Expand Up @@ -83,6 +93,11 @@ private void HandleSizeChanged(uint width, uint height)
io.DisplaySize = new System.Numerics.Vector2(width, height);
}

/// <summary>
/// A method that updates ImGui inputs and for drawing.
/// </summary>
/// <param name="inputs">An application input device</param>
/// <param name="imGuiCallback">A callback used for rendering</param>
public void Update(MoonWorks.Input.Inputs inputs, Action imGuiCallback)
{
var io = ImGui.GetIO();
Expand Down Expand Up @@ -124,6 +139,14 @@ public void Update(MoonWorks.Input.Inputs inputs, Action imGuiCallback)
imGuiCallback();
ImGui.EndFrame();
}

/// <summary>
/// A draw method used for rendering all of the drawn ImGui surface.
/// </summary>
/// <param name="cmdBuf">
/// A command buffer used for handling and submitting a buffers
/// </param>
/// <param name="texture">A target texture to draw on</param>
public void Draw(CommandBuffer cmdBuf, Texture texture)
{
ImGui.Render();
Expand Down Expand Up @@ -278,6 +301,9 @@ private void RenderCommandLists(CommandBuffer commandBuffer, Texture renderTextu
commandBuffer.EndRenderPass();
}

/// <summary>
/// Destroy the ImGui context.
/// </summary>
public void Destroy()
{
ImGui.DestroyContext();
Expand Down Expand Up @@ -314,7 +340,7 @@ out int bytesPerPixel
AddToPointer(fontTexture);
}

public IntPtr AddToPointer(Texture texture)
internal IntPtr AddToPointer(Texture texture)
{
if (!PtrMap.ContainsKey(texture.Handle))
{
Expand All @@ -324,7 +350,7 @@ public IntPtr AddToPointer(Texture texture)
return texture.Handle;
}

public Texture GetPointer(IntPtr ptr)
internal Texture GetPointer(IntPtr ptr)
{
if (!PtrMap.ContainsKey(ptr))
{
Expand All @@ -336,29 +362,3 @@ public Texture GetPointer(IntPtr ptr)
return texture;
}
}

[StructLayout(LayoutKind.Sequential)]
public struct Position2DTextureColorVertex : IVertexType
{
public Vector2 Position;
public Vector2 TexCoord;
public Color Color;

public Position2DTextureColorVertex(
Vector2 position,
Vector2 texcoord,
Color color
)
{
Position = position;
TexCoord = texcoord;
Color = color;
}

public static VertexElementFormat[] Formats { get; } = new VertexElementFormat[3]
{
VertexElementFormat.Vector2,
VertexElementFormat.Vector2,
VertexElementFormat.Color
};
}
31 changes: 30 additions & 1 deletion Riateu/Core/Structs/InstancedVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,46 @@

namespace Riateu.Components;

/// <summary>
/// A vertex type to be used for the <see cref="GameContext.InstancedPipeline"/>.
/// It can also be used elsewhere.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct InstancedVertex(Vector3 position, Vector2 scale, UV uv, Color color) : IVertexType
{
/// <summary>
/// The position of the vertex.
/// </summary>
public Vector3 Position = position;
/// <summary>
/// The first coordinates of a texture.
/// </summary>
public Vector2 UV0 = uv.TopLeft;
/// <summary>
/// The second coordinates of a texture.
/// </summary>
public Vector2 UV1 = uv.BottomLeft;
/// <summary>
/// The third coordinates of a texture.
/// </summary>
public Vector2 UV2 = uv.TopRight;
/// <summary>
/// The fourth coordinates of a texture.
/// </summary>
public Vector2 UV3 = uv.BottomRight;
/// <summary>
/// The amount of pixel scale of the vertex.
/// </summary>
public Vector2 Scale = scale;
/// <summary>
/// A color that will be passed to the fragment shader
/// </summary>
public Color Color = color;

/// <summary>
/// The element format used in the <see cref="GameContext.InstancedPipeline"/>. And also
/// for other pipeline.
/// </summary>
public static VertexElementFormat[] Formats => [
VertexElementFormat.Vector3,

Expand All @@ -27,4 +56,4 @@ public struct InstancedVertex(Vector3 position, Vector2 scale, UV uv, Color colo
VertexElementFormat.Vector2,
VertexElementFormat.Color,
];
}
}
52 changes: 52 additions & 0 deletions Riateu/Core/Structs/Position2DTextureColorVertex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Runtime.InteropServices;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;

namespace Riateu.Graphics;

/// <summary>
/// A vertex type to be used for the shader info. Usually used by the ImGui renderer.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Position2DTextureColorVertex : IVertexType
{
/// <summary>
/// The position of the vertex in 2d space.
/// </summary>
public Vector2 Position;
/// <summary>
/// A screen-space location of the texture.
/// </summary>
public Vector2 TexCoord;
/// <summary>
/// A color that will be passed to the fragment shader
/// </summary>
public Color Color;

/// <summary>
/// Initialization for this struct.
/// </summary>
/// <param name="position">The position of the vertex in 2d space</param>
/// <param name="texcoord">A screen-space location of the texture</param>
/// <param name="color">A color that will be passed to the fragment shader</param>
public Position2DTextureColorVertex(
Vector2 position,
Vector2 texcoord,
Color color
)
{
Position = position;
TexCoord = texcoord;
Color = color;
}

/// <summary>
/// The element format used for the graphics pipeline.
/// </summary>
public static VertexElementFormat[] Formats { get; } = new VertexElementFormat[3]
{
VertexElementFormat.Vector2,
VertexElementFormat.Vector2,
VertexElementFormat.Color
};
}
12 changes: 12 additions & 0 deletions Riateu/Core/Structs/PositionColorVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@

namespace Riateu.Graphics;

/// <summary>
/// A vertex type to be used for the shader info
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct PositionColorVertex(Vector3 position, Color color) : IVertexType
{
/// <summary>
/// The position of the vertex
/// </summary>
public Vector3 Position = position;
/// <summary>
/// A color that will be passed to the fragment shader
/// </summary>
public Color Color = color;

/// <summary>
/// The element format used for the graphics pipeline.
/// </summary>
public static VertexElementFormat[] Formats { get; } = new VertexElementFormat[2]
{
VertexElementFormat.Vector3,
Expand Down
17 changes: 17 additions & 0 deletions Riateu/Core/Structs/PositionTextureColorVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@

namespace Riateu.Graphics;

/// <summary>
/// A vertex type to be used for the <see cref="GameContext.DefaultPipeline"/>. It can also
/// be used elsewhere.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct PositionTextureColorVertex(Vector3 position, Vector2 texCoord, Color color) : IVertexType
{
/// <summary>
/// The position of the vertex.
/// </summary>
public Vector3 Position = position;
/// <summary>
/// A screen-space location of the texture.
/// </summary>
public Vector2 TexCoord = texCoord;
/// <summary>
/// A color that will be passed to the fragment shader
/// </summary>
public Color Color = color;

/// <summary>
/// The element format used in the <see cref="GameContext.DefaultPipeline"/>. And also
/// for other pipeline.
/// </summary>
public static VertexElementFormat[] Formats { get; } = [
VertexElementFormat.Vector3,
VertexElementFormat.Vector2,
Expand Down
9 changes: 9 additions & 0 deletions Riateu/Core/Structs/PositionVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

namespace Riateu.Graphics;

/// <summary>
/// A vertex type to be used for the shader info
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct PositionVertex(Vector3 position) : IVertexType
{
/// <summary>
/// The position of the vertex
/// </summary>
public Vector3 Position = position;

/// <summary>
/// The element format used for the graphics pipeline.
/// </summary>
public static VertexElementFormat[] Formats { get; } =
[
VertexElementFormat.Vector3
Expand Down
4 changes: 2 additions & 2 deletions documentation/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"modern"
],
"globalMetadata": {
"_appName": "riateu",
"_appTitle": "riateu",
"_appName": "Riateu",
"_appTitle": "Riateu",
"_enableSearch": true,
"pdf": true
}
Expand Down

0 comments on commit 6b3e058

Please sign in to comment.