Skip to content

Commit

Permalink
Improve Vortice.Framework to be more than Win32 compatible, added Win…
Browse files Browse the repository at this point in the history
…UI support and WinUI example.
  • Loading branch information
amerkoleci committed Jun 15, 2024
1 parent 98a361f commit 3365228
Show file tree
Hide file tree
Showing 52 changed files with 2,063 additions and 1,020 deletions.
11 changes: 7 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
<!-- https://learn.microsoft.com/nuget/consume-packages/central-package-management -->
<!-- Package versions for package references across all projects -->
<PropertyGroup>
<VorticeWindowsVersion>3.4.3-beta</VorticeWindowsVersion>
<VorticeWindowsVersion>3.5.4-beta</VorticeWindowsVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="8.2.2" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.106" />

<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.4.231219000" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.5.240607001" />

<PackageVersion Include="Vortice.Mathematics" Version="1.7.6" />
<PackageVersion Include="Vortice.Mathematics" Version="1.7.8" />
<PackageVersion Include="Vortice.Direct2D1" Version="$(VorticeWindowsVersion)" />
<PackageVersion Include="Vortice.Direct3D11" Version="$(VorticeWindowsVersion)" />
<PackageVersion Include="Vortice.Direct3D12" Version="$(VorticeWindowsVersion)" />
<PackageVersion Include="Vortice.XAudio2" Version="$(VorticeWindowsVersion)" />
<PackageVersion Include="Vortice.MediaFoundation" Version="$(VorticeWindowsVersion)" />
<PackageVersion Include="Vortice.D3DCompiler" Version="$(VorticeWindowsVersion)" />
<PackageVersion Include="Vortice.Dxc" Version="$(VorticeWindowsVersion)" />
<PackageVersion Include="Vortice.WinUI" Version="$(VorticeWindowsVersion)" />

</ItemGroup>

</Project>
263 changes: 263 additions & 0 deletions Vortice.Windows.Samples.sln

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Direct3D11/01_HelloWindow/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected override void OnRender()

public static void Main()
{
using HelloWindowApp app = new();
HelloWindowApp app = new();
app.Run();
}
}
17 changes: 7 additions & 10 deletions src/Direct3D11/02_DrawTriangle/TriangleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ protected override void Initialize()
_inputLayout = Device.CreateInputLayout(VertexPositionColor.InputElements, vertexShaderByteCode.Span);
}

protected override void Dispose(bool dispose)
protected override void OnShutdown()
{
if (dispose)
{
_vertexBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();
}
_vertexBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();

base.Dispose(dispose);
base.OnShutdown();
}

protected override void OnRender()
Expand All @@ -63,7 +60,7 @@ protected override void OnRender()

public static void Main()
{
using TriangleApp app = new();
TriangleApp app = new();
app.Run();
}
}
17 changes: 7 additions & 10 deletions src/Direct3D11/03_DrawQuad/DrawQuadApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ protected override unsafe void Initialize()
_inputLayout = Device.CreateInputLayout(VertexPositionColor.InputElements, vertexShaderByteCode.Span);
}

protected override void Dispose(bool dispose)
protected override void OnShutdown()
{
if (dispose)
{
_vertexBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();
}
_vertexBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();

base.Dispose(dispose);
base.OnShutdown();
}

protected override void OnRender()
Expand Down Expand Up @@ -103,7 +100,7 @@ private Color4 RandomColor()

public static void Main()
{
using DrawQuadApp app = new();
DrawQuadApp app = new();
app.Run();
}
}
21 changes: 9 additions & 12 deletions src/Direct3D11/04_BufferOffsets/BufferOffsetsApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override void Initialize()
};
_vertexBuffer = Device.CreateBuffer(quadVertices, BindFlags.VertexBuffer);

ReadOnlySpan<ushort> quadIndices = stackalloc ushort[] {
ReadOnlySpan<ushort> quadIndices = [
0,
1,
2,
Expand All @@ -46,7 +46,7 @@ protected override void Initialize()
0,
2,
3
};
];
_indexBuffer = Device.CreateBuffer(quadIndices, BindFlags.IndexBuffer);

ReadOnlyMemory<byte> vertexShaderByteCode = CompileBytecode("HelloTriangle.hlsl", "VSMain", "vs_4_0");
Expand All @@ -57,17 +57,14 @@ protected override void Initialize()
_inputLayout = Device.CreateInputLayout(VertexPosition2DColor.InputElements, vertexShaderByteCode.Span);
}

protected override void Dispose(bool dispose)
protected override void OnShutdown()
{
if (dispose)
{
_vertexBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();
}
_vertexBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();

base.Dispose(dispose);
base.OnShutdown();
}

protected override void OnRender()
Expand Down Expand Up @@ -103,7 +100,7 @@ protected override void OnRender()

public static void Main()
{
using BufferOffsetsApp app = new();
BufferOffsetsApp app = new();
app.Run();
}
}
32 changes: 13 additions & 19 deletions src/Direct3D11/05_Cube/CubeApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class CubeApp : D3D11Application
private ID3D11VertexShader _vertexShader;
private ID3D11PixelShader _pixelShader;
private ID3D11InputLayout _inputLayout;
private Stopwatch _clock;

protected override void Initialize()
{
Expand All @@ -35,35 +34,30 @@ protected override void Initialize()
_vertexShader = Device.CreateVertexShader(vertexShaderByteCode.Span);
_pixelShader = Device.CreatePixelShader(pixelShaderByteCode.Span);
_inputLayout = Device.CreateInputLayout(VertexPositionNormalTexture.InputElements, vertexShaderByteCode.Span);

_clock = Stopwatch.StartNew();
}

protected override void Dispose(bool dispose)
protected override void OnShutdown()
{
if (dispose)
{
_vertexBuffer.Dispose();
_indexBuffer.Dispose();
_constantBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();
}

base.Dispose(dispose);
_vertexBuffer.Dispose();
_indexBuffer.Dispose();
_constantBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();

base.OnShutdown();
}

protected unsafe override void OnRender()
{
DeviceContext.ClearRenderTargetView(ColorTextureView, Colors.CornflowerBlue);
DeviceContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);

float time = _clock.ElapsedMilliseconds / 1000.0f;
Matrix4x4 world = Matrix4x4.CreateRotationX(time) * Matrix4x4.CreateRotationY(time * 2) * Matrix4x4.CreateRotationZ(time * .7f);
float deltaTime = (float)Time.Total.TotalSeconds;
Matrix4x4 world = Matrix4x4.CreateRotationX(deltaTime) * Matrix4x4.CreateRotationY(deltaTime * 2) * Matrix4x4.CreateRotationZ(deltaTime * .7f);

Matrix4x4 view = Matrix4x4.CreateLookAt(new Vector3(0, 0, 25), new Vector3(0, 0, 0), Vector3.UnitY);
Matrix4x4 projection = Matrix4x4.CreatePerspectiveFieldOfView((float)Math.PI / 4, AspectRatio, 0.1f, 100);
Matrix4x4 projection = Matrix4x4.CreatePerspectiveFieldOfView(MathF.PI / 4, AspectRatio, 0.1f, 100);
Matrix4x4 viewProjection = Matrix4x4.Multiply(view, projection);
Matrix4x4 worldViewProjection = Matrix4x4.Multiply(world, viewProjection);

Expand All @@ -82,7 +76,7 @@ protected unsafe override void OnRender()

static void Main()
{
using CubeApp app = new();
CubeApp app = new();
app.Run();
}
}
42 changes: 18 additions & 24 deletions src/Direct3D11/06_CubeAlphaBlend/CubeAlphaBlendApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class CubeAlphaBlendApp : D3D11Application
private ID3D11RasterizerState _rasterizerState;
private ID3D11DepthStencilState _depthStencilState;
private ID3D11BlendState _blendState;
private Stopwatch _clock;

protected override void Initialize()
{
Expand All @@ -40,35 +39,30 @@ protected override void Initialize()
_rasterizerState = Device.CreateRasterizerState(RasterizerDescription.CullNone);
_depthStencilState = Device.CreateDepthStencilState(DepthStencilDescription.Default);
_blendState = Device.CreateBlendState(BlendDescription.NonPremultiplied);

_clock = Stopwatch.StartNew();
}

protected override void Dispose(bool dispose)
protected override void OnShutdown()
{
if (dispose)
{
_vertexBuffer.Dispose();
_indexBuffer.Dispose();
_constantBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();
_rasterizerState.Dispose();
_depthStencilState.Dispose();
_blendState.Dispose();
}

base.Dispose(dispose);
_vertexBuffer.Dispose();
_indexBuffer.Dispose();
_constantBuffer.Dispose();
_vertexShader.Dispose();
_pixelShader.Dispose();
_inputLayout.Dispose();
_rasterizerState.Dispose();
_depthStencilState.Dispose();
_blendState.Dispose();

base.OnShutdown();
}

protected unsafe override void OnRender()
{
DeviceContext.ClearRenderTargetView(ColorTextureView, new Color4(0.5f, 0.5f, 0.5f, 1.0f));
DeviceContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);

float time = _clock.ElapsedMilliseconds / 1000.0f;
Matrix4x4 world = Matrix4x4.CreateRotationX(time) * Matrix4x4.CreateRotationY(time * 2) * Matrix4x4.CreateRotationZ(time * .7f);
float deltaTime = (float)Time.Total.TotalSeconds;
Matrix4x4 world = Matrix4x4.CreateRotationX(deltaTime) * Matrix4x4.CreateRotationY(deltaTime * 2) * Matrix4x4.CreateRotationZ(deltaTime * .7f);

Matrix4x4 view = Matrix4x4.CreateLookAt(new Vector3(0, 0, 25), new Vector3(0, 0, 0), Vector3.UnitY);
Matrix4x4 projection = Matrix4x4.CreatePerspectiveFieldOfView((float)Math.PI / 4, AspectRatio, 0.1f, 100);
Expand All @@ -89,7 +83,7 @@ protected unsafe override void OnRender()
DeviceContext.VSSetConstantBuffer(0, _constantBuffer);
DeviceContext.IASetVertexBuffer(0, _vertexBuffer, VertexPositionColor.SizeInBytes);
DeviceContext.IASetIndexBuffer(_indexBuffer, Format.R16_UInt, 0);


DeviceContext.DrawIndexed(36, 0, 0);
}
Expand Down Expand Up @@ -141,8 +135,8 @@ protected unsafe override void OnRender()
indices[indicesCount++] = (ushort)(vbase + 1);
indices[indicesCount++] = (ushort)(vbase + 2);

indices[indicesCount++] =(ushort)(vbase + 0);
indices[indicesCount++] =(ushort)(vbase + 2);
indices[indicesCount++] = (ushort)(vbase + 0);
indices[indicesCount++] = (ushort)(vbase + 2);
indices[indicesCount++] = (ushort)(vbase + 3);

// Four vertices per face.
Expand Down Expand Up @@ -181,7 +175,7 @@ protected unsafe override void OnRender()

static void Main()
{
using CubeAlphaBlendApp app = new();
CubeAlphaBlendApp app = new();
app.Run();
}
}
Loading

0 comments on commit 3365228

Please sign in to comment.