-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51f1e77
commit c0b2168
Showing
213 changed files
with
168,847 additions
and
116,641 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
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
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
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,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(); | ||
} | ||
} | ||
} |
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
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
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
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 |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
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,11 @@ | ||
namespace D3D11Test | ||
{ | ||
public interface IApp | ||
{ | ||
public void Init(SDLWindow window, D3D11DeviceManager manager, DXGIAdapter adapter); | ||
|
||
public void Render(); | ||
|
||
public void Dispose(); | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"profiles": { | ||
"D3D11Test": { | ||
"commandName": "Project", | ||
"nativeDebugging": true | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.