12 | {
13 | ///
14 | /// The operation to perform when the stencil test fails.
15 | ///
16 | public StencilOperation StencilFail;
17 |
18 | ///
19 | /// The operation to perform when the depth test fails.
20 | ///
21 | public StencilOperation DepthFail;
22 |
23 | ///
24 | /// The operation to perform when both the depth and stencil tests pass.
25 | ///
26 | public StencilOperation StencilPass;
27 |
28 | ///
29 | /// The function to use when comparing new stencil data to the existing stencil data.
30 | ///
31 | public ComparisonKind Comparison;
32 |
33 | public StencilBehaviorDescription(StencilOperation stencilFail, StencilOperation depthFail, StencilOperation depthStencilPass, ComparisonKind comparison)
34 | {
35 | StencilFail = stencilFail;
36 | DepthFail = depthFail;
37 | StencilPass = depthStencilPass;
38 | Comparison = comparison;
39 | }
40 |
41 | public readonly bool Equals(StencilBehaviorDescription other)
42 | {
43 | return StencilFail == other.StencilFail &&
44 | DepthFail == other.DepthFail &&
45 | StencilPass == other.StencilPass &&
46 | Comparison == other.Comparison;
47 | }
48 |
49 | public override readonly bool Equals(object? obj)
50 | {
51 | return obj is StencilBehaviorDescription other && Equals(other);
52 | }
53 |
54 | public override readonly int GetHashCode()
55 | {
56 | return HashCode.Combine(StencilFail, DepthFail, StencilPass, Comparison);
57 | }
58 |
59 | public static bool operator ==(StencilBehaviorDescription left, StencilBehaviorDescription right)
60 | {
61 | return left.Equals(right);
62 | }
63 |
64 | public static bool operator !=(StencilBehaviorDescription left, StencilBehaviorDescription right)
65 | {
66 | return !(left == right);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Sekai is the framework that powers Vignette.
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | ## Introduction
26 | Sekai is a fully abstracted graphics framework written under the .NET Runtime in C# inspired by other frameworks such as [LÖVE2D](https://github.com/love/love2d) and [osu! framework](https://github.com/ppy/osu-framework). Its core components such as rendering, audio, windowing, input, and even storage can easily be replaced to suit their requirements. The repository contains implementations that make use of GLFW, OpenGL, and OpenAL as a starting point.
27 |
28 | Sekai is used to build [Vignette](https://github.com/vignetteapp/vignette) and is the choice of platform for Cosyne's graphical-related projects.
29 |
30 | ## Getting Started
31 |
32 | ### Building
33 | Please make sure you meet the following prerequisistes:
34 | - A desktop platform with .NET 7 or above installed.
35 |
36 | ### Examples
37 | There are examples in the `./samples/` directory.
38 |
39 | ## License
40 | Sekai is licensed under MIT. See the [the license](./LICENSE) file in the root of this repository for the full text.
41 |
--------------------------------------------------------------------------------
/source/Sekai.OpenAL/ALAudioBuffer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Cosyne
2 | // Licensed under MIT. See LICENSE for details.
3 |
4 | using System;
5 | using Sekai.Audio;
6 | using Silk.NET.OpenAL;
7 |
8 | namespace Sekai.OpenAL;
9 |
10 | internal sealed class ALAudioBuffer : AudioBuffer
11 | {
12 | public override int Capacity
13 | {
14 | get
15 | {
16 | AL.GetBufferProperty(handle, GetBufferInteger.Size, out int size);
17 | return size;
18 | }
19 | }
20 |
21 | public override int SampleRate
22 | {
23 | get
24 | {
25 | AL.GetBufferProperty(handle, GetBufferInteger.Frequency, out int rate);
26 | return rate;
27 | }
28 | }
29 |
30 | public override AudioFormat Format
31 | {
32 | get
33 | {
34 | AL.GetBufferProperty(handle, GetBufferInteger.Channels, out int channels);
35 | AL.GetBufferProperty(handle, GetBufferInteger.Bits, out int bits);
36 |
37 | return channels == 2
38 | ? bits == 8 ? AudioFormat.Stereo8 : AudioFormat.Stereo16
39 | : bits == 8 ? AudioFormat.Mono8 : AudioFormat.Mono16;
40 | }
41 | }
42 |
43 | #pragma warning disable IDE1006
44 |
45 | private readonly AL AL;
46 |
47 | #pragma warning restore IDE1006
48 |
49 | private bool isDisposed;
50 | private readonly uint handle;
51 |
52 | public ALAudioBuffer(AL al)
53 | {
54 | AL = al;
55 | handle = AL.GenBuffer();
56 | }
57 |
58 | public override unsafe void SetData(nint data, uint size, AudioFormat format, int sampleRate)
59 | {
60 | var fmt = format switch
61 | {
62 | AudioFormat.Mono8 => BufferFormat.Mono8,
63 | AudioFormat.Mono16 => BufferFormat.Mono16,
64 | AudioFormat.Stereo8 => BufferFormat.Stereo8,
65 | AudioFormat.Stereo16 => BufferFormat.Stereo16,
66 | _ => throw new ArgumentOutOfRangeException(nameof(format), format, null),
67 | };
68 |
69 | AL.BufferData(handle, fmt, (void*)data, (int)size, sampleRate);
70 | }
71 |
72 | public override void Dispose()
73 | {
74 | if (isDisposed)
75 | {
76 | return;
77 | }
78 |
79 | AL.DeleteBuffer(handle);
80 |
81 | isDisposed = true;
82 |
83 | GC.SuppressFinalize(this);
84 | }
85 |
86 | public static explicit operator uint(ALAudioBuffer buffer) => buffer.handle;
87 | }
88 |
--------------------------------------------------------------------------------
/source/Sekai.OpenGL/GLBlendState.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Cosyne
2 | // Licensed under MIT. See LICENSE for details.
3 |
4 | using Sekai.Graphics;
5 | using Silk.NET.OpenGL;
6 |
7 | namespace Sekai.OpenGL;
8 |
9 | internal sealed class GLBlendState : BlendState
10 | {
11 | public override bool Enabled { get; }
12 | public override BlendType SourceColor { get; }
13 | public override BlendType DestinationColor { get; }
14 | public override BlendOperation ColorOperation { get; }
15 | public override BlendType SourceAlpha { get; }
16 | public override BlendType DestinationAlpha { get; }
17 | public override BlendOperation AlphaOperation { get; }
18 | public override ColorWriteMask WriteMask { get; }
19 | public readonly bool Red;
20 | public readonly bool Green;
21 | public readonly bool Blue;
22 | public readonly bool Alpha;
23 | public readonly BlendingFactor SrcColor;
24 | public readonly BlendingFactor DstColor;
25 | public readonly BlendingFactor SrcAlpha;
26 | public readonly BlendingFactor DstAlpha;
27 | public readonly BlendEquationModeEXT ColorEquation;
28 | public readonly BlendEquationModeEXT AlphaEquation;
29 |
30 | public GLBlendState(BlendStateDescription description)
31 | {
32 | Enabled = description.Enabled;
33 | SourceColor = description.SourceColor;
34 | SourceAlpha = description.SourceAlpha;
35 | DestinationColor = description.DestinationColor;
36 | DestinationAlpha = description.DestinationAlpha;
37 | ColorOperation = description.ColorOperation;
38 | AlphaOperation = description.AlphaOperation;
39 | WriteMask = description.WriteMask;
40 | Red = (description.WriteMask & ColorWriteMask.Red) == ColorWriteMask.Red;
41 | Green = (description.WriteMask & ColorWriteMask.Green) == ColorWriteMask.Green;
42 | Blue = (description.WriteMask & ColorWriteMask.Blue) == ColorWriteMask.Blue;
43 | Alpha = (description.WriteMask & ColorWriteMask.Alpha) == ColorWriteMask.Alpha;
44 | SrcColor = description.SourceColor.AsFactor();
45 | SrcAlpha = description.SourceAlpha.AsFactor();
46 | DstColor = description.DestinationColor.AsFactor();
47 | DstAlpha = description.DestinationAlpha.AsFactor();
48 | ColorEquation = description.ColorOperation.AsEquation();
49 | AlphaEquation = description.AlphaOperation.AsEquation();
50 | }
51 |
52 | public override void Dispose()
53 | {
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/source/Sekai/Input/Button.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Cosyne
2 | // Licensed under MIT. See LICENSE for details.
3 |
4 | using System;
5 | using System.Diagnostics.CodeAnalysis;
6 |
7 | namespace Sekai.Input;
8 |
9 | ///
10 | /// Represents a controller button.
11 | ///
12 | public readonly struct Button : IEquatable