Skip to content

Commit

Permalink
Merge pull request #2 from AshleighAdams/dotnet7
Browse files Browse the repository at this point in the history
Update to .NET 7
  • Loading branch information
AshleighAdams authored Jul 2, 2023
2 parents af9fa9d + 37cbc34 commit 3724e43
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
with:
fetch-depth: '0'

- name: Setup .NET 6 SDK
- name: Setup .NET 7 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

- name: Install wasm-tools workload
run: |
Expand Down
47 changes: 29 additions & 18 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
using System.Runtime.InteropServices;

using Microsoft.JSInterop.WebAssembly;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using WaveEngine.Bindings.OpenGLES;
using System.Runtime.CompilerServices;
using Evergine.Bindings.OpenGL;
using Microsoft.JSInterop;
using System.Threading.Tasks;

namespace WasmTest;

Expand Down Expand Up @@ -101,18 +98,27 @@ internal static class EGL
public static extern int SwapInterval(IntPtr display, int interval);
}

internal static class Emscripten
{
[DllImport("emscripten", EntryPoint = "emscripten_request_animation_frame_loop")]
[DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
internal static extern unsafe void RequestAnimationFrameLoop(void* f, nint userDataPtr);
}

public static class Test
{
[JSInvokable("frame")]
public static void Frame(double time)
[UnmanagedCallersOnly]
public static int Frame(double time, nint userData)
{
GL.glClearColor(0.7f, 0.2f, 1.0f, 1.0f);
GL.glClear((uint)AttribMask.ColorBufferBit);
GL.glClear((uint)(AttribMask.ColorBufferBit));

return 1;
}

public static int Main(string[] args)
{
Console.WriteLine($"Hello from .Net6!");
Console.WriteLine($"Hello from dotnet!");

var display = EGL.GetDisplay(IntPtr.Zero);
if (display == IntPtr.Zero)
Expand All @@ -123,15 +129,15 @@ public static int Main(string[] args)

int[] attributeList = new int[]
{
EGL.EGL_RED_SIZE , 8,
EGL.EGL_GREEN_SIZE, 8,
EGL.EGL_BLUE_SIZE , 8,
EGL.EGL_DEPTH_SIZE, 24,
EGL.EGL_STENCIL_SIZE, 8,
EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT,
EGL.EGL_RENDERABLE_TYPE, EGL.EGL_OPENGL_ES3_BIT,
EGL.EGL_SAMPLES, 16, //MSAA, 16 samples
EGL.EGL_NONE
EGL.EGL_RED_SIZE , 8,
EGL.EGL_GREEN_SIZE, 8,
EGL.EGL_BLUE_SIZE , 8,
EGL.EGL_DEPTH_SIZE, 24,
EGL.EGL_STENCIL_SIZE, 8,
EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT,
EGL.EGL_RENDERABLE_TYPE, EGL.EGL_OPENGL_ES3_BIT,
EGL.EGL_SAMPLES, 16, //MSAA, 16 samples
EGL.EGL_NONE
};

var config = IntPtr.Zero;
Expand Down Expand Up @@ -167,6 +173,11 @@ public static int Main(string[] args)
using var runtime = new MyRuntime();
runtime.InvokeVoid("initialize");

return args.Length;
unsafe
{
Emscripten.RequestAnimationFrameLoop((delegate* unmanaged<double, nint, int>)&Frame, nint.Zero);
}

return 0;
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# .NET 6 WebAssembly + WebGL
# .NET WebAssembly + WebGL

This is a minimum viable product for running WebGL, using dotnet6's BlazorWebassembly and WaveEngine's OpenGLES with emscripten, based on @emepetres's wasm sample projects.
This is a minimum viable product for running WebGL, using dotnet's BlazorWebassembly and WaveEngine's OpenGLES with emscripten, based on @emepetres's wasm sample projects.

## Areas needing work

Expand Down
19 changes: 10 additions & 9 deletions WasmTest.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<!-- https://github.com/emepetres/dotnet-wasm-sample/blob/main/src/console-native/Wasm.ConsoleNative.Sample.csproj -->
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>11</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EmccFlags>-s FULL_ES3=1</EmccFlags>
<EmccFlags>-s FULL_ES3=1 -lopenal -lGL</EmccFlags>
<InvariantGlobalization>true</InvariantGlobalization>
<!--<EmccFlags>-s MAX_WEBGL_VERSION=2</EmccFlags>-->
</PropertyGroup>
Expand All @@ -14,24 +14,25 @@
<PublishTrimmed Condition="'$(Configuration)' == 'Release'">true</PublishTrimmed>
<BlazorEnableCompression Condition="'$(Configuration)' == 'Debug'">false</BlazorEnableCompression>
<WasmBuildNative>true</WasmBuildNative>
<!-- <RunAOTCompilation>true</RunAOTCompilation>
<AOTMode>LLVMOnly</AOTMode> -->
<RunAOTCompilation>true</RunAOTCompilation>
<!--<AOTMode>LLVMOnly</AOTMode> -->
</PropertyGroup>

<ItemGroup>
<NativeFileReference Include="libEGL.c" ScanForPInvokes="true" />
<NativeFileReference Include="openal32.c" ScanForPInvokes="true" />
<NativeFileReference Include="emscripten.c" ScanForPInvokes="true" />
</ItemGroup>

<ItemGroup>
<TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Verlite.MsBuild" Version="2.0.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0" PrivateAssets="All" />
<PackageReference Include="WaveEngine.Bindings.OpenGLES" Version="1.0.4998" />
<PackageReference Include="Verlite.MsBuild" Version="2.4.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.8" PrivateAssets="all" />
<PackageReference Include="Evergine.Bindings.OpenGL" Version="2023.2.19.1" />
</ItemGroup>

</Project>
6 changes: 1 addition & 5 deletions wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
};

window.initialize = () => {
window.requestAnimationFrame(frame);
// setup interop such as forwarding mouse/keyboard input
}

function frame(time) {
DotNet.invokeMethod("WasmTest", "frame", time);
window.requestAnimationFrame(frame);
}
</script>

<script src="_framework/blazor.webassembly.js"></script>
Expand Down

0 comments on commit 3724e43

Please sign in to comment.