Skip to content

Commit cd7f8d2

Browse files
authored
Merge pull request #22 from HexaEngine/vtable
Vtable
2 parents 80b1ee0 + fdae685 commit cd7f8d2

File tree

342 files changed

+194742
-91012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

342 files changed

+194742
-91012
lines changed

BgfxTest/BgfxTest.csproj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\Hexa.NET.Bgfx\Hexa.NET.Bgfx.csproj" />
13+
<ProjectReference Include="..\Hexa.NET.SDL2\Hexa.NET.SDL2.csproj" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<None Update="bgfx.dll">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
<None Update="bgfx.pdb">
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
</None>
23+
</ItemGroup>
24+
25+
</Project>

BgfxTest/Program.cs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
namespace BgfxTest
2+
{
3+
using Hexa.NET.Bgfx;
4+
using Hexa.NET.SDL2;
5+
using System;
6+
7+
internal unsafe class Program
8+
{
9+
private static int width;
10+
private static int height;
11+
12+
private static void Main(string[] args)
13+
{
14+
SDL.SDLSetHint(SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
15+
SDL.SDLInit(SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_VIDEO);
16+
17+
var window = SDL.SDLCreateWindow("Test Window", 32, 32, 1280, 720, (uint)SDLWindowFlags.Resizable);
18+
var windowId = SDL.SDLGetWindowID(window);
19+
20+
int w, h;
21+
SDL.SDLGetWindowSize(window, &w, &h);
22+
width = w;
23+
height = h;
24+
25+
Init(window, windowId);
26+
27+
SDLEvent sdlEvent = default;
28+
bool exiting = false;
29+
while (!exiting)
30+
{
31+
SDL.SDLPumpEvents();
32+
33+
while ((SDLBool)SDL.SDLPollEvent(ref sdlEvent) == SDLBool.True)
34+
{
35+
switch ((SDLEventType)sdlEvent.Type)
36+
{
37+
case SDLEventType.Quit:
38+
exiting = true;
39+
break;
40+
41+
case SDLEventType.AppTerminating:
42+
exiting = true;
43+
break;
44+
45+
case SDLEventType.Windowevent:
46+
var windowEvent = sdlEvent.Window;
47+
if (windowEvent.WindowID == windowId)
48+
{
49+
if ((SDLWindowEventID)windowEvent.Event == SDLWindowEventID.Close)
50+
{
51+
exiting = true;
52+
}
53+
}
54+
break;
55+
}
56+
}
57+
58+
Render();
59+
}
60+
61+
SDL.SDLQuit();
62+
}
63+
64+
private static void Init(SDLWindow* window, uint windowId)
65+
{
66+
BgfxPlatformData platformData = default;
67+
68+
SDLSysWMInfo wmInfo;
69+
70+
SDL.SDLGetVersion(&wmInfo.Version);
71+
SDL.SDLGetWindowWMInfo(window, &wmInfo);
72+
73+
platformData.Nwh = (void*)wmInfo.Info.Win.Window;
74+
platformData.Ndt = null;
75+
platformData.Type = BgfxNativeWindowHandleType.Default;
76+
77+
int w, h;
78+
SDL.SDLGetWindowSize(window, &w, &h);
79+
80+
BgfxInit init = default;
81+
init.Type = BgfxRendererType.Direct3D12;
82+
init.VendorId = 0;
83+
init.PlatformData = platformData;
84+
init.Resolution.Width = (uint)w;
85+
init.Resolution.Height = (uint)h;
86+
init.Resolution.Reset = 0x80;
87+
init.Resolution.Format = BgfxTextureFormat.Bgra8;
88+
init.Capabilities = ulong.MaxValue;
89+
init.Limits.MaxEncoders = 8;
90+
init.Limits.MinResourceCbSize = 64 << 10;
91+
init.Limits.TransientVbSize = 6 << 20;
92+
init.Limits.TransientIbSize = 2 << 20;
93+
94+
if (!Bgfx.BgfxInit(ref init))
95+
{
96+
throw new Exception("Failed to init");
97+
}
98+
99+
Bgfx.BgfxSetDebug(8);
100+
101+
Bgfx.BgfxSetViewClear(0
102+
, 0x1 | 0x2
103+
, 0x303030ff
104+
, 1.0f
105+
, 0
106+
);
107+
}
108+
109+
private static void Render()
110+
{
111+
Bgfx.BgfxSetViewRect(0, 0, 0, (ushort)(width), (ushort)(height));
112+
Bgfx.BgfxTouch(0);
113+
114+
Bgfx.BgfxDbgTextClear(0, false);
115+
116+
Bgfx.BgfxDbgTextPrintf(0, 1, 0x0f, "Color can be changed with ANSI \x1b[9;me\x1b[10;ms\x1b[11;mc\x1b[12;ma\x1b[13;mp\x1b[14;me\x1b[0m code too.");
117+
118+
Bgfx.BgfxFrame(false);
119+
}
120+
}
121+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"BgfxTest": {
4+
"commandName": "Project",
5+
"nativeDebugging": true
6+
}
7+
}
8+
}

BgfxTest/bgfx.dll

3.68 MB
Binary file not shown.

DaxaTest/Program.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,68 @@
11
namespace DaxaTest
22
{
3+
using Hexa.NET.SDL2;
34
using Hexa.NET.Daxa;
45
using System.Runtime.InteropServices;
6+
using System;
57

68
internal unsafe class Program
79
{
10+
private static int width;
11+
private static int height;
12+
813
private static void Main(string[] args)
14+
{
15+
SDL.SDLSetHint(SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
16+
SDL.SDLInit(SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_VIDEO);
17+
18+
var window = SDL.SDLCreateWindow("Test Window", 32, 32, 1280, 720, (uint)SDLWindowFlags.Resizable);
19+
var windowId = SDL.SDLGetWindowID(window);
20+
21+
int w, h;
22+
SDL.SDLGetWindowSize(window, &w, &h);
23+
width = w;
24+
height = h;
25+
26+
InitGraphics(window);
27+
28+
SDLEvent sdlEvent = default;
29+
bool exiting = false;
30+
while (!exiting)
31+
{
32+
SDL.SDLPumpEvents();
33+
34+
while ((SDLBool)SDL.SDLPollEvent(ref sdlEvent) == SDLBool.True)
35+
{
36+
switch ((SDLEventType)sdlEvent.Type)
37+
{
38+
case SDLEventType.Quit:
39+
exiting = true;
40+
break;
41+
42+
case SDLEventType.AppTerminating:
43+
exiting = true;
44+
break;
45+
46+
case SDLEventType.Windowevent:
47+
var windowEvent = sdlEvent.Window;
48+
if (windowEvent.WindowID == windowId)
49+
{
50+
if ((SDLWindowEventID)windowEvent.Event == SDLWindowEventID.Close)
51+
{
52+
exiting = true;
53+
}
54+
}
55+
break;
56+
}
57+
}
58+
59+
Render();
60+
}
61+
62+
SDL.SDLQuit();
63+
}
64+
65+
private static void InitGraphics(SDLWindow* window)
966
{
1067
DaxaInstanceInfo instanceInfo = new();
1168
DaxaInstance instance;
@@ -22,6 +79,43 @@ private static void Main(string[] args)
2279
DaxaDevice device;
2380

2481
instance.CreateDevice(&deviceInfo, &device).CheckError();
82+
83+
SDLSysWMInfo wmInfo;
84+
85+
SDL.SDLGetVersion(&wmInfo.Version);
86+
SDL.SDLGetWindowWMInfo(window, &wmInfo);
87+
88+
DaxaSwapchainInfo swapchainInfo;
89+
swapchainInfo.NativeWindow = wmInfo.Info.Win.Window;
90+
swapchainInfo.NativeWindowPlatform = DaxaNativeWindowPlatform.Win32Api;
91+
swapchainInfo.PresentOperation = VkSurfaceTransformFlagBitsKHR.InheritBitKhr;
92+
swapchainInfo.PresentMode = VkPresentModeKHR.MailboxKhr;
93+
swapchainInfo.MaxAllowedFramesInFlight = 2;
94+
swapchainInfo.ImageUsage = (uint)VkImageUsageFlagBits.TransferDstBit;
95+
swapchainInfo.SurfaceFormatSelector = (void*)Marshal.GetFunctionPointerForDelegate<SurfaceFormatSelector>(OnSwapchainSurfaceFormatSelector);
96+
97+
DaxaSwapchain swapchain;
98+
device.DvcCreateSwapchain(&swapchainInfo, &swapchain).CheckError();
99+
}
100+
101+
private static int OnSwapchainSurfaceFormatSelector(VkFormat format)
102+
{
103+
switch (format)
104+
{
105+
case VkFormat.B8G8R8A8Unorm:
106+
return 100;
107+
108+
case VkFormat.R8G8B8A8Unorm:
109+
return 2;
110+
111+
default:
112+
return Daxa.DaxaDefaultFormatSelector(format);
113+
}
114+
}
115+
116+
private static void Render()
117+
{
118+
throw new NotImplementedException();
25119
}
26120

27121
private static unsafe int OnSelector(DaxaDeviceProperties* properties)

Hexa.NET.Bgfx/AssemblyInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: DisableRuntimeMarshalling]

Hexa.NET.Bgfx/Bgfx.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#nullable disable
2+
3+
namespace Hexa.NET.Bgfx
4+
{
5+
using System.Numerics;
6+
using System.Runtime.InteropServices;
7+
8+
public static unsafe partial class Bgfx
9+
{
10+
static Bgfx()
11+
{
12+
InitApi();
13+
}
14+
15+
public static nint GetLibraryName()
16+
{
17+
return LibraryLoader.LoadLibrary();
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)