Skip to content

Commit

Permalink
Added FreeType
Browse files Browse the repository at this point in the history
  • Loading branch information
JunaMeinhold committed Mar 8, 2024
1 parent 51f1e77 commit c0b2168
Show file tree
Hide file tree
Showing 213 changed files with 168,847 additions and 116,641 deletions.
29 changes: 29 additions & 0 deletions AudioTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// See https://aka.ms/new-console-template for more information
using Hexa.NET.X3DAudio;
using Hexa.NET.XAudio2;
using HexaGen.Runtime.COM;
using System.Numerics;
using XAudioTest;

unsafe
Expand All @@ -13,6 +15,17 @@
ComPtr<IXAudio2MasteringVoice> master = default;
audio.CreateMasteringVoice(ref master, 2, 192000, 0, null, null, AudioStreamCategory.GameMedia).ThrowIf();

uint channelMask;
master.GetChannelMask(&channelMask);

X3DAudioHandle handle = new();
X3DAudio.X3DAudioInitialize(channelMask, X3DAudio.X3DAudio_SPEED_OF_SOUND, &handle).ThrowIf();

for (int i = 0; i < 20; i++)
{
Console.WriteLine(handle.Data[i]);
}

var fs = File.OpenRead("CantinaBand60.wav");

XAudio2WaveAudioStream stream = new(fs)
Expand All @@ -27,6 +40,22 @@
stream.Initialize(source);
source.Start(0, 0).ThrowIf();

X3DAudioListener listener = new(Vector4.UnitZ, Vector4.UnitY, Vector4.Zero, Vector4.Zero);

X3DAudioEmitter emitter = new(null, Vector4.UnitZ, Vector4.UnitY, Vector4.Zero, Vector4.Zero);
float* channelAzu = stackalloc float[waveFormat.Channels + 32];
emitter.PChannelAzimuths = channelAzu;
emitter.ChannelCount = 1;
emitter.CurveDistanceScaler = emitter.DopplerScaler = 1;
var pos = emitter.Position;

X3DAudioDspSettings settings = default;
float* matrix = stackalloc float[waveFormat.Channels + 32];
settings.SrcChannelCount = 1;
settings.DstChannelCount = waveFormat.Channels;
settings.PMatrixCoefficients = matrix;
X3DAudio.X3DAudioCalculate(&handle, &listener, &emitter, X3DAudio.X3DAudio_CALCULATE_MATRIX | X3DAudio.X3DAudio_CALCULATE_DOPPLER | X3DAudio.X3DAudio_CALCULATE_LPF_DIRECT | X3DAudio.X3DAudio_CALCULATE_REVERB, &settings);

bool running = true;
while (running)
{
Expand Down
2 changes: 1 addition & 1 deletion ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
27 changes: 27 additions & 0 deletions D3D11Test/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
public static class Application
{
private static SDLWindow mainWindow;
private static readonly Dictionary<uint, SDLWindow> idToWindow = new();
private static DXGIAdapter adapter;
private static D3D11DeviceManager deviceManager;
private static IApp app;

public static SDLWindow MainWindow => mainWindow;

public static DXGIAdapter Adapter => adapter;

public static D3D11DeviceManager DeviceManager => deviceManager;

public static IApp App => app;

public static void Run(SDLWindow window)
{
mainWindow = window;
idToWindow.Add(window.Id, window);

PlatformInit();

Expand All @@ -25,17 +30,28 @@ public static void Run(SDLWindow window)

private static void PlatformInit()
{
Console.WriteLine("SDL2 Init");

SDL.SDLSetHint(SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
SDL.SDLInit(SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_VIDEO);

Console.WriteLine("SDL2 Init ... Done");

adapter = new(true);
deviceManager = new(adapter, true);

app = new D3D11App();
}

private static void PlatformRun()
{
SDLEvent sdlEvent = default;
bool exiting = false;

app.Init(mainWindow, deviceManager, adapter);

Console.WriteLine("Entering Message Loop");

while (!exiting)
{
SDL.SDLPumpEvents();
Expand All @@ -61,14 +77,25 @@ private static void PlatformRun()
exiting = true;
}
}
if (idToWindow.TryGetValue(windowEvent.WindowID, out var window))
{
window.ProcessEvent(windowEvent);
}
break;
}
}

app.Render();
}

Console.WriteLine("Exiting Message Loop");

Console.WriteLine("Cleanup");
app.Dispose();
deviceManager.Dispose();
adapter.Dispose();

Console.WriteLine("Exit");
SDL.SDLQuit();
}
}
Expand Down
51 changes: 51 additions & 0 deletions D3D11Test/D3D11App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace D3D11Test
{
using Hexa.NET.D3D11;
using HexaGen.Runtime.COM;
using System.Numerics;

public unsafe class D3D11App : IApp
{
private ComPtr<ID3D11Device5> device;
private ComPtr<ID3D11DeviceContext4> context;
private SDLWindow window;
private DXGISwapChain swapChain;
private D3D11DeviceManager deviceManager;
private bool resized = false;

public void Init(SDLWindow window, D3D11DeviceManager manager, DXGIAdapter adapter)
{
Console.WriteLine("App Init");
this.window = window;
swapChain = adapter.CreateSwapChain(manager, window);
deviceManager = manager;
device = manager.Device;
context = manager.Context;
window.Resized += WindowResized;
}

private void WindowResized(ResizedEventArgs obj)
{
resized = true;
}

public void Render()
{
if (resized)
{
swapChain.Resize(window.Width, window.Height);
resized = false;
}

Vector4 color = new(0.2f, 0.4f, 0.6f, 1);
context.ClearRenderTargetView(swapChain.RTV, (float*)&color);

swapChain.Present(1, 0);
}

public void Dispose()
{
swapChain.Dispose();
}
}
}
3 changes: 3 additions & 0 deletions D3D11Test/D3D11DeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public unsafe class D3D11DeviceManager : IDisposable

public D3D11DeviceManager(DXGIAdapter adapter, bool debug)
{
Console.WriteLine("D3D11 Init");
D3DFeatureLevel[] levelsArr = new D3DFeatureLevel[]
{
D3DFeatureLevel.Level111,
Expand Down Expand Up @@ -47,6 +48,8 @@ public D3D11DeviceManager(DXGIAdapter adapter, bool debug)
{
device.QueryInterface(out this.debug);
}

Console.WriteLine("D3D11 Init ... Done");
}

public D3DFeatureLevel Level { get; }
Expand Down
5 changes: 1 addition & 4 deletions D3D11Test/D3D11Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
</ItemGroup>

<ItemGroup>
<None Update="SDL2d.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SDL2d.pdb">
<None Update="SDL2.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
22 changes: 13 additions & 9 deletions D3D11Test/DXGIAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Hexa.NET.DXGI;
using HexaGen.Runtime;
using HexaGen.Runtime.COM;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

Expand All @@ -26,6 +25,8 @@ public unsafe class DXGIAdapter : IDisposable

public DXGIAdapter(bool debug)
{
Console.WriteLine("DXGI Init");

if (debug)
{
DXGI.DXGIGetDebugInterface1(0, out dxgiDebug);
Expand All @@ -46,6 +47,8 @@ public DXGIAdapter(bool debug)

adapter = GetHardwareAdapter();
this.debug = debug;

Console.WriteLine("DXGI Init Done");
}

public ComPtr<IDXGIFactory7> Factory => factory;
Expand Down Expand Up @@ -106,13 +109,13 @@ public void PumpDebugMessages()
string msg = Encoding.UTF8.GetString(MemoryMarshal.CreateReadOnlySpanFromNullTerminated(message->PDescription));

if (message->Producer == DXGI_DEBUG_DX)
Trace.WriteLine($"DX {Convert(message->Severity)}: {msg} [ {Convert(message->Category)} ]");
Console.WriteLine($"DX {Convert(message->Severity)}: {msg} [ {Convert(message->Category)} ]");
if (message->Producer == DXGI_DEBUG_DXGI)
Trace.WriteLine($"DXGI {Convert(message->Severity)}: {msg} [ {Convert(message->Category)} ]");
Console.WriteLine($"DXGI {Convert(message->Severity)}: {msg} [ {Convert(message->Category)} ]");
if (message->Producer == DXGI_DEBUG_APP)
Trace.WriteLine($"APP {Convert(message->Severity)}: {msg} [ {Convert(message->Category)} ]");
Console.WriteLine($"APP {Convert(message->Severity)}: {msg} [ {Convert(message->Category)} ]");
if (message->Producer == DXGI_DEBUG_D3D11)
Trace.WriteLine($"D3D11 {Convert(message->Severity)}: {msg} [ {Convert(message->Category)} ]");
Console.WriteLine($"D3D11 {Convert(message->Severity)}: {msg} [ {Convert(message->Category)} ]");

Free(message);
}
Expand Down Expand Up @@ -143,12 +146,13 @@ public DXGISwapChain CreateSwapChain(D3D11DeviceManager manager, SDLWindow windo
{
Windowed = 1,
RefreshRate = new DxgiRational(0, 1),
Scaling = Silk.NET.DXGI.ModeScaling.Unspecified,
ScanlineOrdering = Silk.NET.DXGI.ModeScanlineOrder.Unspecified,
Scaling = DxgiModeScaling.Unspecified,
ScanlineOrdering = DxgiModeScanlineOrder.Unspecified,
};

ComPtr<IDXGIOutput> output = default;
factory.CreateSwapChainForHwnd((IUnknown*)manager.Device, Hwnd, &desc, &fullscreenDesc, (IDXGIOutput*)null, out ComPtr<IDXGISwapChain2> swapChain);
factory.CreateSwapChainForHwnd((IUnknown*)manager.Device.Handle, Hwnd, &desc, &fullscreenDesc, (IDXGIOutput*)null, out ComPtr<IDXGISwapChain1> swapChain);

return new DXGISwapChain(manager, swapChain, desc);
}

private ComPtr<IDXGIAdapter4> GetHardwareAdapter()
Expand Down
58 changes: 55 additions & 3 deletions D3D11Test/DXGISwapChain.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,71 @@
namespace D3D11Test
{
using Hexa.NET.D3D11;
using Hexa.NET.DXGI;
using HexaGen.Runtime.COM;

public class DXGISwapChain
public unsafe class DXGISwapChain : IDisposable
{
private readonly D3D11DeviceManager manager;
private ComPtr<IDXGISwapChain2> swapChain;
private readonly DxgiSwapChainDesc1 desc;
private ComPtr<IDXGISwapChain1> swapChain;
private bool disposedValue;

public DXGISwapChain(D3D11DeviceManager manager, ComPtr<IDXGISwapChain2> swapChain, DxgiSwapChainDesc1 desc)
private ComPtr<ID3D11Texture2D> backbuffer;
private ComPtr<ID3D11RenderTargetView> rtv;

public DXGISwapChain(D3D11DeviceManager manager, ComPtr<IDXGISwapChain1> swapChain, DxgiSwapChainDesc1 desc)
{
Console.WriteLine("SwapChain Init");

this.manager = manager;
this.swapChain = swapChain;
this.desc = desc;

swapChain.GetBuffer(0, out backbuffer);
manager.Device.CreateRenderTargetView((ID3D11Resource*)backbuffer.Handle, null, out rtv);

Console.WriteLine("SwapChain Init ... Done");
}

public ComPtr<ID3D11RenderTargetView> RTV => rtv;

public ComPtr<ID3D11Texture2D> Backbuffer => backbuffer;

public void Present(uint syncInterval, uint flags)
{
swapChain.Present(syncInterval, flags);
}

public void Resize(int width, int height)
{
Console.WriteLine($"SwapChain Resize");
rtv.Release();
backbuffer.Release();

swapChain.ResizeBuffers(desc.BufferCount, (uint)width, (uint)height, desc.Format, desc.Flags);

swapChain.GetBuffer(0, out backbuffer);
manager.Device.CreateRenderTargetView((ID3D11Resource*)backbuffer.Handle, null, out rtv);
Console.WriteLine($"SwapChain Resize ... Done");
}

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
rtv.Dispose();
backbuffer.Dispose();
swapChain.Dispose();
disposedValue = true;
}
}

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
11 changes: 11 additions & 0 deletions D3D11Test/IApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace D3D11Test
{
public interface IApp
{
public void Init(SDLWindow window, D3D11DeviceManager manager, DXGIAdapter adapter);

public void Render();

public void Dispose();
}
}
8 changes: 8 additions & 0 deletions D3D11Test/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"D3D11Test": {
"commandName": "Project",
"nativeDebugging": true
}
}
}
Binary file added D3D11Test/SDL2.dll
Binary file not shown.
Binary file removed D3D11Test/SDL2d.dll
Binary file not shown.
Loading

0 comments on commit c0b2168

Please sign in to comment.