-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new Blazor Sample App to Samples (#779).
- Loading branch information
Showing
54 changed files
with
4,576 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="MandelbrotExplorer\" /> | ||
<Folder Include="ILGPUWebHost\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Src\ILGPU\ILGPU.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
<canvas id="@CanvasId" width="@Width" height="@Height" @ref="_canvasRef"></canvas> |
246 changes: 246 additions & 0 deletions
246
Samples/BlazorSampleApp/Components/BasicCanvas.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
| ||
// --------------------------------------------------------------------------------------- | ||
// ILGPU Samples | ||
// Copyright (c) 2021 ILGPU Project | ||
// www.ilgpu.net | ||
// | ||
// File: BasicCanvas.razor.cs | ||
// | ||
// This file is part of ILGPU and is distributed under the University of Illinois Open | ||
// Source License. See LICENSE.txt for details. | ||
// --------------------------------------------------------------------------------------- | ||
|
||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.JSInterop; | ||
|
||
namespace BlazorSampleApp.Components | ||
{ | ||
|
||
#nullable disable | ||
public partial class BasicCanvas : ComponentBase, IAsyncDisposable | ||
{ | ||
|
||
private IJSObjectReference asyncModule = null; | ||
|
||
private IJSInProcessObjectReference module = null; | ||
|
||
protected IJSRuntime _jsRuntime; | ||
|
||
protected IJSInProcessRuntime _jsInProcessRuntime = null; | ||
|
||
public event Action<BasicCanvas> CanvasInitComplete = null; | ||
|
||
|
||
|
||
|
||
[Parameter] | ||
public bool IsTransparent { get; set; } = false; | ||
|
||
[Parameter] | ||
public bool IsDesyncronized { get; set; } = false; | ||
|
||
[Parameter] | ||
public int Height { get; set; } = 600; | ||
|
||
[Parameter] | ||
public int Width { get; set; } = 800; | ||
|
||
[Parameter] | ||
public bool IsFullScreen { get; set; } = false; | ||
|
||
|
||
[Parameter] | ||
public string CanvasId { get; set; } = Guid.NewGuid().ToString(); | ||
|
||
protected ElementReference _canvasRef; | ||
|
||
public ElementReference CanvasReference => this._canvasRef; | ||
|
||
public bool IsWebAssembley { get { return (_jsRuntime is IJSInProcessRuntime); } } | ||
|
||
private bool IsDisposing = false; | ||
|
||
[Inject] | ||
public IJSRuntime JS_Runtime | ||
{ | ||
get | ||
{ | ||
return _jsRuntime; | ||
} | ||
set | ||
{ | ||
_jsRuntime = value; | ||
|
||
if (IsWebAssembley) | ||
{ | ||
_jsInProcessRuntime = (IJSInProcessRuntime)value; | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
protected override async Task OnAfterRenderAsync(bool firstRender) | ||
{ | ||
await base.OnAfterRenderAsync(firstRender); | ||
if (firstRender) | ||
{ | ||
|
||
try | ||
{ | ||
if (IsWebAssembley) | ||
{ | ||
|
||
module = await _jsInProcessRuntime.InvokeAsync<IJSInProcessObjectReference>("import", "./Scripts/BasicCanvas.js"); | ||
|
||
module.InvokeVoid("initializeBasicCanvas", CanvasId, IsWebAssembley, IsTransparent, IsDesyncronized); | ||
} | ||
else | ||
{ | ||
asyncModule = await JS_Runtime.InvokeAsync<IJSObjectReference>("import", "./Scripts/BasicCanvas.js"); | ||
|
||
await asyncModule.InvokeVoidAsync("initializeBasicCanvas", CanvasId, IsWebAssembley, IsTransparent, IsDesyncronized); | ||
|
||
} | ||
|
||
if (CanvasInitComplete != null) | ||
CanvasInitComplete(this); | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
var crap = ex.Message; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
IsDisposing = true; | ||
|
||
if (asyncModule != null) | ||
{ | ||
await asyncModule.DisposeAsync(); | ||
} | ||
module?.Dispose(); | ||
} | ||
|
||
public async ValueTask InjectScript(string scriptText) | ||
{ | ||
if (IsDisposing) return; | ||
|
||
if (module != null) | ||
{ | ||
module.InvokeVoid("InjectScript", scriptText); | ||
} | ||
else | ||
{ | ||
await asyncModule.InvokeVoidAsync("InjectScript", scriptText); | ||
} | ||
} | ||
|
||
#nullable enable | ||
public async ValueTask SetValueBasicContext(string ValueName, params object?[]? args) | ||
{ | ||
#nullable disable | ||
if (IsDisposing) return; | ||
|
||
if (module != null) | ||
{ | ||
module.InvokeVoid("setValueBasicContext", CanvasReference, ValueName, args); | ||
} | ||
else | ||
{ | ||
await asyncModule.InvokeVoidAsync("setValueBasicContext", CanvasReference, ValueName, args); | ||
} | ||
} | ||
|
||
|
||
#nullable enable | ||
public async ValueTask<T> GetValueBasicContext<T>(string ValueName, params object?[]? args) | ||
{ | ||
#nullable disable | ||
if (IsDisposing) return default(T); | ||
|
||
if (module != null) | ||
{ | ||
return module.Invoke<T>("getValueBasicContext", CanvasReference, ValueName, args); | ||
} | ||
else | ||
{ | ||
return await asyncModule.InvokeAsync<T>("getValueBasicContext", CanvasReference, ValueName, args); | ||
} | ||
} | ||
|
||
|
||
#nullable enable | ||
public async ValueTask SetFunctionBasicContext(string FunctionName, params object?[]? args) | ||
{ | ||
#nullable disable | ||
if (IsDisposing) return; | ||
|
||
if (module != null) | ||
{ | ||
module.InvokeVoid("setFunctionBasicContext", CanvasReference, FunctionName, args); | ||
} | ||
else | ||
{ | ||
await asyncModule.InvokeVoidAsync("setFunctionBasicContext", CanvasReference, FunctionName, args); | ||
} | ||
} | ||
|
||
#nullable enable | ||
public async ValueTask<T> GetFunctionBasicContext<T>(string FunctionName, params object?[]? args) | ||
{ | ||
#nullable disable | ||
if (IsDisposing) return default(T); | ||
|
||
if (module != null) | ||
{ | ||
return module.Invoke<T>("getFunctionBasicContext", CanvasReference, FunctionName, args); | ||
} | ||
else | ||
{ | ||
return await asyncModule.InvokeAsync<T>("getFunctionBasicContext", CanvasReference, FunctionName, args); | ||
} | ||
} | ||
|
||
#nullable enable | ||
public async ValueTask SetFunctionDrawingBasis(string FunctionName, params object?[]? args) | ||
{ | ||
#nullable disable | ||
if (IsDisposing) return; | ||
|
||
if (module != null) | ||
{ | ||
module.InvokeVoid("setFunctionDrawingBasis", CanvasReference, FunctionName, args); | ||
} | ||
else | ||
{ | ||
await asyncModule.InvokeVoidAsync("setFunctionDrawingBasis", CanvasReference, FunctionName, args); | ||
} | ||
} | ||
|
||
#nullable enable | ||
public async ValueTask<T> GetFunctionDrawingBasis<T>(string FunctionName, params object?[]? args) | ||
{ | ||
#nullable disable | ||
if (IsDisposing) return default(T); | ||
|
||
if (module != null) | ||
{ | ||
return module.Invoke<T>("getFunctionDrawingBasis", CanvasReference, FunctionName, args); | ||
} | ||
else | ||
{ | ||
return await asyncModule.InvokeAsync<T>("getFunctionDrawingBasis", CanvasReference, FunctionName, args); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
canvas { | ||
border: 5px dotted blue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// --------------------------------------------------------------------------------------- | ||
// ILGPU Samples | ||
// Copyright (c) 2021 ILGPU Project | ||
// www.ilgpu.net | ||
// | ||
// File: BasicCanvasEnums.cs | ||
// | ||
// This file is part of ILGPU and is distributed under the University of Illinois Open | ||
// Source License. See LICENSE.txt for details. | ||
// --------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorSampleApp.Components | ||
{ | ||
public enum CanvasLineCap { butt, round, square }; | ||
public enum CanvasLineJoin { round, bevel, miter }; | ||
public enum CanvasTextAlign { start, end, left, right, center }; | ||
public enum CanvasTextBaseline { top, hanging, middle, alphabetic, ideographic, bottom }; | ||
public enum CanvasDirection { ltr, rtl, inherit }; | ||
|
||
|
||
} |
Oops, something went wrong.